From 1350b29337a67f3b93ddf42f4dfc634b28b5c6b9 Mon Sep 17 00:00:00 2001 From: Jelte Fennema-Nio Date: Sat, 13 Jan 2024 15:25:13 +0100 Subject: [PATCH v7 08/12] 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 881ec34f6fb..eb281606435 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -3800,6 +3800,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) { @@ -3836,6 +3837,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 not work.\n"), + client_major, client_minor, server_major, server_minor); + } + + if (PQunsupportedProtocolExtensions(pset.db)[0] != NULL) + { + const char **unsupported_parameters = PQunsupportedProtocolExtensions(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