Compare commits

..

1 Commits
main ... 2.1.1

Author SHA1 Message Date
Artem Gavrilov c27eba36d3 PG-1370 Bump PGSM version up to 2.1.1 2025-02-21 23:53:04 +02:00
38 changed files with 98 additions and 259 deletions

2
.github/CODEOWNERS vendored
View File

@ -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 @dutow
* @artemgavrilov @darkfronza

View File

@ -3,7 +3,7 @@ description: File a bug report
labels: ["bug"]
assignees:
- artemgavrilov
- dutow
- darkfronza
body:
- type: markdown

View File

@ -3,7 +3,7 @@ description: Suggest an idea for this project
labels: ["feature"]
assignees:
- artemgavrilov
- dutow
- darkfronza
body:
- type: markdown

View File

@ -113,7 +113,7 @@ jobs:
working-directory: src/pg_stat_monitor
- name: Upload
uses: codecov/codecov-action@18283e04ce6e62d37312384ff67231eb8fd56d24 # v5.4.3
uses: codecov/codecov-action@13ce06bfc6bbe3ecf90edbbf1bc32fe5978ca1d3 # v5.3.1
with:
verbose: true
token: ${{ secrets.CODECOV_TOKEN }}
@ -130,7 +130,7 @@ jobs:
- name: Upload logs on fail
if: ${{ failure() }}
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
with:
name: Regressions diff and postgresql log
path: |

View File

@ -118,7 +118,7 @@ jobs:
- name: Upload logs on fail
if: ${{ failure() }}
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
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@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
if: ${{ failure() }}
with:
name: Regressions output files of failed testsuite, and pg log

View File

@ -80,7 +80,7 @@ jobs:
- name: Upload logs on fail
if: ${{ failure() }}
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
with:
name: Regressions diff and postgresql log
path: |

View File

@ -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@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
if: success() || failure() # run this step even if previous step failed
with:
name: tests-artifact

View File

@ -95,7 +95,7 @@ jobs:
- name: Upload logs on fail
if: ${{ failure() }}
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
with:
name: Regressions diff and postgresql log
path: |

View File

@ -117,7 +117,7 @@ jobs:
- name: Upload logs on fail
if: ${{ failure() }}
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
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@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
if: ${{ failure() }}
with:
name: Regressions output files of failed testsuite, and pg log

View File

@ -79,7 +79,7 @@ jobs:
- name: Upload logs on fail
if: ${{ failure() }}
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
with:
name: Regressions diff and postgresql log
path: |

View File

@ -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@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
if: success() || failure() # run this step even if previous step failed
with:
name: tests-artifact

View File

@ -92,7 +92,7 @@ jobs:
- name: Upload logs on fail
if: ${{ failure() }}
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
with:
name: Regressions diff and postgresql log
path: |

View File

@ -118,7 +118,7 @@ jobs:
- name: Upload logs on fail
if: ${{ failure() }}
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
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@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
if: ${{ failure() }}
with:
name: Regressions output files of failed testsuite, and pg log

View File

@ -78,7 +78,7 @@ jobs:
- name: Upload logs on fail
if: ${{ failure() }}
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
with:
name: Regressions diff and postgresql log
path: |

View File

@ -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@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
if: success() || failure() # run this step even if previous step failed
with:
name: tests-artifact

View File

@ -92,7 +92,7 @@ jobs:
- name: Upload logs on fail
if: ${{ failure() }}
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
with:
name: Regressions diff and postgresql log
path: |

View File

@ -118,7 +118,7 @@ jobs:
- name: Upload logs on fail
if: ${{ failure() }}
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
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@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
if: ${{ failure() }}
with:
name: Regressions output files of failed testsuite, and pg log

View File

@ -78,7 +78,7 @@ jobs:
- name: Upload logs on fail
if: ${{ failure() }}
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
with:
name: Regressions diff and postgresql log
path: |

View File

@ -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@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
if: success() || failure() # run this step even if previous step failed
with:
name: tests-artifact

View File

@ -92,7 +92,7 @@ jobs:
- name: Upload logs on fail
if: ${{ failure() }}
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
with:
name: Regressions diff and postgresql log
path: |

View File

@ -118,7 +118,7 @@ jobs:
- name: Upload logs on fail
if: ${{ failure() }}
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
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@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
if: ${{ failure() }}
with:
name: Regressions output files of failed testsuite, and pg log

View File

@ -78,7 +78,7 @@ jobs:
- name: Upload logs on fail
if: ${{ failure() }}
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
with:
name: Regressions diff and postgresql log
path: |

View File

@ -92,7 +92,7 @@ jobs:
- name: Upload logs on fail
if: ${{ failure() }}
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
with:
name: Regressions diff and postgresql log
path: |

View File

@ -118,7 +118,7 @@ jobs:
- name: Upload logs on fail
if: ${{ failure() }}
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
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@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
if: ${{ failure() }}
with:
name: Regressions output files of failed testsuite, and pg log

View File

@ -78,7 +78,7 @@ jobs:
- name: Upload logs on fail
if: ${{ failure() }}
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
with:
name: Regressions diff and postgresql log
path: |

View File

@ -28,14 +28,14 @@ jobs:
persist-credentials: false
- name: Run analysis
uses: ossf/scorecard-action@05b42c624433fc40578a4040d5cf5e36ddca8cde # v2.4.2
uses: ossf/scorecard-action@62b2cac7ed8198b15735ed49ab1e5cf35480ba46 # v2.4.0
with:
results_file: results.sarif
results_format: sarif
publish_results: true
- name: Upload results
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
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@ce28f5bb42b7a9f2c824e633a3f6ee835bab6858 # v3.29.0
uses: github/codeql-action/upload-sarif@9e8d0789d4a0fa9ceb6b1738f7e269594bdd67f0 # v3.28.9
with:
sarif_file: results.sarif

View File

@ -4,7 +4,7 @@ MODULE_big = pg_stat_monitor
OBJS = hash_query.o guc.o pg_stat_monitor.o $(WIN32RES)
EXTENSION = pg_stat_monitor
DATA = pg_stat_monitor--2.0.sql pg_stat_monitor--1.0--2.0.sql pg_stat_monitor--2.0--2.1.sql pg_stat_monitor--2.1--2.2.sql
DATA = pg_stat_monitor--2.0.sql pg_stat_monitor--1.0--2.0.sql pg_stat_monitor--2.0--2.1.sql
PGFILEDESC = "pg_stat_monitor - execution statistics of SQL statements"
@ -12,26 +12,7 @@ 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 \
decode_error_level
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
# Disabled because these tests require "shared_preload_libraries=pg_stat_statements",
# which typical installcheck users do not have (e.g. buildfarm clients).

View File

@ -17,7 +17,6 @@ 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,
)

View File

@ -162,8 +162,7 @@ get_sources(){
source pg-stat-monitor.properties
#
tar --owner=0 --group=0 --exclude=.* -czf ${PRODUCT_FULL}.tar.gz ${PRODUCT_FULL}
DATE_TIMESTAMP=$(date +%F_%H-%M-%S)
echo "UPLOAD=UPLOAD/experimental/BUILDS/${PRODUCT}/${PRODUCT_FULL}/${BRANCH}/${REVISION}/${DATE_TIMESTAMP}/${BUILD_ID}" >> pg-stat-monitor.properties
echo "UPLOAD=UPLOAD/experimental/BUILDS/${PRODUCT}/${PRODUCT_FULL}/${BRANCH}/${REVISION}/${BUILD_ID}" >> pg-stat-monitor.properties
mkdir $WORKDIR/source_tarball
mkdir $CURDIR/source_tarball
cp ${PRODUCT_FULL}.tar.gz $WORKDIR/source_tarball

View File

@ -1,48 +0,0 @@
/* contrib/pg_stat_monitor/pg_stat_monitor--2.1--2.2.sql */
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "ALTER EXTENSION pg_stat_monitor" to load this file. \quit
CREATE OR REPLACE FUNCTION get_cmd_type (cmd_type INTEGER) RETURNS TEXT AS
$$
SELECT
CASE
WHEN cmd_type = 0 THEN ''
WHEN cmd_type = 1 THEN 'SELECT'
WHEN cmd_type = 2 THEN 'UPDATE'
WHEN cmd_type = 3 THEN 'INSERT'
WHEN cmd_type = 4 THEN 'DELETE'
WHEN cmd_type = 5 AND current_setting('server_version_num')::int >= 150000 THEN 'MERGE'
WHEN cmd_type = 5 AND current_setting('server_version_num')::int < 150000 THEN 'UTILITY'
WHEN cmd_type = 6 AND current_setting('server_version_num')::int >= 150000 THEN 'UTILITY'
WHEN cmd_type = 6 AND current_setting('server_version_num')::int < 150000 THEN 'NOTHING'
WHEN cmd_type = 7 THEN 'NOTHING'
END
$$
LANGUAGE SQL PARALLEL SAFE;
-- Create new function that handles error levels across PostgreSQL versions 12-17
CREATE OR REPLACE FUNCTION decode_error_level(elevel int)
RETURNS text
AS $$
SELECT CASE
WHEN elevel = 0 THEN ''
WHEN elevel = 10 THEN 'DEBUG5'
WHEN elevel = 11 THEN 'DEBUG4'
WHEN elevel = 12 THEN 'DEBUG3'
WHEN elevel = 13 THEN 'DEBUG2'
WHEN elevel = 14 THEN 'DEBUG1'
WHEN elevel = 15 THEN 'LOG'
WHEN elevel = 16 THEN 'LOG_SERVER_ONLY'
WHEN elevel = 17 THEN 'INFO'
WHEN elevel = 18 THEN 'NOTICE'
WHEN elevel = 19 THEN 'WARNING'
WHEN elevel = 20 AND current_setting('server_version_num')::int < 140000 THEN 'ERROR'
WHEN elevel = 20 AND current_setting('server_version_num')::int >= 140000 THEN 'WARNING_CLIENT_ONLY'
WHEN elevel = 21 AND current_setting('server_version_num')::int < 140000 THEN 'FATAL'
WHEN elevel = 21 AND current_setting('server_version_num')::int >= 140000 THEN 'ERROR'
WHEN elevel = 22 AND current_setting('server_version_num')::int < 140000 THEN 'PANIC'
WHEN elevel = 22 AND current_setting('server_version_num')::int >= 140000 THEN 'FATAL'
WHEN elevel = 23 AND current_setting('server_version_num')::int >= 140000 THEN 'PANIC'
END;
$$ LANGUAGE SQL PARALLEL SAFE;

View File

@ -19,6 +19,7 @@
#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"
@ -36,7 +37,7 @@ typedef enum pgsmVersion
PG_MODULE_MAGIC;
#define BUILD_VERSION "2.2.0"
#define BUILD_VERSION "2.1.1"
/* Number of output arguments (columns) for various API versions */
#define PG_STAT_MONITOR_COLS_V1_0 52
@ -95,6 +96,8 @@ 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 */
@ -200,7 +203,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, CmdType cmd_type);
static pgsmEntry *pgsm_get_entry_for_query(uint64 queryid, PlanInfo *plan_info, const char *query_text, int query_len, bool create);
static uint64 get_pgsm_query_id_hash(const char *norm_query, int len);
static void pgsm_cleanup_callback(void *arg);
@ -277,6 +280,8 @@ static void pgsm_lock_release(pgsmSharedState *pgsm);
void
_PG_init(void)
{
int rc;
elog(DEBUG2, "[pg_stat_monitor] pg_stat_monitor: %s().", __FUNCTION__);
/*
@ -304,8 +309,18 @@ _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.
*/
@ -721,7 +736,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, queryDesc->operation);
entry = pgsm_get_entry_for_query(queryId, plan_ptr, (char *) queryDesc->sourceText, strlen(queryDesc->sourceText), true);
if (!entry)
{
elog(DEBUG2, "[pg_stat_monitor] pgsm_ExecutorEnd: Failed to find entry for [%lu] %s.", queryId, queryDesc->sourceText);
@ -748,8 +763,6 @@ 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 */
@ -895,7 +908,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, parse->commandType);
entry = pgsm_get_entry_for_query(parse->queryId, NULL, query_string, strlen(query_string), true);
#if PG_VERSION_NUM >= 170000
nesting_level++;
@ -1186,7 +1199,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 = pstmt->commandType;
entry->counters.info.cmd_type = 0;
pgsm_add_to_list(entry, query_text, query_len);
@ -1728,7 +1741,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, CmdType cmd_type)
pgsm_get_entry_for_query(uint64 queryid, PlanInfo *plan_info, const char *query_text, int query_len, bool create)
{
pgsmEntry *entry = NULL;
ListCell *lc = NULL;
@ -1765,7 +1778,6 @@ 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);
}
@ -2075,11 +2087,6 @@ 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);
}
@ -2700,19 +2707,12 @@ 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 + 1) && (*norm_q_iter != '*' || *(norm_q_iter + 1) != '/'))
while (*norm_q_iter && *norm_q_iter != '*' && *(norm_q_iter + 1) != '/')
norm_q_iter++;
/*
* Skip the end if the current character is valid. norm_q_iter
* points to the *, we have to skip 2 characters
*/
/* Skip the '/' if the current character is valid. */
if (*norm_q_iter)
norm_q_iter++;
if (*norm_q_iter)
norm_q_iter++;
continue;
}
/*
@ -3962,70 +3962,46 @@ 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)
{
size_t curr_len = 0;
const char *q_iter = query;
int rc;
size_t nmatch = 1;
regmatch_t pmatch;
regoff_t comment_len,
total_len = 0;
const char *s = query;
if (!pgsm_extract_comments)
while (total_len < max_len)
{
comments[0] = 0;
return;
}
rc = regexec(&preg_query_comments, s, nmatch, &pmatch, 0);
if (rc != 0)
break;
while (q_iter && *q_iter)
{
/*
* multiline comments, + 1 is safe even if we've reach end of string
*/
if (*q_iter == '/' && *(q_iter + 1) == '*')
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)
{
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++;
}
if (total_len + 2 > max_len)
break; /* TODO: log error in error view, insufficient
* space for ", " + comment. */
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, ", ", 2);
comments += 2;
total_len += 2;
}
q_iter++;
memcpy(comments, s + pmatch.rm_so, comment_len);
comments += comment_len;
s += pmatch.rm_eo;
}
comments[curr_len] = 0;
}
#if PG_VERSION_NUM < 140000

View File

@ -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.2'
default_version = '2.1'
module_pathname = '$libdir/pg_stat_monitor'
relocatable = true

View File

@ -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) | 5 | UTILITY
CREATE TABLE t2 (b INTEGER) | 5 | UTILITY
CREATE TABLE t1 (a INTEGER) | 0 |
CREATE TABLE t2 (b INTEGER) | 0 |
DELETE FROM t1 | 4 | DELETE
DROP TABLE t1 | 5 | UTILITY
DROP TABLE t2 | 5 | UTILITY
DROP TABLE t1 | 0 |
DROP TABLE t2 | 0 |
INSERT INTO t1 VALUES(1) | 3 | INSERT
SELECT a FROM t1 | 1 | SELECT
SELECT b FROM t2 FOR UPDATE | 1 | SELECT
SELECT pg_stat_monitor_reset() | 1 | SELECT
TRUNCATE t1 | 5 | UTILITY
TRUNCATE t1 | 0 |
UPDATE t1 SET a = 2 | 2 | UPDATE
(11 rows)

View File

@ -23,22 +23,16 @@ 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
(11 rows)
(6 rows)
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset

View File

@ -1,25 +0,0 @@
CREATE EXTENSION pg_stat_monitor;
DO $$
DECLARE
i integer;
BEGIN
FOR i IN 10..24 LOOP
RAISE NOTICE 'error_code: %, error_level: %', i, decode_error_level(i);
END LOOP;
END $$;
NOTICE: error_code: 10, error_level: DEBUG5
NOTICE: error_code: 11, error_level: DEBUG4
NOTICE: error_code: 12, error_level: DEBUG3
NOTICE: error_code: 13, error_level: DEBUG2
NOTICE: error_code: 14, error_level: DEBUG1
NOTICE: error_code: 15, error_level: LOG
NOTICE: error_code: 16, error_level: LOG_SERVER_ONLY
NOTICE: error_code: 17, error_level: INFO
NOTICE: error_code: 18, error_level: NOTICE
NOTICE: error_code: 19, error_level: WARNING
NOTICE: error_code: 20, error_level: WARNING_CLIENT_ONLY
NOTICE: error_code: 21, error_level: ERROR
NOTICE: error_code: 22, error_level: FATAL
NOTICE: error_code: 23, error_level: PANIC
NOTICE: error_code: 24, error_level: <NULL>
DROP EXTENSION pg_stat_monitor;

View File

@ -1,25 +0,0 @@
CREATE EXTENSION pg_stat_monitor;
DO $$
DECLARE
i integer;
BEGIN
FOR i IN 10..24 LOOP
RAISE NOTICE 'error_code: %, error_level: %', i, decode_error_level(i);
END LOOP;
END $$;
NOTICE: error_code: 10, error_level: DEBUG5
NOTICE: error_code: 11, error_level: DEBUG4
NOTICE: error_code: 12, error_level: DEBUG3
NOTICE: error_code: 13, error_level: DEBUG2
NOTICE: error_code: 14, error_level: DEBUG1
NOTICE: error_code: 15, error_level: LOG
NOTICE: error_code: 16, error_level: LOG_SERVER_ONLY
NOTICE: error_code: 17, error_level: INFO
NOTICE: error_code: 18, error_level: NOTICE
NOTICE: error_code: 19, error_level: WARNING
NOTICE: error_code: 20, error_level: ERROR
NOTICE: error_code: 21, error_level: FATAL
NOTICE: error_code: 22, error_level: PANIC
NOTICE: error_code: 23, error_level: <NULL>
NOTICE: error_code: 24, error_level: <NULL>
DROP EXTENSION pg_stat_monitor;

View File

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

View File

@ -1,12 +0,0 @@
CREATE EXTENSION pg_stat_monitor;
DO $$
DECLARE
i integer;
BEGIN
FOR i IN 10..24 LOOP
RAISE NOTICE 'error_code: %, error_level: %', i, decode_error_level(i);
END LOOP;
END $$;
DROP EXTENSION pg_stat_monitor;