CREATE_TABLESPACE(7pg15)

πŸ“¦ version 15.19, in opensuse-leap 16.0

πŸ‘‘ CREATE TABLESPACE πŸ‘‘

okay bestie, welcome to the PostgreSQL 15.19 Documentation page for CREATE TABLESPACE(7) β€” the manual entry for CREATE_TABLESPACE, no cap. It’s giving β€œdefine a new tablespace,” and we’re gonna walk through every single detail together. πŸ’–


🌸 NAME 🌸

CREATE_TABLESPACE β€” define a new tablespace. periodt. πŸ’…


✨ SYNOPSIS ✨

CREATE TABLESPACE tablespace_name
    [ OWNER { new_owner | CURRENT_ROLE | 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. So like, no duplicate names in the cluster, bestie β€” that’s the vibe check. πŸ’–

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. Lowkey iconic: your data gets its own spot on disk. ✨

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. That’s the whole point, and it ate. πŸ‘‘

⚠️ Warning: A tablespace cannot be used independently of the cluster in which it is defined; see Section 23.6. It’s tied to its cluster, periodt β€” no main-character solo arc for a tablespace. πŸ’€

πŸŽ€ PARAMETERS πŸŽ€

  • tablespace_name β€” the name of a tablespace to be created. The name cannot begin with pg_, as such names are reserved for system tablespaces. 🚫
  • 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. 🫢
  • directory β€” the directory that will be used for the tablespace. The directory must exist (CREATE TABLESPACE will 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 are seq_page_cost, random_page_cost, effective_io_concurrency and maintenance_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 (see seq_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. πŸ”₯

🌈 NOTES 🌈

  • Tablespaces are only supported on systems that support symbolic links. πŸͺ„
  • CREATE TABLESPACE cannot be executed inside a transaction block. Ngl, that’s just the rule. 🚫

πŸ“ 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. slay, it’s a PostgreSQL original. πŸ’œ


⭐ SEE ALSO ⭐


okay that’s the whole page, bestie β€” this iconic little manual comes from PostgreSQL 15.19 and is dated 2026. mwah πŸ’‹βœ¨

πŸ“¦ where this page comes from