DROP_TABLESPACE(7)

๐Ÿ’ซ DROP TABLESPACE โ€” remove a tablespace

okay bestie so you wanna know about DROP TABLESPACE?? this is from the PostgreSQL 18.6 Documentation, section 7 of the manual, and it's literally the "bye bye tablespace" command. let's get into it ๐Ÿ’–


โœจ NAME โœจ

DROP_TABLESPACE โ€” remove a tablespace ๐Ÿ—‘๏ธโœจ


๐ŸŒธ SYNOPSIS ๐ŸŒธ

DROP TABLESPACE [ IF EXISTS ] name

๐Ÿฆ‹ DESCRIPTION ๐Ÿฆ‹

DROP TABLESPACE removes a tablespace from the system. that's the whole vibe. it's gone. slay. ๐Ÿ’…

okay but here's the tea though โ€” a tablespace can only be dropped by its owner or a superuser. nobody else gets to do it. periodt.

also?? the tablespace must be empty of all database objects before it can be dropped. like, fully empty. no objects. none. ๐Ÿซถ

and here's the sneaky part โ€” it is possible that objects in other databases might still reside in the tablespace even if no objects in the current database are using the tablespace. so like, you could be looking at your database going "it's empty!!" and it's actually not, because another database is squatting there. plot twist ๐Ÿ˜ญ

AND one more thing: if the tablespace is listed in the temp_tablespaces setting of any active session, the DROP might fail due to temporary files residing in the tablespace. so basically, active sessions with temp files in there can block you. lowkey rude but that's just how it is.


๐ŸŽ€ PARAMETERS ๐ŸŽ€

  • IF EXISTS โ€” do not throw an error if the tablespace does not exist. a notice is issued in this case instead. it's giving "no drama, just a lil heads up" ๐Ÿ’œ
  • name โ€” the name of a tablespace. yep. that's the one. the name. ๐Ÿท๏ธ

๐Ÿ’€ NOTES ๐Ÿ’€

DROP TABLESPACE cannot be executed inside a transaction block. like, it just can't. don't try it. the server will simply say no. ๐Ÿšซ

๐ŸŒˆ EXAMPLES ๐ŸŒˆ

to remove tablespace mystuff from the system:

DROP TABLESPACE mystuff;

and boom, mystuff is no more. gone. iconic exit. ๐Ÿ‘‘


โญ COMPATIBILITY โญ

DROP TABLESPACE is a PostgreSQL extension. so if you're out here expecting other databases to have it, nope, this is our thing. ๐Ÿ’…


๐Ÿ‘‘ SEE ALSO ๐Ÿ‘‘


okay bestie that's the whole page fr fr ๐Ÿซถ go forth and drop responsibly, and remember: empty it first. this was the DROP TABLESPACE(7) page from PostgreSQL 18.6, dated 2026. mwah ๐Ÿ’‹โœจ๐ŸŒธ