What's the correct way to remove old db and start a fresh one?

I don't know what the correct way to start an empty db. I know that I can remove all nodes and relations by doing

match (n)  
with n limit 10000  
DETACH DELETE n;

over and over again until everything is gone, but this is not reasonable to do on a huge database.

Is there not a simpler way to remove everything?

Hello @Rogie :slight_smile:

With apoc:

CALL apoc.periodic.iterate('MATCH (n) RETURN n', 'DETACH DELETE n', {batchSize:1000, iterateList:true})

Regards,
Cobra

Trying this now, but it seems extremely slow. Has been running for an hour and still not complete.

How many nodes and relationships do you have?

Did you put index on them?

Around 10 million nodes. Each type has a uniqueness constraint for some attribute.

Do you have enough RAM and a good processor?

The request I gave you is the fastest one to delete everything in the database :slight_smile:

Regards,
Cobra

How long should I expect it to take? There are 8GiB of ram on the system.

To be honest I don't know, 8Go looks small for a database with 10 millions nodes :confused:

You just need to wait :confused:

How much RAM do you suggest to have in this case?

I know there is hardware sizing but I never test it :slight_smile:

Hi @Rogie,

If you are using Neo4j 4.x you can switch to the system database using :use system and then run drop database <database_name> Then to create a new empty database run create database <database_name> .

1 Like

Why not simply create a new database?
Anyway, if you insist on deleting the objects don't forget to erase the indexes and constraints (schema). Just look up the command I don't remember the syntax.