Skip to content

Commit

Permalink
Merge pull request #24 from leborchuk/PG94Support
Browse files Browse the repository at this point in the history
Add ifdef instructions to support PG 94
  • Loading branch information
munakoiso authored Jan 17, 2024
2 parents 18d9795 + a603c89 commit 3c15333
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
28 changes: 28 additions & 0 deletions logerrors--2.1.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
\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;

CREATE FUNCTION pg_slow_log_stats(
OUT slow_count integer,
OUT reset_time timestamp
)
RETURNS SETOF record
AS 'MODULE_PATHNAME', 'pg_slow_log_stats'
LANGUAGE C STRICT;
GRANT ALL ON FUNCTION pg_slow_log_stats() TO public;
15 changes: 15 additions & 0 deletions logerrors.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 3c15333

Please sign in to comment.