CREATE DATABASE — create a new database
CREATE DATABASEname[ WITH ] [ OWNER [=]user_name] [ TEMPLATE [=]template] [ ENCODING [=]encoding] [ STRATEGY [=]strategy] [ LOCALE [=]locale] [ LC_COLLATE [=]lc_collate] [ LC_CTYPE [=]lc_ctype] [ BUILTIN_LOCALE [=]builtin_locale] [ ICU_LOCALE [=]icu_locale] [ ICU_RULES [=]icu_rules] [ LOCALE_PROVIDER [=]locale_provider] [ COLLATION_VERSION =collation_version] [ TABLESPACE [=]tablespace_name] [ ALLOW_CONNECTIONS [=]allowconn] [ CONNECTION LIMIT [=]connlimit] [ IS_TEMPLATE [=]istemplate] [ OID [=]oid]
CREATE DATABASE creates a new PostgreSQL database.
To create a database, you must be a superuser or have the special CREATEDB privilege. See CREATE ROLE.
By default, the new database will be created by cloning the standard system database template1. A different template can be specified by writing TEMPLATE . In particular, by writing nameTEMPLATE template0, 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 PostgreSQL. This is useful if you wish to avoid copying any installation-local objects that might have been added to template1.
name #The name of a database to create.
user_name #The role name of the user who will own the new database, or DEFAULT to use the default (namely, the user executing the command). To create a database owned by another role, you must be able to SET ROLE to that role.
template #The name of the template from which to create the new database, or DEFAULT to use the default template (template1).
encoding #Character set encoding to use in the new database. Specify a string constant (e.g., 'SQL_ASCII'), or an integer encoding number, or DEFAULT to use the default encoding (namely, the encoding of the template database). The character sets supported by the PostgreSQL server are described in Section 23.3.1. See below for additional restrictions.
strategy #Strategy to be used in creating the new database. If the WAL_LOG strategy is used, the database will be copied block by block and each block will be separately written to the write-ahead log. This is the most efficient strategy in cases where the template database is small, and therefore it is the default. The older FILE_COPY strategy is also available. This strategy writes a small record to the write-ahead log for each tablespace used by the target database. Each such record represents copying an entire directory to a new location at the filesystem level. While this does reduce the write-ahead log volume substantially, especially if the template database is large, it also forces the system to perform a checkpoint both before and after the creation of the new database. In some situations, this may have a noticeable negative impact on overall system performance. The FILE_COPY strategy is affected by the file_copy_method setting.
locale #Sets the default collation order and character classification in the new database. Collation affects the sort order applied to strings, e.g., in queries with ORDER BY, as well as the order used in indexes on text columns. Character classification affects the categorization of characters, e.g., lower, upper, and digit. Also sets the associated aspects of the operating system environment, LC_COLLATE and LC_CTYPE. The default is the same setting as the template database. See Section 23.2.2.3.1 and