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 →

Checking Database Consistency

About this module

Next, you will learn how to check the consistency of a Neo4j database.

At the end of this module, you should be able to use neo4j-admin to check the consistency of a Neo4j database.

Checking the consistency of a database

A database’s consistency could be compromised if a software or hardware failure has occurred that affects the Neo4j database. You will learn later in this training about live backups, but if you have reason to believe that a specific database has been corrupted, you can perform a consistency check on it.

The Neo4j database must be stopped to perform the consistency check.

Here is how you use the neo4j-admin tool to check the consistency of the database:

neo4j-admin check-consistency --database=<database-name>
                              --report-dir=report-location [--verbose]

The database named database-name is found in the Neo4j instance. If the tool comes back with no error, then the database is consistent. Otherwise, an error is returned and a report is written to report-location. You can specify verbose reporting. See the Neo4j Operations Manual for more options. For example, you typically check the consistency of a backup which is a best practice you will learn about later in this training.

Suppose we had loaded the movies2 database with neo4j-admin. Here is what a successful run of the consistency checker should produce:

ConsistentPassed

No report is written to the reports directory because the consistency check passed.

Example: Inconsistencies found

Here is an example of what an unsuccessful run of the consistency checker should produce:

Inconsistencies

If inconsistencies are found, a report is generated and placed in the directory specified for the report location.

Inconsistencies in a database are a serious matter that should be looked into with the help of Neo4j Technical Support.

Exercise #7: Checking consistency of a database

In this Exercise, you check the consistency of a database that is consistent. Then you modify a file that causes the database to become corrupt and then check its consistency.

Before you begin

  1. Make sure you have a terminal window open to your Docker Neo4j instance for this course.
  2. Ensure that the Docker Neo4j instance is started.

Exercise steps:

  1. Use cypher-shell to load the movies.dump data into a database named movies2.
  2. Use cypher-shell to create the movies2 database.
  3. Confirm that this database has 171 nodes.
  4. Stop the movies2 database.
  5. Create the directory $HOME/docker-neo4j/logs/reports.
  6. Make this new directory writable.
  7. Run the consistency check tool on movies2 using neo4j-admin specifying reports as the directory where the report will be written.
[sudo] docker exec --interactive neo4j bin/neo4j-admin check-consistency --database=movies2 --report-dir=logs/reports

ConsistentPassedDocker

Note
You will see a few information messages about record formats which are specific to Docker Neo4j instances that you can safely ignore.
  1. Use neo4j-admin to load the movies.dump data into a database named movies3.
  2. Use cypher-shell to create the movies3 database.
  3. Confirm that this database has 171 nodes.
  4. Stop the movies3 database.
  5. Next, you will “maliciously” corrupt the database. Modify the file data/new-location/databases/movies3/neostore.nodestore.db by adding some text to the file.

    CorruptMovies3

  6. Run the consistency check tool on movies3 using neo4j-admin specifying logs/reports as the directory where the report will be written. The consistency check tool should return something like the following:

    InconsistenciesDocker

  7. Use cypher-shell to drop the movies3 database.

Exercise summary

You have now you checked the consistency of a database that is consistent. Then you modified a file that causes the database to become corrupt and then checked its consistency.

Check your understanding

Question 1

Suppose that you suspect that one of the user databases in your Neo4j instance has become corrupt. What is the first thing you need to do?

Select the correct answer.

  • Back up the database.
  • Shut down the Neo4j instance.
  • Restart the Neo4j instance.
  • Stop the database that may be corrupt.

Question 2

What tool do you use to check the consistency of a database?

Select the correct answer.

  • neo4j-check-consistency
  • neo4j-admin check-consistency
  • neo4j-admin check
  • cypher-shell

Question 3

As a best practice, when should you always check the consistency of a database?

Select the correct answers.

  • When an event occurs in your monitoring that makes you suspect a problem.
  • Immediately after start up of the Neo4j instance.
  • Prior to shut down of the Neo4j instance.
  • When you back up a database.

Summary

You should now be able to use neo4j-admin to check the consistency of a Neo4j database.

Stay Connected

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