CREATE_TABLESPACE(7pg13)
π CREATE TABLESPACE π
πΈ NAME πΈ
CREATE_TABLESPACE β define a new tablespace. This is the CREATE_TABLESPACE(7pg13) page from the PostgreSQL 13.23 Documentation, and it's literally all about giving your database objects a different filesystem home. π«Ά
β¨ SYNOPSIS β¨
okay so the command shape is exactly this, no cap:
CREATE TABLESPACE tablespace_name
[ OWNER { new_owner | CURRENT_USER | SESSION_USER } ]
LOCATION 'directory'
[ WITH ( tablespace_option = value [, ... ] ) ]
π¦ DESCRIPTION π¦
CREATE TABLESPACE registers a new cluster-wide tablespace. The tablespace name must be distinct from the name of any existing tablespace in the database cluster.
A tablespace allows superusers to define an alternative location on the file system where the data files containing database objects (such as tables and indexes) can reside.
A user with appropriate privileges can pass tablespace_name to CREATE DATABASE, CREATE TABLE, CREATE INDEX or ADD CONSTRAINT to have the data files for these objects stored within the specified tablespace.
β οΈ Warning β A tablespace cannot be used independently of the cluster in which it is defined; see Section 22.6. That's a big deal, bestie. π¨
π PARAMETERS π
tablespace_nameβ the name of a tablespace to be created. The name cannot begin withpg_, as such names are reserved for system tablespaces. periodt.user_nameβ the name of the user who will own the tablespace. If omitted, defaults to the user executing the command. Only superusers can create tablespaces, but they can assign ownership of tablespaces to non-superusers. iconic permission behavior πdirectoryβ the directory that will be used for the tablespace. The directory must exist (CREATE TABLESPACEwill not create it), should be empty, and must be owned by the PostgreSQL system user. The directory must be specified by an absolute path name.tablespace_optionβ a tablespace parameter to be set or reset. Currently, the only available parameters areseq_page_cost,random_page_cost,effective_io_concurrencyandmaintenance_io_concurrency. Setting these values for a particular tablespace will override the planner's usual estimate of the cost of reading pages from tables in that tablespace, and the executor's prefetching behavior, as established by the configuration parameters of the same name (seeseq_page_cost,random_page_cost,effective_io_concurrency,maintenance_io_concurrency). This may be useful if one tablespace is located on a disk which is faster or slower than the remainder of the I/O subsystem. tuning era π₯
π NOTES π
- Tablespaces are only supported on systems that support symbolic links.
CREATE TABLESPACEcannot be executed inside a transaction block.
π EXAMPLES π
To create a tablespace dbspace at file system location /data/dbs, first create the directory using operating system facilities and set the correct ownership:
mkdir /data/dbs
chown postgres:postgres /data/dbs
Then issue the tablespace creation command inside PostgreSQL:
CREATE TABLESPACE dbspace LOCATION '/data/dbs';
To create a tablespace owned by a different database user, use a command like this:
CREATE TABLESPACE indexspace OWNER genevieve LOCATION '/data/indexes';
π COMPATIBILITY π
CREATE TABLESPACE is a PostgreSQL extension. that's it, that's the whole vibe β¨
π SEE ALSO π
CREATE DATABASE(CREATE_DATABASE(7))CREATE TABLE(CREATE_TABLE(7))CREATE INDEX(CREATE_INDEX(7))DROP TABLESPACE(DROP_TABLESPACE(7))ALTER TABLESPACE(ALTER_TABLESPACE(7))
and that's the whole page, bestie π β from PostgreSQL 13.23, dated 2025, on the CREATE TABLESPACE(7) page. slay β¨
π¦ where this page comes from
- opensuse-leap 16.0: postgresql13 13.23-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql13 13.23-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql13 13.23-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql13 13.23-160000.1.1 Β· PostgreSQL
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms