| From: | Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com> |
|---|---|
| To: | Zsolt Parragi <zsolt(dot)parragi(at)percona(dot)com> |
| Cc: | PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Andrew Dunstan <andrew(at)dunslane(dot)net> |
| Subject: | Re: Long reloption values are truncated by pg_dump and pg_get_indexdef() |
| Date: | 2026-11-19 03:01:31 |
| Message-ID: | FD2A2EEC-B77D-4C0D-B04F-ADFE0D6326C2@gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
> On Nov 19, 2026, at 04:50, Zsolt Parragi <zsolt(dot)parragi(at)percona(dot)com> wrote:
>
> Hello
>
> pg_dump's appendReloptionsArray() and ruleutils' get_reloptions()
> print an option value without quotes if it is a valid identifier that
> doesn't need quoting. They don't check the length, so a string value
> of 64 bytes or more is printed unquoted. When the output is replayed
> the scanner truncates it to 63 bytes. The only sign of this is a
> NOTICE during restore, the option silently ends up with a different
> value.
>
> None of the built-in reloptions can have such a value, but string
> options defined by extensions can. Simple repro with the
> dummy_index_am test module:
>
> CREATE EXTENSION dummy_index_am;
> CREATE TABLE t (i int4);
> CREATE INDEX ti ON t USING dummy_index_am (i)
> WITH (option_string_null =
> 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa');
> SELECT pg_get_indexdef('ti'::regclass);
> -- ... WITH (option_string_null=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)
>
> pg_dump prints the same, and restoring it results in a 63 character value.
>
> Currently this only affects index AMs with string options, but there
> are 2 proposals that make it more likely to happen: tablespace options
> defined by extensions [1] (where I ran into it), and table AM
> reloptions [2].
>
> The attached patch quotes values that are too long to be identifiers
> in both places, and adds a test to dummy_index_am.
>
> [1]: https://postgr.es/m/CAN4CZFNxu5BgBge12C%3Df3JV9LdZvUiG%2BpQHOCutATewSywzFuw%40mail.gmail.com
> [2]: https://postgr.es/m/ea1c4d33-0780-473c-96dc-1468cf733a04@dunslane.net
> <v1-0001-Quote-reloption-values-too-long-to-be-identifiers.patch>
I can reproduce the issue with your repro example, and the fix looks good to me.
My only comment is about the new comment:
```
and is short enough not to be truncated as one.
```
From this comment, I cannot quickly understand why the length check is needed. I would propose something like:
```
and is shorter than NAMEDATALEN bytes. Longer values must be quoted as string literals to avoid identifier truncation when the output is parsed.
```
As a non-native English speaker, I always prefer simpler and more explicit code comments. If other folks consider the wording in the patch good enough, I’m fine with withdrawing my comment.
Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Joao Rito | 2026-11-19 03:12:02 | [PATCH] Reject empty string in option_parse_int() |
| Previous Message | Kyotaro Horiguchi | 2026-11-19 02:54:15 | Re: [PATCH] doc: Fix autovacuum_max_workers and autovacuum_worker_slots descriptions |