pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Chao Li <li.evan.chao@gmail.com>
To: Mahendrakar Srinivasarao <mahendrakarforpg@gmail.com>
Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Cc: peter@eisentraut.org
Cc: mths.dev@pm.me
Subject: Re: [PATCH] doc: Fix description of relative extension "directory" setting
Date: Mon, 2 Nov 2026 15:56:45 +0800
Message-ID: <E514FFA2-2F41-4B34-93AE-2BF61C61E623@gmail.com> (raw)
In-Reply-To: <CABkiuWpGiLzDg4D8zRBJ6DHnwYgHqkFxz2gDstXgeOdzh6bdZQ@mail.gmail.com>
References: <CABkiuWpGiLzDg4D8zRBJ6DHnwYgHqkFxz2gDstXgeOdzh6bdZQ@mail.gmail.com>



> On Oct 31, 2026, at 11:47, Mahendrakar Srinivasarao <mahendrakarforpg@gmail.com> wrote:
> 
> Hi,
> 
> Since PostgreSQL 18 (commit 81eaaa2c41d), the documentation of the
> extension control file "directory" parameter says a relative path is
> "relative to the directory where the control file was found".
> However, that doesn't match the code: a relative path is resolved
> against SHAREDIR,
> or against the extension_control_path element in which the control
> file was found, i.e. the parent of that "extension" directory.
> 
> Repro steps on master:
> 
>  /tmp/repro/extension/dir_doc_probe.control:
>      default_version = '1.0'
>      directory = 'scripts'
>      relocatable = true
> 
>  /tmp/repro/scripts/dir_doc_probe--1.0.sql:
>      CREATE TABLE dir_doc_probe_result (origin text);
>      INSERT INTO dir_doc_probe_result VALUES ('installation base');
> 
>  /tmp/repro/extension/scripts/dir_doc_probe--1.0.sql:
>      CREATE TABLE dir_doc_probe_result (origin text);
>      INSERT INTO dir_doc_probe_result VALUES ('control-file directory');
> 
>  BEGIN;
>  SET LOCAL extension_control_path = '/tmp/repro';
>  CREATE EXTENSION dir_doc_probe;
>  SELECT origin FROM dir_doc_probe_result;
>        origin
>  -------------------
>   installation base
>  (1 row)
>  ROLLBACK;
> 
> The attached patch restores the pre-18 wording, extended to cover
> extension_control_path, and clarifies the extension_control_path
> description accordingly.
> <0001-doc-Fix-description-of-relative-extension-directory.patch>

Thanks for the patch. I think the fix is going in the right direction.

The relevant code is:
```
static char *
get_extension_script_directory(ExtensionControlFile *control)
{
	/*
	 * The directory parameter can be omitted, absolute, or relative to the
	 * installation's base directory, which can be the sharedir or a custom
	 * path that was set via extension_control_path. It depends on where the
	 * .control file was found.
	 */
	if (!control->directory)
		return pstrdup(control->control_dir);

	if (is_absolute_path(control->directory))
		return pstrdup(control->directory);

	Assert(control->basedir != NULL);
	return psprintf("%s/%s", control->basedir, control->directory);
}
```

When control->directory is a relative path, it is resolved relative to control->basedir, which is either SHAREDIR or the corresponding path element in extension_control_path.

In the patch:
```
-        the directory where the control file was found.  By default,
-        the script files are looked for in the same directory where the
-        control file was found.
+        the installation's <literal>SHAREDIR</literal> directory, or to the
+        <xref linkend="guc-extension-control-path"/> element in which the
+        control file was found.  The default behavior is equivalent to
+        specifying <literal>directory = 'extension'</literal>.
```

I think the phrase "the extension_control_path element in which the control file was found" is a little misleading.

For example, suppose we have:
```
extension_control_path = '/opt/myext/share’
```

The primary control file is found in /opt/myext/share/extension. If it specifies:
```
directory = ‘scripts’
```

the scripts will be loaded from /opt/myext/share/scripts, not /opt/myext/share/extension/scripts.

So, saying "in which the control file was found" might suggest /opt/myext/share/extension, rather than /opt/myext/share. 

I would suggest wording it more explicitly, like:
```
or to the extension_control_path element used to locate the primary control file.
```

Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/










view thread (7+ messages)  latest in thread

Message-ID: <E514FFA2-2F41-4B34-93AE-2BF61C61E623@gmail.com>
Permalink:  ../E514FFA2-2F41-4B34-93AE-2BF61C61E623@gmail.com/
Also on:    postgresql.org/message-id/E514FFA2-2F41-4B34-93AE-2BF61C61E623@gmail.com

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-hackers@postgresql.org
  Cc: li.evan.chao@gmail.com, mahendrakarforpg@gmail.com, peter@eisentraut.org, mths.dev@pm.me
  Subject: Re: [PATCH] doc: Fix description of relative extension "directory" setting
  In-Reply-To: <E514FFA2-2F41-4B34-93AE-2BF61C61E623@gmail.com>
  References: <CABkiuWpGiLzDg4D8zRBJ6DHnwYgHqkFxz2gDstXgeOdzh6bdZQ@mail.gmail.com> <E514FFA2-2F41-4B34-93AE-2BF61C61E623@gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox