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 capturingThis always writes both workload.yaml and workload.edg.
Flags#
| Flag | Required | Default | Description |
|---|---|---|---|
--flavour | Yes | Database flavour: postgres or cockroachdb | |
--name | Yes | Output file or path without extension (writes both .yaml and .edg; parent directories are created if needed) | |
--driver | Yes | pgx | Database driver |
--url | Yes | Connection URL for the source database | |
--min-calls | No | 10 | Minimum call count to include a query |
--top | No | 50 | Maximum number of queries to include |
--schema | No | Schema or database name to introspect for up/down DDL | |
--database | No | Alias 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, withwaitdurations derived from inter-arrival times.up- (when--schemaor--databaseis set)CREATE TABLEstatements derived from the database’s own DDL, topologically sorted so parent tables are created before children. Uses the same schema introspection as theinitcommand.down- (when--schemaor--databaseis set)DROP TABLE IF EXISTSstatements 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 workloadWithout --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 windowCapture 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 windowThis produces two files:
workload.yaml- YAML config withrun_weights,run, and (when--schemais set)upanddownworkload.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 workloadPostgreSQL requires the
pg_stat_statementsextension to be enabled. Install it withCREATE EXTENSION IF NOT EXISTS pg_stat_statementsand ensureshared_preload_librariesincludespg_stat_statementsinpostgresql.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_idRun edg validate config --config workload.yaml to verify the config after editing.