Skip to content

Commit 54fafca

Browse files
authored
Fix monitor extension for new Postgres 15 shared memory hooks. (#922)
* Fix monitor extension for new Postgres 15 shared memory hooks. * Per review, we didn't introduce PG_VERSION_15 in this project.
1 parent 856d4e7 commit 54fafca

5 files changed

Lines changed: 44 additions & 4 deletions

File tree

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ RUN apt-get update \
5353
&& rm -rf /var/lib/apt/lists/*
5454

5555
RUN curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
56-
RUN echo "deb http://apt.postgresql.org/pub/repos/apt buster-pgdg main" > /etc/apt/sources.list.d/pgdg.list
56+
RUN echo "deb http://apt.postgresql.org/pub/repos/apt buster-pgdg main ${PGVERSION}" > /etc/apt/sources.list.d/pgdg.list
5757

5858
# bypass initdb of a "main" cluster
5959
RUN echo 'create_main_cluster = false' | sudo tee -a /etc/postgresql-common/createcluster.conf
@@ -132,7 +132,7 @@ RUN apt-get update \
132132
&& rm -rf /var/lib/apt/lists/*
133133

134134
RUN curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
135-
RUN echo "deb http://apt.postgresql.org/pub/repos/apt buster-pgdg main" > /etc/apt/sources.list.d/pgdg.list
135+
RUN echo "deb http://apt.postgresql.org/pub/repos/apt buster-pgdg main ${PGVERSION}" > /etc/apt/sources.list.d/pgdg.list
136136

137137
# bypass initdb of a "main" cluster
138138
RUN echo 'create_main_cluster = false' | sudo tee -a /etc/postgresql-common/createcluster.conf

Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,9 @@ build-test-pg13:
174174
build-test-pg14:
175175
docker build --build-arg PGVERSION=14 --target test -t $(TEST_CONTAINER_NAME):pg14 .
176176

177+
build-test-pg15:
178+
docker build --build-arg PGVERSION=15 --target test -t $(TEST_CONTAINER_NAME):pg15 .
179+
177180
run-test: build-test-pg$(PGVERSION)
178181
docker run \
179182
--name $(TEST_CONTAINER_NAME) \
@@ -197,6 +200,9 @@ build-pg13: build-test-pg13
197200
build-pg14: build-test-pg14
198201
docker build --build-arg PGVERSION=14 $(DOCKER_BUILD_OPTS) -t $(CONTAINER_NAME):pg14 .
199202

203+
build-pg15: build-test-pg15
204+
docker build --build-arg PGVERSION=15 $(DOCKER_BUILD_OPTS) -t $(CONTAINER_NAME):pg15 .
205+
200206
build: build-pg10 build-pg11 build-pg12 build-pg13 build-pg14 ;
201207

202208
build-check:

src/monitor/health_check.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ extern int HealthCheckTimeout;
5252
extern int HealthCheckMaxRetries;
5353
extern int HealthCheckRetryDelay;
5454

55+
extern size_t HealthCheckWorkerShmemSize(void);
5556

5657
extern void InitializeHealthCheckWorker(void);
5758
extern void HealthCheckWorkerMain(Datum arg);

src/monitor/health_check_worker.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,6 @@ static int CompareTimes(struct timeval *leftTime, struct timeval *rightTime);
139139
static int SubtractTimes(struct timeval base, struct timeval subtract);
140140
static struct timeval AddTimeMillis(struct timeval base, uint32 additionalMs);
141141
static void LatchWait(long timeoutMs);
142-
static size_t HealthCheckWorkerShmemSize(void);
143142
static void HealthCheckWorkerShmemInit(void);
144143

145144

@@ -196,10 +195,13 @@ pg_auto_failover_monitor_sighup(SIGNAL_ARGS)
196195
void
197196
InitializeHealthCheckWorker(void)
198197
{
198+
/* on PG 15, we use shmem_request_hook_type */
199+
#if PG_VERSION_NUM < 150000
199200
if (!IsUnderPostmaster)
200201
{
201202
RequestAddinShmemSpace(HealthCheckWorkerShmemSize());
202203
}
204+
#endif
203205

204206
prev_shmem_startup_hook = shmem_startup_hook;
205207
shmem_startup_hook = HealthCheckWorkerShmemInit;
@@ -1086,7 +1088,7 @@ AddTimeMillis(struct timeval base, uint32 additionalMs)
10861088
/*
10871089
* HealthCheckWorkerShmemSize computes how much shared memory is required.
10881090
*/
1089-
static size_t
1091+
size_t
10901092
HealthCheckWorkerShmemSize(void)
10911093
{
10921094
Size size = 0;

src/monitor/pg_auto_failover.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@
3838
ProcessUtility_hook_type PreviousProcessUtility_hook = NULL;
3939

4040

41+
#if PG_VERSION_NUM >= 150000
42+
static shmem_request_hook_type prev_shmem_request_hook = NULL;
43+
static void pgautofailover_shmem_request(void);
44+
#endif
45+
46+
4147
void _PG_init(void);
4248
static void StartMonitorNode(void);
4349

@@ -77,10 +83,35 @@ _PG_init(void)
7783
"configuration variable in postgresql.conf.")));
7884
}
7985

86+
#if PG_VERSION_NUM >= 150000
87+
prev_shmem_request_hook = shmem_request_hook;
88+
shmem_request_hook = pgautofailover_shmem_request;
89+
#endif
90+
8091
StartMonitorNode();
8192
}
8293

8394

95+
#if PG_VERSION_NUM >= 150000
96+
97+
/*
98+
* Requests any additional shared memory required for pg_auto_failover health
99+
* check worker.
100+
*/
101+
static void
102+
pgautofailover_shmem_request(void)
103+
{
104+
if (prev_shmem_request_hook)
105+
{
106+
prev_shmem_request_hook();
107+
}
108+
109+
RequestAddinShmemSpace(HealthCheckWorkerShmemSize());
110+
}
111+
112+
113+
#endif
114+
84115
/*
85116
* StartMonitor register GUCs for monitor mode and starts the
86117
* health check worker.

0 commit comments

Comments
 (0)