Cannot restart an offline DB with Java out of memory error

Per this SO, Neo4j: How to bring database back online - Stack Overflow

I was deleting 3 million nodes when I got an out of memory. Now I can not restart the DB. The log file shows a Java out of memory error. I think the key line is this:

Exception in thread "neo4j.Scheduler-1" java.lang.OutOfMemoryError: Java heap space

Presumably the DB is trying to continue with the large query on restart. Is there a way to clear this down?


BUMP - It's nearly 24 hours since I raised this problem, both here and Stackoverflow, with no response.

This is more of an observation than a complaint, but it does make it difficult to see how I could use this in production, even with paid support. In addition, I have seen similarly fatal errors where the response has been 'restore from backup', which compounds the problem.

Hi @KimPrince

My Env

Neo4j Desktop 1.4.7
Neo4j Enterprise 4.3.2
APOC 4.3.0.0

I have created 1,000,000 nodes and 3,000,000 relationships data.

CALL apoc.generate.ba(1000000, 3, 'Foo', 'TEST_REL_TYPE');

And I use "apoc.periodic.iterate".

CALL apoc.periodic.iterate(
"MATCH (n:Foo) RETURN n",
"DETACH DELETE n",
{batchSize:1000})

Thanks Koji, but I can't get the server restarted.

@KimPrince

Is it possible to change the parameters of neo4j.conf?
4G or 8G or 16G, etc.

dbms.memory.heap.initial_size=512m
dbms.memory.heap.max_size=1G

And Restart Neo4j.

Thanks Koji, that fixed it immediately!

It's not that the Neo4j fails to restart with a java.lang.OutOfMemoryError: Java heap space, when the database is attempting to continue the original delete query. As you think, Neo4j will not automatically resume unfinished Cypher queries after a crash. But during startup, Neo4j performs recovery tasks that will bring the store back to a consistent state. So, suppose if deleting a million records was there in the previous operation, then in that case, the recovery process itself can require substantial heap memory to handle this delete. Now the heap memory takes its place. In such cases, if the configured heap size is insufficient, the database may fail again with an OutOfMemoryError during this recovery phase.

Now, you can start with a very basic approach: increasing the JVM heap size in the Neo4j configuration and then attempting to restart the database. This typically allows the recovery process to complete successfully. After the database comes back online, you should review and properly size the heap and page cache memory according to your workload and available system RAM. If you are interested in learning about the types of OutOfMemoryError, you can check out this blog: Types of OutOfMemoryError, Causes, and Solutions. Also, You can check out this blog How to Solve OutOfMemoryError: Java heap space to understand more about this Java Heap Space error.

If increasing the heap does not resolve the issue, then you can evaluate log handling carefully or, if necessary, restore from a backup.