Deleting all nodes and relationships in neo4j using cypher exceeds heap space

后端 未结 6 1631
失恋的感觉
失恋的感觉 2021-02-05 20:50

I have been trying to run this query as recommended in the neo4j google group and in other sources online:

START n = node(*) MATCH n-[r?]-() WHERE ID(n)>0 DELETE n, r;

6条回答
  •  借酒劲吻你
    2021-02-05 20:57

    The cypher statement above causes all nodes (besides the root node with ID 0) to be instantiated before deletion in one single transaction. This eats up too much memory when done with 500k nodes.

    Try to limit the number of nodes to delete to something around 10k-50k, like e.g.:

    START n = node(*) 
    MATCH n-[r?]-() 
    WHERE (ID(n)>0 AND ID(n)<10000) 
    DELETE n, r;
    
    START n = node(*) 
    MATCH n-[r?]-() 
    WHERE (ID(n)>0 AND ID(n)<20000) 
    DELETE n, r;
    

    etc.

    However, there's nothing wrong with removing the entire database directory, it's good practice.

提交回复
热议问题