@@ -12397,24 +12397,6 @@ nextval('foo'::text) <lineannotation><literal>foo</literal> is looked up at
12397
12397
see its command reference page for more information.
12398
12398
</para>
12399
12399
12400
- <important>
12401
- <para>
12402
- To avoid blocking concurrent transactions that obtain numbers from
12403
- the same sequence, a <function>nextval</function> operation is never
12404
- rolled back; that is, once a value has been fetched it is considered
12405
- used and will not be returned again. This is true even if the
12406
- surrounding transaction later aborts, or if the calling query ends
12407
- up not using the value. For example an <command>INSERT</command> with
12408
- an <literal>ON CONFLICT</literal> clause will compute the to-be-inserted
12409
- tuple, including doing any required <function>nextval</function>
12410
- calls, before detecting any conflict that would cause it to follow
12411
- the <literal>ON CONFLICT</literal> rule instead. Such cases will leave
12412
- unused <quote>holes</quote> in the sequence of assigned values.
12413
- Thus, <productname>PostgreSQL</productname> sequence objects <emphasis>cannot
12414
- be used to obtain <quote>gapless</quote> sequences</emphasis>.
12415
- </para>
12416
- </important>
12417
-
12418
12400
<para>
12419
12401
This function requires <literal>USAGE</literal>
12420
12402
or <literal>UPDATE</literal> privilege on the sequence.
@@ -12491,13 +12473,6 @@ SELECT setval('foo', 42, false); <lineannotation>Next <function>nextval</func
12491
12473
The result returned by <function>setval</function> is just the value of its
12492
12474
second argument.
12493
12475
</para>
12494
- <important>
12495
- <para>
12496
- Because sequences are non-transactional, changes made by
12497
- <function>setval</function> are not undone if the transaction rolls
12498
- back.
12499
- </para>
12500
- </important>
12501
12476
12502
12477
<para>
12503
12478
This function requires <literal>UPDATE</literal> privilege on the
@@ -12508,6 +12483,42 @@ SELECT setval('foo', 42, false); <lineannotation>Next <function>nextval</func
12508
12483
</variablelist>
12509
12484
</para>
12510
12485
12486
+ <caution>
12487
+ <para>
12488
+ To avoid blocking concurrent transactions that obtain numbers from
12489
+ the same sequence, the value obtained by <function>nextval</function>
12490
+ is not reclaimed for re-use if the calling transaction later aborts.
12491
+ This means that transaction aborts or database crashes can result in
12492
+ gaps in the sequence of assigned values. That can happen without a
12493
+ transaction abort, too. For example an <command>INSERT</command> with
12494
+ an <literal>ON CONFLICT</literal> clause will compute the to-be-inserted
12495
+ tuple, including doing any required <function>nextval</function>
12496
+ calls, before detecting any conflict that would cause it to follow
12497
+ the <literal>ON CONFLICT</literal> rule instead.
12498
+ Thus, <productname>PostgreSQL</productname> sequence
12499
+ objects <emphasis>cannot be used to obtain <quote>gapless</quote>
12500
+ sequences</emphasis>.
12501
+ </para>
12502
+
12503
+ <para>
12504
+ Likewise, sequence state changes made by <function>setval</function>
12505
+ are immediately visible to other transactions, and are not undone if
12506
+ the calling transaction rolls back.
12507
+ </para>
12508
+
12509
+ <para>
12510
+ If the database cluster crashes before committing a transaction
12511
+ containing a <function>nextval</function>
12512
+ or <function>setval</function> call, the sequence state change might
12513
+ not have made its way to persistent storage, so that it is uncertain
12514
+ whether the sequence will have its original or updated state after the
12515
+ cluster restarts. This is harmless for usage of the sequence within
12516
+ the database, since other effects of uncommitted transactions will not
12517
+ be visible either. However, if you wish to use a sequence value for
12518
+ persistent outside-the-database purposes, make sure that the
12519
+ <function>nextval</function> call has been committed before doing so.
12520
+ </para>
12521
+ </caution>
12511
12522
</sect1>
12512
12523
12513
12524
0 commit comments