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

2025-05-22 Thread PG Doc comments form
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| 0072-000A-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


Add missing references to database object statistics manipulation functions in documentation

2025-05-22 Thread Fujii Masao

Hi,

I noticed that the documentation is missing references to the database
object statistics manipulation functions such as pg_restore_relation_stats
in a few relevant places. For instance, the MAINTAIN privilege section
lists allowed operations but doesn't mention these functions, even though
they're covered. Likewise, the pg_class catalog section describes
what can update fields like reltuples, but omits these functions,
which also affect those fields.

So I'd like to propose adding these missing references to improve clarity.
Patch attached. Thought?

Regards,

--
Fujii Masao
Advanced Computing Technology Center
Research and Development Headquarters
NTT DATA CORPORATION
From 6e02b416f7742adb6fe82aef4692d455a27d4cf6 Mon Sep 17 00:00:00 2001
From: Fujii Masao 
Date: Thu, 22 May 2025 16:35:45 +0900
Subject: [PATCH v1] doc: Add documentation references for database object
 statistics functions.

Database object statistics manipulation functions were introduced
in PostgreSQL 18. However, references to these functions were missing
in several relevant parts of the documentation.

For example, the documentation for the MAINTAIN privilege lists
permitted operations but omitted mention of the statistics functions,
even though they are allowed under that privilege. Similarly,
the description of the pg_class catalog explains which operations
can update fields like reltuples, but did not include the statistics
functions, which also affect these fields.

This commit updates the documentation to explicitly reference
database object statistics manipulation functions where appropriate.
---
 doc/src/sgml/catalogs.sgml | 24 
 doc/src/sgml/ddl.sgml  |  5 +++--
 doc/src/sgml/perform.sgml  | 10 +++---
 3 files changed, 26 insertions(+), 13 deletions(-)

diff --git a/doc/src/sgml/catalogs.sgml b/doc/src/sgml/catalogs.sgml
index cbd4e40a320..60d4c989aba 100644
--- a/doc/src/sgml/catalogs.sgml
+++ b/doc/src/sgml/catalogs.sgml
@@ -2032,8 +2032,10 @@ SCRAM-SHA-256$:&l
Size of the on-disk representation of this table in pages (of size
BLCKSZ).  This is only an estimate used by the
planner.  It is updated by VACUUM,
-   ANALYZE, and a 
few DDL commands such as
-   CREATE INDEX.
+   ANALYZE, a few 
DDL commands such as
+   CREATE INDEX,
+   pg_restore_relation_stats, and
+   pg_clear_relation_stats.
   
  
 
@@ -2044,8 +2046,10 @@ SCRAM-SHA-256$:&l
   
Number of live rows in the table.  This is only an estimate used by
the planner.  It is updated by VACUUM,
-   ANALYZE, and a 
few DDL commands such as
-   CREATE INDEX.
+   ANALYZE, a few 
DDL commands such as
+   CREATE INDEX,
+   pg_restore_relation_stats, and
+   pg_clear_relation_stats.
If the table has never yet been vacuumed or
analyzed, reltuples
contains -1 indicating that the row count is
@@ -2061,8 +2065,10 @@ SCRAM-SHA-256$:&l
Number of pages that are marked all-visible in the table's
visibility map.  This is only an estimate used by the
planner.  It is updated by VACUUM,
-   ANALYZE, and a 
few DDL commands such as
-   CREATE INDEX.
+   ANALYZE, a few 
DDL commands such as
+   CREATE INDEX,
+   pg_restore_relation_stats, and
+   pg_clear_relation_stats.
   
  
 
@@ -2081,8 +2087,10 @@ SCRAM-SHA-256$:&l
It is updated by
VACUUM,
ANALYZE,
-   and a few DDL commands such as
-   CREATE INDEX.
+   a few DDL commands such as
+   CREATE INDEX,
+   pg_restore_relation_stats, and
+   pg_clear_relation_stats.
   
  
 
diff --git a/doc/src/sgml/ddl.sgml b/doc/src/sgml/ddl.sgml
index fcd1cb85352..96936bcd3ae 100644
--- a/doc/src/sgml/ddl.sgml
+++ b/doc/src/sgml/ddl.sgml
@@ -2223,8 +2223,9 @@ REVOKE ALL ON accounts FROM PUBLIC;
  
   Allows VACUUM, ANALYZE,
   CLUSTER, REFRESH MATERIALIZED VIEW,
-  REINDEX, and LOCK TABLE on a
-  relation.
+  REINDEX, LOCK TABLE,
+  and database object statistics manipulation functions
+  (see ) on a relation.
  
 

diff --git a/doc/src/sgml/perform.sgml b/doc/src/sgml/perform.sgml
index 106583fb296..acea2d2ac47 100644
--- a/doc/src/sgml/perform.sgml
+++ b/doc/src/sgml/perform.sgml
@@ -1253,8 +1253,10 @@ WHERE relname LIKE 'tenk1%';
For efficiency reasons, reltuples
and relpages are not updated on-the-fly,
and so they usually contain somewhat out-of-date values.
-   They are updated by VACUUM, ANALYZE, 
and a
-   few DDL commands such as CREATE INDEX.  A 
VACUUM
+   They are updated by VACUUM, ANALYZE,
+   a few DDL commands such as CREATE INDEX,
+   pg_restore_relation_stats, and
+   pg_clear_relation_stats. A VACUUM
or ANALYZE operation that does not scan the entire table
(which is commonly the case) will incrementally update the
reltuples count on

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

2025-05-22 Thread Fujii Masao




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?

 
- 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
+ Applications that do not require
+ snapshot export may suppress it with the SNAPSHOT 
'nothing'
  option.
 

Regards,

[1] 
https://www.postgresql.org/message-id/CAMsr+YFjxv0T8Yi1Q=3tvdgviu2bm+fb_-xubtfxhsnldns...@mail.gmail.com

Regards,

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