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 1lj07I-0004bY-Ni for pgsql-hackers@arkaria.postgresql.org; Tue, 18 May 2021 13:50:37 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lj07H-0006q1-N6 for pgsql-hackers@arkaria.postgresql.org; Tue, 18 May 2021 13:50:35 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lj07H-0006pt-B8 for pgsql-hackers@lists.postgresql.org; Tue, 18 May 2021 13:50:35 +0000 Received: from lahtoruutu.iki.fi ([185.185.170.37]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lj07E-0007Hs-WA for pgsql-hackers@postgresql.org; Tue, 18 May 2021 13:50:35 +0000 Received: from [192.168.1.113] (dsl-hkibng22-54faa4-119.dhcp.inet.fi [84.250.164.119]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: hlinnaka) by lahtoruutu.iki.fi (Postfix) with ESMTPSA id 8FA111B00118 for ; Tue, 18 May 2021 16:50:31 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=lahtoruutu; t=1621345831; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type; bh=cvRoPiIedfW/gsLnCVhm6+4gTKdM1QUied+FR7nXvuU=; b=p/WcSjVrlwGkg69hkPDP2SEDXw/33ctGBFEsFN4SDcXLn0mh9f2KAX5xdzzokgUnENLoGS aH1fNm+N+fNZ5tLNBHoS+GgyFML9+cmhpedrYaIy5JWRL/AajZzx7w/g0fImBFzpEeNBNe 1Rl4SWViZ0tglABdV87X0kb19EsLiITRbxc+L3q+9f6tQY/1mqFYykQ1CP2sQRqiudCKCR lMistWxe3FqHTYVZYkIZCDbEyDXhPVd8Gun4z8EIofSNWHda+h1NSfXkv8tdI/vQVaIB88 cZncJej9/0aSBbspjjErz34Ozdx7dra0+yFqXn/g4ci9xlNIaUFefDYOnrTgxg== From: Heikki Linnakangas To: pgsql-hackers Subject: Multiple pg_waldump --rmgr options Message-ID: <98344bc2-e222-02ad-a75b-81ffc614c155@iki.fi> Date: Tue, 18 May 2021 16:50:31 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.9.0 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------5CD2578A40CA1D4DCD988188" Content-Language: en-US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=lahtoruutu; t=1621345831; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type; bh=cvRoPiIedfW/gsLnCVhm6+4gTKdM1QUied+FR7nXvuU=; b=vI31LOQhToNtV1q9yMxI+U+/Zt2YHYtteI63woe0tYdmcpletHhj57k81P4t6EQBmIOrst ZLwVp7afYgpshm6d8pgmXsrF9sQ37FOsI7a4uN+l7nFjiCm4rKDAStN7aLAxlIEpr4ZRkA BsdpuCSKcmRfhVu3DHJlJ4RiwmYAdxmfrcan2GovbjkNe7+fJOh1FjBpomc0HMgnM71TY8 kqVdaFkX2+ymRYL45B/h98CWfcOggQDmHBttxCwPwMace0km0hsMZSsOG/5+CpyHX9epDT hEb6DlUUTUx8GdPYAm7AgLuRLsSIDB6+1xiNkjiiy1IC0VCWBVGNWv1+7MbW2w== ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=hlinnaka smtp.mailfrom=hlinnaka@iki.fi ARC-Seal: i=1; s=lahtoruutu; d=iki.fi; t=1621345831; a=rsa-sha256; cv=none; b=DUQZLXqH/mhtdwfRj+vW5ZY6RL4WuqXhTh7K0N7lgf+Ic6viTBHg2IIv4i6rrXdAJc020/ FkedMbsvAe8LKiOv0LpRBe/M7tDsPcZcnC2vPDvtdsgbwk1fa2kGqq+V6Ym1mKn5NEcEBv gA8Tuyo5sPkwTpbQ/2dQVZJBxyCjoFfRwsgUdz5dWvafcNFD1jtu0ZFYNoyporAjFuTjBZ jUhlIxzlzlEp0u9upGmXnJaqXf8Gef6nJYQRMXjzJc9/1x70E9cRsg4qBnE75svjjpEkgH wopQVr4cm0kq3Kd0B/Iu4zrutBw5wuSvKvGy0/ixemaCsuRKwtUJrvYGC8uTog== 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. --------------5CD2578A40CA1D4DCD988188 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit I wanted to dump all heap WAL records with pg_waldump, so I did this: > $ pg_waldump --rmgr=heap --rmgr=heap2 data/pg_wal/000000010000000000000001 --stat=record > Type N (%) Record size (%) FPI size (%) Combined size (%) > ---- - --- ----------- --- -------- --- ------------- --- > Heap2/PRUNE 268 ( 8.74) 18192 ( 2.73) 0 ( 0.00) 18192 ( 1.74) > Heap2/VACUUM 55 ( 1.79) 4940 ( 0.74) 0 ( 0.00) 4940 ( 0.47) > Heap2/FREEZE_PAGE 277 ( 9.03) 186868 ( 28.03) 0 ( 0.00) 186868 ( 17.86) > Heap2/VISIBLE 467 ( 15.23) 27783 ( 4.17) 376832 ( 99.34) 404615 ( 38.68) > Heap2/MULTI_INSERT 1944 ( 63.38) 354800 ( 53.21) 2520 ( 0.66) 357320 ( 34.16) > Heap2/MULTI_INSERT+INIT 56 ( 1.83) 74152 ( 11.12) 0 ( 0.00) 74152 ( 7.09) > -------- -------- -------- -------- > Total 3067 666735 [63.74%] 379352 [36.26%] 1046087 [100%] > pg_waldump: fatal: error in WAL record at 0/1680118: invalid record length at 0/1680150: wanted 24, got 0 That didn't do what I wanted. It only printed the Heap2 records, not Heap, even though I specified both. The reason is that if you specify multiple --rmgr options, only the last one takes effect. I propose the attached to allow selecting multiple rmgrs, by giving multiple --rmgr options. With that, it works the way I expected: > $ pg_waldump --rmgr=heap --rmgr=heap2 data/pg_wal/000000010000000000000001 --stat=record > Type N (%) Record size (%) FPI size (%) Combined size (%) > ---- - --- ----------- --- -------- --- ------------- --- > Heap2/PRUNE 268 ( 1.77) 18192 ( 0.71) 0 ( 0.00) 18192 ( 0.55) > Heap2/VACUUM 55 ( 0.36) 4940 ( 0.19) 0 ( 0.00) 4940 ( 0.15) > Heap2/FREEZE_PAGE 277 ( 1.83) 186868 ( 7.33) 0 ( 0.00) 186868 ( 5.67) > Heap2/VISIBLE 467 ( 3.09) 27783 ( 1.09) 376832 ( 50.37) 404615 ( 12.27) > Heap2/MULTI_INSERT 1944 ( 12.86) 354800 ( 13.91) 2520 ( 0.34) 357320 ( 10.83) > Heap2/MULTI_INSERT+INIT 56 ( 0.37) 74152 ( 2.91) 0 ( 0.00) 74152 ( 2.25) > Heap/INSERT 9948 ( 65.80) 1433891 ( 56.22) 8612 ( 1.15) 1442503 ( 43.73) > Heap/DELETE 942 ( 6.23) 50868 ( 1.99) 0 ( 0.00) 50868 ( 1.54) > Heap/UPDATE 193 ( 1.28) 101265 ( 3.97) 9556 ( 1.28) 110821 ( 3.36) > Heap/HOT_UPDATE 349 ( 2.31) 36910 ( 1.45) 1300 ( 0.17) 38210 ( 1.16) > Heap/LOCK 209 ( 1.38) 11481 ( 0.45) 316828 ( 42.35) 328309 ( 9.95) > Heap/INPLACE 212 ( 1.40) 44279 ( 1.74) 32444 ( 4.34) 76723 ( 2.33) > Heap/INSERT+INIT 184 ( 1.22) 188803 ( 7.40) 0 ( 0.00) 188803 ( 5.72) > Heap/UPDATE+INIT 15 ( 0.10) 16273 ( 0.64) 0 ( 0.00) 16273 ( 0.49) > -------- -------- -------- -------- > Total 15119 2550505 [77.32%] 748092 [22.68%] 3298597 [100%] > pg_waldump: fatal: error in WAL record at 0/1680150: invalid record length at 0/16801C8: wanted 24, got 0 - Heikki --------------5CD2578A40CA1D4DCD988188 Content-Type: text/x-patch; charset=UTF-8; name="0001-Allow-specifying-pg_waldump-rmgr-option-multiple-tim.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0001-Allow-specifying-pg_waldump-rmgr-option-multiple-tim.pa"; filename*1="tch" From 991296f690d79a12670f1dca341ecffccf78f907 Mon Sep 17 00:00:00 2001 From: Heikki Linnakangas Date: Tue, 18 May 2021 16:46:53 +0300 Subject: [PATCH 1/1] Allow specifying pg_waldump --rmgr option multiple times. Before, if you specified multiple --rmgr options, only the last one took effect. It seems more sensible to select all the specfied resource managers. --- doc/src/sgml/ref/pg_waldump.sgml | 3 ++- src/bin/pg_waldump/pg_waldump.c | 16 ++++++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/doc/src/sgml/ref/pg_waldump.sgml b/doc/src/sgml/ref/pg_waldump.sgml index 5fcdfe210ac..432254d2d5d 100644 --- a/doc/src/sgml/ref/pg_waldump.sgml +++ b/doc/src/sgml/ref/pg_waldump.sgml @@ -142,7 +142,8 @@ PostgreSQL documentation - Only display records generated by the specified resource manager. + Only display records generated by the specified resource manager. You can + specify the option multiple times to select multiple resource managers. If list is passed as name, print a list of valid resource manager names, and exit. diff --git a/src/bin/pg_waldump/pg_waldump.c b/src/bin/pg_waldump/pg_waldump.c index f8b8afe4a7b..5c6aa0df03e 100644 --- a/src/bin/pg_waldump/pg_waldump.c +++ b/src/bin/pg_waldump/pg_waldump.c @@ -49,7 +49,8 @@ typedef struct XLogDumpConfig bool stats_per_record; /* filter options */ - int filter_by_rmgr; + bool filter_by_rmgr[RM_MAX_ID + 1]; + bool filter_by_rmgr_enabled; TransactionId filter_by_xid; bool filter_by_xid_enabled; } XLogDumpConfig; @@ -814,7 +815,8 @@ main(int argc, char **argv) config.stop_after_records = -1; config.already_displayed_records = 0; config.follow = false; - config.filter_by_rmgr = -1; + /* filter_by_rmgr array was zeroed by memset above */ + config.filter_by_rmgr_enabled = false; config.filter_by_xid = InvalidTransactionId; config.filter_by_xid_enabled = false; config.stats = false; @@ -869,16 +871,17 @@ main(int argc, char **argv) exit(EXIT_SUCCESS); } + config.filter_by_rmgr_enabled = true; for (i = 0; i <= RM_MAX_ID; i++) { if (pg_strcasecmp(optarg, RmgrDescTable[i].rm_name) == 0) { - config.filter_by_rmgr = i; + config.filter_by_rmgr[i] = true; break; } } - if (config.filter_by_rmgr == -1) + if (i > RM_MAX_ID) { pg_log_error("resource manager \"%s\" does not exist", optarg); @@ -1087,8 +1090,9 @@ main(int argc, char **argv) } /* apply all specified filters */ - if (config.filter_by_rmgr != -1 && - config.filter_by_rmgr != record->xl_rmid) + if (config.filter_by_rmgr_enabled && + (record->xl_rmid < 0 || record->xl_rmid > RM_MAX_ID || + !config.filter_by_rmgr[record->xl_rmid])) continue; if (config.filter_by_xid_enabled && -- 2.30.2 --------------5CD2578A40CA1D4DCD988188--