Article DetailsDetailsHelp DetailsWhen deleting a large number of nodes (1000+), or dense nodes it's important to stagger the delete operations not to overwhelm the AuraDB Instance.If you intend to wipe a database completely, see How to wipe out / delete all the content in a Neo4j AuraDB Instance ? You may have used a simple query (see below). Do not use this statement for a large data set as this is not suited for large data set, as mentioned in the documentation. MATCH (n) DETACH DELETE(n) The main issue of the above command is that it first loads all the nodes and consumes a large amount of memory. DETACH DELETE on Dense Nodes: Deleting dense nodes could have a cascading effect:Even a small number of nodes may have thousands (or more) relationships. Deleting these relationships in bulk can lead to: Lock contention in the database.High memory consumption for maintaining the transaction state.Increased write amplification, especially in a dense graph. SOLUTIONS For Dense nodes, please use an even smaller batch size Non-Cypher-Based Solution (Professional Tier) If you wanted to clear the database instance completely rather than remove a number of nodes. You can use the "Reset to blank" option available in the Neo4j Aura console. Please refer to How to wipe out / delete all the content in a Neo4j AuraDB Instance for details on how to do this. Cypher Based Solutions Using CALL {} IN TRANSACTIONS Since 4.4 the best way to achieve that same efficiency is to make use of CALL {} IN TRANSACTIONS.Because of the way graphs are stored, the best approach is to delete the relationships first and then delete the nodes in separate operations. // Delete all relationships MATCH ()-[r]->() CALL { WITH r DELETE r } IN TRANSACTIONS OF 50000 ROWS; // Delete all nodes MATCH (n) CALL { WITH n DETACH DELETE n } IN TRANSACTIONS OF 50000 ROWS;Starting from Neo4j 5.23, the above syntax has been deprecated hence the following syntax should be used: // Delete all relationshipsMATCH ()-[r]->() CALL (r) { DELETE r } IN TRANSACTIONS OF 50000 ROWS; // Delete all nodesMATCH (n) CALL (n) { DETACH DELETE n } IN TRANSACTIONS OF 50000 ROWS; NOTE: If you encounter the error below while running queries from the Neo4j Browser, please prefix the Cypher statements above with :auto. A query with 'CALL { ... } IN TRANSACTIONS' can only be executed in an implicit transaction, but tried to execute in an explicit transaction. Using APOC.PERIODIC.ITERATE with a list of IDs (nodes and/or relationships) Aura has some safeguards for its query memory, and from versions greater than 4.x you should use this improved method instead. If you have dense nodes, it may be more efficient to delete separately, starting with the relationships first and then proceeding with the nodes to avoid any contention/locking; // Delete all relationships CALL apoc.periodic.iterate( 'MATCH ()-[r]->() RETURN id(r) AS id', 'MATCH ()-[r]->() WHERE id(r)=id DELETE r', {batchSize: 5000}); // Delete all nodes CALL apoc.periodic.iterate( 'MATCH (n) RETURN id(n) AS id', 'MATCH (n) WHERE id(n)=id DELETE n', {batchSize: 5000}); InformationTitleDeleting large numbers of nodes.Article Created Date3/15/2024, 10:57 PMURL Name360059882854-Deleting-large-numbers-of-nodesLast Modified Date10/28/2026, 5:52 PM