Skip to content

Statements

/

ALTER

ALTER NAMESPACE

Available since: v3.0.0

The ALTER NAMESPACE statement can be used to modify the namespace. ALTER NAMESPACE is used on the current namespace, which is why a IF EXISTS clause does not exist.

SurrealQL Syntax
ALTER NAMESPACE COMPACT

Performs storage compaction on the current namespace keyspace. To compact other resources, use ALTER SYSTEM to compact the entire datastore, ALTER DATABASE to compact the current database keyspace, or ALTER TABLE to compact a specific table keyspace.

The storage engine carries out the compaction. In SurrealDB 4.0, SurrealKV supports it: it writes recent changes to disk, merges the data files that hold the keys, and drops deleted data and old versions that no reader can see, which frees their space. The statement returns once the compaction is done, and reads and writes carry on meanwhile. Before 4.0, RocksDB was the only engine that supported compaction requests. The in-memory engine and TiKV do not support them, and return the following error:

'There was a problem with the key-value store: The storage layer does not support compaction requests.'

A successful compaction returns NONE.

ALTER NAMESPACE COMPACT;
Output
NONE

Was this page helpful?