1CREATE TABLESPACE(7) PostgreSQL 14.3 Documentation CREATE TABLESPACE(7)
2
3
4
6 CREATE_TABLESPACE - define a new tablespace
7
9 CREATE TABLESPACE tablespace_name
10 [ OWNER { new_owner | CURRENT_ROLE | CURRENT_USER | SESSION_USER } ]
11 LOCATION 'directory'
12 [ WITH ( tablespace_option = value [, ... ] ) ]
13
15 CREATE TABLESPACE registers a new cluster-wide tablespace. The
16 tablespace name must be distinct from the name of any existing
17 tablespace in the database cluster.
18
19 A tablespace allows superusers to define an alternative location on the
20 file system where the data files containing database objects (such as
21 tables and indexes) can reside.
22
23 A user with appropriate privileges can pass tablespace_name to CREATE
24 DATABASE, CREATE TABLE, CREATE INDEX or ADD CONSTRAINT to have the data
25 files for these objects stored within the specified tablespace.
26
27 Warning
28 A tablespace cannot be used independently of the cluster in which
29 it is defined; see Section 23.6.
30
32 tablespace_name
33 The name of a tablespace to be created. The name cannot begin with
34 pg_, as such names are reserved for system tablespaces.
35
36 user_name
37 The name of the user who will own the tablespace. If omitted,
38 defaults to the user executing the command. Only superusers can
39 create tablespaces, but they can assign ownership of tablespaces to
40 non-superusers.
41
42 directory
43 The directory that will be used for the tablespace. The directory
44 must exist (CREATE TABLESPACE will not create it), should be empty,
45 and must be owned by the PostgreSQL system user. The directory must
46 be specified by an absolute path name.
47
48 tablespace_option
49 A tablespace parameter to be set or reset. Currently, the only
50 available parameters are seq_page_cost, random_page_cost,
51 effective_io_concurrency and maintenance_io_concurrency. Setting
52 these values for a particular tablespace will override the
53 planner's usual estimate of the cost of reading pages from tables
54 in that tablespace, and the executor's prefetching behavior, as
55 established by the configuration parameters of the same name (see
56 seq_page_cost, random_page_cost, effective_io_concurrency,
57 maintenance_io_concurrency). This may be useful if one tablespace
58 is located on a disk which is faster or slower than the remainder
59 of the I/O subsystem.
60
62 Tablespaces are only supported on systems that support symbolic links.
63
64 CREATE TABLESPACE cannot be executed inside a transaction block.
65
67 To create a tablespace dbspace at file system location /data/dbs, first
68 create the directory using operating system facilities and set the
69 correct ownership:
70
71 mkdir /data/dbs
72 chown postgres:postgres /data/dbs
73
74 Then issue the tablespace creation command inside PostgreSQL:
75
76 CREATE TABLESPACE dbspace LOCATION '/data/dbs';
77
78 To create a tablespace owned by a different database user, use a
79 command like this:
80
81 CREATE TABLESPACE indexspace OWNER genevieve LOCATION '/data/indexes';
82
84 CREATE TABLESPACE is a PostgreSQL extension.
85
87 CREATE DATABASE (CREATE_DATABASE(7)), CREATE TABLE (CREATE_TABLE(7)),
88 CREATE INDEX (CREATE_INDEX(7)), DROP TABLESPACE (DROP_TABLESPACE(7)),
89 ALTER TABLESPACE (ALTER_TABLESPACE(7))
90
91
92
93PostgreSQL 14.3 2022 CREATE TABLESPACE(7)