alexanoid
alexanoid

Reputation: 25770

Embedded Neo4j Java Heap out of space when cleaning database

I got Java Heap out of space when cleaning my Embedded Neo4j database with a following method:

public static void cleanDb(Neo4jTemplate template) {
    template.query("MATCH (n) OPTIONAL MATCH (n)-[r]-() DELETE n,r", null);
}

Right now I use following config:

GraphDatabaseService graphDb = new GraphDatabaseFactory()
                .newEmbeddedDatabaseBuilder(environment.getProperty(NEO4J_EMBEDDED_DATABASE_PATH_PROPERTY))
                .setConfig(GraphDatabaseSettings.node_keys_indexable, "name,description")
                .setConfig(GraphDatabaseSettings.node_auto_indexing, "true")
                .newGraphDatabase();

How to configure Java Heap size for Embedded Neo4j ?

Can I use setConfig(GraphDatabaseSettings.pagecache_memory, "2g") for this purpose ?

Upvotes: 0

Views: 105

Answers (1)

Martin Preusse
Martin Preusse

Reputation: 9369

Same answer as for your earlier question.

I don't know how it works with Spring Data, but in general you should try to delete nodes/relationships in batches to avoid running out of memory.

Cypher query:

MATCH (n)
WITH n LIMIT 10000
OPTIONAL MATCH (n)-[r]-()
DELETE n, r
RETURN count(n)

In your application you do:

while return_value > 0:
    run_delete_query()      

Depending on your memory you can of course increase the LIMIT.

Upvotes: 1

Related Questions