Home Explore Blog CI



postgresql

7th chunk of `doc/src/sgml/ref/create_database.sgml`
7807ae7e4a9d40817ad0c5a115c4b1783bbd052cafcf40fb000000010000087c
 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 of the locale settings,
   but this choice is deprecated and may result in misbehavior of
   character-string functions if data that is not encoding-compatible
   with the locale is stored in the database.
  </para>

  <para>
   The encoding and locale settings must match those of the template database,
   except when <literal>template0</literal> is used as template.  This is because
   other databases might contain data that does not match the specified
   encoding, or might contain indexes whose sort ordering is affected by
   <literal>LC_COLLATE</literal> and <literal>LC_CTYPE</literal>.  Copying such data would
   result in a database that is corrupt according to the new settings.
   <literal>template0</literal>, however, is known to not contain any data or
   indexes that would be affected.
  </para>

  <para>
   There is currently no option to use a database locale with nondeterministic
   comparisons (see <link linkend="sql-createcollation"><command>CREATE
   COLLATION</command></link> for an explanation).  If this is needed, then
   per-column collations would need to be used.
  </para>

  <para>
   The <literal>CONNECTION LIMIT</literal>

Title: CREATE DATABASE: Template Database Restrictions and Encoding/Locale Compatibility
Summary
This section discusses restrictions when using databases other than `template1` as templates, specifically the requirement for exclusive access. It highlights the importance of character set encoding compatibility with locale settings (`LC_COLLATE` and `LC_CTYPE`), except when using the `C` or `POSIX` locale (UTF-8 on Windows is an exception). It also explains that encoding and locale settings must match the template database, except when using `template0`. Nondeterministic comparisons and connection limits are briefly mentioned.