]> begriffs open source - ai-pg/blob - full-docs/txt/sql-createtablespace.txt
Convert HTML docs to more streamlined TXT
[ai-pg] / full-docs / txt / sql-createtablespace.txt
1
2 CREATE TABLESPACE
3
4    CREATE TABLESPACE — define a new tablespace
5
6 Synopsis
7
8 CREATE TABLESPACE tablespace_name
9     [ OWNER { new_owner | CURRENT_ROLE | CURRENT_USER | SESSION_USER } ]
10     LOCATION 'directory'
11     [ WITH ( tablespace_option = value [, ... ] ) ]
12
13 Description
14
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
29    A tablespace cannot be used independently of the cluster in which it is
30    defined; see Section 22.6.
31
32 Parameters
33
34    tablespace_name
35           The name of a tablespace to be created. The name cannot begin
36           with pg_, as such names are reserved for system tablespaces.
37
38    user_name
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
42           to non-superusers.
43
44    directory
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.
49
50    tablespace_option
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.
62
63 Notes
64
65    CREATE TABLESPACE cannot be executed inside a transaction block.
66
67 Examples
68
69    To create a tablespace dbspace at file system location /data/dbs, first
70    create the directory using operating system facilities and set the
71    correct ownership:
72 mkdir /data/dbs
73 chown postgres:postgres /data/dbs
74
75    Then issue the tablespace creation command inside PostgreSQL:
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 CREATE TABLESPACE indexspace OWNER genevieve LOCATION '/data/indexes';
81
82 Compatibility
83
84    CREATE TABLESPACE is a PostgreSQL extension.
85
86 See Also
87
88    CREATE DATABASE, CREATE TABLE, CREATE INDEX, DROP TABLESPACE, ALTER
89    TABLESPACE