PG-343: Enable TAP testing; PG-292: Automate the QA; PG-338: Calls count.; PG-331: Default values in PMM.

This commit brings following changes to this branch:
1) Port changes/additions TAP testing from main branch to this branch, under PG-292.
2) Changes to test cases due to GUCs change, under PG-331.
3) Call counts verfications, under PG-338.
4) Changes to github workflows to accomodate automation for TAP testing, under PG-343.
pull/193/head
Naeem Akhter 2022-03-22 01:36:47 +05:00
parent 34e14104d7
commit 96eed05890
63 changed files with 27347 additions and 48 deletions

View File

@ -10,13 +10,7 @@ jobs:
uses: actions/checkout@v2
with:
repository: 'postgres/postgres'
ref: 'REL_13_STABLE'
- name: Clone pg_stat_monitor repository
uses: actions/checkout@v2
with:
path: 'src/pg_stat_monitor'
ref: 'master'
ref: 'REL_14_STABLE'
- name: Install dependencies
run: |
@ -33,6 +27,10 @@ jobs:
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 String::Util'
sudo /usr/bin/perl -MCPAN -e 'install Data::Str2Num'
- name: Create pgsql dir
run: mkdir -p /opt/pgsql
@ -46,12 +44,12 @@ jobs:
'--libexecdir=${prefix}/lib/x86_64-linux-gnu' '--disable-maintainer-mode' \
'--disable-dependency-tracking' '--with-icu' '--with-tcl' '--with-perl' \
'--with-python' '--with-pam' '--with-openssl' '--with-libxml' '--with-libxslt' \
'PYTHON=/usr/bin/python3' '--mandir=/usr/share/postgresql/13/man' \
'--docdir=/usr/share/doc/postgresql-doc-13' \
'PYTHON=/usr/bin/python3' '--mandir=/usr/share/postgresql/14/man' \
'--docdir=/usr/share/doc/postgresql-doc-14' \
'--sysconfdir=/etc/postgresql-common' '--datarootdir=/usr/share/' \
'--datadir=/usr/share/postgresql/13' '--bindir=/usr/lib/postgresql/13/bin' \
'--datadir=/usr/share/postgresql/14' '--bindir=/usr/lib/postgresql/14/bin' \
'--libdir=/usr/lib/x86_64-linux-gnu/' '--libexecdir=/usr/lib/postgresql/' \
'--includedir=/usr/include/postgresql/' '--with-extra-version= (Ubuntu 2:13-x.focal)' \
'--includedir=/usr/include/postgresql/' '--with-extra-version= (Ubuntu 2:14-x.focal)' \
'--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' \
@ -61,13 +59,13 @@ jobs:
'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
sudo make install
make world
sudo make install-world
- name: Start postgresql cluster
run: |
/usr/lib/postgresql/13/bin/initdb -D /opt/pgsql/data
/usr/lib/postgresql/13/bin/pg_ctl -D /opt/pgsql/data -l logfile start
/usr/lib/postgresql/14/bin/initdb -D /opt/pgsql/data
/usr/lib/postgresql/14/bin/pg_ctl -D /opt/pgsql/data -l logfile start
- name: Clone pg_stat_monitor repository
uses: actions/checkout@v2
@ -76,18 +74,23 @@ jobs:
- name: Build pg_stat_monitor
run: |
export PATH="/usr/lib/postgresql/13/bin:$PATH"
sudo cp /usr/lib/postgresql/13/bin/pg_config /usr/bin
export PATH="/usr/lib/postgresql/14/bin:$PATH"
sudo cp /usr/lib/postgresql/14/bin/pg_config /usr/bin
make USE_PGXS=1
sudo make USE_PGXS=1 install
working-directory: src/pg_stat_monitor/
- name: Start pg_stat_monitor_tests & Run code coverage
- name: Load pg_stat_monitor library and Restart Server
run: |
/usr/lib/postgresql/13/bin/pg_ctl -D /opt/pgsql/data -l logfile stop
/usr/lib/postgresql/14/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/13/bin/pg_ctl -D /opt/pgsql/data -l logfile start
/usr/lib/postgresql/14/bin/pg_ctl -D /opt/pgsql/data -l logfile start
working-directory: src/pg_stat_monitor/
- name: Start pg_stat_monitor_tests & Run code coverage
run: |
make installcheck
/usr/lib/postgresql/14/bin/psql -d postgres -p 5432 -c "\list"
make coverage-html
lcov --capture --directory . --output-file coverage/lcov.info
pip install cpp-coveralls
@ -95,3 +98,30 @@ jobs:
coveralls --verbose
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@v2
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: 1

50
.github/workflows/doc-build.yml vendored Normal file
View File

@ -0,0 +1,50 @@
name: Build pg_stat_monitor docs
on:
push:
branches:
- main
jobs:
build:
name: Deploy docs
runs-on: ubuntu-latest
steps:
#Pull the latest changes
- name: Chekout code
uses: percona-platform/checkout@v2
with:
fetch-depth: 0
#Prepare the env
- name: Set up Python
uses: percona-platform/setup-python@v2
with:
python-version: '3.x'
#Configure git
- name: Configure git
env:
ROBOT_TOKEN: ${{ secrets.ROBOT_TOKEN }}
run: |
git config --global url."https://percona-platform-robot:${ROBOT_TOKEN}@github.com".insteadOf "https://github.com"
git config user.name "GitHub Action"
git config user.email "github-action@users.noreply.github.com"
git config user.password "${ROBOT_TOKEN}"
echo "GIT_USER=percona-platform-robot:${ROBOT_TOKEN}" >> $GITHUB_ENV
#Set up MkDocs
- name: Setup MkDocs
run: |
python -m pip install --upgrade pip
pip install wheel
if [ -f requirements-doc.txt ]; then pip install -r requirements-doc.txt; fi
# Deploy docs
- name: Deploy docs
run: |
mike deploy main -p
mike set-default main -p
mike retitle main "latest" -p

View File

@ -27,6 +27,10 @@ jobs:
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 String::Util'
sudo /usr/bin/perl -MCPAN -e 'install Data::Str2Num'
- name: Create pgsql dir
run: mkdir -p /opt/pgsql
@ -41,7 +45,7 @@ jobs:
'--disable-dependency-tracking' '--with-icu' '--with-tcl' '--with-perl' \
'--with-python' '--with-pam' '--with-openssl' '--with-libxml' '--with-libxslt' \
'PYTHON=/usr/bin/python3' '--mandir=/usr/share/postgresql/13/man' \
'--docdir=/usr/share/doc/postgresql-doc-13' \
'--docdir=/usr/share/doc/postgresql-doc-13' 'AWK=mawk' \
'--sysconfdir=/etc/postgresql-common' '--datarootdir=/usr/share/' \
'--datadir=/usr/share/postgresql/13' '--bindir=/usr/lib/postgresql/13/bin' \
'--libdir=/usr/lib/x86_64-linux-gnu/' '--libexecdir=/usr/lib/postgresql/' \
@ -49,7 +53,7 @@ jobs:
'--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' \
'LLVM_CONFIG=/usr/bin/llvm-config-9' 'CLANG=/usr/bin/clang-9' \
'--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' \
@ -72,6 +76,7 @@ jobs:
run: |
export PATH="/usr/lib/postgresql/13/bin:$PATH"
sudo cp /usr/lib/postgresql/13/bin/pg_config /usr/bin
pg_config
make USE_PGXS=1
sudo make USE_PGXS=1 install
working-directory: src/pg_stat_monitor/
@ -83,7 +88,7 @@ jobs:
/usr/lib/postgresql/13/bin/pg_ctl -D /opt/pgsql/data -l logfile start
working-directory: src/pg_stat_monitor/
- name: Start Server installcheck-world tests (without TAP)
- name: Start Server installcheck-world tests
run: |
make installcheck-world
- name: Report on installcheck-world test suites fail
@ -102,12 +107,30 @@ jobs:
make installcheck
working-directory: src/pg_stat_monitor/
- name: Report on pg_stat_monitor test fail
uses: actions/upload-artifact@v2
- 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@v2
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: 1

View File

@ -24,6 +24,9 @@ jobs:
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 String::Util'
sudo /usr/bin/perl -MCPAN -e 'install Data::Str2Num'
- name: Install postgresql 13
run: |
@ -39,22 +42,40 @@ jobs:
working-directory: src/pg_stat_monitor/
- name: Change sources owner to postgres
run: sudo chown -R postgres:postgres src/pg_stat_monitor/
run: |
sudo chown -R postgres:postgres 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/13/main/postgresql.conf
sudo service postgresql start
sudo -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: Report on test fail
uses: actions/upload-artifact@v2
- 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@v2
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: 1

View File

@ -23,6 +23,10 @@ jobs:
sudo rm -rf /usr/share/postgresql
sudo rm -rf /etc/postgresql
sudo rm -f /usr/bin/pg_config
sudo apt-get install libreadline6-dev systemtap-sdt-dev zlib1g-dev libssl-dev libpam0g-dev python-dev bison flex libipc-run-perl wget -y
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: |
@ -31,6 +35,8 @@ jobs:
sudo apt-get update
sudo apt-get -y install postgresql-13 postgresql-client-13 postgresql-contrib postgresql-server-dev-13
sudo chown -R postgres:postgres src/
sudo cpan install IPC::RUN
sudo cpan install String::Util
- name: Build pg_stat_monitor
run: |
@ -48,12 +54,30 @@ jobs:
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
- 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@v2
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: 1

View File

@ -27,6 +27,10 @@ jobs:
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 String::Util'
sudo /usr/bin/perl -MCPAN -e 'install Data::Str2Num'
- name: Create pgsql dir
run: mkdir -p /opt/pgsql
@ -88,12 +92,30 @@ jobs:
make installcheck
working-directory: src/pg_stat_monitor/
- name: Report on pg_stat_monitor test fail
uses: actions/upload-artifact@v2
- 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@v2
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: 1

View File

@ -29,6 +29,7 @@ ifneq (,$(findstring PostgreSQL14,$(MAJOR)))
ifneq (,$(wildcard pg_stat_monitor--1.0.14.sql.in))
CP := $(shell cp pg_stat_monitor--1.0.14.sql.in pg_stat_monitor--1.0.sql)
endif
TAP_TESTS = 1
endif
ifneq (,$(findstring PostgreSQL13,$(MAJOR)))
@ -38,6 +39,7 @@ ifneq (,$(findstring PostgreSQL13,$(MAJOR)))
ifneq (,$(wildcard pg_stat_monitor--1.0.13.sql.in))
CP := $(shell cp pg_stat_monitor--1.0.13.sql.in pg_stat_monitor--1.0.sql)
endif
TAP_TESTS = 1
endif
ifneq (,$(findstring PostgreSQL12,$(MAJOR)))

View File

@ -1,4 +1,5 @@
CREATE EXTENSION pg_stat_monitor;
Set pg_stat_monitor.pgsm_track='all';
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset
-----------------------

View File

@ -24,11 +24,12 @@ SELECT * FROM pg_stat_monitor_settings ORDER BY name COLLATE "C";
pg_stat_monitor.pgsm_max_buckets | 10 | 10 | Sets the maximum number of buckets. | 1 | 10 | | yes
pg_stat_monitor.pgsm_normalized_query | yes | yes | 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 | 1024 | 1024 | Sets the maximum length of query. | 1024 | 2147483647 | | 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 | all | all | Selects which statements are tracked by pg_stat_monitor. | | | none, top, all | no
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
(14 rows)
(15 rows)
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset

View File

@ -24,12 +24,11 @@ SELECT * FROM pg_stat_monitor_settings ORDER BY name COLLATE "C";
pg_stat_monitor.pgsm_max_buckets | 10 | 10 | Sets the maximum number of buckets. | 1 | 10 | | yes
pg_stat_monitor.pgsm_normalized_query | yes | yes | 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 | 1024 | 1024 | Sets the maximum length of query. | 1024 | 2147483647 | | 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 | all | all | 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 | 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
(15 rows)
(14 rows)
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset

View File

@ -32,7 +32,7 @@ SELECT pg_stat_monitor_reset();
(1 row)
Set pg_stat_monitor.track='all';
Set pg_stat_monitor.pgsm_track='all';
select run_pg_sleep(5);
INFO: Sleep 1 seconds
INFO: Sleep 2 seconds
@ -50,13 +50,13 @@ SELECT substr(query, 0,50) as query, calls, resp_calls FROM pg_stat_monitor ORDE
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, $1,$2) as query, calls, resp | 1 | {1,0,0,0,0,0,0,0,0,0}
Set pg_stat_monitor.track='all' | 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($1) | 1 | {0,0,0,0,0,0,0,0,1,0}
(5 rows)
select * from generate_histogram();
range | freq | bar
--------------------+------+--------------------------------
range | freq | bar
--------------------+------+--------------------------------------------------------------------------------------------
(0 - 3)} | 0 |
(3 - 10)} | 0 |
(10 - 31)} | 0 |

View File

@ -1,4 +1,5 @@
CREATE EXTENSION pg_stat_monitor;
Set pg_stat_monitor.pgsm_track='all';
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset
-----------------------
@ -25,6 +26,7 @@ SELECT add2(1,2);
SELECT query, top_query FROM pg_stat_monitor ORDER BY query COLLATE "C";
query | top_query
-------------------------------------------------------------------------+--------------------
(select $1 + $2) | SELECT add2($1,$2)
CREATE OR REPLACE FUNCTION add(int, int) RETURNS INTEGER AS +|
$$ +|
BEGIN +|
@ -36,7 +38,6 @@ SELECT query, top_query FROM pg_stat_monitor ORDER BY query COLLATE "C";
return add($1,$2); +|
END; +|
$$ language plpgsql |
SELECT (select $1 + $2) | SELECT add2($1,$2)
SELECT add2($1,$2) |
SELECT pg_stat_monitor_reset() |
SELECT query, top_query FROM pg_stat_monitor ORDER BY query COLLATE "C" |

View File

@ -1,4 +1,5 @@
CREATE EXTENSION pg_stat_monitor;
Set pg_stat_monitor.pgsm_track='all';
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset
-----------------------
@ -25,7 +26,6 @@ SELECT add2(1,2);
SELECT query, top_query FROM pg_stat_monitor ORDER BY query COLLATE "C";
query | top_query
-------------------------------------------------------------------------+--------------------
(select $1 + $2) | SELECT add2($1,$2)
CREATE OR REPLACE FUNCTION add(int, int) RETURNS INTEGER AS +|
$$ +|
BEGIN +|
@ -37,6 +37,7 @@ SELECT query, top_query FROM pg_stat_monitor ORDER BY query COLLATE "C";
return add($1,$2); +|
END; +|
$$ language plpgsql |
SELECT (select $1 + $2) | SELECT add2($1,$2)
SELECT add2($1,$2) |
SELECT pg_stat_monitor_reset() |
SELECT query, top_query FROM pg_stat_monitor ORDER BY query COLLATE "C" |

View File

@ -1,4 +1,5 @@
CREATE EXTENSION pg_stat_monitor;
Set pg_stat_monitor.pgsm_track='all';
SELECT pg_stat_monitor_reset();
CREATE TABLE t1 (a INTEGER);

View File

@ -29,7 +29,7 @@ $$ LANGUAGE 'plpgsql' STRICT;
CREATE EXTENSION pg_stat_monitor;
SELECT pg_stat_monitor_reset();
Set pg_stat_monitor.track='all';
Set pg_stat_monitor.pgsm_track='all';
select run_pg_sleep(5);
SELECT substr(query, 0,50) as query, calls, resp_calls FROM pg_stat_monitor ORDER BY query COLLATE "C";

View File

@ -1,4 +1,5 @@
CREATE EXTENSION pg_stat_monitor;
Set pg_stat_monitor.pgsm_track='all';
SELECT pg_stat_monitor_reset();
CREATE OR REPLACE FUNCTION add(int, int) RETURNS INTEGER AS
$$

10454
scripts/data_1.sql Normal file

File diff suppressed because it is too large Load Diff

10454
scripts/data_2.sql Normal file

File diff suppressed because it is too large Load Diff

124
t/001_settings_default.pl Normal file
View File

@ -0,0 +1,124 @@
#!/usr/bin/perl
use strict;
use warnings;
use File::Basename;
use File::Compare;
use PostgresNode;
use Test::More;
# Expected folder where expected output will be present
my $expected_folder = "t/expected";
# Results/out folder where generated results files will be placed
my $results_folder = "t/results";
# Check if results folder exists or not, create if it doesn't
unless (-d $results_folder)
{
mkdir $results_folder or die "Can't create folder $results_folder: $!\n";;
}
# Check if expected folder exists or not, bail out if it doesn't
unless (-d $expected_folder)
{
BAIL_OUT "Expected files folder $expected_folder doesn't exist: \n";;
}
# Get filename of the this perl file
my $perlfilename = basename($0);
#Remove .pl from filename and store in a variable
my($filename,$extension) = split('.', $perlfilename);
print '$filename';
print '$extension';
$perlfilename =~ s/.pl//;
my $filename_without_extension = $perlfilename;
# Create expected filename with path
my $expected_filename = "${filename_without_extension}.out";
my $expected_filename_with_path = "${expected_folder}/${expected_filename}" ;
# Create results filename with path
my $out_filename = "${filename_without_extension}.out";
my $out_filename_with_path = "${results_folder}/${out_filename}" ;
# Delete already existing result out file, if it exists.
if ( -f $out_filename_with_path)
{
unlink($out_filename_with_path) or die "Can't delete already existing $out_filename_with_path: $!\n";
}
# Create new PostgreSQL node and do initdb
my $node = PostgresNode->get_new_node('test');
my $pgdata = $node->data_dir;
$node->dump_info;
$node->init;
# Update postgresql.conf to include/load pg_stat_monitor library
open my $conf, '>>', "$pgdata/postgresql.conf";
print $conf "shared_preload_libraries = 'pg_stat_monitor'\n";
close $conf;
# Start server
my $rt_value = $node->start;
ok($rt_value == 1, "Start Server");
# Create extension and change out file permissions
my ($cmdret, $stdout, $stderr) = $node->psql('postgres', 'CREATE EXTENSION pg_stat_monitor;', extra_params => ['-a']);
ok($cmdret == 0, "Create PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
chmod(0640 , $out_filename_with_path)
or die("unable to set permissions for $out_filename_with_path");
# Run required commands/queries and dump output to out file.
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT * from pg_stat_monitor_settings;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
# Create example database and run pgbench init
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'CREATE database example;', extra_params => ['-a']);
ok($cmdret == 0, "Create Database example");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
my $port = $node->port;
my $out = system ("pgbench -i -s 10 -p $port example");
ok($cmdret == 0, "Perform pgbench init");
$out = system ("pgbench -c 10 -j 2 -t 1000 -p $port example");
ok($cmdret == 0, "Run pgbench");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select datname, substr(query,0,100) as query, calls from pg_stat_monitor order by datname, query, calls desc Limit 20;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Select XXX from pg_stat_monitor");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT * from pg_stat_monitor_settings;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
# Drop extension
$stdout = $node->safe_psql('postgres', 'Drop extension pg_stat_monitor;', extra_params => ['-a']);
ok($cmdret == 0, "Drop PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
# Stop the server
$node->stop;
# compare the expected and out file
my $compare = compare($expected_filename_with_path, $out_filename_with_path);
# Test/check if expected and result/out file match. If Yes, test passes.
is($compare,0,"Compare Files: $expected_filename_with_path and $out_filename_with_path match.");
# Done testing for this testcase file.
done_testing();

View File

@ -0,0 +1,206 @@
#!/usr/bin/perl
use strict;
use warnings;
use String::Util qw(trim);
use File::Basename;
use File::Compare;
use PostgresNode;
use Test::More;
# Expected folder where expected output will be present
my $expected_folder = "t/expected";
# Results/out folder where generated results files will be placed
my $results_folder = "t/results";
# Check if results folder exists or not, create if it doesn't
unless (-d $results_folder)
{
mkdir $results_folder or die "Can't create folder $results_folder: $!\n";;
}
# Check if expected folder exists or not, bail out if it doesn't
unless (-d $expected_folder)
{
BAIL_OUT "Expected files folder $expected_folder doesn't exist: \n";;
}
# Get filename of the this perl file
my $perlfilename = basename($0);
#Remove .pl from filename and store in a variable
$perlfilename =~ s/\.[^.]+$//;
my $filename_without_extension = $perlfilename;
# Create expected filename with path
my $expected_filename = "${filename_without_extension}.out";
my $expected_filename_with_path = "${expected_folder}/${expected_filename}" ;
# Create results filename with path
my $out_filename = "${filename_without_extension}.out";
my $out_filename_with_path = "${results_folder}/${out_filename}" ;
my $dynamic_out_filename_with_path = "${results_folder}/${out_filename}.dynamic" ;
# Delete already existing result out file, if it exists.
if ( -f $out_filename_with_path)
{
unlink($out_filename_with_path) or die "Can't delete already existing $out_filename_with_path: $!\n";
}
# Create new PostgreSQL node and do initdb
my $node = PostgresNode->get_new_node('test');
my $pgdata = $node->data_dir;
$node->dump_info;
$node->init;
# Update postgresql.conf to include/load pg_stat_monitor library
open my $conf, '>>', "$pgdata/postgresql.conf";
print $conf "shared_preload_libraries = 'pg_stat_monitor'\n";
print $conf "pg_stat_monitor.pgsm_track_planning = 'yes'\n";
close $conf;
# Start server
my $rt_value = $node->start;
ok($rt_value == 1, "Start Server");
# Create extension and change out file permissions
my ($cmdret, $stdout, $stderr) = $node->psql('postgres', 'CREATE EXTENSION pg_stat_monitor;', extra_params => ['-a']);
ok($cmdret == 0, "Create PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
chmod(0640 , $out_filename_with_path)
or die("unable to set permissions for $out_filename_with_path");
# Run required commands/queries and dump output to out file.
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
# Run 'SELECT * from pg_stat_monitor_settings;' two times and dump output to out file
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT * from pg_stat_monitor_settings;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT * from pg_stat_monitor_settings;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT query, calls, total_plan_time, min_plan_time, max_plan_time, mean_plan_time, stddev_plan_time from pg_stat_monitor;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Select from PGSM view");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
# Test: total_plan_time is not 0
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select (total_plan_time = 0) from pg_stat_monitor where calls = 2 ;', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'f',"Compare: total_plan_time is not 0).");
# Test: min_plan_time is not 0
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select (min_plan_time = 0) from pg_stat_monitor where calls = 2 ;', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'f',"Compare: min_plan_time is not 0).");
# Test: max_plan_time is not 0
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select (max_plan_time = 0) from pg_stat_monitor where calls = 2 ;', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'f',"Compare: max_plan_time is not 0).");
# Test: mean_plan_time is not 0
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select (mean_plan_time = 0) from pg_stat_monitor where calls = 2 ;', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'f',"Compare: mean_plan_time is not 0).");
# Test: stddev_plan_time is not 0
#($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select (stddev_plan_time = 0) from pg_stat_monitor where calls = 2 ;', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
#trim($stdout);
#is($stdout,'f',"Compare: stddev_plan_time is not 0).");
# Test: total_plan_time = min_plan_time + max_plan_time
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select (round(total_plan_time::numeric,3) = round(min_plan_time::numeric + max_plan_time::numeric,3)) from pg_stat_monitor where calls = 2 ;', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Compare: (round(total_plan_time::numeric,3) = round(min_plan_time::numeric + max_plan_time::numeric,3)).");
# Test: mean_plan_time = total_plan_time/2
#($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select (round(mean_plan_time::numeric,3) = round((total_plan_time/2)::numeric,3)) from pg_stat_monitor where calls = 2 ;', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
#trim($stdout);
#is($stdout,'t',"Test mean_plan_time: (round(mean_plan_time::numeric,3) = round((total_plan_time/2)::numeric,3)).");
# Test: stddev_plan_time = mean_plan_time - min_plan_time
#($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select (round(stddev_plan_time::numeric,3) = round(mean_plan_time::numeric - min_plan_time::numeric,3)) from pg_stat_monitor where calls = 2 ;', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
#trim($stdout);
#is($stdout,'t',"Compare mean_plan_time: (round(stddev_plan_time::numeric,3) = round(mean_plan_time::numeric - min_plan_time::numeric,3)).");
# Dump output to out file
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select substr(query, 0,100) as query, calls, total_plan_time, min_plan_time,max_plan_time,mean_plan_time,stddev_plan_time from pg_stat_monitor order by query;', extra_params => ['-a','-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($dynamic_out_filename_with_path, $stdout . "\n");
# Disable pgsm_track_planning
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_track_planning = 'no'\n");
$node->restart();
# Dump output to out file
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
# Run 'SELECT * from pg_stat_monitor_settings;' two times and dump output to out file
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT * from pg_stat_monitor_settings;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT * from pg_stat_monitor_settings;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT query, calls, total_plan_time, min_plan_time, max_plan_time, mean_plan_time, stddev_plan_time from pg_stat_monitor;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Select from PGSM view");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
# Test: total_plan_time is 0
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select (total_plan_time = 0) from pg_stat_monitor where calls = 2 ;', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Compare: total_plan_time is 0).");
# Test: min_plan_time is 0
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select (min_plan_time = 0) from pg_stat_monitor where calls = 2 ;', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Compare: min_plan_time is 0).");
# Test: max_plan_time is 0
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select (max_plan_time = 0) from pg_stat_monitor where calls = 2 ;', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Compare: max_plan_time is 0).");
# Test: mean_plan_time is 0
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select (mean_plan_time = 0) from pg_stat_monitor where calls = 2 ;', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Compare: mean_plan_time is 0).");
# Test: stddev_plan_time is 0
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select (stddev_plan_time = 0) from pg_stat_monitor where calls = 2 ;', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Compare: stddev_plan_time is 0).");
# Dump output to out file
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select substr(query, 0,100) as query, calls, total_plan_time, min_plan_time,max_plan_time,mean_plan_time,stddev_plan_time from pg_stat_monitor order by query;', extra_params => ['-a','-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
# Dump output to out file
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
# Drop extension
$stdout = $node->safe_psql('postgres', 'Drop extension pg_stat_monitor;', extra_params => ['-a']);
ok($cmdret == 0, "Drop PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
# Stop the server
$node->stop;
# compare the expected and out file
#my $compare = compare($expected_filename_with_path, $out_filename_with_path);
# Test/check if expected and result/out file match. If Yes, test passes.
#is($compare,0,"Compare Files: $expected_filename_with_path and $out_filename_with_path match.");
# Done testing for this testcase file.
done_testing();

View File

@ -0,0 +1,120 @@
#!/usr/bin/perl
use strict;
use warnings;
use File::Basename;
use File::Compare;
use PostgresNode;
use Test::More;
# Expected folder where expected output will be present
my $expected_folder = "t/expected";
# Results/out folder where generated results files will be placed
my $results_folder = "t/results";
# Check if results folder exists or not, create if it doesn't
unless (-d $results_folder)
{
mkdir $results_folder or die "Can't create folder $results_folder: $!\n";;
}
# Check if expected folder exists or not, bail out if it doesn't
unless (-d $expected_folder)
{
BAIL_OUT "Expected files folder $expected_folder doesn't exist: \n";;
}
# Get filename of the this perl file
my $perlfilename = basename($0);
#Remove .pl from filename and store in a variable
$perlfilename =~ s/\.[^.]+$//;
my $filename_without_extension = $perlfilename;
# Create expected filename with path
my $expected_filename = "${filename_without_extension}.out";
my $expected_filename_with_path = "${expected_folder}/${expected_filename}" ;
# Create results filename with path
my $out_filename = "${filename_without_extension}.out";
my $out_filename_with_path = "${results_folder}/${out_filename}" ;
# Delete already existing result out file, if it exists.
if ( -f $out_filename_with_path)
{
unlink($out_filename_with_path) or die "Can't delete already existing $out_filename_with_path: $!\n";
}
# Create new PostgreSQL node and do initdb
my $node = PostgresNode->get_new_node('test');
my $pgdata = $node->data_dir;
$node->dump_info;
$node->init;
# Update postgresql.conf to include/load pg_stat_monitor library
open my $conf, '>>', "$pgdata/postgresql.conf";
print $conf "shared_preload_libraries = 'pg_stat_monitor'\n";
print $conf "pg_stat_monitor.pgsm_extract_comments = 'yes'\n";
close $conf;
# Start server
my $rt_value = $node->start;
ok($rt_value == 1, "Start Server");
# Create extension and change out file permissions
my ($cmdret, $stdout, $stderr) = $node->psql('postgres', 'CREATE EXTENSION pg_stat_monitor;', extra_params => ['-a']);
ok($cmdret == 0, "Create PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
chmod(0640 , $out_filename_with_path)
or die("unable to set permissions for $out_filename_with_path");
# Run required commands/queries and dump output to out file.
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT * from pg_stat_monitor_settings;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', "SELECT 1 AS num /* First comment */, 'John' as Name /* Second comment*/;", extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT query, comments FROM pg_stat_monitor ORDER BY query COLLATE "C";', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_extract_comments = 'no'\n");
$node->restart();
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT * from pg_stat_monitor_settings;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', "SELECT 1 AS num /* First comment */, 'John' as Name /* Second comment*/;", extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT query, comments FROM pg_stat_monitor ORDER BY query COLLATE "C";', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
# Drop extension
$stdout = $node->safe_psql('postgres', 'Drop extension pg_stat_monitor;', extra_params => ['-a']);
ok($cmdret == 0, "Drop PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
# Stop the server
$node->stop;
# compare the expected and out file
my $compare = compare($expected_filename_with_path, $out_filename_with_path);
# Test/check if expected and result/out file match. If Yes, test passes.
is($compare,0,"Compare Files: $expected_filename_with_path and $out_filename_with_path match.");
# Done testing for this testcase file.
done_testing();

View File

@ -0,0 +1,118 @@
#!/usr/bin/perl
use strict;
use warnings;
use File::Basename;
use File::Compare;
use PostgresNode;
use Test::More;
# Expected folder where expected output will be present
my $expected_folder = "t/expected";
# Results/out folder where generated results files will be placed
my $results_folder = "t/results";
# Check if results folder exists or not, create if it doesn't
unless (-d $results_folder)
{
mkdir $results_folder or die "Can't create folder $results_folder: $!\n";;
}
# Check if expected folder exists or not, bail out if it doesn't
unless (-d $expected_folder)
{
BAIL_OUT "Expected files folder $expected_folder doesn't exist: \n";;
}
# Get filename of the this perl file
my $perlfilename = basename($0);
#Remove .pl from filename and store in a variable
$perlfilename =~ s/\.[^.]+$//;
my $filename_without_extension = $perlfilename;
# Create expected filename with path
my $expected_filename = "${filename_without_extension}.out";
my $expected_filename_with_path = "${expected_folder}/${expected_filename}" ;
# Create results filename with path
my $out_filename = "${filename_without_extension}.out";
my $out_filename_with_path = "${results_folder}/${out_filename}" ;
# Delete already existing result out file, if it exists.
if ( -f $out_filename_with_path)
{
unlink($out_filename_with_path) or die "Can't delete already existing $out_filename_with_path: $!\n";
}
# Create new PostgreSQL node and do initdb
my $node = PostgresNode->get_new_node('test');
my $pgdata = $node->data_dir;
$node->dump_info;
$node->init;
# Update postgresql.conf to include/load pg_stat_monitor library
open my $conf, '>>', "$pgdata/postgresql.conf";
print $conf "shared_preload_libraries = 'pg_stat_monitor'\n";
print $conf "pg_stat_monitor.pgsm_track = 'none'\n";
close $conf;
# Start server
my $rt_value = $node->start;
ok($rt_value == 1, "Start Server");
# Create extension and change out file permissions
my ($cmdret, $stdout, $stderr) = $node->psql('postgres', 'CREATE EXTENSION pg_stat_monitor;', extra_params => ['-a']);
ok($cmdret == 0, "Create PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
chmod(0640 , $out_filename_with_path)
or die("unable to set permissions for $out_filename_with_path");
# Run required commands/queries and dump output to out file.
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT * from pg_stat_monitor_settings;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_track = 'all'\n");
$node->restart();
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT * from pg_stat_monitor_settings;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_track = 'top'\n");
$node->restart();
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT * from pg_stat_monitor_settings;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
# Drop extension
$stdout = $node->safe_psql('postgres', 'Drop extension pg_stat_monitor;', extra_params => ['-a']);
ok($cmdret == 0, "Drop PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
# Stop the server
$node->stop;
# compare the expected and out file
my $compare = compare($expected_filename_with_path, $out_filename_with_path);
# Test/check if expected and result/out file match. If Yes, test passes.
is($compare,0,"Compare Files: $expected_filename_with_path and $out_filename_with_path match.");
# Done testing for this testcase file.
done_testing();

View File

@ -0,0 +1,160 @@
#!/usr/bin/perl
use strict;
use warnings;
use String::Util qw(trim);
use File::Basename;
use File::Compare;
use PostgresNode;
use Test::More;
# Expected folder where expected output will be present
my $expected_folder = "t/expected";
# Results/out folder where generated results files will be placed
my $results_folder = "t/results";
# Check if results folder exists or not, create if it doesn't
unless (-d $results_folder)
{
mkdir $results_folder or die "Can't create folder $results_folder: $!\n";;
}
# Check if expected folder exists or not, bail out if it doesn't
unless (-d $expected_folder)
{
BAIL_OUT "Expected files folder $expected_folder doesn't exist: \n";;
}
# Get filename of the this perl file
my $perlfilename = basename($0);
#Remove .pl from filename and store in a variable
$perlfilename =~ s/\.[^.]+$//;
my $filename_without_extension = $perlfilename;
# Create expected filename with path
my $expected_filename = "${filename_without_extension}.out";
my $expected_filename_with_path = "${expected_folder}/${expected_filename}" ;
# Create results filename with path
my $out_filename = "${filename_without_extension}.out";
my $out_filename_with_path = "${results_folder}/${out_filename}" ;
# Delete already existing result out file, if it exists.
if ( -f $out_filename_with_path)
{
unlink($out_filename_with_path) or die "Can't delete already existing $out_filename_with_path: $!\n";
}
# Create new PostgreSQL node and do initdb
my $node = PostgresNode->get_new_node('test');
my $pgdata = $node->data_dir;
$node->dump_info;
$node->init;
# Update postgresql.conf to include/load pg_stat_monitor library
open my $conf, '>>', "$pgdata/postgresql.conf";
print $conf "shared_preload_libraries = 'pg_stat_monitor'\n";
print $conf "pg_stat_monitor.pgsm_enable_query_plan = 'yes'\n";
close $conf;
# Start server
my $rt_value = $node->start;
ok($rt_value == 1, "Start Server");
# Create extension and change out file permissions
my ($cmdret, $stdout, $stderr) = $node->psql('postgres', 'CREATE EXTENSION pg_stat_monitor;', extra_params => ['-a']);
ok($cmdret == 0, "Create PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
chmod(0640 , $out_filename_with_path)
or die("unable to set permissions for $out_filename_with_path");
# Run required commands/queries and dump output to out file.
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT * from pg_stat_monitor_settings;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'CREATE TABLE TBL_0(key text primary key, txt_0 text, value_0 int);', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', "INSERT INTO TBL_0(key, txt_0, value_0) VALUES('000000', '846930886', 1804289383);", extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT key, txt_0, value_0 FROM TBL_0;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT key, txt_0, value_0 FROM TBL_0;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'UPDATE TBL_0 SET value_0 = 1681692777;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select substr(query, 0,50) as query, calls, query_plan from pg_stat_monitor order by query,calls;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
# Test: planid is not 0 or empty
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select planid from pg_stat_monitor where calls = 2 ;', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
isnt($stdout,'',"Test: planid should not be empty");
ok(length($stdout) == 16, 'Length of planid is 16');
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_enable_query_plan = 'no'\n");
$node->restart();
# Run required commands/queries and dump output to out file.
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Drop TABLE TBL_0;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT * from pg_stat_monitor_settings;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'CREATE TABLE TBL_0(key text primary key, txt_0 text, value_0 int);', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', "INSERT INTO TBL_0(key, txt_0, value_0) VALUES('000000', '846930886', 1804289383);", extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT key, txt_0, value_0 FROM TBL_0;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT key, txt_0, value_0 FROM TBL_0;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'UPDATE TBL_0 SET value_0 = 1681692777;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select substr(query, 0,50) as query, calls, query_plan from pg_stat_monitor order by query,calls;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
# Test: planid is empty
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select planid from pg_stat_monitor where calls = 2 ;', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'',"Test: planid should be empty");
ok(length($stdout) == 0, 'Length of planid is 0');
# Drop extension
$stdout = $node->safe_psql('postgres', 'Drop extension pg_stat_monitor;', extra_params => ['-a']);
ok($cmdret == 0, "Drop PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
# Stop the server
$node->stop;
# compare the expected and out file
my $compare = compare($expected_filename_with_path, $out_filename_with_path);
# Test/check if expected and result/out file match. If Yes, test passes.
is($compare,0,"Compare Files: $expected_filename_with_path and $out_filename_with_path match.");
# Done testing for this testcase file.
done_testing();

View File

@ -0,0 +1,107 @@
#!/usr/bin/perl
use strict;
use warnings;
use File::Basename;
use File::Compare;
use PostgresNode;
use Test::More;
# Expected folder where expected output will be present
my $expected_folder = "t/expected";
# Results/out folder where generated results files will be placed
my $results_folder = "t/results";
# Check if results folder exists or not, create if it doesn't
unless (-d $results_folder)
{
mkdir $results_folder or die "Can't create folder $results_folder: $!\n";;
}
# Check if expected folder exists or not, bail out if it doesn't
unless (-d $expected_folder)
{
BAIL_OUT "Expected files folder $expected_folder doesn't exist: \n";;
}
# Get filename of the this perl file
my $perlfilename = basename($0);
#Remove .pl from filename and store in a variable
$perlfilename =~ s/\.[^.]+$//;
my $filename_without_extension = $perlfilename;
# Create expected filename with path
my $expected_filename = "${filename_without_extension}.out";
my $expected_filename_with_path = "${expected_folder}/${expected_filename}" ;
# Create results filename with path
my $out_filename = "${filename_without_extension}.out";
my $out_filename_with_path = "${results_folder}/${out_filename}" ;
# Delete already existing result out file, if it exists.
if ( -f $out_filename_with_path)
{
unlink($out_filename_with_path) or die "Can't delete already existing $out_filename_with_path: $!\n";
}
# Create new PostgreSQL node and do initdb
my $node = PostgresNode->get_new_node('test');
my $pgdata = $node->data_dir;
$node->dump_info;
$node->init;
# Update postgresql.conf to include/load pg_stat_monitor library
open my $conf, '>>', "$pgdata/postgresql.conf";
print $conf "shared_preload_libraries = 'pg_stat_monitor'\n";
print $conf "pg_stat_monitor.pgsm_overflow_target = 0\n";
close $conf;
# Start server
my $rt_value = $node->start;
ok($rt_value == 1, "Start Server");
# Create extension and change out file permissions
my ($cmdret, $stdout, $stderr) = $node->psql('postgres', 'CREATE EXTENSION pg_stat_monitor;', extra_params => ['-a']);
ok($cmdret == 0, "Create PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
chmod(0640 , $out_filename_with_path)
or die("unable to set permissions for $out_filename_with_path");
# Run required commands/queries and dump output to out file.
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT * from pg_stat_monitor_settings;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_overflow_target = 1\n");
$node->restart();
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT * from pg_stat_monitor_settings;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
# Drop extension
$stdout = $node->safe_psql('postgres', 'Drop extension pg_stat_monitor;', extra_params => ['-a']);
ok($cmdret == 0, "Drop PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
# Stop the server
$node->stop;
# compare the expected and out file
my $compare = compare($expected_filename_with_path, $out_filename_with_path);
# Test/check if expected and result/out file match. If Yes, test passes.
is($compare,0,"Compare Files: $expected_filename_with_path and $out_filename_with_path match.");
# Done testing for this testcase file.
done_testing();

View File

@ -0,0 +1,141 @@
#!/usr/bin/perl
use strict;
use warnings;
use File::Basename;
use File::Compare;
use PostgresNode;
use Test::More;
# Expected folder where expected output will be present
my $expected_folder = "t/expected";
# Results/out folder where generated results files will be placed
my $results_folder = "t/results";
# Check if results folder exists or not, create if it doesn't
unless (-d $results_folder)
{
mkdir $results_folder or die "Can't create folder $results_folder: $!\n";;
}
# Check if expected folder exists or not, bail out if it doesn't
unless (-d $expected_folder)
{
BAIL_OUT "Expected files folder $expected_folder doesn't exist: \n";;
}
# Get filename of the this perl file
my $perlfilename = basename($0);
#Remove .pl from filename and store in a variable
$perlfilename =~ s/\.[^.]+$//;
my $filename_without_extension = $perlfilename;
# Create expected filename with path
my $expected_filename = "${filename_without_extension}.out";
my $expected_filename_with_path = "${expected_folder}/${expected_filename}" ;
# Create results filename with path
my $out_filename = "${filename_without_extension}.out";
my $out_filename_with_path = "${results_folder}/${out_filename}" ;
# Delete already existing result out file, if it exists.
if ( -f $out_filename_with_path)
{
unlink($out_filename_with_path) or die "Can't delete already existing $out_filename_with_path: $!\n";
}
# Create new PostgreSQL node and do initdb
my $node = PostgresNode->get_new_node('test');
my $pgdata = $node->data_dir;
$node->dump_info;
$node->init;
# Update postgresql.conf to include/load pg_stat_monitor library
open my $conf, '>>', "$pgdata/postgresql.conf";
print $conf "shared_preload_libraries = 'pg_stat_monitor'\n";
print $conf "pg_stat_monitor.pgsm_query_shared_buffer = 1\n";
close $conf;
# Start server
my $rt_value = $node->start;
ok($rt_value == 1, "Start Server");
# Create extension and change out file permissions
my ($cmdret, $stdout, $stderr) = $node->psql('postgres', 'CREATE EXTENSION pg_stat_monitor;', extra_params => ['-a']);
ok($cmdret == 0, "Create PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
chmod(0640 , $out_filename_with_path)
or die("unable to set permissions for $out_filename_with_path");
# Run required commands/queries and dump output to out file.
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT * from pg_stat_monitor_settings;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
# Create example database and run pgbench init
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'CREATE database example;', extra_params => ['-a']);
print "cmdret $cmdret\n";
ok($cmdret == 0, "Create Database example");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
my $port = $node->port;
print "port $port \n";
my $out = system ("pgbench -i -s 10 -p $port example");
print " out: $out \n" ;
ok($cmdret == 0, "Perform pgbench init");
$out = system ("pgbench -c 10 -j 2 -t 1000 -p $port example");
print " out: $out \n" ;
ok($cmdret == 0, "Run pgbench");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select datname, substr(query,0,100) as query, calls from pg_stat_monitor order by datname, query, calls desc Limit 20;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
print "cmdret $cmdret\n";
ok($cmdret == 0, "Select XXX from pg_stat_monitor");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_query_shared_buffer = 100\n");
$node->restart();
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT * from pg_stat_monitor_settings;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_query_shared_buffer = 20\n");
$node->restart();
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT * from pg_stat_monitor_settings;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
# Drop extension
$stdout = $node->safe_psql('postgres', 'Drop extension pg_stat_monitor;', extra_params => ['-a']);
ok($cmdret == 0, "Drop PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
# Stop the server
$node->stop;
# compare the expected and out file
my $compare = compare($expected_filename_with_path, $out_filename_with_path);
# Test/check if expected and result/out file match. If Yes, test passes.
is($compare,0,"Compare Files: $expected_filename_with_path and $out_filename_with_path match.");
# Done testing for this testcase file.
done_testing();

View File

@ -0,0 +1,141 @@
#!/usr/bin/perl
use strict;
use warnings;
use File::Basename;
use File::Compare;
use PostgresNode;
use Test::More;
# Expected folder where expected output will be present
my $expected_folder = "t/expected";
# Results/out folder where generated results files will be placed
my $results_folder = "t/results";
# Check if results folder exists or not, create if it doesn't
unless (-d $results_folder)
{
mkdir $results_folder or die "Can't create folder $results_folder: $!\n";;
}
# Check if expected folder exists or not, bail out if it doesn't
unless (-d $expected_folder)
{
BAIL_OUT "Expected files folder $expected_folder doesn't exist: \n";;
}
# Get filename of the this perl file
my $perlfilename = basename($0);
#Remove .pl from filename and store in a variable
$perlfilename =~ s/\.[^.]+$//;
my $filename_without_extension = $perlfilename;
# Create expected filename with path
my $expected_filename = "${filename_without_extension}.out";
my $expected_filename_with_path = "${expected_folder}/${expected_filename}" ;
# Create results filename with path
my $out_filename = "${filename_without_extension}.out";
my $out_filename_with_path = "${results_folder}/${out_filename}" ;
# Delete already existing result out file, if it exists.
if ( -f $out_filename_with_path)
{
unlink($out_filename_with_path) or die "Can't delete already existing $out_filename_with_path: $!\n";
}
# Create new PostgreSQL node and do initdb
my $node = PostgresNode->get_new_node('test');
my $pgdata = $node->data_dir;
$node->dump_info;
$node->init;
# Update postgresql.conf to include/load pg_stat_monitor library
open my $conf, '>>', "$pgdata/postgresql.conf";
print $conf "shared_preload_libraries = 'pg_stat_monitor'\n";
print $conf "pg_stat_monitor.pgsm_histogram_buckets = 10000\n";
close $conf;
# Start server
my $rt_value = $node->start;
ok($rt_value == 1, "Start Server");
# Create extension and change out file permissions
my ($cmdret, $stdout, $stderr) = $node->psql('postgres', 'CREATE EXTENSION pg_stat_monitor;', extra_params => ['-a']);
ok($cmdret == 0, "Create PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
chmod(0640 , $out_filename_with_path)
or die("unable to set permissions for $out_filename_with_path");
# Run required commands/queries and dump output to out file.
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT * from pg_stat_monitor_settings;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_histogram_buckets = 1000\n");
$node->restart();
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT * from pg_stat_monitor_settings;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_histogram_buckets = 100\n");
$node->restart();
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT * from pg_stat_monitor_settings;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_histogram_buckets = 10\n");
$node->restart();
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT * from pg_stat_monitor_settings;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_histogram_buckets = 1\n");
$node->restart();
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT * from pg_stat_monitor_settings;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
# Drop extension
$stdout = $node->safe_psql('postgres', 'Drop extension pg_stat_monitor;', extra_params => ['-a']);
ok($cmdret == 0, "Drop PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
# Stop the server
$node->stop;
# compare the expected and out file
my $compare = compare($expected_filename_with_path, $out_filename_with_path);
# Test/check if expected and result/out file match. If Yes, test passes.
is($compare,0,"Compare Files: $expected_filename_with_path and $out_filename_with_path match.");
# Done testing for this testcase file.
done_testing();

View File

@ -0,0 +1,130 @@
#!/usr/bin/perl
use strict;
use warnings;
use File::Basename;
use File::Compare;
use PostgresNode;
use Test::More;
# Expected folder where expected output will be present
my $expected_folder = "t/expected";
# Results/out folder where generated results files will be placed
my $results_folder = "t/results";
# Check if results folder exists or not, create if it doesn't
unless (-d $results_folder)
{
mkdir $results_folder or die "Can't create folder $results_folder: $!\n";;
}
# Check if expected folder exists or not, bail out if it doesn't
unless (-d $expected_folder)
{
BAIL_OUT "Expected files folder $expected_folder doesn't exist: \n";;
}
# Get filename of the this perl file
my $perlfilename = basename($0);
#Remove .pl from filename and store in a variable
$perlfilename =~ s/\.[^.]+$//;
my $filename_without_extension = $perlfilename;
# Create expected filename with path
my $expected_filename = "${filename_without_extension}.out";
my $expected_filename_with_path = "${expected_folder}/${expected_filename}" ;
# Create results filename with path
my $out_filename = "${filename_without_extension}.out";
my $out_filename_with_path = "${results_folder}/${out_filename}" ;
# Delete already existing result out file, if it exists.
if ( -f $out_filename_with_path)
{
unlink($out_filename_with_path) or die "Can't delete already existing $out_filename_with_path: $!\n";
}
# Create new PostgreSQL node and do initdb
my $node = PostgresNode->get_new_node('test');
my $pgdata = $node->data_dir;
$node->dump_info;
$node->init;
# Update postgresql.conf to include/load pg_stat_monitor library
open my $conf, '>>', "$pgdata/postgresql.conf";
print $conf "shared_preload_libraries = 'pg_stat_monitor'\n";
print $conf "pg_stat_monitor.pgsm_histogram_max = 1\n";
close $conf;
# Start server
my $rt_value = $node->start;
ok($rt_value == 1, "Start Server");
# Create extension and change out file permissions
my ($cmdret, $stdout, $stderr) = $node->psql('postgres', 'CREATE EXTENSION pg_stat_monitor;', extra_params => ['-a']);
ok($cmdret == 0, "Create PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
chmod(0640 , $out_filename_with_path)
or die("unable to set permissions for $out_filename_with_path");
# Run required commands/queries and dump output to out file.
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT * from pg_stat_monitor_settings;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_histogram_max = 10\n");
$node->restart();
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT * from pg_stat_monitor_settings;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_histogram_max = 100\n");
$node->restart();
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT * from pg_stat_monitor_settings;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_histogram_max = 1000\n");
$node->restart();
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT * from pg_stat_monitor_settings;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
# Drop extension
$stdout = $node->safe_psql('postgres', 'Drop extension pg_stat_monitor;', extra_params => ['-a']);
ok($cmdret == 0, "Drop PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
# Stop the server
$node->stop;
# compare the expected and out file
my $compare = compare($expected_filename_with_path, $out_filename_with_path);
# Test/check if expected and result/out file match. If Yes, test passes.
is($compare,0,"Compare Files: $expected_filename_with_path and $out_filename_with_path match.");
# Done testing for this testcase file.
done_testing();

View File

@ -0,0 +1,130 @@
#!/usr/bin/perl
use strict;
use warnings;
use File::Basename;
use File::Compare;
use PostgresNode;
use Test::More;
# Expected folder where expected output will be present
my $expected_folder = "t/expected";
# Results/out folder where generated results files will be placed
my $results_folder = "t/results";
# Check if results folder exists or not, create if it doesn't
unless (-d $results_folder)
{
mkdir $results_folder or die "Can't create folder $results_folder: $!\n";;
}
# Check if expected folder exists or not, bail out if it doesn't
unless (-d $expected_folder)
{
BAIL_OUT "Expected files folder $expected_folder doesn't exist: \n";;
}
# Get filename of the this perl file
my $perlfilename = basename($0);
#Remove .pl from filename and store in a variable
$perlfilename =~ s/\.[^.]+$//;
my $filename_without_extension = $perlfilename;
# Create expected filename with path
my $expected_filename = "${filename_without_extension}.out";
my $expected_filename_with_path = "${expected_folder}/${expected_filename}" ;
# Create results filename with path
my $out_filename = "${filename_without_extension}.out";
my $out_filename_with_path = "${results_folder}/${out_filename}" ;
# Delete already existing result out file, if it exists.
if ( -f $out_filename_with_path)
{
unlink($out_filename_with_path) or die "Can't delete already existing $out_filename_with_path: $!\n";
}
# Create new PostgreSQL node and do initdb
my $node = PostgresNode->get_new_node('test');
my $pgdata = $node->data_dir;
$node->dump_info;
$node->init;
# Update postgresql.conf to include/load pg_stat_monitor library
open my $conf, '>>', "$pgdata/postgresql.conf";
print $conf "shared_preload_libraries = 'pg_stat_monitor'\n";
print $conf "pg_stat_monitor.pgsm_histogram_min = 1\n";
close $conf;
# Start server
my $rt_value = $node->start;
ok($rt_value == 1, "Start Server");
# Create extension and change out file permissions
my ($cmdret, $stdout, $stderr) = $node->psql('postgres', 'CREATE EXTENSION pg_stat_monitor;', extra_params => ['-a']);
ok($cmdret == 0, "Create PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
chmod(0640 , $out_filename_with_path)
or die("unable to set permissions for $out_filename_with_path");
# Run required commands/queries and dump output to out file.
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT * from pg_stat_monitor_settings;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_histogram_min = 1000\n");
$node->restart();
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT * from pg_stat_monitor_settings;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_histogram_min = 10000\n");
$node->restart();
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT * from pg_stat_monitor_settings;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_histogram_min = 99999\n");
$node->restart();
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT * from pg_stat_monitor_settings;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
# Drop extension
$stdout = $node->safe_psql('postgres', 'Drop extension pg_stat_monitor;', extra_params => ['-a']);
ok($cmdret == 0, "Drop PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
# Stop the server
$node->stop;
# compare the expected and out file
my $compare = compare($expected_filename_with_path, $out_filename_with_path);
# Test/check if expected and result/out file match. If Yes, test passes.
is($compare,0,"Compare Files: $expected_filename_with_path and $out_filename_with_path match.");
# Done testing for this testcase file.
done_testing();

View File

@ -0,0 +1,152 @@
#!/usr/bin/perl
use strict;
use warnings;
use File::Basename;
use File::Compare;
use PostgresNode;
use Test::More;
# Expected folder where expected output will be present
my $expected_folder = "t/expected";
# Results/out folder where generated results files will be placed
my $results_folder = "t/results";
# Check if results folder exists or not, create if it doesn't
unless (-d $results_folder)
{
mkdir $results_folder or die "Can't create folder $results_folder: $!\n";;
}
# Check if expected folder exists or not, bail out if it doesn't
unless (-d $expected_folder)
{
BAIL_OUT "Expected files folder $expected_folder doesn't exist: \n";;
}
# Get filename of the this perl file
my $perlfilename = basename($0);
#Remove .pl from filename and store in a variable
$perlfilename =~ s/\.[^.]+$//;
my $filename_without_extension = $perlfilename;
# Create expected filename with path
my $expected_filename = "${filename_without_extension}.out";
my $expected_filename_with_path = "${expected_folder}/${expected_filename}" ;
# Create results filename with path
my $out_filename = "${filename_without_extension}.out";
my $out_filename_with_path = "${results_folder}/${out_filename}" ;
# Delete already existing result out file, if it exists.
if ( -f $out_filename_with_path)
{
unlink($out_filename_with_path) or die "Can't delete already existing $out_filename_with_path: $!\n";
}
# Create new PostgreSQL node and do initdb
my $node = PostgresNode->get_new_node('test');
my $pgdata = $node->data_dir;
$node->dump_info;
$node->init;
# Update postgresql.conf to include/load pg_stat_monitor library
open my $conf, '>>', "$pgdata/postgresql.conf";
print $conf "shared_preload_libraries = 'pg_stat_monitor'\n";
print $conf "pg_stat_monitor.pgsm_bucket_time = 10000\n";
close $conf;
# Start server
my $rt_value = $node->start;
ok($rt_value == 1, "Start Server");
# Create extension and change out file permissions
my ($cmdret, $stdout, $stderr) = $node->psql('postgres', 'CREATE EXTENSION pg_stat_monitor;', extra_params => ['-a']);
ok($cmdret == 0, "Create PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
chmod(0640 , $out_filename_with_path)
or die("unable to set permissions for $out_filename_with_path");
# Run required commands/queries and dump output to out file.
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT * from pg_stat_monitor_settings;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_bucket_time = 1000\n");
$node->restart();
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT * from pg_stat_monitor_settings;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_bucket_time = 100\n");
$node->restart();
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT * from pg_stat_monitor_settings;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_bucket_time = 60\n");
$node->restart();
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT * from pg_stat_monitor_settings;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_bucket_time = 1\n");
$node->restart();
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT * from pg_stat_monitor_settings;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_bucket_time = 0\n");
$node->restart();
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT * from pg_stat_monitor_settings;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
# Drop extension
$stdout = $node->safe_psql('postgres', 'Drop extension pg_stat_monitor;', extra_params => ['-a']);
ok($cmdret == 0, "Drop PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
# Stop the server
$node->stop;
# compare the expected and out file
my $compare = compare($expected_filename_with_path, $out_filename_with_path);
# Test/check if expected and result/out file match. If Yes, test passes.
is($compare,0,"Compare Files: $expected_filename_with_path and $out_filename_with_path match.");
# Done testing for this testcase file.
done_testing();

View File

@ -0,0 +1,152 @@
#!/usr/bin/perl
use strict;
use warnings;
use File::Basename;
use File::Compare;
use PostgresNode;
use Test::More;
# Expected folder where expected output will be present
my $expected_folder = "t/expected";
# Results/out folder where generated results files will be placed
my $results_folder = "t/results";
# Check if results folder exists or not, create if it doesn't
unless (-d $results_folder)
{
mkdir $results_folder or die "Can't create folder $results_folder: $!\n";;
}
# Check if expected folder exists or not, bail out if it doesn't
unless (-d $expected_folder)
{
BAIL_OUT "Expected files folder $expected_folder doesn't exist: \n";;
}
# Get filename of the this perl file
my $perlfilename = basename($0);
#Remove .pl from filename and store in a variable
$perlfilename =~ s/\.[^.]+$//;
my $filename_without_extension = $perlfilename;
# Create expected filename with path
my $expected_filename = "${filename_without_extension}.out";
my $expected_filename_with_path = "${expected_folder}/${expected_filename}" ;
# Create results filename with path
my $out_filename = "${filename_without_extension}.out";
my $out_filename_with_path = "${results_folder}/${out_filename}" ;
# Delete already existing result out file, if it exists.
if ( -f $out_filename_with_path)
{
unlink($out_filename_with_path) or die "Can't delete already existing $out_filename_with_path: $!\n";
}
# Create new PostgreSQL node and do initdb
my $node = PostgresNode->get_new_node('test');
my $pgdata = $node->data_dir;
$node->dump_info;
$node->init;
# Update postgresql.conf to include/load pg_stat_monitor library
open my $conf, '>>', "$pgdata/postgresql.conf";
print $conf "shared_preload_libraries = 'pg_stat_monitor'\n";
print $conf "pg_stat_monitor.pgsm_max_buckets = 1\n";
close $conf;
# Start server
my $rt_value = $node->start;
ok($rt_value == 1, "Start Server");
# Create extension and change out file permissions
my ($cmdret, $stdout, $stderr) = $node->psql('postgres', 'CREATE EXTENSION pg_stat_monitor;', extra_params => ['-a']);
ok($cmdret == 0, "Create PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
chmod(0640 , $out_filename_with_path)
or die("unable to set permissions for $out_filename_with_path");
# Run required commands/queries and dump output to out file.
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT * from pg_stat_monitor_settings;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_max_buckets = 2\n");
$node->restart();
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT * from pg_stat_monitor_settings;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_max_buckets = 5\n");
$node->restart();
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT * from pg_stat_monitor_settings;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_max_buckets = 10\n");
$node->restart();
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT * from pg_stat_monitor_settings;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_max_buckets = 11\n");
$node->restart();
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT * from pg_stat_monitor_settings;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_max_buckets = 0\n");
$node->restart();
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT * from pg_stat_monitor_settings;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
# Drop extension
$stdout = $node->safe_psql('postgres', 'Drop extension pg_stat_monitor;', extra_params => ['-a']);
ok($cmdret == 0, "Drop PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
# Stop the server
$node->stop;
# compare the expected and out file
my $compare = compare($expected_filename_with_path, $out_filename_with_path);
# Test/check if expected and result/out file match. If Yes, test passes.
is($compare,0,"Compare Files: $expected_filename_with_path and $out_filename_with_path match.");
# Done testing for this testcase file.
done_testing();

View File

@ -0,0 +1,149 @@
#!/usr/bin/perl
use strict;
use warnings;
use File::Basename;
use File::Compare;
use PostgresNode;
use Test::More;
# Expected folder where expected output will be present
my $expected_folder = "t/expected";
# Results/out folder where generated results files will be placed
my $results_folder = "t/results";
# Check if results folder exists or not, create if it doesn't
unless (-d $results_folder)
{
mkdir $results_folder or die "Can't create folder $results_folder: $!\n";;
}
# Check if expected folder exists or not, bail out if it doesn't
unless (-d $expected_folder)
{
BAIL_OUT "Expected files folder $expected_folder doesn't exist: \n";;
}
# Get filename of the this perl file
my $perlfilename = basename($0);
#Remove .pl from filename and store in a variable
$perlfilename =~ s/\.[^.]+$//;
my $filename_without_extension = $perlfilename;
# Create expected filename with path
my $expected_filename = "${filename_without_extension}.out";
my $expected_filename_with_path = "${expected_folder}/${expected_filename}" ;
# Create results filename with path
my $out_filename = "${filename_without_extension}.out";
my $out_filename_with_path = "${results_folder}/${out_filename}" ;
# Delete already existing result out file, if it exists.
if ( -f $out_filename_with_path)
{
unlink($out_filename_with_path) or die "Can't delete already existing $out_filename_with_path: $!\n";
}
# Create new PostgreSQL node and do initdb
my $node = PostgresNode->get_new_node('test');
my $pgdata = $node->data_dir;
$node->dump_info;
$node->init;
# Update postgresql.conf to include/load pg_stat_monitor library
open my $conf, '>>', "$pgdata/postgresql.conf";
print $conf "shared_preload_libraries = 'pg_stat_monitor'\n";
print $conf "pg_stat_monitor.pgsm_normalized_query = 'no'\n";
close $conf;
# Start server
my $rt_value = $node->start;
ok($rt_value == 1, "Start Server");
# Create extension and change out file permissions
my ($cmdret, $stdout, $stderr) = $node->psql('postgres', 'CREATE EXTENSION pg_stat_monitor;', extra_params => ['-a']);
ok($cmdret == 0, "Create PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
chmod(0640 , $out_filename_with_path)
or die("unable to set permissions for $out_filename_with_path");
# Run required commands/queries and dump output to out file.
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT * from pg_stat_monitor_settings;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'CREATE TABLE TBL_0(key text primary key, txt_0 text, value_0 int);', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', "INSERT INTO TBL_0(key, txt_0, value_0) VALUES('000000', '846930886', 1804289383);", extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT key, txt_0, value_0 FROM TBL_0;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT key, txt_0, value_0 FROM TBL_0;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'UPDATE TBL_0 SET value_0 = 1681692777;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select datname, substr(query,0,100) as query, calls from pg_stat_monitor order by datname, query, calls desc Limit 20;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Select XXX from pg_stat_monitor");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_normalized_query = 'yes'\n");
$node->restart();
# Run required commands/queries and dump output to out file.
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Drop TABLE TBL_0;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT * from pg_stat_monitor_settings;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'CREATE TABLE TBL_0(key text primary key, txt_0 text, value_0 int);', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', "INSERT INTO TBL_0(key, txt_0, value_0) VALUES('000000', '846930886', 1804289383);", extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT key, txt_0, value_0 FROM TBL_0;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT key, txt_0, value_0 FROM TBL_0;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'UPDATE TBL_0 SET value_0 = 1681692777;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select datname, substr(query,0,100) as query, calls from pg_stat_monitor order by datname, query, calls desc Limit 20;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Select XXX from pg_stat_monitor");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
# Drop extension
$stdout = $node->safe_psql('postgres', 'Drop extension pg_stat_monitor;', extra_params => ['-a']);
ok($cmdret == 0, "Drop PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
# Stop the server
$node->stop;
# compare the expected and out file
my $compare = compare($expected_filename_with_path, $out_filename_with_path);
# Test/check if expected and result/out file match. If Yes, test passes.
is($compare,0,"Compare Files: $expected_filename_with_path and $out_filename_with_path match.");
# Done testing for this testcase file.
done_testing();

View File

@ -0,0 +1,158 @@
#!/usr/bin/perl
use strict;
use warnings;
use File::Basename;
use File::Compare;
use PostgresNode;
use Test::More;
# Expected folder where expected output will be present
my $expected_folder = "t/expected";
# Results/out folder where generated results files will be placed
my $results_folder = "t/results";
# Check if results folder exists or not, create if it doesn't
unless (-d $results_folder)
{
mkdir $results_folder or die "Can't create folder $results_folder: $!\n";;
}
# Check if expected folder exists or not, bail out if it doesn't
unless (-d $expected_folder)
{
BAIL_OUT "Expected files folder $expected_folder doesn't exist: \n";;
}
# Get filename of the this perl file
my $perlfilename = basename($0);
#Remove .pl from filename and store in a variable
$perlfilename =~ s/\.[^.]+$//;
my $filename_without_extension = $perlfilename;
# Create expected filename with path
my $expected_filename = "${filename_without_extension}.out";
my $expected_filename_with_path = "${expected_folder}/${expected_filename}" ;
# Create results filename with path
my $out_filename = "${filename_without_extension}.out";
my $out_filename_with_path = "${results_folder}/${out_filename}" ;
# Delete already existing result out file, if it exists.
if ( -f $out_filename_with_path)
{
unlink($out_filename_with_path) or die "Can't delete already existing $out_filename_with_path: $!\n";
}
# Create new PostgreSQL node and do initdb
my $node = PostgresNode->get_new_node('test');
my $pgdata = $node->data_dir;
$node->dump_info;
$node->init;
# Update postgresql.conf to include/load pg_stat_monitor library
open my $conf, '>>', "$pgdata/postgresql.conf";
print $conf "shared_preload_libraries = 'pg_stat_monitor'\n";
print $conf "pg_stat_monitor.pgsm_track_utility = 'no'\n";
close $conf;
# Start server
my $rt_value = $node->start;
ok($rt_value == 1, "Start Server");
# Create extension and change out file permissions
my ($cmdret, $stdout, $stderr) = $node->psql('postgres', 'CREATE EXTENSION pg_stat_monitor;', extra_params => ['-a']);
ok($cmdret == 0, "Create PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
chmod(0640 , $out_filename_with_path)
or die("unable to set permissions for $out_filename_with_path");
# Run required commands/queries and dump output to out file.
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT * from pg_stat_monitor_settings;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'CREATE TABLE TBL_0(key text primary key, txt_0 text, value_0 int);', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', "INSERT INTO TBL_0(key, txt_0, value_0) VALUES('000000', '846930886', 1804289383);", extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT key, txt_0, value_0 FROM TBL_0;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT key, txt_0, value_0 FROM TBL_0;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'UPDATE TBL_0 SET value_0 = 1681692777;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Analyze TBL_0;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'DROP TABLE TBL_0;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select datname, substr(query,0,100) as query, calls from pg_stat_monitor order by datname, query, calls desc Limit 20;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Select XXX from pg_stat_monitor");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_track_utility = 'yes'\n");
$node->restart();
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT * from pg_stat_monitor_settings;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'CREATE TABLE TBL_0(key text primary key, txt_0 text, value_0 int);', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', "INSERT INTO TBL_0(key, txt_0, value_0) VALUES('000000', '846930886', 1804289383);", extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT key, txt_0, value_0 FROM TBL_0;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT key, txt_0, value_0 FROM TBL_0;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'UPDATE TBL_0 SET value_0 = 1681692777;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Analyze TBL_0;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'DROP TABLE TBL_0;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select datname, substr(query,0,100) as query, calls from pg_stat_monitor order by datname, query, calls desc Limit 20;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Select XXX from pg_stat_monitor");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
# Drop extension
$stdout = $node->safe_psql('postgres', 'Drop extension pg_stat_monitor;', extra_params => ['-a']);
ok($cmdret == 0, "Drop PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
# Stop the server
$node->stop;
# compare the expected and out file
my $compare = compare($expected_filename_with_path, $out_filename_with_path);
# Test/check if expected and result/out file match. If Yes, test passes.
is($compare,0,"Compare Files: $expected_filename_with_path and $out_filename_with_path match.");
# Done testing for this testcase file.
done_testing();

View File

@ -0,0 +1,141 @@
#!/usr/bin/perl
use strict;
use warnings;
use File::Basename;
use File::Compare;
use PostgresNode;
use Test::More;
# Expected folder where expected output will be present
my $expected_folder = "t/expected";
# Results/out folder where generated results files will be placed
my $results_folder = "t/results";
# Check if results folder exists or not, create if it doesn't
unless (-d $results_folder)
{
mkdir $results_folder or die "Can't create folder $results_folder: $!\n";;
}
# Check if expected folder exists or not, bail out if it doesn't
unless (-d $expected_folder)
{
BAIL_OUT "Expected files folder $expected_folder doesn't exist: \n";;
}
# Get filename of the this perl file
my $perlfilename = basename($0);
#Remove .pl from filename and store in a variable
$perlfilename =~ s/\.[^.]+$//;
my $filename_without_extension = $perlfilename;
# Create expected filename with path
my $expected_filename = "${filename_without_extension}.out";
my $expected_filename_with_path = "${expected_folder}/${expected_filename}" ;
# Create results filename with path
my $out_filename = "${filename_without_extension}.out";
my $out_filename_with_path = "${results_folder}/${out_filename}" ;
# Delete already existing result out file, if it exists.
if ( -f $out_filename_with_path)
{
unlink($out_filename_with_path) or die "Can't delete already existing $out_filename_with_path: $!\n";
}
# Create new PostgreSQL node and do initdb
my $node = PostgresNode->get_new_node('test');
my $pgdata = $node->data_dir;
$node->dump_info;
$node->init;
# Update postgresql.conf to include/load pg_stat_monitor library
open my $conf, '>>', "$pgdata/postgresql.conf";
print $conf "shared_preload_libraries = 'pg_stat_monitor'\n";
print $conf "pg_stat_monitor.pgsm_query_max_len = 10240\n";
close $conf;
# Start server
my $rt_value = $node->start;
ok($rt_value == 1, "Start Server");
# Create extension and change out file permissions
my ($cmdret, $stdout, $stderr) = $node->psql('postgres', 'CREATE EXTENSION pg_stat_monitor;', extra_params => ['-a']);
ok($cmdret == 0, "Create PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
chmod(0640 , $out_filename_with_path)
or die("unable to set permissions for $out_filename_with_path");
# Run required commands/queries and dump output to out file.
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT * from pg_stat_monitor_settings;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_query_max_len = 1024\n");
$node->restart();
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT * from pg_stat_monitor_settings;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_query_max_len = 100\n");
$node->restart();
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT * from pg_stat_monitor_settings;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_query_max_len = 10\n");
$node->restart();
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT * from pg_stat_monitor_settings;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_query_max_len = 0\n");
$node->restart();
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT * from pg_stat_monitor_settings;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
# Drop extension
$stdout = $node->safe_psql('postgres', 'Drop extension pg_stat_monitor;', extra_params => ['-a']);
ok($cmdret == 0, "Drop PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
# Stop the server
$node->stop;
# compare the expected and out file
my $compare = compare($expected_filename_with_path, $out_filename_with_path);
# Test/check if expected and result/out file match. If Yes, test passes.
is($compare,0,"Compare Files: $expected_filename_with_path and $out_filename_with_path match.");
# Done testing for this testcase file.
done_testing();

141
t/016_settings_pgsm_max.pl Normal file
View File

@ -0,0 +1,141 @@
#!/usr/bin/perl
use strict;
use warnings;
use File::Basename;
use File::Compare;
use PostgresNode;
use Test::More;
# Expected folder where expected output will be present
my $expected_folder = "t/expected";
# Results/out folder where generated results files will be placed
my $results_folder = "t/results";
# Check if results folder exists or not, create if it doesn't
unless (-d $results_folder)
{
mkdir $results_folder or die "Can't create folder $results_folder: $!\n";;
}
# Check if expected folder exists or not, bail out if it doesn't
unless (-d $expected_folder)
{
BAIL_OUT "Expected files folder $expected_folder doesn't exist: \n";;
}
# Get filename of the this perl file
my $perlfilename = basename($0);
#Remove .pl from filename and store in a variable
$perlfilename =~ s/\.[^.]+$//;
my $filename_without_extension = $perlfilename;
# Create expected filename with path
my $expected_filename = "${filename_without_extension}.out";
my $expected_filename_with_path = "${expected_folder}/${expected_filename}" ;
# Create results filename with path
my $out_filename = "${filename_without_extension}.out";
my $out_filename_with_path = "${results_folder}/${out_filename}" ;
# Delete already existing result out file, if it exists.
if ( -f $out_filename_with_path)
{
unlink($out_filename_with_path) or die "Can't delete already existing $out_filename_with_path: $!\n";
}
# Create new PostgreSQL node and do initdb
my $node = PostgresNode->get_new_node('test');
my $pgdata = $node->data_dir;
$node->dump_info;
$node->init;
# Update postgresql.conf to include/load pg_stat_monitor library
open my $conf, '>>', "$pgdata/postgresql.conf";
print $conf "shared_preload_libraries = 'pg_stat_monitor'\n";
print $conf "pg_stat_monitor.pgsm_max = 1000\n";
close $conf;
# Start server
my $rt_value = $node->start;
ok($rt_value == 1, "Start Server");
# Create extension and change out file permissions
my ($cmdret, $stdout, $stderr) = $node->psql('postgres', 'CREATE EXTENSION pg_stat_monitor;', extra_params => ['-a']);
ok($cmdret == 0, "Create PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
chmod(0640 , $out_filename_with_path)
or die("unable to set permissions for $out_filename_with_path");
# Run required commands/queries and dump output to out file.
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT * from pg_stat_monitor_settings;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_max = 500\n");
$node->restart();
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT * from pg_stat_monitor_settings;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_max = 100\n");
$node->restart();
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT * from pg_stat_monitor_settings;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_max = 10\n");
$node->restart();
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT * from pg_stat_monitor_settings;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_max = 0\n");
$node->restart();
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT * from pg_stat_monitor_settings;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
# Drop extension
$stdout = $node->safe_psql('postgres', 'Drop extension pg_stat_monitor;', extra_params => ['-a']);
ok($cmdret == 0, "Drop PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
# Stop the server
$node->stop;
# compare the expected and out file
my $compare = compare($expected_filename_with_path, $out_filename_with_path);
# Test/check if expected and result/out file match. If Yes, test passes.
is($compare,0,"Compare Files: $expected_filename_with_path and $out_filename_with_path match.");
# Done testing for this testcase file.
done_testing();

155
t/017_execution_stats.pl Normal file
View File

@ -0,0 +1,155 @@
#!/usr/bin/perl
use strict;
use warnings;
use String::Util qw(trim);
use File::Basename;
use File::Compare;
use PostgresNode;
use Test::More;
# Expected folder where expected output will be present
my $expected_folder = "t/expected";
# Results/out folder where generated results files will be placed
my $results_folder = "t/results";
# Check if results folder exists or not, create if it doesn't
unless (-d $results_folder)
{
mkdir $results_folder or die "Can't create folder $results_folder: $!\n";;
}
# Check if expected folder exists or not, bail out if it doesn't
unless (-d $expected_folder)
{
BAIL_OUT "Expected files folder $expected_folder doesn't exist: \n";;
}
# Get filename of the this perl file
my $perlfilename = basename($0);
#Remove .pl from filename and store in a variable
$perlfilename =~ s/\.[^.]+$//;
my $filename_without_extension = $perlfilename;
# Create expected filename with path
my $expected_filename = "${filename_without_extension}.out";
my $expected_filename_with_path = "${expected_folder}/${expected_filename}" ;
# Create results filename with path
my $out_filename = "${filename_without_extension}.out";
my $out_filename_with_path = "${results_folder}/${out_filename}" ;
my $dynamic_out_filename_with_path = "${results_folder}/${out_filename}.dynamic" ;
# Delete already existing result out file, if it exists.
if ( -f $out_filename_with_path)
{
unlink($out_filename_with_path) or die "Can't delete already existing $out_filename_with_path: $!\n";
}
# Create new PostgreSQL node and do initdb
my $node = PostgresNode->get_new_node('test');
my $pgdata = $node->data_dir;
$node->dump_info;
$node->init;
# Update postgresql.conf to include/load pg_stat_monitor library
open my $conf, '>>', "$pgdata/postgresql.conf";
print $conf "shared_preload_libraries = 'pg_stat_monitor'\n";
close $conf;
# Start server
my $rt_value = $node->start;
ok($rt_value == 1, "Start Server");
# Create extension and change out file permissions
my ($cmdret, $stdout, $stderr) = $node->psql('postgres', 'CREATE EXTENSION pg_stat_monitor;', extra_params => ['-a']);
ok($cmdret == 0, "Create PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
chmod(0640 , $out_filename_with_path)
or die("unable to set permissions for $out_filename_with_path");
# Run required commands/queries and dump output to out file.
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
# Run 'SELECT * from pg_stat_monitor_settings;' two times and dump output to out file
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT * from pg_stat_monitor_settings;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT * from pg_stat_monitor_settings;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT query, calls, total_exec_time, min_exec_time, max_exec_time, mean_exec_time, stddev_exec_time from pg_stat_monitor;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Select from PGSM view");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
# Test: total_exec_time is not 0
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select (total_exec_time = 0) from pg_stat_monitor where calls = 2 ;', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'f',"Compare: total_exec_time is not 0).");
# Test: min_exec_time is not 0
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select (min_exec_time = 0) from pg_stat_monitor where calls = 2 ;', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'f',"Compare: min_exec_time is not 0).");
# Test: max_exec_time is not 0
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select (max_exec_time = 0) from pg_stat_monitor where calls = 2 ;', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'f',"Compare: max_exec_time is not 0).");
# Test: mean_exec_time is not 0
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select (mean_exec_time = 0) from pg_stat_monitor where calls = 2 ;', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'f',"Compare: mean_exec_time is not 0).");
# Test: stddev_exec_time is not 0
#($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select (stddev_exec_time = 0) from pg_stat_monitor where calls = 2 ;', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
#trim($stdout);
#is($stdout,'f',"Test: stddev_exec_time should not be 0).");
# Test: total_exec_time = min_exec_time + max_exec_time
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select (round(total_exec_time::numeric,3) = round(min_exec_time::numeric + max_exec_time::numeric,3)) from pg_stat_monitor where calls = 2 ;', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Compare: (round(total_exec_time::numeric,3) = round(min_exec_time::numeric + max_exec_time::numeric,3)).");
# Test: mean_exec_time = total_exec_time/2
#($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select (round(mean_exec_time::numeric,3) = round((total_exec_time/2)::numeric,3)) from pg_stat_monitor where calls = 2 ;', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
#trim($stdout);
#is($stdout,'t',"Compare mean_exec_time: (round(mean_exec_time::numeric,3) = round((total_exec_time/2)::numeric,3)).");
# Test: stddev_exec_time = mean_exec_time - min_exec_time
#($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select (round(stddev_exec_time::numeric,3) = round(mean_exec_time::numeric - min_exec_time::numeric,3)) from pg_stat_monitor where calls = 2 ;', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
#trim($stdout);
#is($stdout,'t',"Compare mean_exec_time: (round(stddev_exec_time::numeric,3) = round(mean_exec_time::numeric - min_exec_time::numeric,3)).");
# Dump output to out file
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select substr(query, 0,100) as query, calls, total_exec_time, min_exec_time,max_exec_time,mean_exec_time,stddev_exec_time from pg_stat_monitor order by query;', extra_params => ['-a','-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($dynamic_out_filename_with_path, $stdout . "\n");
# Dump output to out file
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
# Drop extension
$stdout = $node->safe_psql('postgres', 'Drop extension pg_stat_monitor;', extra_params => ['-a']);
ok($cmdret == 0, "Drop PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
# Stop the server
$node->stop;
# compare the expected and out file
#my $compare = compare($expected_filename_with_path, $out_filename_with_path);
# Test/check if expected and result/out file match. If Yes, test passes.
#is($compare,0,"Compare Files: $expected_filename_with_path and $out_filename_with_path match.");
# Done testing for this testcase file.
done_testing();

View File

@ -0,0 +1,135 @@
#!/usr/bin/perl
use strict;
use warnings;
use String::Util qw(trim);
use File::Basename;
use File::Compare;
use PostgresNode;
use Test::More;
# Expected folder where expected output will be present
my $expected_folder = "t/expected";
# Results/out folder where generated results files will be placed
my $results_folder = "t/results";
# Check if results folder exists or not, create if it doesn't
unless (-d $results_folder)
{
mkdir $results_folder or die "Can't create folder $results_folder: $!\n";;
}
# Check if expected folder exists or not, bail out if it doesn't
unless (-d $expected_folder)
{
BAIL_OUT "Expected files folder $expected_folder doesn't exist: \n";;
}
# Get filename of the this perl file
my $perlfilename = basename($0);
#Remove .pl from filename and store in a variable
$perlfilename =~ s/\.[^.]+$//;
my $filename_without_extension = $perlfilename;
# Create expected filename with path
my $expected_filename = "${filename_without_extension}.out";
my $expected_filename_with_path = "${expected_folder}/${expected_filename}" ;
# Create results filename with path
my $out_filename = "${filename_without_extension}.out";
my $out_filename_with_path = "${results_folder}/${out_filename}" ;
# Delete already existing result out file, if it exists.
if ( -f $out_filename_with_path)
{
unlink($out_filename_with_path) or die "Can't delete already existing $out_filename_with_path: $!\n";
}
# Create new PostgreSQL node and do initdb
my $node = PostgresNode->get_new_node('test');
my $pgdata = $node->data_dir;
$node->dump_info;
$node->init;
# Update postgresql.conf to include/load pg_stat_monitor library
open my $conf, '>>', "$pgdata/postgresql.conf";
print $conf "shared_preload_libraries = 'pg_stat_monitor'\n";
print $conf "pg_stat_monitor.pgsm_overflow_target = 0\n";
print $conf "pg_stat_monitor.pgsm_max = 1\n";
print $conf "pg_stat_monitor.pgsm_query_shared_buffer = 1\n";
close $conf;
# Start server
my $rt_value = $node->start;
ok($rt_value == 1, "Start Server");
# Create extension and change out file permissions
my ($cmdret, $stdout, $stderr) = $node->psql('postgres', 'CREATE EXTENSION pg_stat_monitor;', extra_params => ['-a']);
ok($cmdret == 0, "Create PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
chmod(0640 , $out_filename_with_path)
or die("unable to set permissions for $out_filename_with_path");
# Run required commands/queries and dump output to out file.
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'create table foo (id int generated by default as identity,col1 varchar(100) not null,primary key(id));', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Create Table foo");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT * from pg_stat_monitor_settings;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', '\i scripts/data_1.sql' , extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Run sql file: scripts/data.sql");
#TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT substr(query, 0, 50), length(query), bucket, queryid, calls, elevel, sqlcode, message from pg_stat_monitor;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "SELECT substr(query, 0, 50), calls, message from pg_stat_monitor");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT count(queryid) from pg_stat_monitor;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "SELECT count(queryid) from pg_stat_monitor");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_overflow_target = 1\n");
$node->restart();
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT * from pg_stat_monitor_settings;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', '\i scripts/data_2.sql' , extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Run sql file: scripts/data2.sql");
#TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT substr(query, 0, 50), length(query), bucket, queryid, calls, elevel, sqlcode, message from pg_stat_monitor;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "SELECT substr(query, 0, 50), calls, message from pg_stat_monitor");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT count(queryid) from pg_stat_monitor;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "SELECT count(queryid) from pg_stat_monitor");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
# Drop extension
$stdout = $node->safe_psql('postgres', 'Drop extension pg_stat_monitor;', extra_params => ['-a']);
ok($cmdret == 0, "Drop PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
# Stop the server
$node->stop;
# Done testing for this testcase file.
done_testing();

137
t/020_buffer_overflow.pl Normal file
View File

@ -0,0 +1,137 @@
#!/usr/bin/perl
use strict;
use warnings;
use String::Util qw(trim);
use File::Basename;
use File::Compare;
use PostgresNode;
use Test::More;
# Expected folder where expected output will be present
my $expected_folder = "t/expected";
# Results/out folder where generated results files will be placed
my $results_folder = "t/results";
# Check if results folder exists or not, create if it doesn't
unless (-d $results_folder)
{
mkdir $results_folder or die "Can't create folder $results_folder: $!\n";;
}
# Check if expected folder exists or not, bail out if it doesn't
unless (-d $expected_folder)
{
BAIL_OUT "Expected files folder $expected_folder doesn't exist: \n";;
}
# Get filename of the this perl file
my $perlfilename = basename($0);
#Remove .pl from filename and store in a variable
$perlfilename =~ s/\.[^.]+$//;
my $filename_without_extension = $perlfilename;
# Create expected filename with path
my $expected_filename = "${filename_without_extension}.out";
my $expected_filename_with_path = "${expected_folder}/${expected_filename}" ;
# Create results filename with path
my $out_filename = "${filename_without_extension}.out";
my $out_filename_with_path = "${results_folder}/${out_filename}" ;
# Delete already existing result out file, if it exists.
if ( -f $out_filename_with_path)
{
unlink($out_filename_with_path) or die "Can't delete already existing $out_filename_with_path: $!\n";
}
# Create new PostgreSQL node and do initdb
my $node = PostgresNode->get_new_node('test');
my $pgdata = $node->data_dir;
$node->dump_info;
$node->init;
# Update postgresql.conf to include/load pg_stat_monitor library
open my $conf, '>>', "$pgdata/postgresql.conf";
print $conf "shared_preload_libraries = 'pg_stat_monitor'\n";
print $conf "pg_stat_monitor.pgsm_overflow_target = 0\n";
print $conf "pg_stat_monitor.pgsm_bucket_time = 1\n";
print $conf "pg_stat_monitor.pgsm_max_buckets = 2\n";
print $conf "pg_stat_monitor.pgsm_max = 1\n";
print $conf "pg_stat_monitor.pgsm_query_shared_buffer = 1\n";
close $conf;
# Start server
my $rt_value = $node->start;
ok($rt_value == 1, "Start Server");
# Create extension and change out file permissions
my ($cmdret, $stdout, $stderr) = $node->psql('postgres', 'CREATE EXTENSION pg_stat_monitor;', extra_params => ['-a']);
ok($cmdret == 0, "Create PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
chmod(0640 , $out_filename_with_path)
or die("unable to set permissions for $out_filename_with_path");
# Run required commands/queries and dump output to out file.
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'create table foo (id int generated by default as identity,col1 varchar(100) not null,primary key(id));', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Create Table foo");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT * from pg_stat_monitor_settings;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', '\i scripts/data_1.sql' , extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Run sql file: scripts/data.sql");
#TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT substr(query, 0, 50), length(query), bucket, queryid, calls, elevel, sqlcode, message from pg_stat_monitor;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "SELECT substr(query, 0, 50), calls, message from pg_stat_monitor");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT count(queryid) from pg_stat_monitor;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "SELECT count(queryid) from pg_stat_monitor");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_overflow_target = 1\n");
$node->restart();
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT * from pg_stat_monitor_settings;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', '\i scripts/data_2.sql' , extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Run sql file: scripts/data2.sql");
#TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT substr(query, 0, 50), length(query), bucket, queryid, calls, elevel, sqlcode, message from pg_stat_monitor;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "SELECT substr(query, 0, 50), calls, message from pg_stat_monitor");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT count(queryid) from pg_stat_monitor;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "SELECT count(queryid) from pg_stat_monitor");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
# Drop extension
$stdout = $node->safe_psql('postgres', 'Drop extension pg_stat_monitor;', extra_params => ['-a']);
ok($cmdret == 0, "Drop PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
# Stop the server
$node->stop;
# Done testing for this testcase file.
done_testing();

140
t/021_misc_1.pl Normal file
View File

@ -0,0 +1,140 @@
#!/usr/bin/perl
use strict;
use warnings;
use String::Util qw(trim);
use File::Basename;
use File::Compare;
use PostgresNode;
use Test::More;
# Expected folder where expected output will be present
my $expected_folder = "t/expected";
# Results/out folder where generated results files will be placed
my $results_folder = "t/results";
# Check if results folder exists or not, create if it doesn't
unless (-d $results_folder)
{
mkdir $results_folder or die "Can't create folder $results_folder: $!\n";;
}
# Check if expected folder exists or not, bail out if it doesn't
unless (-d $expected_folder)
{
BAIL_OUT "Expected files folder $expected_folder doesn't exist: \n";;
}
# Get filename of the this perl file
my $perlfilename = basename($0);
#Remove .pl from filename and store in a variable
$perlfilename =~ s/\.[^.]+$//;
my $filename_without_extension = $perlfilename;
# Create expected filename with path
my $expected_filename = "${filename_without_extension}.out";
my $expected_filename_with_path = "${expected_folder}/${expected_filename}" ;
# Create results filename with path
my $out_filename = "${filename_without_extension}.out";
my $out_filename_with_path = "${results_folder}/${out_filename}" ;
# Delete already existing result out file, if it exists.
if ( -f $out_filename_with_path)
{
unlink($out_filename_with_path) or die "Can't delete already existing $out_filename_with_path: $!\n";
}
# Create new PostgreSQL node and do initdb
my $node = PostgresNode->get_new_node('test');
my $pgdata = $node->data_dir;
$node->dump_info;
$node->init;
# Update postgresql.conf to include/load pg_stat_monitor library
open my $conf, '>>', "$pgdata/postgresql.conf";
print $conf "shared_preload_libraries = 'pg_stat_monitor'\n";
print $conf "pg_stat_monitor.pgsm_overflow_target = 0\n";
print $conf "pg_stat_monitor.pgsm_max = 1\n";
print $conf "pg_stat_monitor.pgsm_query_shared_buffer = 1\n";
print $conf "pg_stat_monitor.pgsm_query_max_len =10000\n";
print $conf " pg_stat_monitor.pgsm_enable_query_plan = 'yes'\n";
print $conf "pg_stat_monitor.pgsm_track_planning = 'yes'\n";
print $conf "pg_stat_monitor.pgsm_track = 'all'\n";
print $conf "pg_stat_monitor.pgsm_extract_comments = 'yes'\n";
close $conf;
# Start server
my $rt_value = $node->start;
ok($rt_value == 1, "Start Server");
# Create extension and change out file permissions
my ($cmdret, $stdout, $stderr) = $node->psql('postgres', 'CREATE EXTENSION pg_stat_monitor;', extra_params => ['-a']);
ok($cmdret == 0, "Create PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
chmod(0640 , $out_filename_with_path)
or die("unable to set permissions for $out_filename_with_path");
# Run required commands/queries and dump output to out file.
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'create table foo (id int generated by default as identity,col1 varchar(100) not null,primary key(id));', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Create Table foo");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT * from pg_stat_monitor_settings;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', '\i scripts/data_1.sql' , extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Run sql file: scripts/data.sql");
#TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT substr(query, 0, 50), length(query), bucket, queryid, calls, elevel, sqlcode, message from pg_stat_monitor;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "SELECT substr(query, 0, 50), calls, message from pg_stat_monitor");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT count(queryid) from pg_stat_monitor;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "SELECT count(queryid) from pg_stat_monitor");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_overflow_target = 1\n");
$node->restart();
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT * from pg_stat_monitor_settings;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', '\i scripts/data_2.sql' , extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Run sql file: scripts/data2.sql");
#TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT substr(query, 0, 50), length(query), bucket, queryid, calls, elevel, sqlcode, message from pg_stat_monitor;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "SELECT substr(query, 0, 50), calls, message from pg_stat_monitor");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT count(queryid) from pg_stat_monitor;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "SELECT count(queryid) from pg_stat_monitor");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
# Drop extension
$stdout = $node->safe_psql('postgres', 'Drop extension pg_stat_monitor;', extra_params => ['-a']);
ok($cmdret == 0, "Drop PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
# Stop the server
$node->stop;
# Done testing for this testcase file.
done_testing();

158
t/022_misc_2.pl Normal file
View File

@ -0,0 +1,158 @@
#!/usr/bin/perl
use strict;
use warnings;
use String::Util qw(trim);
use File::Basename;
use File::Compare;
use PostgresNode;
use Test::More;
# Expected folder where expected output will be present
my $expected_folder = "t/expected";
# Results/out folder where generated results files will be placed
my $results_folder = "t/results";
# Check if results folder exists or not, create if it doesn't
unless (-d $results_folder)
{
mkdir $results_folder or die "Can't create folder $results_folder: $!\n";;
}
# Check if expected folder exists or not, bail out if it doesn't
unless (-d $expected_folder)
{
BAIL_OUT "Expected files folder $expected_folder doesn't exist: \n";;
}
# Get filename of the this perl file
my $perlfilename = basename($0);
#Remove .pl from filename and store in a variable
$perlfilename =~ s/\.[^.]+$//;
my $filename_without_extension = $perlfilename;
# Create expected filename with path
my $expected_filename = "${filename_without_extension}.out";
my $expected_filename_with_path = "${expected_folder}/${expected_filename}" ;
# Create results filename with path
my $out_filename = "${filename_without_extension}.out";
my $out_filename_with_path = "${results_folder}/${out_filename}" ;
# Delete already existing result out file, if it exists.
if ( -f $out_filename_with_path)
{
unlink($out_filename_with_path) or die "Can't delete already existing $out_filename_with_path: $!\n";
}
# Create new PostgreSQL node and do initdb
my $node = PostgresNode->get_new_node('test');
my $pgdata = $node->data_dir;
$node->dump_info;
$node->init;
# Update postgresql.conf to include/load pg_stat_monitor library
open my $conf, '>>', "$pgdata/postgresql.conf";
print $conf "shared_preload_libraries = 'pg_stat_monitor'\n";
print $conf "pg_stat_monitor.pgsm_overflow_target = 0\n";
print $conf "pg_stat_monitor.pgsm_max = 1\n";
print $conf "pg_stat_monitor.pgsm_query_shared_buffer = 1\n";
print $conf "pg_stat_monitor.pgsm_query_max_len =10000\n";
print $conf " pg_stat_monitor.pgsm_enable_query_plan = 'yes'\n";
print $conf "pg_stat_monitor.pgsm_track_planning = 'yes'\n";
print $conf "pg_stat_monitor.pgsm_track = 'top'\n";
print $conf "pg_stat_monitor.pgsm_extract_comments = 'no'\n";
close $conf;
# Start server
my $rt_value = $node->start;
ok($rt_value == 1, "Start Server");
# Create extension and change out file permissions
my ($cmdret, $stdout, $stderr) = $node->psql('postgres', 'CREATE EXTENSION pg_stat_monitor;', extra_params => ['-a']);
ok($cmdret == 0, "Create PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
chmod(0640 , $out_filename_with_path)
or die("unable to set permissions for $out_filename_with_path");
# Run required commands/queries and dump output to out file.
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'create table foo (id int generated by default as identity,col1 varchar(100) not null,primary key(id));', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Create Table foo");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT * from pg_stat_monitor_settings;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', '\i scripts/data_1.sql' , extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Run sql file: scripts/data.sql");
#TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT substr(query, 0, 50), length(query), bucket, queryid, calls, elevel, sqlcode, message from pg_stat_monitor;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "SELECT substr(query, 0, 50), calls, message from pg_stat_monitor");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT count(queryid) from pg_stat_monitor;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "SELECT count(queryid) from pg_stat_monitor");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_max = 100\n");
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_query_max_len = 1024\n");
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_track_utility = 'yes'\n");
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_normalized_query = 'yes'\n");
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_max_buckets = 10\n");
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_bucket_time = 60\n");
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_histogram_min = 0\n");
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_histogram_max = 100000\n");
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_histogram_buckets = 10\n");
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_query_shared_buffer = 20\n");
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_overflow_target = 1\n");
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_enable_query_plan = 'no'\n");
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_track = 'top'\n");
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_extract_comments = 'no'\n");
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_track_planning = 'no'\n");
$node->restart();
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT * from pg_stat_monitor_settings;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', '\i scripts/data_2.sql' , extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Run sql file: scripts/data2.sql");
#TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT substr(query, 0, 50), length(query), bucket, queryid, calls, elevel, sqlcode, message from pg_stat_monitor;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "SELECT substr(query, 0, 50), calls, message from pg_stat_monitor");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT count(queryid) from pg_stat_monitor;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "SELECT count(queryid) from pg_stat_monitor");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT * from pg_stat_monitor_settings;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
# Drop extension
$stdout = $node->safe_psql('postgres', 'Drop extension pg_stat_monitor;', extra_params => ['-a']);
ok($cmdret == 0, "Drop PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
# Stop the server
$node->stop;
# Done testing for this testcase file.
done_testing();

99
t/023_missing_queries.pl Normal file
View File

@ -0,0 +1,99 @@
#!/usr/bin/perl
# Tap test for PG-291 / eb4087be4e8cce8eb19d893d9a47975dd19039a0 bug fix.
#
# Before the fix, there were scenarios in which pg_stat_monitor could lose
# queries (thus wrong call count/stats) when transitioning to a new bucket.
#
# The problem before the fix is described below:
# 1. Say current active bucket number is 1.
# 2. QueryID XYZ has call count (calls) = 4.
# 3. QueryID also has a pending query (not yet finished).
# 4. Bucket 1 timer expires, pg_stat_monitor moves to bucket 2.
# 5. pg_stat_monitor moves only the pending QueryID XYZ to bucket 2.
# 6. Remove QueryID XYZ from bucket 1 (all stats, calls=4, etc..).
#
# Since only the pending QueryID XYZ was moved to bucket 2, all
# previous statistics for the same QueryID would have been incorrectly
# removed from the previous bucket (1).
#
# PG-291 fixes the problem, by keeping finished queries in the previous bucket
# and moving only the pending query to the new bucket.
#
# This test works as follows:
# 1. Set pg_stat_monitor bucket time to 14 seconds.
# 2. Start PostgreSQL, reset pg_stat_monitor view.
# 3. Execute "SELECT pg_sleep(5)" three times in a row.
# It's expected that the first two queries execute and finish in the
# first bucket, then the last query starts in the same bucket but is finished
# in the next bucket.
# We expect a total query count of 3 for this query, and it must exist in two
# buckets.
use strict;
use warnings;
use PostgresNode;
use Test::More;
# Create new PostgreSQL node and do initdb
my $node = PostgresNode->get_new_node('test');
my $pgdata = $node->data_dir;
$node->dump_info;
$node->init;
$node->append_conf('postgresql.conf', "shared_preload_libraries = 'pg_stat_monitor'");
# Set bucket duration to 14 seconds so tests don't take too long.
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_bucket_time = 14");
# Start server
my $rt_value = $node->start;
ok($rt_value == 1, "Start Server");
my ($cmdret, $stdout, $stderr) = $node->psql('postgres', 'CREATE EXTENSION pg_stat_monitor;', extra_params => ['-a']);
ok($cmdret == 0, "Create PGSM Extension");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
$node->psql('postgres', "SELECT pg_sleep(5)");
$node->psql('postgres', "SELECT pg_sleep(5)");
$node->psql('postgres', "SELECT pg_sleep(5)");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT bucket, queryid, calls, query FROM pg_stat_monitor;', extra_params => ['-a', '-Pformat=aligned']);
ok($cmdret == 0, "Query pg_stat_monitor view");
sub trim { my $s = shift; $s =~ s/^\s+|\s+$//g; return $s };
my $last_bucket = "";
my $bucket_cnt = 0;
my $calls = 0;
my @lines = split /\n/, $stdout;
foreach my $line(@lines) {
my @tokens = split /\|/, $line;
my $bucket = trim($tokens[0]);
my $queryid = trim($tokens[1]);
my $ncalls = trim($tokens[2]);
my $query = trim($tokens[3]);
if ($query =~ "SELECT pg_sleep") {
$calls += $ncalls;
if ($bucket_cnt == 0) {
$bucket_cnt += 1;
$last_bucket = $bucket;
} elsif ($bucket != $last_bucket) {
$bucket_cnt += 1;
$last_bucket = $bucket;
}
}
}
ok($calls == 3, "Check total query count is correct");
ok($bucket_cnt == 2, "Check total bucket count is correct");
# Stop the server
$node->stop;
# Done testing for this testcase file.
done_testing();

251
t/024_check_timings.pl Normal file
View File

@ -0,0 +1,251 @@
#!/usr/bin/perl
use strict;
use warnings;
use String::Util qw(trim);
use File::Basename;
use File::Compare;
use PostgresNode;
use Test::More;
# Expected folder where expected output will be present
my $expected_folder = "t/expected";
# Results/out folder where generated results files will be placed
my $results_folder = "t/results";
# Check if results folder exists or not, create if it doesn't
unless (-d $results_folder)
{
mkdir $results_folder or die "Can't create folder $results_folder: $!\n";;
}
# Check if expected folder exists or not, bail out if it doesn't
unless (-d $expected_folder)
{
BAIL_OUT "Expected files folder $expected_folder doesn't exist: \n";;
}
# Get filename of the this perl file
my $perlfilename = basename($0);
#Remove .pl from filename and store in a variable
$perlfilename =~ s/\.[^.]+$//;
my $filename_without_extension = $perlfilename;
# Create expected filename with path
my $expected_filename = "${filename_without_extension}.out";
my $expected_filename_with_path = "${expected_folder}/${expected_filename}" ;
# Create results filename with path
my $out_filename = "${filename_without_extension}.out";
my $out_filename_with_path = "${results_folder}/${out_filename}" ;
my $dynamic_out_filename_with_path = "${results_folder}/${out_filename}.dynamic" ;
# Delete already existing result out file, if it exists.
if ( -f $out_filename_with_path)
{
unlink($out_filename_with_path) or die "Can't delete already existing $out_filename_with_path: $!\n";
}
# Create new PostgreSQL node and do initdb
my $node = PostgresNode->get_new_node('test');
my $pgdata = $node->data_dir;
$node->dump_info;
$node->init;
# Update postgresql.conf to include/load pg_stat_monitor library
$node->append_conf('postgresql.conf', "shared_preload_libraries = 'pg_stat_statements,pg_stat_monitor'");
# Set bucket duration to 3600 seconds so bucket doesn't change.
$node->append_conf('postgresql.conf', "pg_stat_statements.track_utility = off");
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_bucket_time = 1800");
$node->append_conf('postgresql.conf', "track_io_timing = on");
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_track_utility = no");
# Start server
my $rt_value = $node->start;
ok($rt_value == 1, "Start Server");
# Create extension and change out file permissions
my ($cmdret, $stdout, $stderr) = $node->psql('postgres', 'CREATE EXTENSION pg_stat_statements;', extra_params => ['-a']);
ok($cmdret == 0, "Create PGSS Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
chmod(0640 , $out_filename_with_path)
or die("unable to set permissions for $out_filename_with_path");
# Create extension and change out file permissions
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'CREATE EXTENSION pg_stat_monitor;', extra_params => ['-a']);
ok($cmdret == 0, "Create PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
chmod(0640 , $out_filename_with_path)
or die("unable to set permissions for $out_filename_with_path");
# Run required commands/queries and dump output to out file.
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
# Run required commands/queries and dump output to out file.
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_statements_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSS Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
# Run 'SELECT * from pg_stat_monitor_settings;' two times and dump output to out file
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT * from pg_stat_monitor_settings;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
# Create example database and run pgbench init
# ($cmdret, $stdout, $stderr) = $node->psql('postgres', 'CREATE database example;', extra_params => ['-a']);
# ok($cmdret == 0, "Create Database example");
# TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
my $port = $node->port;
my $out = system ("pgbench -i -s 100 -p $port postgres");
ok($cmdret == 0, "Perform pgbench init");
$out = system ("pgbench -c 10 -j 2 -t 10000 -p $port postgres");
ok($cmdret == 0, "Run pgbench");
($cmdret, $stdout, $stderr) = $node->psql('postgres', "Delete from pgbench_accounts where aid % 9 = 1;", extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
($cmdret, $stdout, $stderr) = $node->psql('postgres', "Delete from pgbench_accounts where aid % 10 = 1;", extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
($cmdret, $stdout, $stderr) = $node->psql('postgres', "Delete from pgbench_accounts where aid % 5 = 1;", extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
($cmdret, $stdout, $stderr) = $node->psql('postgres', "Delete from pgbench_accounts where aid % 3 = 1;", extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
($cmdret, $stdout, $stderr) = $node->psql('postgres', "Delete from pgbench_accounts where aid % 2 = 1;", extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select substr(query,0,130) as query, calls, rows, total_exec_time,min_exec_time,max_exec_time,mean_exec_time,stddev_exec_time from pg_stat_statements where query Like \'%bench%\' order by query,calls desc;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($dynamic_out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select substr(query,0,130) as query, calls, rows_retrieved, total_exec_time, min_exec_time, max_exec_time, mean_exec_time,stddev_exec_time, cpu_user_time, cpu_sys_time from pg_stat_monitor where query Like \'%bench%\' order by query,calls desc;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($dynamic_out_filename_with_path, $stdout . "\n");
TestLib::append_to_file($dynamic_out_filename_with_path, "\n\n");
# Compare values for query 'Delete from pgbench_accounts where $1 = $2'
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select PGSM.total_exec_time != 0 from pg_stat_monitor as PGSM where PGSM.query Like \'%Delete from pgbench_accounts%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Check: total_exec_time should not be 0.");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select PGSM.min_exec_time != 0 from pg_stat_monitor as PGSM where PGSM.query Like \'%Delete from pgbench_accounts%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Check: min_exec_time should not be 0.");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select PGSM.max_exec_time != 0 from pg_stat_monitor as PGSM where PGSM.query Like \'%Delete from pgbench_accounts%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Check: max_exec_time should not be 0.");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select PGSM.mean_exec_time != 0 from pg_stat_monitor as PGSM where PGSM.query Like \'%Delete from pgbench_accounts%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Check: mean_exec_time should not be 0.");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select PGSM.stddev_exec_time != 0 from pg_stat_monitor as PGSM where PGSM.query Like \'%Delete from pgbench_accounts%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Check: stddev_exec_time should not be 0.");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select PGSM.cpu_user_time != 0 from pg_stat_monitor as PGSM where PGSM.query Like \'%Delete from pgbench_accounts%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Check: cpu_user_time should not be 0.");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select PGSM.cpu_sys_time != 0 from pg_stat_monitor as PGSM where PGSM.query Like \'%Delete from pgbench_accounts%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Check: cpu_sys_time should not be 0.");
# Compare values for query 'INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES ($1, $2, $3, $4, CURRENT_TIMESTAMP)'
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select PGSM.total_exec_time != 0 from pg_stat_monitor as PGSM where PGSM.query Like \'%INSERT INTO pgbench_history%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Check: total_exec_time should not be 0.");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select PGSM.min_exec_time != 0 from pg_stat_monitor as PGSM where PGSM.query Like \'%INSERT INTO pgbench_history%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Check: min_exec_time should not be 0.");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select PGSM.max_exec_time != 0 from pg_stat_monitor as PGSM where PGSM.query Like \'%INSERT INTO pgbench_history%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Check: max_exec_time should not be 0.");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select PGSM.mean_exec_time != 0 from pg_stat_monitor as PGSM where PGSM.query Like \'%INSERT INTO pgbench_history%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Check: mean_exec_time should not be 0.");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select PGSM.stddev_exec_time != 0 from pg_stat_monitor as PGSM where PGSM.query Like \'%INSERT INTO pgbench_history%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Check: stddev_exec_time should not be 0.");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select PGSM.cpu_user_time != 0 from pg_stat_monitor as PGSM where PGSM.query Like \'%INSERT INTO pgbench_history%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Check: cpu_user_time should not be 0.");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select PGSM.cpu_sys_time != 0 from pg_stat_monitor as PGSM where PGSM.query Like \'%INSERT INTO pgbench_history%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Check: cpu_sys_time should not be 0.");
# Compare values for query 'SELECT abalance FROM pgbench_accounts WHERE aid = $1'
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select PGSM.total_exec_time != 0 from pg_stat_monitor as PGSM where PGSM.query Like \'%SELECT abalance FROM pgbench_accounts%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Check: total_exec_time should not be 0.");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select PGSM.min_exec_time != 0 from pg_stat_monitor as PGSM where PGSM.query Like \'%SELECT abalance FROM pgbench_accounts%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Check: min_exec_time should not be 0.");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select PGSM.max_exec_time != 0 from pg_stat_monitor as PGSM where PGSM.query Like \'%SELECT abalance FROM pgbench_accounts%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Check: max_exec_time should not be 0.");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select PGSM.mean_exec_time != 0 from pg_stat_monitor as PGSM where PGSM.query Like \'%SELECT abalance FROM pgbench_accounts%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Check: mean_exec_time should not be 0.");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select PGSM.stddev_exec_time != 0 from pg_stat_monitor as PGSM where PGSM.query Like \'%SELECT abalance FROM pgbench_accounts%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Check: stddev_exec_time should not be 0.");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select PGSM.cpu_user_time != 0 from pg_stat_monitor as PGSM where PGSM.query Like \'%SELECT abalance FROM pgbench_accounts%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Check: cpu_user_time should not be 0.");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select PGSM.cpu_sys_time != 0 from pg_stat_monitor as PGSM where PGSM.query Like \'%SELECT abalance FROM pgbench_accounts%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Check: cpu_sys_time should not be 0.");
# Compare values for query 'UPDATE pgbench_accounts SET abalance = abalance + $1 WHERE aid = $2'
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select PGSM.total_exec_time != 0 from pg_stat_monitor as PGSM where PGSM.query Like \'%UPDATE pgbench_accounts SET abalance%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Check: total_exec_time should not be 0.");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select PGSM.min_exec_time != 0 from pg_stat_monitor as PGSM where PGSM.query Like \'%UPDATE pgbench_accounts SET abalance%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Check: min_exec_time should not be 0.");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select PGSM.max_exec_time != 0 from pg_stat_monitor as PGSM where PGSM.query Like \'%UPDATE pgbench_accounts SET abalance%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Check: max_exec_time should not be 0.");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select PGSM.mean_exec_time != 0 from pg_stat_monitor as PGSM where PGSM.query Like \'%UPDATE pgbench_accounts SET abalance%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Check: mean_exec_time should not be 0.");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select PGSM.stddev_exec_time != 0 from pg_stat_monitor as PGSM where PGSM.query Like \'%UPDATE pgbench_accounts SET abalance%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Check: stddev_exec_time should not be 0.");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select PGSM.cpu_user_time != 0 from pg_stat_monitor as PGSM where PGSM.query Like \'%UPDATE pgbench_accounts SET abalance%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Check: cpu_user_time should not be 0.");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select PGSM.cpu_sys_time != 0 from pg_stat_monitor as PGSM where PGSM.query Like \'%UPDATE pgbench_accounts SET abalance%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Check: cpu_sys_time should not be 0.");
# Drop extension
$stdout = $node->safe_psql('postgres', 'Drop extension pg_stat_monitor;', extra_params => ['-a']);
ok($cmdret == 0, "Drop PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
# Stop the server
$node->stop;
# Done testing for this testcase file.
done_testing();

342
t/025_compare_pgss.pl Normal file
View File

@ -0,0 +1,342 @@
#!/usr/bin/perl
use strict;
use warnings;
use String::Util qw(trim);
use File::Basename;
use File::Compare;
use PostgresNode;
use Test::More;
# Expected folder where expected output will be present
my $expected_folder = "t/expected";
# Results/out folder where generated results files will be placed
my $results_folder = "t/results";
# Check if results folder exists or not, create if it doesn't
unless (-d $results_folder)
{
mkdir $results_folder or die "Can't create folder $results_folder: $!\n";;
}
# Check if expected folder exists or not, bail out if it doesn't
unless (-d $expected_folder)
{
BAIL_OUT "Expected files folder $expected_folder doesn't exist: \n";;
}
# Get filename of the this perl file
my $perlfilename = basename($0);
#Remove .pl from filename and store in a variable
$perlfilename =~ s/\.[^.]+$//;
my $filename_without_extension = $perlfilename;
# Create expected filename with path
my $expected_filename = "${filename_without_extension}.out";
my $expected_filename_with_path = "${expected_folder}/${expected_filename}" ;
# Create results filename with path
my $out_filename = "${filename_without_extension}.out";
my $out_filename_with_path = "${results_folder}/${out_filename}" ;
my $dynamic_out_filename_with_path = "${results_folder}/${out_filename}.dynamic" ;
# Delete already existing result out file, if it exists.
if ( -f $out_filename_with_path)
{
unlink($out_filename_with_path) or die "Can't delete already existing $out_filename_with_path: $!\n";
}
# Create new PostgreSQL node and do initdb
my $node = PostgresNode->get_new_node('test');
my $pgdata = $node->data_dir;
$node->dump_info;
$node->init;
# Update postgresql.conf to include/load pg_stat_monitor library
$node->append_conf('postgresql.conf', "shared_preload_libraries = 'pg_stat_statements,pg_stat_monitor'");
# Set bucket duration to 3600 seconds so bucket doesn't change.
$node->append_conf('postgresql.conf', "pg_stat_statements.track_utility = off");
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_bucket_time = 1800");
$node->append_conf('postgresql.conf', "track_io_timing = on");
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_track_utility = no");
# Start server
my $rt_value = $node->start;
ok($rt_value == 1, "Start Server");
# Create extension and change out file permissions
my ($cmdret, $stdout, $stderr) = $node->psql('postgres', 'CREATE EXTENSION pg_stat_statements;', extra_params => ['-a']);
ok($cmdret == 0, "Create PGSS Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
chmod(0640 , $out_filename_with_path)
or die("unable to set permissions for $out_filename_with_path");
# Create extension and change out file permissions
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'CREATE EXTENSION pg_stat_monitor;', extra_params => ['-a']);
ok($cmdret == 0, "Create PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
chmod(0640 , $out_filename_with_path)
or die("unable to set permissions for $out_filename_with_path");
# Run required commands/queries and dump output to out file.
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
# Run required commands/queries and dump output to out file.
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_statements_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSS Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
# Run 'SELECT * from pg_stat_monitor_settings;' two times and dump output to out file
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT * from pg_stat_monitor_settings;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
# Create example database and run pgbench init
# ($cmdret, $stdout, $stderr) = $node->psql('postgres', 'CREATE database example;', extra_params => ['-a']);
# ok($cmdret == 0, "Create Database example");
# TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
my $port = $node->port;
my $out = system ("pgbench -i -s 100 -p $port postgres");
ok($cmdret == 0, "Perform pgbench init");
$out = system ("pgbench -c 10 -j 2 -t 10000 -p $port postgres");
ok($cmdret == 0, "Run pgbench");
($cmdret, $stdout, $stderr) = $node->psql('postgres', "Delete from pgbench_accounts where aid % 9 = 1;", extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
($cmdret, $stdout, $stderr) = $node->psql('postgres', "Delete from pgbench_accounts where aid % 10 = 1;", extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
($cmdret, $stdout, $stderr) = $node->psql('postgres', "Delete from pgbench_accounts where aid % 5 = 1;", extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
($cmdret, $stdout, $stderr) = $node->psql('postgres', "Delete from pgbench_accounts where aid % 3 = 1;", extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
($cmdret, $stdout, $stderr) = $node->psql('postgres', "Delete from pgbench_accounts where aid % 2 = 1;", extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select queryid, substr(query,0,130) as query, calls, rows, total_exec_time,min_exec_time,max_exec_time,mean_exec_time from pg_stat_statements where query Like \'%bench%\' order by query,calls desc;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($dynamic_out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select client_ip, bucket, queryid, substr(query,0,130) as query, cmd_type_text, calls, rows_retrieved, total_exec_time, min_exec_time, max_exec_time, mean_exec_time, cpu_user_time, cpu_sys_time from pg_stat_monitor where query Like \'%bench%\' order by query,calls desc;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($dynamic_out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select substr(query,0,30) as query,calls,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,wal_records,wal_fpi,wal_bytes from pg_stat_statements where query Like \'%bench%\' order by query,calls ;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($dynamic_out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select substr(query,0,30) as query,calls,rows_retrieved as 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,wal_records,wal_fpi,wal_bytes, cmd_type_text from pg_stat_monitor where query Like \'%bench%\' order by query,calls ;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($dynamic_out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select substr(query,0,30),calls, rows, ROUND(total_exec_time::numeric,4) as total_exec_time, ROUND(min_exec_time::numeric,4) as min_exec_time, ROUND(max_exec_time::numeric,4) as max_exec_time, ROUND(mean_exec_time::numeric,4) as mean_exec_time, ROUND(stddev_exec_time::numeric,4) as stddev_exec_time, ROUND(blk_read_time::numeric,4) as blk_read_time, ROUND(blk_write_time::numeric,4) as blk_write_time, wal_records, wal_fpi, wal_bytes from pg_stat_statements where query Like \'%bench%\' order by query,calls desc;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($dynamic_out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select substr(query,0,30), calls, rows_retrieved as rows, total_exec_time, min_exec_time, max_exec_time, mean_exec_time, stddev_exec_time, ROUND(blk_read_time::numeric,4) as blk_read_time, ROUND(blk_write_time::numeric,4) as blk_write_time, wal_records, wal_fpi, wal_bytes from pg_stat_monitor where query Like \'%bench%\' order by query,calls desc;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($dynamic_out_filename_with_path, $stdout . "\n");
TestLib::append_to_file($dynamic_out_filename_with_path, "\n\n");
# Compare values for query 'Delete from pgbench_accounts where $1 = $2'
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select PGSM.calls = PGSS.calls from pg_stat_monitor as PGSM INNER JOIN pg_stat_statements as PGSS ON PGSS.query = PGSM.query where PGSM.query Like \'%Delete from pgbench_accounts%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Compare: calls are equal.");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select PGSM.rows_retrieved = PGSS.rows from pg_stat_monitor as PGSM INNER JOIN pg_stat_statements as PGSS ON PGSS.query = PGSM.query where PGSM.query Like \'%Delete from pgbench_accounts%\'; ', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Compare: rows are equal).");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select PGSM.total_exec_time = ROUND(PGSS.total_exec_time::numeric,4) from pg_stat_monitor as PGSM INNER JOIN pg_stat_statements as PGSS ON PGSS.query = PGSM.query where PGSM.query Like \'%Delete from pgbench_accounts%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Compare: total_exec_time is equal.");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select PGSM.min_exec_time = ROUND(PGSS.min_exec_time::numeric,4) from pg_stat_monitor as PGSM INNER JOIN pg_stat_statements as PGSS ON PGSS.query = PGSM.query where PGSM.query Like \'%Delete from pgbench_accounts%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Compare: min_exec_time is equal.");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select PGSM.max_exec_time = ROUND(PGSS.max_exec_time::numeric,4) from pg_stat_monitor as PGSM INNER JOIN pg_stat_statements as PGSS ON PGSS.query = PGSM.query where PGSM.query Like \'%Delete from pgbench_accounts%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Compare: max_exec_time is equal.");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select PGSM.mean_exec_time = ROUND(PGSS.mean_exec_time::numeric,4) from pg_stat_monitor as PGSM INNER JOIN pg_stat_statements as PGSS ON PGSS.query = PGSM.query where PGSM.query Like \'%Delete from pgbench_accounts%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Compare: mean_exec_time is equal.");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select PGSM.stddev_exec_time = ROUND(PGSS.stddev_exec_time::numeric,4) from pg_stat_monitor as PGSM INNER JOIN pg_stat_statements as PGSS ON PGSS.query = PGSM.query where PGSM.query Like \'%Delete from pgbench_accounts%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Compare: stddev_exec_time is equal.");
#($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select ROUND(PGSM.blk_read_time::numeric,4) = ROUND(PGSS.blk_read_time::numeric,4) from pg_stat_monitor as PGSM INNER JOIN pg_stat_statements as PGSS ON PGSS.query = PGSM.query where PGSM.query Like \'%Delete from pgbench_accounts%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
#trim($stdout);
#is($stdout,'t',"Compare: blk_read_time is equal.");
#($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select ROUND(PGSM.blk_write_time::numeric,4) = ROUND(PGSS.blk_write_time::numeric,4) from pg_stat_monitor as PGSM INNER JOIN pg_stat_statements as PGSS ON PGSS.query = PGSM.query where PGSM.query Like \'%Delete from pgbench_accounts%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
#trim($stdout);
#is($stdout,'t',"Compare: blk_write_time is equal.");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select PGSM.wal_records = PGSS.wal_records from pg_stat_monitor as PGSM INNER JOIN pg_stat_statements as PGSS ON PGSS.query = PGSM.query where PGSM.query Like \'%Delete from pgbench_accounts%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Compare: wal_records are equal.");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select PGSM.wal_fpi = PGSS.wal_fpi from pg_stat_monitor as PGSM INNER JOIN pg_stat_statements as PGSS ON PGSS.query = PGSM.query where PGSM.query Like \'%Delete from pgbench_accounts%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Compare: wal_fpi is equal.");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select PGSM.wal_bytes = PGSS.wal_bytes from pg_stat_monitor as PGSM INNER JOIN pg_stat_statements as PGSS ON PGSS.query = PGSM.query where PGSM.query Like \'%Delete from pgbench_accounts%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Compare: wal_bytes are equal.");
# Compare values for query 'INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES ($1, $2, $3, $4, CURRENT_TIMESTAMP)'
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select PGSM.calls = PGSS.calls from pg_stat_monitor as PGSM INNER JOIN pg_stat_statements as PGSS ON PGSS.query = PGSM.query where PGSM.query Like \'%INSERT INTO pgbench_history%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Compare: calls are equal.");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select PGSM.rows_retrieved = PGSS.rows from pg_stat_monitor as PGSM INNER JOIN pg_stat_statements as PGSS ON PGSS.query = PGSM.query where PGSM.query Like \'%INSERT INTO pgbench_history%\'; ', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Compare: rows are equal).");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select PGSM.total_exec_time = ROUND(PGSS.total_exec_time::numeric,4) from pg_stat_monitor as PGSM INNER JOIN pg_stat_statements as PGSS ON PGSS.query = PGSM.query where PGSM.query Like \'%INSERT INTO pgbench_history%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Compare: total_exec_time is equal.");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select PGSM.min_exec_time = ROUND(PGSS.min_exec_time::numeric,4) from pg_stat_monitor as PGSM INNER JOIN pg_stat_statements as PGSS ON PGSS.query = PGSM.query where PGSM.query Like \'%INSERT INTO pgbench_history%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Compare: min_exec_time is equal.");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select PGSM.max_exec_time = ROUND(PGSS.max_exec_time::numeric,4) from pg_stat_monitor as PGSM INNER JOIN pg_stat_statements as PGSS ON PGSS.query = PGSM.query where PGSM.query Like \'%INSERT INTO pgbench_history%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Compare: max_exec_time is equal.");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select PGSM.mean_exec_time = ROUND(PGSS.mean_exec_time::numeric,4) from pg_stat_monitor as PGSM INNER JOIN pg_stat_statements as PGSS ON PGSS.query = PGSM.query where PGSM.query Like \'%INSERT INTO pgbench_history%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Compare: mean_exec_time is equal.");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select PGSM.stddev_exec_time = ROUND(PGSS.stddev_exec_time::numeric,4) from pg_stat_monitor as PGSM INNER JOIN pg_stat_statements as PGSS ON PGSS.query = PGSM.query where PGSM.query Like \'%INSERT INTO pgbench_history%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Compare: stddev_exec_time is equal.");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select ROUND(PGSM.blk_read_time::numeric,4) = ROUND(PGSS.blk_read_time::numeric,4) from pg_stat_monitor as PGSM INNER JOIN pg_stat_statements as PGSS ON PGSS.query = PGSM.query where PGSM.query Like \'%INSERT INTO pgbench_history%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Compare: blk_read_time is equal.");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select ROUND(PGSM.blk_write_time::numeric,4) = ROUND(PGSS.blk_write_time::numeric,4) from pg_stat_monitor as PGSM INNER JOIN pg_stat_statements as PGSS ON PGSS.query = PGSM.query where PGSM.query Like \'%INSERT INTO pgbench_history%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Compare: blk_write_time is equal.");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select PGSM.wal_records = PGSS.wal_records from pg_stat_monitor as PGSM INNER JOIN pg_stat_statements as PGSS ON PGSS.query = PGSM.query where PGSM.query Like \'%INSERT INTO pgbench_history%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Compare: wal_records are equal.");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select PGSM.wal_fpi = PGSS.wal_fpi from pg_stat_monitor as PGSM INNER JOIN pg_stat_statements as PGSS ON PGSS.query = PGSM.query where PGSM.query Like \'%INSERT INTO pgbench_history%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Compare: wal_fpi is equal.");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select PGSM.wal_bytes = PGSS.wal_bytes from pg_stat_monitor as PGSM INNER JOIN pg_stat_statements as PGSS ON PGSS.query = PGSM.query where PGSM.query Like \'%INSERT INTO pgbench_history%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Compare: wal_bytes are equal.");
# Compare values for query 'SELECT abalance FROM pgbench_accounts WHERE aid = $1'
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select PGSM.calls = PGSS.calls from pg_stat_monitor as PGSM INNER JOIN pg_stat_statements as PGSS ON PGSS.query = PGSM.query where PGSM.query Like \'%SELECT abalance FROM pgbench_accounts%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Compare: calls are equal.");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select PGSM.rows_retrieved = PGSS.rows from pg_stat_monitor as PGSM INNER JOIN pg_stat_statements as PGSS ON PGSS.query = PGSM.query where PGSM.query Like \'%SELECT abalance FROM pgbench_accounts%\'; ', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Compare: rows are equal).");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select PGSM.total_exec_time = ROUND(PGSS.total_exec_time::numeric,4) from pg_stat_monitor as PGSM INNER JOIN pg_stat_statements as PGSS ON PGSS.query = PGSM.query where PGSM.query Like \'%SELECT abalance FROM pgbench_accounts%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Compare: total_exec_time is equal.");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select PGSM.min_exec_time = ROUND(PGSS.min_exec_time::numeric,4) from pg_stat_monitor as PGSM INNER JOIN pg_stat_statements as PGSS ON PGSS.query = PGSM.query where PGSM.query Like \'%SELECT abalance FROM pgbench_accounts%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Compare: min_exec_time is equal.");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select PGSM.max_exec_time = ROUND(PGSS.max_exec_time::numeric,4) from pg_stat_monitor as PGSM INNER JOIN pg_stat_statements as PGSS ON PGSS.query = PGSM.query where PGSM.query Like \'%SELECT abalance FROM pgbench_accounts%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Compare: max_exec_time is equal.");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select PGSM.mean_exec_time = ROUND(PGSS.mean_exec_time::numeric,4) from pg_stat_monitor as PGSM INNER JOIN pg_stat_statements as PGSS ON PGSS.query = PGSM.query where PGSM.query Like \'%SELECT abalance FROM pgbench_accounts%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Compare: mean_exec_time is equal.");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select PGSM.stddev_exec_time = ROUND(PGSS.stddev_exec_time::numeric,4) from pg_stat_monitor as PGSM INNER JOIN pg_stat_statements as PGSS ON PGSS.query = PGSM.query where PGSM.query Like \'%SELECT abalance FROM pgbench_accounts%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Compare: stddev_exec_time is equal.");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select ROUND(PGSM.blk_read_time::numeric,4) = ROUND(PGSS.blk_read_time::numeric,4) from pg_stat_monitor as PGSM INNER JOIN pg_stat_statements as PGSS ON PGSS.query = PGSM.query where PGSM.query Like \'%SELECT abalance FROM pgbench_accounts%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Compare: blk_read_time is equal.");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select ROUND(PGSM.blk_write_time::numeric,4) = ROUND(PGSS.blk_write_time::numeric,4) from pg_stat_monitor as PGSM INNER JOIN pg_stat_statements as PGSS ON PGSS.query = PGSM.query where PGSM.query Like \'%SELECT abalance FROM pgbench_accounts%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Compare: blk_write_time is equal.");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select PGSM.wal_records = PGSS.wal_records from pg_stat_monitor as PGSM INNER JOIN pg_stat_statements as PGSS ON PGSS.query = PGSM.query where PGSM.query Like \'%SELECT abalance FROM pgbench_accounts%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Compare: wal_records are equal.");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select PGSM.wal_fpi = PGSS.wal_fpi from pg_stat_monitor as PGSM INNER JOIN pg_stat_statements as PGSS ON PGSS.query = PGSM.query where PGSM.query Like \'%SELECT abalance FROM pgbench_accounts%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Compare: wal_fpi is equal.");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select PGSM.wal_bytes = PGSS.wal_bytes from pg_stat_monitor as PGSM INNER JOIN pg_stat_statements as PGSS ON PGSS.query = PGSM.query where PGSM.query Like \'%SELECT abalance FROM pgbench_accounts%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Compare: wal_bytes are equal.");
# Compare values for query 'UPDATE pgbench_accounts SET abalance = abalance + $1 WHERE aid = $2'
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select PGSM.calls = PGSS.calls from pg_stat_monitor as PGSM INNER JOIN pg_stat_statements as PGSS ON PGSS.query = PGSM.query where PGSM.query Like \'%UPDATE pgbench_accounts%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Compare: calls are equal.");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select PGSM.rows_retrieved = PGSS.rows from pg_stat_monitor as PGSM INNER JOIN pg_stat_statements as PGSS ON PGSS.query = PGSM.query where PGSM.query Like \'%UPDATE pgbench_accounts%\'; ', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Compare: rows are equal).");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select PGSM.total_exec_time = ROUND(PGSS.total_exec_time::numeric,4) from pg_stat_monitor as PGSM INNER JOIN pg_stat_statements as PGSS ON PGSS.query = PGSM.query where PGSM.query Like \'%UPDATE pgbench_accounts%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Compare: total_exec_time is equal.");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select PGSM.min_exec_time = ROUND(PGSS.min_exec_time::numeric,4) from pg_stat_monitor as PGSM INNER JOIN pg_stat_statements as PGSS ON PGSS.query = PGSM.query where PGSM.query Like \'%UPDATE pgbench_accounts%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Compare: min_exec_time is equal.");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select PGSM.max_exec_time = ROUND(PGSS.max_exec_time::numeric,4) from pg_stat_monitor as PGSM INNER JOIN pg_stat_statements as PGSS ON PGSS.query = PGSM.query where PGSM.query Like \'%UPDATE pgbench_accounts%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Compare: max_exec_time is equal.");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select PGSM.mean_exec_time = ROUND(PGSS.mean_exec_time::numeric,4) from pg_stat_monitor as PGSM INNER JOIN pg_stat_statements as PGSS ON PGSS.query = PGSM.query where PGSM.query Like \'%UPDATE pgbench_accounts%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Compare: mean_exec_time is equal.");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select PGSM.stddev_exec_time = ROUND(PGSS.stddev_exec_time::numeric,4) from pg_stat_monitor as PGSM INNER JOIN pg_stat_statements as PGSS ON PGSS.query = PGSM.query where PGSM.query Like \'%UPDATE pgbench_accounts%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Compare: stddev_exec_time is equal.");
#($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select ROUND(PGSM.blk_read_time::numeric,4) = ROUND(PGSS.blk_read_time::numeric,4) from pg_stat_monitor as PGSM INNER JOIN pg_stat_statements as PGSS ON PGSS.query = PGSM.query where PGSM.query Like \'%UPDATE pgbench_accounts%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
#trim($stdout);
#is($stdout,'t',"Compare: blk_read_time is equal.");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select ROUND(PGSM.blk_write_time::numeric,4) = ROUND(PGSS.blk_write_time::numeric,4) from pg_stat_monitor as PGSM INNER JOIN pg_stat_statements as PGSS ON PGSS.query = PGSM.query where PGSM.query Like \'%UPDATE pgbench_accounts%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Compare: blk_write_time is equal.");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select PGSM.wal_records = PGSS.wal_records from pg_stat_monitor as PGSM INNER JOIN pg_stat_statements as PGSS ON PGSS.query = PGSM.query where PGSM.query Like \'%UPDATE pgbench_accounts%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Compare: wal_records are equal.");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select PGSM.wal_fpi = PGSS.wal_fpi from pg_stat_monitor as PGSM INNER JOIN pg_stat_statements as PGSS ON PGSS.query = PGSM.query where PGSM.query Like \'%UPDATE pgbench_accounts%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Compare: wal_fpi is equal.");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select PGSM.wal_bytes = PGSS.wal_bytes from pg_stat_monitor as PGSM INNER JOIN pg_stat_statements as PGSS ON PGSS.query = PGSM.query where PGSM.query Like \'%UPDATE pgbench_accounts%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Compare: wal_bytes are equal.");
# Drop extension
$stdout = $node->safe_psql('postgres', 'Drop extension pg_stat_monitor;', extra_params => ['-a']);
ok($cmdret == 0, "Drop PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
# Stop the server
$node->stop;
# Done testing for this testcase file.
done_testing();

209
t/026_shared_blocks.pl Normal file
View File

@ -0,0 +1,209 @@
#!/usr/bin/perl
use strict;
use warnings;
use String::Util qw(trim);
use File::Basename;
use File::Compare;
use PostgresNode;
use Test::More;
# Expected folder where expected output will be present
my $expected_folder = "t/expected";
# Results/out folder where generated results files will be placed
my $results_folder = "t/results";
# Check if results folder exists or not, create if it doesn't
unless (-d $results_folder)
{
mkdir $results_folder or die "Can't create folder $results_folder: $!\n";;
}
# Check if expected folder exists or not, bail out if it doesn't
unless (-d $expected_folder)
{
BAIL_OUT "Expected files folder $expected_folder doesn't exist: \n";;
}
# Get filename of the this perl file
my $perlfilename = basename($0);
#Remove .pl from filename and store in a variable
$perlfilename =~ s/\.[^.]+$//;
my $filename_without_extension = $perlfilename;
# Create expected filename with path
my $expected_filename = "${filename_without_extension}.out";
my $expected_filename_with_path = "${expected_folder}/${expected_filename}" ;
# Create results filename with path
my $out_filename = "${filename_without_extension}.out";
my $out_filename_with_path = "${results_folder}/${out_filename}" ;
my $dynamic_out_filename_with_path = "${results_folder}/${out_filename}.dynamic" ;
# Delete already existing result out file, if it exists.
if ( -f $out_filename_with_path)
{
unlink($out_filename_with_path) or die "Can't delete already existing $out_filename_with_path: $!\n";
}
# Create new PostgreSQL node and do initdb
my $node = PostgresNode->get_new_node('test');
my $pgdata = $node->data_dir;
$node->dump_info;
$node->init;
# Update postgresql.conf to include/load pg_stat_monitor library
$node->append_conf('postgresql.conf', "shared_preload_libraries = 'pg_stat_statements,pg_stat_monitor'");
# Set bucket duration to 3600 seconds so bucket doesn't change.
$node->append_conf('postgresql.conf', "pg_stat_statements.track_utility = off");
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_bucket_time = 1800");
$node->append_conf('postgresql.conf', "track_io_timing = on");
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_track_utility = no");
# Start server
my $rt_value = $node->start;
ok($rt_value == 1, "Start Server");
# Create extension and change out file permissions
my ($cmdret, $stdout, $stderr) = $node->psql('postgres', 'CREATE EXTENSION pg_stat_statements;', extra_params => ['-a']);
ok($cmdret == 0, "Create PGSS Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
chmod(0640 , $out_filename_with_path)
or die("unable to set permissions for $out_filename_with_path");
# Create extension and change out file permissions
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'CREATE EXTENSION pg_stat_monitor;', extra_params => ['-a']);
ok($cmdret == 0, "Create PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
chmod(0640 , $out_filename_with_path)
or die("unable to set permissions for $out_filename_with_path");
# Run required commands/queries and dump output to out file.
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
# Run required commands/queries and dump output to out file.
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_statements_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSS Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
# Run 'SELECT * from pg_stat_monitor_settings;' two times and dump output to out file
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT * from pg_stat_monitor_settings;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
# Create example database and run pgbench init
# ($cmdret, $stdout, $stderr) = $node->psql('postgres', 'CREATE database example;', extra_params => ['-a']);
# ok($cmdret == 0, "Create Database example");
# TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
my $port = $node->port;
my $out = system ("pgbench -i -s 100 -p $port postgres");
ok($cmdret == 0, "Perform pgbench init");
$out = system ("pgbench -c 10 -j 2 -t 10000 -p $port postgres");
ok($cmdret == 0, "Run pgbench");
($cmdret, $stdout, $stderr) = $node->psql('postgres', "Delete from pgbench_accounts where aid % 9 = 1;", extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
($cmdret, $stdout, $stderr) = $node->psql('postgres', "Delete from pgbench_accounts where aid % 10 = 1;", extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
($cmdret, $stdout, $stderr) = $node->psql('postgres', "Delete from pgbench_accounts where aid % 5 = 1;", extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
($cmdret, $stdout, $stderr) = $node->psql('postgres', "Delete from pgbench_accounts where aid % 3 = 1;", extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
($cmdret, $stdout, $stderr) = $node->psql('postgres', "Delete from pgbench_accounts where aid % 2 = 1;", extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select substr(query,0,130) as query, calls, rows, total_exec_time,min_exec_time,max_exec_time,mean_exec_time,stddev_exec_time from pg_stat_statements where query Like \'%bench%\' order by query,calls desc;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($dynamic_out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select substr(query,0,130) as query, calls, rows_retrieved, total_exec_time, min_exec_time, max_exec_time, mean_exec_time,stddev_exec_time, cpu_user_time, cpu_sys_time from pg_stat_monitor where query Like \'%bench%\' order by query,calls desc;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($dynamic_out_filename_with_path, $stdout . "\n");
TestLib::append_to_file($dynamic_out_filename_with_path, "\n\n");
# Compare values for query 'Delete from pgbench_accounts where $1 = $2'
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select PGSM.shared_blks_hit != 0 from pg_stat_monitor as PGSM where PGSM.query Like \'%Delete from pgbench_accounts%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Check: shared_blks_hit should not be 0.");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select PGSM.shared_blks_read != 0 from pg_stat_monitor as PGSM where PGSM.query Like \'%Delete from pgbench_accounts%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Check: shared_blks_read should not be 0.");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select PGSM.shared_blks_dirtied != 0 from pg_stat_monitor as PGSM where PGSM.query Like \'%Delete from pgbench_accounts%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Check: shared_blks_dirtied should not be 0.");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select PGSM.shared_blks_written != 0 from pg_stat_monitor as PGSM where PGSM.query Like \'%Delete from pgbench_accounts%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Check: shared_blks_written should not be 0.");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select PGSM.blk_read_time != 0 from pg_stat_monitor as PGSM where PGSM.query Like \'%Delete from pgbench_accounts%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Check: blk_read_time should not be 0.");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select PGSM.blk_write_time != 0 from pg_stat_monitor as PGSM where PGSM.query Like \'%Delete from pgbench_accounts%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Check: blk_write_time should not be 0.");
# Compare values for query 'INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES ($1, $2, $3, $4, CURRENT_TIMESTAMP)'
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select PGSM.shared_blks_hit != 0 from pg_stat_monitor as PGSM where PGSM.query Like \'%INSERT INTO pgbench_history%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Check: shared_blks_hit should not be 0.");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select PGSM.shared_blks_read != 0 from pg_stat_monitor as PGSM where PGSM.query Like \'%INSERT INTO pgbench_history%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Check: shared_blks_read should not be 0.");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select PGSM.shared_blks_dirtied != 0 from pg_stat_monitor as PGSM where PGSM.query Like \'%INSERT INTO pgbench_history%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Check: shared_blks_dirtied should not be 0.");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select PGSM.shared_blks_written != 0 from pg_stat_monitor as PGSM where PGSM.query Like \'%INSERT INTO pgbench_history%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Check: shared_blks_written should not be 0.");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select PGSM.blk_read_time != 0 from pg_stat_monitor as PGSM where PGSM.query Like \'%INSERT INTO pgbench_history%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Check: blk_read_time should not be 0.");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select PGSM.blk_write_time != 0 from pg_stat_monitor as PGSM where PGSM.query Like \'%INSERT INTO pgbench_history%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Check: blk_write_time should not be 0.");
# Compare values for query 'UPDATE pgbench_accounts SET abalance = abalance + $1 WHERE aid = $2'
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select PGSM.shared_blks_hit != 0 from pg_stat_monitor as PGSM where PGSM.query Like \'%UPDATE pgbench_accounts SET abalance%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Check: shared_blks_hit should not be 0.");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select PGSM.shared_blks_read != 0 from pg_stat_monitor as PGSM where PGSM.query Like \'%UPDATE pgbench_accounts SET abalance%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Check: shared_blks_read should not be 0.");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select PGSM.shared_blks_dirtied != 0 from pg_stat_monitor as PGSM where PGSM.query Like \'%UPDATE pgbench_accounts SET abalance%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Check: shared_blks_dirtied should not be 0.");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select PGSM.shared_blks_written != 0 from pg_stat_monitor as PGSM where PGSM.query Like \'%UPDATE pgbench_accounts SET abalance%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Check: shared_blks_written should not be 0.");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select PGSM.blk_read_time != 0 from pg_stat_monitor as PGSM where PGSM.query Like \'%UPDATE pgbench_accounts SET abalance%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Check: blk_read_time should not be 0.");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select PGSM.blk_write_time != 0 from pg_stat_monitor as PGSM where PGSM.query Like \'%UPDATE pgbench_accounts SET abalance%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Check: blk_write_time should not be 0.");
# Drop extension
$stdout = $node->safe_psql('postgres', 'Drop extension pg_stat_monitor;', extra_params => ['-a']);
ok($cmdret == 0, "Drop PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
# Stop the server
$node->stop;
# Done testing for this testcase file.
done_testing();

131
t/027_local_blocks.pl Normal file
View File

@ -0,0 +1,131 @@
#!/usr/bin/perl
use strict;
use warnings;
use String::Util qw(trim);
use File::Basename;
use File::Compare;
use PostgresNode;
use Test::More;
# Expected folder where expected output will be present
my $expected_folder = "t/expected";
# Results/out folder where generated results files will be placed
my $results_folder = "t/results";
# Check if results folder exists or not, create if it doesn't
unless (-d $results_folder)
{
mkdir $results_folder or die "Can't create folder $results_folder: $!\n";;
}
# Check if expected folder exists or not, bail out if it doesn't
unless (-d $expected_folder)
{
BAIL_OUT "Expected files folder $expected_folder doesn't exist: \n";;
}
# Get filename of the this perl file
my $perlfilename = basename($0);
#Remove .pl from filename and store in a variable
$perlfilename =~ s/\.[^.]+$//;
my $filename_without_extension = $perlfilename;
# Create expected filename with path
my $expected_filename = "${filename_without_extension}.out";
my $expected_filename_with_path = "${expected_folder}/${expected_filename}" ;
# Create results filename with path
my $out_filename = "${filename_without_extension}.out";
my $out_filename_with_path = "${results_folder}/${out_filename}" ;
my $dynamic_out_filename_with_path = "${results_folder}/${out_filename}.dynamic" ;
# Delete already existing result out file, if it exists.
if ( -f $out_filename_with_path)
{
unlink($out_filename_with_path) or die "Can't delete already existing $out_filename_with_path: $!\n";
}
# Create new PostgreSQL node and do initdb
my $node = PostgresNode->get_new_node('test');
my $pgdata = $node->data_dir;
$node->dump_info;
$node->init;
# Update postgresql.conf to include/load pg_stat_monitor library
$node->append_conf('postgresql.conf', "shared_preload_libraries = 'pg_stat_monitor'");
# Set bucket duration to 3600 seconds so bucket doesn't change.
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_bucket_time = 1800");
$node->append_conf('postgresql.conf', "track_io_timing = on");
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_track_utility = no");
# Start server
my $rt_value = $node->start;
ok($rt_value == 1, "Start Server");
# Create extension and change out file permissions
my ($cmdret, $stdout, $stderr) = $node->psql('postgres', 'CREATE EXTENSION pg_stat_statements;', extra_params => ['-a']);
ok($cmdret == 0, "Create PGSS Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
chmod(0640 , $out_filename_with_path)
or die("unable to set permissions for $out_filename_with_path");
# Create extension and change out file permissions
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'CREATE EXTENSION pg_stat_monitor;', extra_params => ['-a']);
ok($cmdret == 0, "Create PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
chmod(0640 , $out_filename_with_path)
or die("unable to set permissions for $out_filename_with_path");
# Run required commands/queries and dump output to out file.
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
# Run 'SELECT * from pg_stat_monitor_settings;' two times and dump output to out file
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT * from pg_stat_monitor_settings;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', ' CREATE Temporary TABLE t1(a int); INSERT INTO t1 VALUES(generate_series(1,10000)); ANALYZE t1; SELECT * FROM t1;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Create Temporary Table and insert values in a single session.");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select substr(query,0,130) as query, calls, rows_retrieved, cpu_user_time, cpu_sys_time, local_blks_hit, local_blks_read, local_blks_dirtied, local_blks_written, temp_blks_read, temp_blks_written from pg_stat_monitor where query Like \'%t1%\' order by query,calls desc;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($dynamic_out_filename_with_path, $stdout . "\n");
# Compare values for query 'INSERT INTO t1 VALUES(generate_series($1,$2))'
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select PGSM.local_blks_hit != 0 from pg_stat_monitor as PGSM where PGSM.query Like \'%INSERT INTO t1%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Check: shared_blks_hit should not be 0.");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select PGSM.local_blks_read != 0 from pg_stat_monitor as PGSM where PGSM.query Like \'%INSERT INTO t1%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Check: shared_blks_hit should not be 0.");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select PGSM.local_blks_dirtied != 0 from pg_stat_monitor as PGSM where PGSM.query Like \'%INSERT INTO t1%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Check: shared_blks_hit should not be 0.");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select PGSM.local_blks_written != 0 from pg_stat_monitor as PGSM where PGSM.query Like \'%INSERT INTO t1%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Check: shared_blks_hit should not be 0.");
# Compare values for query 'SELECT * FROM t1'
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select PGSM.local_blks_hit != 0 from pg_stat_monitor as PGSM where PGSM.query Like \'%FROM t1%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Check: shared_blks_hit should not be 0.");
# Drop extension
$stdout = $node->safe_psql('postgres', 'Drop extension pg_stat_monitor;', extra_params => ['-a']);
ok($cmdret == 0, "Drop PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
# Stop the server
$node->stop;
# Done testing for this testcase file.
done_testing();

139
t/028_temp_block.pl Normal file
View File

@ -0,0 +1,139 @@
#!/usr/bin/perl
use strict;
use warnings;
use String::Util qw(trim);
use File::Basename;
use File::Compare;
use PostgresNode;
use Test::More;
# Expected folder where expected output will be present
my $expected_folder = "t/expected";
# Results/out folder where generated results files will be placed
my $results_folder = "t/results";
# Check if results folder exists or not, create if it doesn't
unless (-d $results_folder)
{
mkdir $results_folder or die "Can't create folder $results_folder: $!\n";;
}
# Check if expected folder exists or not, bail out if it doesn't
unless (-d $expected_folder)
{
BAIL_OUT "Expected files folder $expected_folder doesn't exist: \n";;
}
# Get filename of the this perl file
my $perlfilename = basename($0);
#Remove .pl from filename and store in a variable
$perlfilename =~ s/\.[^.]+$//;
my $filename_without_extension = $perlfilename;
# Create expected filename with path
my $expected_filename = "${filename_without_extension}.out";
my $expected_filename_with_path = "${expected_folder}/${expected_filename}" ;
# Create results filename with path
my $out_filename = "${filename_without_extension}.out";
my $out_filename_with_path = "${results_folder}/${out_filename}" ;
my $dynamic_out_filename_with_path = "${results_folder}/${out_filename}.dynamic" ;
# Delete already existing result out file, if it exists.
if ( -f $out_filename_with_path)
{
unlink($out_filename_with_path) or die "Can't delete already existing $out_filename_with_path: $!\n";
}
# Create new PostgreSQL node and do initdb
my $node = PostgresNode->get_new_node('test');
my $pgdata = $node->data_dir;
$node->dump_info;
$node->init;
# Update postgresql.conf to include/load pg_stat_monitor library
$node->append_conf('postgresql.conf', "shared_preload_libraries = 'pg_stat_monitor'");
# Set bucket duration to 3600 seconds so bucket doesn't change.
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_bucket_time = 1800");
$node->append_conf('postgresql.conf', "track_io_timing = on");
$node->append_conf('postgresql.conf', "log_temp_files = 0");
$node->append_conf('postgresql.conf', "work_mem = 64kB");
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_track_utility = no");
# Start server
my $rt_value = $node->start;
ok($rt_value == 1, "Start Server");
# Create extension and change out file permissions
my ($cmdret, $stdout, $stderr) = $node->psql('postgres', 'CREATE EXTENSION pg_stat_statements;', extra_params => ['-a']);
ok($cmdret == 0, "Create PGSS Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
chmod(0640 , $out_filename_with_path)
or die("unable to set permissions for $out_filename_with_path");
# Create extension and change out file permissions
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'CREATE EXTENSION pg_stat_monitor;', extra_params => ['-a']);
ok($cmdret == 0, "Create PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
chmod(0640 , $out_filename_with_path)
or die("unable to set permissions for $out_filename_with_path");
# Run required commands/queries and dump output to out file.
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
# Run 'SELECT * from pg_stat_monitor_settings;' two times and dump output to out file
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT * from pg_stat_monitor_settings;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', ' CREATE TABLE t1(a int);', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Create Table t1");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'CREATE INDEX idx_t1_a on t1(a);', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Create index.");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'INSERT INTO t1 VALUES(generate_series(1,1000000));', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Insert 10000 records.");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'ANALYZE t1;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Analyze t1.");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT * FROM t1 AS XX INNER JOIN t1 as TT ON XX.a = TT.a;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Select * from t1.");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select substr(query,0,130) as query, calls, rows_retrieved, cpu_user_time, cpu_sys_time, local_blks_hit, local_blks_read, local_blks_dirtied, local_blks_written, temp_blks_read, temp_blks_written from pg_stat_monitor where query Like \'%t1%\' order by query,calls desc;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($dynamic_out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT temp_files, temp_bytes FROM pg_stat_database db;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($dynamic_out_filename_with_path, $stdout . "\n");
# Compare values for query 'SELECT * FROM t1'
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select PGSM.temp_blks_read != 0 from pg_stat_monitor as PGSM where PGSM.query Like \'%FROM t1%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Check: shared_blks_hit should not be 0.");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select PGSM.temp_blks_written != 0 from pg_stat_monitor as PGSM where PGSM.query Like \'%FROM t1%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Check: temp_blks_read should not be 0.");
# Drop extension
$stdout = $node->safe_psql('postgres', 'Drop extension pg_stat_monitor;', extra_params => ['-a']);
ok($cmdret == 0, "Drop PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
# Stop the server
$node->stop;
# Done testing for this testcase file.
done_testing();

View File

@ -0,0 +1,80 @@
CREATE EXTENSION pg_stat_monitor;
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset
-----------------------
(1 row)
SELECT * from pg_stat_monitor_settings;
name | value | default_value | description | minimum | maximum | options | restart
------------------------------------------+--------+---------------+----------------------------------------------------------------------------------------------------------+---------+------------+----------------+---------
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_query_max_len | 2048 | 2048 | Sets the maximum length of query. | 1024 | 2147483647 | | yes
pg_stat_monitor.pgsm_track_utility | yes | yes | Selects whether utility commands are tracked. | | | yes, no | no
pg_stat_monitor.pgsm_normalized_query | yes | yes | Selects whether save query in normalized format. | | | yes, no | no
pg_stat_monitor.pgsm_max_buckets | 10 | 10 | Sets the maximum number of buckets. | 1 | 10 | | yes
pg_stat_monitor.pgsm_bucket_time | 60 | 60 | Sets the time in seconds per bucket. | 1 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_min | 0 | 0 | Sets the time in millisecond. | 0 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_max | 100000 | 100000 | Sets the time in millisecond. | 10 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_buckets | 10 | 10 | Sets the maximum number of histogram buckets | 2 | 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_overflow_target | 1 | 1 | Sets the overflow target for pg_stat_monitor | 0 | 1 | | yes
pg_stat_monitor.pgsm_enable_query_plan | no | no | Enable/Disable query plan monitoring | | | yes, no | no
pg_stat_monitor.pgsm_track | top | top | Selects which statements are tracked by pg_stat_monitor. | | | none, top, all | no
pg_stat_monitor.pgsm_extract_comments | no | no | Enable/Disable extracting comments from queries. | | | yes, no | no
pg_stat_monitor.pgsm_track_planning | no | no | Selects whether planning statistics are tracked. | | | yes, no | no
(15 rows)
CREATE database example;
select datname, substr(query,0,100) as query, calls from pg_stat_monitor order by datname, query, calls desc Limit 20;
datname | query | calls
---------+-----------------------------------------------------------------------------------------------------+-------
example | BEGIN | 10000
example | END | 10000
example | INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES ($1, $2, $3, $4, CURRENT_TIMESTAMP | 10000
example | SELECT abalance FROM pgbench_accounts WHERE aid = $1 | 10000
example | UPDATE pgbench_accounts SET abalance = abalance + $1 WHERE aid = $2 | 10000
example | UPDATE pgbench_branches SET bbalance = bbalance + $1 WHERE bid = $2 | 10000
example | UPDATE pgbench_tellers SET tbalance = tbalance + $1 WHERE tid = $2 | 10000
example | alter table pgbench_accounts add primary key (aid) | 1
example | alter table pgbench_branches add primary key (bid) | 1
example | alter table pgbench_tellers add primary key (tid) | 1
example | begin | 1
example | commit | 1
example | copy pgbench_accounts from stdin | 1
example | create table pgbench_accounts(aid int not null,bid int,abalance int,filler char(84)) with (fillf | 1
example | create table pgbench_branches(bid int not null,bbalance int,filler char(88)) with (fillfactor=100) | 1
example | create table pgbench_history(tid int,bid int,aid int,delta int,mtime timestamp,filler char(22)) | 1
example | create table pgbench_tellers(tid int not null,bid int,tbalance int,filler char(84)) with (fillfacto | 1
example | drop table if exists pgbench_accounts, pgbench_branches, pgbench_history, pgbench_tellers | 1
example | insert into pgbench_branches(bid,bbalance) values($1,$2) | 10
example | insert into pgbench_tellers(tid,bid,tbalance) values ($1,$2,$3) | 100
(20 rows)
SELECT * from pg_stat_monitor_settings;
name | value | default_value | description | minimum | maximum | options | restart
------------------------------------------+--------+---------------+----------------------------------------------------------------------------------------------------------+---------+------------+----------------+---------
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_query_max_len | 2048 | 2048 | Sets the maximum length of query. | 1024 | 2147483647 | | yes
pg_stat_monitor.pgsm_track_utility | yes | yes | Selects whether utility commands are tracked. | | | yes, no | no
pg_stat_monitor.pgsm_normalized_query | yes | yes | Selects whether save query in normalized format. | | | yes, no | no
pg_stat_monitor.pgsm_max_buckets | 10 | 10 | Sets the maximum number of buckets. | 1 | 10 | | yes
pg_stat_monitor.pgsm_bucket_time | 60 | 60 | Sets the time in seconds per bucket. | 1 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_min | 0 | 0 | Sets the time in millisecond. | 0 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_max | 100000 | 100000 | Sets the time in millisecond. | 10 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_buckets | 10 | 10 | Sets the maximum number of histogram buckets | 2 | 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_overflow_target | 1 | 1 | Sets the overflow target for pg_stat_monitor | 0 | 1 | | yes
pg_stat_monitor.pgsm_enable_query_plan | no | no | Enable/Disable query plan monitoring | | | yes, no | no
pg_stat_monitor.pgsm_track | top | top | Selects which statements are tracked by pg_stat_monitor. | | | none, top, all | no
pg_stat_monitor.pgsm_extract_comments | no | no | Enable/Disable extracting comments from queries. | | | yes, no | no
pg_stat_monitor.pgsm_track_planning | no | no | Selects whether planning statistics are tracked. | | | yes, no | no
(15 rows)
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset
-----------------------
(1 row)
Drop extension pg_stat_monitor;

View File

@ -0,0 +1,130 @@
CREATE EXTENSION pg_stat_monitor;
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset
-----------------------
(1 row)
SELECT * from pg_stat_monitor_settings;
name | value | default_value | description | minimum | maximum | options | restart
------------------------------------------+--------+---------------+----------------------------------------------------------------------------------------------------------+---------+------------+----------------+---------
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_query_max_len | 1024 | 1024 | Sets the maximum length of query. | 1024 | 2147483647 | | yes
pg_stat_monitor.pgsm_track_utility | yes | yes | Selects whether utility commands are tracked. | | | yes, no | no
pg_stat_monitor.pgsm_normalized_query | yes | yes | Selects whether save query in normalized format. | | | yes, no | no
pg_stat_monitor.pgsm_max_buckets | 10 | 10 | Sets the maximum number of buckets. | 1 | 10 | | yes
pg_stat_monitor.pgsm_bucket_time | 60 | 60 | Sets the time in seconds per bucket. | 1 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_min | 0 | 0 | Sets the time in millisecond. | 0 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_max | 100000 | 100000 | Sets the time in millisecond. | 10 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_buckets | 10 | 10 | Sets the maximum number of histogram buckets | 2 | 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_overflow_target | 1 | 1 | Sets the overflow target for pg_stat_monitor | 0 | 1 | | yes
pg_stat_monitor.pgsm_enable_query_plan | no | no | Enable/Disable query plan monitoring | | | yes, no | no
pg_stat_monitor.pgsm_track | all | all | Selects which statements are tracked by pg_stat_monitor. | | | none, top, all | no
pg_stat_monitor.pgsm_extract_comments | no | no | Enable/Disable extracting comments from queries. | | | yes, no | no
pg_stat_monitor.pgsm_track_planning | yes | no | Selects whether planning statistics are tracked. | | | yes, no | no
(15 rows)
SELECT * from pg_stat_monitor_settings;
name | value | default_value | description | minimum | maximum | options | restart
------------------------------------------+--------+---------------+----------------------------------------------------------------------------------------------------------+---------+------------+----------------+---------
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_query_max_len | 1024 | 1024 | Sets the maximum length of query. | 1024 | 2147483647 | | yes
pg_stat_monitor.pgsm_track_utility | yes | yes | Selects whether utility commands are tracked. | | | yes, no | no
pg_stat_monitor.pgsm_normalized_query | yes | yes | Selects whether save query in normalized format. | | | yes, no | no
pg_stat_monitor.pgsm_max_buckets | 10 | 10 | Sets the maximum number of buckets. | 1 | 10 | | yes
pg_stat_monitor.pgsm_bucket_time | 60 | 60 | Sets the time in seconds per bucket. | 1 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_min | 0 | 0 | Sets the time in millisecond. | 0 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_max | 100000 | 100000 | Sets the time in millisecond. | 10 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_buckets | 10 | 10 | Sets the maximum number of histogram buckets | 2 | 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_overflow_target | 1 | 1 | Sets the overflow target for pg_stat_monitor | 0 | 1 | | yes
pg_stat_monitor.pgsm_enable_query_plan | no | no | Enable/Disable query plan monitoring | | | yes, no | no
pg_stat_monitor.pgsm_track | all | all | Selects which statements are tracked by pg_stat_monitor. | | | none, top, all | no
pg_stat_monitor.pgsm_extract_comments | no | no | Enable/Disable extracting comments from queries. | | | yes, no | no
pg_stat_monitor.pgsm_track_planning | yes | no | Selects whether planning statistics are tracked. | | | yes, no | no
(15 rows)
SELECT query, calls, total_plan_time, min_plan_time, max_plan_time, mean_plan_time, stddev_plan_time from pg_stat_monitor;
query | calls | total_plan_time | min_plan_time | max_plan_time | mean_plan_time | stddev_plan_time
---------------------------------------------------------------------------------------------------------------------------+-------+-----------------+---------------+---------------+----------------+------------------
SELECT * from pg_stat_monitor_settings | 2 | 0.4454 | 0.2148 | 0.2307 | 0.2227 | 0.0079
SELECT query, calls, total_plan_time, min_plan_time, max_plan_time, mean_plan_time, stddev_plan_time from pg_stat_monitor | 1 | 1.1586 | 1.1586 | 1.1586 | 1.1586 | 0
SELECT pg_stat_monitor_reset() | 1 | 0 | 0 | 0 | 0 | 0
(3 rows)
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset
-----------------------
(1 row)
SELECT * from pg_stat_monitor_settings;
name | value | default_value | description | minimum | maximum | options | restart
------------------------------------------+--------+---------------+----------------------------------------------------------------------------------------------------------+---------+------------+----------------+---------
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_query_max_len | 1024 | 1024 | Sets the maximum length of query. | 1024 | 2147483647 | | yes
pg_stat_monitor.pgsm_track_utility | yes | yes | Selects whether utility commands are tracked. | | | yes, no | no
pg_stat_monitor.pgsm_normalized_query | yes | yes | Selects whether save query in normalized format. | | | yes, no | no
pg_stat_monitor.pgsm_max_buckets | 10 | 10 | Sets the maximum number of buckets. | 1 | 10 | | yes
pg_stat_monitor.pgsm_bucket_time | 60 | 60 | Sets the time in seconds per bucket. | 1 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_min | 0 | 0 | Sets the time in millisecond. | 0 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_max | 100000 | 100000 | Sets the time in millisecond. | 10 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_buckets | 10 | 10 | Sets the maximum number of histogram buckets | 2 | 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_overflow_target | 1 | 1 | Sets the overflow target for pg_stat_monitor | 0 | 1 | | yes
pg_stat_monitor.pgsm_enable_query_plan | no | no | Enable/Disable query plan monitoring | | | yes, no | no
pg_stat_monitor.pgsm_track | all | all | Selects which statements are tracked by pg_stat_monitor. | | | none, top, all | no
pg_stat_monitor.pgsm_extract_comments | no | no | Enable/Disable extracting comments from queries. | | | yes, no | no
pg_stat_monitor.pgsm_track_planning | no | no | Selects whether planning statistics are tracked. | | | yes, no | no
(15 rows)
SELECT * from pg_stat_monitor_settings;
name | value | default_value | description | minimum | maximum | options | restart
------------------------------------------+--------+---------------+----------------------------------------------------------------------------------------------------------+---------+------------+----------------+---------
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_query_max_len | 1024 | 1024 | Sets the maximum length of query. | 1024 | 2147483647 | | yes
pg_stat_monitor.pgsm_track_utility | yes | yes | Selects whether utility commands are tracked. | | | yes, no | no
pg_stat_monitor.pgsm_normalized_query | yes | yes | Selects whether save query in normalized format. | | | yes, no | no
pg_stat_monitor.pgsm_max_buckets | 10 | 10 | Sets the maximum number of buckets. | 1 | 10 | | yes
pg_stat_monitor.pgsm_bucket_time | 60 | 60 | Sets the time in seconds per bucket. | 1 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_min | 0 | 0 | Sets the time in millisecond. | 0 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_max | 100000 | 100000 | Sets the time in millisecond. | 10 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_buckets | 10 | 10 | Sets the maximum number of histogram buckets | 2 | 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_overflow_target | 1 | 1 | Sets the overflow target for pg_stat_monitor | 0 | 1 | | yes
pg_stat_monitor.pgsm_enable_query_plan | no | no | Enable/Disable query plan monitoring | | | yes, no | no
pg_stat_monitor.pgsm_track | all | all | Selects which statements are tracked by pg_stat_monitor. | | | none, top, all | no
pg_stat_monitor.pgsm_extract_comments | no | no | Enable/Disable extracting comments from queries. | | | yes, no | no
pg_stat_monitor.pgsm_track_planning | no | no | Selects whether planning statistics are tracked. | | | yes, no | no
(15 rows)
SELECT query, calls, total_plan_time, min_plan_time, max_plan_time, mean_plan_time, stddev_plan_time from pg_stat_monitor;
query | calls | total_plan_time | min_plan_time | max_plan_time | mean_plan_time | stddev_plan_time
---------------------------------------------------------------------------------------------------------------------------+-------+-----------------+---------------+---------------+----------------+------------------
SELECT * from pg_stat_monitor_settings | 2 | 0 | 0 | 0 | 0 | 0
SELECT query, calls, total_plan_time, min_plan_time, max_plan_time, mean_plan_time, stddev_plan_time from pg_stat_monitor | 1 | 0 | 0 | 0 | 0 | 0
SELECT pg_stat_monitor_reset() | 1 | 0 | 0 | 0 | 0 | 0
(3 rows)
select substr(query, 0,100) as query, calls, total_plan_time, min_plan_time,max_plan_time,mean_plan_time,stddev_plan_time from pg_stat_monitor order by query;
query | calls | total_plan_time | min_plan_time | max_plan_time | mean_plan_time | stddev_plan_time
-----------------------------------------------------------------------------------------------------+-------+-----------------+---------------+---------------+----------------+------------------
SELECT * from pg_stat_monitor_settings | 2 | 0 | 0 | 0 | 0 | 0
SELECT pg_stat_monitor_reset() | 1 | 0 | 0 | 0 | 0 | 0
SELECT query, calls, total_plan_time, min_plan_time, max_plan_time, mean_plan_time, stddev_plan_tim | 1 | 0 | 0 | 0 | 0 | 0
select (max_plan_time = $1) from pg_stat_monitor where calls = $2 | 1 | 0 | 0 | 0 | 0 | 0
select (mean_plan_time = $1) from pg_stat_monitor where calls = $2 | 1 | 0 | 0 | 0 | 0 | 0
select (min_plan_time = $1) from pg_stat_monitor where calls = $2 | 1 | 0 | 0 | 0 | 0 | 0
select (stddev_plan_time = $1) from pg_stat_monitor where calls = $2 | 1 | 0 | 0 | 0 | 0 | 0
select (total_plan_time = $1) from pg_stat_monitor where calls = $2 | 1 | 0 | 0 | 0 | 0 | 0
select substr(query, $1,$2) as query, calls, total_plan_time, min_plan_time,max_plan_time,mean_plan | 1 | 0 | 0 | 0 | 0 | 0
(9 rows)
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset
-----------------------
(1 row)
Drop extension pg_stat_monitor;

View File

@ -0,0 +1,206 @@
#!/usr/bin/perl
use strict;
use warnings;
use String::Util qw(trim);
use File::Basename;
use File::Compare;
use PostgresNode;
use Test::More;
# Expected folder where expected output will be present
my $expected_folder = "t/expected";
# Results/out folder where generated results files will be placed
my $results_folder = "t/results";
# Check if results folder exists or not, create if it doesn't
unless (-d $results_folder)
{
mkdir $results_folder or die "Can't create folder $results_folder: $!\n";;
}
# Check if expected folder exists or not, bail out if it doesn't
unless (-d $expected_folder)
{
BAIL_OUT "Expected files folder $expected_folder doesn't exist: \n";;
}
# Get filename of the this perl file
my $perlfilename = basename($0);
#Remove .pl from filename and store in a variable
$perlfilename =~ s/\.[^.]+$//;
my $filename_without_extension = $perlfilename;
# Create expected filename with path
my $expected_filename = "${filename_without_extension}.out";
my $expected_filename_with_path = "${expected_folder}/${expected_filename}" ;
# Create results filename with path
my $out_filename = "${filename_without_extension}.out";
my $out_filename_with_path = "${results_folder}/${out_filename}" ;
my $dynamic_out_filename_with_path = "${results_folder}/${out_filename}.dynamic" ;
# Delete already existing result out file, if it exists.
if ( -f $out_filename_with_path)
{
unlink($out_filename_with_path) or die "Can't delete already existing $out_filename_with_path: $!\n";
}
# Create new PostgreSQL node and do initdb
my $node = PostgresNode->get_new_node('test');
my $pgdata = $node->data_dir;
$node->dump_info;
$node->init;
# Update postgresql.conf to include/load pg_stat_monitor library
open my $conf, '>>', "$pgdata/postgresql.conf";
print $conf "shared_preload_libraries = 'pg_stat_monitor'\n";
print $conf "pg_stat_monitor.pgsm_track_planning = 'yes'\n";
close $conf;
# Start server
my $rt_value = $node->start;
ok($rt_value == 1, "Start Server");
# Create extension and change out file permissions
my ($cmdret, $stdout, $stderr) = $node->psql('postgres', 'CREATE EXTENSION pg_stat_monitor;', extra_params => ['-a']);
ok($cmdret == 0, "Create PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
chmod(0640 , $out_filename_with_path)
or die("unable to set permissions for $out_filename_with_path");
# Run required commands/queries and dump output to out file.
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
# Run 'SELECT * from pg_stat_monitor_settings;' two times and dump output to out file
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT * from pg_stat_monitor_settings;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT * from pg_stat_monitor_settings;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT query, calls, total_plan_time, min_plan_time, max_plan_time, mean_plan_time, stddev_plan_time from pg_stat_monitor;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Select from PGSM view");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
# Test: total_plan_time is not 0
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select (total_plan_time = 0) from pg_stat_monitor where calls = 2 ;', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'f',"Compare: total_plan_time is not 0).");
# Test: min_plan_time is not 0
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select (min_plan_time = 0) from pg_stat_monitor where calls = 2 ;', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'f',"Compare: min_plan_time is not 0).");
# Test: max_plan_time is not 0
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select (max_plan_time = 0) from pg_stat_monitor where calls = 2 ;', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'f',"Compare: max_plan_time is not 0).");
# Test: mean_plan_time is not 0
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select (mean_plan_time = 0) from pg_stat_monitor where calls = 2 ;', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'f',"Compare: mean_plan_time is not 0).");
# Test: stddev_plan_time is not 0
#($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select (stddev_plan_time = 0) from pg_stat_monitor where calls = 2 ;', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
#trim($stdout);
#is($stdout,'f',"Compare: stddev_plan_time is not 0).");
# Test: total_plan_time = min_plan_time + max_plan_time
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select (round(total_plan_time::numeric,3) = round(min_plan_time::numeric + max_plan_time::numeric,3)) from pg_stat_monitor where calls = 2 ;', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Compare: (round(total_plan_time::numeric,3) = round(min_plan_time::numeric + max_plan_time::numeric,3)).");
# Test: mean_plan_time = total_plan_time/2
#($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select (round(mean_plan_time::numeric,3) = round((total_plan_time/2)::numeric,3)) from pg_stat_monitor where calls = 2 ;', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
#trim($stdout);
#is($stdout,'t',"Test mean_plan_time: (round(mean_plan_time::numeric,3) = round((total_plan_time/2)::numeric,3)).");
# Test: stddev_plan_time = mean_plan_time - min_plan_time
#($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select (round(stddev_plan_time::numeric,3) = round(mean_plan_time::numeric - min_plan_time::numeric,3)) from pg_stat_monitor where calls = 2 ;', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
#trim($stdout);
#is($stdout,'t',"Compare mean_plan_time: (round(stddev_plan_time::numeric,3) = round(mean_plan_time::numeric - min_plan_time::numeric,3)).");
# Dump output to out file
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select substr(query, 0,100) as query, calls, total_plan_time, min_plan_time,max_plan_time,mean_plan_time,stddev_plan_time from pg_stat_monitor order by query;', extra_params => ['-a','-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($dynamic_out_filename_with_path, $stdout . "\n");
# Disable pgsm_track_planning
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_track_planning = 'no'\n");
$node->restart();
# Dump output to out file
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
# Run 'SELECT * from pg_stat_monitor_settings;' two times and dump output to out file
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT * from pg_stat_monitor_settings;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT * from pg_stat_monitor_settings;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT query, calls, total_plan_time, min_plan_time, max_plan_time, mean_plan_time, stddev_plan_time from pg_stat_monitor;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Select from PGSM view");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
# Test: total_plan_time is 0
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select (total_plan_time = 0) from pg_stat_monitor where calls = 2 ;', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Compare: total_plan_time is 0).");
# Test: min_plan_time is 0
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select (min_plan_time = 0) from pg_stat_monitor where calls = 2 ;', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Compare: min_plan_time is 0).");
# Test: max_plan_time is 0
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select (max_plan_time = 0) from pg_stat_monitor where calls = 2 ;', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Compare: max_plan_time is 0).");
# Test: mean_plan_time is 0
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select (mean_plan_time = 0) from pg_stat_monitor where calls = 2 ;', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Compare: mean_plan_time is 0).");
# Test: stddev_plan_time is 0
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select (stddev_plan_time = 0) from pg_stat_monitor where calls = 2 ;', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'t',"Compare: stddev_plan_time is 0).");
# Dump output to out file
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select substr(query, 0,100) as query, calls, total_plan_time, min_plan_time,max_plan_time,mean_plan_time,stddev_plan_time from pg_stat_monitor order by query;', extra_params => ['-a','-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
# Dump output to out file
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
# Drop extension
$stdout = $node->safe_psql('postgres', 'Drop extension pg_stat_monitor;', extra_params => ['-a']);
ok($cmdret == 0, "Drop PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
# Stop the server
$node->stop;
# compare the expected and out file
#my $compare = compare($expected_filename_with_path, $out_filename_with_path);
# Test/check if expected and result/out file match. If Yes, test passes.
#is($compare,0,"Compare Files: $expected_filename_with_path and $out_filename_with_path match.");
# Done testing for this testcase file.
done_testing();

View File

@ -0,0 +1,84 @@
CREATE EXTENSION pg_stat_monitor;
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset
-----------------------
(1 row)
SELECT * from pg_stat_monitor_settings;
name | value | default_value | description | minimum | maximum | options | restart
------------------------------------------+--------+---------------+----------------------------------------------------------------------------------------------------------+---------+------------+----------------+---------
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_query_max_len | 2048 | 2048 | Sets the maximum length of query. | 1024 | 2147483647 | | yes
pg_stat_monitor.pgsm_track_utility | yes | yes | Selects whether utility commands are tracked. | | | yes, no | no
pg_stat_monitor.pgsm_normalized_query | yes | yes | Selects whether save query in normalized format. | | | yes, no | no
pg_stat_monitor.pgsm_max_buckets | 10 | 10 | Sets the maximum number of buckets. | 1 | 10 | | yes
pg_stat_monitor.pgsm_bucket_time | 60 | 60 | Sets the time in seconds per bucket. | 1 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_min | 0 | 0 | Sets the time in millisecond. | 0 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_max | 100000 | 100000 | Sets the time in millisecond. | 10 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_buckets | 10 | 10 | Sets the maximum number of histogram buckets | 2 | 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_overflow_target | 1 | 1 | Sets the overflow target for pg_stat_monitor | 0 | 1 | | yes
pg_stat_monitor.pgsm_enable_query_plan | no | no | Enable/Disable query plan monitoring | | | yes, no | no
pg_stat_monitor.pgsm_track | top | top | Selects which statements are tracked by pg_stat_monitor. | | | none, top, all | no
pg_stat_monitor.pgsm_extract_comments | yes | no | Enable/Disable extracting comments from queries. | | | yes, no | no
pg_stat_monitor.pgsm_track_planning | no | no | Selects whether planning statistics are tracked. | | | yes, no | no
(15 rows)
SELECT 1 AS num /* First comment */, 'John' as Name /* Second comment*/;
num | name
-----+------
1 | John
(1 row)
SELECT query, comments FROM pg_stat_monitor ORDER BY query COLLATE "C";
query | comments
------------------------------------------------------------------------+------------------------------------------
SELECT $1 AS num /* First comment */, $2 as Name /* Second comment*/ | /* First comment */, /* Second comment*/
SELECT * from pg_stat_monitor_settings |
SELECT pg_stat_monitor_reset() |
SELECT query, comments FROM pg_stat_monitor ORDER BY query COLLATE "C" |
(4 rows)
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset
-----------------------
(1 row)
SELECT * from pg_stat_monitor_settings;
name | value | default_value | description | minimum | maximum | options | restart
------------------------------------------+--------+---------------+----------------------------------------------------------------------------------------------------------+---------+------------+----------------+---------
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_query_max_len | 2048 | 2048 | Sets the maximum length of query. | 1024 | 2147483647 | | yes
pg_stat_monitor.pgsm_track_utility | yes | yes | Selects whether utility commands are tracked. | | | yes, no | no
pg_stat_monitor.pgsm_normalized_query | yes | yes | Selects whether save query in normalized format. | | | yes, no | no
pg_stat_monitor.pgsm_max_buckets | 10 | 10 | Sets the maximum number of buckets. | 1 | 10 | | yes
pg_stat_monitor.pgsm_bucket_time | 60 | 60 | Sets the time in seconds per bucket. | 1 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_min | 0 | 0 | Sets the time in millisecond. | 0 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_max | 100000 | 100000 | Sets the time in millisecond. | 10 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_buckets | 10 | 10 | Sets the maximum number of histogram buckets | 2 | 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_overflow_target | 1 | 1 | Sets the overflow target for pg_stat_monitor | 0 | 1 | | yes
pg_stat_monitor.pgsm_enable_query_plan | no | no | Enable/Disable query plan monitoring | | | yes, no | no
pg_stat_monitor.pgsm_track | top | top | Selects which statements are tracked by pg_stat_monitor. | | | none, top, all | no
pg_stat_monitor.pgsm_extract_comments | no | no | Enable/Disable extracting comments from queries. | | | yes, no | no
pg_stat_monitor.pgsm_track_planning | no | no | Selects whether planning statistics are tracked. | | | yes, no | no
(15 rows)
SELECT 1 AS num /* First comment */, 'John' as Name /* Second comment*/;
num | name
-----+------
1 | John
(1 row)
SELECT query, comments FROM pg_stat_monitor ORDER BY query COLLATE "C";
query | comments
------------------------------------------------------------------------+------------------------------------------
SELECT $1 AS num /* First comment */, $2 as Name /* Second comment*/ | /* First comment */, /* Second comment*/
SELECT * from pg_stat_monitor_settings |
SELECT pg_stat_monitor_reset() |
SELECT query, comments FROM pg_stat_monitor ORDER BY query COLLATE "C" |
(4 rows)
Drop extension pg_stat_monitor;

View File

@ -0,0 +1,80 @@
CREATE EXTENSION pg_stat_monitor;
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset
-----------------------
(1 row)
SELECT * from pg_stat_monitor_settings;
name | value | default_value | description | minimum | maximum | options | restart
------------------------------------------+--------+---------------+----------------------------------------------------------------------------------------------------------+---------+------------+----------------+---------
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_query_max_len | 2048 | 2048 | Sets the maximum length of query. | 1024 | 2147483647 | | yes
pg_stat_monitor.pgsm_track_utility | yes | yes | Selects whether utility commands are tracked. | | | yes, no | no
pg_stat_monitor.pgsm_normalized_query | yes | yes | Selects whether save query in normalized format. | | | yes, no | no
pg_stat_monitor.pgsm_max_buckets | 10 | 10 | Sets the maximum number of buckets. | 1 | 10 | | yes
pg_stat_monitor.pgsm_bucket_time | 60 | 60 | Sets the time in seconds per bucket. | 1 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_min | 0 | 0 | Sets the time in millisecond. | 0 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_max | 100000 | 100000 | Sets the time in millisecond. | 10 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_buckets | 10 | 10 | Sets the maximum number of histogram buckets | 2 | 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_overflow_target | 1 | 1 | Sets the overflow target for pg_stat_monitor | 0 | 1 | | yes
pg_stat_monitor.pgsm_enable_query_plan | no | no | Enable/Disable query plan monitoring | | | yes, no | no
pg_stat_monitor.pgsm_track | none | top | Selects which statements are tracked by pg_stat_monitor. | | | none, top, all | no
pg_stat_monitor.pgsm_extract_comments | no | no | Enable/Disable extracting comments from queries. | | | yes, no | no
pg_stat_monitor.pgsm_track_planning | no | no | Selects whether planning statistics are tracked. | | | yes, no | no
(15 rows)
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset
-----------------------
(1 row)
SELECT * from pg_stat_monitor_settings;
name | value | default_value | description | minimum | maximum | options | restart
------------------------------------------+--------+---------------+----------------------------------------------------------------------------------------------------------+---------+------------+----------------+---------
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_query_max_len | 2048 | 2048 | Sets the maximum length of query. | 1024 | 2147483647 | | yes
pg_stat_monitor.pgsm_track_utility | yes | yes | Selects whether utility commands are tracked. | | | yes, no | no
pg_stat_monitor.pgsm_normalized_query | yes | yes | Selects whether save query in normalized format. | | | yes, no | no
pg_stat_monitor.pgsm_max_buckets | 10 | 10 | Sets the maximum number of buckets. | 1 | 10 | | yes
pg_stat_monitor.pgsm_bucket_time | 60 | 60 | Sets the time in seconds per bucket. | 1 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_min | 0 | 0 | Sets the time in millisecond. | 0 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_max | 100000 | 100000 | Sets the time in millisecond. | 10 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_buckets | 10 | 10 | Sets the maximum number of histogram buckets | 2 | 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_overflow_target | 1 | 1 | Sets the overflow target for pg_stat_monitor | 0 | 1 | | yes
pg_stat_monitor.pgsm_enable_query_plan | no | no | Enable/Disable query plan monitoring | | | yes, no | no
pg_stat_monitor.pgsm_track | all | top | Selects which statements are tracked by pg_stat_monitor. | | | none, top, all | no
pg_stat_monitor.pgsm_extract_comments | no | no | Enable/Disable extracting comments from queries. | | | yes, no | no
pg_stat_monitor.pgsm_track_planning | no | no | Selects whether planning statistics are tracked. | | | yes, no | no
(15 rows)
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset
-----------------------
(1 row)
SELECT * from pg_stat_monitor_settings;
name | value | default_value | description | minimum | maximum | options | restart
------------------------------------------+--------+---------------+----------------------------------------------------------------------------------------------------------+---------+------------+----------------+---------
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_query_max_len | 2048 | 2048 | Sets the maximum length of query. | 1024 | 2147483647 | | yes
pg_stat_monitor.pgsm_track_utility | yes | yes | Selects whether utility commands are tracked. | | | yes, no | no
pg_stat_monitor.pgsm_normalized_query | yes | yes | Selects whether save query in normalized format. | | | yes, no | no
pg_stat_monitor.pgsm_max_buckets | 10 | 10 | Sets the maximum number of buckets. | 1 | 10 | | yes
pg_stat_monitor.pgsm_bucket_time | 60 | 60 | Sets the time in seconds per bucket. | 1 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_min | 0 | 0 | Sets the time in millisecond. | 0 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_max | 100000 | 100000 | Sets the time in millisecond. | 10 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_buckets | 10 | 10 | Sets the maximum number of histogram buckets | 2 | 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_overflow_target | 1 | 1 | Sets the overflow target for pg_stat_monitor | 0 | 1 | | yes
pg_stat_monitor.pgsm_enable_query_plan | no | no | Enable/Disable query plan monitoring | | | yes, no | no
pg_stat_monitor.pgsm_track | top | top | Selects which statements are tracked by pg_stat_monitor. | | | none, top, all | no
pg_stat_monitor.pgsm_extract_comments | no | no | Enable/Disable extracting comments from queries. | | | yes, no | no
pg_stat_monitor.pgsm_track_planning | no | no | Selects whether planning statistics are tracked. | | | yes, no | no
(15 rows)
Drop extension pg_stat_monitor;

View File

@ -0,0 +1,108 @@
CREATE EXTENSION pg_stat_monitor;
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset
-----------------------
(1 row)
SELECT * from pg_stat_monitor_settings;
name | value | default_value | description | minimum | maximum | options | restart
------------------------------------------+--------+---------------+----------------------------------------------------------------------------------------------------------+---------+------------+----------------+---------
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_query_max_len | 2048 | 2048 | Sets the maximum length of query. | 1024 | 2147483647 | | yes
pg_stat_monitor.pgsm_track_utility | yes | yes | Selects whether utility commands are tracked. | | | yes, no | no
pg_stat_monitor.pgsm_normalized_query | yes | yes | Selects whether save query in normalized format. | | | yes, no | no
pg_stat_monitor.pgsm_max_buckets | 10 | 10 | Sets the maximum number of buckets. | 1 | 10 | | yes
pg_stat_monitor.pgsm_bucket_time | 60 | 60 | Sets the time in seconds per bucket. | 1 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_min | 0 | 0 | Sets the time in millisecond. | 0 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_max | 100000 | 100000 | Sets the time in millisecond. | 10 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_buckets | 10 | 10 | Sets the maximum number of histogram buckets | 2 | 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_overflow_target | 1 | 1 | Sets the overflow target for pg_stat_monitor | 0 | 1 | | yes
pg_stat_monitor.pgsm_enable_query_plan | yes | no | Enable/Disable query plan monitoring | | | yes, no | no
pg_stat_monitor.pgsm_track | top | top | Selects which statements are tracked by pg_stat_monitor. | | | none, top, all | no
pg_stat_monitor.pgsm_extract_comments | no | no | Enable/Disable extracting comments from queries. | | | yes, no | no
pg_stat_monitor.pgsm_track_planning | no | no | Selects whether planning statistics are tracked. | | | yes, no | no
(15 rows)
CREATE TABLE TBL_0(key text primary key, txt_0 text, value_0 int);
INSERT INTO TBL_0(key, txt_0, value_0) VALUES('000000', '846930886', 1804289383);
SELECT key, txt_0, value_0 FROM TBL_0;
key | txt_0 | value_0
--------+-----------+------------
000000 | 846930886 | 1804289383
(1 row)
SELECT key, txt_0, value_0 FROM TBL_0;
key | txt_0 | value_0
--------+-----------+------------
000000 | 846930886 | 1804289383
(1 row)
UPDATE TBL_0 SET value_0 = 1681692777;
select substr(query, 0,50) as query, calls, query_plan from pg_stat_monitor order by query,calls;
query | calls | query_plan
---------------------------------------------------+-------+-------------------------------------------
CREATE TABLE TBL_0(key text primary key, txt_0 te | 1 |
INSERT INTO TBL_0(key, txt_0, value_0) VALUES($1, | 1 |
SELECT * from pg_stat_monitor_settings | 1 | Function Scan on pg_stat_monitor_settings
SELECT key, txt_0, value_0 FROM TBL_0 | 2 | Seq Scan on tbl_0
SELECT pg_stat_monitor_reset() | 1 | Result
UPDATE TBL_0 SET value_0 = $1 | 1 |
(6 rows)
Drop TABLE TBL_0;
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset
-----------------------
(1 row)
SELECT * from pg_stat_monitor_settings;
name | value | default_value | description | minimum | maximum | options | restart
------------------------------------------+--------+---------------+----------------------------------------------------------------------------------------------------------+---------+------------+----------------+---------
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_query_max_len | 2048 | 2048 | Sets the maximum length of query. | 1024 | 2147483647 | | yes
pg_stat_monitor.pgsm_track_utility | yes | yes | Selects whether utility commands are tracked. | | | yes, no | no
pg_stat_monitor.pgsm_normalized_query | yes | yes | Selects whether save query in normalized format. | | | yes, no | no
pg_stat_monitor.pgsm_max_buckets | 10 | 10 | Sets the maximum number of buckets. | 1 | 10 | | yes
pg_stat_monitor.pgsm_bucket_time | 60 | 60 | Sets the time in seconds per bucket. | 1 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_min | 0 | 0 | Sets the time in millisecond. | 0 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_max | 100000 | 100000 | Sets the time in millisecond. | 10 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_buckets | 10 | 10 | Sets the maximum number of histogram buckets | 2 | 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_overflow_target | 1 | 1 | Sets the overflow target for pg_stat_monitor | 0 | 1 | | yes
pg_stat_monitor.pgsm_enable_query_plan | no | no | Enable/Disable query plan monitoring | | | yes, no | no
pg_stat_monitor.pgsm_track | top | top | Selects which statements are tracked by pg_stat_monitor. | | | none, top, all | no
pg_stat_monitor.pgsm_extract_comments | no | no | Enable/Disable extracting comments from queries. | | | yes, no | no
pg_stat_monitor.pgsm_track_planning | no | no | Selects whether planning statistics are tracked. | | | yes, no | no
(15 rows)
CREATE TABLE TBL_0(key text primary key, txt_0 text, value_0 int);
INSERT INTO TBL_0(key, txt_0, value_0) VALUES('000000', '846930886', 1804289383);
SELECT key, txt_0, value_0 FROM TBL_0;
key | txt_0 | value_0
--------+-----------+------------
000000 | 846930886 | 1804289383
(1 row)
SELECT key, txt_0, value_0 FROM TBL_0;
key | txt_0 | value_0
--------+-----------+------------
000000 | 846930886 | 1804289383
(1 row)
UPDATE TBL_0 SET value_0 = 1681692777;
select substr(query, 0,50) as query, calls, query_plan from pg_stat_monitor order by query,calls;
query | calls | query_plan
---------------------------------------------------+-------+------------
CREATE TABLE TBL_0(key text primary key, txt_0 te | 1 |
INSERT INTO TBL_0(key, txt_0, value_0) VALUES($1, | 1 |
SELECT * from pg_stat_monitor_settings | 1 |
SELECT key, txt_0, value_0 FROM TBL_0 | 2 |
SELECT pg_stat_monitor_reset() | 1 |
UPDATE TBL_0 SET value_0 = $1 | 1 |
select substr(query, $1,$2) as query, calls, quer | 1 |
(7 rows)
Drop extension pg_stat_monitor;

View File

@ -0,0 +1,54 @@
CREATE EXTENSION pg_stat_monitor;
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset
-----------------------
(1 row)
SELECT * from pg_stat_monitor_settings;
name | value | default_value | description | minimum | maximum | options | restart
------------------------------------------+--------+---------------+----------------------------------------------------------------------------------------------------------+---------+------------+----------------+---------
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_query_max_len | 2048 | 2048 | Sets the maximum length of query. | 1024 | 2147483647 | | yes
pg_stat_monitor.pgsm_track_utility | yes | yes | Selects whether utility commands are tracked. | | | yes, no | no
pg_stat_monitor.pgsm_normalized_query | yes | yes | Selects whether save query in normalized format. | | | yes, no | no
pg_stat_monitor.pgsm_max_buckets | 10 | 10 | Sets the maximum number of buckets. | 1 | 10 | | yes
pg_stat_monitor.pgsm_bucket_time | 60 | 60 | Sets the time in seconds per bucket. | 1 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_min | 0 | 0 | Sets the time in millisecond. | 0 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_max | 100000 | 100000 | Sets the time in millisecond. | 10 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_buckets | 10 | 10 | Sets the maximum number of histogram buckets | 2 | 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_overflow_target | 0 | 1 | Sets the overflow target for pg_stat_monitor | 0 | 1 | | yes
pg_stat_monitor.pgsm_enable_query_plan | no | no | Enable/Disable query plan monitoring | | | yes, no | no
pg_stat_monitor.pgsm_track | top | top | Selects which statements are tracked by pg_stat_monitor. | | | none, top, all | no
pg_stat_monitor.pgsm_extract_comments | no | no | Enable/Disable extracting comments from queries. | | | yes, no | no
pg_stat_monitor.pgsm_track_planning | no | no | Selects whether planning statistics are tracked. | | | yes, no | no
(15 rows)
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset
-----------------------
(1 row)
SELECT * from pg_stat_monitor_settings;
name | value | default_value | description | minimum | maximum | options | restart
------------------------------------------+--------+---------------+----------------------------------------------------------------------------------------------------------+---------+------------+----------------+---------
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_query_max_len | 2048 | 2048 | Sets the maximum length of query. | 1024 | 2147483647 | | yes
pg_stat_monitor.pgsm_track_utility | yes | yes | Selects whether utility commands are tracked. | | | yes, no | no
pg_stat_monitor.pgsm_normalized_query | yes | yes | Selects whether save query in normalized format. | | | yes, no | no
pg_stat_monitor.pgsm_max_buckets | 10 | 10 | Sets the maximum number of buckets. | 1 | 10 | | yes
pg_stat_monitor.pgsm_bucket_time | 60 | 60 | Sets the time in seconds per bucket. | 1 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_min | 0 | 0 | Sets the time in millisecond. | 0 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_max | 100000 | 100000 | Sets the time in millisecond. | 10 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_buckets | 10 | 10 | Sets the maximum number of histogram buckets | 2 | 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_overflow_target | 1 | 1 | Sets the overflow target for pg_stat_monitor | 0 | 1 | | yes
pg_stat_monitor.pgsm_enable_query_plan | no | no | Enable/Disable query plan monitoring | | | yes, no | no
pg_stat_monitor.pgsm_track | top | top | Selects which statements are tracked by pg_stat_monitor. | | | none, top, all | no
pg_stat_monitor.pgsm_extract_comments | no | no | Enable/Disable extracting comments from queries. | | | yes, no | no
pg_stat_monitor.pgsm_track_planning | no | no | Selects whether planning statistics are tracked. | | | yes, no | no
(15 rows)
Drop extension pg_stat_monitor;

View File

@ -0,0 +1,106 @@
CREATE EXTENSION pg_stat_monitor;
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset
-----------------------
(1 row)
SELECT * from pg_stat_monitor_settings;
name | value | default_value | description | minimum | maximum | options | restart
------------------------------------------+--------+---------------+----------------------------------------------------------------------------------------------------------+---------+------------+----------------+---------
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_query_max_len | 2048 | 2048 | Sets the maximum length of query. | 1024 | 2147483647 | | yes
pg_stat_monitor.pgsm_track_utility | yes | yes | Selects whether utility commands are tracked. | | | yes, no | no
pg_stat_monitor.pgsm_normalized_query | yes | yes | Selects whether save query in normalized format. | | | yes, no | no
pg_stat_monitor.pgsm_max_buckets | 10 | 10 | Sets the maximum number of buckets. | 1 | 10 | | yes
pg_stat_monitor.pgsm_bucket_time | 60 | 60 | Sets the time in seconds per bucket. | 1 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_min | 0 | 0 | Sets the time in millisecond. | 0 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_max | 100000 | 100000 | Sets the time in millisecond. | 10 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_buckets | 10 | 10 | Sets the maximum number of histogram buckets | 2 | 2147483647 | | yes
pg_stat_monitor.pgsm_query_shared_buffer | 1 | 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_overflow_target | 1 | 1 | Sets the overflow target for pg_stat_monitor | 0 | 1 | | yes
pg_stat_monitor.pgsm_enable_query_plan | no | no | Enable/Disable query plan monitoring | | | yes, no | no
pg_stat_monitor.pgsm_track | top | top | Selects which statements are tracked by pg_stat_monitor. | | | none, top, all | no
pg_stat_monitor.pgsm_extract_comments | no | no | Enable/Disable extracting comments from queries. | | | yes, no | no
pg_stat_monitor.pgsm_track_planning | no | no | Selects whether planning statistics are tracked. | | | yes, no | no
(15 rows)
CREATE database example;
select datname, substr(query,0,100) as query, calls from pg_stat_monitor order by datname, query, calls desc Limit 20;
datname | query | calls
---------+-----------------------------------------------------------------------------------------------------+-------
example | BEGIN | 10000
example | END | 10000
example | INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES ($1, $2, $3, $4, CURRENT_TIMESTAMP | 10000
example | SELECT abalance FROM pgbench_accounts WHERE aid = $1 | 10000
example | UPDATE pgbench_accounts SET abalance = abalance + $1 WHERE aid = $2 | 10000
example | UPDATE pgbench_branches SET bbalance = bbalance + $1 WHERE bid = $2 | 10000
example | UPDATE pgbench_tellers SET tbalance = tbalance + $1 WHERE tid = $2 | 10000
example | alter table pgbench_accounts add primary key (aid) | 1
example | alter table pgbench_branches add primary key (bid) | 1
example | alter table pgbench_tellers add primary key (tid) | 1
example | begin | 1
example | commit | 1
example | copy pgbench_accounts from stdin | 1
example | create table pgbench_accounts(aid int not null,bid int,abalance int,filler char(84)) with (fillf | 1
example | create table pgbench_branches(bid int not null,bbalance int,filler char(88)) with (fillfactor=100) | 1
example | create table pgbench_history(tid int,bid int,aid int,delta int,mtime timestamp,filler char(22)) | 1
example | create table pgbench_tellers(tid int not null,bid int,tbalance int,filler char(84)) with (fillfacto | 1
example | drop table if exists pgbench_accounts, pgbench_branches, pgbench_history, pgbench_tellers | 1
example | insert into pgbench_branches(bid,bbalance) values($1,$2) | 10
example | insert into pgbench_tellers(tid,bid,tbalance) values ($1,$2,$3) | 100
(20 rows)
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset
-----------------------
(1 row)
SELECT * from pg_stat_monitor_settings;
name | value | default_value | description | minimum | maximum | options | restart
------------------------------------------+--------+---------------+----------------------------------------------------------------------------------------------------------+---------+------------+----------------+---------
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_query_max_len | 2048 | 2048 | Sets the maximum length of query. | 1024 | 2147483647 | | yes
pg_stat_monitor.pgsm_track_utility | yes | yes | Selects whether utility commands are tracked. | | | yes, no | no
pg_stat_monitor.pgsm_normalized_query | yes | yes | Selects whether save query in normalized format. | | | yes, no | no
pg_stat_monitor.pgsm_max_buckets | 10 | 10 | Sets the maximum number of buckets. | 1 | 10 | | yes
pg_stat_monitor.pgsm_bucket_time | 60 | 60 | Sets the time in seconds per bucket. | 1 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_min | 0 | 0 | Sets the time in millisecond. | 0 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_max | 100000 | 100000 | Sets the time in millisecond. | 10 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_buckets | 10 | 10 | Sets the maximum number of histogram buckets | 2 | 2147483647 | | yes
pg_stat_monitor.pgsm_query_shared_buffer | 100 | 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_overflow_target | 1 | 1 | Sets the overflow target for pg_stat_monitor | 0 | 1 | | yes
pg_stat_monitor.pgsm_enable_query_plan | no | no | Enable/Disable query plan monitoring | | | yes, no | no
pg_stat_monitor.pgsm_track | top | top | Selects which statements are tracked by pg_stat_monitor. | | | none, top, all | no
pg_stat_monitor.pgsm_extract_comments | no | no | Enable/Disable extracting comments from queries. | | | yes, no | no
pg_stat_monitor.pgsm_track_planning | no | no | Selects whether planning statistics are tracked. | | | yes, no | no
(15 rows)
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset
-----------------------
(1 row)
SELECT * from pg_stat_monitor_settings;
name | value | default_value | description | minimum | maximum | options | restart
------------------------------------------+--------+---------------+----------------------------------------------------------------------------------------------------------+---------+------------+----------------+---------
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_query_max_len | 2048 | 2048 | Sets the maximum length of query. | 1024 | 2147483647 | | yes
pg_stat_monitor.pgsm_track_utility | yes | yes | Selects whether utility commands are tracked. | | | yes, no | no
pg_stat_monitor.pgsm_normalized_query | yes | yes | Selects whether save query in normalized format. | | | yes, no | no
pg_stat_monitor.pgsm_max_buckets | 10 | 10 | Sets the maximum number of buckets. | 1 | 10 | | yes
pg_stat_monitor.pgsm_bucket_time | 60 | 60 | Sets the time in seconds per bucket. | 1 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_min | 0 | 0 | Sets the time in millisecond. | 0 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_max | 100000 | 100000 | Sets the time in millisecond. | 10 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_buckets | 10 | 10 | Sets the maximum number of histogram buckets | 2 | 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_overflow_target | 1 | 1 | Sets the overflow target for pg_stat_monitor | 0 | 1 | | yes
pg_stat_monitor.pgsm_enable_query_plan | no | no | Enable/Disable query plan monitoring | | | yes, no | no
pg_stat_monitor.pgsm_track | top | top | Selects which statements are tracked by pg_stat_monitor. | | | none, top, all | no
pg_stat_monitor.pgsm_extract_comments | no | no | Enable/Disable extracting comments from queries. | | | yes, no | no
pg_stat_monitor.pgsm_track_planning | no | no | Selects whether planning statistics are tracked. | | | yes, no | no
(15 rows)
Drop extension pg_stat_monitor;

View File

@ -0,0 +1,132 @@
CREATE EXTENSION pg_stat_monitor;
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset
-----------------------
(1 row)
SELECT * from pg_stat_monitor_settings;
name | value | default_value | description | minimum | maximum | options | restart
------------------------------------------+--------+---------------+----------------------------------------------------------------------------------------------------------+---------+------------+----------------+---------
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_query_max_len | 2048 | 2048 | Sets the maximum length of query. | 1024 | 2147483647 | | yes
pg_stat_monitor.pgsm_track_utility | yes | yes | Selects whether utility commands are tracked. | | | yes, no | no
pg_stat_monitor.pgsm_normalized_query | yes | yes | Selects whether save query in normalized format. | | | yes, no | no
pg_stat_monitor.pgsm_max_buckets | 10 | 10 | Sets the maximum number of buckets. | 1 | 10 | | yes
pg_stat_monitor.pgsm_bucket_time | 60 | 60 | Sets the time in seconds per bucket. | 1 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_min | 0 | 0 | Sets the time in millisecond. | 0 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_max | 100000 | 100000 | Sets the time in millisecond. | 10 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_buckets | 10000 | 10 | Sets the maximum number of histogram buckets | 2 | 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_overflow_target | 1 | 1 | Sets the overflow target for pg_stat_monitor | 0 | 1 | | yes
pg_stat_monitor.pgsm_enable_query_plan | no | no | Enable/Disable query plan monitoring | | | yes, no | no
pg_stat_monitor.pgsm_track | top | top | Selects which statements are tracked by pg_stat_monitor. | | | none, top, all | no
pg_stat_monitor.pgsm_extract_comments | no | no | Enable/Disable extracting comments from queries. | | | yes, no | no
pg_stat_monitor.pgsm_track_planning | no | no | Selects whether planning statistics are tracked. | | | yes, no | no
(15 rows)
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset
-----------------------
(1 row)
SELECT * from pg_stat_monitor_settings;
name | value | default_value | description | minimum | maximum | options | restart
------------------------------------------+--------+---------------+----------------------------------------------------------------------------------------------------------+---------+------------+----------------+---------
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_query_max_len | 2048 | 2048 | Sets the maximum length of query. | 1024 | 2147483647 | | yes
pg_stat_monitor.pgsm_track_utility | yes | yes | Selects whether utility commands are tracked. | | | yes, no | no
pg_stat_monitor.pgsm_normalized_query | yes | yes | Selects whether save query in normalized format. | | | yes, no | no
pg_stat_monitor.pgsm_max_buckets | 10 | 10 | Sets the maximum number of buckets. | 1 | 10 | | yes
pg_stat_monitor.pgsm_bucket_time | 60 | 60 | Sets the time in seconds per bucket. | 1 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_min | 0 | 0 | Sets the time in millisecond. | 0 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_max | 100000 | 100000 | Sets the time in millisecond. | 10 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_buckets | 1000 | 10 | Sets the maximum number of histogram buckets | 2 | 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_overflow_target | 1 | 1 | Sets the overflow target for pg_stat_monitor | 0 | 1 | | yes
pg_stat_monitor.pgsm_enable_query_plan | no | no | Enable/Disable query plan monitoring | | | yes, no | no
pg_stat_monitor.pgsm_track | top | top | Selects which statements are tracked by pg_stat_monitor. | | | none, top, all | no
pg_stat_monitor.pgsm_extract_comments | no | no | Enable/Disable extracting comments from queries. | | | yes, no | no
pg_stat_monitor.pgsm_track_planning | no | no | Selects whether planning statistics are tracked. | | | yes, no | no
(15 rows)
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset
-----------------------
(1 row)
SELECT * from pg_stat_monitor_settings;
name | value | default_value | description | minimum | maximum | options | restart
------------------------------------------+--------+---------------+----------------------------------------------------------------------------------------------------------+---------+------------+----------------+---------
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_query_max_len | 2048 | 2048 | Sets the maximum length of query. | 1024 | 2147483647 | | yes
pg_stat_monitor.pgsm_track_utility | yes | yes | Selects whether utility commands are tracked. | | | yes, no | no
pg_stat_monitor.pgsm_normalized_query | yes | yes | Selects whether save query in normalized format. | | | yes, no | no
pg_stat_monitor.pgsm_max_buckets | 10 | 10 | Sets the maximum number of buckets. | 1 | 10 | | yes
pg_stat_monitor.pgsm_bucket_time | 60 | 60 | Sets the time in seconds per bucket. | 1 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_min | 0 | 0 | Sets the time in millisecond. | 0 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_max | 100000 | 100000 | Sets the time in millisecond. | 10 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_buckets | 100 | 10 | Sets the maximum number of histogram buckets | 2 | 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_overflow_target | 1 | 1 | Sets the overflow target for pg_stat_monitor | 0 | 1 | | yes
pg_stat_monitor.pgsm_enable_query_plan | no | no | Enable/Disable query plan monitoring | | | yes, no | no
pg_stat_monitor.pgsm_track | top | top | Selects which statements are tracked by pg_stat_monitor. | | | none, top, all | no
pg_stat_monitor.pgsm_extract_comments | no | no | Enable/Disable extracting comments from queries. | | | yes, no | no
pg_stat_monitor.pgsm_track_planning | no | no | Selects whether planning statistics are tracked. | | | yes, no | no
(15 rows)
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset
-----------------------
(1 row)
SELECT * from pg_stat_monitor_settings;
name | value | default_value | description | minimum | maximum | options | restart
------------------------------------------+--------+---------------+----------------------------------------------------------------------------------------------------------+---------+------------+----------------+---------
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_query_max_len | 2048 | 2048 | Sets the maximum length of query. | 1024 | 2147483647 | | yes
pg_stat_monitor.pgsm_track_utility | yes | yes | Selects whether utility commands are tracked. | | | yes, no | no
pg_stat_monitor.pgsm_normalized_query | yes | yes | Selects whether save query in normalized format. | | | yes, no | no
pg_stat_monitor.pgsm_max_buckets | 10 | 10 | Sets the maximum number of buckets. | 1 | 10 | | yes
pg_stat_monitor.pgsm_bucket_time | 60 | 60 | Sets the time in seconds per bucket. | 1 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_min | 0 | 0 | Sets the time in millisecond. | 0 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_max | 100000 | 100000 | Sets the time in millisecond. | 10 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_buckets | 10 | 10 | Sets the maximum number of histogram buckets | 2 | 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_overflow_target | 1 | 1 | Sets the overflow target for pg_stat_monitor | 0 | 1 | | yes
pg_stat_monitor.pgsm_enable_query_plan | no | no | Enable/Disable query plan monitoring | | | yes, no | no
pg_stat_monitor.pgsm_track | top | top | Selects which statements are tracked by pg_stat_monitor. | | | none, top, all | no
pg_stat_monitor.pgsm_extract_comments | no | no | Enable/Disable extracting comments from queries. | | | yes, no | no
pg_stat_monitor.pgsm_track_planning | no | no | Selects whether planning statistics are tracked. | | | yes, no | no
(15 rows)
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset
-----------------------
(1 row)
SELECT * from pg_stat_monitor_settings;
name | value | default_value | description | minimum | maximum | options | restart
------------------------------------------+--------+---------------+----------------------------------------------------------------------------------------------------------+---------+------------+----------------+---------
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_query_max_len | 2048 | 2048 | Sets the maximum length of query. | 1024 | 2147483647 | | yes
pg_stat_monitor.pgsm_track_utility | yes | yes | Selects whether utility commands are tracked. | | | yes, no | no
pg_stat_monitor.pgsm_normalized_query | yes | yes | Selects whether save query in normalized format. | | | yes, no | no
pg_stat_monitor.pgsm_max_buckets | 10 | 10 | Sets the maximum number of buckets. | 1 | 10 | | yes
pg_stat_monitor.pgsm_bucket_time | 60 | 60 | Sets the time in seconds per bucket. | 1 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_min | 0 | 0 | Sets the time in millisecond. | 0 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_max | 100000 | 100000 | Sets the time in millisecond. | 10 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_buckets | 10 | 10 | Sets the maximum number of histogram buckets | 2 | 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_overflow_target | 1 | 1 | Sets the overflow target for pg_stat_monitor | 0 | 1 | | yes
pg_stat_monitor.pgsm_enable_query_plan | no | no | Enable/Disable query plan monitoring | | | yes, no | no
pg_stat_monitor.pgsm_track | top | top | Selects which statements are tracked by pg_stat_monitor. | | | none, top, all | no
pg_stat_monitor.pgsm_extract_comments | no | no | Enable/Disable extracting comments from queries. | | | yes, no | no
pg_stat_monitor.pgsm_track_planning | no | no | Selects whether planning statistics are tracked. | | | yes, no | no
(15 rows)
Drop extension pg_stat_monitor;

View File

@ -0,0 +1,106 @@
CREATE EXTENSION pg_stat_monitor;
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset
-----------------------
(1 row)
SELECT * from pg_stat_monitor_settings;
name | value | default_value | description | minimum | maximum | options | restart
------------------------------------------+--------+---------------+----------------------------------------------------------------------------------------------------------+---------+------------+----------------+---------
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_query_max_len | 2048 | 2048 | Sets the maximum length of query. | 1024 | 2147483647 | | yes
pg_stat_monitor.pgsm_track_utility | yes | yes | Selects whether utility commands are tracked. | | | yes, no | no
pg_stat_monitor.pgsm_normalized_query | yes | yes | Selects whether save query in normalized format. | | | yes, no | no
pg_stat_monitor.pgsm_max_buckets | 10 | 10 | Sets the maximum number of buckets. | 1 | 10 | | yes
pg_stat_monitor.pgsm_bucket_time | 60 | 60 | Sets the time in seconds per bucket. | 1 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_min | 0 | 0 | Sets the time in millisecond. | 0 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_max | 100000 | 100000 | Sets the time in millisecond. | 10 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_buckets | 10 | 10 | Sets the maximum number of histogram buckets | 2 | 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_overflow_target | 1 | 1 | Sets the overflow target for pg_stat_monitor | 0 | 1 | | yes
pg_stat_monitor.pgsm_enable_query_plan | no | no | Enable/Disable query plan monitoring | | | yes, no | no
pg_stat_monitor.pgsm_track | top | top | Selects which statements are tracked by pg_stat_monitor. | | | none, top, all | no
pg_stat_monitor.pgsm_extract_comments | no | no | Enable/Disable extracting comments from queries. | | | yes, no | no
pg_stat_monitor.pgsm_track_planning | no | no | Selects whether planning statistics are tracked. | | | yes, no | no
(15 rows)
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset
-----------------------
(1 row)
SELECT * from pg_stat_monitor_settings;
name | value | default_value | description | minimum | maximum | options | restart
------------------------------------------+-------+---------------+----------------------------------------------------------------------------------------------------------+---------+------------+----------------+---------
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_query_max_len | 2048 | 2048 | Sets the maximum length of query. | 1024 | 2147483647 | | yes
pg_stat_monitor.pgsm_track_utility | yes | yes | Selects whether utility commands are tracked. | | | yes, no | no
pg_stat_monitor.pgsm_normalized_query | yes | yes | Selects whether save query in normalized format. | | | yes, no | no
pg_stat_monitor.pgsm_max_buckets | 10 | 10 | Sets the maximum number of buckets. | 1 | 10 | | yes
pg_stat_monitor.pgsm_bucket_time | 60 | 60 | Sets the time in seconds per bucket. | 1 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_min | 0 | 0 | Sets the time in millisecond. | 0 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_max | 10 | 100000 | Sets the time in millisecond. | 10 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_buckets | 10 | 10 | Sets the maximum number of histogram buckets | 2 | 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_overflow_target | 1 | 1 | Sets the overflow target for pg_stat_monitor | 0 | 1 | | yes
pg_stat_monitor.pgsm_enable_query_plan | no | no | Enable/Disable query plan monitoring | | | yes, no | no
pg_stat_monitor.pgsm_track | top | top | Selects which statements are tracked by pg_stat_monitor. | | | none, top, all | no
pg_stat_monitor.pgsm_extract_comments | no | no | Enable/Disable extracting comments from queries. | | | yes, no | no
pg_stat_monitor.pgsm_track_planning | no | no | Selects whether planning statistics are tracked. | | | yes, no | no
(15 rows)
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset
-----------------------
(1 row)
SELECT * from pg_stat_monitor_settings;
name | value | default_value | description | minimum | maximum | options | restart
------------------------------------------+-------+---------------+----------------------------------------------------------------------------------------------------------+---------+------------+----------------+---------
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_query_max_len | 2048 | 2048 | Sets the maximum length of query. | 1024 | 2147483647 | | yes
pg_stat_monitor.pgsm_track_utility | yes | yes | Selects whether utility commands are tracked. | | | yes, no | no
pg_stat_monitor.pgsm_normalized_query | yes | yes | Selects whether save query in normalized format. | | | yes, no | no
pg_stat_monitor.pgsm_max_buckets | 10 | 10 | Sets the maximum number of buckets. | 1 | 10 | | yes
pg_stat_monitor.pgsm_bucket_time | 60 | 60 | Sets the time in seconds per bucket. | 1 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_min | 0 | 0 | Sets the time in millisecond. | 0 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_max | 100 | 100000 | Sets the time in millisecond. | 10 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_buckets | 10 | 10 | Sets the maximum number of histogram buckets | 2 | 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_overflow_target | 1 | 1 | Sets the overflow target for pg_stat_monitor | 0 | 1 | | yes
pg_stat_monitor.pgsm_enable_query_plan | no | no | Enable/Disable query plan monitoring | | | yes, no | no
pg_stat_monitor.pgsm_track | top | top | Selects which statements are tracked by pg_stat_monitor. | | | none, top, all | no
pg_stat_monitor.pgsm_extract_comments | no | no | Enable/Disable extracting comments from queries. | | | yes, no | no
pg_stat_monitor.pgsm_track_planning | no | no | Selects whether planning statistics are tracked. | | | yes, no | no
(15 rows)
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset
-----------------------
(1 row)
SELECT * from pg_stat_monitor_settings;
name | value | default_value | description | minimum | maximum | options | restart
------------------------------------------+-------+---------------+----------------------------------------------------------------------------------------------------------+---------+------------+----------------+---------
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_query_max_len | 2048 | 2048 | Sets the maximum length of query. | 1024 | 2147483647 | | yes
pg_stat_monitor.pgsm_track_utility | yes | yes | Selects whether utility commands are tracked. | | | yes, no | no
pg_stat_monitor.pgsm_normalized_query | yes | yes | Selects whether save query in normalized format. | | | yes, no | no
pg_stat_monitor.pgsm_max_buckets | 10 | 10 | Sets the maximum number of buckets. | 1 | 10 | | yes
pg_stat_monitor.pgsm_bucket_time | 60 | 60 | Sets the time in seconds per bucket. | 1 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_min | 0 | 0 | Sets the time in millisecond. | 0 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_max | 1000 | 100000 | Sets the time in millisecond. | 10 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_buckets | 10 | 10 | Sets the maximum number of histogram buckets | 2 | 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_overflow_target | 1 | 1 | Sets the overflow target for pg_stat_monitor | 0 | 1 | | yes
pg_stat_monitor.pgsm_enable_query_plan | no | no | Enable/Disable query plan monitoring | | | yes, no | no
pg_stat_monitor.pgsm_track | top | top | Selects which statements are tracked by pg_stat_monitor. | | | none, top, all | no
pg_stat_monitor.pgsm_extract_comments | no | no | Enable/Disable extracting comments from queries. | | | yes, no | no
pg_stat_monitor.pgsm_track_planning | no | no | Selects whether planning statistics are tracked. | | | yes, no | no
(15 rows)
Drop extension pg_stat_monitor;

View File

@ -0,0 +1,106 @@
CREATE EXTENSION pg_stat_monitor;
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset
-----------------------
(1 row)
SELECT * from pg_stat_monitor_settings;
name | value | default_value | description | minimum | maximum | options | restart
------------------------------------------+--------+---------------+----------------------------------------------------------------------------------------------------------+---------+------------+----------------+---------
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_query_max_len | 2048 | 2048 | Sets the maximum length of query. | 1024 | 2147483647 | | yes
pg_stat_monitor.pgsm_track_utility | yes | yes | Selects whether utility commands are tracked. | | | yes, no | no
pg_stat_monitor.pgsm_normalized_query | yes | yes | Selects whether save query in normalized format. | | | yes, no | no
pg_stat_monitor.pgsm_max_buckets | 10 | 10 | Sets the maximum number of buckets. | 1 | 10 | | yes
pg_stat_monitor.pgsm_bucket_time | 60 | 60 | Sets the time in seconds per bucket. | 1 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_min | 1 | 0 | Sets the time in millisecond. | 0 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_max | 100000 | 100000 | Sets the time in millisecond. | 10 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_buckets | 10 | 10 | Sets the maximum number of histogram buckets | 2 | 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_overflow_target | 1 | 1 | Sets the overflow target for pg_stat_monitor | 0 | 1 | | yes
pg_stat_monitor.pgsm_enable_query_plan | no | no | Enable/Disable query plan monitoring | | | yes, no | no
pg_stat_monitor.pgsm_track | top | top | Selects which statements are tracked by pg_stat_monitor. | | | none, top, all | no
pg_stat_monitor.pgsm_extract_comments | no | no | Enable/Disable extracting comments from queries. | | | yes, no | no
pg_stat_monitor.pgsm_track_planning | no | no | Selects whether planning statistics are tracked. | | | yes, no | no
(15 rows)
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset
-----------------------
(1 row)
SELECT * from pg_stat_monitor_settings;
name | value | default_value | description | minimum | maximum | options | restart
------------------------------------------+--------+---------------+----------------------------------------------------------------------------------------------------------+---------+------------+----------------+---------
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_query_max_len | 2048 | 2048 | Sets the maximum length of query. | 1024 | 2147483647 | | yes
pg_stat_monitor.pgsm_track_utility | yes | yes | Selects whether utility commands are tracked. | | | yes, no | no
pg_stat_monitor.pgsm_normalized_query | yes | yes | Selects whether save query in normalized format. | | | yes, no | no
pg_stat_monitor.pgsm_max_buckets | 10 | 10 | Sets the maximum number of buckets. | 1 | 10 | | yes
pg_stat_monitor.pgsm_bucket_time | 60 | 60 | Sets the time in seconds per bucket. | 1 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_min | 1000 | 0 | Sets the time in millisecond. | 0 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_max | 100000 | 100000 | Sets the time in millisecond. | 10 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_buckets | 10 | 10 | Sets the maximum number of histogram buckets | 2 | 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_overflow_target | 1 | 1 | Sets the overflow target for pg_stat_monitor | 0 | 1 | | yes
pg_stat_monitor.pgsm_enable_query_plan | no | no | Enable/Disable query plan monitoring | | | yes, no | no
pg_stat_monitor.pgsm_track | top | top | Selects which statements are tracked by pg_stat_monitor. | | | none, top, all | no
pg_stat_monitor.pgsm_extract_comments | no | no | Enable/Disable extracting comments from queries. | | | yes, no | no
pg_stat_monitor.pgsm_track_planning | no | no | Selects whether planning statistics are tracked. | | | yes, no | no
(15 rows)
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset
-----------------------
(1 row)
SELECT * from pg_stat_monitor_settings;
name | value | default_value | description | minimum | maximum | options | restart
------------------------------------------+--------+---------------+----------------------------------------------------------------------------------------------------------+---------+------------+----------------+---------
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_query_max_len | 2048 | 2048 | Sets the maximum length of query. | 1024 | 2147483647 | | yes
pg_stat_monitor.pgsm_track_utility | yes | yes | Selects whether utility commands are tracked. | | | yes, no | no
pg_stat_monitor.pgsm_normalized_query | yes | yes | Selects whether save query in normalized format. | | | yes, no | no
pg_stat_monitor.pgsm_max_buckets | 10 | 10 | Sets the maximum number of buckets. | 1 | 10 | | yes
pg_stat_monitor.pgsm_bucket_time | 60 | 60 | Sets the time in seconds per bucket. | 1 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_min | 10000 | 0 | Sets the time in millisecond. | 0 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_max | 100000 | 100000 | Sets the time in millisecond. | 10 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_buckets | 10 | 10 | Sets the maximum number of histogram buckets | 2 | 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_overflow_target | 1 | 1 | Sets the overflow target for pg_stat_monitor | 0 | 1 | | yes
pg_stat_monitor.pgsm_enable_query_plan | no | no | Enable/Disable query plan monitoring | | | yes, no | no
pg_stat_monitor.pgsm_track | top | top | Selects which statements are tracked by pg_stat_monitor. | | | none, top, all | no
pg_stat_monitor.pgsm_extract_comments | no | no | Enable/Disable extracting comments from queries. | | | yes, no | no
pg_stat_monitor.pgsm_track_planning | no | no | Selects whether planning statistics are tracked. | | | yes, no | no
(15 rows)
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset
-----------------------
(1 row)
SELECT * from pg_stat_monitor_settings;
name | value | default_value | description | minimum | maximum | options | restart
------------------------------------------+--------+---------------+----------------------------------------------------------------------------------------------------------+---------+------------+----------------+---------
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_query_max_len | 2048 | 2048 | Sets the maximum length of query. | 1024 | 2147483647 | | yes
pg_stat_monitor.pgsm_track_utility | yes | yes | Selects whether utility commands are tracked. | | | yes, no | no
pg_stat_monitor.pgsm_normalized_query | yes | yes | Selects whether save query in normalized format. | | | yes, no | no
pg_stat_monitor.pgsm_max_buckets | 10 | 10 | Sets the maximum number of buckets. | 1 | 10 | | yes
pg_stat_monitor.pgsm_bucket_time | 60 | 60 | Sets the time in seconds per bucket. | 1 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_min | 99999 | 0 | Sets the time in millisecond. | 0 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_max | 100000 | 100000 | Sets the time in millisecond. | 10 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_buckets | 10 | 10 | Sets the maximum number of histogram buckets | 2 | 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_overflow_target | 1 | 1 | Sets the overflow target for pg_stat_monitor | 0 | 1 | | yes
pg_stat_monitor.pgsm_enable_query_plan | no | no | Enable/Disable query plan monitoring | | | yes, no | no
pg_stat_monitor.pgsm_track | top | top | Selects which statements are tracked by pg_stat_monitor. | | | none, top, all | no
pg_stat_monitor.pgsm_extract_comments | no | no | Enable/Disable extracting comments from queries. | | | yes, no | no
pg_stat_monitor.pgsm_track_planning | no | no | Selects whether planning statistics are tracked. | | | yes, no | no
(15 rows)
Drop extension pg_stat_monitor;

View File

@ -0,0 +1,158 @@
CREATE EXTENSION pg_stat_monitor;
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset
-----------------------
(1 row)
SELECT * from pg_stat_monitor_settings;
name | value | default_value | description | minimum | maximum | options | restart
------------------------------------------+--------+---------------+----------------------------------------------------------------------------------------------------------+---------+------------+----------------+---------
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_query_max_len | 2048 | 2048 | Sets the maximum length of query. | 1024 | 2147483647 | | yes
pg_stat_monitor.pgsm_track_utility | yes | yes | Selects whether utility commands are tracked. | | | yes, no | no
pg_stat_monitor.pgsm_normalized_query | yes | yes | Selects whether save query in normalized format. | | | yes, no | no
pg_stat_monitor.pgsm_max_buckets | 10 | 10 | Sets the maximum number of buckets. | 1 | 10 | | yes
pg_stat_monitor.pgsm_bucket_time | 10000 | 60 | Sets the time in seconds per bucket. | 1 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_min | 0 | 0 | Sets the time in millisecond. | 0 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_max | 100000 | 100000 | Sets the time in millisecond. | 10 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_buckets | 10 | 10 | Sets the maximum number of histogram buckets | 2 | 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_overflow_target | 1 | 1 | Sets the overflow target for pg_stat_monitor | 0 | 1 | | yes
pg_stat_monitor.pgsm_enable_query_plan | no | no | Enable/Disable query plan monitoring | | | yes, no | no
pg_stat_monitor.pgsm_track | top | top | Selects which statements are tracked by pg_stat_monitor. | | | none, top, all | no
pg_stat_monitor.pgsm_extract_comments | no | no | Enable/Disable extracting comments from queries. | | | yes, no | no
pg_stat_monitor.pgsm_track_planning | no | no | Selects whether planning statistics are tracked. | | | yes, no | no
(15 rows)
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset
-----------------------
(1 row)
SELECT * from pg_stat_monitor_settings;
name | value | default_value | description | minimum | maximum | options | restart
------------------------------------------+--------+---------------+----------------------------------------------------------------------------------------------------------+---------+------------+----------------+---------
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_query_max_len | 2048 | 2048 | Sets the maximum length of query. | 1024 | 2147483647 | | yes
pg_stat_monitor.pgsm_track_utility | yes | yes | Selects whether utility commands are tracked. | | | yes, no | no
pg_stat_monitor.pgsm_normalized_query | yes | yes | Selects whether save query in normalized format. | | | yes, no | no
pg_stat_monitor.pgsm_max_buckets | 10 | 10 | Sets the maximum number of buckets. | 1 | 10 | | yes
pg_stat_monitor.pgsm_bucket_time | 1000 | 60 | Sets the time in seconds per bucket. | 1 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_min | 0 | 0 | Sets the time in millisecond. | 0 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_max | 100000 | 100000 | Sets the time in millisecond. | 10 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_buckets | 10 | 10 | Sets the maximum number of histogram buckets | 2 | 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_overflow_target | 1 | 1 | Sets the overflow target for pg_stat_monitor | 0 | 1 | | yes
pg_stat_monitor.pgsm_enable_query_plan | no | no | Enable/Disable query plan monitoring | | | yes, no | no
pg_stat_monitor.pgsm_track | top | top | Selects which statements are tracked by pg_stat_monitor. | | | none, top, all | no
pg_stat_monitor.pgsm_extract_comments | no | no | Enable/Disable extracting comments from queries. | | | yes, no | no
pg_stat_monitor.pgsm_track_planning | no | no | Selects whether planning statistics are tracked. | | | yes, no | no
(15 rows)
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset
-----------------------
(1 row)
SELECT * from pg_stat_monitor_settings;
name | value | default_value | description | minimum | maximum | options | restart
------------------------------------------+--------+---------------+----------------------------------------------------------------------------------------------------------+---------+------------+----------------+---------
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_query_max_len | 2048 | 2048 | Sets the maximum length of query. | 1024 | 2147483647 | | yes
pg_stat_monitor.pgsm_track_utility | yes | yes | Selects whether utility commands are tracked. | | | yes, no | no
pg_stat_monitor.pgsm_normalized_query | yes | yes | Selects whether save query in normalized format. | | | yes, no | no
pg_stat_monitor.pgsm_max_buckets | 10 | 10 | Sets the maximum number of buckets. | 1 | 10 | | yes
pg_stat_monitor.pgsm_bucket_time | 100 | 60 | Sets the time in seconds per bucket. | 1 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_min | 0 | 0 | Sets the time in millisecond. | 0 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_max | 100000 | 100000 | Sets the time in millisecond. | 10 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_buckets | 10 | 10 | Sets the maximum number of histogram buckets | 2 | 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_overflow_target | 1 | 1 | Sets the overflow target for pg_stat_monitor | 0 | 1 | | yes
pg_stat_monitor.pgsm_enable_query_plan | no | no | Enable/Disable query plan monitoring | | | yes, no | no
pg_stat_monitor.pgsm_track | top | top | Selects which statements are tracked by pg_stat_monitor. | | | none, top, all | no
pg_stat_monitor.pgsm_extract_comments | no | no | Enable/Disable extracting comments from queries. | | | yes, no | no
pg_stat_monitor.pgsm_track_planning | no | no | Selects whether planning statistics are tracked. | | | yes, no | no
(15 rows)
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset
-----------------------
(1 row)
SELECT * from pg_stat_monitor_settings;
name | value | default_value | description | minimum | maximum | options | restart
------------------------------------------+--------+---------------+----------------------------------------------------------------------------------------------------------+---------+------------+----------------+---------
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_query_max_len | 2048 | 2048 | Sets the maximum length of query. | 1024 | 2147483647 | | yes
pg_stat_monitor.pgsm_track_utility | yes | yes | Selects whether utility commands are tracked. | | | yes, no | no
pg_stat_monitor.pgsm_normalized_query | yes | yes | Selects whether save query in normalized format. | | | yes, no | no
pg_stat_monitor.pgsm_max_buckets | 10 | 10 | Sets the maximum number of buckets. | 1 | 10 | | yes
pg_stat_monitor.pgsm_bucket_time | 60 | 60 | Sets the time in seconds per bucket. | 1 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_min | 0 | 0 | Sets the time in millisecond. | 0 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_max | 100000 | 100000 | Sets the time in millisecond. | 10 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_buckets | 10 | 10 | Sets the maximum number of histogram buckets | 2 | 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_overflow_target | 1 | 1 | Sets the overflow target for pg_stat_monitor | 0 | 1 | | yes
pg_stat_monitor.pgsm_enable_query_plan | no | no | Enable/Disable query plan monitoring | | | yes, no | no
pg_stat_monitor.pgsm_track | top | top | Selects which statements are tracked by pg_stat_monitor. | | | none, top, all | no
pg_stat_monitor.pgsm_extract_comments | no | no | Enable/Disable extracting comments from queries. | | | yes, no | no
pg_stat_monitor.pgsm_track_planning | no | no | Selects whether planning statistics are tracked. | | | yes, no | no
(15 rows)
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset
-----------------------
(1 row)
SELECT * from pg_stat_monitor_settings;
name | value | default_value | description | minimum | maximum | options | restart
------------------------------------------+--------+---------------+----------------------------------------------------------------------------------------------------------+---------+------------+----------------+---------
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_query_max_len | 2048 | 2048 | Sets the maximum length of query. | 1024 | 2147483647 | | yes
pg_stat_monitor.pgsm_track_utility | yes | yes | Selects whether utility commands are tracked. | | | yes, no | no
pg_stat_monitor.pgsm_normalized_query | yes | yes | Selects whether save query in normalized format. | | | yes, no | no
pg_stat_monitor.pgsm_max_buckets | 10 | 10 | Sets the maximum number of buckets. | 1 | 10 | | yes
pg_stat_monitor.pgsm_bucket_time | 1 | 60 | Sets the time in seconds per bucket. | 1 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_min | 0 | 0 | Sets the time in millisecond. | 0 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_max | 100000 | 100000 | Sets the time in millisecond. | 10 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_buckets | 10 | 10 | Sets the maximum number of histogram buckets | 2 | 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_overflow_target | 1 | 1 | Sets the overflow target for pg_stat_monitor | 0 | 1 | | yes
pg_stat_monitor.pgsm_enable_query_plan | no | no | Enable/Disable query plan monitoring | | | yes, no | no
pg_stat_monitor.pgsm_track | top | top | Selects which statements are tracked by pg_stat_monitor. | | | none, top, all | no
pg_stat_monitor.pgsm_extract_comments | no | no | Enable/Disable extracting comments from queries. | | | yes, no | no
pg_stat_monitor.pgsm_track_planning | no | no | Selects whether planning statistics are tracked. | | | yes, no | no
(15 rows)
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset
-----------------------
(1 row)
SELECT * from pg_stat_monitor_settings;
name | value | default_value | description | minimum | maximum | options | restart
------------------------------------------+--------+---------------+----------------------------------------------------------------------------------------------------------+---------+------------+----------------+---------
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_query_max_len | 2048 | 2048 | Sets the maximum length of query. | 1024 | 2147483647 | | yes
pg_stat_monitor.pgsm_track_utility | yes | yes | Selects whether utility commands are tracked. | | | yes, no | no
pg_stat_monitor.pgsm_normalized_query | yes | yes | Selects whether save query in normalized format. | | | yes, no | no
pg_stat_monitor.pgsm_max_buckets | 10 | 10 | Sets the maximum number of buckets. | 1 | 10 | | yes
pg_stat_monitor.pgsm_bucket_time | 60 | 60 | Sets the time in seconds per bucket. | 1 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_min | 0 | 0 | Sets the time in millisecond. | 0 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_max | 100000 | 100000 | Sets the time in millisecond. | 10 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_buckets | 10 | 10 | Sets the maximum number of histogram buckets | 2 | 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_overflow_target | 1 | 1 | Sets the overflow target for pg_stat_monitor | 0 | 1 | | yes
pg_stat_monitor.pgsm_enable_query_plan | no | no | Enable/Disable query plan monitoring | | | yes, no | no
pg_stat_monitor.pgsm_track | top | top | Selects which statements are tracked by pg_stat_monitor. | | | none, top, all | no
pg_stat_monitor.pgsm_extract_comments | no | no | Enable/Disable extracting comments from queries. | | | yes, no | no
pg_stat_monitor.pgsm_track_planning | no | no | Selects whether planning statistics are tracked. | | | yes, no | no
(15 rows)
Drop extension pg_stat_monitor;

View File

@ -0,0 +1,158 @@
CREATE EXTENSION pg_stat_monitor;
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset
-----------------------
(1 row)
SELECT * from pg_stat_monitor_settings;
name | value | default_value | description | minimum | maximum | options | restart
------------------------------------------+--------+---------------+----------------------------------------------------------------------------------------------------------+---------+------------+----------------+---------
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_query_max_len | 2048 | 2048 | Sets the maximum length of query. | 1024 | 2147483647 | | yes
pg_stat_monitor.pgsm_track_utility | yes | yes | Selects whether utility commands are tracked. | | | yes, no | no
pg_stat_monitor.pgsm_normalized_query | yes | yes | Selects whether save query in normalized format. | | | yes, no | no
pg_stat_monitor.pgsm_max_buckets | 1 | 10 | Sets the maximum number of buckets. | 1 | 10 | | yes
pg_stat_monitor.pgsm_bucket_time | 60 | 60 | Sets the time in seconds per bucket. | 1 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_min | 0 | 0 | Sets the time in millisecond. | 0 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_max | 100000 | 100000 | Sets the time in millisecond. | 10 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_buckets | 10 | 10 | Sets the maximum number of histogram buckets | 2 | 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_overflow_target | 1 | 1 | Sets the overflow target for pg_stat_monitor | 0 | 1 | | yes
pg_stat_monitor.pgsm_enable_query_plan | no | no | Enable/Disable query plan monitoring | | | yes, no | no
pg_stat_monitor.pgsm_track | top | top | Selects which statements are tracked by pg_stat_monitor. | | | none, top, all | no
pg_stat_monitor.pgsm_extract_comments | no | no | Enable/Disable extracting comments from queries. | | | yes, no | no
pg_stat_monitor.pgsm_track_planning | no | no | Selects whether planning statistics are tracked. | | | yes, no | no
(15 rows)
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset
-----------------------
(1 row)
SELECT * from pg_stat_monitor_settings;
name | value | default_value | description | minimum | maximum | options | restart
------------------------------------------+--------+---------------+----------------------------------------------------------------------------------------------------------+---------+------------+----------------+---------
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_query_max_len | 2048 | 2048 | Sets the maximum length of query. | 1024 | 2147483647 | | yes
pg_stat_monitor.pgsm_track_utility | yes | yes | Selects whether utility commands are tracked. | | | yes, no | no
pg_stat_monitor.pgsm_normalized_query | yes | yes | Selects whether save query in normalized format. | | | yes, no | no
pg_stat_monitor.pgsm_max_buckets | 2 | 10 | Sets the maximum number of buckets. | 1 | 10 | | yes
pg_stat_monitor.pgsm_bucket_time | 60 | 60 | Sets the time in seconds per bucket. | 1 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_min | 0 | 0 | Sets the time in millisecond. | 0 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_max | 100000 | 100000 | Sets the time in millisecond. | 10 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_buckets | 10 | 10 | Sets the maximum number of histogram buckets | 2 | 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_overflow_target | 1 | 1 | Sets the overflow target for pg_stat_monitor | 0 | 1 | | yes
pg_stat_monitor.pgsm_enable_query_plan | no | no | Enable/Disable query plan monitoring | | | yes, no | no
pg_stat_monitor.pgsm_track | top | top | Selects which statements are tracked by pg_stat_monitor. | | | none, top, all | no
pg_stat_monitor.pgsm_extract_comments | no | no | Enable/Disable extracting comments from queries. | | | yes, no | no
pg_stat_monitor.pgsm_track_planning | no | no | Selects whether planning statistics are tracked. | | | yes, no | no
(15 rows)
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset
-----------------------
(1 row)
SELECT * from pg_stat_monitor_settings;
name | value | default_value | description | minimum | maximum | options | restart
------------------------------------------+--------+---------------+----------------------------------------------------------------------------------------------------------+---------+------------+----------------+---------
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_query_max_len | 2048 | 2048 | Sets the maximum length of query. | 1024 | 2147483647 | | yes
pg_stat_monitor.pgsm_track_utility | yes | yes | Selects whether utility commands are tracked. | | | yes, no | no
pg_stat_monitor.pgsm_normalized_query | yes | yes | Selects whether save query in normalized format. | | | yes, no | no
pg_stat_monitor.pgsm_max_buckets | 5 | 10 | Sets the maximum number of buckets. | 1 | 10 | | yes
pg_stat_monitor.pgsm_bucket_time | 60 | 60 | Sets the time in seconds per bucket. | 1 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_min | 0 | 0 | Sets the time in millisecond. | 0 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_max | 100000 | 100000 | Sets the time in millisecond. | 10 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_buckets | 10 | 10 | Sets the maximum number of histogram buckets | 2 | 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_overflow_target | 1 | 1 | Sets the overflow target for pg_stat_monitor | 0 | 1 | | yes
pg_stat_monitor.pgsm_enable_query_plan | no | no | Enable/Disable query plan monitoring | | | yes, no | no
pg_stat_monitor.pgsm_track | top | top | Selects which statements are tracked by pg_stat_monitor. | | | none, top, all | no
pg_stat_monitor.pgsm_extract_comments | no | no | Enable/Disable extracting comments from queries. | | | yes, no | no
pg_stat_monitor.pgsm_track_planning | no | no | Selects whether planning statistics are tracked. | | | yes, no | no
(15 rows)
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset
-----------------------
(1 row)
SELECT * from pg_stat_monitor_settings;
name | value | default_value | description | minimum | maximum | options | restart
------------------------------------------+--------+---------------+----------------------------------------------------------------------------------------------------------+---------+------------+----------------+---------
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_query_max_len | 2048 | 2048 | Sets the maximum length of query. | 1024 | 2147483647 | | yes
pg_stat_monitor.pgsm_track_utility | yes | yes | Selects whether utility commands are tracked. | | | yes, no | no
pg_stat_monitor.pgsm_normalized_query | yes | yes | Selects whether save query in normalized format. | | | yes, no | no
pg_stat_monitor.pgsm_max_buckets | 10 | 10 | Sets the maximum number of buckets. | 1 | 10 | | yes
pg_stat_monitor.pgsm_bucket_time | 60 | 60 | Sets the time in seconds per bucket. | 1 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_min | 0 | 0 | Sets the time in millisecond. | 0 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_max | 100000 | 100000 | Sets the time in millisecond. | 10 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_buckets | 10 | 10 | Sets the maximum number of histogram buckets | 2 | 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_overflow_target | 1 | 1 | Sets the overflow target for pg_stat_monitor | 0 | 1 | | yes
pg_stat_monitor.pgsm_enable_query_plan | no | no | Enable/Disable query plan monitoring | | | yes, no | no
pg_stat_monitor.pgsm_track | top | top | Selects which statements are tracked by pg_stat_monitor. | | | none, top, all | no
pg_stat_monitor.pgsm_extract_comments | no | no | Enable/Disable extracting comments from queries. | | | yes, no | no
pg_stat_monitor.pgsm_track_planning | no | no | Selects whether planning statistics are tracked. | | | yes, no | no
(15 rows)
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset
-----------------------
(1 row)
SELECT * from pg_stat_monitor_settings;
name | value | default_value | description | minimum | maximum | options | restart
------------------------------------------+--------+---------------+----------------------------------------------------------------------------------------------------------+---------+------------+----------------+---------
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_query_max_len | 2048 | 2048 | Sets the maximum length of query. | 1024 | 2147483647 | | yes
pg_stat_monitor.pgsm_track_utility | yes | yes | Selects whether utility commands are tracked. | | | yes, no | no
pg_stat_monitor.pgsm_normalized_query | yes | yes | Selects whether save query in normalized format. | | | yes, no | no
pg_stat_monitor.pgsm_max_buckets | 10 | 10 | Sets the maximum number of buckets. | 1 | 10 | | yes
pg_stat_monitor.pgsm_bucket_time | 60 | 60 | Sets the time in seconds per bucket. | 1 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_min | 0 | 0 | Sets the time in millisecond. | 0 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_max | 100000 | 100000 | Sets the time in millisecond. | 10 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_buckets | 10 | 10 | Sets the maximum number of histogram buckets | 2 | 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_overflow_target | 1 | 1 | Sets the overflow target for pg_stat_monitor | 0 | 1 | | yes
pg_stat_monitor.pgsm_enable_query_plan | no | no | Enable/Disable query plan monitoring | | | yes, no | no
pg_stat_monitor.pgsm_track | top | top | Selects which statements are tracked by pg_stat_monitor. | | | none, top, all | no
pg_stat_monitor.pgsm_extract_comments | no | no | Enable/Disable extracting comments from queries. | | | yes, no | no
pg_stat_monitor.pgsm_track_planning | no | no | Selects whether planning statistics are tracked. | | | yes, no | no
(15 rows)
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset
-----------------------
(1 row)
SELECT * from pg_stat_monitor_settings;
name | value | default_value | description | minimum | maximum | options | restart
------------------------------------------+--------+---------------+----------------------------------------------------------------------------------------------------------+---------+------------+----------------+---------
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_query_max_len | 2048 | 2048 | Sets the maximum length of query. | 1024 | 2147483647 | | yes
pg_stat_monitor.pgsm_track_utility | yes | yes | Selects whether utility commands are tracked. | | | yes, no | no
pg_stat_monitor.pgsm_normalized_query | yes | yes | Selects whether save query in normalized format. | | | yes, no | no
pg_stat_monitor.pgsm_max_buckets | 10 | 10 | Sets the maximum number of buckets. | 1 | 10 | | yes
pg_stat_monitor.pgsm_bucket_time | 60 | 60 | Sets the time in seconds per bucket. | 1 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_min | 0 | 0 | Sets the time in millisecond. | 0 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_max | 100000 | 100000 | Sets the time in millisecond. | 10 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_buckets | 10 | 10 | Sets the maximum number of histogram buckets | 2 | 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_overflow_target | 1 | 1 | Sets the overflow target for pg_stat_monitor | 0 | 1 | | yes
pg_stat_monitor.pgsm_enable_query_plan | no | no | Enable/Disable query plan monitoring | | | yes, no | no
pg_stat_monitor.pgsm_track | top | top | Selects which statements are tracked by pg_stat_monitor. | | | none, top, all | no
pg_stat_monitor.pgsm_extract_comments | no | no | Enable/Disable extracting comments from queries. | | | yes, no | no
pg_stat_monitor.pgsm_track_planning | no | no | Selects whether planning statistics are tracked. | | | yes, no | no
(15 rows)
Drop extension pg_stat_monitor;

View File

@ -0,0 +1,109 @@
CREATE EXTENSION pg_stat_monitor;
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset
-----------------------
(1 row)
SELECT * from pg_stat_monitor_settings;
name | value | default_value | description | minimum | maximum | options | restart
------------------------------------------+--------+---------------+----------------------------------------------------------------------------------------------------------+---------+------------+----------------+---------
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_query_max_len | 2048 | 2048 | Sets the maximum length of query. | 1024 | 2147483647 | | yes
pg_stat_monitor.pgsm_track_utility | yes | yes | Selects whether utility commands are tracked. | | | yes, no | no
pg_stat_monitor.pgsm_normalized_query | no | yes | Selects whether save query in normalized format. | | | yes, no | no
pg_stat_monitor.pgsm_max_buckets | 10 | 10 | Sets the maximum number of buckets. | 1 | 10 | | yes
pg_stat_monitor.pgsm_bucket_time | 60 | 60 | Sets the time in seconds per bucket. | 1 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_min | 0 | 0 | Sets the time in millisecond. | 0 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_max | 100000 | 100000 | Sets the time in millisecond. | 10 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_buckets | 10 | 10 | Sets the maximum number of histogram buckets | 2 | 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_overflow_target | 1 | 1 | Sets the overflow target for pg_stat_monitor | 0 | 1 | | yes
pg_stat_monitor.pgsm_enable_query_plan | no | no | Enable/Disable query plan monitoring | | | yes, no | no
pg_stat_monitor.pgsm_track | top | top | Selects which statements are tracked by pg_stat_monitor. | | | none, top, all | no
pg_stat_monitor.pgsm_extract_comments | no | no | Enable/Disable extracting comments from queries. | | | yes, no | no
pg_stat_monitor.pgsm_track_planning | no | no | Selects whether planning statistics are tracked. | | | yes, no | no
(15 rows)
CREATE TABLE TBL_0(key text primary key, txt_0 text, value_0 int);
INSERT INTO TBL_0(key, txt_0, value_0) VALUES('000000', '846930886', 1804289383);
SELECT key, txt_0, value_0 FROM TBL_0;
key | txt_0 | value_0
--------+-----------+------------
000000 | 846930886 | 1804289383
(1 row)
SELECT key, txt_0, value_0 FROM TBL_0;
key | txt_0 | value_0
--------+-----------+------------
000000 | 846930886 | 1804289383
(1 row)
UPDATE TBL_0 SET value_0 = 1681692777;
select datname, substr(query,0,100) as query, calls from pg_stat_monitor order by datname, query, calls desc Limit 20;
datname | query | calls
----------+-----------------------------------------------------------------------------------------------------+-------
postgres | CREATE TABLE TBL_0(key text primary key, txt_0 text, value_0 int) | 1
postgres | INSERT INTO TBL_0(key, txt_0, value_0) VALUES('000000', '846930886', 1804289383) | 1
postgres | SELECT * from pg_stat_monitor_settings | 1
postgres | SELECT key, txt_0, value_0 FROM TBL_0 | 2
postgres | SELECT pg_stat_monitor_reset() | 1
postgres | UPDATE TBL_0 SET value_0 = 1681692777 | 1
postgres | select datname, substr(query,0,100) as query, calls from pg_stat_monitor order by datname, query, c | 1
(7 rows)
Drop TABLE TBL_0;
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset
-----------------------
(1 row)
SELECT * from pg_stat_monitor_settings;
name | value | default_value | description | minimum | maximum | options | restart
------------------------------------------+--------+---------------+----------------------------------------------------------------------------------------------------------+---------+------------+----------------+---------
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_query_max_len | 2048 | 2048 | Sets the maximum length of query. | 1024 | 2147483647 | | yes
pg_stat_monitor.pgsm_track_utility | yes | yes | Selects whether utility commands are tracked. | | | yes, no | no
pg_stat_monitor.pgsm_normalized_query | yes | yes | Selects whether save query in normalized format. | | | yes, no | no
pg_stat_monitor.pgsm_max_buckets | 10 | 10 | Sets the maximum number of buckets. | 1 | 10 | | yes
pg_stat_monitor.pgsm_bucket_time | 60 | 60 | Sets the time in seconds per bucket. | 1 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_min | 0 | 0 | Sets the time in millisecond. | 0 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_max | 100000 | 100000 | Sets the time in millisecond. | 10 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_buckets | 10 | 10 | Sets the maximum number of histogram buckets | 2 | 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_overflow_target | 1 | 1 | Sets the overflow target for pg_stat_monitor | 0 | 1 | | yes
pg_stat_monitor.pgsm_enable_query_plan | no | no | Enable/Disable query plan monitoring | | | yes, no | no
pg_stat_monitor.pgsm_track | top | top | Selects which statements are tracked by pg_stat_monitor. | | | none, top, all | no
pg_stat_monitor.pgsm_extract_comments | no | no | Enable/Disable extracting comments from queries. | | | yes, no | no
pg_stat_monitor.pgsm_track_planning | no | no | Selects whether planning statistics are tracked. | | | yes, no | no
(15 rows)
CREATE TABLE TBL_0(key text primary key, txt_0 text, value_0 int);
INSERT INTO TBL_0(key, txt_0, value_0) VALUES('000000', '846930886', 1804289383);
SELECT key, txt_0, value_0 FROM TBL_0;
key | txt_0 | value_0
--------+-----------+------------
000000 | 846930886 | 1804289383
(1 row)
SELECT key, txt_0, value_0 FROM TBL_0;
key | txt_0 | value_0
--------+-----------+------------
000000 | 846930886 | 1804289383
(1 row)
UPDATE TBL_0 SET value_0 = 1681692777;
select datname, substr(query,0,100) as query, calls from pg_stat_monitor order by datname, query, calls desc Limit 20;
datname | query | calls
----------+-----------------------------------------------------------------------------------------------------+-------
postgres | CREATE TABLE TBL_0(key text primary key, txt_0 text, value_0 int) | 1
postgres | INSERT INTO TBL_0(key, txt_0, value_0) VALUES($1, $2, $3) | 1
postgres | SELECT * from pg_stat_monitor_settings | 1
postgres | SELECT key, txt_0, value_0 FROM TBL_0 | 2
postgres | SELECT pg_stat_monitor_reset() | 1
postgres | UPDATE TBL_0 SET value_0 = $1 | 1
postgres | select datname, substr(query,$1,$2) as query, calls from pg_stat_monitor order by datname, query, c | 1
(7 rows)
Drop extension pg_stat_monitor;

View File

@ -0,0 +1,113 @@
CREATE EXTENSION pg_stat_monitor;
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset
-----------------------
(1 row)
SELECT * from pg_stat_monitor_settings;
name | value | default_value | description | minimum | maximum | options | restart
------------------------------------------+--------+---------------+----------------------------------------------------------------------------------------------------------+---------+------------+----------------+---------
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_query_max_len | 2048 | 2048 | Sets the maximum length of query. | 1024 | 2147483647 | | yes
pg_stat_monitor.pgsm_track_utility | no | yes | Selects whether utility commands are tracked. | | | yes, no | no
pg_stat_monitor.pgsm_normalized_query | yes | yes | Selects whether save query in normalized format. | | | yes, no | no
pg_stat_monitor.pgsm_max_buckets | 10 | 10 | Sets the maximum number of buckets. | 1 | 10 | | yes
pg_stat_monitor.pgsm_bucket_time | 60 | 60 | Sets the time in seconds per bucket. | 1 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_min | 0 | 0 | Sets the time in millisecond. | 0 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_max | 100000 | 100000 | Sets the time in millisecond. | 10 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_buckets | 10 | 10 | Sets the maximum number of histogram buckets | 2 | 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_overflow_target | 1 | 1 | Sets the overflow target for pg_stat_monitor | 0 | 1 | | yes
pg_stat_monitor.pgsm_enable_query_plan | no | no | Enable/Disable query plan monitoring | | | yes, no | no
pg_stat_monitor.pgsm_track | top | top | Selects which statements are tracked by pg_stat_monitor. | | | none, top, all | no
pg_stat_monitor.pgsm_extract_comments | no | no | Enable/Disable extracting comments from queries. | | | yes, no | no
pg_stat_monitor.pgsm_track_planning | no | no | Selects whether planning statistics are tracked. | | | yes, no | no
(15 rows)
CREATE TABLE TBL_0(key text primary key, txt_0 text, value_0 int);
INSERT INTO TBL_0(key, txt_0, value_0) VALUES('000000', '846930886', 1804289383);
SELECT key, txt_0, value_0 FROM TBL_0;
key | txt_0 | value_0
--------+-----------+------------
000000 | 846930886 | 1804289383
(1 row)
SELECT key, txt_0, value_0 FROM TBL_0;
key | txt_0 | value_0
--------+-----------+------------
000000 | 846930886 | 1804289383
(1 row)
UPDATE TBL_0 SET value_0 = 1681692777;
Analyze TBL_0;
DROP TABLE TBL_0;
select datname, substr(query,0,100) as query, calls from pg_stat_monitor order by datname, query, calls desc Limit 20;
datname | query | calls
----------+-----------------------------------------------------------------------------------------------------+-------
postgres | INSERT INTO TBL_0(key, txt_0, value_0) VALUES($1, $2, $3) | 1
postgres | SELECT * from pg_stat_monitor_settings | 1
postgres | SELECT key, txt_0, value_0 FROM TBL_0 | 2
postgres | SELECT pg_stat_monitor_reset() | 1
postgres | UPDATE TBL_0 SET value_0 = $1 | 1
postgres | select datname, substr(query,$1,$2) as query, calls from pg_stat_monitor order by datname, query, c | 1
(6 rows)
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset
-----------------------
(1 row)
SELECT * from pg_stat_monitor_settings;
name | value | default_value | description | minimum | maximum | options | restart
------------------------------------------+--------+---------------+----------------------------------------------------------------------------------------------------------+---------+------------+----------------+---------
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_query_max_len | 2048 | 2048 | Sets the maximum length of query. | 1024 | 2147483647 | | yes
pg_stat_monitor.pgsm_track_utility | yes | yes | Selects whether utility commands are tracked. | | | yes, no | no
pg_stat_monitor.pgsm_normalized_query | yes | yes | Selects whether save query in normalized format. | | | yes, no | no
pg_stat_monitor.pgsm_max_buckets | 10 | 10 | Sets the maximum number of buckets. | 1 | 10 | | yes
pg_stat_monitor.pgsm_bucket_time | 60 | 60 | Sets the time in seconds per bucket. | 1 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_min | 0 | 0 | Sets the time in millisecond. | 0 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_max | 100000 | 100000 | Sets the time in millisecond. | 10 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_buckets | 10 | 10 | Sets the maximum number of histogram buckets | 2 | 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_overflow_target | 1 | 1 | Sets the overflow target for pg_stat_monitor | 0 | 1 | | yes
pg_stat_monitor.pgsm_enable_query_plan | no | no | Enable/Disable query plan monitoring | | | yes, no | no
pg_stat_monitor.pgsm_track | top | top | Selects which statements are tracked by pg_stat_monitor. | | | none, top, all | no
pg_stat_monitor.pgsm_extract_comments | no | no | Enable/Disable extracting comments from queries. | | | yes, no | no
pg_stat_monitor.pgsm_track_planning | no | no | Selects whether planning statistics are tracked. | | | yes, no | no
(15 rows)
CREATE TABLE TBL_0(key text primary key, txt_0 text, value_0 int);
INSERT INTO TBL_0(key, txt_0, value_0) VALUES('000000', '846930886', 1804289383);
SELECT key, txt_0, value_0 FROM TBL_0;
key | txt_0 | value_0
--------+-----------+------------
000000 | 846930886 | 1804289383
(1 row)
SELECT key, txt_0, value_0 FROM TBL_0;
key | txt_0 | value_0
--------+-----------+------------
000000 | 846930886 | 1804289383
(1 row)
UPDATE TBL_0 SET value_0 = 1681692777;
Analyze TBL_0;
DROP TABLE TBL_0;
select datname, substr(query,0,100) as query, calls from pg_stat_monitor order by datname, query, calls desc Limit 20;
datname | query | calls
----------+-----------------------------------------------------------------------------------------------------+-------
postgres | Analyze TBL_0 | 1
postgres | CREATE TABLE TBL_0(key text primary key, txt_0 text, value_0 int) | 1
postgres | DROP TABLE TBL_0 | 1
postgres | INSERT INTO TBL_0(key, txt_0, value_0) VALUES($1, $2, $3) | 1
postgres | SELECT * from pg_stat_monitor_settings | 1
postgres | SELECT key, txt_0, value_0 FROM TBL_0 | 2
postgres | SELECT pg_stat_monitor_reset() | 1
postgres | UPDATE TBL_0 SET value_0 = $1 | 1
postgres | select datname, substr(query,$1,$2) as query, calls from pg_stat_monitor order by datname, query, c | 1
(9 rows)
Drop extension pg_stat_monitor;

View File

@ -0,0 +1,132 @@
CREATE EXTENSION pg_stat_monitor;
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset
-----------------------
(1 row)
SELECT * from pg_stat_monitor_settings;
name | value | default_value | description | minimum | maximum | options | restart
------------------------------------------+--------+---------------+----------------------------------------------------------------------------------------------------------+---------+------------+----------------+---------
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_query_max_len | 10240 | 2048 | Sets the maximum length of query. | 1024 | 2147483647 | | yes
pg_stat_monitor.pgsm_track_utility | yes | yes | Selects whether utility commands are tracked. | | | yes, no | no
pg_stat_monitor.pgsm_normalized_query | yes | yes | Selects whether save query in normalized format. | | | yes, no | no
pg_stat_monitor.pgsm_max_buckets | 10 | 10 | Sets the maximum number of buckets. | 1 | 10 | | yes
pg_stat_monitor.pgsm_bucket_time | 60 | 60 | Sets the time in seconds per bucket. | 1 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_min | 0 | 0 | Sets the time in millisecond. | 0 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_max | 100000 | 100000 | Sets the time in millisecond. | 10 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_buckets | 10 | 10 | Sets the maximum number of histogram buckets | 2 | 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_overflow_target | 1 | 1 | Sets the overflow target for pg_stat_monitor | 0 | 1 | | yes
pg_stat_monitor.pgsm_enable_query_plan | no | no | Enable/Disable query plan monitoring | | | yes, no | no
pg_stat_monitor.pgsm_track | top | top | Selects which statements are tracked by pg_stat_monitor. | | | none, top, all | no
pg_stat_monitor.pgsm_extract_comments | no | no | Enable/Disable extracting comments from queries. | | | yes, no | no
pg_stat_monitor.pgsm_track_planning | no | no | Selects whether planning statistics are tracked. | | | yes, no | no
(15 rows)
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset
-----------------------
(1 row)
SELECT * from pg_stat_monitor_settings;
name | value | default_value | description | minimum | maximum | options | restart
------------------------------------------+--------+---------------+----------------------------------------------------------------------------------------------------------+---------+------------+----------------+---------
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_query_max_len | 1024 | 2048 | Sets the maximum length of query. | 1024 | 2147483647 | | yes
pg_stat_monitor.pgsm_track_utility | yes | yes | Selects whether utility commands are tracked. | | | yes, no | no
pg_stat_monitor.pgsm_normalized_query | yes | yes | Selects whether save query in normalized format. | | | yes, no | no
pg_stat_monitor.pgsm_max_buckets | 10 | 10 | Sets the maximum number of buckets. | 1 | 10 | | yes
pg_stat_monitor.pgsm_bucket_time | 60 | 60 | Sets the time in seconds per bucket. | 1 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_min | 0 | 0 | Sets the time in millisecond. | 0 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_max | 100000 | 100000 | Sets the time in millisecond. | 10 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_buckets | 10 | 10 | Sets the maximum number of histogram buckets | 2 | 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_overflow_target | 1 | 1 | Sets the overflow target for pg_stat_monitor | 0 | 1 | | yes
pg_stat_monitor.pgsm_enable_query_plan | no | no | Enable/Disable query plan monitoring | | | yes, no | no
pg_stat_monitor.pgsm_track | top | top | Selects which statements are tracked by pg_stat_monitor. | | | none, top, all | no
pg_stat_monitor.pgsm_extract_comments | no | no | Enable/Disable extracting comments from queries. | | | yes, no | no
pg_stat_monitor.pgsm_track_planning | no | no | Selects whether planning statistics are tracked. | | | yes, no | no
(15 rows)
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset
-----------------------
(1 row)
SELECT * from pg_stat_monitor_settings;
name | value | default_value | description | minimum | maximum | options | restart
------------------------------------------+--------+---------------+----------------------------------------------------------------------------------------------------------+---------+------------+----------------+---------
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_query_max_len | 2048 | 2048 | Sets the maximum length of query. | 1024 | 2147483647 | | yes
pg_stat_monitor.pgsm_track_utility | yes | yes | Selects whether utility commands are tracked. | | | yes, no | no
pg_stat_monitor.pgsm_normalized_query | yes | yes | Selects whether save query in normalized format. | | | yes, no | no
pg_stat_monitor.pgsm_max_buckets | 10 | 10 | Sets the maximum number of buckets. | 1 | 10 | | yes
pg_stat_monitor.pgsm_bucket_time | 60 | 60 | Sets the time in seconds per bucket. | 1 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_min | 0 | 0 | Sets the time in millisecond. | 0 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_max | 100000 | 100000 | Sets the time in millisecond. | 10 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_buckets | 10 | 10 | Sets the maximum number of histogram buckets | 2 | 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_overflow_target | 1 | 1 | Sets the overflow target for pg_stat_monitor | 0 | 1 | | yes
pg_stat_monitor.pgsm_enable_query_plan | no | no | Enable/Disable query plan monitoring | | | yes, no | no
pg_stat_monitor.pgsm_track | top | top | Selects which statements are tracked by pg_stat_monitor. | | | none, top, all | no
pg_stat_monitor.pgsm_extract_comments | no | no | Enable/Disable extracting comments from queries. | | | yes, no | no
pg_stat_monitor.pgsm_track_planning | no | no | Selects whether planning statistics are tracked. | | | yes, no | no
(15 rows)
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset
-----------------------
(1 row)
SELECT * from pg_stat_monitor_settings;
name | value | default_value | description | minimum | maximum | options | restart
------------------------------------------+--------+---------------+----------------------------------------------------------------------------------------------------------+---------+------------+----------------+---------
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_query_max_len | 2048 | 2048 | Sets the maximum length of query. | 1024 | 2147483647 | | yes
pg_stat_monitor.pgsm_track_utility | yes | yes | Selects whether utility commands are tracked. | | | yes, no | no
pg_stat_monitor.pgsm_normalized_query | yes | yes | Selects whether save query in normalized format. | | | yes, no | no
pg_stat_monitor.pgsm_max_buckets | 10 | 10 | Sets the maximum number of buckets. | 1 | 10 | | yes
pg_stat_monitor.pgsm_bucket_time | 60 | 60 | Sets the time in seconds per bucket. | 1 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_min | 0 | 0 | Sets the time in millisecond. | 0 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_max | 100000 | 100000 | Sets the time in millisecond. | 10 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_buckets | 10 | 10 | Sets the maximum number of histogram buckets | 2 | 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_overflow_target | 1 | 1 | Sets the overflow target for pg_stat_monitor | 0 | 1 | | yes
pg_stat_monitor.pgsm_enable_query_plan | no | no | Enable/Disable query plan monitoring | | | yes, no | no
pg_stat_monitor.pgsm_track | top | top | Selects which statements are tracked by pg_stat_monitor. | | | none, top, all | no
pg_stat_monitor.pgsm_extract_comments | no | no | Enable/Disable extracting comments from queries. | | | yes, no | no
pg_stat_monitor.pgsm_track_planning | no | no | Selects whether planning statistics are tracked. | | | yes, no | no
(15 rows)
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset
-----------------------
(1 row)
SELECT * from pg_stat_monitor_settings;
name | value | default_value | description | minimum | maximum | options | restart
------------------------------------------+--------+---------------+----------------------------------------------------------------------------------------------------------+---------+------------+----------------+---------
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_query_max_len | 2048 | 2048 | Sets the maximum length of query. | 1024 | 2147483647 | | yes
pg_stat_monitor.pgsm_track_utility | yes | yes | Selects whether utility commands are tracked. | | | yes, no | no
pg_stat_monitor.pgsm_normalized_query | yes | yes | Selects whether save query in normalized format. | | | yes, no | no
pg_stat_monitor.pgsm_max_buckets | 10 | 10 | Sets the maximum number of buckets. | 1 | 10 | | yes
pg_stat_monitor.pgsm_bucket_time | 60 | 60 | Sets the time in seconds per bucket. | 1 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_min | 0 | 0 | Sets the time in millisecond. | 0 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_max | 100000 | 100000 | Sets the time in millisecond. | 10 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_buckets | 10 | 10 | Sets the maximum number of histogram buckets | 2 | 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_overflow_target | 1 | 1 | Sets the overflow target for pg_stat_monitor | 0 | 1 | | yes
pg_stat_monitor.pgsm_enable_query_plan | no | no | Enable/Disable query plan monitoring | | | yes, no | no
pg_stat_monitor.pgsm_track | top | top | Selects which statements are tracked by pg_stat_monitor. | | | none, top, all | no
pg_stat_monitor.pgsm_extract_comments | no | no | Enable/Disable extracting comments from queries. | | | yes, no | no
pg_stat_monitor.pgsm_track_planning | no | no | Selects whether planning statistics are tracked. | | | yes, no | no
(15 rows)
Drop extension pg_stat_monitor;

View File

@ -0,0 +1,132 @@
CREATE EXTENSION pg_stat_monitor;
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset
-----------------------
(1 row)
SELECT * from pg_stat_monitor_settings;
name | value | default_value | description | minimum | maximum | options | restart
------------------------------------------+--------+---------------+----------------------------------------------------------------------------------------------------------+---------+------------+----------------+---------
pg_stat_monitor.pgsm_max | 1000 | 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_query_max_len | 2048 | 2048 | Sets the maximum length of query. | 1024 | 2147483647 | | yes
pg_stat_monitor.pgsm_track_utility | yes | yes | Selects whether utility commands are tracked. | | | yes, no | no
pg_stat_monitor.pgsm_normalized_query | yes | yes | Selects whether save query in normalized format. | | | yes, no | no
pg_stat_monitor.pgsm_max_buckets | 10 | 10 | Sets the maximum number of buckets. | 1 | 10 | | yes
pg_stat_monitor.pgsm_bucket_time | 60 | 60 | Sets the time in seconds per bucket. | 1 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_min | 0 | 0 | Sets the time in millisecond. | 0 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_max | 100000 | 100000 | Sets the time in millisecond. | 10 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_buckets | 10 | 10 | Sets the maximum number of histogram buckets | 2 | 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_overflow_target | 1 | 1 | Sets the overflow target for pg_stat_monitor | 0 | 1 | | yes
pg_stat_monitor.pgsm_enable_query_plan | no | no | Enable/Disable query plan monitoring | | | yes, no | no
pg_stat_monitor.pgsm_track | top | top | Selects which statements are tracked by pg_stat_monitor. | | | none, top, all | no
pg_stat_monitor.pgsm_extract_comments | no | no | Enable/Disable extracting comments from queries. | | | yes, no | no
pg_stat_monitor.pgsm_track_planning | no | no | Selects whether planning statistics are tracked. | | | yes, no | no
(15 rows)
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset
-----------------------
(1 row)
SELECT * from pg_stat_monitor_settings;
name | value | default_value | description | minimum | maximum | options | restart
------------------------------------------+--------+---------------+----------------------------------------------------------------------------------------------------------+---------+------------+----------------+---------
pg_stat_monitor.pgsm_max | 500 | 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_query_max_len | 2048 | 2048 | Sets the maximum length of query. | 1024 | 2147483647 | | yes
pg_stat_monitor.pgsm_track_utility | yes | yes | Selects whether utility commands are tracked. | | | yes, no | no
pg_stat_monitor.pgsm_normalized_query | yes | yes | Selects whether save query in normalized format. | | | yes, no | no
pg_stat_monitor.pgsm_max_buckets | 10 | 10 | Sets the maximum number of buckets. | 1 | 10 | | yes
pg_stat_monitor.pgsm_bucket_time | 60 | 60 | Sets the time in seconds per bucket. | 1 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_min | 0 | 0 | Sets the time in millisecond. | 0 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_max | 100000 | 100000 | Sets the time in millisecond. | 10 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_buckets | 10 | 10 | Sets the maximum number of histogram buckets | 2 | 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_overflow_target | 1 | 1 | Sets the overflow target for pg_stat_monitor | 0 | 1 | | yes
pg_stat_monitor.pgsm_enable_query_plan | no | no | Enable/Disable query plan monitoring | | | yes, no | no
pg_stat_monitor.pgsm_track | top | top | Selects which statements are tracked by pg_stat_monitor. | | | none, top, all | no
pg_stat_monitor.pgsm_extract_comments | no | no | Enable/Disable extracting comments from queries. | | | yes, no | no
pg_stat_monitor.pgsm_track_planning | no | no | Selects whether planning statistics are tracked. | | | yes, no | no
(15 rows)
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset
-----------------------
(1 row)
SELECT * from pg_stat_monitor_settings;
name | value | default_value | description | minimum | maximum | options | restart
------------------------------------------+--------+---------------+----------------------------------------------------------------------------------------------------------+---------+------------+----------------+---------
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_query_max_len | 2048 | 2048 | Sets the maximum length of query. | 1024 | 2147483647 | | yes
pg_stat_monitor.pgsm_track_utility | yes | yes | Selects whether utility commands are tracked. | | | yes, no | no
pg_stat_monitor.pgsm_normalized_query | yes | yes | Selects whether save query in normalized format. | | | yes, no | no
pg_stat_monitor.pgsm_max_buckets | 10 | 10 | Sets the maximum number of buckets. | 1 | 10 | | yes
pg_stat_monitor.pgsm_bucket_time | 60 | 60 | Sets the time in seconds per bucket. | 1 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_min | 0 | 0 | Sets the time in millisecond. | 0 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_max | 100000 | 100000 | Sets the time in millisecond. | 10 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_buckets | 10 | 10 | Sets the maximum number of histogram buckets | 2 | 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_overflow_target | 1 | 1 | Sets the overflow target for pg_stat_monitor | 0 | 1 | | yes
pg_stat_monitor.pgsm_enable_query_plan | no | no | Enable/Disable query plan monitoring | | | yes, no | no
pg_stat_monitor.pgsm_track | top | top | Selects which statements are tracked by pg_stat_monitor. | | | none, top, all | no
pg_stat_monitor.pgsm_extract_comments | no | no | Enable/Disable extracting comments from queries. | | | yes, no | no
pg_stat_monitor.pgsm_track_planning | no | no | Selects whether planning statistics are tracked. | | | yes, no | no
(15 rows)
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset
-----------------------
(1 row)
SELECT * from pg_stat_monitor_settings;
name | value | default_value | description | minimum | maximum | options | restart
------------------------------------------+--------+---------------+----------------------------------------------------------------------------------------------------------+---------+------------+----------------+---------
pg_stat_monitor.pgsm_max | 10 | 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_query_max_len | 2048 | 2048 | Sets the maximum length of query. | 1024 | 2147483647 | | yes
pg_stat_monitor.pgsm_track_utility | yes | yes | Selects whether utility commands are tracked. | | | yes, no | no
pg_stat_monitor.pgsm_normalized_query | yes | yes | Selects whether save query in normalized format. | | | yes, no | no
pg_stat_monitor.pgsm_max_buckets | 10 | 10 | Sets the maximum number of buckets. | 1 | 10 | | yes
pg_stat_monitor.pgsm_bucket_time | 60 | 60 | Sets the time in seconds per bucket. | 1 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_min | 0 | 0 | Sets the time in millisecond. | 0 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_max | 100000 | 100000 | Sets the time in millisecond. | 10 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_buckets | 10 | 10 | Sets the maximum number of histogram buckets | 2 | 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_overflow_target | 1 | 1 | Sets the overflow target for pg_stat_monitor | 0 | 1 | | yes
pg_stat_monitor.pgsm_enable_query_plan | no | no | Enable/Disable query plan monitoring | | | yes, no | no
pg_stat_monitor.pgsm_track | top | top | Selects which statements are tracked by pg_stat_monitor. | | | none, top, all | no
pg_stat_monitor.pgsm_extract_comments | no | no | Enable/Disable extracting comments from queries. | | | yes, no | no
pg_stat_monitor.pgsm_track_planning | no | no | Selects whether planning statistics are tracked. | | | yes, no | no
(15 rows)
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset
-----------------------
(1 row)
SELECT * from pg_stat_monitor_settings;
name | value | default_value | description | minimum | maximum | options | restart
------------------------------------------+--------+---------------+----------------------------------------------------------------------------------------------------------+---------+------------+----------------+---------
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_query_max_len | 2048 | 2048 | Sets the maximum length of query. | 1024 | 2147483647 | | yes
pg_stat_monitor.pgsm_track_utility | yes | yes | Selects whether utility commands are tracked. | | | yes, no | no
pg_stat_monitor.pgsm_normalized_query | yes | yes | Selects whether save query in normalized format. | | | yes, no | no
pg_stat_monitor.pgsm_max_buckets | 10 | 10 | Sets the maximum number of buckets. | 1 | 10 | | yes
pg_stat_monitor.pgsm_bucket_time | 60 | 60 | Sets the time in seconds per bucket. | 1 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_min | 0 | 0 | Sets the time in millisecond. | 0 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_max | 100000 | 100000 | Sets the time in millisecond. | 10 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_buckets | 10 | 10 | Sets the maximum number of histogram buckets | 2 | 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_overflow_target | 1 | 1 | Sets the overflow target for pg_stat_monitor | 0 | 1 | | yes
pg_stat_monitor.pgsm_enable_query_plan | no | no | Enable/Disable query plan monitoring | | | yes, no | no
pg_stat_monitor.pgsm_track | top | top | Selects which statements are tracked by pg_stat_monitor. | | | none, top, all | no
pg_stat_monitor.pgsm_extract_comments | no | no | Enable/Disable extracting comments from queries. | | | yes, no | no
pg_stat_monitor.pgsm_track_planning | no | no | Selects whether planning statistics are tracked. | | | yes, no | no
(15 rows)
Drop extension pg_stat_monitor;

View File

@ -0,0 +1,54 @@
CREATE EXTENSION pg_stat_monitor;
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset
-----------------------
(1 row)
SELECT * from pg_stat_monitor_settings;
name | value | default_value | description | minimum | maximum | options | restart
------------------------------------------+--------+---------------+----------------------------------------------------------------------------------------------------------+---------+------------+----------------+---------
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_query_max_len | 1024 | 1024 | Sets the maximum length of query. | 1024 | 2147483647 | | yes
pg_stat_monitor.pgsm_track_utility | yes | yes | Selects whether utility commands are tracked. | | | yes, no | no
pg_stat_monitor.pgsm_normalized_query | yes | yes | Selects whether save query in normalized format. | | | yes, no | no
pg_stat_monitor.pgsm_max_buckets | 10 | 10 | Sets the maximum number of buckets. | 1 | 10 | | yes
pg_stat_monitor.pgsm_bucket_time | 60 | 60 | Sets the time in seconds per bucket. | 1 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_min | 0 | 0 | Sets the time in millisecond. | 0 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_max | 100000 | 100000 | Sets the time in millisecond. | 10 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_buckets | 10 | 10 | Sets the maximum number of histogram buckets | 2 | 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_overflow_target | 1 | 1 | Sets the overflow target for pg_stat_monitor | 0 | 1 | | yes
pg_stat_monitor.pgsm_enable_query_plan | no | no | Enable/Disable query plan monitoring | | | yes, no | no
pg_stat_monitor.track | top | top | Selects which statements are tracked by pg_stat_monitor. | | | none, top, all | no
pg_stat_monitor.extract_comments | no | no | Enable/Disable extracting comments from queries. | | | yes, no | no
pg_stat_monitor.pgsm_track_planning | no | no | Selects whether planning statistics are tracked. | | | yes, no | no
(15 rows)
SELECT * from pg_stat_monitor_settings;
name | value | default_value | description | minimum | maximum | options | restart
------------------------------------------+--------+---------------+----------------------------------------------------------------------------------------------------------+---------+------------+----------------+---------
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_query_max_len | 1024 | 1024 | Sets the maximum length of query. | 1024 | 2147483647 | | yes
pg_stat_monitor.pgsm_track_utility | yes | yes | Selects whether utility commands are tracked. | | | yes, no | no
pg_stat_monitor.pgsm_normalized_query | yes | yes | Selects whether save query in normalized format. | | | yes, no | no
pg_stat_monitor.pgsm_max_buckets | 10 | 10 | Sets the maximum number of buckets. | 1 | 10 | | yes
pg_stat_monitor.pgsm_bucket_time | 60 | 60 | Sets the time in seconds per bucket. | 1 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_min | 0 | 0 | Sets the time in millisecond. | 0 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_max | 100000 | 100000 | Sets the time in millisecond. | 10 | 2147483647 | | yes
pg_stat_monitor.pgsm_histogram_buckets | 10 | 10 | Sets the maximum number of histogram buckets | 2 | 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_overflow_target | 1 | 1 | Sets the overflow target for pg_stat_monitor | 0 | 1 | | yes
pg_stat_monitor.pgsm_enable_query_plan | no | no | Enable/Disable query plan monitoring | | | yes, no | no
pg_stat_monitor.track | top | top | Selects which statements are tracked by pg_stat_monitor. | | | none, top, all | no
pg_stat_monitor.extract_comments | no | no | Enable/Disable extracting comments from queries. | | | yes, no | no
pg_stat_monitor.pgsm_track_planning | no | no | Selects whether planning statistics are tracked. | | | yes, no | no
(15 rows)
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset
-----------------------
(1 row)
Drop extension pg_stat_monitor;