summaryrefslogtreecommitdiffstats
path: root/doc/src/sgml/html/sql-createtablespace.html
blob: df16fbffeb02ac4c40f0cf80e3afa4c07f787b04 (plain)
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
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>CREATE TABLESPACE</title><link rel="stylesheet" type="text/css" href="stylesheet.css" /><link rev="made" href="pgsql-docs@lists.postgresql.org" /><meta name="generator" content="DocBook XSL Stylesheets Vsnapshot" /><link rel="prev" href="sql-createtableas.html" title="CREATE TABLE AS" /><link rel="next" href="sql-createtsconfig.html" title="CREATE TEXT SEARCH CONFIGURATION" /></head><body id="docContent" class="container-fluid col-10"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">CREATE TABLESPACE</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="sql-createtableas.html" title="CREATE TABLE AS">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="sql-commands.html" title="SQL Commands">Up</a></td><th width="60%" align="center">SQL Commands</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 15.5 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="sql-createtsconfig.html" title="CREATE TEXT SEARCH CONFIGURATION">Next</a></td></tr></table><hr /></div><div class="refentry" id="SQL-CREATETABLESPACE"><div class="titlepage"></div><a id="id-1.9.3.87.1" class="indexterm"></a><div class="refnamediv"><h2><span class="refentrytitle">CREATE TABLESPACE</span></h2><p>CREATE TABLESPACE — define a new tablespace</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
CREATE TABLESPACE <em class="replaceable"><code>tablespace_name</code></em>
    [ OWNER { <em class="replaceable"><code>new_owner</code></em> | CURRENT_ROLE | CURRENT_USER | SESSION_USER } ]
    LOCATION '<em class="replaceable"><code>directory</code></em>'
    [ WITH ( <em class="replaceable"><code>tablespace_option</code></em> = <em class="replaceable"><code>value</code></em> [, ... ] ) ]
</pre></div><div class="refsect1" id="id-1.9.3.87.5"><h2>Description</h2><p>
   <code class="command">CREATE TABLESPACE</code> registers a new cluster-wide
   tablespace.  The tablespace name must be distinct from the name of any
   existing tablespace in the database cluster.
  </p><p>
   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.
  </p><p>
   A user with appropriate privileges can pass
   <em class="replaceable"><code>tablespace_name</code></em> to
   <code class="command">CREATE DATABASE</code>, <code class="command">CREATE TABLE</code>,
   <code class="command">CREATE INDEX</code> or <code class="command">ADD CONSTRAINT</code> to have the data
   files for these objects stored within the specified tablespace.
  </p><div class="warning"><h3 class="title">Warning</h3><p>
    A tablespace cannot be used independently of the cluster in which it
    is defined;  see <a class="xref" href="manage-ag-tablespaces.html" title="23.6. Tablespaces">Section 23.6</a>.
   </p></div></div><div class="refsect1" id="id-1.9.3.87.6"><h2>Parameters</h2><div class="variablelist"><dl class="variablelist"><dt><span class="term"><em class="replaceable"><code>tablespace_name</code></em></span></dt><dd><p>
        The name of a tablespace to be created.  The name cannot
        begin with <code class="literal">pg_</code>, as such names
        are reserved for system tablespaces.
       </p></dd><dt><span class="term"><em class="replaceable"><code>user_name</code></em></span></dt><dd><p>
        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.
       </p></dd><dt><span class="term"><em class="replaceable"><code>directory</code></em></span></dt><dd><p>
        The directory that will be used for the tablespace. The directory
        must exist (<code class="command">CREATE TABLESPACE</code> will not create it),
        should be empty, and must be owned by the
        <span class="productname">PostgreSQL</span> system user.  The directory must be
        specified by an absolute path name.
       </p></dd><dt><span class="term"><em class="replaceable"><code>tablespace_option</code></em></span></dt><dd><p>
        A tablespace parameter to be set or reset.  Currently, the only
        available parameters are <code class="varname">seq_page_cost</code>,
        <code class="varname">random_page_cost</code>, <code class="varname">effective_io_concurrency</code>
        and <code class="varname">maintenance_io_concurrency</code>.
        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 <a class="xref" href="runtime-config-query.html#GUC-SEQ-PAGE-COST">seq_page_cost</a>,
        <a class="xref" href="runtime-config-query.html#GUC-RANDOM-PAGE-COST">random_page_cost</a>,
        <a class="xref" href="runtime-config-resource.html#GUC-EFFECTIVE-IO-CONCURRENCY">effective_io_concurrency</a>,
        <a class="xref" href="runtime-config-resource.html#GUC-MAINTENANCE-IO-CONCURRENCY">maintenance_io_concurrency</a>).  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.
       </p></dd></dl></div></div><div class="refsect1" id="id-1.9.3.87.7"><h2>Notes</h2><p>
   Tablespaces are only supported on systems that support symbolic links.
  </p><p>
    <code class="command">CREATE TABLESPACE</code> cannot be executed inside a transaction
    block.
   </p></div><div class="refsect1" id="id-1.9.3.87.8"><h2>Examples</h2><p>
   To create a tablespace <code class="literal">dbspace</code> at file system location
   <code class="literal">/data/dbs</code>, first create the directory using operating
   system facilities and set the correct ownership:
</p><pre class="programlisting">
mkdir /data/dbs
chown postgres:postgres /data/dbs
</pre><p>
   Then issue the tablespace creation command inside
   <span class="productname">PostgreSQL</span>:
</p><pre class="programlisting">
CREATE TABLESPACE dbspace LOCATION '/data/dbs';
</pre><p>
  </p><p>
   To create a tablespace owned by a different database user, use a command
   like this:
</p><pre class="programlisting">
CREATE TABLESPACE indexspace OWNER genevieve LOCATION '/data/indexes';
</pre></div><div class="refsect1" id="id-1.9.3.87.9"><h2>Compatibility</h2><p>
   <code class="command">CREATE TABLESPACE</code> is a <span class="productname">PostgreSQL</span>
   extension.
  </p></div><div class="refsect1" id="id-1.9.3.87.10"><h2>See Also</h2><span class="simplelist"><a class="xref" href="sql-createdatabase.html" title="CREATE DATABASE"><span class="refentrytitle">CREATE DATABASE</span></a>, <a class="xref" href="sql-createtable.html" title="CREATE TABLE"><span class="refentrytitle">CREATE TABLE</span></a>, <a class="xref" href="sql-createindex.html" title="CREATE INDEX"><span class="refentrytitle">CREATE INDEX</span></a>, <a class="xref" href="sql-droptablespace.html" title="DROP TABLESPACE"><span class="refentrytitle">DROP TABLESPACE</span></a>, <a class="xref" href="sql-altertablespace.html" title="ALTER TABLESPACE"><span class="refentrytitle">ALTER TABLESPACE</span></a></span></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="sql-createtableas.html" title="CREATE TABLE AS">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="sql-commands.html" title="SQL Commands">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="sql-createtsconfig.html" title="CREATE TEXT SEARCH CONFIGURATION">Next</a></td></tr><tr><td width="40%" align="left" valign="top">CREATE TABLE AS </td><td width="20%" align="center"><a accesskey="h" href="index.html" title="PostgreSQL 15.5 Documentation">Home</a></td><td width="40%" align="right" valign="top"> CREATE TEXT SEARCH CONFIGURATION</td></tr></table></div></body></html>