DROP_DATABASE(7pg15)

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

πŸ’… 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 postgres or 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 FORCE option 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 DATABASE cannot 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 postgres or any other database first.) because of that tiny inconvenience, it might be more convenient to use the program dropdb(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