12

Is there any way I can remove all data in a single database while RavenDB is still running, hosting other databases?

In a production environment with RavenDB hosting multiple databases for different customers, it is not acceptable to stop RavenDB in order to delete the data from a single database. Would it be necessary to custom develop a tool, at delete documents individually to achieve this?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Stephan Møller
  • 1,247
  • 19
  • 39

3 Answers3

10

If you delete the document that describes the database then you have prevented access to it. RavenDB doesn't provide a way to actually delete the database, but the database would be shut down if you delete the document describing it. You can then delete the database directory, or back it up, according to your needs.

Andy Rose
  • 16,770
  • 7
  • 43
  • 49
Ayende Rahien
  • 22,925
  • 1
  • 36
  • 41
  • Im not sure, if I got you right. I can delete the describing document and afterwards, ravenDB will remove its locks on the associated database files, and I will be able to delete the database file manually then? – Stephan Møller Aug 17 '11 at 20:08
  • 1
    How do you delete the document that describes the database? Is there documentation for this somewhere? – Mike Jul 03 '12 at 02:52
  • Go to the default database, you'll see the document in there. – John Fisher Oct 08 '12 at 02:44
6

In version 2.0.3 (maybe even in releases before) the studio is calling the following http endpoint in order to delete a database:

/admin/databases/nameOfYourDatabase?hard-delete=true
?hard-delete=true is optional.

Based on the source code from the studio I have created this function:

    public void DeleteDatabase(string name, bool hardDelete = false)
    {
        if (string.IsNullOrEmpty(name))
            throw new ArgumentNullException("name");

        var databaseCommands = _documentStore.DatabaseCommands;
        var relativeUrl = "/admin/databases/" + name;

        if (hardDelete)
            relativeUrl += "?hard-delete=true";

        var serverClient = databaseCommands.ForSystemDatabase() as ServerClient;
        if (serverClient == null)
            throw new ApplicationException("Please use a more intelligent exception here");

        var httpJsonRequest = serverClient.CreateRequest("DELETE", relativeUrl);
        httpJsonRequest.ExecuteRequest();
    }
ms007
  • 4,661
  • 3
  • 28
  • 31
1

I want to update your solution, that are the only solution for "deleting" a database.

Actually in the new version (2.0) of RavenDB, which are still unstable, you can delete a database with the new version of the studio.

You can download it from here: http://hibernatingrhinos.com/builds/ravendb-unstable-v2.0/

I'll hope this help you aditionally to the Ayende good answer.

Best, Dario

rdarioduarte
  • 1,929
  • 2
  • 21
  • 29