DROP_DATABASE(7pg18)

๐Ÿ“ฆ version 18.6, in opensuse-leap 16.0

๐Ÿ’– 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