# CLI

The SlateDB Admin CLI provides an interface for managing and maintaining SlateDB databases. It enables direct interaction with SlateDB manifests, checkpoints, and garbage collector.

## Installation

You can install the SlateDB CLI using Cargo. Run:

```
cargo install --locked slatedb-cli
```

Alternatively, build from source by cloning the repository and compiling the CLI:

```
git clone https://github.com/slatedb/slatedb.git
cd slatedb
cargo build --release -p slatedb-cli
```

The resulting binary will be available at `target/release/slatedb`.

## Setup

The CLI requires environment variables to configure access to your object store. You can set these variables in your shell environment or provide them via a `.env` file using the `--env-file` option. The required variables depend on your object store provider. See [admin.rs](https://github.com/slatedb/slatedb/blob/main/slatedb/src/admin.rs) for details.

Every command requires the `--path` option, which specifies the root directory in your object store.

## Usage

Run the CLI with `slatedb --help` to see a list of available commands and options.

## Run the standalone compactor

Run compaction as a standalone process (instead of inside your `Db` clients):

```bash
slatedb --env-file .env --path <db-path> run-compactor
```

The compactor runs until interrupted (Ctrl-C), then shuts down gracefully.

:::note

The compactor expects the database to already exist (a manifest must be present). If you're creating a new database, open it once before starting the compactor.

:::

See [Run a Standalone Compactor](/docs/tutorials/standalone-compactor/) for how to disable the embedded compactor in your database clients.

## Run the standalone garbage collector

Run garbage collection as a standalone process (instead of inside your `Db` clients).

For a single foreground pass over one file type, use `run-garbage-collection`:

```bash
slatedb --env-file .env --path <db-path> run-garbage-collection \
  --resource compacted \
  --min-age 5m
```

Valid resources are `manifest`, `wal`, `wal-fence`, `compacted`, and `compactions`.

To run garbage collection on a schedule in a standalone process, pass one or more schedules:

```bash
slatedb --env-file .env --path <db-path> schedule-garbage-collection \
  --manifest min_age=5m,period=1m \
  --wal min_age=5m,period=1m \
  --compacted min_age=5m,period=1m \
  --compactions min_age=5m,period=1m
```

The scheduled process runs until interrupted (Ctrl-C), then shuts down gracefully.

Pass `--disable-boundary-files` to `run-garbage-collection` or
`schedule-garbage-collection` to delete eligible manifest and compactions metadata without
advancing boundary files. Use the same setting for every garbage collector operating on the
database.

:::note

The garbage collector expects the database to already exist (a manifest must be present). If you're creating a new database, open it once before starting the garbage collector.

:::

See [Run a Standalone Garbage Collector](/docs/tutorials/standalone-garbage-collector/) for how to disable the embedded garbage collector in your database clients.
