{
    "mode": "man",
    "parameter": "CREATE_DATABASE",
    "section": "7",
    "url": "https://www.chedong.com/phpMan.php/man/CREATE_DATABASE/7/json",
    "generated": "2026-11-20T16:37:42Z",
    "synopsis": "CREATE DATABASE name\n[ WITH ] [ OWNER [=] username ]\n[ TEMPLATE [=] template ]\n[ ENCODING [=] encoding ]\n[ STRATEGY [=] strategy ]\n[ LOCALE [=] locale ]\n[ LCCOLLATE [=] lccollate ]\n[ LCCTYPE [=] lcctype ]\n[ ICULOCALE [=] iculocale ]\n[ ICURULES [=] icurules ]\n[ LOCALEPROVIDER [=] localeprovider ]\n[ COLLATIONVERSION = collationversion ]\n[ TABLESPACE [=] tablespacename ]\n[ ALLOWCONNECTIONS [=] allowconn ]\n[ CONNECTION LIMIT [=] connlimit ]\n[ ISTEMPLATE [=] istemplate ]\n[ OID [=] oid ]",
    "sections": {
        "NAME": {
            "content": "CREATEDATABASE - create a new database\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "CREATE DATABASE name\n[ WITH ] [ OWNER [=] username ]\n[ TEMPLATE [=] template ]\n[ ENCODING [=] encoding ]\n[ STRATEGY [=] strategy ]\n[ LOCALE [=] locale ]\n[ LCCOLLATE [=] lccollate ]\n[ LCCTYPE [=] lcctype ]\n[ ICULOCALE [=] iculocale ]\n[ ICURULES [=] icurules ]\n[ LOCALEPROVIDER [=] localeprovider ]\n[ COLLATIONVERSION = collationversion ]\n[ TABLESPACE [=] tablespacename ]\n[ ALLOWCONNECTIONS [=] allowconn ]\n[ CONNECTION LIMIT [=] connlimit ]\n[ ISTEMPLATE [=] istemplate ]\n[ OID [=] oid ]\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "CREATE DATABASE creates a new PostgreSQL database.\n\nTo create a database, you must be a superuser or have the special CREATEDB privilege. See\nCREATE ROLE (CREATEROLE(7)).\n\nBy default, the new database will be created by cloning the standard system database\ntemplate1. A different template can be specified by writing TEMPLATE name. In particular, by\nwriting TEMPLATE template0, you can create a pristine database (one where no user-defined\nobjects exist and where the system objects have not been altered) containing only the\nstandard objects predefined by your version of PostgreSQL. This is useful if you wish to\navoid copying any installation-local objects that might have been added to template1.\n",
            "subsections": []
        },
        "PARAMETERS": {
            "content": "name\nThe name of a database to create.\n\nusername\nThe role name of the user who will own the new database, or DEFAULT to use the default\n(namely, the user executing the command). To create a database owned by another role, you\nmust be able to SET ROLE to that role.\n\ntemplate\nThe name of the template from which to create the new database, or DEFAULT to use the\ndefault template (template1).\n\nencoding\nCharacter set encoding to use in the new database. Specify a string constant (e.g.,\n'SQLASCII'), or an integer encoding number, or DEFAULT to use the default encoding\n(namely, the encoding of the template database). The character sets supported by the\nPostgreSQL server are described in Section 24.3.1. See below for additional restrictions.\n\nstrategy\nStrategy to be used in creating the new database. If the WALLOG strategy is used, the\ndatabase will be copied block by block and each block will be separately written to the\nwrite-ahead log. This is the most efficient strategy in cases where the template database\nis small, and therefore it is the default. The older FILECOPY strategy is also\navailable. This strategy writes a small record to the write-ahead log for each tablespace\nused by the target database. Each such record represents copying an entire directory to a\nnew location at the filesystem level. While this does reduce the write-ahead log volume\nsubstantially, especially if the template database is large, it also forces the system to\nperform a checkpoint both before and after the creation of the new database. In some\nsituations, this may have a noticeable negative impact on overall system performance.\n\nlocale\nSets the default collation order and character classification in the new database.\nCollation affects the sort order applied to strings, e.g., in queries with ORDER BY, as\nwell as the order used in indexes on text columns. Character classification affects the\ncategorization of characters, e.g., lower, upper, and digit. Also sets the associated\naspects of the operating system environment, LCCOLLATE and LCCTYPE. The default is the\nsame setting as the template database. See Section 24.2.2.3.1 and Section 24.2.2.3.2 for\ndetails.\n\nCan be overridden by setting lccollate, lcctype, or iculocale individually.\n\nTip\nThe other locale settings lcmessages, lcmonetary, lcnumeric, and lctime are not\nfixed per database and are not set by this command. If you want to make them the\ndefault for a specific database, you can use ALTER DATABASE ... SET.\n\nlccollate\nSets LCCOLLATE in the database server's operating system environment. The default is the\nsetting of locale if specified, otherwise the same setting as the template database. See\nbelow for additional restrictions.\n\nIf localeprovider is libc, also sets the default collation order to use in the new\ndatabase, overriding the setting locale.\n\nlcctype\nSets LCCTYPE in the database server's operating system environment. The default is the\nsetting of locale if specified, otherwise the same setting as the template database. See\nbelow for additional restrictions.\n\nIf localeprovider is libc, also sets the default character classification to use in the\nnew database, overriding the setting locale.\n\niculocale\nSpecifies the ICU locale (see Section 24.2.2.3.2) for the database default collation\norder and character classification, overriding the setting locale. The locale provider\nmust be ICU. The default is the setting of locale if specified; otherwise the same\nsetting as the template database.\n\nicurules\nSpecifies additional collation rules to customize the behavior of the default collation\nof this database. This is supported for ICU only. See Section 24.2.3.4 for details.\n\nlocaleprovider\nSpecifies the provider to use for the default collation in this database. Possible values\nare icu (if the server was built with ICU support) or libc. By default, the provider is\nthe same as that of the template. See Section 24.1.4 for details.\n\ncollationversion\nSpecifies the collation version string to store with the database. Normally, this should\nbe omitted, which will cause the version to be computed from the actual version of the\ndatabase collation as provided by the operating system. This option is intended to be\nused by pgupgrade for copying the version from an existing installation.\n\nSee also ALTER DATABASE (ALTERDATABASE(7)) for how to handle database collation version\nmismatches.\n\ntablespacename\nThe name of the tablespace that will be associated with the new database, or DEFAULT to\nuse the template database's tablespace. This tablespace will be the default tablespace\nused for objects created in this database. See CREATE TABLESPACE (CREATETABLESPACE(7))\nfor more information.\n\nallowconn\nIf false then no one can connect to this database. The default is true, allowing\nconnections (except as restricted by other mechanisms, such as GRANT/REVOKE CONNECT).\n\nconnlimit\nHow many concurrent connections can be made to this database. -1 (the default) means no\nlimit.\n\nistemplate\nIf true, then this database can be cloned by any user with CREATEDB privileges; if false\n(the default), then only superusers or the owner of the database can clone it.\n\noid\nThe object identifier to be used for the new database. If this parameter is not\nspecified, PostgreSQL will choose a suitable OID automatically. This parameter is\nprimarily intended for internal use by pgupgrade, and only pgupgrade can specify a\nvalue less than 16384.\n\nOptional parameters can be written in any order, not only the order illustrated above.\n",
            "subsections": []
        },
        "NOTES": {
            "content": "CREATE DATABASE cannot be executed inside a transaction block.\n\nErrors along the line of “could not initialize database directory” are most likely related to\ninsufficient permissions on the data directory, a full disk, or other file system problems.\n\nUse DROP DATABASE to remove a database.\n\nThe program createdb(1) is a wrapper program around this command, provided for convenience.\n\nDatabase-level configuration parameters (set via ALTER DATABASE) and database-level\npermissions (set via GRANT) are not copied from the template database.\n\nAlthough it is possible to copy a database other than template1 by specifying its name as the\ntemplate, this is not (yet) intended as a general-purpose “COPY DATABASE” facility. The\nprincipal limitation is that no other sessions can be connected to the template database\nwhile it is being copied.  CREATE DATABASE will fail if any other connection exists when it\nstarts; otherwise, new connections to the template database are locked out until CREATE\nDATABASE completes. See Section 23.3 for more information.\n\nThe character set encoding specified for the new database must be compatible with the chosen\nlocale settings (LCCOLLATE and LCCTYPE). If the locale is C (or equivalently POSIX), then\nall encodings are allowed, but for other locale settings there is only one encoding that will\nwork properly. (On Windows, however, UTF-8 encoding can be used with any locale.)  CREATE\nDATABASE will allow superusers to specify SQLASCII encoding regardless of the locale\nsettings, but this choice is deprecated and may result in misbehavior of character-string\nfunctions if data that is not encoding-compatible with the locale is stored in the database.\n\nThe encoding and locale settings must match those of the template database, except when\ntemplate0 is used as template. This is because other databases might contain data that does\nnot match the specified encoding, or might contain indexes whose sort ordering is affected by\nLCCOLLATE and LCCTYPE. Copying such data would result in a database that is corrupt\naccording to the new settings.  template0, however, is known to not contain any data or\nindexes that would be affected.\n\nThere is currently no option to use a database locale with nondeterministic comparisons (see\nCREATE COLLATION for an explanation). If this is needed, then per-column collations would\nneed to be used.\n\nThe CONNECTION LIMIT option is only enforced approximately; if two new sessions start at\nabout the same time when just one connection “slot” remains for the database, it is possible\nthat both will fail. Also, the limit is not enforced against superusers or background worker\nprocesses.\n",
            "subsections": []
        },
        "EXAMPLES": {
            "content": "To create a new database:\n\nCREATE DATABASE lusiadas;\n\nTo create a database sales owned by user salesapp with a default tablespace of salesspace:\n\nCREATE DATABASE sales OWNER salesapp TABLESPACE salesspace;\n\nTo create a database music with a different locale:\n\nCREATE DATABASE music\nLOCALE 'svSE.utf8'\nTEMPLATE template0;\n\nIn this example, the TEMPLATE template0 clause is required if the specified locale is\ndifferent from the one in template1. (If it is not, then specifying the locale explicitly is\nredundant.)\n\nTo create a database music2 with a different locale and a different character set encoding:\n\nCREATE DATABASE music2\nLOCALE 'svSE.iso885915'\nENCODING LATIN9\nTEMPLATE template0;\n\nThe specified locale and encoding settings must match, or an error will be reported.\n\nNote that locale names are specific to the operating system, so that the above commands might\nnot work in the same way everywhere.\n",
            "subsections": []
        },
        "COMPATIBILITY": {
            "content": "There is no CREATE DATABASE statement in the SQL standard. Databases are equivalent to\ncatalogs, whose creation is implementation-defined.\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "ALTER DATABASE (ALTERDATABASE(7)), DROP DATABASE (DROPDATABASE(7))\n\nPostgreSQL 16.14                                2026                              CREATE DATABASE(7)",
            "subsections": []
        }
    },
    "summary": "CREATEDATABASE - create a new database",
    "flags": [],
    "examples": [
        "To create a new database:",
        "CREATE DATABASE lusiadas;",
        "To create a database sales owned by user salesapp with a default tablespace of salesspace:",
        "CREATE DATABASE sales OWNER salesapp TABLESPACE salesspace;",
        "To create a database music with a different locale:",
        "CREATE DATABASE music",
        "LOCALE 'svSE.utf8'",
        "TEMPLATE template0;",
        "In this example, the TEMPLATE template0 clause is required if the specified locale is",
        "different from the one in template1. (If it is not, then specifying the locale explicitly is",
        "redundant.)",
        "To create a database music2 with a different locale and a different character set encoding:",
        "CREATE DATABASE music2",
        "LOCALE 'svSE.iso885915'",
        "ENCODING LATIN9",
        "TEMPLATE template0;",
        "The specified locale and encoding settings must match, or an error will be reported.",
        "Note that locale names are specific to the operating system, so that the above commands might",
        "not work in the same way everywhere."
    ],
    "see_also": [
        {
            "name": "ALTERDATABASE",
            "section": "7",
            "url": "https://www.chedong.com/phpMan.php/man/ALTERDATABASE/7/json"
        },
        {
            "name": "DROPDATABASE",
            "section": "7",
            "url": "https://www.chedong.com/phpMan.php/man/DROPDATABASE/7/json"
        },
        {
            "name": "DATABASE",
            "section": "7",
            "url": "https://www.chedong.com/phpMan.php/man/DATABASE/7/json"
        }
    ]
}