An SQL command for removing a tablespace

DROP TABLESPACE is a DDL command for removing a tablespace.

DROP TABLESPACE was added in PostgreSQL 8.0.


DROP TABLESPACE can only be executed if the tablespace contains no objects from any database. For this reason, there is no DROP TABLESPACE ... CASCADE option, as it is not possible for commands in one database to selectively manipulate objects in another database.

The system function pg_tablespace_databases() can be used verify if a tablespace contains any objects, and if so which databases they belong to. See that function's examples section for a sample query.

Change history


Dropping an empty tablespace:

postgres=# DROP TABLESPACE tblspace_2;

Attempting to drop a tablespace which still contains objects:

postgres=# DROP TABLESPACE tblspace_1;
ERROR:  tablespace "tblspace_1" is not empty

Attempting to drop a non-existent tablespace:

postgres=# DROP TABLESPACE foo;
ERROR:  tablespace "foo" does not exist


DDL, SQL command, Tablespaces

See also

CREATE TABLESPACE, ALTER TABLESPACE, tablespace, pg_tablespace_databases()