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

About this module

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.

Modifying the location of the database

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:

ChangeDatabaseDirectory

In addition, we have specified mainDB as the default database.

Best practice for configuration modifications

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:

BestPracticeConfigChangesAtEnd

Configuring Neo4j instance with a new location

After you have modified the neo4j.conf file with the new location for the databases, you must:

  1. Ensure the directory exists.
  2. Change the owner of the directory to be neo4j.
  3. Start or restart the Neo4j instance.
  4. Confirm that the instance started with no errors.

Neo4jStarted-newLocation1

Starting Neo4j instance with a new location

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:

Neo4jStarted-newLocation2

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.

Password change required

Just as you needed to change the password for the admin user, neo4j the first time you accessed a database, you must do the same here for this new location of the Neo4j databases:

passwordChangeNewLocation

Exercise #6: Modifying the location of the databases

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.

Before you begin

  1. Make sure you have a terminal window open to your Docker Neo4j instance for this course.
  2. Ensure that the Neo4j instance is stopped.
  3. You should have previously created the dump file, movies.dump for the movie database in the $HOME/docker-neo4j/data directory.

Exercise steps:

  1. 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.
  2. Make sure that this new-location directory is writable.
  3. 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:
dbms.default_database=maindb
dbms.directories.data=data/new-location

NewLocationDocker

  1. Start the Docker Neo4j instance.
  2. Examine the log file to ensure that the instance started without errors.

    Neo4jStarted-newLocationDocker

  3. 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:

    Neo4jStarted-newLocation2Docker

  4. Connect to the maindb database using cypher-shell. Did you need to change the password?
  5. Exit cypher-shell.
  6. Use the load command of the neo4j-admin tool 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
  7. In cypher-shell create movies.
  8. Confirm that this movies database has 171 nodes.

Exercise summary

You have now configured the Neo4j instance to use a different location for the databases.

Check your understanding

Question 1

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.

  • database.conf
  • neo4j-database.conf
  • neo4j-instance.conf
  • neo4j.conf

Question 2

The directory/folder that will be used for the Neo4j instance databases must be owned by which user:group?

Select the correct answer.

  • root:root
  • neo4j:root
  • neo4j:neo4j
  • root:neo4j

Question 3

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.

Summary

You should now be able to:

  • Modify the location where Neo4j databases are placed.

Stay Connected

Sign up to find out more about Neo4j's upcoming events & meetups.