From 270181dbc9874da12b437da115d3d8f242a06cd8 Mon Sep 17 00:00:00 2001 From: Leonid Borchuk Date: Tue, 16 Jan 2024 18:46:49 +0300 Subject: [PATCH] Add ifdef instructions to support PG 94 --- Makefile | 2 +- logerrors--2.1.sql | 19 +++++++++++++++++++ logerrors.c | 15 +++++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 logerrors--2.1.sql diff --git a/Makefile b/Makefile index baa2bd9..46ed32c 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ EXTENSION = logerrors MODULE_big = logerrors -DATA = logerrors--1.0.sql logerrors--1.0--1.1.sql logerrors--1.1--2.0.sql logerrors--2.0--2.1.sql +DATA = logerrors--1.0.sql logerrors--1.0--1.1.sql logerrors--1.1--2.0.sql logerrors--2.0--2.1.sql logerrors--2.1.sql OBJS = logerrors.o PG_CONFIG = pg_config PGXS := $(shell $(PG_CONFIG) --pgxs) diff --git a/logerrors--2.1.sql b/logerrors--2.1.sql new file mode 100644 index 0000000..16bd8f0 --- /dev/null +++ b/logerrors--2.1.sql @@ -0,0 +1,19 @@ +\echo Use "CREATE EXTENSION logerrors" to load this file. \quit + +CREATE FUNCTION pg_log_errors_stats( + OUT time_interval integer, + OUT type text, + OUT message text, + OUT count integer, + OUT username text, + OUT database text, + OUT sqlstate text +) + RETURNS SETOF record +AS 'MODULE_PATHNAME', 'pg_log_errors_stats' + LANGUAGE C STRICT; + +CREATE FUNCTION pg_log_errors_reset() + RETURNS void +AS 'MODULE_PATHNAME', 'pg_log_errors_reset' + LANGUAGE C STRICT; diff --git a/logerrors.c b/logerrors.c index b1cc70b..6ca3f39 100644 --- a/logerrors.c +++ b/logerrors.c @@ -21,6 +21,9 @@ #include "access/htup_details.h" #include "commands/dbcommands.h" #include "utils/resowner.h" +#if PG_VERSION_NUM < 100000 +#include "port/atomics.h" +#endif #include "constants.h" @@ -283,7 +286,11 @@ logerrors_main(Datum main_arg) int rc; /* Wait necessary amount of time */ rc = WaitLatch(&MyProc->procLatch, +#if PG_VERSION_NUM < 100000 + WL_LATCH_SET | WL_TIMEOUT | WL_POSTMASTER_DEATH, interval); +#else WL_LATCH_SET | WL_TIMEOUT | WL_POSTMASTER_DEATH, interval, PG_WAIT_EXTENSION); +#endif ResetLatch(&MyProc->procLatch); /* Emergency bailout if postmaster has died */ @@ -436,7 +443,11 @@ logerrors_shmem_startup(void) { error_names_hashtable = ShmemInitHash("logerrors hash", error_codes_count, error_codes_count, &ctl, +#if PG_VERSION_NUM < 100000 + HASH_ELEM); +#else HASH_ELEM | HASH_BLOBS); +#endif global_variables = ShmemInitStruct("logerrors global_variables", sizeof(GlobalInfo), &found); @@ -631,7 +642,11 @@ pg_log_errors_stats(PG_FUNCTION_ARGS) ctl.keysize = sizeof(MessageInfo); ctl.entrysize = sizeof(CounterHashElem); /* an unshared hashtable can be expanded on-the-fly */ +#if PG_VERSION_NUM < 100000 + counters_hashtable = hash_create("counters hashtable", 1, &ctl, HASH_ELEM); +#else counters_hashtable = hash_create("counters hashtable", 1, &ctl, HASH_ELEM | HASH_BLOBS); +#endif per_query_ctx = rsinfo->econtext->ecxt_per_query_memory; oldcontext = MemoryContextSwitchTo(per_query_ctx);