Compare commits

...

11 Commits
2.3.0 ... main

Author SHA1 Message Date
Artem Gavrilov 71b045b3a4
Merge pull request #582 from percona/release-2.3.1
PGSM 2.3.1 release
2025-12-01 18:00:54 +02:00
Andrei V. Lepikhov 133432ed92 Fix annoying compilation warnings 2025-12-01 17:26:48 +02:00
dependabot[bot] ff4c134e2a Bump actions/checkout from 5.0.0 to 6.0.0
Bumps [actions/checkout](https://github.com/actions/checkout) from 5.0.0 to 6.0.0.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](08c6903cd8...1af3b93b68)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-version: 6.0.0
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-11-27 16:14:52 +02:00
dependabot[bot] e01e159a7d Bump github/codeql-action from 4.31.2 to 4.31.5
Bumps [github/codeql-action](https://github.com/github/codeql-action) from 4.31.2 to 4.31.5.
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](0499de31b9...fdbfb4d275)

---
updated-dependencies:
- dependency-name: github/codeql-action
  dependency-version: 4.31.5
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-11-27 16:14:24 +02:00
Andreas Karlsson bcd345a873 PG-2014 Initalize nested query stack to fix crash on DDL
The pgsm_ProcessUtility() which handles DDL increments nesting_level but
does not put a query text on the next_queries stack while
pgsm_ExecutorRun() does both. It is unclear to me if this is a mistake
or by design but since readers of the query check for is the query text
pointer is NULL and pgsm_ExecutorRun() reset the pointer to NULL before
returning it is safe as long as we initialize the stack to all NULL
pointers, which we did not.

This bug was found by our test suite in Jenkins on some RHEL based
distro version and seems to mostly happen when the first query of a
backend is CREATE EXTENSION and we have enabled query normalization but
it is entirely possible that it could happen under other circumstances
too.

The use of calloc() over palloc0() is to keep the patch small since the
previous code used malloc().
2025-11-21 11:25:05 +02:00
Manika Singhal 2235e8bf44 fix llvm for ol8 2025-11-21 11:10:43 +02:00
Artem Gavrilov d2c1842fde Bump version to 2.3.1
Increment pg_stat_monitor version to 2.3.1
2025-11-13 15:29:50 +02:00
Manika Singhal b00caafb68 fix llvm dependency for bullseye 2025-11-13 12:09:14 +02:00
Manika Singhal 4aa3751e6a Backport buils scripts fixes from 2.2.0 release branch
We missed to backport some commits after 2.2.0 release.

fix llvm source

try trixie

fix empty variable

remove unwanted code
2025-11-12 14:51:03 +02:00
Zsolt Parragi 5f8b716ef6 PG-2005: Do not keep unnecessary entries in the query stack
PGSM support nested query tracking, and it has to track the current SQL
call stack for this feature to work. But it incorrectly tracked all
previous queries executed within the current top level statement instead
o only the currently active queries.

This was easily visible for example with a FOR LOOP in a user function,
but could be also reproduced in many other ways.

There's also an issue that the related assertion, that compares the
length of the list with the max_stack_depth is incorrect. The stack
depth limits the size of the postgres stack for the C code, not the
number of nested SQL statements.

For now this commit leaves these assertions as-is, as while they are not
technically correct, these at least provide some kind of check on the
nesting depth. Maybe it would make sense to remove them in the future,
but for now, it could be a useful sanity check for testing the actual
fix - we shouldn't hit this assertion anymore with the changes in this
commit.

As for the actual fix, with the changes in this commit pgsm removes list
entries after we finished working on them. At that point we persisted
everything we needed already into the shared memory, and no longer need
the entries in the process local list. This is also true for the
duplicated query string, which if needed was already copied to the
shared memory.
2025-11-12 11:15:37 +01:00
dependabot[bot] aa24b90c66 Bump github/codeql-action from 4.31.0 to 4.31.2
Bumps [github/codeql-action](https://github.com/github/codeql-action) from 4.31.0 to 4.31.2.
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](4e94bd11f7...0499de31b9)

---
updated-dependencies:
- dependency-name: github/codeql-action
  dependency-version: 4.31.2
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-11-04 12:10:25 +02:00
30 changed files with 146 additions and 72 deletions

View File

@ -10,12 +10,12 @@ jobs:
steps:
- name: Checkout sources
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
with:
path: src/pg_stat_monitor
- name: Checkout cppcheck sources
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
with:
repository: "danmar/cppcheck"
ref: "2.13.4"
@ -43,13 +43,13 @@ jobs:
steps:
- name: Clone postgres repository
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
with:
repository: 'postgres/postgres'
ref: 'REL_17_STABLE'
- name: Checkout sources
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
with:
path: 'contrib/pg_stat_monitor'
@ -87,7 +87,7 @@ jobs:
steps:
- name: Checkout sources
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
- name: Check license headers
uses: apache/skywalking-eyes/header@61275cc80d0798a405cb070f7d3a8aaf7cf2c2c1 # v0.8.0

View File

@ -16,7 +16,7 @@ jobs:
steps:
- name: Clone postgres repository
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
with:
repository: 'postgres/postgres'
ref: 'REL_15_STABLE'
@ -83,7 +83,7 @@ jobs:
pg_ctl -D /opt/pgsql/data -l logfile start
- name: Clone pg_stat_monitor repository
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
with:
path: 'src/pg_stat_monitor'

View File

@ -22,7 +22,7 @@ jobs:
shell: bash
- name: Check out
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
with:
ref: '${{ inputs.version }}'

View File

@ -17,7 +17,7 @@ jobs:
timeout-minutes: 30
steps:
- name: Clone postgres repository
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
with:
repository: 'postgres/postgres'
ref: 'REL_13_STABLE'
@ -83,7 +83,7 @@ jobs:
pg_ctl -D /opt/pgsql/data -l logfile start
- name: Clone pg_stat_monitor repository
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
with:
path: 'src/pg_stat_monitor'

View File

@ -17,7 +17,7 @@ jobs:
timeout-minutes: 30
steps:
- name: Clone pg_stat_monitor repository
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
with:
path: 'src/pg_stat_monitor'

View File

@ -17,7 +17,7 @@ jobs:
timeout-minutes: 30
steps:
- name: Clone QA Integration repository
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
with:
repository: 'Percona-Lab/qa-integration'
ref: 'main'

View File

@ -17,7 +17,7 @@ jobs:
timeout-minutes: 30
steps:
- name: Clone pg_stat_monitor repository
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
with:
path: 'src/pg_stat_monitor'

View File

@ -17,7 +17,7 @@ jobs:
timeout-minutes: 30
steps:
- name: Clone postgres repository
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
with:
repository: 'postgres/postgres'
ref: 'REL_14_STABLE'
@ -83,7 +83,7 @@ jobs:
pg_ctl -D /opt/pgsql/data -l logfile start
- name: Clone pg_stat_monitor repository
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
with:
path: 'src/pg_stat_monitor'

View File

@ -17,7 +17,7 @@ jobs:
timeout-minutes: 30
steps:
- name: Clone pg_stat_monitor repository
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
with:
path: 'src/pg_stat_monitor'

View File

@ -17,7 +17,7 @@ jobs:
timeout-minutes: 30
steps:
- name: Clone QA Integration repository
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
with:
repository: 'Percona-Lab/qa-integration'
ref: 'main'

View File

@ -17,7 +17,7 @@ jobs:
timeout-minutes: 30
steps:
- name: Clone pg_stat_monitor repository
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
with:
path: 'src/pg_stat_monitor'

View File

@ -17,7 +17,7 @@ jobs:
timeout-minutes: 30
steps:
- name: Clone postgres repository
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
with:
repository: 'postgres/postgres'
ref: 'REL_15_STABLE'
@ -83,7 +83,7 @@ jobs:
pg_ctl -D /opt/pgsql/data -l logfile start
- name: Clone pg_stat_monitor repository
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
with:
path: 'src/pg_stat_monitor'

View File

@ -17,7 +17,7 @@ jobs:
timeout-minutes: 30
steps:
- name: Clone pg_stat_monitor repository
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
with:
path: 'src/pg_stat_monitor'

View File

@ -17,7 +17,7 @@ jobs:
timeout-minutes: 30
steps:
- name: Clone QA Integration repository
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
with:
repository: 'Percona-Lab/qa-integration'
ref: 'main'

View File

@ -17,7 +17,7 @@ jobs:
timeout-minutes: 30
steps:
- name: Clone pg_stat_monitor repository
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
with:
path: 'src/pg_stat_monitor'

View File

@ -17,7 +17,7 @@ jobs:
timeout-minutes: 30
steps:
- name: Clone postgres repository
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
with:
repository: 'postgres/postgres'
ref: 'REL_16_STABLE'
@ -83,7 +83,7 @@ jobs:
pg_ctl -D /opt/pgsql/data -l logfile start
- name: Clone pg_stat_monitor repository
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
with:
path: 'src/pg_stat_monitor'

View File

@ -17,7 +17,7 @@ jobs:
timeout-minutes: 30
steps:
- name: Clone pg_stat_monitor repository
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
with:
path: 'src/pg_stat_monitor'

View File

@ -17,7 +17,7 @@ jobs:
timeout-minutes: 30
steps:
- name: Clone pg_stat_monitor repository
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
with:
path: 'src/pg_stat_monitor'

View File

@ -17,7 +17,7 @@ jobs:
timeout-minutes: 30
steps:
- name: Clone postgres repository
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
with:
repository: 'postgres/postgres'
ref: 'REL_17_STABLE'
@ -83,7 +83,7 @@ jobs:
pg_ctl -D /opt/pgsql/data -l logfile start
- name: Clone pg_stat_monitor repository
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
with:
path: 'src/pg_stat_monitor'

View File

@ -17,7 +17,7 @@ jobs:
timeout-minutes: 30
steps:
- name: Clone pg_stat_monitor repository
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
with:
path: 'src/pg_stat_monitor'

View File

@ -17,7 +17,7 @@ jobs:
timeout-minutes: 30
steps:
- name: Clone postgres repository
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
with:
repository: 'postgres/postgres'
ref: 'REL_18_STABLE'
@ -83,7 +83,7 @@ jobs:
pg_ctl -D /opt/pgsql/data -l logfile start
- name: Clone pg_stat_monitor repository
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
with:
path: 'src/pg_stat_monitor'

View File

@ -17,7 +17,7 @@ jobs:
timeout-minutes: 30
steps:
- name: Clone pg_stat_monitor repository
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
with:
path: 'src/pg_stat_monitor'

View File

@ -23,7 +23,7 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
with:
persist-credentials: false
@ -43,6 +43,6 @@ jobs:
# Upload the results to GitHub's code scanning dashboard (optional).
- name: "Upload to code-scanning"
uses: github/codeql-action/upload-sarif@4e94bd11f71e507f7f87df81788dff88d1dacbfb # v4.31.0
uses: github/codeql-action/upload-sarif@fdbfb4d2750291e159f0156def62b853c2798ca2 # v4.31.5
with:
sarif_file: results.sarif

View File

@ -2,7 +2,7 @@
"name": "pg_stat_monitor",
"abstract": "PostgreSQL Query Performance Monitoring Tool",
"description": "pg_stat_monitor is a PostgreSQL Query Performance Monitoring tool, based on PostgreSQL's contrib module pg_stat_statements. PostgreSQL’s pg_stat_statements provides the basic statistics, which is sometimes not enough. The major shortcoming in pg_stat_statements is that it accumulates all the queries and their statistics and does not provide aggregated statistics nor histogram information. In this case, a user would need to calculate the aggregates, which is quite an expensive operation.",
"version": "2.3.0",
"version": "2.3.1",
"maintainer": [
"Artem Gavrilov <artem.gavrilov@percona.com>",
"Diego dos Santos Fronza <diego.fronza@percona.com>"
@ -15,7 +15,7 @@
"abstract": "PostgreSQL Query Performance Monitoring Tool",
"file": "pg_stat_monitor--2.2--2.3.sql",
"docfile": "README.md",
"version": "2.3.0"
"version": "2.3.1"
}
},
"prereqs": {

View File

@ -209,19 +209,16 @@ install_deps() {
then
yum -y install git wget
yum install -y https://repo.percona.com/yum/percona-release-latest.noarch.rpm
wget https://raw.githubusercontent.com/percona/percona-repositories/release-1.0-28/scripts/percona-release.sh
mv percona-release.sh /usr/bin/percona-release
chmod 777 /usr/bin/percona-release
percona-release enable ${PPG_REPO_NAME} testing
if [ x"$RHEL" = x8 ];
then
clang_version=$(yum list --showduplicates clang-devel | grep "17.0" | grep clang | awk '{print $2}' | head -n 1)
llvm_version=$(yum list --showduplicates llvm-devel | grep "17.0" | grep llvm | awk '{print $2}' | head -n 1)
yum install -y clang-devel-${clang_version} clang-${clang_version} llvm-devel-${llvm_version}
dnf module -y disable llvm-toolset
clang_version=$(yum list --showduplicates clang-devel | grep "20.1" | grep clang | awk '{print $2}' | head -n 1)
llvm_version=$(yum list --showduplicates llvm-devel | grep "20.1" | grep llvm | awk '{print $2}' | head -n 1)
yum install -y clang-devel-${clang_version} clang-${clang_version} llvm-devel-${llvm_version}
dnf module disable -y rust-toolset llvm-toolset
else
yum install -y clang-devel clang llvm-devel
yum install -y clang-devel clang llvm-devel
fi
PKGLIST="percona-postgresql${PG_RELEASE}-devel"
@ -251,32 +248,26 @@ install_deps() {
else
apt-get update
DEBIAN_FRONTEND=noninteractive apt-get -y install lsb-release gnupg git wget curl
export DEBIAN=$(lsb_release -sc)
wget https://repo.percona.com/apt/percona-release_latest.generic_all.deb
dpkg -i percona-release_latest.generic_all.deb
rm -f percona-release_latest.generic_all.deb
percona-release enable ${PPG_REPO_NAME} testing
PKGLIST="percona-postgresql-${PG_RELEASE} percona-postgresql-common percona-postgresql-server-dev-all"
# ---- using a community version of postgresql
#wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
#echo "deb http://apt.postgresql.org/pub/repos/apt/ ${PG_RELEASE}"-pgdg main | sudo tee /etc/apt/sources.list.d/pgdg.list
#PKGLIST="postgresql-${PG_RELEASE} postgresql-common postgresql-server-dev-all"
apt-get update
if [[ "${OS_NAME}" != "focal" ]]; then
LLVM_EXISTS=$(grep -c "apt.llvm.org" /etc/apt/sources.list)
if [ "${LLVM_EXISTS}" == 0 ]; then
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key|sudo apt-key add -
echo "deb http://apt.llvm.org/${OS_NAME}/ llvm-toolchain-${OS_NAME}-7 main" >> /etc/apt/sources.list
echo "deb-src http://apt.llvm.org/${OS_NAME}/ llvm-toolchain-${OS_NAME}-7 main" >> /etc/apt/sources.list
apt-get update
fi
fi
if [[ "x${DEBIAN}" == "xbullseye" ]]; then
DEBIAN_FRONTEND=noninteractive apt-get -y install software-properties-common
wget https://apt.llvm.org/llvm.sh
chmod +x llvm.sh
./llvm.sh 14 bullseye
else
wget http://mirrors.kernel.org/ubuntu/pool/universe/l/llvm-toolchain-7/llvm-7_7.0.1-12_amd64.deb http://mirrors.kernel.org/ubuntu/pool/universe/l/llvm-toolchain-7/libllvm7_7.0.1-12_amd64.deb http://mirrors.kernel.org/ubuntu/pool/universe/l/llvm-toolchain-7/llvm-7-runtime_7.0.1-12_amd64.deb
apt install ./libllvm7_7.0.1-12_amd64.deb ./llvm-7_7.0.1-12_amd64.deb ./llvm-7-runtime_7.0.1-12_amd64.deb
fi
PKGLIST+=" debconf debhelper clang devscripts dh-exec git wget libkrb5-dev libssl-dev"
PKGLIST+=" build-essential debconf debhelper devscripts dh-exec git wget libxml-checker-perl"
PKGLIST+=" libxml-libxml-perl libio-socket-ssl-perl libperl-dev libssl-dev libxml2-dev txt2man zlib1g-dev libpq-dev"

View File

@ -43,7 +43,7 @@ typedef enum pgsmVersion
PG_MODULE_MAGIC;
#define BUILD_VERSION "2.3.0"
#define BUILD_VERSION "2.3.1"
/* Number of output arguments (columns) for various API versions */
#define PG_STAT_MONITOR_COLS_V1_0 52
@ -82,7 +82,6 @@ void _PG_init(void);
/* Current nesting depth of planner/ExecutorRun/ProcessUtility calls */
static int nesting_level = 0;
volatile bool __pgsm_do_not_capture_error = false;
#if PG_VERSION_NUM < 170000
/* Before planner nesting level was conunted separately */
@ -98,10 +97,10 @@ static int hist_bucket_count_total;
static uint32 pgsm_client_ip = PGSM_INVALID_IP_MASK;
/* The array to store outer layer query id*/
int64 *nested_queryids;
char **nested_query_txts;
List *lentries = NIL;
/* The array to store outer layer query id */
static int64 *nested_queryids;
static char **nested_query_txts;
static List *lentries = NIL;
static char relations[REL_LST][REL_LEN];
@ -203,6 +202,7 @@ char *unpack_sql_state(int sql_state);
static pgsmEntry *pgsm_create_hash_entry(uint64 bucket_id, int64 queryid, PlanInfo *plan_info);
static void pgsm_add_to_list(pgsmEntry *entry, char *query_text, int query_len);
static void pgsm_delete_entry(uint64 queryid);
static pgsmEntry *pgsm_get_entry_for_query(int64 queryid, PlanInfo *plan_info, const char *query_text, int query_len, bool create, CmdType cmd_type);
static int64 get_pgsm_query_id_hash(const char *norm_query, int len);
@ -210,12 +210,12 @@ static void pgsm_cleanup_callback(void *arg);
static void pgsm_store_error(const char *query, ErrorData *edata);
/*---- Local variables ----*/
MemoryContextCallback mem_cxt_reset_callback =
static MemoryContextCallback mem_cxt_reset_callback =
{
.func = pgsm_cleanup_callback,
.arg = NULL
};
volatile bool callback_setup = false;
static volatile bool callback_setup = false;
static void pgsm_update_entry(pgsmEntry *entry,
const char *query,
@ -342,7 +342,7 @@ _PG_init(void)
ExecutorCheckPerms_hook = HOOK(pgsm_ExecutorCheckPerms);
nested_queryids = (int64 *) malloc(sizeof(int64) * max_stack_depth);
nested_query_txts = (char **) malloc(sizeof(char *) * max_stack_depth);
nested_query_txts = (char **) calloc(max_stack_depth, sizeof(char *));
system_init = true;
}
@ -804,6 +804,8 @@ pgsm_ExecutorEnd(QueryDesc *queryDesc)
else
standard_ExecutorEnd(queryDesc);
pgsm_delete_entry(queryDesc->plannedstmt->queryId);
num_relations = 0;
}
@ -1274,6 +1276,7 @@ pgsm_ProcessUtility(PlannedStmt *pstmt, const char *queryString,
PG_END_TRY();
#endif
}
pgsm_delete_entry(pstmt->queryId);
}
/*
@ -1688,6 +1691,43 @@ pgsm_add_to_list(pgsmEntry *entry, char *query_text, int query_len)
MemoryContextSwitchTo(oldctx);
}
static void
pgsm_delete_entry(uint64 queryid)
{
pgsmEntry *entry = NULL;
ListCell *lc = NULL;
if (lentries == NIL)
return;
entry = (pgsmEntry *) llast(lentries);
if (entry->key.queryid == queryid)
{
pfree(entry->query_text.query_pointer);
entry->query_text.query_pointer = NULL;
lentries = list_delete_last(lentries);
return;
}
/*
* The rest of the code is just paranoia. In theory this list is a stack,
* and we always want to remove the last item. Similarly, in the getter
* method we are always looking for the last item.
*/
foreach(lc, lentries)
{
entry = lfirst(lc);
if (entry->key.queryid == queryid)
{
pfree(entry->query_text.query_pointer);
entry->query_text.query_pointer = NULL;
lentries = list_delete_cell(lentries, lc);
return;
}
}
}
static pgsmEntry *
pgsm_get_entry_for_query(int64 queryid, PlanInfo *plan_info, const char *query_text, int query_len, bool create, CmdType cmd_type)
{

View File

@ -42,6 +42,19 @@ SELECT query, top_query FROM pg_stat_monitor ORDER BY query COLLATE "C";
SELECT pg_stat_monitor_reset() |
(5 rows)
-- make sure that we handle nested queries correctly
BEGIN;
DO $$
DECLARE
i int;
BEGIN
-- default stack limit is 2000kB, 50000 is much larger than that
FOR i IN 1..50000 LOOP
EXECUTE format('SELECT %s', i);
END LOOP;
END;
$$;
COMMIT;
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset
-----------------------

View File

@ -42,6 +42,19 @@ SELECT query, top_query FROM pg_stat_monitor ORDER BY query COLLATE "C";
SELECT pg_stat_monitor_reset() |
(5 rows)
-- make sure that we handle nested queries correctly
BEGIN;
DO $$
DECLARE
i int;
BEGIN
-- default stack limit is 2000kB, 50000 is much larger than that
FOR i IN 1..50000 LOOP
EXECUTE format('SELECT %s', i);
END LOOP;
END;
$$;
COMMIT;
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset
-----------------------

View File

@ -2,7 +2,7 @@ CREATE EXTENSION pg_stat_monitor;
SELECT pg_stat_monitor_version();
pg_stat_monitor_version
-------------------------
2.3.0
2.3.1
(1 row)
DROP EXTENSION pg_stat_monitor;

View File

@ -16,5 +16,22 @@ $$ language plpgsql;
SELECT add2(1,2);
SELECT query, top_query FROM pg_stat_monitor ORDER BY query COLLATE "C";
-- make sure that we handle nested queries correctly
BEGIN;
DO $$
DECLARE
i int;
BEGIN
-- default stack limit is 2000kB, 50000 is much larger than that
FOR i IN 1..50000 LOOP
EXECUTE format('SELECT %s', i);
END LOOP;
END;
$$;
COMMIT;
SELECT pg_stat_monitor_reset();
DROP EXTENSION pg_stat_monitor;