Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ansible/files/pg_wait_sampling_extension.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CREATE SCHEMA IF NOT exists extensions;
CREATE EXTENSION IF NOT EXISTS pg_wait_sampling with schema extensions;
Comment on lines +1 to +2

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
CREATE SCHEMA IF NOT exists extensions;
CREATE EXTENSION IF NOT EXISTS pg_wait_sampling with schema extensions;
CREATE SCHEMA IF NOT EXISTS extensions;
CREATE EXTENSION IF NOT EXISTS pg_wait_sampling WITH SCHEMA extensions;

Cosmetic only.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we typically use a shared namespace for all extensions, rather than separate namespaces for each? Probably the odds of collisions is low, but just curious.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK we use mostly extensions schema with few exceptions, which are installed either to a separate schema or to pg_catalog.

2 changes: 1 addition & 1 deletion ansible/files/postgresql_config/postgresql.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ default_text_search_config = 'pg_catalog.english'
#local_preload_libraries = ''
#session_preload_libraries = ''

shared_preload_libraries = 'pg_stat_statements, pgaudit, plpgsql, plpgsql_check, pg_cron, pg_net, pgsodium, timescaledb, auto_explain, pg_tle, plan_filter, supabase_vault' # (change requires restart)
shared_preload_libraries = 'pg_stat_statements, pg_wait_sampling, pgaudit, plpgsql, plpgsql_check, pg_cron, pg_net, pgsodium, timescaledb, auto_explain, pg_tle, plan_filter, supabase_vault' # (change requires restart)
jit_provider = 'llvmjit' # JIT library to use

# - Other Defaults -
Expand Down
4 changes: 2 additions & 2 deletions ansible/files/postgresql_config/supautils.conf.j2
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
supautils.extensions_parameter_overrides = '{"pg_cron":{"schema":"pg_catalog"}}'
supautils.policy_grants = '{"postgres":["auth.audit_log_entries","auth.flow_state","auth.identities","auth.instances","auth.mfa_amr_claims","auth.mfa_challenges","auth.mfa_factors","auth.oauth_clients","auth.one_time_tokens","auth.refresh_tokens","auth.saml_providers","auth.saml_relay_states","auth.sessions","auth.sso_domains","auth.sso_providers","auth.users","realtime.messages","realtime.subscription","storage.buckets","storage.buckets_analytics","storage.objects","storage.prefixes","storage.s3_multipart_uploads","storage.s3_multipart_uploads_parts"]}'
supautils.drop_trigger_grants = '{"postgres":["auth.audit_log_entries","auth.flow_state","auth.identities","auth.instances","auth.mfa_amr_claims","auth.mfa_challenges","auth.mfa_factors","auth.oauth_clients","auth.one_time_tokens","auth.refresh_tokens","auth.saml_providers","auth.saml_relay_states","auth.sessions","auth.sso_domains","auth.sso_providers","auth.users","realtime.messages","realtime.subscription","storage.buckets","storage.buckets_analytics","storage.objects","storage.prefixes","storage.s3_multipart_uploads","storage.s3_multipart_uploads_parts"]}'
# full list: address_standardizer, address_standardizer_data_us, adminpack, amcheck, autoinc, bloom, btree_gin, btree_gist, citext, cube, dblink, dict_int, dict_xsyn, earthdistance, file_fdw, fuzzystrmatch, hstore, http, hypopg, index_advisor, insert_username, intagg, intarray, isn, lo, ltree, moddatetime, old_snapshot, orioledb, pageinspect, pg_buffercache, pg_cron, pg_freespacemap, pg_graphql, pg_hashids, pg_jsonschema, pg_net, pg_prewarm, pg_repack, pg_stat_monitor, pg_stat_statements, pg_surgery, pg_tle, pg_trgm, pg_visibility, pg_walinspect, pgaudit, pgcrypto, pgjwt, pgmq, pgroonga, pgroonga_database, pgrouting, pgrowlocks, pgsodium, pgstattuple, pgtap, plcoffee, pljava, plls, plpgsql, plpgsql_check, plv8, postgis, postgis_raster, postgis_sfcgal, postgis_tiger_geocoder, postgis_topology, postgres_fdw, refint, rum, seg, sslinfo, supabase_vault, supautils, tablefunc, tcn, timescaledb, tsm_system_rows, tsm_system_time, unaccent, uuid-ossp, vector, wrappers, xml2
# full list: address_standardizer, address_standardizer_data_us, adminpack, amcheck, autoinc, bloom, btree_gin, btree_gist, citext, cube, dblink, dict_int, dict_xsyn, earthdistance, file_fdw, fuzzystrmatch, hstore, http, hypopg, index_advisor, insert_username, intagg, intarray, isn, lo, ltree, moddatetime, old_snapshot, orioledb, pageinspect, pg_buffercache, pg_cron, pg_freespacemap, pg_graphql, pg_hashids, pg_jsonschema, pg_net, pg_prewarm, pg_repack, pg_stat_monitor, pg_stat_statements, pg_surgery, pg_tle, pg_trgm, pg_visibility, pg_wait_sampling, pg_walinspect, pgaudit, pgcrypto, pgjwt, pgmq, pgroonga, pgroonga_database, pgrouting, pgrowlocks, pgsodium, pgstattuple, pgtap, plcoffee, pljava, plls, plpgsql, plpgsql_check, plv8, postgis, postgis_raster, postgis_sfcgal, postgis_tiger_geocoder, postgis_topology, postgres_fdw, refint, rum, seg, sslinfo, supabase_vault, supautils, tablefunc, tcn, timescaledb, tsm_system_rows, tsm_system_time, unaccent, uuid-ossp, vector, wrappers, xml2
# omitted because may be unsafe: adminpack, amcheck, file_fdw, lo, old_snapshot, pageinspect, pg_freespacemap, pg_surgery, pg_visibility
# omitted because deprecated: intagg, xml2
# omitted because doesn't require superuser: pgmq
# omitted because protected: plpgsql
# NOTE: keep nix/tests/prime-superuser.sql in sync with the "may be unsafe" + "deprecated" lists above.
supautils.privileged_extensions = 'address_standardizer, address_standardizer_data_us, autoinc, bloom, btree_gin, btree_gist, citext, cube, dblink, dict_int, dict_xsyn, earthdistance, fuzzystrmatch, hstore, http, hypopg, index_advisor, insert_username, intarray, isn, ltree, moddatetime, orioledb, pg_buffercache, pg_cron, pg_graphql, pg_hashids, pg_jsonschema, pg_net, pg_prewarm, pg_repack, pg_stat_monitor, pg_stat_statements, pg_tle, pg_trgm, pg_walinspect, pgaudit, pgcrypto, pgjwt, pgroonga, pgroonga_database, pgrouting, pgrowlocks, pgsodium, pgstattuple, pgtap, plcoffee, pljava, plls, plpgsql_check, plv8, postgis, postgis_raster, postgis_sfcgal, postgis_tiger_geocoder, postgis_topology, postgres_fdw, refint, rum, seg, sslinfo, supabase_vault, supautils, tablefunc, tcn, timescaledb, tsm_system_rows, tsm_system_time, unaccent, uuid-ossp, vector, wrappers'
supautils.privileged_extensions = 'address_standardizer, address_standardizer_data_us, autoinc, bloom, btree_gin, btree_gist, citext, cube, dblink, dict_int, dict_xsyn, earthdistance, fuzzystrmatch, hstore, http, hypopg, index_advisor, insert_username, intarray, isn, ltree, moddatetime, orioledb, pg_buffercache, pg_cron, pg_graphql, pg_hashids, pg_jsonschema, pg_net, pg_prewarm, pg_repack, pg_stat_monitor, pg_stat_statements, pg_tle, pg_trgm, pg_wait_sampling, pg_walinspect, pgaudit, pgcrypto, pgjwt, pgroonga, pgroonga_database, pgrouting, pgrowlocks, pgsodium, pgstattuple, pgtap, plcoffee, pljava, plls, plpgsql_check, plv8, postgis, postgis_raster, postgis_sfcgal, postgis_tiger_geocoder, postgis_topology, postgres_fdw, refint, rum, seg, sslinfo, supabase_vault, supautils, tablefunc, tcn, timescaledb, tsm_system_rows, tsm_system_time, unaccent, uuid-ossp, vector, wrappers'
supautils.extension_custom_scripts_path = '/etc/postgresql-custom/extension-custom-scripts'
supautils.restrict_extension_versions = 'warn'
supautils.privileged_extensions_superuser = 'supabase_admin'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- Upstream revokes this from PUBLIC (it's the only function of the
-- extension not already granted to PUBLIC); grant it back to postgres so
-- the extension is fully usable without superuser.
grant execute on function pg_wait_sampling_reset_profile() to postgres with grant option;
6 changes: 5 additions & 1 deletion ansible/playbook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@
dest: "00-schema.sql",
}
- { source: "stat_extension.sql", dest: "01-extension.sql" }

- {
source: "pg_wait_sampling_extension.sql",
dest: "02-extension.sql",
}

environment:
PATH: /usr/lib/postgresql/bin:{{ ansible_env.PATH }}

Expand Down
6 changes: 3 additions & 3 deletions ansible/vars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ postgres_major:
# This is the source of truth for Postgres versions used in the Dockerfiles, and
# is used to derive image tags and base images in the release matrix.
postgres_release:
postgresorioledb-17: "17.9.0.020-orioledb"
postgres17: "17.6.1.167"
postgres15: "15.14.1.167"
postgresorioledb-17: "17.9.0.021-orioledb-bench-5"
postgres17: "17.6.1.168-bench-5"
postgres15: "15.14.1.168-bench-5"
# Docker release matrix — base images built first, layered images built on top.
# tag and base_tag are derived at build time from postgres_release via release_key.
# tag_suffix is appended to the release version to form the final image tag.
Expand Down
2 changes: 1 addition & 1 deletion docker/pgctld/orioledb-postgresql.conf.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ wal_log_hints = 'on'
# These settings activate OrioleDB as the default table storage engine.
# Injected automatically by the /usr/local/bin/pgctld wrapper in variant-orioledb-17.
#------------------------------------------------------------------------------
shared_preload_libraries = 'pg_stat_statements, pgaudit, plpgsql, plpgsql_check, pg_cron, pg_net, auto_explain, pg_tle, plan_filter, supabase_vault, orioledb'
shared_preload_libraries = 'pg_stat_statements, pg_wait_sampling, pgaudit, plpgsql, plpgsql_check, pg_cron, pg_net, auto_explain, pg_tle, plan_filter, supabase_vault, orioledb'
default_table_access_method = 'orioledb'
orioledb.enable_rewind = true
orioledb.rewind_max_time = 1200
Expand Down
2 changes: 1 addition & 1 deletion docker/pgctld/postgresql.conf.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ default_text_search_config = 'pg_catalog.english'

session_preload_libraries = 'supautils'

shared_preload_libraries = 'pg_stat_statements, pgaudit, plpgsql, plpgsql_check, pg_cron, pg_net, auto_explain, pg_tle, plan_filter, supabase_vault'
shared_preload_libraries = 'pg_stat_statements, pg_wait_sampling, pgaudit, plpgsql, plpgsql_check, pg_cron, pg_net, auto_explain, pg_tle, plan_filter, supabase_vault'
session_preload_libraries = 'supautils'

jit_provider = 'llvmjit' # JIT library to use
Expand Down
4 changes: 2 additions & 2 deletions migrations/schema-orioledb-17.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

\restrict SupabaseTestDumpKey123

-- Dumped from database version 17.9
-- Dumped by pg_dump version 17.9
-- Dumped from database version 17.10
-- Dumped by pg_dump version 17.10

SET statement_timeout = 0;
SET lock_timeout = 0;
Expand Down
2 changes: 2 additions & 0 deletions nix/checks.nix
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@
# Define which extensions should be preloaded (in order of priority)
WANTED_EXTS=(
"pg_stat_statements"
"pg_wait_sampling"
"pgaudit"
"plpgsql"
"plpgsql_check"
Expand Down Expand Up @@ -255,6 +256,7 @@
"pg_net_worker_privileges" # needs the authenticated/postgres roles from the full migrations, not present in the CLI prime file
"pg_cron_trigger_privileges" # needs pg_cron + the postgres role and cron-schema grants from the full migrations, not in the CLI prime file
"supautils_restrict_versions" # needs the postgres role + primed hstore from the full migrations/prime, not present in the CLI variant
"pg_wait_sampling"
# Version-specific extension tests
"z_17_ext_interface"
"z_17_pg_stat_monitor"
Expand Down
3 changes: 2 additions & 1 deletion nix/config.nix
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ in
orioledb = {
"17" = {
version = "17_20";
hash = "sha256-HDrHTx9yeIPJoyIBs+BdAhBQqt1IEtQrG9pFfvHJqdg=";
revision = "b8970548a74d2adec467ce7c99469a34edbc563b";
hash = "sha256-yQCUw8A11heKWASlZS57L4etFNbsssZ2Z9XPpYT9do4=";
};
};
};
Expand Down
8 changes: 4 additions & 4 deletions nix/ext/orioledb.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ stdenv.mkDerivation rec {
src = fetchFromGitHub {
owner = "orioledb";
repo = "orioledb";
rev = "beta16";
sha256 = "sha256-HCfNzMPt80nGeVwlstUCeMpdNZYd9KhLLHYyD/Hvuhk=";
rev = "657812f526d732417630bd4355fb6be28a72321b";
sha256 = "sha256-NzAk1wrWL89tUxvHJ/P2W2Sh4HxeJ0Kvw2lQQN1bRqY=";
};
version = "beta16";
version = "657812f526d732417630bd4355fb6be28a72321b";
buildInputs = [
curl
libkrb5
Expand All @@ -27,7 +27,7 @@ stdenv.mkDerivation rec {
openssl
];
buildPhase = ''
make USE_PGXS=1 ORIOLEDB_PATCHSET_VERSION=20
make USE_PGXS=1 ORIOLEDB_PATCHSET_VERSION=b8970548a74d2adec467ce7c99469a34edbc563b
'';
separateDebugInfo = true;
installPhase = ''
Expand Down
20 changes: 20 additions & 0 deletions nix/ext/pg_wait_sampling-defaults.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
--- a/pg_wait_sampling.c
+++ b/pg_wait_sampling.c
@@ -363,7 +363,7 @@
"Sets size of waits history.",
NULL,
&pgws_historySize,
- 5000,
+ 300000,
100,
/* to avoid error in collector.c:alloc_history */
MaxAllocSize / sizeof(HistoryItem),
@@ -403,7 +403,7 @@
"Sets whether profile should be collected per pid.",
NULL,
&pgws_profilePid,
- true,
+ false,
PGC_SIGHUP,
0,
NULL,
113 changes: 113 additions & 0 deletions nix/ext/pg_wait_sampling.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
{
pkgs,
lib,
stdenv,
fetchFromGitHub,
postgresql,
makeWrapper,
switch-ext-version,
latestOnly ? false,
}:

let
pname = "pg_wait_sampling";
build =
version: versionData:
stdenv.mkDerivation rec {
inherit pname version;

buildInputs = [ postgresql ];

src = fetchFromGitHub {
owner = "postgrespro";
repo = pname;
rev = versionData.rev or "v${version}";
hash = versionData.hash;
};

makeFlags = [ "USE_PGXS=1" ];

# Ship with different compiled-in defaults than upstream
patches = [ ./pg_wait_sampling-defaults.patch ];

installPhase = ''
mkdir -p $out/{lib,share/postgresql/extension}

# Install versioned library
install -Dm755 ${pname}${postgresql.dlSuffix} $out/lib/${pname}-${version}${postgresql.dlSuffix}

if [[ "${version}" == "${latestVersion}" ]]; then
cp ${pname}--*.sql $out/share/postgresql/extension/
fi

# Create versioned control file with modified module path
sed -e "/^default_version =/d" \
-e "s|^module_pathname = .*|module_pathname = '\$libdir/${pname}-${version}'|" \
${pname}.control > $out/share/postgresql/extension/${pname}--${version}.control
'';

meta = with lib; {
description = "Sampling based statistics of wait events";
homepage = "https://github.com/postgrespro/pg_wait_sampling";
platforms = postgresql.meta.platforms;
license = licenses.postgresql;
};
};
allVersions = (builtins.fromJSON (builtins.readFile ./versions.json)).${pname};
supportedVersions = lib.filterAttrs (
_: value: builtins.elem (lib.versions.major postgresql.version) value.postgresql
) allVersions;
versions = lib.naturalSort (lib.attrNames supportedVersions);
latestVersion = lib.last versions;
versionsToUse =
if latestOnly then
{ "${latestVersion}" = supportedVersions.${latestVersion}; }
else
supportedVersions;
versionsBuilt = if latestOnly then [ latestVersion ] else versions;
numberOfVersionsBuilt = builtins.length versionsBuilt;
packages = builtins.attrValues (lib.mapAttrs (name: value: build name value) versionsToUse);
in
pkgs.buildEnv {
name = pname;
paths = packages;
nativeBuildInputs = [ makeWrapper ];

pathsToLink = [
"/lib"
"/share/postgresql/extension"
];

postBuild = ''
{
echo "default_version = '${latestVersion}'"
cat $out/share/postgresql/extension/${pname}--${latestVersion}.control
} > $out/share/postgresql/extension/${pname}.control
ln -sfn ${pname}-${latestVersion}${postgresql.dlSuffix} $out/lib/${pname}${postgresql.dlSuffix}

# checks
(set -x
test "$(ls -A $out/lib/${pname}*${postgresql.dlSuffix} | wc -l)" = "${
toString (numberOfVersionsBuilt + 1)
}"
)

makeWrapper ${lib.getExe switch-ext-version} $out/bin/switch_${pname}_version \
--prefix EXT_WRAPPER : "$out" --prefix EXT_NAME : "${pname}"
'';

passthru = {
versions = versionsBuilt;
numberOfVersions = numberOfVersionsBuilt;
inherit switch-ext-version latestOnly;
hasBackgroundWorker = true;
defaultSettings = {
shared_preload_libraries = [ pname ];
};
version =
if latestOnly then
latestVersion
else
"multi-" + lib.concatStringsSep "-" (map (v: lib.replaceStrings [ "." ] [ "-" ] v) versions);
};
}
11 changes: 11 additions & 0 deletions nix/ext/versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -932,5 +932,16 @@
],
"hash": "sha256-+QoACPCKiFfuT2lJfSUmgfzC5MXf75KpSoc2PzPxKyM="
}
},
"pg_wait_sampling": {
"1.1": {
"postgresql": [
"15",
"17",
"orioledb-17"
],
"rev": "v1.1.11",
"hash": "sha256-Jz96QriyocruvTECfDP24Qvxe8No/SulOCon5hmr2Po="
}
}
}
1 change: 1 addition & 0 deletions nix/packages/postgres.nix
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
../ext/pgsodium.nix
../ext/pg_graphql
../ext/pg_stat_monitor.nix
../ext/pg_wait_sampling.nix
../ext/pg_jsonschema
../ext/pg_partman.nix
../ext/pgvector.nix
Expand Down
48 changes: 48 additions & 0 deletions nix/tests/expected/pg_wait_sampling.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
show pg_wait_sampling.profile_pid;
pg_wait_sampling.profile_pid
------------------------------
off
(1 row)

show pg_wait_sampling.history_size;
pg_wait_sampling.history_size
-------------------------------
300000
(1 row)

select
*
from
pg_wait_sampling_current
where
false;
pid | event_type | event | queryid
-----+------------+-------+---------
(0 rows)

select
*
from
pg_wait_sampling_history
where
false;
pid | ts | event_type | event | queryid
-----+----+------------+-------+---------
(0 rows)

select
*
from
pg_wait_sampling_profile
where
false;
pid | event_type | event | queryid | count
-----+------------+-------+---------+-------
(0 rows)

select pg_wait_sampling_reset_profile();
pg_wait_sampling_reset_profile
--------------------------------

(1 row)

Loading
Loading