---
title: "CREATE DATABASE"
url: "https://docs.yugabyte.com/stable/api/ysql/the-sql-language/statements/ddl_create_database/"
---

# CREATE DATABASE

Use the CREATE DATABASE statement to create a database that functions as a grouping mechanism for database objects, such as tables.

## Synopsis

Use the `CREATE DATABASE` statement to create a database that functions as a grouping mechanism for database objects, such as [tables](/stable/api/ysql/the-sql-language/statements/ddl_create_table "tables").

## Syntax

- [![Grammar Icon](/icons/file-lines.svg)Grammar](#grammar-1)
- [![Diagram Icon](/icons/diagram.svg)Diagram](#diagram-1)

```output.ebnf
create_database ::= CREATE DATABASE name [ create_database_options ]

create_database_options ::= [ WITH ] [ OWNER [ = ] user_name ]  
                            [ TEMPLATE [ = ] template_name ]  
                            [ ENCODING [ = ] encoding ]  
                            [ LC_COLLATE [ = ] lc_collate ]  
                            [ LC_CTYPE [ = ] lc_ctype ]  
                            [ ALLOW_CONNECTIONS [ = ] allowconn ]  
                            [ CONNECTION LIMIT [ = ] connlimit ]  
                            [ IS_TEMPLATE [ = ] istemplate ]  
                            [ COLOCATION [ = ] { 'true' | 'false' } ]  
                            [ AS OF [ = ] clone_timestamp ]
```

#### create\_database

CREATEDATABASE[name](/stable/api/ysql/syntax_resources/grammar_diagrams#name)[create\_database\_options](#create-database-options)

#### create\_database\_options

WITHOWNER=[user\_name](/stable/api/ysql/syntax_resources/grammar_diagrams#user-name)TEMPLATE=[template\_name](/stable/api/ysql/syntax_resources/grammar_diagrams#template-name)ENCODING=[encoding](/stable/api/ysql/syntax_resources/grammar_diagrams#encoding)LC\_COLLATE=[lc\_collate](/stable/api/ysql/syntax_resources/grammar_diagrams#lc-collate)LC\_CTYPE=[lc\_ctype](/stable/api/ysql/syntax_resources/grammar_diagrams#lc-ctype)ALLOW\_CONNECTIONS=[allowconn](/stable/api/ysql/syntax_resources/grammar_diagrams#allowconn)CONNECTIONLIMIT=[connlimit](/stable/api/ysql/syntax_resources/grammar_diagrams#connlimit)IS\_TEMPLATE=[istemplate](/stable/api/ysql/syntax_resources/grammar_diagrams#istemplate)COLOCATION=truefalseAS OF=[clone\_timestamp](/stable/api/ysql/syntax_resources/grammar_diagrams#clone-timestamp)

## 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.

### COLOCATION

Specify `true` if tables (and their indexes) for this database should be colocated on a single tablet by default. See [Colocated tables](/stable/additional-features/colocation/ "Colocated tables") for details on when colocated tables are beneficial.

Default is `false` and every table in the database will have its own set of tablets.

### AS OF

Specify the [Unix timestamp](https://www.unixtimestamp.com/ "Unix timestamp") (in microseconds) to create a clone of the original database at a specific point in time, within the history retention period specified when creating the snapshot schedule for the database. See [Clone to PIT](/stable/manage/backup-restore/point-in-time-recovery/clone/ "Clone to PIT").

## Examples

### Create a colocated database

```plpgsql
yugabyte=# CREATE DATABASE company WITH COLOCATION = true;
```

In this example, tables in the database `company` will be colocated on a single tablet by default.

## See also

- [ALTER DATABASE](/stable/api/ysql/the-sql-language/statements/ddl_alter_db "ALTER DATABASE")
- [DROP DATABASE](/stable/api/ysql/the-sql-language/statements/ddl_drop_database "DROP DATABASE")
