From 65c0153f0145b029cec360e4962b4c09bfc0bd96 Mon Sep 17 00:00:00 2001 From: Jelte Fennema-Nio Date: Sat, 13 Jan 2024 15:25:13 +0100 Subject: [PATCH v12 10/14] psql: Warn about unsupported protocol features When the requested protocol version or protocol extension parameters are not supported by the server this warns the user of that. This is a warning, and not an error, since most functionality continues to work just fine. --- src/bin/psql/command.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index bc5f431629c..84329db24cc 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -3872,6 +3872,7 @@ connection_warnings(bool in_startup) int client_ver = PG_VERSION_NUM; char cverbuf[32]; char sverbuf[32]; + int server_protocol_version; if (pset.sversion != client_ver) { @@ -3908,6 +3909,42 @@ connection_warnings(bool in_startup) formatPGVersionNumber(pset.sversion, false, sverbuf, sizeof(sverbuf))); + server_protocol_version = PQprotocolVersion(pset.db); + if (server_protocol_version < PG_PROTOCOL_FULL(PG_PROTOCOL_LATEST)) + { + int client_major = PG_PROTOCOL_MAJOR(PG_PROTOCOL_LATEST); + int client_minor = PG_PROTOCOL_MINOR(PG_PROTOCOL_LATEST); + int server_major; + int server_minor; + + if (server_protocol_version == 3) + { + server_major = 3; + server_minor = 0; + } + else + { + server_major = server_protocol_version / 10000; + server_minor = server_protocol_version / 10000; + } + printf(_("WARNING: psql protocol version %d.%d, server protocol version %d.%d.\n" + " \\parameterset will not work.\n"), + client_major, client_minor, server_major, server_minor); + } + + if (PQunsupportedProtocolExtensionParameters(pset.db)[0] != NULL) + { + const char **unsupported_parameters = PQunsupportedProtocolExtensionParameters(pset.db); + int i = 0; + + printf(_("WARNING: Server does not support the following requested protocol extension parameters:\n")); + while (unsupported_parameters[i] != NULL) + { + printf(" %s\n", unsupported_parameters[i]); + i++; + } + } + #ifdef WIN32 if (in_startup) checkWin32Codepage(); -- 2.34.1