Create, start, and stop databases
Neo4j supports the management of multiple databases within the same DBMS.
The metadata for these databases, including the associated security model, is maintained in a special database called the system
database.
All multi-database administrative commands must be run against the system
database.
These administrative commands are automatically routed to the system
database when connected to the DBMS over Bolt.
Administrative commands should not be used during a rolling upgrade. For more information, see Upgrade and Migration Guide → Upgrade a cluster. |
Create databases
You can create a database using the Cypher command CREATE DATABASE
.
Database names are subject to the rules specified in Database names section.
Having dots ( |
In versions previous to Neo4j 5.22, the default store format for all new databases is aligned
.
From Neo4j 5.22, block
is the default format for all newly-created databases as long as they do not have the db.format
setting specified.
If you want to change it, you can set a new value for the db.format
configuration in the neo4j.conf file.
Alternatively, you can set the store format of new databases using the CREATE DATABASE databasename OPTIONS {storeFormat: 'the-new-format'}
command.
However, if the store is seeded with seedURI
, existingDataSeedServer
or existingDataSeedInstance
, or if the command is being used to mount pre-existing store files already present on the disk, they will use their current store format without any alterations.
See Store formats, for more details about available database store formats in Neo4j.
Syntax
Command | Syntax |
---|---|
|
|
Options
The CREATE DATABASE
command can have a map of options, e.g. OPTIONS {key: 'value'}
.
Key | Value | Description |
---|---|---|
|
|
Controls how the system handles existing data on disk when creating the database.
Currently, this is only supported with |
|
ID of the cluster server |
Defines which server is used for seeding the data of the created database.
The server ID can be found in the |
|
URI to a backup or a dump from an existing database. |
Defines an identical seed from an external source which will be used to seed all servers. |
|
Comma-separated list of configuration values. |
For more information see Seed from URI. |
|
credentials |
Defines credentials that need to be passed into certain seed providers.
From 5.26, it is recommended to use the |
|
|
Defines the level of enrichment applied to transaction logs for Change Data Capture (CDC) purposes. For details about enrichment mode, see Change Data Capture Manual → Enable CDC on self-managed instances → Set the enrichment mode. |
|
|
Defines the store format if the database created is new.
If the store is seeded with |
The |
Examples
Create a database
To create a database named customers
, use the command CREATE DATABASE
followed by the name of this database.
CREATE DATABASE customers
When you create a database, it shows up in the listing provided by the command SHOW DATABASES
:
SHOW DATABASES YIELD name
+-------------+ | name | +-------------+ | "customers" | | "movies" | | "neo4j" | | "system" | +-------------+
Create a database with WAIT
Sub-clause WAIT
allows you to specify a time limit in which the command must complete and return.
CREATE DATABASE slow WAIT 5 SECONDS
+-------------------------------------------------------+ | address | state | message | success | +-------------------------------------------------------+ | "localhost:7687" | "CaughtUp" | "caught up" | TRUE | +-------------------------------------------------------+
The success
column provides an aggregate status of whether or not the command is considered successful.
Thus, every row has the same value, determined on a successful completion without a timeout.
Create databases with IF NOT EXISTS
or OR REPLACE
The CREATE DATABASE
command is optionally idempotent, with the default behavior to fail with an error if the database already exists.
There are two ways to circumvent this behavior.
First, appending IF NOT EXISTS
to the command ensures that no error is returned and that nothing happens if the database already exists.
CREATE DATABASE customers IF NOT EXISTS
Second, adding OR REPLACE
to the command deletes any existing database and creates a new one.
CREATE OR REPLACE DATABASE customers
This is equivalent to running DROP DATABASE customers IF EXISTS
followed by CREATE DATABASE customers
.
The behavior of IF NOT EXISTS
and OR REPLACE
apply to both standard and composite databases (e.g. a composite database may replace a standard database or another composite database).
The |
Start databases
Databases can be started using the command START DATABASE
.
Both standard databases and composite databases can be started using this command. |
Examples
Start a database
Starting a database is a straightforward operation.
Suppose you have a database named customers
.
To start it, use the following command:
START DATABASE customers
You can see the status of the started database by running the command SHOW DATABASE name
.
SHOW DATABASE customers YIELD name, requestedStatus, currentStatus
+-----------------------------------------------+ | name | requestedStatus | currentStatus | +-----------------------------------------------+ | "customers" | "online" | "online" | +-----------------------------------------------+
Start a database with WAIT
You can start your database using WAIT
sub-clause to ensure that the command waits for a specified amount of time until the database is started.
START DATABASE customers WAIT 5 SECONDS
Stop databases
Databases can be stopped using the command STOP DATABASE
.
Examples
Stop a database
To stop a database, use the following command:
STOP DATABASE customers
Both standard databases and composite databases can be stopped using this command. |
The status of the stopped database can be seen using the command SHOW DATABASE name
:
SHOW DATABASE customers YIELD name, requestedStatus, currentStatus
+-----------------------------------------------+ | name | requestedStatus | currentStatus | +-----------------------------------------------+ | "customers" | "offline" | "offline" | +-----------------------------------------------+
Stop a database with WAIT
You can also stop your database using the WAIT
sub-clause, which allows you to specify the amount of time that the system should wait for the database to stop.
STOP DATABASE customers WAIT 10 SECONDS
Databases that are stopped with the |