Online Course Basic Neo4j 4.0 Administration Introduction to Neo4j Overview of Neo4j Administration Managing a Neo4j Instance Using cypher-shell to Manage Databases Copying Databases Changing the Database Location Checking Database Consistency Scripting to Manage Databases Configuring Plugins Managing HTTP Ports… Read more →
Changing the Database Location
Next, you will learn how to set up the Neo4j instance to use a specific, non-default location for the databases.
At the end of this module, you should be able to:
- Modify the location where Neo4j databases are placed.
If you do not want the databases used by the Neo4j instance to reside in the same location as the Neo4j installation, you can modify its location in the neo4j.conf file. If you specify a new location for the data, it must exist in the filesystem and the directory must be owned by neo4j:neo4j.
Here we have specified a new location for the data in the configuration file:
In addition, we have specified mainDB as the default database.
Here is a best practice you should follow when managing a Neo4j installation. It is easier to place all changed property values at the end of the neo4j.conf file. That way, you can easily see what non-default values you have configured.
Here is an example:
After you have modified the neo4j.conf file with the new location for the databases, you must:
- Ensure the directory exists.
- Change the owner of the directory to be neo4j.
- Start or restart the Neo4j instance.
- Confirm that the instance started with no errors.
When you start the Neo4j instance using a different location for the databases, it first creates and starts a database named whatever you have specified as the default database. If you did not specify the default database in the configuration file, it will create a database named neo4j.
Here are the new databases in the new location:
If you have existing databases that you want to reside in a different location for the Neo4j instance, remember that you must dump and load the databases to safely copy them to the new location.
In this Exercise, you will set up a different location for the databases from where they are placed by default.
If your production system were to use Docker instances, you would simply specify a different location for the data directory (–volume) when you create the Docker Neo4j instance.
Since a Docker Neo4j instance is already created for this training with volumes mounted in your local filesystem, you will get some experience with specifying a different location for the databases in the Neo4j configuration.
On a non-Docker installation, you would specify this location in the Neo4j configuration as you will do in this exercise.
- Make sure you have a terminal window open to your Docker Neo4j instance for this course.
- Ensure that the Neo4j instance is stopped.
- You should have previously created the dump file, movies.dump for the movie database in the $HOME/docker-neo4j/data directory.
- Create a directory named $HOME/docker-neo4j/neo4j/data/new-location. This is the directory where the databases will reside which is different from the default location used by Neo4j.
- Make sure that this new-location directory is writable.
- Modify the neo4j.conf file to use this new location as the data directory. Also ensure that there the default database is maindb. Your neo4j.conf file should look something like this:
- Start the Docker Neo4j instance.
Examine the log file to ensure that the instance started without errors.
Examine the files in the new-location directory. The instance should have created the databases and transactions directories. The databases directory should look as follows:
Connect to the maindb database using
cypher-shell. Did you need to change the password?
loadcommand of the
neo4j-admintool to create the database, movies from the dump file as follows:
[sudo] docker exec --interactive neo4j bin/neo4j-admin load --database=movies --from=data/movies.dump
- Confirm that this movies database has 171 nodes.
You have now configured the Neo4j instance to use a different location for the databases.
What file must you modify if you want the location of the databases for your Neo4j instance to be located in a non-default directory?
Select the correct answer.
The directory/folder that will be used for the Neo4j instance databases must be owned by which user:group?
Select the correct answer.
Suppose you configure a new location for the databases for the Neo4j instance. After the Neo4j instance starts, what are the first things you must do?
Select the correct answers.
- Create the system database.
- Create the user database.
- Ensure the Neo4j instance successfully starts.
- Change the password for the neo4j user.