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 1miR0r-0005p3-W5 for pgsql-hackers@arkaria.postgresql.org; Thu, 04 Nov 2021 00:53:54 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1miR0q-0001VT-Tb for pgsql-hackers@arkaria.postgresql.org; Thu, 04 Nov 2021 00:53:52 +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 1miR0q-0001VK-Gc for pgsql-hackers@lists.postgresql.org; Thu, 04 Nov 2021 00:53:52 +0000 Received: from mail-yb1-xb32.google.com ([2607:f8b0:4864:20::b32]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1miR0m-0006fp-QU for pgsql-hackers@lists.postgresql.org; Thu, 04 Nov 2021 00:53:51 +0000 Received: by mail-yb1-xb32.google.com with SMTP id q74so10570415ybq.11 for ; Wed, 03 Nov 2021 17:53:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=QXjFSJPZFN4xOI6vPiC/YmSjlt1snhDpSmQ6AtM3D0U=; b=NSBV/E/P70rvgNEBVTPwWZtn0KzkygtlRvTq9PxEcmW8356ePR9scibSQl9CoVXjtI Zr5pnR1whc7I3BPw541/DsmkWs2MaLwFdXcJXYP0boAvIDG9S0PtaWSKJUC7i2VFhUV6 pOx+C2v9QogKS22kNo/rebpYa6H56gnj5FWgEanopc4l8wGxWxDASpPA2KqLTu/coJvV Jg68aA7+c88c7Dx+e5IRZeahIhvtojvyG56o++368asrmp56NFL5Z4iAod8+ougiCxH+ B/g7pTpHGLilHhnZJCibLiq8bN7FnaGG4LkgoKifxv/eqgxeGcuLaXRq4zAmOh4wMHdJ sA8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=QXjFSJPZFN4xOI6vPiC/YmSjlt1snhDpSmQ6AtM3D0U=; b=mPW8YEr++TQBzi5gEh2AIl7a840wK7H8rxyICOcgR+QLrujE+NIwg6WVrJHnvRdPum qNX9c18iHP2rSF/W33Pnkao7uONY2NfbeBbAmKJwev1CJcjrVgCR1VcpOQc/C2tvvObh 4W26yJyEyVRduRonCsKRDnLUw+uMexRyKFJ5XvXijaEFrAWZ7GO+UJbRwBjcE7iBcWcO MB2wYBLy4kji3Nmd6Mah7uwPvHibtH7Xu5wF6X40vANOHTHY/xKuD0lKIOA/y1OGVsMM FL3xptPzeO5+M7/Xo6qAioxv6hwXbItS4ya4y9XtEqiofz9Tdz+yO5CN7arTQQUMfuBX mh2A== X-Gm-Message-State: AOAM531tOg/5s+dp5CHXl4fZwvSZF1+ZBkU7e/ls8woDBeMp0hNleZkR OWnC0/onE2PG5Q2/Dsa7DM91ITRj7Fx1VWYZNs8= X-Google-Smtp-Source: ABdhPJzy3tX/Uw/5oO76BLe8FpSq5YpyEZCzbqcn02WTigzDNG/icAN4a7Rir/m3RY7T3FLs4xVNNtxD4JrHv2lhcGQ= X-Received: by 2002:a25:58d4:: with SMTP id m203mr50211834ybb.17.1635987227621; Wed, 03 Nov 2021 17:53:47 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Greg Nancarrow Date: Thu, 4 Nov 2021 11:53:47 +1100 Message-ID: Subject: Re: Failed transaction statistics to measure the logical replication progress To: "osumi.takamichi@fujitsu.com" Cc: Masahiko Sawada , Amit Kapila , "houzj.fnst@fujitsu.com" , "pgsql-hackers@lists.postgresql.org" Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Tue, Nov 2, 2021 at 12:18 AM osumi.takamichi@fujitsu.com wrote: > > On Thursday, October 28, 2021 11:19 PM I wrote: > > I've created a new patch that extends pg_stat_subscription_workers to include > > other transaction statistics. > > > > Note that this patch depends on v18 patch-set in [1]... > Rebased based on the v19 in [1]. > Also, fixed documentation a little and made tests tidy. > FYI, the newly included TAP test(027_worker_xact_stats.pl) is stable > because I checked that 100 times of its execution in a tight loop all passed. > I have done some basic testing of the patch and have some initial review comments: (1) I think this patch needs to be in "git format-patch" format, with a proper commit message that describes the purpose of the patch and the functionality it adds, and any high-level design points (something like the overview given in the initial post, and accounting for the subsequent discussion points and updated functionality). (2) doc/src/sgml/monitoring.sgml There are some grammatical issues in the current description. I suggest changing it to something like: BEFORE: + At least one row per subscription, showing about transaction statistics and error summary that AFTER: + At least one row per subscription, showing transaction statistics and information about errors that (2) doc/src/sgml/monitoring.sgml The current description seems a little confusing. Per subscription, it shows the transaction statistics and any last error info from tablesync/apply workers? If this is the case, I'd suggest the following change: BEFORE: + one row per subscription for transaction statistics and summary of the last + error reported by workers applying logical replication changes and workers + handling the initial data copy of the subscribed tables. AFTER: + one row per subscription, showing corresponding transaction statistics and + information about the last error reported by workers applying logical replication + changes or by workers handling the initial data copy of the subscribed tables. (3) xact_commit I think that the "xact_commit" column should be named "xact_commit_count" or "xact_commits". Similarly, I think "xact_error" should be named "xact_error_count" or "xact_errors", and "xact_aborts" should be named "xact_abort_count" or "xact_aborts". (4) xact_commit_bytes + Amount of transactions data successfully applied in this subscription. + Consumed memory for xact_commit is displayed. I find this description a bit confusing. "Consumed memory for xact_commit" seems different to "transactions data". Could the description be something like: Amount of data (in bytes) successfully applied in this subscription, across "xact_commit_count" transactions. (5) I'd suggest some minor rewording for the following: BEFORE: + Number of transactions failed to be applied and caught by table + sync worker or main apply worker in this subscription. AFTER: + Number of transactions that failed to be applied by the table + sync worker or main apply worker in this subscription. (6) xact_error_bytes Again, it's a little confusing referring to "consumed memory" here. How about rewording this, something like: BEFORE: + Amount of transactions data unsuccessfully applied in this subscription. + Consumed memory that past failed transaction used is displayed. AFTER: + Amount of data (in bytes) unsuccessfully applied in this subscription by the last failed transaction. (7) The additional information provided for "xact_abort_bytes" needs some rewording, something like: BEFORE: + Increase logical_decoding_work_mem on the publisher + so that it exceeds the size of whole streamed transaction + to suppress unnecessary consumed network bandwidth in addition to change + in memory of the subscriber, if unexpected amount of streamed transactions + are aborted. AFTER: + In order to suppress unnecessary consumed network bandwidth, increase + logical_decoding_work_mem on the publisher so that it + exceeds the size of the whole streamed transaction, and additionally increase + the available subscriber memory, if an unexpected amount of streamed transactions + are aborted. (8) Suggested update: BEFORE: + * Tell the collector that worker transaction has finished without problem. AFTER: + * Tell the collector that the worker transaction has successfully completed. (9) src/backend/postmaster/pgstat.c I think that the GID copying is unnecessarily copying the whole GID buffer or using an additional strlen(). It should be changed to use strlcpy() to match other code: BEFORE: + /* get the gid for this two phase operation */ + if (command == LOGICAL_REP_MSG_PREPARE || + command == LOGICAL_REP_MSG_STREAM_PREPARE) + memcpy(msg.m_gid, prepare_data->gid, GIDSIZE); + else if (command == LOGICAL_REP_MSG_COMMIT_PREPARED) + memcpy(msg.m_gid, commit_data->gid, GIDSIZE); + else /* rollback prepared */ + memcpy(msg.m_gid, rollback_data->gid, GIDSIZE); AFTER: + /* get the gid for this two phase operation */ + if (command == LOGICAL_REP_MSG_PREPARE || + command == LOGICAL_REP_MSG_STREAM_PREPARE) + strlcpy(msg.m_gid, prepare_data->gid, sizeof(msg.m_gid)); + else if (command == LOGICAL_REP_MSG_COMMIT_PREPARED) + strlcpy(msg.m_gid, commit_data->gid, sizeof(msg.m_gid)); + else /* rollback prepared */ + strlcpy(msg.m_gid, rollback_data->gid, sizeof(msg.m_gid)); BEFORE: + strlcpy(prepared_txn->gid, msg->m_gid, strlen(msg->m_gid) + 1); AFTER: + strlcpy(prepared_txn->gid, msg->m_gid, sizeof(prepared_txn->gid)); BEFORE: + memcpy(key.gid, msg->m_gid, strlen(msg->m_gid)); AFTER: + strlcpy(key.gid, msg->m_gid, sizeof(key.gid)); BEFORE: + memcpy(key.gid, gid, strlen(gid)); AFTER: + strlcpy(key.gid, gid, sizeof(key.gid)); (10) src/backend/replication/logical/worker.c Some suggested rewording: BEFORE: + * size of streaming transaction resources because it have used the AFTER: + * size of streaming transaction resources because it has used the BEFORE: + * tradeoff should not be good. Also, add multiple values + * at once in order to reduce the number of this function call. AFTER: + * tradeoff would not be good. Also, add multiple values + * at once in order to reduce the number of calls to this function. (11) update_apply_change_size() Shouldn't this function be declared static? (12) stream_write_change() + streamed_entry->xact_size = streamed_entry->xact_size + total_len; /* update */ could be simply written as: + streamed_entry->xact_size += total_len; /* update */ Regards, Greg Nancarrow Fujitsu Australia