CREATE DATABASE creates a database. By default, the new database will be created by cloning the standard system database template1. A different template can be specified using TEMPLATE template name.
1 2 3 4 5 6 7 8 9 | CREATE DATABASE database_name [ [ WITH ] { [ OWNER [=] user_name ] | [ TEMPLATE [=] template ] | [ ENCODING [=] encoding ] | [ LC_COLLATE [=] lc_collate ] | [ LC_CTYPE [=] lc_ctype ] | [ DBCOMPATIBILITY [=] compatibilty_type ] | [ CONNECTION LIMIT [=] connlimit ]}[...] ]; |
Indicates the database name.
Value range: a string. It must comply with the naming convention.
Indicates the owner of the new database. By default, the owner of the database is the current user.
Value range: an existing user name
Indicates the template name, that is, the name of the template to be used to create the database. GaussDB(DWS) creates a database by coping a database template. GaussDB(DWS) has two default template databases template0 and template1 and a default user database gaussdb.
Value range: An existing database name. If this it is not specified, the system copies template1 by default. Its value cannot be gaussdb.
Currently, database templates cannot contain sequences. If a database template contains sequences, database creation using this template will fail.
Specifies the encoding format used by the new database. The value can be a string (for example, SQL_ASCII) or an integer.
By default, the encoding format of the template database is used. The encoding formats of the template databases template0 and template1 vary based on OS environments by default. The template1 database does not allow encoding customization. To specify encoding for a database when creating it, use template0. To specify encoding, set template to template0.
Common values: GBK, UTF8, and Latin1
Specifies the collation order to use in the new database. For example, this parameter can be set using lc_collate = 'zh_CN.gbk'.
The use of this parameter affects the sort order applied to strings, for example, in queries with ORDER BY, as well as the order used in indexes on text columns. The default is to use the collation order of the template database.
Value range: A valid order type.
Specifies the character classification to use in the new database. For example, this parameter can be set using lc_ctype = 'zh_CN.gbk'. The use of this parameter affects the categorization of characters, for example, lower, upper and digit. The default is to use the character classification of the template database.
Value range: A valid character type.
Specifies the compatible database type.
Value range: ORA, TD, and MySQL, representing the Oracle-, Teradata-, and MySQL-compatible modes, respectively. If this parameter is not specified, the default value ORA is used.
Specifies the name of the tablespace that will be associated with the new database.
Value range: An existing tablespace name.
The specified tablespace cannot be the OBS tablespace.
Indicates the maximum number of concurrent connections that can be made to the new database.
Value range: An integer greater than or equal to -1. The default value -1 means no limit.
The following are limitations on character encoding:
Create database music using GBK (the local encoding type is also GBK).
1 | CREATE DATABASE music ENCODING 'GBK' template = template0; |
Create database music2 and specify jim as its owner.
1 | CREATE DATABASE music2 OWNER jim; |
Create database music3 using template template0 and specify jim as its owner.
1 | CREATE DATABASE music3 OWNER jim TEMPLATE template0; |
Create a compatible Oracle database ora_compatible_db.
1 | CREATE DATABASE ora_compatible_db DBCOMPATIBILITY 'ORA'; |