Home Explore Blog CI



postgresql

1st chunk of `doc/src/sgml/ref/create_database.sgml`
3eb55ad33c942add3257656d3ffd95803221b344945902240000000100000fab
<!--
doc/src/sgml/ref/create_database.sgml
PostgreSQL documentation
-->

<refentry id="sql-createdatabase">
 <indexterm zone="sql-createdatabase">
  <primary>CREATE DATABASE</primary>
 </indexterm>

 <refmeta>
  <refentrytitle>CREATE DATABASE</refentrytitle>
  <manvolnum>7</manvolnum>
  <refmiscinfo>SQL - Language Statements</refmiscinfo>
 </refmeta>

 <refnamediv>
  <refname>CREATE DATABASE</refname>
  <refpurpose>create a new database</refpurpose>
 </refnamediv>

 <refsynopsisdiv>
<synopsis>
CREATE DATABASE <replaceable class="parameter">name</replaceable>
    [ WITH ] [ OWNER [=] <replaceable class="parameter">user_name</replaceable> ]
           [ TEMPLATE [=] <replaceable class="parameter">template</replaceable> ]
           [ ENCODING [=] <replaceable class="parameter">encoding</replaceable> ]
           [ STRATEGY [=] <replaceable class="parameter">strategy</replaceable> ]
           [ LOCALE [=] <replaceable class="parameter">locale</replaceable> ]
           [ LC_COLLATE [=] <replaceable class="parameter">lc_collate</replaceable> ]
           [ LC_CTYPE [=] <replaceable class="parameter">lc_ctype</replaceable> ]
           [ BUILTIN_LOCALE [=] <replaceable class="parameter">builtin_locale</replaceable> ]
           [ ICU_LOCALE [=] <replaceable class="parameter">icu_locale</replaceable> ]
           [ ICU_RULES [=] <replaceable class="parameter">icu_rules</replaceable> ]
           [ LOCALE_PROVIDER [=] <replaceable class="parameter">locale_provider</replaceable> ]
           [ COLLATION_VERSION = <replaceable>collation_version</replaceable> ]
           [ TABLESPACE [=] <replaceable class="parameter">tablespace_name</replaceable> ]
           [ ALLOW_CONNECTIONS [=] <replaceable class="parameter">allowconn</replaceable> ]
           [ CONNECTION LIMIT [=] <replaceable class="parameter">connlimit</replaceable> ]
           [ IS_TEMPLATE [=] <replaceable class="parameter">istemplate</replaceable> ]
           [ OID [=] <replaceable class="parameter">oid</replaceable> ]
</synopsis>
 </refsynopsisdiv>

 <refsect1>
  <title>Description</title>

  <para>
   <command>CREATE DATABASE</command> creates a new
   <productname>PostgreSQL</productname> database.
  </para>

  <para>
   To create a database, you must be a superuser or have the special
   <literal>CREATEDB</literal> privilege.
   See <xref linkend="sql-createrole"/>.
  </para>

  <para>
   By default, the new database will be created by cloning the standard
   system database <literal>template1</literal>.  A different template can be
   specified by writing <literal>TEMPLATE
   <replaceable class="parameter">name</replaceable></literal>.  In particular,
   by writing <literal>TEMPLATE template0</literal>, you can create a pristine
   database (one where no user-defined objects exist and where the system
   objects have not been altered)
   containing only the standard objects predefined by your
   version of <productname>PostgreSQL</productname>.  This is useful
   if you wish to avoid copying
   any installation-local objects that might have been added to
   <literal>template1</literal>.
  </para>
 </refsect1>

 <refsect1>
  <title>Parameters</title>

    <variablelist>
     <varlistentry id="create-database-name">
      <term><replaceable class="parameter">name</replaceable></term>
      <listitem>
       <para>
        The name of a database to create.
       </para>
      </listitem>
     </varlistentry>
     <varlistentry id="create-database-user-name">
      <term><replaceable class="parameter">user_name</replaceable></term>
      <listitem>
       <para>
        The role name of the user who will own the new database,
        or <literal>DEFAULT</literal> to use the default (namely, the
        user executing the command).  To create a database owned by another
        role, you must be able to <literal>SET ROLE</literal> to that
        role.
       </para>
      </listitem>
     </varlistentry>
     <varlistentry id="create-database-template">
      <term><replaceable

Title: CREATE DATABASE: Creating a New PostgreSQL Database
Summary
This section of the PostgreSQL documentation describes the CREATE DATABASE command, which creates a new database. It details the required privileges (superuser or CREATEDB privilege), the default template database (template1) used for cloning, and the option to create a pristine database using template0. It also outlines the basic syntax and introduces key parameters like database name and owner.