mirror of
https://github.com/postgres/postgres.git
synced 2025-08-08 06:02:22 +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:
@@ -31,6 +31,7 @@ ALTER SEQUENCE [ IF EXISTS ] <replaceable class="parameter">name</replaceable>
|
||||
[ RESTART [ [ WITH ] <replaceable class="parameter">restart</replaceable> ] ]
|
||||
[ CACHE <replaceable class="parameter">cache</replaceable> ] [ [ NO ] CYCLE ]
|
||||
[ OWNED BY { <replaceable class="parameter">table_name</replaceable>.<replaceable class="parameter">column_name</replaceable> | NONE } ]
|
||||
ALTER SEQUENCE [ IF EXISTS ] <replaceable class="parameter">name</replaceable> SET { LOGGED | UNLOGGED }
|
||||
ALTER SEQUENCE [ IF EXISTS ] <replaceable class="parameter">name</replaceable> OWNER TO { <replaceable class="parameter">new_owner</replaceable> | CURRENT_ROLE | CURRENT_USER | SESSION_USER }
|
||||
ALTER SEQUENCE [ IF EXISTS ] <replaceable class="parameter">name</replaceable> RENAME TO <replaceable class="parameter">new_name</replaceable>
|
||||
ALTER SEQUENCE [ IF EXISTS ] <replaceable class="parameter">name</replaceable> SET SCHEMA <replaceable class="parameter">new_schema</replaceable>
|
||||
@@ -237,6 +238,17 @@ ALTER SEQUENCE [ IF EXISTS ] <replaceable class="parameter">name</replaceable> S
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><literal>SET { LOGGED | UNLOGGED }</literal></term>
|
||||
<listitem>
|
||||
<para>
|
||||
This form changes the sequence from unlogged to logged or vice-versa
|
||||
(see <xref linkend="sql-createsequence"/>). It cannot be applied to a
|
||||
temporary sequence.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><literal>OWNED BY</literal> <replaceable class="parameter">table_name</replaceable>.<replaceable class="parameter">column_name</replaceable></term>
|
||||
<term><literal>OWNED BY NONE</literal></term>
|
||||
|
@@ -753,6 +753,12 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
|
||||
(see <xref linkend="sql-createtable-unlogged"/>). It cannot be applied
|
||||
to a temporary table.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
This also changes the persistence of any sequences linked to the table
|
||||
(for identity or serial columns). However, it is also possible to
|
||||
change the persistence of such sequences separately.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
|
@@ -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>
|
||||
|
@@ -215,6 +215,11 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
|
||||
Any indexes created on an unlogged table are automatically unlogged as
|
||||
well.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
If this is specified, any sequences created together with the unlogged
|
||||
table (for identity or serial columns) are also created as unlogged.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
|
@@ -981,9 +981,10 @@ PostgreSQL documentation
|
||||
<term><option>--no-unlogged-table-data</option></term>
|
||||
<listitem>
|
||||
<para>
|
||||
Do not dump the contents of unlogged tables. This option has no
|
||||
effect on whether or not the table definitions (schema) are dumped;
|
||||
it only suppresses dumping the table data. Data in unlogged tables
|
||||
Do not dump the contents of unlogged tables and sequences. This
|
||||
option has no effect on whether or not the table and sequence
|
||||
definitions (schema) are dumped; it only suppresses dumping the table
|
||||
and sequence data. Data in unlogged tables and sequences
|
||||
is always excluded when dumping from a standby server.
|
||||
</para>
|
||||
</listitem>
|
||||
|
Reference in New Issue
Block a user