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 1outNc-00066Z-Ct for pgsql-hackers@arkaria.postgresql.org; Tue, 15 Nov 2022 10:41:24 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1outNa-0000md-OO for pgsql-hackers@arkaria.postgresql.org; Tue, 15 Nov 2022 10:41:22 +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 1outNa-0000mA-B2 for pgsql-hackers@lists.postgresql.org; Tue, 15 Nov 2022 10:41:22 +0000 Received: from mail-wr1-x431.google.com ([2a00:1450:4864:20::431]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1outNX-0005Ak-EW for pgsql-hackers@postgresql.org; Tue, 15 Nov 2022 10:41:21 +0000 Received: by mail-wr1-x431.google.com with SMTP id o4so23399702wrq.6 for ; Tue, 15 Nov 2022 02:41:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=SmP0kkQ4xetkg6RRiHnmoapmIQpqlZ5YAR334grMZro=; b=OFQVOGbU4j0+5/TTR5ob6uRwjrhDQl6WcBXZ6yfx9TNoxc2sENJTZDV9FIfeV0bSXV B01hGhXeNmi2R0SMtFgbMtEWinOch+iDgXCBxd1kGL6xv2LYPMgb09E94D/o6cljKlfE m5LAJSvOVpSWu6EKLRHzc18T3GtJP1OygPaNGaF40iLB/xTBqkIyRsBaskynntJPb2Qn ufKM/KkDGhKdgAewybZqYEP7//2rhmciaxou/3MeZUKl+GhvsUaa2+50/iCafQrcBFIL xvdTEskAKjh2znvrypmXf+ANv+WvPW5gEys/TpuVmOtnOM9CTw7G6uJNL0ZLEBBEX1Jn VDJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=SmP0kkQ4xetkg6RRiHnmoapmIQpqlZ5YAR334grMZro=; b=4/ppH/HLAeHno3MIqFDcB6+g+bCDTtMUgNNvaj6pExjg9No3zQFyjo4gh2mgm9DBBw nfI67Uw8v5brhaAzdwLGmp3Voz345q+pn1RiWEvbIETX4E/CxETdpyewkvv+oTTwy4xJ GJ0HPPW+5jZuH98apj75JQMUOg/1IQQ3mVQmV2JupvmlrFc4L4YyfEz3FwyLFF86iG6x Vg+wknxpaN6b5+P0X+3oPTiByZK9u5NGaO0XMeES30hNInLieeInoj5N8NQ7cJvauNsO XxPMImrMgpgiXbECoolX9l6JVPZGapzJA2JmNScmLoWNei6EiKxT59PvGZfrfhz7/Ops Mi3Q== X-Gm-Message-State: ANoB5pkLDMjAvMGEPN+k9fOqpNUDIMNBWeC60T8Rj+x9NjwKejRDVZIC 5RC/pKXyE7JNeI26NHGo7W4ux+TW9ADVD6SQlNA= X-Google-Smtp-Source: AA0mqf652JpZg6cP5GQEDviFHl4pnuTN4SjWnVCXj/Sy/9t3phM473bcmDPjBGlEO+ExXC94JcNbG+9S7/7R4ipX6oI= X-Received: by 2002:adf:a3cb:0:b0:22e:4b62:7ca6 with SMTP id m11-20020adfa3cb000000b0022e4b627ca6mr9609272wrb.441.1668508877428; Tue, 15 Nov 2022 02:41:17 -0800 (PST) MIME-Version: 1.0 References: <20221104140238.GA16921@telsasoft.com> <4E379ADE-1FC3-4D53-BE46-562BDC77C5FE@crunchydata.com> <20221104183838.GD16921@telsasoft.com> <20221108224519.GH3775@telsasoft.com> In-Reply-To: From: Bharath Rupireddy Date: Tue, 15 Nov 2022 16:11:05 +0530 Message-ID: Subject: Re: [PATCH] Teach pg_waldump to extract FPIs from the WAL To: David Christensen Cc: Justin Pryzby , Ian Lawrence Barwick , Michael Paquier , Matthias van de Meent , pgsql-hackers@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 15, 2022 at 1:29 AM David Christensen wrote: > > Enclosed is v8, which uses the replication slot method to retain WAL > as well as fsync'ing the output directory when everything is done. Thanks. It mostly is in good shape. However, few more comments: 1. + if it does not exist. The images saved will be subject to the same + filtering and limiting criteria as display records, but in this + mode pg_waldump will not output any other + information. May I know what's the intention of the statement 'The images saved ....'? If it's not necessary and convey anything useful to the user, can we remove it? 2. +#include "storage/checksum.h" +#include "storage/checksum_impl.h" I think we don't need the above includes as we got rid of verifying page checksums. The patch compiles without them for me. 3. + char *save_fpw_path; Can we rename the above variable to save_fpi_path, just to be in sync with what we expose to the user, the option name 'save-fpi'? 4. + if (config.save_fpw_path != NULL) + { + /* Fsync our output directory */ + fsync_fname(config.save_fpw_path, true); + } I guess adding a comment there as to why we aren't fsyncing for every file that gets created, but once per the directory at the end. That'd help clarify doubts that other members might get while looking at the code. 5. + if (config.save_fpw_path != NULL) + { + /* Fsync our output directory */ + fsync_fname(config.save_fpw_path, true); + } So, are we sure that we don't want to fsync for time_to_stop exit(0) cases, say when CTRL+C'ed. Looks like we handle time_to_stop safely meaning exiting with return code 0, shouldn't we fsync the directory? 6. + else if (config.save_fpw_path) Let's use the same convention to check non-NULLness, config.save_fpw_path != NULL. 7. +CHECKPOINT; +SELECT pg_switch_wal(); +UPDATE test_table SET a = a + 1; +SELECT pg_switch_wal(); I don't think switching WAL after checkpoint is necessary here, because the checkpoint ensures all the WAL gets flushed to disk. Please remove it. PS: I've seen the following code: +my $walfile = [sort { $a <=> $b } glob("$waldir/00*")]->[1]; # we want the second WAL file, which will be a complete WAL file with full-page writes for our specific relation. 8. +$node->safe_psql('postgres', <safe_psql( 'postgres', qq[ SELECT data FROM pg_logical_slot_get_changes('regression_slot1', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1'); SELECT data FROM pg_logical_slot_get_changes('regression_slot2', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1'); SELECT data FROM pg_logical_slot_get_changes('regression_slot3', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1'); SELECT data FROM pg_logical_slot_get_changes('regression_slot4', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1'); ]); Same here: +$node->safe_psql('postgres', < $b } glob("$waldir/00*")]->[1]; # we want the second WAL file, which will be a complete WAL file with full-page writes for our specific relation. Is it guaranteed that just looking at the second WAL file in the pg_wal directory assures WAL file with FPIs? I think we have to save the WAL file that contains FPIs, that is the file after, CHECKPOINT, UPDATE and pg_switch_wal. I think you can store output LSN of pg_switch_wal 10. +$node->safe_psql('postgres', <