{
    "mode": "man",
    "parameter": "createdb",
    "section": "1",
    "url": "https://www.chedong.com/phpMan.php/man/createdb/1/json",
    "generated": "2026-06-17T13:15:59Z",
    "synopsis": "createdb [connection-option...] [option...] [dbname [description]]",
    "sections": {
        "NAME": {
            "content": "createdb - create a new PostgreSQL database\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "createdb [connection-option...] [option...] [dbname [description]]\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "createdb creates a new PostgreSQL database.\n\nNormally, the database user who executes this command becomes the owner of the new database.\nHowever, a different owner can be specified via the -O option, if the executing user has\nappropriate privileges.\n\ncreatedb is a wrapper around the SQL command CREATE DATABASE. There is no effective\ndifference between creating databases via this utility and via other methods for accessing\nthe server.\n",
            "subsections": []
        },
        "OPTIONS": {
            "content": "createdb accepts the following command-line arguments:\n\ndbname\nSpecifies the name of the database to be created. The name must be unique among all\nPostgreSQL databases in this cluster. The default is to create a database with the same\nname as the current system user.\n\ndescription\nSpecifies a comment to be associated with the newly created database.\n",
            "subsections": [
                {
                    "name": "-D",
                    "content": "--tablespace=tablespace\nSpecifies the default tablespace for the database. (This name is processed as a\ndouble-quoted identifier.)\n",
                    "flag": "-D"
                },
                {
                    "name": "-e",
                    "content": "",
                    "flag": "-e"
                },
                {
                    "name": "--echo",
                    "content": "Echo the commands that createdb generates and sends to the server.\n",
                    "long": "--echo"
                },
                {
                    "name": "-E",
                    "content": "--encoding=encoding\nSpecifies the character encoding scheme to be used in this database. The character sets\nsupported by the PostgreSQL server are described in Section 24.3.1.\n",
                    "flag": "-E"
                },
                {
                    "name": "-l",
                    "content": "--locale=locale\nSpecifies the locale to be used in this database. This is equivalent to specifying both\n--lc-collate and --lc-ctype.\n\n--lc-collate=locale\nSpecifies the LCCOLLATE setting to be used in this database.\n\n--lc-ctype=locale\nSpecifies the LCCTYPE setting to be used in this database.\n",
                    "flag": "-l"
                },
                {
                    "name": "-O",
                    "content": "--owner=owner\nSpecifies the database user who will own the new database. (This name is processed as a\ndouble-quoted identifier.)\n",
                    "flag": "-O"
                },
                {
                    "name": "-T",
                    "content": "--template=template\nSpecifies the template database from which to build this database. (This name is\nprocessed as a double-quoted identifier.)\n",
                    "flag": "-T"
                },
                {
                    "name": "-V",
                    "content": "",
                    "flag": "-V"
                },
                {
                    "name": "--version",
                    "content": "Print the createdb version and exit.\n\n-?",
                    "long": "--version"
                },
                {
                    "name": "--help",
                    "content": "Show help about createdb command line arguments, and exit.\n\nThe options -D, -l, -E, -O, and -T correspond to options of the underlying SQL command CREATE\nDATABASE; see there for more information about them.\n\ncreatedb also accepts the following command-line arguments for connection parameters:\n",
                    "long": "--help"
                },
                {
                    "name": "-h",
                    "content": "--host=host\nSpecifies the host name of the machine on which the server is running. If the value\nbegins with a slash, it is used as the directory for the Unix domain socket.\n",
                    "flag": "-h"
                },
                {
                    "name": "-p",
                    "content": "--port=port\nSpecifies the TCP port or the local Unix domain socket file extension on which the server\nis listening for connections.\n",
                    "flag": "-p"
                },
                {
                    "name": "-U",
                    "content": "--username=username\nUser name to connect as.\n",
                    "flag": "-U"
                },
                {
                    "name": "-w",
                    "content": "",
                    "flag": "-w"
                },
                {
                    "name": "--no-password",
                    "content": "Never issue a password prompt. If the server requires password authentication and a\npassword is not available by other means such as a .pgpass file, the connection attempt\nwill fail. This option can be useful in batch jobs and scripts where no user is present\nto enter a password.\n",
                    "long": "--no-password"
                },
                {
                    "name": "-W",
                    "content": "",
                    "flag": "-W"
                },
                {
                    "name": "--password",
                    "content": "Force createdb to prompt for a password before connecting to a database.\n\nThis option is never essential, since createdb will automatically prompt for a password\nif the server demands password authentication. However, createdb will waste a connection\nattempt finding out that the server wants a password. In some cases it is worth typing -W\nto avoid the extra connection attempt.\n\n--maintenance-db=dbname\nSpecifies the name of the database to connect to when creating the new database. If not\nspecified, the postgres database will be used; if that does not exist (or if it is the\nname of the new database being created), template1 will be used. This can be a connection\nstring. If so, connection string parameters will override any conflicting command line\noptions.\n",
                    "long": "--password"
                }
            ]
        },
        "ENVIRONMENT": {
            "content": "PGDATABASE\nIf set, the name of the database to create, unless overridden on the command line.\n\nPGHOST\nPGPORT\nPGUSER\nDefault connection parameters.  PGUSER also determines the name of the database to\ncreate, if it is not specified on the command line or by PGDATABASE.\n\nPGCOLOR\nSpecifies whether to use color in diagnostic messages. Possible values are always, auto\nand never.\n\nThis utility, like most other PostgreSQL utilities, also uses the environment variables\nsupported by libpq (see Section 34.15).\n",
            "subsections": []
        },
        "DIAGNOSTICS": {
            "content": "In case of difficulty, see CREATE DATABASE (CREATEDATABASE(7)) and psql(1) for discussions\nof potential problems and error messages. The database server must be running at the targeted\nhost. Also, any default connection settings and environment variables used by the libpq\nfront-end library will apply.\n",
            "subsections": []
        },
        "EXAMPLES": {
            "content": "To create the database demo using the default database server:\n\n$ createdb demo\n\nTo create the database demo using the server on host eden, port 5000, using the template0\ntemplate database, here is the command-line command and the underlying SQL command:\n\n$ createdb -p 5000 -h eden -T template0 -e demo\nCREATE DATABASE demo TEMPLATE template0;\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "dropdb(1), CREATE DATABASE (CREATEDATABASE(7))\n\n\n\nPostgreSQL 14.23                                2026                                     CREATEDB(1)",
            "subsections": []
        }
    },
    "summary": "createdb - create a new PostgreSQL database",
    "flags": [
        {
            "flag": "-D",
            "long": null,
            "arg": null,
            "description": "--tablespace=tablespace Specifies the default tablespace for the database. (This name is processed as a double-quoted identifier.)"
        },
        {
            "flag": "-e",
            "long": null,
            "arg": null,
            "description": ""
        },
        {
            "flag": "",
            "long": "--echo",
            "arg": null,
            "description": "Echo the commands that createdb generates and sends to the server."
        },
        {
            "flag": "-E",
            "long": null,
            "arg": null,
            "description": "--encoding=encoding Specifies the character encoding scheme to be used in this database. The character sets supported by the PostgreSQL server are described in Section 24.3.1."
        },
        {
            "flag": "-l",
            "long": null,
            "arg": null,
            "description": "--locale=locale Specifies the locale to be used in this database. This is equivalent to specifying both --lc-collate and --lc-ctype. --lc-collate=locale Specifies the LCCOLLATE setting to be used in this database. --lc-ctype=locale Specifies the LCCTYPE setting to be used in this database."
        },
        {
            "flag": "-O",
            "long": null,
            "arg": null,
            "description": "--owner=owner Specifies the database user who will own the new database. (This name is processed as a double-quoted identifier.)"
        },
        {
            "flag": "-T",
            "long": null,
            "arg": null,
            "description": "--template=template Specifies the template database from which to build this database. (This name is processed as a double-quoted identifier.)"
        },
        {
            "flag": "-V",
            "long": null,
            "arg": null,
            "description": ""
        },
        {
            "flag": "",
            "long": "--version",
            "arg": null,
            "description": "Print the createdb version and exit. -?"
        },
        {
            "flag": "",
            "long": "--help",
            "arg": null,
            "description": "Show help about createdb command line arguments, and exit. The options -D, -l, -E, -O, and -T correspond to options of the underlying SQL command CREATE DATABASE; see there for more information about them. createdb also accepts the following command-line arguments for connection parameters:"
        },
        {
            "flag": "-h",
            "long": null,
            "arg": null,
            "description": "--host=host Specifies the host name of the machine on which the server is running. If the value begins with a slash, it is used as the directory for the Unix domain socket."
        },
        {
            "flag": "-p",
            "long": null,
            "arg": null,
            "description": "--port=port Specifies the TCP port or the local Unix domain socket file extension on which the server is listening for connections."
        },
        {
            "flag": "-U",
            "long": null,
            "arg": null,
            "description": "--username=username User name to connect as."
        },
        {
            "flag": "-w",
            "long": null,
            "arg": null,
            "description": ""
        },
        {
            "flag": "",
            "long": "--no-password",
            "arg": null,
            "description": "Never issue a password prompt. If the server requires password authentication and a password is not available by other means such as a .pgpass file, the connection attempt will fail. This option can be useful in batch jobs and scripts where no user is present to enter a password."
        },
        {
            "flag": "-W",
            "long": null,
            "arg": null,
            "description": ""
        },
        {
            "flag": "",
            "long": "--password",
            "arg": null,
            "description": "Force createdb to prompt for a password before connecting to a database. This option is never essential, since createdb will automatically prompt for a password if the server demands password authentication. However, createdb will waste a connection attempt finding out that the server wants a password. In some cases it is worth typing -W to avoid the extra connection attempt. --maintenance-db=dbname Specifies the name of the database to connect to when creating the new database. If not specified, the postgres database will be used; if that does not exist (or if it is the name of the new database being created), template1 will be used. This can be a connection string. If so, connection string parameters will override any conflicting command line options."
        }
    ],
    "examples": [
        "To create the database demo using the default database server:",
        "$ createdb demo",
        "To create the database demo using the server on host eden, port 5000, using the template0",
        "template database, here is the command-line command and the underlying SQL command:",
        "$ createdb -p 5000 -h eden -T template0 -e demo",
        "CREATE DATABASE demo TEMPLATE template0;"
    ],
    "see_also": [
        {
            "name": "dropdb",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/dropdb/1/json"
        },
        {
            "name": "CREATEDATABASE",
            "section": "7",
            "url": "https://www.chedong.com/phpMan.php/man/CREATEDATABASE/7/json"
        }
    ],
    "tldr": {
        "source": "official",
        "description": "Create a PostgreSQL database.",
        "examples": [
            {
                "description": "Create a database owned by the current user",
                "command": "createdb {{database_name}}"
            },
            {
                "description": "Create a database owned by a specific user with a description",
                "command": "createdb {{-O|--owner}} {{username}} {{database_name}} '{{description}}'"
            },
            {
                "description": "Create a database from a template",
                "command": "createdb {{-T|--template}} {{template_name}} {{database_name}}"
            }
        ]
    }
}