Allow table AMs to define their own reloptions

Поиск
Список
Период
Сортировка
Искать

Allow table AMs to define their own reloptions

От:
Julien Tachoires <julien@tachoires.me>
Дата:
Вложения:
Hi,

With the help of the new TAM routine 'relation_options', table access 
methods can with this patch define their own reloptions 
parser/validator.

These reloptions can be set via the following commands:
1. CREATE TABLE ... USING table_am
       WITH (option1='value1', option2='value2');
2. ALTER TABLE ...
       SET (option1 'value1', option2 'value2');
3. ALTER TABLE ... SET ACCESS METHOD table_am
       OPTIONS (option1 'value1', option2 'value2');

When changing table's access method, the settings inherited from the 
former TAM can be dropped (if not supported by the new TAM) via: DROP 
option, or, updated via: SET option 'value'.

Currently, tables using different TAMs than heap are able to use heap's 
reloptions (fillfactor, toast_tuple_target, etc...). With this patch 
applied, this is not the case anymore: if the TAM needs to have access 
to similar settings to heap ones, they have to explicitly define them.

The 2nd patch file includes a new test module 'dummy_table_am' which 
implements a dummy table access method utilized to exercise TAM 
reloptions. This test module is strongly based on what we already have 
in 'dummy_index_am'. 'dummy_table_am' provides a complete example of TAM 
reloptions definition.

This work is directly derived from SadhuPrasad's patch here [2]. Others 
attempts were posted here [1] and here [3].

[1] https://www.postgresql.org/message-id/flat/429fb58fa3218221bb17c7bf9e70e1aa6cfc6b5d.camel%40j-davis.com
[2] https://www.postgresql.org/message-id/flat/CAFF0-CG4KZHdtYHMsonWiXNzj16gWZpduXAn8yF7pDDub+GQMg@mail.gmail.com
[3] https://www.postgresql.org/message-id/flat/AMUA1wBBBxfc3tKRLLdU64rb.1.1683276279979.Hmail.wuhao%40hashdata.cn

-- 
Julien Tachoires

Re: Allow table AMs to define their own reloptions

От:
Julien Tachoires <julien@tachoires.me>
Дата:
Вложения:
On Sun, Mar 02, 2025 at 09:56:41AM +0100, Julien Tachoires wrote:
> With the help of the new TAM routine 'relation_options', table access 
> methods can with this patch define their own reloptions 
> parser/validator.
> 
> These reloptions can be set via the following commands:
> 1. CREATE TABLE ... USING table_am
>        WITH (option1='value1', option2='value2');
> 2. ALTER TABLE ...
>        SET (option1 'value1', option2 'value2');
> 3. ALTER TABLE ... SET ACCESS METHOD table_am
>        OPTIONS (option1 'value1', option2 'value2');
> 
> When changing table's access method, the settings inherited from the 
> former TAM can be dropped (if not supported by the new TAM) via: DROP 
> option, or, updated via: SET option 'value'.
> 
> Currently, tables using different TAMs than heap are able to use heap's 
> reloptions (fillfactor, toast_tuple_target, etc...). With this patch 
> applied, this is not the case anymore: if the TAM needs to have access 
> to similar settings to heap ones, they have to explicitly define them.
> 
> The 2nd patch file includes a new test module 'dummy_table_am' which 
> implements a dummy table access method utilized to exercise TAM 
> reloptions. This test module is strongly based on what we already have 
> in 'dummy_index_am'. 'dummy_table_am' provides a complete example of TAM 
> reloptions definition.
> 
> This work is directly derived from SadhuPrasad's patch here [2]. Others 
> attempts were posted here [1] and here [3].
> 
> [1] https://www.postgresql.org/message-id/flat/429fb58fa3218221bb17c7bf9e70e1aa6cfc6b5d.camel%40j-davis.com
> [2] https://www.postgresql.org/message-id/flat/CAFF0-CG4KZHdtYHMsonWiXNzj16gWZpduXAn8yF7pDDub+GQMg@mail.gmail.com
> [3] https://www.postgresql.org/message-id/flat/AMUA1wBBBxfc3tKRLLdU64rb.1.1683276279979.Hmail.wuhao%40hashdata.cn

Please find a new version including minor fixes: 'TAM' terms are
replaced by 'table AM'

-- 
Julien Tachoires

Re: Allow table AMs to define their own reloptions

От:
Yura Sokolov <y.sokolov@postgrespro.ru>
Дата:
02.03.2025 16:23, Julien Tachoires пишет:
> On Sun, Mar 02, 2025 at 09:56:41AM +0100, Julien Tachoires wrote:
>> With the help of the new TAM routine 'relation_options', table access 
>> methods can with this patch define their own reloptions 
>> parser/validator.
>>
>> These reloptions can be set via the following commands:
>> 1. CREATE TABLE ... USING table_am
>>        WITH (option1='value1', option2='value2');
>> 2. ALTER TABLE ...
>>        SET (option1 'value1', option2 'value2');
>> 3. ALTER TABLE ... SET ACCESS METHOD table_am
>>        OPTIONS (option1 'value1', option2 'value2');
>>
>> When changing table's access method, the settings inherited from the 
>> former TAM can be dropped (if not supported by the new TAM) via: DROP 
>> option, or, updated via: SET option 'value'.
>>
>> Currently, tables using different TAMs than heap are able to use heap's 
>> reloptions (fillfactor, toast_tuple_target, etc...). With this patch 
>> applied, this is not the case anymore: if the TAM needs to have access 
>> to similar settings to heap ones, they have to explicitly define them.
>>
>> The 2nd patch file includes a new test module 'dummy_table_am' which 
>> implements a dummy table access method utilized to exercise TAM 
>> reloptions. This test module is strongly based on what we already have 
>> in 'dummy_index_am'. 'dummy_table_am' provides a complete example of TAM 
>> reloptions definition.
>>
>> This work is directly derived from SadhuPrasad's patch here [2]. Others 
>> attempts were posted here [1] and here [3].
>>
>> [1] https://www.postgresql.org/message-id/flat/429fb58fa3218221bb17c7bf9e70e1aa6cfc6b5d.camel%40j-davis.com
>> [2] https://www.postgresql.org/message-id/flat/CAFF0-CG4KZHdtYHMsonWiXNzj16gWZpduXAn8yF7pDDub+GQMg@mail.gmail.com
>> [3] https://www.postgresql.org/message-id/flat/AMUA1wBBBxfc3tKRLLdU64rb.1.1683276279979.Hmail.wuhao%40hashdata.cn
> 
> Please find a new version including minor fixes: 'TAM' terms are
> replaced by 'table AM'

Good day, Julien.

Your forgot another one attempt discussion with patch [1] with alive
commitfest entry [2]

[1] https://postgr.es/m/flat/3766675.7eaCOWfIcx%40thinkpad-pgpro
[2] https://commitfest.postgresql.org/patch/4688/


-------
regards
Yura Sokolov aka funny-falcon


Re: Allow table AMs to define their own reloptions

От:
Julien Tachoires <julien@tachoires.me>
Дата:
Hi Yura,

On Sun, Mar 02, 2025 at 06:20:07PM +0300, Yura Sokolov wrote:
> Your forgot another one attempt discussion with patch [1] with alive
> commitfest entry [2]
> 
> [1] https://postgr.es/m/flat/3766675.7eaCOWfIcx%40thinkpad-pgpro
> [2] https://commitfest.postgresql.org/patch/4688/

Thank you. After taking a look at the patch itself and the email thread,
it seems this patch does not add custom reloptions to table AMs, see
[1].

[1]: https://www.postgresql.org/message-id/1823308.yXV3o4JbTB%40thinkpad-pgpro

-- 
Julien Tachoires


Re: Allow table AMs to define their own reloptions

От:
Yura Sokolov <y.sokolov@postgrespro.ru>
Дата:
04.03.2025 09:16, Julien Tachoires пишет:
> Hi Yura,
> 
> On Sun, Mar 02, 2025 at 06:20:07PM +0300, Yura Sokolov wrote:
>> Your forgot another one attempt discussion with patch [1] with alive
>> commitfest entry [2]
>>
>> [1] https://postgr.es/m/flat/3766675.7eaCOWfIcx%40thinkpad-pgpro
>> [2] https://commitfest.postgresql.org/patch/4688/
> 
> Thank you. After taking a look at the patch itself and the email thread,
> it seems this patch does not add custom reloptions to table AMs, see
> [1].
> 
> [1]: https://www.postgresql.org/message-id/1823308.yXV3o4JbTB%40thinkpad-pgpro

But intention of this patch is to make adding options easier, as author says:

  But new option engine will make adding custom options for table AM more
  easy task, as main goal of this patch is to  simplify adding options
  everywhere they needed. And yes, adding custom table AM options is one of
  my next goals, as soon as this patch is commit.

I believe, adding generic way to options extension is better way than
targeting specific options. Don't you?

I believe Nikolay's patch needs review and support. As you're interesting
to the problem, may you at least look at his suggestion and analyze it from
the point of view of your task?

-------
regards
Yura Sokolov aka funny-falcon


Re: Allow table AMs to define their own reloptions

От:
Julien Tachoires <julien@tachoires.me>
Дата:
Вложения:
On Sun, Mar 02, 2025 at 02:23:54PM +0100, Julien Tachoires wrote:
> On Sun, Mar 02, 2025 at 09:56:41AM +0100, Julien Tachoires wrote:
> > With the help of the new TAM routine 'relation_options', table access 
> > methods can with this patch define their own reloptions 
> > parser/validator.
> > 
> > These reloptions can be set via the following commands:
> > 1. CREATE TABLE ... USING table_am
> >        WITH (option1='value1', option2='value2');
> > 2. ALTER TABLE ...
> >        SET (option1 'value1', option2 'value2');
> > 3. ALTER TABLE ... SET ACCESS METHOD table_am
> >        OPTIONS (option1 'value1', option2 'value2');
> > 
> > When changing table's access method, the settings inherited from the 
> > former TAM can be dropped (if not supported by the new TAM) via: DROP 
> > option, or, updated via: SET option 'value'.
> > 
> > Currently, tables using different TAMs than heap are able to use heap's 
> > reloptions (fillfactor, toast_tuple_target, etc...). With this patch 
> > applied, this is not the case anymore: if the TAM needs to have access 
> > to similar settings to heap ones, they have to explicitly define them.
> > 
> > The 2nd patch file includes a new test module 'dummy_table_am' which 
> > implements a dummy table access method utilized to exercise TAM 
> > reloptions. This test module is strongly based on what we already have 
> > in 'dummy_index_am'. 'dummy_table_am' provides a complete example of TAM 
> > reloptions definition.
> > 
> > This work is directly derived from SadhuPrasad's patch here [2]. Others 
> > attempts were posted here [1] and here [3].
> > 
> > [1] https://www.postgresql.org/message-id/flat/429fb58fa3218221bb17c7bf9e70e1aa6cfc6b5d.camel%40j-davis.com
> > [2] https://www.postgresql.org/message-id/flat/CAFF0-CG4KZHdtYHMsonWiXNzj16gWZpduXAn8yF7pDDub+GQMg@mail.gmail.com
> > [3] https://www.postgresql.org/message-id/flat/AMUA1wBBBxfc3tKRLLdU64rb.1.1683276279979.Hmail.wuhao%40hashdata.cn
> 
> Please find a new version including minor fixes: 'TAM' terms are
> replaced by 'table AM'

Please find a new rebased version. 

-- 
Julien Tachoires

Re: Allow table AMs to define their own reloptions

От:
Rafia Sabih <rafia.pghackers@gmail.com>
Дата:


On Thu, 4 Jun 2026 at 04:32, Andrew Dunstan <andrew@dunslane.net> wrote:

On 2025-05-26 Mo 7:06 AM, Julien Tachoires wrote:
> On Sat, Mar 29, 2025 at 08:46:01AM +0100, Julien Tachoires wrote:
>> On Sun, Mar 02, 2025 at 02:23:54PM +0100, Julien Tachoires wrote:
>>> On Sun, Mar 02, 2025 at 09:56:41AM +0100, Julien Tachoires wrote:
>>>> With the help of the new TAM routine 'relation_options', table access
>>>> methods can with this patch define their own reloptions
>>>> parser/validator.
>>>>
>>>> These reloptions can be set via the following commands:
>>>> 1. CREATE TABLE ... USING table_am
>>>>         WITH (option1='value1', option2='value2');
>>>> 2. ALTER TABLE ...
>>>>         SET (option1 'value1', option2 'value2');
>>>> 3. ALTER TABLE ... SET ACCESS METHOD table_am
>>>>         OPTIONS (option1 'value1', option2 'value2');
>>>>
>>>> When changing table's access method, the settings inherited from the
>>>> former TAM can be dropped (if not supported by the new TAM) via: DROP
>>>> option, or, updated via: SET option 'value'.
>>>>
>>>> Currently, tables using different TAMs than heap are able to use heap's
>>>> reloptions (fillfactor, toast_tuple_target, etc...). With this patch
>>>> applied, this is not the case anymore: if the TAM needs to have access
>>>> to similar settings to heap ones, they have to explicitly define them.
>>>>
>>>> The 2nd patch file includes a new test module 'dummy_table_am' which
>>>> implements a dummy table access method utilized to exercise TAM
>>>> reloptions. This test module is strongly based on what we already have
>>>> in 'dummy_index_am'. 'dummy_table_am' provides a complete example of TAM
>>>> reloptions definition.
>>>>
>>>> This work is directly derived from SadhuPrasad's patch here [2]. Others
>>>> attempts were posted here [1] and here [3].
>>>>
>>>> [1] https://www.postgresql.org/message-id/flat/429fb58fa3218221bb17c7bf9e70e1aa6cfc6b5d.camel%40j-davis.com
>>>> [2] https://www.postgresql.org/message-id/flat/CAFF0-CG4KZHdtYHMsonWiXNzj16gWZpduXAn8yF7pDDub+GQMg@mail.gmail.com
>>>> [3] https://www.postgresql.org/message-id/flat/AMUA1wBBBxfc3tKRLLdU64rb.1.1683276279979.Hmail.wuhao%40hashdata.cn
>>> Please find a new version including minor fixes: 'TAM' terms are
>>> replaced by 'table AM'
>> Please find a new rebased version.
> New rebased version.
>


This thread seems to have gone dormant, sadly. Here's a fresh attempt I
made (with assistance from Claude), before I was aware of the existence
of this and other efforts. I think it meets most of the previous
objections, and is in line with what we do for Index AMs.

I was testing this patch and found this issue,
CREATE EXTENSION dummy_table_am;
CREATE TABLE t (a int) USING dummy_table_am WITH (option_int = 42);
ALTER TABLE t SET ACCESS METHOD heap;
SELECT reloptions FROM pg_class WHERE oid = 't'::regclass;
  reloptions    
-----------------
 {option_int=42}
(1 row)
ALTER TABLE t SET (fillfactor = 50);
2026-07-16 19:01:36.060 IST [95058] ERROR:  unrecognized parameter "option_int"
2026-07-16 19:01:36.060 IST [95058] STATEMENT:  ALTER TABLE t SET (fillfactor = 50);
ERROR:  unrecognized parameter "option_int"

Basically, the option is left behind after changing the tableam to heap, I think that isn't intentional. 

cheers


andrew


--
Andrew Dunstan
EDB: https://www.enterprisedb.com


--
Regards,
Rafia Sabih
CYBERTEC PostgreSQL International GmbH

Re: Allow table AMs to define their own reloptions

От:
Andrew Dunstan <andrew@dunslane.net>
Дата:
Вложения:


On Thu, Jul 16, 2026 at 9:37 AM Rafia Sabih <rafia.pghackers@gmail.com> wrote:


On Thu, 4 Jun 2026 at 04:32, Andrew Dunstan <andrew@dunslane.net> wrote:

On 2025-05-26 Mo 7:06 AM, Julien Tachoires wrote:
> On Sat, Mar 29, 2025 at 08:46:01AM +0100, Julien Tachoires wrote:
>> On Sun, Mar 02, 2025 at 02:23:54PM +0100, Julien Tachoires wrote:
>>> On Sun, Mar 02, 2025 at 09:56:41AM +0100, Julien Tachoires wrote:
>>>> With the help of the new TAM routine 'relation_options', table access
>>>> methods can with this patch define their own reloptions
>>>> parser/validator.
>>>>
>>>> These reloptions can be set via the following commands:
>>>> 1. CREATE TABLE ... USING table_am
>>>>         WITH (option1='value1', option2='value2');
>>>> 2. ALTER TABLE ...
>>>>         SET (option1 'value1', option2 'value2');
>>>> 3. ALTER TABLE ... SET ACCESS METHOD table_am
>>>>         OPTIONS (option1 'value1', option2 'value2');
>>>>
>>>> When changing table's access method, the settings inherited from the
>>>> former TAM can be dropped (if not supported by the new TAM) via: DROP
>>>> option, or, updated via: SET option 'value'.
>>>>
>>>> Currently, tables using different TAMs than heap are able to use heap's
>>>> reloptions (fillfactor, toast_tuple_target, etc...). With this patch
>>>> applied, this is not the case anymore: if the TAM needs to have access
>>>> to similar settings to heap ones, they have to explicitly define them.
>>>>
>>>> The 2nd patch file includes a new test module 'dummy_table_am' which
>>>> implements a dummy table access method utilized to exercise TAM
>>>> reloptions. This test module is strongly based on what we already have
>>>> in 'dummy_index_am'. 'dummy_table_am' provides a complete example of TAM
>>>> reloptions definition.
>>>>
>>>> This work is directly derived from SadhuPrasad's patch here [2]. Others
>>>> attempts were posted here [1] and here [3].
>>>>
>>>> [1] https://www.postgresql.org/message-id/flat/429fb58fa3218221bb17c7bf9e70e1aa6cfc6b5d.camel%40j-davis.com
>>>> [2] https://www.postgresql.org/message-id/flat/CAFF0-CG4KZHdtYHMsonWiXNzj16gWZpduXAn8yF7pDDub+GQMg@mail.gmail.com
>>>> [3] https://www.postgresql.org/message-id/flat/AMUA1wBBBxfc3tKRLLdU64rb.1.1683276279979.Hmail.wuhao%40hashdata.cn
>>> Please find a new version including minor fixes: 'TAM' terms are
>>> replaced by 'table AM'
>> Please find a new rebased version.
> New rebased version.
>


This thread seems to have gone dormant, sadly. Here's a fresh attempt I
made (with assistance from Claude), before I was aware of the existence
of this and other efforts. I think it meets most of the previous
objections, and is in line with what we do for Index AMs.

I was testing this patch and found this issue,
CREATE EXTENSION dummy_table_am;
CREATE TABLE t (a int) USING dummy_table_am WITH (option_int = 42);
ALTER TABLE t SET ACCESS METHOD heap;
SELECT reloptions FROM pg_class WHERE oid = 't'::regclass;
  reloptions    
-----------------
 {option_int=42}
(1 row)
ALTER TABLE t SET (fillfactor = 50);
2026-07-16 19:01:36.060 IST [95058] ERROR:  unrecognized parameter "option_int"
2026-07-16 19:01:36.060 IST [95058] STATEMENT:  ALTER TABLE t SET (fillfactor = 50);
ERROR:  unrecognized parameter "option_int"

Basically, the option is left behind after changing the tableam to heap, I think that isn't intentional. 



 
 
Thanks for reviewing. Good catch!

Basically the code had an early exit in the validation code that shouldn't have been there.

 v2 attached with a fix for that, plus a regression test covering this
direction (dummy_table_am -> heap with a still-set AM-specific option),
which I verified fails against v1 and passes with the fix. I also
folded the two independent access-method-resolution code paths in
DefineRelation into one and added the new test module's typedefs to
typedefs.list

cheers

andrew

Re: Allow table AMs to define their own reloptions

От:
Rafia Sabih <rafia.pghackers@gmail.com>
Дата:


On Thu, 16 Jul 2026 at 20:02, Andrew Dunstan <andrew@dunslane.net> wrote:


On Thu, Jul 16, 2026 at 9:37 AM Rafia Sabih <rafia.pghackers@gmail.com> wrote:


On Thu, 4 Jun 2026 at 04:32, Andrew Dunstan <andrew@dunslane.net> wrote:

On 2025-05-26 Mo 7:06 AM, Julien Tachoires wrote:
> On Sat, Mar 29, 2025 at 08:46:01AM +0100, Julien Tachoires wrote:
>> On Sun, Mar 02, 2025 at 02:23:54PM +0100, Julien Tachoires wrote:
>>> On Sun, Mar 02, 2025 at 09:56:41AM +0100, Julien Tachoires wrote:
>>>> With the help of the new TAM routine 'relation_options', table access
>>>> methods can with this patch define their own reloptions
>>>> parser/validator.
>>>>
>>>> These reloptions can be set via the following commands:
>>>> 1. CREATE TABLE ... USING table_am
>>>>         WITH (option1='value1', option2='value2');
>>>> 2. ALTER TABLE ...
>>>>         SET (option1 'value1', option2 'value2');
>>>> 3. ALTER TABLE ... SET ACCESS METHOD table_am
>>>>         OPTIONS (option1 'value1', option2 'value2');
>>>>
>>>> When changing table's access method, the settings inherited from the
>>>> former TAM can be dropped (if not supported by the new TAM) via: DROP
>>>> option, or, updated via: SET option 'value'.
>>>>
>>>> Currently, tables using different TAMs than heap are able to use heap's
>>>> reloptions (fillfactor, toast_tuple_target, etc...). With this patch
>>>> applied, this is not the case anymore: if the TAM needs to have access
>>>> to similar settings to heap ones, they have to explicitly define them.
>>>>
>>>> The 2nd patch file includes a new test module 'dummy_table_am' which
>>>> implements a dummy table access method utilized to exercise TAM
>>>> reloptions. This test module is strongly based on what we already have
>>>> in 'dummy_index_am'. 'dummy_table_am' provides a complete example of TAM
>>>> reloptions definition.
>>>>
>>>> This work is directly derived from SadhuPrasad's patch here [2]. Others
>>>> attempts were posted here [1] and here [3].
>>>>
>>>> [1] https://www.postgresql.org/message-id/flat/429fb58fa3218221bb17c7bf9e70e1aa6cfc6b5d.camel%40j-davis.com
>>>> [2] https://www.postgresql.org/message-id/flat/CAFF0-CG4KZHdtYHMsonWiXNzj16gWZpduXAn8yF7pDDub+GQMg@mail.gmail.com
>>>> [3] https://www.postgresql.org/message-id/flat/AMUA1wBBBxfc3tKRLLdU64rb.1.1683276279979.Hmail.wuhao%40hashdata.cn
>>> Please find a new version including minor fixes: 'TAM' terms are
>>> replaced by 'table AM'
>> Please find a new rebased version.
> New rebased version.
>


This thread seems to have gone dormant, sadly. Here's a fresh attempt I
made (with assistance from Claude), before I was aware of the existence
of this and other efforts. I think it meets most of the previous
objections, and is in line with what we do for Index AMs.

I was testing this patch and found this issue,
CREATE EXTENSION dummy_table_am;
CREATE TABLE t (a int) USING dummy_table_am WITH (option_int = 42);
ALTER TABLE t SET ACCESS METHOD heap;
SELECT reloptions FROM pg_class WHERE oid = 't'::regclass;
  reloptions    
-----------------
 {option_int=42}
(1 row)
ALTER TABLE t SET (fillfactor = 50);
2026-07-16 19:01:36.060 IST [95058] ERROR:  unrecognized parameter "option_int"
2026-07-16 19:01:36.060 IST [95058] STATEMENT:  ALTER TABLE t SET (fillfactor = 50);
ERROR:  unrecognized parameter "option_int"

Basically, the option is left behind after changing the tableam to heap, I think that isn't intentional. 



 
 
Thanks for reviewing. Good catch!

Basically the code had an early exit in the validation code that shouldn't have been there.

 v2 attached with a fix for that, plus a regression test covering this
direction (dummy_table_am -> heap with a still-set AM-specific option),
which I verified fails against v1 and passes with the fix. I also
folded the two independent access-method-resolution code paths in
DefineRelation into one and added the new test module's typedefs to
typedefs.list

I can confirm that on the new patch, the alter command gives error and the one with the RESET does the job,
 ALTER TABLE t SET ACCESS METHOD heap;
2026-07-17 12:55:04.244 IST [55465] ERROR:  unrecognized parameter "option_int"
2026-07-17 12:55:04.244 IST [55465] STATEMENT:  ALTER TABLE t SET ACCESS METHOD heap;
ALTER TABLE t SET ACCESS METHOD heap, RESET(option_int);
ALTER TABLE 

However, I encountered another issues now, this time with partitioning,
CREATE TABLE parted(a int) PARTITION BY RANGE(a);
CREATE TABLE parted_p1 PARTITION OF parted for values from (1) to (10) WITH (option_int=50);                                                                                                             2026-07-20 12:20:54.137 IST [55465] ERROR:  unrecognized parameter "option_int"
2026-07-20 12:20:54.137 IST [55465] STATEMENT:  CREATE TABLE parted_p1 PARTITION OF parted for values from (1) to (10) WITH (option_int=50);
ERROR:  unrecognized parameter "option_int"
So basically partitioned table is not able to read the new reloption.

cheers

andrew

 


--
Regards,
Rafia Sabih
CYBERTEC PostgreSQL International GmbH

Re: Allow table AMs to define their own reloptions

От:
Andrew Dunstan <andrew@dunslane.net>
Дата:

On 2026-09-07 Mo 8:41 AM, Aleksander Alekseev wrote:
> Hi Andrew,
>
>> Attached is v7. Changes since v6:
>>
>> [...]
> That's an important feature, thanks for driving it. We wanted
> something like this in the recent commit 0e944fe3 but ended up using a
> GUC.
>
> There is one important design difference however. Your patch allows
> given TAMs to have their own reloptions. In 0e944fe3 the task was
> different. An extension that doesn't implement a TableAM should be
> able to extend `CREATE TABLE foo WITH (...)` with its own options
> independent of the underlying TAM. The way these options are
> interpreted depends on the extension, not the underlying TAM.
>
> If we could separate reloptions extension from TAM implementation that
> would be much more flexible. Do you think it's possible?


I kind of feel like that's a separate project, and I'm not keen to hold 
this one up for scope creep.


cheers


andrew

--
Andrew Dunstan
EDB: https://www.enterprisedb.com



Re: Allow table AMs to define their own reloptions

От:
Andrew Dunstan <andrew@dunslane.net>
Дата:
Вложения:


On 2026-09-08 Tu 8:34 AM, Ajit Awekar wrote:
Hi all,

I forgot to attach the TAM code used for repro. please find it attached

Thanks & Best Regards,
Ajit

On Tue, 8 Sept 2026 at 15:33, Ajit Awekar <ajitpostgres@gmail.com> wrote:
Hi hackers,

I managed to get a crash with the patch. Below are the details


Repro:

Any table AM that sets amoptions but leaves has_std_options_prefix false
and returns a bytea smaller than sizeof(StdRdOptions) will
crash on VACUUM of a table that has a toastable column.

postgres=# CREATE EXTENSION tiny_table_am;
CREATE EXTENSION
postgres=# CREATE TABLE t_tiny (a int, b text) USING tiny_table_am WITH (option_int = 7);
CREATE TABLE
postgres=# INSERT INTO t_tiny VALUES (1, repeat('x', 10000));
INSERT 0 1
postgres=# VACUUM t_tiny;
server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
The connection to the server was lost. Attempting reset: Failed.
The connection to the server was lost. Attempting reset: Failed.


Root cause:
vacuum_rel() in  has two places that read
rel->rd_options as a StdRdOptions to hand storage parameters down to the
relation's TOAST table. Only one of them was updated to use the new
RelationHasStdRdOptions() guard:

    ~line 2214 (correctly guarded):
      relopts = merge_toast_reloptions(RelationHasStdRdOptions(rel) ?
                                       (StdRdOptions *) rel->rd_options : NULL,
                                       params.main_relopts);

    ~line 2310-2312 (still just checks != NULL):
      if (OidIsValid(toast_relid) && rel->rd_options)
      {
          memcpy(&relopts_copy, rel->rd_options, sizeof(StdRdOptions));
          toast_vacuum_params.main_relopts = &relopts_copy;
      }




Suggested fix
-------------
Same guard as the nearby, already-fixed call:

--- a/src/backend/commands/vacuum.c
+++ b/src/backend/commands/vacuum.c
@@ -2307,9 +2307,8 @@ vacuum_rel(Oid relid, RangeVar *relation, VacuumParams params,
     * Hand our storage parameters down for the TOAST table to inherit.  Take
     * a copy while we still have the relation open; the relcache entry can go
     * away once we close it.
     */
-   if (OidIsValid(toast_relid) && rel->rd_options)
+   if (OidIsValid(toast_relid) && RelationHasStdRdOptions(rel))
    {
        memcpy(&relopts_copy, rel->rd_options, sizeof(StdRdOptions));
        toast_vacuum_params.main_relopts = &relopts_copy;
    }



Thanks, this should be fixed in v8 attached.


cheers


andrew


--
Andrew Dunstan
EDB: https://www.enterprisedb.com

Re: Allow table AMs to define their own reloptions

От:
Ajit Awekar <ajitpostgres@gmail.com>
Дата:
I tested v8 and found below two issues.

1. SET before RESET.  Final state (heap, fillfactor=50) is valid. but resulting in an error ERROR:  unrecognized parameter "option_int". However Reset before set works as expected.

postgres=# CREATE EXTENSION dummy_table_am;
CREATE EXTENSION
postgres=# CREATE TABLE x (a int);
CREATE TABLE
postgres=# ALTER TABLE x SET ACCESS METHOD dummy_table_am, SET (option_int = 25);
ALTER TABLE
postgres=# SELECT reloptions FROM pg_class WHERE oid = 'x'::regclass;
   reloptions    
-----------------
 {option_int=25}
(1 row)

postgres=# ALTER TABLE x SET ACCESS METHOD heap, SET (fillfactor = 50), RESET (option_int);
ERROR:  unrecognized parameter "option_int"
postgres=# SELECT (SELECT amname FROM pg_am WHERE oid = relam) AS amname, reloptions FROM pg_class WHERE oid = 'x'::regclass;
     amname     |   reloptions    
----------------+-----------------
 dummy_table_am | {option_int=25}
(1 row)

postgres=# ALTER TABLE x SET ACCESS METHOD heap, RESET (option_int), SET (fillfactor = 50);
ALTER TABLE
postgres=# SELECT (SELECT amname FROM pg_am WHERE oid = relam) AS amname, reloptions FROM pg_class WHERE oid = 'x'::regclass;
 amname |   reloptions    
--------+-----------------
 heap   | {fillfactor=50}
(1 row)

2.The current dummy_table_am always embeds StdRdOptions, so it cannot
  catch this. For this issue  make dummy_table_am's struct start with
  {int32 vl_len_; int pad1; int pad2; int option_int;}, keep only the
  option_int registration, dt_relopt_tab[1], and set
  has_std_options_prefix = false.

postgres=# CREATE EXTENSION dummy_table_am;
CREATE EXTENSION
postgres=# CREATE TABLE t0 (a int, b text) USING dummy_table_am WITH (option_int = 0);
ERROR:  unexpected toast_value_type value 0
postgres=# CREATE TABLE t2 (a int, b text) USING dummy_table_am WITH (option_int = 2);
CREATE TABLE
postgres=# SELECT atttypid::regtype AS chunk_id_type FROM pg_attribute WHERE attrelid = (SELECT reltoastrelid FROM pg_class WHERE oid = 't2'::regclass) AND attname = 'chunk_id';                                                  
 chunk_id_type
---------------
 oid8
(1 row)
postgres=# CREATE TABLE tn (a int, b text) USING dummy_table_am;
CREATE TABLE
postgres=# SELECT atttypid::regtype AS chunk_id_type FROM pg_attribute WHERE attrelid = (SELECT reltoastrelid FROM pg_class WHERE oid = 'tn'::regclass) AND attname = 'chunk_id';
 chunk_id_type
---------------
 oid
(1 row)

I think RelationGetToastValueType() is not guarded by RelationHasStdRdOptions() causing this issue.

Possible fix for second issue:
#define RelationGetToastValueType(relation, defaulttarg) \
        (RelationHasStdRdOptions(relation) ? \
         ((StdRdOptions *) (relation)->rd_options)->toast_value_type : (defaulttarg))

Thanks & Best Regards,
Ajit

On Mon, 28 Sept 2026 at 18:53, Andrew Dunstan <andrew@dunslane.net> wrote:


On 2026-09-08 Tu 8:34 AM, Ajit Awekar wrote:
Hi all,

I forgot to attach the TAM code used for repro. please find it attached

Thanks & Best Regards,
Ajit

On Tue, 8 Sept 2026 at 15:33, Ajit Awekar <ajitpostgres@gmail.com> wrote:
Hi hackers,

I managed to get a crash with the patch. Below are the details


Repro:

Any table AM that sets amoptions but leaves has_std_options_prefix false
and returns a bytea smaller than sizeof(StdRdOptions) will
crash on VACUUM of a table that has a toastable column.

postgres=# CREATE EXTENSION tiny_table_am;
CREATE EXTENSION
postgres=# CREATE TABLE t_tiny (a int, b text) USING tiny_table_am WITH (option_int = 7);
CREATE TABLE
postgres=# INSERT INTO t_tiny VALUES (1, repeat('x', 10000));
INSERT 0 1
postgres=# VACUUM t_tiny;
server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
The connection to the server was lost. Attempting reset: Failed.
The connection to the server was lost. Attempting reset: Failed.


Root cause:
vacuum_rel() in  has two places that read
rel->rd_options as a StdRdOptions to hand storage parameters down to the
relation's TOAST table. Only one of them was updated to use the new
RelationHasStdRdOptions() guard:

    ~line 2214 (correctly guarded):
      relopts = merge_toast_reloptions(RelationHasStdRdOptions(rel) ?
                                       (StdRdOptions *) rel->rd_options : NULL,
                                       params.main_relopts);

    ~line 2310-2312 (still just checks != NULL):
      if (OidIsValid(toast_relid) && rel->rd_options)
      {
          memcpy(&relopts_copy, rel->rd_options, sizeof(StdRdOptions));
          toast_vacuum_params.main_relopts = &relopts_copy;
      }




Suggested fix
-------------
Same guard as the nearby, already-fixed call:

--- a/src/backend/commands/vacuum.c
+++ b/src/backend/commands/vacuum.c
@@ -2307,9 +2307,8 @@ vacuum_rel(Oid relid, RangeVar *relation, VacuumParams params,
     * Hand our storage parameters down for the TOAST table to inherit.  Take
     * a copy while we still have the relation open; the relcache entry can go
     * away once we close it.
     */
-   if (OidIsValid(toast_relid) && rel->rd_options)
+   if (OidIsValid(toast_relid) && RelationHasStdRdOptions(rel))
    {
        memcpy(&relopts_copy, rel->rd_options, sizeof(StdRdOptions));
        toast_vacuum_params.main_relopts = &relopts_copy;
    }



Thanks, this should be fixed in v8 attached.


cheers


andrew


--
Andrew Dunstan
EDB: https://www.enterprisedb.com

Re: Allow table AMs to define their own reloptions

От:
Andrew Dunstan <andrew@dunslane.net>
Дата:
Вложения:


[please don't top-post]


On 2026-09-30 We 4:35 AM, Ajit Awekar wrote:
I tested v8 and found below two issues.

1. SET before RESET.  Final state (heap, fillfactor=50) is valid. but resulting in an error ERROR:  unrecognized parameter "option_int". However Reset before set works as expected.



Yes, that's a bug.  v9 skips  the per-subcommand check when SET ACCESS METHOD is queued in the same statement. The deferred check still rejects unknown names and out-of-range values, and there are tests for both orders as well as those cases.



2.The current dummy_table_am always embeds StdRdOptions, so it cannot
  catch this. For this issue  make dummy_table_am's struct start with
  {int32 vl_len_; int pad1; int pad2; int option_int;}, keep only the
  option_int registration, dt_relopt_tab[1], and set
  has_std_options_prefix = false.


The bug is fixed in v9. I've added a second dummy AM to the test that doesn't embed StdRdoptions, so we could catch issues like this in future.


cheers


andrew

--
Andrew Dunstan
EDB: https://www.enterprisedb.com

Re: Allow table AMs to define their own reloptions

От:
Zsolt Parragi <zsolt.parragi@percona.com>
Дата:
pg_dump has the option "--no-table-access-method". Should that somehow
interact with this feature? As currently that can result in non
restorable dumps.



There's also one more limitation similar to the TEXT issue I reported
upthread - and similarly it's not an issue for current tests, but
might be worth improving:

/* src: src/backend/access/heap/heapam.c:1449-1452 */
if (unlikely(sscan->rs_rd->rd_tableam != GetHeapamTableAmRoutine()))
    ereport(ERROR, ... errmsg_internal("only heap AM is supported")));

CREATE TABLE ti (a int) USING dummy_table_am;
CREATE INDEX ON ti(a);                                   -- ERROR:
only heap AM is supported

CREATE TABLE tp (a int PRIMARY KEY) USING dummy_table_am; -- ERROR:
only heap AM is supported


Re: Allow table AMs to define their own reloptions

От:
Andrew Dunstan <andrew@dunslane.net>
Дата:

On 2026-09-30 We 5:22 PM, Zsolt Parragi wrote:
> pg_dump has the option "--no-table-access-method". Should that somehow
> interact with this feature? As currently that can result in non
> restorable dumps.
>

Good catch.

Worse, the CREATE TABLE fails, so the table and its data are lost,
with both pg_dump and pg_restore --no-table-access-method.

We can't just move the options to a later ALTER TABLE, because some
standard ones (toast_value_type) only matter at creation time. So my
plan, as a second patch:

- A function pg_reloption_is_standard(name), true if the option is
   registered for RELOPT_KIND_HEAP (including ones an AM inherits via
   add_reloption_to_kind()).

- For non-heap tables and matviews, pg_dump keeps standard options in
   the CREATE, and puts AM-specific ones in a separate ALTER TABLE ...
   SET (...) TOC entry, which --no-table-access-method omits or skips.

- TAP tests using dummy_table_am.

That requires AMs to inherit standard option names rather than
redefine them, and to have their own options work when set by ALTER
TABLE on an empty table, since every restore would apply them that
way. I'd document both in tableam.sgml. The second one isn't ideal,
but I don't see a simpler way. Better ideas welcome.

>
> There's also one more limitation similar to the TEXT issue I reported
> upthread - and similarly it's not an issue for current tests, but
> might be worth improving:
>
> /* src: src/backend/access/heap/heapam.c:1449-1452 */
> if (unlikely(sscan->rs_rd->rd_tableam != GetHeapamTableAmRoutine()))
>      ereport(ERROR, ... errmsg_internal("only heap AM is supported")));
>
> CREATE TABLE ti (a int) USING dummy_table_am;
> CREATE INDEX ON ti(a);                                   -- ERROR:
> only heap AM is supported
>
> CREATE TABLE tp (a int PRIMARY KEY) USING dummy_table_am; -- ERROR:
> only heap AM is supported


Same cause as the TOAST issue: heap_getnext() requires the heap routine
itself, and dummy_table_am has to copy it to substitute amoptions.
Working around it for index builds would mean reimplementing heap's
index build scan in the module, which doesn't seem worthdoing for this
dummy whose only purpose is to test handling options. So I'll just note
the restriction in the README. We might need to revisit it if we want
to make the dummy AM do more.


cheers


andrew


--
Andrew Dunstan
EDB: https://www.enterprisedb.com



Re: Allow table AMs to define their own reloptions

От:
Álvaro Herrera <alvherre@kurilemu.de>
Дата:
On 2026-Sep-30, Andrew Dunstan wrote:

> diff --git a/src/include/access/tableam.h b/src/include/access/tableam.h
> index ea3f2a6be99..6dfc6e8026c 100644
> --- a/src/include/access/tableam.h
> +++ b/src/include/access/tableam.h
> @@ -17,6 +17,7 @@
>  #ifndef TABLEAM_H
>  #define TABLEAM_H
>  
> +#include "access/amapi.h"
>  #include "access/relscan.h"
>  #include "access/sdir.h"
>  #include "access/xact.h"

I don't love this.  I have a bunch of patches queued to remove includes
from other includes to reduce cross-header contamination.  This kind of
change makes it impossible to remove the cross inclusion here and is
more or less a step backwards.  (It's not _too_ bad because tableam.h is
not as widely used

Is there a better way to have a function definition that can be used in
both amapi.h and tableam.h without this cross-header inclusion?


Other comments on verbiage, just passing by:

I'm not much in love with the LLM-written comments TBH -- I don't think
phrases like "owns the option set entirely" are valuable, for example.
Also, the comment just above the ATValidateAccessMethodOptions() call in
ATController is redundant: it would be enough to say "validate options
as needed", and then have the comment atop ATValidateAccessMethodOptions()
itself carry the explanation of what we do and why.

In tableam.sgml, I'm not sure it makes much sense to state "The callback
has the same signature as the corresponding index AM callback".  Why not
just say what the signature is without directing the user to read a
reference page that's not relevant to the topic of table AMs?  I think
the first mention of reloptions in that page should be .

It also talks about validating and throwing ereport(ERROR) but it
doesn't say in so many words what must happen or not happen on each
possible value of 'validate'.  It could be clearer.

There's also "raises an error rather than silently dropping the value".
I mean, why not say "rather than launching an ICBM"?  Why not just
"raises an error, period"?

If I were the user of such an AM, I would not be sure how to interpret
the phrase "validate that the option read with SELECT reloptions FROM
pg_class are the ones that will be used".  What does that mean exactly?
Should it say "examine" rather than "validate"?

-- 
Álvaro Herrera               48°01'N 7°57'E  —  https://www.EnterpriseDB.com/
"No me acuerdo, pero no es cierto.  No es cierto, y si fuera cierto,
 no me acuerdo."                 (Augusto Pinochet a una corte de justicia)


Re: Allow table AMs to define their own reloptions

От:
Andrew Dunstan <andrew@dunslane.net>
Дата:
Вложения:


On 2026-10-01 Th 10:57 AM, Álvaro Herrera wrote:
On 2026-Sep-30, Andrew Dunstan wrote:

diff --git a/src/include/access/tableam.h b/src/include/access/tableam.h
index ea3f2a6be99..6dfc6e8026c 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -17,6 +17,7 @@ #ifndef TABLEAM_H #define TABLEAM_H 
+#include "access/amapi.h" #include "access/relscan.h" #include "access/sdir.h" #include "access/xact.h"
I don't love this.  I have a bunch of patches queued to remove includes
from other includes to reduce cross-header contamination.  This kind of
change makes it impossible to remove the cross inclusion here and is
more or less a step backwards.  (It's not _too_ bad because tableam.h is
not as widely used

Is there a better way to have a function definition that can be used in
both amapi.h and tableam.h without this cross-header inclusion?


Yes, there's no need for it. All the other TableAmRoutine members are
declared as bare function pointers, so amoptions now is too:

     bytea      *(*amoptions) (Datum reloptions, bool validate);

and the include is gone. The type is identical to amoptions_function,
so nothing else changes.



Other comments on verbiage, just passing by:

I'm not much in love with the LLM-written comments TBH -- I don't think
phrases like "owns the option set entirely" are valuable, for example.


You're absolutely right! :-)

I should have been much more careful. I hope the attached is more to your liking.


Also, the comment just above the ATValidateAccessMethodOptions() call in
ATController is redundant: it would be enough to say "validate options
as needed", and then have the comment atop ATValidateAccessMethodOptions()
itself carry the explanation of what we do and why.


Done



In tableam.sgml, I'm not sure it makes much sense to state "The callback
has the same signature as the corresponding index AM callback".  Why not
just say what the signature is without directing the user to read a
reference page that's not relevant to the topic of table AMs?  I think
the first mention of reloptions in that page should be <firstterm>.

It also talks about validating and throwing ereport(ERROR) but it
doesn't say in so many words what must happen or not happen on each
possible value of 'validate'.  It could be clearer.


I've rewritten that section. It's now called "Table Access Method
Options", since a lot of what goes under the user-facing name "storage
parameters" isn't about storage, and refers to CREATE TABLE for that.
It uses <firstterm> for reloptions, gives the signature, and says what
the callback must do when validate is true (error on unrecognized or
invalid values, and never substitute something else for them) and when
it's false (ignore invalid entries without error).


There's also "raises an error rather than silently dropping the value".
I mean, why not say "rather than launching an ICBM"?  Why not just
"raises an error, period"?


Done



If I were the user of such an AM, I would not be sure how to interpret
the phrase "validate that the option read with SELECT reloptions FROM
pg_class are the ones that will be used".  What does that mean exactly?
Should it say "examine" rather than "validate"?


That sentence is gone. What it was trying to say is now stated
directly: the callback must not accept an invalid value and use
something else in its place, since the stored parameters would then
not be the ones in effect.


I wrote:

On 2026-09-30 We 5:22 PM, Zsolt Parragi wrote:
pg_dump has the option "--no-table-access-method". Should that somehow
interact with this feature? As currently that can result in non
restorable dumps.


Good catch.

Worse, the CREATE TABLE fails, so the table and its data are lost,
with both pg_dump and pg_restore --no-table-access-method.

We can't just move the options to a later ALTER TABLE, because some
standard ones (toast_value_type) only matter at creation time. So my
plan, as a second patch:

- A function pg_reloption_is_standard(name), true if the option is
  registered for RELOPT_KIND_HEAP (including ones an AM inherits via
  add_reloption_to_kind()).

- For non-heap tables and matviews, pg_dump keeps standard options in
  the CREATE, and puts AM-specific ones in a separate ALTER TABLE ...
  SET (...) TOC entry, which --no-table-access-method omits or skips.

- TAP tests using dummy_table_am.

That requires AMs to inherit standard option names rather than
redefine them, and to have their own options work when set by ALTER
TABLE on an empty table, since every restore would apply them that
way. I'd document both in tableam.sgml. The second one isn't ideal,
but I don't see a simpler way. 

patch 2 implements this.


cheers


andrew


--
Andrew Dunstan
EDB: https://www.enterprisedb.com

Re: Allow table AMs to define their own reloptions

От:
Andrew Dunstan <andrew@dunslane.net>
Дата:
Вложения:


On 2026-10-02 Fr 5:48 PM, Andrew Dunstan wrote:


On 2026-10-01 Th 10:57 AM, Álvaro Herrera wrote:
On 2026-Sep-30, Andrew Dunstan wrote:

diff --git a/src/include/access/tableam.h b/src/include/access/tableam.h
index ea3f2a6be99..6dfc6e8026c 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -17,6 +17,7 @@ #ifndef TABLEAM_H #define TABLEAM_H 
+#include "access/amapi.h" #include "access/relscan.h" #include "access/sdir.h" #include "access/xact.h"
I don't love this.  I have a bunch of patches queued to remove includes
from other includes to reduce cross-header contamination.  This kind of
change makes it impossible to remove the cross inclusion here and is
more or less a step backwards.  (It's not _too_ bad because tableam.h is
not as widely used

Is there a better way to have a function definition that can be used in
both amapi.h and tableam.h without this cross-header inclusion?


Yes, there's no need for it. All the other TableAmRoutine members are
declared as bare function pointers, so amoptions now is too:

     bytea      *(*amoptions) (Datum reloptions, bool validate);

and the include is gone. The type is identical to amoptions_function,
so nothing else changes.

Other comments on verbiage, just passing by:

I'm not much in love with the LLM-written comments TBH -- I don't think
phrases like "owns the option set entirely" are valuable, for example.


You're absolutely right! :-)

I should have been much more careful. I hope the attached is more to your liking.


Also, the comment just above the ATValidateAccessMethodOptions() call in
ATController is redundant: it would be enough to say "validate options
as needed", and then have the comment atop ATValidateAccessMethodOptions()
itself carry the explanation of what we do and why.


Done


In tableam.sgml, I'm not sure it makes much sense to state "The callback
has the same signature as the corresponding index AM callback".  Why not
just say what the signature is without directing the user to read a
reference page that's not relevant to the topic of table AMs?  I think
the first mention of reloptions in that page should be <firstterm>.

It also talks about validating and throwing ereport(ERROR) but it
doesn't say in so many words what must happen or not happen on each
possible value of 'validate'.  It could be clearer.


I've rewritten that section. It's now called "Table Access Method
Options", since a lot of what goes under the user-facing name "storage
parameters" isn't about storage, and refers to CREATE TABLE for that.
It uses <firstterm> for reloptions, gives the signature, and says what
the callback must do when validate is true (error on unrecognized or
invalid values, and never substitute something else for them) and when
it's false (ignore invalid entries without error).

There's also "raises an error rather than silently dropping the value".
I mean, why not say "rather than launching an ICBM"?  Why not just
"raises an error, period"?


Done


If I were the user of such an AM, I would not be sure how to interpret
the phrase "validate that the option read with SELECT reloptions FROM
pg_class are the ones that will be used".  What does that mean exactly?
Should it say "examine" rather than "validate"?


That sentence is gone. What it was trying to say is now stated
directly: the callback must not accept an invalid value and use
something else in its place, since the stored parameters would then
not be the ones in effect.


I wrote:

On 2026-09-30 We 5:22 PM, Zsolt Parragi wrote:
pg_dump has the option "--no-table-access-method". Should that somehow
interact with this feature? As currently that can result in non
restorable dumps.


Good catch.

Worse, the CREATE TABLE fails, so the table and its data are lost,
with both pg_dump and pg_restore --no-table-access-method.

We can't just move the options to a later ALTER TABLE, because some
standard ones (toast_value_type) only matter at creation time. So my
plan, as a second patch:

- A function pg_reloption_is_standard(name), true if the option is
  registered for RELOPT_KIND_HEAP (including ones an AM inherits via
  add_reloption_to_kind()).

- For non-heap tables and matviews, pg_dump keeps standard options in
  the CREATE, and puts AM-specific ones in a separate ALTER TABLE ...
  SET (...) TOC entry, which --no-table-access-method omits or skips.

- TAP tests using dummy_table_am.

That requires AMs to inherit standard option names rather than
redefine them, and to have their own options work when set by ALTER
TABLE on an empty table, since every restore would apply them that
way. I'd document both in tableam.sgml. The second one isn't ideal,
but I don't see a simpler way. 

patch 2 implements this.


Here's a v11.


Changes since v10, all in 0001:
 - Whether rd_options holds StdRdOptions is now decided once, where
   RelationParseRelOptions() picks the parser, and cached in a new
   rd_stdoptions field.  The two checks can no longer disagree, and the
   per-tuple heap insert path is back to a single inline test, same as
   master, fixing a small performance hit.
 - New RelationGetTableAmOptions() helper replaces two copies of the
   parser-choice test.


cheers


andrew

--
Andrew Dunstan
EDB: https://www.enterprisedb.com

Re: Allow table AMs to define their own reloptions

От:
Andrew Dunstan <andrew@dunslane.net>
Дата:
Вложения:


On 2026-10-10 Sa 7:29 AM, Andrew Dunstan wrote:


On 2026-10-02 Fr 5:48 PM, Andrew Dunstan wrote:


On 2026-10-01 Th 10:57 AM, Álvaro Herrera wrote:
On 2026-Sep-30, Andrew Dunstan wrote:

diff --git a/src/include/access/tableam.h b/src/include/access/tableam.h
index ea3f2a6be99..6dfc6e8026c 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -17,6 +17,7 @@ #ifndef TABLEAM_H #define TABLEAM_H 
+#include "access/amapi.h" #include "access/relscan.h" #include "access/sdir.h" #include "access/xact.h"
I don't love this.  I have a bunch of patches queued to remove includes
from other includes to reduce cross-header contamination.  This kind of
change makes it impossible to remove the cross inclusion here and is
more or less a step backwards.  (It's not _too_ bad because tableam.h is
not as widely used

Is there a better way to have a function definition that can be used in
both amapi.h and tableam.h without this cross-header inclusion?


Yes, there's no need for it. All the other TableAmRoutine members are
declared as bare function pointers, so amoptions now is too:

     bytea      *(*amoptions) (Datum reloptions, bool validate);

and the include is gone. The type is identical to amoptions_function,
so nothing else changes.

Other comments on verbiage, just passing by:

I'm not much in love with the LLM-written comments TBH -- I don't think
phrases like "owns the option set entirely" are valuable, for example.


You're absolutely right! :-)

I should have been much more careful. I hope the attached is more to your liking.


Also, the comment just above the ATValidateAccessMethodOptions() call in
ATController is redundant: it would be enough to say "validate options
as needed", and then have the comment atop ATValidateAccessMethodOptions()
itself carry the explanation of what we do and why.


Done


In tableam.sgml, I'm not sure it makes much sense to state "The callback
has the same signature as the corresponding index AM callback".  Why not
just say what the signature is without directing the user to read a
reference page that's not relevant to the topic of table AMs?  I think
the first mention of reloptions in that page should be <firstterm>.

It also talks about validating and throwing ereport(ERROR) but it
doesn't say in so many words what must happen or not happen on each
possible value of 'validate'.  It could be clearer.


I've rewritten that section. It's now called "Table Access Method
Options", since a lot of what goes under the user-facing name "storage
parameters" isn't about storage, and refers to CREATE TABLE for that.
It uses <firstterm> for reloptions, gives the signature, and says what
the callback must do when validate is true (error on unrecognized or
invalid values, and never substitute something else for them) and when
it's false (ignore invalid entries without error).

There's also "raises an error rather than silently dropping the value".
I mean, why not say "rather than launching an ICBM"?  Why not just
"raises an error, period"?


Done


If I were the user of such an AM, I would not be sure how to interpret
the phrase "validate that the option read with SELECT reloptions FROM
pg_class are the ones that will be used".  What does that mean exactly?
Should it say "examine" rather than "validate"?


That sentence is gone. What it was trying to say is now stated
directly: the callback must not accept an invalid value and use
something else in its place, since the stored parameters would then
not be the ones in effect.


I wrote:

On 2026-09-30 We 5:22 PM, Zsolt Parragi wrote:
pg_dump has the option "--no-table-access-method". Should that somehow
interact with this feature? As currently that can result in non
restorable dumps.


Good catch.

Worse, the CREATE TABLE fails, so the table and its data are lost,
with both pg_dump and pg_restore --no-table-access-method.

We can't just move the options to a later ALTER TABLE, because some
standard ones (toast_value_type) only matter at creation time. So my
plan, as a second patch:

- A function pg_reloption_is_standard(name), true if the option is
  registered for RELOPT_KIND_HEAP (including ones an AM inherits via
  add_reloption_to_kind()).

- For non-heap tables and matviews, pg_dump keeps standard options in
  the CREATE, and puts AM-specific ones in a separate ALTER TABLE ...
  SET (...) TOC entry, which --no-table-access-method omits or skips.

- TAP tests using dummy_table_am.

That requires AMs to inherit standard option names rather than
redefine them, and to have their own options work when set by ALTER
TABLE on an empty table, since every restore would apply them that
way. I'd document both in tableam.sgml. The second one isn't ideal,
but I don't see a simpler way. 

patch 2 implements this.


Here's a v11.


Changes since v10, all in 0001:
 - Whether rd_options holds StdRdOptions is now decided once, where
   RelationParseRelOptions() picks the parser, and cached in a new
   rd_stdoptions field.  The two checks can no longer disagree, and the
   per-tuple heap insert path is back to a single inline test, same as
   master, fixing a small performance hit.
 - New RelationGetTableAmOptions() helper replaces two copies of the
   parser-choice test.





Here's a v12. Changes are cosmetic to make it pgindent clean.


cheers


andrew

--
Andrew Dunstan
EDB: https://www.enterprisedb.com

Re: Allow table AMs to define their own reloptions

От:
Osama Abdul Qader <osamaabdulqader.cs@gmail.com>
Дата:
Hey Everyone,

I've been following this thread since September 8, albeit passively, and I'm interested in contributing by reviewing the patches. Could you let me know if the work is still ongoing?
With regards,
Osama Abdul Qader


On Sun, Oct 11, 2026 at 6:53 PM Andrew Dunstan <andrew@dunslane.net> wrote:


On 2026-10-10 Sa 7:29 AM, Andrew Dunstan wrote:


On 2026-10-02 Fr 5:48 PM, Andrew Dunstan wrote:


On 2026-10-01 Th 10:57 AM, Álvaro Herrera wrote:
On 2026-Sep-30, Andrew Dunstan wrote:

diff --git a/src/include/access/tableam.h b/src/include/access/tableam.h
index ea3f2a6be99..6dfc6e8026c 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -17,6 +17,7 @@ #ifndef TABLEAM_H #define TABLEAM_H 
+#include "access/amapi.h" #include "access/relscan.h" #include "access/sdir.h" #include "access/xact.h"
I don't love this.  I have a bunch of patches queued to remove includes
from other includes to reduce cross-header contamination.  This kind of
change makes it impossible to remove the cross inclusion here and is
more or less a step backwards.  (It's not _too_ bad because tableam.h is
not as widely used

Is there a better way to have a function definition that can be used in
both amapi.h and tableam.h without this cross-header inclusion?


Yes, there's no need for it. All the other TableAmRoutine members are
declared as bare function pointers, so amoptions now is too:

     bytea      *(*amoptions) (Datum reloptions, bool validate);

and the include is gone. The type is identical to amoptions_function,
so nothing else changes.

Other comments on verbiage, just passing by:

I'm not much in love with the LLM-written comments TBH -- I don't think
phrases like "owns the option set entirely" are valuable, for example.


You're absolutely right! :-)

I should have been much more careful. I hope the attached is more to your liking.


Also, the comment just above the ATValidateAccessMethodOptions() call in
ATController is redundant: it would be enough to say "validate options
as needed", and then have the comment atop ATValidateAccessMethodOptions()
itself carry the explanation of what we do and why.


Done


In tableam.sgml, I'm not sure it makes much sense to state "The callback
has the same signature as the corresponding index AM callback".  Why not
just say what the signature is without directing the user to read a
reference page that's not relevant to the topic of table AMs?  I think
the first mention of reloptions in that page should be <firstterm>.

It also talks about validating and throwing ereport(ERROR) but it
doesn't say in so many words what must happen or not happen on each
possible value of 'validate'.  It could be clearer.


I've rewritten that section. It's now called "Table Access Method
Options", since a lot of what goes under the user-facing name "storage
parameters" isn't about storage, and refers to CREATE TABLE for that.
It uses <firstterm> for reloptions, gives the signature, and says what
the callback must do when validate is true (error on unrecognized or
invalid values, and never substitute something else for them) and when
it's false (ignore invalid entries without error).

There's also "raises an error rather than silently dropping the value".
I mean, why not say "rather than launching an ICBM"?  Why not just
"raises an error, period"?


Done


If I were the user of such an AM, I would not be sure how to interpret
the phrase "validate that the option read with SELECT reloptions FROM
pg_class are the ones that will be used".  What does that mean exactly?
Should it say "examine" rather than "validate"?


That sentence is gone. What it was trying to say is now stated
directly: the callback must not accept an invalid value and use
something else in its place, since the stored parameters would then
not be the ones in effect.


I wrote:

On 2026-09-30 We 5:22 PM, Zsolt Parragi wrote:
pg_dump has the option "--no-table-access-method". Should that somehow
interact with this feature? As currently that can result in non
restorable dumps.


Good catch.

Worse, the CREATE TABLE fails, so the table and its data are lost,
with both pg_dump and pg_restore --no-table-access-method.

We can't just move the options to a later ALTER TABLE, because some
standard ones (toast_value_type) only matter at creation time. So my
plan, as a second patch:

- A function pg_reloption_is_standard(name), true if the option is
  registered for RELOPT_KIND_HEAP (including ones an AM inherits via
  add_reloption_to_kind()).

- For non-heap tables and matviews, pg_dump keeps standard options in
  the CREATE, and puts AM-specific ones in a separate ALTER TABLE ...
  SET (...) TOC entry, which --no-table-access-method omits or skips.

- TAP tests using dummy_table_am.

That requires AMs to inherit standard option names rather than
redefine them, and to have their own options work when set by ALTER
TABLE on an empty table, since every restore would apply them that
way. I'd document both in tableam.sgml. The second one isn't ideal,
but I don't see a simpler way. 

patch 2 implements this.


Here's a v11.


Changes since v10, all in 0001:
 - Whether rd_options holds StdRdOptions is now decided once, where
   RelationParseRelOptions() picks the parser, and cached in a new
   rd_stdoptions field.  The two checks can no longer disagree, and the
   per-tuple heap insert path is back to a single inline test, same as
   master, fixing a small performance hit.
 - New RelationGetTableAmOptions() helper replaces two copies of the
   parser-choice test.





Here's a v12. Changes are cosmetic to make it pgindent clean.


cheers


andrew

--
Andrew Dunstan
EDB: https://www.enterprisedb.com

Re: Allow table AMs to define their own reloptions

От:
Zsolt Parragi <zsolt.parragi@percona.com>
Дата:
> That requires AMs to inherit standard option names rather than
> redefine

It looks a lot better this way, but shouldn't the documentation
mention somewhere that AMs that don't do this, like
dummy_custom_table_am can fail to restore --no-table-access-method
dumps from other AMs?

+
+/* The standard options, all of which dummy_table_am accepts */
+static const relopt_parse_elt dt_std_options[] = {
+	{"fillfactor", RELOPT_TYPE_INT,
+	offsetof(struct DummyTableOptions, std.fillfactor)},

and

+	for (int j = 0; j < lengthof(dt_std_options); j++)
+	{
+		add_reloption_to_kind(dt_std_options[j].optname, dt_relopt_kind);
+		dt_relopt_tab[i++] = dt_std_options[j];
+	}
+

Wouldn't a helper be useful for this based on / around
stdRdOptionsTab, so that it doesn't require this much fragile
copy-pasting?


Re: Allow table AMs to define their own reloptions

От:
Andrew Dunstan <andrew@dunslane.net>
Дата:
Вложения:

On 2026-10-11 Su 6:26 PM, Zsolt Parragi wrote:
>> That requires AMs to inherit standard option names rather than
>> redefine
> It looks a lot better this way, but shouldn't the documentation
> mention somewhere that AMs that don't do this, like
> dummy_custom_table_am can fail to restore --no-table-access-method
> dumps from other AMs?
>
> +
> +/* The standard options, all of which dummy_table_am accepts */
> +static const relopt_parse_elt dt_std_options[] = {
> +	{"fillfactor", RELOPT_TYPE_INT,
> +	offsetof(struct DummyTableOptions, std.fillfactor)},
>
> and
>
> +	for (int j = 0; j < lengthof(dt_std_options); j++)
> +	{
> +		add_reloption_to_kind(dt_std_options[j].optname, dt_relopt_kind);
> +		dt_relopt_tab[i++] = dt_std_options[j];
> +	}
> +
>
> Wouldn't a helper be useful for this based on / around
> stdRdOptionsTab, so that it doesn't require this much fragile
> copy-pasting?


Hi, thanks (again) for the review. here's a v13 that I think addresses 
your points.


Changes since v12:
   - 0001: new add_std_reloptions_to_kind(), which makes all the
     standard options valid for an AM's relopt_kind and copies their
     parse table entries, for an AM whose options struct begins with a
     StdRdOptions.  NUM_STD_RELOPTIONS gives the number of entries, and
     a static assertion keeps it in step with stdRdOptionsTab.
     dummy_table_am uses it instead of its own copy of the table.
   - 0001: fix tableam.h comments that referred to the old title of the
     documentation section.
   - 0002: tableam.sgml now says that a --no-table-access-method dump
     can only be restored if the default access method accepts every
     standard option set on the dumped tables, so an AM that supplies
     amoptions should accept them all unless it has a good reason not to.


cheers

andrew


--
Andrew Dunstan
EDB: https://www.enterprisedb.com

Re: Allow table AMs to define their own reloptions

От:
Andrew Dunstan <andrew@dunslane.net>
Дата:

On 2026-10-11 Su 2:24 PM, Osama Abdul Qader wrote:
> Hey Everyone,
>
> I've been following this thread since September 8, albeit passively, 
> and I'm interested in contributing by reviewing the patches. Could you 
> let me know if the work is still ongoing?
>
>
>

Please don't top-post.


Work is ongoing. I have just posted a v13 set.


cheers


andrew

--
Andrew Dunstan
EDB: https://www.enterprisedb.com



Re: Allow table AMs to define their own reloptions

От:
Rui Zhao <zhaorui126@gmail.com>
Дата:
Вложения:
Hi Andrew,

Thanks for adding the helper for standard options, which is very helpful
for AM extensions.

I found an issue:
In a fresh backend, ALTER TABLE can change an AM-specific option without
taking the lock requested by the AM. dummy_table_am registers option_int
with AccessExclusiveLock, but I got ShareUpdateExclusiveLock on v13.

Setup in one connection:

CREATE EXTENSION dummy_table_am;
CREATE TABLE t_std (a int) USING dummy_table_am WITH (option_int = 7);

Then, in a new connection:

BEGIN;
ALTER TABLE t_std SET (option_int = 9);
SELECT mode FROM pg_locks
WHERE pid = pg_backend_pid() AND relation = 't_std'::regclass;
-- ShareUpdateExclusiveLock
ROLLBACK;

With LOAD 'dummy_table_am' before BEGIN in another new connection, the
same commands take AccessExclusiveLock. RESET has the same problem.

The reason is that ProcessUtilitySlow() calls AlterTableGetLockLevel()
before opening the relation and loading its AM. option_int is not
registered at that point.
AlterTableGetRelOptionsLockLevel() ignores the unknown name and returns
NoLock, leaving AlterTableGetLockLevel()'s ShareUpdateExclusiveLock
minimum unchanged. Loading the AM later does not upgrade that lock.

This is an existing helper issue, not a v13 regression. I reproduced it
with bloom on unpatched master at e75fcc9867f. Setup in one connection:

CREATE EXTENSION bloom;
CREATE TABLE bloom_probe (a int);
CREATE INDEX bloom_probe_idx ON bloom_probe USING bloom (a);

Then, in a new connection:

BEGIN;
ALTER INDEX bloom_probe_idx SET (length = 100);
SELECT mode FROM pg_locks
WHERE pid = pg_backend_pid() AND relation = 'bloom_probe_idx'::regclass
ORDER BY mode;
-- ShareUpdateExclusiveLock
ROLLBACK;

With LOAD 'bloom' before BEGIN in another new connection, the same
commands take AccessExclusiveLock.

With 0001 on top of v13, an option not yet registered requires
AccessExclusiveLock. Registered options keep their declared lock levels.
Until the AM is loaded, we cannot tell which lock the option requires.
This ensures the lock is strong enough. I think this is a harmless and
safe fix with minimal changes.

The TAP test checks SET and RESET for both test AMs, with and without
loading the library first, and checks that fillfactor still uses the
weaker lock.

Core regression, isolation and dummy_table_am tests passed with the
patch. Without the fix, the four cases without LOAD fail.

Regards,
Rui

Re: Allow table AMs to define their own reloptions

От:
Andrew Dunstan <andrew@dunslane.net>
Дата:
Вложения:

On 2026-10-21 We 10:56 AM, Rui Zhao wrote:
> Hi Andrew,
>
> Thanks for adding the helper for standard options, which is very helpful
> for AM extensions.
>
> I found an issue:
> In a fresh backend, ALTER TABLE can change an AM-specific option without
> taking the lock requested by the AM. dummy_table_am registers option_int
> with AccessExclusiveLock, but I got ShareUpdateExclusiveLock on v13.
>
> Setup in one connection:
>
> CREATE EXTENSION dummy_table_am;
> CREATE TABLE t_std (a int) USING dummy_table_am WITH (option_int = 7);
>
> Then, in a new connection:
>
> BEGIN;
> ALTER TABLE t_std SET (option_int = 9);
> SELECT mode FROM pg_locks
> WHERE pid = pg_backend_pid() AND relation = 't_std'::regclass;
> -- ShareUpdateExclusiveLock
> ROLLBACK;
>
> With LOAD 'dummy_table_am' before BEGIN in another new connection, the
> same commands take AccessExclusiveLock. RESET has the same problem.
>
> The reason is that ProcessUtilitySlow() calls AlterTableGetLockLevel()
> before opening the relation and loading its AM. option_int is not
> registered at that point.
> AlterTableGetRelOptionsLockLevel() ignores the unknown name and returns
> NoLock, leaving AlterTableGetLockLevel()'s ShareUpdateExclusiveLock
> minimum unchanged. Loading the AM later does not upgrade that lock.
>
> This is an existing helper issue, not a v13 regression. I reproduced it
> with bloom on unpatched master at e75fcc9867f. Setup in one connection:
>
> CREATE EXTENSION bloom;
> CREATE TABLE bloom_probe (a int);
> CREATE INDEX bloom_probe_idx ON bloom_probe USING bloom (a);
>
> Then, in a new connection:
>
> BEGIN;
> ALTER INDEX bloom_probe_idx SET (length = 100);
> SELECT mode FROM pg_locks
> WHERE pid = pg_backend_pid() AND relation = 'bloom_probe_idx'::regclass
> ORDER BY mode;
> -- ShareUpdateExclusiveLock
> ROLLBACK;
>
> With LOAD 'bloom' before BEGIN in another new connection, the same
> commands take AccessExclusiveLock.
>
> With 0001 on top of v13, an option not yet registered requires
> AccessExclusiveLock. Registered options keep their declared lock levels.
> Until the AM is loaded, we cannot tell which lock the option requires.
> This ensures the lock is strong enough. I think this is a harmless and
> safe fix with minimal changes.
>
> The TAP test checks SET and RESET for both test AMs, with and without
> loading the library first, and checks that fillfactor still uses the
> weaker lock.
>
> Core regression, isolation and dummy_table_am tests passed with the
> patch. Without the fix, the four cases without LOAD fail.
>

Nice Catch! I agree with your analysis and your fix.

I doubt this is worth backpatching.

Here's a v14 that incorporates your fix. I changed the tests some. 
tableam.sgml now describes which options need AccessExclusiveLock.

One case this doesn't cover: options are matched by name across all
kinds, so an AM option with the same name as a core option but a
stronger lock gets the core option's lock in a backend that hasn't
loaded the AM. Fixing that would mean finding the AM before choosing
the lock, so I've just documented that such an option shouldn't
declare a stronger lock than the built-in one.

cheers


andrew

--
Andrew Dunstan
EDB: https://www.enterprisedb.com
FAQ