PostgreSQL CREATE TABLESPACE
A tablespace is a location on the storage device where PostgreSQL database stores data file containing database objects such as indexes, and tables.
PostgreSQL uses a tablespace to map a logical name to a physical location on disk.
PostgreSQL comes with two default tablespaces:
- pg_default tablespace ---> stores user data.
- pg_global tablespace ---> stores global data.
Advantages of using tablespaces:
1. if a partition on which the cluster was initialized is out of space, you can create a new tablespace on a different partition and use it until you reconfigure the system.
2. you can use statistics to optimize database performance. For example, you can place the frequent access indexes or tables on devices that perform very fast e.g., solid-state devices, and put the tables containing archive data which is rarely used on slower devices.
Use the CREATE TABLESAPCE statement to create a new tablespace.
OWNER <user_name>
LOCATION <directory_path>;
NOTE:
The name of the tablespace should not begin with pg_, because these names are reserved for the system tablespaces.
By default, the user who executes the CREATE TABLESPACE is the owner of the tablespace.
To assign another user as the owner of the tablespace, you specify it after the OWNER keyword.
The name of the tablespace should not begin with pg_, because these names are reserved for the system tablespaces.
By default, the user who executes the CREATE TABLESPACE is the owner of the tablespace.
To assign another user as the owner of the tablespace, you specify it after the OWNER keyword.
Comments