PATCH: Report libpq version and configuration

From: Craig Ringer <craig(dot)ringer(at)enterprisedb(dot)com>
To: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: PATCH: Report libpq version and configuration
Date: 2020-10-26 12:56:57
Message-ID: CAGRY4nybirHxTn2P9B_EY_dT3iMk+rPtGwBf_E1+v+-Eanr5sw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

The attached patches propose new interfaces for exposing more configuration
and versioning information from libpq at runtime. They are to be used by
applications to obtain finer grained information about libpq's
configuration (SSL, GSSAPI, etc), to identify libpq binaries, and for
applications that use libpq to report diagnostic information

Patch 0001 adds PQlibInfo(), which returns an array of key/value
description items reporting on configuration like the full version string,
SSL support, gssapi support, thread safety, default port and default unix
socket path. This is for application use and application diagnostics. It
also adds PQlibInfoPrint() which dumps PQlibInfo() keys/values to stdout.
See the commit message in patch 0001 for details.

Patch 0002 exposes LIBPQ_VERSION_STR, LIBPQ_VERSION_NUM and
LIBPQ_CONFIGURE_ARGS symbols in the dynamic symbol table. These can be
accessed by a debugger even when the library cannot be loaded or executed,
and unlike macros are available even in a stripped executable. So they can
be used to identify a libpq binary found in the wild. Their storage is
shared with PQlibInfo()'s static data, so they only cost three symbol table
entries.

$ cp ./build/src/interfaces/libpq/libpq.so libpq.so.stripped
$ strip libpq.so.stripped
$ gdb -batch -ex 'p (int)LIBPQ_VERSION_NUM' -ex 'p (const char
*)LIBPQ_VERSION_STR' -ex 'p (const char *)LIBPQ_CONFIGURE_ARGS'
./libpq.so.stripped
$1 = 140000
$2 = 0x285f0 "PostgreSQL 14devel on x86_64-pc-linux-gnu, ...."
$3 = 0x28660 " '--cache-file=config.cache-'
'--prefix=/home/craig/pg/master' '--enable-debug' '--enable-cassert'
'--enable-tap-tests' '--enable-dtrace' 'CC=/usr/lib64/ccache/gcc'
'CFLAGS=-Og -ggdb3' ..."

Patch 0003 allows libpq.so to be executed directly from the command line to
print its version, configure arguments etc exactly as PQlibInfoPrint()
would output them. This is only enabled on x64 linux for now but can be
extended to other targets quite simply.

$ ./build/src/interfaces/libpq/libpq.so
VERSION_NUM: 140000
VERSION: PostgreSQL 14devel on x86_64-pc-linux-gnu, compiled by gcc (GCC)
10.2.1 20200723 (Red Hat 10.2.1-1), 64-bit
CONFIGURE_ARGS: '--cache-file=config.cache-'
'--prefix=/home/craig/pg/master' '--enable-debug' '--enable-cassert'
'--enable-tap-tests' '--enable-dtrace' 'CC=/usr/lib64/ccache/gcc'
'CFLAGS=-Og -ggdb3' 'CPPFLAGS=' 'CPP=/usr/lib64/ccache/gcc -E'
USE_SSL: 0
ENABLE_GSS: 0
ENABLE_THREAD_SAFETY: 1
HAVE_UNIX_SOCKETS: 1
DEFAULT_PGSOCKET_DIR: /tmp
DEF_PGPORT: 5432

Attachment Content-Type Size
v1-0002-Add-libpq-version-information-to-dynamic-symbol-t.patch text/x-patch 3.4 KB
v1-0003-On-x64-linux-run-PQlibInfoPrint-when-libpq.so-is-.patch text/x-patch 3.1 KB
v1-0001-Add-PQlibInfo-to-get-runtime-configuration-of-cur.patch text/x-patch 16.2 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Jürgen Purtz 2020-10-26 13:33:35 Re: Additional Chapter for Tutorial
Previous Message Julien Rouhaud 2020-10-26 12:33:58 Re: Collation versioning