Is there any fast way to remove all data from the local database? Like SQL 'drop database'?
I was looking through the documentation but haven't found anythig interesting yet.
Is there any fast way to remove all data from the local database? Like SQL 'drop database'?
I was looking through the documentation but haven't found anythig interesting yet.
You can do this by clearing the entire range of keys.
In Python, it looks like this:
Database.clear_range('', '\xFF')
Where '' is the default slice begin, and '\xFF' is the default slice end, according to the clear_range
documentation.
You can find the more information on clear_range for the API you're using in the documentation.
The "CLI" way
Using the provided fdbcli
interface, you can clear all the keys in the database using a single clearrange
command, like this:
fdb> writemode on
fdb> clearrange "" \xFF
Committed (68666816293119)
Be warned that it executes instantly and that there is no undo possible!
Also, any application still connected to the database may continue reading/writing data using cached directory subspace prefixes, which may introduce data corruption! You should make sure to only use this method when nothing is actively using the cluster.
This method requires that your cluster be in a working state, and it will not immediately reclaim the space used on disk, and also will not reset the cluster's read version.
The "hard" way
If you have a single-node cluster, you can stop the fdb service, remove all files in its data_dir
folder, restart the service, and then using fdbcli
, execute the configure new single ssd
command.
This will reclaim the disk space used previously, and reset everything back to the post-install state.
create new single ssd
command." That should be " execute the configure new single ssd
command" –
Pamphylia You can do this by clearing the entire range of keys.
In Python, it looks like this:
Database.clear_range('', '\xFF')
Where '' is the default slice begin, and '\xFF' is the default slice end, according to the clear_range
documentation.
You can find the more information on clear_range for the API you're using in the documentation.
public void clearDB() { db.run(new Function<Transaction, Void>() { public Void apply(final Transaction tr) { tr.clear(new Range(Tuple.from("").pack(), Tuple.from("xFF").pack())); return null; } }); }
–
Confabulation To do this programmatically in Java:
db.run(tx -> {
final byte[] st = new Subspace(new byte[]{(byte) 0x00}).getKey();
final byte[] en = new Subspace(new byte[]{(byte) 0xFF}).getKey();
tx.clear(st, en);
return null;
});
© 2022 - 2024 — McMap. All rights reserved.
public void clearDB() { db.run(new Function<Transaction, Void>() { public Void apply(final Transaction tr) { tr.clear(new Range(Tuple.from("").pack(), Tuple.from("xFF").pack())); return null; } }); }
– Confabulation