Home Explore Blog CI



postgresql

1st chunk of `doc/src/sgml/ref/create_tablespace.sgml`
4d44eab3d9782b5f1c0ba73c7f690fba9bbda62cef2e32c60000000100000b9b
<!--
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.

Title: CREATE TABLESPACE: Defining a New Tablespace in PostgreSQL
Summary
The CREATE TABLESPACE command registers a new cluster-wide tablespace, allowing superusers to specify an alternative file system location for database object data files (tables, indexes, etc.). Users with appropriate privileges can then use this tablespace when creating databases, tables, indexes, or adding constraints. The tablespace name must be unique within the cluster.