public inbox for [email protected]
help / color / mirror / Atom feed[PATCH v50 5/7] Doc part of shared-memory based stats collector.
8+ messages / 4 participants
[nested] [flat]
* [PATCH v50 5/7] Doc part of shared-memory based stats collector.
@ 2020-03-19 06:11 Kyotaro Horiguchi <[email protected]>
0 siblings, 0 replies; 8+ messages in thread
From: Kyotaro Horiguchi @ 2020-03-19 06:11 UTC (permalink / raw)
---
doc/src/sgml/catalogs.sgml | 6 +-
doc/src/sgml/config.sgml | 27 +++---
doc/src/sgml/high-availability.sgml | 13 +--
doc/src/sgml/monitoring.sgml | 127 +++++++++++++---------------
doc/src/sgml/ref/pg_dump.sgml | 9 +-
5 files changed, 86 insertions(+), 96 deletions(-)
diff --git a/doc/src/sgml/catalogs.sgml b/doc/src/sgml/catalogs.sgml
index b1de6d0674..0ef684d4d0 100644
--- a/doc/src/sgml/catalogs.sgml
+++ b/doc/src/sgml/catalogs.sgml
@@ -9261,9 +9261,9 @@ SCRAM-SHA-256$<replaceable><iteration count></replaceable>:<replaceable>&l
<para>
<xref linkend="view-table"/> lists the system views described here.
More detailed documentation of each view follows below.
- There are some additional views that provide access to the results of
- the statistics collector; they are described in <xref
- linkend="monitoring-stats-views-table"/>.
+ There are some additional views that provide access to the activity
+ statistics; they are described in
+ <xref linkend="monitoring-stats-views-table"/>.
</para>
<para>
diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml
index 529876895b..99a8664026 100644
--- a/doc/src/sgml/config.sgml
+++ b/doc/src/sgml/config.sgml
@@ -7375,11 +7375,11 @@ COPY postgres_log FROM '/full/path/to/logfile.csv' WITH csv;
<title>Run-time Statistics</title>
<sect2 id="runtime-config-statistics-collector">
- <title>Query and Index Statistics Collector</title>
+ <title>Query and Index Activity Statistics</title>
<para>
- These parameters control server-wide statistics collection features.
- When statistics collection is enabled, the data that is produced can be
+ These parameters control server-wide activity statistics features.
+ When activity statistics is enabled, the data that is produced can be
accessed via the <structname>pg_stat</structname> and
<structname>pg_statio</structname> family of system views.
Refer to <xref linkend="monitoring"/> for more information.
@@ -7395,14 +7395,13 @@ COPY postgres_log FROM '/full/path/to/logfile.csv' WITH csv;
</term>
<listitem>
<para>
- Enables the collection of information on the currently
- executing command of each session, along with the time when
- that command began execution. This parameter is on by
- default. Note that even when enabled, this information is not
- visible to all users, only to superusers and the user owning
- the session being reported on, so it should not represent a
- security risk.
- Only superusers can change this setting.
+ Enables activity tracking on the currently executing command of
+ each session, along with the time when that command began
+ execution. This parameter is on by default. Note that even when
+ enabled, this information is not visible to all users, only to
+ superusers and the user owning the session being reported on, so it
+ should not represent a security risk. Only superusers can change this
+ setting.
</para>
</listitem>
</varlistentry>
@@ -7433,9 +7432,9 @@ COPY postgres_log FROM '/full/path/to/logfile.csv' WITH csv;
</term>
<listitem>
<para>
- Enables collection of statistics on database activity.
+ Enables tracking of database activity.
This parameter is on by default, because the autovacuum
- daemon needs the collected information.
+ daemon needs the activity information.
Only superusers can change this setting.
</para>
</listitem>
@@ -8554,7 +8553,7 @@ COPY postgres_log FROM '/full/path/to/logfile.csv' WITH csv;
<listitem>
<para>
Specifies the fraction of the total number of heap tuples counted in
- the previous statistics collection that can be inserted without
+ the previously collected statistics that can be inserted without
incurring an index scan at the <command>VACUUM</command> cleanup stage.
This setting currently applies to B-tree indexes only.
</para>
diff --git a/doc/src/sgml/high-availability.sgml b/doc/src/sgml/high-availability.sgml
index f49f5c0108..45095857eb 100644
--- a/doc/src/sgml/high-availability.sgml
+++ b/doc/src/sgml/high-availability.sgml
@@ -2217,12 +2217,13 @@ HINT: You can then restart the server after making the necessary configuration
</para>
<para>
- The statistics collector is active during recovery. All scans, reads, blocks,
- index usage, etc., will be recorded normally on the standby. Replayed
- actions will not duplicate their effects on primary, so replaying an
- insert will not increment the Inserts column of pg_stat_user_tables.
- The stats file is deleted at the start of recovery, so stats from primary
- and standby will differ; this is considered a feature, not a bug.
+ The activity statistics is collected during recovery. All scans, reads,
+ blocks, index usage, etc., will be recorded normally on the
+ standby. Replayed actions will not duplicate their effects on primary, so
+ replaying an insert will not increment the Inserts column of
+ pg_stat_user_tables. The activity statistics is reset at the start of
+ recovery, so stats from primary and standby will differ; this is
+ considered a feature, not a bug.
</para>
<para>
diff --git a/doc/src/sgml/monitoring.sgml b/doc/src/sgml/monitoring.sgml
index 3335d71eba..6217ed9792 100644
--- a/doc/src/sgml/monitoring.sgml
+++ b/doc/src/sgml/monitoring.sgml
@@ -22,7 +22,7 @@
<para>
Several tools are available for monitoring database activity and
analyzing performance. Most of this chapter is devoted to describing
- <productname>PostgreSQL</productname>'s statistics collector,
+ <productname>PostgreSQL</productname>'s activity statistics,
but one should not neglect regular Unix monitoring programs such as
<command>ps</command>, <command>top</command>, <command>iostat</command>, and <command>vmstat</command>.
Also, once one has identified a
@@ -53,7 +53,6 @@ postgres 15554 0.0 0.0 57536 1184 ? Ss 18:02 0:00 postgres: back
postgres 15555 0.0 0.0 57536 916 ? Ss 18:02 0:00 postgres: checkpointer
postgres 15556 0.0 0.0 57536 916 ? Ss 18:02 0:00 postgres: walwriter
postgres 15557 0.0 0.0 58504 2244 ? Ss 18:02 0:00 postgres: autovacuum launcher
-postgres 15558 0.0 0.0 17512 1068 ? Ss 18:02 0:00 postgres: stats collector
postgres 15582 0.0 0.0 58772 3080 ? Ss 18:04 0:00 postgres: joe runbug 127.0.0.1 idle
postgres 15606 0.0 0.0 58772 3052 ? Ss 18:07 0:00 postgres: tgl regression [local] SELECT waiting
postgres 15610 0.0 0.0 58772 3056 ? Ss 18:07 0:00 postgres: tgl regression [local] idle in transaction
@@ -65,9 +64,8 @@ postgres 15610 0.0 0.0 58772 3056 ? Ss 18:07 0:00 postgres: tgl
primary server process. The command arguments
shown for it are the same ones used when it was launched. The next five
processes are background worker processes automatically launched by the
- primary process. (The <quote>stats collector</quote> process will not be present
- if you have set the system not to start the statistics collector; likewise
- the <quote>autovacuum launcher</quote> process can be disabled.)
+ primary process. (The <quote>autovacuum launcher</quote> process will not
+ be present if you have set the system not to start it.)
Each of the remaining
processes is a server process handling one client connection. Each such
process sets its command line display in the form
@@ -130,20 +128,21 @@ postgres 27093 0.0 0.0 30096 2752 ? Ss 11:34 0:00 postgres: ser
</sect1>
<sect1 id="monitoring-stats">
- <title>The Statistics Collector</title>
+ <title>The Activity Statistics</title>
<indexterm zone="monitoring-stats">
<primary>statistics</primary>
</indexterm>
<para>
- <productname>PostgreSQL</productname>'s <firstterm>statistics collector</firstterm>
- is a subsystem that supports collection and reporting of information about
- server activity. Presently, the collector can count accesses to tables
- and indexes in both disk-block and individual-row terms. It also tracks
- the total number of rows in each table, and information about vacuum and
- analyze actions for each table. It can also count calls to user-defined
- functions and the total time spent in each one.
+ <productname>PostgreSQL</productname>'s <firstterm>activity
+ statistics</firstterm> is a subsystem that supports tracking and reporting
+ of information about server activity. Presently, the activity statistics
+ tracks the count of accesses to tables and indexes in both disk-block and
+ individual-row terms. It also tracks the total number of rows in each
+ table, and information about vacuum and analyze actions for each table. It
+ can also track calls to user-defined functions and the total time spent in
+ each one.
</para>
<para>
@@ -151,15 +150,15 @@ postgres 27093 0.0 0.0 30096 2752 ? Ss 11:34 0:00 postgres: ser
information about exactly what is going on in the system right now, such as
the exact command currently being executed by other server processes, and
which other connections exist in the system. This facility is independent
- of the collector process.
+ of the activity statistics.
</para>
<sect2 id="monitoring-stats-setup">
- <title>Statistics Collection Configuration</title>
+ <title>Activity Statistics Configuration</title>
<para>
- Since collection of statistics adds some overhead to query execution,
- the system can be configured to collect or not collect information.
+ Since tracking for the activity statistics adds some overhead to query
+ execution, the system can be configured to track or not track activity.
This is controlled by configuration parameters that are normally set in
<filename>postgresql.conf</filename>. (See <xref linkend="runtime-config"/> for
details about setting configuration parameters.)
@@ -172,7 +171,7 @@ postgres 27093 0.0 0.0 30096 2752 ? Ss 11:34 0:00 postgres: ser
<para>
The parameter <xref linkend="guc-track-counts"/> controls whether
- statistics are collected about table and index accesses.
+ to track activity about table and index accesses.
</para>
<para>
@@ -201,18 +200,11 @@ postgres 27093 0.0 0.0 30096 2752 ? Ss 11:34 0:00 postgres: ser
</para>
<para>
- The statistics collector transmits the collected information to other
- <productname>PostgreSQL</productname> processes through temporary files.
- These files are stored in the directory named by the
- <xref linkend="guc-stats-temp-directory"/> parameter,
- <filename>pg_stat_tmp</filename> by default.
- For better performance, <varname>stats_temp_directory</varname> can be
- pointed at a RAM-based file system, decreasing physical I/O requirements.
- When the server shuts down cleanly, a permanent copy of the statistics
- data is stored in the <filename>pg_stat</filename> subdirectory, so that
- statistics can be retained across server restarts. When recovery is
- performed at server start (e.g., after immediate shutdown, server crash,
- and point-in-time recovery), all statistics counters are reset.
+ down cleanly, a permanent copy of the statistics data is stored in
+ the <filename>pg_stat</filename> subdirectory, so that statistics can be
+ retained across server restarts. When recovery is performed at server
+ start (e.g. after immediate shutdown, server crash, and point-in-time
+ recovery), all statistics counters are reset.
</para>
</sect2>
@@ -225,48 +217,46 @@ postgres 27093 0.0 0.0 30096 2752 ? Ss 11:34 0:00 postgres: ser
linkend="monitoring-stats-dynamic-views-table"/>, are available to show
the current state of the system. There are also several other
views, listed in <xref
- linkend="monitoring-stats-views-table"/>, available to show the results
- of statistics collection. Alternatively, one can
- build custom views using the underlying statistics functions, as discussed
- in <xref linkend="monitoring-stats-functions"/>.
+ linkend="monitoring-stats-views-table"/>, available to show the activity
+ statistics. Alternatively, one can build custom views using the underlying
+ statistics functions, as discussed in
+ <xref linkend="monitoring-stats-functions"/>.
</para>
<para>
- When using the statistics to monitor collected data, it is important
- to realize that the information does not update instantaneously.
- Each individual server process transmits new statistical counts to
- the collector just before going idle; so a query or transaction still in
- progress does not affect the displayed totals. Also, the collector itself
- emits a new report at most once per <varname>PGSTAT_STAT_INTERVAL</varname>
- milliseconds (500 ms unless altered while building the server). So the
- displayed information lags behind actual activity. However, current-query
- information collected by <varname>track_activities</varname> is
- always up-to-date.
+ When using the activity statistics, it is important to realize that the
+ information does not update instantaneously. Each individual server writes
+ out new statistical counts just before going idle, not frequent than once
+ per <varname>PGSTAT_STAT_INTERVAL</varname> milliseconds (1 second unless
+ altered while building the server); so a query or transaction still in
+ progress does not affect the displayed totals. However, current-query
+ information tracked by <varname>track_activities</varname> is always
+ up-to-date.
</para>
<para>
Another important point is that when a server process is asked to display
- any of these statistics, it first fetches the most recent report emitted by
- the collector process and then continues to use this snapshot for all
- statistical views and functions until the end of its current transaction.
- So the statistics will show static information as long as you continue the
- current transaction. Similarly, information about the current queries of
- all sessions is collected when any such information is first requested
- within a transaction, and the same information will be displayed throughout
- the transaction.
- This is a feature, not a bug, because it allows you to perform several
- queries on the statistics and correlate the results without worrying that
- the numbers are changing underneath you. But if you want to see new
- results with each query, be sure to do the queries outside any transaction
- block. Alternatively, you can invoke
+ any of these statistics, it first reads the current statistics and then
+ continues to use this snapshot for all statistical views and functions
+ until the end of its current transaction. So the statistics will show
+ static information as long as you continue the current transaction.
+ Similarly, information about the current queries of all sessions is tracked
+ when any such information is first requested within a transaction, and the
+ same information will be displayed throughout the transaction. This is a
+ feature, not a bug, because it allows you to perform several queries on the
+ statistics and correlate the results without worrying that the numbers are
+ changing underneath you. But if you want to see new results with each
+ query, be sure to do the queries outside any transaction block.
+ Alternatively, you can invoke
<function>pg_stat_clear_snapshot</function>(), which will discard the
current transaction's statistics snapshot (if any). The next use of
statistical information will cause a new snapshot to be fetched.
</para>
-
+
<para>
- A transaction can also see its own statistics (as yet untransmitted to the
- collector) in the views <structname>pg_stat_xact_all_tables</structname>,
+ A transaction can also see its own statistics (as yet unwritten to the
+ server-wide activity statistics) in the
+ views <structname>pg_stat_xact_all_tables</structname>,
<structname>pg_stat_xact_sys_tables</structname>,
<structname>pg_stat_xact_user_tables</structname>, and
<structname>pg_stat_xact_user_functions</structname>. These numbers do not act as
@@ -648,7 +638,7 @@ postgres 27093 0.0 0.0 30096 2752 ? Ss 11:34 0:00 postgres: ser
kernel's I/O cache, and might therefore still be fetched without
requiring a physical read. Users interested in obtaining more
detailed information on <productname>PostgreSQL</productname> I/O behavior are
- advised to use the <productname>PostgreSQL</productname> statistics collector
+ advised to use the <productname>PostgreSQL</productname> activity statistics
in combination with operating system utilities that allow insight
into the kernel's handling of I/O.
</para>
@@ -1085,10 +1075,6 @@ postgres 27093 0.0 0.0 30096 2752 ? Ss 11:34 0:00 postgres: ser
<entry><literal>LogicalLauncherMain</literal></entry>
<entry>Waiting in main loop of logical replication launcher process.</entry>
</row>
- <row>
- <entry><literal>PgStatMain</literal></entry>
- <entry>Waiting in main loop of statistics collector process.</entry>
- </row>
<row>
<entry><literal>RecoveryWalStream</literal></entry>
<entry>Waiting in main loop of startup process for WAL to arrive, during
@@ -1843,6 +1829,10 @@ postgres 27093 0.0 0.0 30096 2752 ? Ss 11:34 0:00 postgres: ser
</thead>
<tbody>
+ <row>
+ <entry><literal>ActivityStatistics</literal></entry>
+ <entry>Waiting to write out activity statistics to shared memory.</entry>
+ </row>
<row>
<entry><literal>AddinShmemInit</literal></entry>
<entry>Waiting to manage an extension's space allocation in shared
@@ -6123,9 +6113,10 @@ SELECT pg_stat_get_backend_pid(s.backendid) AS pid,
<entry><literal>performing final cleanup</literal></entry>
<entry>
<command>VACUUM</command> is performing final cleanup. During this phase,
- <command>VACUUM</command> will vacuum the free space map, update statistics
- in <literal>pg_class</literal>, and report statistics to the statistics
- collector. When this phase is completed, <command>VACUUM</command> will end.
+ <command>VACUUM</command> will vacuum the free space map, update
+ statistics in <literal>pg_class</literal>, and system-wide activity
+ statistics. When this phase is completed, <command>VACUUM</command>
+ will end.
</entry>
</row>
</tbody>
diff --git a/doc/src/sgml/ref/pg_dump.sgml b/doc/src/sgml/ref/pg_dump.sgml
index bcbb7a25fb..1fa59a2fdf 100644
--- a/doc/src/sgml/ref/pg_dump.sgml
+++ b/doc/src/sgml/ref/pg_dump.sgml
@@ -1280,11 +1280,10 @@ PostgreSQL documentation
</para>
<para>
- The database activity of <application>pg_dump</application> is
- normally collected by the statistics collector. If this is
- undesirable, you can set parameter <varname>track_counts</varname>
- to false via <envar>PGOPTIONS</envar> or the <literal>ALTER
- USER</literal> command.
+ The database activity of <application>pg_dump</application> is normally
+ collected. If this is undesirable, you can set
+ parameter <varname>track_counts</varname> to false
+ via <envar>PGOPTIONS</envar> or the <literal>ALTER USER</literal> command.
</para>
</refsect1>
--
2.27.0
----Next_Part(Tue_Mar__9_18_29_34_2021_806)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v50-0006-Remove-the-GUC-stats_temp_directory.patch"
^ permalink raw reply [nested|flat] 8+ messages in thread
* Fix a test case in 035_standby_logical_decoding.pl
@ 2023-04-27 08:11 Yu Shi (Fujitsu) <[email protected]>
2023-04-27 08:46 ` Re: Fix a test case in 035_standby_logical_decoding.pl Drouvot, Bertrand <[email protected]>
0 siblings, 1 reply; 8+ messages in thread
From: Yu Shi (Fujitsu) @ 2023-04-27 08:11 UTC (permalink / raw)
To: pgsql-hackers
Hi hackers,
In 035_standby_logical_decoding.pl, I think that the check in the following test
case should be performed on the standby node, instead of the primary node, as
the slot is created on the standby node. The test currently passes because it
only checks the return value of psql. It might be more appropriate to check the
error message. Please see the attached patch.
```
$node_primary->safe_psql('postgres', 'CREATE DATABASE otherdb');
is( $node_primary->psql(
'otherdb',
"SELECT lsn FROM pg_logical_slot_peek_changes('behaves_ok_activeslot', NULL, NULL) ORDER BY lsn DESC LIMIT 1;"
),
3,
'replaying logical slot from another database fails');
```
The regress log:
psql:<stdin>:1: ERROR: replication slot "behaves_ok_activeslot" does not exist
[11:23:21.859](0.086s) ok 8 - replaying logical slot from another database fails
Regards,
Shi Yu
Attachments:
[application/octet-stream] v1-0001-Fix-a-test-case-in-035_standby_logical_decoding.p.patch (1.6K, ../../OSZPR01MB6310B0A507A0F2A2D379F38CFD6A9@OSZPR01MB6310.jpnprd01.prod.outlook.com/2-v1-0001-Fix-a-test-case-in-035_standby_logical_decoding.p.patch)
download | inline diff:
From c27953c59fdfb0a4a4933843d5ec233a84b0ff19 Mon Sep 17 00:00:00 2001
From: Shi Yu <[email protected]>
Date: Thu, 27 Apr 2023 11:05:40 +0800
Subject: [PATCH v1] Fix a test case in 035_standby_logical_decoding.pl
For the "replaying logical slot from another database fails" check, perform it
on the standby node instead of the primary node.
---
src/test/recovery/t/035_standby_logical_decoding.pl | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/src/test/recovery/t/035_standby_logical_decoding.pl b/src/test/recovery/t/035_standby_logical_decoding.pl
index b8f5311fe9..f559cde914 100644
--- a/src/test/recovery/t/035_standby_logical_decoding.pl
+++ b/src/test/recovery/t/035_standby_logical_decoding.pl
@@ -358,12 +358,17 @@ is($stdout_recv, '', 'pg_recvlogical acknowledged changes');
$node_primary->safe_psql('postgres', 'CREATE DATABASE otherdb');
-is( $node_primary->psql(
+# Wait for catchup to ensure that the new database is visible to other sessions
+# on the standby.
+$node_primary->wait_for_replay_catchup($node_standby);
+
+($result, $stdout, $stderr) = $node_standby->psql(
'otherdb',
"SELECT lsn FROM pg_logical_slot_peek_changes('behaves_ok_activeslot', NULL, NULL) ORDER BY lsn DESC LIMIT 1;"
- ),
- 3,
- 'replaying logical slot from another database fails');
+ );
+ok( $stderr =~
+ m/replication slot "behaves_ok_activeslot" was not created in this database/,
+ "replaying logical slot from another database fails");
##################################################
# Recovery conflict: Invalidate conflicting slots, including in-use slots
--
2.31.1
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: Fix a test case in 035_standby_logical_decoding.pl
2023-04-27 08:11 Fix a test case in 035_standby_logical_decoding.pl Yu Shi (Fujitsu) <[email protected]>
@ 2023-04-27 08:46 ` Drouvot, Bertrand <[email protected]>
2023-04-27 09:41 ` RE: Fix a test case in 035_standby_logical_decoding.pl Yu Shi (Fujitsu) <[email protected]>
2023-04-27 09:53 ` Re: Fix a test case in 035_standby_logical_decoding.pl Amit Kapila <[email protected]>
0 siblings, 2 replies; 8+ messages in thread
From: Drouvot, Bertrand @ 2023-04-27 08:46 UTC (permalink / raw)
To: Yu Shi (Fujitsu) <[email protected]>; pgsql-hackers
Hi,
On 4/27/23 10:11 AM, Yu Shi (Fujitsu) wrote:
> Hi hackers,
>
> In 035_standby_logical_decoding.pl, I think that the check in the following test
> case should be performed on the standby node, instead of the primary node, as
> the slot is created on the standby node.
Oh right, the current test is not done on the right node, thanks!
> The test currently passes because it
> only checks the return value of psql. It might be more appropriate to check the
> error message.
Agree, and it's consistent with what is being done in 006_logical_decoding.pl.
> Please see the attached patch.
>
+
+($result, $stdout, $stderr) = $node_standby->psql(
'otherdb',
"SELECT lsn FROM pg_logical_slot_peek_changes('behaves_ok_activeslot', NULL, NULL) ORDER BY lsn DESC LIMIT 1;"
- ),
- 3,
- 'replaying logical slot from another database fails');
+ );
+ok( $stderr =~
+ m/replication slot "behaves_ok_activeslot" was not created in this database/,
+ "replaying logical slot from another database fails");
That does look good to me.
Nit: I wonder if while at it (as it was already there) we could not remove the " ORDER BY lsn DESC LIMIT 1" part of it.
It does not change anything regarding the test but looks more appropriate to me.
Regards,
--
Bertrand Drouvot
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com
^ permalink raw reply [nested|flat] 8+ messages in thread
* RE: Fix a test case in 035_standby_logical_decoding.pl
2023-04-27 08:11 Fix a test case in 035_standby_logical_decoding.pl Yu Shi (Fujitsu) <[email protected]>
2023-04-27 08:46 ` Re: Fix a test case in 035_standby_logical_decoding.pl Drouvot, Bertrand <[email protected]>
@ 2023-04-27 09:41 ` Yu Shi (Fujitsu) <[email protected]>
1 sibling, 0 replies; 8+ messages in thread
From: Yu Shi (Fujitsu) @ 2023-04-27 09:41 UTC (permalink / raw)
To: Drouvot, Bertrand <[email protected]>; pgsql-hackers
On Thu, Apr 27, 2023 4:47 PM Drouvot, Bertrand <[email protected]> wrote:
>
> Hi,
>
> On 4/27/23 10:11 AM, Yu Shi (Fujitsu) wrote:
> > Hi hackers,
> >
> > In 035_standby_logical_decoding.pl, I think that the check in the following test
> > case should be performed on the standby node, instead of the primary node,
> as
> > the slot is created on the standby node.
>
> Oh right, the current test is not done on the right node, thanks!
>
> > The test currently passes because it
> > only checks the return value of psql. It might be more appropriate to check the
> > error message.
>
> Agree, and it's consistent with what is being done in 006_logical_decoding.pl.
>
> > Please see the attached patch.
> >
>
> +
> +($result, $stdout, $stderr) = $node_standby->psql(
> 'otherdb',
> "SELECT lsn FROM pg_logical_slot_peek_changes('behaves_ok_activeslot',
> NULL, NULL) ORDER BY lsn DESC LIMIT 1;"
> - ),
> - 3,
> - 'replaying logical slot from another database fails');
> + );
> +ok( $stderr =~
> + m/replication slot "behaves_ok_activeslot" was not created in this
> database/,
> + "replaying logical slot from another database fails");
>
>
> That does look good to me.
>
> Nit: I wonder if while at it (as it was already there) we could not remove the "
> ORDER BY lsn DESC LIMIT 1" part of it.
> It does not change anything regarding the test but looks more appropriate to
> me.
>
Thanks for your reply. I agree with you and I removed it in the attached patch.
Regards,
Shi Yu
Attachments:
[application/octet-stream] v2-0001-Fix-a-test-case-in-035_standby_logical_decoding.p.patch (1.7K, ../../OSZPR01MB6310F63EE52F979ACF90ACCBFD6A9@OSZPR01MB6310.jpnprd01.prod.outlook.com/2-v2-0001-Fix-a-test-case-in-035_standby_logical_decoding.p.patch)
download | inline diff:
From 40fd8053f73d29a13e2ddc5b77b15dcb686a6915 Mon Sep 17 00:00:00 2001
From: Shi Yu <[email protected]>
Date: Thu, 27 Apr 2023 11:05:40 +0800
Subject: [PATCH v2] Fix a test case in 035_standby_logical_decoding.pl
For the "replaying logical slot from another database fails" check, perform it
on the standby node instead of the primary node.
---
.../recovery/t/035_standby_logical_decoding.pl | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/src/test/recovery/t/035_standby_logical_decoding.pl b/src/test/recovery/t/035_standby_logical_decoding.pl
index f6d6447412..930e755712 100644
--- a/src/test/recovery/t/035_standby_logical_decoding.pl
+++ b/src/test/recovery/t/035_standby_logical_decoding.pl
@@ -384,12 +384,17 @@ is($stdout_recv, '', 'pg_recvlogical acknowledged changes');
$node_primary->safe_psql('postgres', 'CREATE DATABASE otherdb');
-is( $node_primary->psql(
+# Wait for catchup to ensure that the new database is visible to other sessions
+# on the standby.
+$node_primary->wait_for_replay_catchup($node_standby);
+
+($result, $stdout, $stderr) = $node_standby->psql(
'otherdb',
- "SELECT lsn FROM pg_logical_slot_peek_changes('behaves_ok_activeslot', NULL, NULL) ORDER BY lsn DESC LIMIT 1;"
- ),
- 3,
- 'replaying logical slot from another database fails');
+ "SELECT lsn FROM pg_logical_slot_peek_changes('behaves_ok_activeslot', NULL, NULL);"
+ );
+ok( $stderr =~
+ m/replication slot "behaves_ok_activeslot" was not created in this database/,
+ "replaying logical slot from another database fails");
##################################################
# Test that we can subscribe on the standby with the publication
--
2.30.0.windows.2
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: Fix a test case in 035_standby_logical_decoding.pl
2023-04-27 08:11 Fix a test case in 035_standby_logical_decoding.pl Yu Shi (Fujitsu) <[email protected]>
2023-04-27 08:46 ` Re: Fix a test case in 035_standby_logical_decoding.pl Drouvot, Bertrand <[email protected]>
@ 2023-04-27 09:53 ` Amit Kapila <[email protected]>
2023-04-27 10:37 ` Re: Fix a test case in 035_standby_logical_decoding.pl Drouvot, Bertrand <[email protected]>
1 sibling, 1 reply; 8+ messages in thread
From: Amit Kapila @ 2023-04-27 09:53 UTC (permalink / raw)
To: Drouvot, Bertrand <[email protected]>; +Cc: Yu Shi (Fujitsu) <[email protected]>; pgsql-hackers
On Thu, Apr 27, 2023 at 2:16 PM Drouvot, Bertrand
<[email protected]> wrote:
>
> On 4/27/23 10:11 AM, Yu Shi (Fujitsu) wrote:
> > Hi hackers,
> >
> > In 035_standby_logical_decoding.pl, I think that the check in the following test
> > case should be performed on the standby node, instead of the primary node, as
> > the slot is created on the standby node.
>
> Oh right, the current test is not done on the right node, thanks!
>
> > The test currently passes because it
> > only checks the return value of psql. It might be more appropriate to check the
> > error message.
>
> Agree, and it's consistent with what is being done in 006_logical_decoding.pl.
>
> > Please see the attached patch.
> >
>
> +
> +($result, $stdout, $stderr) = $node_standby->psql(
> 'otherdb',
> "SELECT lsn FROM pg_logical_slot_peek_changes('behaves_ok_activeslot', NULL, NULL) ORDER BY lsn DESC LIMIT 1;"
> - ),
> - 3,
> - 'replaying logical slot from another database fails');
> + );
> +ok( $stderr =~
> + m/replication slot "behaves_ok_activeslot" was not created in this database/,
> + "replaying logical slot from another database fails");
>
>
> That does look good to me.
>
I agree that that the check should be done on standby but how does it
make a difference to check the error message or return value? Won't it
be the same for both primary and standby?
> Nit: I wonder if while at it (as it was already there) we could not remove the " ORDER BY lsn DESC LIMIT 1" part of it.
> It does not change anything regarding the test but looks more appropriate to me.
>
It may not make a difference as this is anyway an error case but it
looks more logical to LIMIT by 1 as you are fetching a single LSN
value and it will be consistent with other tests in this file and the
test case in the file 006_logical_decoding.pl.
BTW, in the same test, I see it uses wait_for_catchup() in one place
and wait_for_replay_catchup() in another place after Insert. Isn't it
better to use wait_for_replay_catchup in both places?
--
With Regards,
Amit Kapila.
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: Fix a test case in 035_standby_logical_decoding.pl
2023-04-27 08:11 Fix a test case in 035_standby_logical_decoding.pl Yu Shi (Fujitsu) <[email protected]>
2023-04-27 08:46 ` Re: Fix a test case in 035_standby_logical_decoding.pl Drouvot, Bertrand <[email protected]>
2023-04-27 09:53 ` Re: Fix a test case in 035_standby_logical_decoding.pl Amit Kapila <[email protected]>
@ 2023-04-27 10:37 ` Drouvot, Bertrand <[email protected]>
2023-04-27 13:53 ` Re: Fix a test case in 035_standby_logical_decoding.pl Amit Kapila <[email protected]>
0 siblings, 1 reply; 8+ messages in thread
From: Drouvot, Bertrand @ 2023-04-27 10:37 UTC (permalink / raw)
To: Amit Kapila <[email protected]>; +Cc: Yu Shi (Fujitsu) <[email protected]>; pgsql-hackers
Hi,
On 4/27/23 11:53 AM, Amit Kapila wrote:
> On Thu, Apr 27, 2023 at 2:16 PM Drouvot, Bertrand
> <[email protected]> wrote:
>>
>> On 4/27/23 10:11 AM, Yu Shi (Fujitsu) wrote:
>>> Hi hackers,
>>>
>>> In 035_standby_logical_decoding.pl, I think that the check in the following test
>>> case should be performed on the standby node, instead of the primary node, as
>>> the slot is created on the standby node.
>>
>> Oh right, the current test is not done on the right node, thanks!
>>
>>> The test currently passes because it
>>> only checks the return value of psql. It might be more appropriate to check the
>>> error message.
>>
>> Agree, and it's consistent with what is being done in 006_logical_decoding.pl.
>>
>>> Please see the attached patch.
>>>
>>
>> +
>> +($result, $stdout, $stderr) = $node_standby->psql(
>> 'otherdb',
>> "SELECT lsn FROM pg_logical_slot_peek_changes('behaves_ok_activeslot', NULL, NULL) ORDER BY lsn DESC LIMIT 1;"
>> - ),
>> - 3,
>> - 'replaying logical slot from another database fails');
>> + );
>> +ok( $stderr =~
>> + m/replication slot "behaves_ok_activeslot" was not created in this database/,
>> + "replaying logical slot from another database fails");
>>
>>
>> That does look good to me.
>>
>
> I agree that that the check should be done on standby but how does it
> make a difference to check the error message or return value? Won't it
> be the same for both primary and standby?
>
Yes that would be the same. I think the original idea from Shi-san (please correct me If I'm wrong)
was "while at it" let's also make this test on the right node even better.
>> Nit: I wonder if while at it (as it was already there) we could not remove the " ORDER BY lsn DESC LIMIT 1" part of it.
>> It does not change anything regarding the test but looks more appropriate to me.
>>
>
> It may not make a difference as this is anyway an error case but it
> looks more logical to LIMIT by 1 as you are fetching a single LSN
> value and it will be consistent with other tests in this file and the
> test case in the file 006_logical_decoding.pl.
>
yeah I think it all depends how one see this test (sort of test a failure or try to get
a result and see if it fails). That was a Nit so I don't have a strong opinion on this one.
> BTW, in the same test, I see it uses wait_for_catchup() in one place
> and wait_for_replay_catchup() in another place after Insert. Isn't it
> better to use wait_for_replay_catchup in both places?
>
They are both using the 'replay' mode so both are perfectly correct but for consistency (and as
they don't use the same "target_lsn" ('write' vs 'flush')) I think that using wait_for_replay_catchup()
in both places (which is using the 'flush' target lsn) is a good idea.
Regards,
--
Bertrand Drouvot
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: Fix a test case in 035_standby_logical_decoding.pl
2023-04-27 08:11 Fix a test case in 035_standby_logical_decoding.pl Yu Shi (Fujitsu) <[email protected]>
2023-04-27 08:46 ` Re: Fix a test case in 035_standby_logical_decoding.pl Drouvot, Bertrand <[email protected]>
2023-04-27 09:53 ` Re: Fix a test case in 035_standby_logical_decoding.pl Amit Kapila <[email protected]>
2023-04-27 10:37 ` Re: Fix a test case in 035_standby_logical_decoding.pl Drouvot, Bertrand <[email protected]>
@ 2023-04-27 13:53 ` Amit Kapila <[email protected]>
2023-04-28 02:05 ` RE: Fix a test case in 035_standby_logical_decoding.pl Yu Shi (Fujitsu) <[email protected]>
0 siblings, 1 reply; 8+ messages in thread
From: Amit Kapila @ 2023-04-27 13:53 UTC (permalink / raw)
To: Drouvot, Bertrand <[email protected]>; +Cc: Yu Shi (Fujitsu) <[email protected]>; pgsql-hackers
On Thu, Apr 27, 2023 at 4:07 PM Drouvot, Bertrand
<[email protected]> wrote:
>
> On 4/27/23 11:53 AM, Amit Kapila wrote:
> > On Thu, Apr 27, 2023 at 2:16 PM Drouvot, Bertrand
> > <[email protected]> wrote:
> >>
> >> On 4/27/23 10:11 AM, Yu Shi (Fujitsu) wrote:
> >>> Hi hackers,
> >>>
> >>> In 035_standby_logical_decoding.pl, I think that the check in the following test
> >>> case should be performed on the standby node, instead of the primary node, as
> >>> the slot is created on the standby node.
> >>
> >> Oh right, the current test is not done on the right node, thanks!
> >>
> >>> The test currently passes because it
> >>> only checks the return value of psql. It might be more appropriate to check the
> >>> error message.
> >>
> >> Agree, and it's consistent with what is being done in 006_logical_decoding.pl.
> >>
> >>> Please see the attached patch.
> >>>
> >>
> >> +
> >> +($result, $stdout, $stderr) = $node_standby->psql(
> >> 'otherdb',
> >> "SELECT lsn FROM pg_logical_slot_peek_changes('behaves_ok_activeslot', NULL, NULL) ORDER BY lsn DESC LIMIT 1;"
> >> - ),
> >> - 3,
> >> - 'replaying logical slot from another database fails');
> >> + );
> >> +ok( $stderr =~
> >> + m/replication slot "behaves_ok_activeslot" was not created in this database/,
> >> + "replaying logical slot from another database fails");
> >>
> >>
> >> That does look good to me.
> >>
> >
> > I agree that that the check should be done on standby but how does it
> > make a difference to check the error message or return value? Won't it
> > be the same for both primary and standby?
> >
>
> Yes that would be the same. I think the original idea from Shi-san (please correct me If I'm wrong)
> was "while at it" let's also make this test on the right node even better.
>
Fair enough. Let''s do it that way then.
> >> Nit: I wonder if while at it (as it was already there) we could not remove the " ORDER BY lsn DESC LIMIT 1" part of it.
> >> It does not change anything regarding the test but looks more appropriate to me.
> >>
> >
> > It may not make a difference as this is anyway an error case but it
> > looks more logical to LIMIT by 1 as you are fetching a single LSN
> > value and it will be consistent with other tests in this file and the
> > test case in the file 006_logical_decoding.pl.
> >
>
> yeah I think it all depends how one see this test (sort of test a failure or try to get
> a result and see if it fails). That was a Nit so I don't have a strong opinion on this one.
>
I feel let's be consistent here and keep it as it is.
> > BTW, in the same test, I see it uses wait_for_catchup() in one place
> > and wait_for_replay_catchup() in another place after Insert. Isn't it
> > better to use wait_for_replay_catchup in both places?
> >
>
> They are both using the 'replay' mode so both are perfectly correct but for consistency (and as
> they don't use the same "target_lsn" ('write' vs 'flush')) I think that using wait_for_replay_catchup()
> in both places (which is using the 'flush' target lsn) is a good idea.
>
Yeah, let's use wait_for_replay_catchup() at both places.
--
With Regards,
Amit Kapila.
^ permalink raw reply [nested|flat] 8+ messages in thread
* RE: Fix a test case in 035_standby_logical_decoding.pl
2023-04-27 08:11 Fix a test case in 035_standby_logical_decoding.pl Yu Shi (Fujitsu) <[email protected]>
2023-04-27 08:46 ` Re: Fix a test case in 035_standby_logical_decoding.pl Drouvot, Bertrand <[email protected]>
2023-04-27 09:53 ` Re: Fix a test case in 035_standby_logical_decoding.pl Amit Kapila <[email protected]>
2023-04-27 10:37 ` Re: Fix a test case in 035_standby_logical_decoding.pl Drouvot, Bertrand <[email protected]>
2023-04-27 13:53 ` Re: Fix a test case in 035_standby_logical_decoding.pl Amit Kapila <[email protected]>
@ 2023-04-28 02:05 ` Yu Shi (Fujitsu) <[email protected]>
0 siblings, 0 replies; 8+ messages in thread
From: Yu Shi (Fujitsu) @ 2023-04-28 02:05 UTC (permalink / raw)
To: Amit Kapila <[email protected]>; Drouvot, Bertrand <[email protected]>; +Cc: pgsql-hackers
On Thu, Apr 27, 2023 9:53 PM Amit Kapila <[email protected]> wrote:
>
> On Thu, Apr 27, 2023 at 4:07 PM Drouvot, Bertrand
> <[email protected]> wrote:
> >
> > On 4/27/23 11:53 AM, Amit Kapila wrote:
> > > On Thu, Apr 27, 2023 at 2:16 PM Drouvot, Bertrand
> > > <[email protected]> wrote:
> > >>
> > >> On 4/27/23 10:11 AM, Yu Shi (Fujitsu) wrote:
> > >>> Hi hackers,
> > >>>
> > >>> In 035_standby_logical_decoding.pl, I think that the check in the following
> test
> > >>> case should be performed on the standby node, instead of the primary
> node, as
> > >>> the slot is created on the standby node.
> > >>
> > >> Oh right, the current test is not done on the right node, thanks!
> > >>
> > >>> The test currently passes because it
> > >>> only checks the return value of psql. It might be more appropriate to check
> the
> > >>> error message.
> > >>
> > >> Agree, and it's consistent with what is being done in
> 006_logical_decoding.pl.
> > >>
> > >>> Please see the attached patch.
> > >>>
> > >>
> > >> +
> > >> +($result, $stdout, $stderr) = $node_standby->psql(
> > >> 'otherdb',
> > >> "SELECT lsn FROM
> pg_logical_slot_peek_changes('behaves_ok_activeslot', NULL, NULL) ORDER BY
> lsn DESC LIMIT 1;"
> > >> - ),
> > >> - 3,
> > >> - 'replaying logical slot from another database fails');
> > >> + );
> > >> +ok( $stderr =~
> > >> + m/replication slot "behaves_ok_activeslot" was not created in this
> database/,
> > >> + "replaying logical slot from another database fails");
> > >>
> > >>
> > >> That does look good to me.
> > >>
> > >
> > > I agree that that the check should be done on standby but how does it
> > > make a difference to check the error message or return value? Won't it
> > > be the same for both primary and standby?
> > >
> >
> > Yes that would be the same. I think the original idea from Shi-san (please
> correct me If I'm wrong)
> > was "while at it" let's also make this test on the right node even better.
> >
>
> Fair enough. Let''s do it that way then.
>
> > >> Nit: I wonder if while at it (as it was already there) we could not remove the
> " ORDER BY lsn DESC LIMIT 1" part of it.
> > >> It does not change anything regarding the test but looks more appropriate
> to me.
> > >>
> > >
> > > It may not make a difference as this is anyway an error case but it
> > > looks more logical to LIMIT by 1 as you are fetching a single LSN
> > > value and it will be consistent with other tests in this file and the
> > > test case in the file 006_logical_decoding.pl.
> > >
> >
> > yeah I think it all depends how one see this test (sort of test a failure or try to
> get
> > a result and see if it fails). That was a Nit so I don't have a strong opinion on
> this one.
> >
>
> I feel let's be consistent here and keep it as it is.
>
> > > BTW, in the same test, I see it uses wait_for_catchup() in one place
> > > and wait_for_replay_catchup() in another place after Insert. Isn't it
> > > better to use wait_for_replay_catchup in both places?
> > >
> >
> > They are both using the 'replay' mode so both are perfectly correct but for
> consistency (and as
> > they don't use the same "target_lsn" ('write' vs 'flush')) I think that using
> wait_for_replay_catchup()
> > in both places (which is using the 'flush' target lsn) is a good idea.
> >
>
> Yeah, let's use wait_for_replay_catchup() at both places.
>
Thanks for your reply. Your suggestions make sense to me.
Please see the attached patch.
Regards,
Shi Yu
Attachments:
[application/octet-stream] v3-0001-Fix-a-test-case-in-035_standby_logical_decoding.p.patch (2.0K, ../../OSZPR01MB6310C83F99B56DFB43F4186EFD6B9@OSZPR01MB6310.jpnprd01.prod.outlook.com/2-v3-0001-Fix-a-test-case-in-035_standby_logical_decoding.p.patch)
download | inline diff:
From a9d850131dc375b69f69f319d189ed4ba6430f9b Mon Sep 17 00:00:00 2001
From: Shi Yu <[email protected]>
Date: Thu, 27 Apr 2023 11:05:40 +0800
Subject: [PATCH v3] Fix a test case in 035_standby_logical_decoding.pl
For the "replaying logical slot from another database fails" check, perform it
on the standby node instead of the primary node.
---
.../recovery/t/035_standby_logical_decoding.pl | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/src/test/recovery/t/035_standby_logical_decoding.pl b/src/test/recovery/t/035_standby_logical_decoding.pl
index f6d6447412..66d264f230 100644
--- a/src/test/recovery/t/035_standby_logical_decoding.pl
+++ b/src/test/recovery/t/035_standby_logical_decoding.pl
@@ -361,7 +361,7 @@ $node_primary->safe_psql('testdb',
qq[INSERT INTO decoding_test(x,y) SELECT s, s::text FROM generate_series(5,50) s;]
);
-$node_primary->wait_for_catchup($node_standby);
+$node_primary->wait_for_replay_catchup($node_standby);
my $stdout_recv = $node_standby->pg_recvlogical_upto(
'testdb', 'behaves_ok_activeslot', $endpos, $default_timeout,
@@ -384,12 +384,17 @@ is($stdout_recv, '', 'pg_recvlogical acknowledged changes');
$node_primary->safe_psql('postgres', 'CREATE DATABASE otherdb');
-is( $node_primary->psql(
+# Wait for catchup to ensure that the new database is visible to other sessions
+# on the standby.
+$node_primary->wait_for_replay_catchup($node_standby);
+
+($result, $stdout, $stderr) = $node_standby->psql(
'otherdb',
"SELECT lsn FROM pg_logical_slot_peek_changes('behaves_ok_activeslot', NULL, NULL) ORDER BY lsn DESC LIMIT 1;"
- ),
- 3,
- 'replaying logical slot from another database fails');
+ );
+ok( $stderr =~
+ m/replication slot "behaves_ok_activeslot" was not created in this database/,
+ "replaying logical slot from another database fails");
##################################################
# Test that we can subscribe on the standby with the publication
--
2.30.0.windows.2
^ permalink raw reply [nested|flat] 8+ messages in thread
end of thread, other threads:[~2023-04-28 02:05 UTC | newest]
Thread overview: 8+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2020-03-19 06:11 [PATCH v50 5/7] Doc part of shared-memory based stats collector. Kyotaro Horiguchi <[email protected]>
2023-04-27 08:11 Fix a test case in 035_standby_logical_decoding.pl Yu Shi (Fujitsu) <[email protected]>
2023-04-27 08:46 ` Re: Fix a test case in 035_standby_logical_decoding.pl Drouvot, Bertrand <[email protected]>
2023-04-27 09:41 ` RE: Fix a test case in 035_standby_logical_decoding.pl Yu Shi (Fujitsu) <[email protected]>
2023-04-27 09:53 ` Re: Fix a test case in 035_standby_logical_decoding.pl Amit Kapila <[email protected]>
2023-04-27 10:37 ` Re: Fix a test case in 035_standby_logical_decoding.pl Drouvot, Bertrand <[email protected]>
2023-04-27 13:53 ` Re: Fix a test case in 035_standby_logical_decoding.pl Amit Kapila <[email protected]>
2023-04-28 02:05 ` RE: Fix a test case in 035_standby_logical_decoding.pl Yu Shi (Fujitsu) <[email protected]>
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox