CLI Reference

This page lists every command-line entry point in the repository: the synergydb server binary with its flags and offline subcommands, and the two other binaries, synergydb-cli and synergydb-migrate. Operator procedures that use these commands are in Operations; configuration keys and environment overrides are in the configuration reference; what happens after the server starts is in Server Runtime.

Binaries

Binary Source Notes
synergydb src/main.rs Server, plus the offline subcommands passwd, backup, restore, backup-verify, encryption, audit
synergydb-cli src/bin/cli.rs Interactive prompt; every command except help and quit is a placeholder
synergydb-migrate src/bin/migrate.rs Import tool; database sources and the target writer need migrate-* features

Source: Cargo.toml, [[bin]] entries. The container image builds synergydb and synergydb-cli, not synergydb-migrate (source: Dockerfile).

clap 4.4 with the derive feature is listed as a dependency, but no source file uses it. All three binaries parse std::env::args() by hand (source: Cargo.toml, [dependencies]; src/main.rs, Args::parse; src/bin/migrate.rs, parse_args). Consequences of hand parsing, common to all of them:

  • An option that takes a value and is given last with no value is silently treated as absent.
  • There are no --opt=value forms and no combined short flags such as -dl.
  • There are no shell completions or man pages.

None of the command-line parsing has a test, and there are no tests that run the built binaries (no CARGO_BIN_EXE_* use). Not verified: everything on this page about argument handling and exit codes comes from reading the code.

synergydb (server)

Dispatch order

main does the following before parsing server flags (source: src/main.rs, main):

  1. Installs the rustls crypto provider.
  2. Enables heap counting if SYNERGYDB_MEMORY_LOG_SECS is set.
  3. Installs the tracing subscriber (RUST_LOG, default warn, stderr).
  4. If the first argument is passwd, backup, restore, backup-verify, encryption or audit, runs that subcommand with the remaining arguments and exits with its code.
  5. Raises the open-files limit, builds the tokio runtime (64 workers, 8 MiB stacks) and runs async_main. A runtime build failure exits 1.

async_main then parses the server flags and checks, in this order: --help, --version, --generate-config. The first one present runs and exits 0; the others are ignored (source: src/main.rs, async_main).

Server flags

Flag Value Effect
-c, --config <FILE> Configuration file. Overrides SYNERGYDB_CONFIG.
--generate-config   Writes the default configuration to synergydb.toml in the working directory and exits
-d, --dev   Development mode (below)
-l, --localhost   Bind address 127.0.0.1
-a, --bind-all   Bind address 0.0.0.0
-b, --bind <ADDR> Bind address as given
-v, --version   Prints SynergyDB version <version> (the crate version, 0.1.0) and exits 0
-h, --help   Prints help and exits 0

Source: src/main.rs, Args::parse, print_help, print_version.

An unrecognised argument prints Unknown argument: <arg> to stderr, then prints the help and exits 0 (source: src/main.rs, Args::parse). A script that passes a misspelt flag therefore sees success and no server.

The help text lists the subcommands passwd, backup, restore, encryption status and backup-verify. It does not list audit, encryption rewrite or encryption generate-key (source: src/main.rs, print_help).

Bind address precedence

The bind address is resolved in this order; the last step that applies wins (source: src/main.rs, async_main):

  1. [server] bind_address from the configuration file (after SYNERGYDB_<SECTION>_<KEY> overrides).
  2. The first of these that is present: --bind <ADDR>, then --localhost, then --bind-all, then --dev (which sets 127.0.0.1).
  3. SYNERGYDB_BIND_ADDRESS, which overrides every flag.

--generate-config

Calls Config::create_default("synergydb.toml"), which serialises the defaults and writes them with std::fs::write. An existing synergydb.toml in the working directory is overwritten without a prompt. On success it prints Generated default configuration: synergydb.toml to stdout and exits 0; on failure it prints the error and exits 1 (source: src/main.rs, async_main; src/config.rs, Config::create_default, Config::save). The output file name is fixed; there is no way to write elsewhere or to stdout.

--dev

Variable Set to Only if unset
SYNERGYDB_SUPERUSER postgres yes
SYNERGYDB_SUPERUSER_PASSWORD postgres yes
SYNERGYDB_DATABASE synergydb yes
SYNERGYDB_NON_INTERACTIVE 1 no, always set

It also binds to 127.0.0.1 unless another bind flag or SYNERGYDB_BIND_ADDRESS is given. It prints Username: postgres, Password: postgres, Database: synergydb even when those variables were already set to something else (source: src/main.rs, async_main).

Configuration file resolution

load_config uses the file named by -c; otherwise SYNERGYDB_CONFIG if it is not blank; otherwise ./synergydb.toml, falling back to built-in defaults if that file is absent. It prints Loaded configuration from: <path> or Using default configuration. It then applies SYNERGYDB_<SECTION>_<KEY> environment overrides, printing warnings for any it cannot apply, and runs validation. A missing explicit file, a parse error or a validation failure ends the process with exit code 1 (source: src/main.rs, load_config). The passwd, backup, restore and encryption subcommands use the same function.

Environment variables read by main

Variable Effect
RUST_LOG Log filter; default warn
SYNERGYDB_MEMORY_LOG_SECS Periodic memory log and heap counting
SYNERGYDB_CONFIG Configuration file when -c is absent
SYNERGYDB_SUPERUSER_PASSWORD Superuser password on first start
SYNERGYDB_ADMIN_PASSWORD Copied to SYNERGYDB_SUPERUSER_PASSWORD when that is unset or empty (older Helm charts)
SYNERGYDB_SUPERUSER, SYNERGYDB_DATABASE, SYNERGYDB_NON_INTERACTIVE Set by --dev if unset; read by bootstrap
SYNERGYDB_BIND_ADDRESS Bind address, overrides flags
SYNERGYDB_KAFKA_ADVERTISED_HOST Host the Kafka wire advertises; blank means unset
SYNERGYDB_DEV_INSECURE_AUTH, SYNERGYDB_TEST_AUTH_CHEAP Test switches; see the start checks below
SYNERGYDB_ALLOW_INSECURE_BIND Lets the test switches run on a non-loopback bind

Source: src/main.rs, main, async_main. The help text also lists SYNERGYDB_AUTO_CREATE_DATABASES, SYNERGYDB_<SECTION>_<KEY>, SYNERGYDB_DATA_DIR, SYNERGYDB_WAL_DIR and SYNERGYDB_SERVER_PROTECTED_MODE, which are read elsewhere; see the configuration reference. Per-wire variables are in Connection Handling and diagnostic variables in Observability Internals.

Start checks

When the bind address is not loopback (localhost or a loopback IP):

  • If SYNERGYDB_DEV_INSECURE_AUTH or SYNERGYDB_TEST_AUTH_CHEAP is 1 or true, protected mode is on, and SYNERGYDB_ALLOW_INSECURE_BIND is not 1 or true, the server prints a FATAL line and exits 1.
  • If SYNERGYDB_SUPERUSER_PASSWORD is one of CHANGE_ME, CHANGE_ME_IN_PRODUCTION, changeme or CHANGEME, the server prints a FATAL line and exits 1.

Source: src/main.rs, async_main.

Exit codes

Code When
0 --help, --version, an unknown argument, successful --generate-config, or a normal shutdown after SIGINT or SIGTERM
1 runtime build failure, configuration load or validation failure, --generate-config write failure, either start check above, Server::start failure

Source: src/main.rs, main, async_main. Signal handling is described in Server Runtime.

synergydb passwd

Sets a role's password offline, with the server stopped.

synergydb passwd [-c FILE] [-U USER] [--password-stdin] [-h]
Option Effect
-c, --config <FILE> Configuration, resolved as for the server
-U, --user <USER> Role to change. Default: the first role that is both superuser and login.
--password-stdin Read one line from stdin as the new password (trailing \r\n removed)
-h, --help Help, exit 0

Source: src/main.rs, run_passwd, passwd_on_open_store.

Behaviour:

  • Refuses (exit 1) if <data_dir>/MANIFEST is missing, with no SynergyDB data directory at <dir> (no MANIFEST). Check --config. This prevents a mistyped config from creating a fresh store.
  • Opening the store takes the data-directory lock (LOCK, LOCK.pid), so the command fails while a server holds that directory (source: src/storage/mod.rs, acquire_data_dir_lock; test second_engine_on_same_data_dir_is_refused_while_first_is_open).
  • Refuses if the catalog is not bootstrapped, if there is no terminal and no --password-stdin, if the role does not exist (it lists the login roles), or if the role is NOLOGIN.
  • With a terminal, prompts for the role (default as above) and for the password with confirmation, using the dialoguer crate.
  • The password must be at least 8 characters (MIN_PASSWORD_LEN) and must not equal the role name, ignoring case (source: src/catalog/credentials.rs, validate_password). Interactive entry re-prompts on a rejected password; --password-stdin exits 1.
  • Deletes <data_dir>/initial_superuser_password if that file held the old password.
  • Syncs, flushes and shuts the store down before exiting, whatever the WAL sync mode.

Unknown argument: prints passwd: unknown argument: <arg>, the help, and exits 1. Exit codes: 0 success, 1 any failure.

synergydb backup

synergydb backup [-c FILE] --to <DIR> [-h]

Takes a full offline backup with BackupManager::create_backup(BackupOptions::full()). --to is required. It fails if <data_dir>/MANIFEST is missing or <DIR> already exists, and creates the parent of <DIR>. The parent directory becomes the backup root and holds BACKUP_CATALOG. It prints the backup id, type, sequence number, and counts of SSTables, WAL files and bytes (source: src/backup_cmd.rs, run_backup). The help text points to POST /api/v1/backups for online backups. Exit codes: 0 success, 1 failure.

synergydb restore

synergydb restore [-c FILE] --from <BACKUP_DIR | BACKUP_ROOT> [--force] [--to-backup <ID>] [--to-sequence <N>] [-h]
Option Effect
--from A single backup directory (contains BACKUP_METADATA) or a backup root (contains BACKUP_CATALOG)
--force Restore even if the data directory has a MANIFEST or the WAL directory is not empty
--to-backup <ID> Restore the chain up to this backup
--to-sequence <N> Point-in-time restore to this sequence number. A non-numeric value prints --to-sequence needs a number and exits 1.

Source: src/backup_cmd.rs, run_restore.

The command takes the data-directory lock first. A single backup given without --to-backup or --to-sequence is restored with BackupManager::restore with checksum verification. Otherwise it runs a chain restore with restore_pitr from the root (the parent of a single backup directory, or the directory that holds BACKUP_CATALOG). It then opens the store to replay the WAL and prints restore complete ... next sequence <N>. Exit codes: 0 success, 1 failure.

Tests (library): backup_restores_runtime_flushed_and_wal_only_data, restore_chain_never_selects_full_backup_taken_after_target, pitr_restores_to_sequence_cutoff_not_beyond, restore_refuses_backup_missing_listed_sstable, incremental_refuses_when_parent_wal_was_reclaimed, create_backup_registers_full_in_catalog_for_incrementals, wal_retention_reclaims_but_keeps_backup_chain, test_backup_catalog, test_backup_catalog_retention (source: src/storage/backup.rs, tests). These exercise BackupManager, not the command-line wrapper.

synergydb backup-verify

synergydb backup-verify <BACKUP_DIR>
synergydb backup-verify --list <BACKUP_ROOT>

Checks a backup against its recorded checksums, or lists the backups in a root. It prints backup OK and exits 0, or backup DAMAGED and exits 1. With no target it prints help and exits 1; a second positional argument prints unexpected argument and exits 1 (source: src/backup_cmd.rs, run_verify).

synergydb encryption

synergydb encryption <status | rewrite | generate-key | help> [-c FILE] [--path DIR]... [-q] [-h]

The first argument is always the subcommand; options follow it.

Subcommand Effect
generate-key Prints a random 32-byte key as 64 hex characters on stdout, and its fingerprint on stderr
status Read-only audit of every file in the data directory, the WAL directory, <data_dir>/raft/* and each --path directory: counts encrypted, plaintext, mixed, metadata and unreadable files, and files per key fingerprint
rewrite With the server stopped and MANIFEST present, re-encrypts SSTables under the active key and removes flushed WAL segments
help, empty, -h, --help Help, exit 0
Option Effect
-c, --config <FILE> Configuration
--path <DIR> Extra directory to audit; may be repeated
-q, --quiet Less output from status

Keys come from SYNERGYDB_ENCRYPTION_KEY (active), SYNERGYDB_ENCRYPTION_RETIRED_KEYS, and [storage] encryption_key_file (one key per line; the first is active) (source: src/storage/at_rest.rs; src/encryption_cmd.rs, run, status, rewrite).

Exit code Meaning
0 status: every data-bearing file is encrypted under a configured key; other subcommands: success
1 configuration or key load failure, unknown option or subcommand, rewrite failure
2 status: plaintext or mixed files found, or encryption disabled
3 status: files sealed under a key that is not configured, unreadable files, or the key check failed

Source: src/encryption_cmd.rs, run, status. Tests (library): disabled_means_no_keys, enabled_without_key_fails_closed, repeated_byte_key_is_refused, env_active_plus_retired_and_file, retired_ring_opens_old_blobs_and_reports_fingerprint, purpose_is_bound (source: src/storage/at_rest.rs, tests). Security context is in Security.

synergydb audit

synergydb audit verify [-c FILE] [--path AUDIT_LOG] [--json] [--expect-head SEQ:HASH]
synergydb audit generate-key
synergydb audit help
Subcommand or option Effect
verify Checks the hash chain (and HMAC, when a key is configured) of the audit log
generate-key Prints a random 32-byte key in hex on stdout and key id: <id> on stderr
-c, --config <FILE> Loads the file with Config::load directly, without environment overrides or validation
--path <AUDIT_LOG> Audit log location, instead of the configured one
--json Machine-readable result
--expect-head <SEQ>:<HASH> Also require the chain head to match; a malformed value exits 3

The HMAC key comes from SYNERGYDB_AUDIT_KEY, else [audit] key_file (source: src/audit_cmd.rs, run, verify).

Exit code Meaning
0 chain intact
2 tampering or damage detected, including finding no records
3 read, key or usage error, unknown option or subcommand

Because the first argument is taken as the subcommand, synergydb audit -h reports unknown audit command "-h" and exits 3. synergydb audit help, synergydb audit alone, or -h after a subcommand print the help and exit 0 (source: src/audit_cmd.rs, run).

Tests (library): intact_chain_verifies, reopen_continues_the_chain, edited_record_is_detected, deleted_record_is_detected, reordered_records_are_detected, hmac_chain_needs_the_key_and_rejects_a_forgery, torn_tail_is_recovered_and_recorded, rotation_keeps_one_chain, deleting_the_oldest_segment_outside_retention_is_caught, retention_prunes_old_segments_and_records_it, six_year_default_retention_keeps_five_year_old_segments (source: src/auth/audit_chain.rs, tests).

Subcommand exit codes at a glance

Command 0 1 2 3
server help, version, unknown argument, clean shutdown start or config failure    
passwd success any failure    
backup, restore success any failure    
backup-verify backup OK backup DAMAGED, usage error    
encryption success, all encrypted config, key or usage error plaintext found or encryption off unknown key or unreadable
audit intact, help   tampered or empty read, key or usage error

synergydb-cli

Not wired: an interactive placeholder. It takes no options and ignores all arguments. It prints SynergyDB CLI v<version> and reads lines at the prompt synergydb> (source: src/bin/cli.rs, main).

Input Response
quit, exit, \q prints Goodbye! and exits
help, \? command list
\c <host>, connect <host> Connecting to <host>... then (Connection not yet implemented)
\d... (Schema listing not yet implemented)
anything else (Query execution not yet implemented)

End of input also exits. The exit code is always 0. Input is lower-cased before matching (source: src/bin/cli.rs, main). Options used elsewhere in the repository, --metrics-export in deploy/swarm/synergydb-stack.yml, and --command and --host in the June book, do not exist. To run SQL from a shell, use a PostgreSQL or MySQL client against the wire ports.

synergydb-migrate

Imports data from an external source. Workflow and caveats are in Migration.

synergydb-migrate [OPTIONS] [SOURCE]
Option Value Default Effect
-s, --source URL or path   Source; a bare argument is also taken as the source if none is set yet
-n, --name name   Migration name
-t, --tables comma list all Tables to include
-e, --exclude comma list none Tables to exclude
-r, --resume id   Resume (see below)
-l, --list     List migrations in the state directory
--status id   Print a migration's state file
-b, --batch-size N 10000 Rows per batch; an unparsable value gives 10000
-v, --verify none, rowcount, checksum rowcount Verification mode; any other value warns and uses rowcount. -v is not version here.
-d, --dry-run   off Do not write
--state-dir dir .synergydb/migrations Where state JSON files live
--target PostgreSQL-wire URL none Target SynergyDB server
-V, --verbose   off Prints a banner
-h, --help     Help, exit 0

Source: src/bin/migrate.rs, parse_args, print_help. Unrecognised options are not reported: the first one is taken as the source if no source is set, and the rest are ignored.

Order and behaviour

main checks --list, then --status, then --resume, then starts a new migration. Only the first one that applies runs (source: src/bin/migrate.rs, main).

  • Dry run is on when --dry-run is given or --target is absent. The run then goes through NoOpTarget (source: src/bin/migrate.rs, run_migration).
  • Target. With --target, a binary built with migrate-postgres writes through PgTarget; without that feature it prints a warning and uses NoOpTarget.
  • Engine settings. parallel_tables is 1, and checkpoint_interval is the larger of the batch size and 1000.
  • --resume. Not wired: checks that <state_dir>/<id>.json exists, prints progress messages, and stops without migrating anything (source: src/bin/migrate.rs, resume_migration).

Source detection

Source string Type Needs feature
postgres://, postgresql:// PostgreSQL migrate-postgres
mysql://, mariadb:// MySQL migrate-mysql
mongodb:// MongoDB migrate-mongodb
sqlite://, *.sqlite, *.db SQLite migrate-sqlite
*.csv CSV none
*.json JSON none
*.parquet Parquet no source exists; the error suggests --features migrate-all, which does not add one
anything else Unknown error Unsupported source type

Source: src/bin/migrate.rs, detect_source_type, run_migration. A type whose feature is not compiled in fails with Source type <T> not compiled in (rebuild with --features migrate-<x>). migrate-couchdb exists as a feature but the binary has no CouchDB detection (source: Cargo.toml, [features]). migrate-all and full enable all migrate features.

Exit codes

Code When
0 success, --help, --list, --status found, --resume found
1 no source, --status or --resume id not found, unreadable state file, tokio runtime failure, migration failure (including unsupported or uncompiled source)

Source: src/bin/migrate.rs, main, show_migration_status, resume_migration, start_migration.

Defects

  • The binary's own sanitize_connection removes the user name together with the password: postgres://user:pass@host is printed as postgres://:***@host (source: src/bin/migrate.rs, sanitize_connection). The separate function of the same name in src/migrate/state.rs is the one covered by test_sanitize_connection, which checks only that the password is hidden.
  • The --verbose banner claims "100% data cohesiveness"; Migration records end-to-end runs as not verified.

Tests for the migration library include test_verification_detects_target_side_row_loss, test_verification_passes_when_target_holds_all_rows, test_verification_strategy_none_skips, test_verification_dry_run_is_explicit_about_unqueried_target, test_migration_state and test_sanitize_connection (source: src/migrate/engine.rs, src/migrate/state.rs, tests). None runs the binary.

Build features that change the binaries

Feature Default Effect on commands
postgres-wire, rest-api, grpc yes Server wires
system-allocator no Uses the system allocator instead of mimalloc
migrate-postgres, migrate-mysql, migrate-sqlite, migrate-mongodb, migrate-couchdb no Migration sources; migrate-postgres also enables the migrate target
migrate-all no All of the above migrate features
full no All wires and migrate-all

Source: Cargo.toml, [features]. Build commands are in Building.