Databases
Introduction
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.
Listing databases
There are three different commands for listing databases. Listing all databases, listing a particular database or listing the default database.
SHOW { DATABASE name | DATABASES | DEFAULT DATABASE }
[YIELD field[, ...] [ORDER BY field[, ...]] [SKIP n] [LIMIT n]]
[WHERE expression]
All available databases can be seen using the command SHOW DATABASES
.
SHOW DATABASES
name | address | role | requestedStatus | currentStatus | error | default |
---|---|---|---|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Rows: 4 |
Note that the results of this command are filtered according to the |
A particular database can be seen using the command SHOW DATABASE name
.
SHOW DATABASE system
name | address | role | requestedStatus | currentStatus | error | default |
---|---|---|---|---|---|---|
|
|
|
|
|
|
|
Rows: 1 |
The default database can be seen using the command SHOW DEFAULT DATABASE
.
SHOW DEFAULT DATABASE
name | address | role | requestedStatus | currentStatus | error |
---|---|---|---|---|---|
|
|
|
|
|
|
Rows: 1 |
It is also possible to filter and sort the results by using YIELD
, ORDER BY
and WHERE
.
SHOW DATABASES YIELD name, currentStatus, requestedStatus ORDER BY currentStatus WHERE name CONTAINS 'e'
In this example:
-
The number of columns returned has been reduced with the
YIELD
clause. -
The order of the returned columns has been changed.
-
The results have been filtered to only show database names containing 'e'.
-
The results are ordered by the 'currentStatus' column using
ORDER BY
.
It is also possible to use SKIP
and LIMIT
to paginate the results.
name | currentStatus | requestedStatus |
---|---|---|
|
|
|
|
|
|
|
|
|
Rows: 3 |
Note that for failed databases, the |
Creating databases
Databases can be created using CREATE DATABASE
.
CREATE DATABASE customers
0 rows, System updates: 1
Database names are subject to the standard Cypher® restrictions on valid identifiers. The following naming rules apply:
|
When a database has been created, it will show up in the listing provided by the command SHOW DATABASES
.
SHOW DATABASES
name | address | role | requestedStatus | currentStatus | error | default |
---|---|---|---|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Rows: 5 |
This command is optionally idempotent, with the default behavior to throw an exception if the database already exists. Appending IF NOT EXISTS
to the command will ensure that no exception is thrown and nothing happens should the database already exist. Adding OR REPLACE
to the command will result in any existing database being deleted and a new one created.
CREATE DATABASE customers IF NOT EXISTS
CREATE OR REPLACE DATABASE customers
This is equivalent to running DROP DATABASE customers IF EXISTS
followed by CREATE DATABASE customers
.
The |
Stopping databases
Databases can be stopped using the command STOP DATABASE
.
STOP DATABASE customers
0 rows, System updates: 1
The status of the stopped database can be seen using the command SHOW DATABASE name
.
SHOW DATABASE customers
name | address | role | requestedStatus | currentStatus | error | default |
---|---|---|---|---|---|---|
|
|
|
|
|
|
|
Rows: 1 |
Starting databases
Databases can be started using the command START DATABASE
.
START DATABASE customers
0 rows, System updates: 1
The status of the started database can be seen using the command SHOW DATABASE name
.
SHOW DATABASE customers
name | address | role | requestedStatus | currentStatus | error | default |
---|---|---|---|---|---|---|
|
|
|
|
|
|
|
Rows: 1 |
Deleting databases
Databases can be deleted using the command DROP DATABASE
.
DROP DATABASE customers
0 rows, System updates: 1
When a database has been deleted, it will no longer show up in the listing provided by the command SHOW DATABASES
.
SHOW DATABASES
name | address | role | requestedStatus | currentStatus | error | default |
---|---|---|---|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Rows: 4 |
This command is optionally idempotent, with the default behavior to throw an exception if the database does not exists. Appending IF EXISTS
to the command will ensure that no exception is thrown and nothing happens should the database not exist.
DROP DATABASE customers IF EXISTS
The DROP DATABASE
command will remove a database entirely. However, you can request that a dump of the store files is produced first, and stored in the path configured using the dbms.directories.dumps.root
setting (by default <neo4j-home>/data/dumps
). This can be achieved by appending DUMP DATA
to the command (or DESTROY DATA
to explicitly request the default behaviour). These dumps are equivalent to those produced by neo4j-admin dump
and can be similarly restored using neo4j-admin load
.
DROP DATABASE customers DUMP DATA
The options IF EXISTS
and DUMP DATA
/ DESTROY DATA
can also be combined. An example could look like this:
DROP DATABASE customers IF EXISTS DUMP DATA