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 1nSVOq-00036T-LA for pgsql-hackers@arkaria.postgresql.org; Fri, 11 Mar 2022 02:53:04 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nSVOp-0001Ay-7j for pgsql-hackers@arkaria.postgresql.org; Fri, 11 Mar 2022 02:53:03 +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 1nSVOo-0001Ap-S3 for pgsql-hackers@lists.postgresql.org; Fri, 11 Mar 2022 02:53:02 +0000 Received: from mail-pf1-x430.google.com ([2607:f8b0:4864:20::430]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1nSVOi-0000M5-HY for pgsql-hackers@lists.postgresql.org; Fri, 11 Mar 2022 02:53:02 +0000 Received: by mail-pf1-x430.google.com with SMTP id s8so6747239pfk.12 for ; Thu, 10 Mar 2022 18:52:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=date:message-id:to:cc:subject:from:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=Klvv6cM3dvJ3maWC/KMVScQSYn0Kn/ARHGe3cJdHih8=; b=QQJpyvqQbkiI3wSakiiNLOFgrSAmQF+3Qhq4cc9wx8IjwYiQr9tAtzgNCEk12l9A8w odgG6XNkHviyJDFbGmU7pDSNsNYc1tlqm3dHm+fNKCtCZBmWzEPToLVv19ny8g4puVuf 5oe1sZq/Ysh2UBlosxUU5I6PIO/i3sVcLyGeJhy70z6mXTj6hP9c7IkZz1ihaS7vNhoD RTrxvQn752L57r6EVvEfoZVWGcxg3R/9mXHHMbJDh2VPZB9aOXFa5UVq1Th/kbXvD5Ob AlhamEGDiBRa8I2fjidbM8v7XqUFwN2/BuEICBHrQoysy3lENqGvRrOCR2ZtYscnCtUC GyfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:message-id:to:cc:subject:from:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=Klvv6cM3dvJ3maWC/KMVScQSYn0Kn/ARHGe3cJdHih8=; b=wWK4Wh3+qbtqdBLfZ06vZ5cPp0ZZXwjqB1ArPHRq3nXl1iIvAHXeviT6MbdUTjdjp6 twYx8Z8RAC8Ccun2efSXhvXOkiS3RnrxsYZ1Y34lW5jJfXEss6wE0kx9cRTyS/wutns5 1AOHnfZcCChJEF6Dk338EGGu9IwO5+5s5OoDlBpeaB6AyVadAjegnufsf5axXU1dehWn X4mpba2Szzv6kpZoxMTt3kDXjAN8d4R2k0kfoGrbnoDYVAzetoE8/43rBJcBzI63awtH 72TIvkVh0C038zTmqWjMiEltrinQBIqGaLW3mNDkNYulb6WOs5V7qvH1l3NLZwI81FJT /x2A== X-Gm-Message-State: AOAM531B7lebYApgBVWdWCPMwiAx2zIWV798RyrFJr3I8f8CV6Oy0wyh fSRv2DdhlN+5Ho/M02iX6Oo= X-Google-Smtp-Source: ABdhPJwvMgnB0UUSW9ew3VJ5eu3BWdg1qDifbl0mpM4FmjVhEI7kuHZlPP+qrhPvtqBVEDIx/Tgw+w== X-Received: by 2002:a63:7502:0:b0:37f:f089:7d56 with SMTP id q2-20020a637502000000b0037ff0897d56mr6549135pgc.531.1646967174226; Thu, 10 Mar 2022 18:52:54 -0800 (PST) Received: from localhost (KD036014041111.ppp-bb.dion.ne.jp. [36.14.41.111]) by smtp.gmail.com with ESMTPSA id a12-20020a056a000c8c00b004e1a76f0a8asm8480653pfv.51.2022.03.10.18.52.50 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 10 Mar 2022 18:52:53 -0800 (PST) Date: Fri, 11 Mar 2022 11:52:49 +0900 (JST) Message-Id: <20220311.115249.268200339858571765.horikyota.ntt@gmail.com> To: bharath.rupireddyforpostgres@gmail.com Cc: pgsql@j-davis.com, ashu.coek88@gmail.com, andrew@dunslane.net, robertmhaas@gmail.com, stark@mit.edu, schneider@ardentperf.com, bruce@momjian.us, pgsql-hackers@lists.postgresql.org, satyanarlapuram@gmail.com, marvin_liang@qq.com, actyzhang@outlook.com Subject: Re: pg_walinspect - a new extension to get raw WAL data and WAL stats From: Kyotaro Horiguchi In-Reply-To: <20220311.113822.1784045072426345189.horikyota.ntt@gmail.com> References: <39c13407c8b7311e9a3b24f2df814696bfa2ebff.camel@j-davis.com> <20220311.113822.1784045072426345189.horikyota.ntt@gmail.com> User-Agent: Mew version 6.8 on Emacs 26.1 Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Sorry, some minor non-syntactical corrections. At Fri, 11 Mar 2022 11:38:22 +0900 (JST), Kyotaro Horiguchi wrote in > I played with this a bit, and would like to share some thoughts on it. > > It seems to me too rigorous that pg_get_wal_records_info/stats() > reject future LSNs as end-LSN and I think WARNING or INFO and stop at > the real end-of-WAL is more kind to users. I think the same with the > restriction that start and end LSN are required to be different. > > The definition of end-lsn is fuzzy here. If I fed a future LSN to the > functions, they tell me the beginning of the current insertion point > in error message. On the other hand they don't accept the same > value as end-LSN. I think it is right that they tell the current > insertion point and they should take the end-LSN as the LSN to stop > reading. > > I think pg_get_wal_stats() is worth to have but I think it should be > implemented in SQL. Currently pg_get_wal_records_info() doesn't tell > about FPI since pg_waldump doesn't but it is internally collected (of > course!) and easily revealed. If we do that, the > pg_get_wal_records_stats() would be reduced to the following SQL > statement > > SELECT resource_manager resmgr, > count(*) AS N, > (count(*) * 100 / sum(count(*)) OVER tot)::numeric(5,2) AS "%N", > sum(total_length) AS "combined size", > (sum(total_length) * 100 / sum(sum(total_length)) OVER tot)::numeric(5,2) AS "%combined size", > sum(fpi_len) AS fpilen, > (sum(fpi_len) * 100 / sum(sum(fpi_len)) OVER tot)::numeric(5,2) AS "%fpilen" > FROM pg_get_wal_records_info('0/1000000', '0/175DD7f') > GROUP by resource_manager > WINDOW tot AS () > ORDER BY "combined size" desc; > > The only difference with pg_waldump is the statement above doesn't > show lines for the resource managers that don't contained in the > result of pg_get_wal_records_info(). But I don't think that matters. > > > Sometimes the field description has very long (28kb long) content. It > makes the result output almost unreadable and I had a bit hard time > struggling with the output full of '-'s. I would like have a default > limit on the length of such fields that can be long but I'm not sure > we want that. > > - The difference between pg_get_wal_record_info and _records_ other than - the number of argument is the former accepts incorrect LSNs. The discussion is somewhat confused after some twists and turns.. It should be something like the following. pg_get_wal_record_info and pg_get_wal_records_info are almost same since the latter can show a single record. However it is a bit annoying to do that. Since, other than it doens't accept same LSNs for start and end, it doesn't show a record when there' no record in the specfied LSN range. But I don't think there's no usefulness of the behavior. The following works, pg_get_wal_record_info('0/1000000'); pg_get_wal_records_info('0/1000000'); but this doesn't pg_get_wal_records_info('0/1000000', '0/1000000'); > ERROR: WAL start LSN must be less than end LSN And the following shows no records. pg_get_wal_records_info('0/1000000', '0/1000001'); pg_get_wal_records_info('0/1000000', '0/1000028'); But the following works pg_get_wal_records_info('0/1000000', '0/1000029'); > 0/1000028 | 0/0 | 0 > So I think we can consolidate the two functions as: > > - pg_get_wal_records_info('0/1000000'); > > (current behavior) find the first record and show all records > thereafter. > > - pg_get_wal_records_info('0/1000000', '0/1000000'); > > finds the first record since the start lsn and show it. > > - pg_get_wal_records_info('0/1000000', '0/1000030'); > > finds the first record since the start lsn then show records up to > the end-lsn. > > > And about pg_get_raw_wal_record(). I don't see any use-case of the > function alone on SQL interface. Even if we need to inspect broken > WAL files, it needs profound knowledge of WAL format and tools that > doesn't work on SQL interface. > > However like pageinspect, if we separate the WAL-record fetching and > parsing it could be thought as useful. > > pg_get_wal_records_info woule be like: > > SELECT * FROM pg_walinspect_parse(raw) > FROM (SELECT * FROM pg_walinspect_get_raw(start_lsn, end_lsn)); > > And pg_get_wal_stats woule be like: > > SELECT * FROM pg_walinpect_stat(pg_walinspect_parse(raw)) > FROM (SELECT * FROM pg_walinspect_get_raw(start_lsn, end_lsn))); Regards. -- Kyotaro Horiguchi NTT Open Source Software Center