Logo ← PostgreSQL Blog

1- ALTER TABLE student SET TABLESPACE pg_default;

This command moves only the student table to the pg_default tablespace.

1- ALTER TABLE student SET TABLESPACE pg_default;

This command moves only the student table to the pg_default tablespace.

However, it does not move any indexes associated with the table. Indexes must be moved separately using:

ALTER INDEX your_index_name SET TABLESPACE target_tablespace;

2- ALTER TABLE ALL IN TABLESPACE space2 SET TABLESPACE pg_default;

This command also moves only tables from the space2 tablespace to pg_default.

It does not move indexes, sequences, or materialized views. TOAST tables are automatically moved because they are internally linked to their main tables. However, if you want to move other objects like materialized views, you must specify them explicitly.

3- ALTER DATABASE bim_db SET TABLESPACE pg_default;

This command sets the default tablespace for future objects created in the bim_db database.

It does not move any existing objects. All current tables, indexes, and other database objects will remain in their original tablespaces.

Note: In PostgreSQL, it is not possible to move all related objects of a table (such as indexes or sequences) with a single command latest version for now. Each object type must be moved separately using the appropriate ALTER statement.