YMatrix
Quick Start
Simulate Time Series Scenarios
Standard Cluster Deployment
Data Modeling
Connecting to The database
Data Writing
Data Migration
Data Query
Scene Application Examples
Federal Query
Maintenance and Monitoring
Global Maintenance
Partition Maintenance
Backup and Restore
Cluster Expansion
Enable Mirroring
Resource Management
Security
Monitoring
Performance Tuning
Troubleshooting
Reference Guide
Tool Guide
Data Type
Storage Engine
Execution Engine
Stream Processing
DR (Disaster Recovery)
Configuration Parameters
Index
Extension
SQL Reference
FAQ
Create a new database.
CREATE DATABASE name [ [WITH] [OWNER [=] user_name]
[TEMPLATE [=] template]
[ENCODING [=] encoding]
[LC_COLLATE [=] lc_collate]
[LC_CTYPE [=] lc_ctype]
[TABLESPACE [=] tablespace]
[CONNECTION LIMIT [=] connlimit ] ]
CREATE DATABASE creates a new database. To create a database, you must be a superuser or have special CREATEDB privileges.
By default, the creator becomes the owner of the new database. Superusers can use the OWNER clause to create databases owned by other users. They can even create databases owned by users without special privileges. Non-super users with CREATEDB privileges can only create databases that they own.
By default, a new database will be created by cloning the standard system database template1. Other templates can be specified by writing to the TEMPLATE name. In particular, by writing TEMPLATE template0, you can create a clean database that contains only standard objects predefined by the YMatrix database. This feature is useful if you want to avoid copying any local installation objects that may have been added to template1.
name
user_name
template
encoding
lc_collate
lc_ctype
tablespace
connlimit
CREATE DATABASE cannot be executed within a transaction block.
When you replicate a database by specifying the database name as a template, other sessions cannot be connected to the template database during the replication process. The new connection to the template database is locked until CREATE DATABASE is completed.
There is no mandatory CONNECTION LIMIT for superusers.
The character set encoding specified for the new database must be compatible with the selected locale settings (LC_COLLATE and LC_CTYPE). If the locale is C (or equivalent POSIX), all encodings are allowed, but for other locale settings, only one encoding works fine. CREATE DATABASE will allow superusers to specify SQL_ASCII encoding regardless of locale settings, but this option is not recommended and may cause an exception to the string function if locale is not compatible with the locale.
The encoding and locale settings must match the settings of the template database unless template0 is used as the template. This is because COLLATE and CTYPE affect the order of indexes, so any index copied from the template database will be invalid in a new database with different settings. However, template0 is known to contain no data or indexes that will be affected.
To create a new database:
CREATE DATABASE test;
To create a database sales owned by the user salesapp and use the default tablespace of salesspace:
CREATE DATABASE sales OWNER salesapp TABLESPACE salesspace;
To create a database music that supports the ISO-8859-1 character set:
CREATE DATABASE music ENCODING 'LATIN1' TEMPLATE template0;
In this example, the TEMPLATE template0 clause is only required if the encoding of template1 is not ISO-8859-1. Note that changing the encoding may also require selecting new LC_COLLATE and LC_CTYPE settings.
There is no CREATE DATABASE statement in the SQL standard. A database is equivalent to a directory, and the creation of a directory is implemented to define it.