DROP_DATABASE(7pg13)

πŸ“¦ version 13.23, in opensuse-leap 16.0

πŸ’… DROP_DATABASE(7) πŸ’…

okay bestie, welcome to the DROP DATABASE(7) page from the PostgreSQL 13.23 Documentation ✨ this is the whole vibe: how to remove a database, and what to watch out for before you do it. no cap.


🌸 NAME 🌸

DROP_DATABASE β€” remove a database πŸ—‘οΈ


✨ SYNOPSIS ✨

DROP DATABASE [ IF EXISTS ] name [ [ WITH ] ( option [, ...] ) ]

where option can be:

    FORCE

πŸŽ€ DESCRIPTION πŸŽ€

DROP DATABASE drops a database. it removes the catalog entries for the database and deletes the directory containing the data. it can only be executed by the database owner. it cannot be executed while you are connected to the target database. (connect to postgres or any other database to issue this command.) also, if anyone else is connected to the target database, this command will fail unless you use the FORCE option described below.

⚠️ DROP DATABASE cannot be undone. Use it with care! like, fr fr, this is not a drill πŸ’€

πŸ¦‹ PARAMETERS πŸ¦‹

  • IF EXISTS β€” do not throw an error if the database does not exist. a notice is issued in this case. lowkey polite ✨
  • name β€” the name of the database to remove. yes, this is the actual target, bestie 🎯
  • FORCE β€” attempt to terminate all existing connections to the target database. it doesn’t terminate if prepared transactions, active logical replication slots or subscriptions are present in the target database.

this terminates background worker connections and connections that the current user has permission to terminate with pg_terminate_backend, described in Section 9.27.2. if connections would remain, this command will fail.


🌈 NOTES 🌈

DROP DATABASE cannot be executed inside a transaction block.

this command cannot be executed while connected to the target database. thus, it might be more convenient to use the program dropdb(1) instead, which is a wrapper around this command. iconic little shortcut behavior πŸ‘‘


⭐ COMPATIBILITY ⭐

there is no DROP DATABASE statement in the SQL standard. so yeah, this one is very much a PostgreSQL main character move πŸ’…


πŸ’– SEE ALSO πŸ’–

CREATE DATABASE (CREATE_DATABASE(7))


and that’s the whole page, bestie 🫢 stay hydrated, back up your stuff, and remember this was PostgreSQL 13.23 docs, dated 2025 β€” mwah πŸ’‹πŸŽ€

πŸ“¦ where this page comes from