Capture PRO#

The capture command connects to a database, takes a baseline snapshot of query statistics, then waits for you to press Ctrl+C. When you stop it, it takes a second snapshot, diffs the two, and generates an edg workload config that approximates the workload observed during the capture window.

edg capture \
  --driver pgx \
  --flavour cockroachdb \
  --url "postgres://root@localhost:26257/movr?sslmode=disable" \
  --name workload
# run your application workload, then press Ctrl+C to stop capturing

This always writes both workload.yaml and workload.edg.

Flags#

FlagRequiredDefaultDescription
--flavourYesDatabase flavour: postgres or cockroachdb
--nameYesOutput file or path without extension (writes both .yaml and .edg; parent directories are created if needed)
--driverYespgxDatabase driver
--urlYesConnection URL for the source database
--min-callsNo10Minimum call count to include a query
--topNo50Maximum number of queries to include
--schemaNoSchema or database name to introspect for up/down DDL
--databaseNoAlias for --schema

Generated Config#

The generated config includes:

  • run_weights - proportional to observed call counts so the workload mix matches production.
  • run - each frequently-executed query as a run item, with wait durations derived from inter-arrival times.
  • up - (when --schema or --database is set) CREATE TABLE statements derived from the database’s own DDL, topologically sorted so parent tables are created before children. Uses the same schema introspection as the init command.
  • down - (when --schema or --database is set) DROP TABLE IF EXISTS statements in reverse dependency order.

Query parameters are set to TODO placeholders. Replace them with expressions that match your actual data distributions.

Schema introspection#

When --schema or --database is provided, capture inspects the target schema and adds up and down sections to the output. This uses the same introspection logic as the init command, reading the database’s own DDL and sorting tables by foreign key dependencies.

This lets the generated config create and tear down the schema as part of a self-contained workload, without needing a separate init run.

edg capture \
  --driver pgx \
  --flavour cockroachdb \
  --url "postgres://root@localhost:26257/movr?sslmode=disable" \
  --schema public \
  --name workload

Without --schema, the output contains only run_weights and run - suitable for replaying against an existing database that already has the schema in place.

Examples#

Basic capture (CockroachDB)#

edg capture \
  --driver pgx \
  --flavour cockroachdb \
  --url "postgres://root@localhost:26257/movr?sslmode=disable" \
  --min-calls 100 \
  --top 20 \
  --name workload
# press Ctrl+C after the desired capture window

Capture with schema DDL#

edg capture \
  --driver pgx \
  --flavour cockroachdb \
  --url "postgres://root@localhost:26257/movr?sslmode=disable" \
  --schema public \
  --min-calls 100 \
  --top 20 \
  --name workload
# press Ctrl+C after the desired capture window

This produces two files:

  • workload.yaml - YAML config with run_weights, run, and (when --schema is set) up and down
  • workload.edg - the same config in edg-lang format

PostgreSQL#

edg capture \
  --driver pgx \
  --flavour postgres \
  --url "postgres://user:pass@localhost:5432/mydb?sslmode=disable" \
  --schema public \
  --name workload

PostgreSQL requires the pg_stat_statements extension to be enabled. Install it with CREATE EXTENSION IF NOT EXISTS pg_stat_statements and ensure shared_preload_libraries includes pg_stat_statements in postgresql.conf.

Next steps#

The captured config uses TODO as a default for all query parameters. Replace these with expressions that match your actual data distributions:

args:
  - ref_rand('fetch_users').id    # instead of TODO
  - ref_rand('fetch_districts').d_id

Run edg validate config --config workload.yaml to verify the config after editing.