Databases in a Causal Cluster
Multiple databases in a Causal Cluster are managed the same way as a single instance. Administrators can use the same Cypher commands described in Administrative commands to manage databases. This is based on two main principles:
-
All databases are available on all members of a cluster - this applies to Core servers and Read Replicas.
-
Administrative commands must be executed on the
system
database, on the Leader member of the cluster.
Change the default database
You can use the procedure dbms.cluster.setDefaultDatabase("newDefaultDatabaseName")
to change the default database of a Causal cluster.
-
Ensure that the database to be set as default exists, otherwise create it using the command
CREATE DATABASE <database-name>
. -
Show the name and status of the current default database by using the command
SHOW DEFAULT DATABASE
. -
Stop the current default database using the command
STOP DATABASE <database-name>
. -
On the Leader member of the cluster, run
CALL dbms.cluster.setDefaultDatabase("newDefaultDatabaseName")
against thesystem
database to set the new default database. -
On each cluster member:
-
Open the <neo4j-home>/conf/neo4j.conf file and update the value of
dbms.default_database
to the new default database. -
Restart the instance.
-
-
Optionally, you can start the previous default database as non-default by using
START DATABASE <database-name>
.
Run Cypher administrative commands from Cypher Shell on a Causal Cluster
For the following examples consider a Causal Cluster environment formed by 5 members, 3 Core servers, and 2 Read Replicas:
neo4j@neo4j> CALL dbms.cluster.overview();
+------------------------------------------------------------------------------------------------------------------------------------------------------------+ | id | addresses | databases | groups | +------------------------------------------------------------------------------------------------------------------------------------------------------------+ | "8c...3d" | ["bolt://localhost:7683", "http://localhost:7473", "https://localhost:7483"] | {neo4j: "FOLLOWER", system: "FOLLOWER"} | [] | | "8f...28" | ["bolt://localhost:7681", "http://localhost:7471", "https://localhost:7481"] | {neo4j: "LEADER", system: "LEADER"} | [] | | "e0...4d" | ["bolt://localhost:7684", "http://localhost:7474", "https://localhost:7484"] | {neo4j: "READ_REPLICA", system: "READ_REPLICA"} | [] | | "1a...64" | ["bolt://localhost:7682", "http://localhost:7472", "https://localhost:7482"] | {neo4j: "FOLLOWER", system: "FOLLOWER"} | [] | | "59...87" | ["bolt://localhost:7685", "http://localhost:7475", "https://localhost:7485"] | {neo4j: "READ_REPLICA", system: "READ_REPLICA"} | [] | +------------------------------------------------------------------------------------------------------------------------------------------------------------+ 5 rows available after 5 ms, consumed after another 0 ms
The leader is currently the instance exposing port 7681
for the bolt
protocol, and 7471/7481
for the http/https
protocol.
Administrators can connect and execute Cypher commands in the following ways:
bolt://
scheme to connect to the Leader:$ bin/cypher-shell -a bolt://localhost:7681 -d system -u neo4j -p neo4j1
Connected to Neo4j 4.0.0 at bolt://localhost:7681 as user neo4j. Type :help for a list of available commands or :exit to exit the shell. Note that Cypher queries must end with a semicolon.
neo4j@system> SHOW DATABASES;
+-------------------------------+ | name | status | default | +-------------------------------+ | "neo4j" | "online" | TRUE | | "system" | "online" | FALSE | +-------------------------------+ 2 rows available after 34 ms, consumed after another 0 ms
neo4j@system> CREATE DATABASE data001;
0 rows available after 378 ms, consumed after another 12 ms Added 1 nodes, Set 4 properties, Added 1 labels neo4j@system> SHOW DATABASES; +--------------------------------+ | name | status | default | +--------------------------------+ | "neo4j" | "online" | TRUE | | "system" | "online" | FALSE | | "data001" | "online" | FALSE | +--------------------------------+ 3 rows available after 2 ms, consumed after another 1 ms
neo4j://
scheme to connect to any Core member:$ bin/cypher-shell -a neo4j://localhost:7683 -d system -u neo4j -p neo4j1
Connected to Neo4j 4.0.0 at neo4j://localhost:7683 as user neo4j. Type :help for a list of available commands or :exit to exit the shell. Note that Cypher queries must end with a semicolon.
neo4j@system> SHOW DATABASES;
+--------------------------------+ | name | status | default | +--------------------------------+ | "neo4j" | "online" | TRUE | | "system" | "online" | FALSE | | "data001" | "online" | FALSE | +--------------------------------+ 3 rows available after 0 ms, consumed after another 0 ms
neo4j@system> CREATE DATABASE data002;
0 rows available after 8 ms, consumed after another 1 ms Added 1 nodes, Set 4 properties, Added 1 labels
neo4j@system> SHOW DATABASES;
+--------------------------------+ | name | status | default | +--------------------------------+ | "neo4j" | "online" | TRUE | | "system" | "online" | FALSE | | "data001" | "online" | FALSE | | "data002" | "online" | FALSE | +--------------------------------+ 4 rows available after 33 ms, consumed after another 0 ms
The neo4j:// scheme is the equivalent to the bolt+routing: scheme available in earlier versions of Neo4j, but it can be used seamlessly with a standalone and clustered DBMS.
|