Delete a single ravendb database while ravendb is running hosting other databases
Asked Answered
S

3

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?

Savona answered 17/8, 2011 at 10:4 Comment(0)
F
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.

Fact answered 17/8, 2011 at 18:56 Comment(3)
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?Crease
How do you delete the document that describes the database? Is there documentation for this somewhere?Charlean
Go to the default database, you'll see the document in there.Pretoria
M
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();
    }
Mersey answered 28/3, 2013 at 10:9 Comment(0)
U
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

Unsupportable answered 25/1, 2013 at 14:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.