Hot standbys now support exporting snapshots while creating a logical replication slot

Started by PG Bug reporting form11 months ago5 messagesdocs
Jump to latest
#1PG Bug reporting form
noreply@postgresql.org

The following documentation comment has been logged on the website:

Page: https://www.postgresql.org/docs/17/logicaldecoding-explanation.html
Description:

Hi,
I'm referring to this bit at the very end of the page: Creation of a
snapshot is not always possible. In particular, it will fail when connected
to a hot standby. Applications that do not require snapshot export may
suppress it with the NOEXPORT_SNAPSHOT option.
It's not clear what the intention of this is (is it referring only to
physical replication slots?) but as it stands you can export snapshots while
creating a logical replication slot. This should have been possible starting
PG16, I've tested this on PG17.
postgres=# CREATE_REPLICATION_SLOT export LOGICAL pgoutput (SNAPSHOT
'export');
-[ RECORD 1 ]----+--------------------
slot_name | export
consistent_point | 0/36C9F28
snapshot_name | 00000072-0000000A-1
output_plugin | pgoutput
postgres=# SELECT pg_is_in_recovery();
-[ RECORD 1 ]-----+--
pg_is_in_recovery | t
postgres=# SHOW hot_standby;
-[ RECORD 1 ]---
hot_standby | on
As an aside, I think NOEXPORT_SNAPSHOT is from the older syntax of
CREATE_REPLICATION_SLOT and should be swapped with SNAPSHOT 'nothing'.
Thanks,
Kevin

#2Fujii Masao
masao.fujii@gmail.com
In reply to: PG Bug reporting form (#1)
Re: Hot standbys now support exporting snapshots while creating a logical replication slot

On 2025/05/22 20:53, PG Doc comments form wrote:

The following documentation comment has been logged on the website:

Page: https://www.postgresql.org/docs/17/logicaldecoding-explanation.html
Description:

Hi,
I'm referring to this bit at the very end of the page: Creation of a
snapshot is not always possible. In particular, it will fail when connected
to a hot standby. Applications that do not require snapshot export may
suppress it with the NOEXPORT_SNAPSHOT option.
It's not clear what the intention of this is (is it referring only to
physical replication slots?) but as it stands you can export snapshots while
creating a logical replication slot. This should have been possible starting
PG16, I've tested this on PG17.

The description "Creation of a snapshot is not always possible. In particular,
it will fail when connected to a hot standby." no longer seems accurate.
Since v10 (commit 6c2003f8a1b), exporting snapshots on a standby has been supported.

This description was accurate when the first patch [1]/messages/by-id/CAMsr+YFjxv0T8Yi1Q=3tVdgViU2bm+fb_-XUbTfxHsnLDNSkzg@mail.gmail.com adding that description
was written, but I think we just overlooked updating it later.

As an aside, I think NOEXPORT_SNAPSHOT is from the older syntax of
CREATE_REPLICATION_SLOT and should be swapped with SNAPSHOT 'nothing'.

Yes, so how about the following change?

      <para>
-     Creation of a snapshot is not always possible.  In particular, it will
-     fail when connected to a hot standby.  Applications that do not require
-     snapshot export may suppress it with the <literal>NOEXPORT_SNAPSHOT</literal>
+     Applications that do not require
+     snapshot export may suppress it with the <literal>SNAPSHOT 'nothing'</literal>
       option.
      </para>

Regards,

[1]: /messages/by-id/CAMsr+YFjxv0T8Yi1Q=3tVdgViU2bm+fb_-XUbTfxHsnLDNSkzg@mail.gmail.com

Regards,

--
Fujii Masao
Advanced Computing Technology Center
Research and Development Headquarters
NTT DATA CORPORATION

#3Kevin K Biju
kevinkbiju@gmail.com
In reply to: Fujii Masao (#2)
Re: Hot standbys now support exporting snapshots while creating a logical replication slot

Hi Fuiji,

I wasn't aware that support for exporting snapshots goes as far back as
v10. The change looks good.

Thanks,
Kevin

On Fri, May 23, 2025 at 7:12 AM Fujii Masao <masao.fujii@oss.nttdata.com>
wrote:

Show quoted text

On 2025/05/22 20:53, PG Doc comments form wrote:

The following documentation comment has been logged on the website:

Page:

https://www.postgresql.org/docs/17/logicaldecoding-explanation.html

Description:

Hi,
I'm referring to this bit at the very end of the page: Creation of a
snapshot is not always possible. In particular, it will fail when

connected

to a hot standby. Applications that do not require snapshot export may
suppress it with the NOEXPORT_SNAPSHOT option.
It's not clear what the intention of this is (is it referring only to
physical replication slots?) but as it stands you can export snapshots

while

creating a logical replication slot. This should have been possible

starting

PG16, I've tested this on PG17.

The description "Creation of a snapshot is not always possible. In
particular,
it will fail when connected to a hot standby." no longer seems accurate.
Since v10 (commit 6c2003f8a1b), exporting snapshots on a standby has been
supported.

This description was accurate when the first patch [1] adding that
description
was written, but I think we just overlooked updating it later.

As an aside, I think NOEXPORT_SNAPSHOT is from the older syntax of
CREATE_REPLICATION_SLOT and should be swapped with SNAPSHOT 'nothing'.

Yes, so how about the following change?

<para>
-     Creation of a snapshot is not always possible.  In particular, it
will
-     fail when connected to a hot standby.  Applications that do not
require
-     snapshot export may suppress it with the
<literal>NOEXPORT_SNAPSHOT</literal>
+     Applications that do not require
+     snapshot export may suppress it with the <literal>SNAPSHOT
'nothing'</literal>
option.
</para>

Regards,

[1]
/messages/by-id/CAMsr+YFjxv0T8Yi1Q=3tVdgViU2bm+fb_-XUbTfxHsnLDNSkzg@mail.gmail.com

Regards,

--
Fujii Masao
Advanced Computing Technology Center
Research and Development Headquarters
NTT DATA CORPORATION

#4Fujii Masao
masao.fujii@gmail.com
In reply to: Kevin K Biju (#3)
Re: Hot standbys now support exporting snapshots while creating a logical replication slot

On 2025/05/23 19:52, Kevin K Biju wrote:

Hi Fuiji,

I wasn't aware that support for exporting snapshots goes as far back as v10. The change looks good.

Thanks for the review!

I've prepared two patches: one for v15 and later, and another for v13 and v14.
Unless there are any objections, I'll go ahead and commit and back-patch the patch
to all supported branches.

Regards,

--
Fujii Masao
NTT DATA Japan Corporation

Attachments:

v1-0001-PG13_PG14-doc-Fix-documenation-for-snapshot-export-in-logic.patchtext/plain; charset=UTF-8; name=v1-0001-PG13_PG14-doc-Fix-documenation-for-snapshot-export-in-logic.patchDownload+1-3
v1-0001-PG15_master-doc-Fix-documenation-for-snapshot-export-in-logic.patchtext/plain; charset=UTF-8; name=v1-0001-PG15_master-doc-Fix-documenation-for-snapshot-export-in-logic.patchDownload+2-4
#5Fujii Masao
masao.fujii@gmail.com
In reply to: Fujii Masao (#4)
Re: Hot standbys now support exporting snapshots while creating a logical replication slot

On 2025/05/23 23:46, Fujii Masao wrote:

On 2025/05/23 19:52, Kevin K Biju wrote:

Hi Fuiji,

I wasn't aware that support for exporting snapshots goes as far back as v10. The change looks good.

Thanks for the review!

I've prepared two patches: one for v15 and later, and another for v13 and v14.
Unless there are any objections, I'll go ahead and commit and back-patch the patch
to all supported branches.

I've pushed the patch. Thanks!

Regards,

--
Fujii Masao
NTT DATA Japan Corporation