1
votes

MAX OS X 10.11.6, neo4j 3.2.0

a simple query in a database without relations (relations were deleted with MATCH ()-[a]-() delete a);

The setup:

match ()-[a]-() return count(a);

+----------+
| count(a) |
+----------+
| 576333   |
+----------+

Then I wish to clean up the database:

match (a) delete a;

and after 5 minutes I get

There is not enough memory to perform the current task. Please try increasing 'dbms.memory.heap.max_size' in the neo4j configuration (normally in 'conf/neo4j.conf' or, if you you are using Neo4j Desktop, found through the user interface) or if you are running an embedded installation increase the heap by using '-Xmx' command line flag, and then restart the database.

However, this helps:

MATCH (n) with n limit 100000 delete (n) ;

0 rows available after 302 ms, consumed after another 0 ms

Deleted 100000 nodes

Could someone comment such behavior of the DATABASE? Is this a bug or a feature?

1

1 Answers

2
votes

Firstly, if you want to delete all your data, please consider to use DETACH DELETE instead of the DELETE command.

This will delete all relationships of your nodes, and then delete the node. Otherwise with MATCH (n) with n limit 100000 delete (n) you will only delete orphan nodes.

All data modifications in a transaction are kept in memory. So if you try to delete 10G of data at once, you will need 10G of RAM.

To avoid to add some memory to the java heap for resolving this problem, you have to batch your operations.

One way, is to repeat this query until its result is 0 : MATCH (n) WITH n LIMIT 100000 DETACH DELETE n RETURN count(*).

There is some helpers on the APOC project that can help you to do it like apoc.periodic.commit. Take a look here : https://neo4j-contrib.github.io/neo4j-apoc-procedures/#_further_functions

Cheers