Skip to content

Commit 7204e2a

Browse files
authored
Fix build with Postgres 166 libpq-dev in debian. (#1006)
* Add build support for Postgres 16. Build passes locally with a released version of Postgres 16.0 and still builds with previous version. Still missing CI changes to pass all the test suite with PGVERSION=16. See #1005. * Allow src/bin/lib/pg/snprintf.c to build with older Postgres versions. * Allow code to build with newer Postgres releases. The internal organisation of the header files in Postgres 16 changed in a way that we can't poke into libpq-int.h anymore, when building on debian, because of the way the include/common bits are including in libpq (16) rather than in the postgresql-server-dev-16 parts. That said, we can stop looking into the internal details of libpq: - connection->last_sqlstate allowed an optimisation to conclude that the connection is okay early in the polling. - connection->auth_req_received allowed to discard authentication error as connectivity problems, but we decided in the past that we need to deploy a monitor user on the Postgres nodes anyway, to avoid flooding Postgres logs with authentication errors. * Review Citus/Postgres compat matrix. Allow building for Postgres 16 and Citus 12.1.0. * Activate CI tests for Postgres 16. * The GUC_NO_SHOW_ALL flag now requires GUC_NOT_IN_SAMPLE. * Fix previous commit.
1 parent 97de12e commit 7204e2a

File tree

14 files changed

+51
-53
lines changed

14 files changed

+51
-53
lines changed

.github/workflows/run-tests.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ jobs:
2323
- 13
2424
- 14
2525
- 15
26+
- 16
2627
TEST:
2728
- multi
2829
- single

Makefile

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ PGVERSION ?= 14
2828
BUILD_ARGS_PG11 = --build-arg PGVERSION=11 --build-arg CITUSTAG=v9.5.10
2929
BUILD_ARGS_PG12 = --build-arg PGVERSION=12 --build-arg CITUSTAG=v10.2.9
3030
BUILD_ARGS_PG13 = --build-arg PGVERSION=13 --build-arg CITUSTAG=v10.2.9
31-
BUILD_ARGS_PG14 = --build-arg PGVERSION=14 --build-arg CITUSTAG=v11.2.1
32-
BUILD_ARGS_PG15 = --build-arg PGVERSION=15 --build-arg CITUSTAG=v11.2.1
31+
BUILD_ARGS_PG14 = --build-arg PGVERSION=14 --build-arg CITUSTAG=v12.1.0
32+
BUILD_ARGS_PG15 = --build-arg PGVERSION=15 --build-arg CITUSTAG=v12.1.0
33+
BUILD_ARGS_PG16 = --build-arg PGVERSION=16 --build-arg CITUSTAG=v12.1.0
3334

3435
NOSETESTS = $(shell which nosetests3 || which nosetests)
3536

@@ -279,6 +280,9 @@ build-test-pg14: version
279280
build-test-pg15: version
280281
docker build $(BUILD_ARGS_PG15) --target test -t $(TEST_CONTAINER_NAME):pg15 .
281282

283+
build-test-pg16: version
284+
docker build $(BUILD_ARGS_PG16) --target test -t $(TEST_CONTAINER_NAME):pg16 .
285+
282286

283287
build-test-image: build-test-pg$(PGVERSION) ;
284288

@@ -310,10 +314,13 @@ build-pg14: build-test-pg14
310314
build-pg15: build-test-pg15
311315
docker build $(BUILD_ARGS_PG15) -t $(CONTAINER_NAME):pg15 .
312316

313-
build: build-pg11 build-pg12 build-pg13 build-pg14 build-pg15 ;
317+
build-pg16: build-test-pg16
318+
docker build $(BUILD_ARGS_PG16) -t $(CONTAINER_NAME):pg16 .
319+
320+
build: build-pg11 build-pg12 build-pg13 build-pg14 build-pg15 build-pg16 ;
314321

315322
build-check:
316-
for v in 11 12 13 14 15; do \
323+
for v in 11 12 13 14 15 16; do \
317324
docker run --rm -t pg_auto_failover_test:pg$$v pg_autoctl version --json | jq ".pg_version" | xargs echo $$v: ; \
318325
done
319326

src/bin/lib/pg/snprintf.c

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Copyright (c) 1983, 1995, 1996 Eric P. Allman
33
* Copyright (c) 1988, 1993
44
* The Regents of the University of California. All rights reserved.
5-
* Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group
5+
* Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group
66
*
77
* Redistribution and use in source and binary forms, with or without
88
* modification, are permitted provided that the following conditions
@@ -739,12 +739,8 @@ find_arguments(const char *format, va_list args,
739739
int longflag;
740740
int fmtpos;
741741
int i;
742-
int last_dollar;
743-
PrintfArgType argtypes[PG_NL_ARGMAX + 1];
744-
745-
/* Initialize to "no dollar arguments known" */
746-
last_dollar = 0;
747-
MemSet(argtypes, 0, sizeof(argtypes));
742+
int last_dollar = 0; /* Init to "no dollar arguments known" */
743+
PrintfArgType argtypes[PG_NL_ARGMAX + 1] = {0};
748744

749745
/*
750746
* This loop must accept the same format strings as the one in dopr().
@@ -985,8 +981,8 @@ fmtptr(const void *value, PrintfTarget *target)
985981
int vallen;
986982
char convert[64];
987983

988-
/* we rely on regular C library's sprintf to do the basic conversion */
989-
vallen = sprintf(convert, "%p", value);
984+
/* we rely on regular C library's snprintf to do the basic conversion */
985+
vallen = snprintf(convert, sizeof(convert), "%p", value);
990986
if (vallen < 0)
991987
target->failed = true;
992988
else
@@ -1136,11 +1132,11 @@ fmtfloat(double value, char type, int forcesign, int leftjust,
11361132
int padlen; /* amount to pad with spaces */
11371133

11381134
/*
1139-
* We rely on the regular C library's sprintf to do the basic conversion,
1135+
* We rely on the regular C library's snprintf to do the basic conversion,
11401136
* then handle padding considerations here.
11411137
*
11421138
* The dynamic range of "double" is about 1E+-308 for IEEE math, and not
1143-
* too wildly more than that with other hardware. In "f" format, sprintf
1139+
* too wildly more than that with other hardware. In "f" format, snprintf
11441140
* could therefore generate at most 308 characters to the left of the
11451141
* decimal point; while we need to allow the precision to get as high as
11461142
* 308+17 to ensure that we don't truncate significant digits from very
@@ -1192,14 +1188,14 @@ fmtfloat(double value, char type, int forcesign, int leftjust,
11921188
fmt[2] = '*';
11931189
fmt[3] = type;
11941190
fmt[4] = '\0';
1195-
vallen = sprintf(convert, fmt, prec, value);
1191+
vallen = snprintf(convert, sizeof(convert), fmt, prec, value);
11961192
}
11971193
else
11981194
{
11991195
fmt[0] = '%';
12001196
fmt[1] = type;
12011197
fmt[2] = '\0';
1202-
vallen = sprintf(convert, fmt, value);
1198+
vallen = snprintf(convert, sizeof(convert), fmt, value);
12031199
}
12041200
if (vallen < 0)
12051201
goto fail;
@@ -1328,7 +1324,7 @@ pg_strfromd(char *str, size_t count, int precision, double value)
13281324
fmt[2] = '*';
13291325
fmt[3] = 'g';
13301326
fmt[4] = '\0';
1331-
vallen = sprintf(convert, fmt, precision, value);
1327+
vallen = snprintf(convert, sizeof(convert), fmt, precision, value);
13321328
if (vallen < 0)
13331329
{
13341330
target.failed = true;

src/bin/pg_autoctl/azure.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1585,9 +1585,9 @@ azure_fetch_resource_list(const char *group, AzureRegionResources *azRegion)
15851585
}
15861586
else if (streq(type, "Microsoft.Compute/virtualMachines"))
15871587
{
1588-
int index = azure_node_index_from_name(group, name);
1588+
int idx = azure_node_index_from_name(group, name);
15891589

1590-
strlcpy(azRegion->vmArray[index].name, name, NAMEDATALEN);
1590+
strlcpy(azRegion->vmArray[idx].name, name, NAMEDATALEN);
15911591

15921592
log_info("Found existing VM \"%s\"", name);
15931593
}

src/bin/pg_autoctl/cli_common.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1524,7 +1524,7 @@ keeper_cli_print_version(int argc, char **argv)
15241524
"pg_autoctl extension version %s\n",
15251525
PG_AUTOCTL_EXTENSION_VERSION);
15261526
fformat(stdout, "compiled with %s\n", PG_VERSION_STR);
1527-
fformat(stdout, "compatible with Postgres 11, 12, 13, 14, and 15\n");
1527+
fformat(stdout, "compatible with Postgres 11, 12, 13, 14, 15, and 16\n");
15281528
}
15291529

15301530
exit(0);

src/bin/pg_autoctl/pgctl.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1837,9 +1837,6 @@ pg_log_startup(const char *pgdata, int logLevel)
18371837
*/
18381838
if (pgLogFileMtime >= pgStartupMtime)
18391839
{
1840-
char *fileContents;
1841-
long fileSize;
1842-
18431840
log_level(pathLogLevel,
18441841
"Postgres logs from \"%s\":", pgLogFilePath);
18451842

src/bin/pg_autoctl/pgsetup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ get_pgpid(PostgresSetup *pgSetup, bool pgIsNotRunningIsOk)
501501
}
502502
else
503503
{
504-
int logLevel = pgIsNotRunningIsOk ? LOG_DEBUG : LOG_WARN;
504+
logLevel = pgIsNotRunningIsOk ? LOG_DEBUG : LOG_WARN;
505505

506506
log_level(logLevel,
507507
"Read a stale pid in \"postmaster.pid\": %d", pid);

src/bin/pg_autoctl/primary_standby.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1239,7 +1239,7 @@ postgres_maybe_do_crash_recovery(LocalPostgresServer *postgres)
12391239
* Now stop Postgres by just killing our child process, and
12401240
* wait until the child process has finished with waitpid().
12411241
*/
1242-
int wpid, status;
1242+
int wpid;
12431243

12441244
do {
12451245
if (kill(fpid, SIGTERM) != 0)

src/bin/pg_autoctl/watch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1430,7 +1430,7 @@ print_event(WatchContext *context, EventColPolicy *policy, int index, int r, int
14301430
case EVENT_COLUMN_TYPE_DESCRIPTION:
14311431
{
14321432
char *text = event->description;
1433-
int len = strlen(text);
1433+
len = strlen(text);
14341434

14351435
/* when KEY_END is used, ensure we see the end of text */
14361436
if (context->move == WATCH_MOVE_FOCUS_END)

src/monitor/health_check_worker.c

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
#include "fmgr.h"
3838
#include "lib/stringinfo.h"
3939
#include "libpq-fe.h"
40-
#include "libpq-int.h"
4140
#include "libpq/pqsignal.h"
4241
#include "poll.h"
4342
#include "sys/time.h"
@@ -58,8 +57,6 @@
5857
"connect_timeout=%u"
5958
#define MAX_CONN_INFO_SIZE 1024
6059

61-
#define CANNOT_CONNECT_NOW "57P03"
62-
6360

6461
typedef enum
6562
{
@@ -939,20 +936,9 @@ ManageHealthCheck(HealthCheck *healthCheck, struct timeval currentTime)
939936
break;
940937
}
941938

942-
/* This logic is taken from libpq's internal_ping (fe-connect.c) */
943939
pollingStatus = PQconnectPoll(connection);
944-
char *sqlstate = connection->last_sqlstate;
945-
bool receivedSqlstate = (sqlstate != NULL && strlen(sqlstate) == 5);
946-
bool cannotConnectNowSqlstate = (receivedSqlstate &&
947-
strcmp(sqlstate, CANNOT_CONNECT_NOW) == 0);
948-
949-
if (pollingStatus == PGRES_POLLING_OK ||
950-
951-
/* an auth request means pg is running */
952-
connection->auth_req_received ||
953940

954-
/* any error but CANNOT_CONNECT means the db is accepting connections */
955-
(receivedSqlstate && !cannotConnectNowSqlstate))
941+
if (pollingStatus == PGRES_POLLING_OK)
956942
{
957943
PQfinish(connection);
958944

0 commit comments

Comments
 (0)