Skip to content

Commit d5e6c05

Browse files
committed
Complete 0.5.0: enable available diagnostic extensions by default
1 parent 01f58cf commit d5e6c05

5 files changed

Lines changed: 33 additions & 2 deletions

File tree

‎README.md‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,11 @@ instead of `--passfile`; `PGPASSWORD` is accepted only as an admin-password comp
152152
`prepare-db --recreate` drops only the selected workload database after terminating its sessions;
153153
it does not drop the workload role.
154154
Unless `--extensions` is supplied, it creates both `pg_stat_statements` and
155-
`pg_buffercache`, matching the default pg_diag metric set used by pg_play.
155+
`pg_buffercache`, and also installs `pg_stat_kcache` and `pg_wait_sampling` when
156+
the server provides them. Managed `pg_stand` images include and preload the required
157+
libraries, and new databases inherit the extensions from `template1`. An explicit
158+
`--extensions` list replaces both default lists. Optional extension choices are
159+
included in the machine plan.
156160

157161
## Targets
158162

‎src/pg_workload/common.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
DEFAULT_PGBENCH_CLIENTS = 2
3333
DEFAULT_PGBENCH_THREADS = 2
3434
DEFAULT_EXTENSIONS = ("pg_stat_statements", "pg_buffercache")
35+
# Installed by prepare-db only when the server image provides them.
36+
DEFAULT_OPTIONAL_EXTENSIONS = ("pg_stat_kcache", "pg_wait_sampling")
3537
DEFAULT_SCRIPT_PATTERNS = ("sql/[0-9][0-9]_*.sql", "sql/select_*.sql")
3638
DEFAULT_RESOURCE_DISK_MAX_USED_PCT = 90
3739
DEFAULT_RESOURCE_MEM_MIN_AVAILABLE_PCT = 10

‎src/pg_workload/orchestration.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from typing import Any
99

1010
from pg_workload import __version__
11-
from pg_workload.common import DEFAULT_EXTENSIONS, csv_list, resolve_relative_path
11+
from pg_workload.common import DEFAULT_EXTENSIONS, DEFAULT_OPTIONAL_EXTENSIONS, csv_list, resolve_relative_path
1212
from pg_workload.profiles import Profile
1313
from pg_workload.state import load_state, state_with_profiles_enabled
1414

@@ -140,6 +140,9 @@ def execution_plan(args: Any, profiles: list[Profile], operation: str) -> dict[s
140140
"workload_superuser": getattr(args, "workload_superuser", False),
141141
"rotate_workload_password": getattr(args, "rotate_workload_password", False),
142142
"extensions": sorted(set(csv_list(getattr(args, "extensions", None)) or DEFAULT_EXTENSIONS)),
143+
"optional_extensions": (
144+
[] if csv_list(getattr(args, "extensions", None)) else sorted(DEFAULT_OPTIONAL_EXTENSIONS)
145+
),
143146
"preload_libraries": sorted(set(csv_list(getattr(args, "preload_libraries", None)))),
144147
},
145148
"execution": {

‎src/pg_workload/runner.py‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from pg_workload.common import (
77
DEFAULT_EXTENSIONS,
8+
DEFAULT_OPTIONAL_EXTENSIONS,
89
WorkloadError,
910
as_string_list,
1011
csv_list,
@@ -101,6 +102,23 @@ def prepare_database(client: PgClient, config: RuntimeConfig, args: argparse.Nam
101102
admin_password,
102103
command=f"CREATE EXTENSION IF NOT EXISTS {safe_extension_name(extension)};",
103104
)
105+
if not csv_list(args.extensions):
106+
for extension in DEFAULT_OPTIONAL_EXTENSIONS:
107+
available = client.query_scalar(
108+
config.dbname,
109+
config.admin_user,
110+
admin_password,
111+
f"SELECT 1 FROM pg_available_extensions WHERE name = {quote_literal(extension)};",
112+
)
113+
if available:
114+
client.run_psql(
115+
config.dbname,
116+
config.admin_user,
117+
admin_password,
118+
command=(f"CREATE EXTENSION IF NOT EXISTS {safe_extension_name(extension)};"),
119+
)
120+
else:
121+
eprint(f"Optional extension {extension} is not available; skipping")
104122

105123
preload_libraries = csv_list(args.preload_libraries) or ["auto_explain", "pg_stat_statements"]
106124
check_preload_libraries(client, config, admin_password, preload_libraries)

‎tests/test_workload.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -912,6 +912,8 @@ def __init__(self):
912912
def query_scalar(self, dbname, user, password, sql):
913913
if "pg_roles" in sql or "pg_database" in sql:
914914
return "1"
915+
if "pg_available_extensions" in sql:
916+
return "1"
915917
return "auto_explain,pg_stat_statements"
916918

917919
def run_psql(self, dbname, user, password, *, command, **kwargs):
@@ -933,6 +935,8 @@ def run_psql(self, dbname, user, password, *, command, **kwargs):
933935

934936
self.assertIn('CREATE EXTENSION IF NOT EXISTS "pg_stat_statements";', client.commands)
935937
self.assertIn('CREATE EXTENSION IF NOT EXISTS "pg_buffercache";', client.commands)
938+
self.assertIn('CREATE EXTENSION IF NOT EXISTS "pg_stat_kcache";', client.commands)
939+
self.assertIn('CREATE EXTENSION IF NOT EXISTS "pg_wait_sampling";', client.commands)
936940

937941
def test_job_recover_on_failure_defaults_to_true(self):
938942
self.assertTrue(self.workload.job_recover_on_failure({}))

0 commit comments

Comments
 (0)