DROP_DATABASE(7pg18)
๐ DROP_DATABASE ๐
okay bestie, we're doing PostgreSQL 18.6 documentation today and this one is the scary one. it's DROP DATABASE, a manual page from the DROP_DATABASE(7) section. she's powerful, she's permanent, and she does not do takebacks. let's get into it ๐ซถ
โจ NAME โจ
DROP_DATABASE โ remove a database ๐
๐ธ SYNOPSIS ๐ธ
DROP DATABASE [ IF EXISTS ] name [ [ WITH ] ( option [, ...] ) ]
where option can be:
FORCE
๐ DESCRIPTION ๐
okay so DROP DATABASE drops a database. literally just. yeets it. it removes the catalog entries for the database and deletes the directory containing the data. it's giving "gone, no trace, nothing left" ๐
the way that this can only be executed by the database owner though. like, owner energy only, nobody else gets to touch this.
and it cannot be executed while you are connected to the target database. so if you're sitting inside the database you're trying to delete, that's a no. (connect to postgres or any other database to issue this command, bestie.) also, if anyone else is connected to the target database, this command will fail unless you use the FORCE option described below. so rude of them to be connected honestly ๐ญ
DROP DATABASE cannot be undone. Use it with care! this is not a "whoops undo" situation, this is a "it's over" situation. periodt.
๐ฆ PARAMETERS ๐ฆ
IF EXISTSโ do not throw an error if the database does not exist. a notice is issued in this case. so like, if she's already gone, she's already gone, no drama ๐nameโ the name of the database to remove. that's the one. that's the victim. ๐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. so like, those specific things are safe from the force, bestie, no cap.
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. if connections would remain, this command will fail. so it's force but it's like, polite force. permission-based force. iykyk ๐
โญ NOTES โญ
DROP DATABASE cannot be executed inside a transaction block. nope. not happening. no wrapping her in a transaction, she refuses ๐ซ
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. so like, if you're feeling lazy (valid), dropdb(1) is right there for you ๐ซถ
๐ COMPATIBILITY ๐
there is no DROP DATABASE statement in the SQL standard. she's built different. she's original. she's not following anyone's rules ๐ฅ
๐ SEE ALSO ๐
CREATE DATABASE(CREATE_DATABASE(7)) โ the opposite of this one, the birth to her destruction, the main character to her villain arc โจ
and that's the whole page bestie, every flag, every warning, every "this will fail" moment preserved with love ๐
this has been PostgreSQL 18.6 documentation, dated 2026, page DROP DATABASE(7) โ so if you're reading this, you're on that version, and you should probably double-check which database you're connected to before typing anything ๐
stay safe out there, don't drop anything you love ๐๐ฆ๐
๐ฆ where this page comes from
- opensuse-leap 16.0: postgresql18 18.6-160000.1.1 ยท PostgreSQL
- opensuse-leap 16.0: postgresql18 18.6-160000.1.1 ยท PostgreSQL
- opensuse-leap 16.0: postgresql18 18.6-160000.1.1 ยท PostgreSQL
- opensuse-leap 16.0: postgresql18 18.6-160000.1.1 ยท PostgreSQL
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms