CREATE DATABASE
Synopsis
Use the CREATE DATABASE
statement to create a database that functions as a grouping mechanism for database objects, such as tables.
Syntax
create_database ::= CREATE DATABASE name [ create_database_options ]
create_database_options ::= [ WITH ] [ OWNER [ = ] user_name ]
[ TEMPLATE [ = ] template ]
[ ENCODING [ = ] encoding ]
[ LC_COLLATE [ = ] lc_collate ]
[ LC_CTYPE [ = ] lc_ctype ]
[ ALLOW_CONNECTIONS [ = ] allowconn ]
[ CONNECTION_LIMIT [ = ] connlimit ]
[ IS_TEMPLATE [ = ] istemplate ]
[ COLOCATED [ = ] { 'true' | 'false' } ]
create_database
create_database_options
Semantics
create_database
CREATE DATABASE name
Specify the name of the database to be created. An error is raised if a YSQL database of the given name
already exists.
create_database_options
[ WITH ] OWNER user_name
Specify the role name of the user who will own the new database. When not specified, the database creator is the owner.
TEMPLATE template
Specify the name of the template from which the new database is created.
ENCODING encoding
Specify the character set encoding to use in the new database.
LC_COLLATE lc_collate
Specify the collation order (LC_COLLATE
).
LC_CTYPE lc_ctype
Specify the character classification (LC_CTYPE
).
ALLOW_CONNECTIONS allowconn
Specify false
to disallow connections to the database. Default is true
, which allows connections to the database.
CONNECTION_LIMIT connlimit
Specify how many concurrent connections can be made to this database. Default of -1
allows unlimited concurrent connections.
IS_TEMPLATE istemplate
true
— This database can be cloned by any user with CREATEDB
privileges.
Specify false
to only superusers or the owner of the database can clone it.
COLOCATED
Specify true
if all tables for this database should be colocated on a single tablet. See colocated tables architecture for details on when colocated tables are useful.
Default value is false
and every table in the database will have its own set of tablets.
Examples
Create a colocated database
yugabyte=# CREATE DATABASE company WITH COLOCATED = true;
In this example, all tables in the database company
will be colocated on a single tablet.