DOCS - Clarify that REFRESH SEQUENCES might be using stale publication data
Today I was experimenting with logical replication of sequences and
encountered some "unexpected" behaviour. It makes sense in hindsight,
but at the time it seemed surprising. It turns out that it is possible
to synchronise sequence values (using "ALTER SUBSCRIPTION... REFRESH
SEQUENCES") even when those sequences are not published.
That's because a subscription only knows which sequences are
subscribed to from the `pg_subscription_rel` table, but that
information can be stale if the publication has since stopped
publishing those sequences. In other words, if a sequence was removed
from the publication but REFRESH PUBLICATION hasn't been run, REFRESH
SEQUENCES would continue to synchronise it since it is still in
`pg_subscription_rel`.
The docs do refer to "currently subscribed sequences" but do not
explicitly warn about this gotcha.
PSA: a patch to add a clarifying sentence.
(I also removed an earlier link to "ALTER SUBSCRIPTION ... REFRESH
PUBLICATION", because it did not seem good to have multiple links to
the same place).
======
Kind Regards,
Peter Smith.
Fujitsu Australia
Attachments:
v1-0001-DOCS-clarify-that-REFRESH-SEQUENCES-might-be-usin.patchapplication/octet-stream; name=v1-0001-DOCS-clarify-that-REFRESH-SEQUENCES-might-be-usin.patchDownload+8-3
On Thu, Jul 2, 2026 at 8:29 AM Peter Smith <smithpb2250@gmail.com> wrote:
The docs do refer to "currently subscribed sequences" but do not
explicitly warn about this gotcha.PSA: a patch to add a clarifying sentence.
It does not add or remove
sequences from the subscription to match the publication.
</para>
+ <para>
+ If the publication's sequence membership has changed,
+ <link linkend="sql-altersubscription-params-refresh-publication">
+ <command>ALTER SUBSCRIPTION ... REFRESH PUBLICATION</command></link>
+ should be run before <literal>REFRESH SEQUENCES</literal> to ensure the
+ subscription's known sequence list is current.
+ </para>
It is already mentioned that this command "does not add or remove
sequences from the subscription to match the publication.". Adding
more information, especially a separate para for the same, appears
like bloating the text in docs. OTOH, I see your point of running
REFRESH PUBLICATION before REFRESH SEQUENCES which I tried to cover in
the existing paragraph. Apart from that, I have merged your
doc-changes from another thread [1]/messages/by-id/CAHut+PsrVntfrJ8gV45+6=1bs5dTWD5mU7Q6aKrBnf1vmyZQkQ@mail.gmail.com which is on the same topic. Let's
commit them together.
[1]: /messages/by-id/CAHut+PsrVntfrJ8gV45+6=1bs5dTWD5mU7Q6aKrBnf1vmyZQkQ@mail.gmail.com
--
With Regards,
Amit Kapila.
Attachments:
v2-0001-doc-Clarify-sequence-synchronization-commands.patchapplication/octet-stream; name=v2-0001-doc-Clarify-sequence-synchronization-commands.patchDownload+9-6
On Thu, Jul 2, 2026 at 6:48 PM Amit Kapila <amit.kapila16@gmail.com> wrote:
On Thu, Jul 2, 2026 at 8:29 AM Peter Smith <smithpb2250@gmail.com> wrote:
The docs do refer to "currently subscribed sequences" but do not
explicitly warn about this gotcha.PSA: a patch to add a clarifying sentence.
It does not add or remove sequences from the subscription to match the publication. </para> + <para> + If the publication's sequence membership has changed, + <link linkend="sql-altersubscription-params-refresh-publication"> + <command>ALTER SUBSCRIPTION ... REFRESH PUBLICATION</command></link> + should be run before <literal>REFRESH SEQUENCES</literal> to ensure the + subscription's known sequence list is current. + </para>It is already mentioned that this command "does not add or remove
sequences from the subscription to match the publication.". Adding
more information, especially a separate para for the same, appears
like bloating the text in docs. OTOH, I see your point of running
REFRESH PUBLICATION before REFRESH SEQUENCES which I tried to cover in
the existing paragraph. Apart from that, I have merged your
doc-changes from another thread [1] which is on the same topic. Let's
commit them together.
+1 to combine both patches.
Upon re-reading, I think there is still ambiguity due to that word
"synchronizing".
IMO, when we are talking about "synchronizing" sequences, we mean that
the sequence *values* on the subscriber will be synchronized with
those from the publisher.
So, REFRESH SEQUENCES synchronizes all currently known sequences.
OTOH, the REFRESH PUBLICATION refreshes all sequences known to the
subscriber, but it will only synchronize values for newly added ones
(not all of them). So "synchnonizing" is a misleading term to use when
describing the `pg_subscription_rel` members getting updated.
~~~
CHANGES:
Alter Subscription REFRESH SEQUENCES:
The REFRESH PUBLICATION option already correctly describes all that
above ("Previously subscribed sequences are not re-synchronized."), so
I think the fix is to remove the unnecessary explanation: "Unlike
...". After doing that, the remaining text is shorter and more
correct.
Logical Replication:
(2nd bullet) Should also mention that REFRESH PUBLICATION refreshes
the sequences known to the subscription.
~~~
PSA v3.
======
Kind Regards,
Peter Smith.
Fujitsu Australia
Attachments:
v3-0001-doc-Clarify-sequence-synchronization-commands.patchapplication/octet-stream; name=v3-0001-doc-Clarify-sequence-synchronization-commands.patchDownload+9-9
On Fri, Jul 3, 2026 at 8:48 AM Peter Smith <smithpb2250@gmail.com> wrote:
On Thu, Jul 2, 2026 at 6:48 PM Amit Kapila <amit.kapila16@gmail.com> wrote:
On Thu, Jul 2, 2026 at 8:29 AM Peter Smith <smithpb2250@gmail.com> wrote:
The docs do refer to "currently subscribed sequences" but do not
explicitly warn about this gotcha.PSA: a patch to add a clarifying sentence.
It does not add or remove sequences from the subscription to match the publication. </para> + <para> + If the publication's sequence membership has changed, + <link linkend="sql-altersubscription-params-refresh-publication"> + <command>ALTER SUBSCRIPTION ... REFRESH PUBLICATION</command></link> + should be run before <literal>REFRESH SEQUENCES</literal> to ensure the + subscription's known sequence list is current. + </para>It is already mentioned that this command "does not add or remove
sequences from the subscription to match the publication.". Adding
more information, especially a separate para for the same, appears
like bloating the text in docs. OTOH, I see your point of running
REFRESH PUBLICATION before REFRESH SEQUENCES which I tried to cover in
the existing paragraph. Apart from that, I have merged your
doc-changes from another thread [1] which is on the same topic. Let's
commit them together.+1 to combine both patches.
Upon re-reading, I think there is still ambiguity due to that word
"synchronizing".
I don't read it that way. I feel the current wording is succinct and
conveys what the command is supposed to do. I read your new version of
the patch but I still like the one I shared previously, so I'll
go-ahead with that unless someone else has preference for one or the
other version.
--
With Regards,
Amit Kapila.