diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2024-09-17 15:53:26 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2024-09-17 15:53:35 -0400 |
commit | 918e21d25178c8ae09808c581a782002f702ed9e (patch) | |
tree | d15798662be397175ee9ece367a5a25537d004a5 /doc/src | |
parent | 2520226c953c0b443791a185a8d1fb8b71d9fe9e (diff) | |
download | postgresql-918e21d25178c8ae09808c581a782002f702ed9e.tar.gz postgresql-918e21d25178c8ae09808c581a782002f702ed9e.zip |
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
Diffstat (limited to 'doc/src')
-rw-r--r-- | doc/src/sgml/ref/create_table.sgml | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/doc/src/sgml/ref/create_table.sgml b/doc/src/sgml/ref/create_table.sgml index 9d552241a16..c1855b8d827 100644 --- a/doc/src/sgml/ref/create_table.sgml +++ b/doc/src/sgml/ref/create_table.sgml @@ -924,8 +924,8 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM <para> This clause creates the column as an <firstterm>identity column</firstterm>. It will have an implicit sequence attached to it - and the column in new rows will automatically have values from the - sequence assigned to it. + and in newly-inserted rows the column will automatically have values + from the sequence assigned to it. Such a column is implicitly <literal>NOT NULL</literal>. </para> @@ -955,9 +955,16 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM </para> <para> - The optional <replaceable>sequence_options</replaceable> clause can be - used to override the options of the sequence. - See <xref linkend="sql-createsequence"/> for details. + The optional <replaceable>sequence_options</replaceable> clause can + be used to override the parameters of the sequence. The available + options include those shown for <xref linkend="sql-createsequence"/>, + plus <literal>SEQUENCE NAME <replaceable>name</replaceable></literal>, + <literal>LOGGED</literal>, and <literal>UNLOGGED</literal>, which + allow selection of the name and persistence level of the + sequence. Without <literal>SEQUENCE NAME</literal>, the system + chooses an unused name for the sequence. + Without <literal>LOGGED</literal> or <literal>UNLOGGED</literal>, + the sequence will have the same persistence level as the table. </para> </listitem> </varlistentry> |