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 ๐
CREATE TABLESPACE(CREATE_TABLESPACE(7))ALTER TABLESPACE(ALTER_TABLESPACE(7))
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 ๐โจ๐ธ
๐ฆ where this page comes from
- alpine 3.23: postgresql18-doc 18.6-r0 ยท PostgreSQL
- alpine 3.24: postgresql18-doc 18.6-r0 ยท PostgreSQL
- arch rolling: postgresql 18.6-4 ยท PostgreSQL
- fedora 43: postgresql 18.6-1.fc43 ยท PostgreSQL
- fedora 43: postgresql 18.6-1.fc43 ยท PostgreSQL
- fedora 44: postgresql 18.6-1.fc44 ยท PostgreSQL
- fedora 44: postgresql 18.6-1.fc44 ยท PostgreSQL
- nixos 26.05: postgresql 18.6
- ubuntu resolute: postgresql-client-18 18.6-0ubuntu0.26.04.1 ยท PostgreSQL
- ubuntu stonking: postgresql-client-18 18.6-3build2 ยท PostgreSQL
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms