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

**URL:** <https://community.neo4j.com/t/whats-the-correct-way-to-remove-old-db-and-start-a-fresh-one/19976>\
**Category:** Neo4j Graph Platform\
**Created:** [June 13, 2020, 2:09pm UTC](https://community.neo4j.com/t/whats-the-correct-way-to-remove-old-db-and-start-a-fresh-one/19976 "2020-06-13T14:09:58Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rogie](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/rogie/32/3913_2.png) [@Rogie](https://community.neo4j.com/u/Rogie)\
**Post date:** [June 13, 2020, 2:09pm UTC](https://community.neo4j.com/t/whats-the-correct-way-to-remove-old-db-and-start-a-fresh-one/19976/1 "2020-06-13T14:09:58Z")

</div>

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

```auto
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?

---

<div class="post-metadata">

**Author:** ![Cobra](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/cobra/32/35243_2.png) [@Cobra](https://community.neo4j.com/u/Cobra)\
**Post date:** [June 13, 2020, 2:14pm UTC](https://community.neo4j.com/t/whats-the-correct-way-to-remove-old-db-and-start-a-fresh-one/19976/2 "2020-06-13T14:14:33Z")

</div>

Hello @Rogie 🙂

With apoc:

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

```

Regards,  
Cobra

---

<div class="post-metadata">

**Author:** ![Rogie](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/rogie/32/3913_2.png) [@Rogie](https://community.neo4j.com/u/Rogie)\
**Post date:** [June 13, 2020, 3:14pm UTC](https://community.neo4j.com/t/whats-the-correct-way-to-remove-old-db-and-start-a-fresh-one/19976/3 "2020-06-13T15:14:58Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Cobra](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/cobra/32/35243_2.png) [@Cobra](https://community.neo4j.com/u/Cobra)\
**Post date:** [June 13, 2020, 3:18pm UTC](https://community.neo4j.com/t/whats-the-correct-way-to-remove-old-db-and-start-a-fresh-one/19976/4 "2020-06-13T15:18:48Z")

</div>

How many nodes and relationships do you have?

Did you put index on them?

---

<div class="post-metadata">

**Author:** ![Rogie](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/rogie/32/3913_2.png) [@Rogie](https://community.neo4j.com/u/Rogie)\
**Post date:** [June 13, 2020, 3:24pm UTC](https://community.neo4j.com/t/whats-the-correct-way-to-remove-old-db-and-start-a-fresh-one/19976/5 "2020-06-13T15:24:18Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Cobra](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/cobra/32/35243_2.png) [@Cobra](https://community.neo4j.com/u/Cobra)\
**Post date:** [June 13, 2020, 3:28pm UTC](https://community.neo4j.com/t/whats-the-correct-way-to-remove-old-db-and-start-a-fresh-one/19976/6 "2020-06-13T15:28:21Z")

</div>

Do you have enough RAM and a good processor?

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

Regards,  
Cobra

---

<div class="post-metadata">

**Author:** ![Rogie](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/rogie/32/3913_2.png) [@Rogie](https://community.neo4j.com/u/Rogie)\
**Post date:** [June 13, 2020, 3:29pm UTC](https://community.neo4j.com/t/whats-the-correct-way-to-remove-old-db-and-start-a-fresh-one/19976/7 "2020-06-13T15:29:25Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Cobra](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/cobra/32/35243_2.png) [@Cobra](https://community.neo4j.com/u/Cobra)\
**Post date:** [June 13, 2020, 3:44pm UTC](https://community.neo4j.com/t/whats-the-correct-way-to-remove-old-db-and-start-a-fresh-one/19976/8 "2020-06-13T15:44:44Z")

</div>

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

You just need to wait 😕

---

<div class="post-metadata">

**Author:** ![Rogie](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/rogie/32/3913_2.png) [@Rogie](https://community.neo4j.com/u/Rogie)\
**Post date:** [June 13, 2020, 3:59pm UTC](https://community.neo4j.com/t/whats-the-correct-way-to-remove-old-db-and-start-a-fresh-one/19976/9 "2020-06-13T15:59:19Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Cobra](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/cobra/32/35243_2.png) [@Cobra](https://community.neo4j.com/u/Cobra)\
**Post date:** [June 13, 2020, 4:06pm UTC](https://community.neo4j.com/t/whats-the-correct-way-to-remove-old-db-and-start-a-fresh-one/19976/10 "2020-06-13T16:06:54Z")

</div>

I know there is [hardware sizing](https://neo4j.com/hardware-sizing/) but I never test it 🙂

---

<div class="post-metadata">

**Author:** ![stugorf](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/stugorf/32/5191_2.png) [@stugorf](https://community.neo4j.com/u/stugorf)\
**Post date:** [June 24, 2020, 5:53pm UTC](https://community.neo4j.com/t/whats-the-correct-way-to-remove-old-db-and-start-a-fresh-one/19976/11 "2020-06-24T17:53:31Z")

</div>

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>` .

---

<div class="post-metadata">

**Author:** ![ofer.bar](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/ofer.bar/32/7850_2.png) [@ofer.bar](https://community.neo4j.com/u/ofer.bar)\
**Post date:** [June 25, 2020, 12:34pm UTC](https://community.neo4j.com/t/whats-the-correct-way-to-remove-old-db-and-start-a-fresh-one/19976/12 "2020-06-25T12:34:19Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![emigre459](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/emigre459/32/15117_2.png) [@emigre459](https://community.neo4j.com/u/emigre459)\
**Post date:** [April 15, 2021, 12:14am UTC](https://community.neo4j.com/t/whats-the-correct-way-to-remove-old-db-and-start-a-fresh-one/19976/13 "2021-04-15T00:14:45Z")

</div>

To be clear, this solution only works for Enterprise Edition.
