PostgreSQL Tablesapces

PostgreSQL Tablespaces allows database administrators to define locations in the file system where the files representing database objects(tables,functions, procedures,,,etc) can be stored. Once created, a tablespace can be referred to by name when creating database objects.

Syntax:
CREATE TABLESPACE tablespace_name LOCATION ‘location of tablespace’;

Examples:
Create Tablespace on Windows:

CREATE TABLESPACE k2schools1 LOCATION ‘C:\PostgreSQL’;

Create Tablespace on Unix:

CREATE TABLESPACE k2schools1 LOCATION ‘/opt/PostgreSQL’;

To change default tabelspace:

SET default_tablespace = K2SCHOOLS1;

To get all tablespaces:

SELECT spcname FROM pg_tablespace;

Powered by k2schools