DROP_DATABASE(7pg15)
π DROP_DATABASE β the manual page, but make it make sense
okay so you're reading the DROP DATABASE page from the PostgreSQL 15.19 docs (that's the section 7 one, bestie) and honestly? it's giving "big red button energy." let's get into it π
β¨ NAME β¨
DROP_DATABASE β remove a database. like, gone gone. π
πΈ SYNOPSIS πΈ
DROP DATABASE [ IF EXISTS ] name [ [ WITH ] ( option [, ...] ) ]
where option can be:
FORCE
that's the whole shape of it, no cap. and yes, FORCE is the only option in that list β she's the main character and the entire cast at the same time π
π¦ DESCRIPTION π¦
okay so DROP DATABASE drops a database. ground-breaking, i know. but fr fr what it actually does is: it removes the catalog entries for the database, and then it deletes the directory containing the data. like it's not just hiding it in the group chat, it's leaving the group chat AND deleting the chat history. π
real talk though, there are rules:
- it can only be executed by the database owner β this is not a shared-account situation, it's not "we all run this together," it's the owner's name on the lease π
- it cannot be executed while you are connected to the target database. so connect to
postgresor any other database to issue this command. you literally cannot yeet the app while you're inside the app, that's not how doors work β¨ - also, if anyone else is connected to the target database, this command will fail β unless you use the
FORCEoption described below. stubborn connections are stubborn π«Ά
β οΈ DROP DATABASE cannot be undone. use it with care! like i know i'm being cute but i mean it, this is not an undo-able story, there's no ctrl+z arc π
π§ PARAMETERS π§
IF EXISTSβ do not throw an error if the database does not exist. a notice is issued in this case instead. so like, it still tells you, but politely. no error, just a little "hey btw it wasn't there" πnameβ the name of the database to remove. the actual target. the one getting dropped πFORCEβ attempt to terminate all existing connections to the target database. but! and this is a big but: it doesn't terminate if prepared transactions, active logical replication slots or subscriptions are present in the target database. those are the immovable objects, bestie, they do not get evicted π
so what does it actually terminate? it 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. so it's not "force means guaranteed," it's "force means i tried my best" π
π NOTES π
DROP DATABASEcannot be executed inside a transaction block. put it outside, it's not a transaction girlie π- this command cannot be executed while connected to the target database. (say it with me: connect to
postgresor any other database first.) because of that tiny inconvenience, it might be more convenient to use the programdropdb(1)instead β which is literally just a wrapper around this command. slay for convenience, honestly β
π₯ COMPATIBILITY π₯
there is no DROP DATABASE statement in the SQL standard. so if someone's like "is this standard SQL," the answer is no, it's our thing, we invented it π
π SEE ALSO π
CREATE DATABASE (CREATE_DATABASE(7)) β the birth, for when you're feeling constructive instead of destructive π¦
okay that's the whole page, every flag and every caveat intact, and honestly you're gonna do great. go forth and drop responsibly πβ¨
sign-off szn: this little beauty is from PostgreSQL 15.19, dated 2026, and it lives at DROP DATABASE(7). mwah π«Άπ
π¦ where this page comes from
- opensuse-leap 16.0: postgresql15 15.19-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql15 15.19-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql15 15.19-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql15 15.19-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