CREATE DATABASE
The CREATE DATABASE statement creates a new, empty database. A single SereneDB server can host many independent databases (the default is postgres); switch between them with USE or by connecting to one directly.
Examples
Create a database named app_production:
DROP DATABASE IF EXISTS app_production;
CREATE DATABASE app_production;Use IF NOT EXISTS so the statement succeeds even when the database already exists, instead of raising an error:
CREATE DATABASE IF NOT EXISTS app_production;Once created, you can connect to it like any other database — for example with psql:
psql -h localhost -p 7890 -d app_production
As an alternative to reconnecting, switch to the new database within the current session with the USE statement:
USE app_production;Storage options
WITH sets how the new database stores its tables:
DROP DATABASE IF EXISTS app_archive;
CREATE DATABASE app_archive WITH (BLOCK_SIZE = 16384, ROW_GROUP_SIZE = 1048576);
SELECT block_size FROM pragma_database_size() WHERE database_name = 'app_archive'; block_size
------------
16384| Option | Description | Default |
|---|---|---|
BLOCK_SIZE | The block size of the database file in bytes: a power of two from 16384 to 262144. | 262144 |
ROW_GROUP_SIZE | The number of rows in a row group: a multiple of 2048. | 122880 |
The options are stored with the database, so the server opens it with them again after a restart. BLOCK_SIZE is fixed once the file exists; ROW_GROUP_SIZE applies to the row groups written from then on. Any other option is refused.
See also
- ATTACH / DETACH — attach an existing database file
- USE — switch the active database