Home Explore Blog CI



postgresql

6th chunk of `doc/src/sgml/ref/create_database.sgml`
88e7475b90d5028af6e626cf61b36e53a9d456cb6324f8810000000100000d0d
 <term><replaceable class="parameter">istemplate</replaceable></term>
       <listitem>
        <para>
         If true, then this database can be cloned by any user with <literal>CREATEDB</literal>
         privileges; if false (the default), then only superusers or the owner
         of the database can clone it.
        </para>
       </listitem>
      </varlistentry>

      <varlistentry id="create-database-oid">
       <term><replaceable class="parameter">oid</replaceable></term>
       <listitem>
        <para>
         The object identifier to be used for the new database. If this
         parameter is not specified, <productname>PostgreSQL</productname>
         will choose a suitable OID automatically. This parameter is primarily
         intended for internal use by <application>pg_upgrade</application>,
         and only <application>pg_upgrade</application> can specify a value
         less than 16384.
        </para>
       </listitem>
      </varlistentry>

    </variablelist>

  <para>
   Optional parameters can be written in any order, not only the order
   illustrated above.
  </para>
 </refsect1>

 <refsect1>
  <title>Notes</title>

   <para>
    <command>CREATE DATABASE</command> cannot be executed inside a transaction
    block.
   </para>

   <para>
    Errors along the line of <quote>could not initialize database directory</quote>
    are most likely related to insufficient permissions on the data
    directory, a full disk, or other file system problems.
   </para>

   <para>
    Use <link linkend="sql-dropdatabase"><command>DROP DATABASE</command></link> to remove a database.
   </para>

   <para>
    The program <xref linkend="app-createdb"/> is a
    wrapper program around this command, provided for convenience.
   </para>

   <para>
    Database-level configuration parameters (set via <link
    linkend="sql-alterdatabase"><command>ALTER DATABASE</command></link>) and database-level permissions (set via
    <link linkend="sql-grant"><command>GRANT</command></link>) are not copied from the template database.
   </para>

  <para>
   Although it is possible to copy a database other than <literal>template1</literal>
   by specifying its name as the template, this is not (yet) intended as
   a general-purpose <quote><command>COPY DATABASE</command></quote> facility.
   The principal limitation is that no other sessions can be connected to
   the template database while it is being copied.  <command>CREATE
   DATABASE</command> will fail if any other connection exists when it starts;
   otherwise, new connections to the template database are locked out
   until <command>CREATE DATABASE</command> completes.
   See <xref linkend="manage-ag-templatedbs"/> for more information.
  </para>

  <para>
   The character set encoding specified for the new database must be
   compatible with the chosen locale settings (<literal>LC_COLLATE</literal> and
   <literal>LC_CTYPE</literal>).  If the locale is <literal>C</literal> (or equivalently
   <literal>POSIX</literal>), then all encodings are allowed, but for other
   locale settings there is only one encoding that will work properly.
   (On Windows, however, UTF-8 encoding can be used with any locale.)
   <command>CREATE DATABASE</command> will allow superusers to specify
   <literal>SQL_ASCII</literal> encoding regardless

Title: CREATE DATABASE: Istemplate, OID Parameters, Notes, and Considerations
Summary
This section details the `istemplate` and `oid` parameters for the `CREATE DATABASE` command. `istemplate` controls who can clone the database, while `oid` allows specifying the object identifier for the new database, mainly for `pg_upgrade`'s use. Notes on transaction block restrictions, potential errors, removing databases, and the createdb wrapper program are provided. It also covers database-level configuration, permissions, limitations when copying databases other than `template1`, and the requirement for compatible character set encoding with locale settings.