1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
|
<!--
doc/src/sgml/ref/create_tablespace.sgml
PostgreSQL documentation
-->
<refentry id="sql-createtablespace">
<indexterm zone="sql-createtablespace">
<primary>CREATE TABLESPACE</primary>
</indexterm>
<refmeta>
<refentrytitle>CREATE TABLESPACE</refentrytitle>
<manvolnum>7</manvolnum>
<refmiscinfo>SQL - Language Statements</refmiscinfo>
</refmeta>
<refnamediv>
<refname>CREATE TABLESPACE</refname>
<refpurpose>define a new tablespace</refpurpose>
</refnamediv>
<refsynopsisdiv>
<synopsis>
CREATE TABLESPACE <replaceable class="parameter">tablespace_name</replaceable>
[ OWNER { <replaceable>new_owner</replaceable> | CURRENT_ROLE | CURRENT_USER | SESSION_USER } ]
LOCATION '<replaceable class="parameter">directory</replaceable>'
[ WITH ( <replaceable class="parameter">tablespace_option</replaceable> = <replaceable class="parameter">value</replaceable> [, ... ] ) ]
</synopsis>
</refsynopsisdiv>
<refsect1>
<title>Description</title>
<para>
<command>CREATE TABLESPACE</command> registers a new cluster-wide
tablespace. The tablespace name must be distinct from the name of any
existing tablespace in the database cluster.
</para>
<para>
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.
</para>
<para>
A user with appropriate privileges can pass
<replaceable class="parameter">tablespace_name</replaceable> to
<command>CREATE DATABASE</command>, <command>CREATE TABLE</command>,
<command>CREATE INDEX</command> or <command>ADD CONSTRAINT</command> to have the data
files for these objects stored within the specified tablespace.
</para>
<warning>
<para>
A tablespace cannot be used independently of the cluster in which it
is defined; see <xref linkend="manage-ag-tablespaces"/>.
</para>
</warning>
</refsect1>
<refsect1>
<title>Parameters</title>
<variablelist>
<varlistentry>
<term><replaceable class="parameter">tablespace_name</replaceable></term>
<listitem>
<para>
The name of a tablespace to be created. The name cannot
begin with <literal>pg_</literal>, as such names
are reserved for system tablespaces.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><replaceable class="parameter">user_name</replaceable></term>
<listitem>
<para>
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.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><replaceable class="parameter">directory</replaceable></term>
<listitem>
<para>
The directory that will be used for the tablespace. The directory
must exist (<command>CREATE TABLESPACE</command> will not create it),
should be empty, and must be owned by the
<productname>PostgreSQL</productname> system user. The directory must be
specified by an absolute path name.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><replaceable class="parameter">tablespace_option</replaceable></term>
<listitem>
<para>
A tablespace parameter to be set or reset. Currently, the only
available parameters are <varname>seq_page_cost</varname>,
<varname>random_page_cost</varname>, <varname>effective_io_concurrency</varname>
and <varname>maintenance_io_concurrency</varname>.
Setting these values for a particular tablespace will override the
planner's usual estimate of the cost of reading pages from tables in
that tablespace, and the executor's prefetching behavior, as established
by the configuration parameters of the
same name (see <xref linkend="guc-seq-page-cost"/>,
<xref linkend="guc-random-page-cost"/>,
<xref linkend="guc-effective-io-concurrency"/>,
<xref linkend="guc-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.
</para>
</listitem>
</varlistentry>
</variablelist>
</refsect1>
<refsect1>
<title>Notes</title>
<para>
<command>CREATE TABLESPACE</command> cannot be executed inside a transaction
block.
</para>
</refsect1>
<refsect1>
<title>Examples</title>
<para>
To create a tablespace <literal>dbspace</literal> at file system location
<literal>/data/dbs</literal>, first create the directory using operating
system facilities and set the correct ownership:
<programlisting>
mkdir /data/dbs
chown postgres:postgres /data/dbs
</programlisting>
Then issue the tablespace creation command inside
<productname>PostgreSQL</productname>:
<programlisting>
CREATE TABLESPACE dbspace LOCATION '/data/dbs';
</programlisting>
</para>
<para>
To create a tablespace owned by a different database user, use a command
like this:
<programlisting>
CREATE TABLESPACE indexspace OWNER genevieve LOCATION '/data/indexes';
</programlisting></para>
</refsect1>
<refsect1>
<title>Compatibility</title>
<para>
<command>CREATE TABLESPACE</command> is a <productname>PostgreSQL</productname>
extension.
</para>
</refsect1>
<refsect1>
<title>See Also</title>
<simplelist type="inline">
<member><xref linkend="sql-createdatabase"/></member>
<member><xref linkend="sql-createtable"/></member>
<member><xref linkend="sql-createindex"/></member>
<member><xref linkend="sql-droptablespace"/></member>
<member><xref linkend="sql-altertablespace"/></member>
</simplelist>
</refsect1>
</refentry>
|