Updated on 2025-05-29 GMT+08:00

DROP TABLESPACE

Description

Deletes a tablespace.

Precautions

  • Only the tablespace owner or a user granted the DROP permission can run the DROP TABLESPACE command. The system administrator has this permission by default.
  • The tablespace to be deleted should not contain any database objects. Otherwise, an error will be reported.
  • DROP TABLESPACE cannot be rolled back and therefore cannot be run in transaction blocks.
  • During execution of DROP TABLESPACE, database queries by other sessions using \db may fail and need to be reattempted.
  • If DROP TABLESPACE fails to be executed, execute DROP TABLESPACE IF EXISTS.

Syntax

DROP TABLESPACE [ IF EXISTS ] tablespace_name;

Parameters

  • IF EXISTS

    Reports a notice instead of an error if the specified tablespace does not exist.

  • tablespace_name

    Specifies the name of the tablespace to be deleted.

    Value range: an existing tablespace name

Examples

1
2
3
4
5
-- Create a tablespace.
gaussdb=# CREATE TABLESPACE tbs_location1 RELATIVE LOCATION 'test_tablespace/test_tablespace_1';

-- Delete the tablespace.
gaussdb=# DROP TABLESPACE tbs_location1;

Suggestions

Do not delete tablespaces during transactions using DROP TABLESPACE.