Skip to content
Related Articles

Related Articles

Improve Article
PostgreSQL – ALTER TABLESPACE
  • Last Updated : 08 Feb, 2021

In PostgreSQL, the ALTER TABLESPACE statement is used to rename, change the owner, or set parameters for a tablespace.

Syntax:
ALTER TABLESPACE tablespace_name
action;

To rename the tablespace, the ALTER TABLESPACE RENAME TO statement can be used as shown below:

Syntax: 
ALTER TABLESPACE tablespace_name 
RENAME TO new_name;

To change the owner of the tablespace, one can use the ALTER TABLESPACE OWNER TO statement:

Syntax:
ALTER TABLESPACE tablespace_name 
OWNER TO new_owner;

The following statement changes the parameters for a tablespace:

Syntax:
ALTER TABLESPACE tablespace_name 
SET parameter_name = value;

Note: Only superusers or tablespace owners can execute the ALTER TABLESPACE statement.



Example 1:

The following statement renames the tablespace ts_primary to ts_secondary:

ALTER TABLESPACE ts_primary
RENAME TO ts_secondary;

verify it using the below command:

\db+

Output:

Example 2:

The following statement changes the owner of the ts_secondary from Postgres to ‘raju’:

ALTER TABLESPACE ts_secondary 
OWNER to raju;

Verify the above using the below command:

\db+

Output:

My Personal Notes arrow_drop_up
Recommended Articles
Page :