2 .\" Title: CREATE TABLESPACE
3 .\" Author: The PostgreSQL Global Development Group
4 .\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
6 .\" Manual: PostgreSQL 18.0 Documentation
7 .\" Source: PostgreSQL 18.0
10 .TH "CREATE TABLESPACE" "7" "2025" "PostgreSQL 18.0" "PostgreSQL 18.0 Documentation"
11 .\" -----------------------------------------------------------------
12 .\" * Define some portability stuff
13 .\" -----------------------------------------------------------------
14 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15 .\" http://bugs.debian.org/507673
16 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
17 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
20 .\" -----------------------------------------------------------------
21 .\" * set default formatting
22 .\" -----------------------------------------------------------------
23 .\" disable hyphenation
25 .\" disable justification (adjust text to left margin only)
27 .\" -----------------------------------------------------------------
28 .\" * MAIN CONTENT STARTS HERE *
29 .\" -----------------------------------------------------------------
31 CREATE_TABLESPACE \- define a new tablespace
35 CREATE TABLESPACE \fItablespace_name\fR
36 [ OWNER { \fInew_owner\fR | CURRENT_ROLE | CURRENT_USER | SESSION_USER } ]
37 LOCATION \*(Aq\fIdirectory\fR\*(Aq
38 [ WITH ( \fItablespace_option\fR = \fIvalue\fR [, \&.\&.\&. ] ) ]
42 \fBCREATE TABLESPACE\fR
43 registers a new cluster\-wide tablespace\&. The tablespace name must be distinct from the name of any existing tablespace in the database cluster\&.
45 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\&.
47 A user with appropriate privileges can pass
50 \fBCREATE DATABASE\fR,
55 to have the data files for these objects stored within the specified tablespace\&.
61 .nr an-no-space-flag 1
69 A tablespace cannot be used independently of the cluster in which it is defined; see
77 The name of a tablespace to be created\&. The name cannot begin with
78 pg_, as such names are reserved for system tablespaces\&.
83 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\&.
88 The directory that will be used for the tablespace\&. The directory must exist (\fBCREATE TABLESPACE\fR
89 will not create it), should be empty, and must be owned by the
91 system user\&. The directory must be specified by an absolute path name\&.
94 \fItablespace_option\fR
96 A tablespace parameter to be set or reset\&. Currently, the only available parameters are
98 \fIrandom_page_cost\fR,
99 \fIeffective_io_concurrency\fR
101 \fImaintenance_io_concurrency\fR\&. Setting these values for a particular tablespace will override the planner\*(Aqs usual estimate of the cost of reading pages from tables in that tablespace, and how many concurrent I/Os are issued, as established by the configuration parameters of the same name (see
104 effective_io_concurrency,
105 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\&.
109 \fBCREATE TABLESPACE\fR
110 cannot be executed inside a transaction block\&.
113 To create a tablespace
115 at file system location
116 /data/dbs, first create the directory using operating system facilities and set the correct ownership:
123 chown postgres:postgres /data/dbs
129 Then issue the tablespace creation command inside
136 CREATE TABLESPACE dbspace LOCATION \*(Aq/data/dbs\*(Aq;
142 To create a tablespace owned by a different database user, use a command like this:
148 CREATE TABLESPACE indexspace OWNER genevieve LOCATION \*(Aq/data/indexes\*(Aq;
155 \fBCREATE TABLESPACE\fR
160 CREATE DATABASE (\fBCREATE_DATABASE\fR(7)), CREATE TABLE (\fBCREATE_TABLE\fR(7)), CREATE INDEX (\fBCREATE_INDEX\fR(7)), DROP TABLESPACE (\fBDROP_TABLESPACE\fR(7)), ALTER TABLESPACE (\fBALTER_TABLESPACE\fR(7))