From 918e21d25178c8ae09808c581a782002f702ed9e Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Tue, 17 Sep 2024 15:53:26 -0400 Subject: Repair pg_upgrade for identity sequences with non-default persistence. Since we introduced unlogged sequences in v15, identity sequences have defaulted to having the same persistence as their owning table. However, it is possible to change that with ALTER SEQUENCE, and pg_dump tries to preserve the logged-ness of sequences when it doesn't match (as indeed it wouldn't for an unlogged table from before v15). The fly in the ointment is that ALTER SEQUENCE SET [UN]LOGGED fails in binary-upgrade mode, because it needs to assign a new relfilenode which we cannot permit in that mode. Thus, trying to pg_upgrade a database containing a mismatching identity sequence failed. To fix, add syntax to ADD/ALTER COLUMN GENERATED AS IDENTITY to allow the sequence's persistence to be set correctly at creation, and use that instead of ALTER SEQUENCE SET [UN]LOGGED in pg_dump. (I tried to make SET [UN]LOGGED work without any pg_dump modifications, but that seems too fragile to be a desirable answer. This way should be markedly faster anyhow.) In passing, document the previously-undocumented SEQUENCE NAME option that pg_dump also relies on for identity sequences; I see no value in trying to pretend it doesn't exist. Per bug #18618 from Anthony Hsu. Back-patch to v15 where we invented this stuff. Discussion: https://postgr.es/m/18618-d4eb26d669ed110a@postgresql.org --- src/backend/commands/sequence.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/backend/commands/sequence.c') diff --git a/src/backend/commands/sequence.c b/src/backend/commands/sequence.c index b37fd688d34..0188e8bbd5b 100644 --- a/src/backend/commands/sequence.c +++ b/src/backend/commands/sequence.c @@ -1347,7 +1347,10 @@ init_params(ParseState *pstate, List *options, bool for_identity, /* * The parser allows this, but it is only for identity columns, in * which case it is filtered out in parse_utilcmd.c. We only get - * here if someone puts it into a CREATE SEQUENCE. + * here if someone puts it into a CREATE SEQUENCE, where it'd be + * redundant. (The same is true for the equally-nonstandard + * LOGGED and UNLOGGED options, but for those, the default error + * below seems sufficient.) */ ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), -- cgit v1.2.3