Compare commits
23 Commits
Author | SHA1 | Date |
---|---|---|
|
9e0a252873 | |
|
3653dd6041 | |
|
76b0802142 | |
|
61662cc58f | |
|
f7dc7fb5fe | |
|
38f13e893f | |
|
9d2f2cd8cc | |
|
d0237f8d83 | |
|
d116dd47fe | |
|
9c72c2e73d | |
|
76424b6c64 | |
|
f76b1860e3 | |
|
a7edd766e3 | |
|
24c1c59416 | |
|
b860effd97 | |
|
64b08e422c | |
|
acd559842f | |
|
8bbb49e409 | |
|
7bddd5a033 | |
|
5312f6f8a7 | |
|
c305b8a086 | |
|
8dcf24a879 | |
|
32b1beb6ff |
|
@ -1,4 +1,4 @@
|
|||
# https://docs.github.com/en/github/creating-cloning-and-archiving-repositories/about-code-owners
|
||||
# Order is important; the last matching pattern takes the most precedence.
|
||||
|
||||
* @artemgavrilov @darkfronza
|
||||
* @artemgavrilov @dutow
|
||||
|
|
|
@ -3,7 +3,7 @@ description: File a bug report
|
|||
labels: ["bug"]
|
||||
assignees:
|
||||
- artemgavrilov
|
||||
- darkfronza
|
||||
- dutow
|
||||
|
||||
body:
|
||||
- type: markdown
|
||||
|
|
|
@ -3,7 +3,7 @@ description: Suggest an idea for this project
|
|||
labels: ["feature"]
|
||||
assignees:
|
||||
- artemgavrilov
|
||||
- darkfronza
|
||||
- dutow
|
||||
|
||||
body:
|
||||
- type: markdown
|
||||
|
|
|
@ -113,7 +113,7 @@ jobs:
|
|||
working-directory: src/pg_stat_monitor
|
||||
|
||||
- name: Upload
|
||||
uses: codecov/codecov-action@13ce06bfc6bbe3ecf90edbbf1bc32fe5978ca1d3 # v5.3.1
|
||||
uses: codecov/codecov-action@18283e04ce6e62d37312384ff67231eb8fd56d24 # v5.4.3
|
||||
with:
|
||||
verbose: true
|
||||
token: ${{ secrets.CODECOV_TOKEN }}
|
||||
|
@ -130,7 +130,7 @@ jobs:
|
|||
|
||||
- name: Upload logs on fail
|
||||
if: ${{ failure() }}
|
||||
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
|
||||
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
|
||||
with:
|
||||
name: Regressions diff and postgresql log
|
||||
path: |
|
||||
|
|
|
@ -118,7 +118,7 @@ jobs:
|
|||
|
||||
- name: Upload logs on fail
|
||||
if: ${{ failure() }}
|
||||
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
|
||||
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
|
||||
with:
|
||||
name: Regressions diff and postgresql log
|
||||
path: |
|
||||
|
@ -141,7 +141,7 @@ jobs:
|
|||
make installcheck-world
|
||||
|
||||
- name: Report on installcheck-world test suites fail
|
||||
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
|
||||
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
|
||||
if: ${{ failure() }}
|
||||
with:
|
||||
name: Regressions output files of failed testsuite, and pg log
|
||||
|
|
|
@ -80,7 +80,7 @@ jobs:
|
|||
|
||||
- name: Upload logs on fail
|
||||
if: ${{ failure() }}
|
||||
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
|
||||
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
|
||||
with:
|
||||
name: Regressions diff and postgresql log
|
||||
path: |
|
||||
|
|
|
@ -42,7 +42,7 @@ jobs:
|
|||
run: docker exec pgsql_pgsm_12 cat pmm-agent.log > ./pmm-ui-tests/tests/output/pmm-agent.log
|
||||
|
||||
- name: Upload Tests Artifacts
|
||||
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
|
||||
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
|
||||
if: success() || failure() # run this step even if previous step failed
|
||||
with:
|
||||
name: tests-artifact
|
||||
|
|
|
@ -95,7 +95,7 @@ jobs:
|
|||
|
||||
- name: Upload logs on fail
|
||||
if: ${{ failure() }}
|
||||
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
|
||||
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
|
||||
with:
|
||||
name: Regressions diff and postgresql log
|
||||
path: |
|
||||
|
|
|
@ -117,7 +117,7 @@ jobs:
|
|||
|
||||
- name: Upload logs on fail
|
||||
if: ${{ failure() }}
|
||||
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
|
||||
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
|
||||
with:
|
||||
name: Regressions diff and postgresql log
|
||||
path: |
|
||||
|
@ -140,7 +140,7 @@ jobs:
|
|||
make installcheck-world
|
||||
|
||||
- name: Report on installcheck-world test suites fail
|
||||
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
|
||||
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
|
||||
if: ${{ failure() }}
|
||||
with:
|
||||
name: Regressions output files of failed testsuite, and pg log
|
||||
|
|
|
@ -79,7 +79,7 @@ jobs:
|
|||
|
||||
- name: Upload logs on fail
|
||||
if: ${{ failure() }}
|
||||
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
|
||||
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
|
||||
with:
|
||||
name: Regressions diff and postgresql log
|
||||
path: |
|
||||
|
|
|
@ -42,7 +42,7 @@ jobs:
|
|||
run: docker exec pgsql_pgsm_13 cat pmm-agent.log > ./pmm-ui-tests/tests/output/pmm-agent.log
|
||||
|
||||
- name: Upload Tests Artifacts
|
||||
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
|
||||
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
|
||||
if: success() || failure() # run this step even if previous step failed
|
||||
with:
|
||||
name: tests-artifact
|
||||
|
|
|
@ -92,7 +92,7 @@ jobs:
|
|||
|
||||
- name: Upload logs on fail
|
||||
if: ${{ failure() }}
|
||||
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
|
||||
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
|
||||
with:
|
||||
name: Regressions diff and postgresql log
|
||||
path: |
|
||||
|
|
|
@ -118,7 +118,7 @@ jobs:
|
|||
|
||||
- name: Upload logs on fail
|
||||
if: ${{ failure() }}
|
||||
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
|
||||
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
|
||||
with:
|
||||
name: Regressions diff and postgresql log
|
||||
path: |
|
||||
|
@ -140,7 +140,7 @@ jobs:
|
|||
run: make installcheck-world
|
||||
|
||||
- name: Report on installcheck-world test suites fail
|
||||
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
|
||||
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
|
||||
if: ${{ failure() }}
|
||||
with:
|
||||
name: Regressions output files of failed testsuite, and pg log
|
||||
|
|
|
@ -78,7 +78,7 @@ jobs:
|
|||
|
||||
- name: Upload logs on fail
|
||||
if: ${{ failure() }}
|
||||
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
|
||||
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
|
||||
with:
|
||||
name: Regressions diff and postgresql log
|
||||
path: |
|
||||
|
|
|
@ -42,7 +42,7 @@ jobs:
|
|||
run: docker exec pgsql_pgsm_14 cat pmm-agent.log > ./pmm-ui-tests/tests/output/pmm-agent.log
|
||||
|
||||
- name: Upload Tests Artifacts
|
||||
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
|
||||
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
|
||||
if: success() || failure() # run this step even if previous step failed
|
||||
with:
|
||||
name: tests-artifact
|
||||
|
|
|
@ -92,7 +92,7 @@ jobs:
|
|||
|
||||
- name: Upload logs on fail
|
||||
if: ${{ failure() }}
|
||||
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
|
||||
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
|
||||
with:
|
||||
name: Regressions diff and postgresql log
|
||||
path: |
|
||||
|
|
|
@ -118,7 +118,7 @@ jobs:
|
|||
|
||||
- name: Upload logs on fail
|
||||
if: ${{ failure() }}
|
||||
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
|
||||
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
|
||||
with:
|
||||
name: Regressions diff and postgresql log
|
||||
path: |
|
||||
|
@ -140,7 +140,7 @@ jobs:
|
|||
run: make installcheck-world
|
||||
|
||||
- name: Report on installcheck-world test suites fail
|
||||
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
|
||||
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
|
||||
if: ${{ failure() }}
|
||||
with:
|
||||
name: Regressions output files of failed testsuite, and pg log
|
||||
|
|
|
@ -78,7 +78,7 @@ jobs:
|
|||
|
||||
- name: Upload logs on fail
|
||||
if: ${{ failure() }}
|
||||
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
|
||||
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
|
||||
with:
|
||||
name: Regressions diff and postgresql log
|
||||
path: |
|
||||
|
|
|
@ -42,7 +42,7 @@ jobs:
|
|||
run: docker exec pgsql_pgsm_15 cat pmm-agent.log > ./pmm-ui-tests/tests/output/pmm-agent.log
|
||||
|
||||
- name: Upload Tests Artifacts
|
||||
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
|
||||
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
|
||||
if: success() || failure() # run this step even if previous step failed
|
||||
with:
|
||||
name: tests-artifact
|
||||
|
|
|
@ -92,7 +92,7 @@ jobs:
|
|||
|
||||
- name: Upload logs on fail
|
||||
if: ${{ failure() }}
|
||||
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
|
||||
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
|
||||
with:
|
||||
name: Regressions diff and postgresql log
|
||||
path: |
|
||||
|
|
|
@ -118,7 +118,7 @@ jobs:
|
|||
|
||||
- name: Upload logs on fail
|
||||
if: ${{ failure() }}
|
||||
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
|
||||
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
|
||||
with:
|
||||
name: Regressions diff and postgresql log
|
||||
path: |
|
||||
|
@ -140,7 +140,7 @@ jobs:
|
|||
run: make installcheck-world
|
||||
|
||||
- name: Report on installcheck-world test suites fail
|
||||
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
|
||||
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
|
||||
if: ${{ failure() }}
|
||||
with:
|
||||
name: Regressions output files of failed testsuite, and pg log
|
||||
|
|
|
@ -78,7 +78,7 @@ jobs:
|
|||
|
||||
- name: Upload logs on fail
|
||||
if: ${{ failure() }}
|
||||
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
|
||||
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
|
||||
with:
|
||||
name: Regressions diff and postgresql log
|
||||
path: |
|
||||
|
|
|
@ -92,7 +92,7 @@ jobs:
|
|||
|
||||
- name: Upload logs on fail
|
||||
if: ${{ failure() }}
|
||||
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
|
||||
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
|
||||
with:
|
||||
name: Regressions diff and postgresql log
|
||||
path: |
|
||||
|
|
|
@ -118,7 +118,7 @@ jobs:
|
|||
|
||||
- name: Upload logs on fail
|
||||
if: ${{ failure() }}
|
||||
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
|
||||
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
|
||||
with:
|
||||
name: Regressions diff and postgresql log
|
||||
path: |
|
||||
|
@ -140,7 +140,7 @@ jobs:
|
|||
run: make installcheck-world
|
||||
|
||||
- name: Report on installcheck-world test suites fail
|
||||
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
|
||||
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
|
||||
if: ${{ failure() }}
|
||||
with:
|
||||
name: Regressions output files of failed testsuite, and pg log
|
||||
|
|
|
@ -78,7 +78,7 @@ jobs:
|
|||
|
||||
- name: Upload logs on fail
|
||||
if: ${{ failure() }}
|
||||
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
|
||||
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
|
||||
with:
|
||||
name: Regressions diff and postgresql log
|
||||
path: |
|
||||
|
|
|
@ -28,14 +28,14 @@ jobs:
|
|||
persist-credentials: false
|
||||
|
||||
- name: Run analysis
|
||||
uses: ossf/scorecard-action@62b2cac7ed8198b15735ed49ab1e5cf35480ba46 # v2.4.0
|
||||
uses: ossf/scorecard-action@05b42c624433fc40578a4040d5cf5e36ddca8cde # v2.4.2
|
||||
with:
|
||||
results_file: results.sarif
|
||||
results_format: sarif
|
||||
publish_results: true
|
||||
|
||||
- name: Upload results
|
||||
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
|
||||
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
|
||||
with:
|
||||
name: SARIF file
|
||||
path: results.sarif
|
||||
|
@ -43,6 +43,6 @@ jobs:
|
|||
|
||||
# Upload the results to GitHub's code scanning dashboard (optional).
|
||||
- name: "Upload to code-scanning"
|
||||
uses: github/codeql-action/upload-sarif@9e8d0789d4a0fa9ceb6b1738f7e269594bdd67f0 # v3.28.9
|
||||
uses: github/codeql-action/upload-sarif@ce28f5bb42b7a9f2c824e633a3f6ee835bab6858 # v3.29.0
|
||||
with:
|
||||
sarif_file: results.sarif
|
||||
|
|
23
Makefile
23
Makefile
|
@ -4,7 +4,7 @@ MODULE_big = pg_stat_monitor
|
|||
OBJS = hash_query.o guc.o pg_stat_monitor.o $(WIN32RES)
|
||||
|
||||
EXTENSION = pg_stat_monitor
|
||||
DATA = pg_stat_monitor--2.0.sql pg_stat_monitor--1.0--2.0.sql pg_stat_monitor--2.0--2.1.sql
|
||||
DATA = pg_stat_monitor--2.0.sql pg_stat_monitor--1.0--2.0.sql pg_stat_monitor--2.0--2.1.sql pg_stat_monitor--2.1--2.2.sql
|
||||
|
||||
PGFILEDESC = "pg_stat_monitor - execution statistics of SQL statements"
|
||||
|
||||
|
@ -12,7 +12,26 @@ LDFLAGS_SL += $(filter -lm, $(LIBS))
|
|||
|
||||
TAP_TESTS = 1
|
||||
REGRESS_OPTS = --temp-config $(top_srcdir)/contrib/pg_stat_monitor/pg_stat_monitor.conf --inputdir=regression
|
||||
REGRESS = basic version guc pgsm_query_id functions counters relations database error_insert application_name application_name_unique top_query different_parent_queries cmd_type error rows tags user level_tracking
|
||||
REGRESS = basic \
|
||||
version \
|
||||
guc \
|
||||
pgsm_query_id \
|
||||
functions \
|
||||
counters \
|
||||
relations \
|
||||
database \
|
||||
error_insert \
|
||||
application_name \
|
||||
application_name_unique \
|
||||
top_query \
|
||||
different_parent_queries \
|
||||
cmd_type \
|
||||
error \
|
||||
rows \
|
||||
tags \
|
||||
user \
|
||||
level_tracking \
|
||||
decode_error_level
|
||||
|
||||
# Disabled because these tests require "shared_preload_libraries=pg_stat_statements",
|
||||
# which typical installcheck users do not have (e.g. buildfarm clients).
|
||||
|
|
|
@ -17,6 +17,7 @@ install_data(
|
|||
'pg_stat_monitor--2.0.sql',
|
||||
'pg_stat_monitor--1.0--2.0.sql',
|
||||
'pg_stat_monitor--2.0--2.1.sql',
|
||||
'pg_stat_monitor--2.1--2.2.sql',
|
||||
kwargs: contrib_data_args,
|
||||
)
|
||||
|
||||
|
|
|
@ -162,7 +162,8 @@ get_sources(){
|
|||
source pg-stat-monitor.properties
|
||||
#
|
||||
tar --owner=0 --group=0 --exclude=.* -czf ${PRODUCT_FULL}.tar.gz ${PRODUCT_FULL}
|
||||
echo "UPLOAD=UPLOAD/experimental/BUILDS/${PRODUCT}/${PRODUCT_FULL}/${BRANCH}/${REVISION}/${BUILD_ID}" >> pg-stat-monitor.properties
|
||||
DATE_TIMESTAMP=$(date +%F_%H-%M-%S)
|
||||
echo "UPLOAD=UPLOAD/experimental/BUILDS/${PRODUCT}/${PRODUCT_FULL}/${BRANCH}/${REVISION}/${DATE_TIMESTAMP}/${BUILD_ID}" >> pg-stat-monitor.properties
|
||||
mkdir $WORKDIR/source_tarball
|
||||
mkdir $CURDIR/source_tarball
|
||||
cp ${PRODUCT_FULL}.tar.gz $WORKDIR/source_tarball
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
/* contrib/pg_stat_monitor/pg_stat_monitor--2.1--2.2.sql */
|
||||
|
||||
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
|
||||
\echo Use "ALTER EXTENSION pg_stat_monitor" to load this file. \quit
|
||||
|
||||
CREATE OR REPLACE FUNCTION get_cmd_type (cmd_type INTEGER) RETURNS TEXT AS
|
||||
$$
|
||||
SELECT
|
||||
CASE
|
||||
WHEN cmd_type = 0 THEN ''
|
||||
WHEN cmd_type = 1 THEN 'SELECT'
|
||||
WHEN cmd_type = 2 THEN 'UPDATE'
|
||||
WHEN cmd_type = 3 THEN 'INSERT'
|
||||
WHEN cmd_type = 4 THEN 'DELETE'
|
||||
WHEN cmd_type = 5 AND current_setting('server_version_num')::int >= 150000 THEN 'MERGE'
|
||||
WHEN cmd_type = 5 AND current_setting('server_version_num')::int < 150000 THEN 'UTILITY'
|
||||
WHEN cmd_type = 6 AND current_setting('server_version_num')::int >= 150000 THEN 'UTILITY'
|
||||
WHEN cmd_type = 6 AND current_setting('server_version_num')::int < 150000 THEN 'NOTHING'
|
||||
WHEN cmd_type = 7 THEN 'NOTHING'
|
||||
END
|
||||
$$
|
||||
LANGUAGE SQL PARALLEL SAFE;
|
||||
|
||||
-- Create new function that handles error levels across PostgreSQL versions 12-17
|
||||
CREATE OR REPLACE FUNCTION decode_error_level(elevel int)
|
||||
RETURNS text
|
||||
AS $$
|
||||
SELECT CASE
|
||||
WHEN elevel = 0 THEN ''
|
||||
WHEN elevel = 10 THEN 'DEBUG5'
|
||||
WHEN elevel = 11 THEN 'DEBUG4'
|
||||
WHEN elevel = 12 THEN 'DEBUG3'
|
||||
WHEN elevel = 13 THEN 'DEBUG2'
|
||||
WHEN elevel = 14 THEN 'DEBUG1'
|
||||
WHEN elevel = 15 THEN 'LOG'
|
||||
WHEN elevel = 16 THEN 'LOG_SERVER_ONLY'
|
||||
WHEN elevel = 17 THEN 'INFO'
|
||||
WHEN elevel = 18 THEN 'NOTICE'
|
||||
WHEN elevel = 19 THEN 'WARNING'
|
||||
WHEN elevel = 20 AND current_setting('server_version_num')::int < 140000 THEN 'ERROR'
|
||||
WHEN elevel = 20 AND current_setting('server_version_num')::int >= 140000 THEN 'WARNING_CLIENT_ONLY'
|
||||
WHEN elevel = 21 AND current_setting('server_version_num')::int < 140000 THEN 'FATAL'
|
||||
WHEN elevel = 21 AND current_setting('server_version_num')::int >= 140000 THEN 'ERROR'
|
||||
WHEN elevel = 22 AND current_setting('server_version_num')::int < 140000 THEN 'PANIC'
|
||||
WHEN elevel = 22 AND current_setting('server_version_num')::int >= 140000 THEN 'FATAL'
|
||||
WHEN elevel = 23 AND current_setting('server_version_num')::int >= 140000 THEN 'PANIC'
|
||||
END;
|
||||
$$ LANGUAGE SQL PARALLEL SAFE;
|
|
@ -19,7 +19,6 @@
|
|||
#include "access/parallel.h"
|
||||
#include "nodes/pg_list.h"
|
||||
#include "utils/guc.h"
|
||||
#include <regex.h>
|
||||
#include "pgstat.h"
|
||||
#include "commands/dbcommands.h"
|
||||
#include "commands/explain.h"
|
||||
|
@ -37,7 +36,7 @@ typedef enum pgsmVersion
|
|||
|
||||
PG_MODULE_MAGIC;
|
||||
|
||||
#define BUILD_VERSION "2.1.1"
|
||||
#define BUILD_VERSION "2.2.0"
|
||||
|
||||
/* Number of output arguments (columns) for various API versions */
|
||||
#define PG_STAT_MONITOR_COLS_V1_0 52
|
||||
|
@ -96,8 +95,6 @@ uint64 *nested_queryids;
|
|||
char **nested_query_txts;
|
||||
List *lentries = NIL;
|
||||
|
||||
/* Regex object used to extract query comments. */
|
||||
static regex_t preg_query_comments;
|
||||
static char relations[REL_LST][REL_LEN];
|
||||
|
||||
static int num_relations; /* Number of relation in the query */
|
||||
|
@ -203,7 +200,7 @@ char *unpack_sql_state(int sql_state);
|
|||
|
||||
static pgsmEntry *pgsm_create_hash_entry(uint64 bucket_id, uint64 queryid, PlanInfo *plan_info);
|
||||
static void pgsm_add_to_list(pgsmEntry *entry, char *query_text, int query_len);
|
||||
static pgsmEntry *pgsm_get_entry_for_query(uint64 queryid, PlanInfo *plan_info, const char *query_text, int query_len, bool create);
|
||||
static pgsmEntry *pgsm_get_entry_for_query(uint64 queryid, PlanInfo *plan_info, const char *query_text, int query_len, bool create, CmdType cmd_type);
|
||||
static uint64 get_pgsm_query_id_hash(const char *norm_query, int len);
|
||||
|
||||
static void pgsm_cleanup_callback(void *arg);
|
||||
|
@ -280,8 +277,6 @@ static void pgsm_lock_release(pgsmSharedState *pgsm);
|
|||
void
|
||||
_PG_init(void)
|
||||
{
|
||||
int rc;
|
||||
|
||||
elog(DEBUG2, "[pg_stat_monitor] pg_stat_monitor: %s().", __FUNCTION__);
|
||||
|
||||
/*
|
||||
|
@ -309,18 +304,8 @@ _PG_init(void)
|
|||
EnableQueryId();
|
||||
#endif
|
||||
|
||||
|
||||
EmitWarningsOnPlaceholders("pg_stat_monitor");
|
||||
|
||||
/*
|
||||
* Compile regular expression for extracting out query comments only once.
|
||||
*/
|
||||
rc = regcomp(&preg_query_comments, "/\\*([^*]|[\r\n]|(\\*+([^*/]|[\r\n])))*\\*+/", REG_EXTENDED);
|
||||
if (rc != 0)
|
||||
{
|
||||
elog(ERROR, "[pg_stat_monitor] _PG_init: query comments regcomp() failed, return code=(%d).", rc);
|
||||
}
|
||||
|
||||
/*
|
||||
* Install hooks.
|
||||
*/
|
||||
|
@ -736,7 +721,7 @@ pgsm_ExecutorEnd(QueryDesc *queryDesc)
|
|||
|
||||
if (queryId != UINT64CONST(0) && queryDesc->totaltime && pgsm_enabled(nesting_level))
|
||||
{
|
||||
entry = pgsm_get_entry_for_query(queryId, plan_ptr, (char *) queryDesc->sourceText, strlen(queryDesc->sourceText), true);
|
||||
entry = pgsm_get_entry_for_query(queryId, plan_ptr, (char *) queryDesc->sourceText, strlen(queryDesc->sourceText), true, queryDesc->operation);
|
||||
if (!entry)
|
||||
{
|
||||
elog(DEBUG2, "[pg_stat_monitor] pgsm_ExecutorEnd: Failed to find entry for [%lu] %s.", queryId, queryDesc->sourceText);
|
||||
|
@ -763,6 +748,8 @@ pgsm_ExecutorEnd(QueryDesc *queryDesc)
|
|||
sys_info.stime = time_diff(rusage_end.ru_stime, rusage_start.ru_stime);
|
||||
}
|
||||
|
||||
entry->counters.info.cmd_type = queryDesc->operation;
|
||||
|
||||
pgsm_update_entry(entry, /* entry */
|
||||
NULL, /* query */
|
||||
NULL, /* comments */
|
||||
|
@ -908,7 +895,7 @@ pgsm_planner_hook(Query *parse, const char *query_string, int cursorOptions, Par
|
|||
INSTR_TIME_SET_CURRENT(start);
|
||||
|
||||
if (MemoryContextIsValid(MessageContext))
|
||||
entry = pgsm_get_entry_for_query(parse->queryId, NULL, query_string, strlen(query_string), true);
|
||||
entry = pgsm_get_entry_for_query(parse->queryId, NULL, query_string, strlen(query_string), true, parse->commandType);
|
||||
|
||||
#if PG_VERSION_NUM >= 170000
|
||||
nesting_level++;
|
||||
|
@ -1199,7 +1186,7 @@ pgsm_ProcessUtility(PlannedStmt *pstmt, const char *queryString,
|
|||
query_text = (char *) CleanQuerytext(queryString, &location, &query_len);
|
||||
|
||||
entry->pgsm_query_id = get_pgsm_query_id_hash(query_text, query_len);
|
||||
entry->counters.info.cmd_type = 0;
|
||||
entry->counters.info.cmd_type = pstmt->commandType;
|
||||
|
||||
pgsm_add_to_list(entry, query_text, query_len);
|
||||
|
||||
|
@ -1741,7 +1728,7 @@ pgsm_add_to_list(pgsmEntry *entry, char *query_text, int query_len)
|
|||
}
|
||||
|
||||
static pgsmEntry *
|
||||
pgsm_get_entry_for_query(uint64 queryid, PlanInfo *plan_info, const char *query_text, int query_len, bool create)
|
||||
pgsm_get_entry_for_query(uint64 queryid, PlanInfo *plan_info, const char *query_text, int query_len, bool create, CmdType cmd_type)
|
||||
{
|
||||
pgsmEntry *entry = NULL;
|
||||
ListCell *lc = NULL;
|
||||
|
@ -1778,6 +1765,7 @@ pgsm_get_entry_for_query(uint64 queryid, PlanInfo *plan_info, const char *query_
|
|||
* worry about these.
|
||||
*/
|
||||
entry->pgsm_query_id = get_pgsm_query_id_hash(query_text, query_len);
|
||||
entry->counters.info.cmd_type = cmd_type;
|
||||
pgsm_add_to_list(entry, (char *) query_text, query_len);
|
||||
}
|
||||
|
||||
|
@ -2087,6 +2075,11 @@ pgsm_store(pgsmEntry *entry)
|
|||
reset, /* reset */
|
||||
PGSM_STORE);
|
||||
|
||||
if (reset)
|
||||
{
|
||||
shared_hash_entry->counters.info.cmd_type = entry->counters.info.cmd_type;
|
||||
}
|
||||
|
||||
memset(&entry->counters, 0, sizeof(entry->counters));
|
||||
pgsm_lock_release(pgsm);
|
||||
}
|
||||
|
@ -2707,12 +2700,19 @@ get_pgsm_query_id_hash(const char *norm_query, int norm_len)
|
|||
*/
|
||||
if (*norm_q_iter == '/' && *(norm_q_iter + 1) == '*')
|
||||
{
|
||||
while (*norm_q_iter && *norm_q_iter != '*' && *(norm_q_iter + 1) != '/')
|
||||
while (*norm_q_iter && *(norm_q_iter + 1) && (*norm_q_iter != '*' || *(norm_q_iter + 1) != '/'))
|
||||
norm_q_iter++;
|
||||
|
||||
/* Skip the '/' if the current character is valid. */
|
||||
/*
|
||||
* Skip the end if the current character is valid. norm_q_iter
|
||||
* points to the *, we have to skip 2 characters
|
||||
*/
|
||||
if (*norm_q_iter)
|
||||
norm_q_iter++;
|
||||
if (*norm_q_iter)
|
||||
norm_q_iter++;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -3962,46 +3962,70 @@ get_histogram_timings(PG_FUNCTION_ARGS)
|
|||
return CStringGetTextDatum(text_str);
|
||||
}
|
||||
|
||||
|
||||
static bool
|
||||
append_comment_char(char *comments, size_t max_len, size_t *idx, char c)
|
||||
{
|
||||
if (*idx >= max_len)
|
||||
return false;
|
||||
|
||||
comments[*idx] = c;
|
||||
(*idx)++;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void
|
||||
extract_query_comments(const char *query, char *comments, size_t max_len)
|
||||
{
|
||||
int rc;
|
||||
size_t nmatch = 1;
|
||||
regmatch_t pmatch;
|
||||
regoff_t comment_len,
|
||||
total_len = 0;
|
||||
const char *s = query;
|
||||
size_t curr_len = 0;
|
||||
const char *q_iter = query;
|
||||
|
||||
while (total_len < max_len)
|
||||
if (!pgsm_extract_comments)
|
||||
{
|
||||
rc = regexec(&preg_query_comments, s, nmatch, &pmatch, 0);
|
||||
if (rc != 0)
|
||||
break;
|
||||
comments[0] = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
comment_len = pmatch.rm_eo - pmatch.rm_so;
|
||||
|
||||
if (total_len + comment_len > max_len)
|
||||
break; /* TODO: log error in error view, insufficient
|
||||
* space for comment. */
|
||||
|
||||
total_len += comment_len;
|
||||
|
||||
/* Not 1st iteration, append ", " before next comment. */
|
||||
if (s != query)
|
||||
while (q_iter && *q_iter)
|
||||
{
|
||||
/*
|
||||
* multiline comments, + 1 is safe even if we've reach end of string
|
||||
*/
|
||||
if (*q_iter == '/' && *(q_iter + 1) == '*')
|
||||
{
|
||||
if (total_len + 2 > max_len)
|
||||
break; /* TODO: log error in error view, insufficient
|
||||
* space for ", " + comment. */
|
||||
if (curr_len != 0)
|
||||
{
|
||||
if (!append_comment_char(comments, max_len, &curr_len, ','))
|
||||
return;
|
||||
if (!append_comment_char(comments, max_len, &curr_len, ' '))
|
||||
return;
|
||||
}
|
||||
while (*q_iter && *(q_iter + 1) && (*q_iter != '*' || *(q_iter + 1) != '/'))
|
||||
{
|
||||
if (!append_comment_char(comments, max_len, &curr_len, *q_iter))
|
||||
return;
|
||||
q_iter++;
|
||||
}
|
||||
|
||||
memcpy(comments, ", ", 2);
|
||||
comments += 2;
|
||||
total_len += 2;
|
||||
if (*q_iter)
|
||||
{
|
||||
if (!append_comment_char(comments, max_len, &curr_len, *q_iter))
|
||||
return;
|
||||
q_iter++;
|
||||
}
|
||||
if (*q_iter)
|
||||
{
|
||||
if (!append_comment_char(comments, max_len, &curr_len, *q_iter))
|
||||
return;
|
||||
q_iter++;
|
||||
}
|
||||
}
|
||||
|
||||
memcpy(comments, s + pmatch.rm_so, comment_len);
|
||||
comments += comment_len;
|
||||
s += pmatch.rm_eo;
|
||||
q_iter++;
|
||||
}
|
||||
|
||||
comments[curr_len] = 0;
|
||||
}
|
||||
|
||||
#if PG_VERSION_NUM < 140000
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# pg_stat_monitor extension
|
||||
comment = 'The pg_stat_monitor is a PostgreSQL Query Performance Monitoring tool, based on PostgreSQL contrib module pg_stat_statements. pg_stat_monitor provides aggregated statistics, client information, plan details including plan, and histogram information.'
|
||||
default_version = '2.1'
|
||||
default_version = '2.2'
|
||||
module_pathname = '$libdir/pg_stat_monitor'
|
||||
relocatable = true
|
||||
|
|
|
@ -27,16 +27,16 @@ DROP TABLE t2;
|
|||
SELECT query, cmd_type, cmd_type_text FROM pg_stat_monitor ORDER BY query COLLATE "C";
|
||||
query | cmd_type | cmd_type_text
|
||||
--------------------------------+----------+---------------
|
||||
CREATE TABLE t1 (a INTEGER) | 0 |
|
||||
CREATE TABLE t2 (b INTEGER) | 0 |
|
||||
CREATE TABLE t1 (a INTEGER) | 5 | UTILITY
|
||||
CREATE TABLE t2 (b INTEGER) | 5 | UTILITY
|
||||
DELETE FROM t1 | 4 | DELETE
|
||||
DROP TABLE t1 | 0 |
|
||||
DROP TABLE t2 | 0 |
|
||||
DROP TABLE t1 | 5 | UTILITY
|
||||
DROP TABLE t2 | 5 | UTILITY
|
||||
INSERT INTO t1 VALUES(1) | 3 | INSERT
|
||||
SELECT a FROM t1 | 1 | SELECT
|
||||
SELECT b FROM t2 FOR UPDATE | 1 | SELECT
|
||||
SELECT pg_stat_monitor_reset() | 1 | SELECT
|
||||
TRUNCATE t1 | 0 |
|
||||
TRUNCATE t1 | 5 | UTILITY
|
||||
UPDATE t1 SET a = 2 | 2 | UPDATE
|
||||
(11 rows)
|
||||
|
||||
|
|
|
@ -23,16 +23,22 @@ SELECT b FROM t2 FOR UPDATE;
|
|||
|
||||
TRUNCATE t1;
|
||||
DROP TABLE t1;
|
||||
DROP TABLE t2;
|
||||
SELECT query, cmd_type, cmd_type_text FROM pg_stat_monitor ORDER BY query COLLATE "C";
|
||||
query | cmd_type | cmd_type_text
|
||||
--------------------------------+----------+---------------
|
||||
CREATE TABLE t1 (a INTEGER) | 6 | UTILITY
|
||||
CREATE TABLE t2 (b INTEGER) | 6 | UTILITY
|
||||
DELETE FROM t1 | 4 | DELETE
|
||||
DROP TABLE t1 | 6 | UTILITY
|
||||
DROP TABLE t2 | 6 | UTILITY
|
||||
INSERT INTO t1 VALUES(1) | 3 | INSERT
|
||||
SELECT a FROM t1 | 1 | SELECT
|
||||
SELECT b FROM t2 FOR UPDATE | 1 | SELECT
|
||||
SELECT pg_stat_monitor_reset() | 1 | SELECT
|
||||
TRUNCATE t1 | 6 | UTILITY
|
||||
UPDATE t1 SET a = 2 | 2 | UPDATE
|
||||
(6 rows)
|
||||
(11 rows)
|
||||
|
||||
SELECT pg_stat_monitor_reset();
|
||||
pg_stat_monitor_reset
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
CREATE EXTENSION pg_stat_monitor;
|
||||
DO $$
|
||||
DECLARE
|
||||
i integer;
|
||||
BEGIN
|
||||
FOR i IN 10..24 LOOP
|
||||
RAISE NOTICE 'error_code: %, error_level: %', i, decode_error_level(i);
|
||||
END LOOP;
|
||||
END $$;
|
||||
NOTICE: error_code: 10, error_level: DEBUG5
|
||||
NOTICE: error_code: 11, error_level: DEBUG4
|
||||
NOTICE: error_code: 12, error_level: DEBUG3
|
||||
NOTICE: error_code: 13, error_level: DEBUG2
|
||||
NOTICE: error_code: 14, error_level: DEBUG1
|
||||
NOTICE: error_code: 15, error_level: LOG
|
||||
NOTICE: error_code: 16, error_level: LOG_SERVER_ONLY
|
||||
NOTICE: error_code: 17, error_level: INFO
|
||||
NOTICE: error_code: 18, error_level: NOTICE
|
||||
NOTICE: error_code: 19, error_level: WARNING
|
||||
NOTICE: error_code: 20, error_level: WARNING_CLIENT_ONLY
|
||||
NOTICE: error_code: 21, error_level: ERROR
|
||||
NOTICE: error_code: 22, error_level: FATAL
|
||||
NOTICE: error_code: 23, error_level: PANIC
|
||||
NOTICE: error_code: 24, error_level: <NULL>
|
||||
DROP EXTENSION pg_stat_monitor;
|
|
@ -0,0 +1,25 @@
|
|||
CREATE EXTENSION pg_stat_monitor;
|
||||
DO $$
|
||||
DECLARE
|
||||
i integer;
|
||||
BEGIN
|
||||
FOR i IN 10..24 LOOP
|
||||
RAISE NOTICE 'error_code: %, error_level: %', i, decode_error_level(i);
|
||||
END LOOP;
|
||||
END $$;
|
||||
NOTICE: error_code: 10, error_level: DEBUG5
|
||||
NOTICE: error_code: 11, error_level: DEBUG4
|
||||
NOTICE: error_code: 12, error_level: DEBUG3
|
||||
NOTICE: error_code: 13, error_level: DEBUG2
|
||||
NOTICE: error_code: 14, error_level: DEBUG1
|
||||
NOTICE: error_code: 15, error_level: LOG
|
||||
NOTICE: error_code: 16, error_level: LOG_SERVER_ONLY
|
||||
NOTICE: error_code: 17, error_level: INFO
|
||||
NOTICE: error_code: 18, error_level: NOTICE
|
||||
NOTICE: error_code: 19, error_level: WARNING
|
||||
NOTICE: error_code: 20, error_level: ERROR
|
||||
NOTICE: error_code: 21, error_level: FATAL
|
||||
NOTICE: error_code: 22, error_level: PANIC
|
||||
NOTICE: error_code: 23, error_level: <NULL>
|
||||
NOTICE: error_code: 24, error_level: <NULL>
|
||||
DROP EXTENSION pg_stat_monitor;
|
|
@ -2,7 +2,7 @@ CREATE EXTENSION pg_stat_monitor;
|
|||
SELECT pg_stat_monitor_version();
|
||||
pg_stat_monitor_version
|
||||
-------------------------
|
||||
2.1.1
|
||||
2.2.0
|
||||
(1 row)
|
||||
|
||||
DROP EXTENSION pg_stat_monitor;
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
CREATE EXTENSION pg_stat_monitor;
|
||||
|
||||
DO $$
|
||||
DECLARE
|
||||
i integer;
|
||||
BEGIN
|
||||
FOR i IN 10..24 LOOP
|
||||
RAISE NOTICE 'error_code: %, error_level: %', i, decode_error_level(i);
|
||||
END LOOP;
|
||||
END $$;
|
||||
|
||||
DROP EXTENSION pg_stat_monitor;
|
Loading…
Reference in New Issue