From ed9f977cc760fea29386e8c8758eb32ea5baa19e Mon Sep 17 00:00:00 2001 From: Sergey Shinderuk Date: Fri, 14 Jun 2024 10:08:16 +0300 Subject: [PATCH] Drop support for Postgres < 12 --- .travis.yml | 1 - README.md | 8 ++++---- collector.c | 8 +------- compat.h | 24 +----------------------- pg_wait_sampling.c | 43 +++++-------------------------------------- pg_wait_sampling.h | 7 +------ 6 files changed, 12 insertions(+), 79 deletions(-) diff --git a/.travis.yml b/.travis.yml index ffbb0da..1fce04a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,7 +7,6 @@ env: - PG_MAJOR=14 - PG_MAJOR=13 - PG_MAJOR=12 -- PG_MAJOR=11 before_script: - curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add - - echo "deb https://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" | sudo tee -a /etc/apt/sources.list diff --git a/README.md b/README.md index d8b03dc..cac5be7 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ Introduction ------------ -PostgreSQL 9.6+ provides an information about current wait event of particular +PostgreSQL provides information about current wait event of particular process. However, in order to gather descriptive statistics of server behavior user have to sample current wait event multiple times. `pg_wait_sampling` is an extension for collecting sampling statistics of wait @@ -47,7 +47,7 @@ PostgreSQL installation. It is available from [github](https://github.com/postgrespro/pg_wait_sampling) under the same license as [PostgreSQL](http://www.postgresql.org/about/licence/) -and supports PostgreSQL 9.6+. +and supports PostgreSQL 12+. Installation ------------ @@ -58,10 +58,10 @@ repository: https://download.postgresql.org/pub/repos/ Manual build ------------ -`pg_wait_sampling` is PostgreSQL extension which requires PostgreSQL 9.6 or +`pg_wait_sampling` is PostgreSQL extension which requires PostgreSQL 12 or higher. Before build and install you should ensure following: - * PostgreSQL version is 9.6 or higher. + * PostgreSQL version is 12 or higher. * You have development package of PostgreSQL installed or you built PostgreSQL from source. * Your PATH variable is configured so that `pg_config` command available, or diff --git a/collector.c b/collector.c index dcb9695..29e8ee2 100644 --- a/collector.c +++ b/collector.c @@ -423,15 +423,9 @@ pgws_collector_main(Datum main_arg) * Wait until next sample time or request to do something through * shared memory. */ -#if PG_VERSION_NUM >= 100000 rc = WaitLatch(&MyProc->procLatch, WL_LATCH_SET | WL_TIMEOUT | WL_POSTMASTER_DEATH, Min(history_period - (int)history_diff, profile_period - (int)profile_diff), PG_WAIT_EXTENSION); -#else - rc = WaitLatch(&MyProc->procLatch, WL_LATCH_SET | WL_TIMEOUT | WL_POSTMASTER_DEATH, - Min(history_period - (int)history_diff, - profile_period - (int)profile_diff)); -#endif if (rc & WL_POSTMASTER_DEATH) proc_exit(1); @@ -482,7 +476,7 @@ pgws_collector_main(Datum main_arg) default: Assert(false); } - shm_mq_detach_compat(mqh, pgws_collector_mq); + shm_mq_detach(mqh); } else if (request == PROFILE_RESET) { diff --git a/compat.h b/compat.h index 5fcc814..72a63ab 100644 --- a/compat.h +++ b/compat.h @@ -17,26 +17,6 @@ #include "storage/shm_mq.h" #include "utils/guc_tables.h" -static inline TupleDesc -CreateTemplateTupleDescCompat(int nattrs, bool hasoid) -{ -#if PG_VERSION_NUM >= 120000 - return CreateTemplateTupleDesc(nattrs); -#else - return CreateTemplateTupleDesc(nattrs, hasoid); -#endif -} - -static inline void -shm_mq_detach_compat(shm_mq_handle *mqh, shm_mq *mq) -{ -#if PG_VERSION_NUM >= 100000 - shm_mq_detach(mqh); -#else - shm_mq_detach(mq); -#endif -} - static inline shm_mq_result shm_mq_send_compat(shm_mq_handle *mqh, Size nbytes, const void *data, bool nowait, bool force_flush) @@ -61,11 +41,9 @@ InitPostgresCompat(const char *in_dbname, Oid dboid, #elif PG_VERSION_NUM >= 150000 InitPostgres(in_dbname, dboid, username, useroid, load_session_libraries, override_allow_connections, out_dbname); -#elif PG_VERSION_NUM >= 110000 +#else InitPostgres(in_dbname, dboid, username, useroid, out_dbname, override_allow_connections); -#else - InitPostgres(in_dbname, dboid, username, useroid, out_dbname); #endif } diff --git a/pg_wait_sampling.c b/pg_wait_sampling.c index 268b40e..72e2fb4 100644 --- a/pg_wait_sampling.c +++ b/pg_wait_sampling.c @@ -18,9 +18,7 @@ #include "optimizer/planner.h" #include "pgstat.h" #include "postmaster/autovacuum.h" -#if PG_VERSION_NUM >= 120000 #include "replication/walsender.h" -#endif #include "storage/ipc.h" #include "storage/pg_shmem.h" #include "storage/procarray.h" @@ -119,9 +117,7 @@ get_max_procs_count(void) * Starting with pg12, wal senders aren't part of MaxConnections anymore * and have to be accounted for. */ -#if PG_VERSION_NUM >= 120000 count += max_wal_senders; -#endif /* pg 12+ */ #endif /* pg 15- */ /* End of MaxBackends calculation. */ @@ -331,16 +327,9 @@ pgws_shmem_startup(void) else { toc = shm_toc_attach(PG_WAIT_SAMPLING_MAGIC, pgws); - -#if PG_VERSION_NUM >= 100000 pgws_collector_hdr = shm_toc_lookup(toc, 0, false); pgws_collector_mq = shm_toc_lookup(toc, 1, false); pgws_proc_queryids = shm_toc_lookup(toc, 2, false); -#else - pgws_collector_hdr = shm_toc_lookup(toc, 0); - pgws_collector_mq = shm_toc_lookup(toc, 1); - pgws_proc_queryids = shm_toc_lookup(toc, 2); -#endif } shmem_initialized = true; @@ -366,7 +355,7 @@ static void pgws_cleanup_callback(int code, Datum arg) { elog(DEBUG3, "pg_wait_sampling cleanup: detaching shm_mq and releasing queue lock"); - shm_mq_detach_compat(recv_mqh, recv_mq); + shm_mq_detach(recv_mqh); LockRelease(&queueTag, ExclusiveLock, false); } @@ -463,7 +452,7 @@ pg_wait_sampling_get_current(PG_FUNCTION_ARGS) params->ts = GetCurrentTimestamp(); funcctx->user_fctx = params; - tupdesc = CreateTemplateTupleDescCompat(4, false); + tupdesc = CreateTemplateTupleDesc(4); TupleDescInitEntry(tupdesc, (AttrNumber) 1, "pid", INT4OID, -1, 0); TupleDescInitEntry(tupdesc, (AttrNumber) 2, "type", @@ -651,7 +640,7 @@ receive_array(SHMRequest request, Size item_size, Size *count) PG_END_ENSURE_ERROR_CLEANUP(pgws_cleanup_callback, 0); /* We still have to detach and release lock during normal operation. */ - shm_mq_detach_compat(recv_mqh, recv_mq); + shm_mq_detach(recv_mqh); LockRelease(&queueTag, ExclusiveLock, false); return result; @@ -684,7 +673,7 @@ pg_wait_sampling_get_profile(PG_FUNCTION_ARGS) funcctx->max_calls = profile->count; /* Make tuple descriptor */ - tupdesc = CreateTemplateTupleDescCompat(5, false); + tupdesc = CreateTemplateTupleDesc(5); TupleDescInitEntry(tupdesc, (AttrNumber) 1, "pid", INT4OID, -1, 0); TupleDescInitEntry(tupdesc, (AttrNumber) 2, "type", @@ -801,7 +790,7 @@ pg_wait_sampling_get_history(PG_FUNCTION_ARGS) funcctx->max_calls = history->count; /* Make tuple descriptor */ - tupdesc = CreateTemplateTupleDescCompat(5, false); + tupdesc = CreateTemplateTupleDesc(5); TupleDescInitEntry(tupdesc, (AttrNumber) 1, "pid", INT4OID, -1, 0); TupleDescInitEntry(tupdesc, (AttrNumber) 2, "sample_ts", @@ -879,17 +868,6 @@ pgws_planner_hook(Query *parse, if (MyProc) { int i = MyProc - ProcGlobal->allProcs; -#if PG_VERSION_NUM >= 110000 - /* - * since we depend on queryId we need to check that its size - * is uint64 as we coded in pg_wait_sampling - */ - StaticAssertExpr(sizeof(parse->queryId) == sizeof(uint64), - "queryId size is not uint64"); -#else - StaticAssertExpr(sizeof(parse->queryId) == sizeof(uint32), - "queryId size is not uint32"); -#endif if (!pgws_proc_queryids[i]) pgws_proc_queryids[i] = parse->queryId; @@ -921,17 +899,6 @@ pgws_ExecutorStart(QueryDesc *queryDesc, int eflags) if (MyProc) { i = MyProc - ProcGlobal->allProcs; -#if PG_VERSION_NUM >= 110000 - /* - * since we depend on queryId we need to check that its size - * is uint64 as we coded in pg_wait_sampling - */ - StaticAssertExpr(sizeof(queryDesc->plannedstmt->queryId) == sizeof(uint64), - "queryId size is not uint64"); -#else - StaticAssertExpr(sizeof(queryDesc->plannedstmt->queryId) == sizeof(uint32), - "queryId size is not uint32"); -#endif if (!pgws_proc_queryids[i]) pgws_proc_queryids[i] = queryDesc->plannedstmt->queryId; } diff --git a/pg_wait_sampling.h b/pg_wait_sampling.h index 29425fc..79297e8 100644 --- a/pg_wait_sampling.h +++ b/pg_wait_sampling.h @@ -10,12 +10,7 @@ #ifndef __PG_WAIT_SAMPLING_H__ #define __PG_WAIT_SAMPLING_H__ -#include - -/* Check PostgreSQL version */ -#if PG_VERSION_NUM < 90600 - #error "You are trying to build pg_wait_sampling with PostgreSQL version lower than 9.6. Please, check you environment." -#endif +#include "postgres.h" #include "storage/proc.h" #include "storage/shm_mq.h"