Re: extension_control_path: ignore empty elements and deduplicate directories

From: "Matheus Alcantara" <matheusssilv97(at)gmail(dot)com>
To: "Chao Li" <li(dot)evan(dot)chao(at)gmail(dot)com>, "Peter Eisentraut" <peter(at)eisentraut(dot)org>
Cc: "Andres Freund" <andres(at)anarazel(dot)de>, "PostgreSQL-development" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: extension_control_path: ignore empty elements and deduplicate directories
Date: 2026-12-02 14:32:10
Message-ID: DNABJ73KA5F4.2S5PIME4P6BUX@gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tue Dec 1, 2026 at 12:06 AM -03, Chao Li wrote:
> I’ve updated the patch to v7 following your suggestion. In summary, the behavior on master is:
>
> * Empty and relative path elements are rejected when the path is used.
> * An entirely empty string is still interpreted as "$system".
> * When checking for an extension to provide an unknown-language hint, empty and relative path elements generate warnings and are skipped. The original unknown-language error is preserved, and a hint can still be provided using the remaining directories.
>
> For the v18 backpatch, the main changes are the same, but empty and relative path elements are ignored with a warning.
>

Thanks for the new version!

I've tested v7 on master and and the v7-REL-18 patches and both seems to
work as expected. Although I have a few comments:

1: On 18 the warning is raised for each invalid element every time
get_extension_control_directories() is called, so the same warning can
show up more than once in a single command:

SET extension_control_path = ':';
SELECT count(*) FROM pg_available_extensions;
WARNING: zero-length component in parameter "extension_control_path"
WARNING: zero-length component in parameter "extension_control_path"

SET extension_control_path = '$system:';
CREATE EXTENSION earthdistance CASCADE;
WARNING: zero-length component in parameter "extension_control_path"
NOTICE: installing required extension "cube"
WARNING: zero-length component in parameter "extension_control_path"

ALTER EXTENSION UPDATE also shows the warning twice. It's minor and I'm
not sure it's worth complicating the code to avoid it, but I think that
it's worh to mention it.

2: The error/warning messages don't say which element is invalid:

ERROR: component in parameter "extension_control_path" is not an absolute path

This is the same message that find_in_path() uses for
dynamic_library_path, but with a long path it could be hard to find the
wrong element. Maybe we could add the element in a DETAIL message?

Also, I'm wondering if a check hook would fit better for master. Since
we now reject empty and relative elements, we could validate them when
the value is set, similar to what check_search_path() does for
search_path: it only checks the syntax of the list, not whether the
schemas exist. Here the check hook would only check that each element
is non-empty and is either $system or an absolute path, and nonexistent
directories would still be accepted.

I think this has some wins:

- A wrong value is reported when it's set (SET, ALTER SYSTEM, ALTER
ROLE/DATABASE ... SET) and not only later when someone runs CREATE
EXTENSION or queries pg_available_extensions.
- An invalid value can never be in use, so we don't need the elevel
parameter on get_extension_control_directories(), and we don't need
the special case for the unknown-language hint either.
- It's easy to say which element is wrong, e.g:

ERROR: invalid value for parameter "extension_control_path": "$system:rel"
DETAIL: Path element "rel" is not absolute.

The side effect is that a server with an invalid value in
postgresql.conf would not start after an upgrade to the new major
version.

For 18 and 19 we could keep the approach of v7-REL-18 (warn and skip),
since a check hook can't raise an error on back branches. It just
wouldn't need the elevel parameter on
get_extension_control_directories(): every caller passes WARNING there,
so we can use WARNING directly and keep the function signature as is.

Thoughts?

--
Matheus Alcantara
EDB: https://www.enterprisedb.com

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Baji Shaik 2026-12-02 14:35:33 Re: postgres_fdw: statistics import can silently fall back to sampling across encodings
Previous Message Shrihari Danawe 2026-12-02 14:25:17 Re: pg_rewind WAL segments deletion pitfall