Allow extensions to define tablespace options

From: Zsolt Parragi <zsolt(dot)parragi(at)percona(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Allow extensions to define tablespace options
Date: 2026-11-18 20:45:58
Message-ID: CAN4CZFNxu5BgBge12C=f3JV9LdZvUiG+pQHOCutATewSywzFuw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hello

Extensions can define their own reloptions for index AMs, and there is
an ongoing thread about doing the same for table AMs [1], but
tablespaces only accept the 4 built-in options.

The support is partially already there, add_*_reloption() already
accepts RELOPT_KIND_TABLESPACE, but any extension-defined option fails
with "reloption ... not found in parse table".

I think there are many possible use cases for extensions using
per-tablespace settings. Mine is pg_tde where we could use it to store
encryption options/policies, as talespaces are a more natural fit for
encryption than global settings or per table options.

The attached patch series completes the support for this:

0001 makes pg_dumpall quote tablespace option names and values like
pg_dump does for relation options - the current way only works because
all built-in tablespace options are numeric.

0002 is the actual feature, with a few restrictions that differ from
index AM options:

* Tablespaces are global, while extensions are per database, so there
is no way to record a dependency between a tablespace and the
extension providing its options, and every backend has to know about
them. Because of this, tablespace options can only be registered from
shared_preload_libraries.
* Names have to be qualified like custom GUC names, as in
"my_extension.my_option", as all extensions share one namespace with
the built-in options. They also have to be shorter than NAMEDATALEN,
otherwise they wouldn't survive being dumped as a single quoted
identifier.
* Both checks are FATAL, like the similar checks for custom GUCs, as
the module might be already partly initialized when it fails.

0003 adds a pg_upgrade check: without it, if the new cluster doesn't
preload the extension pg_upgrade fails late when restoring the global
objects. To do this it introduces 2 SQL functions:
pg_validate_tablespace_options checks an options array the way CREATE
TABLESPACE would, and pg_available_tablespace_options lists the
options the server knows about. The second one isn't strictly required
for pg_upgrade, but I think it is useful on its own, as currently
there is no way to see which tablespace options are available. This
patch needs a catversion bump.

Some limitations that I think are acceptable, but I want to point them out:

* While the extension isn't loaded, its options are ignored, but ALTER
TABLESPACE SET/RESET fails on tablespaces that have them set, unless
the RESET removes all of them.
* pg_dumpall skips pg_default and pg_global, options set on these
tablespaces are lost on dump/restore and pg_upgrade. This is an
existing issue with the built-in options too, so I left it out of this
series.

[1]: https://postgr.es/m/ea1c4d33-0780-473c-96dc-1468cf733a04@dunslane.net

Attachment Content-Type Size
v1-0003-Check-tablespace-options-in-pg_upgrade.patch application/octet-stream 24.9 KB
v1-0001-Quote-tablespace-options-in-pg_dumpall.patch application/octet-stream 1.9 KB
v1-0002-Allow-extensions-to-define-tablespace-options.patch application/octet-stream 23.9 KB

Browse pgsql-hackers by date

  From Date Subject
Next Message Zsolt Parragi 2026-11-18 20:50:36 Long reloption values are truncated by pg_dump and pg_get_indexdef()
Previous Message Tristan Partin 2026-11-18 20:35:48 Re: Add ids to catalog/view columns in documentation