mirror of
https://github.com/postgres/postgres.git
synced 2025-06-13 07:41:39 +03:00
Make ALTER SEQUENCE, including RESTART, fully transactional.
Previously the changes to the "data" part of the sequence, i.e. the one containing the current value, were not transactional, whereas the definition, including minimum and maximum value were. That leads to odd behaviour if a schema change is rolled back, with the potential that out-of-bound sequence values can be returned. To avoid the issue create a new relfilenode fork whenever ALTER SEQUENCE is executed, similar to how TRUNCATE ... RESTART IDENTITY already is already handled. This commit also makes ALTER SEQUENCE RESTART transactional, as it seems to be too confusing to have some forms of ALTER SEQUENCE behave transactionally, some forms not. This way setval() and nextval() are not transactional, but DDL is, which seems to make sense. This commit also rolls back parts of the changes made in3d092fe540
andf8dc1985f
as they're now not needed anymore. Author: Andres Freund Discussion: https://postgr.es/m/20170522154227.nvafbsm62sjpbxvd@alap3.anarazel.de Backpatch: Bug is in master/v10 only
This commit is contained in:
@ -171,7 +171,7 @@ ALTER SEQUENCE [ IF EXISTS ] <replaceable class="parameter">name</replaceable> S
|
||||
<para>
|
||||
The optional clause <literal>RESTART [ WITH <replaceable
|
||||
class="parameter">restart</replaceable> ]</literal> changes the
|
||||
current value of the sequence. This is equivalent to calling the
|
||||
current value of the sequence. This is similar to calling the
|
||||
<function>setval</> function with <literal>is_called</literal> =
|
||||
<literal>false</>: the specified value will be returned by the
|
||||
<emphasis>next</> call of <function>nextval</>.
|
||||
@ -182,11 +182,11 @@ ALTER SEQUENCE [ IF EXISTS ] <replaceable class="parameter">name</replaceable> S
|
||||
</para>
|
||||
|
||||
<para>
|
||||
Like a <function>setval</function> call, a <literal>RESTART</literal>
|
||||
operation on a sequence is never rolled back, to avoid blocking of
|
||||
concurrent transactions that obtain numbers from the same sequence.
|
||||
(The other clauses cause ordinary catalog updates that can be rolled
|
||||
back.)
|
||||
In contrast to a <function>setval</function> call,
|
||||
a <literal>RESTART</literal> operation on a sequence is transactional
|
||||
and blocks concurrent transactions from obtaining numbers from the
|
||||
same sequence. If that's not the desired mode of
|
||||
operation, <function>setval</> should be used.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
@ -307,8 +307,7 @@ ALTER SEQUENCE [ IF EXISTS ] <replaceable class="parameter">name</replaceable> S
|
||||
<para>
|
||||
<command>ALTER SEQUENCE</command> blocks
|
||||
concurrent <function>nextval</function>, <function>currval</function>,
|
||||
<function>lastval</function>, and <command>setval</command> calls, except
|
||||
if only the <literal>RESTART</literal> clause is used.
|
||||
<function>lastval</function>, and <command>setval</command> calls.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
|
Reference in New Issue
Block a user