4 CREATE TABLESPACE — define a new tablespace
8 CREATE TABLESPACE tablespace_name
9 [ OWNER { new_owner | CURRENT_ROLE | CURRENT_USER | SESSION_USER } ]
11 [ WITH ( tablespace_option = value [, ... ] ) ]
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.
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.
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.
29 A tablespace cannot be used independently of the cluster in which it is
30 defined; see Section 22.6.
35 The name of a tablespace to be created. The name cannot begin
36 with pg_, as such names are reserved for system tablespaces.
39 The name of the user who will own the tablespace. If omitted,
40 defaults to the user executing the command. Only superusers can
41 create tablespaces, but they can assign ownership of tablespaces
45 The directory that will be used for the tablespace. The
46 directory must exist (CREATE TABLESPACE will not create it),
47 should be empty, and must be owned by the PostgreSQL system
48 user. The directory must be specified by an absolute path name.
51 A tablespace parameter to be set or reset. Currently, the only
52 available parameters are seq_page_cost, random_page_cost,
53 effective_io_concurrency and maintenance_io_concurrency. Setting
54 these values for a particular tablespace will override the
55 planner's usual estimate of the cost of reading pages from
56 tables in that tablespace, and how many concurrent I/Os are
57 issued, as established by the configuration parameters of the
58 same name (see seq_page_cost, random_page_cost,
59 effective_io_concurrency, maintenance_io_concurrency). This may
60 be useful if one tablespace is located on a disk which is faster
61 or slower than the remainder of the I/O subsystem.
65 CREATE TABLESPACE cannot be executed inside a transaction block.
69 To create a tablespace dbspace at file system location /data/dbs, first
70 create the directory using operating system facilities and set the
73 chown postgres:postgres /data/dbs
75 Then issue the tablespace creation command inside PostgreSQL:
76 CREATE TABLESPACE dbspace LOCATION '/data/dbs';
78 To create a tablespace owned by a different database user, use a
80 CREATE TABLESPACE indexspace OWNER genevieve LOCATION '/data/indexes';
84 CREATE TABLESPACE is a PostgreSQL extension.
88 CREATE DATABASE, CREATE TABLE, CREATE INDEX, DROP TABLESPACE, ALTER