Apache®, Apache Tomcat®, Apache Kafka®, Apache Cassandra™, and Apache Geode™ are trademarks or registered trademarks of the Apache Software Foundation in the United States and/or other countries. Java™, Java™ SE, Java™ EE, and OpenJDK™ are trademarks of Oracle and/or its affiliates. Kubernetes® is a registered trademark of the Linux Foundation in the United States and other countries. Linux® is the registered trademark of Linus Torvalds in the United States and other countries. Windows® and Microsoft® Azure are registered trademarks of Microsoft Corporation. “AWS” and “Amazon Web Services” are trademarks or registered trademarks of Amazon.com Inc. or its affiliates. All other trademarks and copyrights are property of their respective owners and are only mentioned for informative purposes. Other names may be trademarks of their respective owners. Show The role name of the user who will own the new database, or CREATE DATABASE lusiadas; 3 to use the default (namely, the user executing the command). To create a database owned by another role, you must be able to CREATE DATABASE lusiadas; 4 to that role. CREATE DATABASE lusiadas; 5 The name of the template from which to create the new database, or CREATE DATABASE lusiadas; 3 to use the default template ( CREATE DATABASE lusiadas; 8 Character set encoding to use in the new database. Specify a string constant (e.g., CREATE DATABASE lusiadas; 9), or an integer encoding number, or CREATE DATABASE lusiadas; 3 to use the default encoding (namely, the encoding of the template database). The character sets supported by the PostgreSQL server are described in . See below for additional restrictions. CREATE DATABASE sales OWNER salesapp TABLESPACE salesspace; 1 Strategy to be used in creating the new database. If the CREATE DATABASE sales OWNER salesapp TABLESPACE salesspace; 2 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 CREATE DATABASE sales OWNER salesapp TABLESPACE salesspace; 3 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. CREATE DATABASE sales OWNER salesapp TABLESPACE salesspace; 4 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 CREATE DATABASE sales OWNER salesapp TABLESPACE salesspace; 5, 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, CREATE DATABASE sales OWNER salesapp TABLESPACE salesspace; 6 and CREATE DATABASE sales OWNER salesapp TABLESPACE salesspace; 7. The default is the same setting as the template database. See and for details. Can be overridden by setting , , or individually. TipThe other locale settings , , , and are not fixed per database and are not set by this command. If you want to make them the default for a specific database, you can use CREATE DATABASE music
1.CREATE DATABASE sales OWNER salesapp TABLESPACE salesspace; 8 Sets CREATE DATABASE sales OWNER salesapp TABLESPACE salesspace; 6 in the database server's operating system environment. The default is the setting of if specified, otherwise the same setting as the template database. See below for additional restrictions. If is CREATE DATABASE music
6, also sets the default collation order to use in the new database, overriding the setting .CREATE DATABASE sales OWNER salesapp TABLESPACE salesspace; 9 Sets CREATE DATABASE sales OWNER salesapp TABLESPACE salesspace; 7 in the database server's operating system environment. The default is the setting of if specified, otherwise the same setting as the template database. See below for additional restrictions. If is CREATE DATABASE music
6, also sets the default character classification to use in the new database, overriding the setting .CREATE DATABASE music
0 Specifies the ICU locale (see ) for the database default collation order and character classification, overriding the setting . The must be ICU. The default is the setting of if specified; otherwise the same setting as the template database. CREATE DATABASE music2
7 Specifies additional collation rules to customize the behavior of the default collation of this database. This is supported for ICU only. See for details. CREATE DATABASE music
5 Specifies the provider to use for the default collation in this database. Possible values are CREATE DATABASE music2
9 (if the server was built with ICU support) or CREATE DATABASE music
6. By default, the provider is the same as that of the . See for details.`CREATE DATABASE`2 Specifies the collation version string to store with the database. Normally, this should be omitted, which will cause the version to be computed from the actual version of the database collation as provided by the operating system. This option is intended to be used by `CREATE DATABASE`3 for copying the version from an existing installation. See also ALTER DATABASE for how to handle database collation version mismatches. `CREATE DATABASE`4 The name of the tablespace that will be associated with the new database, or CREATE DATABASE lusiadas; 3 to use the template database's tablespace. This tablespace will be the default tablespace used for objects created in this database. See CREATE TABLESPACE for more information. `CREATE DATABASE`6 If false then no one can connect to this database. The default is true, allowing connections (except as restricted by other mechanisms, such as `CREATE DATABASE`7/`CREATE DATABASE`8). `CREATE DATABASE`9 How many concurrent connections can be made to this database. -1 (the default) means no limit. `CREATEDB`0 If true, then this database can be cloned by any user with `CREATEDB`2 The object identifier to be used for the new database. If this parameter is not specified, PostgreSQL will choose a suitable OID automatically. This parameter is primarily intended for internal use by pg_upgrade, and only pg_upgrade can specify a value less than 16384. Optional parameters can be written in any order, not only the order illustrated above. Notes
Errors along the line of “could not initialize database directory” are most likely related to insufficient permissions on the data directory, a full disk, or other file system problems. Use `CREATEDB`4 to remove a database. The program createdb is a wrapper program around this command, provided for convenience. Database-level configuration parameters (set via `CREATEDB`5) and database-level permissions (set via `CREATE DATABASE`7) are not copied from the template database. Although it is possible to copy a database other than The character set encoding specified for the new database must be compatible with the chosen locale settings ( CREATE DATABASE sales OWNER salesapp TABLESPACE salesspace; 6 and CREATE DATABASE sales OWNER salesapp TABLESPACE salesspace; 7). If the locale is The encoding and locale settings must match those of the template database, except when `template1`7 is used as template. This is because other databases might contain data that does not match the specified encoding, or might contain indexes whose sort ordering is affected by CREATE DATABASE sales OWNER salesapp TABLESPACE salesspace; 6 and CREATE DATABASE sales OWNER salesapp TABLESPACE salesspace; 7. Copying such data would result in a database that is corrupt according to the new settings. `template1`7, however, is known to not contain any data or indexes that would be affected. There is currently no option to use a database locale with nondeterministic comparisons (see TEMPLATE `name`1 for an explanation). If this is needed, then per-column collations would need to be used. The TEMPLATE `name`2 option is only enforced approximately; if two new sessions start at about the same time when just one connection “slot” remains for the database, it is possible that both will fail. Also, the limit is not enforced against superusers or background worker processes. ExamplesTo create a new database: CREATE DATABASE lusiadas; To create a database TEMPLATE `name`3 owned by user TEMPLATE `name`4 with a default tablespace of TEMPLATE `name`5: CREATE DATABASE sales OWNER salesapp TABLESPACE salesspace; To create a database TEMPLATE `name`6 with a different locale: CREATE DATABASE music
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 TEMPLATE `name`9 with a different locale and a different character set encoding: CREATE DATABASE music2
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. CompatibilityThere is no |