public inbox for [email protected]
help / color / mirror / Atom feedFrom: PG Bug reporting form <[email protected]>
To: [email protected]
Cc: [email protected]
Subject: BUG #19518: Path resolution for loading a function fails, if postgres is somewhere in the path.
Date: Fri, 12 Jun 2026 19:19:31 +0000
Message-ID: <[email protected]> (raw)
The following bug has been logged on the website:
Bug reference: 19518
Logged by: Clemens Ruck
Email address: [email protected]
PostgreSQL version: 17.4
Operating system: Ubuntu 24.04.04
Description:
I encountered an incorrect $libdir expansion when loading a C-language
function from a shared library.
My directory layout is:
/home/testuser/projects/hol-postgres/
install/bin/postgres
install/lib/
/home/testuser/projects/hol-lambdas/
src/ext/lambda_udfs.so
PostgreSQL was configured with:
./configure \
--prefix=/home/testuser/projects/hol-postgres/install \
--with-llvm
The following statement fails:
CREATE OR REPLACE FUNCTION test(integer)
RETURNS integer
AS '$libdir/../../../hol-lambdas/src/ext/l_udfs.so',
'l_test'
LANGUAGE C
STRICT;
The expected expansion is:
$libdir
= /home/testuser/projects/hol-postgres/install/lib
and therefore:
$libdir/../../../hol-lambdas/src/ext/lambda_udfs.so
= /home/testuser/projects/hol-lambdas/src/ext/lambda_udfs.so
That file exists and is readable by the PostgreSQL server process.
However, PostgreSQL resolves $libdir to an unexpected directory and reports
that the shared library cannot be found.
The issue depends on the surrounding directory names. With the PostgreSQL
repository located under a differently named directory, the same build and
SQL statement resolve the expected path.
The server binary and matching pg_config are used explicitly:
/home/testuser/projects/hol-postgres/install/bin/postgres
/home/testuser/projects/hol-postgres/install/bin/pg_config
and:
pg_config --pkglibdir
reports:
/home/testuser/projects/hol-postgres/install/lib
The relevant loading path appears to be:
src/backend/utils/fmgr/dfmgr.c
load_external_function()
expand_dynamic_library_name()
internal_load_library()
$libdir is expanded from pkglib_path. That path is initialized using:
get_pkglib_path(my_exec_path, pkglib_path)
which calls make_relative_path() in src/port/path.c.
I suspect that the relocatable-installation suffix matching in
make_relative_path() incorrectly recognizes part of the actual executable
path as the compiled-in PGBINDIR suffix, causing an incorrect relocated
PKGLIBDIR to be derived.
Expected behavior:
The running server should derive:
/home/testuser/projects/hol-postgres/install/lib
as pkglib_path, consistently with the matching pg_config --pkglibdir output.
Actual behavior:
The backend derives a different path, causing $libdir references in CREATE
FUNCTION ... LANGUAGE C to fail.
I can provide the exact compiled values of PGBINDIR and PKGLIBDIR, the
resulting runtime pkglib_path, and a patch or regression test if required.
view thread (2+ messages) latest in thread
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected], [email protected]
Subject: Re: BUG #19518: Path resolution for loading a function fails, if postgres is somewhere in the path.
In-Reply-To: <[email protected]>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox