Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wY7te-0004tq-0o for pgsql-bugs@arkaria.postgresql.org; Fri, 12 Jun 2026 19:50:30 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wY7tc-001cQA-0z for pgsql-bugs@arkaria.postgresql.org; Fri, 12 Jun 2026 19:50:28 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wY7QI-001b1D-2E for pgsql-bugs@lists.postgresql.org; Fri, 12 Jun 2026 19:20:10 +0000 Received: from mahout.postgresql.org ([2001:4800:3e1:1::227]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wY7QF-000000004Ak-3atl for pgsql-bugs@lists.postgresql.org; Fri, 12 Jun 2026 19:20:10 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=postgresql.org; s=20171124; h=Message-ID:Date:Reply-To:Cc:From:To:Subject: Content-Transfer-Encoding:MIME-Version:Content-Type:Sender:Content-ID: Content-Description:In-Reply-To:References; bh=00QvylTO6h44KPVs14wnHiyvL2BpTeYyr5yYO0j5ZeE=; b=sOXqmqLaf1bu8IfKEI7XazvEK8 Q7SDMDQwkDyaPkH7Orh5f1dIR6G/ZGxcFa3RGs2et6/PxkDvyiOWYXSHYLEiKDy/Rn5EYvv23tVvx 1HLYCDxnohOixRmZIxR6AYF6jGVSDnNJFIt19Gh96uclRQBNzWY5ZZFqckhrNIa26jtz/fkB/zEYS AGi3q/FqIrtCJ5dHTOgfcwY2JDYv91aNEk5Gl+HvgaUDKoTV2CpjFy/e90VAVfXaNd2aI/l4I4XEy slCeVU4j5Wos3NOV7FIToe/ri92LxcXWkjfarrY2MBOsKC/YqyTeL+lRMvFNZOgeKK9mMHRkQwR4E jlP0H/Eg==; Received: from wrigleys.postgresql.org ([2a02:16a8:dc51::60]) by mahout.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wY7QC-0009kg-0g for pgsql-bugs@lists.postgresql.org; Fri, 12 Jun 2026 19:20:06 +0000 Received: from localhost ([127.0.0.1] helo=wrigleys.postgresql.org) by wrigleys.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wY7QB-000Im9-05 for pgsql-bugs@lists.postgresql.org; Fri, 12 Jun 2026 19:20:03 +0000 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: BUG #19518: Path resolution for loading a function fails, if postgres is somewhere in the path. To: pgsql-bugs@lists.postgresql.org From: PG Bug reporting form Cc: clemens.ruck@t-online.de Reply-To: clemens.ruck@t-online.de, pgsql-bugs@lists.postgresql.org Date: Fri, 12 Jun 2026 19:19:31 +0000 Message-ID: <19518-902fabd6a225851f@postgresql.org> X-Auto-Response-Suppress: All Auto-Submitted: auto-generated List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk The following bug has been logged on the website: Bug reference: 19518 Logged by: Clemens Ruck Email address: clemens.ruck@t-online.de PostgreSQL version: 17.4 Operating system: Ubuntu 24.04.04 Description: =20 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=3D/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 =3D /home/testuser/projects/hol-postgres/install/lib and therefore: $libdir/../../../hol-lambdas/src/ext/lambda_udfs.so =3D /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.