1
0
mirror of https://github.com/postgres/postgres.git synced 2025-08-28 18:48:04 +03:00

Unlogged sequences

Add support for unlogged sequences.  Unlike for unlogged tables, this
is not a performance feature.  It allows sequences associated with
unlogged tables to be excluded from replication.

A new subcommand ALTER SEQUENCE ... SET LOGGED/UNLOGGED is added.

An identity/serial sequence now automatically gets and follows the
persistence level (logged/unlogged) of its owning table.  (The
sequences owned by temporary tables were already temporary through the
separate mechanism in RangeVarAdjustRelationPersistence().)  But you
can still change the persistence of an owned sequence separately.
Also, pg_dump and pg_upgrade preserve the persistence of existing
sequences.

Discussion: https://www.postgresql.org/message-id/flat/04e12818-2f98-257c-b926-2845d74ed04f%402ndquadrant.com
This commit is contained in:
Peter Eisentraut
2022-04-07 16:13:23 +02:00
parent bab588cd5c
commit 344d62fb9a
16 changed files with 237 additions and 31 deletions

View File

@@ -21,7 +21,7 @@ PostgreSQL documentation
<refsynopsisdiv>
<synopsis>
CREATE [ TEMPORARY | TEMP ] SEQUENCE [ IF NOT EXISTS ] <replaceable class="parameter">name</replaceable>
CREATE [ { TEMPORARY | TEMP } | UNLOGGED ] SEQUENCE [ IF NOT EXISTS ] <replaceable class="parameter">name</replaceable>
[ AS <replaceable class="parameter">data_type</replaceable> ]
[ INCREMENT [ BY ] <replaceable class="parameter">increment</replaceable> ]
[ MINVALUE <replaceable class="parameter">minvalue</replaceable> | NO MINVALUE ] [ MAXVALUE <replaceable class="parameter">maxvalue</replaceable> | NO MAXVALUE ]
@@ -92,6 +92,27 @@ SELECT * FROM <replaceable>name</replaceable>;
</listitem>
</varlistentry>
<varlistentry>
<term><literal>UNLOGGED</literal></term>
<listitem>
<para>
If specified, the sequence is created as an unlogged sequence. Changes
to unlogged sequences are not written to the write-ahead log. They are
not crash-safe: an unlogged sequence is automatically reset to its
initial state after a crash or unclean shutdown. Unlogged sequences are
also not replicated to standby servers.
</para>
<para>
Unlike unlogged tables, unlogged sequences do not offer a significant
performance advantage. This option is mainly intended for sequences
associated with unlogged tables via identity columns or serial columns.
In those cases, it usually wouldn't make sense to have the sequence
WAL-logged and replicated but not its associated table.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>IF NOT EXISTS</literal></term>
<listitem>