Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lOIh3-0007i8-4j for pgsql-hackers@arkaria.postgresql.org; Mon, 22 Mar 2021 11:25:57 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lOIh0-0001Oz-Sh for pgsql-hackers@arkaria.postgresql.org; Mon, 22 Mar 2021 11:25:54 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lOIh0-0001Os-HV for pgsql-hackers@lists.postgresql.org; Mon, 22 Mar 2021 11:25:54 +0000 Received: from oss.nttdata.com ([49.212.34.109]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lOIgw-0007Pv-0N for pgsql-hackers@postgresql.org; Mon, 22 Mar 2021 11:25:53 +0000 Received: from [192.168.0.4] (124-144-135-173.rev.home.ne.jp [124.144.135.173]) by oss.nttdata.com (Postfix) with ESMTPSA id 4CA2E623C6; Mon, 22 Mar 2021 20:25:46 +0900 (JST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.102.3 at oss.nttdata.com Subject: Re: About to add WAL write/fsync statistics to pg_stat_wal view To: Fujii Masao Cc: "David G. Johnston" , PostgreSQL-development , Masahiko Sawada , Li Japin , kuroda.hayato@fujitsu.com References: <0509ad67b585a5b86a83d445dfa75392@oss.nttdata.com> <930cae989a0fe8db6870cbeb5f24cf97@oss.nttdata.com> <9a70efda-6f47-8b1c-0513-419e1185000a@oss.nttdata.com> <6c8932c2b0756971e4b28f06af07be9a@oss.nttdata.com> <4a81fc95615db54b75f59759752b2cef@oss.nttdata.com> <49d412cc-2e39-a487-1861-a8560ebb88cb@oss.nttdata.com> <99fbf195e4b02a629cbf8190a0b9d47a@oss.nttdata.com> <7c08820c-06d6-0968-100a-5df71d67768b@oss.nttdata.com> <550de3c1-3408-de76-6fc1-a46eedc217a3@oss.nttdata.com> <90d8baf25655a08299185cb1a616bda1@oss.nttdata.com> <82ccde1a-ead9-598c-f472-004a01ff23e9@oss.nttdata.com> <940c12fd-96dc-67d2-afe9-dbb679eda010@oss.nttdata.com> From: ikedamsh Message-ID: Date: Mon, 22 Mar 2021 20:25:45 +0900 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.1 MIME-Version: 1.0 In-Reply-To: <940c12fd-96dc-67d2-afe9-dbb679eda010@oss.nttdata.com> Content-Type: multipart/mixed; boundary="------------A7A617337472EF64BB168943" Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------A7A617337472EF64BB168943 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 8bit On 2021/03/22 16:50, Fujii Masao wrote: > > > On 2021/03/22 9:50, ikedamsh wrote: >> Agreed. I separated the patches. >> >> If only the former is committed, my trivial concern is that there may be >> a disadvantage, but no advantage for the standby server. It may lead to >> performance degradation to the wal receiver by calling >> INSTR_TIME_SET_CURRENT(), but the stats can't visible for users until the >> latter patch is committed. > > Your concern is valid, so let's polish and commit also the 0003 patch to v14. > I'm still thinking that it's better to separate wal_xxx columns into > walreceiver's and the others. But if we count even walreceiver activity on > the existing columns, regarding 0003 patch, we need to update the document? > For example, "Number of times WAL buffers were written out to disk via > XLogWrite request." should be "Number of times WAL buffers were written > out to disk via XLogWrite request and by WAL receiver process."? Maybe > we need to append some descriptions about this into "WAL configuration" > section? Agreed. Users can know whether the stats is for walreceiver or not. The pg_stat_wal view in standby server shows for the walreceiver, and in primary server it shows for the others. So, I updated the document. (v20-0003-Makes-the-wal-receiver-report-WAL-statistics.patch) >> I followed the argument of pg_pwrite(). >> But, I think "char *" is better, so fixed it. > > Thanks for updating the patch! > > +extern int    XLogWriteFile(int fd, char *buf, > +                          size_t nbyte, off_t offset, > +                          TimeLineID timelineid, XLogSegNo segno, > +                          bool write_all); > > write_all seems not to be necessary. You added this flag for walreceiver, > I guess. But even without the argument, walreceiver seems to work expectedly. > So, what about the attached patch? I applied some cosmetic changes to the patch. Thanks a lot. Yes, "write_all" is unnecessary. Your patch is looks good to me. Regards, -- Masahiro Ikeda NTT DATA CORPORATION --------------A7A617337472EF64BB168943 Content-Type: text/x-patch; charset=UTF-8; name="v20-0003-Makes-the-wal-receiver-report-WAL-statistics.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="v20-0003-Makes-the-wal-receiver-report-WAL-statistics.patch" diff --git a/doc/src/sgml/monitoring.sgml b/doc/src/sgml/monitoring.sgml index db4b4e460c..281b13b9fa 100644 --- a/doc/src/sgml/monitoring.sgml +++ b/doc/src/sgml/monitoring.sgml @@ -3493,7 +3493,8 @@ SELECT pid, wait_event_type, wait_event FROM pg_stat_activity WHERE wait_event i Number of times WAL buffers were written out to disk via - XLogWrite request. + XLogWrite request and WAL data were written + out to disk by the WAL receiver process. See for more information about the internal WAL function XLogWrite. @@ -3521,7 +3522,8 @@ SELECT pid, wait_event_type, wait_event FROM pg_stat_activity WHERE wait_event i Total amount of time spent writing WAL buffers to disk via - XLogWrite request, in milliseconds + XLogWrite request and WAL data to disk + by the WAL receiver process, in milliseconds (if is enabled, otherwise zero). This includes the sync time when wal_sync_method is either diff --git a/doc/src/sgml/wal.sgml b/doc/src/sgml/wal.sgml index ae4a3c1293..39e7028c96 100644 --- a/doc/src/sgml/wal.sgml +++ b/doc/src/sgml/wal.sgml @@ -769,7 +769,7 @@ - There are two internal functions to write WAL data to disk: + There are two internal functions to write generated WAL data to disk: XLogWrite and issue_xlog_fsync. When is enabled, the total amounts of time XLogWrite writes and @@ -795,7 +795,19 @@ issue_xlog_fsync syncs WAL data to disk are also counted as wal_write and wal_sync in pg_stat_wal, respectively. - + To write replicated WAL data to disk by the WAL receiver is almost the same + as above except for some points. First, there is a dedicated code path for the + WAL receiver to write data although issue_xlog_fsync is + the same for syncing data. + Second, the WAL receiver writes replicated WAL data per bytes from the local + memory although the generated WAL data is written per WAL buffer pages. + The counters of wal_write, wal_sync, + wal_write_time, and wal_sync_time are + common statistics for writing/syncing both generated and replicated WAL data. + But, you can distinguish them because the generated WAL data is written/synced + in the primary server and the replicated WAL data is written/synced in + the standby server. + diff --git a/src/backend/replication/walreceiver.c b/src/backend/replication/walreceiver.c index a7a94d2a83..df028c5039 100644 --- a/src/backend/replication/walreceiver.c +++ b/src/backend/replication/walreceiver.c @@ -771,6 +771,9 @@ WalRcvDie(int code, Datum arg) /* Ensure that all WAL records received are flushed to disk */ XLogWalRcvFlush(true); + /* Send WAL statistics to the stats collector before terminating */ + pgstat_send_wal(true); + /* Mark ourselves inactive in shared memory */ SpinLockAcquire(&walrcv->mutex); Assert(walrcv->walRcvState == WALRCV_STREAMING || @@ -910,6 +913,12 @@ XLogWalRcvWrite(char *buf, Size nbytes, XLogRecPtr recptr) XLogArchiveForceDone(xlogfname); else XLogArchiveNotify(xlogfname); + + /* + * Send WAL statistics to the stats collector when finishing + * the current WAL segment file to avoid overloading it. + */ + pgstat_send_wal(false); } recvFile = -1; --------------A7A617337472EF64BB168943--