{
    "content": [
        {
            "type": "text",
            "text": "# CREATE_DATABASE(7) (man)\n\n**Summary:** CREATEDATABASE - create a new database\n\n**Synopsis:** CREATE DATABASE name\n[ WITH ] [ OWNER [=] username ]\n[ TEMPLATE [=] template ]\n[ ENCODING [=] encoding ]\n[ LOCALE [=] locale ]\n[ LCCOLLATE [=] lccollate ]\n[ LCCTYPE [=] lcctype ]\n[ TABLESPACE [=] tablespacename ]\n[ ALLOWCONNECTIONS [=] allowconn ]\n[ CONNECTION LIMIT [=] connlimit ]\n[ ISTEMPLATE [=] istemplate ]\n\n## Examples\n\n- `To create a new database:`\n- `CREATE DATABASE lusiadas;`\n- `To create a database sales owned by user salesapp with a default tablespace of salesspace:`\n- `CREATE DATABASE sales OWNER salesapp TABLESPACE salesspace;`\n- `To create a database music with a different locale:`\n- `CREATE DATABASE music`\n- `LOCALE 'svSE.utf8'`\n- `TEMPLATE template0;`\n- `In this example, the TEMPLATE template0 clause is required if the specified locale is`\n- `different from the one in template1. (If it is not, then specifying the locale explicitly is`\n- `redundant.)`\n- `To create a database music2 with a different locale and a different character set encoding:`\n- `CREATE DATABASE music2`\n- `LOCALE 'svSE.iso885915'`\n- `ENCODING LATIN9`\n- `TEMPLATE template0;`\n- `The specified locale and encoding settings must match, or an error will be reported.`\n- `Note that locale names are specific to the operating system, so that the above commands might`\n- `not work in the same way everywhere.`\n\n## See Also\n\n- ALTERDATABASE(7)\n- DROPDATABASE(7)\n- DATABASE(7)\n\n## Section Outline\n\n- **NAME** (2 lines)\n- **SYNOPSIS** (12 lines)\n- **DESCRIPTION** (12 lines)\n- **PARAMETERS** (58 lines)\n- **NOTES** (39 lines)\n- **EXAMPLES** (30 lines)\n- **COMPATIBILITY** (3 lines)\n- **SEE ALSO** (5 lines)\n\n## Full Content\n\n### NAME\n\nCREATEDATABASE - create a new database\n\n### SYNOPSIS\n\nCREATE DATABASE name\n[ WITH ] [ OWNER [=] username ]\n[ TEMPLATE [=] template ]\n[ ENCODING [=] encoding ]\n[ LOCALE [=] locale ]\n[ LCCOLLATE [=] lccollate ]\n[ LCCTYPE [=] lcctype ]\n[ TABLESPACE [=] tablespacename ]\n[ ALLOWCONNECTIONS [=] allowconn ]\n[ CONNECTION LIMIT [=] connlimit ]\n[ ISTEMPLATE [=] istemplate ]\n\n### DESCRIPTION\n\nCREATE 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\n### PARAMETERS\n\nname\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 a direct or indirect member of that role, or be a superuser.\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\nlocale\nThis is a shortcut for setting LCCOLLATE and LCCTYPE at once. If you specify this, you\ncannot specify either of those parameters.\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\nCollation order (LCCOLLATE) to use in the new database. This affects the sort order\napplied to strings, e.g., in queries with ORDER BY, as well as the order used in indexes\non text columns. The default is to use the collation order of the template database. See\nbelow for additional restrictions.\n\nlcctype\nCharacter classification (LCCTYPE) to use in the new database. This affects the\ncategorization of characters, e.g., lower, upper and digit. The default is to use the\ncharacter classification of the template database. See below for additional restrictions.\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\nOptional parameters can be written in any order, not only the order illustrated above.\n\n### NOTES\n\nCREATE 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\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\n### EXAMPLES\n\nTo 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\n### COMPATIBILITY\n\nThere is no CREATE DATABASE statement in the SQL standard. Databases are equivalent to\ncatalogs, whose creation is implementation-defined.\n\n### SEE ALSO\n\nALTER DATABASE (ALTERDATABASE(7)), DROP DATABASE (DROPDATABASE(7))\n\n\n\nPostgreSQL 14.23                                2026                              CREATE DATABASE(7)\n\n"
        }
    ],
    "structuredContent": {
        "command": "CREATE_DATABASE",
        "section": "7",
        "mode": "man",
        "summary": "CREATEDATABASE - create a new database",
        "synopsis": "CREATE DATABASE name\n[ WITH ] [ OWNER [=] username ]\n[ TEMPLATE [=] template ]\n[ ENCODING [=] encoding ]\n[ LOCALE [=] locale ]\n[ LCCOLLATE [=] lccollate ]\n[ LCCTYPE [=] lcctype ]\n[ TABLESPACE [=] tablespacename ]\n[ ALLOWCONNECTIONS [=] allowconn ]\n[ CONNECTION LIMIT [=] connlimit ]\n[ ISTEMPLATE [=] istemplate ]",
        "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"
            }
        ],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 12,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 12,
                "subsections": []
            },
            {
                "name": "PARAMETERS",
                "lines": 58,
                "subsections": []
            },
            {
                "name": "NOTES",
                "lines": 39,
                "subsections": []
            },
            {
                "name": "EXAMPLES",
                "lines": 30,
                "subsections": []
            },
            {
                "name": "COMPATIBILITY",
                "lines": 3,
                "subsections": []
            },
            {
                "name": "SEE ALSO",
                "lines": 5,
                "subsections": []
            }
        ]
    }
}