-
-
Notifications
You must be signed in to change notification settings - Fork 268
[DO NOT MERGE] add pg_wait_sampling #2408
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
za-arthur
wants to merge
1
commit into
develop
Choose a base branch
from
artur/add_pg_wait_sampling
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
ansible/files/postgresql_extension_custom_scripts/pg_wait_sampling/after-create.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| }; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
|
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cosmetic only.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAIK we use mostly
extensionsschema with few exceptions, which are installed either to a separate schema or to pg_catalog.