DROP_DATABASE(7pg17)
π DROP_DATABASE π
okay bestie, this is the DROP DATABASE page from the PostgreSQL 17.11 docs, and it's honestly iconic but also kind of scary, so buckle up π
β¨ NAME β¨
DROP_DATABASE β the "remove a database" one. like, gone gone. poof. π
πΈ SYNOPSIS πΈ
DROP DATABASE [ IF EXISTS ] name [ [ WITH ] ( option [, ...] ) ]
where option can be:
FORCE
no cap, that's the whole shape of it. name is the victim, the brackets are all optional-vibes, and the only option in the list is FORCE. periodt. π
π¦ DESCRIPTION π¦
so DROP DATABASE does exactly what it says on the tin: it drops a database. it removes the catalog entries for that database and deletes the directory containing the data. full send, no leftovers. ποΈβ¨
but here's the tea β there are rules, bestie:
- it can only be executed by the database owner. main character only, iykyk. π
- it cannot be executed while you're connected to the target database. like, you can't nuke the room you're standing in. (connect to
postgresor literally 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
FORCEoption described below. π
β οΈ DROP DATABASE cannot be undone. use it with care! this is not a drill, there's no undo button, there's no "jk lol". it's giving irreversible. π
π PARAMETERS π
IF EXISTSβ do not throw an error if the database does not exist. instead, a notice is issued in that case. very "no worries if not" energy. πnameβ the name of the database to remove. yes, you have to say which one. we're not out here dropping databases by vibe alone. πFORCEβ attempt to terminate all existing connections to the target database. π₯
okay but the important fine print: it doesn't terminate if prepared transactions, active logical replication slots, or subscriptions are present in the target database. so those things are basically immune, no matter how hard you FORCE.
this terminates background worker connections, and connections that the current user has permission to terminate with pg_terminate_backend, described in Section 9.28.2. and if connections would remain after all that? the command will fail. π
π§ NOTES π§
DROP DATABASEcannot be executed inside a transaction block. nope. not happening. π«- this command cannot be executed while connected to the target database. so honestly? it might be way more convenient to use the program
dropdb(1)instead β it's literally a wrapper around this command. lowkey the glow-up move. β¨
β COMPATIBILITY β
there is no DROP DATABASE statement in the SQL standard. we're built different, fr fr. π¦
π₯ SEE ALSO π₯
CREATE DATABASE(CREATE_DATABASE(7)) β the opposite vibe, for when you're feeling constructive instead of destructive π±
okay that's the whole page, bestie, you're now fully certified to drop a database (responsibly!!) π
PostgreSQL 17.11 Β· 2026 Β· mwah, thanks for reading, slay π«Άβ¨π
π¦ where this page comes from
- opensuse-leap 16.0: postgresql17 17.11-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql17 17.11-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql17 17.11-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql17 17.11-160000.1.1 Β· PostgreSQL
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms