1CREATE TABLESPACE(7)     PostgreSQL 12.2 Documentation    CREATE TABLESPACE(7)
2
3
4

NAME

6       CREATE_TABLESPACE - define a new tablespace
7

SYNOPSIS

9       CREATE TABLESPACE tablespace_name
10           [ OWNER { new_owner | CURRENT_USER | SESSION_USER } ]
11           LOCATION 'directory'
12           [ WITH ( tablespace_option = value [, ... ] ) ]
13

DESCRIPTION

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 22.6.
30

PARAMETERS

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 and
51           effective_io_concurrency. Setting either value for a particular
52           tablespace will override the planner's usual estimate of the cost
53           of reading pages from tables in that tablespace, as established by
54           the configuration parameters of the same name (see seq_page_cost,
55           random_page_cost, effective_io_concurrency). This may be useful if
56           one tablespace is located on a disk which is faster or slower than
57           the remainder of the I/O subsystem.
58

NOTES

60       Tablespaces are only supported on systems that support symbolic links.
61
62       CREATE TABLESPACE cannot be executed inside a transaction block.
63

EXAMPLES

65       To create a tablespace dbspace at file system location /data/dbs, first
66       create the directory using operating system facilities and set the
67       correct ownership:
68
69           mkdir /data/dbs
70           chown postgres:postgres /data/dbs
71
72       Then issue the tablespace creation command inside PostgreSQL:
73
74           CREATE TABLESPACE dbspace LOCATION '/data/dbs';
75
76       To create a tablespace owned by a different database user, use a
77       command like this:
78
79           CREATE TABLESPACE indexspace OWNER genevieve LOCATION '/data/indexes';
80

COMPATIBILITY

82       CREATE TABLESPACE is a PostgreSQL extension.
83

SEE ALSO

85       CREATE DATABASE (CREATE_DATABASE(7)), CREATE TABLE (CREATE_TABLE(7)),
86       CREATE INDEX (CREATE_INDEX(7)), DROP TABLESPACE (DROP_TABLESPACE(7)),
87       ALTER TABLESPACE (ALTER_TABLESPACE(7))
88
89
90
91PostgreSQL 12.2                      2020                 CREATE TABLESPACE(7)
Impressum