Compare commits
8 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
ce12d56b17 | |
|
|
50aaef47c1 | |
|
|
0586f10d2b | |
|
|
be9b15aab6 | |
|
|
cddc838809 | |
|
|
5e8c11a46c | |
|
|
72baeccc3e | |
|
|
dff4ff0e92 |
|
|
@ -1,4 +0,0 @@
|
|||
# https://docs.github.com/en/github/creating-cloning-and-archiving-repositories/about-code-owners
|
||||
# Order is important; the last matching pattern takes the most precedence.
|
||||
|
||||
* @artemgavrilov @dutow
|
||||
|
|
@ -1,60 +0,0 @@
|
|||
name: Bug Report
|
||||
description: File a bug report
|
||||
labels: ["bug"]
|
||||
assignees:
|
||||
- artemgavrilov
|
||||
- dutow
|
||||
|
||||
body:
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: |
|
||||
Thanks for taking the time to fill out this bug report! Please provide as much information as possible, it will help us to address this problem faster.
|
||||
- type: textarea
|
||||
id: description
|
||||
attributes:
|
||||
label: Description
|
||||
description: Please describe the problem.
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: expected
|
||||
attributes:
|
||||
label: Expected Results
|
||||
description: What did you expect to happen?
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: actual
|
||||
attributes:
|
||||
label: Actual Results
|
||||
description: What actually happened?
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: version
|
||||
attributes:
|
||||
label: Version
|
||||
description: What version of PostgreSQL and pg_stat_monitor are you running?
|
||||
placeholder: PostgreSQL 16.2, pg_stat_monitor v2.0.4
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: steps
|
||||
attributes:
|
||||
label: Steps to reproduce
|
||||
description: Which steps do we need to take to reproduce this error?
|
||||
- type: textarea
|
||||
id: logs
|
||||
attributes:
|
||||
label: Relevant logs
|
||||
description: Please copy and paste any relevant log output. This will be automatically formatted into code, so no need for backticks.
|
||||
render: Shell
|
||||
- type: checkboxes
|
||||
id: terms
|
||||
attributes:
|
||||
label: Code of Conduct
|
||||
description: By submitting this issue, you agree to follow [Percona Community Code of Conduct](https://github.com/percona/community/blob/main/content/contribute/coc.md)
|
||||
options:
|
||||
- label: I agree to follow Percona Community Code of Conduct
|
||||
required: true
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
blank_issues_enabled: false
|
||||
contact_links:
|
||||
- name: Forum
|
||||
url: https://forums.percona.com/
|
||||
about: Please join our forums for general questions ans discussions.
|
||||
|
|
@ -1,37 +0,0 @@
|
|||
name: Feature Request
|
||||
description: Suggest an idea for this project
|
||||
labels: ["feature"]
|
||||
assignees:
|
||||
- artemgavrilov
|
||||
- dutow
|
||||
|
||||
body:
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: |
|
||||
Thank you for suggesting an idea to make pg_stat_monitor better! Please complete the below form to ensure we have all the details to get things started.
|
||||
- type: textarea
|
||||
id: description
|
||||
attributes:
|
||||
label: Description
|
||||
description: Description of the feature and of the problem it solves.
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: solution
|
||||
attributes:
|
||||
label: Suggested solution
|
||||
description: A concise description of your preferred solution.
|
||||
- type: textarea
|
||||
id: context
|
||||
attributes:
|
||||
label: Additional context
|
||||
description: Any information that may help.
|
||||
- type: checkboxes
|
||||
id: terms
|
||||
attributes:
|
||||
label: Code of Conduct
|
||||
description: By submitting this issue, you agree to follow our [Code of Conduct](https://github.com/percona/community/blob/main/content/contribute/coc.md)
|
||||
options:
|
||||
- label: I agree to follow this project's Code of Conduct
|
||||
required: true
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
---
|
||||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: "github-actions"
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "weekly"
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
PG-0
|
||||
|
||||
### Description
|
||||
<!--- Describe your changes in detail -->
|
||||
|
||||
|
||||
### Links
|
||||
<!--- Please provide links to any related PRs in this or other repositories --->
|
||||
|
||||
|
|
@ -1,95 +0,0 @@
|
|||
name: Checks
|
||||
on:
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
cppcheck:
|
||||
name: Cppcheck
|
||||
runs-on: ubuntu-22.04
|
||||
timeout-minutes: 5
|
||||
|
||||
steps:
|
||||
- name: Checkout sources
|
||||
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
|
||||
with:
|
||||
path: src/pg_stat_monitor
|
||||
|
||||
- name: Checkout cppcheck sources
|
||||
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
|
||||
with:
|
||||
repository: "danmar/cppcheck"
|
||||
ref: "2.13.4"
|
||||
path: src/cppcheck
|
||||
|
||||
- name: Build and install cppcheck
|
||||
working-directory: src/cppcheck
|
||||
run: |
|
||||
mkdir build
|
||||
cd build
|
||||
cmake ..
|
||||
cmake --build .
|
||||
sudo cmake --install .
|
||||
|
||||
- name: Execute linter check with cppcheck
|
||||
working-directory: src/pg_stat_monitor
|
||||
run: |
|
||||
set -x
|
||||
cppcheck --enable=all --inline-suppr --template='{file}:{line},{severity},{id},{message}' --error-exitcode=1 --suppress=missingIncludeSystem --suppress=missingInclude --suppress=unmatchedSuppression:pg_stat_monitor.c --check-config .
|
||||
|
||||
format:
|
||||
name: Format
|
||||
runs-on: ubuntu-22.04
|
||||
timeout-minutes: 5
|
||||
|
||||
steps:
|
||||
- name: Clone postgres repository
|
||||
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
|
||||
with:
|
||||
repository: 'postgres/postgres'
|
||||
ref: 'REL_17_STABLE'
|
||||
|
||||
- name: Checkout sources
|
||||
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
|
||||
with:
|
||||
path: 'contrib/pg_stat_monitor'
|
||||
|
||||
- name: Configure postgres
|
||||
run: ./configure
|
||||
|
||||
- name: Install perltidy
|
||||
run: sudo cpan -T SHANCOCK/Perl-Tidy-20230309.tar.gz
|
||||
|
||||
- name: Install pg_bsd_indent
|
||||
working-directory: src/tools/pg_bsd_indent
|
||||
run: sudo make install
|
||||
|
||||
- name: Add pg_bsd_indent and pgindent to path
|
||||
run: |
|
||||
echo "/usr/local/pgsql/bin" >> $GITHUB_PATH
|
||||
echo "${{ github.workspace }}/src/tools/pgindent" >> $GITHUB_PATH
|
||||
|
||||
- name: Format sources
|
||||
working-directory: contrib/pg_stat_monitor
|
||||
run: |
|
||||
make update-typedefs
|
||||
make indent
|
||||
|
||||
- name: Check files are formatted and no source code changes
|
||||
working-directory: contrib/pg_stat_monitor
|
||||
run: |
|
||||
git status
|
||||
git diff --exit-code
|
||||
|
||||
license:
|
||||
name: License
|
||||
runs-on: ubuntu-22.04
|
||||
timeout-minutes: 5
|
||||
|
||||
steps:
|
||||
- name: Checkout sources
|
||||
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
|
||||
|
||||
- name: Check license headers
|
||||
uses: apache/skywalking-eyes/header@61275cc80d0798a405cb070f7d3a8aaf7cf2c2c1 # v0.8.0
|
||||
with:
|
||||
token: "" # Prevent comments
|
||||
|
|
@ -1,25 +1,16 @@
|
|||
name: code-coverage-test
|
||||
on:
|
||||
pull_request:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
on: ["push", "pull_request"]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: coverage-test
|
||||
runs-on: ubuntu-22.04
|
||||
timeout-minutes: 30
|
||||
|
||||
steps:
|
||||
- name: Clone postgres repository
|
||||
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
repository: 'postgres/postgres'
|
||||
ref: 'REL_15_STABLE'
|
||||
ref: 'REL_14_STABLE'
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
|
|
@ -37,8 +28,9 @@ jobs:
|
|||
/usr/lib/postgresql /usr/include/postgresql /usr/share/postgresql \
|
||||
/etc/postgresql
|
||||
sudo rm -f /usr/bin/pg_config
|
||||
sudo /usr/bin/perl -MCPAN -e 'install IPC::Run'
|
||||
sudo /usr/bin/perl -MCPAN -e 'install Text::Trim'
|
||||
sudo /usr/bin/perl -MCPAN -e 'install IPC::RUN'
|
||||
sudo /usr/bin/perl -MCPAN -e 'install String::Util'
|
||||
sudo /usr/bin/perl -MCPAN -e 'install Data::Str2Num'
|
||||
|
||||
- name: Create pgsql dir
|
||||
run: mkdir -p /opt/pgsql
|
||||
|
|
@ -54,11 +46,11 @@ jobs:
|
|||
'--libexecdir=${prefix}/lib/x86_64-linux-gnu' '--with-perl' \
|
||||
'--with-python' '--with-pam' '--with-openssl' '--with-libxml' \
|
||||
'--with-libxslt' 'PYTHON=/usr/bin/python3' '--enable-nls' \
|
||||
'--mandir=/usr/share/postgresql/15/man' '--enable-thread-safety' \
|
||||
'--docdir=/usr/share/doc/postgresql-doc-15' '--enable-dtrace' \
|
||||
'--mandir=/usr/share/postgresql/14/man' '--enable-thread-safety' \
|
||||
'--docdir=/usr/share/doc/postgresql-doc-14' '--enable-dtrace' \
|
||||
'--sysconfdir=/etc/postgresql-common' '--datarootdir=/usr/share' \
|
||||
'--datadir=/usr/share/postgresql/15' '--with-uuid=e2fs' \
|
||||
'--bindir=/usr/lib/postgresql/15/bin' '--with-gnu-ld' \
|
||||
'--datadir=/usr/share/postgresql/14' '--with-uuid=e2fs' \
|
||||
'--bindir=/usr/lib/postgresql/14/bin' '--with-gnu-ld' \
|
||||
'--libdir=/usr/lib/x86_64-linux-gnu' '--enable-tap-tests' \
|
||||
'--libexecdir=/usr/lib/postgresql' '--enable-debug' \
|
||||
'--includedir=/usr/include/postgresql' '--disable-rpath' \
|
||||
|
|
@ -77,13 +69,13 @@ jobs:
|
|||
|
||||
- name: Start postgresql cluster
|
||||
run: |
|
||||
export PATH="/usr/lib/postgresql/15/bin:$PATH"
|
||||
sudo cp /usr/lib/postgresql/15/bin/pg_config /usr/bin
|
||||
export PATH="/usr/lib/postgresql/14/bin:$PATH"
|
||||
sudo cp /usr/lib/postgresql/14/bin/pg_config /usr/bin
|
||||
initdb -D /opt/pgsql/data
|
||||
pg_ctl -D /opt/pgsql/data -l logfile start
|
||||
|
||||
- name: Clone pg_stat_monitor repository
|
||||
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
path: 'src/pg_stat_monitor'
|
||||
|
||||
|
|
@ -95,7 +87,7 @@ jobs:
|
|||
|
||||
- name: Load pg_stat_monitor library and Restart Server
|
||||
run: |
|
||||
export PATH="/usr/lib/postgresql/15/bin:$PATH"
|
||||
export PATH="/usr/lib/postgresql/14/bin:$PATH"
|
||||
pg_ctl -D /opt/pgsql/data -l logfile stop
|
||||
echo "shared_preload_libraries = 'pg_stat_monitor'" \
|
||||
>> /opt/pgsql/data/postgresql.conf
|
||||
|
|
@ -105,7 +97,7 @@ jobs:
|
|||
- name: Start pg_stat_monitor_tests & Run code coverage
|
||||
run: |
|
||||
make installcheck
|
||||
/usr/lib/postgresql/15/bin/psql -d postgres -p 5432 -c "\list"
|
||||
/usr/lib/postgresql/14/bin/psql -d postgres -p 5432 -c "\list"
|
||||
gcov -abcfu pg_stat_monitor.c
|
||||
gcov -abcfu guc.c
|
||||
gcov -abcfu hash_query.c
|
||||
|
|
@ -113,10 +105,9 @@ jobs:
|
|||
working-directory: src/pg_stat_monitor
|
||||
|
||||
- name: Upload
|
||||
uses: codecov/codecov-action@5a1091511ad55cbe89839c7260b706298ca349f7 # v5.5.1
|
||||
uses: codecov/codecov-action@v2
|
||||
with:
|
||||
verbose: true
|
||||
token: ${{ secrets.CODECOV_TOKEN }}
|
||||
working-directory: ./src/pg_stat_monitor
|
||||
files: ./pg_stat_monitor.c.gcov,./hash_query.c.gcov,./guc.c.gcov
|
||||
|
||||
|
|
@ -130,7 +121,7 @@ jobs:
|
|||
|
||||
- name: Upload logs on fail
|
||||
if: ${{ failure() }}
|
||||
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
|
||||
uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: Regressions diff and postgresql log
|
||||
path: |
|
||||
|
|
|
|||
|
|
@ -0,0 +1,18 @@
|
|||
name: cppcheck-action-test
|
||||
on: [push]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: cppcheck-test
|
||||
runs-on: ubuntu-18.04
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- name: install cppcheck
|
||||
run: sudo apt-get install cppcheck
|
||||
|
||||
- name: Execute linter check with cppcheck
|
||||
run: |
|
||||
set -x
|
||||
cppcheck --enable=all --inline-suppr --template='{file}:{line},{severity},{id},{message}' --error-exitcode=1 --suppress=missingIncludeSystem --suppress=missingInclude --suppress=unmatchedSuppression:pg_stat_monitor.c --check-config .
|
||||
|
||||
|
|
@ -1,37 +0,0 @@
|
|||
name: PGXN
|
||||
on:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
version:
|
||||
description: 'Version to release'
|
||||
required: true
|
||||
type: string
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
release:
|
||||
name: Release
|
||||
runs-on: ubuntu-22.04
|
||||
timeout-minutes: 10
|
||||
container: pgxn/pgxn-tools
|
||||
steps:
|
||||
- name: Validate version tag
|
||||
run: '[[ ${{ inputs.version }} =~ ^[0-9]+.[0-9]+.[0-9]+ ]]'
|
||||
shell: bash
|
||||
|
||||
- name: Check out
|
||||
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
|
||||
with:
|
||||
ref: '${{ inputs.version }}'
|
||||
|
||||
- name: Bundle
|
||||
id: bundle
|
||||
run: pgxn-bundle
|
||||
|
||||
- name: Upload
|
||||
env:
|
||||
PGXN_USERNAME: percona
|
||||
PGXN_PASSWORD: ${{ secrets.PGXN_PERCONA }}
|
||||
run: pgxn-release
|
||||
|
|
@ -0,0 +1,121 @@
|
|||
name: postgresql-11-build
|
||||
on: [push]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: pg-11-build-test
|
||||
runs-on: ubuntu-22.04
|
||||
steps:
|
||||
- name: Clone postgres repository
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
repository: 'postgres/postgres'
|
||||
ref: 'REL_11_STABLE'
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt purge postgresql-client-common postgresql-common \
|
||||
postgresql postgresql*
|
||||
sudo apt-get install -y libreadline6-dev systemtap-sdt-dev \
|
||||
zlib1g-dev libssl-dev libpam0g-dev bison flex \
|
||||
libipc-run-perl -y docbook-xsl docbook-xsl libxml2 libxml2-utils \
|
||||
libxml2-dev libxslt-dev xsltproc libkrb5-dev libldap2-dev \
|
||||
libsystemd-dev gettext tcl-dev libperl-dev pkg-config clang-11 \
|
||||
llvm-11 llvm-11-dev libselinux1-dev python3-dev uuid-dev liblz4-dev
|
||||
sudo rm -rf /var/lib/postgresql /var/log/postgresql /etc/postgresql \
|
||||
/usr/lib/postgresql /usr/include/postgresql /usr/share/postgresql \
|
||||
/etc/postgresql
|
||||
sudo rm -f /usr/bin/pg_config
|
||||
|
||||
- name: Create pgsql dir
|
||||
run: mkdir -p /opt/pgsql
|
||||
|
||||
- name: Build postgres
|
||||
run: |
|
||||
export PATH="/opt/pgsql/bin:$PATH"
|
||||
./configure '--build=x86_64-linux-gnu' '--prefix=/usr' \
|
||||
'--includedir=/usr/include' '--mandir=/usr/share/man' \
|
||||
'--infodir=/usr/share/info' '--sysconfdir=/etc' '--enable-nls' \
|
||||
'--localstatedir=/var' '--libdir=/usr/lib/x86_64-linux-gnu' \
|
||||
'runstatedir=/run' '--with-icu' '--with-tcl' '--with-perl' \
|
||||
'--with-python' '--with-pam' '--with-openssl' '--with-libxml' \
|
||||
'--with-libxslt' 'PYTHON=/usr/bin/python3' 'MKDIR_P=/bin/mkdir -p' \
|
||||
'--mandir=/usr/share/postgresql/11/man' '--enable-dtrace' \
|
||||
'--docdir=/usr/share/doc/postgresql-doc-11' '--enable-debug' \
|
||||
'--sysconfdir=/etc/postgresql-common' '--datarootdir=/usr/share' \
|
||||
'--datadir=/usr/share/postgresql/11' '--enable-thread-safety' \
|
||||
'--bindir=/usr/lib/postgresql/11/bin' '--enable-tap-tests' \
|
||||
'--libdir=/usr/lib/x86_64-linux-gnu' '--disable-rpath' \
|
||||
'--libexecdir=/usr/lib/postgresql' '--with-uuid=e2fs' \
|
||||
'--includedir=/usr/include/postgresql' '--with-gnu-ld' \
|
||||
'--with-pgport=5432' '--with-system-tzdata=/usr/share/zoneinfo' \
|
||||
'--with-llvm' 'LLVM_CONFIG=/usr/bin/llvm-config-11' \
|
||||
'CLANG=/usr/bin/clang-11' '--with-systemd' '--with-selinux' \
|
||||
'PROVE=/usr/bin/prove' 'TAR=/bin/tar' '--with-gssapi' '--with-ldap' \
|
||||
'LDFLAGS=-Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now' \
|
||||
'--with-includes=/usr/include/mit-krb5' '--with-libs=/usr/lib/mit-krb5' \
|
||||
'--with-libs=/usr/lib/x86_64-linux-gnu/mit-krb5' \
|
||||
'build_alias=x86_64-linux-gnu' \
|
||||
'CPPFLAGS=-Wdate-time -D_FORTIFY_SOURCE=2' \
|
||||
'CFLAGS=-g -O2 -fstack-protector-strong -Wformat -Werror=format-security -fno-omit-frame-pointer' \
|
||||
'CXXFLAGS=-g -O2 -fstack-protector-strong -Wformat -Werror=format-security'
|
||||
make world
|
||||
sudo make install-world
|
||||
|
||||
- name: Start postgresql cluster
|
||||
run: |
|
||||
export PATH="/usr/lib/postgresql/11/bin:$PATH"
|
||||
sudo cp /usr/lib/postgresql/11/bin/pg_config /usr/bin
|
||||
initdb -D /opt/pgsql/data
|
||||
pg_ctl -D /opt/pgsql/data -l logfile start
|
||||
|
||||
- name: Clone pg_stat_monitor repository
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
path: 'src/pg_stat_monitor'
|
||||
|
||||
- name: Build pg_stat_monitor
|
||||
run: |
|
||||
make USE_PGXS=1
|
||||
sudo make USE_PGXS=1 install
|
||||
working-directory: src/pg_stat_monitor/
|
||||
|
||||
- name: Load pg_stat_monitor library and Restart Server
|
||||
run: |
|
||||
export PATH="/usr/lib/postgresql/11/bin:$PATH"
|
||||
pg_ctl -D /opt/pgsql/data -l logfile stop
|
||||
echo "shared_preload_libraries = 'pg_stat_monitor'" >> \
|
||||
/opt/pgsql/data/postgresql.conf
|
||||
pg_ctl -D /opt/pgsql/data -l logfile start
|
||||
working-directory: src/pg_stat_monitor
|
||||
|
||||
- name: Start pg_stat_monitor_tests
|
||||
run: |
|
||||
make installcheck
|
||||
working-directory: src/pg_stat_monitor
|
||||
|
||||
- name: Report on pg_stat_monitor test fail
|
||||
uses: actions/upload-artifact@v2
|
||||
if: ${{ failure() }}
|
||||
with:
|
||||
name: Regressions diff and postgresql log
|
||||
path: |
|
||||
src/pg_stat_monitor/regression.diffs
|
||||
src/pg_stat_monitor/logfile
|
||||
retention-days: 1
|
||||
|
||||
- name: Start Server installcheck-world tests
|
||||
run: |
|
||||
make installcheck-world
|
||||
|
||||
- name: Report on installcheck-world test suites fail
|
||||
uses: actions/upload-artifact@v2
|
||||
if: ${{ failure() }}
|
||||
with:
|
||||
name: Regressions output files of failed testsuite, and pg log
|
||||
path: |
|
||||
**/regression.diffs
|
||||
**/regression.out
|
||||
src/pg_stat_monitor/logfile
|
||||
retention-days: 3
|
||||
|
|
@ -0,0 +1,62 @@
|
|||
name: postgresql-11-pgdg-package
|
||||
on: [push]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: pg-11-pgdg-package-test
|
||||
runs-on: ubuntu-20.04
|
||||
steps:
|
||||
- name: Clone pg_stat_monitor repository
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
path: 'src/pg_stat_monitor'
|
||||
|
||||
- name: Delete old postgresql files
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt purge postgresql-client-common postgresql-common \
|
||||
postgresql postgresql*
|
||||
sudo rm -rf /var/lib/postgresql /var/log/postgresql /etc/postgresql \
|
||||
/usr/lib/postgresql /usr/include/postgresql /usr/share/postgresql \
|
||||
/etc/postgresql
|
||||
sudo rm -f /usr/bin/pg_config
|
||||
|
||||
- name: Install PG Distribution Postgresql 11
|
||||
run: |
|
||||
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt \
|
||||
$(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
|
||||
sudo wget --quiet -O - \
|
||||
https://www.postgresql.org/media/keys/ACCC4CF8.asc |
|
||||
sudo apt-key add -
|
||||
sudo apt-get -y update
|
||||
sudo apt-get -y install postgresql-11 postgresql-server-dev-11
|
||||
|
||||
- name: Change src owner to postgres
|
||||
run: |
|
||||
sudo chown -R postgres:postgres src
|
||||
|
||||
- name: Build pg_stat_monitor
|
||||
run: |
|
||||
sudo -u postgres bash -c 'make USE_PGXS=1'
|
||||
sudo make USE_PGXS=1 install
|
||||
working-directory: src/pg_stat_monitor
|
||||
|
||||
- name: Start pg_stat_monitor_tests
|
||||
run: |
|
||||
sudo service postgresql stop
|
||||
echo "shared_preload_libraries = 'pg_stat_monitor'" |
|
||||
sudo tee -a /etc/postgresql/11/main/postgresql.conf
|
||||
sudo service postgresql start
|
||||
sudo psql -V
|
||||
sudo -u postgres bash -c 'make installcheck USE_PGXS=1'
|
||||
working-directory: src/pg_stat_monitor
|
||||
|
||||
- name: Report on test fail
|
||||
uses: actions/upload-artifact@v2
|
||||
if: ${{ failure() }}
|
||||
with:
|
||||
name: Regressions diff and postgresql log
|
||||
path: |
|
||||
src/pg_stat_monitor/regression.diffs
|
||||
src/pg_stat_monitor/logfile
|
||||
retention-days: 3
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
name: postgresql-11-pmm-integration
|
||||
on: push
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: pg-11-pgsm-pmm-integration-test
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 30
|
||||
steps:
|
||||
- name: Clone QA Integration repository
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
repository: 'Percona-Lab/qa-integration'
|
||||
ref: 'main'
|
||||
|
||||
# print branch and Repo name
|
||||
- name: Get branch and Repo Name
|
||||
run: echo 'The branch and Repo Name is' ${{ github.head_ref }} ${{ github.actor }}/pg_stat_monitor
|
||||
|
||||
- name: Run PMM & PGSM Setup, E2E Tests
|
||||
run: bash -xe ./pmm_pgsm_setup/pmm_pgsm_setup.sh --pgsql-version=11 --pgstat-monitor-branch=REL_1_1_1
|
||||
|
||||
- name: Get PMM-Agent Logs from the Container
|
||||
if: success() || failure() # run this step even if previous step failed
|
||||
run: docker exec pgsql_pgsm_11 cat pmm-agent.log > ./pmm-ui-tests/tests/output/pmm-agent.log
|
||||
|
||||
- name: Upload Tests Artifacts
|
||||
uses: actions/upload-artifact@v3
|
||||
if: success() || failure() # run this step even if previous step failed
|
||||
with:
|
||||
name: tests-artifact
|
||||
path: ./pmm-ui-tests/tests/output/
|
||||
if-no-files-found: ignore # 'warn' or 'ignore' are also available, defaults to `warn`
|
||||
|
|
@ -0,0 +1,71 @@
|
|||
name: postgresql-11-ppg-package
|
||||
on: [push]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: pg-11-ppg-package-test
|
||||
runs-on: ubuntu-20.04
|
||||
steps:
|
||||
- name: Clone pg_stat_monitor repository
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
path: 'src/pg_stat_monitor'
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt purge postgresql-client-common postgresql-common \
|
||||
postgresql postgresql*
|
||||
sudo apt-get install -y libreadline6-dev systemtap-sdt-dev \
|
||||
zlib1g-dev libssl-dev libpam0g-dev python3-dev bison flex \
|
||||
libipc-run-perl wget
|
||||
sudo rm -rf /var/lib/postgresql /var/log/postgresql /etc/postgresql \
|
||||
/usr/lib/postgresql /usr/include/postgresql /usr/share/postgresql \
|
||||
/etc/postgresql
|
||||
sudo rm -f /usr/bin/pg_config
|
||||
|
||||
- name: Install percona-release script
|
||||
run: |
|
||||
sudo apt-get -y update
|
||||
sudo apt-get -y upgrade
|
||||
sudo apt-get install -y wget gnupg2 curl lsb-release
|
||||
sudo wget \
|
||||
https://repo.percona.com/apt/percona-release_latest.generic_all.deb
|
||||
sudo dpkg -i percona-release_latest.generic_all.deb
|
||||
|
||||
- name: Install Percona Distribution Postgresql 11
|
||||
run: |
|
||||
sudo percona-release setup ppg-11
|
||||
sudo apt-get update -y
|
||||
sudo apt-get install -y percona-postgresql-11 \
|
||||
percona-postgresql-contrib percona-postgresql-server-dev-all
|
||||
|
||||
- name: Change src owner to postgres
|
||||
run: |
|
||||
sudo chown -R postgres:postgres src
|
||||
|
||||
- name: Build pg_stat_monitor
|
||||
run: |
|
||||
sudo -u postgres bash -c 'make USE_PGXS=1'
|
||||
sudo make USE_PGXS=1 install
|
||||
working-directory: src/pg_stat_monitor
|
||||
|
||||
- name: Start pg_stat_monitor_tests
|
||||
run: |
|
||||
sudo service postgresql stop
|
||||
echo "shared_preload_libraries = 'pg_stat_monitor'" |
|
||||
sudo tee -a /etc/postgresql/11/main/postgresql.conf
|
||||
sudo service postgresql start
|
||||
sudo psql -V
|
||||
sudo -u postgres bash -c 'make installcheck USE_PGXS=1'
|
||||
working-directory: src/pg_stat_monitor
|
||||
|
||||
- name: Report on test fail
|
||||
uses: actions/upload-artifact@v2
|
||||
if: ${{ failure() }}
|
||||
with:
|
||||
name: Regressions diff and postgresql log
|
||||
path: |
|
||||
src/pg_stat_monitor/regression.diffs
|
||||
src/pg_stat_monitor/logfile
|
||||
retention-days: 3
|
||||
|
|
@ -1,26 +1,16 @@
|
|||
name: postgresql-16-build
|
||||
on:
|
||||
pull_request:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
tags:
|
||||
- '[0-9]+.[0-9]+.[0-9]+*'
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
name: postgresql-12-build
|
||||
on: [push]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: pg-16-build-test
|
||||
name: pg-12-build-test
|
||||
runs-on: ubuntu-22.04
|
||||
timeout-minutes: 30
|
||||
steps:
|
||||
- name: Clone postgres repository
|
||||
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
repository: 'postgres/postgres'
|
||||
ref: 'REL_16_STABLE'
|
||||
ref: 'REL_12_STABLE'
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
|
|
@ -29,17 +19,17 @@ jobs:
|
|||
postgresql postgresql*
|
||||
sudo apt-get install -y libreadline6-dev systemtap-sdt-dev \
|
||||
zlib1g-dev libssl-dev libpam0g-dev bison flex \
|
||||
libipc-run-perl -y docbook-xsl docbook-xsl libxml2 libxml2-utils \
|
||||
libipc-run-perl docbook-xsl docbook-xsl libxml2 libxml2-utils \
|
||||
libxml2-dev libxslt-dev xsltproc libkrb5-dev libldap2-dev \
|
||||
libsystemd-dev gettext tcl-dev libperl-dev pkg-config clang-11 \
|
||||
llvm-11 llvm-11-dev libselinux1-dev python3-dev \
|
||||
uuid-dev liblz4-dev
|
||||
llvm-11 llvm-11-dev libselinux1-dev python3-dev uuid-dev liblz4-dev
|
||||
sudo rm -rf /var/lib/postgresql /var/log/postgresql /etc/postgresql \
|
||||
/usr/lib/postgresql /usr/include/postgresql /usr/share/postgresql \
|
||||
/etc/postgresql
|
||||
sudo rm -f /usr/bin/pg_config
|
||||
sudo /usr/bin/perl -MCPAN -e 'install IPC::Run'
|
||||
sudo /usr/bin/perl -MCPAN -e 'install Text::Trim'
|
||||
sudo /usr/bin/perl -MCPAN -e 'install IPC::RUN'
|
||||
sudo /usr/bin/perl -MCPAN -e 'install String::Util'
|
||||
sudo /usr/bin/perl -MCPAN -e 'install Data::Str2Num'
|
||||
|
||||
- name: Create pgsql dir
|
||||
run: mkdir -p /opt/pgsql
|
||||
|
|
@ -48,28 +38,29 @@ jobs:
|
|||
run: |
|
||||
export PATH="/opt/pgsql/bin:$PATH"
|
||||
./configure '--build=x86_64-linux-gnu' '--prefix=/usr' \
|
||||
'--includedir=${prefix}/include' '--mandir=${prefix}/share/man' \
|
||||
'--infodir=${prefix}/share/info' '--sysconfdir=/etc' \
|
||||
'--localstatedir=/var' '--libdir=${prefix}/lib/x86_64-linux-gnu' \
|
||||
'--libexecdir=${prefix}/lib/x86_64-linux-gnu' '--with-icu' \
|
||||
'--with-tcl' '--with-perl' '--with-python' '--with-pam' \
|
||||
'--with-openssl' '--with-libxml' '--with-libxslt' '--with-ldap' \
|
||||
'PYTHON=/usr/bin/python3' '--mandir=/usr/share/postgresql/16/man' \
|
||||
'--docdir=/usr/share/doc/postgresql-doc-16' '--with-pgport=5432' \
|
||||
'--includedir=/usr/include' '--mandir=/usr/share/man' \
|
||||
'--infodir=/usr/share/info' '--sysconfdir=/etc' '--with-gnu-ld' \
|
||||
'--localstatedir=/var' '--libdir=/usr/lib/x86_64-linux-gnu' \
|
||||
'runstatedir=/run' '--with-icu' '--with-tcl' '--with-perl' \
|
||||
'--with-python' '--with-pam' '--with-openssl' '--with-libxml' \
|
||||
'--with-libxslt' 'PYTHON=/usr/bin/python3' '--enable-tap-tests' \
|
||||
'--mandir=/usr/share/postgresql/12/man' '--enable-thread-safety' \
|
||||
'--docdir=/usr/share/doc/postgresql-doc-12' '--enable-debug' \
|
||||
'--sysconfdir=/etc/postgresql-common' '--datarootdir=/usr/share' \
|
||||
'--datadir=/usr/share/postgresql/16' '--with-uuid=e2fs' \
|
||||
'--bindir=/usr/lib/postgresql/16/bin' '--enable-tap-tests' \
|
||||
'--libdir=/usr/lib/x86_64-linux-gnu' '--enable-debug' \
|
||||
'--libexecdir=/usr/lib/postgresql' '--with-gnu-ld' \
|
||||
'--includedir=/usr/include/postgresql' '--enable-dtrace' \
|
||||
'--enable-nls' '--enable-thread-safety' '--disable-rpath' \
|
||||
'--datadir=/usr/share/postgresql/12' '--enable-dtrace' \
|
||||
'--bindir=/usr/lib/postgresql/12/bin' '--disable-rpath' \
|
||||
'--libdir=/usr/lib/x86_64-linux-gnu' '--with-pgport=5432' \
|
||||
'--libexecdir=/usr/lib/postgresql' '--with-uuid=e2fs' \
|
||||
'--includedir=/usr/include/postgresql' 'TAR=/bin/tar' \
|
||||
'--with-system-tzdata=/usr/share/zoneinfo' '--with-llvm' \
|
||||
'LLVM_CONFIG=/usr/bin/llvm-config-11' 'CLANG=/usr/bin/clang-11' \
|
||||
'--with-systemd' '--with-selinux' 'MKDIR_P=/bin/mkdir -p' \
|
||||
'PROVE=/usr/bin/prove' 'TAR=/bin/tar' 'XSLTPROC=xsltproc --nonet' \
|
||||
'PROVE=/usr/bin/prove' '--with-gssapi' '--with-ldap' \
|
||||
'LDFLAGS=-Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now' \
|
||||
'build_alias=x86_64-linux-gnu' '--with-gssapi' \
|
||||
'CPPFLAGS=-Wdate-time -D_FORTIFY_SOURCE=2' \
|
||||
'--with-includes=/usr/include/mit-krb5' '--with-libs=/usr/lib/mit-krb5' \
|
||||
'--with-libs=/usr/lib/x86_64-linux-gnu/mit-krb5' \
|
||||
'build_alias=x86_64-linux-gnu' \
|
||||
'CPPFLAGS=-Wdate-time -D_FORTIFY_SOURCE=2' '--enable-nls' \
|
||||
'CFLAGS=-g -O2 -fstack-protector-strong -Wformat -Werror=format-security -fno-omit-frame-pointer' \
|
||||
'CXXFLAGS=-g -O2 -fstack-protector-strong -Wformat -Werror=format-security'
|
||||
make world
|
||||
|
|
@ -77,13 +68,13 @@ jobs:
|
|||
|
||||
- name: Start postgresql cluster
|
||||
run: |
|
||||
export PATH="/usr/lib/postgresql/16/bin:$PATH"
|
||||
sudo cp /usr/lib/postgresql/16/bin/pg_config /usr/bin
|
||||
export PATH="/usr/lib/postgresql/12/bin:$PATH"
|
||||
sudo cp /usr/lib/postgresql/12/bin/pg_config /usr/bin
|
||||
initdb -D /opt/pgsql/data
|
||||
pg_ctl -D /opt/pgsql/data -l logfile start
|
||||
|
||||
- name: Clone pg_stat_monitor repository
|
||||
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
path: 'src/pg_stat_monitor'
|
||||
|
||||
|
|
@ -93,20 +84,19 @@ jobs:
|
|||
sudo make USE_PGXS=1 install
|
||||
working-directory: src/pg_stat_monitor
|
||||
|
||||
- name: Configure and Restart Server
|
||||
- name: Load pg_stat_monitor library and Restart Server
|
||||
run: |
|
||||
export PATH="/usr/lib/postgresql/16/bin:$PATH"
|
||||
export PATH="/usr/lib/postgresql/12/bin:$PATH"
|
||||
pg_ctl -D /opt/pgsql/data -l logfile stop
|
||||
echo "shared_preload_libraries = 'pg_stat_monitor'" >> \
|
||||
/opt/pgsql/data/postgresql.conf
|
||||
echo "compute_query_id = regress" >> /opt/pgsql/data/postgresql.conf
|
||||
pg_ctl -D /opt/pgsql/data -l logfile start
|
||||
working-directory: src/pg_stat_monitor
|
||||
|
||||
- name: Start pg_stat_monitor_tests
|
||||
run: |
|
||||
make installcheck
|
||||
working-directory: src/pg_stat_monitor/
|
||||
working-directory: src/pg_stat_monitor
|
||||
|
||||
- name: Change dir permissions on fail
|
||||
if: ${{ failure() }}
|
||||
|
|
@ -118,7 +108,7 @@ jobs:
|
|||
|
||||
- name: Upload logs on fail
|
||||
if: ${{ failure() }}
|
||||
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
|
||||
uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: Regressions diff and postgresql log
|
||||
path: |
|
||||
|
|
@ -137,10 +127,11 @@ jobs:
|
|||
retention-days: 3
|
||||
|
||||
- name: Start Server installcheck-world tests
|
||||
run: make installcheck-world
|
||||
run: |
|
||||
make installcheck-world
|
||||
|
||||
- name: Report on installcheck-world test suites fail
|
||||
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
|
||||
uses: actions/upload-artifact@v2
|
||||
if: ${{ failure() }}
|
||||
with:
|
||||
name: Regressions output files of failed testsuite, and pg log
|
||||
|
|
@ -1,23 +1,13 @@
|
|||
name: postgresql-16-pgdg-package
|
||||
on:
|
||||
pull_request:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
tags:
|
||||
- '[0-9]+.[0-9]+.[0-9]+*'
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
name: postgresql-12-pgdg-package
|
||||
on: [push]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: pg-16-pgdg-package-test
|
||||
runs-on: ubuntu-22.04
|
||||
timeout-minutes: 30
|
||||
name: pg-12-pgdg-package-test
|
||||
runs-on: ubuntu-20.04
|
||||
steps:
|
||||
- name: Clone pg_stat_monitor repository
|
||||
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
path: 'src/pg_stat_monitor'
|
||||
|
||||
|
|
@ -26,28 +16,29 @@ jobs:
|
|||
sudo apt-get update
|
||||
sudo apt purge postgresql-client-common postgresql-common \
|
||||
postgresql postgresql*
|
||||
sudo apt-get install -y libreadline6-dev systemtap-sdt-dev wget \
|
||||
zlib1g-dev libssl-dev libpam0g-dev bison flex libipc-run-perl
|
||||
sudo apt-get install -y libreadline6-dev systemtap-sdt-dev \
|
||||
zlib1g-dev libssl-dev libpam0g-dev python3-dev bison flex \
|
||||
libipc-run-perl wget -y
|
||||
sudo rm -rf /var/lib/postgresql /var/log/postgresql /etc/postgresql \
|
||||
/usr/lib/postgresql /usr/include/postgresql /usr/share/postgresql \
|
||||
/etc/postgresql
|
||||
sudo rm -f /usr/bin/pg_config
|
||||
sudo /usr/bin/perl -MCPAN -e 'install IPC::Run'
|
||||
sudo /usr/bin/perl -MCPAN -e 'install Text::Trim'
|
||||
sudo /usr/bin/perl -MCPAN -e 'install IPC::RUN'
|
||||
sudo /usr/bin/perl -MCPAN -e 'install String::Util'
|
||||
sudo /usr/bin/perl -MCPAN -e 'install Data::Str2Num'
|
||||
|
||||
- name: Install PG Distribution Postgresql 16
|
||||
- name: Install PG Distribution Postgresql 12
|
||||
run: |
|
||||
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt \
|
||||
$(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
|
||||
sudo wget --quiet -O - \
|
||||
https://www.postgresql.org/media/keys/ACCC4CF8.asc |
|
||||
sudo apt-key add -
|
||||
sudo apt update
|
||||
sudo apt -y install postgresql-16 postgresql-server-dev-16
|
||||
sudo apt-get -y update
|
||||
sudo apt-get -y install postgresql-12 postgresql-server-dev-12
|
||||
|
||||
- name: Change src owner to postgres
|
||||
run: |
|
||||
sudo chmod o+rx ~
|
||||
sudo chown -R postgres:postgres src
|
||||
|
||||
- name: Build pg_stat_monitor
|
||||
|
|
@ -60,12 +51,10 @@ jobs:
|
|||
run: |
|
||||
sudo service postgresql stop
|
||||
echo "shared_preload_libraries = 'pg_stat_monitor'" |
|
||||
sudo tee -a /etc/postgresql/16/main/postgresql.conf
|
||||
sudo tee -a /etc/postgresql/12/main/postgresql.conf
|
||||
sudo service postgresql start
|
||||
sudo psql -V
|
||||
export PG_TEST_PORT_DIR=${GITHUB_WORKSPACE}/src/pg_stat_monitor
|
||||
echo $PG_TEST_PORT_DIR
|
||||
sudo -E -u postgres bash -c 'make installcheck USE_PGXS=1'
|
||||
sudo -u postgres bash -c 'make installcheck USE_PGXS=1'
|
||||
working-directory: src/pg_stat_monitor
|
||||
|
||||
- name: Change dir permissions on fail
|
||||
|
|
@ -78,7 +67,7 @@ jobs:
|
|||
|
||||
- name: Upload logs on fail
|
||||
if: ${{ failure() }}
|
||||
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
|
||||
uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: Regressions diff and postgresql log
|
||||
path: |
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
name: postgresql-12-pmm-integration
|
||||
on: push
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: pg-12-pgsm-pmm-integration-test
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 30
|
||||
steps:
|
||||
- name: Clone QA Integration repository
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
repository: 'Percona-Lab/qa-integration'
|
||||
ref: 'main'
|
||||
|
||||
# print branch and Repo name
|
||||
- name: Get branch and Repo Name
|
||||
run: echo 'The branch and Repo Name is' ${{ github.head_ref }} ${{ github.actor }}/pg_stat_monitor
|
||||
|
||||
- name: Run PMM & PGSM Setup, E2E Tests
|
||||
run: bash -xe ./pmm_pgsm_setup/pmm_pgsm_setup.sh --pgsql-version=12 --pgstat-monitor-branch=REL_1_1_1
|
||||
|
||||
- name: Get PMM-Agent Logs from the Container
|
||||
if: success() || failure() # run this step even if previous step failed
|
||||
run: docker exec pgsql_pgsm_12 cat pmm-agent.log > ./pmm-ui-tests/tests/output/pmm-agent.log
|
||||
|
||||
- name: Upload Tests Artifacts
|
||||
uses: actions/upload-artifact@v3
|
||||
if: success() || failure() # run this step even if previous step failed
|
||||
with:
|
||||
name: tests-artifact
|
||||
path: ./pmm-ui-tests/tests/output/
|
||||
if-no-files-found: ignore # 'warn' or 'ignore' are also available, defaults to `warn`
|
||||
|
|
@ -1,27 +1,17 @@
|
|||
name: postgresql-15-ppg-package
|
||||
on:
|
||||
pull_request:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
tags:
|
||||
- '[0-9]+.[0-9]+.[0-9]+*'
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
name: postgresql-12-ppg-package
|
||||
on: [push]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: pg-15-ppg-package-test
|
||||
runs-on: ubuntu-22.04
|
||||
timeout-minutes: 30
|
||||
name: pg-12-ppg-package-test
|
||||
runs-on: ubuntu-20.04
|
||||
steps:
|
||||
- name: Clone pg_stat_monitor repository
|
||||
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
path: 'src/pg_stat_monitor'
|
||||
|
||||
- name: Delete old postgresql files
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt purge postgresql-client-common postgresql-common \
|
||||
|
|
@ -29,12 +19,16 @@ jobs:
|
|||
sudo apt-get install -y libreadline6-dev systemtap-sdt-dev \
|
||||
zlib1g-dev libssl-dev libpam0g-dev python3-dev bison flex \
|
||||
libipc-run-perl wget
|
||||
sudo apt-get install -y libreadline6-dev systemtap-sdt-dev \
|
||||
zlib1g-dev libssl-dev libpam0g-dev python3-dev bison flex \
|
||||
libipc-run-perl wget
|
||||
sudo rm -rf /var/lib/postgresql /var/log/postgresql /etc/postgresql \
|
||||
/usr/lib/postgresql /usr/include/postgresql /usr/share/postgresql \
|
||||
/etc/postgresql
|
||||
sudo rm -f /usr/bin/pg_config
|
||||
sudo /usr/bin/perl -MCPAN -e 'install IPC::Run'
|
||||
sudo /usr/bin/perl -MCPAN -e 'install Text::Trim'
|
||||
sudo /usr/bin/perl -MCPAN -e 'install IPC::RUN'
|
||||
sudo /usr/bin/perl -MCPAN -e 'install String::Util'
|
||||
sudo /usr/bin/perl -MCPAN -e 'install Data::Str2Num'
|
||||
|
||||
- name: Install percona-release script
|
||||
run: |
|
||||
|
|
@ -45,23 +39,15 @@ jobs:
|
|||
https://repo.percona.com/apt/percona-release_latest.generic_all.deb
|
||||
sudo dpkg -i percona-release_latest.generic_all.deb
|
||||
|
||||
- name: Install Percona Distribution Postgresql 15 & Extensions
|
||||
- name: Install Percona Distribution Postgresql 12
|
||||
run: |
|
||||
sudo percona-release setup ppg-15
|
||||
sudo percona-release setup ppg-12
|
||||
sudo apt-get update -y
|
||||
sudo apt-get install -y percona-postgresql-15 \
|
||||
percona-postgresql-contrib percona-postgresql-server-dev-all \
|
||||
percona-pgpool2 libpgpool2 percona-postgresql-15-pgaudit \
|
||||
percona-postgresql-15-pgaudit-dbgsym percona-postgresql-15-repack \
|
||||
percona-postgresql-15-repack-dbgsym percona-pgaudit15-set-user \
|
||||
percona-pgaudit15-set-user-dbgsym percona-postgresql-15-postgis-3 \
|
||||
percona-postgresql-15-postgis-3-scripts \
|
||||
percona-postgresql-postgis-scripts percona-postgresql-postgis \
|
||||
percona-postgis
|
||||
sudo apt-get install -y percona-postgresql-12 \
|
||||
percona-postgresql-contrib percona-postgresql-server-dev-all
|
||||
|
||||
- name: Change src owner to postgres
|
||||
run: |
|
||||
sudo chmod o+rx ~
|
||||
sudo chown -R postgres:postgres src
|
||||
|
||||
- name: Build pg_stat_monitor
|
||||
|
|
@ -74,12 +60,10 @@ jobs:
|
|||
run: |
|
||||
sudo service postgresql stop
|
||||
echo "shared_preload_libraries = 'pg_stat_monitor'" |
|
||||
sudo tee -a /etc/postgresql/15/main/postgresql.conf
|
||||
sudo tee -a /etc/postgresql/12/main/postgresql.conf
|
||||
sudo service postgresql start
|
||||
sudo psql -V
|
||||
export PG_TEST_PORT_DIR=${GITHUB_WORKSPACE}/src/pg_stat_monitor
|
||||
echo $PG_TEST_PORT_DIR
|
||||
sudo -E -u postgres bash -c 'make installcheck USE_PGXS=1'
|
||||
sudo -u postgres bash -c 'make installcheck USE_PGXS=1'
|
||||
working-directory: src/pg_stat_monitor
|
||||
|
||||
- name: Change dir permissions on fail
|
||||
|
|
@ -92,7 +76,7 @@ jobs:
|
|||
|
||||
- name: Upload logs on fail
|
||||
if: ${{ failure() }}
|
||||
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
|
||||
uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: Regressions diff and postgresql log
|
||||
path: |
|
||||
|
|
@ -1,23 +1,13 @@
|
|||
name: postgresql-13-build
|
||||
on:
|
||||
pull_request:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
tags:
|
||||
- '[0-9]+.[0-9]+.[0-9]+*'
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
on: [push]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: pg-13-build-test
|
||||
runs-on: ubuntu-22.04
|
||||
timeout-minutes: 30
|
||||
steps:
|
||||
- name: Clone postgres repository
|
||||
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
repository: 'postgres/postgres'
|
||||
ref: 'REL_13_STABLE'
|
||||
|
|
@ -37,8 +27,9 @@ jobs:
|
|||
/usr/lib/postgresql /usr/include/postgresql /usr/share/postgresql \
|
||||
/etc/postgresql
|
||||
sudo rm -f /usr/bin/pg_config
|
||||
sudo /usr/bin/perl -MCPAN -e 'install IPC::Run'
|
||||
sudo /usr/bin/perl -MCPAN -e 'install Text::Trim'
|
||||
sudo /usr/bin/perl -MCPAN -e 'install IPC::RUN'
|
||||
sudo /usr/bin/perl -MCPAN -e 'install String::Util'
|
||||
sudo /usr/bin/perl -MCPAN -e 'install Data::Str2Num'
|
||||
|
||||
- name: Create pgsql dir
|
||||
run: mkdir -p /opt/pgsql
|
||||
|
|
@ -83,7 +74,7 @@ jobs:
|
|||
pg_ctl -D /opt/pgsql/data -l logfile start
|
||||
|
||||
- name: Clone pg_stat_monitor repository
|
||||
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
path: 'src/pg_stat_monitor'
|
||||
|
||||
|
|
@ -117,7 +108,7 @@ jobs:
|
|||
|
||||
- name: Upload logs on fail
|
||||
if: ${{ failure() }}
|
||||
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
|
||||
uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: Regressions diff and postgresql log
|
||||
path: |
|
||||
|
|
@ -140,7 +131,7 @@ jobs:
|
|||
make installcheck-world
|
||||
|
||||
- name: Report on installcheck-world test suites fail
|
||||
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
|
||||
uses: actions/upload-artifact@v2
|
||||
if: ${{ failure() }}
|
||||
with:
|
||||
name: Regressions output files of failed testsuite, and pg log
|
||||
|
|
|
|||
|
|
@ -1,23 +1,13 @@
|
|||
name: postgresql-13-pgdg-package
|
||||
on:
|
||||
pull_request:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
tags:
|
||||
- '[0-9]+.[0-9]+.[0-9]+*'
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
on: [push]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: pg-13-pgdg-package-test
|
||||
runs-on: ubuntu-22.04
|
||||
timeout-minutes: 30
|
||||
runs-on: ubuntu-20.04
|
||||
steps:
|
||||
- name: Clone pg_stat_monitor repository
|
||||
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
path: 'src/pg_stat_monitor'
|
||||
|
||||
|
|
@ -33,8 +23,9 @@ jobs:
|
|||
/usr/lib/postgresql /usr/include/postgresql /usr/share/postgresql \
|
||||
/etc/postgresql
|
||||
sudo rm -f /usr/bin/pg_config
|
||||
sudo /usr/bin/perl -MCPAN -e 'install IPC::Run'
|
||||
sudo /usr/bin/perl -MCPAN -e 'install Text::Trim'
|
||||
sudo /usr/bin/perl -MCPAN -e 'install IPC::RUN'
|
||||
sudo /usr/bin/perl -MCPAN -e 'install String::Util'
|
||||
sudo /usr/bin/perl -MCPAN -e 'install Data::Str2Num'
|
||||
|
||||
- name: Install PG Distribution Postgresql 13
|
||||
run: |
|
||||
|
|
@ -48,7 +39,6 @@ jobs:
|
|||
|
||||
- name: Change src owner to postgres
|
||||
run: |
|
||||
sudo chmod o+rx ~
|
||||
sudo chown -R postgres:postgres src
|
||||
|
||||
- name: Build pg_stat_monitor
|
||||
|
|
@ -64,9 +54,7 @@ jobs:
|
|||
sudo tee -a /etc/postgresql/13/main/postgresql.conf
|
||||
sudo service postgresql start
|
||||
sudo psql -V
|
||||
export PG_TEST_PORT_DIR=${GITHUB_WORKSPACE}/src/pg_stat_monitor
|
||||
echo $PG_TEST_PORT_DIR
|
||||
sudo -E -u postgres bash -c 'make installcheck USE_PGXS=1'
|
||||
sudo -u postgres bash -c 'make installcheck USE_PGXS=1'
|
||||
working-directory: src/pg_stat_monitor
|
||||
|
||||
- name: Change dir permissions on fail
|
||||
|
|
@ -79,7 +67,7 @@ jobs:
|
|||
|
||||
- name: Upload logs on fail
|
||||
if: ${{ failure() }}
|
||||
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
|
||||
uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: Regressions diff and postgresql log
|
||||
path: |
|
||||
|
|
|
|||
|
|
@ -1,14 +1,5 @@
|
|||
name: postgresql-13-pmm-integration
|
||||
on:
|
||||
pull_request:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
tags:
|
||||
- '[0-9]+.[0-9]+.[0-9]+*'
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
on: push
|
||||
|
||||
jobs:
|
||||
build:
|
||||
|
|
@ -17,7 +8,7 @@ jobs:
|
|||
timeout-minutes: 30
|
||||
steps:
|
||||
- name: Clone QA Integration repository
|
||||
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
repository: 'Percona-Lab/qa-integration'
|
||||
ref: 'main'
|
||||
|
|
@ -26,23 +17,15 @@ jobs:
|
|||
- name: Get branch and Repo Name
|
||||
run: echo 'The branch and Repo Name is' ${{ github.head_ref }} ${{ github.actor }}/pg_stat_monitor
|
||||
|
||||
- name: "Set TARGET_BRANCH variable for a PR run"
|
||||
if: github.event_name == 'pull_request'
|
||||
run: echo "TARGET_BRANCH=${{ github.event.pull_request.base.ref }}" >> $GITHUB_ENV
|
||||
|
||||
- name: "Set TARGET_BRANCH variable for a PUSH run"
|
||||
if: github.event_name == 'push'
|
||||
run: echo "TARGET_BRANCH=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
|
||||
|
||||
- name: Run PMM & PGSM Setup, E2E Tests
|
||||
run: bash -xe ./pmm_pgsm_setup/pmm_pgsm_setup.sh --pgsql-version=13 --pgstat-monitor-branch=${{ env.TARGET_BRANCH }}
|
||||
run: bash -xe ./pmm_pgsm_setup/pmm_pgsm_setup.sh --pgsql-version=13 --pgstat-monitor-branch=REL_1_1_1
|
||||
|
||||
- name: Get PMM-Agent Logs from the Container
|
||||
if: success() || failure() # run this step even if previous step failed
|
||||
run: docker exec pgsql_pgsm_13 cat pmm-agent.log > ./pmm-ui-tests/tests/output/pmm-agent.log
|
||||
|
||||
- name: Upload Tests Artifacts
|
||||
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
|
||||
uses: actions/upload-artifact@v3
|
||||
if: success() || failure() # run this step even if previous step failed
|
||||
with:
|
||||
name: tests-artifact
|
||||
|
|
|
|||
|
|
@ -1,23 +1,13 @@
|
|||
name: postgresql-13-ppg-package
|
||||
on:
|
||||
pull_request:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
tags:
|
||||
- '[0-9]+.[0-9]+.[0-9]+*'
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
on: [push]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: pg-13-ppg-package-test
|
||||
runs-on: ubuntu-22.04
|
||||
timeout-minutes: 30
|
||||
runs-on: ubuntu-20.04
|
||||
steps:
|
||||
- name: Clone pg_stat_monitor repository
|
||||
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
path: 'src/pg_stat_monitor'
|
||||
|
||||
|
|
@ -33,8 +23,9 @@ jobs:
|
|||
/usr/lib/postgresql /usr/include/postgresql /usr/share/postgresql \
|
||||
/etc/postgresql
|
||||
sudo rm -f /usr/bin/pg_config
|
||||
sudo /usr/bin/perl -MCPAN -e 'install IPC::Run'
|
||||
sudo /usr/bin/perl -MCPAN -e 'install Text::Trim'
|
||||
sudo /usr/bin/perl -MCPAN -e 'install IPC::RUN'
|
||||
sudo /usr/bin/perl -MCPAN -e 'install String::Util'
|
||||
sudo /usr/bin/perl -MCPAN -e 'install Data::Str2Num'
|
||||
|
||||
- name: Install percona-release script
|
||||
run: |
|
||||
|
|
@ -45,23 +36,15 @@ jobs:
|
|||
https://repo.percona.com/apt/percona-release_latest.generic_all.deb
|
||||
sudo dpkg -i percona-release_latest.generic_all.deb
|
||||
|
||||
- name: Install Percona Distribution Postgresql 13 & Extensions
|
||||
- name: Install Percona Distribution Postgresql 13
|
||||
run: |
|
||||
sudo percona-release setup ppg-13
|
||||
sudo apt-get update -y
|
||||
sudo apt-get install -y percona-postgresql-13 \
|
||||
percona-postgresql-contrib percona-postgresql-server-dev-all \
|
||||
percona-pgpool2 libpgpool2 percona-postgresql-13-pgaudit \
|
||||
percona-postgresql-13-pgaudit-dbgsym percona-postgresql-13-repack \
|
||||
percona-postgresql-13-repack-dbgsym percona-pgaudit13-set-user \
|
||||
percona-pgaudit13-set-user-dbgsym percona-postgresql-13-postgis-3 \
|
||||
percona-postgresql-13-postgis-3-scripts \
|
||||
percona-postgresql-postgis-scripts percona-postgresql-postgis \
|
||||
percona-postgis
|
||||
percona-postgresql-contrib percona-postgresql-server-dev-all
|
||||
|
||||
- name: Change src owner to postgres
|
||||
run: |
|
||||
sudo chmod o+rx ~
|
||||
sudo chown -R postgres:postgres src
|
||||
|
||||
- name: Build pg_stat_monitor
|
||||
|
|
@ -77,9 +60,7 @@ jobs:
|
|||
sudo tee -a /etc/postgresql/13/main/postgresql.conf
|
||||
sudo service postgresql start
|
||||
sudo psql -V
|
||||
export PG_TEST_PORT_DIR=${GITHUB_WORKSPACE}/src/pg_stat_monitor
|
||||
echo $PG_TEST_PORT_DIR
|
||||
sudo -E -u postgres bash -c 'make installcheck USE_PGXS=1'
|
||||
sudo -u postgres bash -c 'make installcheck USE_PGXS=1'
|
||||
working-directory: src/pg_stat_monitor
|
||||
|
||||
- name: Change dir permissions on fail
|
||||
|
|
@ -92,7 +73,7 @@ jobs:
|
|||
|
||||
- name: Upload logs on fail
|
||||
if: ${{ failure() }}
|
||||
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
|
||||
uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: Regressions diff and postgresql log
|
||||
path: |
|
||||
|
|
|
|||
|
|
@ -1,23 +1,13 @@
|
|||
name: postgresql-14-build
|
||||
on:
|
||||
pull_request:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
tags:
|
||||
- '[0-9]+.[0-9]+.[0-9]+*'
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
on: ["push", "pull_request"]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: pg-14-build-test
|
||||
runs-on: ubuntu-22.04
|
||||
timeout-minutes: 30
|
||||
steps:
|
||||
- name: Clone postgres repository
|
||||
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
repository: 'postgres/postgres'
|
||||
ref: 'REL_14_STABLE'
|
||||
|
|
@ -38,8 +28,9 @@ jobs:
|
|||
/usr/lib/postgresql /usr/include/postgresql /usr/share/postgresql \
|
||||
/etc/postgresql
|
||||
sudo rm -f /usr/bin/pg_config
|
||||
sudo /usr/bin/perl -MCPAN -e 'install IPC::Run'
|
||||
sudo /usr/bin/perl -MCPAN -e 'install Text::Trim'
|
||||
sudo /usr/bin/perl -MCPAN -e 'install IPC::RUN'
|
||||
sudo /usr/bin/perl -MCPAN -e 'install String::Util'
|
||||
sudo /usr/bin/perl -MCPAN -e 'install Data::Str2Num'
|
||||
|
||||
- name: Create pgsql dir
|
||||
run: mkdir -p /opt/pgsql
|
||||
|
|
@ -83,7 +74,7 @@ jobs:
|
|||
pg_ctl -D /opt/pgsql/data -l logfile start
|
||||
|
||||
- name: Clone pg_stat_monitor repository
|
||||
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
path: 'src/pg_stat_monitor'
|
||||
|
||||
|
|
@ -93,13 +84,12 @@ jobs:
|
|||
sudo make USE_PGXS=1 install
|
||||
working-directory: src/pg_stat_monitor
|
||||
|
||||
- name: Configure and Restart Server
|
||||
- name: Load pg_stat_monitor library and Restart Server
|
||||
run: |
|
||||
export PATH="/usr/lib/postgresql/14/bin:$PATH"
|
||||
pg_ctl -D /opt/pgsql/data -l logfile stop
|
||||
echo "shared_preload_libraries = 'pg_stat_monitor'" >> \
|
||||
/opt/pgsql/data/postgresql.conf
|
||||
echo "compute_query_id = regress" >> /opt/pgsql/data/postgresql.conf
|
||||
pg_ctl -D /opt/pgsql/data -l logfile start
|
||||
working-directory: src/pg_stat_monitor
|
||||
|
||||
|
|
@ -118,7 +108,7 @@ jobs:
|
|||
|
||||
- name: Upload logs on fail
|
||||
if: ${{ failure() }}
|
||||
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
|
||||
uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: Regressions diff and postgresql log
|
||||
path: |
|
||||
|
|
@ -135,17 +125,3 @@ jobs:
|
|||
!src/pg_stat_monitor/tmp_check/**/pgdata/
|
||||
if-no-files-found: warn
|
||||
retention-days: 3
|
||||
|
||||
- name: Start Server installcheck-world tests
|
||||
run: make installcheck-world
|
||||
|
||||
- name: Report on installcheck-world test suites fail
|
||||
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
|
||||
if: ${{ failure() }}
|
||||
with:
|
||||
name: Regressions output files of failed testsuite, and pg log
|
||||
path: |
|
||||
**/regression.diffs
|
||||
**/regression.out
|
||||
src/pg_stat_monitor/logfile
|
||||
retention-days: 3
|
||||
|
|
|
|||
|
|
@ -1,23 +1,13 @@
|
|||
name: postgresql-14-pgdg-package
|
||||
on:
|
||||
pull_request:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
tags:
|
||||
- '[0-9]+.[0-9]+.[0-9]+*'
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
on: [push]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: pg-14-pgdg-package-test
|
||||
runs-on: ubuntu-22.04
|
||||
timeout-minutes: 30
|
||||
runs-on: ubuntu-20.04
|
||||
steps:
|
||||
- name: Clone pg_stat_monitor repository
|
||||
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
path: 'src/pg_stat_monitor'
|
||||
|
||||
|
|
@ -32,8 +22,9 @@ jobs:
|
|||
/usr/lib/postgresql /usr/include/postgresql /usr/share/postgresql \
|
||||
/etc/postgresql
|
||||
sudo rm -f /usr/bin/pg_config
|
||||
sudo /usr/bin/perl -MCPAN -e 'install IPC::Run'
|
||||
sudo /usr/bin/perl -MCPAN -e 'install Text::Trim'
|
||||
sudo /usr/bin/perl -MCPAN -e 'install IPC::RUN'
|
||||
sudo /usr/bin/perl -MCPAN -e 'install String::Util'
|
||||
sudo /usr/bin/perl -MCPAN -e 'install Data::Str2Num'
|
||||
|
||||
- name: Install PG Distribution Postgresql 14
|
||||
run: |
|
||||
|
|
@ -47,7 +38,6 @@ jobs:
|
|||
|
||||
- name: Change src owner to postgres
|
||||
run: |
|
||||
sudo chmod o+rx ~
|
||||
sudo chown -R postgres:postgres src
|
||||
|
||||
- name: Build pg_stat_monitor
|
||||
|
|
@ -63,9 +53,7 @@ jobs:
|
|||
sudo tee -a /etc/postgresql/14/main/postgresql.conf
|
||||
sudo service postgresql start
|
||||
sudo psql -V
|
||||
export PG_TEST_PORT_DIR=${GITHUB_WORKSPACE}/src/pg_stat_monitor
|
||||
echo $PG_TEST_PORT_DIR
|
||||
sudo -E -u postgres bash -c 'make installcheck USE_PGXS=1'
|
||||
sudo -u postgres bash -c 'make installcheck USE_PGXS=1'
|
||||
working-directory: src/pg_stat_monitor
|
||||
|
||||
- name: Change dir permissions on fail
|
||||
|
|
@ -78,7 +66,7 @@ jobs:
|
|||
|
||||
- name: Upload logs on fail
|
||||
if: ${{ failure() }}
|
||||
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
|
||||
uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: Regressions diff and postgresql log
|
||||
path: |
|
||||
|
|
|
|||
|
|
@ -1,14 +1,5 @@
|
|||
name: postgresql-14-pmm-integration
|
||||
on:
|
||||
pull_request:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
tags:
|
||||
- '[0-9]+.[0-9]+.[0-9]+*'
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
on: push
|
||||
|
||||
jobs:
|
||||
build:
|
||||
|
|
@ -17,7 +8,7 @@ jobs:
|
|||
timeout-minutes: 30
|
||||
steps:
|
||||
- name: Clone QA Integration repository
|
||||
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
repository: 'Percona-Lab/qa-integration'
|
||||
ref: 'main'
|
||||
|
|
@ -26,23 +17,15 @@ jobs:
|
|||
- name: Get branch and Repo Name
|
||||
run: echo 'The branch and Repo Name is' ${{ github.head_ref }} ${{ github.actor }}/pg_stat_monitor
|
||||
|
||||
- name: "Set TARGET_BRANCH variable for a PR run"
|
||||
if: github.event_name == 'pull_request'
|
||||
run: echo "TARGET_BRANCH=${{ github.event.pull_request.base.ref }}" >> $GITHUB_ENV
|
||||
|
||||
- name: "Set TARGET_BRANCH variable for a PUSH run"
|
||||
if: github.event_name == 'push'
|
||||
run: echo "TARGET_BRANCH=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
|
||||
|
||||
- name: Run PMM & PGSM Setup, E2E Tests
|
||||
run: bash -xe ./pmm_pgsm_setup/pmm_pgsm_setup.sh --pgsql-version=14 --pgstat-monitor-branch=${{ env.TARGET_BRANCH }}
|
||||
run: bash -xe ./pmm_pgsm_setup/pmm_pgsm_setup.sh --pgsql-version=14 --pgstat-monitor-branch=REL_1_1_1
|
||||
|
||||
- name: Get PMM-Agent Logs from the Container
|
||||
if: success() || failure() # run this step even if previous step failed
|
||||
run: docker exec pgsql_pgsm_14 cat pmm-agent.log > ./pmm-ui-tests/tests/output/pmm-agent.log
|
||||
|
||||
- name: Upload Tests Artifacts
|
||||
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
|
||||
uses: actions/upload-artifact@v3
|
||||
if: success() || failure() # run this step even if previous step failed
|
||||
with:
|
||||
name: tests-artifact
|
||||
|
|
|
|||
|
|
@ -1,23 +1,13 @@
|
|||
name: postgresql-14-ppg-package
|
||||
on:
|
||||
pull_request:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
tags:
|
||||
- '[0-9]+.[0-9]+.[0-9]+*'
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
on: [push]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: pg-14-ppg-package-test
|
||||
runs-on: ubuntu-22.04
|
||||
timeout-minutes: 30
|
||||
runs-on: ubuntu-20.04
|
||||
steps:
|
||||
- name: Clone pg_stat_monitor repository
|
||||
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
path: 'src/pg_stat_monitor'
|
||||
|
||||
|
|
@ -33,8 +23,9 @@ jobs:
|
|||
/usr/lib/postgresql /usr/include/postgresql /usr/share/postgresql \
|
||||
/etc/postgresql
|
||||
sudo rm -f /usr/bin/pg_config
|
||||
sudo /usr/bin/perl -MCPAN -e 'install IPC::Run'
|
||||
sudo /usr/bin/perl -MCPAN -e 'install Text::Trim'
|
||||
sudo /usr/bin/perl -MCPAN -e 'install IPC::RUN'
|
||||
sudo /usr/bin/perl -MCPAN -e 'install String::Util'
|
||||
sudo /usr/bin/perl -MCPAN -e 'install Data::Str2Num'
|
||||
|
||||
- name: Install percona-release script
|
||||
run: |
|
||||
|
|
@ -45,23 +36,15 @@ jobs:
|
|||
https://repo.percona.com/apt/percona-release_latest.generic_all.deb
|
||||
sudo dpkg -i percona-release_latest.generic_all.deb
|
||||
|
||||
- name: Install Percona Distribution Postgresql 14 & Extensions
|
||||
- name: Install Percona Distribution Postgresql 14
|
||||
run: |
|
||||
sudo percona-release setup ppg-14
|
||||
sudo apt-get update -y
|
||||
sudo apt-get install -y percona-postgresql-14 \
|
||||
percona-postgresql-contrib percona-postgresql-server-dev-all \
|
||||
percona-pgpool2 libpgpool2 percona-postgresql-14-pgaudit \
|
||||
percona-postgresql-14-pgaudit-dbgsym percona-postgresql-14-repack \
|
||||
percona-postgresql-14-repack-dbgsym percona-pgaudit14-set-user \
|
||||
percona-pgaudit14-set-user-dbgsym percona-postgresql-14-postgis-3 \
|
||||
percona-postgresql-14-postgis-3-scripts \
|
||||
percona-postgresql-postgis-scripts percona-postgresql-postgis \
|
||||
percona-postgis
|
||||
percona-postgresql-contrib percona-postgresql-server-dev-all
|
||||
|
||||
- name: Change src owner to postgres
|
||||
run: |
|
||||
sudo chmod o+rx ~
|
||||
sudo chown -R postgres:postgres src
|
||||
|
||||
- name: Build pg_stat_monitor
|
||||
|
|
@ -77,9 +60,7 @@ jobs:
|
|||
sudo tee -a /etc/postgresql/14/main/postgresql.conf
|
||||
sudo service postgresql start
|
||||
sudo psql -V
|
||||
export PG_TEST_PORT_DIR=${GITHUB_WORKSPACE}/src/pg_stat_monitor
|
||||
echo $PG_TEST_PORT_DIR
|
||||
sudo -E -u postgres bash -c 'make installcheck USE_PGXS=1'
|
||||
sudo -u postgres bash -c 'make installcheck USE_PGXS=1'
|
||||
working-directory: src/pg_stat_monitor
|
||||
|
||||
- name: Change dir permissions on fail
|
||||
|
|
@ -92,7 +73,7 @@ jobs:
|
|||
|
||||
- name: Upload logs on fail
|
||||
if: ${{ failure() }}
|
||||
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
|
||||
uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: Regressions diff and postgresql log
|
||||
path: |
|
||||
|
|
|
|||
|
|
@ -1,23 +1,13 @@
|
|||
name: postgresql-15-build
|
||||
on:
|
||||
pull_request:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
tags:
|
||||
- '[0-9]+.[0-9]+.[0-9]+*'
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
on: ["push", "pull_request"]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: pg-15-build-test
|
||||
runs-on: ubuntu-22.04
|
||||
timeout-minutes: 30
|
||||
steps:
|
||||
- name: Clone postgres repository
|
||||
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
repository: 'postgres/postgres'
|
||||
ref: 'REL_15_STABLE'
|
||||
|
|
@ -25,21 +15,21 @@ jobs:
|
|||
- name: Install dependencies
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt purge postgresql-client-common postgresql-common \
|
||||
postgresql postgresql*
|
||||
sudo apt-get install -y libreadline6-dev systemtap-sdt-dev \
|
||||
zlib1g-dev libssl-dev libpam0g-dev bison flex \
|
||||
libipc-run-perl -y docbook-xsl docbook-xsl libxml2 libxml2-utils \
|
||||
libxml2-dev libxslt-dev xsltproc libkrb5-dev libldap2-dev \
|
||||
libsystemd-dev gettext tcl-dev libperl-dev pkg-config clang-11 \
|
||||
llvm-11 llvm-11-dev libselinux1-dev python3-dev \
|
||||
uuid-dev liblz4-dev
|
||||
sudo rm -rf /var/lib/postgresql /var/log/postgresql /etc/postgresql \
|
||||
/usr/lib/postgresql /usr/include/postgresql /usr/share/postgresql \
|
||||
/etc/postgresql
|
||||
sudo apt purge postgresql-client-common postgresql-common postgresql postgresql*
|
||||
sudo apt-get install libreadline6-dev systemtap-sdt-dev zlib1g-dev libssl-dev libpam0g-dev python3-dev bison flex libipc-run-perl -y docbook-xsl docbook-xsl
|
||||
sudo apt-get install -y libxml2 libxml2-utils libxml2-dev libxslt-dev xsltproc libkrb5-dev libldap2-dev libsystemd-dev gettext tcl-dev libperl-dev
|
||||
sudo apt-get install -y pkg-config clang-11 llvm-11 llvm-11-dev libselinux1-dev uuid-dev liblz4-dev
|
||||
sudo rm -rf /var/lib/postgresql/
|
||||
sudo rm -rf /var/log/postgresql/
|
||||
sudo rm -rf /etc/postgresql/
|
||||
sudo rm -rf /usr/lib/postgresql
|
||||
sudo rm -rf /usr/include/postgresql
|
||||
sudo rm -rf /usr/share/postgresql
|
||||
sudo rm -rf /etc/postgresql
|
||||
sudo rm -f /usr/bin/pg_config
|
||||
sudo /usr/bin/perl -MCPAN -e 'install IPC::Run'
|
||||
sudo /usr/bin/perl -MCPAN -e 'install Text::Trim'
|
||||
sudo /usr/bin/perl -MCPAN -e 'install IPC::RUN'
|
||||
sudo /usr/bin/perl -MCPAN -e 'install String::Util'
|
||||
sudo /usr/bin/perl -MCPAN -e 'install Data::Str2Num'
|
||||
|
||||
- name: Create pgsql dir
|
||||
run: mkdir -p /opt/pgsql
|
||||
|
|
@ -47,61 +37,55 @@ jobs:
|
|||
- name: Build postgres
|
||||
run: |
|
||||
export PATH="/opt/pgsql/bin:$PATH"
|
||||
./configure '--build=x86_64-linux-gnu' '--prefix=/usr' \
|
||||
'--includedir=${prefix}/include' '--mandir=${prefix}/share/man' \
|
||||
'--infodir=${prefix}/share/info' '--sysconfdir=/etc' \
|
||||
'--localstatedir=/var' '--libdir=${prefix}/lib/x86_64-linux-gnu' \
|
||||
'--libexecdir=${prefix}/lib/x86_64-linux-gnu' '--with-icu' \
|
||||
'--with-tcl' '--with-perl' '--with-python' '--with-pam' \
|
||||
'--with-openssl' '--with-libxml' '--with-libxslt' '--with-ldap' \
|
||||
./configure '--build=x86_64-linux-gnu' '--prefix=/usr' '--includedir=${prefix}/include' \
|
||||
'--mandir=${prefix}/share/man' '--infodir=${prefix}/share/info' \
|
||||
'--sysconfdir=/etc' '--localstatedir=/var' \
|
||||
'--libdir=${prefix}/lib/x86_64-linux-gnu' \
|
||||
'--libexecdir=${prefix}/lib/x86_64-linux-gnu' \
|
||||
'--with-icu' '--with-tcl' '--with-perl' \
|
||||
'--with-python' '--with-pam' '--with-openssl' '--with-libxml' '--with-libxslt' \
|
||||
'PYTHON=/usr/bin/python3' '--mandir=/usr/share/postgresql/15/man' \
|
||||
'--docdir=/usr/share/doc/postgresql-doc-15' '--with-pgport=5432' \
|
||||
'--sysconfdir=/etc/postgresql-common' '--datarootdir=/usr/share' \
|
||||
'--datadir=/usr/share/postgresql/15' '--with-uuid=e2fs' \
|
||||
'--bindir=/usr/lib/postgresql/15/bin' '--enable-tap-tests' \
|
||||
'--libdir=/usr/lib/x86_64-linux-gnu' '--enable-debug' \
|
||||
'--libexecdir=/usr/lib/postgresql' '--with-gnu-ld' \
|
||||
'--includedir=/usr/include/postgresql' '--enable-dtrace' \
|
||||
'--enable-nls' '--enable-thread-safety' '--disable-rpath' \
|
||||
'--with-system-tzdata=/usr/share/zoneinfo' '--with-llvm' \
|
||||
'--docdir=/usr/share/doc/postgresql-doc-15' \
|
||||
'--sysconfdir=/etc/postgresql-common' '--datarootdir=/usr/share/' \
|
||||
'--datadir=/usr/share/postgresql/15' '--bindir=/usr/lib/postgresql/15/bin' \
|
||||
'--libdir=/usr/lib/x86_64-linux-gnu/' '--libexecdir=/usr/lib/postgresql/' \
|
||||
'--includedir=/usr/include/postgresql/' \
|
||||
'--enable-nls' '--enable-thread-safety' '--enable-tap-tests' '--enable-debug' \
|
||||
'--enable-dtrace' '--disable-rpath' '--with-uuid=e2fs' '--with-gnu-ld' \
|
||||
'--with-pgport=5432' '--with-system-tzdata=/usr/share/zoneinfo' '--with-llvm' \
|
||||
'LLVM_CONFIG=/usr/bin/llvm-config-11' 'CLANG=/usr/bin/clang-11' \
|
||||
'--with-systemd' '--with-selinux' 'MKDIR_P=/bin/mkdir -p' \
|
||||
'PROVE=/usr/bin/prove' 'TAR=/bin/tar' 'XSLTPROC=xsltproc --nonet' \
|
||||
'LDFLAGS=-Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now' \
|
||||
'build_alias=x86_64-linux-gnu' '--with-gssapi' \
|
||||
'CPPFLAGS=-Wdate-time -D_FORTIFY_SOURCE=2' \
|
||||
'CFLAGS=-g -O2 -fstack-protector-strong -Wformat -Werror=format-security -fno-omit-frame-pointer' \
|
||||
'--with-systemd' '--with-selinux' 'MKDIR_P=/bin/mkdir -p' 'PROVE=/usr/bin/prove' \
|
||||
'TAR=/bin/tar' 'XSLTPROC=xsltproc --nonet' 'CFLAGS=-g -O2 -fstack-protector-strong -Wformat -Werror=format-security -fno-omit-frame-pointer' \
|
||||
'LDFLAGS=-Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now' '--with-gssapi' '--with-ldap' \
|
||||
'build_alias=x86_64-linux-gnu' 'CPPFLAGS=-Wdate-time -D_FORTIFY_SOURCE=2' \
|
||||
'CXXFLAGS=-g -O2 -fstack-protector-strong -Wformat -Werror=format-security'
|
||||
make world
|
||||
sudo make install-world
|
||||
|
||||
- name: Start postgresql cluster
|
||||
run: |
|
||||
export PATH="/usr/lib/postgresql/15/bin:$PATH"
|
||||
sudo cp /usr/lib/postgresql/15/bin/pg_config /usr/bin
|
||||
initdb -D /opt/pgsql/data
|
||||
pg_ctl -D /opt/pgsql/data -l logfile start
|
||||
/usr/lib/postgresql/15/bin/initdb -D /opt/pgsql/data
|
||||
/usr/lib/postgresql/15/bin/pg_ctl -D /opt/pgsql/data -l logfile start
|
||||
|
||||
- name: Clone pg_stat_monitor repository
|
||||
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
path: 'src/pg_stat_monitor'
|
||||
|
||||
- name: Build pg_stat_monitor
|
||||
run: |
|
||||
export PATH="/usr/lib/postgresql/15/bin:$PATH"
|
||||
sudo cp /usr/lib/postgresql/15/bin/pg_config /usr/bin
|
||||
make USE_PGXS=1
|
||||
sudo make USE_PGXS=1 install
|
||||
working-directory: src/pg_stat_monitor
|
||||
working-directory: src/pg_stat_monitor/
|
||||
|
||||
- name: Configure and Restart Server
|
||||
- name: Load pg_stat_monitor library and Restart Server
|
||||
run: |
|
||||
export PATH="/usr/lib/postgresql/15/bin:$PATH"
|
||||
pg_ctl -D /opt/pgsql/data -l logfile stop
|
||||
echo "shared_preload_libraries = 'pg_stat_monitor'" >> \
|
||||
/opt/pgsql/data/postgresql.conf
|
||||
echo "compute_query_id = regress" >> /opt/pgsql/data/postgresql.conf
|
||||
pg_ctl -D /opt/pgsql/data -l logfile start
|
||||
working-directory: src/pg_stat_monitor
|
||||
/usr/lib/postgresql/15/bin/pg_ctl -D /opt/pgsql/data -l logfile stop
|
||||
echo "shared_preload_libraries = 'pg_stat_monitor'" >> /opt/pgsql/data/postgresql.conf
|
||||
/usr/lib/postgresql/15/bin/pg_ctl -D /opt/pgsql/data -l logfile start
|
||||
working-directory: src/pg_stat_monitor/
|
||||
|
||||
- name: Start pg_stat_monitor_tests
|
||||
run: |
|
||||
|
|
@ -114,11 +98,11 @@ jobs:
|
|||
sudo chmod -R ugo+rwx t
|
||||
sudo chmod -R ugo+rwx tmp_check
|
||||
exit 2 # regenerate error so that we can upload files in next step
|
||||
working-directory: src/pg_stat_monitor
|
||||
working-directory: src/pg_stat_monitor/
|
||||
|
||||
- name: Upload logs on fail
|
||||
if: ${{ failure() }}
|
||||
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
|
||||
uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: Regressions diff and postgresql log
|
||||
path: |
|
||||
|
|
@ -135,17 +119,3 @@ jobs:
|
|||
!src/pg_stat_monitor/tmp_check/**/pgdata/
|
||||
if-no-files-found: warn
|
||||
retention-days: 3
|
||||
|
||||
- name: Start Server installcheck-world tests
|
||||
run: make installcheck-world
|
||||
|
||||
- name: Report on installcheck-world test suites fail
|
||||
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
|
||||
if: ${{ failure() }}
|
||||
with:
|
||||
name: Regressions output files of failed testsuite, and pg log
|
||||
path: |
|
||||
**/regression.diffs
|
||||
**/regression.out
|
||||
src/pg_stat_monitor/logfile
|
||||
retention-days: 3
|
||||
|
|
|
|||
|
|
@ -1,97 +0,0 @@
|
|||
name: postgresql-15-pgdg-package
|
||||
on:
|
||||
pull_request:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
tags:
|
||||
- '[0-9]+.[0-9]+.[0-9]+*'
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: pg-15-pgdg-package-test
|
||||
runs-on: ubuntu-22.04
|
||||
timeout-minutes: 30
|
||||
steps:
|
||||
- name: Clone pg_stat_monitor repository
|
||||
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
|
||||
with:
|
||||
path: 'src/pg_stat_monitor'
|
||||
|
||||
- name: Delete old postgresql files
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt purge postgresql-client-common postgresql-common \
|
||||
postgresql postgresql*
|
||||
sudo apt-get install -y libreadline6-dev systemtap-sdt-dev wget \
|
||||
zlib1g-dev libssl-dev libpam0g-dev bison flex libipc-run-perl
|
||||
sudo rm -rf /var/lib/postgresql /var/log/postgresql /etc/postgresql \
|
||||
/usr/lib/postgresql /usr/include/postgresql /usr/share/postgresql \
|
||||
/etc/postgresql
|
||||
sudo rm -f /usr/bin/pg_config
|
||||
sudo /usr/bin/perl -MCPAN -e 'install IPC::Run'
|
||||
sudo /usr/bin/perl -MCPAN -e 'install Text::Trim'
|
||||
|
||||
- name: Install PG Distribution Postgresql 15
|
||||
run: |
|
||||
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt \
|
||||
$(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
|
||||
sudo wget --quiet -O - \
|
||||
https://www.postgresql.org/media/keys/ACCC4CF8.asc |
|
||||
sudo apt-key add -
|
||||
sudo apt update
|
||||
sudo apt -y install postgresql-15 postgresql-server-dev-15
|
||||
|
||||
- name: Change src owner to postgres
|
||||
run: |
|
||||
sudo chmod o+rx ~
|
||||
sudo chown -R postgres:postgres src
|
||||
|
||||
- name: Build pg_stat_monitor
|
||||
run: |
|
||||
sudo -u postgres bash -c 'make USE_PGXS=1'
|
||||
sudo make USE_PGXS=1 install
|
||||
working-directory: src/pg_stat_monitor
|
||||
|
||||
- name: Start pg_stat_monitor_tests
|
||||
run: |
|
||||
sudo service postgresql stop
|
||||
echo "shared_preload_libraries = 'pg_stat_monitor'" |
|
||||
sudo tee -a /etc/postgresql/15/main/postgresql.conf
|
||||
sudo service postgresql start
|
||||
sudo psql -V
|
||||
export PG_TEST_PORT_DIR=${GITHUB_WORKSPACE}/src/pg_stat_monitor
|
||||
echo $PG_TEST_PORT_DIR
|
||||
sudo -E -u postgres bash -c 'make installcheck USE_PGXS=1'
|
||||
working-directory: src/pg_stat_monitor
|
||||
|
||||
- name: Change dir permissions on fail
|
||||
if: ${{ failure() }}
|
||||
run: |
|
||||
sudo chmod -R ugo+rwx t
|
||||
sudo chmod -R ugo+rwx tmp_check
|
||||
exit 2 # regenerate error so that we can upload files in next step
|
||||
working-directory: src/pg_stat_monitor
|
||||
|
||||
- name: Upload logs on fail
|
||||
if: ${{ failure() }}
|
||||
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
|
||||
with:
|
||||
name: Regressions diff and postgresql log
|
||||
path: |
|
||||
src/pg_stat_monitor/regression.diffs
|
||||
src/pg_stat_monitor/regression.out
|
||||
src/pg_stat_monitor/logfile
|
||||
src/pg_stat_monitor/t/results/
|
||||
src/pg_stat_monitor/tmp_check/log/
|
||||
!src/pg_stat_monitor/tmp_check/**/archives/*
|
||||
!src/pg_stat_monitor/tmp_check/**/backup/*
|
||||
!src/pg_stat_monitor/tmp_check/**/pgdata/*
|
||||
!src/pg_stat_monitor/tmp_check/**/archives/
|
||||
!src/pg_stat_monitor/tmp_check/**/backup/
|
||||
!src/pg_stat_monitor/tmp_check/**/pgdata/
|
||||
if-no-files-found: warn
|
||||
retention-days: 3
|
||||
|
|
@ -1,14 +1,5 @@
|
|||
name: postgresql-15-pmm-integration
|
||||
on:
|
||||
pull_request:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
tags:
|
||||
- '[0-9]+.[0-9]+.[0-9]+*'
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
on: push
|
||||
|
||||
jobs:
|
||||
build:
|
||||
|
|
@ -17,7 +8,7 @@ jobs:
|
|||
timeout-minutes: 30
|
||||
steps:
|
||||
- name: Clone QA Integration repository
|
||||
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
repository: 'Percona-Lab/qa-integration'
|
||||
ref: 'main'
|
||||
|
|
@ -26,23 +17,15 @@ jobs:
|
|||
- name: Get branch and Repo Name
|
||||
run: echo 'The branch and Repo Name is' ${{ github.head_ref }} ${{ github.actor }}/pg_stat_monitor
|
||||
|
||||
- name: "Set TARGET_BRANCH variable for a PR run"
|
||||
if: github.event_name == 'pull_request'
|
||||
run: echo "TARGET_BRANCH=${{ github.event.pull_request.base.ref }}" >> $GITHUB_ENV
|
||||
|
||||
- name: "Set TARGET_BRANCH variable for a PUSH run"
|
||||
if: github.event_name == 'push'
|
||||
run: echo "TARGET_BRANCH=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
|
||||
|
||||
- name: Run PMM & PGSM Setup, E2E Tests
|
||||
run: bash -xe ./pmm_pgsm_setup/pmm_pgsm_setup.sh --pgsql-version=15 --pgstat-monitor-branch=${{ env.TARGET_BRANCH }}
|
||||
run: bash -xe ./pmm_pgsm_setup/pmm_pgsm_setup.sh --pgsql-version=15 --pgstat-monitor-branch=REL_1_1_1
|
||||
|
||||
- name: Get PMM-Agent Logs from the Container
|
||||
if: success() || failure() # run this step even if previous step failed
|
||||
run: docker exec pgsql_pgsm_15 cat pmm-agent.log > ./pmm-ui-tests/tests/output/pmm-agent.log
|
||||
|
||||
- name: Upload Tests Artifacts
|
||||
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
|
||||
uses: actions/upload-artifact@v3
|
||||
if: success() || failure() # run this step even if previous step failed
|
||||
with:
|
||||
name: tests-artifact
|
||||
|
|
|
|||
|
|
@ -1,111 +0,0 @@
|
|||
name: postgresql-16-ppg-package
|
||||
on:
|
||||
pull_request:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
tags:
|
||||
- '[0-9]+.[0-9]+.[0-9]+*'
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: pg-16-ppg-package-test
|
||||
runs-on: ubuntu-22.04
|
||||
timeout-minutes: 30
|
||||
steps:
|
||||
- name: Clone pg_stat_monitor repository
|
||||
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
|
||||
with:
|
||||
path: 'src/pg_stat_monitor'
|
||||
|
||||
- name: Delete old postgresql files
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt purge postgresql-client-common postgresql-common \
|
||||
postgresql postgresql*
|
||||
sudo apt-get install -y libreadline6-dev systemtap-sdt-dev \
|
||||
zlib1g-dev libssl-dev libpam0g-dev python3-dev bison flex \
|
||||
libipc-run-perl wget
|
||||
sudo rm -rf /var/lib/postgresql /var/log/postgresql /etc/postgresql \
|
||||
/usr/lib/postgresql /usr/include/postgresql /usr/share/postgresql \
|
||||
/etc/postgresql
|
||||
sudo rm -f /usr/bin/pg_config
|
||||
sudo /usr/bin/perl -MCPAN -e 'install IPC::Run'
|
||||
sudo /usr/bin/perl -MCPAN -e 'install Text::Trim'
|
||||
|
||||
- name: Install percona-release script
|
||||
run: |
|
||||
sudo apt-get -y update
|
||||
sudo apt-get -y upgrade
|
||||
sudo apt-get install -y wget gnupg2 curl lsb-release
|
||||
sudo wget \
|
||||
https://repo.percona.com/apt/percona-release_latest.generic_all.deb
|
||||
sudo dpkg -i percona-release_latest.generic_all.deb
|
||||
|
||||
- name: Install Percona Distribution Postgresql 16 & Extensions
|
||||
run: |
|
||||
sudo percona-release setup ppg-16
|
||||
sudo apt-get update -y
|
||||
sudo apt-get install -y percona-postgresql-16 \
|
||||
percona-postgresql-contrib percona-postgresql-server-dev-all \
|
||||
percona-pgpool2 libpgpool2 percona-postgresql-16-pgaudit \
|
||||
percona-postgresql-16-pgaudit-dbgsym percona-postgresql-16-repack \
|
||||
percona-postgresql-16-repack-dbgsym percona-pgaudit16-set-user \
|
||||
percona-pgaudit16-set-user-dbgsym percona-postgresql-16-postgis-3 \
|
||||
percona-postgresql-16-postgis-3-scripts \
|
||||
percona-postgresql-postgis-scripts percona-postgresql-postgis \
|
||||
percona-postgis
|
||||
|
||||
- name: Change src owner to postgres
|
||||
run: |
|
||||
sudo chmod o+rx ~
|
||||
sudo chown -R postgres:postgres src
|
||||
|
||||
- name: Build pg_stat_monitor
|
||||
run: |
|
||||
sudo -u postgres bash -c 'make USE_PGXS=1'
|
||||
sudo make USE_PGXS=1 install
|
||||
working-directory: src/pg_stat_monitor
|
||||
|
||||
- name: Start pg_stat_monitor_tests
|
||||
run: |
|
||||
sudo service postgresql stop
|
||||
echo "shared_preload_libraries = 'pg_stat_monitor'" |
|
||||
sudo tee -a /etc/postgresql/16/main/postgresql.conf
|
||||
sudo service postgresql start
|
||||
sudo psql -V
|
||||
export PG_TEST_PORT_DIR=${GITHUB_WORKSPACE}/src/pg_stat_monitor
|
||||
echo $PG_TEST_PORT_DIR
|
||||
sudo -E -u postgres bash -c 'make installcheck USE_PGXS=1'
|
||||
working-directory: src/pg_stat_monitor
|
||||
|
||||
- name: Change dir permissions on fail
|
||||
if: ${{ failure() }}
|
||||
run: |
|
||||
sudo chmod -R ugo+rwx t
|
||||
sudo chmod -R ugo+rwx tmp_check
|
||||
exit 2 # regenerate error so that we can upload files in next step
|
||||
working-directory: src/pg_stat_monitor
|
||||
|
||||
- name: Upload logs on fail
|
||||
if: ${{ failure() }}
|
||||
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
|
||||
with:
|
||||
name: Regressions diff and postgresql log
|
||||
path: |
|
||||
src/pg_stat_monitor/regression.diffs
|
||||
src/pg_stat_monitor/regression.out
|
||||
src/pg_stat_monitor/logfile
|
||||
src/pg_stat_monitor/t/results/
|
||||
src/pg_stat_monitor/tmp_check/log/
|
||||
!src/pg_stat_monitor/tmp_check/**/archives/*
|
||||
!src/pg_stat_monitor/tmp_check/**/backup/*
|
||||
!src/pg_stat_monitor/tmp_check/**/pgdata/*
|
||||
!src/pg_stat_monitor/tmp_check/**/archives/
|
||||
!src/pg_stat_monitor/tmp_check/**/backup/
|
||||
!src/pg_stat_monitor/tmp_check/**/pgdata/
|
||||
if-no-files-found: warn
|
||||
retention-days: 3
|
||||
|
|
@ -1,151 +0,0 @@
|
|||
name: postgresql-17-build
|
||||
on:
|
||||
pull_request:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
tags:
|
||||
- '[0-9]+.[0-9]+.[0-9]+*'
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: pg-17-build-test
|
||||
runs-on: ubuntu-22.04
|
||||
timeout-minutes: 30
|
||||
steps:
|
||||
- name: Clone postgres repository
|
||||
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
|
||||
with:
|
||||
repository: 'postgres/postgres'
|
||||
ref: 'REL_17_STABLE'
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt purge postgresql-client-common postgresql-common \
|
||||
postgresql postgresql*
|
||||
sudo apt-get install -y libreadline6-dev systemtap-sdt-dev \
|
||||
zlib1g-dev libssl-dev libpam0g-dev bison flex \
|
||||
libipc-run-perl -y docbook-xsl docbook-xsl libxml2 libxml2-utils \
|
||||
libxml2-dev libxslt-dev xsltproc libkrb5-dev libldap2-dev \
|
||||
libsystemd-dev gettext tcl-dev libperl-dev pkg-config clang-11 \
|
||||
llvm-11 llvm-11-dev libselinux1-dev python3-dev \
|
||||
uuid-dev liblz4-dev
|
||||
sudo rm -rf /var/lib/postgresql /var/log/postgresql /etc/postgresql \
|
||||
/usr/lib/postgresql /usr/include/postgresql /usr/share/postgresql \
|
||||
/etc/postgresql
|
||||
sudo rm -f /usr/bin/pg_config
|
||||
sudo /usr/bin/perl -MCPAN -e 'install IPC::Run'
|
||||
sudo /usr/bin/perl -MCPAN -e 'install Text::Trim'
|
||||
|
||||
- name: Create pgsql dir
|
||||
run: mkdir -p /opt/pgsql
|
||||
|
||||
- name: Build postgres
|
||||
run: |
|
||||
export PATH="/opt/pgsql/bin:$PATH"
|
||||
./configure '--build=x86_64-linux-gnu' '--prefix=/usr' \
|
||||
'--includedir=${prefix}/include' '--mandir=${prefix}/share/man' \
|
||||
'--infodir=${prefix}/share/info' '--sysconfdir=/etc' \
|
||||
'--localstatedir=/var' '--libdir=${prefix}/lib/x86_64-linux-gnu' \
|
||||
'--libexecdir=${prefix}/lib/x86_64-linux-gnu' '--with-icu' \
|
||||
'--with-tcl' '--with-perl' '--with-python' '--with-pam' \
|
||||
'--with-openssl' '--with-libxml' '--with-libxslt' '--with-ldap' \
|
||||
'PYTHON=/usr/bin/python3' '--mandir=/usr/share/postgresql/17/man' \
|
||||
'--docdir=/usr/share/doc/postgresql-doc-17' '--with-pgport=5432' \
|
||||
'--sysconfdir=/etc/postgresql-common' '--datarootdir=/usr/share' \
|
||||
'--datadir=/usr/share/postgresql/17' '--with-uuid=e2fs' \
|
||||
'--bindir=/usr/lib/postgresql/17/bin' '--enable-tap-tests' \
|
||||
'--libdir=/usr/lib/x86_64-linux-gnu' '--enable-debug' \
|
||||
'--libexecdir=/usr/lib/postgresql' '--with-gnu-ld' \
|
||||
'--includedir=/usr/include/postgresql' '--enable-dtrace' \
|
||||
'--enable-nls' '--enable-thread-safety' '--disable-rpath' \
|
||||
'--with-system-tzdata=/usr/share/zoneinfo' '--with-llvm' \
|
||||
'LLVM_CONFIG=/usr/bin/llvm-config-11' 'CLANG=/usr/bin/clang-11' \
|
||||
'--with-systemd' '--with-selinux' 'MKDIR_P=/bin/mkdir -p' \
|
||||
'PROVE=/usr/bin/prove' 'TAR=/bin/tar' 'XSLTPROC=xsltproc --nonet' \
|
||||
'LDFLAGS=-Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now' \
|
||||
'build_alias=x86_64-linux-gnu' '--with-gssapi' \
|
||||
'CPPFLAGS=-Wdate-time -D_FORTIFY_SOURCE=2' \
|
||||
'CFLAGS=-g -O2 -fstack-protector-strong -Wformat -Werror=format-security -fno-omit-frame-pointer' \
|
||||
'CXXFLAGS=-g -O2 -fstack-protector-strong -Wformat -Werror=format-security'
|
||||
make world
|
||||
sudo make install-world
|
||||
|
||||
- name: Start postgresql cluster
|
||||
run: |
|
||||
export PATH="/usr/lib/postgresql/17/bin:$PATH"
|
||||
sudo cp /usr/lib/postgresql/17/bin/pg_config /usr/bin
|
||||
initdb -D /opt/pgsql/data
|
||||
pg_ctl -D /opt/pgsql/data -l logfile start
|
||||
|
||||
- name: Clone pg_stat_monitor repository
|
||||
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
|
||||
with:
|
||||
path: 'src/pg_stat_monitor'
|
||||
|
||||
- name: Build pg_stat_monitor
|
||||
run: |
|
||||
make USE_PGXS=1
|
||||
sudo make USE_PGXS=1 install
|
||||
working-directory: src/pg_stat_monitor
|
||||
|
||||
- name: Configure and Restart Server
|
||||
run: |
|
||||
export PATH="/usr/lib/postgresql/17/bin:$PATH"
|
||||
pg_ctl -D /opt/pgsql/data -l logfile stop
|
||||
echo "shared_preload_libraries = 'pg_stat_monitor'" >> \
|
||||
/opt/pgsql/data/postgresql.conf
|
||||
echo "compute_query_id = regress" >> /opt/pgsql/data/postgresql.conf
|
||||
pg_ctl -D /opt/pgsql/data -l logfile start
|
||||
working-directory: src/pg_stat_monitor
|
||||
|
||||
- name: Start pg_stat_monitor_tests
|
||||
run: |
|
||||
make installcheck
|
||||
working-directory: src/pg_stat_monitor/
|
||||
|
||||
- name: Change dir permissions on fail
|
||||
if: ${{ failure() }}
|
||||
run: |
|
||||
sudo chmod -R ugo+rwx t
|
||||
sudo chmod -R ugo+rwx tmp_check
|
||||
exit 2 # regenerate error so that we can upload files in next step
|
||||
working-directory: src/pg_stat_monitor
|
||||
|
||||
- name: Upload logs on fail
|
||||
if: ${{ failure() }}
|
||||
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
|
||||
with:
|
||||
name: Regressions diff and postgresql log
|
||||
path: |
|
||||
src/pg_stat_monitor/regression.diffs
|
||||
src/pg_stat_monitor/regression.out
|
||||
src/pg_stat_monitor/logfile
|
||||
src/pg_stat_monitor/t/results/
|
||||
src/pg_stat_monitor/tmp_check/log/
|
||||
!src/pg_stat_monitor/tmp_check/**/archives/*
|
||||
!src/pg_stat_monitor/tmp_check/**/backup/*
|
||||
!src/pg_stat_monitor/tmp_check/**/pgdata/*
|
||||
!src/pg_stat_monitor/tmp_check/**/archives/
|
||||
!src/pg_stat_monitor/tmp_check/**/backup/
|
||||
!src/pg_stat_monitor/tmp_check/**/pgdata/
|
||||
if-no-files-found: warn
|
||||
retention-days: 3
|
||||
|
||||
- name: Start Server installcheck-world tests
|
||||
run: make installcheck-world
|
||||
|
||||
- name: Report on installcheck-world test suites fail
|
||||
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
|
||||
if: ${{ failure() }}
|
||||
with:
|
||||
name: Regressions output files of failed testsuite, and pg log
|
||||
path: |
|
||||
**/regression.diffs
|
||||
**/regression.out
|
||||
src/pg_stat_monitor/logfile
|
||||
retention-days: 3
|
||||
|
|
@ -1,97 +0,0 @@
|
|||
name: postgresql-17-pgdg-package
|
||||
on:
|
||||
pull_request:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
tags:
|
||||
- '[0-9]+.[0-9]+.[0-9]+*'
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: pg-17-pgdg-package-test
|
||||
runs-on: ubuntu-22.04
|
||||
timeout-minutes: 30
|
||||
steps:
|
||||
- name: Clone pg_stat_monitor repository
|
||||
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
|
||||
with:
|
||||
path: 'src/pg_stat_monitor'
|
||||
|
||||
- name: Delete old postgresql files
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt purge postgresql-client-common postgresql-common \
|
||||
postgresql postgresql*
|
||||
sudo apt-get install -y libreadline6-dev systemtap-sdt-dev wget \
|
||||
zlib1g-dev libssl-dev libpam0g-dev bison flex libipc-run-perl
|
||||
sudo rm -rf /var/lib/postgresql /var/log/postgresql /etc/postgresql \
|
||||
/usr/lib/postgresql /usr/include/postgresql /usr/share/postgresql \
|
||||
/etc/postgresql
|
||||
sudo rm -f /usr/bin/pg_config
|
||||
sudo /usr/bin/perl -MCPAN -e 'install IPC::Run'
|
||||
sudo /usr/bin/perl -MCPAN -e 'install Text::Trim'
|
||||
|
||||
- name: Install PG Distribution Postgresql 17
|
||||
run: |
|
||||
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt \
|
||||
$(lsb_release -cs)-pgdg main 17" > /etc/apt/sources.list.d/pgdg.list'
|
||||
sudo wget --quiet -O - \
|
||||
https://www.postgresql.org/media/keys/ACCC4CF8.asc |
|
||||
sudo apt-key add -
|
||||
sudo apt update
|
||||
sudo apt -y install postgresql-17 postgresql-server-dev-17
|
||||
|
||||
- name: Change src owner to postgres
|
||||
run: |
|
||||
sudo chmod o+rx ~
|
||||
sudo chown -R postgres:postgres src
|
||||
|
||||
- name: Build pg_stat_monitor
|
||||
run: |
|
||||
sudo -u postgres bash -c 'make USE_PGXS=1'
|
||||
sudo make USE_PGXS=1 install
|
||||
working-directory: src/pg_stat_monitor
|
||||
|
||||
- name: Start pg_stat_monitor_tests
|
||||
run: |
|
||||
sudo service postgresql stop
|
||||
echo "shared_preload_libraries = 'pg_stat_monitor'" |
|
||||
sudo tee -a /etc/postgresql/17/main/postgresql.conf
|
||||
sudo service postgresql start
|
||||
sudo psql -V
|
||||
export PG_TEST_PORT_DIR=${GITHUB_WORKSPACE}/src/pg_stat_monitor
|
||||
echo $PG_TEST_PORT_DIR
|
||||
sudo -E -u postgres bash -c 'make installcheck USE_PGXS=1'
|
||||
working-directory: src/pg_stat_monitor
|
||||
|
||||
- name: Change dir permissions on fail
|
||||
if: ${{ failure() }}
|
||||
run: |
|
||||
sudo chmod -R ugo+rwx t
|
||||
sudo chmod -R ugo+rwx tmp_check
|
||||
exit 2 # regenerate error so that we can upload files in next step
|
||||
working-directory: src/pg_stat_monitor
|
||||
|
||||
- name: Upload logs on fail
|
||||
if: ${{ failure() }}
|
||||
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
|
||||
with:
|
||||
name: Regressions diff and postgresql log
|
||||
path: |
|
||||
src/pg_stat_monitor/regression.diffs
|
||||
src/pg_stat_monitor/regression.out
|
||||
src/pg_stat_monitor/logfile
|
||||
src/pg_stat_monitor/t/results/
|
||||
src/pg_stat_monitor/tmp_check/log/
|
||||
!src/pg_stat_monitor/tmp_check/**/archives/*
|
||||
!src/pg_stat_monitor/tmp_check/**/backup/*
|
||||
!src/pg_stat_monitor/tmp_check/**/pgdata/*
|
||||
!src/pg_stat_monitor/tmp_check/**/archives/
|
||||
!src/pg_stat_monitor/tmp_check/**/backup/
|
||||
!src/pg_stat_monitor/tmp_check/**/pgdata/
|
||||
if-no-files-found: warn
|
||||
retention-days: 3
|
||||
|
|
@ -1,151 +0,0 @@
|
|||
name: postgresql-18-build
|
||||
on:
|
||||
pull_request:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
tags:
|
||||
- '[0-9]+.[0-9]+.[0-9]+*'
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: pg-18-build-test
|
||||
runs-on: ubuntu-22.04
|
||||
timeout-minutes: 30
|
||||
steps:
|
||||
- name: Clone postgres repository
|
||||
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
|
||||
with:
|
||||
repository: 'postgres/postgres'
|
||||
ref: 'REL_18_STABLE'
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt purge postgresql-client-common postgresql-common \
|
||||
postgresql postgresql*
|
||||
sudo apt-get install -y libreadline6-dev systemtap-sdt-dev \
|
||||
zlib1g-dev libssl-dev libpam0g-dev bison flex \
|
||||
libipc-run-perl -y docbook-xsl docbook-xsl libxml2 libxml2-utils \
|
||||
libxml2-dev libxslt-dev xsltproc libkrb5-dev libldap2-dev \
|
||||
libsystemd-dev gettext tcl-dev libperl-dev pkg-config clang-14 \
|
||||
llvm-14 llvm-14-dev libselinux1-dev python3-dev \
|
||||
uuid-dev liblz4-dev
|
||||
sudo rm -rf /var/lib/postgresql /var/log/postgresql /etc/postgresql \
|
||||
/usr/lib/postgresql /usr/include/postgresql /usr/share/postgresql \
|
||||
/etc/postgresql
|
||||
sudo rm -f /usr/bin/pg_config
|
||||
sudo /usr/bin/perl -MCPAN -e 'install IPC::Run'
|
||||
sudo /usr/bin/perl -MCPAN -e 'install Text::Trim'
|
||||
|
||||
- name: Create pgsql dir
|
||||
run: mkdir -p /opt/pgsql
|
||||
|
||||
- name: Build postgres
|
||||
run: |
|
||||
export PATH="/opt/pgsql/bin:$PATH"
|
||||
./configure '--build=x86_64-linux-gnu' '--prefix=/usr' \
|
||||
'--includedir=${prefix}/include' '--mandir=${prefix}/share/man' \
|
||||
'--infodir=${prefix}/share/info' '--sysconfdir=/etc' \
|
||||
'--localstatedir=/var' '--libdir=${prefix}/lib/x86_64-linux-gnu' \
|
||||
'--libexecdir=${prefix}/lib/x86_64-linux-gnu' '--with-icu' \
|
||||
'--with-tcl' '--with-perl' '--with-python' '--with-pam' \
|
||||
'--with-openssl' '--with-libxml' '--with-libxslt' '--with-ldap' \
|
||||
'PYTHON=/usr/bin/python3' '--mandir=/usr/share/postgresql/18/man' \
|
||||
'--docdir=/usr/share/doc/postgresql-doc-18' '--with-pgport=5432' \
|
||||
'--sysconfdir=/etc/postgresql-common' '--datarootdir=/usr/share' \
|
||||
'--datadir=/usr/share/postgresql/18' '--with-uuid=e2fs' \
|
||||
'--bindir=/usr/lib/postgresql/18/bin' '--enable-tap-tests' \
|
||||
'--libdir=/usr/lib/x86_64-linux-gnu' '--enable-debug' \
|
||||
'--libexecdir=/usr/lib/postgresql' '--with-gnu-ld' \
|
||||
'--includedir=/usr/include/postgresql' '--enable-dtrace' \
|
||||
'--enable-nls' '--enable-thread-safety' '--disable-rpath' \
|
||||
'--with-system-tzdata=/usr/share/zoneinfo' '--with-llvm' \
|
||||
'LLVM_CONFIG=/usr/bin/llvm-config-14' 'CLANG=/usr/bin/clang-14' \
|
||||
'--with-systemd' '--with-selinux' 'MKDIR_P=/bin/mkdir -p' \
|
||||
'PROVE=/usr/bin/prove' 'TAR=/bin/tar' 'XSLTPROC=xsltproc --nonet' \
|
||||
'LDFLAGS=-Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now' \
|
||||
'build_alias=x86_64-linux-gnu' '--with-gssapi' \
|
||||
'CPPFLAGS=-Wdate-time -D_FORTIFY_SOURCE=2' \
|
||||
'CFLAGS=-g -O2 -fstack-protector-strong -Wformat -Werror=format-security -fno-omit-frame-pointer' \
|
||||
'CXXFLAGS=-g -O2 -fstack-protector-strong -Wformat -Werror=format-security'
|
||||
make world
|
||||
sudo make install-world
|
||||
|
||||
- name: Start postgresql cluster
|
||||
run: |
|
||||
export PATH="/usr/lib/postgresql/18/bin:$PATH"
|
||||
sudo cp /usr/lib/postgresql/18/bin/pg_config /usr/bin
|
||||
initdb -D /opt/pgsql/data
|
||||
pg_ctl -D /opt/pgsql/data -l logfile start
|
||||
|
||||
- name: Clone pg_stat_monitor repository
|
||||
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
|
||||
with:
|
||||
path: 'src/pg_stat_monitor'
|
||||
|
||||
- name: Build pg_stat_monitor
|
||||
run: |
|
||||
make USE_PGXS=1
|
||||
sudo make USE_PGXS=1 install
|
||||
working-directory: src/pg_stat_monitor
|
||||
|
||||
- name: Configure and Restart Server
|
||||
run: |
|
||||
export PATH="/usr/lib/postgresql/18/bin:$PATH"
|
||||
pg_ctl -D /opt/pgsql/data -l logfile stop
|
||||
echo "shared_preload_libraries = 'pg_stat_monitor'" >> \
|
||||
/opt/pgsql/data/postgresql.conf
|
||||
echo "compute_query_id = regress" >> /opt/pgsql/data/postgresql.conf
|
||||
pg_ctl -D /opt/pgsql/data -l logfile start
|
||||
working-directory: src/pg_stat_monitor
|
||||
|
||||
- name: Start pg_stat_monitor_tests
|
||||
run: |
|
||||
make installcheck
|
||||
working-directory: src/pg_stat_monitor/
|
||||
|
||||
- name: Change dir permissions on fail
|
||||
if: ${{ failure() }}
|
||||
run: |
|
||||
sudo chmod -R ugo+rwx t
|
||||
sudo chmod -R ugo+rwx tmp_check
|
||||
exit 2 # regenerate error so that we can upload files in next step
|
||||
working-directory: src/pg_stat_monitor
|
||||
|
||||
- name: Upload logs on fail
|
||||
if: ${{ failure() }}
|
||||
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
|
||||
with:
|
||||
name: Regressions diff and postgresql log
|
||||
path: |
|
||||
src/pg_stat_monitor/regression.diffs
|
||||
src/pg_stat_monitor/regression.out
|
||||
src/pg_stat_monitor/logfile
|
||||
src/pg_stat_monitor/t/results/
|
||||
src/pg_stat_monitor/tmp_check/log/
|
||||
!src/pg_stat_monitor/tmp_check/**/archives/*
|
||||
!src/pg_stat_monitor/tmp_check/**/backup/*
|
||||
!src/pg_stat_monitor/tmp_check/**/pgdata/*
|
||||
!src/pg_stat_monitor/tmp_check/**/archives/
|
||||
!src/pg_stat_monitor/tmp_check/**/backup/
|
||||
!src/pg_stat_monitor/tmp_check/**/pgdata/
|
||||
if-no-files-found: warn
|
||||
retention-days: 3
|
||||
|
||||
- name: Start Server installcheck-world tests
|
||||
run: make installcheck-world
|
||||
|
||||
- name: Report on installcheck-world test suites fail
|
||||
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
|
||||
if: ${{ failure() }}
|
||||
with:
|
||||
name: Regressions output files of failed testsuite, and pg log
|
||||
path: |
|
||||
**/regression.diffs
|
||||
**/regression.out
|
||||
src/pg_stat_monitor/logfile
|
||||
retention-days: 3
|
||||
|
|
@ -1,97 +0,0 @@
|
|||
name: postgresql-18-pgdg-package
|
||||
on:
|
||||
pull_request:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
tags:
|
||||
- '[0-9]+.[0-9]+.[0-9]+*'
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: pg-18-pgdg-package-test
|
||||
runs-on: ubuntu-22.04
|
||||
timeout-minutes: 30
|
||||
steps:
|
||||
- name: Clone pg_stat_monitor repository
|
||||
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
|
||||
with:
|
||||
path: 'src/pg_stat_monitor'
|
||||
|
||||
- name: Delete old postgresql files
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt purge postgresql-client-common postgresql-common \
|
||||
postgresql postgresql*
|
||||
sudo apt-get install -y libreadline6-dev systemtap-sdt-dev wget \
|
||||
zlib1g-dev libssl-dev libpam0g-dev bison flex libipc-run-perl
|
||||
sudo rm -rf /var/lib/postgresql /var/log/postgresql /etc/postgresql \
|
||||
/usr/lib/postgresql /usr/include/postgresql /usr/share/postgresql \
|
||||
/etc/postgresql
|
||||
sudo rm -f /usr/bin/pg_config
|
||||
sudo /usr/bin/perl -MCPAN -e 'install IPC::Run'
|
||||
sudo /usr/bin/perl -MCPAN -e 'install Text::Trim'
|
||||
|
||||
- name: Install PG Distribution Postgresql 18
|
||||
run: |
|
||||
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt \
|
||||
$(lsb_release -cs)-pgdg main 18" > /etc/apt/sources.list.d/pgdg.list'
|
||||
sudo wget --quiet -O - \
|
||||
https://www.postgresql.org/media/keys/ACCC4CF8.asc |
|
||||
sudo apt-key add -
|
||||
sudo apt update
|
||||
sudo apt -y install postgresql-18 postgresql-server-dev-18
|
||||
|
||||
- name: Change src owner to postgres
|
||||
run: |
|
||||
sudo chmod o+rx ~
|
||||
sudo chown -R postgres:postgres src
|
||||
|
||||
- name: Build pg_stat_monitor
|
||||
run: |
|
||||
sudo -u postgres bash -c 'make USE_PGXS=1'
|
||||
sudo make USE_PGXS=1 install
|
||||
working-directory: src/pg_stat_monitor
|
||||
|
||||
- name: Start pg_stat_monitor_tests
|
||||
run: |
|
||||
sudo service postgresql stop
|
||||
echo "shared_preload_libraries = 'pg_stat_monitor'" |
|
||||
sudo tee -a /etc/postgresql/18/main/postgresql.conf
|
||||
sudo service postgresql start
|
||||
sudo psql -V
|
||||
export PG_TEST_PORT_DIR=${GITHUB_WORKSPACE}/src/pg_stat_monitor
|
||||
echo $PG_TEST_PORT_DIR
|
||||
sudo -E -u postgres bash -c 'make installcheck USE_PGXS=1'
|
||||
working-directory: src/pg_stat_monitor
|
||||
|
||||
- name: Change dir permissions on fail
|
||||
if: ${{ failure() }}
|
||||
run: |
|
||||
sudo chmod -R ugo+rwx t
|
||||
sudo chmod -R ugo+rwx tmp_check
|
||||
exit 2 # regenerate error so that we can upload files in next step
|
||||
working-directory: src/pg_stat_monitor
|
||||
|
||||
- name: Upload logs on fail
|
||||
if: ${{ failure() }}
|
||||
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
|
||||
with:
|
||||
name: Regressions diff and postgresql log
|
||||
path: |
|
||||
src/pg_stat_monitor/regression.diffs
|
||||
src/pg_stat_monitor/regression.out
|
||||
src/pg_stat_monitor/logfile
|
||||
src/pg_stat_monitor/t/results/
|
||||
src/pg_stat_monitor/tmp_check/log/
|
||||
!src/pg_stat_monitor/tmp_check/**/archives/*
|
||||
!src/pg_stat_monitor/tmp_check/**/backup/*
|
||||
!src/pg_stat_monitor/tmp_check/**/pgdata/*
|
||||
!src/pg_stat_monitor/tmp_check/**/archives/
|
||||
!src/pg_stat_monitor/tmp_check/**/backup/
|
||||
!src/pg_stat_monitor/tmp_check/**/pgdata/
|
||||
if-no-files-found: warn
|
||||
retention-days: 3
|
||||
|
|
@ -1,48 +0,0 @@
|
|||
name: Scorecard
|
||||
on:
|
||||
# To guarantee Maintained check is occasionally updated. See
|
||||
# https://github.com/ossf/scorecard/blob/main/docs/checks.md#maintained
|
||||
schedule:
|
||||
- cron: "24 3 * * 1"
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
|
||||
# Declare default permissions as read only.
|
||||
permissions: read-all
|
||||
|
||||
jobs:
|
||||
analysis:
|
||||
name: Analysis
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
# Needed to upload the results to code-scanning dashboard.
|
||||
security-events: write
|
||||
# Needed to publish results and get a badge (see publish_results below).
|
||||
id-token: write
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
|
||||
with:
|
||||
persist-credentials: false
|
||||
|
||||
- name: Run analysis
|
||||
uses: ossf/scorecard-action@4eaacf0543bb3f2c246792bd56e8cdeffafb205a # v2.4.3
|
||||
with:
|
||||
results_file: results.sarif
|
||||
results_format: sarif
|
||||
publish_results: true
|
||||
|
||||
- name: Upload results
|
||||
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
|
||||
with:
|
||||
name: SARIF file
|
||||
path: results.sarif
|
||||
retention-days: 5
|
||||
|
||||
# Upload the results to GitHub's code scanning dashboard (optional).
|
||||
- name: "Upload to code-scanning"
|
||||
uses: github/codeql-action/upload-sarif@cf1bb45a277cb3c205638b2cd5c984db1c46a412 # v4.31.7
|
||||
with:
|
||||
sarif_file: results.sarif
|
||||
|
|
@ -45,7 +45,6 @@
|
|||
*.mod*
|
||||
*.cmd
|
||||
.tmp_versions/
|
||||
.deps/
|
||||
modules.order
|
||||
Module.symvers
|
||||
Mkfile.old
|
||||
|
|
@ -60,6 +59,3 @@ dkms.conf
|
|||
## .vscode
|
||||
.vscode/
|
||||
.vscode/*
|
||||
|
||||
# tools files
|
||||
typedefs-full.list
|
||||
|
|
|
|||
|
|
@ -1,19 +0,0 @@
|
|||
header:
|
||||
paths:
|
||||
- "**/*.c"
|
||||
- "**/*.h"
|
||||
license:
|
||||
pattern: |
|
||||
.*\.(c|h)
|
||||
.*
|
||||
|
||||
Portions Copyright © 2018-2025, Percona LLC and/or its affiliates
|
||||
|
||||
Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
|
||||
|
||||
Portions Copyright (c) 1994, The Regents of the University of California
|
||||
|
||||
IDENTIFICATION
|
||||
contrib/pg_stat_monitor/.*\.(c|h)
|
||||
|
||||
comment: never
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
# List of pg_stat_monitor Adopters
|
||||
|
||||
This is the list of organizations and users that publicly shared details of how
|
||||
they are using pg_stat_monitor.
|
||||
|
||||
Please send us a pull request if you want to be added or removed from this
|
||||
list.
|
||||
|
||||
The list of organizations that have publicly shared the usage of
|
||||
pg_stat_monitor:
|
||||
|
||||
| Organization | Description | Success Story |
|
||||
| :--- | :--- | :--- |
|
||||
| [Example](https://example.com/) | Example company running pg_stat_monitor for dev and production for core application | [English](./adopters/example/README.md) |
|
||||
|
||||
The list of users that have publicly shared the usage of pg_stat_monitor.
|
||||
|
||||
| User | Description | Success Story |
|
||||
| :--- | :--- | :--- |
|
||||
| [Example User](https://github.com/username) | Personal tests of pg_stat_monitor | [English](./adopters/users/username/README.md) |
|
||||
21
META.json
21
META.json
|
|
@ -2,33 +2,30 @@
|
|||
"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.1",
|
||||
"version": "1.1.1",
|
||||
"maintainer": [
|
||||
"Artem Gavrilov <artem.gavrilov@percona.com>",
|
||||
"Diego dos Santos Fronza <diego.fronza@percona.com>"
|
||||
"ibrar.ahmed@percona.com"
|
||||
],
|
||||
"license": {
|
||||
"PostgreSQL": "https://www.postgresql.org/about/licence"
|
||||
},
|
||||
"license": "postgresql",
|
||||
"provides": {
|
||||
"pg_stat_monitor": {
|
||||
"abstract": "PostgreSQL Query Performance Monitoring Tool",
|
||||
"file": "pg_stat_monitor--2.2--2.3.sql",
|
||||
"file": "pg_stat_monitor--1.0.sql",
|
||||
"docfile": "README.md",
|
||||
"version": "2.3.1"
|
||||
"version": "1.1.1"
|
||||
}
|
||||
},
|
||||
"prereqs": {
|
||||
"runtime": {
|
||||
"requires": {
|
||||
"PostgreSQL": "12.0.0"
|
||||
"PostgreSQL": "11.0.0"
|
||||
}
|
||||
}
|
||||
},
|
||||
"resources": {
|
||||
"homepage": "https://github.com/percona/pg_stat_monitor",
|
||||
"homepage": "https://percona.github.io/pg_stat_monitor/",
|
||||
"bugtracker": {
|
||||
"web": "https://perconadev.atlassian.net/jira/software/c/projects/PG/issues"
|
||||
"web": "https://jira.percona.com/projects/PG/issues"
|
||||
},
|
||||
"repository": {
|
||||
"url": "https://github.com/percona/pg_stat_monitor.git",
|
||||
|
|
@ -36,7 +33,7 @@
|
|||
"type": "git"
|
||||
}
|
||||
},
|
||||
"generated_by": "Artem Gavrilov",
|
||||
"generated_by": "ibrar.ahmed@percona.com",
|
||||
"meta-spec": {
|
||||
"version": "1.0.0",
|
||||
"url": "http://pgxn.org/meta/spec.txt"
|
||||
|
|
|
|||
52
Makefile
52
Makefile
|
|
@ -4,7 +4,7 @@ MODULE_big = pg_stat_monitor
|
|||
OBJS = hash_query.o guc.o pg_stat_monitor.o $(WIN32RES)
|
||||
|
||||
EXTENSION = pg_stat_monitor
|
||||
DATA = pg_stat_monitor--2.0.sql pg_stat_monitor--1.0--2.0.sql pg_stat_monitor--2.0--2.1.sql pg_stat_monitor--2.1--2.2.sql pg_stat_monitor--2.2--2.3.sql
|
||||
DATA = pg_stat_monitor--1.0.sql
|
||||
|
||||
PGFILEDESC = "pg_stat_monitor - execution statistics of SQL statements"
|
||||
|
||||
|
|
@ -12,37 +12,17 @@ LDFLAGS_SL += $(filter -lm, $(LIBS))
|
|||
|
||||
TAP_TESTS = 1
|
||||
REGRESS_OPTS = --temp-config $(top_srcdir)/contrib/pg_stat_monitor/pg_stat_monitor.conf --inputdir=regression
|
||||
REGRESS = basic \
|
||||
version \
|
||||
guc \
|
||||
pgsm_query_id \
|
||||
functions \
|
||||
counters \
|
||||
relations \
|
||||
database \
|
||||
error_insert \
|
||||
application_name \
|
||||
application_name_unique \
|
||||
top_query \
|
||||
different_parent_queries \
|
||||
cmd_type \
|
||||
error \
|
||||
rows \
|
||||
squashing \
|
||||
tags \
|
||||
user \
|
||||
level_tracking \
|
||||
decode_error_level \
|
||||
parallel
|
||||
REGRESS = basic version guc counters relations database error_insert application_name application_name_unique top_query cmd_type error rows tags histogram
|
||||
|
||||
# Disabled because these tests require "shared_preload_libraries=pg_stat_statements",
|
||||
# which typical installcheck users do not have (e.g. buildfarm clients).
|
||||
# NO_INSTALLCHECK = 1
|
||||
|
||||
PG_CONFIG ?= pg_config
|
||||
PG_CONFIG = pg_config
|
||||
PGSM_INPUT_SQL_VERSION := 1.0
|
||||
|
||||
ifdef USE_PGXS
|
||||
MAJORVERSION := $(shell $(PG_CONFIG) --version | awk {'print $$2'} | cut -f1 -d".")
|
||||
MAJORVERSION := $(shell pg_config --version | awk {'print $$2'} | cut -f1 -d".")
|
||||
PGXS := $(shell $(PG_CONFIG) --pgxs)
|
||||
include $(PGXS)
|
||||
else
|
||||
|
|
@ -52,13 +32,19 @@ include $(top_builddir)/src/Makefile.global
|
|||
include $(top_srcdir)/contrib/contrib-global.mk
|
||||
endif
|
||||
|
||||
# Fetches typedefs list for PostgreSQL core and merges it with typedefs defined in this project.
|
||||
# https://wiki.postgresql.org/wiki/Running_pgindent_on_non-core_code_or_development_code
|
||||
update-typedefs:
|
||||
wget -q -O - "https://buildfarm.postgresql.org/cgi-bin/typedefs.pl?branch=REL_17_STABLE" | cat - typedefs.list | sort | uniq > typedefs-full.list
|
||||
ifeq ($(shell test $(MAJORVERSION) -gt 12; echo $$?),0)
|
||||
PGSM_INPUT_SQL_VERSION := ${PGSM_INPUT_SQL_VERSION}.${MAJORVERSION}
|
||||
endif
|
||||
|
||||
# Indents projects sources.
|
||||
indent:
|
||||
pgindent --typedefs=typedefs-full.list .
|
||||
$(info Using pg_stat_monitor--${PGSM_INPUT_SQL_VERSION}.sql.in file to generate sql filea.)
|
||||
|
||||
.PHONY: update-typedefs indent
|
||||
ifneq (,$(wildcard ../pg_stat_monitor--${PGSM_INPUT_SQL_VERSION}.sql.in))
|
||||
CP := $(shell cp -v ../pg_stat_monitor--${PGSM_INPUT_SQL_VERSION}.sql.in ../pg_stat_monitor--1.0.sql)
|
||||
endif
|
||||
ifneq (,$(wildcard pg_stat_monitor--${PGSM_INPUT_SQL_VERSION}.sql.in))
|
||||
CP := $(shell cp -v pg_stat_monitor--${PGSM_INPUT_SQL_VERSION}.sql.in pg_stat_monitor--1.0.sql)
|
||||
endif
|
||||
|
||||
clean:
|
||||
rm -rf ${DATA}
|
||||
rm -rf t/results
|
||||
|
|
|
|||
66
README.md
66
README.md
|
|
@ -1,15 +1,6 @@
|
|||
[](https://github.com/percona/pg_stat_monitor/actions/workflows/postgresql-13-pgdg-package.yml)
|
||||
[](https://github.com/percona/pg_stat_monitor/actions/workflows/postgresql-14-pgdg-package.yml)
|
||||
[](https://github.com/percona/pg_stat_monitor/actions/workflows/postgresql-15-pgdg-package.yml)
|
||||
[](https://github.com/percona/pg_stat_monitor/actions/workflows/postgresql-16-pgdg-package.yml)
|
||||
[](https://github.com/percona/pg_stat_monitor/actions/workflows/postgresql-17-pgdg-package.yml)
|
||||
[](https://github.com/percona/pg_stat_monitor/actions/workflows/postgresql-18-pgdg-package.yml)
|
||||
[](https://github.com/percona/pg_stat_monitor/actions/workflows/postgresql-14-build.yml) [](https://github.com/percona/pg_stat_monitor/actions/workflows/postgresql-14-pgdg-package.yml) [](https://github.com/percona/pg_stat_monitor/actions/workflows/postgresql-14-ppg-package.yml)
|
||||
|
||||
[](https://badge.fury.io/pg/pg_stat_monitor)
|
||||
[](https://scorecard.dev/viewer/?uri=github.com/percona/pg_stat_monitor)
|
||||
[](https://www.bestpractices.dev/projects/9703)
|
||||
[](https://codecov.io/gh/percona/pg_stat_monitor)
|
||||
[](https://forums.percona.com/)
|
||||
# pg_stat_monitor: Query Performance Monitoring Tool for PostgreSQL
|
||||
|
||||
## Table of Contents
|
||||
|
|
@ -25,7 +16,6 @@
|
|||
- [Installing from Percona repositories](#installing-from-percona-repositories)
|
||||
- [Installing from PostgreSQL `yum` repositories](#installing-from-postgresql-yum-repositories)
|
||||
- [Installing from PGXN](#installing-from-pgxn)
|
||||
- [Installing from sources](#building-from-source)
|
||||
- [Configuration](#configuration)
|
||||
- [Setup](#setup)
|
||||
- [Building from source](#building-from-source)
|
||||
|
|
@ -51,9 +41,9 @@ While `pg_stat_statements` provides ever-increasing metrics, `pg_stat_monitor` a
|
|||
|
||||
To learn about other features, available in `pg_stat_monitor`, see the [Features](#pg_stat_monitor-features) section and the [User Guide](https://docs.percona.com/pg-stat-monitor/user_guide.html).
|
||||
|
||||
`pg_stat_monitor` supports PostgreSQL versions 13 and above. It is compatible with both PostgreSQL provided by PostgreSQL Global Development Group (PGDG) and [Percona Distribution for PostgreSQL](https://www.percona.com/software/postgresql-distribution).
|
||||
`pg_stat_monitor` supports PostgreSQL versions 11 and above. It is compatible with both PostgreSQL provided by PostgreSQL Global Development Group (PGDG) and [Percona Distribution for PostgreSQL](https://www.percona.com/software/postgresql-distribution).
|
||||
|
||||
The `RPM` (for RHEL and CentOS) and the `DEB` (for Debian and Ubuntu) packages are available from Percona repositories for PostgreSQL versions [13](https://www.percona.com/downloads/postgresql-distribution-13/LATEST/), [14](https://www.percona.com/downloads/postgresql-distribution-14/LATEST/), [15](https://www.percona.com/downloads/postgresql-distribution-15/LATEST/), [16](https://www.percona.com/downloads/postgresql-distribution-16/LATEST/), [17](https://www.percona.com/downloads/postgresql-distribution-17/LATEST/) and [18](https://www.percona.com/downloads/postgresql-distribution-18/LATEST/).
|
||||
The `RPM` (for RHEL and CentOS) and the `DEB` (for Debian and Ubuntu) packages are available from Percona repositories for PostgreSQL versions [11](https://www.percona.com/downloads/percona-postgresql-11/LATEST/), [12](https://www.percona.com/downloads/postgresql-distribution-12/LATEST/), [13](https://www.percona.com/downloads/postgresql-distribution-13/LATEST/) and [14](https://www.percona.com/downloads/postgresql-distribution-14/LATEST/).
|
||||
|
||||
The RPM packages are also available in the official PostgreSQL (PGDG) yum repositories.
|
||||
|
||||
|
|
@ -63,8 +53,8 @@ The `pg_stat_monitor` should work on the latest version of both [Percona Distrib
|
|||
|
||||
| **Distribution** | **Version** | **Provider** |
|
||||
| ---------------- | --------------- | ------------ |
|
||||
|[Percona Distribution for PostgreSQL](https://www.percona.com/software/postgresql-distribution)| [13](https://www.percona.com/downloads/postgresql-distribution-13/LATEST/), [14](https://www.percona.com/downloads/postgresql-distribution-14/LATEST/), [15](https://www.percona.com/downloads/postgresql-distribution-15/LATEST/), [16](https://www.percona.com/downloads/postgresql-distribution-16/LATEST/), [17](https://www.percona.com/downloads/postgresql-distribution-17/LATEST/) and [18](https://www.percona.com/downloads/postgresql-distribution-18/LATEST/)| Percona|
|
||||
| PostgreSQL | 13, 14, 15, 16, 17 and 18 | PostgreSQL Global Development Group (PGDG) |
|
||||
|[Percona Distribution for PostgreSQL](https://www.percona.com/software/postgresql-distribution)| [11](https://www.percona.com/downloads/percona-postgresql-11/LATEST/), [12](https://www.percona.com/downloads/postgresql-distribution-12/LATEST/), [13](https://www.percona.com/downloads/postgresql-distribution-13/LATEST/) and [14](https://www.percona.com/downloads/postgresql-distribution-14/LATEST/)| Percona|
|
||||
| PostgreSQL | 11, 12, 13 and 14 | PostgreSQL Global Development Group (PGDG) |
|
||||
|
||||
|
||||
### Features
|
||||
|
|
@ -95,7 +85,7 @@ The following are useful links in [`pg_stat_monitor` documentation](https://docs
|
|||
|
||||
The PostgreSQL YUM repository supports `pg_stat_monitor` for all [supported versions](#supported-versions) for the following platforms:
|
||||
|
||||
* Red Hat Enterprise/Rocky/CentOS/Oracle Linux 7, 8 and 9
|
||||
* Red Hat Enterprise/Rocky/CentOS/Oracle Linux 7 and 8
|
||||
* Fedora 33 and 34
|
||||
|
||||
Find the list of supported platforms for `pg_stat_monitor` within [Percona Distribution for PostgreSQL](https://www.percona.com/software/postgresql-distribution) on the [Percona Release Lifecycle Overview](https://www.percona.com/services/policies/percona-software-support-lifecycle#pgsql) page.
|
||||
|
|
@ -105,10 +95,10 @@ Find the list of supported platforms for `pg_stat_monitor` within [Percona Distr
|
|||
|
||||
You can install `pg_stat_monitor` from the following sources:
|
||||
|
||||
* [Percona repositories](#installing-from-percona-repositories)
|
||||
* [PostgreSQL PGDG yum repositories](#installing-from-postgresql-yum-repositories)
|
||||
* [PGXN](#installing-from-pgxn)
|
||||
* [source code](#building-from-source)
|
||||
* [Percona repositories](#installing-from-percona-repositories),
|
||||
* [PostgreSQL PGDG yum repositories](#installing-from-postgresql-yum-repositories),
|
||||
* [PGXN](#installing-from-pgxn) and
|
||||
* [source code](#building-from-source).
|
||||
|
||||
|
||||
#### Installing from Percona repositories
|
||||
|
|
@ -119,19 +109,19 @@ To install `pg_stat_monitor` from Percona repositories, you need to use the `per
|
|||
2. Enable Percona repository:
|
||||
|
||||
``` sh
|
||||
percona-release setup ppg-XX
|
||||
percona-release setup ppgXX
|
||||
```
|
||||
|
||||
Replace XX with the desired PostgreSQL version. For example, to install `pg_stat_monitor ` for PostgreSQL 17, specify `ppg-17`.
|
||||
Replace XX with the desired PostgreSQL version. For example, to install `pg_stat_monitor ` for PostgreSQL 13, specify `ppg13`.
|
||||
|
||||
3. Install `pg_stat_monitor` package
|
||||
* For Debian and Ubuntu:
|
||||
``` sh
|
||||
apt-get install percona-pg-stat-monitor17
|
||||
apt-get install percona-pg-stat-monitor13
|
||||
```
|
||||
* For RHEL and CentOS:
|
||||
``` sh
|
||||
yum install percona-pg-stat-monitor17
|
||||
yum install percona-pg-stat-monitor13
|
||||
```
|
||||
|
||||
#### Installing from PostgreSQL `yum` repositories
|
||||
|
|
@ -144,12 +134,12 @@ Install `pg_stat_monitor`:
|
|||
dnf install -y pg_stat_monitor_<VERSION>
|
||||
```
|
||||
|
||||
Replace the `VERSION` variable with the PostgreSQL version you are using (e.g. specify `pg_stat_monitor_17` for PostgreSQL 17)
|
||||
Replace the `VERSION` variable with the PostgreSQL version you are using (e.g. specify `pg_stat_monitor_13` for PostgreSQL 13)
|
||||
|
||||
|
||||
#### Installing from PGXN
|
||||
|
||||
You can install `pg_stat_monitor` from [PGXN (PostgreSQL Extensions Network)](https://pgxn.org/) using the [PGXN client](https://pgxn.github.io/pgxnclient/).
|
||||
You can install `pg_stat_monitor` from PGXN (PostgreSQL Extensions Network) using the [PGXN client](https://pgxn.github.io/pgxnclient/).
|
||||
|
||||
Use the following command:
|
||||
|
||||
|
|
@ -159,7 +149,7 @@ pgxn install pg_stat_monitor
|
|||
|
||||
### Configuration
|
||||
|
||||
You can find the configuration parameters of the `pg_stat_monitor` extension in the `pg_settings` view. To change the default configuration, specify new values for the desired parameters using the GUC (Grant Unified Configuration) system. To learn more, refer to the [Configuration parameters](https://docs.percona.com/pg-stat-monitor/configuration.html) section of the documentation.
|
||||
You can find the configuration parameters of the `pg_stat_monitor` extension in the `pg_stat_monitor_settings` view. To change the default configuration, specify new values for the desired parameters using the GUC (Grant Unified Configuration) system. To learn more, refer to the [Configuration parameters](https://docs.percona.com/pg-stat-monitor/configuration.html) section of the documentation.
|
||||
|
||||
|
||||
### Setup
|
||||
|
|
@ -176,7 +166,7 @@ ALTER SYSTEM SET shared_preload_libraries = 'pg_stat_monitor';
|
|||
|
||||
> **NOTE**: If you’ve added other modules to the `shared_preload_libraries` parameter (for example, `pg_stat_statements`), list all of them separated by commas for the `ALTER SYSTEM` command.
|
||||
>
|
||||
>:warning: For PostgreSQL 13 `pg_stat_monitor` **must** follow `pg_stat_statements`. For example, `ALTER SYSTEM SET shared_preload_libraries = 'foo, pg_stat_statements, pg_stat_monitor'`.
|
||||
>:warning: For PostgreSQL 13 and earlier versions,`pg_stat_monitor` **must** follow `pg_stat_statements`. For example, `ALTER SYSTEM SET shared_preload_libraries = 'foo, pg_stat_statements, pg_stat_monitor'`.
|
||||
>
|
||||
>In PostgreSQL 14, you can specify `pg_stat_statements` and `pg_stat_monitor` in any order. However, due to the extensions' architecture, if both `pg_stat_statements` and `pg_stat_monitor` are loaded, only the last listed extension captures utility queries, CREATE TABLE, Analyze, etc. The first listed extension captures most common queries like SELECT, UPDATE, INSERT, but does not capture utility queries.
|
||||
>
|
||||
|
|
@ -195,7 +185,7 @@ sudo systemctl restart postgresql.service
|
|||
|
||||
|
||||
```sh
|
||||
sudo systemctl restart postgresql-17
|
||||
sudo systemctl restart postgresql-13
|
||||
```
|
||||
|
||||
Create the extension using the [CREATE EXTENSION](https://www.postgresql.org/docs/current/sql-createextension.html) command. Using this command requires the privileges of a superuser or a database owner. Connect to `psql` as a superuser for a database and run the following command:
|
||||
|
|
@ -257,13 +247,19 @@ make USE_PGXS=1 install
|
|||
|
||||
To uninstall `pg_stat_monitor`, do the following:
|
||||
|
||||
1. Drop `pg_stat_monitor` extension:
|
||||
1. Disable statistics collection. From the `psql` terminal, run the following command:
|
||||
|
||||
```sql
|
||||
ALTER SYSTEM SET pg_stat_monitor.pgsm_enable = 0;
|
||||
```
|
||||
|
||||
2. Drop `pg_stat_monitor` extension:
|
||||
|
||||
```sql
|
||||
DROP EXTENSION pg_stat_monitor;
|
||||
```
|
||||
|
||||
2. Remove `pg_stat_monitor` from the `shared_preload_libraries` configuration parameter:
|
||||
3. Remove `pg_stat_monitor` from the `shared_preload_libraries` configuration parameter:
|
||||
|
||||
```sql
|
||||
ALTER SYSTEM SET shared_preload_libraries = '';
|
||||
|
|
@ -271,7 +267,7 @@ To uninstall `pg_stat_monitor`, do the following:
|
|||
|
||||
**Important**: If the `shared_preload_libraries` parameter includes other modules, specify them all for the `ALTER SYSTEM SET` command to keep using them.
|
||||
|
||||
3. Restart the `postgresql` instance to apply the changes. The following command restarts PostgreSQL 17. Replace the version value with the one you are using.
|
||||
4. Restart the `postgresql` instance to apply the changes. The following command restarts PostgreSQL 13. Replace the version value with the one you are using.
|
||||
|
||||
* On Debian and Ubuntu:
|
||||
|
||||
|
|
@ -283,7 +279,7 @@ To uninstall `pg_stat_monitor`, do the following:
|
|||
|
||||
|
||||
```sh
|
||||
sudo systemctl restart postgresql-17
|
||||
sudo systemctl restart postgresql-13
|
||||
```
|
||||
|
||||
### How we work
|
||||
|
|
@ -323,6 +319,6 @@ This project is licensed under the same open liberal terms and conditions as the
|
|||
|
||||
### Copyright notice
|
||||
|
||||
* Portions Copyright © 2018-2025, Percona LLC and/or its affiliates
|
||||
* Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
|
||||
* Portions Copyright © 2018-2021, Percona LLC and/or its affiliates
|
||||
* Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, The Regents of the University of California
|
||||
|
|
|
|||
|
|
@ -0,0 +1,231 @@
|
|||
# Release Notes
|
||||
|
||||
Below is the complete list of release notes for every version of ``pg_stat_monitor``.
|
||||
|
||||
## 1.1.1
|
||||
|
||||
### Bugs Fixed
|
||||
|
||||
[PG-520](https://jira.percona.com/browse/PG-520): pg_stat_monitor does not work with PostgreSQL15
|
||||
|
||||
|
||||
## 1.1.0
|
||||
|
||||
### Improvements
|
||||
|
||||
[PG-474](https://jira.percona.com/browse/PG-474): Make pg_stat_monitor compiled with CLANG
|
||||
[PG-159](https://jira.percona.com/browse/PG-159): Change the bucket start time scheme to align with the bucket time size
|
||||
[PG-293](https://jira.percona.com/browse/PG-293): Add the ability to control features added on top of `pg_stat_monitor` using GUC (Grand Unified Configuration) parameters
|
||||
[PG-300](https://jira.percona.com/browse/PG-300): Improve compatibility with PMM by making QueryIDs persistent for the same queries across different buckets and regardless of the node / client a query is executed on.
|
||||
[PG-362](https://jira.percona.com/browse/PG-362): Fix the `pgsm_normalized_query` default value to provide query examples in the `pg_stat_monitor` view by default.
|
||||
[PG-439](https://jira.percona.com/browse/PG-439): Remove warning of comparison of unsigned enum expression
|
||||
|
||||
### Bugs Fixed
|
||||
|
||||
[PG-221](https://jira.percona.com/browse/PG-221): Fixed the issue with pg_stat_monitor crashing when querying JSON with parallel workers enabled
|
||||
[PG-289](https://jira.percona.com/browse/PG-289): Fixed the issue with pg_stat_monitor failing to build on C11 compilers by removing 'for' loop initial declarations
|
||||
[PG-449](https://jira.percona.com/browse/PG-449): Fix comments visibility by correcting the behavior of the `pgsm_extract_comments` parameter
|
||||
[PG-453](https://jira.percona.com/browse/PG-453): Fixed query normalization for INSERT statements in PostgreSQL 13 and earlier versions
|
||||
[PG-455](https://jira.percona.com/browse/PG-455): Fixed the issue with data collection for any value specified for `pgsm_bucket_time` parameter within the min / max range
|
||||
|
||||
|
||||
## 1.0.1
|
||||
|
||||
### Bugs Fixed
|
||||
|
||||
[PG-382](https://jira.percona.com/browse/PG-382): Histogram default settings changed to prevent the PostgreSQL server to crash
|
||||
|
||||
[PG-417](https://jira.percona.com/browse/PG-417): Addressed security vulnerabilities to prevent an attacker from precreating functions
|
||||
|
||||
[DISTPG-427](https://jira.percona.com/browse/DISTPG-427): Fixed the issue with the extensions not working when pg_stat_monitor is enabled by replacing the `return` with `goto exit` for the `pgsm_emit_log_hook` function
|
||||
|
||||
## 1.0.0
|
||||
|
||||
Bump version from 1.0.0-rc.2 to 1.0.0.
|
||||
|
||||
## 1.0.0-rc.2
|
||||
|
||||
### Improvements
|
||||
|
||||
[PG-331](https://jira.percona.com/browse/PG-331): Changed the default value for the `pg_stat_monitor.pgsm_query_max_len` parameter from 1024 to 2048 for better data presentation in PMM
|
||||
|
||||
[PG-355](https://jira.percona.com/browse/PG-355): Changed the collection of `sys_time` and `user_time` metrics so that they are now presented as an accumulative value
|
||||
|
||||
[PG-286](https://jira.percona.com/browse/PG-286): Improved pg_stat_monitor performance by decreasing the overhead by more than 50%.
|
||||
|
||||
[PG-267](https://jira.percona.com/browse/PG-267): Added test case to verify histogram feature
|
||||
|
||||
[PG-359](https://jira.percona.com/browse/PG-359): Documentation: updated the `pg_stat_monitor_settings` view reference.
|
||||
|
||||
[PG-344](https://jira.percona.com/browse/PG-344): Documentation: Updated the extensions order and behavior with data collection for PostgreSQL 14.
|
||||
|
||||
[PG-358](https://jira.percona.com/browse/PG-358): Documentation: data display of `** blk **` and `** wal **` columns when both `pg_stat_monitor` and `pg_stat_statements` are loaded together.
|
||||
|
||||
### Bugs Fixed
|
||||
|
||||
[PG-350](https://jira.percona.com/browse/PG-350): Fixed bucket time overflow
|
||||
|
||||
[PG-338](https://jira.percona.com/browse/PG-338): Fixed query calls count by setting the default value for `pg_stat_monitor.pgsm_track` to `top`.
|
||||
|
||||
[PG-291](https://jira.percona.com/browse/PG-338): Fixed calls count.
|
||||
|
||||
[PG-325](https://jira.percona.com/browse/PG-325): Fixed deadlock that occurred when the query length exceeded the `pgsm_query_max_len` value.
|
||||
|
||||
[PG-326](https://jira.percona.com/browse/PG-326): Added validation for `pgsm_histogram_min` and `pgsm_histogram_max` ranges
|
||||
|
||||
[PG-329](https://jira.percona.com/browse/PG-329): Fixed creation of `pg_stat_monitor_errors` view on SQL files.
|
||||
|
||||
[PG-296](https://jira.percona.com/browse/PG-296): Fixed issue with the application name not displaying in the view when changed.
|
||||
|
||||
[PG-290](https://jira.percona.com/browse/PG-290): Fixed issue with PostgreSQL crashing after enabling debug log level and when `pg_stat_monitor` is enabled.
|
||||
|
||||
[PG-166](https://jira.percona.com/browse/PG-166): Fixed issue with displaying the actual system time values instead of `NULL`
|
||||
|
||||
[PG-369](https://jira.percona.com/browse/PG-358): Fixed issue with incorrect `wal_bytes` values for PostgreSQL 11 and 12 that caused Query Analytics failure in PMM by ignoring the `WalUsage` variable value for these versions.
|
||||
|
||||
## 1.0.0-rc.1
|
||||
|
||||
### Improvements
|
||||
|
||||
[PG-165](https://jira.percona.com/browse/PG-165): Recycle expired buckets
|
||||
|
||||
[PG-167](https://jira.percona.com/browse/PG-167): Make SQL error codes readable by updating their data types
|
||||
|
||||
[PG-193](https://jira.percona.com/browse/PG-193): Create a comment based tags to identify different parameters
|
||||
|
||||
[PG-199](https://jira.percona.com/browse/PG-199): Documentation: Add the integration with PMM section in User Guide
|
||||
|
||||
[PG-210](https://jira.percona.com/browse/PG-210): Documentation: Update column names per POstgreSQL version to match the upstream ones
|
||||
|
||||
### Bugs Fixed
|
||||
|
||||
[PG-177](https://jira.percona.com/browse/PG-177): Fixed the error in histogram ranges
|
||||
|
||||
[PG-214](https://jira.percona.com/browse/PG-214): Fixed the issue with the display of the error message as part of the query column in `pg_stat_monitor` view
|
||||
|
||||
[PG-246](https://jira.percona.com/browse/PG-246): Fixed the issue with significant CPU and memory resource usage when `pg_stat_monitor.pgsm_enable_query_plan` parameter is enabled
|
||||
|
||||
[PG-262](https://jira.percona.com/browse/PG-262): Fixed the way the comments are extracted in pg_stat_monitor view
|
||||
|
||||
[PG-271](https://jira.percona.com/browse/PG-271): Fixed the issue with enabling the ``pg_stat_monitor.pgsm_overflow_target`` configuration parameter.
|
||||
|
||||
[PG-272](https://jira.percona.com/browse/PG-272): Fixed the server crash when calling the `pg_stat_monitor_reset()` function by using the correct `PGSM_MAX_BUCKETS` GUC as the limit to the loop
|
||||
|
||||
## REL0_9_0_STABLE
|
||||
|
||||
### Improvements
|
||||
|
||||
[PG-186](https://jira.percona.com/browse/PG-186): Add support to monitor query execution plan
|
||||
|
||||
[PG-147](https://jira.percona.com/browse/PG-147): Store top query, instead of parent query.
|
||||
|
||||
[PG-188](https://jira.percona.com/browse/PG-188): Added a new column to monitor the query state i.e PARSING/PLANNING/ACTIVE/FINISHED.
|
||||
|
||||
[PG-180](https://jira.percona.com/browse/PG-180): Schema Qualified table/relations names.
|
||||
|
||||
Regression Test Suite.
|
||||
|
||||
### Bugs Fixed
|
||||
|
||||
[PG-189](https://jira.percona.com/browse/PG-189): Regression crash in case of PostgreSQL 11.
|
||||
|
||||
[PG-187](https://jira.percona.com/browse/PG-187): Compilation Error for PostgreSQL 11 and PostgreSQL 12.
|
||||
|
||||
[PG-186](https://jira.percona.com/browse/PG-186): Add support to monitor query execution plan.
|
||||
|
||||
[PG-182](https://jira.percona.com/browse/PG-182): Added a new option for the query buffer overflow.
|
||||
|
||||
[PG-181](https://jira.percona.com/browse/PG-181): Segmentation fault in case of track_utility is ON.
|
||||
|
||||
Some Code refactoring.
|
||||
|
||||
## REL0_8_1
|
||||
|
||||
[PG-147](https://jira.percona.com/browse/PG-147): Stored Procedure Support add parentid to track caller.
|
||||
|
||||
[PG-177](https://jira.percona.com/browse/PG-177): Error in Histogram ranges.
|
||||
|
||||
## REL0_8_0_STABLE
|
||||
### Improvements
|
||||
|
||||
Column userid (int64) was removed.
|
||||
Column dbid (int64) was removed.
|
||||
|
||||
Column user (string) was added (replacement for userid).
|
||||
Column datname (string) was added (replacement for dbid).
|
||||
|
||||
[PG-176](https://jira.percona.com/browse/PG-176): Extract fully qualified relations name.
|
||||
|
||||
[PG-175](https://jira.percona.com/browse/PG-175): Only Superuser / Privileged user can view IP address.
|
||||
|
||||
[PG-174](https://jira.percona.com/browse/PG-174): Code cleanup.
|
||||
|
||||
[PG-173](https://jira.percona.com/browse/PG-173): Added new WAL usage statistics.
|
||||
|
||||
[PG-172](https://jira.percona.com/browse/PG-172): Exponential histogram for time buckets.
|
||||
|
||||
[PG-164](https://jira.percona.com/browse/PG-164): Query timing will be four decimal places instead of two.
|
||||
|
||||
[PG-167](https://jira.percona.com/browse/PG-167): SQLERRCODE must be in readable format.
|
||||
|
||||
### Bugs Fixed
|
||||
|
||||
[PG-169](https://jira.percona.com/browse/PG-169): Fixing message buffer overrun and incorrect index access to fix the server crash.
|
||||
|
||||
[PG-168](https://jira.percona.com/browse/PG-168): "calls" and histogram parameter does not match.
|
||||
|
||||
[PG-166](https://jira.percona.com/browse/PG-166): Display actual system time instead of null.
|
||||
|
||||
[PG-165](https://jira.percona.com/browse/PG-165): Recycle expired buckets.
|
||||
|
||||
[PG-150](https://jira.percona.com/browse/PG-150): Error while logging CMD Type like SELECT, UPDATE, INSERT, DELETE.
|
||||
|
||||
|
||||
## REL0_7_2
|
||||
|
||||
[PG-165](https://jira.percona.com/browse/PG-165): Recycle expired buckets.
|
||||
|
||||
[PG-164](https://jira.percona.com/browse/PG-164): Query timing will be four decimal places instead of two.
|
||||
|
||||
[PG-161](https://jira.percona.com/browse/PG-161): Miscellaneous small issues.
|
||||
|
||||
## REL0_7_1
|
||||
|
||||
[PG-158](https://jira.percona.com/browse/PG-158): Segmentation fault while using pgbench with clients > 1.
|
||||
|
||||
[PG-159](https://jira.percona.com/browse/PG-159): Bucket start time (bucket_start_time) should be aligned with bucket_time.
|
||||
|
||||
[PG-160](https://jira.percona.com/browse/PG-160): Integration with PGXN.
|
||||
|
||||
|
||||
|
||||
## REL0_7_0_STABLE
|
||||
|
||||
### Improvements
|
||||
|
||||
[PG-153](https://jira.percona.com/browse/PG-153): Capture and record the application_name executing the query.
|
||||
|
||||
[PG-145](https://jira.percona.com/browse/PG-143): Add a new View/Query to show the actual Database name and Username.
|
||||
|
||||
[PG-110](https://jira.percona.com/browse/PG-110); Aggregate the number of warnings.
|
||||
|
||||
[PG-109](https://jira.percona.com/browse/PG-109): Log failed queries or queries with warning messages.
|
||||
|
||||
[PG-150](https://jira.percona.com/browse/PG-150): Differentiate different types of queries such as SELECT, UPDATE, INSERT or DELETE.
|
||||
|
||||
### Bugs Fixed
|
||||
|
||||
[PG-111](https://jira.percona.com/browse/PG-111) Show information for incomplete buckets.
|
||||
|
||||
[PG-148](https://jira.percona.com/browse/PG-148) Loss of query statistics/monitoring due to not enough “slots” available.
|
||||
|
||||
## v0.6.0
|
||||
Initial Release.
|
||||
|
||||
|
||||
## Master
|
||||
|
||||
### Improvements
|
||||
|
||||
[PG-156](https://jira.percona.com/browse/PG-156): Adding a placeholder replacement function for the prepared statement
|
||||
|
||||
24
SECURITY.md
24
SECURITY.md
|
|
@ -1,24 +0,0 @@
|
|||
# Security Policy
|
||||
|
||||
## Supported Versions
|
||||
|
||||
pg_stat_monitor project follows rolling release strategy. So all security updates go to new versions.
|
||||
|
||||
## Reporting a Vulnerability
|
||||
|
||||
Please report any vulnerabilities to our project in [Jira](https://perconadev.atlassian.net/jira/software/c/projects/PG/issues).
|
||||
|
||||
If the vulnerability is accepted and confirmed by our experts, you should normally expect us to deliver
|
||||
a version with a fix according to the timelines provided below:
|
||||
|
||||
For Percona created software (our engineers wrote the code):
|
||||
|
||||
- Low/Medium: 120 days
|
||||
- High: 90 days
|
||||
- Critical: ASAP but should not exceed 30 days
|
||||
|
||||
For Non-Percona created software (upstream provided/packaged) from the time the vendor releases a patch:
|
||||
|
||||
- Low/Medium: 2nd release from current version
|
||||
- High: Next release
|
||||
- Critical: Hotfix or no later than next release (our regular release cadence is once every month)
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
# Percona Code of Conduct
|
||||
# Percona Distribution for PostgreSQL Operator Code of Conduct
|
||||
|
||||
All Percona Products follow the [Percona Community Code of Conduct](https://github.com/percona/community/blob/main/content/contribute/coc.md).
|
||||
|
||||
|
|
|
|||
529
guc.c
529
guc.c
|
|
@ -1,14 +1,14 @@
|
|||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* guc.c
|
||||
* guc variable handling of pg_stat_monitor
|
||||
* guc.c: guc variable handling of pg_stat_monitor
|
||||
*
|
||||
* Portions Copyright © 2018-2025, Percona LLC and/or its affiliates
|
||||
* Portions Copyright © 2018-2020, Percona LLC and/or its affiliates
|
||||
*
|
||||
* Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1996-2020, PostgreSQL Global Development Group
|
||||
*
|
||||
* Portions Copyright (c) 1994, The Regents of the University of California
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* contrib/pg_stat_monitor/guc.c
|
||||
*
|
||||
|
|
@ -18,30 +18,15 @@
|
|||
|
||||
#include "pg_stat_monitor.h"
|
||||
|
||||
/* GUC variables */
|
||||
int pgsm_max;
|
||||
int pgsm_query_max_len;
|
||||
int pgsm_bucket_time;
|
||||
int pgsm_max_buckets;
|
||||
int pgsm_histogram_buckets;
|
||||
double pgsm_histogram_min;
|
||||
double pgsm_histogram_max;
|
||||
int pgsm_query_shared_buffer;
|
||||
bool pgsm_track_planning;
|
||||
bool pgsm_extract_comments;
|
||||
bool pgsm_enable_query_plan;
|
||||
bool pgsm_enable_overflow;
|
||||
bool pgsm_normalized_query;
|
||||
bool pgsm_track_utility;
|
||||
bool pgsm_track_application_names;
|
||||
bool pgsm_enable_pgsm_query_id;
|
||||
int pgsm_track;
|
||||
static int pgsm_overflow_target; /* Not used since 2.0 */
|
||||
GucVariable conf[MAX_SETTINGS];
|
||||
static void DefineIntGUC(GucVariable * conf);
|
||||
static void DefineIntGUCWithCheck(GucVariable * conf, GucIntCheckHook check);
|
||||
static void DefineBoolGUC(GucVariable * conf);
|
||||
static void DefineEnumGUC(GucVariable * conf, const struct config_enum_entry *options);
|
||||
|
||||
/* Check hooks to ensure histogram_min < histogram_max */
|
||||
static bool check_histogram_min(double *newval, void **extra, GucSource source);
|
||||
static bool check_histogram_max(double *newval, void **extra, GucSource source);
|
||||
static bool check_overflow_targer(int *newval, void **extra, GucSource source);
|
||||
static bool check_histogram_min(int *newval, void **extra, GucSource source);
|
||||
static bool check_histogram_max(int *newval, void **extra, GucSource source);
|
||||
|
||||
/*
|
||||
* Define (or redefine) custom GUC variables.
|
||||
|
|
@ -49,267 +34,287 @@ static bool check_overflow_targer(int *newval, void **extra, GucSource source);
|
|||
void
|
||||
init_guc(void)
|
||||
{
|
||||
pgsm_track = PGSM_TRACK_TOP;
|
||||
int i = 0,
|
||||
j;
|
||||
|
||||
DefineCustomIntVariable("pg_stat_monitor.pgsm_max", /* name */
|
||||
"Sets the maximum size of shared memory in (MB) used for statement's metadata tracked by pg_stat_monitor.", /* short_desc */
|
||||
NULL, /* long_desc */
|
||||
&pgsm_max, /* value address */
|
||||
256, /* boot value */
|
||||
10, /* min value */
|
||||
10240, /* max value */
|
||||
PGC_POSTMASTER, /* context */
|
||||
GUC_UNIT_MB, /* flags */
|
||||
NULL, /* check_hook */
|
||||
NULL, /* assign_hook */
|
||||
NULL /* show_hook */
|
||||
);
|
||||
conf[i] = (GucVariable)
|
||||
{
|
||||
.guc_name = "pg_stat_monitor.pgsm_max",
|
||||
.guc_desc = "Sets the maximum size of shared memory in (MB) used for statement's metadata tracked by pg_stat_monitor.",
|
||||
.guc_default = 100,
|
||||
.guc_min = 1,
|
||||
.guc_max = 1000,
|
||||
.guc_restart = true,
|
||||
.guc_unit = GUC_UNIT_MB,
|
||||
.guc_value = &PGSM_MAX
|
||||
};
|
||||
DefineIntGUC(&conf[i++]);
|
||||
|
||||
DefineCustomIntVariable("pg_stat_monitor.pgsm_query_max_len", /* name */
|
||||
"Sets the maximum length of query.", /* short_desc */
|
||||
NULL, /* long_desc */
|
||||
&pgsm_query_max_len, /* value address */
|
||||
2048, /* boot value */
|
||||
1024, /* min value */
|
||||
INT_MAX, /* max value */
|
||||
PGC_POSTMASTER, /* context */
|
||||
0, /* flags */
|
||||
NULL, /* check_hook */
|
||||
NULL, /* assign_hook */
|
||||
NULL /* show_hook */
|
||||
);
|
||||
conf[i] = (GucVariable)
|
||||
{
|
||||
.guc_name = "pg_stat_monitor.pgsm_query_max_len",
|
||||
.guc_desc = "Sets the maximum length of query.",
|
||||
.guc_default = 2048,
|
||||
.guc_min = 1024,
|
||||
.guc_max = INT_MAX,
|
||||
.guc_unit = 0,
|
||||
.guc_restart = true,
|
||||
.guc_value = &PGSM_QUERY_MAX_LEN
|
||||
};
|
||||
DefineIntGUC(&conf[i++]);
|
||||
|
||||
DefineCustomIntVariable("pg_stat_monitor.pgsm_max_buckets", /* name */
|
||||
"Sets the maximum number of buckets.", /* short_desc */
|
||||
NULL, /* long_desc */
|
||||
&pgsm_max_buckets, /* value address */
|
||||
10, /* boot value */
|
||||
1, /* min value */
|
||||
20000, /* max value */
|
||||
PGC_POSTMASTER, /* context */
|
||||
0, /* flags */
|
||||
NULL, /* check_hook */
|
||||
NULL, /* assign_hook */
|
||||
NULL /* show_hook */
|
||||
);
|
||||
conf[i] = (GucVariable)
|
||||
{
|
||||
.guc_name = "pg_stat_monitor.pgsm_track_utility",
|
||||
.guc_desc = "Selects whether utility commands are tracked.",
|
||||
.guc_default = 1,
|
||||
.guc_min = 0,
|
||||
.guc_max = 0,
|
||||
.guc_restart = false,
|
||||
.guc_unit = 0,
|
||||
.guc_value = &PGSM_TRACK_UTILITY
|
||||
};
|
||||
DefineBoolGUC(&conf[i++]);
|
||||
|
||||
DefineCustomIntVariable("pg_stat_monitor.pgsm_bucket_time", /* name */
|
||||
"Sets the time in seconds per bucket.", /* short_desc */
|
||||
NULL, /* long_desc */
|
||||
&pgsm_bucket_time, /* value address */
|
||||
60, /* boot value */
|
||||
1, /* min value */
|
||||
INT_MAX, /* max value */
|
||||
PGC_POSTMASTER, /* context */
|
||||
GUC_UNIT_S, /* flags */
|
||||
NULL, /* check_hook */
|
||||
NULL, /* assign_hook */
|
||||
NULL /* show_hook */
|
||||
);
|
||||
conf[i] = (GucVariable)
|
||||
{
|
||||
.guc_name = "pg_stat_monitor.pgsm_normalized_query",
|
||||
.guc_desc = "Selects whether save query in normalized format.",
|
||||
.guc_default = 0,
|
||||
.guc_min = 0,
|
||||
.guc_max = 0,
|
||||
.guc_restart = false,
|
||||
.guc_unit = 0,
|
||||
.guc_value = &PGSM_NORMALIZED_QUERY
|
||||
};
|
||||
DefineBoolGUC(&conf[i++]);
|
||||
|
||||
DefineCustomRealVariable("pg_stat_monitor.pgsm_histogram_min", /* name */
|
||||
"Sets the time in millisecond.", /* short_desc */
|
||||
NULL, /* long_desc */
|
||||
&pgsm_histogram_min, /* value address */
|
||||
1, /* boot value */
|
||||
0, /* min value */
|
||||
HISTOGRAM_MAX_TIME, /* max value */
|
||||
PGC_POSTMASTER, /* context */
|
||||
GUC_UNIT_MS, /* flags */
|
||||
check_histogram_min, /* check_hook */
|
||||
NULL, /* assign_hook */
|
||||
NULL /* show_hook */
|
||||
);
|
||||
conf[i] = (GucVariable)
|
||||
{
|
||||
.guc_name = "pg_stat_monitor.pgsm_max_buckets",
|
||||
.guc_desc = "Sets the maximum number of buckets.",
|
||||
.guc_default = 10,
|
||||
.guc_min = 1,
|
||||
.guc_max = 10,
|
||||
.guc_restart = true,
|
||||
.guc_unit = 0,
|
||||
.guc_value = &PGSM_MAX_BUCKETS
|
||||
};
|
||||
DefineIntGUC(&conf[i++]);
|
||||
|
||||
DefineCustomRealVariable("pg_stat_monitor.pgsm_histogram_max", /* name */
|
||||
"Sets the time in millisecond.", /* short_desc */
|
||||
NULL, /* long_desc */
|
||||
&pgsm_histogram_max, /* value address */
|
||||
100000.0, /* boot value */
|
||||
10.0, /* min value */
|
||||
HISTOGRAM_MAX_TIME, /* max value */
|
||||
PGC_POSTMASTER, /* context */
|
||||
GUC_UNIT_MS, /* flags */
|
||||
check_histogram_max, /* check_hook */
|
||||
NULL, /* assign_hook */
|
||||
NULL /* show_hook */
|
||||
);
|
||||
conf[i] = (GucVariable)
|
||||
{
|
||||
.guc_name = "pg_stat_monitor.pgsm_bucket_time",
|
||||
.guc_desc = "Sets the time in seconds per bucket.",
|
||||
.guc_default = 60,
|
||||
.guc_min = 1,
|
||||
.guc_max = INT_MAX,
|
||||
.guc_restart = true,
|
||||
.guc_unit = 0,
|
||||
.guc_value = &PGSM_BUCKET_TIME
|
||||
};
|
||||
DefineIntGUC(&conf[i++]);
|
||||
|
||||
DefineCustomIntVariable("pg_stat_monitor.pgsm_histogram_buckets", /* name */
|
||||
"Sets the maximum number of histogram buckets.", /* short_desc */
|
||||
NULL, /* long_desc */
|
||||
&pgsm_histogram_buckets, /* value address */
|
||||
20, /* boot value */
|
||||
2, /* min value */
|
||||
MAX_RESPONSE_BUCKET, /* max value */
|
||||
PGC_POSTMASTER, /* context */
|
||||
0, /* flags */
|
||||
NULL, /* check_hook */
|
||||
NULL, /* assign_hook */
|
||||
NULL /* show_hook */
|
||||
);
|
||||
conf[i] = (GucVariable)
|
||||
{
|
||||
.guc_name = "pg_stat_monitor.pgsm_histogram_min",
|
||||
.guc_desc = "Sets the time in millisecond.",
|
||||
.guc_default = 0,
|
||||
.guc_min = 0,
|
||||
.guc_max = INT_MAX,
|
||||
.guc_restart = true,
|
||||
.guc_unit = 0,
|
||||
.guc_value = &PGSM_HISTOGRAM_MIN
|
||||
};
|
||||
DefineIntGUCWithCheck(&conf[i++], check_histogram_min);
|
||||
|
||||
DefineCustomIntVariable("pg_stat_monitor.pgsm_query_shared_buffer", /* name */
|
||||
"Sets the maximum size of shared memory in (MB) used for query tracked by pg_stat_monitor.", /* short_desc */
|
||||
NULL, /* long_desc */
|
||||
&pgsm_query_shared_buffer, /* value address */
|
||||
20, /* boot value */
|
||||
1, /* min value */
|
||||
10000, /* max value */
|
||||
PGC_POSTMASTER, /* context */
|
||||
GUC_UNIT_MB, /* flags */
|
||||
NULL, /* check_hook */
|
||||
NULL, /* assign_hook */
|
||||
NULL /* show_hook */
|
||||
);
|
||||
conf[i] = (GucVariable)
|
||||
{
|
||||
.guc_name = "pg_stat_monitor.pgsm_histogram_max",
|
||||
.guc_desc = "Sets the time in millisecond.",
|
||||
.guc_default = 100000,
|
||||
.guc_min = 10,
|
||||
.guc_max = INT_MAX,
|
||||
.guc_restart = true,
|
||||
.guc_unit = 0,
|
||||
.guc_value = &PGSM_HISTOGRAM_MAX
|
||||
};
|
||||
DefineIntGUCWithCheck(&conf[i++], check_histogram_max);
|
||||
|
||||
/* deprecated in V 2.0 */
|
||||
DefineCustomIntVariable("pg_stat_monitor.pgsm_overflow_target", /* name */
|
||||
"Sets the overflow target for pg_stat_monitor. (Deprecated, use pgsm_enable_overflow)", /* short_desc */
|
||||
NULL, /* long_desc */
|
||||
&pgsm_overflow_target, /* value address */
|
||||
1, /* boot value */
|
||||
0, /* min value */
|
||||
1, /* max value */
|
||||
PGC_POSTMASTER, /* context */
|
||||
0, /* flags */
|
||||
check_overflow_targer, /* check_hook */
|
||||
NULL, /* assign_hook */
|
||||
NULL /* show_hook */
|
||||
);
|
||||
conf[i] = (GucVariable)
|
||||
{
|
||||
.guc_name = "pg_stat_monitor.pgsm_histogram_buckets",
|
||||
.guc_desc = "Sets the maximum number of histogram buckets",
|
||||
.guc_default = 10,
|
||||
.guc_min = 2,
|
||||
.guc_max = MAX_RESPONSE_BUCKET,
|
||||
.guc_restart = true,
|
||||
.guc_unit = 0,
|
||||
.guc_value = &PGSM_HISTOGRAM_BUCKETS
|
||||
};
|
||||
DefineIntGUC(&conf[i++]);
|
||||
|
||||
conf[i] = (GucVariable)
|
||||
{
|
||||
.guc_name = "pg_stat_monitor.pgsm_query_shared_buffer",
|
||||
.guc_desc = "Sets the maximum size of shared memory in (MB) used for query tracked by pg_stat_monitor.",
|
||||
.guc_default = 20,
|
||||
.guc_min = 1,
|
||||
.guc_max = 10000,
|
||||
.guc_restart = true,
|
||||
.guc_unit = GUC_UNIT_MB,
|
||||
.guc_value = &PGSM_QUERY_SHARED_BUFFER
|
||||
};
|
||||
DefineIntGUC(&conf[i++]);
|
||||
|
||||
DefineCustomBoolVariable("pg_stat_monitor.pgsm_track_utility", /* name */
|
||||
"Selects whether utility commands are tracked.", /* short_desc */
|
||||
NULL, /* long_desc */
|
||||
&pgsm_track_utility, /* value address */
|
||||
true, /* boot value */
|
||||
PGC_USERSET, /* context */
|
||||
0, /* flags */
|
||||
NULL, /* check_hook */
|
||||
NULL, /* assign_hook */
|
||||
NULL /* show_hook */
|
||||
);
|
||||
conf[i] = (GucVariable)
|
||||
{
|
||||
.guc_name = "pg_stat_monitor.pgsm_overflow_target",
|
||||
.guc_desc = "Sets the overflow target for pg_stat_monitor",
|
||||
.guc_default = 1,
|
||||
.guc_min = 0,
|
||||
.guc_max = 1,
|
||||
.guc_restart = true,
|
||||
.guc_unit = 0,
|
||||
.guc_value = &PGSM_OVERFLOW_TARGET
|
||||
};
|
||||
DefineIntGUC(&conf[i++]);
|
||||
|
||||
DefineCustomBoolVariable("pg_stat_monitor.pgsm_track_application_names", /* name */
|
||||
"Enable/Disable application names tracking.", /* short_desc */
|
||||
NULL, /* long_desc */
|
||||
&pgsm_track_application_names, /* value address */
|
||||
true, /* boot value */
|
||||
PGC_USERSET, /* context */
|
||||
0, /* flags */
|
||||
NULL, /* check_hook */
|
||||
NULL, /* assign_hook */
|
||||
NULL /* show_hook */
|
||||
);
|
||||
conf[i] = (GucVariable)
|
||||
{
|
||||
.guc_name = "pg_stat_monitor.pgsm_enable_query_plan",
|
||||
.guc_desc = "Enable/Disable query plan monitoring",
|
||||
.guc_default = 0,
|
||||
.guc_min = 0,
|
||||
.guc_max = 0,
|
||||
.guc_restart = false,
|
||||
.guc_unit = 0,
|
||||
.guc_value = &PGSM_QUERY_PLAN
|
||||
};
|
||||
DefineBoolGUC(&conf[i++]);
|
||||
|
||||
DefineCustomBoolVariable("pg_stat_monitor.pgsm_enable_pgsm_query_id", /* name */
|
||||
"Enable/disable PGSM specific query id calculation which is very useful in comparing same query across databases and clusters..", /* short_desc */
|
||||
NULL, /* long_desc */
|
||||
&pgsm_enable_pgsm_query_id, /* value address */
|
||||
true, /* boot value */
|
||||
PGC_USERSET, /* context */
|
||||
0, /* flags */
|
||||
NULL, /* check_hook */
|
||||
NULL, /* assign_hook */
|
||||
NULL /* show_hook */
|
||||
);
|
||||
conf[i] = (GucVariable)
|
||||
{
|
||||
.guc_name = "pg_stat_monitor.pgsm_track",
|
||||
.guc_desc = "Selects which statements are tracked by pg_stat_monitor.",
|
||||
.n_options = 3,
|
||||
.guc_default = PGSM_TRACK_TOP,
|
||||
.guc_min = PSGM_TRACK_NONE,
|
||||
.guc_max = PGSM_TRACK_ALL,
|
||||
.guc_restart = false,
|
||||
.guc_unit = 0,
|
||||
.guc_value = &PGSM_TRACK
|
||||
};
|
||||
for (j = 0; j < conf[i].n_options; ++j)
|
||||
{
|
||||
strlcpy(conf[i].guc_options[j], track_options[j].name, sizeof(conf[i].guc_options[j]));
|
||||
}
|
||||
DefineEnumGUC(&conf[i++], track_options);
|
||||
|
||||
DefineCustomBoolVariable("pg_stat_monitor.pgsm_normalized_query", /* name */
|
||||
"Selects whether save query in normalized format.", /* short_desc */
|
||||
NULL, /* long_desc */
|
||||
&pgsm_normalized_query, /* value address */
|
||||
false, /* boot value */
|
||||
PGC_USERSET, /* context */
|
||||
0, /* flags */
|
||||
NULL, /* check_hook */
|
||||
NULL, /* assign_hook */
|
||||
NULL /* show_hook */
|
||||
);
|
||||
|
||||
DefineCustomBoolVariable("pg_stat_monitor.pgsm_enable_overflow", /* name */
|
||||
"Enable/Disable pg_stat_monitor to grow beyond shared memory into swap space.", /* short_desc */
|
||||
NULL, /* long_desc */
|
||||
&pgsm_enable_overflow, /* value address */
|
||||
true, /* boot value */
|
||||
PGC_POSTMASTER, /* context */
|
||||
0, /* flags */
|
||||
NULL, /* check_hook */
|
||||
NULL, /* assign_hook */
|
||||
NULL /* show_hook */
|
||||
);
|
||||
|
||||
DefineCustomBoolVariable("pg_stat_monitor.pgsm_enable_query_plan", /* name */
|
||||
"Enable/Disable query plan monitoring.", /* short_desc */
|
||||
NULL, /* long_desc */
|
||||
&pgsm_enable_query_plan, /* value address */
|
||||
false, /* boot value */
|
||||
PGC_USERSET, /* context */
|
||||
0, /* flags */
|
||||
NULL, /* check_hook */
|
||||
NULL, /* assign_hook */
|
||||
NULL /* show_hook */
|
||||
);
|
||||
|
||||
DefineCustomBoolVariable("pg_stat_monitor.pgsm_extract_comments", /* name */
|
||||
"Enable/Disable extracting comments from queries.", /* short_desc */
|
||||
NULL, /* long_desc */
|
||||
&pgsm_extract_comments, /* value address */
|
||||
false, /* boot value */
|
||||
PGC_USERSET, /* context */
|
||||
0, /* flags */
|
||||
NULL, /* check_hook */
|
||||
NULL, /* assign_hook */
|
||||
NULL /* show_hook */
|
||||
);
|
||||
|
||||
DefineCustomEnumVariable("pg_stat_monitor.pgsm_track", /* name */
|
||||
"Selects which statements are tracked by pg_stat_monitor.", /* short_desc */
|
||||
NULL, /* long_desc */
|
||||
&pgsm_track, /* value address */
|
||||
PGSM_TRACK_TOP, /* boot value */
|
||||
track_options, /* enum options */
|
||||
PGC_USERSET, /* context */
|
||||
0, /* flags */
|
||||
NULL, /* check_hook */
|
||||
NULL, /* assign_hook */
|
||||
NULL /* show_hook */
|
||||
);
|
||||
DefineCustomBoolVariable("pg_stat_monitor.pgsm_track_planning", /* name */
|
||||
"Selects whether planning statistics are tracked.", /* short_desc */
|
||||
NULL, /* long_desc */
|
||||
&pgsm_track_planning, /* value address */
|
||||
false, /* boot value */
|
||||
PGC_USERSET, /* context */
|
||||
0, /* flags */
|
||||
NULL, /* check_hook */
|
||||
NULL, /* assign_hook */
|
||||
NULL /* show_hook */
|
||||
);
|
||||
conf[i] = (GucVariable)
|
||||
{
|
||||
.guc_name = "pg_stat_monitor.pgsm_extract_comments",
|
||||
.guc_desc = "Enable/Disable extracting comments from queries.",
|
||||
.guc_default = 0,
|
||||
.guc_min = 0,
|
||||
.guc_max = 0,
|
||||
.guc_restart = false,
|
||||
.guc_unit = 0,
|
||||
.guc_value = &PGSM_EXTRACT_COMMENTS
|
||||
};
|
||||
DefineBoolGUC(&conf[i++]);
|
||||
|
||||
#if PG_VERSION_NUM >= 130000
|
||||
conf[i] = (GucVariable)
|
||||
{
|
||||
.guc_name = "pg_stat_monitor.pgsm_track_planning",
|
||||
.guc_desc = "Selects whether planning statistics are tracked.",
|
||||
.guc_default = 0,
|
||||
.guc_min = 0,
|
||||
.guc_max = 0,
|
||||
.guc_restart = false,
|
||||
.guc_unit = 0,
|
||||
.guc_value = &PGSM_TRACK_PLANNING
|
||||
};
|
||||
DefineBoolGUC(&conf[i++]);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void
|
||||
DefineIntGUCWithCheck(GucVariable * conf, GucIntCheckHook check)
|
||||
{
|
||||
conf->type = PGC_INT;
|
||||
DefineCustomIntVariable(conf->guc_name,
|
||||
conf->guc_desc,
|
||||
NULL,
|
||||
conf->guc_value,
|
||||
conf->guc_default,
|
||||
conf->guc_min,
|
||||
conf->guc_max,
|
||||
conf->guc_restart ? PGC_POSTMASTER : PGC_USERSET,
|
||||
conf->guc_unit,
|
||||
check,
|
||||
NULL,
|
||||
NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
DefineIntGUC(GucVariable * conf)
|
||||
{
|
||||
DefineIntGUCWithCheck(conf, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
DefineBoolGUC(GucVariable * conf)
|
||||
{
|
||||
conf->type = PGC_BOOL;
|
||||
DefineCustomBoolVariable(conf->guc_name,
|
||||
conf->guc_desc,
|
||||
NULL,
|
||||
(bool *) conf->guc_value,
|
||||
conf->guc_default,
|
||||
conf->guc_restart ? PGC_POSTMASTER : PGC_USERSET,
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
DefineEnumGUC(GucVariable * conf, const struct config_enum_entry *options)
|
||||
{
|
||||
conf->type = PGC_ENUM;
|
||||
DefineCustomEnumVariable(conf->guc_name,
|
||||
conf->guc_desc,
|
||||
NULL,
|
||||
conf->guc_value,
|
||||
conf->guc_default,
|
||||
options,
|
||||
conf->guc_restart ? PGC_POSTMASTER : PGC_USERSET,
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL);
|
||||
}
|
||||
|
||||
GucVariable *
|
||||
get_conf(int i)
|
||||
{
|
||||
return &conf[i];
|
||||
}
|
||||
|
||||
/* Maximum value must be greater or equal to minimum + 1.0 */
|
||||
static bool
|
||||
check_histogram_min(double *newval, void **extra, GucSource source)
|
||||
check_histogram_min(int *newval, void **extra, GucSource source)
|
||||
{
|
||||
/*
|
||||
* During module initialization PGSM_HISTOGRAM_MIN is initialized before
|
||||
* PGSM_HISTOGRAM_MAX, in this case PGSM_HISTOGRAM_MAX will be zero.
|
||||
*/
|
||||
return (pgsm_histogram_max == 0 || (*newval + 1.0) <= pgsm_histogram_max);
|
||||
return (PGSM_HISTOGRAM_MAX == 0 || *newval < PGSM_HISTOGRAM_MAX);
|
||||
}
|
||||
|
||||
static bool
|
||||
check_histogram_max(double *newval, void **extra, GucSource source)
|
||||
check_histogram_max(int *newval, void **extra, GucSource source)
|
||||
{
|
||||
return (*newval >= (pgsm_histogram_min + 1.0));
|
||||
}
|
||||
|
||||
static bool
|
||||
check_overflow_targer(int *newval, void **extra, GucSource source)
|
||||
{
|
||||
if (source != PGC_S_DEFAULT)
|
||||
elog(WARNING, "pg_stat_monitor.pgsm_overflow_target is deprecated, use pgsm_enable_overflow");
|
||||
return true;
|
||||
return (*newval > PGSM_HISTOGRAM_MIN);
|
||||
}
|
||||
|
|
|
|||
519
hash_query.c
519
hash_query.c
|
|
@ -3,9 +3,9 @@
|
|||
* hash_query.c
|
||||
* Track statement execution times across a whole database cluster.
|
||||
*
|
||||
* Portions Copyright © 2018-2025, Percona LLC and/or its affiliates
|
||||
* Portions Copyright © 2018-2020, Percona LLC and/or its affiliates
|
||||
*
|
||||
* Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1996-2020, PostgreSQL Global Development Group
|
||||
*
|
||||
* Portions Copyright (c) 1994, The Regents of the University of California
|
||||
*
|
||||
|
|
@ -16,255 +16,85 @@
|
|||
*/
|
||||
#include "postgres.h"
|
||||
#include "nodes/pg_list.h"
|
||||
|
||||
#include "pg_stat_monitor.h"
|
||||
|
||||
static pgsmLocalState pgsmStateLocal;
|
||||
static PGSM_HASH_TABLE_HANDLE pgsm_create_bucket_hash(pgsmSharedState *pgsm, dsa_area *dsa);
|
||||
static Size pgsm_get_shared_area_size(void);
|
||||
static void InitializeSharedState(pgsmSharedState *pgsm);
|
||||
|
||||
#define PGSM_BUCKET_INFO_SIZE (sizeof(TimestampTz) * pgsm_max_buckets)
|
||||
#define PGSM_SHARED_STATE_SIZE (sizeof(pgsmSharedState) + PGSM_BUCKET_INFO_SIZE)
|
||||
static pgssSharedState *pgss;
|
||||
static HTAB *pgss_hash;
|
||||
static HTAB *pgss_query_hash;
|
||||
|
||||
#if USE_DYNAMIC_HASH
|
||||
/* parameter for the shared hash */
|
||||
static dshash_parameters dsh_params = {
|
||||
sizeof(pgsmHashKey),
|
||||
sizeof(pgsmEntry),
|
||||
dshash_memcmp,
|
||||
dshash_memhash
|
||||
};
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Returns the shared memory area size for storing the query texts.
|
||||
* USE_DYNAMIC_HASH also creates the hash table in the same memory space,
|
||||
* so add the required bucket memory size to the query text area size
|
||||
*/
|
||||
|
||||
static Size
|
||||
pgsm_query_area_size(void)
|
||||
static HTAB *
|
||||
hash_init(const char *hash_name, int key_size, int entry_size, int hash_size)
|
||||
{
|
||||
Size sz = MAX_QUERY_BUF;
|
||||
#if USE_DYNAMIC_HASH
|
||||
/* Dynamic hash also lives DSA area */
|
||||
sz = add_size(sz, MAX_BUCKETS_MEM);
|
||||
#endif
|
||||
return MAXALIGN(sz);
|
||||
}
|
||||
HASHCTL info;
|
||||
|
||||
/*
|
||||
* Total shared memory area required by pgsm
|
||||
*/
|
||||
Size
|
||||
pgsm_ShmemSize(void)
|
||||
{
|
||||
Size sz = MAXALIGN(PGSM_SHARED_STATE_SIZE);
|
||||
|
||||
sz = add_size(sz, MAX_QUERY_BUF);
|
||||
#if USE_DYNAMIC_HASH
|
||||
sz = add_size(sz, MAX_BUCKETS_MEM);
|
||||
#else
|
||||
sz = add_size(sz, hash_estimate_size(MAX_BUCKET_ENTRIES, sizeof(pgsmEntry)));
|
||||
#endif
|
||||
return MAXALIGN(sz);
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns the shared memory area size for storing the query texts and pgsm
|
||||
* shared state structure,
|
||||
* Moreover, for USE_DYNAMIC_HASH, both the hash table and raw query text area
|
||||
* get allocated as a single shared memory chunk.
|
||||
*/
|
||||
static Size
|
||||
pgsm_get_shared_area_size(void)
|
||||
{
|
||||
Size sz;
|
||||
#if USE_DYNAMIC_HASH
|
||||
sz = pgsm_ShmemSize();
|
||||
#else
|
||||
sz = MAXALIGN(sizeof(pgsmSharedState));
|
||||
sz = add_size(sz, pgsm_query_area_size());
|
||||
#endif
|
||||
return sz;
|
||||
memset(&info, 0, sizeof(info));
|
||||
info.keysize = key_size;
|
||||
info.entrysize = entry_size;
|
||||
return ShmemInitHash(hash_name, hash_size, hash_size, &info, HASH_ELEM | HASH_BLOBS);
|
||||
}
|
||||
|
||||
void
|
||||
pgsm_startup(void)
|
||||
pgss_startup(void)
|
||||
{
|
||||
bool found = false;
|
||||
pgsmSharedState *pgsm;
|
||||
|
||||
/* reset in case this is a restart within the postmaster */
|
||||
pgsmStateLocal.dsa = NULL;
|
||||
pgsmStateLocal.shared_hash = NULL;
|
||||
pgsmStateLocal.shared_pgsmState = NULL;
|
||||
|
||||
pgss = NULL;
|
||||
pgss_hash = NULL;
|
||||
|
||||
/*
|
||||
* Create or attach to the shared memory state, including hash table
|
||||
*/
|
||||
LWLockAcquire(AddinShmemInitLock, LW_EXCLUSIVE);
|
||||
|
||||
pgsm = ShmemInitStruct("pg_stat_monitor", pgsm_get_shared_area_size(), &found);
|
||||
pgss = ShmemInitStruct("pg_stat_monitor", sizeof(pgssSharedState), &found);
|
||||
if (!found)
|
||||
{
|
||||
/* First time through ... */
|
||||
dsa_area *dsa;
|
||||
char *p = (char *) pgsm;
|
||||
|
||||
pgsm->pgsm_oom = false;
|
||||
pgsm->lock = &(GetNamedLWLockTranche("pg_stat_monitor"))->lock;
|
||||
SpinLockInit(&pgsm->mutex);
|
||||
InitializeSharedState(pgsm);
|
||||
/* the allocation of pgsmSharedState itself */
|
||||
p += MAXALIGN(PGSM_SHARED_STATE_SIZE);
|
||||
pgsm->raw_dsa_area = p;
|
||||
dsa = dsa_create_in_place(pgsm->raw_dsa_area,
|
||||
pgsm_query_area_size(),
|
||||
LWLockNewTrancheId(), 0);
|
||||
dsa_pin(dsa);
|
||||
dsa_set_size_limit(dsa, pgsm_query_area_size());
|
||||
|
||||
pgsm->hash_handle = pgsm_create_bucket_hash(pgsm, dsa);
|
||||
|
||||
/*
|
||||
* If overflow is enabled, set the DSA size to unlimited, and allow
|
||||
* the DSA to grow beyond the shared memory space into the swap area
|
||||
*/
|
||||
if (pgsm_enable_overflow)
|
||||
dsa_set_size_limit(dsa, -1);
|
||||
|
||||
pgsmStateLocal.shared_pgsmState = pgsm;
|
||||
|
||||
/*
|
||||
* Postmaster will never access the dsa again, thus free it's local
|
||||
* references.
|
||||
*/
|
||||
dsa_detach(dsa);
|
||||
|
||||
pgsmStateLocal.pgsm_mem_cxt = AllocSetContextCreate(TopMemoryContext,
|
||||
"pg_stat_monitor local store",
|
||||
ALLOCSET_DEFAULT_SIZES);
|
||||
pgss->lock = &(GetNamedLWLockTranche("pg_stat_monitor"))->lock;
|
||||
SpinLockInit(&pgss->mutex);
|
||||
ResetSharedState(pgss);
|
||||
}
|
||||
|
||||
#ifdef BENCHMARK
|
||||
init_hook_stats();
|
||||
#endif
|
||||
|
||||
set_qbuf((unsigned char *) ShmemAlloc(MAX_QUERY_BUF));
|
||||
|
||||
pgss_hash = hash_init("pg_stat_monitor: bucket hashtable", sizeof(pgssHashKey), sizeof(pgssEntry), MAX_BUCKET_ENTRIES);
|
||||
pgss_query_hash = hash_init("pg_stat_monitor: queryID hashtable", sizeof(uint64), sizeof(pgssQueryEntry), MAX_BUCKET_ENTRIES);
|
||||
|
||||
LWLockRelease(AddinShmemInitLock);
|
||||
|
||||
/*
|
||||
* If we're in the postmaster (or a standalone backend...), set up a shmem
|
||||
* exit hook to dump the statistics to disk.
|
||||
*/
|
||||
on_shmem_exit(pgsm_shmem_shutdown, (Datum) 0);
|
||||
on_shmem_exit(pgss_shmem_shutdown, (Datum) 0);
|
||||
}
|
||||
|
||||
static void
|
||||
InitializeSharedState(pgsmSharedState *pgsm)
|
||||
{
|
||||
pg_atomic_init_u64(&pgsm->current_wbucket, 0);
|
||||
pg_atomic_init_u64(&pgsm->prev_bucket_sec, 0);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Create the classic or dshahs hash table for storing the query statistics.
|
||||
*/
|
||||
static PGSM_HASH_TABLE_HANDLE
|
||||
pgsm_create_bucket_hash(pgsmSharedState *pgsm, dsa_area *dsa)
|
||||
{
|
||||
PGSM_HASH_TABLE_HANDLE bucket_hash;
|
||||
|
||||
#if USE_DYNAMIC_HASH
|
||||
dshash_table *dsh;
|
||||
|
||||
pgsm->hash_tranche_id = LWLockNewTrancheId();
|
||||
dsh_params.tranche_id = pgsm->hash_tranche_id;
|
||||
dsh = dshash_create(dsa, &dsh_params, 0);
|
||||
bucket_hash = dshash_get_hash_table_handle(dsh);
|
||||
dshash_detach(dsh);
|
||||
#else
|
||||
HASHCTL info;
|
||||
|
||||
memset(&info, 0, sizeof(info));
|
||||
info.keysize = sizeof(pgsmHashKey);
|
||||
info.entrysize = sizeof(pgsmEntry);
|
||||
bucket_hash = ShmemInitHash("pg_stat_monitor: bucket hashtable", MAX_BUCKET_ENTRIES, MAX_BUCKET_ENTRIES, &info, HASH_ELEM | HASH_BLOBS);
|
||||
#endif
|
||||
return bucket_hash;
|
||||
}
|
||||
|
||||
/*
|
||||
* Attach to a DSA area created by the postmaster, in the case of
|
||||
* USE_DYNAMIC_HASH, also attach the local dshash handle to
|
||||
* the dshash created by the postmaster.
|
||||
*
|
||||
* Note: The dsa area and dshash for the process may be mapped at a
|
||||
* different virtual address in this process.
|
||||
*
|
||||
*/
|
||||
void
|
||||
pgsm_attach_shmem(void)
|
||||
{
|
||||
MemoryContext oldcontext;
|
||||
|
||||
if (pgsmStateLocal.dsa)
|
||||
return;
|
||||
|
||||
/*
|
||||
* We want the dsa to remain valid throughout the lifecycle of this
|
||||
* process. so switch to TopMemoryContext before attaching
|
||||
*/
|
||||
oldcontext = MemoryContextSwitchTo(TopMemoryContext);
|
||||
|
||||
pgsmStateLocal.dsa = dsa_attach_in_place(pgsmStateLocal.shared_pgsmState->raw_dsa_area,
|
||||
NULL);
|
||||
|
||||
/*
|
||||
* pin the attached area to keep the area attached until end of session or
|
||||
* explicit detach.
|
||||
*/
|
||||
dsa_pin_mapping(pgsmStateLocal.dsa);
|
||||
|
||||
#if USE_DYNAMIC_HASH
|
||||
dsh_params.tranche_id = pgsmStateLocal.shared_pgsmState->hash_tranche_id;
|
||||
pgsmStateLocal.shared_hash = dshash_attach(pgsmStateLocal.dsa, &dsh_params,
|
||||
pgsmStateLocal.shared_pgsmState->hash_handle, 0);
|
||||
#else
|
||||
pgsmStateLocal.shared_hash = pgsmStateLocal.shared_pgsmState->hash_handle;
|
||||
#endif
|
||||
|
||||
MemoryContextSwitchTo(oldcontext);
|
||||
}
|
||||
|
||||
MemoryContext
|
||||
GetPgsmMemoryContext(void)
|
||||
{
|
||||
return pgsmStateLocal.pgsm_mem_cxt;
|
||||
}
|
||||
|
||||
dsa_area *
|
||||
get_dsa_area_for_query_text(void)
|
||||
{
|
||||
pgsm_attach_shmem();
|
||||
return pgsmStateLocal.dsa;
|
||||
}
|
||||
|
||||
PGSM_HASH_TABLE *
|
||||
get_pgsmHash(void)
|
||||
{
|
||||
pgsm_attach_shmem();
|
||||
return pgsmStateLocal.shared_hash;
|
||||
}
|
||||
|
||||
pgsmSharedState *
|
||||
pgssSharedState *
|
||||
pgsm_get_ss(void)
|
||||
{
|
||||
pgsm_attach_shmem();
|
||||
return pgsmStateLocal.shared_pgsmState;
|
||||
return pgss;
|
||||
}
|
||||
|
||||
HTAB *
|
||||
pgsm_get_hash(void)
|
||||
{
|
||||
return pgss_hash;
|
||||
}
|
||||
|
||||
HTAB *
|
||||
pgsm_get_query_hash(void)
|
||||
{
|
||||
return pgss_query_hash;
|
||||
}
|
||||
|
||||
/*
|
||||
* shmem_shutdown hook: Dump statistics into file.
|
||||
|
|
@ -273,50 +103,58 @@ pgsm_get_ss(void)
|
|||
* other processes running when this is called.
|
||||
*/
|
||||
void
|
||||
pgsm_shmem_shutdown(int code, Datum arg)
|
||||
pgss_shmem_shutdown(int code, Datum arg)
|
||||
{
|
||||
/* Don't try to dump during a crash. */
|
||||
elog(LOG, "[pg_stat_monitor] pgsm_shmem_shutdown: Shutdown initiated.");
|
||||
|
||||
if (code)
|
||||
return;
|
||||
|
||||
pgsmStateLocal.shared_pgsmState = NULL;
|
||||
pgss = NULL;
|
||||
/* Safety check ... shouldn't get here unless shmem is set up. */
|
||||
if (!IsHashInitialize())
|
||||
return;
|
||||
}
|
||||
|
||||
pgsmEntry *
|
||||
hash_entry_alloc(pgsmSharedState *pgsm, pgsmHashKey *key, int encoding)
|
||||
Size
|
||||
hash_memsize(void)
|
||||
{
|
||||
pgsmEntry *entry = NULL;
|
||||
Size size;
|
||||
|
||||
size = MAXALIGN(sizeof(pgssSharedState));
|
||||
size += MAXALIGN(MAX_QUERY_BUF);
|
||||
size = add_size(size, hash_estimate_size(MAX_BUCKET_ENTRIES, sizeof(pgssEntry)));
|
||||
size = add_size(size, hash_estimate_size(MAX_BUCKET_ENTRIES, sizeof(pgssQueryEntry)));
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
pgssEntry *
|
||||
hash_entry_alloc(pgssSharedState *pgss, pgssHashKey *key, int encoding)
|
||||
{
|
||||
pgssEntry *entry = NULL;
|
||||
bool found = false;
|
||||
|
||||
if (hash_get_num_entries(pgss_hash) >= MAX_BUCKET_ENTRIES)
|
||||
{
|
||||
elog(DEBUG1, "pg_stat_monitor: out of memory");
|
||||
return NULL;
|
||||
}
|
||||
/* Find or create an entry with desired hash code */
|
||||
entry = (pgsmEntry *) pgsm_hash_find_or_insert(pgsmStateLocal.shared_hash, key, &found);
|
||||
entry = (pgssEntry *) hash_search(pgss_hash, key, HASH_ENTER_NULL, &found);
|
||||
if (entry == NULL)
|
||||
elog(DEBUG1, "[pg_stat_monitor] hash_entry_alloc: OUT OF MEMORY.");
|
||||
elog(DEBUG1, "hash_entry_alloc: OUT OF MEMORY");
|
||||
else if (!found)
|
||||
{
|
||||
pgss->bucket_entry[pg_atomic_read_u64(&pgss->current_wbucket)]++;
|
||||
/* New entry, initialize it */
|
||||
/* reset the statistics */
|
||||
memset(&entry->counters, 0, sizeof(Counters));
|
||||
entry->query_text.query_pos = InvalidDsaPointer;
|
||||
entry->counters.info.parent_query = InvalidDsaPointer;
|
||||
entry->stats_since = GetCurrentTimestamp();
|
||||
entry->minmax_stats_since = entry->stats_since;
|
||||
|
||||
/* set the appropriate initial usage count */
|
||||
/* re-initialize the mutex each time ... we assume no one using it */
|
||||
SpinLockInit(&entry->mutex);
|
||||
/* ... and don't forget the query text metadata */
|
||||
entry->encoding = encoding;
|
||||
}
|
||||
#if USE_DYNAMIC_HASH
|
||||
if (entry)
|
||||
dshash_release_lock(pgsmStateLocal.shared_hash, entry);
|
||||
#endif
|
||||
|
||||
return entry;
|
||||
}
|
||||
|
|
@ -324,132 +162,167 @@ hash_entry_alloc(pgsmSharedState *pgsm, pgsmHashKey *key, int encoding)
|
|||
/*
|
||||
* Prepare resources for using the new bucket:
|
||||
* - Deallocate finished hash table entries in new_bucket_id (entries whose
|
||||
* state is PGSM_EXEC or PGSM_ERROR).
|
||||
* state is PGSS_FINISHED or PGSS_FINISHED).
|
||||
* - Clear query buffer for new_bucket_id.
|
||||
* - If old_bucket_id != -1, move all pending hash table entries in
|
||||
* old_bucket_id to the new bucket id, also move pending queries from the
|
||||
* previous query buffer (query_buffer[old_bucket_id]) to the new one
|
||||
* (query_buffer[new_bucket_id]).
|
||||
*
|
||||
* Caller must hold an exclusive lock on pgsm->lock.
|
||||
* Caller must hold an exclusive lock on pgss->lock.
|
||||
*/
|
||||
void
|
||||
hash_entry_dealloc(int new_bucket_id, int old_bucket_id, unsigned char *query_buffer)
|
||||
{
|
||||
PGSM_HASH_SEQ_STATUS hstat;
|
||||
pgsmEntry *entry = NULL;
|
||||
HASH_SEQ_STATUS hash_seq;
|
||||
pgssEntry *entry = NULL;
|
||||
|
||||
/* Store pending query ids from the previous bucket. */
|
||||
|
||||
if (!pgsmStateLocal.shared_hash)
|
||||
return;
|
||||
List *pending_entries = NIL;
|
||||
ListCell *pending_entry;
|
||||
|
||||
/* Iterate over the hash table. */
|
||||
pgsm_hash_seq_init(&hstat, pgsmStateLocal.shared_hash, true);
|
||||
|
||||
while ((entry = pgsm_hash_seq_next(&hstat)) != NULL)
|
||||
hash_seq_init(&hash_seq, pgss_hash);
|
||||
while ((entry = hash_seq_search(&hash_seq)) != NULL)
|
||||
{
|
||||
dsa_pointer pdsa;
|
||||
|
||||
/*
|
||||
* Remove all entries if new_bucket_id == -1. Otherwise remove entry
|
||||
* in new_bucket_id if it has finished already.
|
||||
*/
|
||||
if (new_bucket_id < 0 ||
|
||||
(entry->key.bucket_id == new_bucket_id))
|
||||
(entry->key.bucket_id == new_bucket_id &&
|
||||
(entry->counters.state == PGSS_FINISHED || entry->counters.state == PGSS_ERROR)))
|
||||
{
|
||||
dsa_pointer parent_qdsa = entry->counters.info.parent_query;
|
||||
if (new_bucket_id == -1)
|
||||
{
|
||||
/*
|
||||
* pg_stat_monitor_reset(), remove entry from query hash table
|
||||
* too.
|
||||
*/
|
||||
hash_search(pgss_query_hash, &(entry->key.queryid), HASH_REMOVE, NULL);
|
||||
}
|
||||
|
||||
pdsa = entry->query_text.query_pos;
|
||||
entry = hash_search(pgss_hash, &entry->key, HASH_REMOVE, NULL);
|
||||
}
|
||||
|
||||
pgsm_hash_delete_current(&hstat, pgsmStateLocal.shared_hash, &entry->key);
|
||||
/*
|
||||
* If we detect a pending query residing in the previous bucket id, we
|
||||
* add it to a list of pending elements to be moved to the new bucket
|
||||
* id. Can't update the hash table while iterating it inside this
|
||||
* loop, as this may introduce all sort of problems.
|
||||
*/
|
||||
if (old_bucket_id != -1 && entry->key.bucket_id == old_bucket_id)
|
||||
{
|
||||
if (entry->counters.state == PGSS_PARSE ||
|
||||
entry->counters.state == PGSS_PLAN ||
|
||||
entry->counters.state == PGSS_EXEC)
|
||||
{
|
||||
pgssEntry *bkp_entry = malloc(sizeof(pgssEntry));
|
||||
|
||||
if (DsaPointerIsValid(pdsa))
|
||||
dsa_free(pgsmStateLocal.dsa, pdsa);
|
||||
if (!bkp_entry)
|
||||
{
|
||||
elog(DEBUG1, "hash_entry_dealloc: out of memory");
|
||||
|
||||
if (DsaPointerIsValid(parent_qdsa))
|
||||
dsa_free(pgsmStateLocal.dsa, parent_qdsa);
|
||||
/*
|
||||
* No memory, If the entry has calls > 1 then we change
|
||||
* the state to finished, as the pending query will likely
|
||||
* finish execution during the new bucket time window. The
|
||||
* pending query will vanish in this case, can't list it
|
||||
* until it completes.
|
||||
*
|
||||
* If there is only one call to the query and it's
|
||||
* pending, remove the entry from the previous bucket and
|
||||
* allow it to finish in the new bucket, in order to avoid
|
||||
* the query living in the old bucket forever.
|
||||
*/
|
||||
if (entry->counters.calls.calls > 1)
|
||||
entry->counters.state = PGSS_FINISHED;
|
||||
else
|
||||
entry = hash_search(pgss_hash, &entry->key, HASH_REMOVE, NULL);
|
||||
continue;
|
||||
}
|
||||
|
||||
pgsmStateLocal.shared_pgsmState->pgsm_oom = false;
|
||||
/* Save key/data from the previous entry. */
|
||||
memcpy(bkp_entry, entry, sizeof(pgssEntry));
|
||||
|
||||
/* Update key to use the new bucket id. */
|
||||
bkp_entry->key.bucket_id = new_bucket_id;
|
||||
|
||||
/* Add the entry to a list of nodes to be processed later. */
|
||||
pending_entries = lappend(pending_entries, bkp_entry);
|
||||
|
||||
/*
|
||||
* If the entry has calls > 1 then we change the state to
|
||||
* finished in the previous bucket, as the pending query will
|
||||
* likely finish execution during the new bucket time window.
|
||||
* Can't remove it from the previous bucket as it may have
|
||||
* many calls and we would lose the query statistics.
|
||||
*
|
||||
* If there is only one call to the query and it's pending,
|
||||
* remove the entry from the previous bucket and allow it to
|
||||
* finish in the new bucket, in order to avoid the query
|
||||
* living in the old bucket forever.
|
||||
*/
|
||||
if (entry->counters.calls.calls > 1)
|
||||
entry->counters.state = PGSS_FINISHED;
|
||||
else
|
||||
entry = hash_search(pgss_hash, &entry->key, HASH_REMOVE, NULL);
|
||||
}
|
||||
}
|
||||
pgsm_hash_seq_term(&hstat);
|
||||
}
|
||||
|
||||
/*
|
||||
* Iterate over the list of pending queries in order to add them back to
|
||||
* the hash table with the updated bucket id.
|
||||
*/
|
||||
foreach(pending_entry, pending_entries)
|
||||
{
|
||||
bool found = false;
|
||||
pgssEntry *new_entry;
|
||||
pgssEntry *old_entry = (pgssEntry *) lfirst(pending_entry);
|
||||
|
||||
new_entry = (pgssEntry *) hash_search(pgss_hash, &old_entry->key, HASH_ENTER_NULL, &found);
|
||||
if (new_entry == NULL)
|
||||
elog(DEBUG1, "%s", "pg_stat_monitor: out of memory");
|
||||
else if (!found)
|
||||
{
|
||||
/* Restore counters and other data. */
|
||||
new_entry->counters = old_entry->counters;
|
||||
SpinLockInit(&new_entry->mutex);
|
||||
new_entry->encoding = old_entry->encoding;
|
||||
new_entry->query_pos = old_entry->query_pos;
|
||||
}
|
||||
|
||||
free(old_entry);
|
||||
}
|
||||
|
||||
list_free(pending_entries);
|
||||
}
|
||||
|
||||
/*
|
||||
* Release all entries.
|
||||
*/
|
||||
void
|
||||
hash_entry_reset()
|
||||
{
|
||||
pgssSharedState *pgss = pgsm_get_ss();
|
||||
HASH_SEQ_STATUS hash_seq;
|
||||
pgssEntry *entry;
|
||||
|
||||
LWLockAcquire(pgss->lock, LW_EXCLUSIVE);
|
||||
|
||||
hash_seq_init(&hash_seq, pgss_hash);
|
||||
while ((entry = hash_seq_search(&hash_seq)) != NULL)
|
||||
{
|
||||
hash_search(pgss_hash, &entry->key, HASH_REMOVE, NULL);
|
||||
}
|
||||
pg_atomic_write_u64(&pgss->current_wbucket, 0);
|
||||
LWLockRelease(pgss->lock);
|
||||
}
|
||||
|
||||
bool
|
||||
IsHashInitialize(void)
|
||||
{
|
||||
return (pgsmStateLocal.shared_pgsmState != NULL);
|
||||
}
|
||||
|
||||
bool
|
||||
IsSystemOOM(void)
|
||||
{
|
||||
return (IsHashInitialize() && pgsmStateLocal.shared_pgsmState->pgsm_oom);
|
||||
}
|
||||
|
||||
/*
|
||||
* pgsm_* functions are just wrapper functions over the hash table standard
|
||||
* API and call the appropriate hash table function based on USE_DYNAMIC_HASH
|
||||
*/
|
||||
|
||||
void *
|
||||
pgsm_hash_find_or_insert(PGSM_HASH_TABLE * shared_hash, pgsmHashKey *key, bool *found)
|
||||
{
|
||||
#if USE_DYNAMIC_HASH
|
||||
void *entry;
|
||||
|
||||
entry = dshash_find_or_insert(shared_hash, key, found);
|
||||
return entry;
|
||||
#else
|
||||
return hash_search(shared_hash, key, HASH_ENTER_NULL, found);
|
||||
#endif
|
||||
}
|
||||
|
||||
void *
|
||||
pgsm_hash_find(PGSM_HASH_TABLE * shared_hash, pgsmHashKey *key, bool *found)
|
||||
{
|
||||
#if USE_DYNAMIC_HASH
|
||||
return dshash_find(shared_hash, key, false);
|
||||
#else
|
||||
return hash_search(shared_hash, key, HASH_FIND, found);
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
pgsm_hash_seq_init(PGSM_HASH_SEQ_STATUS * hstat, PGSM_HASH_TABLE * shared_hash, bool lock)
|
||||
{
|
||||
#if USE_DYNAMIC_HASH
|
||||
dshash_seq_init(hstat, shared_hash, lock);
|
||||
#else
|
||||
hash_seq_init(hstat, shared_hash);
|
||||
#endif
|
||||
}
|
||||
|
||||
void *
|
||||
pgsm_hash_seq_next(PGSM_HASH_SEQ_STATUS * hstat)
|
||||
{
|
||||
#if USE_DYNAMIC_HASH
|
||||
return dshash_seq_next(hstat);
|
||||
#else
|
||||
return hash_seq_search(hstat);
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
pgsm_hash_seq_term(PGSM_HASH_SEQ_STATUS * hstat)
|
||||
{
|
||||
#if USE_DYNAMIC_HASH
|
||||
dshash_seq_term(hstat);
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
pgsm_hash_delete_current(PGSM_HASH_SEQ_STATUS * hstat, PGSM_HASH_TABLE * shared_hash, void *key)
|
||||
{
|
||||
#if USE_DYNAMIC_HASH
|
||||
dshash_delete_current(hstat);
|
||||
#else
|
||||
hash_search(shared_hash, key, HASH_REMOVE, NULL);
|
||||
#endif
|
||||
return (pgss != NULL &&
|
||||
pgss_hash != NULL);
|
||||
}
|
||||
|
|
|
|||
61
meson.build
61
meson.build
|
|
@ -1,61 +0,0 @@
|
|||
# Copyright (c) 2022-2023, PostgreSQL Global Development Group
|
||||
|
||||
pg_stat_monitor_sources = files(
|
||||
'pg_stat_monitor.c',
|
||||
)
|
||||
|
||||
pg_stat_monitor = shared_module('pg_stat_monitor',
|
||||
pg_stat_monitor_sources,
|
||||
kwargs: contrib_mod_args + {
|
||||
'dependencies': contrib_mod_args['dependencies'],
|
||||
},
|
||||
)
|
||||
contrib_targets += pg_stat_monitor
|
||||
|
||||
install_data(
|
||||
'pg_stat_monitor.control',
|
||||
'pg_stat_monitor--2.0.sql',
|
||||
'pg_stat_monitor--1.0--2.0.sql',
|
||||
'pg_stat_monitor--2.0--2.1.sql',
|
||||
'pg_stat_monitor--2.1--2.2.sql',
|
||||
'pg_stat_monitor--2.2--2.3.sql',
|
||||
kwargs: contrib_data_args,
|
||||
)
|
||||
|
||||
tests += {
|
||||
'name': 'pg_stat_monitor',
|
||||
'sd': meson.current_source_dir(),
|
||||
'bd': meson.current_build_dir(),
|
||||
'regress': {
|
||||
'sql': [
|
||||
'application_name',
|
||||
'application_name_unique',
|
||||
'basic',
|
||||
'cmd_type',
|
||||
'counters',
|
||||
'database',
|
||||
'different_parent_queries'
|
||||
'error_insert',
|
||||
'error',
|
||||
'functions',
|
||||
'guc',
|
||||
'histogram',
|
||||
'level_tracking'
|
||||
'parallel',
|
||||
'pgsqm_query_id',
|
||||
'relations',
|
||||
'rows',
|
||||
'squashing',
|
||||
'state',
|
||||
'tags',
|
||||
'top_query',
|
||||
'user',
|
||||
'version'
|
||||
],
|
||||
'regress_args': ['--temp-config', files('pg_stat_monitor.conf')],
|
||||
# Disabled because these tests require
|
||||
# "shared_preload_libraries=pg_stat_monitor", which typical
|
||||
# runningcheck users do not have (e.g. buildfarm clients).
|
||||
'runningcheck': false,
|
||||
},
|
||||
}
|
||||
|
|
@ -0,0 +1,101 @@
|
|||
# MkDocs configuration for Netlify builds
|
||||
|
||||
site_name: pg_stat_monitor Documentation
|
||||
site_description: Documentation
|
||||
site_author: Percona LLC
|
||||
copyright: Percona LLC, © 2022
|
||||
|
||||
repo_name: percona/pg_stat_monitor
|
||||
repo_url: https://github.com/percona/pg_stat_monitor
|
||||
edit_uri: edit/master/docs/
|
||||
|
||||
use_directory_urls: false
|
||||
|
||||
# Theme for netlify testing
|
||||
theme:
|
||||
name: material
|
||||
logo: _images/percona-logo.svg
|
||||
favicon: _images/percona-favicon.ico
|
||||
custom_dir: docs/overrides
|
||||
|
||||
palette:
|
||||
|
||||
# Light mode
|
||||
- media: "(prefers-color-scheme: light)"
|
||||
scheme: percona-light
|
||||
toggle:
|
||||
icon: material/toggle-switch-off-outline
|
||||
name: Switch to dark mode
|
||||
|
||||
# Dark mode
|
||||
- media: "(prefers-color-scheme: dark)"
|
||||
scheme: slate
|
||||
toggle:
|
||||
icon: material/toggle-switch
|
||||
name: Switch to light mode
|
||||
|
||||
# Theme features
|
||||
|
||||
features:
|
||||
- search.highlight
|
||||
- navigation.top
|
||||
|
||||
|
||||
extra_css:
|
||||
- https://unicons.iconscout.com/release/v3.0.3/css/line.css
|
||||
- https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.4.0/css/font-awesome.min.css
|
||||
- css/version-select.css
|
||||
- css/toctree.css
|
||||
- css/percona.css
|
||||
|
||||
extra_javascript:
|
||||
- js/version-select.js
|
||||
|
||||
markdown_extensions:
|
||||
- attr_list
|
||||
- toc:
|
||||
permalink: True
|
||||
- admonition
|
||||
- footnotes
|
||||
- def_list # https://michelf.ca/projects/php-markdown/extra/#def-list
|
||||
- meta
|
||||
- smarty:
|
||||
smart_angled_quotes: true
|
||||
- pymdownx.mark
|
||||
- pymdownx.smartsymbols
|
||||
- pymdownx.tabbed
|
||||
- pymdownx.tilde
|
||||
- pymdownx.superfences
|
||||
- pymdownx.highlight:
|
||||
linenums: false
|
||||
- pymdownx.emoji:
|
||||
emoji_index: !!python/name:materialx.emoji.twemoji
|
||||
emoji_generator: !!python/name:materialx.emoji.to_svg
|
||||
#- plantuml_markdown
|
||||
|
||||
plugins:
|
||||
- search
|
||||
- git-revision-date
|
||||
- section-index # Adds links to nodes - comment out when creating PDF
|
||||
# - htmlproofer # Uncomment to check links - but extends build time significantly
|
||||
- mike:
|
||||
version_selector: true
|
||||
css_dir: css
|
||||
javascript_dir: js
|
||||
canonical_version: null
|
||||
|
||||
|
||||
extra:
|
||||
version:
|
||||
provider: mike
|
||||
|
||||
nav:
|
||||
- index.md
|
||||
- setup.md
|
||||
- User guide:
|
||||
- USER_GUIDE.md
|
||||
- REFERENCE.md
|
||||
- COMPARISON.md
|
||||
- Release notes:
|
||||
- RELEASE_NOTES.md
|
||||
# - Version Selector: "../"
|
||||
|
|
@ -21,7 +21,6 @@ Usage: $0 [OPTIONS]
|
|||
--rpm_release RPM version( default = 1)
|
||||
--deb_release DEB version( default = 1)
|
||||
--pg_release PPG version build on( default = 11)
|
||||
--ppg_repo_name PPG repo name (default ppg-11.18)
|
||||
--version product version
|
||||
--help) usage ;;
|
||||
Example $0 --builddir=/tmp/test --get_sources=1 --build_src_rpm=1 --build_rpm=1
|
||||
|
|
@ -58,7 +57,6 @@ append_arg_to_args () {
|
|||
--rpm_release=*) RPM_RELEASE="$val" ;;
|
||||
--deb_release=*) DEB_RELEASE="$val" ;;
|
||||
--pg_release=*) PG_RELEASE="$val" ;;
|
||||
--ppg_repo_name=*) PPG_REPO_NAME="$val";;
|
||||
--version=*) VERSION="$val" ;;
|
||||
--help) usage ;;
|
||||
*)
|
||||
|
|
@ -86,6 +84,14 @@ check_workdir(){
|
|||
return
|
||||
}
|
||||
|
||||
add_percona_yum_repo(){
|
||||
if [ ! -f /etc/yum.repos.d/percona-dev.repo ]; then
|
||||
curl -o /etc/yum.repos.d/percona-dev.repo https://jenkins.percona.com/yum-repo/percona-dev.repo
|
||||
sed -i 's:$basearch:x86_64:g' /etc/yum.repos.d/percona-dev.repo
|
||||
fi
|
||||
return
|
||||
}
|
||||
|
||||
set_changelog(){
|
||||
if [ -z $1 ]
|
||||
then
|
||||
|
|
@ -117,10 +123,6 @@ get_sources(){
|
|||
echo "Sources will not be downloaded"
|
||||
return 0
|
||||
fi
|
||||
IS_RELEASE_BRANCH=$(echo ${VERSION} | grep -c release)
|
||||
if [ ${IS_RELEASE_BRANCH} != 0 ]; then
|
||||
VERSION=$(echo $VERSION | awk -F'-' '{print $2}')
|
||||
fi
|
||||
PRODUCT=percona-pg-stat-monitor${PG_RELEASE}
|
||||
PRODUCT_FULL=${PRODUCT}-${VERSION}
|
||||
|
||||
|
|
@ -166,8 +168,7 @@ get_sources(){
|
|||
source pg-stat-monitor.properties
|
||||
#
|
||||
tar --owner=0 --group=0 --exclude=.* -czf ${PRODUCT_FULL}.tar.gz ${PRODUCT_FULL}
|
||||
DATE_TIMESTAMP=$(date +%F_%H-%M-%S)
|
||||
echo "UPLOAD=UPLOAD/experimental/BUILDS/${PRODUCT}/${PRODUCT_FULL}/${BRANCH}/${REVISION}/${DATE_TIMESTAMP}/${BUILD_ID}" >> pg-stat-monitor.properties
|
||||
echo "UPLOAD=UPLOAD/experimental/BUILDS/${PRODUCT}/${PRODUCT_FULL}/${BRANCH}/${REVISION}/${BUILD_ID}" >> pg-stat-monitor.properties
|
||||
mkdir $WORKDIR/source_tarball
|
||||
mkdir $CURDIR/source_tarball
|
||||
cp ${PRODUCT_FULL}.tar.gz $WORKDIR/source_tarball
|
||||
|
|
@ -207,27 +208,20 @@ install_deps() {
|
|||
CURPLACE=$(pwd)
|
||||
if [ "$OS" == "rpm" ]
|
||||
then
|
||||
yum -y install git wget
|
||||
yum install -y https://repo.percona.com/yum/percona-release-latest.noarch.rpm
|
||||
percona-release enable ${PPG_REPO_NAME} testing
|
||||
|
||||
if [ x"$RHEL" = x8 ];
|
||||
then
|
||||
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
|
||||
add_percona_yum_repo
|
||||
if [[ ${PG_RELEASE} == "11" ]]; then
|
||||
percona-release enable ppg-11 release
|
||||
elif [[ $PG_RELEASE == "12" ]]; then
|
||||
percona-release enable ppg-12 release
|
||||
fi
|
||||
|
||||
PKGLIST="percona-postgresql${PG_RELEASE}-devel"
|
||||
PKGLIST+=" git rpmdevtools vim wget"
|
||||
yum -y install git wget
|
||||
PKGLIST="percona-postgresql-common percona-postgresql${PG_RELEASE}-devel"
|
||||
PKGLIST+=" clang-devel git clang llvm-devel rpmdevtools vim wget"
|
||||
PKGLIST+=" perl binutils gcc gcc-c++"
|
||||
PKGLIST+=" git rpm-build rpmdevtools wget gcc make autoconf"
|
||||
if [[ "${RHEL}" -ge 8 ]]; then
|
||||
dnf config-manager --set-enabled ol${RHEL}_codeready_builder
|
||||
dnf -y module disable postgresql || true
|
||||
PKGLIST+=" clang-devel llvm-devel git rpm-build rpmdevtools wget gcc make autoconf"
|
||||
if [[ "${RHEL}" -eq 8 ]]; then
|
||||
dnf -y module disable postgresql
|
||||
elif [[ "${RHEL}" -eq 7 ]]; then
|
||||
PKGLIST+=" llvm-toolset-7-clang llvm-toolset-7-llvm-devel llvm5.0-devel"
|
||||
until yum -y install epel-release centos-release-scl; do
|
||||
|
|
@ -247,29 +241,37 @@ install_deps() {
|
|||
done
|
||||
else
|
||||
apt-get update
|
||||
DEBIAN_FRONTEND=noninteractive apt-get -y install lsb-release gnupg git wget curl
|
||||
export DEBIAN=$(lsb_release -sc)
|
||||
DEBIAN_FRONTEND=noninteractive apt-get -y install lsb-release gnupg git wget
|
||||
|
||||
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"
|
||||
apt-get update
|
||||
|
||||
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
|
||||
wget https://repo.percona.com/apt/percona-release_latest.$(lsb_release -sc)_all.deb && dpkg -i percona-release_latest.$(lsb_release -sc)_all.deb
|
||||
if [[ "${PG_RELEASE}" == "11" ]]; then
|
||||
percona-release enable ppg-11 release
|
||||
elif [[ "${PG_RELEASE}" == "12" ]]; then
|
||||
percona-release enable ppg-12 release
|
||||
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="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
|
||||
|
||||
PKGLIST+=" debconf debhelper clang-7 devscripts dh-exec dh-systemd git wget libkrb5-dev libssl-dev"
|
||||
PKGLIST+=" build-essential debconf debhelper devscripts dh-exec dh-systemd git wget libxml-checker-perl"
|
||||
PKGLIST+=" libxml-libxml-perl libio-socket-ssl-perl libperl-dev libssl-dev libxml2-dev txt2man zlib1g-dev libpq-dev"
|
||||
|
||||
until DEBIAN_FRONTEND=noninteractive apt-get -y install ${PKGLIST}; do
|
||||
|
|
@ -396,9 +398,6 @@ build_rpm(){
|
|||
fi
|
||||
export LIBPQ_DIR=/usr/pgsql-${PG_RELEASE}/
|
||||
export LIBRARY_PATH=/usr/pgsql-${PG_RELEASE}/lib/:/usr/pgsql-${PG_RELEASE}/include/
|
||||
if [[ "${RHEL}" -eq 10 ]]; then
|
||||
export QA_RPATHS=0x0002
|
||||
fi
|
||||
rpmbuild --define "_topdir ${WORKDIR}/rpmbuild" --define "dist .$OS_NAME" --define "version ${VERSION}" --rebuild rpmbuild/SRPMS/$SRC_RPM
|
||||
|
||||
return_code=$?
|
||||
|
|
@ -452,19 +451,6 @@ build_source_deb(){
|
|||
cp *.orig.tar.gz $CURDIR/source_deb
|
||||
}
|
||||
|
||||
change_ddeb_package_to_deb(){
|
||||
|
||||
directory=$1
|
||||
|
||||
for file in "$directory"/*.ddeb; do
|
||||
if [ -e "$file" ]; then
|
||||
# Change extension to .deb
|
||||
mv "$file" "${file%.ddeb}.deb"
|
||||
echo "Changed extension of $file to ${file%.ddeb}.deb"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
build_deb(){
|
||||
if [ $DEB = 0 ]
|
||||
then
|
||||
|
|
@ -496,13 +482,11 @@ build_deb(){
|
|||
sed -i "s:\. :${WORKDIR}/percona-pg-stat-monitor-${VERSION} :g" debian/rules
|
||||
dch -m -D "${OS_NAME}" --force-distribution -v "1:${VERSION}-${DEB_RELEASE}.${OS_NAME}" 'Update distribution'
|
||||
unset $(locale|cut -d= -f1)
|
||||
pg_buildext updatecontrol
|
||||
dpkg-buildpackage -rfakeroot -us -uc -b
|
||||
mkdir -p $CURDIR/deb
|
||||
mkdir -p $WORKDIR/deb
|
||||
cp $WORKDIR/*.*deb $WORKDIR/deb
|
||||
cp $WORKDIR/*.*deb $CURDIR/deb
|
||||
change_ddeb_package_to_deb "$CURDIR/deb"
|
||||
}
|
||||
|
||||
CURDIR=$(pwd)
|
||||
|
|
@ -526,7 +510,6 @@ DEB_RELEASE=1
|
|||
REPO="https://github.com/Percona/pg_stat_monitor.git"
|
||||
VERSION="1.0.0"
|
||||
PG_RELEASE=11
|
||||
PPG_REPO_NAME=ppg-11
|
||||
parse_arguments PICK-ARGS-FROM-ARGV "$@"
|
||||
|
||||
check_workdir
|
||||
|
|
|
|||
|
|
@ -1,415 +0,0 @@
|
|||
/* contrib/pg_stat_monitor/pg_stat_monitor--1.0--2.0.sql */
|
||||
|
||||
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
|
||||
\echo Use "ALTER EXTENSION pg_stat_monitor" to load this file. \quit
|
||||
|
||||
DROP FUNCTION pg_stat_monitor_internal CASCADE;
|
||||
DROP FUNCTION histogram;
|
||||
DROP FUNCTION get_state;
|
||||
DROP FUNCTION pg_stat_monitor_settings CASCADE;
|
||||
|
||||
CREATE FUNCTION pg_stat_monitor_internal(
|
||||
IN showtext boolean,
|
||||
OUT bucket int8, -- 0
|
||||
OUT userid oid,
|
||||
OUT username text,
|
||||
OUT dbid oid,
|
||||
OUT datname text,
|
||||
OUT client_ip int8,
|
||||
|
||||
OUT queryid int8, -- 4
|
||||
OUT planid int8,
|
||||
OUT query text,
|
||||
OUT query_plan text,
|
||||
OUT pgsm_query_id int8,
|
||||
OUT top_queryid int8,
|
||||
OUT top_query text,
|
||||
OUT application_name text,
|
||||
|
||||
OUT relations text, -- 11
|
||||
OUT cmd_type int,
|
||||
OUT elevel int,
|
||||
OUT sqlcode TEXT,
|
||||
OUT message text,
|
||||
OUT bucket_start_time timestamptz,
|
||||
|
||||
OUT calls int8, -- 16
|
||||
|
||||
OUT total_exec_time float8,
|
||||
OUT min_exec_time float8,
|
||||
OUT max_exec_time float8,
|
||||
OUT mean_exec_time float8,
|
||||
OUT stddev_exec_time float8,
|
||||
|
||||
OUT rows int8,
|
||||
|
||||
OUT plans int8, -- 23
|
||||
|
||||
OUT total_plan_time float8,
|
||||
OUT min_plan_time float8,
|
||||
OUT max_plan_time float8,
|
||||
OUT mean_plan_time float8,
|
||||
OUT stddev_plan_time float8,
|
||||
|
||||
OUT shared_blks_hit int8, -- 29
|
||||
OUT shared_blks_read int8,
|
||||
OUT shared_blks_dirtied int8,
|
||||
OUT shared_blks_written int8,
|
||||
OUT local_blks_hit int8,
|
||||
OUT local_blks_read int8,
|
||||
OUT local_blks_dirtied int8,
|
||||
OUT local_blks_written int8,
|
||||
OUT temp_blks_read int8,
|
||||
OUT temp_blks_written int8,
|
||||
OUT blk_read_time float8,
|
||||
OUT blk_write_time float8,
|
||||
|
||||
OUT temp_blk_read_time float8,
|
||||
OUT temp_blk_write_time float8,
|
||||
|
||||
OUT resp_calls text, -- 41
|
||||
OUT cpu_user_time float8,
|
||||
OUT cpu_sys_time float8,
|
||||
OUT wal_records int8,
|
||||
OUT wal_fpi int8,
|
||||
OUT wal_bytes numeric,
|
||||
OUT comments TEXT,
|
||||
|
||||
OUT jit_functions int8,
|
||||
OUT jit_generation_time float8,
|
||||
OUT jit_inlining_count int8,
|
||||
OUT jit_inlining_time float8,
|
||||
OUT jit_optimization_count int8,
|
||||
OUT jit_optimization_time float8,
|
||||
OUT jit_emission_count int8,
|
||||
OUT jit_emission_time float8,
|
||||
|
||||
OUT toplevel BOOLEAN,
|
||||
OUT bucket_done BOOLEAN
|
||||
)
|
||||
RETURNS SETOF record
|
||||
AS 'MODULE_PATHNAME', 'pg_stat_monitor_2_0'
|
||||
LANGUAGE C STRICT VOLATILE PARALLEL SAFE;
|
||||
|
||||
CREATE FUNCTION histogram(_bucket int, _quryid int8)
|
||||
RETURNS SETOF RECORD AS $$
|
||||
DECLARE
|
||||
rec record;
|
||||
BEGIN
|
||||
FOR rec IN
|
||||
WITH stat AS (select queryid, bucket, unnest(range()) AS range,
|
||||
unnest(resp_calls)::int freq FROM pg_stat_monitor) select range,
|
||||
freq, repeat('â– ', (freq::float / max(freq) over() * 30)::int) AS bar
|
||||
FROM stat WHERE queryid = _quryid and bucket = _bucket
|
||||
LOOP
|
||||
RETURN next rec;
|
||||
END loop;
|
||||
END
|
||||
$$ language plpgsql;
|
||||
|
||||
-- Register a view on the function for ease of use.
|
||||
CREATE FUNCTION pgsm_create_11_view() RETURNS INT AS
|
||||
$$
|
||||
BEGIN
|
||||
CREATE VIEW pg_stat_monitor AS SELECT
|
||||
bucket,
|
||||
bucket_start_time AS bucket_start_time,
|
||||
userid,
|
||||
username,
|
||||
dbid,
|
||||
datname,
|
||||
'0.0.0.0'::inet + client_ip AS client_ip,
|
||||
pgsm_query_id,
|
||||
queryid,
|
||||
top_queryid,
|
||||
query,
|
||||
comments,
|
||||
planid,
|
||||
query_plan,
|
||||
top_query,
|
||||
application_name,
|
||||
string_to_array(relations, ',') AS relations,
|
||||
cmd_type,
|
||||
get_cmd_type(cmd_type) AS cmd_type_text,
|
||||
elevel,
|
||||
sqlcode,
|
||||
message,
|
||||
calls,
|
||||
total_exec_time AS total_time,
|
||||
min_exec_time AS min_time,
|
||||
max_exec_time AS max_time,
|
||||
mean_exec_time AS mean_time,
|
||||
stddev_exec_time AS stddev_time,
|
||||
rows,
|
||||
shared_blks_hit,
|
||||
shared_blks_read,
|
||||
shared_blks_dirtied,
|
||||
shared_blks_written,
|
||||
local_blks_hit,
|
||||
local_blks_read,
|
||||
local_blks_dirtied,
|
||||
local_blks_written,
|
||||
temp_blks_read,
|
||||
temp_blks_written,
|
||||
blk_read_time,
|
||||
blk_write_time,
|
||||
(string_to_array(resp_calls, ',')) resp_calls,
|
||||
cpu_user_time,
|
||||
cpu_sys_time,
|
||||
bucket_done
|
||||
FROM pg_stat_monitor_internal(TRUE)
|
||||
ORDER BY bucket_start_time;
|
||||
RETURN 0;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
|
||||
CREATE FUNCTION pgsm_create_13_view() RETURNS INT AS
|
||||
$$
|
||||
BEGIN
|
||||
CREATE VIEW pg_stat_monitor AS SELECT
|
||||
bucket,
|
||||
bucket_start_time AS bucket_start_time,
|
||||
userid,
|
||||
username,
|
||||
dbid,
|
||||
datname,
|
||||
'0.0.0.0'::inet + client_ip AS client_ip,
|
||||
pgsm_query_id,
|
||||
queryid,
|
||||
toplevel,
|
||||
top_queryid,
|
||||
query,
|
||||
comments,
|
||||
planid,
|
||||
query_plan,
|
||||
top_query,
|
||||
application_name,
|
||||
string_to_array(relations, ',') AS relations,
|
||||
cmd_type,
|
||||
get_cmd_type(cmd_type) AS cmd_type_text,
|
||||
elevel,
|
||||
sqlcode,
|
||||
message,
|
||||
calls,
|
||||
total_exec_time,
|
||||
min_exec_time,
|
||||
max_exec_time,
|
||||
mean_exec_time,
|
||||
stddev_exec_time,
|
||||
rows,
|
||||
shared_blks_hit,
|
||||
shared_blks_read,
|
||||
shared_blks_dirtied,
|
||||
shared_blks_written,
|
||||
local_blks_hit,
|
||||
local_blks_read,
|
||||
local_blks_dirtied,
|
||||
local_blks_written,
|
||||
temp_blks_read,
|
||||
temp_blks_written,
|
||||
blk_read_time,
|
||||
blk_write_time,
|
||||
(string_to_array(resp_calls, ',')) resp_calls,
|
||||
cpu_user_time,
|
||||
cpu_sys_time,
|
||||
wal_records,
|
||||
wal_fpi,
|
||||
wal_bytes,
|
||||
bucket_done,
|
||||
-- PostgreSQL-13 Specific Coulumns
|
||||
plans,
|
||||
total_plan_time,
|
||||
min_plan_time,
|
||||
max_plan_time,
|
||||
mean_plan_time,
|
||||
stddev_plan_time
|
||||
FROM pg_stat_monitor_internal(TRUE)
|
||||
ORDER BY bucket_start_time;
|
||||
RETURN 0;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
CREATE FUNCTION pgsm_create_14_view() RETURNS INT AS
|
||||
$$
|
||||
BEGIN
|
||||
CREATE VIEW pg_stat_monitor AS SELECT
|
||||
bucket,
|
||||
bucket_start_time AS bucket_start_time,
|
||||
userid,
|
||||
username,
|
||||
dbid,
|
||||
datname,
|
||||
'0.0.0.0'::inet + client_ip AS client_ip,
|
||||
pgsm_query_id,
|
||||
queryid,
|
||||
toplevel,
|
||||
top_queryid,
|
||||
query,
|
||||
comments,
|
||||
planid,
|
||||
query_plan,
|
||||
top_query,
|
||||
application_name,
|
||||
string_to_array(relations, ',') AS relations,
|
||||
cmd_type,
|
||||
get_cmd_type(cmd_type) AS cmd_type_text,
|
||||
elevel,
|
||||
sqlcode,
|
||||
message,
|
||||
calls,
|
||||
total_exec_time,
|
||||
min_exec_time,
|
||||
max_exec_time,
|
||||
mean_exec_time,
|
||||
stddev_exec_time,
|
||||
rows,
|
||||
shared_blks_hit,
|
||||
shared_blks_read,
|
||||
shared_blks_dirtied,
|
||||
shared_blks_written,
|
||||
local_blks_hit,
|
||||
local_blks_read,
|
||||
local_blks_dirtied,
|
||||
local_blks_written,
|
||||
temp_blks_read,
|
||||
temp_blks_written,
|
||||
blk_read_time,
|
||||
blk_write_time,
|
||||
(string_to_array(resp_calls, ',')) resp_calls,
|
||||
cpu_user_time,
|
||||
cpu_sys_time,
|
||||
wal_records,
|
||||
wal_fpi,
|
||||
wal_bytes,
|
||||
bucket_done,
|
||||
|
||||
plans,
|
||||
total_plan_time,
|
||||
min_plan_time,
|
||||
max_plan_time,
|
||||
mean_plan_time,
|
||||
stddev_plan_time
|
||||
FROM pg_stat_monitor_internal(TRUE)
|
||||
ORDER BY bucket_start_time;
|
||||
RETURN 0;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
CREATE FUNCTION pgsm_create_15_view() RETURNS INT AS
|
||||
$$
|
||||
BEGIN
|
||||
CREATE VIEW pg_stat_monitor AS SELECT
|
||||
bucket,
|
||||
bucket_start_time AS bucket_start_time,
|
||||
userid,
|
||||
username,
|
||||
dbid,
|
||||
datname,
|
||||
'0.0.0.0'::inet + client_ip AS client_ip,
|
||||
pgsm_query_id,
|
||||
queryid,
|
||||
toplevel,
|
||||
top_queryid,
|
||||
query,
|
||||
comments,
|
||||
planid,
|
||||
query_plan,
|
||||
top_query,
|
||||
application_name,
|
||||
string_to_array(relations, ',') AS relations,
|
||||
cmd_type,
|
||||
get_cmd_type(cmd_type) AS cmd_type_text,
|
||||
elevel,
|
||||
sqlcode,
|
||||
message,
|
||||
calls,
|
||||
total_exec_time,
|
||||
min_exec_time,
|
||||
max_exec_time,
|
||||
mean_exec_time,
|
||||
stddev_exec_time,
|
||||
rows,
|
||||
shared_blks_hit,
|
||||
shared_blks_read,
|
||||
shared_blks_dirtied,
|
||||
shared_blks_written,
|
||||
local_blks_hit,
|
||||
local_blks_read,
|
||||
local_blks_dirtied,
|
||||
local_blks_written,
|
||||
temp_blks_read,
|
||||
temp_blks_written,
|
||||
blk_read_time,
|
||||
blk_write_time,
|
||||
temp_blk_read_time,
|
||||
temp_blk_write_time,
|
||||
|
||||
(string_to_array(resp_calls, ',')) resp_calls,
|
||||
cpu_user_time,
|
||||
cpu_sys_time,
|
||||
wal_records,
|
||||
wal_fpi,
|
||||
wal_bytes,
|
||||
bucket_done,
|
||||
|
||||
plans,
|
||||
total_plan_time,
|
||||
min_plan_time,
|
||||
max_plan_time,
|
||||
mean_plan_time,
|
||||
stddev_plan_time,
|
||||
|
||||
jit_functions,
|
||||
jit_generation_time,
|
||||
jit_inlining_count,
|
||||
jit_inlining_time,
|
||||
jit_optimization_count,
|
||||
jit_optimization_time,
|
||||
jit_emission_count,
|
||||
jit_emission_time
|
||||
|
||||
FROM pg_stat_monitor_internal(TRUE)
|
||||
ORDER BY bucket_start_time;
|
||||
RETURN 0;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
CREATE FUNCTION pgsm_create_view() RETURNS INT AS
|
||||
$$
|
||||
DECLARE ver integer;
|
||||
BEGIN
|
||||
SELECT current_setting('server_version_num') INTO ver;
|
||||
IF (ver >= 150000) THEN
|
||||
return pgsm_create_15_view();
|
||||
END IF;
|
||||
IF (ver >= 140000) THEN
|
||||
return pgsm_create_14_view();
|
||||
END IF;
|
||||
IF (ver >= 130000) THEN
|
||||
return pgsm_create_13_view();
|
||||
END IF;
|
||||
IF (ver >= 110000) THEN
|
||||
return pgsm_create_11_view();
|
||||
END IF;
|
||||
RETURN 0;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
SELECT pgsm_create_view();
|
||||
REVOKE ALL ON FUNCTION pgsm_create_view FROM PUBLIC;
|
||||
REVOKE ALL ON FUNCTION pgsm_create_11_view FROM PUBLIC;
|
||||
REVOKE ALL ON FUNCTION pgsm_create_13_view FROM PUBLIC;
|
||||
REVOKE ALL ON FUNCTION pgsm_create_14_view FROM PUBLIC;
|
||||
REVOKE ALL ON FUNCTION pgsm_create_15_view FROM PUBLIC;
|
||||
|
||||
GRANT EXECUTE ON FUNCTION range TO PUBLIC;
|
||||
GRANT EXECUTE ON FUNCTION decode_error_level TO PUBLIC;
|
||||
GRANT EXECUTE ON FUNCTION get_histogram_timings TO PUBLIC;
|
||||
GRANT EXECUTE ON FUNCTION get_cmd_type TO PUBLIC;
|
||||
GRANT EXECUTE ON FUNCTION pg_stat_monitor_internal TO PUBLIC;
|
||||
|
||||
GRANT SELECT ON pg_stat_monitor TO PUBLIC;
|
||||
|
||||
-- Reset is only available to super user
|
||||
REVOKE ALL ON FUNCTION pg_stat_monitor_reset FROM PUBLIC;
|
||||
|
|
@ -0,0 +1,266 @@
|
|||
/* contrib/pg_stat_monitor/pg_stat_monitor--1.0.sql */
|
||||
|
||||
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
|
||||
\echo Use "CREATE EXTENSION pg_stat_monitor" to load this file. \quit
|
||||
|
||||
-- Register functions.
|
||||
CREATE FUNCTION pg_stat_monitor_reset()
|
||||
RETURNS void
|
||||
AS 'MODULE_PATHNAME'
|
||||
LANGUAGE C PARALLEL SAFE;
|
||||
|
||||
CREATE FUNCTION pg_stat_monitor_version()
|
||||
RETURNS text
|
||||
AS 'MODULE_PATHNAME'
|
||||
LANGUAGE C PARALLEL SAFE;
|
||||
|
||||
CREATE FUNCTION get_histogram_timings()
|
||||
RETURNS text
|
||||
AS 'MODULE_PATHNAME'
|
||||
LANGUAGE C PARALLEL SAFE;
|
||||
|
||||
CREATE FUNCTION range()
|
||||
RETURNS text[] AS $$
|
||||
SELECT string_to_array(get_histogram_timings(), ',');
|
||||
$$ LANGUAGE SQL;
|
||||
|
||||
CREATE FUNCTION pg_stat_monitor_internal(IN showtext boolean,
|
||||
OUT bucket int8, -- 0
|
||||
OUT userid oid,
|
||||
OUT dbid oid,
|
||||
OUT client_ip int8,
|
||||
|
||||
OUT queryid text, -- 4
|
||||
OUT planid text,
|
||||
OUT query text,
|
||||
OUT query_plan text,
|
||||
OUT state_code int8,
|
||||
OUT top_queryid text,
|
||||
OUT top_query text,
|
||||
OUT application_name text,
|
||||
|
||||
OUT relations text, -- 11
|
||||
OUT cmd_type int,
|
||||
OUT elevel int,
|
||||
OUT sqlcode TEXT,
|
||||
OUT message text,
|
||||
OUT bucket_start_time text,
|
||||
|
||||
OUT calls int8, -- 16
|
||||
|
||||
OUT total_exec_time float8,
|
||||
OUT min_exec_time float8,
|
||||
OUT max_exec_time float8,
|
||||
OUT mean_exec_time float8,
|
||||
OUT stddev_exec_time float8,
|
||||
|
||||
OUT rows_retrieved int8,
|
||||
|
||||
OUT plans_calls int8, -- 23
|
||||
|
||||
OUT total_plan_time float8,
|
||||
OUT min_plan_time float8,
|
||||
OUT max_plan_time float8,
|
||||
OUT mean_plan_time float8,
|
||||
OUT stddev_plan_time float8,
|
||||
|
||||
OUT shared_blks_hit int8, -- 29
|
||||
OUT shared_blks_read int8,
|
||||
OUT shared_blks_dirtied int8,
|
||||
OUT shared_blks_written int8,
|
||||
OUT local_blks_hit int8,
|
||||
OUT local_blks_read int8,
|
||||
OUT local_blks_dirtied int8,
|
||||
OUT local_blks_written int8,
|
||||
OUT temp_blks_read int8,
|
||||
OUT temp_blks_written int8,
|
||||
OUT blk_read_time float8,
|
||||
OUT blk_write_time float8,
|
||||
OUT resp_calls text, -- 41
|
||||
OUT cpu_user_time float8,
|
||||
OUT cpu_sys_time float8,
|
||||
OUT wal_records int8,
|
||||
OUT wal_fpi int8,
|
||||
OUT wal_bytes numeric,
|
||||
OUT comments TEXT,
|
||||
OUT toplevel BOOLEAN
|
||||
)
|
||||
RETURNS SETOF record
|
||||
AS 'MODULE_PATHNAME', 'pg_stat_monitor'
|
||||
LANGUAGE C STRICT VOLATILE PARALLEL SAFE;
|
||||
|
||||
CREATE FUNCTION get_state(state_code int8) RETURNS TEXT AS
|
||||
$$
|
||||
SELECT
|
||||
CASE
|
||||
WHEN state_code = 0 THEN 'PARSING'
|
||||
WHEN state_code = 1 THEN 'PLANNING'
|
||||
WHEN state_code = 2 THEN 'ACTIVE'
|
||||
WHEN state_code = 3 THEN 'FINISHED'
|
||||
WHEN state_code = 4 THEN 'FINISHED WITH ERROR'
|
||||
END
|
||||
$$
|
||||
LANGUAGE SQL PARALLEL SAFE;
|
||||
|
||||
CREATE FUNCTION get_cmd_type (cmd_type INTEGER) RETURNS TEXT AS
|
||||
$$
|
||||
SELECT
|
||||
CASE
|
||||
WHEN cmd_type = 0 THEN ''
|
||||
WHEN cmd_type = 1 THEN 'SELECT'
|
||||
WHEN cmd_type = 2 THEN 'UPDATE'
|
||||
WHEN cmd_type = 3 THEN 'INSERT'
|
||||
WHEN cmd_type = 4 THEN 'DELETE'
|
||||
WHEN cmd_type = 5 THEN 'UTILITY'
|
||||
WHEN cmd_type = 6 THEN 'NOTHING'
|
||||
END
|
||||
$$
|
||||
LANGUAGE SQL PARALLEL SAFE;
|
||||
|
||||
CREATE FUNCTION pg_stat_monitor_settings(
|
||||
OUT name text,
|
||||
OUT value text,
|
||||
OUT default_value text,
|
||||
OUT description text,
|
||||
OUT minimum INTEGER,
|
||||
OUT maximum INTEGER,
|
||||
OUT options text,
|
||||
OUT restart text
|
||||
)
|
||||
RETURNS SETOF record
|
||||
AS 'MODULE_PATHNAME', 'pg_stat_monitor_settings'
|
||||
LANGUAGE C STRICT VOLATILE PARALLEL SAFE;
|
||||
|
||||
CREATE VIEW pg_stat_monitor_settings AS SELECT
|
||||
name,
|
||||
value,
|
||||
default_value,
|
||||
description,
|
||||
minimum,
|
||||
maximum,
|
||||
options,
|
||||
restart
|
||||
FROM pg_stat_monitor_settings();
|
||||
|
||||
-- Register a view on the function for ease of use.
|
||||
CREATE VIEW pg_stat_monitor AS SELECT
|
||||
bucket,
|
||||
bucket_start_time AS bucket_start_time,
|
||||
userid::regrole,
|
||||
datname,
|
||||
'0.0.0.0'::inet + client_ip AS client_ip,
|
||||
queryid,
|
||||
top_queryid,
|
||||
query,
|
||||
comments,
|
||||
planid,
|
||||
query_plan,
|
||||
top_query,
|
||||
application_name,
|
||||
string_to_array(relations, ',') AS relations,
|
||||
cmd_type,
|
||||
get_cmd_type(cmd_type) AS cmd_type_text,
|
||||
elevel,
|
||||
sqlcode,
|
||||
message,
|
||||
calls,
|
||||
total_exec_time,
|
||||
min_exec_time,
|
||||
max_exec_time,
|
||||
mean_exec_time,
|
||||
stddev_exec_time,
|
||||
|
||||
rows_retrieved,
|
||||
|
||||
plans_calls,
|
||||
|
||||
total_plan_time,
|
||||
min_plan_time,
|
||||
max_plan_time,
|
||||
mean_plan_time,
|
||||
stddev_plan_time,
|
||||
|
||||
shared_blks_hit,
|
||||
shared_blks_read,
|
||||
shared_blks_dirtied,
|
||||
shared_blks_written,
|
||||
local_blks_hit,
|
||||
local_blks_read,
|
||||
local_blks_dirtied,
|
||||
local_blks_written,
|
||||
temp_blks_read,
|
||||
temp_blks_written,
|
||||
blk_read_time,
|
||||
blk_write_time,
|
||||
(string_to_array(resp_calls, ',')) resp_calls,
|
||||
cpu_user_time,
|
||||
cpu_sys_time,
|
||||
wal_records,
|
||||
wal_fpi,
|
||||
wal_bytes,
|
||||
state_code,
|
||||
get_state(state_code) as state
|
||||
FROM pg_stat_monitor_internal(TRUE) p, pg_database d WHERE dbid = oid
|
||||
ORDER BY bucket_start_time;
|
||||
|
||||
CREATE FUNCTION decode_error_level(elevel int)
|
||||
RETURNS text
|
||||
AS
|
||||
$$
|
||||
SELECT
|
||||
CASE
|
||||
WHEN elevel = 0 THEN ''
|
||||
WHEN elevel = 10 THEN 'DEBUG5'
|
||||
WHEN elevel = 11 THEN 'DEBUG4'
|
||||
WHEN elevel = 12 THEN 'DEBUG3'
|
||||
WHEN elevel = 13 THEN 'DEBUG2'
|
||||
WHEN elevel = 14 THEN 'DEBUG1'
|
||||
WHEN elevel = 15 THEN 'LOG'
|
||||
WHEN elevel = 16 THEN 'LOG_SERVER_ONLY'
|
||||
WHEN elevel = 17 THEN 'INFO'
|
||||
WHEN elevel = 18 THEN 'NOTICE'
|
||||
WHEN elevel = 19 THEN 'WARNING'
|
||||
WHEN elevel = 20 THEN 'ERROR'
|
||||
END
|
||||
$$
|
||||
LANGUAGE SQL PARALLEL SAFE;
|
||||
|
||||
CREATE FUNCTION histogram(_bucket int, _quryid text)
|
||||
RETURNS SETOF RECORD AS $$
|
||||
DECLARE
|
||||
rec record;
|
||||
BEGIN
|
||||
for rec in
|
||||
with stat as (select queryid, bucket, unnest(range()) as range, unnest(resp_calls)::int freq from pg_stat_monitor) select range, freq, repeat('â– ', (freq::float / max(freq) over() * 30)::int) as bar from stat where queryid = _quryid and bucket = _bucket
|
||||
loop
|
||||
return next rec;
|
||||
end loop;
|
||||
END
|
||||
$$ language plpgsql;
|
||||
|
||||
--CREATE FUNCTION pg_stat_monitor_hook_stats(
|
||||
-- OUT hook text,
|
||||
-- OUT min_time float8,
|
||||
-- OUT max_time float8,
|
||||
-- OUT total_time float8,
|
||||
-- OUT ncalls int8
|
||||
--)
|
||||
--RETURNS SETOF record
|
||||
--AS 'MODULE_PATHNAME', 'pg_stat_monitor_hook_stats'
|
||||
--LANGUAGE C STRICT VOLATILE PARALLEL SAFE;
|
||||
|
||||
--CREATE VIEW pg_stat_monitor_hook_stats AS SELECT
|
||||
-- hook,
|
||||
-- min_time,
|
||||
-- max_time,
|
||||
-- total_time,
|
||||
-- total_time / greatest(ncalls, 1) as avg_time,
|
||||
-- ncalls,
|
||||
-- ROUND(CAST(total_time / greatest(sum(total_time) OVER(), 0.00000001) * 100 as numeric), 2)::text || '%' as load_comparison
|
||||
-- FROM pg_stat_monitor_hook_stats();
|
||||
|
||||
GRANT SELECT ON pg_stat_monitor TO PUBLIC;
|
||||
GRANT SELECT ON pg_stat_monitor_settings TO PUBLIC;
|
||||
|
||||
-- Don't want this to be available to non-superusers.
|
||||
REVOKE ALL ON FUNCTION pg_stat_monitor_reset() FROM PUBLIC;
|
||||
|
|
@ -0,0 +1,267 @@
|
|||
/* contrib/pg_stat_monitor/pg_stat_monitor--1.0.sql */
|
||||
|
||||
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
|
||||
\echo Use "CREATE EXTENSION pg_stat_monitor" to load this file. \quit
|
||||
|
||||
-- Register functions.
|
||||
CREATE FUNCTION pg_stat_monitor_reset()
|
||||
RETURNS void
|
||||
AS 'MODULE_PATHNAME'
|
||||
LANGUAGE C PARALLEL SAFE;
|
||||
|
||||
CREATE FUNCTION pg_stat_monitor_version()
|
||||
RETURNS text
|
||||
AS 'MODULE_PATHNAME'
|
||||
LANGUAGE C PARALLEL SAFE;
|
||||
|
||||
CREATE FUNCTION get_histogram_timings()
|
||||
RETURNS text
|
||||
AS 'MODULE_PATHNAME'
|
||||
LANGUAGE C PARALLEL SAFE;
|
||||
|
||||
CREATE FUNCTION range()
|
||||
RETURNS text[] AS $$
|
||||
SELECT string_to_array(get_histogram_timings(), ',');
|
||||
$$ LANGUAGE SQL;
|
||||
|
||||
CREATE FUNCTION pg_stat_monitor_internal(IN showtext boolean,
|
||||
OUT bucket int8, -- 0
|
||||
OUT userid oid,
|
||||
OUT dbid oid,
|
||||
OUT client_ip int8,
|
||||
|
||||
OUT queryid text, -- 4
|
||||
OUT planid text,
|
||||
OUT query text,
|
||||
OUT query_plan text,
|
||||
OUT state_code int8,
|
||||
OUT top_queryid text,
|
||||
OUT top_query text,
|
||||
OUT application_name text,
|
||||
|
||||
OUT relations text, -- 11
|
||||
OUT cmd_type int,
|
||||
OUT elevel int,
|
||||
OUT sqlcode TEXT,
|
||||
OUT message text,
|
||||
OUT bucket_start_time text,
|
||||
|
||||
OUT calls int8, -- 16
|
||||
|
||||
OUT total_exec_time float8,
|
||||
OUT min_exec_time float8,
|
||||
OUT max_exec_time float8,
|
||||
OUT mean_exec_time float8,
|
||||
OUT stddev_exec_time float8,
|
||||
|
||||
OUT rows_retrieved int8,
|
||||
|
||||
OUT plans_calls int8, -- 23
|
||||
|
||||
OUT total_plan_time float8,
|
||||
OUT min_plan_time float8,
|
||||
OUT max_plan_time float8,
|
||||
OUT mean_plan_time float8,
|
||||
OUT stddev_plan_time float8,
|
||||
|
||||
OUT shared_blks_hit int8, -- 29
|
||||
OUT shared_blks_read int8,
|
||||
OUT shared_blks_dirtied int8,
|
||||
OUT shared_blks_written int8,
|
||||
OUT local_blks_hit int8,
|
||||
OUT local_blks_read int8,
|
||||
OUT local_blks_dirtied int8,
|
||||
OUT local_blks_written int8,
|
||||
OUT temp_blks_read int8,
|
||||
OUT temp_blks_written int8,
|
||||
OUT blk_read_time float8,
|
||||
OUT blk_write_time float8,
|
||||
OUT resp_calls text, -- 41
|
||||
OUT cpu_user_time float8,
|
||||
OUT cpu_sys_time float8,
|
||||
OUT wal_records int8,
|
||||
OUT wal_fpi int8,
|
||||
OUT wal_bytes numeric,
|
||||
OUT comments TEXT,
|
||||
OUT toplevel BOOLEAN
|
||||
)
|
||||
RETURNS SETOF record
|
||||
AS 'MODULE_PATHNAME', 'pg_stat_monitor'
|
||||
LANGUAGE C STRICT VOLATILE PARALLEL SAFE;
|
||||
|
||||
CREATE FUNCTION get_state(state_code int8) RETURNS TEXT AS
|
||||
$$
|
||||
SELECT
|
||||
CASE
|
||||
WHEN state_code = 0 THEN 'PARSING'
|
||||
WHEN state_code = 1 THEN 'PLANNING'
|
||||
WHEN state_code = 2 THEN 'ACTIVE'
|
||||
WHEN state_code = 3 THEN 'FINISHED'
|
||||
WHEN state_code = 4 THEN 'FINISHED WITH ERROR'
|
||||
END
|
||||
$$
|
||||
LANGUAGE SQL PARALLEL SAFE;
|
||||
|
||||
CREATE FUNCTION get_cmd_type (cmd_type INTEGER) RETURNS TEXT AS
|
||||
$$
|
||||
SELECT
|
||||
CASE
|
||||
WHEN cmd_type = 0 THEN ''
|
||||
WHEN cmd_type = 1 THEN 'SELECT'
|
||||
WHEN cmd_type = 2 THEN 'UPDATE'
|
||||
WHEN cmd_type = 3 THEN 'INSERT'
|
||||
WHEN cmd_type = 4 THEN 'DELETE'
|
||||
WHEN cmd_type = 5 THEN 'UTILITY'
|
||||
WHEN cmd_type = 6 THEN 'NOTHING'
|
||||
END
|
||||
$$
|
||||
LANGUAGE SQL PARALLEL SAFE;
|
||||
|
||||
CREATE FUNCTION pg_stat_monitor_settings(
|
||||
OUT name text,
|
||||
OUT value text,
|
||||
OUT default_value text,
|
||||
OUT description text,
|
||||
OUT minimum INTEGER,
|
||||
OUT maximum INTEGER,
|
||||
OUT options text,
|
||||
OUT restart text
|
||||
)
|
||||
RETURNS SETOF record
|
||||
AS 'MODULE_PATHNAME', 'pg_stat_monitor_settings'
|
||||
LANGUAGE C STRICT VOLATILE PARALLEL SAFE;
|
||||
|
||||
CREATE VIEW pg_stat_monitor_settings AS SELECT
|
||||
name,
|
||||
value,
|
||||
default_value,
|
||||
description,
|
||||
minimum,
|
||||
maximum,
|
||||
options,
|
||||
restart
|
||||
FROM pg_stat_monitor_settings();
|
||||
|
||||
-- Register a view on the function for ease of use.
|
||||
CREATE VIEW pg_stat_monitor AS SELECT
|
||||
bucket,
|
||||
bucket_start_time AS bucket_start_time,
|
||||
userid::regrole,
|
||||
datname,
|
||||
'0.0.0.0'::inet + client_ip AS client_ip,
|
||||
queryid,
|
||||
toplevel,
|
||||
top_queryid,
|
||||
query,
|
||||
comments,
|
||||
planid,
|
||||
query_plan,
|
||||
top_query,
|
||||
application_name,
|
||||
string_to_array(relations, ',') AS relations,
|
||||
cmd_type,
|
||||
get_cmd_type(cmd_type) AS cmd_type_text,
|
||||
elevel,
|
||||
sqlcode,
|
||||
message,
|
||||
calls,
|
||||
total_exec_time,
|
||||
min_exec_time,
|
||||
max_exec_time,
|
||||
mean_exec_time,
|
||||
stddev_exec_time,
|
||||
|
||||
rows_retrieved,
|
||||
|
||||
plans_calls,
|
||||
|
||||
total_plan_time,
|
||||
min_plan_time,
|
||||
max_plan_time,
|
||||
mean_plan_time,
|
||||
stddev_plan_time,
|
||||
|
||||
shared_blks_hit,
|
||||
shared_blks_read,
|
||||
shared_blks_dirtied,
|
||||
shared_blks_written,
|
||||
local_blks_hit,
|
||||
local_blks_read,
|
||||
local_blks_dirtied,
|
||||
local_blks_written,
|
||||
temp_blks_read,
|
||||
temp_blks_written,
|
||||
blk_read_time,
|
||||
blk_write_time,
|
||||
(string_to_array(resp_calls, ',')) resp_calls,
|
||||
cpu_user_time,
|
||||
cpu_sys_time,
|
||||
wal_records,
|
||||
wal_fpi,
|
||||
wal_bytes,
|
||||
state_code,
|
||||
get_state(state_code) as state
|
||||
FROM pg_stat_monitor_internal(TRUE) p, pg_database d WHERE dbid = oid
|
||||
ORDER BY bucket_start_time;
|
||||
|
||||
CREATE FUNCTION decode_error_level(elevel int)
|
||||
RETURNS text
|
||||
AS
|
||||
$$
|
||||
SELECT
|
||||
CASE
|
||||
WHEN elevel = 0 THEN ''
|
||||
WHEN elevel = 10 THEN 'DEBUG5'
|
||||
WHEN elevel = 11 THEN 'DEBUG4'
|
||||
WHEN elevel = 12 THEN 'DEBUG3'
|
||||
WHEN elevel = 13 THEN 'DEBUG2'
|
||||
WHEN elevel = 14 THEN 'DEBUG1'
|
||||
WHEN elevel = 15 THEN 'LOG'
|
||||
WHEN elevel = 16 THEN 'LOG_SERVER_ONLY'
|
||||
WHEN elevel = 17 THEN 'INFO'
|
||||
WHEN elevel = 18 THEN 'NOTICE'
|
||||
WHEN elevel = 19 THEN 'WARNING'
|
||||
WHEN elevel = 20 THEN 'ERROR'
|
||||
END
|
||||
$$
|
||||
LANGUAGE SQL PARALLEL SAFE;
|
||||
|
||||
CREATE FUNCTION histogram(_bucket int, _quryid text)
|
||||
RETURNS SETOF RECORD AS $$
|
||||
DECLARE
|
||||
rec record;
|
||||
BEGIN
|
||||
for rec in
|
||||
with stat as (select queryid, bucket, unnest(range()) as range, unnest(resp_calls)::int freq from pg_stat_monitor) select range, freq, repeat('â– ', (freq::float / max(freq) over() * 30)::int) as bar from stat where queryid = _quryid and bucket = _bucket
|
||||
loop
|
||||
return next rec;
|
||||
end loop;
|
||||
END
|
||||
$$ language plpgsql;
|
||||
|
||||
--CREATE FUNCTION pg_stat_monitor_hook_stats(
|
||||
-- OUT hook text,
|
||||
-- OUT min_time float8,
|
||||
-- OUT max_time float8,
|
||||
-- OUT total_time float8,
|
||||
-- OUT ncalls int8
|
||||
--)
|
||||
--RETURNS SETOF record
|
||||
--AS 'MODULE_PATHNAME', 'pg_stat_monitor_hook_stats'
|
||||
--LANGUAGE C STRICT VOLATILE PARALLEL SAFE;
|
||||
--
|
||||
--CREATE VIEW pg_stat_monitor_hook_stats AS SELECT
|
||||
-- hook,
|
||||
-- min_time,
|
||||
-- max_time,
|
||||
-- total_time,
|
||||
-- total_time / greatest(ncalls, 1) as avg_time,
|
||||
-- ncalls,
|
||||
-- ROUND(CAST(total_time / greatest(sum(total_time) OVER(), 0.00000001) * 100 as numeric), 2)::text || '%' as load_comparison
|
||||
-- FROM pg_stat_monitor_hook_stats();
|
||||
|
||||
GRANT SELECT ON pg_stat_monitor TO PUBLIC;
|
||||
GRANT SELECT ON pg_stat_monitor_settings TO PUBLIC;
|
||||
|
||||
-- Don't want this to be available to non-superusers.
|
||||
REVOKE ALL ON FUNCTION pg_stat_monitor_reset() FROM PUBLIC;
|
||||
|
|
@ -0,0 +1,267 @@
|
|||
/* contrib/pg_stat_monitor/pg_stat_monitor--1.0.sql */
|
||||
|
||||
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
|
||||
\echo Use "CREATE EXTENSION pg_stat_monitor" to load this file. \quit
|
||||
|
||||
-- Register functions.
|
||||
CREATE FUNCTION pg_stat_monitor_reset()
|
||||
RETURNS void
|
||||
AS 'MODULE_PATHNAME'
|
||||
LANGUAGE C PARALLEL SAFE;
|
||||
|
||||
CREATE FUNCTION pg_stat_monitor_version()
|
||||
RETURNS text
|
||||
AS 'MODULE_PATHNAME'
|
||||
LANGUAGE C PARALLEL SAFE;
|
||||
|
||||
CREATE FUNCTION get_histogram_timings()
|
||||
RETURNS text
|
||||
AS 'MODULE_PATHNAME'
|
||||
LANGUAGE C PARALLEL SAFE;
|
||||
|
||||
CREATE FUNCTION range()
|
||||
RETURNS text[] AS $$
|
||||
SELECT string_to_array(get_histogram_timings(), ',');
|
||||
$$ LANGUAGE SQL;
|
||||
|
||||
CREATE FUNCTION pg_stat_monitor_internal(IN showtext boolean,
|
||||
OUT bucket int8, -- 0
|
||||
OUT userid oid,
|
||||
OUT dbid oid,
|
||||
OUT client_ip int8,
|
||||
|
||||
OUT queryid text, -- 4
|
||||
OUT planid text,
|
||||
OUT query text,
|
||||
OUT query_plan text,
|
||||
OUT state_code int8,
|
||||
OUT top_queryid text,
|
||||
OUT top_query text,
|
||||
OUT application_name text,
|
||||
|
||||
OUT relations text, -- 11
|
||||
OUT cmd_type int,
|
||||
OUT elevel int,
|
||||
OUT sqlcode TEXT,
|
||||
OUT message text,
|
||||
OUT bucket_start_time text,
|
||||
|
||||
OUT calls int8, -- 16
|
||||
|
||||
OUT total_exec_time float8,
|
||||
OUT min_exec_time float8,
|
||||
OUT max_exec_time float8,
|
||||
OUT mean_exec_time float8,
|
||||
OUT stddev_exec_time float8,
|
||||
|
||||
OUT rows_retrieved int8,
|
||||
|
||||
OUT plans_calls int8, -- 23
|
||||
|
||||
OUT total_plan_time float8,
|
||||
OUT min_plan_time float8,
|
||||
OUT max_plan_time float8,
|
||||
OUT mean_plan_time float8,
|
||||
OUT stddev_plan_time float8,
|
||||
|
||||
OUT shared_blks_hit int8, -- 29
|
||||
OUT shared_blks_read int8,
|
||||
OUT shared_blks_dirtied int8,
|
||||
OUT shared_blks_written int8,
|
||||
OUT local_blks_hit int8,
|
||||
OUT local_blks_read int8,
|
||||
OUT local_blks_dirtied int8,
|
||||
OUT local_blks_written int8,
|
||||
OUT temp_blks_read int8,
|
||||
OUT temp_blks_written int8,
|
||||
OUT blk_read_time float8,
|
||||
OUT blk_write_time float8,
|
||||
OUT resp_calls text, -- 41
|
||||
OUT cpu_user_time float8,
|
||||
OUT cpu_sys_time float8,
|
||||
OUT wal_records int8,
|
||||
OUT wal_fpi int8,
|
||||
OUT wal_bytes numeric,
|
||||
OUT comments TEXT,
|
||||
OUT toplevel BOOLEAN
|
||||
)
|
||||
RETURNS SETOF record
|
||||
AS 'MODULE_PATHNAME', 'pg_stat_monitor'
|
||||
LANGUAGE C STRICT VOLATILE PARALLEL SAFE;
|
||||
|
||||
CREATE FUNCTION get_state(state_code int8) RETURNS TEXT AS
|
||||
$$
|
||||
SELECT
|
||||
CASE
|
||||
WHEN state_code = 0 THEN 'PARSING'
|
||||
WHEN state_code = 1 THEN 'PLANNING'
|
||||
WHEN state_code = 2 THEN 'ACTIVE'
|
||||
WHEN state_code = 3 THEN 'FINISHED'
|
||||
WHEN state_code = 4 THEN 'FINISHED WITH ERROR'
|
||||
END
|
||||
$$
|
||||
LANGUAGE SQL PARALLEL SAFE;
|
||||
|
||||
CREATE FUNCTION get_cmd_type (cmd_type INTEGER) RETURNS TEXT AS
|
||||
$$
|
||||
SELECT
|
||||
CASE
|
||||
WHEN cmd_type = 0 THEN ''
|
||||
WHEN cmd_type = 1 THEN 'SELECT'
|
||||
WHEN cmd_type = 2 THEN 'UPDATE'
|
||||
WHEN cmd_type = 3 THEN 'INSERT'
|
||||
WHEN cmd_type = 4 THEN 'DELETE'
|
||||
WHEN cmd_type = 5 THEN 'UTILITY'
|
||||
WHEN cmd_type = 6 THEN 'NOTHING'
|
||||
END
|
||||
$$
|
||||
LANGUAGE SQL PARALLEL SAFE;
|
||||
|
||||
CREATE FUNCTION pg_stat_monitor_settings(
|
||||
OUT name text,
|
||||
OUT value text,
|
||||
OUT default_value text,
|
||||
OUT description text,
|
||||
OUT minimum INTEGER,
|
||||
OUT maximum INTEGER,
|
||||
OUT options text,
|
||||
OUT restart text
|
||||
)
|
||||
RETURNS SETOF record
|
||||
AS 'MODULE_PATHNAME', 'pg_stat_monitor_settings'
|
||||
LANGUAGE C STRICT VOLATILE PARALLEL SAFE;
|
||||
|
||||
CREATE VIEW pg_stat_monitor_settings AS SELECT
|
||||
name,
|
||||
value,
|
||||
default_value,
|
||||
description,
|
||||
minimum,
|
||||
maximum,
|
||||
options,
|
||||
restart
|
||||
FROM pg_stat_monitor_settings();
|
||||
|
||||
-- Register a view on the function for ease of use.
|
||||
CREATE VIEW pg_stat_monitor AS SELECT
|
||||
bucket,
|
||||
bucket_start_time AS bucket_start_time,
|
||||
userid::regrole,
|
||||
datname,
|
||||
'0.0.0.0'::inet + client_ip AS client_ip,
|
||||
queryid,
|
||||
toplevel,
|
||||
top_queryid,
|
||||
query,
|
||||
comments,
|
||||
planid,
|
||||
query_plan,
|
||||
top_query,
|
||||
application_name,
|
||||
string_to_array(relations, ',') AS relations,
|
||||
cmd_type,
|
||||
get_cmd_type(cmd_type) AS cmd_type_text,
|
||||
elevel,
|
||||
sqlcode,
|
||||
message,
|
||||
calls,
|
||||
total_exec_time,
|
||||
min_exec_time,
|
||||
max_exec_time,
|
||||
mean_exec_time,
|
||||
stddev_exec_time,
|
||||
|
||||
rows_retrieved,
|
||||
|
||||
plans_calls,
|
||||
|
||||
total_plan_time,
|
||||
min_plan_time,
|
||||
max_plan_time,
|
||||
mean_plan_time,
|
||||
stddev_plan_time,
|
||||
|
||||
shared_blks_hit,
|
||||
shared_blks_read,
|
||||
shared_blks_dirtied,
|
||||
shared_blks_written,
|
||||
local_blks_hit,
|
||||
local_blks_read,
|
||||
local_blks_dirtied,
|
||||
local_blks_written,
|
||||
temp_blks_read,
|
||||
temp_blks_written,
|
||||
blk_read_time,
|
||||
blk_write_time,
|
||||
(string_to_array(resp_calls, ',')) resp_calls,
|
||||
cpu_user_time,
|
||||
cpu_sys_time,
|
||||
wal_records,
|
||||
wal_fpi,
|
||||
wal_bytes,
|
||||
state_code,
|
||||
get_state(state_code) as state
|
||||
FROM pg_stat_monitor_internal(TRUE) p, pg_database d WHERE dbid = oid
|
||||
ORDER BY bucket_start_time;
|
||||
|
||||
CREATE FUNCTION decode_error_level(elevel int)
|
||||
RETURNS text
|
||||
AS
|
||||
$$
|
||||
SELECT
|
||||
CASE
|
||||
WHEN elevel = 0 THEN ''
|
||||
WHEN elevel = 10 THEN 'DEBUG5'
|
||||
WHEN elevel = 11 THEN 'DEBUG4'
|
||||
WHEN elevel = 12 THEN 'DEBUG3'
|
||||
WHEN elevel = 13 THEN 'DEBUG2'
|
||||
WHEN elevel = 14 THEN 'DEBUG1'
|
||||
WHEN elevel = 15 THEN 'LOG'
|
||||
WHEN elevel = 16 THEN 'LOG_SERVER_ONLY'
|
||||
WHEN elevel = 17 THEN 'INFO'
|
||||
WHEN elevel = 18 THEN 'NOTICE'
|
||||
WHEN elevel = 19 THEN 'WARNING'
|
||||
WHEN elevel = 20 THEN 'ERROR'
|
||||
END
|
||||
$$
|
||||
LANGUAGE SQL PARALLEL SAFE;
|
||||
|
||||
CREATE FUNCTION histogram(_bucket int, _quryid text)
|
||||
RETURNS SETOF RECORD AS $$
|
||||
DECLARE
|
||||
rec record;
|
||||
BEGIN
|
||||
for rec in
|
||||
with stat as (select queryid, bucket, unnest(range()) as range, unnest(resp_calls)::int freq from pg_stat_monitor) select range, freq, repeat('â– ', (freq::float / max(freq) over() * 30)::int) as bar from stat where queryid = _quryid and bucket = _bucket
|
||||
loop
|
||||
return next rec;
|
||||
end loop;
|
||||
END
|
||||
$$ language plpgsql;
|
||||
|
||||
--CREATE FUNCTION pg_stat_monitor_hook_stats(
|
||||
-- OUT hook text,
|
||||
-- OUT min_time float8,
|
||||
-- OUT max_time float8,
|
||||
-- OUT total_time float8,
|
||||
-- OUT ncalls int8
|
||||
--)
|
||||
--RETURNS SETOF record
|
||||
--AS 'MODULE_PATHNAME', 'pg_stat_monitor_hook_stats'
|
||||
--LANGUAGE C STRICT VOLATILE PARALLEL SAFE;
|
||||
--
|
||||
--CREATE VIEW pg_stat_monitor_hook_stats AS SELECT
|
||||
-- hook,
|
||||
-- min_time,
|
||||
-- max_time,
|
||||
-- total_time,
|
||||
-- total_time / greatest(ncalls, 1) as avg_time,
|
||||
-- ncalls,
|
||||
-- ROUND(CAST(total_time / greatest(sum(total_time) OVER(), 0.00000001) * 100 as numeric), 2)::text || '%' as load_comparison
|
||||
-- FROM pg_stat_monitor_hook_stats();
|
||||
|
||||
GRANT SELECT ON pg_stat_monitor TO PUBLIC;
|
||||
GRANT SELECT ON pg_stat_monitor_settings TO PUBLIC;
|
||||
|
||||
-- Don't want this to be available to non-superusers.
|
||||
REVOKE ALL ON FUNCTION pg_stat_monitor_reset() FROM PUBLIC;
|
||||
|
|
@ -0,0 +1,255 @@
|
|||
/* contrib/pg_stat_monitor/pg_stat_monitor--1.0.sql */
|
||||
|
||||
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
|
||||
\echo Use "CREATE EXTENSION pg_stat_monitor" to load this file. \quit
|
||||
|
||||
-- Register functions.
|
||||
CREATE FUNCTION pg_stat_monitor_reset()
|
||||
RETURNS void
|
||||
AS 'MODULE_PATHNAME'
|
||||
LANGUAGE C PARALLEL SAFE;
|
||||
|
||||
CREATE FUNCTION pg_stat_monitor_version()
|
||||
RETURNS text
|
||||
AS 'MODULE_PATHNAME'
|
||||
LANGUAGE C PARALLEL SAFE;
|
||||
|
||||
CREATE FUNCTION get_histogram_timings()
|
||||
RETURNS text
|
||||
AS 'MODULE_PATHNAME'
|
||||
LANGUAGE C PARALLEL SAFE;
|
||||
|
||||
CREATE FUNCTION range()
|
||||
RETURNS text[] AS $$
|
||||
SELECT string_to_array(get_histogram_timings(), ',');
|
||||
$$ LANGUAGE SQL;
|
||||
|
||||
CREATE FUNCTION pg_stat_monitor_internal(IN showtext boolean,
|
||||
OUT bucket int8, -- 0
|
||||
OUT userid oid,
|
||||
OUT dbid oid,
|
||||
OUT client_ip int8,
|
||||
|
||||
OUT queryid text, -- 4
|
||||
OUT planid text,
|
||||
OUT query text,
|
||||
OUT query_plan text,
|
||||
OUT state_code int8,
|
||||
OUT top_queryid text,
|
||||
OUT top_query text,
|
||||
OUT application_name text,
|
||||
|
||||
OUT relations text, -- 11
|
||||
OUT cmd_type int,
|
||||
OUT elevel int,
|
||||
OUT sqlcode TEXT,
|
||||
OUT message text,
|
||||
OUT bucket_start_time text,
|
||||
|
||||
OUT calls int8, -- 16
|
||||
OUT total_time float8,
|
||||
OUT min_time float8,
|
||||
OUT max_time float8,
|
||||
OUT mean_time float8,
|
||||
OUT stddev_time float8,
|
||||
OUT rows_retrieved int8,
|
||||
|
||||
OUT plans_calls int8, -- 23
|
||||
OUT plan_total_time float8,
|
||||
OUT plan_min_time float8,
|
||||
OUT plan_max_time float8,
|
||||
OUT plan_mean_time float8,
|
||||
OUT plan_stddev_time float8,
|
||||
|
||||
OUT shared_blks_hit int8, -- 29
|
||||
OUT shared_blks_read int8,
|
||||
OUT shared_blks_dirtied int8,
|
||||
OUT shared_blks_written int8,
|
||||
OUT local_blks_hit int8,
|
||||
OUT local_blks_read int8,
|
||||
OUT local_blks_dirtied int8,
|
||||
OUT local_blks_written int8,
|
||||
OUT temp_blks_read int8,
|
||||
OUT temp_blks_written int8,
|
||||
OUT blk_read_time float8,
|
||||
OUT blk_write_time float8,
|
||||
OUT resp_calls text, -- 41
|
||||
OUT cpu_user_time float8,
|
||||
OUT cpu_sys_time float8,
|
||||
OUT wal_records int8,
|
||||
OUT wal_fpi int8,
|
||||
OUT wal_bytes numeric,
|
||||
OUT comments TEXT,
|
||||
OUT toplevel BOOLEAN
|
||||
)
|
||||
RETURNS SETOF record
|
||||
AS 'MODULE_PATHNAME', 'pg_stat_monitor'
|
||||
LANGUAGE C STRICT VOLATILE PARALLEL SAFE;
|
||||
|
||||
CREATE FUNCTION get_state(state_code int8) RETURNS TEXT AS
|
||||
$$
|
||||
SELECT
|
||||
CASE
|
||||
WHEN state_code = 0 THEN 'PARSING'
|
||||
WHEN state_code = 1 THEN 'PLANNING'
|
||||
WHEN state_code = 2 THEN 'ACTIVE'
|
||||
WHEN state_code = 3 THEN 'FINISHED'
|
||||
WHEN state_code = 4 THEN 'FINISHED WITH ERROR'
|
||||
END
|
||||
$$
|
||||
LANGUAGE SQL PARALLEL SAFE;
|
||||
|
||||
CREATE FUNCTION get_cmd_type (cmd_type INTEGER) RETURNS TEXT AS
|
||||
$$
|
||||
SELECT
|
||||
CASE
|
||||
WHEN cmd_type = 0 THEN ''
|
||||
WHEN cmd_type = 1 THEN 'SELECT'
|
||||
WHEN cmd_type = 2 THEN 'UPDATE'
|
||||
WHEN cmd_type = 3 THEN 'INSERT'
|
||||
WHEN cmd_type = 4 THEN 'DELETE'
|
||||
WHEN cmd_type = 5 THEN 'UTILITY'
|
||||
WHEN cmd_type = 6 THEN 'NOTHING'
|
||||
END
|
||||
$$
|
||||
LANGUAGE SQL PARALLEL SAFE;
|
||||
|
||||
CREATE FUNCTION pg_stat_monitor_settings(
|
||||
OUT name text,
|
||||
OUT value text,
|
||||
OUT default_value text,
|
||||
OUT description text,
|
||||
OUT minimum INTEGER,
|
||||
OUT maximum INTEGER,
|
||||
OUT options text,
|
||||
OUT restart text
|
||||
)
|
||||
RETURNS SETOF record
|
||||
AS 'MODULE_PATHNAME', 'pg_stat_monitor_settings'
|
||||
LANGUAGE C STRICT VOLATILE PARALLEL SAFE;
|
||||
|
||||
CREATE VIEW pg_stat_monitor_settings AS SELECT
|
||||
name,
|
||||
value,
|
||||
default_value,
|
||||
description,
|
||||
minimum,
|
||||
maximum,
|
||||
options,
|
||||
restart
|
||||
FROM pg_stat_monitor_settings();
|
||||
|
||||
-- Register a view on the function for ease of use.
|
||||
CREATE VIEW pg_stat_monitor AS SELECT
|
||||
bucket,
|
||||
bucket_start_time AS bucket_start_time,
|
||||
userid::regrole,
|
||||
datname,
|
||||
'0.0.0.0'::inet + client_ip AS client_ip,
|
||||
queryid,
|
||||
top_queryid,
|
||||
query,
|
||||
comments,
|
||||
planid,
|
||||
query_plan,
|
||||
top_query,
|
||||
application_name,
|
||||
string_to_array(relations, ',') AS relations,
|
||||
cmd_type,
|
||||
get_cmd_type(cmd_type) AS cmd_type_text,
|
||||
elevel,
|
||||
sqlcode,
|
||||
message,
|
||||
calls,
|
||||
total_time,
|
||||
min_time,
|
||||
max_time,
|
||||
mean_time,
|
||||
stddev_time,
|
||||
rows_retrieved,
|
||||
shared_blks_hit,
|
||||
shared_blks_read,
|
||||
shared_blks_dirtied,
|
||||
shared_blks_written,
|
||||
local_blks_hit,
|
||||
local_blks_read,
|
||||
local_blks_dirtied,
|
||||
local_blks_written,
|
||||
temp_blks_read,
|
||||
temp_blks_written,
|
||||
blk_read_time,
|
||||
blk_write_time,
|
||||
(string_to_array(resp_calls, ',')) resp_calls,
|
||||
cpu_user_time,
|
||||
cpu_sys_time,
|
||||
wal_records,
|
||||
wal_fpi,
|
||||
wal_bytes,
|
||||
state_code,
|
||||
get_state(state_code) as state
|
||||
FROM pg_stat_monitor_internal(TRUE) p, pg_database d WHERE dbid = oid
|
||||
ORDER BY bucket_start_time;
|
||||
|
||||
CREATE FUNCTION decode_error_level(elevel int)
|
||||
RETURNS text
|
||||
AS
|
||||
$$
|
||||
SELECT
|
||||
CASE
|
||||
WHEN elevel = 0 THEN ''
|
||||
WHEN elevel = 10 THEN 'DEBUG5'
|
||||
WHEN elevel = 11 THEN 'DEBUG4'
|
||||
WHEN elevel = 12 THEN 'DEBUG3'
|
||||
WHEN elevel = 13 THEN 'DEBUG2'
|
||||
WHEN elevel = 14 THEN 'DEBUG1'
|
||||
WHEN elevel = 15 THEN 'LOG'
|
||||
WHEN elevel = 16 THEN 'LOG_SERVER_ONLY'
|
||||
WHEN elevel = 17 THEN 'INFO'
|
||||
WHEN elevel = 18 THEN 'NOTICE'
|
||||
WHEN elevel = 19 THEN 'WARNING'
|
||||
WHEN elevel = 20 THEN 'ERROR'
|
||||
END
|
||||
$$
|
||||
LANGUAGE SQL PARALLEL SAFE;
|
||||
|
||||
CREATE FUNCTION histogram(_bucket int, _quryid text)
|
||||
RETURNS SETOF RECORD AS $$
|
||||
DECLARE
|
||||
rec record;
|
||||
BEGIN
|
||||
for rec in
|
||||
with stat as (select queryid, bucket, unnest(range()) as range, unnest(resp_calls)::int freq from pg_stat_monitor) select range, freq, repeat('â– ', (freq::float / max(freq) over() * 30)::int) as bar from stat where queryid = _quryid and bucket = _bucket
|
||||
loop
|
||||
return next rec;
|
||||
end loop;
|
||||
END
|
||||
$$ language plpgsql;
|
||||
|
||||
-- CREATE FUNCTION pg_stat_monitor_hook_stats(
|
||||
-- OUT hook text,
|
||||
-- OUT min_time float8,
|
||||
-- OUT max_time float8,
|
||||
-- OUT total_time float8,
|
||||
-- OUT ncalls int8
|
||||
--)
|
||||
--RETURNS SETOF record
|
||||
--AS 'MODULE_PATHNAME', 'pg_stat_monitor_hook_stats'
|
||||
--LANGUAGE C STRICT VOLATILE PARALLEL SAFE;
|
||||
|
||||
--CREATE VIEW pg_stat_monitor_hook_stats AS SELECT
|
||||
-- hook,
|
||||
-- min_time,
|
||||
-- max_time,
|
||||
-- total_time,
|
||||
-- total_time / greatest(ncalls, 1) as avg_time,
|
||||
-- ncalls,
|
||||
-- ROUND(CAST(total_time / greatest(sum(total_time) OVER(), 0.00000001) * 100 as numeric), 2)::text || '%' as load_comparison
|
||||
-- FROM pg_stat_monitor_hook_stats();
|
||||
|
||||
GRANT SELECT ON pg_stat_monitor TO PUBLIC;
|
||||
GRANT SELECT ON pg_stat_monitor_settings TO PUBLIC;
|
||||
|
||||
-- Don't want this to be available to non-superusers.
|
||||
REVOKE ALL ON FUNCTION pg_stat_monitor_reset() FROM PUBLIC;
|
||||
|
||||
|
||||
|
|
@ -1,497 +0,0 @@
|
|||
/* contrib/pg_stat_monitor/pg_stat_monitor--2.0--2.1.sql */
|
||||
|
||||
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
|
||||
\echo Use "ALTER EXTENSION pg_stat_monitor" to load this file. \quit
|
||||
|
||||
DROP FUNCTION pg_stat_monitor_internal CASCADE;
|
||||
DROP FUNCTION pgsm_create_view CASCADE;
|
||||
DROP FUNCTION pgsm_create_11_view();
|
||||
DROP FUNCTION pgsm_create_13_view();
|
||||
DROP FUNCTION pgsm_create_14_view();
|
||||
DROP FUNCTION pgsm_create_15_view();
|
||||
|
||||
CREATE FUNCTION pg_stat_monitor_internal(
|
||||
IN showtext boolean,
|
||||
OUT bucket int8, -- 0
|
||||
OUT userid oid,
|
||||
OUT username text,
|
||||
OUT dbid oid,
|
||||
OUT datname text,
|
||||
OUT client_ip int8,
|
||||
|
||||
OUT queryid int8, -- 6
|
||||
OUT planid int8,
|
||||
OUT query text,
|
||||
OUT query_plan text,
|
||||
OUT pgsm_query_id int8,
|
||||
OUT top_queryid int8,
|
||||
OUT top_query text,
|
||||
OUT application_name text,
|
||||
|
||||
OUT relations text, -- 14
|
||||
OUT cmd_type int,
|
||||
OUT elevel int,
|
||||
OUT sqlcode TEXT,
|
||||
OUT message text,
|
||||
OUT bucket_start_time timestamptz,
|
||||
|
||||
OUT calls int8, -- 20
|
||||
|
||||
OUT total_exec_time float8, -- 21
|
||||
OUT min_exec_time float8,
|
||||
OUT max_exec_time float8,
|
||||
OUT mean_exec_time float8,
|
||||
OUT stddev_exec_time float8,
|
||||
|
||||
OUT rows int8, -- 26
|
||||
|
||||
OUT plans int8, -- 27
|
||||
|
||||
OUT total_plan_time float8, -- 28
|
||||
OUT min_plan_time float8,
|
||||
OUT max_plan_time float8,
|
||||
OUT mean_plan_time float8,
|
||||
OUT stddev_plan_time float8,
|
||||
|
||||
OUT shared_blks_hit int8, -- 33
|
||||
OUT shared_blks_read int8,
|
||||
OUT shared_blks_dirtied int8,
|
||||
OUT shared_blks_written int8,
|
||||
OUT local_blks_hit int8,
|
||||
OUT local_blks_read int8,
|
||||
OUT local_blks_dirtied int8,
|
||||
OUT local_blks_written int8,
|
||||
OUT temp_blks_read int8,
|
||||
OUT temp_blks_written int8,
|
||||
OUT shared_blk_read_time float8,
|
||||
OUT shared_blk_write_time float8,
|
||||
OUT local_blk_read_time float8,
|
||||
OUT local_blk_write_time float8,
|
||||
OUT temp_blk_read_time float8,
|
||||
OUT temp_blk_write_time float8,
|
||||
|
||||
OUT resp_calls text, -- 49
|
||||
OUT cpu_user_time float8,
|
||||
OUT cpu_sys_time float8,
|
||||
OUT wal_records int8,
|
||||
OUT wal_fpi int8,
|
||||
OUT wal_bytes numeric,
|
||||
OUT comments TEXT,
|
||||
|
||||
OUT jit_functions int8, -- 56
|
||||
OUT jit_generation_time float8,
|
||||
OUT jit_inlining_count int8,
|
||||
OUT jit_inlining_time float8,
|
||||
OUT jit_optimization_count int8,
|
||||
OUT jit_optimization_time float8,
|
||||
OUT jit_emission_count int8,
|
||||
OUT jit_emission_time float8,
|
||||
OUT jit_deform_count int8,
|
||||
OUT jit_deform_time float8,
|
||||
|
||||
OUT stats_since timestamp with time zone, -- 66
|
||||
OUT minmax_stats_since timestamp with time zone,
|
||||
|
||||
OUT toplevel BOOLEAN, -- 68
|
||||
OUT bucket_done BOOLEAN
|
||||
)
|
||||
RETURNS SETOF record
|
||||
AS 'MODULE_PATHNAME', 'pg_stat_monitor_2_1'
|
||||
LANGUAGE C STRICT VOLATILE PARALLEL SAFE;
|
||||
|
||||
-- Register a view on the function for ease of use.
|
||||
CREATE FUNCTION pgsm_create_11_view() RETURNS INT AS
|
||||
$$
|
||||
BEGIN
|
||||
CREATE VIEW pg_stat_monitor AS SELECT
|
||||
bucket,
|
||||
bucket_start_time AS bucket_start_time,
|
||||
userid,
|
||||
username,
|
||||
dbid,
|
||||
datname,
|
||||
'0.0.0.0'::inet + client_ip AS client_ip,
|
||||
pgsm_query_id,
|
||||
queryid,
|
||||
top_queryid,
|
||||
query,
|
||||
comments,
|
||||
planid,
|
||||
query_plan,
|
||||
top_query,
|
||||
application_name,
|
||||
string_to_array(relations, ',') AS relations,
|
||||
cmd_type,
|
||||
get_cmd_type(cmd_type) AS cmd_type_text,
|
||||
elevel,
|
||||
sqlcode,
|
||||
message,
|
||||
calls,
|
||||
total_exec_time AS total_time,
|
||||
min_exec_time AS min_time,
|
||||
max_exec_time AS max_time,
|
||||
mean_exec_time AS mean_time,
|
||||
stddev_exec_time AS stddev_time,
|
||||
rows,
|
||||
shared_blks_hit,
|
||||
shared_blks_read,
|
||||
shared_blks_dirtied,
|
||||
shared_blks_written,
|
||||
local_blks_hit,
|
||||
local_blks_read,
|
||||
local_blks_dirtied,
|
||||
local_blks_written,
|
||||
temp_blks_read,
|
||||
temp_blks_written,
|
||||
shared_blk_read_time AS blk_read_time,
|
||||
shared_blk_write_time AS blk_write_time,
|
||||
(string_to_array(resp_calls, ',')) resp_calls,
|
||||
cpu_user_time,
|
||||
cpu_sys_time,
|
||||
bucket_done
|
||||
FROM pg_stat_monitor_internal(TRUE)
|
||||
ORDER BY bucket_start_time;
|
||||
RETURN 0;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
|
||||
CREATE FUNCTION pgsm_create_13_view() RETURNS INT AS
|
||||
$$
|
||||
BEGIN
|
||||
CREATE VIEW pg_stat_monitor AS SELECT
|
||||
bucket,
|
||||
bucket_start_time AS bucket_start_time,
|
||||
userid,
|
||||
username,
|
||||
dbid,
|
||||
datname,
|
||||
'0.0.0.0'::inet + client_ip AS client_ip,
|
||||
pgsm_query_id,
|
||||
queryid,
|
||||
toplevel,
|
||||
top_queryid,
|
||||
query,
|
||||
comments,
|
||||
planid,
|
||||
query_plan,
|
||||
top_query,
|
||||
application_name,
|
||||
string_to_array(relations, ',') AS relations,
|
||||
cmd_type,
|
||||
get_cmd_type(cmd_type) AS cmd_type_text,
|
||||
elevel,
|
||||
sqlcode,
|
||||
message,
|
||||
calls,
|
||||
total_exec_time,
|
||||
min_exec_time,
|
||||
max_exec_time,
|
||||
mean_exec_time,
|
||||
stddev_exec_time,
|
||||
rows,
|
||||
shared_blks_hit,
|
||||
shared_blks_read,
|
||||
shared_blks_dirtied,
|
||||
shared_blks_written,
|
||||
local_blks_hit,
|
||||
local_blks_read,
|
||||
local_blks_dirtied,
|
||||
local_blks_written,
|
||||
temp_blks_read,
|
||||
temp_blks_written,
|
||||
shared_blk_read_time AS blk_read_time,
|
||||
shared_blk_write_time AS blk_write_time,
|
||||
(string_to_array(resp_calls, ',')) resp_calls,
|
||||
cpu_user_time,
|
||||
cpu_sys_time,
|
||||
wal_records,
|
||||
wal_fpi,
|
||||
wal_bytes,
|
||||
bucket_done,
|
||||
-- PostgreSQL-13 Specific Coulumns
|
||||
plans,
|
||||
total_plan_time,
|
||||
min_plan_time,
|
||||
max_plan_time,
|
||||
mean_plan_time,
|
||||
stddev_plan_time
|
||||
FROM pg_stat_monitor_internal(TRUE)
|
||||
ORDER BY bucket_start_time;
|
||||
RETURN 0;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
CREATE FUNCTION pgsm_create_14_view() RETURNS INT AS
|
||||
$$
|
||||
BEGIN
|
||||
CREATE VIEW pg_stat_monitor AS SELECT
|
||||
bucket,
|
||||
bucket_start_time AS bucket_start_time,
|
||||
userid,
|
||||
username,
|
||||
dbid,
|
||||
datname,
|
||||
'0.0.0.0'::inet + client_ip AS client_ip,
|
||||
pgsm_query_id,
|
||||
queryid,
|
||||
toplevel,
|
||||
top_queryid,
|
||||
query,
|
||||
comments,
|
||||
planid,
|
||||
query_plan,
|
||||
top_query,
|
||||
application_name,
|
||||
string_to_array(relations, ',') AS relations,
|
||||
cmd_type,
|
||||
get_cmd_type(cmd_type) AS cmd_type_text,
|
||||
elevel,
|
||||
sqlcode,
|
||||
message,
|
||||
calls,
|
||||
total_exec_time,
|
||||
min_exec_time,
|
||||
max_exec_time,
|
||||
mean_exec_time,
|
||||
stddev_exec_time,
|
||||
rows,
|
||||
shared_blks_hit,
|
||||
shared_blks_read,
|
||||
shared_blks_dirtied,
|
||||
shared_blks_written,
|
||||
local_blks_hit,
|
||||
local_blks_read,
|
||||
local_blks_dirtied,
|
||||
local_blks_written,
|
||||
temp_blks_read,
|
||||
temp_blks_written,
|
||||
shared_blk_read_time AS blk_read_time,
|
||||
shared_blk_write_time AS blk_write_time,
|
||||
(string_to_array(resp_calls, ',')) resp_calls,
|
||||
cpu_user_time,
|
||||
cpu_sys_time,
|
||||
wal_records,
|
||||
wal_fpi,
|
||||
wal_bytes,
|
||||
bucket_done,
|
||||
|
||||
plans,
|
||||
total_plan_time,
|
||||
min_plan_time,
|
||||
max_plan_time,
|
||||
mean_plan_time,
|
||||
stddev_plan_time
|
||||
FROM pg_stat_monitor_internal(TRUE)
|
||||
ORDER BY bucket_start_time;
|
||||
RETURN 0;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
CREATE FUNCTION pgsm_create_15_view() RETURNS INT AS
|
||||
$$
|
||||
BEGIN
|
||||
CREATE VIEW pg_stat_monitor AS SELECT
|
||||
bucket,
|
||||
bucket_start_time AS bucket_start_time,
|
||||
userid,
|
||||
username,
|
||||
dbid,
|
||||
datname,
|
||||
'0.0.0.0'::inet + client_ip AS client_ip,
|
||||
pgsm_query_id,
|
||||
queryid,
|
||||
toplevel,
|
||||
top_queryid,
|
||||
query,
|
||||
comments,
|
||||
planid,
|
||||
query_plan,
|
||||
top_query,
|
||||
application_name,
|
||||
string_to_array(relations, ',') AS relations,
|
||||
cmd_type,
|
||||
get_cmd_type(cmd_type) AS cmd_type_text,
|
||||
elevel,
|
||||
sqlcode,
|
||||
message,
|
||||
calls,
|
||||
total_exec_time,
|
||||
min_exec_time,
|
||||
max_exec_time,
|
||||
mean_exec_time,
|
||||
stddev_exec_time,
|
||||
rows,
|
||||
shared_blks_hit,
|
||||
shared_blks_read,
|
||||
shared_blks_dirtied,
|
||||
shared_blks_written,
|
||||
local_blks_hit,
|
||||
local_blks_read,
|
||||
local_blks_dirtied,
|
||||
local_blks_written,
|
||||
temp_blks_read,
|
||||
temp_blks_written,
|
||||
shared_blk_read_time AS blk_read_time,
|
||||
shared_blk_write_time AS blk_write_time,
|
||||
temp_blk_read_time,
|
||||
temp_blk_write_time,
|
||||
|
||||
(string_to_array(resp_calls, ',')) resp_calls,
|
||||
cpu_user_time,
|
||||
cpu_sys_time,
|
||||
wal_records,
|
||||
wal_fpi,
|
||||
wal_bytes,
|
||||
bucket_done,
|
||||
|
||||
plans,
|
||||
total_plan_time,
|
||||
min_plan_time,
|
||||
max_plan_time,
|
||||
mean_plan_time,
|
||||
stddev_plan_time,
|
||||
|
||||
jit_functions,
|
||||
jit_generation_time,
|
||||
jit_inlining_count,
|
||||
jit_inlining_time,
|
||||
jit_optimization_count,
|
||||
jit_optimization_time,
|
||||
jit_emission_count,
|
||||
jit_emission_time
|
||||
|
||||
FROM pg_stat_monitor_internal(TRUE)
|
||||
ORDER BY bucket_start_time;
|
||||
RETURN 0;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
CREATE FUNCTION pgsm_create_17_view() RETURNS INT AS
|
||||
$$
|
||||
BEGIN
|
||||
CREATE VIEW pg_stat_monitor AS SELECT
|
||||
bucket,
|
||||
bucket_start_time,
|
||||
userid,
|
||||
username,
|
||||
dbid,
|
||||
datname,
|
||||
'0.0.0.0'::inet + client_ip AS client_ip,
|
||||
pgsm_query_id,
|
||||
queryid,
|
||||
toplevel,
|
||||
top_queryid,
|
||||
query,
|
||||
comments,
|
||||
planid,
|
||||
query_plan,
|
||||
top_query,
|
||||
application_name,
|
||||
string_to_array(relations, ',') AS relations,
|
||||
cmd_type,
|
||||
get_cmd_type(cmd_type) AS cmd_type_text,
|
||||
elevel,
|
||||
sqlcode,
|
||||
message,
|
||||
calls,
|
||||
total_exec_time,
|
||||
min_exec_time,
|
||||
max_exec_time,
|
||||
mean_exec_time,
|
||||
stddev_exec_time,
|
||||
rows,
|
||||
shared_blks_hit,
|
||||
shared_blks_read,
|
||||
shared_blks_dirtied,
|
||||
shared_blks_written,
|
||||
local_blks_hit,
|
||||
local_blks_read,
|
||||
local_blks_dirtied,
|
||||
local_blks_written,
|
||||
temp_blks_read,
|
||||
temp_blks_written,
|
||||
shared_blk_read_time,
|
||||
shared_blk_write_time,
|
||||
local_blk_read_time,
|
||||
local_blk_write_time,
|
||||
temp_blk_read_time,
|
||||
temp_blk_write_time,
|
||||
|
||||
(string_to_array(resp_calls, ',')) resp_calls,
|
||||
cpu_user_time,
|
||||
cpu_sys_time,
|
||||
wal_records,
|
||||
wal_fpi,
|
||||
wal_bytes,
|
||||
bucket_done,
|
||||
|
||||
plans,
|
||||
total_plan_time,
|
||||
min_plan_time,
|
||||
max_plan_time,
|
||||
mean_plan_time,
|
||||
stddev_plan_time,
|
||||
|
||||
jit_functions,
|
||||
jit_generation_time,
|
||||
jit_inlining_count,
|
||||
jit_inlining_time,
|
||||
jit_optimization_count,
|
||||
jit_optimization_time,
|
||||
jit_emission_count,
|
||||
jit_emission_time,
|
||||
jit_deform_count,
|
||||
jit_deform_time,
|
||||
|
||||
stats_since,
|
||||
minmax_stats_since
|
||||
|
||||
FROM pg_stat_monitor_internal(TRUE)
|
||||
ORDER BY bucket_start_time;
|
||||
RETURN 0;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
CREATE FUNCTION pgsm_create_view() RETURNS INT AS
|
||||
$$
|
||||
DECLARE ver integer;
|
||||
BEGIN
|
||||
SELECT current_setting('server_version_num') INTO ver;
|
||||
IF (ver >= 170000) THEN
|
||||
return pgsm_create_17_view();
|
||||
END IF;
|
||||
IF (ver >= 150000) THEN
|
||||
return pgsm_create_15_view();
|
||||
END IF;
|
||||
IF (ver >= 140000) THEN
|
||||
return pgsm_create_14_view();
|
||||
END IF;
|
||||
IF (ver >= 130000) THEN
|
||||
return pgsm_create_13_view();
|
||||
END IF;
|
||||
IF (ver >= 110000) THEN
|
||||
return pgsm_create_11_view();
|
||||
END IF;
|
||||
RETURN 0;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
SELECT pgsm_create_view();
|
||||
REVOKE ALL ON FUNCTION pgsm_create_view FROM PUBLIC;
|
||||
REVOKE ALL ON FUNCTION pgsm_create_11_view FROM PUBLIC;
|
||||
REVOKE ALL ON FUNCTION pgsm_create_13_view FROM PUBLIC;
|
||||
REVOKE ALL ON FUNCTION pgsm_create_14_view FROM PUBLIC;
|
||||
REVOKE ALL ON FUNCTION pgsm_create_15_view FROM PUBLIC;
|
||||
REVOKE ALL ON FUNCTION pgsm_create_17_view FROM PUBLIC;
|
||||
|
||||
GRANT EXECUTE ON FUNCTION range TO PUBLIC;
|
||||
GRANT EXECUTE ON FUNCTION decode_error_level TO PUBLIC;
|
||||
GRANT EXECUTE ON FUNCTION get_histogram_timings TO PUBLIC;
|
||||
GRANT EXECUTE ON FUNCTION get_cmd_type TO PUBLIC;
|
||||
GRANT EXECUTE ON FUNCTION pg_stat_monitor_internal TO PUBLIC;
|
||||
|
||||
GRANT SELECT ON pg_stat_monitor TO PUBLIC;
|
||||
|
||||
-- Reset is only available to super user
|
||||
REVOKE ALL ON FUNCTION pg_stat_monitor_reset FROM PUBLIC;
|
||||
|
|
@ -1,471 +0,0 @@
|
|||
/* contrib/pg_stat_monitor/pg_stat_monitor--2.0.sql */
|
||||
|
||||
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
|
||||
\echo Use "CREATE EXTENSION pg_stat_monitor" to load this file. \quit
|
||||
|
||||
-- Register functions.
|
||||
CREATE FUNCTION pg_stat_monitor_reset()
|
||||
RETURNS void
|
||||
AS 'MODULE_PATHNAME'
|
||||
LANGUAGE C PARALLEL SAFE;
|
||||
|
||||
CREATE FUNCTION pg_stat_monitor_version()
|
||||
RETURNS text
|
||||
AS 'MODULE_PATHNAME'
|
||||
LANGUAGE C PARALLEL SAFE;
|
||||
|
||||
CREATE FUNCTION get_histogram_timings()
|
||||
RETURNS text
|
||||
AS 'MODULE_PATHNAME'
|
||||
LANGUAGE C PARALLEL SAFE;
|
||||
|
||||
CREATE FUNCTION range()
|
||||
RETURNS text[] AS $$
|
||||
SELECT string_to_array(get_histogram_timings(), ',');
|
||||
$$ LANGUAGE SQL;
|
||||
|
||||
-- Some generic utility function used internally.
|
||||
|
||||
CREATE FUNCTION get_cmd_type (cmd_type INTEGER) RETURNS TEXT AS
|
||||
$$
|
||||
SELECT
|
||||
CASE
|
||||
WHEN cmd_type = 0 THEN ''
|
||||
WHEN cmd_type = 1 THEN 'SELECT'
|
||||
WHEN cmd_type = 2 THEN 'UPDATE'
|
||||
WHEN cmd_type = 3 THEN 'INSERT'
|
||||
WHEN cmd_type = 4 THEN 'DELETE'
|
||||
WHEN cmd_type = 5 THEN 'UTILITY'
|
||||
WHEN cmd_type = 6 THEN 'NOTHING'
|
||||
END
|
||||
$$
|
||||
LANGUAGE SQL PARALLEL SAFE;
|
||||
|
||||
CREATE FUNCTION decode_error_level(elevel int)
|
||||
RETURNS text
|
||||
AS
|
||||
$$
|
||||
SELECT
|
||||
CASE
|
||||
WHEN elevel = 0 THEN ''
|
||||
WHEN elevel = 10 THEN 'DEBUG5'
|
||||
WHEN elevel = 11 THEN 'DEBUG4'
|
||||
WHEN elevel = 12 THEN 'DEBUG3'
|
||||
WHEN elevel = 13 THEN 'DEBUG2'
|
||||
WHEN elevel = 14 THEN 'DEBUG1'
|
||||
WHEN elevel = 15 THEN 'LOG'
|
||||
WHEN elevel = 16 THEN 'LOG_SERVER_ONLY'
|
||||
WHEN elevel = 17 THEN 'INFO'
|
||||
WHEN elevel = 18 THEN 'NOTICE'
|
||||
WHEN elevel = 19 THEN 'WARNING'
|
||||
WHEN elevel = 20 THEN 'ERROR'
|
||||
END
|
||||
$$
|
||||
LANGUAGE SQL PARALLEL SAFE;
|
||||
|
||||
CREATE FUNCTION histogram(_bucket int, _quryid int8)
|
||||
RETURNS SETOF RECORD AS $$
|
||||
DECLARE
|
||||
rec record;
|
||||
BEGIN
|
||||
FOR rec IN
|
||||
WITH stat AS (select queryid, bucket, unnest(range()) AS range,
|
||||
unnest(resp_calls)::int freq FROM pg_stat_monitor) select range,
|
||||
freq, repeat('â– ', (freq::float / max(freq) over() * 30)::int) AS bar
|
||||
FROM stat WHERE queryid = _quryid and bucket = _bucket
|
||||
LOOP
|
||||
RETURN next rec;
|
||||
END loop;
|
||||
END
|
||||
$$ language plpgsql;
|
||||
|
||||
-- pg_stat_monitor internal function, must not call outside from this file.
|
||||
CREATE FUNCTION pg_stat_monitor_internal(
|
||||
IN showtext boolean,
|
||||
OUT bucket int8, -- 0
|
||||
OUT userid oid,
|
||||
OUT username text,
|
||||
OUT dbid oid,
|
||||
OUT datname text,
|
||||
OUT client_ip int8,
|
||||
|
||||
OUT queryid int8, -- 4
|
||||
OUT planid int8,
|
||||
OUT query text,
|
||||
OUT query_plan text,
|
||||
OUT pgsm_query_id int8,
|
||||
OUT top_queryid int8,
|
||||
OUT top_query text,
|
||||
OUT application_name text,
|
||||
|
||||
OUT relations text, -- 11
|
||||
OUT cmd_type int,
|
||||
OUT elevel int,
|
||||
OUT sqlcode TEXT,
|
||||
OUT message text,
|
||||
OUT bucket_start_time timestamptz,
|
||||
|
||||
OUT calls int8, -- 16
|
||||
|
||||
OUT total_exec_time float8,
|
||||
OUT min_exec_time float8,
|
||||
OUT max_exec_time float8,
|
||||
OUT mean_exec_time float8,
|
||||
OUT stddev_exec_time float8,
|
||||
|
||||
OUT rows int8,
|
||||
|
||||
OUT plans int8, -- 23
|
||||
|
||||
OUT total_plan_time float8,
|
||||
OUT min_plan_time float8,
|
||||
OUT max_plan_time float8,
|
||||
OUT mean_plan_time float8,
|
||||
OUT stddev_plan_time float8,
|
||||
|
||||
OUT shared_blks_hit int8, -- 29
|
||||
OUT shared_blks_read int8,
|
||||
OUT shared_blks_dirtied int8,
|
||||
OUT shared_blks_written int8,
|
||||
OUT local_blks_hit int8,
|
||||
OUT local_blks_read int8,
|
||||
OUT local_blks_dirtied int8,
|
||||
OUT local_blks_written int8,
|
||||
OUT temp_blks_read int8,
|
||||
OUT temp_blks_written int8,
|
||||
OUT blk_read_time float8,
|
||||
OUT blk_write_time float8,
|
||||
|
||||
OUT temp_blk_read_time float8,
|
||||
OUT temp_blk_write_time float8,
|
||||
|
||||
OUT resp_calls text, -- 41
|
||||
OUT cpu_user_time float8,
|
||||
OUT cpu_sys_time float8,
|
||||
OUT wal_records int8,
|
||||
OUT wal_fpi int8,
|
||||
OUT wal_bytes numeric,
|
||||
OUT comments TEXT,
|
||||
|
||||
OUT jit_functions int8,
|
||||
OUT jit_generation_time float8,
|
||||
OUT jit_inlining_count int8,
|
||||
OUT jit_inlining_time float8,
|
||||
OUT jit_optimization_count int8,
|
||||
OUT jit_optimization_time float8,
|
||||
OUT jit_emission_count int8,
|
||||
OUT jit_emission_time float8,
|
||||
|
||||
OUT toplevel BOOLEAN,
|
||||
OUT bucket_done BOOLEAN
|
||||
)
|
||||
RETURNS SETOF record
|
||||
AS 'MODULE_PATHNAME', 'pg_stat_monitor_2_0'
|
||||
LANGUAGE C STRICT VOLATILE PARALLEL SAFE;
|
||||
|
||||
-- Register a view on the function for ease of use.
|
||||
CREATE FUNCTION pgsm_create_11_view() RETURNS INT AS
|
||||
$$
|
||||
BEGIN
|
||||
CREATE VIEW pg_stat_monitor AS SELECT
|
||||
bucket,
|
||||
bucket_start_time AS bucket_start_time,
|
||||
userid,
|
||||
username,
|
||||
dbid,
|
||||
datname,
|
||||
'0.0.0.0'::inet + client_ip AS client_ip,
|
||||
pgsm_query_id,
|
||||
queryid,
|
||||
top_queryid,
|
||||
query,
|
||||
comments,
|
||||
planid,
|
||||
query_plan,
|
||||
top_query,
|
||||
application_name,
|
||||
string_to_array(relations, ',') AS relations,
|
||||
cmd_type,
|
||||
get_cmd_type(cmd_type) AS cmd_type_text,
|
||||
elevel,
|
||||
sqlcode,
|
||||
message,
|
||||
calls,
|
||||
total_exec_time AS total_time,
|
||||
min_exec_time AS min_time,
|
||||
max_exec_time AS max_time,
|
||||
mean_exec_time AS mean_time,
|
||||
stddev_exec_time AS stddev_time,
|
||||
rows,
|
||||
shared_blks_hit,
|
||||
shared_blks_read,
|
||||
shared_blks_dirtied,
|
||||
shared_blks_written,
|
||||
local_blks_hit,
|
||||
local_blks_read,
|
||||
local_blks_dirtied,
|
||||
local_blks_written,
|
||||
temp_blks_read,
|
||||
temp_blks_written,
|
||||
blk_read_time,
|
||||
blk_write_time,
|
||||
(string_to_array(resp_calls, ',')) resp_calls,
|
||||
cpu_user_time,
|
||||
cpu_sys_time,
|
||||
bucket_done
|
||||
FROM pg_stat_monitor_internal(TRUE)
|
||||
ORDER BY bucket_start_time;
|
||||
RETURN 0;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
|
||||
CREATE FUNCTION pgsm_create_13_view() RETURNS INT AS
|
||||
$$
|
||||
BEGIN
|
||||
CREATE VIEW pg_stat_monitor AS SELECT
|
||||
bucket,
|
||||
bucket_start_time AS bucket_start_time,
|
||||
userid,
|
||||
username,
|
||||
dbid,
|
||||
datname,
|
||||
'0.0.0.0'::inet + client_ip AS client_ip,
|
||||
pgsm_query_id,
|
||||
queryid,
|
||||
toplevel,
|
||||
top_queryid,
|
||||
query,
|
||||
comments,
|
||||
planid,
|
||||
query_plan,
|
||||
top_query,
|
||||
application_name,
|
||||
string_to_array(relations, ',') AS relations,
|
||||
cmd_type,
|
||||
get_cmd_type(cmd_type) AS cmd_type_text,
|
||||
elevel,
|
||||
sqlcode,
|
||||
message,
|
||||
calls,
|
||||
total_exec_time,
|
||||
min_exec_time,
|
||||
max_exec_time,
|
||||
mean_exec_time,
|
||||
stddev_exec_time,
|
||||
rows,
|
||||
shared_blks_hit,
|
||||
shared_blks_read,
|
||||
shared_blks_dirtied,
|
||||
shared_blks_written,
|
||||
local_blks_hit,
|
||||
local_blks_read,
|
||||
local_blks_dirtied,
|
||||
local_blks_written,
|
||||
temp_blks_read,
|
||||
temp_blks_written,
|
||||
blk_read_time,
|
||||
blk_write_time,
|
||||
(string_to_array(resp_calls, ',')) resp_calls,
|
||||
cpu_user_time,
|
||||
cpu_sys_time,
|
||||
wal_records,
|
||||
wal_fpi,
|
||||
wal_bytes,
|
||||
bucket_done,
|
||||
-- PostgreSQL-13 Specific Coulumns
|
||||
plans,
|
||||
total_plan_time,
|
||||
min_plan_time,
|
||||
max_plan_time,
|
||||
mean_plan_time,
|
||||
stddev_plan_time
|
||||
FROM pg_stat_monitor_internal(TRUE)
|
||||
ORDER BY bucket_start_time;
|
||||
RETURN 0;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
CREATE FUNCTION pgsm_create_14_view() RETURNS INT AS
|
||||
$$
|
||||
BEGIN
|
||||
CREATE VIEW pg_stat_monitor AS SELECT
|
||||
bucket,
|
||||
bucket_start_time AS bucket_start_time,
|
||||
userid,
|
||||
username,
|
||||
dbid,
|
||||
datname,
|
||||
'0.0.0.0'::inet + client_ip AS client_ip,
|
||||
pgsm_query_id,
|
||||
queryid,
|
||||
toplevel,
|
||||
top_queryid,
|
||||
query,
|
||||
comments,
|
||||
planid,
|
||||
query_plan,
|
||||
top_query,
|
||||
application_name,
|
||||
string_to_array(relations, ',') AS relations,
|
||||
cmd_type,
|
||||
get_cmd_type(cmd_type) AS cmd_type_text,
|
||||
elevel,
|
||||
sqlcode,
|
||||
message,
|
||||
calls,
|
||||
total_exec_time,
|
||||
min_exec_time,
|
||||
max_exec_time,
|
||||
mean_exec_time,
|
||||
stddev_exec_time,
|
||||
rows,
|
||||
shared_blks_hit,
|
||||
shared_blks_read,
|
||||
shared_blks_dirtied,
|
||||
shared_blks_written,
|
||||
local_blks_hit,
|
||||
local_blks_read,
|
||||
local_blks_dirtied,
|
||||
local_blks_written,
|
||||
temp_blks_read,
|
||||
temp_blks_written,
|
||||
blk_read_time,
|
||||
blk_write_time,
|
||||
(string_to_array(resp_calls, ',')) resp_calls,
|
||||
cpu_user_time,
|
||||
cpu_sys_time,
|
||||
wal_records,
|
||||
wal_fpi,
|
||||
wal_bytes,
|
||||
bucket_done,
|
||||
|
||||
plans,
|
||||
total_plan_time,
|
||||
min_plan_time,
|
||||
max_plan_time,
|
||||
mean_plan_time,
|
||||
stddev_plan_time
|
||||
FROM pg_stat_monitor_internal(TRUE)
|
||||
ORDER BY bucket_start_time;
|
||||
RETURN 0;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
CREATE FUNCTION pgsm_create_15_view() RETURNS INT AS
|
||||
$$
|
||||
BEGIN
|
||||
CREATE VIEW pg_stat_monitor AS SELECT
|
||||
bucket,
|
||||
bucket_start_time AS bucket_start_time,
|
||||
userid,
|
||||
username,
|
||||
dbid,
|
||||
datname,
|
||||
'0.0.0.0'::inet + client_ip AS client_ip,
|
||||
pgsm_query_id,
|
||||
queryid,
|
||||
toplevel,
|
||||
top_queryid,
|
||||
query,
|
||||
comments,
|
||||
planid,
|
||||
query_plan,
|
||||
top_query,
|
||||
application_name,
|
||||
string_to_array(relations, ',') AS relations,
|
||||
cmd_type,
|
||||
get_cmd_type(cmd_type) AS cmd_type_text,
|
||||
elevel,
|
||||
sqlcode,
|
||||
message,
|
||||
calls,
|
||||
total_exec_time,
|
||||
min_exec_time,
|
||||
max_exec_time,
|
||||
mean_exec_time,
|
||||
stddev_exec_time,
|
||||
rows,
|
||||
shared_blks_hit,
|
||||
shared_blks_read,
|
||||
shared_blks_dirtied,
|
||||
shared_blks_written,
|
||||
local_blks_hit,
|
||||
local_blks_read,
|
||||
local_blks_dirtied,
|
||||
local_blks_written,
|
||||
temp_blks_read,
|
||||
temp_blks_written,
|
||||
blk_read_time,
|
||||
blk_write_time,
|
||||
temp_blk_read_time,
|
||||
temp_blk_write_time,
|
||||
|
||||
(string_to_array(resp_calls, ',')) resp_calls,
|
||||
cpu_user_time,
|
||||
cpu_sys_time,
|
||||
wal_records,
|
||||
wal_fpi,
|
||||
wal_bytes,
|
||||
bucket_done,
|
||||
|
||||
plans,
|
||||
total_plan_time,
|
||||
min_plan_time,
|
||||
max_plan_time,
|
||||
mean_plan_time,
|
||||
stddev_plan_time,
|
||||
|
||||
jit_functions,
|
||||
jit_generation_time,
|
||||
jit_inlining_count,
|
||||
jit_inlining_time,
|
||||
jit_optimization_count,
|
||||
jit_optimization_time,
|
||||
jit_emission_count,
|
||||
jit_emission_time
|
||||
|
||||
FROM pg_stat_monitor_internal(TRUE)
|
||||
ORDER BY bucket_start_time;
|
||||
RETURN 0;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
CREATE FUNCTION pgsm_create_view() RETURNS INT AS
|
||||
$$
|
||||
DECLARE ver integer;
|
||||
BEGIN
|
||||
SELECT current_setting('server_version_num') INTO ver;
|
||||
IF (ver >= 150000) THEN
|
||||
return pgsm_create_15_view();
|
||||
END IF;
|
||||
IF (ver >= 140000) THEN
|
||||
return pgsm_create_14_view();
|
||||
END IF;
|
||||
IF (ver >= 130000) THEN
|
||||
return pgsm_create_13_view();
|
||||
END IF;
|
||||
IF (ver >= 110000) THEN
|
||||
return pgsm_create_11_view();
|
||||
END IF;
|
||||
RETURN 0;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
SELECT pgsm_create_view();
|
||||
REVOKE ALL ON FUNCTION pgsm_create_view FROM PUBLIC;
|
||||
REVOKE ALL ON FUNCTION pgsm_create_11_view FROM PUBLIC;
|
||||
REVOKE ALL ON FUNCTION pgsm_create_13_view FROM PUBLIC;
|
||||
REVOKE ALL ON FUNCTION pgsm_create_14_view FROM PUBLIC;
|
||||
REVOKE ALL ON FUNCTION pgsm_create_15_view FROM PUBLIC;
|
||||
|
||||
GRANT EXECUTE ON FUNCTION range TO PUBLIC;
|
||||
GRANT EXECUTE ON FUNCTION decode_error_level TO PUBLIC;
|
||||
GRANT EXECUTE ON FUNCTION get_histogram_timings TO PUBLIC;
|
||||
GRANT EXECUTE ON FUNCTION get_cmd_type TO PUBLIC;
|
||||
GRANT EXECUTE ON FUNCTION pg_stat_monitor_internal TO PUBLIC;
|
||||
|
||||
GRANT SELECT ON pg_stat_monitor TO PUBLIC;
|
||||
|
||||
-- Reset is only available to super user
|
||||
REVOKE ALL ON FUNCTION pg_stat_monitor_reset FROM PUBLIC;
|
||||
|
|
@ -1,48 +0,0 @@
|
|||
/* contrib/pg_stat_monitor/pg_stat_monitor--2.1--2.2.sql */
|
||||
|
||||
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
|
||||
\echo Use "ALTER EXTENSION pg_stat_monitor" to load this file. \quit
|
||||
|
||||
CREATE OR REPLACE FUNCTION get_cmd_type (cmd_type INTEGER) RETURNS TEXT AS
|
||||
$$
|
||||
SELECT
|
||||
CASE
|
||||
WHEN cmd_type = 0 THEN ''
|
||||
WHEN cmd_type = 1 THEN 'SELECT'
|
||||
WHEN cmd_type = 2 THEN 'UPDATE'
|
||||
WHEN cmd_type = 3 THEN 'INSERT'
|
||||
WHEN cmd_type = 4 THEN 'DELETE'
|
||||
WHEN cmd_type = 5 AND current_setting('server_version_num')::int >= 150000 THEN 'MERGE'
|
||||
WHEN cmd_type = 5 AND current_setting('server_version_num')::int < 150000 THEN 'UTILITY'
|
||||
WHEN cmd_type = 6 AND current_setting('server_version_num')::int >= 150000 THEN 'UTILITY'
|
||||
WHEN cmd_type = 6 AND current_setting('server_version_num')::int < 150000 THEN 'NOTHING'
|
||||
WHEN cmd_type = 7 THEN 'NOTHING'
|
||||
END
|
||||
$$
|
||||
LANGUAGE SQL PARALLEL SAFE;
|
||||
|
||||
-- Create new function that handles error levels across PostgreSQL versions 12-17
|
||||
CREATE OR REPLACE FUNCTION decode_error_level(elevel int)
|
||||
RETURNS text
|
||||
AS $$
|
||||
SELECT CASE
|
||||
WHEN elevel = 0 THEN ''
|
||||
WHEN elevel = 10 THEN 'DEBUG5'
|
||||
WHEN elevel = 11 THEN 'DEBUG4'
|
||||
WHEN elevel = 12 THEN 'DEBUG3'
|
||||
WHEN elevel = 13 THEN 'DEBUG2'
|
||||
WHEN elevel = 14 THEN 'DEBUG1'
|
||||
WHEN elevel = 15 THEN 'LOG'
|
||||
WHEN elevel = 16 THEN 'LOG_SERVER_ONLY'
|
||||
WHEN elevel = 17 THEN 'INFO'
|
||||
WHEN elevel = 18 THEN 'NOTICE'
|
||||
WHEN elevel = 19 THEN 'WARNING'
|
||||
WHEN elevel = 20 AND current_setting('server_version_num')::int < 140000 THEN 'ERROR'
|
||||
WHEN elevel = 20 AND current_setting('server_version_num')::int >= 140000 THEN 'WARNING_CLIENT_ONLY'
|
||||
WHEN elevel = 21 AND current_setting('server_version_num')::int < 140000 THEN 'FATAL'
|
||||
WHEN elevel = 21 AND current_setting('server_version_num')::int >= 140000 THEN 'ERROR'
|
||||
WHEN elevel = 22 AND current_setting('server_version_num')::int < 140000 THEN 'PANIC'
|
||||
WHEN elevel = 22 AND current_setting('server_version_num')::int >= 140000 THEN 'FATAL'
|
||||
WHEN elevel = 23 AND current_setting('server_version_num')::int >= 140000 THEN 'PANIC'
|
||||
END;
|
||||
$$ LANGUAGE SQL PARALLEL SAFE;
|
||||
|
|
@ -1,221 +0,0 @@
|
|||
/* contrib/pg_stat_monitor/pg_stat_monitor--2.2--2.3.sql */
|
||||
|
||||
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
|
||||
\echo Use "ALTER EXTENSION pg_stat_monitor" to load this file. \quit
|
||||
|
||||
DROP FUNCTION pgsm_create_11_view();
|
||||
DROP VIEW pg_stat_monitor;
|
||||
DROP FUNCTION pg_stat_monitor_internal;
|
||||
|
||||
CREATE FUNCTION pg_stat_monitor_internal(
|
||||
IN showtext boolean,
|
||||
OUT bucket int8, -- 0
|
||||
OUT userid oid,
|
||||
OUT username text,
|
||||
OUT dbid oid,
|
||||
OUT datname text,
|
||||
OUT client_ip int8,
|
||||
|
||||
OUT queryid int8, -- 6
|
||||
OUT planid int8,
|
||||
OUT query text,
|
||||
OUT query_plan text,
|
||||
OUT pgsm_query_id int8,
|
||||
OUT top_queryid int8,
|
||||
OUT top_query text,
|
||||
OUT application_name text,
|
||||
|
||||
OUT relations text, -- 14
|
||||
OUT cmd_type int,
|
||||
OUT elevel int,
|
||||
OUT sqlcode TEXT,
|
||||
OUT message text,
|
||||
OUT bucket_start_time timestamptz,
|
||||
|
||||
OUT calls int8, -- 20
|
||||
|
||||
OUT total_exec_time float8, -- 21
|
||||
OUT min_exec_time float8,
|
||||
OUT max_exec_time float8,
|
||||
OUT mean_exec_time float8,
|
||||
OUT stddev_exec_time float8,
|
||||
|
||||
OUT rows int8, -- 26
|
||||
|
||||
OUT plans int8, -- 27
|
||||
|
||||
OUT total_plan_time float8, -- 28
|
||||
OUT min_plan_time float8,
|
||||
OUT max_plan_time float8,
|
||||
OUT mean_plan_time float8,
|
||||
OUT stddev_plan_time float8,
|
||||
|
||||
OUT shared_blks_hit int8, -- 33
|
||||
OUT shared_blks_read int8,
|
||||
OUT shared_blks_dirtied int8,
|
||||
OUT shared_blks_written int8,
|
||||
OUT local_blks_hit int8,
|
||||
OUT local_blks_read int8,
|
||||
OUT local_blks_dirtied int8,
|
||||
OUT local_blks_written int8,
|
||||
OUT temp_blks_read int8,
|
||||
OUT temp_blks_written int8,
|
||||
OUT shared_blk_read_time float8,
|
||||
OUT shared_blk_write_time float8,
|
||||
OUT local_blk_read_time float8,
|
||||
OUT local_blk_write_time float8,
|
||||
OUT temp_blk_read_time float8,
|
||||
OUT temp_blk_write_time float8,
|
||||
|
||||
OUT resp_calls text, -- 49
|
||||
OUT cpu_user_time float8,
|
||||
OUT cpu_sys_time float8,
|
||||
OUT wal_records int8,
|
||||
OUT wal_fpi int8,
|
||||
OUT wal_bytes numeric,
|
||||
OUT wal_buffers_full int8,
|
||||
OUT comments TEXT,
|
||||
|
||||
OUT jit_functions int8, -- 57
|
||||
OUT jit_generation_time float8,
|
||||
OUT jit_inlining_count int8,
|
||||
OUT jit_inlining_time float8,
|
||||
OUT jit_optimization_count int8,
|
||||
OUT jit_optimization_time float8,
|
||||
OUT jit_emission_count int8,
|
||||
OUT jit_emission_time float8,
|
||||
OUT jit_deform_count int8,
|
||||
OUT jit_deform_time float8,
|
||||
|
||||
OUT parallel_workers_to_launch int, -- 67
|
||||
OUT parallel_workers_launched int,
|
||||
|
||||
OUT stats_since timestamp with time zone, -- 69
|
||||
OUT minmax_stats_since timestamp with time zone,
|
||||
|
||||
OUT toplevel BOOLEAN, -- 71
|
||||
OUT bucket_done BOOLEAN
|
||||
)
|
||||
RETURNS SETOF record
|
||||
AS 'MODULE_PATHNAME', 'pg_stat_monitor_2_3'
|
||||
LANGUAGE C STRICT VOLATILE PARALLEL SAFE;
|
||||
|
||||
CREATE FUNCTION pgsm_create_18_view() RETURNS INT AS
|
||||
$$
|
||||
BEGIN
|
||||
CREATE VIEW pg_stat_monitor AS SELECT
|
||||
bucket,
|
||||
bucket_start_time,
|
||||
userid,
|
||||
username,
|
||||
dbid,
|
||||
datname,
|
||||
'0.0.0.0'::inet + client_ip AS client_ip,
|
||||
pgsm_query_id,
|
||||
queryid,
|
||||
toplevel,
|
||||
top_queryid,
|
||||
query,
|
||||
comments,
|
||||
planid,
|
||||
query_plan,
|
||||
top_query,
|
||||
application_name,
|
||||
string_to_array(relations, ',') AS relations,
|
||||
cmd_type,
|
||||
get_cmd_type(cmd_type) AS cmd_type_text,
|
||||
elevel,
|
||||
sqlcode,
|
||||
message,
|
||||
calls,
|
||||
total_exec_time,
|
||||
min_exec_time,
|
||||
max_exec_time,
|
||||
mean_exec_time,
|
||||
stddev_exec_time,
|
||||
rows,
|
||||
shared_blks_hit,
|
||||
shared_blks_read,
|
||||
shared_blks_dirtied,
|
||||
shared_blks_written,
|
||||
local_blks_hit,
|
||||
local_blks_read,
|
||||
local_blks_dirtied,
|
||||
local_blks_written,
|
||||
temp_blks_read,
|
||||
temp_blks_written,
|
||||
shared_blk_read_time,
|
||||
shared_blk_write_time,
|
||||
local_blk_read_time,
|
||||
local_blk_write_time,
|
||||
temp_blk_read_time,
|
||||
temp_blk_write_time,
|
||||
|
||||
(string_to_array(resp_calls, ',')) resp_calls,
|
||||
cpu_user_time,
|
||||
cpu_sys_time,
|
||||
wal_records,
|
||||
wal_fpi,
|
||||
wal_bytes,
|
||||
wal_buffers_full,
|
||||
bucket_done,
|
||||
|
||||
plans,
|
||||
total_plan_time,
|
||||
min_plan_time,
|
||||
max_plan_time,
|
||||
mean_plan_time,
|
||||
stddev_plan_time,
|
||||
|
||||
jit_functions,
|
||||
jit_generation_time,
|
||||
jit_inlining_count,
|
||||
jit_inlining_time,
|
||||
jit_optimization_count,
|
||||
jit_optimization_time,
|
||||
jit_emission_count,
|
||||
jit_emission_time,
|
||||
jit_deform_count,
|
||||
jit_deform_time,
|
||||
|
||||
parallel_workers_to_launch,
|
||||
parallel_workers_launched,
|
||||
|
||||
stats_since,
|
||||
minmax_stats_since
|
||||
|
||||
FROM pg_stat_monitor_internal(TRUE)
|
||||
ORDER BY bucket_start_time;
|
||||
RETURN 0;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
CREATE OR REPLACE FUNCTION pgsm_create_view() RETURNS INT AS
|
||||
$$
|
||||
DECLARE ver integer;
|
||||
BEGIN
|
||||
SELECT current_setting('server_version_num') INTO ver;
|
||||
IF (ver >= 180000) THEN
|
||||
return pgsm_create_18_view();
|
||||
END IF;
|
||||
IF (ver >= 170000) THEN
|
||||
return pgsm_create_17_view();
|
||||
END IF;
|
||||
IF (ver >= 150000) THEN
|
||||
return pgsm_create_15_view();
|
||||
END IF;
|
||||
IF (ver >= 140000) THEN
|
||||
return pgsm_create_14_view();
|
||||
END IF;
|
||||
IF (ver >= 130000) THEN
|
||||
return pgsm_create_13_view();
|
||||
END IF;
|
||||
RETURN 0;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
SELECT pgsm_create_view();
|
||||
REVOKE ALL ON FUNCTION pgsm_create_view FROM PUBLIC;
|
||||
REVOKE ALL ON FUNCTION pgsm_create_18_view FROM PUBLIC;
|
||||
|
||||
GRANT SELECT ON pg_stat_monitor TO PUBLIC;
|
||||
3561
pg_stat_monitor.c
3561
pg_stat_monitor.c
File diff suppressed because it is too large
Load Diff
|
|
@ -1,5 +1,5 @@
|
|||
# pg_stat_monitor extension
|
||||
comment = 'The pg_stat_monitor is a PostgreSQL Query Performance Monitoring tool, based on PostgreSQL contrib module pg_stat_statements. pg_stat_monitor provides aggregated statistics, client information, plan details including plan, and histogram information.'
|
||||
default_version = '2.3'
|
||||
default_version = '1.0'
|
||||
module_pathname = '$libdir/pg_stat_monitor'
|
||||
relocatable = true
|
||||
|
|
|
|||
|
|
@ -3,9 +3,9 @@
|
|||
* pg_stat_monitor.h
|
||||
* Track statement execution times across a whole database cluster.
|
||||
*
|
||||
* Portions Copyright © 2018-2025, Percona LLC and/or its affiliates
|
||||
* Portions Copyright © 2018-2020, Percona LLC and/or its affiliates
|
||||
*
|
||||
* Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1996-2020, PostgreSQL Global Development Group
|
||||
*
|
||||
* Portions Copyright (c) 1994, The Regents of the University of California
|
||||
*
|
||||
|
|
@ -27,14 +27,10 @@
|
|||
#include <sys/time.h>
|
||||
#include <sys/resource.h>
|
||||
|
||||
#include "lib/dshash.h"
|
||||
#include "utils/dsa.h"
|
||||
|
||||
#include "access/hash.h"
|
||||
#include "catalog/pg_authid.h"
|
||||
#include "executor/instrument.h"
|
||||
#include "common/ip.h"
|
||||
#include "jit/jit.h"
|
||||
#include "funcapi.h"
|
||||
#include "access/twophase.h"
|
||||
#include "mb/pg_wchar.h"
|
||||
|
|
@ -57,9 +53,6 @@
|
|||
#include "utils/lsyscache.h"
|
||||
#include "utils/guc.h"
|
||||
#include "utils/guc_tables.h"
|
||||
#include "utils/memutils.h"
|
||||
#include "utils/palloc.h"
|
||||
|
||||
|
||||
#define MAX_BACKEND_PROCESES (MaxBackends + NUM_AUXILIARY_PROCS + max_prepared_xacts)
|
||||
#define IntArrayGetTextDatum(x,y) intarray_get_datum(x,y)
|
||||
|
|
@ -67,6 +60,7 @@
|
|||
/* XXX: Should USAGE_EXEC reflect execution time and/or buffer usage? */
|
||||
#define USAGE_EXEC(duration) (1.0)
|
||||
#define USAGE_INIT (1.0) /* including initial planning */
|
||||
#define ASSUMED_MEDIAN_INIT (10.0) /* initial assumed median usage */
|
||||
#define ASSUMED_LENGTH_INIT 1024 /* initial assumed mean query length */
|
||||
#define USAGE_DECREASE_FACTOR (0.99) /* decreased every entry_dealloc */
|
||||
#define STICKY_DECREASE_FACTOR (0.50) /* factor for sticky entries */
|
||||
|
|
@ -74,87 +68,90 @@
|
|||
|
||||
#define JUMBLE_SIZE 1024 /* query serialization buffer size */
|
||||
|
||||
#define HISTOGRAM_MAX_TIME 50000000
|
||||
#define MAX_RESPONSE_BUCKET 50
|
||||
#define INVALID_BUCKET_ID -1
|
||||
#define MAX_REL_LEN 255
|
||||
#define MAX_BUCKETS 10
|
||||
#define TEXT_LEN 255
|
||||
#define ERROR_MESSAGE_LEN 100
|
||||
#define REL_TYPENAME_LEN 64
|
||||
#define REL_LST 10
|
||||
#define REL_LEN 132 /* REL_TYPENAME_LEN * 2 (relname + schema) + 1
|
||||
* (for view indication) + 1 and dot and
|
||||
* string terminator */
|
||||
#define REL_LEN 1000
|
||||
#define CMD_LST 10
|
||||
#define CMD_LEN 20
|
||||
#define APPLICATIONNAME_LEN NAMEDATALEN
|
||||
#define COMMENTS_LEN 256
|
||||
#define APPLICATIONNAME_LEN 100
|
||||
#define COMMENTS_LEN 512
|
||||
#define PGSM_OVER_FLOW_MAX 10
|
||||
#define PLAN_TEXT_LEN 1024
|
||||
/* the assumption of query max nested level */
|
||||
#define DEFAULT_MAX_NESTED_LEVEL 10
|
||||
|
||||
#define MAX_QUERY_BUF ((int64)pgsm_query_shared_buffer * 1024 * 1024)
|
||||
#define MAX_BUCKETS_MEM ((int64)pgsm_max * 1024 * 1024)
|
||||
#define BUCKETS_MEM_OVERFLOW() ((hash_get_num_entries(pgsm_hash) * sizeof(pgsmEntry)) >= MAX_BUCKETS_MEM)
|
||||
#define MAX_BUCKET_ENTRIES (MAX_BUCKETS_MEM / sizeof(pgsmEntry))
|
||||
#define MAX_QUERY_BUF (PGSM_QUERY_SHARED_BUFFER * 1024 * 1024)
|
||||
#define MAX_BUCKETS_MEM (PGSM_MAX * 1024 * 1024)
|
||||
#define BUCKETS_MEM_OVERFLOW() ((hash_get_num_entries(pgss_hash) * sizeof(pgssEntry)) >= MAX_BUCKETS_MEM)
|
||||
#define MAX_BUCKET_ENTRIES (MAX_BUCKETS_MEM / sizeof(pgssEntry))
|
||||
#define QUERY_BUFFER_OVERFLOW(x,y) ((x + y + sizeof(uint64) + sizeof(uint64)) > MAX_QUERY_BUF)
|
||||
#define QUERY_MARGIN 100
|
||||
#define MIN_QUERY_LEN 10
|
||||
#define SQLCODE_LEN 20
|
||||
#define TOTAL_RELS_LENGTH (REL_LST * REL_LEN)
|
||||
|
||||
#if PG_VERSION_NUM >= 130000
|
||||
#define MAX_SETTINGS 15
|
||||
#else
|
||||
#define MAX_SETTINGS 14
|
||||
#endif
|
||||
|
||||
/* Update this if need a enum GUC with more options. */
|
||||
#define MAX_ENUM_OPTIONS 6
|
||||
typedef struct GucVariables
|
||||
{
|
||||
enum config_type type; /* PGC_BOOL, PGC_INT, PGC_REAL, PGC_STRING,
|
||||
* PGC_ENUM */
|
||||
int guc_variable;
|
||||
char guc_name[TEXT_LEN];
|
||||
char guc_desc[TEXT_LEN];
|
||||
int guc_default;
|
||||
int guc_min;
|
||||
int guc_max;
|
||||
int guc_unit;
|
||||
int *guc_value;
|
||||
bool guc_restart;
|
||||
int n_options;
|
||||
char guc_options[MAX_ENUM_OPTIONS][32];
|
||||
} GucVariable;
|
||||
|
||||
/*
|
||||
* pg_stat_monitor uses the hash structure to store all query statistics
|
||||
* except the query text, which gets stored out of line in the raw DSA area.
|
||||
* Enabling USE_DYNAMIC_HASH uses the dshash for storing the query statistics
|
||||
* that get created in the DSA area and can grow to any size.
|
||||
*
|
||||
* The only issue with using the dshash is that the newly created hash entries
|
||||
* are explicitly locked by dshash, and its caller is required to release the lock.
|
||||
* That works well as long as we do not want to swallow the errors thrown from
|
||||
* dshash function. Since the lightweight locks acquired internally by dshash
|
||||
* automatically get released by error.
|
||||
* But throwing an error from pg_stat_monitor would mean erroring out the user query,
|
||||
* which is not acceptable for any stat collector extension.
|
||||
*
|
||||
* Moreover, some of the pg_stat_monitor functions perform the sequence scan on the
|
||||
* hash table, while the sequence scan support for dshash table is only available
|
||||
* for PG 15 and onwards.
|
||||
* So until we figure out the way to release the locks acquired internally by dshash
|
||||
* in case of an error while ignoring the error at the same time, we will keep using
|
||||
* the classic shared memory hash table.
|
||||
*/
|
||||
#ifdef USE_DYNAMIC_HASH
|
||||
#define PGSM_HASH_TABLE dshash_table
|
||||
#define PGSM_HASH_TABLE_HANDLE dshash_table_handle
|
||||
#define PGSM_HASH_SEQ_STATUS dshash_seq_status
|
||||
#else
|
||||
#define PGSM_HASH_TABLE HTAB
|
||||
#define PGSM_HASH_TABLE_HANDLE HTAB*
|
||||
#define PGSM_HASH_SEQ_STATUS HASH_SEQ_STATUS
|
||||
|
||||
#if PG_VERSION_NUM < 130000
|
||||
typedef struct WalUsage
|
||||
{
|
||||
long wal_records; /* # of WAL records produced */
|
||||
long wal_fpi; /* # of WAL full page images produced */
|
||||
uint64 wal_bytes; /* size of WAL records produced */
|
||||
} WalUsage;
|
||||
#endif
|
||||
|
||||
typedef enum pgsmStoreKind
|
||||
typedef enum OVERFLOW_TARGET
|
||||
{
|
||||
PGSM_INVALID = -1,
|
||||
OVERFLOW_TARGET_NONE = 0,
|
||||
OVERFLOW_TARGET_DISK
|
||||
} OVERFLOW_TARGET;
|
||||
|
||||
typedef enum pgssStoreKind
|
||||
{
|
||||
PGSS_INVALID = -1,
|
||||
|
||||
/*
|
||||
* PGSM_PLAN and PGSM_EXEC must be respectively 0 and 1 as they're used to
|
||||
* PGSS_PLAN and PGSS_EXEC must be respectively 0 and 1 as they're used to
|
||||
* reference the underlying values in the arrays in the Counters struct,
|
||||
* and this order is required in pg_stat_monitor_internal().
|
||||
* and this order is required in pg_stat_statements_internal().
|
||||
*/
|
||||
PGSM_PARSE = 0,
|
||||
PGSM_PLAN,
|
||||
PGSM_EXEC,
|
||||
PGSM_STORE,
|
||||
PGSM_ERROR,
|
||||
} pgsmStoreKind;
|
||||
PGSS_PARSE = 0,
|
||||
PGSS_PLAN,
|
||||
PGSS_EXEC,
|
||||
PGSS_FINISHED,
|
||||
PGSS_ERROR,
|
||||
|
||||
#define PGSM_NUMKIND (PGSM_ERROR + 1)
|
||||
PGSS_NUMKIND /* Must be last value of this enum */
|
||||
} pgssStoreKind;
|
||||
|
||||
/* the assumption of query max nested level */
|
||||
#define DEFAULT_MAX_NESTED_LEVEL 10
|
||||
|
|
@ -181,30 +178,43 @@ typedef struct CallTime
|
|||
double sum_var_time; /* sum of variances in execution time in msec */
|
||||
} CallTime;
|
||||
|
||||
/*
|
||||
* Entry type for queries hash table (query ID).
|
||||
*
|
||||
* We use a hash table to keep track of query IDs that have their
|
||||
* corresponding query text added to the query buffer (pgsm_query_shared_buffer).
|
||||
*
|
||||
* This allow us to avoid adding duplicated queries to the buffer, therefore
|
||||
* leaving more space for other queries and saving some CPU.
|
||||
*/
|
||||
typedef struct pgssQueryEntry
|
||||
{
|
||||
uint64 queryid; /* query identifier, also the key. */
|
||||
size_t query_pos; /* query location within query buffer */
|
||||
} pgssQueryEntry;
|
||||
|
||||
typedef struct PlanInfo
|
||||
{
|
||||
int64 planid; /* plan identifier */
|
||||
uint64 planid; /* plan identifier */
|
||||
char plan_text[PLAN_TEXT_LEN]; /* plan text */
|
||||
size_t plan_len; /* strlen(plan_text) */
|
||||
} PlanInfo;
|
||||
|
||||
typedef struct pgsmHashKey
|
||||
typedef struct pgssHashKey
|
||||
{
|
||||
uint64 bucket_id; /* bucket number */
|
||||
int64 queryid; /* query identifier */
|
||||
int64 planid; /* plan identifier */
|
||||
int64 appid; /* hash of application name */
|
||||
Oid userid; /* user OID */
|
||||
Oid dbid; /* database OID */
|
||||
uint32 ip; /* client ip address */
|
||||
bool toplevel; /* query executed at top level */
|
||||
int64 parentid; /* parent queryId of current query */
|
||||
} pgsmHashKey;
|
||||
uint64 queryid; /* query identifier */
|
||||
uint64 userid; /* user OID */
|
||||
uint64 dbid; /* database OID */
|
||||
uint64 ip; /* client ip address */
|
||||
uint64 planid; /* plan identifier */
|
||||
uint64 appid; /* hash of application name */
|
||||
uint64 toplevel; /* query executed at top level */
|
||||
} pgssHashKey;
|
||||
|
||||
typedef struct QueryInfo
|
||||
{
|
||||
dsa_pointer parent_query;
|
||||
uint64 parentid; /* parent queryid of current query */
|
||||
int64 type; /* type of query, options are query, info,
|
||||
* warning, error, fatal */
|
||||
char application_name[APPLICATIONNAME_LEN];
|
||||
|
|
@ -243,64 +253,14 @@ typedef struct Blocks
|
|||
int64 local_blks_written; /* # of local disk blocks written */
|
||||
int64 temp_blks_read; /* # of temp blocks read */
|
||||
int64 temp_blks_written; /* # of temp blocks written */
|
||||
double shared_blk_read_time; /* time spent reading shared blocks,
|
||||
* in msec */
|
||||
double shared_blk_write_time; /* time spent writing shared blocks,
|
||||
* in msec */
|
||||
double local_blk_read_time; /* time spent reading local blocks, in
|
||||
* msec */
|
||||
double local_blk_write_time; /* time spent writing local blocks, in
|
||||
* msec */
|
||||
double temp_blk_read_time; /* time spent reading temp blocks, in msec */
|
||||
double temp_blk_write_time; /* time spent writing temp blocks, in
|
||||
* msec */
|
||||
|
||||
/*
|
||||
* Variables for local entry. The values to be passed to pgsm_update_entry
|
||||
* from pgsm_store.
|
||||
*/
|
||||
instr_time instr_shared_blk_read_time; /* time spent reading shared
|
||||
* blocks */
|
||||
instr_time instr_shared_blk_write_time; /* time spent writing shared
|
||||
* blocks */
|
||||
instr_time instr_local_blk_read_time; /* time spent reading local blocks */
|
||||
instr_time instr_local_blk_write_time; /* time spent writing local blocks */
|
||||
instr_time instr_temp_blk_read_time; /* time spent reading temp blocks */
|
||||
instr_time instr_temp_blk_write_time; /* time spent writing temp blocks */
|
||||
double blk_read_time; /* time spent reading, in msec */
|
||||
double blk_write_time; /* time spent writing, in msec */
|
||||
} Blocks;
|
||||
|
||||
typedef struct JitInfo
|
||||
{
|
||||
int64 jit_functions; /* total number of JIT functions emitted */
|
||||
double jit_generation_time; /* total time to generate jit code */
|
||||
int64 jit_inlining_count; /* number of times inlining time has been
|
||||
* > 0 */
|
||||
double jit_deform_time; /* total time to deform tuples in jit code */
|
||||
int64 jit_deform_count; /* number of times deform time has been >
|
||||
* 0 */
|
||||
double jit_inlining_time; /* total time to inline jit code */
|
||||
int64 jit_optimization_count; /* number of times optimization time
|
||||
* has been > 0 */
|
||||
double jit_optimization_time; /* total time to optimize jit code */
|
||||
int64 jit_emission_count; /* number of times emission time has been
|
||||
* > 0 */
|
||||
double jit_emission_time; /* total time to emit jit code */
|
||||
|
||||
/*
|
||||
* Variables for local entry. The values to be passed to pgsm_update_entry
|
||||
* from pgsm_store.
|
||||
*/
|
||||
instr_time instr_generation_counter; /* generation counter */
|
||||
instr_time instr_inlining_counter; /* inlining counter */
|
||||
instr_time instr_deform_counter; /* deform counter */
|
||||
instr_time instr_optimization_counter; /* optimization counter */
|
||||
instr_time instr_emission_counter; /* emission counter */
|
||||
} JitInfo;
|
||||
|
||||
typedef struct SysInfo
|
||||
{
|
||||
double utime; /* user cpu time */
|
||||
double stime; /* system cpu time */
|
||||
float utime; /* user cpu time */
|
||||
float stime; /* system cpu time */
|
||||
} SysInfo;
|
||||
|
||||
typedef struct Wal_Usage
|
||||
|
|
@ -308,11 +268,11 @@ typedef struct Wal_Usage
|
|||
int64 wal_records; /* # of WAL records generated */
|
||||
int64 wal_fpi; /* # of WAL full page images generated */
|
||||
uint64 wal_bytes; /* total amount of WAL bytes generated */
|
||||
int64 wal_buffers_full; /* # of times the WAL buffers became full */
|
||||
} Wal_Usage;
|
||||
|
||||
typedef struct Counters
|
||||
{
|
||||
uint64 bucket_id; /* bucket id */
|
||||
Calls calls;
|
||||
QueryInfo info;
|
||||
CallTime time;
|
||||
|
|
@ -323,15 +283,11 @@ typedef struct Counters
|
|||
|
||||
Blocks blocks;
|
||||
SysInfo sysinfo;
|
||||
JitInfo jitinfo;
|
||||
ErrorInfo error;
|
||||
Wal_Usage walusage;
|
||||
int resp_calls[MAX_RESPONSE_BUCKET]; /* execution time's in
|
||||
* msec */
|
||||
int64 parallel_workers_to_launch; /* # of parallel workers planned
|
||||
* to be launched */
|
||||
int64 parallel_workers_launched; /* # of parallel workers actually
|
||||
* launched */
|
||||
uint64 state; /* query state */
|
||||
} Counters;
|
||||
|
||||
/* Some global structure to get the cpu usage, really don't like the idea of global variable */
|
||||
|
|
@ -339,57 +295,59 @@ typedef struct Counters
|
|||
/*
|
||||
* Statistics per statement
|
||||
*/
|
||||
typedef struct pgsmEntry
|
||||
typedef struct pgssEntry
|
||||
{
|
||||
pgsmHashKey key; /* hash key of entry - MUST BE FIRST */
|
||||
int64 pgsm_query_id; /* pgsm generate normalized query hash */
|
||||
char datname[NAMEDATALEN]; /* database name */
|
||||
char username[NAMEDATALEN]; /* user name */
|
||||
pgssHashKey key; /* hash key of entry - MUST BE FIRST */
|
||||
Counters counters; /* the statistics for this query */
|
||||
int encoding; /* query text encoding */
|
||||
TimestampTz stats_since; /* timestamp of entry allocation */
|
||||
TimestampTz minmax_stats_since; /* timestamp of last min/max values reset */
|
||||
slock_t mutex; /* protects the counters only */
|
||||
union
|
||||
{
|
||||
dsa_pointer query_pos; /* query location within query buffer */
|
||||
char *query_pointer;
|
||||
} query_text;
|
||||
} pgsmEntry;
|
||||
size_t query_pos; /* query location within query buffer */
|
||||
} pgssEntry;
|
||||
|
||||
/*
|
||||
* Global shared state
|
||||
*/
|
||||
typedef struct pgsmSharedState
|
||||
typedef struct pgssSharedState
|
||||
{
|
||||
LWLock *lock; /* protects hashtable search/modification */
|
||||
double cur_median_usage; /* current median usage in hashtable */
|
||||
slock_t mutex; /* protects following fields only: */
|
||||
Size extent; /* current extent of query file */
|
||||
int64 n_writers; /* number of active writers to query file */
|
||||
pg_atomic_uint64 current_wbucket;
|
||||
pg_atomic_uint64 prev_bucket_sec;
|
||||
int hash_tranche_id;
|
||||
void *raw_dsa_area; /* DSA area pointer to store query texts.
|
||||
* dshash also lives in this memory when
|
||||
* USE_DYNAMIC_HASH is enabled */
|
||||
PGSM_HASH_TABLE_HANDLE hash_handle;
|
||||
uint64 bucket_entry[MAX_BUCKETS];
|
||||
char bucket_start_time[MAX_BUCKETS][60]; /* start time of the
|
||||
* bucket */
|
||||
LWLock *errors_lock; /* protects errors hashtable
|
||||
* search/modification */
|
||||
|
||||
/*
|
||||
* hash table handle. can be either classic shared memory hash or dshash
|
||||
* (if we are using USE_DYNAMIC_HASH)
|
||||
* These variables are used when pgsm_overflow_target is ON.
|
||||
*
|
||||
* overflow is set to true when the query buffer overflows.
|
||||
*
|
||||
* n_bucket_cycles counts the number of times we changed bucket since the
|
||||
* query buffer overflowed. When it reaches pgsm_max_buckets we remove the
|
||||
* dump file, also reset the counter.
|
||||
*
|
||||
* This allows us to avoid having a large file on disk that would also
|
||||
* slowdown queries to the pg_stat_monitor view.
|
||||
*/
|
||||
bool overflow;
|
||||
size_t n_bucket_cycles;
|
||||
} pgssSharedState;
|
||||
|
||||
bool pgsm_oom;
|
||||
TimestampTz bucket_start_time[]; /* start time of the bucket */
|
||||
} pgsmSharedState;
|
||||
#define ResetSharedState(x) \
|
||||
do { \
|
||||
x->cur_median_usage = ASSUMED_MEDIAN_INIT; \
|
||||
x->cur_median_usage = ASSUMED_MEDIAN_INIT; \
|
||||
x->n_writers = 0; \
|
||||
pg_atomic_init_u64(&x->current_wbucket, 0); \
|
||||
pg_atomic_init_u64(&x->prev_bucket_sec, 0); \
|
||||
memset(&x->bucket_entry, 0, MAX_BUCKETS * sizeof(uint64)); \
|
||||
} while(0)
|
||||
|
||||
typedef struct pgsmLocalState
|
||||
{
|
||||
pgsmSharedState *shared_pgsmState;
|
||||
dsa_area *dsa; /* local dsa area for backend attached to the
|
||||
* dsa area created by postmaster at startup. */
|
||||
PGSM_HASH_TABLE *shared_hash;
|
||||
MemoryContext pgsm_mem_cxt;
|
||||
|
||||
} pgsmLocalState;
|
||||
|
||||
#if PG_VERSION_NUM < 140000
|
||||
/*
|
||||
|
|
@ -427,35 +385,45 @@ typedef struct JumbleState
|
|||
} JumbleState;
|
||||
#endif
|
||||
|
||||
/* Links to shared memory state */
|
||||
|
||||
bool SaveQueryText(uint64 bucketid,
|
||||
uint64 queryid,
|
||||
unsigned char *buf,
|
||||
const char *query,
|
||||
uint64 query_len,
|
||||
size_t *query_pos);
|
||||
|
||||
/* guc.c */
|
||||
void init_guc(void);
|
||||
GucVariable *get_conf(int i);
|
||||
|
||||
/* hash_create.c */
|
||||
dsa_area *get_dsa_area_for_query_text(void);
|
||||
PGSM_HASH_TABLE *get_pgsmHash(void);
|
||||
|
||||
void pgsm_attach_shmem(void);
|
||||
bool IsHashInitialize(void);
|
||||
bool IsSystemOOM(void);
|
||||
void pgsm_shmem_startup(void);
|
||||
void pgsm_shmem_shutdown(int code, Datum arg);
|
||||
void pgss_shmem_startup(void);
|
||||
void pgss_shmem_shutdown(int code, Datum arg);
|
||||
int pgsm_get_bucket_size(void);
|
||||
pgsmSharedState *pgsm_get_ss(void);
|
||||
pgssSharedState *pgsm_get_ss(void);
|
||||
HTAB *pgsm_get_plan_hash(void);
|
||||
HTAB *pgsm_get_hash(void);
|
||||
HTAB *pgsm_get_query_hash(void);
|
||||
HTAB *pgsm_get_plan_hash(void);
|
||||
void hash_entry_reset(void);
|
||||
void hash_query_entryies_reset(void);
|
||||
void hash_query_entries();
|
||||
void hash_query_entry_dealloc(int new_bucket_id, int old_bucket_id, unsigned char *query_buffer[]);
|
||||
void hash_entry_dealloc(int new_bucket_id, int old_bucket_id, unsigned char *query_buffer);
|
||||
pgsmEntry *hash_entry_alloc(pgsmSharedState *pgsm, pgsmHashKey *key, int encoding);
|
||||
Size pgsm_ShmemSize(void);
|
||||
void pgsm_startup(void);
|
||||
pgssEntry *hash_entry_alloc(pgssSharedState *pgss, pgssHashKey *key, int encoding);
|
||||
Size hash_memsize(void);
|
||||
|
||||
int read_query_buffer(int bucket_id, uint64 queryid, char *query_txt, size_t pos);
|
||||
uint64 read_query(unsigned char *buf, uint64 queryid, char *query, size_t pos);
|
||||
void pgss_startup(void);
|
||||
void set_qbuf(unsigned char *);
|
||||
|
||||
/* hash_query.c */
|
||||
void pgsm_startup(void);
|
||||
MemoryContext GetPgsmMemoryContext(void);
|
||||
void pgss_startup(void);
|
||||
|
||||
/* guc.c */
|
||||
void init_guc(void);
|
||||
|
||||
/* GUC variables*/
|
||||
/*---- GUC variables ----*/
|
||||
typedef enum
|
||||
{
|
||||
|
|
@ -471,30 +439,90 @@ static const struct config_enum_entry track_options[] =
|
|||
{NULL, 0, false}
|
||||
};
|
||||
|
||||
typedef enum
|
||||
{
|
||||
HISTOGRAM_START,
|
||||
HISTOGRAM_END,
|
||||
HISTOGRAM_COUNT
|
||||
} HistogramTimingType;
|
||||
#define PGSM_MAX get_conf(0)->guc_variable
|
||||
#define PGSM_QUERY_MAX_LEN get_conf(1)->guc_variable
|
||||
#define PGSM_TRACK_UTILITY get_conf(2)->guc_variable
|
||||
#define PGSM_NORMALIZED_QUERY get_conf(3)->guc_variable
|
||||
#define PGSM_MAX_BUCKETS get_conf(4)->guc_variable
|
||||
#define PGSM_BUCKET_TIME get_conf(5)->guc_variable
|
||||
#define PGSM_HISTOGRAM_MIN get_conf(6)->guc_variable
|
||||
#define PGSM_HISTOGRAM_MAX get_conf(7)->guc_variable
|
||||
#define PGSM_HISTOGRAM_BUCKETS get_conf(8)->guc_variable
|
||||
#define PGSM_QUERY_SHARED_BUFFER get_conf(9)->guc_variable
|
||||
#define PGSM_OVERFLOW_TARGET get_conf(10)->guc_variable
|
||||
#define PGSM_QUERY_PLAN get_conf(11)->guc_variable
|
||||
#define PGSM_TRACK get_conf(12)->guc_variable
|
||||
#define PGSM_EXTRACT_COMMENTS get_conf(13)->guc_variable
|
||||
#define PGSM_TRACK_PLANNING get_conf(14)->guc_variable
|
||||
|
||||
extern int pgsm_max;
|
||||
extern int pgsm_query_max_len;
|
||||
extern int pgsm_bucket_time;
|
||||
extern int pgsm_max_buckets;
|
||||
extern int pgsm_histogram_buckets;
|
||||
extern double pgsm_histogram_min;
|
||||
extern double pgsm_histogram_max;
|
||||
extern int pgsm_query_shared_buffer;
|
||||
extern bool pgsm_track_planning;
|
||||
extern bool pgsm_extract_comments;
|
||||
extern bool pgsm_enable_query_plan;
|
||||
extern bool pgsm_enable_overflow;
|
||||
extern bool pgsm_normalized_query;
|
||||
extern bool pgsm_track_utility;
|
||||
extern bool pgsm_track_application_names;
|
||||
extern bool pgsm_enable_pgsm_query_id;
|
||||
extern int pgsm_track;
|
||||
|
||||
/*---- Benchmarking ----*/
|
||||
#ifdef BENCHMARK
|
||||
/*
|
||||
* These enumerator values are used as index in the hook stats array.
|
||||
* STATS_START and STATS_END are used only to delimit the range.
|
||||
* STATS_END is also the length of the valid items in the enum.
|
||||
*/
|
||||
enum pg_hook_stats_id
|
||||
{
|
||||
STATS_START = -1,
|
||||
STATS_PGSS_POST_PARSE_ANALYZE,
|
||||
STATS_PGSS_EXECUTORSTART,
|
||||
STATS_PGSS_EXECUTORUN,
|
||||
STATS_PGSS_EXECUTORFINISH,
|
||||
STATS_PGSS_EXECUTOREND,
|
||||
STATS_PGSS_PROCESSUTILITY,
|
||||
#if PG_VERSION_NUM >= 130000
|
||||
STATS_PGSS_PLANNER_HOOK,
|
||||
#endif
|
||||
STATS_PGSM_EMIT_LOG_HOOK,
|
||||
STATS_PGSS_EXECUTORCHECKPERMS,
|
||||
STATS_END
|
||||
};
|
||||
|
||||
/* Hold time to execute statistics for a hook. */
|
||||
struct pg_hook_stats_t
|
||||
{
|
||||
char hook_name[64];
|
||||
double min_time;
|
||||
double max_time;
|
||||
double total_time;
|
||||
uint64 ncalls;
|
||||
};
|
||||
|
||||
#define HOOK_STATS_SIZE MAXALIGN((size_t)STATS_END * sizeof(struct pg_hook_stats_t))
|
||||
|
||||
/* Allocate a pg_hook_stats_t array of size HOOK_STATS_SIZE on shared memory. */
|
||||
void init_hook_stats(void);
|
||||
|
||||
/* Update hook time execution statistics. */
|
||||
void update_hook_stats(enum pg_hook_stats_id hook_id, double time_elapsed);
|
||||
|
||||
/*
|
||||
* Macro used to declare a hook function:
|
||||
* Example:
|
||||
* DECLARE_HOOK(void my_hook, const char *query, size_t length);
|
||||
* Will expand to:
|
||||
* static void my_hook(const char *query, size_t length);
|
||||
* static void my_hook_benchmark(const char *query, size_t length);
|
||||
*/
|
||||
#define DECLARE_HOOK(hook, ...) \
|
||||
static hook(__VA_ARGS__); \
|
||||
static hook##_benchmark(__VA_ARGS__);
|
||||
|
||||
/*
|
||||
* Macro used to wrap a hook when pg_stat_monitor is compiled with -DBENCHMARK.
|
||||
*
|
||||
* It is intended to be used as follows in _PG_init():
|
||||
* pg_hook_function = HOOK(my_hook_function);
|
||||
* Then, if pg_stat_monitor is compiled with -DBENCHMARK this will expand to:
|
||||
* pg_hook_name = my_hook_function_benchmark;
|
||||
* Otherwise it will simple expand to:
|
||||
* pg_hook_name = my_hook_function;
|
||||
*/
|
||||
#define HOOK(name) name##_benchmark
|
||||
|
||||
#else /* #ifdef BENCHMARK */
|
||||
|
||||
#define DECLARE_HOOK(hook, ...) \
|
||||
static hook(__VA_ARGS__);
|
||||
|
|
@ -502,9 +530,4 @@ extern int pgsm_track;
|
|||
#define HOOK_STATS_SIZE 0
|
||||
#endif
|
||||
|
||||
void *pgsm_hash_find_or_insert(PGSM_HASH_TABLE * shared_hash, pgsmHashKey *key, bool *found);
|
||||
void *pgsm_hash_find(PGSM_HASH_TABLE * shared_hash, pgsmHashKey *key, bool *found);
|
||||
void pgsm_hash_seq_init(PGSM_HASH_SEQ_STATUS * hstat, PGSM_HASH_TABLE * shared_hash, bool lock);
|
||||
void *pgsm_hash_seq_next(PGSM_HASH_SEQ_STATUS * hstat);
|
||||
void pgsm_hash_seq_term(PGSM_HASH_SEQ_STATUS * hstat);
|
||||
void pgsm_hash_delete_current(PGSM_HASH_SEQ_STATUS * hstat, PGSM_HASH_TABLE * shared_hash, void *key);
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -0,0 +1,228 @@
|
|||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* pgsm_errors.c
|
||||
* Track pg_stat_monitor internal error messages.
|
||||
*
|
||||
* Copyright © 2021, Percona LLC and/or its affiliates
|
||||
*
|
||||
* Portions Copyright (c) 1996-2020, PostgreSQL Global Development Group
|
||||
*
|
||||
* Portions Copyright (c) 1994, The Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* contrib/pg_stat_monitor/pgsm_errors.c
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include <postgres.h>
|
||||
#include <access/hash.h>
|
||||
#include <storage/shmem.h>
|
||||
#include <utils/hsearch.h>
|
||||
|
||||
#include "pg_stat_monitor.h"
|
||||
#include "pgsm_errors.h"
|
||||
|
||||
|
||||
PG_FUNCTION_INFO_V1(pg_stat_monitor_errors);
|
||||
PG_FUNCTION_INFO_V1(pg_stat_monitor_reset_errors);
|
||||
|
||||
|
||||
/*
|
||||
* Maximum number of error messages tracked.
|
||||
* This should be set to a sensible value in order to track
|
||||
* the different type of errors that pg_stat_monitor may
|
||||
* report, e.g. out of memory.
|
||||
*/
|
||||
#define PSGM_ERRORS_MAX 128
|
||||
|
||||
static HTAB *pgsm_errors_ht = NULL;
|
||||
|
||||
void
|
||||
psgm_errors_init(void)
|
||||
{
|
||||
HASHCTL info;
|
||||
#if PG_VERSION_NUM >= 140000
|
||||
int flags = HASH_ELEM | HASH_STRINGS;
|
||||
#else
|
||||
int flags = HASH_ELEM | HASH_BLOBS;
|
||||
#endif
|
||||
|
||||
|
||||
memset(&info, 0, sizeof(info));
|
||||
info.keysize = ERROR_MSG_MAX_LEN;
|
||||
info.entrysize = sizeof(ErrorEntry);
|
||||
pgsm_errors_ht = ShmemInitHash("pg_stat_monitor: errors hashtable",
|
||||
PSGM_ERRORS_MAX, /* initial size */
|
||||
PSGM_ERRORS_MAX, /* maximum size */
|
||||
&info,
|
||||
flags);
|
||||
}
|
||||
|
||||
size_t
|
||||
pgsm_errors_size(void)
|
||||
{
|
||||
return hash_estimate_size(PSGM_ERRORS_MAX, sizeof(ErrorEntry));
|
||||
}
|
||||
|
||||
void
|
||||
pgsm_log(PgsmLogSeverity severity, const char *format,...)
|
||||
{
|
||||
char key[ERROR_MSG_MAX_LEN];
|
||||
ErrorEntry *entry;
|
||||
bool found = false;
|
||||
va_list ap;
|
||||
int n;
|
||||
struct timeval tv;
|
||||
struct tm *lt;
|
||||
pgssSharedState *pgss;
|
||||
|
||||
va_start(ap, format);
|
||||
n = vsnprintf(key, ERROR_MSG_MAX_LEN, format, ap);
|
||||
va_end(ap);
|
||||
|
||||
if (n < 0)
|
||||
return;
|
||||
|
||||
pgss = pgsm_get_ss();
|
||||
LWLockAcquire(pgss->errors_lock, LW_EXCLUSIVE);
|
||||
|
||||
entry = (ErrorEntry *) hash_search(pgsm_errors_ht, key, HASH_ENTER_NULL, &found);
|
||||
if (!entry)
|
||||
{
|
||||
LWLockRelease(pgss->errors_lock);
|
||||
|
||||
/*
|
||||
* We're out of memory, can't track this error message.
|
||||
*/
|
||||
return;
|
||||
}
|
||||
|
||||
if (!found)
|
||||
{
|
||||
entry->severity = severity;
|
||||
entry->calls = 0;
|
||||
}
|
||||
|
||||
/* Update message timestamp. */
|
||||
gettimeofday(&tv, NULL);
|
||||
lt = localtime(&tv.tv_sec);
|
||||
snprintf(entry->time, sizeof(entry->time),
|
||||
"%04d-%02d-%02d %02d:%02d:%02d",
|
||||
lt->tm_year + 1900,
|
||||
lt->tm_mon + 1,
|
||||
lt->tm_mday,
|
||||
lt->tm_hour,
|
||||
lt->tm_min,
|
||||
lt->tm_sec);
|
||||
|
||||
entry->calls++;
|
||||
|
||||
LWLockRelease(pgss->errors_lock);
|
||||
}
|
||||
|
||||
/*
|
||||
* Clear all entries from the hash table.
|
||||
*/
|
||||
Datum
|
||||
pg_stat_monitor_reset_errors(PG_FUNCTION_ARGS)
|
||||
{
|
||||
HASH_SEQ_STATUS hash_seq;
|
||||
ErrorEntry *entry;
|
||||
pgssSharedState *pgss = pgsm_get_ss();
|
||||
|
||||
/* Safety check... */
|
||||
if (!IsSystemInitialized())
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
|
||||
errmsg("pg_stat_monitor: must be loaded via shared_preload_libraries")));
|
||||
|
||||
LWLockAcquire(pgss->errors_lock, LW_EXCLUSIVE);
|
||||
|
||||
hash_seq_init(&hash_seq, pgsm_errors_ht);
|
||||
while ((entry = hash_seq_search(&hash_seq)) != NULL)
|
||||
entry = hash_search(pgsm_errors_ht, &entry->message, HASH_REMOVE, NULL);
|
||||
|
||||
LWLockRelease(pgss->errors_lock);
|
||||
PG_RETURN_VOID();
|
||||
}
|
||||
|
||||
/*
|
||||
* Invoked when users query the view pg_stat_monitor_errors.
|
||||
* This function creates tuples with error messages from data present in
|
||||
* the hash table, then return the dataset to the caller.
|
||||
*/
|
||||
Datum
|
||||
pg_stat_monitor_errors(PG_FUNCTION_ARGS)
|
||||
{
|
||||
ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
|
||||
TupleDesc tupdesc;
|
||||
Tuplestorestate *tupstore;
|
||||
MemoryContext per_query_ctx;
|
||||
MemoryContext oldcontext;
|
||||
HASH_SEQ_STATUS hash_seq;
|
||||
ErrorEntry *error_entry;
|
||||
pgssSharedState *pgss = pgsm_get_ss();
|
||||
|
||||
/* Safety check... */
|
||||
if (!IsSystemInitialized())
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
|
||||
errmsg("pg_stat_monitor: must be loaded via shared_preload_libraries")));
|
||||
|
||||
/* check to see if caller supports us returning a tuplestore */
|
||||
if (rsinfo == NULL || !IsA(rsinfo, ReturnSetInfo))
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("pg_stat_monitor: set-valued function called in context that cannot accept a set")));
|
||||
|
||||
/* Switch into long-lived context to construct returned data structures */
|
||||
per_query_ctx = rsinfo->econtext->ecxt_per_query_memory;
|
||||
oldcontext = MemoryContextSwitchTo(per_query_ctx);
|
||||
|
||||
/* Build a tuple descriptor for our result type */
|
||||
if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
|
||||
elog(ERROR, "pg_stat_monitor: return type must be a row type");
|
||||
|
||||
if (tupdesc->natts != 4)
|
||||
elog(ERROR, "pg_stat_monitor: incorrect number of output arguments, required 3, found %d", tupdesc->natts);
|
||||
|
||||
tupstore = tuplestore_begin_heap(true, false, work_mem);
|
||||
rsinfo->returnMode = SFRM_Materialize;
|
||||
rsinfo->setResult = tupstore;
|
||||
rsinfo->setDesc = tupdesc;
|
||||
|
||||
MemoryContextSwitchTo(oldcontext);
|
||||
|
||||
LWLockAcquire(pgss->errors_lock, LW_SHARED);
|
||||
|
||||
hash_seq_init(&hash_seq, pgsm_errors_ht);
|
||||
while ((error_entry = hash_seq_search(&hash_seq)) != NULL)
|
||||
{
|
||||
Datum values[4];
|
||||
bool nulls[4];
|
||||
int i = 0;
|
||||
|
||||
memset(values, 0, sizeof(values));
|
||||
memset(nulls, 0, sizeof(nulls));
|
||||
|
||||
values[i++] = Int64GetDatumFast(error_entry->severity);
|
||||
values[i++] = CStringGetTextDatum(error_entry->message);
|
||||
values[i++] = CStringGetTextDatum(error_entry->time);
|
||||
values[i++] = Int64GetDatumFast(error_entry->calls);
|
||||
|
||||
tuplestore_putvalues(tupstore, tupdesc, values, nulls);
|
||||
}
|
||||
|
||||
LWLockRelease(pgss->errors_lock);
|
||||
/* clean up and return the tuplestore */
|
||||
tuplestore_donestoring(tupstore);
|
||||
|
||||
return (Datum) 0;
|
||||
}
|
||||
|
|
@ -13,38 +13,11 @@ SELECT 1 AS num;
|
|||
|
||||
SELECT query,application_name FROM pg_stat_monitor ORDER BY query COLLATE "C";
|
||||
query | application_name
|
||||
--------------------------------+-----------------------------
|
||||
-------------------------------------------------------------------------------+-----------------------------
|
||||
SELECT 1 AS num | pg_regress/application_name
|
||||
SELECT pg_stat_monitor_reset() | pg_regress/application_name
|
||||
(2 rows)
|
||||
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
-----------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
SELECT 1 AS num;
|
||||
num
|
||||
-----
|
||||
1
|
||||
(1 row)
|
||||
|
||||
SET pg_stat_monitor.pgsm_track_application_names='no';
|
||||
SELECT 1 AS num;
|
||||
num
|
||||
-----
|
||||
1
|
||||
(1 row)
|
||||
|
||||
SELECT query,application_name FROM pg_stat_monitor ORDER BY query, application_name COLLATE "C";
|
||||
query | application_name
|
||||
-------------------------------------------------------+-----------------------------
|
||||
SELECT 1 AS num | pg_regress/application_name
|
||||
SELECT 1 AS num |
|
||||
SELECT pg_stat_monitor_reset() | pg_regress/application_name
|
||||
SET pg_stat_monitor.pgsm_track_application_names='no' |
|
||||
(4 rows)
|
||||
SELECT query,application_name FROM pg_stat_monitor ORDER BY query COLLATE "C" | pg_regress/application_name
|
||||
(3 rows)
|
||||
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
|
|
|
|||
|
|
@ -1,18 +1,18 @@
|
|||
CREATE EXTENSION pg_stat_monitor;
|
||||
Create EXTENSION pg_stat_monitor;
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
-----------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
SET application_name = 'naeem' ;
|
||||
Set application_name = 'naeem' ;
|
||||
SELECT 1 AS num;
|
||||
num
|
||||
-----
|
||||
1
|
||||
(1 row)
|
||||
|
||||
SET application_name = 'psql' ;
|
||||
Set application_name = 'psql' ;
|
||||
SELECT 1 AS num;
|
||||
num
|
||||
-----
|
||||
|
|
@ -21,13 +21,14 @@ SELECT 1 AS num;
|
|||
|
||||
SELECT query,application_name FROM pg_stat_monitor ORDER BY query, application_name COLLATE "C";
|
||||
query | application_name
|
||||
--------------------------------+------------------------------------
|
||||
-------------------------------------------------------------------------------------------------+------------------------------------
|
||||
SELECT 1 AS num | naeem
|
||||
SELECT 1 AS num | psql
|
||||
SELECT pg_stat_monitor_reset() | pg_regress/application_name_unique
|
||||
SET application_name = 'naeem' | naeem
|
||||
SET application_name = 'psql' | psql
|
||||
(5 rows)
|
||||
SELECT query,application_name FROM pg_stat_monitor ORDER BY query, application_name COLLATE "C" | psql
|
||||
Set application_name = 'naeem' | naeem
|
||||
Set application_name = 'psql' | psql
|
||||
(6 rows)
|
||||
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
|
|
|
|||
|
|
@ -1,36 +0,0 @@
|
|||
CREATE EXTENSION pg_stat_monitor;
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
-----------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
SET application_name = 'naeem' ;
|
||||
SELECT 1 AS num;
|
||||
num
|
||||
-----
|
||||
1
|
||||
(1 row)
|
||||
|
||||
SET application_name = 'psql' ;
|
||||
SELECT 1 AS num;
|
||||
num
|
||||
-----
|
||||
1
|
||||
(1 row)
|
||||
|
||||
SELECT query,application_name FROM pg_stat_monitor ORDER BY query, application_name COLLATE "C";
|
||||
query | application_name
|
||||
--------------------------------+------------------------------------
|
||||
SELECT 1 AS num | naeem
|
||||
SELECT 1 AS num | psql
|
||||
SELECT pg_stat_monitor_reset() | pg_regress/application_name_unique
|
||||
(3 rows)
|
||||
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
-----------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
DROP EXTENSION pg_stat_monitor;
|
||||
|
|
@ -13,10 +13,11 @@ SELECT 1 AS num;
|
|||
|
||||
SELECT query FROM pg_stat_monitor ORDER BY query COLLATE "C";
|
||||
query
|
||||
--------------------------------
|
||||
--------------------------------------------------------------
|
||||
SELECT 1 AS num
|
||||
SELECT pg_stat_monitor_reset()
|
||||
(2 rows)
|
||||
SELECT query FROM pg_stat_monitor ORDER BY query COLLATE "C"
|
||||
(3 rows)
|
||||
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
|
|
|
|||
|
|
@ -0,0 +1,35 @@
|
|||
CREATE EXTENSION pg_stat_monitor;
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
-----------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
select pg_sleep(.5);
|
||||
pg_sleep
|
||||
----------
|
||||
|
||||
(1 row)
|
||||
|
||||
SELECT 1;
|
||||
?column?
|
||||
----------
|
||||
1
|
||||
(1 row)
|
||||
|
||||
SELECT query FROM pg_stat_monitor ORDER BY query COLLATE "C";
|
||||
query
|
||||
--------------------------------------------------------------
|
||||
SELECT $1
|
||||
SELECT pg_stat_monitor_reset()
|
||||
SELECT query FROM pg_stat_monitor ORDER BY query COLLATE "C"
|
||||
select pg_sleep($1)
|
||||
(4 rows)
|
||||
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
-----------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
DROP EXTENSION pg_stat_monitor;
|
||||
|
|
@ -23,20 +23,19 @@ SELECT b FROM t2 FOR UPDATE;
|
|||
|
||||
TRUNCATE t1;
|
||||
DROP TABLE t1;
|
||||
DROP TABLE t2;
|
||||
SELECT query, cmd_type, cmd_type_text FROM pg_stat_monitor ORDER BY query COLLATE "C";
|
||||
query | cmd_type | cmd_type_text
|
||||
--------------------------------+----------+---------------
|
||||
CREATE TABLE t1 (a INTEGER) | 5 | UTILITY
|
||||
CREATE TABLE t2 (b INTEGER) | 5 | UTILITY
|
||||
----------------------------------------------------------------------------------------+----------+---------------
|
||||
CREATE TABLE t1 (a INTEGER) | 0 |
|
||||
CREATE TABLE t2 (b INTEGER) | 0 |
|
||||
DELETE FROM t1 | 4 | DELETE
|
||||
DROP TABLE t1 | 5 | UTILITY
|
||||
DROP TABLE t2 | 5 | UTILITY
|
||||
DROP TABLE t1 | 0 |
|
||||
INSERT INTO t1 VALUES(1) | 3 | INSERT
|
||||
SELECT a FROM t1 | 1 | SELECT
|
||||
SELECT b FROM t2 FOR UPDATE | 1 | SELECT
|
||||
SELECT pg_stat_monitor_reset() | 1 | SELECT
|
||||
TRUNCATE t1 | 5 | UTILITY
|
||||
SELECT query, cmd_type, cmd_type_text FROM pg_stat_monitor ORDER BY query COLLATE "C" | 1 | SELECT
|
||||
TRUNCATE t1 | 0 |
|
||||
UPDATE t1 SET a = 2 | 2 | UPDATE
|
||||
(11 rows)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,49 +0,0 @@
|
|||
CREATE EXTENSION pg_stat_monitor;
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
-----------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
CREATE TABLE t1 (a INTEGER);
|
||||
CREATE TABLE t2 (b INTEGER);
|
||||
INSERT INTO t1 VALUES(1);
|
||||
SELECT a FROM t1;
|
||||
a
|
||||
---
|
||||
1
|
||||
(1 row)
|
||||
|
||||
UPDATE t1 SET a = 2;
|
||||
DELETE FROM t1;
|
||||
SELECT b FROM t2 FOR UPDATE;
|
||||
b
|
||||
---
|
||||
(0 rows)
|
||||
|
||||
TRUNCATE t1;
|
||||
DROP TABLE t1;
|
||||
DROP TABLE t2;
|
||||
SELECT query, cmd_type, cmd_type_text FROM pg_stat_monitor ORDER BY query COLLATE "C";
|
||||
query | cmd_type | cmd_type_text
|
||||
--------------------------------+----------+---------------
|
||||
CREATE TABLE t1 (a INTEGER) | 6 | UTILITY
|
||||
CREATE TABLE t2 (b INTEGER) | 6 | UTILITY
|
||||
DELETE FROM t1 | 4 | DELETE
|
||||
DROP TABLE t1 | 6 | UTILITY
|
||||
DROP TABLE t2 | 6 | UTILITY
|
||||
INSERT INTO t1 VALUES(1) | 3 | INSERT
|
||||
SELECT a FROM t1 | 1 | SELECT
|
||||
SELECT b FROM t2 FOR UPDATE | 1 | SELECT
|
||||
SELECT pg_stat_monitor_reset() | 1 | SELECT
|
||||
TRUNCATE t1 | 6 | UTILITY
|
||||
UPDATE t1 SET a = 2 | 2 | UPDATE
|
||||
(11 rows)
|
||||
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
-----------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
DROP EXTENSION pg_stat_monitor;
|
||||
|
|
@ -36,12 +36,13 @@ SELECT a,b,c,d FROM t1, t2, t3, t4 WHERE t1.a = t2.b AND t3.c = t4.d ORDER BY a;
|
|||
---+---+---+---
|
||||
(0 rows)
|
||||
|
||||
SELECT query, sum(calls) as calls FROM pg_stat_monitor GROUP BY query ORDER BY query COLLATE "C";
|
||||
SELECT query,calls FROM pg_stat_monitor ORDER BY query COLLATE "C";
|
||||
query | calls
|
||||
---------------------------------------------------------------------------------+-------
|
||||
SELECT a,b,c,d FROM t1, t2, t3, t4 WHERE t1.a = t2.b AND t3.c = t4.d ORDER BY a | 4
|
||||
SELECT pg_stat_monitor_reset() | 1
|
||||
(2 rows)
|
||||
SELECT query,calls FROM pg_stat_monitor ORDER BY query COLLATE "C" | 1
|
||||
(3 rows)
|
||||
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
|
|
@ -59,11 +60,12 @@ begin
|
|||
n := n + 1;
|
||||
end loop;
|
||||
end $$;
|
||||
SELECT query, sum(calls) as calls FROM pg_stat_monitor GROUP BY query ORDER BY query COLLATE "C";
|
||||
SELECT query,calls FROM pg_stat_monitor ORDER BY query COLLATE "C";
|
||||
query | calls
|
||||
---------------------------------------------------------------------------------------------------+-------
|
||||
SELECT a,b,c,d FROM t1, t2, t3, t4 WHERE t1.a = t2.b AND t3.c = t4.d ORDER BY a | 1000
|
||||
SELECT pg_stat_monitor_reset() | 1
|
||||
SELECT query,calls FROM pg_stat_monitor ORDER BY query COLLATE "C" | 1
|
||||
do $$ +| 1
|
||||
declare +|
|
||||
n integer:= 1; +|
|
||||
|
|
@ -74,7 +76,7 @@ SELECT query, sum(calls) as calls FROM pg_stat_monitor GROUP BY query ORDER BY q
|
|||
n := n + 1; +|
|
||||
end loop; +|
|
||||
end $$ |
|
||||
(3 rows)
|
||||
(4 rows)
|
||||
|
||||
DROP TABLE t1;
|
||||
DROP TABLE t2;
|
||||
|
|
|
|||
|
|
@ -27,13 +27,12 @@ SELECT * FROM t3,t4 WHERE t3.c = t4.d;
|
|||
(0 rows)
|
||||
|
||||
\c contrib_regression
|
||||
DROP DATABASE db2;
|
||||
SELECT datname, query FROM pg_stat_monitor ORDER BY query COLLATE "C";
|
||||
datname | query
|
||||
--------------------+---------------------------------------
|
||||
contrib_regression | DROP DATABASE db2
|
||||
--------------------+-----------------------------------------------------------------------
|
||||
db1 | SELECT * FROM t1,t2 WHERE t1.a = t2.b
|
||||
db2 | SELECT * FROM t3,t4 WHERE t3.c = t4.d
|
||||
contrib_regression | SELECT datname, query FROM pg_stat_monitor ORDER BY query COLLATE "C"
|
||||
contrib_regression | SELECT pg_stat_monitor_reset()
|
||||
(4 rows)
|
||||
|
||||
|
|
@ -46,6 +45,10 @@ SELECT pg_stat_monitor_reset();
|
|||
\c db1
|
||||
DROP TABLE t1;
|
||||
DROP TABLE t2;
|
||||
\c db2
|
||||
DROP TABLE t3;
|
||||
DROP TABLE t4;
|
||||
\c contrib_regression
|
||||
DROP DATABASE db1;
|
||||
DROP DATABASE db2;
|
||||
DROP EXTENSION pg_stat_monitor;
|
||||
|
|
|
|||
|
|
@ -1,25 +0,0 @@
|
|||
CREATE EXTENSION pg_stat_monitor;
|
||||
DO $$
|
||||
DECLARE
|
||||
i integer;
|
||||
BEGIN
|
||||
FOR i IN 10..24 LOOP
|
||||
RAISE NOTICE 'error_code: %, error_level: %', i, decode_error_level(i);
|
||||
END LOOP;
|
||||
END $$;
|
||||
NOTICE: error_code: 10, error_level: DEBUG5
|
||||
NOTICE: error_code: 11, error_level: DEBUG4
|
||||
NOTICE: error_code: 12, error_level: DEBUG3
|
||||
NOTICE: error_code: 13, error_level: DEBUG2
|
||||
NOTICE: error_code: 14, error_level: DEBUG1
|
||||
NOTICE: error_code: 15, error_level: LOG
|
||||
NOTICE: error_code: 16, error_level: LOG_SERVER_ONLY
|
||||
NOTICE: error_code: 17, error_level: INFO
|
||||
NOTICE: error_code: 18, error_level: NOTICE
|
||||
NOTICE: error_code: 19, error_level: WARNING
|
||||
NOTICE: error_code: 20, error_level: WARNING_CLIENT_ONLY
|
||||
NOTICE: error_code: 21, error_level: ERROR
|
||||
NOTICE: error_code: 22, error_level: FATAL
|
||||
NOTICE: error_code: 23, error_level: PANIC
|
||||
NOTICE: error_code: 24, error_level: <NULL>
|
||||
DROP EXTENSION pg_stat_monitor;
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
CREATE EXTENSION pg_stat_monitor;
|
||||
DO $$
|
||||
DECLARE
|
||||
i integer;
|
||||
BEGIN
|
||||
FOR i IN 10..24 LOOP
|
||||
RAISE NOTICE 'error_code: %, error_level: %', i, decode_error_level(i);
|
||||
END LOOP;
|
||||
END $$;
|
||||
NOTICE: error_code: 10, error_level: DEBUG5
|
||||
NOTICE: error_code: 11, error_level: DEBUG4
|
||||
NOTICE: error_code: 12, error_level: DEBUG3
|
||||
NOTICE: error_code: 13, error_level: DEBUG2
|
||||
NOTICE: error_code: 14, error_level: DEBUG1
|
||||
NOTICE: error_code: 15, error_level: LOG
|
||||
NOTICE: error_code: 16, error_level: LOG_SERVER_ONLY
|
||||
NOTICE: error_code: 17, error_level: INFO
|
||||
NOTICE: error_code: 18, error_level: NOTICE
|
||||
NOTICE: error_code: 19, error_level: WARNING
|
||||
NOTICE: error_code: 20, error_level: ERROR
|
||||
NOTICE: error_code: 21, error_level: FATAL
|
||||
NOTICE: error_code: 22, error_level: PANIC
|
||||
NOTICE: error_code: 23, error_level: <NULL>
|
||||
NOTICE: error_code: 24, error_level: <NULL>
|
||||
DROP EXTENSION pg_stat_monitor;
|
||||
|
|
@ -1,54 +0,0 @@
|
|||
CREATE EXTENSION pg_stat_monitor;
|
||||
SET pg_stat_monitor.pgsm_track='all';
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
-----------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
CREATE OR REPLACE FUNCTION test() RETURNS VOID AS
|
||||
$$
|
||||
BEGIN
|
||||
PERFORM 1 + 2;
|
||||
END; $$ language plpgsql;
|
||||
CREATE OR REPLACE FUNCTION test2() RETURNS VOID AS
|
||||
$$
|
||||
BEGIN
|
||||
PERFORM 1 + 2;
|
||||
END; $$ language plpgsql;
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
-----------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
SELECT test();
|
||||
test
|
||||
------
|
||||
|
||||
(1 row)
|
||||
|
||||
SELECT test2();
|
||||
test2
|
||||
-------
|
||||
|
||||
(1 row)
|
||||
|
||||
SELECT 1 + 2;
|
||||
?column?
|
||||
----------
|
||||
3
|
||||
(1 row)
|
||||
|
||||
SELECT left(query, 15) as query, calls, top_query, pgsm_query_id FROM pg_stat_monitor ORDER BY query, top_query COLLATE "C";
|
||||
query | calls | top_query | pgsm_query_id
|
||||
-----------------+-------+-----------------+----------------------
|
||||
SELECT 1 + 2 | 1 | SELECT test(); | 5193804135051352284
|
||||
SELECT 1 + 2 | 1 | SELECT test2(); | 5193804135051352284
|
||||
SELECT 1 + 2 | 1 | | 5193804135051352284
|
||||
SELECT pg_stat_ | 1 | | 689150021118383254
|
||||
SELECT test() | 1 | | -6801876889834540522
|
||||
SELECT test2() | 1 | | 369102705908374543
|
||||
(6 rows)
|
||||
|
||||
DROP EXTENSION pg_stat_monitor;
|
||||
|
|
@ -22,11 +22,12 @@ END $$;
|
|||
WARNING: warning message
|
||||
SELECT query, elevel, sqlcode, message FROM pg_stat_monitor ORDER BY query COLLATE "C",elevel;
|
||||
query | elevel | sqlcode | message
|
||||
----------------------------------+--------+---------+-----------------------------------
|
||||
ELECET * FROM unknown; | 20 | 42601 | syntax error at or near "ELECET"
|
||||
SELECT * FROM unknown; | 20 | 42P01 | relation "unknown" does not exist
|
||||
SELECT 1/0; | 20 | 22012 | division by zero
|
||||
-----------------------------------------------------------------------------------------------+--------+---------+-----------------------------------
|
||||
ELECET * FROM unknown; | 21 | 42601 | syntax error at or near "ELECET"
|
||||
SELECT * FROM unknown; | 21 | 42P01 | relation "unknown" does not exist
|
||||
SELECT 1/0; | 21 | 22012 | division by zero
|
||||
SELECT pg_stat_monitor_reset() | 0 | |
|
||||
SELECT query, elevel, sqlcode, message FROM pg_stat_monitor ORDER BY query COLLATE "C",elevel | 0 | |
|
||||
do $$ +| 0 | |
|
||||
BEGIN +| | |
|
||||
RAISE WARNING 'warning message'; +| | |
|
||||
|
|
@ -35,7 +36,7 @@ SELECT query, elevel, sqlcode, message FROM pg_stat_monitor ORDER BY query COLLA
|
|||
BEGIN +| | |
|
||||
RAISE WARNING 'warning message'; +| | |
|
||||
END $$; | | |
|
||||
(6 rows)
|
||||
(7 rows)
|
||||
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
|
|
|
|||
|
|
@ -22,11 +22,12 @@ END $$;
|
|||
WARNING: warning message
|
||||
SELECT query, elevel, sqlcode, message FROM pg_stat_monitor ORDER BY query COLLATE "C",elevel;
|
||||
query | elevel | sqlcode | message
|
||||
----------------------------------+--------+---------+-----------------------------------
|
||||
ELECET * FROM unknown; | 21 | 42601 | syntax error at or near "ELECET"
|
||||
SELECT * FROM unknown; | 21 | 42P01 | relation "unknown" does not exist
|
||||
SELECT 1/0; | 21 | 22012 | division by zero
|
||||
-----------------------------------------------------------------------------------------------+--------+---------+-----------------------------------
|
||||
ELECET * FROM unknown; | 20 | 42601 | syntax error at or near "ELECET"
|
||||
SELECT * FROM unknown; | 20 | 42P01 | relation "unknown" does not exist
|
||||
SELECT 1/0; | 20 | 22012 | division by zero
|
||||
SELECT pg_stat_monitor_reset() | 0 | |
|
||||
SELECT query, elevel, sqlcode, message FROM pg_stat_monitor ORDER BY query COLLATE "C",elevel | 0 | |
|
||||
do $$ +| 0 | |
|
||||
BEGIN +| | |
|
||||
RAISE WARNING 'warning message'; +| | |
|
||||
|
|
@ -35,7 +36,7 @@ SELECT query, elevel, sqlcode, message FROM pg_stat_monitor ORDER BY query COLLA
|
|||
BEGIN +| | |
|
||||
RAISE WARNING 'warning message'; +| | |
|
||||
END $$; | | |
|
||||
(6 rows)
|
||||
(7 rows)
|
||||
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
|
|
|
|||
|
|
@ -1,42 +0,0 @@
|
|||
CREATE EXTENSION pg_stat_monitor;
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
-----------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
SELECT 1/0; -- divide by zero
|
||||
ERROR: division by zero
|
||||
SELECT * FROM unknown; -- unknown table
|
||||
ERROR: relation "unknown" does not exist
|
||||
LINE 1: SELECT * FROM unknown;
|
||||
^
|
||||
ELECET * FROM unknown; -- syntax error
|
||||
ERROR: syntax error at or near "ELECET"
|
||||
LINE 1: ELECET * FROM unknown;
|
||||
^
|
||||
do $$
|
||||
BEGIN
|
||||
RAISE WARNING 'warning message';
|
||||
END $$;
|
||||
WARNING: warning message
|
||||
SELECT query, elevel, sqlcode, message FROM pg_stat_monitor ORDER BY query COLLATE "C",elevel;
|
||||
query | elevel | sqlcode | message
|
||||
----------------------------------+--------+---------+-----------------------------------
|
||||
ELECET * FROM unknown; | 20 | 42601 | syntax error at or near "ELECET"
|
||||
SELECT * FROM unknown; | 20 | 42P01 | relation "unknown" does not exist
|
||||
SELECT 1/0; | 20 | 22012 | division by zero
|
||||
SELECT pg_stat_monitor_reset() | 0 | |
|
||||
do $$ +| 0 | 01000 | warning message
|
||||
BEGIN +| | |
|
||||
RAISE WARNING 'warning message';+| | |
|
||||
END $$; | | |
|
||||
(5 rows)
|
||||
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
-----------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
DROP EXTENSION pg_stat_monitor;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
DROP TABLE IF EXISTS Company;
|
||||
Drop Table if exists Company;
|
||||
NOTICE: table "company" does not exist, skipping
|
||||
CREATE TABLE Company(
|
||||
ID INT PRIMARY KEY NOT NULL,
|
||||
|
|
@ -15,15 +15,16 @@ INSERT INTO Company(ID, Name) VALUES (1, 'Percona');
|
|||
INSERT INTO Company(ID, Name) VALUES (1, 'Percona');
|
||||
ERROR: duplicate key value violates unique constraint "company_pkey"
|
||||
DETAIL: Key (id)=(1) already exists.
|
||||
DROP TABLE IF EXISTS Company;
|
||||
Drop Table if exists Company;
|
||||
SELECT query, elevel, sqlcode, message FROM pg_stat_monitor ORDER BY query COLLATE "C",elevel;
|
||||
query | elevel | sqlcode | message
|
||||
-------------------------------------------------------+--------+---------+---------------------------------------------------------------
|
||||
DROP TABLE IF EXISTS Company | 0 | |
|
||||
-----------------------------------------------------------------------------------------------+--------+---------+---------------------------------------------------------------
|
||||
Drop Table if exists Company | 0 | |
|
||||
INSERT INTO Company(ID, Name) VALUES (1, 'Percona') | 0 | |
|
||||
INSERT INTO Company(ID, Name) VALUES (1, 'Percona'); | 21 | 23505 | duplicate key value violates unique constraint "company_pkey"
|
||||
SELECT pg_stat_monitor_reset() | 0 | |
|
||||
(4 rows)
|
||||
SELECT query, elevel, sqlcode, message FROM pg_stat_monitor ORDER BY query COLLATE "C",elevel | 0 | |
|
||||
(5 rows)
|
||||
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
DROP TABLE IF EXISTS Company;
|
||||
Drop Table if exists Company;
|
||||
NOTICE: table "company" does not exist, skipping
|
||||
CREATE TABLE Company(
|
||||
ID INT PRIMARY KEY NOT NULL,
|
||||
|
|
@ -15,15 +15,16 @@ INSERT INTO Company(ID, Name) VALUES (1, 'Percona');
|
|||
INSERT INTO Company(ID, Name) VALUES (1, 'Percona');
|
||||
ERROR: duplicate key value violates unique constraint "company_pkey"
|
||||
DETAIL: Key (id)=(1) already exists.
|
||||
DROP TABLE IF EXISTS Company;
|
||||
Drop Table if exists Company;
|
||||
SELECT query, elevel, sqlcode, message FROM pg_stat_monitor ORDER BY query COLLATE "C",elevel;
|
||||
query | elevel | sqlcode | message
|
||||
-------------------------------------------------------+--------+---------+---------------------------------------------------------------
|
||||
DROP TABLE IF EXISTS Company | 0 | |
|
||||
-----------------------------------------------------------------------------------------------+--------+---------+---------------------------------------------------------------
|
||||
Drop Table if exists Company | 0 | |
|
||||
INSERT INTO Company(ID, Name) VALUES (1, 'Percona') | 0 | |
|
||||
INSERT INTO Company(ID, Name) VALUES (1, 'Percona'); | 20 | 23505 | duplicate key value violates unique constraint "company_pkey"
|
||||
SELECT pg_stat_monitor_reset() | 0 | |
|
||||
(4 rows)
|
||||
SELECT query, elevel, sqlcode, message FROM pg_stat_monitor ORDER BY query COLLATE "C",elevel | 0 | |
|
||||
(5 rows)
|
||||
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
|
|
|
|||
|
|
@ -1,49 +0,0 @@
|
|||
DROP ROLE IF EXISTS su;
|
||||
NOTICE: role "su" does not exist, skipping
|
||||
CREATE USER su WITH SUPERUSER;
|
||||
SET ROLE su;
|
||||
CREATE EXTENSION pg_stat_monitor;
|
||||
CREATE USER u1;
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
-----------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
SELECT routine_schema, routine_name, routine_type, data_type FROM information_schema.routines WHERE routine_schema = 'public' ORDER BY routine_name COLLATE "C";
|
||||
routine_schema | routine_name | routine_type | data_type
|
||||
----------------+--------------------------+--------------+-----------
|
||||
public | decode_error_level | FUNCTION | text
|
||||
public | get_cmd_type | FUNCTION | text
|
||||
public | get_histogram_timings | FUNCTION | text
|
||||
public | histogram | FUNCTION | record
|
||||
public | pg_stat_monitor_internal | FUNCTION | record
|
||||
public | pg_stat_monitor_reset | FUNCTION | void
|
||||
public | pg_stat_monitor_version | FUNCTION | text
|
||||
public | pgsm_create_13_view | FUNCTION | integer
|
||||
public | pgsm_create_14_view | FUNCTION | integer
|
||||
public | pgsm_create_15_view | FUNCTION | integer
|
||||
public | pgsm_create_17_view | FUNCTION | integer
|
||||
public | pgsm_create_18_view | FUNCTION | integer
|
||||
public | pgsm_create_view | FUNCTION | integer
|
||||
public | range | FUNCTION | ARRAY
|
||||
(14 rows)
|
||||
|
||||
SET ROLE u1;
|
||||
SELECT routine_schema, routine_name, routine_type, data_type FROM information_schema.routines WHERE routine_schema = 'public' ORDER BY routine_name COLLATE "C";
|
||||
routine_schema | routine_name | routine_type | data_type
|
||||
----------------+--------------------------+--------------+-----------
|
||||
public | decode_error_level | FUNCTION | text
|
||||
public | get_cmd_type | FUNCTION | text
|
||||
public | get_histogram_timings | FUNCTION | text
|
||||
public | histogram | FUNCTION | record
|
||||
public | pg_stat_monitor_internal | FUNCTION | record
|
||||
public | pg_stat_monitor_version | FUNCTION | text
|
||||
public | range | FUNCTION | ARRAY
|
||||
(7 rows)
|
||||
|
||||
SET ROLE su;
|
||||
DROP USER u1;
|
||||
DROP EXTENSION pg_stat_monitor;
|
||||
DROP USER su;
|
||||
ERROR: current user cannot be dropped
|
||||
|
|
@ -1,43 +0,0 @@
|
|||
DROP ROLE IF EXISTS su;
|
||||
NOTICE: role "su" does not exist, skipping
|
||||
CREATE USER su WITH SUPERUSER;
|
||||
SET ROLE su;
|
||||
CREATE EXTENSION pg_stat_monitor;
|
||||
CREATE USER u1;
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
-----------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
SELECT routine_schema, routine_name, routine_type, data_type FROM information_schema.routines WHERE routine_schema = 'public' ORDER BY routine_name COLLATE "C";
|
||||
routine_schema | routine_name | routine_type | data_type
|
||||
----------------+--------------------------+--------------+-----------
|
||||
public | decode_error_level | FUNCTION | text
|
||||
public | get_cmd_type | FUNCTION | text
|
||||
public | get_histogram_timings | FUNCTION | text
|
||||
public | histogram | FUNCTION | record
|
||||
public | pg_stat_monitor_internal | FUNCTION | record
|
||||
public | pg_stat_monitor_reset | FUNCTION | void
|
||||
public | pg_stat_monitor_version | FUNCTION | text
|
||||
public | pgsm_create_13_view | FUNCTION | integer
|
||||
public | pgsm_create_14_view | FUNCTION | integer
|
||||
public | pgsm_create_15_view | FUNCTION | integer
|
||||
public | pgsm_create_17_view | FUNCTION | integer
|
||||
public | pgsm_create_18_view | FUNCTION | integer
|
||||
public | pgsm_create_view | FUNCTION | integer
|
||||
public | range | FUNCTION | ARRAY
|
||||
(14 rows)
|
||||
|
||||
SET ROLE u1;
|
||||
SELECT routine_schema, routine_name, routine_type, data_type FROM information_schema.routines WHERE routine_schema = 'public' ORDER BY routine_name COLLATE "C";
|
||||
routine_schema | routine_name | routine_type | data_type
|
||||
----------------+-------------------------+--------------+-----------
|
||||
public | histogram | FUNCTION | record
|
||||
public | pg_stat_monitor_reset | FUNCTION | void
|
||||
public | pg_stat_monitor_version | FUNCTION | text
|
||||
(3 rows)
|
||||
|
||||
SET ROLE su;
|
||||
DROP USER u1;
|
||||
DROP EXTENSION pg_stat_monitor;
|
||||
|
|
@ -1,41 +1,40 @@
|
|||
CREATE EXTENSION pg_stat_monitor;
|
||||
SELECT name
|
||||
, setting
|
||||
, unit
|
||||
, context
|
||||
, vartype
|
||||
, source
|
||||
, min_val
|
||||
, max_val
|
||||
, enumvals
|
||||
, boot_val
|
||||
, reset_val
|
||||
, pending_restart
|
||||
FROM pg_settings
|
||||
WHERE name LIKE 'pg_stat_monitor.%'
|
||||
ORDER
|
||||
BY name
|
||||
COLLATE "C";
|
||||
name | setting | unit | context | vartype | source | min_val | max_val | enumvals | boot_val | reset_val | pending_restart
|
||||
----------------------------------------------+---------+------+------------+---------+---------+---------+------------+----------------+----------+-----------+-----------------
|
||||
pg_stat_monitor.pgsm_bucket_time | 60 | s | postmaster | integer | default | 1 | 2147483647 | | 60 | 60 | f
|
||||
pg_stat_monitor.pgsm_enable_overflow | on | | postmaster | bool | default | | | | on | on | f
|
||||
pg_stat_monitor.pgsm_enable_pgsm_query_id | on | | user | bool | default | | | | on | on | f
|
||||
pg_stat_monitor.pgsm_enable_query_plan | off | | user | bool | default | | | | off | off | f
|
||||
pg_stat_monitor.pgsm_extract_comments | off | | user | bool | default | | | | off | off | f
|
||||
pg_stat_monitor.pgsm_histogram_buckets | 20 | | postmaster | integer | default | 2 | 50 | | 20 | 20 | f
|
||||
pg_stat_monitor.pgsm_histogram_max | 100000 | ms | postmaster | real | default | 10 | 5e+07 | | 100000 | 100000 | f
|
||||
pg_stat_monitor.pgsm_histogram_min | 1 | ms | postmaster | real | default | 0 | 5e+07 | | 1 | 1 | f
|
||||
pg_stat_monitor.pgsm_max | 256 | MB | postmaster | integer | default | 10 | 10240 | | 256 | 256 | f
|
||||
pg_stat_monitor.pgsm_max_buckets | 10 | | postmaster | integer | default | 1 | 20000 | | 10 | 10 | f
|
||||
pg_stat_monitor.pgsm_normalized_query | off | | user | bool | default | | | | off | off | f
|
||||
pg_stat_monitor.pgsm_overflow_target | 1 | | postmaster | integer | default | 0 | 1 | | 1 | 1 | f
|
||||
pg_stat_monitor.pgsm_query_max_len | 2048 | | postmaster | integer | default | 1024 | 2147483647 | | 2048 | 2048 | f
|
||||
pg_stat_monitor.pgsm_query_shared_buffer | 20 | MB | postmaster | integer | default | 1 | 10000 | | 20 | 20 | f
|
||||
pg_stat_monitor.pgsm_track | top | | user | enum | default | | | {none,top,all} | top | top | f
|
||||
pg_stat_monitor.pgsm_track_application_names | on | | user | bool | default | | | | on | on | f
|
||||
pg_stat_monitor.pgsm_track_planning | off | | user | bool | default | | | | off | off | f
|
||||
pg_stat_monitor.pgsm_track_utility | on | | user | bool | default | | | | on | on | f
|
||||
(18 rows)
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
-----------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
select pg_sleep(.5);
|
||||
pg_sleep
|
||||
----------
|
||||
|
||||
(1 row)
|
||||
|
||||
SELECT * FROM pg_stat_monitor_settings ORDER BY name COLLATE "C";
|
||||
name | value | default_value | description | minimum | maximum | options | restart
|
||||
------------------------------------------+--------+---------------+----------------------------------------------------------------------------------------------------------+---------+------------+----------------+---------
|
||||
pg_stat_monitor.pgsm_bucket_time | 60 | 60 | Sets the time in seconds per bucket. | 1 | 2147483647 | | yes
|
||||
pg_stat_monitor.pgsm_enable_query_plan | no | no | Enable/Disable query plan monitoring | | | yes, no | no
|
||||
pg_stat_monitor.pgsm_extract_comments | no | no | Enable/Disable extracting comments from queries. | | | yes, no | no
|
||||
pg_stat_monitor.pgsm_histogram_buckets | 10 | 10 | Sets the maximum number of histogram buckets | 2 | 50 | | yes
|
||||
pg_stat_monitor.pgsm_histogram_max | 100000 | 100000 | Sets the time in millisecond. | 10 | 2147483647 | | yes
|
||||
pg_stat_monitor.pgsm_histogram_min | 0 | 0 | Sets the time in millisecond. | 0 | 2147483647 | | yes
|
||||
pg_stat_monitor.pgsm_max | 100 | 100 | Sets the maximum size of shared memory in (MB) used for statement's metadata tracked by pg_stat_monitor. | 1 | 1000 | | yes
|
||||
pg_stat_monitor.pgsm_max_buckets | 10 | 10 | Sets the maximum number of buckets. | 1 | 10 | | yes
|
||||
pg_stat_monitor.pgsm_normalized_query | no | no | Selects whether save query in normalized format. | | | yes, no | no
|
||||
pg_stat_monitor.pgsm_overflow_target | 1 | 1 | Sets the overflow target for pg_stat_monitor | 0 | 1 | | yes
|
||||
pg_stat_monitor.pgsm_query_max_len | 2048 | 2048 | Sets the maximum length of query. | 1024 | 2147483647 | | yes
|
||||
pg_stat_monitor.pgsm_query_shared_buffer | 20 | 20 | Sets the maximum size of shared memory in (MB) used for query tracked by pg_stat_monitor. | 1 | 10000 | | yes
|
||||
pg_stat_monitor.pgsm_track | top | top | Selects which statements are tracked by pg_stat_monitor. | | | none, top, all | no
|
||||
pg_stat_monitor.pgsm_track_planning | no | no | Selects whether planning statistics are tracked. | | | yes, no | no
|
||||
pg_stat_monitor.pgsm_track_utility | yes | yes | Selects whether utility commands are tracked. | | | yes, no | no
|
||||
(15 rows)
|
||||
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
-----------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
DROP EXTENSION pg_stat_monitor;
|
||||
|
|
|
|||
|
|
@ -1,40 +1,39 @@
|
|||
CREATE EXTENSION pg_stat_monitor;
|
||||
SELECT name
|
||||
, setting
|
||||
, unit
|
||||
, context
|
||||
, vartype
|
||||
, source
|
||||
, min_val
|
||||
, max_val
|
||||
, enumvals
|
||||
, boot_val
|
||||
, reset_val
|
||||
, pending_restart
|
||||
FROM pg_settings
|
||||
WHERE name LIKE 'pg_stat_monitor.%'
|
||||
ORDER
|
||||
BY name
|
||||
COLLATE "C";
|
||||
name | setting | unit | context | vartype | source | min_val | max_val | enumvals | boot_val | reset_val | pending_restart
|
||||
----------------------------------------------+---------+------+------------+---------+---------+---------+------------+----------------+----------+-----------+-----------------
|
||||
pg_stat_monitor.pgsm_bucket_time | 60 | s | postmaster | integer | default | 1 | 2147483647 | | 60 | 60 | f
|
||||
pg_stat_monitor.pgsm_enable_overflow | on | | postmaster | bool | default | | | | on | on | f
|
||||
pg_stat_monitor.pgsm_enable_pgsm_query_id | on | | user | bool | default | | | | on | on | f
|
||||
pg_stat_monitor.pgsm_enable_query_plan | off | | user | bool | default | | | | off | off | f
|
||||
pg_stat_monitor.pgsm_extract_comments | off | | user | bool | default | | | | off | off | f
|
||||
pg_stat_monitor.pgsm_histogram_buckets | 20 | | postmaster | integer | default | 2 | 50 | | 20 | 20 | f
|
||||
pg_stat_monitor.pgsm_histogram_max | 100000 | ms | postmaster | real | default | 10 | 5e+07 | | 100000 | 100000 | f
|
||||
pg_stat_monitor.pgsm_histogram_min | 1 | ms | postmaster | real | default | 0 | 5e+07 | | 1 | 1 | f
|
||||
pg_stat_monitor.pgsm_max | 256 | MB | postmaster | integer | default | 10 | 10240 | | 256 | 256 | f
|
||||
pg_stat_monitor.pgsm_max_buckets | 10 | | postmaster | integer | default | 1 | 20000 | | 10 | 10 | f
|
||||
pg_stat_monitor.pgsm_normalized_query | off | | user | bool | default | | | | off | off | f
|
||||
pg_stat_monitor.pgsm_overflow_target | 1 | | postmaster | integer | default | 0 | 1 | | 1 | 1 | f
|
||||
pg_stat_monitor.pgsm_query_max_len | 2048 | | postmaster | integer | default | 1024 | 2147483647 | | 2048 | 2048 | f
|
||||
pg_stat_monitor.pgsm_query_shared_buffer | 20 | MB | postmaster | integer | default | 1 | 10000 | | 20 | 20 | f
|
||||
pg_stat_monitor.pgsm_track | top | | user | enum | default | | | {none,top,all} | top | top | f
|
||||
pg_stat_monitor.pgsm_track_application_names | on | | user | bool | default | | | | on | on | f
|
||||
pg_stat_monitor.pgsm_track_utility | on | | user | bool | default | | | | on | on | f
|
||||
(17 rows)
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
-----------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
select pg_sleep(.5);
|
||||
pg_sleep
|
||||
----------
|
||||
|
||||
(1 row)
|
||||
|
||||
SELECT * FROM pg_stat_monitor_settings ORDER BY name COLLATE "C";
|
||||
name | value | default_value | description | minimum | maximum | options | restart
|
||||
------------------------------------------+--------+---------------+----------------------------------------------------------------------------------------------------------+---------+------------+----------------+---------
|
||||
pg_stat_monitor.pgsm_bucket_time | 60 | 60 | Sets the time in seconds per bucket. | 1 | 2147483647 | | yes
|
||||
pg_stat_monitor.pgsm_enable_query_plan | no | no | Enable/Disable query plan monitoring | | | yes, no | no
|
||||
pg_stat_monitor.pgsm_extract_comments | no | no | Enable/Disable extracting comments from queries. | | | yes, no | no
|
||||
pg_stat_monitor.pgsm_histogram_buckets | 10 | 10 | Sets the maximum number of histogram buckets | 2 | 50 | | yes
|
||||
pg_stat_monitor.pgsm_histogram_max | 100000 | 100000 | Sets the time in millisecond. | 10 | 2147483647 | | yes
|
||||
pg_stat_monitor.pgsm_histogram_min | 0 | 0 | Sets the time in millisecond. | 0 | 2147483647 | | yes
|
||||
pg_stat_monitor.pgsm_max | 100 | 100 | Sets the maximum size of shared memory in (MB) used for statement's metadata tracked by pg_stat_monitor. | 1 | 1000 | | yes
|
||||
pg_stat_monitor.pgsm_max_buckets | 10 | 10 | Sets the maximum number of buckets. | 1 | 10 | | yes
|
||||
pg_stat_monitor.pgsm_normalized_query | no | no | Selects whether save query in normalized format. | | | yes, no | no
|
||||
pg_stat_monitor.pgsm_overflow_target | 1 | 1 | Sets the overflow target for pg_stat_monitor | 0 | 1 | | yes
|
||||
pg_stat_monitor.pgsm_query_max_len | 2048 | 2048 | Sets the maximum length of query. | 1024 | 2147483647 | | yes
|
||||
pg_stat_monitor.pgsm_query_shared_buffer | 20 | 20 | Sets the maximum size of shared memory in (MB) used for query tracked by pg_stat_monitor. | 1 | 10000 | | yes
|
||||
pg_stat_monitor.pgsm_track | top | top | Selects which statements are tracked by pg_stat_monitor. | | | none, top, all | no
|
||||
pg_stat_monitor.pgsm_track_utility | yes | yes | Selects whether utility commands are tracked. | | | yes, no | no
|
||||
(14 rows)
|
||||
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
-----------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
DROP EXTENSION pg_stat_monitor;
|
||||
|
|
|
|||
|
|
@ -1,40 +0,0 @@
|
|||
CREATE EXTENSION pg_stat_monitor;
|
||||
SELECT name
|
||||
, setting
|
||||
, unit
|
||||
, context
|
||||
, vartype
|
||||
, source
|
||||
, min_val
|
||||
, max_val
|
||||
, enumvals
|
||||
, boot_val
|
||||
, reset_val
|
||||
, pending_restart
|
||||
FROM pg_settings
|
||||
WHERE name LIKE 'pg_stat_monitor.%'
|
||||
ORDER
|
||||
BY name
|
||||
COLLATE "C";
|
||||
name | setting | unit | context | vartype | source | min_val | max_val | enumvals | boot_val | reset_val | pending_restart
|
||||
----------------------------------------------+---------+------+------------+---------+---------+---------+------------+----------------+----------+-----------+-----------------
|
||||
pg_stat_monitor.pgsm_bucket_time | 60 | s | postmaster | integer | default | 1 | 2147483647 | | 60 | 60 | f
|
||||
pg_stat_monitor.pgsm_enable_overflow | on | | postmaster | bool | default | | | | on | on | f
|
||||
pg_stat_monitor.pgsm_enable_pgsm_query_id | on | | user | bool | default | | | | on | on | f
|
||||
pg_stat_monitor.pgsm_enable_query_plan | off | | user | bool | default | | | | off | off | f
|
||||
pg_stat_monitor.pgsm_extract_comments | off | | user | bool | default | | | | off | off | f
|
||||
pg_stat_monitor.pgsm_histogram_buckets | 20 | | postmaster | integer | default | 2 | 50 | | 20 | 20 | f
|
||||
pg_stat_monitor.pgsm_histogram_max | 100000 | | postmaster | real | default | 10 | 5e+07 | | 100000 | 100000 | f
|
||||
pg_stat_monitor.pgsm_histogram_min | 1 | | postmaster | real | default | 0 | 5e+07 | | 1 | 1 | f
|
||||
pg_stat_monitor.pgsm_max | 256 | MB | postmaster | integer | default | 10 | 10240 | | 256 | 256 | f
|
||||
pg_stat_monitor.pgsm_max_buckets | 10 | | postmaster | integer | default | 1 | 20000 | | 10 | 10 | f
|
||||
pg_stat_monitor.pgsm_normalized_query | off | | user | bool | default | | | | off | off | f
|
||||
pg_stat_monitor.pgsm_overflow_target | 1 | | postmaster | integer | default | 0 | 1 | | 1 | 1 | f
|
||||
pg_stat_monitor.pgsm_query_max_len | 2048 | | postmaster | integer | default | 1024 | 2147483647 | | 2048 | 2048 | f
|
||||
pg_stat_monitor.pgsm_query_shared_buffer | 20 | MB | postmaster | integer | default | 1 | 10000 | | 20 | 20 | f
|
||||
pg_stat_monitor.pgsm_track | top | | user | enum | default | | | {none,top,all} | top | top | f
|
||||
pg_stat_monitor.pgsm_track_application_names | on | | user | bool | default | | | | on | on | f
|
||||
pg_stat_monitor.pgsm_track_utility | on | | user | bool | default | | | | on | on | f
|
||||
(17 rows)
|
||||
|
||||
DROP EXTENSION pg_stat_monitor;
|
||||
|
|
@ -46,16 +46,17 @@ INFO: Sleep 5 seconds
|
|||
|
||||
SELECT substr(query, 0,50) as query, calls, resp_calls FROM pg_stat_monitor ORDER BY query COLLATE "C";
|
||||
query | calls | resp_calls
|
||||
--------------------------------------+-------+-----------------------
|
||||
---------------------------------------------------+-------+-----------------------
|
||||
SELECT pg_sleep(i) | 5 | {0,0,0,0,0,0,3,2,0,0}
|
||||
SELECT pg_stat_monitor_reset() | 1 | {1,0,0,0,0,0,0,0,0,0}
|
||||
SELECT substr(query, 0,50) as query, calls, resp_ | 1 | {1,0,0,0,0,0,0,0,0,0}
|
||||
Set pg_stat_monitor.pgsm_track='all' | 1 | {1,0,0,0,0,0,0,0,0,0}
|
||||
select run_pg_sleep(5) | 1 | {0,0,0,0,0,0,0,0,1,0}
|
||||
(4 rows)
|
||||
(5 rows)
|
||||
|
||||
select * from generate_histogram();
|
||||
range | freq | bar
|
||||
--------------------+------+--------------------------------
|
||||
--------------------+------+--------------------------------------------------------------------------------------------
|
||||
(0 - 3)} | 0 |
|
||||
(3 - 10)} | 0 |
|
||||
(10 - 31)} | 0 |
|
||||
|
|
|
|||
|
|
@ -46,10 +46,10 @@ INFO: Sleep 5 seconds
|
|||
|
||||
SELECT substr(query, 0,50) as query, calls, resp_calls FROM pg_stat_monitor ORDER BY query COLLATE "C";
|
||||
query | calls | resp_calls
|
||||
--------------------------------------+-------+-----------------------
|
||||
SELECT pg_sleep(i) | 2 | {0,0,0,0,0,0,2,0,0,0}
|
||||
SELECT pg_sleep(i) | 3 | {0,0,0,0,0,0,1,2,0,0}
|
||||
---------------------------------------------------+-------+-----------------------
|
||||
SELECT pg_sleep(i) | 5 | {0,0,0,0,0,0,3,2,0,0}
|
||||
SELECT pg_stat_monitor_reset() | 1 | {1,0,0,0,0,0,0,0,0,0}
|
||||
SELECT substr(query, 0,50) as query, calls, resp_ | 1 | {1,0,0,0,0,0,0,0,0,0}
|
||||
Set pg_stat_monitor.pgsm_track='all' | 1 | {1,0,0,0,0,0,0,0,0,0}
|
||||
select run_pg_sleep(5) | 1 | {0,0,0,0,0,0,0,0,1,0}
|
||||
(5 rows)
|
||||
|
|
@ -63,8 +63,8 @@ select * from generate_histogram();
|
|||
(31 - 100)} | 0 |
|
||||
(100 - 316)} | 0 |
|
||||
(316 - 1000)} | 0 |
|
||||
(1000 - 3162)} | 1 | â– â– â– â– â– â– â– â– â– â– â– â– â– â– â–
|
||||
(3162 - 10000)} | 2 | â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â–
|
||||
(1000 - 3162)} | 3 | â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â–
|
||||
(3162 - 10000)} | 2 | â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â–
|
||||
(10000 - 31622)} | 0 |
|
||||
(31622 - 100000)} | 0 |
|
||||
(10 rows)
|
||||
|
|
|
|||
|
|
@ -46,11 +46,14 @@ INFO: Sleep 5 seconds
|
|||
|
||||
SELECT substr(query, 0,50) as query, calls, resp_calls FROM pg_stat_monitor ORDER BY query COLLATE "C";
|
||||
query | calls | resp_calls
|
||||
--------------------------------+-------+-----------------------
|
||||
SELECT pg_sleep(i) | 5 | {0,0,0,0,0,0,3,2,0,0}
|
||||
---------------------------------------------------+-------+-----------------------
|
||||
SELECT pg_sleep(i) | 4 | {0,0,0,0,0,0,3,1,0,0}
|
||||
SELECT pg_sleep(i) | 1 | {0,0,0,0,0,0,0,1,0,0}
|
||||
SELECT pg_stat_monitor_reset() | 1 | {1,0,0,0,0,0,0,0,0,0}
|
||||
SELECT substr(query, 0,50) as query, calls, resp_ | 1 | {1,0,0,0,0,0,0,0,0,0}
|
||||
Set pg_stat_monitor.pgsm_track='all' | 1 | {1,0,0,0,0,0,0,0,0,0}
|
||||
select run_pg_sleep(5) | 1 | {0,0,0,0,0,0,0,0,1,0}
|
||||
(3 rows)
|
||||
(6 rows)
|
||||
|
||||
select * from generate_histogram();
|
||||
range | freq | bar
|
||||
|
|
@ -62,7 +65,7 @@ select * from generate_histogram();
|
|||
(100 - 316)} | 0 |
|
||||
(316 - 1000)} | 0 |
|
||||
(1000 - 3162)} | 3 | â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â–
|
||||
(3162 - 10000)} | 2 | â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â–
|
||||
(3162 - 10000)} | 1 | â– â– â– â– â– â– â– â– â– â–
|
||||
(10000 - 31622)} | 0 |
|
||||
(31622 - 100000)} | 0 |
|
||||
(10 rows)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,73 @@
|
|||
CREATE OR REPLACE FUNCTION generate_histogram()
|
||||
RETURNS TABLE (
|
||||
range TEXT, freq INT, bar TEXT
|
||||
) AS $$
|
||||
Declare
|
||||
bucket_id integer;
|
||||
query_id text;
|
||||
BEGIN
|
||||
select bucket into bucket_id from pg_stat_monitor order by calls desc limit 1;
|
||||
select queryid into query_id from pg_stat_monitor order by calls desc limit 1;
|
||||
--RAISE INFO 'bucket_id %', bucket_id;
|
||||
--RAISE INFO 'query_id %', query_id;
|
||||
return query
|
||||
SELECT * FROM histogram(bucket_id, query_id) AS a(range TEXT, freq INT, bar TEXT);
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
CREATE OR REPLACE FUNCTION run_pg_sleep(INTEGER) RETURNS VOID AS $$
|
||||
DECLARE
|
||||
loops ALIAS FOR $1;
|
||||
BEGIN
|
||||
FOR i IN 1..loops LOOP
|
||||
--RAISE INFO 'Current timestamp: %', timeofday()::TIMESTAMP;
|
||||
RAISE INFO 'Sleep % seconds', i;
|
||||
PERFORM pg_sleep(i);
|
||||
END LOOP;
|
||||
END;
|
||||
$$ LANGUAGE 'plpgsql' STRICT;
|
||||
CREATE EXTENSION pg_stat_monitor;
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
-----------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
Set pg_stat_monitor.pgsm_track='all';
|
||||
select run_pg_sleep(5);
|
||||
INFO: Sleep 1 seconds
|
||||
INFO: Sleep 2 seconds
|
||||
INFO: Sleep 3 seconds
|
||||
INFO: Sleep 4 seconds
|
||||
INFO: Sleep 5 seconds
|
||||
run_pg_sleep
|
||||
--------------
|
||||
|
||||
(1 row)
|
||||
|
||||
SELECT substr(query, 0,50) as query, calls, resp_calls FROM pg_stat_monitor ORDER BY query COLLATE "C";
|
||||
query | calls | resp_calls
|
||||
---------------------------------------------------+-------+-----------------------
|
||||
SELECT pg_sleep(i) | 3 | {0,0,0,0,0,0,3,0,0,0}
|
||||
SELECT pg_sleep(i) | 2 | {0,0,0,0,0,0,0,2,0,0}
|
||||
SELECT pg_stat_monitor_reset() | 1 | {1,0,0,0,0,0,0,0,0,0}
|
||||
SELECT substr(query, 0,50) as query, calls, resp_ | 1 | {1,0,0,0,0,0,0,0,0,0}
|
||||
Set pg_stat_monitor.pgsm_track='all' | 1 | {1,0,0,0,0,0,0,0,0,0}
|
||||
select run_pg_sleep(5) | 1 | {0,0,0,0,0,0,0,0,1,0}
|
||||
(6 rows)
|
||||
|
||||
select * from generate_histogram();
|
||||
range | freq | bar
|
||||
--------------------+------+--------------------------------------------------------------------------------------------
|
||||
(0 - 3)} | 0 |
|
||||
(3 - 10)} | 0 |
|
||||
(10 - 31)} | 0 |
|
||||
(31 - 100)} | 0 |
|
||||
(100 - 316)} | 0 |
|
||||
(316 - 1000)} | 0 |
|
||||
(1000 - 3162)} | 3 | â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â–
|
||||
(3162 - 10000)} | 0 |
|
||||
(10000 - 31622)} | 0 |
|
||||
(31622 - 100000)} | 0 |
|
||||
(10 rows)
|
||||
|
||||
DROP EXTENSION pg_stat_monitor;
|
||||
|
|
@ -0,0 +1,73 @@
|
|||
CREATE OR REPLACE FUNCTION generate_histogram()
|
||||
RETURNS TABLE (
|
||||
range TEXT, freq INT, bar TEXT
|
||||
) AS $$
|
||||
Declare
|
||||
bucket_id integer;
|
||||
query_id text;
|
||||
BEGIN
|
||||
select bucket into bucket_id from pg_stat_monitor order by calls desc limit 1;
|
||||
select queryid into query_id from pg_stat_monitor order by calls desc limit 1;
|
||||
--RAISE INFO 'bucket_id %', bucket_id;
|
||||
--RAISE INFO 'query_id %', query_id;
|
||||
return query
|
||||
SELECT * FROM histogram(bucket_id, query_id) AS a(range TEXT, freq INT, bar TEXT);
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
CREATE OR REPLACE FUNCTION run_pg_sleep(INTEGER) RETURNS VOID AS $$
|
||||
DECLARE
|
||||
loops ALIAS FOR $1;
|
||||
BEGIN
|
||||
FOR i IN 1..loops LOOP
|
||||
--RAISE INFO 'Current timestamp: %', timeofday()::TIMESTAMP;
|
||||
RAISE INFO 'Sleep % seconds', i;
|
||||
PERFORM pg_sleep(i);
|
||||
END LOOP;
|
||||
END;
|
||||
$$ LANGUAGE 'plpgsql' STRICT;
|
||||
CREATE EXTENSION pg_stat_monitor;
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
-----------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
Set pg_stat_monitor.pgsm_track='all';
|
||||
select run_pg_sleep(5);
|
||||
INFO: Sleep 1 seconds
|
||||
INFO: Sleep 2 seconds
|
||||
INFO: Sleep 3 seconds
|
||||
INFO: Sleep 4 seconds
|
||||
INFO: Sleep 5 seconds
|
||||
run_pg_sleep
|
||||
--------------
|
||||
|
||||
(1 row)
|
||||
|
||||
SELECT substr(query, 0,50) as query, calls, resp_calls FROM pg_stat_monitor ORDER BY query COLLATE "C";
|
||||
query | calls | resp_calls
|
||||
---------------------------------------------------+-------+-----------------------
|
||||
SELECT pg_sleep(i) | 3 | {0,0,0,0,0,0,3,0,0,0}
|
||||
SELECT pg_sleep(i) | 2 | {0,0,0,0,0,0,0,2,0,0}
|
||||
SELECT pg_stat_monitor_reset() | 1 | {1,0,0,0,0,0,0,0,0,0}
|
||||
SELECT substr(query, 0,50) as query, calls, resp_ | 1 | {1,0,0,0,0,0,0,0,0,0}
|
||||
Set pg_stat_monitor.pgsm_track='all' | 1 | {1,0,0,0,0,0,0,0,0,0}
|
||||
select run_pg_sleep(5) | 1 | {0,0,0,0,0,0,0,0,1,0}
|
||||
(6 rows)
|
||||
|
||||
select * from generate_histogram();
|
||||
range | freq | bar
|
||||
--------------------+------+--------------------------------
|
||||
(0 - 3)} | 0 |
|
||||
(3 - 10)} | 0 |
|
||||
(10 - 31)} | 0 |
|
||||
(31 - 100)} | 0 |
|
||||
(100 - 316)} | 0 |
|
||||
(316 - 1000)} | 0 |
|
||||
(1000 - 3162)} | 3 | â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â–
|
||||
(3162 - 10000)} | 0 |
|
||||
(10000 - 31622)} | 0 |
|
||||
(31622 - 100000)} | 0 |
|
||||
(10 rows)
|
||||
|
||||
DROP EXTENSION pg_stat_monitor;
|
||||
|
|
@ -0,0 +1,72 @@
|
|||
CREATE OR REPLACE FUNCTION generate_histogram()
|
||||
RETURNS TABLE (
|
||||
range TEXT, freq INT, bar TEXT
|
||||
) AS $$
|
||||
Declare
|
||||
bucket_id integer;
|
||||
query_id text;
|
||||
BEGIN
|
||||
select bucket into bucket_id from pg_stat_monitor order by calls desc limit 1;
|
||||
select queryid into query_id from pg_stat_monitor order by calls desc limit 1;
|
||||
--RAISE INFO 'bucket_id %', bucket_id;
|
||||
--RAISE INFO 'query_id %', query_id;
|
||||
return query
|
||||
SELECT * FROM histogram(bucket_id, query_id) AS a(range TEXT, freq INT, bar TEXT);
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
CREATE OR REPLACE FUNCTION run_pg_sleep(INTEGER) RETURNS VOID AS $$
|
||||
DECLARE
|
||||
loops ALIAS FOR $1;
|
||||
BEGIN
|
||||
FOR i IN 1..loops LOOP
|
||||
--RAISE INFO 'Current timestamp: %', timeofday()::TIMESTAMP;
|
||||
RAISE INFO 'Sleep % seconds', i;
|
||||
PERFORM pg_sleep(i);
|
||||
END LOOP;
|
||||
END;
|
||||
$$ LANGUAGE 'plpgsql' STRICT;
|
||||
CREATE EXTENSION pg_stat_monitor;
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
-----------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
Set pg_stat_monitor.pgsm_track='all';
|
||||
select run_pg_sleep(5);
|
||||
INFO: Sleep 1 seconds
|
||||
INFO: Sleep 2 seconds
|
||||
INFO: Sleep 3 seconds
|
||||
INFO: Sleep 4 seconds
|
||||
INFO: Sleep 5 seconds
|
||||
run_pg_sleep
|
||||
--------------
|
||||
|
||||
(1 row)
|
||||
|
||||
SELECT substr(query, 0,50) as query, calls, resp_calls FROM pg_stat_monitor ORDER BY query COLLATE "C";
|
||||
query | calls | resp_calls
|
||||
---------------------------------------------------+-------+-----------------------
|
||||
SELECT pg_sleep(i) | 4 | {0,0,0,0,0,0,2,2,0,0}
|
||||
SELECT pg_stat_monitor_reset() | 1 | {1,0,0,0,0,0,0,0,0,0}
|
||||
SELECT substr(query, 0,50) as query, calls, resp_ | 1 | {1,0,0,0,0,0,0,0,0,0}
|
||||
Set pg_stat_monitor.pgsm_track='all' | 1 | {1,0,0,0,0,0,0,0,0,0}
|
||||
select run_pg_sleep(5) | 1 | {0,0,0,0,0,0,0,0,1,0}
|
||||
(5 rows)
|
||||
|
||||
select * from generate_histogram();
|
||||
range | freq | bar
|
||||
--------------------+------+--------------------------------
|
||||
(0 - 3)} | 0 |
|
||||
(3 - 10)} | 0 |
|
||||
(10 - 31)} | 0 |
|
||||
(31 - 100)} | 0 |
|
||||
(100 - 316)} | 0 |
|
||||
(316 - 1000)} | 0 |
|
||||
(1000 - 3162)} | 2 | â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â–
|
||||
(3162 - 10000)} | 2 | â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â–
|
||||
(10000 - 31622)} | 0 |
|
||||
(31622 - 100000)} | 0 |
|
||||
(10 rows)
|
||||
|
||||
DROP EXTENSION pg_stat_monitor;
|
||||
|
|
@ -0,0 +1,73 @@
|
|||
CREATE OR REPLACE FUNCTION generate_histogram()
|
||||
RETURNS TABLE (
|
||||
range TEXT, freq INT, bar TEXT
|
||||
) AS $$
|
||||
Declare
|
||||
bucket_id integer;
|
||||
query_id text;
|
||||
BEGIN
|
||||
select bucket into bucket_id from pg_stat_monitor order by calls desc limit 1;
|
||||
select queryid into query_id from pg_stat_monitor order by calls desc limit 1;
|
||||
--RAISE INFO 'bucket_id %', bucket_id;
|
||||
--RAISE INFO 'query_id %', query_id;
|
||||
return query
|
||||
SELECT * FROM histogram(bucket_id, query_id) AS a(range TEXT, freq INT, bar TEXT);
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
CREATE OR REPLACE FUNCTION run_pg_sleep(INTEGER) RETURNS VOID AS $$
|
||||
DECLARE
|
||||
loops ALIAS FOR $1;
|
||||
BEGIN
|
||||
FOR i IN 1..loops LOOP
|
||||
--RAISE INFO 'Current timestamp: %', timeofday()::TIMESTAMP;
|
||||
RAISE INFO 'Sleep % seconds', i;
|
||||
PERFORM pg_sleep(i);
|
||||
END LOOP;
|
||||
END;
|
||||
$$ LANGUAGE 'plpgsql' STRICT;
|
||||
CREATE EXTENSION pg_stat_monitor;
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
-----------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
Set pg_stat_monitor.pgsm_track='all';
|
||||
select run_pg_sleep(5);
|
||||
INFO: Sleep 1 seconds
|
||||
INFO: Sleep 2 seconds
|
||||
INFO: Sleep 3 seconds
|
||||
INFO: Sleep 4 seconds
|
||||
INFO: Sleep 5 seconds
|
||||
run_pg_sleep
|
||||
--------------
|
||||
|
||||
(1 row)
|
||||
|
||||
SELECT substr(query, 0,50) as query, calls, resp_calls FROM pg_stat_monitor ORDER BY query COLLATE "C";
|
||||
query | calls | resp_calls
|
||||
---------------------------------------------------+-------+-----------------------
|
||||
SELECT pg_sleep(i) | 2 | {0,0,0,0,0,0,2,0,0,0}
|
||||
SELECT pg_sleep(i) | 3 | {0,0,0,0,0,0,1,2,0,0}
|
||||
SELECT pg_stat_monitor_reset() | 1 | {1,0,0,0,0,0,0,0,0,0}
|
||||
SELECT substr(query, 0,50) as query, calls, resp_ | 1 | {1,0,0,0,0,0,0,0,0,0}
|
||||
Set pg_stat_monitor.pgsm_track='all' | 1 | {1,0,0,0,0,0,0,0,0,0}
|
||||
select run_pg_sleep(5) | 1 | {0,0,0,0,0,0,0,0,1,0}
|
||||
(6 rows)
|
||||
|
||||
select * from generate_histogram();
|
||||
range | freq | bar
|
||||
--------------------+------+--------------------------------
|
||||
(0 - 3)} | 0 |
|
||||
(3 - 10)} | 0 |
|
||||
(10 - 31)} | 0 |
|
||||
(31 - 100)} | 0 |
|
||||
(100 - 316)} | 0 |
|
||||
(316 - 1000)} | 0 |
|
||||
(1000 - 3162)} | 1 | â– â– â– â– â– â– â– â– â– â– â– â– â– â– â–
|
||||
(3162 - 10000)} | 2 | â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â–
|
||||
(10000 - 31622)} | 0 |
|
||||
(31622 - 100000)} | 0 |
|
||||
(10 rows)
|
||||
|
||||
DROP EXTENSION pg_stat_monitor;
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
--
|
||||
-- Statement level tracking
|
||||
--
|
||||
SELECT setting::integer < 140000 AS skip_test FROM pg_settings where name = 'server_version_num' \gset
|
||||
\if :skip_test
|
||||
\quit
|
||||
|
|
@ -1,326 +0,0 @@
|
|||
--
|
||||
-- Statement level tracking
|
||||
--
|
||||
SELECT setting::integer < 140000 AS skip_test FROM pg_settings where name = 'server_version_num' \gset
|
||||
\if :skip_test
|
||||
\quit
|
||||
\endif
|
||||
CREATE EXTENSION pg_stat_monitor;
|
||||
SET pg_stat_monitor.pgsm_track_utility = TRUE;
|
||||
SET pg_stat_monitor.pgsm_normalized_query = TRUE;
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
-----------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
-- DO block - top-level tracking.
|
||||
CREATE TABLE stats_track_tab (x int);
|
||||
SET pg_stat_monitor.pgsm_track = 'top';
|
||||
DELETE FROM stats_track_tab;
|
||||
DO $$
|
||||
BEGIN
|
||||
DELETE FROM stats_track_tab;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
SELECT toplevel, calls, query FROM pg_stat_monitor
|
||||
WHERE query LIKE '%DELETE%' ORDER BY query COLLATE "C", toplevel;
|
||||
toplevel | calls | query
|
||||
----------+-------+--------------------------------
|
||||
t | 1 | DELETE FROM stats_track_tab
|
||||
t | 1 | DO $$ +
|
||||
| | BEGIN +
|
||||
| | DELETE FROM stats_track_tab;+
|
||||
| | END; +
|
||||
| | $$ LANGUAGE plpgsql
|
||||
(2 rows)
|
||||
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
-----------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
-- DO block - all-level tracking.
|
||||
SET pg_stat_monitor.pgsm_track = 'all';
|
||||
DELETE FROM stats_track_tab;
|
||||
DO $$
|
||||
BEGIN
|
||||
DELETE FROM stats_track_tab;
|
||||
END; $$;
|
||||
DO LANGUAGE plpgsql $$
|
||||
BEGIN
|
||||
-- this is a SELECT
|
||||
PERFORM 'hello world'::TEXT;
|
||||
END; $$;
|
||||
SELECT toplevel, calls, query FROM pg_stat_monitor
|
||||
ORDER BY query COLLATE "C", toplevel;
|
||||
toplevel | calls | query
|
||||
----------+-------+----------------------------------------
|
||||
f | 1 | DELETE FROM stats_track_tab
|
||||
t | 1 | DELETE FROM stats_track_tab
|
||||
t | 1 | DO $$ +
|
||||
| | BEGIN +
|
||||
| | DELETE FROM stats_track_tab; +
|
||||
| | END; $$
|
||||
t | 1 | DO LANGUAGE plpgsql $$ +
|
||||
| | BEGIN +
|
||||
| | -- this is a SELECT +
|
||||
| | PERFORM 'hello world'::TEXT; +
|
||||
| | END; $$
|
||||
f | 1 | SELECT $1::TEXT
|
||||
t | 1 | SELECT pg_stat_monitor_reset()
|
||||
t | 1 | SET pg_stat_monitor.pgsm_track = 'all'
|
||||
(7 rows)
|
||||
|
||||
-- DO block - top-level tracking without utility.
|
||||
SET pg_stat_monitor.pgsm_track = 'top';
|
||||
SET pg_stat_monitor.pgsm_track_utility = FALSE;
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
-----------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
DELETE FROM stats_track_tab;
|
||||
DO $$
|
||||
BEGIN
|
||||
DELETE FROM stats_track_tab;
|
||||
END; $$;
|
||||
DO LANGUAGE plpgsql $$
|
||||
BEGIN
|
||||
-- this is a SELECT
|
||||
PERFORM 'hello world'::TEXT;
|
||||
END; $$;
|
||||
SELECT toplevel, calls, query FROM pg_stat_monitor
|
||||
ORDER BY query COLLATE "C", toplevel;
|
||||
toplevel | calls | query
|
||||
----------+-------+--------------------------------
|
||||
t | 2 | DELETE FROM stats_track_tab
|
||||
t | 1 | SELECT $1::TEXT
|
||||
t | 1 | SELECT pg_stat_monitor_reset()
|
||||
(3 rows)
|
||||
|
||||
-- DO block - all-level tracking without utility.
|
||||
SET pg_stat_monitor.pgsm_track = 'all';
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
-----------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
DELETE FROM stats_track_tab;
|
||||
DO $$
|
||||
BEGIN
|
||||
DELETE FROM stats_track_tab;
|
||||
END; $$;
|
||||
DO LANGUAGE plpgsql $$
|
||||
BEGIN
|
||||
-- this is a SELECT
|
||||
PERFORM 'hello world'::TEXT;
|
||||
END; $$;
|
||||
SELECT toplevel, calls, query FROM pg_stat_monitor
|
||||
ORDER BY query COLLATE "C", toplevel;
|
||||
toplevel | calls | query
|
||||
----------+-------+--------------------------------
|
||||
t | 2 | DELETE FROM stats_track_tab
|
||||
t | 1 | SELECT $1::TEXT
|
||||
t | 1 | SELECT pg_stat_monitor_reset()
|
||||
(3 rows)
|
||||
|
||||
-- PL/pgSQL function - top-level tracking.
|
||||
SET pg_stat_monitor.pgsm_track = 'top';
|
||||
SET pg_stat_monitor.pgsm_track_utility = FALSE;
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
-----------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
CREATE FUNCTION PLUS_TWO(i INTEGER) RETURNS INTEGER AS $$
|
||||
DECLARE
|
||||
r INTEGER;
|
||||
BEGIN
|
||||
SELECT (i + 1 + 1.0)::INTEGER INTO r;
|
||||
RETURN r;
|
||||
END; $$ LANGUAGE plpgsql;
|
||||
SELECT PLUS_TWO(3);
|
||||
plus_two
|
||||
----------
|
||||
5
|
||||
(1 row)
|
||||
|
||||
SELECT PLUS_TWO(7);
|
||||
plus_two
|
||||
----------
|
||||
9
|
||||
(1 row)
|
||||
|
||||
-- SQL function --- use LIMIT to keep it from being inlined
|
||||
CREATE FUNCTION PLUS_ONE(i INTEGER) RETURNS INTEGER AS
|
||||
$$ SELECT (i + 1.0)::INTEGER LIMIT 1 $$ LANGUAGE SQL;
|
||||
SELECT PLUS_ONE(8);
|
||||
plus_one
|
||||
----------
|
||||
9
|
||||
(1 row)
|
||||
|
||||
SELECT PLUS_ONE(10);
|
||||
plus_one
|
||||
----------
|
||||
11
|
||||
(1 row)
|
||||
|
||||
SELECT calls, rows, query FROM pg_stat_monitor ORDER BY query COLLATE "C";
|
||||
calls | rows | query
|
||||
-------+------+--------------------------------
|
||||
2 | 2 | SELECT PLUS_ONE($1)
|
||||
2 | 2 | SELECT PLUS_TWO($1)
|
||||
1 | 1 | SELECT pg_stat_monitor_reset()
|
||||
(3 rows)
|
||||
|
||||
-- immutable SQL function --- can be executed at plan time
|
||||
CREATE FUNCTION PLUS_THREE(i INTEGER) RETURNS INTEGER AS
|
||||
$$ SELECT i + 3 LIMIT 1 $$ IMMUTABLE LANGUAGE SQL;
|
||||
SELECT PLUS_THREE(8);
|
||||
plus_three
|
||||
------------
|
||||
11
|
||||
(1 row)
|
||||
|
||||
SELECT PLUS_THREE(10);
|
||||
plus_three
|
||||
------------
|
||||
13
|
||||
(1 row)
|
||||
|
||||
SELECT toplevel, calls, rows, query FROM pg_stat_monitor ORDER BY query COLLATE "C";
|
||||
toplevel | calls | rows | query
|
||||
----------+-------+------+---------------------------------------------------------------------------
|
||||
t | 2 | 2 | SELECT PLUS_ONE($1)
|
||||
t | 2 | 2 | SELECT PLUS_THREE($1)
|
||||
t | 2 | 2 | SELECT PLUS_TWO($1)
|
||||
t | 1 | 3 | SELECT calls, rows, query FROM pg_stat_monitor ORDER BY query COLLATE "C"
|
||||
f | 2 | 2 | SELECT i + $2 LIMIT $3
|
||||
t | 1 | 1 | SELECT pg_stat_monitor_reset()
|
||||
(6 rows)
|
||||
|
||||
-- PL/pgSQL function - all-level tracking.
|
||||
SET pg_stat_monitor.pgsm_track = 'all';
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
-----------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
-- we drop and recreate the functions to avoid any caching funnies
|
||||
DROP FUNCTION PLUS_ONE(INTEGER);
|
||||
DROP FUNCTION PLUS_TWO(INTEGER);
|
||||
DROP FUNCTION PLUS_THREE(INTEGER);
|
||||
-- PL/pgSQL function
|
||||
CREATE FUNCTION PLUS_TWO(i INTEGER) RETURNS INTEGER AS $$
|
||||
DECLARE
|
||||
r INTEGER;
|
||||
BEGIN
|
||||
SELECT (i + 1 + 1.0)::INTEGER INTO r;
|
||||
RETURN r;
|
||||
END; $$ LANGUAGE plpgsql;
|
||||
SELECT PLUS_TWO(-1);
|
||||
plus_two
|
||||
----------
|
||||
1
|
||||
(1 row)
|
||||
|
||||
SELECT PLUS_TWO(2);
|
||||
plus_two
|
||||
----------
|
||||
4
|
||||
(1 row)
|
||||
|
||||
-- SQL function --- use LIMIT to keep it from being inlined
|
||||
CREATE FUNCTION PLUS_ONE(i INTEGER) RETURNS INTEGER AS
|
||||
$$ SELECT (i + 1.0)::INTEGER LIMIT 1 $$ LANGUAGE SQL;
|
||||
SELECT PLUS_ONE(3);
|
||||
plus_one
|
||||
----------
|
||||
4
|
||||
(1 row)
|
||||
|
||||
SELECT PLUS_ONE(1);
|
||||
plus_one
|
||||
----------
|
||||
2
|
||||
(1 row)
|
||||
|
||||
SELECT calls, rows, query FROM pg_stat_monitor ORDER BY query COLLATE "C";
|
||||
calls | rows | query
|
||||
-------+------+-----------------------------------
|
||||
2 | 2 | SELECT (i + $2 + $3)::INTEGER
|
||||
2 | 2 | SELECT (i + $2)::INTEGER LIMIT $3
|
||||
2 | 2 | SELECT PLUS_ONE($1)
|
||||
2 | 2 | SELECT PLUS_TWO($1)
|
||||
1 | 1 | SELECT pg_stat_monitor_reset()
|
||||
(5 rows)
|
||||
|
||||
-- immutable SQL function --- can be executed at plan time
|
||||
CREATE FUNCTION PLUS_THREE(i INTEGER) RETURNS INTEGER AS
|
||||
$$ SELECT i + 3 LIMIT 1 $$ IMMUTABLE LANGUAGE SQL;
|
||||
SELECT PLUS_THREE(8);
|
||||
plus_three
|
||||
------------
|
||||
11
|
||||
(1 row)
|
||||
|
||||
SELECT PLUS_THREE(10);
|
||||
plus_three
|
||||
------------
|
||||
13
|
||||
(1 row)
|
||||
|
||||
SELECT toplevel, calls, rows, query FROM pg_stat_monitor ORDER BY query COLLATE "C";
|
||||
toplevel | calls | rows | query
|
||||
----------+-------+------+---------------------------------------------------------------------------
|
||||
f | 2 | 2 | SELECT (i + $2 + $3)::INTEGER
|
||||
f | 2 | 2 | SELECT (i + $2)::INTEGER LIMIT $3
|
||||
t | 2 | 2 | SELECT PLUS_ONE($1)
|
||||
t | 2 | 2 | SELECT PLUS_THREE($1)
|
||||
t | 2 | 2 | SELECT PLUS_TWO($1)
|
||||
t | 1 | 5 | SELECT calls, rows, query FROM pg_stat_monitor ORDER BY query COLLATE "C"
|
||||
f | 2 | 2 | SELECT i + $2 LIMIT $3
|
||||
t | 1 | 1 | SELECT pg_stat_monitor_reset()
|
||||
(8 rows)
|
||||
|
||||
--
|
||||
-- pg_stat_monitor.pgsm_track = none
|
||||
--
|
||||
SET pg_stat_monitor.pgsm_track = 'none';
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
-----------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
SELECT 1 AS "one";
|
||||
one
|
||||
-----
|
||||
1
|
||||
(1 row)
|
||||
|
||||
SELECT 1 + 1 AS "two";
|
||||
two
|
||||
-----
|
||||
2
|
||||
(1 row)
|
||||
|
||||
SELECT calls, rows, query FROM pg_stat_monitor ORDER BY query COLLATE "C";
|
||||
calls | rows | query
|
||||
-------+------+-------
|
||||
(0 rows)
|
||||
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
-----------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
DROP EXTENSION pg_stat_monitor;
|
||||
|
|
@ -1,325 +0,0 @@
|
|||
--
|
||||
-- Statement level tracking
|
||||
--
|
||||
SELECT setting::integer < 140000 AS skip_test FROM pg_settings where name = 'server_version_num' \gset
|
||||
\if :skip_test
|
||||
\quit
|
||||
\endif
|
||||
CREATE EXTENSION pg_stat_monitor;
|
||||
SET pg_stat_monitor.pgsm_track_utility = TRUE;
|
||||
SET pg_stat_monitor.pgsm_normalized_query = TRUE;
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
-----------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
-- DO block - top-level tracking.
|
||||
CREATE TABLE stats_track_tab (x int);
|
||||
SET pg_stat_monitor.pgsm_track = 'top';
|
||||
DELETE FROM stats_track_tab;
|
||||
DO $$
|
||||
BEGIN
|
||||
DELETE FROM stats_track_tab;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
SELECT toplevel, calls, query FROM pg_stat_monitor
|
||||
WHERE query LIKE '%DELETE%' ORDER BY query COLLATE "C", toplevel;
|
||||
toplevel | calls | query
|
||||
----------+-------+--------------------------------
|
||||
t | 1 | DELETE FROM stats_track_tab
|
||||
t | 1 | DO $$ +
|
||||
| | BEGIN +
|
||||
| | DELETE FROM stats_track_tab;+
|
||||
| | END; +
|
||||
| | $$ LANGUAGE plpgsql
|
||||
(2 rows)
|
||||
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
-----------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
-- DO block - all-level tracking.
|
||||
SET pg_stat_monitor.pgsm_track = 'all';
|
||||
DELETE FROM stats_track_tab;
|
||||
DO $$
|
||||
BEGIN
|
||||
DELETE FROM stats_track_tab;
|
||||
END; $$;
|
||||
DO LANGUAGE plpgsql $$
|
||||
BEGIN
|
||||
-- this is a SELECT
|
||||
PERFORM 'hello world'::TEXT;
|
||||
END; $$;
|
||||
SELECT toplevel, calls, query FROM pg_stat_monitor
|
||||
ORDER BY query COLLATE "C", toplevel;
|
||||
toplevel | calls | query
|
||||
----------+-------+----------------------------------------
|
||||
f | 1 | DELETE FROM stats_track_tab
|
||||
t | 1 | DELETE FROM stats_track_tab
|
||||
t | 1 | DO $$ +
|
||||
| | BEGIN +
|
||||
| | DELETE FROM stats_track_tab; +
|
||||
| | END; $$
|
||||
t | 1 | DO LANGUAGE plpgsql $$ +
|
||||
| | BEGIN +
|
||||
| | -- this is a SELECT +
|
||||
| | PERFORM 'hello world'::TEXT; +
|
||||
| | END; $$
|
||||
f | 1 | SELECT $1::TEXT
|
||||
t | 1 | SELECT pg_stat_monitor_reset()
|
||||
t | 1 | SET pg_stat_monitor.pgsm_track = 'all'
|
||||
(7 rows)
|
||||
|
||||
-- DO block - top-level tracking without utility.
|
||||
SET pg_stat_monitor.pgsm_track = 'top';
|
||||
SET pg_stat_monitor.pgsm_track_utility = FALSE;
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
-----------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
DELETE FROM stats_track_tab;
|
||||
DO $$
|
||||
BEGIN
|
||||
DELETE FROM stats_track_tab;
|
||||
END; $$;
|
||||
DO LANGUAGE plpgsql $$
|
||||
BEGIN
|
||||
-- this is a SELECT
|
||||
PERFORM 'hello world'::TEXT;
|
||||
END; $$;
|
||||
SELECT toplevel, calls, query FROM pg_stat_monitor
|
||||
ORDER BY query COLLATE "C", toplevel;
|
||||
toplevel | calls | query
|
||||
----------+-------+--------------------------------
|
||||
t | 1 | DELETE FROM stats_track_tab
|
||||
t | 1 | SELECT pg_stat_monitor_reset()
|
||||
(2 rows)
|
||||
|
||||
-- DO block - all-level tracking without utility.
|
||||
SET pg_stat_monitor.pgsm_track = 'all';
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
-----------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
DELETE FROM stats_track_tab;
|
||||
DO $$
|
||||
BEGIN
|
||||
DELETE FROM stats_track_tab;
|
||||
END; $$;
|
||||
DO LANGUAGE plpgsql $$
|
||||
BEGIN
|
||||
-- this is a SELECT
|
||||
PERFORM 'hello world'::TEXT;
|
||||
END; $$;
|
||||
SELECT toplevel, calls, query FROM pg_stat_monitor
|
||||
ORDER BY query COLLATE "C", toplevel;
|
||||
toplevel | calls | query
|
||||
----------+-------+--------------------------------
|
||||
f | 1 | DELETE FROM stats_track_tab
|
||||
t | 1 | DELETE FROM stats_track_tab
|
||||
f | 1 | SELECT $1::TEXT
|
||||
t | 1 | SELECT pg_stat_monitor_reset()
|
||||
(4 rows)
|
||||
|
||||
-- PL/pgSQL function - top-level tracking.
|
||||
SET pg_stat_monitor.pgsm_track = 'top';
|
||||
SET pg_stat_monitor.pgsm_track_utility = FALSE;
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
-----------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
CREATE FUNCTION PLUS_TWO(i INTEGER) RETURNS INTEGER AS $$
|
||||
DECLARE
|
||||
r INTEGER;
|
||||
BEGIN
|
||||
SELECT (i + 1 + 1.0)::INTEGER INTO r;
|
||||
RETURN r;
|
||||
END; $$ LANGUAGE plpgsql;
|
||||
SELECT PLUS_TWO(3);
|
||||
plus_two
|
||||
----------
|
||||
5
|
||||
(1 row)
|
||||
|
||||
SELECT PLUS_TWO(7);
|
||||
plus_two
|
||||
----------
|
||||
9
|
||||
(1 row)
|
||||
|
||||
-- SQL function --- use LIMIT to keep it from being inlined
|
||||
CREATE FUNCTION PLUS_ONE(i INTEGER) RETURNS INTEGER AS
|
||||
$$ SELECT (i + 1.0)::INTEGER LIMIT 1 $$ LANGUAGE SQL;
|
||||
SELECT PLUS_ONE(8);
|
||||
plus_one
|
||||
----------
|
||||
9
|
||||
(1 row)
|
||||
|
||||
SELECT PLUS_ONE(10);
|
||||
plus_one
|
||||
----------
|
||||
11
|
||||
(1 row)
|
||||
|
||||
SELECT calls, rows, query FROM pg_stat_monitor ORDER BY query COLLATE "C";
|
||||
calls | rows | query
|
||||
-------+------+--------------------------------
|
||||
2 | 2 | SELECT PLUS_ONE($1)
|
||||
2 | 2 | SELECT PLUS_TWO($1)
|
||||
1 | 1 | SELECT pg_stat_monitor_reset()
|
||||
(3 rows)
|
||||
|
||||
-- immutable SQL function --- can be executed at plan time
|
||||
CREATE FUNCTION PLUS_THREE(i INTEGER) RETURNS INTEGER AS
|
||||
$$ SELECT i + 3 LIMIT 1 $$ IMMUTABLE LANGUAGE SQL;
|
||||
SELECT PLUS_THREE(8);
|
||||
plus_three
|
||||
------------
|
||||
11
|
||||
(1 row)
|
||||
|
||||
SELECT PLUS_THREE(10);
|
||||
plus_three
|
||||
------------
|
||||
13
|
||||
(1 row)
|
||||
|
||||
SELECT toplevel, calls, rows, query FROM pg_stat_monitor ORDER BY query COLLATE "C";
|
||||
toplevel | calls | rows | query
|
||||
----------+-------+------+---------------------------------------------------------------------------
|
||||
t | 2 | 2 | SELECT PLUS_ONE($1)
|
||||
t | 2 | 2 | SELECT PLUS_THREE($1)
|
||||
t | 2 | 2 | SELECT PLUS_TWO($1)
|
||||
t | 1 | 3 | SELECT calls, rows, query FROM pg_stat_monitor ORDER BY query COLLATE "C"
|
||||
t | 1 | 1 | SELECT pg_stat_monitor_reset()
|
||||
(5 rows)
|
||||
|
||||
-- PL/pgSQL function - all-level tracking.
|
||||
SET pg_stat_monitor.pgsm_track = 'all';
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
-----------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
-- we drop and recreate the functions to avoid any caching funnies
|
||||
DROP FUNCTION PLUS_ONE(INTEGER);
|
||||
DROP FUNCTION PLUS_TWO(INTEGER);
|
||||
DROP FUNCTION PLUS_THREE(INTEGER);
|
||||
-- PL/pgSQL function
|
||||
CREATE FUNCTION PLUS_TWO(i INTEGER) RETURNS INTEGER AS $$
|
||||
DECLARE
|
||||
r INTEGER;
|
||||
BEGIN
|
||||
SELECT (i + 1 + 1.0)::INTEGER INTO r;
|
||||
RETURN r;
|
||||
END; $$ LANGUAGE plpgsql;
|
||||
SELECT PLUS_TWO(-1);
|
||||
plus_two
|
||||
----------
|
||||
1
|
||||
(1 row)
|
||||
|
||||
SELECT PLUS_TWO(2);
|
||||
plus_two
|
||||
----------
|
||||
4
|
||||
(1 row)
|
||||
|
||||
-- SQL function --- use LIMIT to keep it from being inlined
|
||||
CREATE FUNCTION PLUS_ONE(i INTEGER) RETURNS INTEGER AS
|
||||
$$ SELECT (i + 1.0)::INTEGER LIMIT 1 $$ LANGUAGE SQL;
|
||||
SELECT PLUS_ONE(3);
|
||||
plus_one
|
||||
----------
|
||||
4
|
||||
(1 row)
|
||||
|
||||
SELECT PLUS_ONE(1);
|
||||
plus_one
|
||||
----------
|
||||
2
|
||||
(1 row)
|
||||
|
||||
SELECT calls, rows, query FROM pg_stat_monitor ORDER BY query COLLATE "C";
|
||||
calls | rows | query
|
||||
-------+------+-----------------------------------
|
||||
2 | 2 | SELECT (i + $2 + $3)::INTEGER
|
||||
2 | 2 | SELECT (i + $2)::INTEGER LIMIT $3
|
||||
2 | 2 | SELECT PLUS_ONE($1)
|
||||
2 | 2 | SELECT PLUS_TWO($1)
|
||||
1 | 1 | SELECT pg_stat_monitor_reset()
|
||||
(5 rows)
|
||||
|
||||
-- immutable SQL function --- can be executed at plan time
|
||||
CREATE FUNCTION PLUS_THREE(i INTEGER) RETURNS INTEGER AS
|
||||
$$ SELECT i + 3 LIMIT 1 $$ IMMUTABLE LANGUAGE SQL;
|
||||
SELECT PLUS_THREE(8);
|
||||
plus_three
|
||||
------------
|
||||
11
|
||||
(1 row)
|
||||
|
||||
SELECT PLUS_THREE(10);
|
||||
plus_three
|
||||
------------
|
||||
13
|
||||
(1 row)
|
||||
|
||||
SELECT toplevel, calls, rows, query FROM pg_stat_monitor ORDER BY query COLLATE "C";
|
||||
toplevel | calls | rows | query
|
||||
----------+-------+------+---------------------------------------------------------------------------
|
||||
f | 2 | 2 | SELECT (i + $2 + $3)::INTEGER
|
||||
f | 2 | 2 | SELECT (i + $2)::INTEGER LIMIT $3
|
||||
t | 2 | 2 | SELECT PLUS_ONE($1)
|
||||
t | 2 | 2 | SELECT PLUS_THREE($1)
|
||||
t | 2 | 2 | SELECT PLUS_TWO($1)
|
||||
t | 1 | 5 | SELECT calls, rows, query FROM pg_stat_monitor ORDER BY query COLLATE "C"
|
||||
f | 2 | 2 | SELECT i + $2 LIMIT $3
|
||||
t | 1 | 1 | SELECT pg_stat_monitor_reset()
|
||||
(8 rows)
|
||||
|
||||
--
|
||||
-- pg_stat_monitor.pgsm_track = none
|
||||
--
|
||||
SET pg_stat_monitor.pgsm_track = 'none';
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
-----------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
SELECT 1 AS "one";
|
||||
one
|
||||
-----
|
||||
1
|
||||
(1 row)
|
||||
|
||||
SELECT 1 + 1 AS "two";
|
||||
two
|
||||
-----
|
||||
2
|
||||
(1 row)
|
||||
|
||||
SELECT calls, rows, query FROM pg_stat_monitor ORDER BY query COLLATE "C";
|
||||
calls | rows | query
|
||||
-------+------+-------
|
||||
(0 rows)
|
||||
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
-----------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
DROP EXTENSION pg_stat_monitor;
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
--
|
||||
-- Tests for parallel statistics
|
||||
--
|
||||
SELECT setting::integer < 180000 AS skip_test FROM pg_settings where name = 'server_version_num' \gset
|
||||
\if :skip_test
|
||||
\quit
|
||||
|
|
@ -1,39 +0,0 @@
|
|||
--
|
||||
-- Tests for parallel statistics
|
||||
--
|
||||
SELECT setting::integer < 180000 AS skip_test FROM pg_settings where name = 'server_version_num' \gset
|
||||
\if :skip_test
|
||||
\quit
|
||||
\endif
|
||||
CREATE EXTENSION pg_stat_monitor;
|
||||
SET pgsm.track_utility = FALSE;
|
||||
-- encourage use of parallel plans
|
||||
SET parallel_setup_cost = 0;
|
||||
SET parallel_tuple_cost = 0;
|
||||
SET min_parallel_table_scan_size = 0;
|
||||
SET max_parallel_workers_per_gather = 2;
|
||||
CREATE TABLE pgsm_parallel_tab (a int);
|
||||
SELECT pg_stat_monitor_reset() IS NOT NULL AS t;
|
||||
t
|
||||
---
|
||||
t
|
||||
(1 row)
|
||||
|
||||
SELECT count(*) FROM pgsm_parallel_tab;
|
||||
count
|
||||
-------
|
||||
0
|
||||
(1 row)
|
||||
|
||||
SELECT query,
|
||||
parallel_workers_to_launch > 0 AS has_workers_to_launch,
|
||||
parallel_workers_launched > 0 AS has_workers_launched
|
||||
FROM pg_stat_monitor
|
||||
WHERE query ~ 'SELECT count'
|
||||
ORDER BY query COLLATE "C";
|
||||
query | has_workers_to_launch | has_workers_launched
|
||||
----------------------------------------+-----------------------+----------------------
|
||||
SELECT count(*) FROM pgsm_parallel_tab | t | t
|
||||
(1 row)
|
||||
|
||||
DROP TABLE pgsm_parallel_tab;
|
||||
|
|
@ -0,0 +1,442 @@
|
|||
CREATE EXTENSION pg_stat_monitor;
|
||||
--
|
||||
-- simple and compound statements
|
||||
--
|
||||
SET pg_stat_monitor.track_utility = FALSE;
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
-----------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
SELECT 1 AS "int";
|
||||
int
|
||||
-----
|
||||
1
|
||||
(1 row)
|
||||
|
||||
SELECT 'hello'
|
||||
-- multiline
|
||||
AS "text";
|
||||
text
|
||||
-------
|
||||
hello
|
||||
(1 row)
|
||||
|
||||
SELECT 'world' AS "text";
|
||||
text
|
||||
-------
|
||||
world
|
||||
(1 row)
|
||||
|
||||
-- transaction
|
||||
BEGIN;
|
||||
SELECT 1 AS "int";
|
||||
int
|
||||
-----
|
||||
1
|
||||
(1 row)
|
||||
|
||||
SELECT 'hello' AS "text";
|
||||
text
|
||||
-------
|
||||
hello
|
||||
(1 row)
|
||||
|
||||
COMMIT;
|
||||
-- compound transaction
|
||||
BEGIN \;
|
||||
SELECT 2.0 AS "float" \;
|
||||
SELECT 'world' AS "text" \;
|
||||
COMMIT;
|
||||
-- compound with empty statements and spurious leading spacing
|
||||
\;\; SELECT 3 + 3 \;\;\; SELECT ' ' || ' !' \;\; SELECT 1 + 4 \;;
|
||||
?column?
|
||||
----------
|
||||
5
|
||||
(1 row)
|
||||
|
||||
-- non ;-terminated statements
|
||||
SELECT 1 + 1 + 1 AS "add" \gset
|
||||
SELECT :add + 1 + 1 AS "add" \;
|
||||
SELECT :add + 1 + 1 AS "add" \gset
|
||||
-- set operator
|
||||
SELECT 1 AS i UNION SELECT 2 ORDER BY i;
|
||||
i
|
||||
---
|
||||
1
|
||||
2
|
||||
(2 rows)
|
||||
|
||||
-- ? operator
|
||||
select '{"a":1, "b":2}'::jsonb ? 'b';
|
||||
?column?
|
||||
----------
|
||||
t
|
||||
(1 row)
|
||||
|
||||
-- cte
|
||||
WITH t(f) AS (
|
||||
VALUES (1.0), (2.0)
|
||||
)
|
||||
SELECT f FROM t ORDER BY f;
|
||||
f
|
||||
-----
|
||||
1.0
|
||||
2.0
|
||||
(2 rows)
|
||||
|
||||
-- prepared statement with parameter
|
||||
PREPARE pgss_test (int) AS SELECT $1, 'test' LIMIT 1;
|
||||
EXECUTE pgss_test(1);
|
||||
?column? | ?column?
|
||||
----------+----------
|
||||
1 | test
|
||||
(1 row)
|
||||
|
||||
DEALLOCATE pgss_test;
|
||||
SELECT query, calls, rows FROM pg_stat_monitor ORDER BY query COLLATE "C";
|
||||
query | calls | rows
|
||||
---------------------------------------------------------------------------+-------+------
|
||||
BEGIN | 2 | 0
|
||||
COMMIT | 2 | 0
|
||||
PREPARE pgss_test (int) AS SELECT $1, $2 LIMIT $3 | 1 | 1
|
||||
SELECT $1 | 2 | 2
|
||||
SELECT $1 +| 4 | 4
|
||||
+| |
|
||||
AS "text" | |
|
||||
SELECT $1 + $2 | 2 | 2
|
||||
SELECT $1 + $2 + $3 AS "add" | 3 | 3
|
||||
SELECT $1 AS "float" | 1 | 1
|
||||
SELECT $1 AS i UNION SELECT $2 ORDER BY i | 1 | 2
|
||||
SELECT $1 || $2 | 1 | 1
|
||||
SELECT pg_stat_monitor_reset() | 1 | 1
|
||||
SELECT query, calls, rows FROM pg_stat_monitor ORDER BY query COLLATE "C" | 1 | 0
|
||||
WITH t(f) AS ( +| 1 | 2
|
||||
VALUES ($1), ($2) +| |
|
||||
) +| |
|
||||
SELECT f FROM t ORDER BY f | |
|
||||
select $1::jsonb ? $2 | 1 | 1
|
||||
(14 rows)
|
||||
|
||||
--
|
||||
-- CRUD: INSERT SELECT UPDATE DELETE on test table
|
||||
--
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
-----------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
-- utility "create table" should not be shown
|
||||
CREATE TEMP TABLE test (a int, b char(20));
|
||||
INSERT INTO test VALUES(generate_series(1, 10), 'aaa');
|
||||
UPDATE test SET b = 'bbb' WHERE a > 7;
|
||||
DELETE FROM test WHERE a > 9;
|
||||
-- explicit transaction
|
||||
BEGIN;
|
||||
UPDATE test SET b = '111' WHERE a = 1 ;
|
||||
COMMIT;
|
||||
BEGIN \;
|
||||
UPDATE test SET b = '222' WHERE a = 2 \;
|
||||
COMMIT ;
|
||||
UPDATE test SET b = '333' WHERE a = 3 \;
|
||||
UPDATE test SET b = '444' WHERE a = 4 ;
|
||||
BEGIN \;
|
||||
UPDATE test SET b = '555' WHERE a = 5 \;
|
||||
UPDATE test SET b = '666' WHERE a = 6 \;
|
||||
COMMIT ;
|
||||
-- many INSERT values
|
||||
INSERT INTO test (a, b) VALUES (1, 'a'), (2, 'b'), (3, 'c');
|
||||
-- SELECT with constants
|
||||
SELECT * FROM test WHERE a > 5 ORDER BY a ;
|
||||
a | b
|
||||
---+----------------------
|
||||
6 | 666
|
||||
7 | aaa
|
||||
8 | bbb
|
||||
9 | bbb
|
||||
(4 rows)
|
||||
|
||||
SELECT *
|
||||
FROM test
|
||||
WHERE a > 9
|
||||
ORDER BY a ;
|
||||
a | b
|
||||
---+---
|
||||
(0 rows)
|
||||
|
||||
-- SELECT without constants
|
||||
SELECT * FROM test ORDER BY a;
|
||||
a | b
|
||||
---+----------------------
|
||||
1 | a
|
||||
1 | 111
|
||||
2 | b
|
||||
2 | 222
|
||||
3 | c
|
||||
3 | 333
|
||||
4 | 444
|
||||
5 | 555
|
||||
6 | 666
|
||||
7 | aaa
|
||||
8 | bbb
|
||||
9 | bbb
|
||||
(12 rows)
|
||||
|
||||
-- SELECT with IN clause
|
||||
SELECT * FROM test WHERE a IN (1, 2, 3, 4, 5);
|
||||
a | b
|
||||
---+----------------------
|
||||
1 | 111
|
||||
2 | 222
|
||||
3 | 333
|
||||
4 | 444
|
||||
5 | 555
|
||||
1 | a
|
||||
2 | b
|
||||
3 | c
|
||||
(8 rows)
|
||||
|
||||
SELECT query, calls, rows FROM pg_stat_monitor ORDER BY query COLLATE "C";
|
||||
query | calls | rows
|
||||
---------------------------------------------------------------------------+-------+------
|
||||
BEGIN | 3 | 0
|
||||
COMMIT | 3 | 0
|
||||
CREATE TEMP TABLE test (a int, b char(20)) | 1 | 0
|
||||
DELETE FROM test WHERE a > $1 | 1 | 1
|
||||
INSERT INTO test (a, b) VALUES ($1, $2), ($3, $4), ($5, $6) | 1 | 3
|
||||
INSERT INTO test VALUES(generate_series($1, $2), $3) | 1 | 10
|
||||
SELECT * FROM test ORDER BY a | 1 | 12
|
||||
SELECT * FROM test WHERE a > $1 ORDER BY a | 2 | 4
|
||||
SELECT * FROM test WHERE a IN ($1, $2, $3, $4, $5) | 1 | 8
|
||||
SELECT pg_stat_monitor_reset() | 1 | 1
|
||||
SELECT query, calls, rows FROM pg_stat_monitor ORDER BY query COLLATE "C" | 1 | 0
|
||||
UPDATE test SET b = $1 WHERE a = $2 | 6 | 6
|
||||
UPDATE test SET b = $1 WHERE a > $2 | 1 | 3
|
||||
(13 rows)
|
||||
|
||||
--
|
||||
-- pg_stat_monitor.track = none
|
||||
--
|
||||
SET pg_stat_monitor.track = 'none';
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
-----------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
SELECT 1 AS "one";
|
||||
one
|
||||
-----
|
||||
1
|
||||
(1 row)
|
||||
|
||||
SELECT 1 + 1 AS "two";
|
||||
two
|
||||
-----
|
||||
2
|
||||
(1 row)
|
||||
|
||||
SELECT query, calls, rows FROM pg_stat_monitor ORDER BY query COLLATE "C";
|
||||
query | calls | rows
|
||||
---------------------------------------------------------------------------+-------+------
|
||||
SELECT $1 | 1 | 1
|
||||
SELECT $1 + $2 | 1 | 1
|
||||
SELECT pg_stat_monitor_reset() | 1 | 1
|
||||
SELECT query, calls, rows FROM pg_stat_monitor ORDER BY query COLLATE "C" | 1 | 0
|
||||
(4 rows)
|
||||
|
||||
--
|
||||
-- pg_stat_monitor.track = top
|
||||
--
|
||||
SET pg_stat_monitor.track = 'top';
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
-----------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
DO LANGUAGE plpgsql $$
|
||||
BEGIN
|
||||
-- this is a SELECT
|
||||
PERFORM 'hello world'::TEXT;
|
||||
END;
|
||||
$$;
|
||||
-- PL/pgSQL function
|
||||
CREATE FUNCTION PLUS_TWO(i INTEGER) RETURNS INTEGER AS $$
|
||||
DECLARE
|
||||
r INTEGER;
|
||||
BEGIN
|
||||
SELECT (i + 1 + 1.0)::INTEGER INTO r;
|
||||
RETURN r;
|
||||
END; $$ LANGUAGE plpgsql;
|
||||
SELECT PLUS_TWO(3);
|
||||
plus_two
|
||||
----------
|
||||
5
|
||||
(1 row)
|
||||
|
||||
SELECT PLUS_TWO(7);
|
||||
plus_two
|
||||
----------
|
||||
9
|
||||
(1 row)
|
||||
|
||||
-- SQL function --- use LIMIT to keep it from being inlined
|
||||
CREATE FUNCTION PLUS_ONE(i INTEGER) RETURNS INTEGER AS
|
||||
$$ SELECT (i + 1.0)::INTEGER LIMIT 1 $$ LANGUAGE SQL;
|
||||
SELECT PLUS_ONE(8);
|
||||
plus_one
|
||||
----------
|
||||
9
|
||||
(1 row)
|
||||
|
||||
SELECT PLUS_ONE(10);
|
||||
plus_one
|
||||
----------
|
||||
11
|
||||
(1 row)
|
||||
|
||||
SELECT query, calls, rows FROM pg_stat_monitor ORDER BY query COLLATE "C";
|
||||
query | calls | rows
|
||||
---------------------------------------------------------------------------+-------+------
|
||||
CREATE FUNCTION PLUS_ONE(i INTEGER) RETURNS INTEGER AS +| 1 | 0
|
||||
$$ SELECT (i + 1.0)::INTEGER LIMIT 1 $$ LANGUAGE SQL | |
|
||||
CREATE FUNCTION PLUS_TWO(i INTEGER) RETURNS INTEGER AS $$ +| 1 | 0
|
||||
DECLARE +| |
|
||||
r INTEGER; +| |
|
||||
BEGIN +| |
|
||||
SELECT (i + 1 + 1.0)::INTEGER INTO r; +| |
|
||||
RETURN r; +| |
|
||||
END; $$ LANGUAGE plpgsql | |
|
||||
DO LANGUAGE plpgsql $$ +| 1 | 0
|
||||
BEGIN +| |
|
||||
-- this is a SELECT +| |
|
||||
PERFORM 'hello world'::TEXT; +| |
|
||||
END; +| |
|
||||
$$ | |
|
||||
SELECT $1 +| 1 | 1
|
||||
+| |
|
||||
AS "text" | |
|
||||
SELECT (i + $2 + $3)::INTEGER | 2 | 2
|
||||
SELECT (i + $2)::INTEGER LIMIT $3 | 2 | 2
|
||||
SELECT PLUS_ONE($1) | 2 | 2
|
||||
SELECT PLUS_TWO($1) | 2 | 2
|
||||
SELECT pg_stat_monitor_reset() | 1 | 1
|
||||
SELECT query, calls, rows FROM pg_stat_monitor ORDER BY query COLLATE "C" | 1 | 0
|
||||
(10 rows)
|
||||
|
||||
--
|
||||
-- pg_stat_monitor.track = all
|
||||
--
|
||||
SET pg_stat_monitor.track = 'all';
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
-----------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
-- we drop and recreate the functions to avoid any caching funnies
|
||||
DROP FUNCTION PLUS_ONE(INTEGER);
|
||||
DROP FUNCTION PLUS_TWO(INTEGER);
|
||||
-- PL/pgSQL function
|
||||
CREATE FUNCTION PLUS_TWO(i INTEGER) RETURNS INTEGER AS $$
|
||||
DECLARE
|
||||
r INTEGER;
|
||||
BEGIN
|
||||
SELECT (i + 1 + 1.0)::INTEGER INTO r;
|
||||
RETURN r;
|
||||
END; $$ LANGUAGE plpgsql;
|
||||
SELECT PLUS_TWO(-1);
|
||||
plus_two
|
||||
----------
|
||||
1
|
||||
(1 row)
|
||||
|
||||
SELECT PLUS_TWO(2);
|
||||
plus_two
|
||||
----------
|
||||
4
|
||||
(1 row)
|
||||
|
||||
-- SQL function --- use LIMIT to keep it from being inlined
|
||||
CREATE FUNCTION PLUS_ONE(i INTEGER) RETURNS INTEGER AS
|
||||
$$ SELECT (i + 1.0)::INTEGER LIMIT 1 $$ LANGUAGE SQL;
|
||||
SELECT PLUS_ONE(3);
|
||||
plus_one
|
||||
----------
|
||||
4
|
||||
(1 row)
|
||||
|
||||
SELECT PLUS_ONE(1);
|
||||
plus_one
|
||||
----------
|
||||
2
|
||||
(1 row)
|
||||
|
||||
SELECT query, calls, rows FROM pg_stat_monitor ORDER BY query COLLATE "C";
|
||||
query | calls | rows
|
||||
---------------------------------------------------------------------------+-------+------
|
||||
CREATE FUNCTION PLUS_ONE(i INTEGER) RETURNS INTEGER AS +| 1 | 0
|
||||
$$ SELECT (i + 1.0)::INTEGER LIMIT 1 $$ LANGUAGE SQL | |
|
||||
CREATE FUNCTION PLUS_TWO(i INTEGER) RETURNS INTEGER AS $$ +| 1 | 0
|
||||
DECLARE +| |
|
||||
r INTEGER; +| |
|
||||
BEGIN +| |
|
||||
SELECT (i + 1 + 1.0)::INTEGER INTO r; +| |
|
||||
RETURN r; +| |
|
||||
END; $$ LANGUAGE plpgsql | |
|
||||
DROP FUNCTION PLUS_ONE(INTEGER) | 1 | 0
|
||||
DROP FUNCTION PLUS_TWO(INTEGER) | 1 | 0
|
||||
SELECT (i + $2 + $3)::INTEGER | 2 | 2
|
||||
SELECT (i + $2)::INTEGER LIMIT $3 | 2 | 2
|
||||
SELECT PLUS_ONE($1) | 2 | 2
|
||||
SELECT PLUS_TWO($1) | 2 | 2
|
||||
SELECT pg_stat_monitor_reset() | 1 | 1
|
||||
SELECT query, calls, rows FROM pg_stat_monitor ORDER BY query COLLATE "C" | 1 | 0
|
||||
(10 rows)
|
||||
|
||||
--
|
||||
-- utility commands
|
||||
--
|
||||
SET pg_stat_monitor.track_utility = TRUE;
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
-----------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
SELECT 1;
|
||||
?column?
|
||||
----------
|
||||
1
|
||||
(1 row)
|
||||
|
||||
CREATE INDEX test_b ON test(b);
|
||||
DROP TABLE test \;
|
||||
DROP TABLE IF EXISTS test \;
|
||||
DROP FUNCTION PLUS_ONE(INTEGER);
|
||||
NOTICE: table "test" does not exist, skipping
|
||||
DROP TABLE IF EXISTS test \;
|
||||
DROP TABLE IF EXISTS test \;
|
||||
DROP FUNCTION IF EXISTS PLUS_ONE(INTEGER);
|
||||
NOTICE: table "test" does not exist, skipping
|
||||
NOTICE: table "test" does not exist, skipping
|
||||
NOTICE: function plus_one(pg_catalog.int4) does not exist, skipping
|
||||
DROP FUNCTION PLUS_TWO(INTEGER);
|
||||
SELECT query, calls, rows FROM pg_stat_monitor ORDER BY query COLLATE "C";
|
||||
query | calls | rows
|
||||
---------------------------------------------------------------------------+-------+------
|
||||
CREATE INDEX test_b ON test(b) | 1 | 0
|
||||
DROP FUNCTION IF EXISTS PLUS_ONE(INTEGER) | 1 | 0
|
||||
DROP FUNCTION PLUS_ONE(INTEGER) | 1 | 0
|
||||
DROP FUNCTION PLUS_TWO(INTEGER) | 1 | 0
|
||||
DROP TABLE IF EXISTS test | 3 | 0
|
||||
DROP TABLE test | 1 | 0
|
||||
SELECT $1 | 1 | 1
|
||||
SELECT pg_stat_monitor_reset() | 1 | 1
|
||||
SELECT query, calls, rows FROM pg_stat_monitor ORDER BY query COLLATE "C" | 1 | 0
|
||||
(9 rows)
|
||||
|
||||
DROP EXTENSION pg_stat_monitor;
|
||||
|
|
@ -1,117 +0,0 @@
|
|||
CREATE EXTENSION pg_stat_monitor;
|
||||
CREATE DATABASE db1;
|
||||
CREATE DATABASE db2;
|
||||
\c db1
|
||||
CREATE TABLE t1 (a int);
|
||||
CREATE TABLE t2 (b int);
|
||||
CREATE FUNCTION add(integer, integer) RETURNS integer
|
||||
AS 'select $1 + $2;'
|
||||
LANGUAGE SQL
|
||||
IMMUTABLE
|
||||
RETURNS NULL ON NULL INPUT;
|
||||
\c db2
|
||||
CREATE TABLE t1 (a int);
|
||||
CREATE TABLE t3 (c int);
|
||||
CREATE FUNCTION add(integer, integer) RETURNS integer
|
||||
AS 'select $1 + $2;'
|
||||
LANGUAGE SQL
|
||||
IMMUTABLE
|
||||
RETURNS NULL ON NULL INPUT;
|
||||
\c contrib_regression
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
-----------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
\c db1
|
||||
SELECT * FROM t1;
|
||||
a
|
||||
---
|
||||
(0 rows)
|
||||
|
||||
SELECT *, ADD(1, 2) FROM t1;
|
||||
a | add
|
||||
---+-----
|
||||
(0 rows)
|
||||
|
||||
SELECT * FROM t2;
|
||||
b
|
||||
---
|
||||
(0 rows)
|
||||
|
||||
-- Check that spaces and comments do not generate a different pgsm_query_id
|
||||
SELECT * FROM t2 --WHATEVER;
|
||||
;
|
||||
b
|
||||
---
|
||||
(0 rows)
|
||||
|
||||
SELECT * FROM t2 /* ...
|
||||
...
|
||||
More comments to check for spaces.
|
||||
*/
|
||||
;
|
||||
b
|
||||
---
|
||||
(0 rows)
|
||||
|
||||
\c db2
|
||||
SELECT * FROM t1;
|
||||
a
|
||||
---
|
||||
(0 rows)
|
||||
|
||||
SELECT *, ADD(1, 2) FROM t1;
|
||||
a | add
|
||||
---+-----
|
||||
(0 rows)
|
||||
|
||||
set pg_stat_monitor.pgsm_enable_pgsm_query_id = off;
|
||||
SELECT * FROM t3;
|
||||
c
|
||||
---
|
||||
(0 rows)
|
||||
|
||||
set pg_stat_monitor.pgsm_enable_pgsm_query_id = on;
|
||||
SELECT * FROM t3 where c = 20;
|
||||
c
|
||||
---
|
||||
(0 rows)
|
||||
|
||||
\c contrib_regression
|
||||
SELECT datname, pgsm_query_id, query, calls FROM pg_stat_monitor ORDER BY pgsm_query_id, query, datname;
|
||||
datname | pgsm_query_id | query | calls
|
||||
--------------------+---------------------+-----------------------------------------------------+-------
|
||||
contrib_regression | 689150021118383254 | SELECT pg_stat_monitor_reset() | 1
|
||||
db1 | 1897482803466821995 | SELECT * FROM t2 | 3
|
||||
db1 | 1988437669671417938 | SELECT * FROM t1 | 1
|
||||
db2 | 1988437669671417938 | SELECT * FROM t1 | 1
|
||||
db1 | 2864453209316739369 | select $1 + $2 | 1
|
||||
db2 | 2864453209316739369 | select $1 + $2 | 1
|
||||
db2 | 6220142855706866455 | set pg_stat_monitor.pgsm_enable_pgsm_query_id = on | 1
|
||||
db2 | 6633979598391393345 | SELECT * FROM t3 where c = 20 | 1
|
||||
db1 | 8140395000078788481 | SELECT *, ADD(1, 2) FROM t1 | 1
|
||||
db2 | 8140395000078788481 | SELECT *, ADD(1, 2) FROM t1 | 1
|
||||
db2 | | SELECT * FROM t3 | 1
|
||||
db2 | | set pg_stat_monitor.pgsm_enable_pgsm_query_id = off | 1
|
||||
(12 rows)
|
||||
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
-----------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
\c db1
|
||||
DROP TABLE t1;
|
||||
DROP TABLE t2;
|
||||
DROP FUNCTION ADD;
|
||||
\c db2
|
||||
DROP TABLE t1;
|
||||
DROP TABLE t3;
|
||||
DROP FUNCTION ADD;
|
||||
\c contrib_regression
|
||||
DROP DATABASE db1;
|
||||
DROP DATABASE db2;
|
||||
DROP EXTENSION pg_stat_monitor;
|
||||
|
|
@ -1,115 +0,0 @@
|
|||
CREATE EXTENSION pg_stat_monitor;
|
||||
CREATE DATABASE db1;
|
||||
CREATE DATABASE db2;
|
||||
\c db1
|
||||
CREATE TABLE t1 (a int);
|
||||
CREATE TABLE t2 (b int);
|
||||
CREATE FUNCTION add(integer, integer) RETURNS integer
|
||||
AS 'select $1 + $2;'
|
||||
LANGUAGE SQL
|
||||
IMMUTABLE
|
||||
RETURNS NULL ON NULL INPUT;
|
||||
\c db2
|
||||
CREATE TABLE t1 (a int);
|
||||
CREATE TABLE t3 (c int);
|
||||
CREATE FUNCTION add(integer, integer) RETURNS integer
|
||||
AS 'select $1 + $2;'
|
||||
LANGUAGE SQL
|
||||
IMMUTABLE
|
||||
RETURNS NULL ON NULL INPUT;
|
||||
\c contrib_regression
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
-----------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
\c db1
|
||||
SELECT * FROM t1;
|
||||
a
|
||||
---
|
||||
(0 rows)
|
||||
|
||||
SELECT *, ADD(1, 2) FROM t1;
|
||||
a | add
|
||||
---+-----
|
||||
(0 rows)
|
||||
|
||||
SELECT * FROM t2;
|
||||
b
|
||||
---
|
||||
(0 rows)
|
||||
|
||||
-- Check that spaces and comments do not generate a different pgsm_query_id
|
||||
SELECT * FROM t2 --WHATEVER;
|
||||
;
|
||||
b
|
||||
---
|
||||
(0 rows)
|
||||
|
||||
SELECT * FROM t2 /* ...
|
||||
...
|
||||
More comments to check for spaces.
|
||||
*/
|
||||
;
|
||||
b
|
||||
---
|
||||
(0 rows)
|
||||
|
||||
\c db2
|
||||
SELECT * FROM t1;
|
||||
a
|
||||
---
|
||||
(0 rows)
|
||||
|
||||
SELECT *, ADD(1, 2) FROM t1;
|
||||
a | add
|
||||
---+-----
|
||||
(0 rows)
|
||||
|
||||
set pg_stat_monitor.pgsm_enable_pgsm_query_id = off;
|
||||
SELECT * FROM t3;
|
||||
c
|
||||
---
|
||||
(0 rows)
|
||||
|
||||
set pg_stat_monitor.pgsm_enable_pgsm_query_id = on;
|
||||
SELECT * FROM t3 where c = 20;
|
||||
c
|
||||
---
|
||||
(0 rows)
|
||||
|
||||
\c contrib_regression
|
||||
SELECT datname, pgsm_query_id, query, calls FROM pg_stat_monitor ORDER BY pgsm_query_id, query, datname;
|
||||
datname | pgsm_query_id | query | calls
|
||||
--------------------+---------------------+-----------------------------------------------------+-------
|
||||
contrib_regression | 689150021118383254 | SELECT pg_stat_monitor_reset() | 1
|
||||
db1 | 1897482803466821995 | SELECT * FROM t2 | 3
|
||||
db1 | 1988437669671417938 | SELECT * FROM t1 | 1
|
||||
db2 | 1988437669671417938 | SELECT * FROM t1 | 1
|
||||
db2 | 6220142855706866455 | set pg_stat_monitor.pgsm_enable_pgsm_query_id = on | 1
|
||||
db2 | 6633979598391393345 | SELECT * FROM t3 where c = 20 | 1
|
||||
db1 | 8140395000078788481 | SELECT *, ADD(1, 2) FROM t1 | 1
|
||||
db2 | 8140395000078788481 | SELECT *, ADD(1, 2) FROM t1 | 1
|
||||
db2 | | SELECT * FROM t3 | 1
|
||||
db2 | | set pg_stat_monitor.pgsm_enable_pgsm_query_id = off | 1
|
||||
(10 rows)
|
||||
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
-----------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
\c db1
|
||||
DROP TABLE t1;
|
||||
DROP TABLE t2;
|
||||
DROP FUNCTION ADD;
|
||||
\c db2
|
||||
DROP TABLE t1;
|
||||
DROP TABLE t3;
|
||||
DROP FUNCTION ADD;
|
||||
\c contrib_regression
|
||||
DROP DATABASE db1;
|
||||
DROP DATABASE db2;
|
||||
DROP EXTENSION pg_stat_monitor;
|
||||
|
|
@ -1,114 +0,0 @@
|
|||
CREATE EXTENSION pg_stat_monitor;
|
||||
CREATE DATABASE db1;
|
||||
CREATE DATABASE db2;
|
||||
\c db1
|
||||
CREATE TABLE t1 (a int);
|
||||
CREATE TABLE t2 (b int);
|
||||
CREATE FUNCTION add(integer, integer) RETURNS integer
|
||||
AS 'select $1 + $2;'
|
||||
LANGUAGE SQL
|
||||
IMMUTABLE
|
||||
RETURNS NULL ON NULL INPUT;
|
||||
\c db2
|
||||
CREATE TABLE t1 (a int);
|
||||
CREATE TABLE t3 (c int);
|
||||
CREATE FUNCTION add(integer, integer) RETURNS integer
|
||||
AS 'select $1 + $2;'
|
||||
LANGUAGE SQL
|
||||
IMMUTABLE
|
||||
RETURNS NULL ON NULL INPUT;
|
||||
\c contrib_regression
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
-----------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
\c db1
|
||||
SELECT * FROM t1;
|
||||
a
|
||||
---
|
||||
(0 rows)
|
||||
|
||||
SELECT *, ADD(1, 2) FROM t1;
|
||||
a | add
|
||||
---+-----
|
||||
(0 rows)
|
||||
|
||||
SELECT * FROM t2;
|
||||
b
|
||||
---
|
||||
(0 rows)
|
||||
|
||||
-- Check that spaces and comments do not generate a different pgsm_query_id
|
||||
SELECT * FROM t2 --WHATEVER;
|
||||
;
|
||||
b
|
||||
---
|
||||
(0 rows)
|
||||
|
||||
SELECT * FROM t2 /* ...
|
||||
...
|
||||
More comments to check for spaces.
|
||||
*/
|
||||
;
|
||||
b
|
||||
---
|
||||
(0 rows)
|
||||
|
||||
\c db2
|
||||
SELECT * FROM t1;
|
||||
a
|
||||
---
|
||||
(0 rows)
|
||||
|
||||
SELECT *, ADD(1, 2) FROM t1;
|
||||
a | add
|
||||
---+-----
|
||||
(0 rows)
|
||||
|
||||
set pg_stat_monitor.pgsm_enable_pgsm_query_id = off;
|
||||
SELECT * FROM t3;
|
||||
c
|
||||
---
|
||||
(0 rows)
|
||||
|
||||
set pg_stat_monitor.pgsm_enable_pgsm_query_id = on;
|
||||
SELECT * FROM t3 where c = 20;
|
||||
c
|
||||
---
|
||||
(0 rows)
|
||||
|
||||
\c contrib_regression
|
||||
SELECT datname, pgsm_query_id, query, calls FROM pg_stat_monitor ORDER BY pgsm_query_id, query, datname;
|
||||
datname | pgsm_query_id | query | calls
|
||||
--------------------+---------------------+-----------------------------------------------------+-------
|
||||
contrib_regression | 689150021118383254 | SELECT pg_stat_monitor_reset() | 1
|
||||
db1 | 1897482803466821995 | SELECT * FROM t2 | 3
|
||||
db1 | 1988437669671417938 | SELECT * FROM t1 | 1
|
||||
db2 | 1988437669671417938 | SELECT * FROM t1 | 1
|
||||
db2 | 6633979598391393345 | SELECT * FROM t3 where c = 20 | 1
|
||||
db1 | 8140395000078788481 | SELECT *, ADD(1, 2) FROM t1 | 1
|
||||
db2 | 8140395000078788481 | SELECT *, ADD(1, 2) FROM t1 | 1
|
||||
db2 | | SELECT * FROM t3 | 1
|
||||
db2 | | set pg_stat_monitor.pgsm_enable_pgsm_query_id = off | 2
|
||||
(9 rows)
|
||||
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
-----------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
\c db1
|
||||
DROP TABLE t1;
|
||||
DROP TABLE t2;
|
||||
DROP FUNCTION ADD;
|
||||
\c db2
|
||||
DROP TABLE t1;
|
||||
DROP TABLE t3;
|
||||
DROP FUNCTION ADD;
|
||||
\c contrib_regression
|
||||
DROP DATABASE db1;
|
||||
DROP DATABASE db2;
|
||||
DROP EXTENSION pg_stat_monitor;
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue