Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xFNxE-00000001fUF-1WfN for pgsql-hackers@arkaria.postgresql.org; Sat, 10 Oct 2026 03:41:00 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xFNxC-000000025bn-1weH for pgsql-hackers@arkaria.postgresql.org; Sat, 10 Oct 2026 03:40:58 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xFNxB-000000025be-0wbU for pgsql-hackers@lists.postgresql.org; Sat, 10 Oct 2026 03:40:57 +0000 Received: from mail-pj1-x1029.google.com ([2607:f8b0:4864:20::1029]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1xFNx8-00000001HAK-1RcS for pgsql-hackers@lists.postgresql.org; Sat, 10 Oct 2026 03:40:56 +0000 Received: by mail-pj1-x1029.google.com with SMTP id 98e67ed59e1d1-3ab33730821so153232a91.3 for ; Fri, 09 Oct 2026 20:40:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1791603653; x=1792208453; darn=lists.postgresql.org; h=references:to:cc:in-reply-to:date:subject:mime-version:content-type :message-id:from:from:to:cc:subject:date:message-id:reply-to :content-type; bh=ysImO+47Em1zouRFjrEdz/ltViaDx0GLjUmcz82JLKI=; b=NGZmwaewdEA0I9vb3YrdrLGN+bT8YysWwfdTw/pA61mulbIP5DNUQ+9ZgDK697bxI+ CZ8BEFK53wb9+gBSP+bHzU5jd2TwFmE1Y/jK0iXp8Rktj4QC8FxkTDJE7tIwCCM9jEXT HChJ79JLRbBrGN7Uq6+XTj7pWpY89uKz7nGaT8m8hqddtReABoLAiFxIRko7HfRCmoOj 92kmDOMJC04HQvIxVTDjLgiLdh8WT1pHftdjpk1g1l6ZGdTqXP2jkQ81uqcxx7pzJ3mv A4q036ZHl7irBmkY2VL0TBCM1aqDCaiN3SFYzcJoGaOexwHXCECMJqzxe89Jl1drChEd CrMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1791603653; x=1792208453; h=references:to:cc:in-reply-to:date:subject:mime-version:content-type :message-id:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=ysImO+47Em1zouRFjrEdz/ltViaDx0GLjUmcz82JLKI=; b=LxPjVCiIwUSeuWFWBanEtEppqUJop8ALlsMIPeZIDZw0Z9OsZs/A53IUMU5XiOKzSy 3PV5A1AiQxjRy+bypfNVgLg8KDvBysE66XcMoNjcN8Hr83CVcHKJ5B2U8SQRzca8x0xx czru/rWlLXeD2pgQ7MURQ+71Lf9dvkrZ+JgtVIiEpq+63+5JQF720V6QRc1l5XJycKC1 EzBAy03iSYbSvERA4YIW4KScnPhNNsEGGTli1wjn4Ec2jNxTtF3fy/RPb+ilqz7hsqZt xN9UWQwkrHajAaA1ys9aJbjcUbPRwHGTp7dODKUBLW5guOXA1Tc62dKF+WKYVEu4qEC1 Kidg== X-Gm-Message-State: AFq9FYLLDWTp7Ja1QOIYrmDEJY6Drx+flXXiyqVlYqq5oa3spVJRFoAo Jbny0sK/Uws7usHf3BlsRJKStyIaCuvASKQV9rm/RySJ8gDCPW0AFZ2Y X-Gm-Gg: AYBFou30B4AsZwPtM8blHKTmsFpYzsxdThifJbO2mr4L970bgdACB5Dad0tQQXVM5HB UKDGrGomr9+9hpLB7ow6UkuxHsg9L2BuDOArSVbMuPj/K/yDehFtkuGhHHznmQdnQJbiUQH6wL2 33/WQyZOkMSMX7H/c1tZ9wQ+QqBwiVT24LUfQ/MBfIXZIlPx20FCeBJfK0pNsPg1jf1MOO5j5Y3 KOJW7RPMhcUz0soikQBBdKIJn7f4gZJhlG5NEUNj2didoXhNkhUwsLuULO6jNM+0wz2A1KLtTb7 4isRW72m5YBoKIrAJ8Klqp6zKysdCsXP0LgEy/r691Y5kn4A6mdZYA78CJYkLvLIEnUoxoWyB7t WLBzhTcJjIePWiAe8rSud5MeWhjuopMF0MGC3RFDUOJu3a1J3ivfJtVqbN2m1V2sPPEAG+xUikG ZrqVYfAH+rIPcKStNpOHrMhoLS3aCaNa3vJf45IIysmPWA0Aynk1gursVQjKOqsHGn7gp/HiCPh LVAPsWBaslqpDzIvg== X-Received: by 2002:a17:90b:2b48:b0:3a8:1320:38b5 with SMTP id 98e67ed59e1d1-3ab3a747d7amr3123286a91.30.1791603652504; Fri, 09 Oct 2026 20:40:52 -0700 (PDT) Received: from smtpclient.apple ([185.135.79.125]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3ab3966dc7dsm3502866a91.2.2026.10.09.20.40.49 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 09 Oct 2026 20:40:51 -0700 (PDT) From: Chao Li Message-Id: Content-Type: multipart/mixed; boundary="Apple-Mail=_A1724A3D-C5C8-4ED1-AE94-3480FD42F6C1" Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3864.700.51.1.1\)) Subject: Re: pg_walinspect: add functions to locate and list WAL by time and LSN Date: Sat, 10 Oct 2026 11:40:15 +0800 In-Reply-To: Cc: PostgreSQL Hackers To: surya poondla References: <80E9F0AD-CFC5-4BE5-81DE-D8FE35E10A1C@gmail.com> <654C6555-A407-45DD-B329-5197BBF89347@gmail.com> <863CC649-43A8-4C68-A633-52583B75E490@gmail.com> X-Mailer: Apple Mail (2.3864.700.51.1.1) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --Apple-Mail=_A1724A3D-C5C8-4ED1-AE94-3480FD42F6C1 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii > On Oct 10, 2026, at 07:18, surya poondla = wrote: >=20 > Hi Chao, >=20 > Thanks for v4. The test fix and the doc sentence look good, and CFBot = is green now, including macOS. Thank you very much for the follow up reviewing. >=20 > I did a full read-through of v4, especially the boundary logic in = 0002. > The binary search, the outer anchors, the extra segment scanned on = each side, and the fallback to the current WAL position all look correct = to > me. The tie-breaks and the neighbour scan only ever widen the range, = which is the safe direction. Cool! >=20 > I have a few small comments: > 1. pg_get_wal_records_info(start_lsn, end_lsn) includes the = start-anchor record but not the end-anchor one. > end_lsn is the start LSN of the end-anchor record, and = pg_get_wal_records_info() only returns records that end at or before > end_lsn. So if the transaction of interest committed just after the = window, its COMMIT can be the end anchor, the user sees its changes but > not its commit, and might conclude it never committed. I wouldn't = change end_lsn, since pointing pg_get_wal_record_info() at it to see the = anchor > is useful, but a sentence in the docs would help. (This only applies = when an end anchor is found, not when end_lsn falls back to the current = WAL position.) >=20 This is a good point. Since the requested time range is likely to be = only a rough estimate, users may generally be more interested in the = surrounding WAL than in the exact endpoint. But I agree that this can = sometimes matter. I considered changing end_lsn to the end-anchor record's ending LSN, but = then pg_get_wal_record_info(end_lsn) could no longer be used to inspect = the end-anchor record directly. Therefore, I added a tip to the doc = explaining this situation and how to include the end-anchor record. > 2. The docs say "Unlike the other pg_walinspect functions, this = function may inspect retained WAL from the current timeline's history as = well as > the current timeline." I don't think that's accurate. The existing = functions read through read_local_xlog_page_no_wait(), and > XLogReadDetermineTimeline() already follows the timeline history, = choosing each segment's timeline with tliOfPointInHistory(), the same > rule GetWalTimeSegments() uses. I'd drop the sentence. Agreed. >=20 > 3. Nit: "No retained WAL segment contains a timestamped record" is > reported with ERRCODE_INVALID_PARAMETER_VALUE, but nothing is wrong = with > the arguments. ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE, which the = patch > already uses for "no retained WAL segments are available", seems a = better fit. Agreed. >=20 > With these addressed, I think the patch is ready for committer. >=20 > Regards, > Surya Poondla PFA v5: 0001 unchanged; 0002 addressed the new comments. Best regards, -- Chao Li (Evan) HighGo Software Co., Ltd. https://www.highgo.com/ --Apple-Mail=_A1724A3D-C5C8-4ED1-AE94-3480FD42F6C1 Content-Disposition: attachment; filename=v5-0001-pg_walinspect-add-function-to-list-WAL-files-by-L.patch Content-Type: application/octet-stream; x-unix-mode=0644; name="v5-0001-pg_walinspect-add-function-to-list-WAL-files-by-L.patch" Content-Transfer-Encoding: quoted-printable =46rom=20d03866d3efb5a54bfe9f1c95233a638a97dc78e3=20Mon=20Sep=2017=20= 00:00:00=202001=0AFrom:=20"Chao=20Li=20(Evan)"=20=0A= Date:=20Thu,=201=20Oct=202026=2006:52:59=20+0800=0ASubject:=20[PATCH=20= v5=201/2]=20pg_walinspect:=20add=20function=20to=20list=20WAL=20files=20= by=20LSN=0A=0AAdd=20pg_get_wal_files(),=20which=20returns=20the=20= retained=20WAL=20segment=20files=0Aintersecting=20an=20LSN=20range,=20= together=20with=20each=20segment's=20complete=20LSN=0Aboundaries.=20A=20= point=20lookup=20can=20be=20requested=20by=20omitting=20end_lsn=20or=0A= making=20it=20equal=20to=20start_lsn.=0A=0AChoose=20segment=20file=20= names=20from=20the=20server's=20current=20timeline=20history=0Aso=20that=20= ranges=20spanning=20a=20timeline=20switch=20are=20handled=20correctly.=0A= =0AAuthor:=20Chao=20Li=20=0AReviewed-by:=20Surya=20= Poondla=20=0ADiscussion:=20= https://postgr.es/m/80E9F0AD-CFC5-4BE5-81DE-D8FE35E10A1C@gmail.com=0A---=0A= =20contrib/pg_walinspect/Makefile=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20|=20=20=204=20+-=0A=20= .../pg_walinspect/expected/oldextversions.out=20|=20=20=208=20+-=0A=20= .../pg_walinspect/expected/pg_walinspect.out=20=20|=20=2073=20++++++=0A=20= contrib/pg_walinspect/meson.build=20=20=20=20=20=20=20=20=20=20=20=20=20= |=20=20=206=20+=0A=20.../pg_walinspect/pg_walinspect--1.1--1.2.sql=20|=20= =2022=20++=0A=20contrib/pg_walinspect/pg_walinspect.c=20=20=20=20=20=20=20= =20=20|=20219=20+++++++++++++++++-=0A=20= contrib/pg_walinspect/pg_walinspect.control=20=20=20|=20=20=202=20+-=0A=20= contrib/pg_walinspect/sql/oldextversions.sql=20=20|=20=20=205=20+-=0A=20= contrib/pg_walinspect/sql/pg_walinspect.sql=20=20=20|=20=2034=20+++=0A=20= contrib/pg_walinspect/t/001_timeline.pl=20=20=20=20=20=20=20|=20=2074=20= ++++++=0A=20doc/src/sgml/pgwalinspect.sgml=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20|=20=2041=20+++-=0A=20src/tools/pgindent/typedefs.list=20=20= =20=20=20=20=20=20=20=20=20=20=20=20|=20=20=201=20+=0A=2012=20files=20= changed,=20470=20insertions(+),=2019=20deletions(-)=0A=20create=20mode=20= 100644=20contrib/pg_walinspect/pg_walinspect--1.1--1.2.sql=0A=20create=20= mode=20100644=20contrib/pg_walinspect/t/001_timeline.pl=0A=0Adiff=20= --git=20a/contrib/pg_walinspect/Makefile=20= b/contrib/pg_walinspect/Makefile=0Aindex=2022090f7716c..b7651231077=20= 100644=0A---=20a/contrib/pg_walinspect/Makefile=0A+++=20= b/contrib/pg_walinspect/Makefile=0A@@=20-7,9=20+7,11=20@@=20OBJS=20=3D=20= \=0A=20PGFILEDESC=20=3D=20"pg_walinspect=20-=20functions=20to=20inspect=20= contents=20of=20PostgreSQL=20Write-Ahead=20Log"=0A=20=0A=20EXTENSION=20=3D= =20pg_walinspect=0A-DATA=20=3D=20pg_walinspect--1.0.sql=20= pg_walinspect--1.0--1.1.sql=0A+DATA=20=3D=20pg_walinspect--1.0.sql=20= pg_walinspect--1.0--1.1.sql=20\=0A+=09pg_walinspect--1.1--1.2.sql=0A=20=0A= =20REGRESS=20=3D=20pg_walinspect=20oldextversions=0A+TAP_TESTS=20=3D=201=0A= =20=0A=20REGRESS_OPTS=20=3D=20--temp-config=20= $(top_srcdir)/contrib/pg_walinspect/walinspect.conf=0A=20=0Adiff=20--git=20= a/contrib/pg_walinspect/expected/oldextversions.out=20= b/contrib/pg_walinspect/expected/oldextversions.out=0Aindex=20= 89953af3d0e..311017d66ca=20100644=0A---=20= a/contrib/pg_walinspect/expected/oldextversions.out=0A+++=20= b/contrib/pg_walinspect/expected/oldextversions.out=0A@@=20-46,18=20= +46,20=20@@=20SELECT=20*=20FROM=20= pg_get_wal_records_info_till_end_of_wal('FFFFFFFF/FFFFFFFF');=0A=20= ERROR:=20=20WAL=20start=20LSN=20must=20be=20less=20than=20current=20LSN=0A= =20SELECT=20*=20FROM=20= pg_get_wal_stats_till_end_of_wal('FFFFFFFF/FFFFFFFF');=0A=20ERROR:=20=20= WAL=20start=20LSN=20must=20be=20less=20than=20current=20LSN=0A---=20Move=20= to=20new=20version=201.1.=0A+--=20Test=20each=20upgrade=20step=20through=20= the=20current=20version.=0A=20ALTER=20EXTENSION=20pg_walinspect=20UPDATE=20= TO=20'1.1';=0A---=20List=20what=20version=201.1=20contains.=0A+ALTER=20= EXTENSION=20pg_walinspect=20UPDATE=20TO=20'1.2';=0A+--=20List=20what=20= the=20current=20version=20contains.=0A=20\dx+=20pg_walinspect=0A=20=20=20= =20=20=20=20=20=20=20Objects=20in=20extension=20"pg_walinspect"=0A=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20Object=20description=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=0A=20= -------------------------------------------------------=0A=20=20function=20= pg_get_wal_block_info(pg_lsn,pg_lsn,boolean)=0A+=20function=20= pg_get_wal_files(pg_lsn,pg_lsn)=0A=20=20function=20= pg_get_wal_record_info(pg_lsn)=0A=20=20function=20= pg_get_wal_records_info(pg_lsn,pg_lsn)=0A=20=20function=20= pg_get_wal_stats(pg_lsn,pg_lsn,boolean)=0A-(4=20rows)=0A+(5=20rows)=0A=20= =0A=20SELECT=20pg_drop_replication_slot('regress_pg_walinspect_slot');=0A= =20=20pg_drop_replication_slot=20=0Adiff=20--git=20= a/contrib/pg_walinspect/expected/pg_walinspect.out=20= b/contrib/pg_walinspect/expected/pg_walinspect.out=0Aindex=20= f955ff5d3c5..34864c65ec7=20100644=0A---=20= a/contrib/pg_walinspect/expected/pg_walinspect.out=0A+++=20= b/contrib/pg_walinspect/expected/pg_walinspect.out=0A@@=20-90,6=20+90,54=20= @@=20SELECT=20COUNT(*)=20>=3D=201=20AS=20ok=20FROM=20= pg_get_wal_block_info(:'wal_lsn1',=20:'wal_lsn2');=0A=20=20t=0A=20(1=20= row)=0A=20=0A+--=20Return=20the=20retained=20WAL=20file=20and=20its=20= complete=20segment=20boundaries.=0A+SELECT=20wal_file=20=3D=20= pg_walfile_name(segment_start_lsn)=20AS=20file_ok,=0A+=20=20=20=20=20=20=20= segment_start_lsn=20<=3D=20:'wal_lsn1'::pg_lsn=20AS=20start_ok,=0A+=20=20= =20=20=20=20=20segment_end_lsn=20>=20:'wal_lsn1'::pg_lsn=20AS=20end_ok=0A= +FROM=20pg_get_wal_files(:'wal_lsn1',=20:'wal_lsn1'::pg_lsn=20+=201);=0A= +=20file_ok=20|=20start_ok=20|=20end_ok=20=0A= +---------+----------+--------=0A+=20t=20=20=20=20=20=20=20|=20t=20=20=20= =20=20=20=20=20|=20t=0A+(1=20row)=0A+=0A+--=20An=20end=20LSN=20at=20a=20= segment=20boundary=20must=20not=20include=20the=20next=20segment.=0A= +WITH=20segment=20AS=0A+(=0A+=20=20SELECT=20*=20FROM=20= pg_get_wal_files(:'wal_lsn1',=20:'wal_lsn1'::pg_lsn=20+=201)=0A+)=0A= +SELECT=20count(*)=20=3D=201=20AS=20one_file=0A+FROM=20segment,=0A+=20=20= =20=20=20LATERAL=20pg_get_wal_files(segment_start_lsn,=20= segment_end_lsn);=0A+=20one_file=20=0A+----------=0A+=20t=0A+(1=20row)=0A= +=0A+SELECT=20count(*)=20=3D=201=20AS=20equal_lsn_ok=0A+FROM=20= pg_get_wal_files(:'wal_lsn1',=20:'wal_lsn1');=0A+=20equal_lsn_ok=20=0A= +--------------=0A+=20t=0A+(1=20row)=0A+=0A+SELECT=20count(*)=20=3D=201=20= AS=20default_end_ok=0A+FROM=20pg_get_wal_files(:'wal_lsn1');=0A+=20= default_end_ok=20=0A+----------------=0A+=20t=0A+(1=20row)=0A+=0A+SELECT=20= *=20FROM=20pg_get_wal_files(:'wal_lsn1'::pg_lsn=20+=201,=20:'wal_lsn1');=0A= +ERROR:=20=20WAL=20start=20LSN=20must=20be=20less=20than=20end=20LSN=0A= +SELECT=20count(*)=20=3D=201=20AS=20future_end_ok=0A+FROM=20= pg_get_wal_files(pg_current_wal_lsn(),=20'FFFFFFFF/FFFFFFFF');=0A+=20= future_end_ok=20=0A+---------------=0A+=20t=0A+(1=20row)=0A+=0A+SELECT=20= *=20FROM=20pg_get_wal_files('0/0',=20'0/1');=0A+ERROR:=20=20could=20not=20= read=20WAL=20at=20LSN=200/00000000=0A=20--=20= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A=20--=20Test=20for=20= filtering=20out=20WAL=20records=20of=20a=20particular=20table=0A=20--=20= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A@@=20-183,6=20= +231,13=20@@=20SELECT=20has_function_privilege('regress_pg_walinspect',=0A= =20=20f=0A=20(1=20row)=0A=20=0A+SELECT=20= has_function_privilege('regress_pg_walinspect',=0A+=20=20= 'pg_get_wal_files(pg_lsn,=20pg_lsn)',=20'EXECUTE');=20--=20no=0A+=20= has_function_privilege=20=0A+------------------------=0A+=20f=0A+(1=20= row)=0A+=0A=20--=20Functions=20accessible=20by=20users=20with=20role=20= pg_read_server_files.=0A=20GRANT=20pg_read_server_files=20TO=20= regress_pg_walinspect;=0A=20SELECT=20= has_function_privilege('regress_pg_walinspect',=0A@@=20-213,6=20+268,13=20= @@=20SELECT=20has_function_privilege('regress_pg_walinspect',=0A=20=20t=0A= =20(1=20row)=0A=20=0A+SELECT=20= has_function_privilege('regress_pg_walinspect',=0A+=20=20= 'pg_get_wal_files(pg_lsn,=20pg_lsn)',=20'EXECUTE');=20--=20yes=0A+=20= has_function_privilege=20=0A+------------------------=0A+=20t=0A+(1=20= row)=0A+=0A=20REVOKE=20pg_read_server_files=20FROM=20= regress_pg_walinspect;=0A=20--=20Superuser=20can=20grant=20execute=20to=20= other=20users.=0A=20GRANT=20EXECUTE=20ON=20FUNCTION=20= pg_get_wal_record_info(pg_lsn)=0A@@=20-223,6=20+285,8=20@@=20GRANT=20= EXECUTE=20ON=20FUNCTION=20pg_get_wal_stats(pg_lsn,=20pg_lsn,=20boolean)=0A= =20=20=20TO=20regress_pg_walinspect;=0A=20GRANT=20EXECUTE=20ON=20= FUNCTION=20pg_get_wal_block_info(pg_lsn,=20pg_lsn,=20boolean)=0A=20=20=20= TO=20regress_pg_walinspect;=0A+GRANT=20EXECUTE=20ON=20FUNCTION=20= pg_get_wal_files(pg_lsn,=20pg_lsn)=0A+=20=20TO=20regress_pg_walinspect;=0A= =20SELECT=20has_function_privilege('regress_pg_walinspect',=0A=20=20=20= 'pg_get_wal_record_info(pg_lsn)',=20'EXECUTE');=20--=20yes=0A=20=20= has_function_privilege=20=0A@@=20-251,6=20+315,13=20@@=20SELECT=20= has_function_privilege('regress_pg_walinspect',=0A=20=20t=0A=20(1=20row)=0A= =20=0A+SELECT=20has_function_privilege('regress_pg_walinspect',=0A+=20=20= 'pg_get_wal_files(pg_lsn,=20pg_lsn)',=20'EXECUTE');=20--=20yes=0A+=20= has_function_privilege=20=0A+------------------------=0A+=20t=0A+(1=20= row)=0A+=0A=20REVOKE=20EXECUTE=20ON=20FUNCTION=20= pg_get_wal_record_info(pg_lsn)=0A=20=20=20FROM=20regress_pg_walinspect;=0A= =20REVOKE=20EXECUTE=20ON=20FUNCTION=20pg_get_wal_records_info(pg_lsn,=20= pg_lsn)=0A@@=20-259,6=20+330,8=20@@=20REVOKE=20EXECUTE=20ON=20FUNCTION=20= pg_get_wal_stats(pg_lsn,=20pg_lsn,=20boolean)=0A=20=20=20FROM=20= regress_pg_walinspect;=0A=20REVOKE=20EXECUTE=20ON=20FUNCTION=20= pg_get_wal_block_info(pg_lsn,=20pg_lsn,=20boolean)=0A=20=20=20FROM=20= regress_pg_walinspect;=0A+REVOKE=20EXECUTE=20ON=20FUNCTION=20= pg_get_wal_files(pg_lsn,=20pg_lsn)=0A+=20=20FROM=20= regress_pg_walinspect;=0A=20--=20= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A=20--=20Clean=20up=0A= =20--=20= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0Adiff=20--git=20= a/contrib/pg_walinspect/meson.build=20= b/contrib/pg_walinspect/meson.build=0Aindex=2082ab186c340..6f8b4a6359a=20= 100644=0A---=20a/contrib/pg_walinspect/meson.build=0A+++=20= b/contrib/pg_walinspect/meson.build=0A@@=20-20,6=20+20,7=20@@=20= install_data(=0A=20=20=20'pg_walinspect.control',=0A=20=20=20= 'pg_walinspect--1.0.sql',=0A=20=20=20'pg_walinspect--1.0--1.1.sql',=0A+=20= =20'pg_walinspect--1.1--1.2.sql',=0A=20=20=20kwargs:=20= contrib_data_args,=0A=20)=0A=20=0A@@=20-37,4=20+38,9=20@@=20tests=20+=3D=20= {=0A=20=20=20=20=20'regress_args':=20['--temp-config',=20= files('walinspect.conf')],=0A=20=20=20=20=20'runningcheck':=20false,=0A=20= =20=20},=0A+=20=20'tap':=20{=0A+=20=20=20=20'tests':=20[=0A+=20=20=20=20=20= =20't/001_timeline.pl',=0A+=20=20=20=20],=0A+=20=20},=0A=20}=0Adiff=20= --git=20a/contrib/pg_walinspect/pg_walinspect--1.1--1.2.sql=20= b/contrib/pg_walinspect/pg_walinspect--1.1--1.2.sql=0Anew=20file=20mode=20= 100644=0Aindex=2000000000000..9cc9523b4dc=0A---=20/dev/null=0A+++=20= b/contrib/pg_walinspect/pg_walinspect--1.1--1.2.sql=0A@@=20-0,0=20+1,22=20= @@=0A+/*=20contrib/pg_walinspect/pg_walinspect--1.1--1.2.sql=20*/=0A+=0A= +--=20complain=20if=20script=20is=20sourced=20in=20psql,=20rather=20than=20= via=20ALTER=20EXTENSION=0A+\echo=20Use=20"ALTER=20EXTENSION=20= pg_walinspect=20UPDATE=20TO=20'1.2'"=20to=20load=20this=20file.=20\quit=0A= +=0A+--=0A+--=20pg_get_wal_files()=0A+--=0A+CREATE=20FUNCTION=20= pg_get_wal_files(=0A+=20=20=20=20IN=20start_lsn=20pg_lsn,=0A+=20=20=20=20= IN=20end_lsn=20pg_lsn=20DEFAULT=20NULL,=0A+=20=20=20=20OUT=20wal_file=20= text,=0A+=20=20=20=20OUT=20segment_start_lsn=20pg_lsn,=0A+=20=20=20=20= OUT=20segment_end_lsn=20pg_lsn=0A+)=0A+RETURNS=20SETOF=20record=0A+AS=20= 'MODULE_PATHNAME',=20'pg_get_wal_files'=0A+LANGUAGE=20C=20PARALLEL=20= SAFE;=0A+=0A+REVOKE=20EXECUTE=20ON=20FUNCTION=20pg_get_wal_files(pg_lsn,=20= pg_lsn)=20FROM=20PUBLIC;=0A+GRANT=20EXECUTE=20ON=20FUNCTION=20= pg_get_wal_files(pg_lsn,=20pg_lsn)=0A+=20=20TO=20pg_read_server_files;=0A= diff=20--git=20a/contrib/pg_walinspect/pg_walinspect.c=20= b/contrib/pg_walinspect/pg_walinspect.c=0Aindex=20= a172f9e2b40..85d76fe37c4=20100644=0A---=20= a/contrib/pg_walinspect/pg_walinspect.c=0A+++=20= b/contrib/pg_walinspect/pg_walinspect.c=0A@@=20-13,6=20+13,7=20@@=0A=20= #include=20"postgres.h"=0A=20=0A=20#include=20"access/htup_details.h"=0A= +#include=20"access/timeline.h"=0A=20#include=20"access/xlog.h"=0A=20= #include=20"access/xlog_internal.h"=0A=20#include=20= "access/xlogreader.h"=0A@@=20-22,6=20+23,7=20@@=0A=20#include=20= "funcapi.h"=0A=20#include=20"miscadmin.h"=0A=20#include=20= "port/pg_bitutils.h"=0A+#include=20"storage/fd.h"=0A=20#include=20= "utils/array.h"=0A=20#include=20"utils/builtins.h"=0A=20#include=20= "utils/pg_lsn.h"=0A@@=20-38,6=20+40,7=20@@=20PG_MODULE_MAGIC_EXT(=0A=20= );=0A=20=0A=20PG_FUNCTION_INFO_V1(pg_get_wal_block_info);=0A= +PG_FUNCTION_INFO_V1(pg_get_wal_files);=0A=20= PG_FUNCTION_INFO_V1(pg_get_wal_record_info);=0A=20= PG_FUNCTION_INFO_V1(pg_get_wal_records_info);=0A=20= PG_FUNCTION_INFO_V1(pg_get_wal_records_info_till_end_of_wal);=0A@@=20= -45,7=20+48,7=20@@=20PG_FUNCTION_INFO_V1(pg_get_wal_stats);=0A=20= PG_FUNCTION_INFO_V1(pg_get_wal_stats_till_end_of_wal);=0A=20=0A=20static=20= void=20ValidateInputLSNs(XLogRecPtr=20start_lsn,=20XLogRecPtr=20= *end_lsn);=0A-static=20XLogRecPtr=20GetCurrentLSN(void);=0A+static=20= XLogRecPtr=20GetCurrentLSN(TimeLineID=20*current_tli);=0A=20static=20= XLogReaderState=20*InitXLogReaderState(XLogRecPtr=20lsn);=0A=20static=20= XLogRecord=20*ReadNextXLogRecord(XLogReaderState=20*xlogreader);=0A=20= static=20void=20GetWALRecordInfo(XLogReaderState=20*record,=20Datum=20= *values,=0A@@=20-68,11=20+71,21=20@@=20static=20void=20= GetWalStats(FunctionCallInfo=20fcinfo,=0A=20static=20void=20= GetWALBlockInfo(FunctionCallInfo=20fcinfo,=20XLogReaderState=20*record,=0A= =20=09=09=09=09=09=09=09bool=20show_data);=0A=20=0A+/*=20Metadata=20for=20= one=20retained=20segment=20in=20the=20current=20timeline's=20history.=20= */=0A+typedef=20struct=20WalTimeSegment=0A+{=0A+=09XLogSegNo=09segno;=09=09= =09/*=20segment=20number,=20used=20for=20WAL=20ordering=20*/=0A+=09= TimeLineID=09tli;=09=09=09/*=20timeline=20containing=20this=20segment=20= */=0A+}=20WalTimeSegment;=0A+=0A+static=20int=09= wal_time_segment_cmp(const=20void=20*a,=20const=20void=20*b);=0A+static=20= WalTimeSegment=20*GetWalTimeSegments(int=20*nsegments);=0A+=0A=20/*=0A-=20= *=20Return=20the=20LSN=20up=20to=20which=20the=20server=20has=20WAL.=0A+=20= *=20Return=20the=20LSN=20up=20to=20which=20the=20server=20has=20WAL,=20= and=20optionally=20its=20timeline.=0A=20=20*/=0A=20static=20XLogRecPtr=0A= -GetCurrentLSN(void)=0A+GetCurrentLSN(TimeLineID=20*current_tli)=0A=20{=0A= =20=09XLogRecPtr=09curr_lsn;=0A=20=0A@@=20-81,9=20+94,15=20@@=20= GetCurrentLSN(void)=0A=20=09=20*=20callback=20= read_local_xlog_page_no_wait=20does.=0A=20=09=20*/=0A=20=09if=20= (!RecoveryInProgress())=0A-=09=09curr_lsn=20=3D=20GetFlushRecPtr(NULL);=0A= +=09=09curr_lsn=20=3D=20GetFlushRecPtr(current_tli);=0A=20=09else=0A-=09=09= curr_lsn=20=3D=20GetXLogReplayRecPtr(NULL);=0A+=09{=0A+=09=09curr_lsn=20= =3D=20GetXLogReplayRecPtr(current_tli);=0A+=09=09if=20(current_tli=20!=3D=20= NULL=20&&=20*current_tli=20=3D=3D=200)=0A+=09=09{=0A+=09=09=09= *current_tli=20=3D=20GetWALInsertionTimeLineIfSet();=0A+=09=09}=0A+=09}=0A= =20=0A=20=09Assert(XLogRecPtrIsValid(curr_lsn));=0A=20=0A@@=20-190,6=20= +209,94=20@@=20ReadNextXLogRecord(XLogReaderState=20*xlogreader)=0A=20=09= return=20record;=0A=20}=0A=20=0A+/*=20qsort=20comparator=20that=20puts=20= segments=20in=20WAL=20order.=20*/=0A+static=20int=0A= +wal_time_segment_cmp(const=20void=20*a,=20const=20void=20*b)=0A+{=0A+=09= const=20WalTimeSegment=20*seg1=20=3D=20(const=20WalTimeSegment=20*)=20a;=0A= +=09const=20WalTimeSegment=20*seg2=20=3D=20(const=20WalTimeSegment=20*)=20= b;=0A+=0A+=09if=20(seg1->segno=20<=20seg2->segno)=0A+=09=09return=20-1;=0A= +=09if=20(seg1->segno=20>=20seg2->segno)=0A+=09=09return=201;=0A+=09= return=200;=0A+}=0A+=0A+/*=0A+=20*=20Get=20the=20WAL=20segments=20that=20= form=20the=20history=20of=20the=20server's=20current=0A+=20*=20timeline.=20= =20Other=20timelines=20may=20have=20files=20with=20the=20same=20segment=20= number=20in=0A+=20*=20pg_wal,=20so=20choose=20the=20timeline=20that=20is=20= valid=20at=20the=20end=20of=20each=20segment,=0A+=20*=20as=20= read_local_xlog_page_no_wait()=20does.=20=20Return=20the=20segments=20in=20= WAL=20order.=0A+=20*/=0A+static=20WalTimeSegment=20*=0A= +GetWalTimeSegments(int=20*nsegments)=0A+{=0A+=09WalTimeSegment=20= *segments=20=3D=20NULL;=0A+=09DIR=09=09=20=20=20*dir;=0A+=09struct=20= dirent=20*de;=0A+=09List=09=20=20=20*history;=0A+=09XLogRecPtr=09= current_lsn;=0A+=09TimeLineID=09current_tli;=0A+=09int=09=09=09allocated=20= =3D=200;=0A+=09int=09=09=09count=20=3D=200;=0A+=0A+=09current_lsn=20=3D=20= GetCurrentLSN(¤t_tli);=0A+=0A+=09history=20=3D=20= readTimeLineHistory(current_tli);=0A+=09dir=20=3D=20= AllocateDir(XLOGDIR);=0A+=09while=20((de=20=3D=20ReadDir(dir,=20= XLOGDIR))=20!=3D=20NULL)=0A+=09{=0A+=09=09TimeLineID=09file_tli;=0A+=09=09= XLogSegNo=09segno;=0A+=09=09XLogRecPtr=09seg_start;=0A+=09=09XLogRecPtr=09= seg_end;=0A+=0A+=09=09if=20(!IsXLogFileName(de->d_name))=0A+=09=09=09= continue;=0A+=0A+=09=09XLogFromFileName(de->d_name,=20&file_tli,=20= &segno,=20wal_segment_size);=0A+=09=09seg_start=20=3D=20segno=20*=20= wal_segment_size;=0A+=09=09seg_end=20=3D=20seg_start=20+=20= wal_segment_size=20-=201;=0A+=0A+=09=09if=20(seg_start=20>=3D=20= current_lsn=20||=0A+=09=09=09file_tli=20!=3D=20= tliOfPointInHistory(seg_end,=20history))=0A+=09=09=09continue;=0A+=0A+=09= =09if=20(count=20=3D=3D=20allocated)=0A+=09=09{=0A+=09=09=09allocated=20= =3D=20allocated=20?=20allocated=20*=202=20:=2016;=0A+=09=09=09if=20= (segments=20=3D=3D=20NULL)=0A+=09=09=09=09segments=20=3D=20= palloc_array(WalTimeSegment,=20allocated);=0A+=09=09=09else=0A+=09=09=09=09= segments=20=3D=20repalloc_array(segments,=20WalTimeSegment,=20= allocated);=0A+=09=09}=0A+=0A+=09=09MemSet(&segments[count],=200,=20= sizeof(WalTimeSegment));=0A+=09=09segments[count].segno=20=3D=20segno;=0A= +=09=09segments[count].tli=20=3D=20file_tli;=0A+=09=09count++;=0A+=09}=0A= +=09FreeDir(dir);=0A+=09list_free_deep(history);=0A+=0A+=09if=20(count=20= =3D=3D=200)=0A+=09=09ereport(ERROR,=0A+=09=09=09=09= errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),=0A+=09=09=09=09= errmsg("no=20retained=20WAL=20segments=20are=20available"));=0A+=0A+=09= qsort(segments,=20count,=20sizeof(WalTimeSegment),=20= wal_time_segment_cmp);=0A+=0A+#ifdef=20USE_ASSERT_CHECKING=0A+=09/*=20A=20= segment=20number=20identifies=20at=20most=20one=20file=20in=20this=20= timeline=20history.=20*/=0A+=09for=20(int=20i=20=3D=201;=20i=20<=20= count;=20i++)=0A+=09=09Assert(segments[i=20-=201].segno=20!=3D=20= segments[i].segno);=0A+#endif=0A+=0A+=09*nsegments=20=3D=20count;=0A+=09= return=20segments;=0A+}=0A+=0A=20/*=0A=20=20*=20Output=20values=20that=20= make=20up=20a=20row=20describing=20caller's=20WAL=20record.=0A=20=20*=0A= @@=20-483,7=20+590,7=20@@=20pg_get_wal_record_info(PG_FUNCTION_ARGS)=0A=20= =09HeapTuple=09tuple;=0A=20=0A=20=09lsn=20=3D=20PG_GETARG_LSN(0);=0A-=09= curr_lsn=20=3D=20GetCurrentLSN();=0A+=09curr_lsn=20=3D=20= GetCurrentLSN(NULL);=0A=20=0A=20=09if=20(lsn=20>=20curr_lsn)=0A=20=09=09= ereport(ERROR,=0A@@=20-516,6=20+623,100=20@@=20= pg_get_wal_record_info(PG_FUNCTION_ARGS)=0A=20#undef=20= PG_GET_WAL_RECORD_INFO_COLS=0A=20}=0A=20=0A+/*=0A+=20*=20List=20the=20= retained=20WAL=20segment=20files=20intersecting=20[start_lsn,=20= end_lsn),=20or=0A+=20*=20the=20segment=20containing=20start_lsn=20when=20= end_lsn=20is=20omitted=20or=20equal=20to=20it.=0A+=20*=20Report=20= complete=20segment=20boundaries,=20not=20the=20range=20clipped=20to=20= the=20inputs.=0A+=20*/=0A+Datum=0A+pg_get_wal_files(PG_FUNCTION_ARGS)=0A= +{=0A+#define=20PG_GET_WAL_FILES_COLS=203=0A+=09XLogRecPtr=09start_lsn;=0A= +=09XLogRecPtr=09end_lsn;=0A+=09XLogRecPtr=09current_lsn;=0A+=09= XLogSegNo=09first_segno;=0A+=09XLogSegNo=09last_segno;=0A+=09bool=09=09= point_lookup;=0A+=09WalTimeSegment=20*segments;=0A+=09ReturnSetInfo=20= *rsinfo=20=3D=20(ReturnSetInfo=20*)=20fcinfo->resultinfo;=0A+=09int=09=09= =09nsegments;=0A+=09int=09=09=09segment_index=20=3D=200;=0A+=0A+=09= InitMaterializedSRF(fcinfo,=200);=0A+=0A+=09/*=20A=20NULL=20start=20= produces=20an=20empty=20set.=20*/=0A+=09if=20(PG_ARGISNULL(0))=0A+=09=09= PG_RETURN_VOID();=0A+=0A+=09start_lsn=20=3D=20PG_GETARG_LSN(0);=0A+=09= end_lsn=20=3D=20PG_ARGISNULL(1)=20?=20start_lsn=20:=20PG_GETARG_LSN(1);=0A= +=0A+=09if=20(start_lsn=20<=20XLOG_BLCKSZ)=0A+=09=09ereport(ERROR,=0A+=09= =09=09=09errcode(ERRCODE_INVALID_PARAMETER_VALUE),=0A+=09=09=09=09= errmsg("could=20not=20read=20WAL=20at=20LSN=20%X/%08X",=0A+=09=09=09=09=09= =20=20=20LSN_FORMAT_ARGS(start_lsn)));=0A+=0A+=09= ValidateInputLSNs(start_lsn,=20&end_lsn);=0A+=09point_lookup=20=3D=20= start_lsn=20=3D=3D=20end_lsn;=0A+=09current_lsn=20=3D=20= GetCurrentLSN(NULL);=0A+=0A+=09/*=0A+=09=20*=20At=20a=20segment=20= boundary,=20the=20current=20LSN=20can=20point=20just=20past=20the=20last=0A= +=09=20*=20retained=20WAL=20byte,=20before=20the=20next=20segment=20file=20= has=20been=20created.=20=20In=0A+=09=20*=20that=20case,=20return=20the=20= preceding=20segment=20containing=20the=20available=20WAL.=0A+=09=20*/=0A= +=09if=20(point_lookup=20&&=20start_lsn=20=3D=3D=20current_lsn=20&&=0A+=09= =09XLogSegmentOffset(start_lsn,=20wal_segment_size)=20=3D=3D=200)=0A+=09=09= XLByteToPrevSeg(start_lsn,=20first_segno,=20wal_segment_size);=0A+=09= else=0A+=09=09XLByteToSeg(start_lsn,=20first_segno,=20wal_segment_size);=0A= +=09if=20(point_lookup)=0A+=09=09last_segno=20=3D=20first_segno;=0A+=09= else=0A+=09=09XLByteToPrevSeg(end_lsn,=20last_segno,=20= wal_segment_size);=0A+=09segments=20=3D=20= GetWalTimeSegments(&nsegments);=0A+=0A+=09for=20(XLogSegNo=20segno=20=3D=20= first_segno;;=20segno++)=0A+=09{=0A+=09=09Datum=09=09= values[PG_GET_WAL_FILES_COLS];=0A+=09=09bool=09=09= nulls[PG_GET_WAL_FILES_COLS]=20=3D=20{0};=0A+=09=09XLogRecPtr=09= segment_start_lsn=20=3D=20segno=20*=20wal_segment_size;=0A+=09=09= XLogRecPtr=09segment_end_lsn=20=3D=20segment_start_lsn=20+=20= wal_segment_size;=0A+=09=09char=09=09fname[MAXFNAMELEN];=0A+=0A+=09=09= while=20(segment_index=20<=20nsegments=20&&=0A+=09=09=09=20=20=20= segments[segment_index].segno=20<=20segno)=0A+=09=09=09segment_index++;=0A= +=0A+=09=09if=20(segment_index=20>=3D=20nsegments=20||=0A+=09=09=09= segments[segment_index].segno=20!=3D=20segno)=0A+=09=09=09ereport(ERROR,=0A= +=09=09=09=09=09errcode(ERRCODE_DATA_EXCEPTION),=0A+=09=09=09=09=09= errmsg("WAL=20segment=20needed=20for=20the=20requested=20range=20is=20= missing"),=0A+=09=09=09=09=09errdetail("Segment=20"=20UINT64_FORMAT=20"=20= is=20not=20present=20in=20pg_wal.",=0A+=09=09=09=09=09=09=09=20=20= (uint64)=20segno));=0A+=0A+=09=09XLogFileName(fname,=20= segments[segment_index].tli,=20segno,=0A+=09=09=09=09=09=20= wal_segment_size);=0A+=09=09values[0]=20=3D=20= CStringGetTextDatum(fname);=0A+=09=09values[1]=20=3D=20= LSNGetDatum(segment_start_lsn);=0A+=09=09values[2]=20=3D=20= LSNGetDatum(segment_end_lsn);=0A+=09=09= tuplestore_putvalues(rsinfo->setResult,=20rsinfo->setDesc,=0A+=09=09=09=09= =09=09=09=20values,=20nulls);=0A+=0A+=09=09if=20(segno=20=3D=3D=20= last_segno)=0A+=09=09=09break;=0A+=0A+=09=09CHECK_FOR_INTERRUPTS();=0A+=09= }=0A+=0A+=09pfree(segments);=0A+=09PG_RETURN_VOID();=0A+#undef=20= PG_GET_WAL_FILES_COLS=0A+}=0A+=0A=20/*=0A=20=20*=20Validate=20start=20= and=20end=20LSNs=20coming=20from=20the=20function=20inputs.=0A=20=20*=0A= @@=20-525,7=20+726,7=20@@=20pg_get_wal_record_info(PG_FUNCTION_ARGS)=0A=20= static=20void=0A=20ValidateInputLSNs(XLogRecPtr=20start_lsn,=20= XLogRecPtr=20*end_lsn)=0A=20{=0A-=09XLogRecPtr=09curr_lsn=20=3D=20= GetCurrentLSN();=0A+=09XLogRecPtr=09curr_lsn=20=3D=20= GetCurrentLSN(NULL);=0A=20=0A=20=09if=20(start_lsn=20>=20curr_lsn)=0A=20=09= =09ereport(ERROR,=0A@@=20-831,7=20+1032,7=20@@=20Datum=0A=20= pg_get_wal_records_info_till_end_of_wal(PG_FUNCTION_ARGS)=0A=20{=0A=20=09= XLogRecPtr=09start_lsn=20=3D=20PG_GETARG_LSN(0);=0A-=09XLogRecPtr=09= end_lsn=20=3D=20GetCurrentLSN();=0A+=09XLogRecPtr=09end_lsn=20=3D=20= GetCurrentLSN(NULL);=0A=20=0A=20=09if=20(start_lsn=20>=20end_lsn)=0A=20=09= =09ereport(ERROR,=0A@@=20-849,7=20+1050,7=20@@=20Datum=0A=20= pg_get_wal_stats_till_end_of_wal(PG_FUNCTION_ARGS)=0A=20{=0A=20=09= XLogRecPtr=09start_lsn=20=3D=20PG_GETARG_LSN(0);=0A-=09XLogRecPtr=09= end_lsn=20=3D=20GetCurrentLSN();=0A+=09XLogRecPtr=09end_lsn=20=3D=20= GetCurrentLSN(NULL);=0A=20=09bool=09=09stats_per_record=20=3D=20= PG_GETARG_BOOL(1);=0A=20=0A=20=09if=20(start_lsn=20>=20end_lsn)=0Adiff=20= --git=20a/contrib/pg_walinspect/pg_walinspect.control=20= b/contrib/pg_walinspect/pg_walinspect.control=0Aindex=20= efa3cb2cfe5..5f574b865bb=20100644=0A---=20= a/contrib/pg_walinspect/pg_walinspect.control=0A+++=20= b/contrib/pg_walinspect/pg_walinspect.control=0A@@=20-1,5=20+1,5=20@@=0A=20= #=20pg_walinspect=20extension=0A=20comment=20=3D=20'functions=20to=20= inspect=20contents=20of=20PostgreSQL=20Write-Ahead=20Log'=0A= -default_version=20=3D=20'1.1'=0A+default_version=20=3D=20'1.2'=0A=20= module_pathname=20=3D=20'$libdir/pg_walinspect'=0A=20relocatable=20=3D=20= true=0Adiff=20--git=20a/contrib/pg_walinspect/sql/oldextversions.sql=20= b/contrib/pg_walinspect/sql/oldextversions.sql=0Aindex=20= e35c4f3ed15..b935a067b3e=20100644=0A---=20= a/contrib/pg_walinspect/sql/oldextversions.sql=0A+++=20= b/contrib/pg_walinspect/sql/oldextversions.sql=0A@@=20-27,10=20+27,11=20= @@=20SELECT=20COUNT(*)=20>=3D=201=20AS=20ok=20FROM=20= pg_get_wal_stats_till_end_of_wal(:'wal_lsn1');=0A=20SELECT=20*=20FROM=20= pg_get_wal_records_info_till_end_of_wal('FFFFFFFF/FFFFFFFF');=0A=20= SELECT=20*=20FROM=20= pg_get_wal_stats_till_end_of_wal('FFFFFFFF/FFFFFFFF');=0A=20=0A---=20= Move=20to=20new=20version=201.1.=0A+--=20Test=20each=20upgrade=20step=20= through=20the=20current=20version.=0A=20ALTER=20EXTENSION=20= pg_walinspect=20UPDATE=20TO=20'1.1';=0A+ALTER=20EXTENSION=20= pg_walinspect=20UPDATE=20TO=20'1.2';=0A=20=0A---=20List=20what=20version=20= 1.1=20contains.=0A+--=20List=20what=20the=20current=20version=20= contains.=0A=20\dx+=20pg_walinspect=0A=20=0A=20SELECT=20= pg_drop_replication_slot('regress_pg_walinspect_slot');=0Adiff=20--git=20= a/contrib/pg_walinspect/sql/pg_walinspect.sql=20= b/contrib/pg_walinspect/sql/pg_walinspect.sql=0Aindex=20= 1e64a22d29a..3176a17d855=20100644=0A---=20= a/contrib/pg_walinspect/sql/pg_walinspect.sql=0A+++=20= b/contrib/pg_walinspect/sql/pg_walinspect.sql=0A@@=20-51,6=20+51,30=20@@=20= SELECT=20COUNT(*)=20>=3D=201=20AS=20ok=20FROM=20= pg_get_wal_records_info(:'wal_lsn1',=20:'wal_lsn2'=0A=20SELECT=20= COUNT(*)=20>=3D=201=20AS=20ok=20FROM=20pg_get_wal_stats(:'wal_lsn1',=20= :'wal_lsn2');=0A=20SELECT=20COUNT(*)=20>=3D=201=20AS=20ok=20FROM=20= pg_get_wal_block_info(:'wal_lsn1',=20:'wal_lsn2');=0A=20=0A+--=20Return=20= the=20retained=20WAL=20file=20and=20its=20complete=20segment=20= boundaries.=0A+SELECT=20wal_file=20=3D=20= pg_walfile_name(segment_start_lsn)=20AS=20file_ok,=0A+=20=20=20=20=20=20=20= segment_start_lsn=20<=3D=20:'wal_lsn1'::pg_lsn=20AS=20start_ok,=0A+=20=20= =20=20=20=20=20segment_end_lsn=20>=20:'wal_lsn1'::pg_lsn=20AS=20end_ok=0A= +FROM=20pg_get_wal_files(:'wal_lsn1',=20:'wal_lsn1'::pg_lsn=20+=201);=0A= +=0A+--=20An=20end=20LSN=20at=20a=20segment=20boundary=20must=20not=20= include=20the=20next=20segment.=0A+WITH=20segment=20AS=0A+(=0A+=20=20= SELECT=20*=20FROM=20pg_get_wal_files(:'wal_lsn1',=20:'wal_lsn1'::pg_lsn=20= +=201)=0A+)=0A+SELECT=20count(*)=20=3D=201=20AS=20one_file=0A+FROM=20= segment,=0A+=20=20=20=20=20LATERAL=20pg_get_wal_files(segment_start_lsn,=20= segment_end_lsn);=0A+=0A+SELECT=20count(*)=20=3D=201=20AS=20equal_lsn_ok=0A= +FROM=20pg_get_wal_files(:'wal_lsn1',=20:'wal_lsn1');=0A+SELECT=20= count(*)=20=3D=201=20AS=20default_end_ok=0A+FROM=20= pg_get_wal_files(:'wal_lsn1');=0A+SELECT=20*=20FROM=20= pg_get_wal_files(:'wal_lsn1'::pg_lsn=20+=201,=20:'wal_lsn1');=0A+SELECT=20= count(*)=20=3D=201=20AS=20future_end_ok=0A+FROM=20= pg_get_wal_files(pg_current_wal_lsn(),=20'FFFFFFFF/FFFFFFFF');=0A+SELECT=20= *=20FROM=20pg_get_wal_files('0/0',=20'0/1');=0A+=0A=20--=20= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A=20--=20Test=20for=20= filtering=20out=20WAL=20records=20of=20a=20particular=20table=0A=20--=20= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A@@=20-110,6=20= +134,8=20@@=20SELECT=20has_function_privilege('regress_pg_walinspect',=0A= =20=20=20'pg_get_wal_stats(pg_lsn,=20pg_lsn,=20boolean)=20',=20= 'EXECUTE');=20--=20no=0A=20SELECT=20= has_function_privilege('regress_pg_walinspect',=0A=20=20=20= 'pg_get_wal_block_info(pg_lsn,=20pg_lsn,=20boolean)=20',=20'EXECUTE');=20= --=20no=0A+SELECT=20has_function_privilege('regress_pg_walinspect',=0A+=20= =20'pg_get_wal_files(pg_lsn,=20pg_lsn)',=20'EXECUTE');=20--=20no=0A=20=0A= =20--=20Functions=20accessible=20by=20users=20with=20role=20= pg_read_server_files.=0A=20GRANT=20pg_read_server_files=20TO=20= regress_pg_walinspect;=0A@@=20-122,6=20+148,8=20@@=20SELECT=20= has_function_privilege('regress_pg_walinspect',=0A=20=20=20= 'pg_get_wal_stats(pg_lsn,=20pg_lsn,=20boolean)=20',=20'EXECUTE');=20--=20= yes=0A=20SELECT=20has_function_privilege('regress_pg_walinspect',=0A=20=20= =20'pg_get_wal_block_info(pg_lsn,=20pg_lsn,=20boolean)=20',=20= 'EXECUTE');=20--=20yes=0A+SELECT=20= has_function_privilege('regress_pg_walinspect',=0A+=20=20= 'pg_get_wal_files(pg_lsn,=20pg_lsn)',=20'EXECUTE');=20--=20yes=0A=20=0A=20= REVOKE=20pg_read_server_files=20FROM=20regress_pg_walinspect;=0A=20=0A@@=20= -134,6=20+162,8=20@@=20GRANT=20EXECUTE=20ON=20FUNCTION=20= pg_get_wal_stats(pg_lsn,=20pg_lsn,=20boolean)=0A=20=20=20TO=20= regress_pg_walinspect;=0A=20GRANT=20EXECUTE=20ON=20FUNCTION=20= pg_get_wal_block_info(pg_lsn,=20pg_lsn,=20boolean)=0A=20=20=20TO=20= regress_pg_walinspect;=0A+GRANT=20EXECUTE=20ON=20FUNCTION=20= pg_get_wal_files(pg_lsn,=20pg_lsn)=0A+=20=20TO=20regress_pg_walinspect;=0A= =20=0A=20SELECT=20has_function_privilege('regress_pg_walinspect',=0A=20=20= =20'pg_get_wal_record_info(pg_lsn)',=20'EXECUTE');=20--=20yes=0A@@=20= -143,6=20+173,8=20@@=20SELECT=20= has_function_privilege('regress_pg_walinspect',=0A=20=20=20= 'pg_get_wal_stats(pg_lsn,=20pg_lsn,=20boolean)=20',=20'EXECUTE');=20--=20= yes=0A=20SELECT=20has_function_privilege('regress_pg_walinspect',=0A=20=20= =20'pg_get_wal_block_info(pg_lsn,=20pg_lsn,=20boolean)=20',=20= 'EXECUTE');=20--=20yes=0A+SELECT=20= has_function_privilege('regress_pg_walinspect',=0A+=20=20= 'pg_get_wal_files(pg_lsn,=20pg_lsn)',=20'EXECUTE');=20--=20yes=0A=20=0A=20= REVOKE=20EXECUTE=20ON=20FUNCTION=20pg_get_wal_record_info(pg_lsn)=0A=20=20= =20FROM=20regress_pg_walinspect;=0A@@=20-152,6=20+184,8=20@@=20REVOKE=20= EXECUTE=20ON=20FUNCTION=20pg_get_wal_stats(pg_lsn,=20pg_lsn,=20boolean)=0A= =20=20=20FROM=20regress_pg_walinspect;=0A=20REVOKE=20EXECUTE=20ON=20= FUNCTION=20pg_get_wal_block_info(pg_lsn,=20pg_lsn,=20boolean)=0A=20=20=20= FROM=20regress_pg_walinspect;=0A+REVOKE=20EXECUTE=20ON=20FUNCTION=20= pg_get_wal_files(pg_lsn,=20pg_lsn)=0A+=20=20FROM=20= regress_pg_walinspect;=0A=20=0A=20--=20= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A=20--=20Clean=20up=0A= diff=20--git=20a/contrib/pg_walinspect/t/001_timeline.pl=20= b/contrib/pg_walinspect/t/001_timeline.pl=0Anew=20file=20mode=20100644=0A= index=2000000000000..959fe485268=0A---=20/dev/null=0A+++=20= b/contrib/pg_walinspect/t/001_timeline.pl=0A@@=20-0,0=20+1,74=20@@=0A+#=20= Copyright=20(c)=202026,=20PostgreSQL=20Global=20Development=20Group=0A+=0A= +#=20Test=20that=20pg_get_wal_files()=20follows=20the=20current=20= timeline's=20history=20across=0A+#=20a=20promotion.=0A+use=20strict;=0A= +use=20warnings=20FATAL=20=3D>=20'all';=0A+=0A+use=20= PostgreSQL::Test::Cluster;=0A+use=20PostgreSQL::Test::Utils;=0A+use=20= Test::More;=0A+=0A+sub=20test_timeline_history=0A+{=0A+=09my=20($suffix,=20= $archive_mode)=20=3D=20@_;=0A+=09my=20$primary=20=3D=20= PostgreSQL::Test::Cluster->new("primary_$suffix");=0A+=09my=20$standby=20= =3D=20PostgreSQL::Test::Cluster->new("standby_$suffix");=0A+=0A+=09= $primary->init(allows_streaming=20=3D>=201);=0A+=09= $primary->append_conf('postgresql.conf',=20"autovacuum=20=3D=20off\n");=0A= +=09if=20($archive_mode)=0A+=09{=0A+=09=09$primary->append_conf(=0A+=09=09= =09'postgresql.conf',=0A+=09=09=09"archive_mode=20=3D=20= on\narchive_command=20=3D=20'true'\n");=0A+=09}=0A+=09$primary->start;=0A= +=09$primary->safe_psql('postgres',=0A+=09=09'CREATE=20EXTENSION=20= pg_walinspect;=20CREATE=20TABLE=20test_table=20(a=20int);');=0A+=09= $primary->safe_psql('postgres',=20'SELECT=20pg_switch_wal()');=0A+=09my=20= $boundary_lsn=20=3D=0A+=09=20=20$primary->safe_psql('postgres',=20= 'SELECT=20pg_current_wal_lsn()');=0A+=09my=20$boundary_offset=20=3D=20= $primary->safe_psql('postgres',=0A+=09=09"SELECT=20file_offset=20FROM=20= pg_walfile_name_offset('$boundary_lsn')");=0A+=09is($boundary_offset,=20= '0',=0A+=09=09"WAL=20is=20at=20a=20segment=20boundary=20with=20= archive_mode=3D$archive_mode");=0A+=09my=20$boundary_files=20=3D=20= $primary->safe_psql('postgres',=0A+=09=09"SELECT=20count(*)=20FROM=20= pg_get_wal_files('$boundary_lsn')");=0A+=09is($boundary_files,=20'1',=0A= +=09=09"point=20lookup=20works=20at=20a=20segment=20boundary=20with=20= archive_mode=3D$archive_mode");=0A+=0A+=09my=20$backup_name=20=3D=20= "backup_$suffix";=0A+=09$primary->backup($backup_name);=0A+=09= $standby->init_from_backup($primary,=20$backup_name,=20has_streaming=20= =3D>=201);=0A+=09$standby->append_conf('postgresql.conf',=20= "wal_keep_size=20=3D=20'64MB'\n");=0A+=09$standby->start;=0A+=0A+=09= $primary->safe_psql('postgres',=20'INSERT=20INTO=20test_table=20VALUES=20= (1)');=0A+=09my=20$start_lsn=20=3D=0A+=09=20=20= $primary->safe_psql('postgres',=20'SELECT=20= pg_current_wal_insert_lsn()');=0A+=09$primary->safe_psql('postgres',=20= 'SELECT=20pg_switch_wal()');=0A+=09$primary->safe_psql('postgres',=20= 'INSERT=20INTO=20test_table=20VALUES=20(2)');=0A+=09= $primary->wait_for_catchup($standby);=0A+=0A+=09$standby->promote;=0A+=09= $standby->safe_psql('postgres',=20'INSERT=20INTO=20test_table=20VALUES=20= (3)');=0A+=0A+=09my=20$result=20=3D=20$standby->safe_psql(=0A+=09=09= 'postgres',=20qq{=0A+SELECT=20count(DISTINCT=20left(wal_file,=208))=20=3D=20= 2,=0A+=20=20=20=20=20=20=20min(left(wal_file,=208))=20=3D=20'00000001',=0A= +=20=20=20=20=20=20=20max(left(wal_file,=208))=20=3D=20'00000002'=0A= +FROM=20pg_get_wal_files('$start_lsn',=20pg_current_wal_lsn())});=0A+=09= is($result,=20't|t|t',=0A+=09=09"WAL=20files=20span=20the=20timeline=20= switch=20with=20archive_mode=3D$archive_mode");=0A+=0A+=09= $standby->stop;=0A+=09$primary->stop;=0A+=09return;=0A+}=0A+=0A= +test_timeline_history('archive_off',=200);=0A= +test_timeline_history('archive_on',=201);=0A+=0A+done_testing();=0Adiff=20= --git=20a/doc/src/sgml/pgwalinspect.sgml=20= b/doc/src/sgml/pgwalinspect.sgml=0Aindex=2079c3ead40bc..2f708b32c60=20= 100644=0A---=20a/doc/src/sgml/pgwalinspect.sgml=0A+++=20= b/doc/src/sgml/pgwalinspect.sgml=0A@@=20-34,9=20+34,8=20@@=0A=20=20= =0A=20=20=0A=20=20=20=0A-=20=20=20All=20of=20the=20= pg_walinspect=20functions=20that=20show=0A-=20=20=20= information=20about=20records=20that=20fall=20within=20a=20certain=20LSN=20= range=20are=0A-=20=20=20permissive=20about=20accepting=20= end_lsn=0A+=20=20=20All=20of=20the=20= pg_walinspect=20functions=20that=20accept=20an=20= LSN=0A+=20=20=20range=20are=20permissive=20about=20accepting=20= end_lsn=0A=20=20=20=20arguments=20that=20are=20= after=20the=20server's=20current=20LSN.=20=20Using=20an=0A=20=20=20=20= end_lsn=20from=20the=20future=0A= =20=20=20=20will=20not=20raise=20an=20error.=0A@@=20-60,6=20+59,42=20@@=0A= =20=20=20General=20Functions=0A=20=0A=20=20=20= =0A+=20=20=20=0A+=20=20=20=20=0A+=20=20= =20=20=20pg_get_wal_files(start_lsn=20pg_lsn,=20end_lsn=20= pg_lsn=20DEFAULT=20NULL)=20returns=20setof=20record=0A+=20=20=20= =20=0A+=0A+=20=20=20=20=0A+=20=20=20=20=20=0A+=20=20= =20=20=20=20If=20end_lsn=20is=20specified=20= and=20differs=20from=0A+=20=20=20=20=20=20= start_lsn,=20returns=20each=20retained=20WAL=20= segment=0A+=20=20=20=20=20=20file=20that=20intersects=20the=20half-open=20= WAL=20range=0A+=20=20=20=20=20=20[start_lsn,=0A= +=20=20=20=20=20=20end_lsn).=20=20If=0A+=20=20= =20=20=20=20end_lsn=20is=20omitted,=20is=20= null,=20or=20equals=0A+=20=20=20=20=20=20= start_lsn,=20returns=20the=20segment=20= containing=0A+=20=20=20=20=20=20start_lsn.=20=20= The=0A+=20=20=20=20=20=20wal_file=20column=20= contains=20the=20file=20name,=20while=0A+=20=20=20=20=20=20= segment_start_lsn=20and=0A+=20=20=20=20=20=20= segment_end_lsn=20contain=20the=20complete=20= segment=0A+=20=20=20=20=20=20boundaries=20rather=20than=20boundaries=20= clipped=20to=20the=20requested=20range.=0A+=20=20=20=20=20=20If=20a=20= point=20lookup=20specifies=20the=20current=20WAL=20LSN=20and=20it=20lies=20= exactly=20on=0A+=20=20=20=20=20=20a=20segment=20boundary,=20the=20= preceding=20segment=20is=20returned,=20since=20the=20next=0A+=20=20=20=20= =20=20segment=20might=20not=20have=20been=20created=20yet.=20=20This=20= differs=20from=0A+=20=20=20=20=20=20= pg_walfile_name,=20which=20performs=20a=20pure=20= calculation=0A+=20=20=20=20=20=20that=20maps=20an=20LSN=20to=20a=20WAL=20= file=20name=20without=20checking=20whether=20the=20file=0A+=20=20=20=20=20= =20exists,=20and=20therefore=20maps=20such=20a=20boundary=20LSN=20to=20= the=20next=20segment.=0A+=20=20=20=20=20=0A+=0A+=20=20=20=20=20= =0A+=20=20=20=20=20=20File=20names=20use=20the=20timeline=20valid=20= for=20each=20segment=20in=20the=20current=0A+=20=20=20=20=20=20= timeline's=20history.=20=20This=20allows=20a=20returned=20range=20to=20= cross=20a=20timeline=0A+=20=20=20=20=20=20switch.=20=20The=20function=20= reports=20an=20error=20if=20any=20required=20segment=20file=20is=0A+=20=20= =20=20=20=20not=20currently=20retained=20in=20= pg_wal.=0A+=20=20=20=20=20=0A+=20=20=20=20= =0A+=20=20=20=0A+=0A=20=20=20=20=0A=20=20=20=20=20= =0A=20=20=20=20=20=20pg_get_wal_record_info(in_lsn=20= pg_lsn)=20returns=20record=0Adiff=20--git=20= a/src/tools/pgindent/typedefs.list=20b/src/tools/pgindent/typedefs.list=0A= index=203bed561f7f2..46da9e8a15c=20100644=0A---=20= a/src/tools/pgindent/typedefs.list=0A+++=20= b/src/tools/pgindent/typedefs.list=0A@@=20-3430,6=20+3430,7=20@@=20= WalSummarizerData=0A=20WalSummaryFile=0A=20WalSummaryIO=0A=20= WalTimeSample=0A+WalTimeSegment=0A=20WalUsage=0A=20WalWriteMethod=0A=20= WalWriteMethodOps=0A--=20=0A2.50.1=20(Apple=20Git-155)=0A=0A= --Apple-Mail=_A1724A3D-C5C8-4ED1-AE94-3480FD42F6C1 Content-Disposition: attachment; filename=v5-0002-pg_walinspect-add-function-to-locate-WAL-by-time.patch Content-Type: application/octet-stream; x-unix-mode=0644; name="v5-0002-pg_walinspect-add-function-to-locate-WAL-by-time.patch" Content-Transfer-Encoding: quoted-printable =46rom=20a1dce53ea57647715e672c0b2543825a67669792=20Mon=20Sep=2017=20= 00:00:00=202001=0AFrom:=20"Chao=20Li=20(Evan)"=20=0A= Date:=20Thu,=201=20Oct=202026=2006:52:59=20+0800=0ASubject:=20[PATCH=20= v5=202/2]=20pg_walinspect:=20add=20function=20to=20locate=20WAL=20by=20= time=0A=0AAdd=20pg_get_wal_location_at_time(),=20which=20uses=20= timestamped=20WAL=20records=20to=20locate=0Aa=20useful=20WAL=20range=20= around=20a=20requested=20wall-clock=20time.=20Use=20an=20approximate=0A= binary=20search=20over=20retained=20segments=20and=20allow=20callers=20= to=20widen=20the=20requested=0Ainterval=20when=20timestamp=20reordering=20= makes=20the=20initial=20result=20insufficient.=0A=0AMove=20WAL=20record=20= timestamp=20extraction=20from=20recovery=20into=20xlogreader=0Aso=20= pg_walinspect=20can=20recognize=20the=20same=20timestamp-bearing=20= record=20types=20without=0Aduplicating=20that=20logic.=0A=0AAuthor:=20= Chao=20Li=20=0AReviewed-by:=20Surya=20Poondla=20= =0ADiscussion:=20= https://postgr.es/m/80E9F0AD-CFC5-4BE5-81DE-D8FE35E10A1C@gmail.com=0A---=0A= =20.../pg_walinspect/expected/oldextversions.out=20|=20=20=209=20+-=0A=20= .../pg_walinspect/expected/pg_walinspect.out=20=20|=20164=20++++++=0A=20= contrib/pg_walinspect/meson.build=20=20=20=20=20=20=20=20=20=20=20=20=20= |=20=20=201=20+=0A=20.../pg_walinspect/pg_walinspect--1.1--1.2.sql=20|=20= =2021=20+=0A=20contrib/pg_walinspect/pg_walinspect.c=20=20=20=20=20=20=20= =20=20|=20485=20+++++++++++++++++-=0A=20= contrib/pg_walinspect/sql/pg_walinspect.sql=20=20=20|=20121=20+++++=0A=20= contrib/pg_walinspect/t/002_time_search.pl=20=20=20=20|=20=2098=20++++=0A= =20doc/src/sgml/pgwalinspect.sgml=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20|=20139=20+++++=0A=20src/backend/access/transam/xlogreader.c=20=20=20= =20=20=20=20|=20=2036=20++=0A=20= src/backend/access/transam/xlogrecovery.c=20=20=20=20=20|=20=2048=20+-=0A= =20src/include/access/xlogreader.h=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20|=20=20=203=20+=0A=20src/tools/pgindent/typedefs.list=20=20=20=20=20= =20=20=20=20=20=20=20=20=20|=20=20=201=20+=0A=2012=20files=20changed,=20= 1077=20insertions(+),=2049=20deletions(-)=0A=20create=20mode=20100644=20= contrib/pg_walinspect/t/002_time_search.pl=0A=0Adiff=20--git=20= a/contrib/pg_walinspect/expected/oldextversions.out=20= b/contrib/pg_walinspect/expected/oldextversions.out=0Aindex=20= 311017d66ca..6228ad9ef39=20100644=0A---=20= a/contrib/pg_walinspect/expected/oldextversions.out=0A+++=20= b/contrib/pg_walinspect/expected/oldextversions.out=0A@@=20-51,15=20= +51,16=20@@=20ALTER=20EXTENSION=20pg_walinspect=20UPDATE=20TO=20'1.1';=0A= =20ALTER=20EXTENSION=20pg_walinspect=20UPDATE=20TO=20'1.2';=0A=20--=20= List=20what=20the=20current=20version=20contains.=0A=20\dx+=20= pg_walinspect=0A-=20=20=20=20=20=20=20=20=20Objects=20in=20extension=20= "pg_walinspect"=0A-=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= Object=20description=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=0A--------------------------------------------------------=0A+=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20Objects=20in=20= extension=20"pg_walinspect"=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20Object=20= description=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=0A= +-------------------------------------------------------------------------= ---------=0A=20=20function=20= pg_get_wal_block_info(pg_lsn,pg_lsn,boolean)=0A=20=20function=20= pg_get_wal_files(pg_lsn,pg_lsn)=0A+=20function=20= pg_get_wal_location_at_time(timestamp=20with=20time=20= zone,interval,interval)=0A=20=20function=20= pg_get_wal_record_info(pg_lsn)=0A=20=20function=20= pg_get_wal_records_info(pg_lsn,pg_lsn)=0A=20=20function=20= pg_get_wal_stats(pg_lsn,pg_lsn,boolean)=0A-(5=20rows)=0A+(6=20rows)=0A=20= =0A=20SELECT=20pg_drop_replication_slot('regress_pg_walinspect_slot');=0A= =20=20pg_drop_replication_slot=20=0Adiff=20--git=20= a/contrib/pg_walinspect/expected/pg_walinspect.out=20= b/contrib/pg_walinspect/expected/pg_walinspect.out=0Aindex=20= 34864c65ec7..341bb543295=20100644=0A---=20= a/contrib/pg_walinspect/expected/pg_walinspect.out=0A+++=20= b/contrib/pg_walinspect/expected/pg_walinspect.out=0A@@=20-139,6=20= +139,145=20@@=20FROM=20pg_get_wal_files(pg_current_wal_lsn(),=20= 'FFFFFFFF/FFFFFFFF');=0A=20SELECT=20*=20FROM=20pg_get_wal_files('0/0',=20= '0/1');=0A=20ERROR:=20=20could=20not=20read=20WAL=20at=20LSN=20= 0/00000000=0A=20--=20= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A+--=20Tests=20for=20= locating=20WAL=20by=20timestamps=20stored=20in=20WAL=20records=0A+--=20= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A+--=20Put=20two=20= WAL-logged=20transaction=20commits=20between=20the=20requested=20= boundaries.=0A+INSERT=20INTO=20sample_tbl=20VALUES=20(5,=205);=0A+SELECT=20= clock_timestamp()=20AS=20wal_time_lower=20\gset=0A+INSERT=20INTO=20= sample_tbl=20VALUES=20(6,=206);=0A+INSERT=20INTO=20sample_tbl=20VALUES=20= (10,=2010);=0A+SELECT=20clock_timestamp()=20AS=20wal_time_upper=20\gset=0A= +INSERT=20INTO=20sample_tbl=20VALUES=20(13,=2013);=0A+SELECT=20= start_timestamp=20<=3D=20:'wal_time_lower'::timestamptz=20-=20interval=20= '1=20microsecond'=0A+=20=20=20=20=20=20=20=20=20AS=20start_ok,=0A+=20=20=20= =20=20=20=20end_timestamp=20>=3D=20:'wal_time_upper'::timestamptz=20AS=20= end_ok,=0A+=20=20=20=20=20=20=20start_lsn=20<=20end_lsn=20AS=20lsn_ok=0A= +FROM=20pg_get_wal_location_at_time(:'wal_time_lower',=0A+=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20before=20=3D>=20interval=20'1=20microsecond',=0A+=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20after=20=3D>=20:'wal_time_upper'::timestamptz=20-=0A+=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20:'wal_time_lower'::timestamptz);=0A= +=20start_ok=20|=20end_ok=20|=20lsn_ok=20=0A= +----------+--------+--------=0A+=20t=20=20=20=20=20=20=20=20|=20t=20=20=20= =20=20=20|=20t=0A+(1=20row)=0A+=0A+--=20A=20window=20containing=20one=20= timestamped=20record=20is=20enclosed=20by=20outer=20anchors.=0A+SELECT=20= clock_timestamp()=20AS=20single_time_lower=20\gset=0A+INSERT=20INTO=20= sample_tbl=20VALUES=20(12,=2012);=0A+SELECT=20clock_timestamp()=20AS=20= single_time_upper=20\gset=0A+INSERT=20INTO=20sample_tbl=20VALUES=20(14,=20= 14);=0A+SELECT=20location.start_timestamp=20<=3D=20= :'single_time_lower'::timestamptz=0A+=20=20=20=20=20=20=20=20=20AS=20= start_ok,=0A+=20=20=20=20=20=20=20location.end_timestamp=20>=3D=20= :'single_time_upper'::timestamptz=0A+=20=20=20=20=20=20=20=20=20AS=20= end_ok,=0A+=20=20=20=20=20=20=20location.start_lsn=20<=20= location.end_lsn=20AS=20lsn_ok=0A+FROM=20= pg_get_wal_location_at_time(:'single_time_lower',=0A+=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20interval=20'1=20microsecond',=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= :'single_time_upper'::timestamptz=20-=0A+=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= :'single_time_lower'::timestamptz)=20AS=20location;=0A+=20start_ok=20|=20= end_ok=20|=20lsn_ok=20=0A+----------+--------+--------=0A+=20t=20=20=20=20= =20=20=20=20|=20t=20=20=20=20=20=20|=20t=0A+(1=20row)=0A+=0A+--=20= Exercise=20a=20time=20window=20containing=20a=20COMMIT=20PREPARED=20= record.=20=20Concurrent=0A+--=20activity=20can=20cause=20another=20= timestamped=20record=20to=20be=20selected=20as=20the=20anchor.=0A+INSERT=20= INTO=20sample_tbl=20VALUES=20(11,=2011);=0A+BEGIN;=0A+INSERT=20INTO=20= sample_tbl=20VALUES=20(7,=207);=0A+PREPARE=20TRANSACTION=20= 'regress_pg_walinspect_time';=0A+SELECT=20clock_timestamp()=20AS=20= prepared_time_target=20\gset=0A+COMMIT=20PREPARED=20= 'regress_pg_walinspect_time';=0A+SELECT=20clock_timestamp()=20AS=20= prepared_time_upper=20\gset=0A+INSERT=20INTO=20sample_tbl=20VALUES=20= (15,=2015);=0A+SELECT=20record_type=20IN=20('COMMIT',=20= 'COMMIT_PREPARED',=20'ABORT',=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20'ABORT_PREPARED',=20'RESTORE_POINT')=20AS=20= timestamped_ok=0A+FROM=20= pg_get_wal_location_at_time(:'prepared_time_target',=0A+=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20:'prepared_time_target'::timestamptz=20-=0A+=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20:'wal_time_upper'::timestamptz,=0A+=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= :'prepared_time_upper'::timestamptz=20-=0A+=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= :'prepared_time_target'::timestamptz)=20AS=20location,=0A+=20=20=20=20=20= LATERAL=20pg_get_wal_record_info(location.end_lsn);=0A+=20timestamped_ok=20= =0A+----------------=0A+=20t=0A+(1=20row)=0A+=0A+--=20Exercise=20a=20= time=20window=20containing=20restore=20points,=20allowing=20for=20other=0A= +--=20timestamped=20WAL=20records=20generated=20concurrently.=0A+SELECT=20= pg_create_restore_point('regress_wal_time_lower')=20AS=20restore_lsn=20= \gset=0A+SELECT=20clock_timestamp()=20AS=20restore_time_target=20\gset=0A= +SELECT=20pg_create_restore_point('regress_wal_time_upper')=20AS=20= restore_lsn=20\gset=0A+SELECT=20clock_timestamp()=20AS=20= restore_time_upper=20\gset=0A+INSERT=20INTO=20sample_tbl=20VALUES=20(8,=20= 8);=0A+SELECT=20start_info.record_type=20IN=20('COMMIT',=20= 'COMMIT_PREPARED',=20'ABORT',=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= 'ABORT_PREPARED',=20'RESTORE_POINT')=20AS=20start_ok,=0A+=20=20=20=20=20=20= =20end_info.record_type=20IN=20('COMMIT',=20'COMMIT_PREPARED',=20= 'ABORT',=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20'ABORT_PREPARED',=20'RESTORE_POINT')=20= AS=20end_ok=0A+FROM=20= pg_get_wal_location_at_time(:'restore_time_target',=0A+=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20:'restore_time_target'::timestamptz=20-=0A+=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20:'wal_time_upper'::timestamptz,=0A+=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= :'restore_time_upper'::timestamptz=20-=0A+=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= :'restore_time_target'::timestamptz)=20AS=20location,=0A+=20=20=20=20=20= LATERAL=20pg_get_wal_record_info(location.start_lsn)=20AS=20start_info,=0A= +=20=20=20=20=20LATERAL=20pg_get_wal_record_info(location.end_lsn)=20AS=20= end_info;=0A+=20start_ok=20|=20end_ok=20=0A+----------+--------=0A+=20t=20= =20=20=20=20=20=20=20|=20t=0A+(1=20row)=0A+=0A+--=20A=20future=20upper=20= bound=20falls=20back=20to=20the=20current=20WAL=20position.=0A+SELECT=20= clock_timestamp()=20AS=20current_time_target=20\gset=0A+INSERT=20INTO=20= sample_tbl=20VALUES=20(9,=209);=0A+SELECT=20location.start_timestamp=20= <=3D=20:'restore_time_upper'::timestamptz=0A+=20=20=20=20=20=20=20=20=20= AS=20start_ok,=0A+=20=20=20=20=20=20=20location.end_timestamp=20IS=20= NULL=20AS=20current_end_ok,=0A+=20=20=20=20=20=20=20location.end_lsn=20= <=3D=20pg_current_wal_flush_lsn()=20AS=20end_lsn_ok,=0A+=20=20=20=20=20=20= =20location.start_lsn=20<=20location.end_lsn=20AS=20lsn_ok,=0A+=20=20=20=20= =20=20=20EXISTS=20(SELECT=20FROM=20= pg_get_wal_records_info(location.start_lsn,=0A+=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20location.end_lsn)=0A+=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20WHERE=20resource_manager=20=3D=20= 'Heap'=20AND=20record_type=20=3D=20'INSERT')=0A+=20=20=20=20=20=20=20=20=20= AS=20records_ok=0A+FROM=20= pg_get_wal_location_at_time(:'current_time_target',=0A+=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20:'current_time_target'::timestamptz=20-=0A+=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20:'restore_time_upper'::timestamptz,=0A+=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= interval=20'1=20day')=20AS=20location;=0A+=20start_ok=20|=20= current_end_ok=20|=20end_lsn_ok=20|=20lsn_ok=20|=20records_ok=20=0A= +----------+----------------+------------+--------+------------=0A+=20t=20= =20=20=20=20=20=20=20|=20t=20=20=20=20=20=20=20=20=20=20=20=20=20=20|=20= t=20=20=20=20=20=20=20=20=20=20|=20t=20=20=20=20=20=20|=20t=0A+(1=20row)=0A= +=0A+SELECT=20pg_get_function_arguments(=0A+=20=20= 'pg_get_wal_location_at_time(timestamptz,=20interval,=20= interval)'::regprocedure)=0A+=20=20LIKE=20'%before=20interval=20DEFAULT=20= ''@=201=20min''::interval,=20after=20interval=20DEFAULT=20''@=201=20= min''::interval%'=0A+=20=20AS=20defaults_ok;=0A+=20defaults_ok=20=0A= +-------------=0A+=20t=0A+(1=20row)=0A+=0A+SELECT=20*=20FROM=20= pg_get_wal_location_at_time(:'wal_time_lower',=0A+=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20interval=20'0',=20interval=20'1=20second');=0A= +ERROR:=20=20before=20interval=20must=20be=20finite=20and=20greater=20= than=20zero=0A+SELECT=20*=20FROM=20= pg_get_wal_location_at_time(:'wal_time_lower',=0A+=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20interval=20'1=20second',=20interval=20'0');=0A= +ERROR:=20=20after=20interval=20must=20be=20finite=20and=20greater=20= than=20zero=0A+SELECT=20*=20FROM=20= pg_get_wal_location_at_time(:'wal_time_lower',=20interval=20'-1=20= second');=0A+ERROR:=20=20before=20interval=20must=20be=20finite=20and=20= greater=20than=20zero=0A+SELECT=20*=20FROM=20= pg_get_wal_location_at_time(:'wal_time_lower',=0A+=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20after=20=3D>=20interval=20'-1=20second');=0A= +ERROR:=20=20after=20interval=20must=20be=20finite=20and=20greater=20= than=20zero=0A+SELECT=20*=20FROM=20= pg_get_wal_location_at_time(:'wal_time_lower',=0A+=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20before=20=3D>=20interval=20'1=20day=201=20= microsecond');=0A+ERROR:=20=20before=20interval=20must=20not=20exceed=20= one=20day=0A+SELECT=20*=20FROM=20= pg_get_wal_location_at_time(:'wal_time_lower',=0A+=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20after=20=3D>=20interval=20'1=20day=201=20= microsecond');=0A+ERROR:=20=20after=20interval=20must=20not=20exceed=20= one=20day=0A+SELECT=20*=20FROM=20= pg_get_wal_location_at_time(clock_timestamp()=20-=20interval=20'100=20= years');=0A+ERROR:=20=20could=20not=20locate=20a=20WAL=20time=20boundary=0A= +SELECT=20*=20FROM=20pg_get_wal_location_at_time(clock_timestamp()=20+=20= interval=20'100=20years');=0A+ERROR:=20=20requested=20time=20follows=20= the=20available=20WAL=20range=0A+--=20= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A=20--=20Test=20for=20= filtering=20out=20WAL=20records=20of=20a=20particular=20table=0A=20--=20= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A=20SELECT=20oid=20= AS=20sample_tbl_oid=20FROM=20pg_class=20WHERE=20relname=20=3D=20= 'sample_tbl'=20\gset=0A@@=20-231,6=20+370,13=20@@=20SELECT=20= has_function_privilege('regress_pg_walinspect',=0A=20=20f=0A=20(1=20row)=0A= =20=0A+SELECT=20has_function_privilege('regress_pg_walinspect',=0A+=20=20= 'pg_get_wal_location_at_time(timestamptz,=20interval,=20interval)',=20= 'EXECUTE');=20--=20no=0A+=20has_function_privilege=20=0A= +------------------------=0A+=20f=0A+(1=20row)=0A+=0A=20SELECT=20= has_function_privilege('regress_pg_walinspect',=0A=20=20=20= 'pg_get_wal_files(pg_lsn,=20pg_lsn)',=20'EXECUTE');=20--=20no=0A=20=20= has_function_privilege=20=0A@@=20-268,6=20+414,13=20@@=20SELECT=20= has_function_privilege('regress_pg_walinspect',=0A=20=20t=0A=20(1=20row)=0A= =20=0A+SELECT=20has_function_privilege('regress_pg_walinspect',=0A+=20=20= 'pg_get_wal_location_at_time(timestamptz,=20interval,=20interval)',=20= 'EXECUTE');=20--=20yes=0A+=20has_function_privilege=20=0A= +------------------------=0A+=20t=0A+(1=20row)=0A+=0A=20SELECT=20= has_function_privilege('regress_pg_walinspect',=0A=20=20=20= 'pg_get_wal_files(pg_lsn,=20pg_lsn)',=20'EXECUTE');=20--=20yes=0A=20=20= has_function_privilege=20=0A@@=20-285,6=20+438,8=20@@=20GRANT=20EXECUTE=20= ON=20FUNCTION=20pg_get_wal_stats(pg_lsn,=20pg_lsn,=20boolean)=0A=20=20=20= TO=20regress_pg_walinspect;=0A=20GRANT=20EXECUTE=20ON=20FUNCTION=20= pg_get_wal_block_info(pg_lsn,=20pg_lsn,=20boolean)=0A=20=20=20TO=20= regress_pg_walinspect;=0A+GRANT=20EXECUTE=20ON=20FUNCTION=20= pg_get_wal_location_at_time(timestamptz,=20interval,=20interval)=0A+=20=20= TO=20regress_pg_walinspect;=0A=20GRANT=20EXECUTE=20ON=20FUNCTION=20= pg_get_wal_files(pg_lsn,=20pg_lsn)=0A=20=20=20TO=20= regress_pg_walinspect;=0A=20SELECT=20= has_function_privilege('regress_pg_walinspect',=0A@@=20-315,6=20+470,13=20= @@=20SELECT=20has_function_privilege('regress_pg_walinspect',=0A=20=20t=0A= =20(1=20row)=0A=20=0A+SELECT=20= has_function_privilege('regress_pg_walinspect',=0A+=20=20= 'pg_get_wal_location_at_time(timestamptz,=20interval,=20interval)',=20= 'EXECUTE');=20--=20yes=0A+=20has_function_privilege=20=0A= +------------------------=0A+=20t=0A+(1=20row)=0A+=0A=20SELECT=20= has_function_privilege('regress_pg_walinspect',=0A=20=20=20= 'pg_get_wal_files(pg_lsn,=20pg_lsn)',=20'EXECUTE');=20--=20yes=0A=20=20= has_function_privilege=20=0A@@=20-330,6=20+492,8=20@@=20REVOKE=20EXECUTE=20= ON=20FUNCTION=20pg_get_wal_stats(pg_lsn,=20pg_lsn,=20boolean)=0A=20=20=20= FROM=20regress_pg_walinspect;=0A=20REVOKE=20EXECUTE=20ON=20FUNCTION=20= pg_get_wal_block_info(pg_lsn,=20pg_lsn,=20boolean)=0A=20=20=20FROM=20= regress_pg_walinspect;=0A+REVOKE=20EXECUTE=20ON=20FUNCTION=20= pg_get_wal_location_at_time(timestamptz,=20interval,=20interval)=0A+=20=20= FROM=20regress_pg_walinspect;=0A=20REVOKE=20EXECUTE=20ON=20FUNCTION=20= pg_get_wal_files(pg_lsn,=20pg_lsn)=0A=20=20=20FROM=20= regress_pg_walinspect;=0A=20--=20= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0Adiff=20--git=20= a/contrib/pg_walinspect/meson.build=20= b/contrib/pg_walinspect/meson.build=0Aindex=206f8b4a6359a..79e94e33e4d=20= 100644=0A---=20a/contrib/pg_walinspect/meson.build=0A+++=20= b/contrib/pg_walinspect/meson.build=0A@@=20-41,6=20+41,7=20@@=20tests=20= +=3D=20{=0A=20=20=20'tap':=20{=0A=20=20=20=20=20'tests':=20[=0A=20=20=20=20= =20=20=20't/001_timeline.pl',=0A+=20=20=20=20=20=20= 't/002_time_search.pl',=0A=20=20=20=20=20],=0A=20=20=20},=0A=20}=0Adiff=20= --git=20a/contrib/pg_walinspect/pg_walinspect--1.1--1.2.sql=20= b/contrib/pg_walinspect/pg_walinspect--1.1--1.2.sql=0Aindex=20= 9cc9523b4dc..f72d99a3ceb=20100644=0A---=20= a/contrib/pg_walinspect/pg_walinspect--1.1--1.2.sql=0A+++=20= b/contrib/pg_walinspect/pg_walinspect--1.1--1.2.sql=0A@@=20-3,6=20+3,27=20= @@=0A=20--=20complain=20if=20script=20is=20sourced=20in=20psql,=20rather=20= than=20via=20ALTER=20EXTENSION=0A=20\echo=20Use=20"ALTER=20EXTENSION=20= pg_walinspect=20UPDATE=20TO=20'1.2'"=20to=20load=20this=20file.=20\quit=0A= =20=0A+--=0A+--=20pg_get_wal_location_at_time()=0A+--=0A+CREATE=20= FUNCTION=20pg_get_wal_location_at_time(=0A+=20=20=20=20IN=20target_time=20= timestamptz,=0A+=20=20=20=20IN=20before=20interval=20DEFAULT=20'1=20= minute',=0A+=20=20=20=20IN=20after=20interval=20DEFAULT=20'1=20minute',=0A= +=20=20=20=20OUT=20start_timestamp=20timestamptz,=0A+=20=20=20=20OUT=20= start_lsn=20pg_lsn,=0A+=20=20=20=20OUT=20end_timestamp=20timestamptz,=0A= +=20=20=20=20OUT=20end_lsn=20pg_lsn=0A+)=0A+AS=20'MODULE_PATHNAME',=20= 'pg_get_wal_location_at_time'=0A+LANGUAGE=20C=20STRICT=20PARALLEL=20= SAFE;=0A+=0A+REVOKE=20EXECUTE=20ON=20FUNCTION=0A+=20=20= pg_get_wal_location_at_time(timestamptz,=20interval,=20interval)=20FROM=20= PUBLIC;=0A+GRANT=20EXECUTE=20ON=20FUNCTION=0A+=20=20= pg_get_wal_location_at_time(timestamptz,=20interval,=20interval)=0A+=20=20= TO=20pg_read_server_files;=0A+=0A=20--=0A=20--=20pg_get_wal_files()=0A=20= --=0Adiff=20--git=20a/contrib/pg_walinspect/pg_walinspect.c=20= b/contrib/pg_walinspect/pg_walinspect.c=0Aindex=20= 85d76fe37c4..d57ac4f80ae=20100644=0A---=20= a/contrib/pg_walinspect/pg_walinspect.c=0A+++=20= b/contrib/pg_walinspect/pg_walinspect.c=0A@@=20-12,6=20+12,8=20@@=0A=20=20= */=0A=20#include=20"postgres.h"=0A=20=0A+#include=20=0A+=0A=20= #include=20"access/htup_details.h"=0A=20#include=20"access/timeline.h"=0A= =20#include=20"access/xlog.h"=0A@@=20-26,7=20+28,9=20@@=0A=20#include=20= "storage/fd.h"=0A=20#include=20"utils/array.h"=0A=20#include=20= "utils/builtins.h"=0A+#include=20"utils/fmgrprotos.h"=0A=20#include=20= "utils/pg_lsn.h"=0A+#include=20"utils/timestamp.h"=0A=20#include=20= "utils/tuplestore.h"=0A=20=0A=20/*=0A@@=20-41,6=20+45,7=20@@=20= PG_MODULE_MAGIC_EXT(=0A=20=0A=20= PG_FUNCTION_INFO_V1(pg_get_wal_block_info);=0A=20= PG_FUNCTION_INFO_V1(pg_get_wal_files);=0A= +PG_FUNCTION_INFO_V1(pg_get_wal_location_at_time);=0A=20= PG_FUNCTION_INFO_V1(pg_get_wal_record_info);=0A=20= PG_FUNCTION_INFO_V1(pg_get_wal_records_info);=0A=20= PG_FUNCTION_INFO_V1(pg_get_wal_records_info_till_end_of_wal);=0A@@=20= -71,15=20+76,52=20@@=20static=20void=20GetWalStats(FunctionCallInfo=20= fcinfo,=0A=20static=20void=20GetWALBlockInfo(FunctionCallInfo=20fcinfo,=20= XLogReaderState=20*record,=0A=20=09=09=09=09=09=09=09bool=20show_data);=0A= =20=0A+/*=20Selected=20WAL=20position=20and=20timestamp=20for=20one=20= time=20boundary.=20*/=0A+typedef=20struct=20WalTimeBoundary=0A+{=0A+=09= bool=09=09found;=09=09=09/*=20matching=20record=20was=20found=20*/=0A+=09= TimestampTz=20time;=09=09=09/*=20record's=20local=20event=20time=20*/=0A= +=09XLogRecPtr=09lsn;=09=09=09/*=20record's=20start=20LSN=20*/=0A+=09int=09= =09=09segment_index;=09/*=20index=20of=20the=20segment=20containing=20= the=20record=20*/=0A+}=20WalTimeBoundary;=0A+=0A=20/*=20Metadata=20for=20= one=20retained=20segment=20in=20the=20current=20timeline's=20history.=20= */=0A=20typedef=20struct=20WalTimeSegment=0A=20{=0A=20=09XLogSegNo=09= segno;=09=09=09/*=20segment=20number,=20used=20for=20WAL=20ordering=20*/=0A= =20=09TimeLineID=09tli;=09=09=09/*=20timeline=20containing=20this=20= segment=20*/=0A+=09bool=09=09scanned;=09=09/*=20segment=20has=20already=20= been=20decoded=20*/=0A+=09bool=09=09has_timestamp;=09/*=20segment=20= contains=20timestamped=20records=20*/=0A+=09TimestampTz=20min_time;=09=09= /*=20minimum=20record=20timestamp=20in=20segment=20*/=0A+=09TimestampTz=20= max_time;=09=09/*=20maximum=20record=20timestamp=20in=20segment=20*/=0A+=09= WalTimeBoundary=20lower;=09=09/*=20best=20lower=20anchor=20in=20segment=20= */=0A+=09WalTimeBoundary=20upper;=09=09/*=20best=20upper=20anchor=20in=20= segment=20*/=0A=20}=20WalTimeSegment;=0A=20=0A=20static=20int=09= wal_time_segment_cmp(const=20void=20*a,=20const=20void=20*b);=0A-static=20= WalTimeSegment=20*GetWalTimeSegments(int=20*nsegments);=0A+static=20= WalTimeSegment=20*GetWalTimeSegments(int=20*nsegments,=0A+=09=09=09=09=09= =09=09=09=09=09=20=20XLogRecPtr=20*current_lsn_out);=0A+static=20int=09= FindWalTimeCandidate(WalTimeSegment=20*segments,=0A+=09=09=09=09=09=09=09= =09=20int=20*search_segments,=0A+=09=09=09=09=09=09=09=09=20int=20= *nsearch_segments,=0A+=09=09=09=09=09=09=09=09=20TimestampTz=20= target_time,=0A+=09=09=09=09=09=09=09=09=20bool=20search_left,=0A+=09=09=09= =09=09=09=09=09=20TimestampTz=20wanted_start,=0A+=09=09=09=09=09=09=09=09= =20TimestampTz=20wanted_end,=0A+=09=09=09=09=09=09=09=09=20int=20= *candidate_position,=0A+=09=09=09=09=09=09=09=09=20int=20*nscanned);=0A= +static=20void=20ScanWalTimeSegment(WalTimeSegment=20*segment,=20int=20= segment_index,=0A+=09=09=09=09=09=09=09=20=20=20TimestampTz=20= wanted_start,=0A+=09=09=09=09=09=09=09=20=20=20TimestampTz=20= wanted_end);=0A+static=20void=20MergeWalTimeSegment(WalTimeSegment=20= *segment,=0A+=09=09=09=09=09=09=09=09WalTimeBoundary=20*lower,=0A+=09=09=09= =09=09=09=09=09WalTimeBoundary=20*upper);=0A+static=20void=20= ProbeLowerBoundary(WalTimeBoundary=20*boundary,=0A+=09=09=09=09=09=09=09=20= =20=20TimestampTz=20time,=20XLogRecPtr=20lsn,=0A+=09=09=09=09=09=09=09=20= =20=20int=20segment_index);=0A+static=20void=20= ProbeUpperBoundary(WalTimeBoundary=20*boundary,=0A+=09=09=09=09=09=09=09=20= =20=20TimestampTz=20time,=20XLogRecPtr=20lsn,=0A+=09=09=09=09=09=09=09=20= =20=20int=20segment_index);=0A=20=0A=20/*=0A=20=20*=20Return=20the=20LSN=20= up=20to=20which=20the=20server=20has=20WAL,=20and=20optionally=20its=20= timeline.=0A@@=20-223,6=20+265,46=20@@=20wal_time_segment_cmp(const=20= void=20*a,=20const=20void=20*b)=0A=20=09return=200;=0A=20}=0A=20=0A+/*=0A= +=20*=20Probe=20a=20timestamped=20record=20at=20or=20before=20a=20= requested=20time=20boundary.=20=20Among=0A+=20*=20records=20examined=20= so=20far,=20prefer=20the=20latest=20time,=20breaking=20ties=20in=20favor=0A= +=20*=20of=20the=20earlier=20WAL=20record.=20=20The=20caller=20only=20= passes=20qualifying=20records,=20so=0A+=20*=20a=20greater=20timestamp=20= is=20closer=20to=20the=20requested=20boundary.=0A+=20*/=0A+static=20void=0A= +ProbeLowerBoundary(WalTimeBoundary=20*boundary,=20TimestampTz=20time,=0A= +=09=09=09=09=20=20=20XLogRecPtr=20lsn,=20int=20segment_index)=0A+{=0A+=09= if=20(!boundary->found=20||=20time=20>=20boundary->time=20||=0A+=09=09= (time=20=3D=3D=20boundary->time=20&&=20lsn=20<=20boundary->lsn))=0A+=09{=0A= +=09=09boundary->found=20=3D=20true;=0A+=09=09boundary->time=20=3D=20= time;=0A+=09=09boundary->lsn=20=3D=20lsn;=0A+=09=09= boundary->segment_index=20=3D=20segment_index;=0A+=09}=0A+}=0A+=0A+/*=0A= +=20*=20Probe=20a=20timestamped=20record=20at=20or=20after=20a=20= requested=20time=20boundary.=20=20Among=0A+=20*=20records=20examined=20= so=20far,=20prefer=20the=20earliest=20time,=20breaking=20ties=20in=20= favor=20of=0A+=20*=20the=20later=20WAL=20record.=20=20The=20caller=20= only=20passes=20qualifying=20records,=20so=20a=0A+=20*=20smaller=20= timestamp=20is=20closer=20to=20the=20requested=20boundary.=0A+=20*/=0A= +static=20void=0A+ProbeUpperBoundary(WalTimeBoundary=20*boundary,=20= TimestampTz=20time,=0A+=09=09=09=09=20=20=20XLogRecPtr=20lsn,=20int=20= segment_index)=0A+{=0A+=09if=20(!boundary->found=20||=20time=20<=20= boundary->time=20||=0A+=09=09(time=20=3D=3D=20boundary->time=20&&=20lsn=20= >=20boundary->lsn))=0A+=09{=0A+=09=09boundary->found=20=3D=20true;=0A+=09= =09boundary->time=20=3D=20time;=0A+=09=09boundary->lsn=20=3D=20lsn;=0A+=09= =09boundary->segment_index=20=3D=20segment_index;=0A+=09}=0A+}=0A+=0A=20= /*=0A=20=20*=20Get=20the=20WAL=20segments=20that=20form=20the=20history=20= of=20the=20server's=20current=0A=20=20*=20timeline.=20=20Other=20= timelines=20may=20have=20files=20with=20the=20same=20segment=20number=20= in=0A@@=20-230,7=20+312,7=20@@=20wal_time_segment_cmp(const=20void=20*a,=20= const=20void=20*b)=0A=20=20*=20as=20read_local_xlog_page_no_wait()=20= does.=20=20Return=20the=20segments=20in=20WAL=20order.=0A=20=20*/=0A=20= static=20WalTimeSegment=20*=0A-GetWalTimeSegments(int=20*nsegments)=0A= +GetWalTimeSegments(int=20*nsegments,=20XLogRecPtr=20*current_lsn_out)=0A= =20{=0A=20=09WalTimeSegment=20*segments=20=3D=20NULL;=0A=20=09DIR=09=09=20= =20=20*dir;=0A@@=20-242,6=20+324,8=20@@=20GetWalTimeSegments(int=20= *nsegments)=0A=20=09int=09=09=09count=20=3D=200;=0A=20=0A=20=09= current_lsn=20=3D=20GetCurrentLSN(¤t_tli);=0A+=09if=20= (current_lsn_out=20!=3D=20NULL)=0A+=09=09*current_lsn_out=20=3D=20= current_lsn;=0A=20=0A=20=09history=20=3D=20= readTimeLineHistory(current_tli);=0A=20=09dir=20=3D=20= AllocateDir(XLOGDIR);=0A@@=20-297,6=20+381,140=20@@=20= GetWalTimeSegments(int=20*nsegments)=0A=20=09return=20segments;=0A=20}=0A= =20=0A+/*=0A+=20*=20Approximately=20locate=20the=20segment=20containing=20= target_time=20by=20binary=20search.=0A+=20*=20Record=20timestamps=20are=20= expected=20to=20generally=20increase=20with=20WAL=20position.=0A+=20*=20= Remove=20segments=20without=20timestamped=20records=20from=20the=20= search=20candidates,=0A+=20*=20since=20they=20provide=20no=20value=20= with=20which=20to=20choose=20either=20half.=0A+=20*/=0A+static=20int=0A= +FindWalTimeCandidate(WalTimeSegment=20*segments,=20int=20= *search_segments,=0A+=09=09=09=09=09=20int=20*nsearch_segments,=0A+=09=09= =09=09=09=20TimestampTz=20target_time,=20bool=20search_left,=0A+=09=09=09= =09=09=20TimestampTz=20wanted_start,=20TimestampTz=20wanted_end,=0A+=09=09= =09=09=09=20int=20*candidate_position,=20int=20*nscanned)=0A+{=0A+=09int=09= =09=09left=20=3D=200;=0A+=09int=09=09=09right=20=3D=20*nsearch_segments=20= -=201;=0A+=09int=09=09=09result;=0A+=0A+=09while=20(left=20<=3D=20right)=0A= +=09{=0A+=09=09int=09=09=09middle=20=3D=20left=20+=20(right=20-=20left)=20= /=202;=0A+=09=09int=09=09=09segment_index=20=3D=20= search_segments[middle];=0A+=09=09WalTimeSegment=20*segment=20=3D=20= &segments[segment_index];=0A+=0A+=09=09if=20(!segment->scanned)=0A+=09=09= {=0A+=09=09=09ScanWalTimeSegment(segment,=20segment_index,=20= wanted_start,=20wanted_end);=0A+=09=09=09(*nscanned)++;=0A+=09=09}=0A+=0A= +=09=09if=20(!segment->has_timestamp)=0A+=09=09{=0A+=09=09=09= memmove(&search_segments[middle],=20&search_segments[middle=20+=201],=0A= +=09=09=09=09=09(*nsearch_segments=20-=20middle=20-=201)=20*=20= sizeof(int));=0A+=09=09=09(*nsearch_segments)--;=0A+=09=09=09right--;=0A= +=09=09=09continue;=0A+=09=09}=0A+=09=09else=20if=20(target_time=20<=20= segment->min_time)=0A+=09=09=09right=20=3D=20middle=20-=201;=0A+=09=09= else=20if=20(target_time=20>=20segment->max_time)=0A+=09=09=09left=20=3D=20= middle=20+=201;=0A+=09=09else=0A+=09=09{=0A+=09=09=09if=20= (candidate_position=20!=3D=20NULL)=0A+=09=09=09=09*candidate_position=20= =3D=20middle;=0A+=09=09=09return=20search_segments[middle];=0A+=09=09}=0A= +=09}=0A+=0A+=09if=20(*nsearch_segments=20=3D=3D=200)=0A+=09=09= ereport(ERROR,=0A+=09=09=09=09= errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),=0A+=09=09=09=09= errmsg("could=20not=20locate=20a=20WAL=20time=20boundary"),=0A+=09=09=09=09= errdetail("No=20retained=20WAL=20segment=20contains=20a=20timestamped=20= record."));=0A+=0A+=09if=20(search_left)=0A+=09=09result=20=3D=20= Max(right,=200);=0A+=09else=0A+=09=09result=20=3D=20Min(left,=20= *nsearch_segments=20-=201);=0A+=0A+=09if=20(candidate_position=20!=3D=20= NULL)=0A+=09=09*candidate_position=20=3D=20result;=0A+=09return=20= search_segments[result];=0A+}=0A+=0A+/*=0A+=20*=20Inspect=20timestamped=20= records=20beginning=20in=20one=20segment=20and=20save=20its=20time=0A+=20= *=20range=20and=20best=20boundary=20candidates.=20=20XLogReadRecord()=20= may=20read=20the=20following=0A+=20*=20segment=20to=20assemble=20a=20= record=20crossing=20the=20boundary,=20but=20that=20record=20is=0A+=20*=20= attributed=20to=20the=20segment=20containing=20its=20starting=20LSN.=0A+=20= */=0A+static=20void=0A+ScanWalTimeSegment(WalTimeSegment=20*segment,=20= int=20segment_index,=0A+=09=09=09=09=20=20=20TimestampTz=20wanted_start,=20= TimestampTz=20wanted_end)=0A+{=0A+=09XLogRecPtr=09seg_start=20=3D=20= segment->segno=20*=20wal_segment_size;=0A+=09XLogRecPtr=09seg_end=20=3D=20= seg_start=20+=20wal_segment_size;=0A+=09XLogReaderState=20*xlogreader;=0A= +=0A+=09Assert(!segment->scanned);=0A+=09segment->scanned=20=3D=20true;=0A= +=09xlogreader=20=3D=20InitXLogReaderState(seg_start);=0A+=0A+=09while=20= (ReadNextXLogRecord(xlogreader))=0A+=09{=0A+=09=09TimestampTz=20= record_time;=0A+=0A+=09=09if=20(xlogreader->ReadRecPtr=20>=3D=20seg_end)=0A= +=09=09=09break;=0A+=0A+=09=09if=20(!GetXLogRecordTimestamp(xlogreader,=20= &record_time))=0A+=09=09=09continue;=0A+=0A+=09=09if=20= (!segment->has_timestamp)=0A+=09=09{=0A+=09=09=09segment->has_timestamp=20= =3D=20true;=0A+=09=09=09segment->min_time=20=3D=20segment->max_time=20=3D=20= record_time;=0A+=09=09}=0A+=09=09else=0A+=09=09{=0A+=09=09=09= segment->min_time=20=3D=20Min(segment->min_time,=20record_time);=0A+=09=09= =09segment->max_time=20=3D=20Max(segment->max_time,=20record_time);=0A+=09= =09}=0A+=0A+=09=09if=20(record_time=20<=3D=20wanted_start)=0A+=09=09=09= ProbeLowerBoundary(&segment->lower,=20record_time,=0A+=09=09=09=09=09=09=09= =20=20=20xlogreader->ReadRecPtr,=20segment_index);=0A+=0A+=09=09else=20= if=20(record_time=20>=3D=20wanted_end)=0A+=09=09=09= ProbeUpperBoundary(&segment->upper,=20record_time,=0A+=09=09=09=09=09=09=09= =20=20=20xlogreader->ReadRecPtr,=20segment_index);=0A+=0A+=09=09= CHECK_FOR_INTERRUPTS();=0A+=09}=0A+=0A+=09= pfree(xlogreader->private_data);=0A+=09XLogReaderFree(xlogreader);=0A+}=0A= +=0A+/*=20Merge=20one=20segment's=20boundary=20candidates=20into=20the=20= result.=20*/=0A+static=20void=0A+MergeWalTimeSegment(WalTimeSegment=20= *segment,=20WalTimeBoundary=20*lower,=0A+=09=09=09=09=09WalTimeBoundary=20= *upper)=0A+{=0A+=09Assert(segment->scanned);=0A+=0A+=09if=20(lower=20!=3D=20= NULL=20&&=20segment->lower.found)=0A+=09=09ProbeLowerBoundary(lower,=20= segment->lower.time,=20segment->lower.lsn,=0A+=09=09=09=09=09=09=20=20=20= segment->lower.segment_index);=0A+=09if=20(upper=20!=3D=20NULL=20&&=20= segment->upper.found)=0A+=09=09ProbeUpperBoundary(upper,=20= segment->upper.time,=20segment->upper.lsn,=0A+=09=09=09=09=09=09=20=20=20= segment->upper.segment_index);=0A+}=0A+=0A=20/*=0A=20=20*=20Output=20= values=20that=20make=20up=20a=20row=20describing=20caller's=20WAL=20= record.=0A=20=20*=0A@@=20-623,6=20+841,267=20@@=20= pg_get_wal_record_info(PG_FUNCTION_ARGS)=0A=20#undef=20= PG_GET_WAL_RECORD_INFO_COLS=0A=20}=0A=20=0A+/*=0A+=20*=20Locate=20a=20= WAL=20region=20around=20a=20wall-clock=20time=20range=20using=20= timestamped=20WAL=0A+=20*=20records.=0A+=20*=0A+=20*=20Locate=20each=20= boundary=20by=20an=20approximate=20binary=20search=20over=20retained=20= WAL=0A+=20*=20segments,=20assuming=20that=20record=20timestamps=20= generally=20increase=20with=20WAL=0A+=20*=20position.=20=20Also=20= examine=20one=20preceding=20segment=20for=20the=20lower=20boundary=20and=0A= +=20*=20one=20following=20segment=20for=20the=20upper=20boundary=20to=20= allow=20for=20limited=20timestamp=0A+=20*=20reordering.=20=20The=20lower=20= boundary=20uses=20the=20latest=20timestamped=20record=20at=20or=0A+=20*=20= before=20the=20requested=20start=20time,=20while=20the=20upper=20= boundary=20uses=20the=20earliest=0A+=20*=20one=20at=20or=20after=20the=20= requested=20end=20time.=20=20A=20future=20upper=20bound=20is=20first=0A+=20= *=20capped=20at=20the=20current=20time.=20=20If=20no=20upper=20= timestamped=20record=20is=20available,=0A+=20*=20use=20the=20current=20= WAL=20position.=20=20On=20success,=20the=20boundaries=20form=20a=20= forward=0A+=20*=20WAL=20range,=20but=20are=20not=20necessarily=20the=20= globally=20closest=20timestamped=20records=0A+=20*=20to=20the=20= requested=20bounds.=0A+=20*/=0A+Datum=0A= +pg_get_wal_location_at_time(PG_FUNCTION_ARGS)=0A+{=0A+#define=20= PG_GET_WAL_LOCATION_AT_TIME_COLS=204=0A+=09TimestampTz=20target_time=20=3D= =20PG_GETARG_TIMESTAMPTZ(0);=0A+=09Interval=20=20=20*before=20=3D=20= PG_GETARG_INTERVAL_P(1);=0A+=09Interval=20=20=20*after=20=3D=20= PG_GETARG_INTERVAL_P(2);=0A+=09Interval=09zero=20=3D=20{0};=0A+=09= Interval=09one_day=20=3D=20{.day=20=3D=201};=0A+=09TimestampTz=20= wanted_start;=0A+=09TimestampTz=20wanted_end;=0A+=09TimestampTz=20= current_time;=0A+=09XLogRecPtr=09current_lsn;=0A+=09XLogSegNo=09= current_segno;=0A+=09WalTimeSegment=20*segments;=0A+=09WalTimeBoundary=20= lower=20=3D=20{0};=0A+=09WalTimeBoundary=20upper=20=3D=20{0};=0A+=09= Datum=09=09values[PG_GET_WAL_LOCATION_AT_TIME_COLS];=0A+=09bool=09=09= nulls[PG_GET_WAL_LOCATION_AT_TIME_COLS]=20=3D=20{0};=0A+=09TupleDesc=09= tupdesc;=0A+=09HeapTuple=09tuple;=0A+=09int=09=09=09nsegments;=0A+=09int=09= =09=20=20=20*search_segments;=0A+=09int=09=09=09nsearch_segments;=0A+=09= int=09=09=09lower_candidate;=0A+=09int=09=09=09upper_candidate;=0A+=09= int=09=09=09lower_candidate_position;=0A+=09int=09=09=09= nupper_search_segments;=0A+=09int=09=09=09lower_start;=0A+=09int=09=09=09= upper_end;=0A+=09int=09=09=09upper_segment_index;=0A+=09int=09=09=09= nscanned=20=3D=200;=0A+=09bool=09=09upper_bound_capped=20=3D=20false;=0A= +=09char=09=09lower_fname[MAXFNAMELEN];=0A+=09char=09=09= upper_fname[MAXFNAMELEN];=0A+=0A+=09if=20= (TIMESTAMP_NOT_FINITE(target_time))=0A+=09=09ereport(ERROR,=0A+=09=09=09=09= errcode(ERRCODE_INVALID_PARAMETER_VALUE),=0A+=09=09=09=09errmsg("target=20= time=20must=20be=20finite"));=0A+=09if=20(INTERVAL_NOT_FINITE(before)=20= ||=0A+=09=09DatumGetInt32(DirectFunctionCall2(interval_cmp,=0A+=09=09=09=09= =09=09=09=09=09=09=20=20IntervalPGetDatum(before),=0A+=09=09=09=09=09=09=09= =09=09=09=20=20IntervalPGetDatum(&zero)))=20<=3D=200)=0A+=09=09= ereport(ERROR,=0A+=09=09=09=09errcode(ERRCODE_INVALID_PARAMETER_VALUE),=0A= +=09=09=09=09errmsg("before=20interval=20must=20be=20finite=20and=20= greater=20than=20zero"));=0A+=09if=20= (DatumGetInt32(DirectFunctionCall2(interval_cmp,=0A+=09=09=09=09=09=09=09= =09=09=09=20=20IntervalPGetDatum(before),=0A+=09=09=09=09=09=09=09=09=09=09= =20=20IntervalPGetDatum(&one_day)))=20>=200)=0A+=09=09ereport(ERROR,=0A+=09= =09=09=09errcode(ERRCODE_INVALID_PARAMETER_VALUE),=0A+=09=09=09=09= errmsg("before=20interval=20must=20not=20exceed=20one=20day"));=0A+=09if=20= (INTERVAL_NOT_FINITE(after)=20||=0A+=09=09= DatumGetInt32(DirectFunctionCall2(interval_cmp,=0A+=09=09=09=09=09=09=09=09= =09=09=20=20IntervalPGetDatum(after),=0A+=09=09=09=09=09=09=09=09=09=09=20= =20IntervalPGetDatum(&zero)))=20<=3D=200)=0A+=09=09ereport(ERROR,=0A+=09=09= =09=09errcode(ERRCODE_INVALID_PARAMETER_VALUE),=0A+=09=09=09=09= errmsg("after=20interval=20must=20be=20finite=20and=20greater=20than=20= zero"));=0A+=09if=20(DatumGetInt32(DirectFunctionCall2(interval_cmp,=0A+=09= =09=09=09=09=09=09=09=09=09=20=20IntervalPGetDatum(after),=0A+=09=09=09=09= =09=09=09=09=09=09=20=20IntervalPGetDatum(&one_day)))=20>=200)=0A+=09=09= ereport(ERROR,=0A+=09=09=09=09errcode(ERRCODE_INVALID_PARAMETER_VALUE),=0A= +=09=09=09=09errmsg("after=20interval=20must=20not=20exceed=20one=20= day"));=0A+=0A+=09/*=20The=20timestamp=20functions=20provide=20the=20= normal=20overflow=20checks.=20*/=0A+=09wanted_start=20=3D=20= DatumGetTimestampTz(DirectFunctionCall2(timestamptz_mi_interval,=0A+=09=09= =09=09=09=09=09=09=09=09=09=09=09=09=20=20=20= TimestampTzGetDatum(target_time),=0A+=09=09=09=09=09=09=09=09=09=09=09=09= =09=09=20=20=20IntervalPGetDatum(before)));=0A+=09wanted_end=20=3D=20= DatumGetTimestampTz(DirectFunctionCall2(timestamptz_pl_interval,=0A+=09=09= =09=09=09=09=09=09=09=09=09=09=09=09=20TimestampTzGetDatum(target_time),=0A= +=09=09=09=09=09=09=09=09=09=09=09=09=09=09=20= IntervalPGetDatum(after)));=0A+=09current_time=20=3D=20= GetCurrentTimestamp();=0A+=0A+=09/*=20Cap=20a=20future=20upper=20bound=20= at=20the=20time=20currently=20available.=20*/=0A+=09if=20(wanted_end=20>=20= current_time)=0A+=09{=0A+=09=09if=20(wanted_start=20>=3D=20current_time)=0A= +=09=09=09ereport(ERROR,=0A+=09=09=09=09=09= errcode(ERRCODE_INVALID_PARAMETER_VALUE),=0A+=09=09=09=09=09= errmsg("requested=20time=20follows=20the=20available=20WAL=20range"),=0A= +=09=09=09=09=09errdetail("The=20requested=20lower=20bound=20is=20not=20= earlier=20than=20the=20current=20time."));=0A+=0A+=09=09wanted_end=20=3D=20= current_time;=0A+=09=09upper_bound_capped=20=3D=20true;=0A+=09}=0A+=0A+=09= if=20(get_call_result_type(fcinfo,=20NULL,=20&tupdesc)=20!=3D=20= TYPEFUNC_COMPOSITE)=0A+=09=09elog(ERROR,=20"return=20type=20must=20be=20= a=20row=20type");=0A+=0A+=09segments=20=3D=20= GetWalTimeSegments(&nsegments,=20¤t_lsn);=0A+=09= XLByteToPrevSeg(current_lsn,=20current_segno,=20wal_segment_size);=0A+=0A= +=09/*=0A+=09=20*=20A=20capped=20upper=20bound=20may=20need=20the=20= current=20WAL=20position=20as=20its=20endpoint.=0A+=09=20*=20Detect=20a=20= missing=20WAL=20tail=20before=20decoding=20any=20candidate=20segments.=0A= +=09=20*/=0A+=09if=20(upper_bound_capped=20&&=0A+=09=09= segments[nsegments=20-=201].segno=20!=3D=20current_segno)=0A+=09=09= ereport(ERROR,=0A+=09=09=09=09errcode(ERRCODE_DATA_EXCEPTION),=0A+=09=09=09= =09errmsg("WAL=20segment=20needed=20for=20the=20time=20search=20is=20= missing"),=0A+=09=09=09=09errdetail("The=20current=20WAL=20LSN=20is=20= %X/%08X,=20and=20segment=20"=20UINT64_FORMAT=20"=20is=20not=20present=20= in=20pg_wal.",=0A+=09=09=09=09=09=09=20=20LSN_FORMAT_ARGS(current_lsn),=0A= +=09=09=09=09=09=09=20=20(uint64)=20current_segno));=0A+=0A+=09= search_segments=20=3D=20palloc_array(int,=20nsegments);=0A+=09for=20(int=20= i=20=3D=200;=20i=20<=20nsegments;=20i++)=0A+=09=09search_segments[i]=20=3D= =20i;=0A+=09nsearch_segments=20=3D=20nsegments;=0A+=09lower_candidate=20= =3D=20FindWalTimeCandidate(segments,=20search_segments,=0A+=09=09=09=09=09= =09=09=09=09=09=20=20=20&nsearch_segments,=20wanted_start,=0A+=09=09=09=09= =09=09=09=09=09=09=20=20=20true,=20wanted_start,=20wanted_end,=0A+=09=09=09= =09=09=09=09=09=09=09=20=20=20&lower_candidate_position,=0A+=09=09=09=09=09= =09=09=09=09=09=20=20=20&nscanned);=0A+=0A+=09/*=20Search=20for=20the=20= later=20upper=20boundary=20from=20the=20lower=20candidate=20onward.=20*/=0A= +=09nupper_search_segments=20=3D=20nsearch_segments=20-=20= lower_candidate_position;=0A+=09upper_candidate=20=3D=20= FindWalTimeCandidate(segments,=0A+=09=09=09=09=09=09=09=09=09=09=20=20=20= search_segments=20+=20lower_candidate_position,=0A+=09=09=09=09=09=09=09=09= =09=09=20=20=20&nupper_search_segments,=20wanted_end,=0A+=09=09=09=09=09=09= =09=09=09=09=20=20=20false,=20wanted_start,=20wanted_end,=0A+=09=09=09=09= =09=09=09=09=09=09=20=20=20NULL,=0A+=09=09=09=09=09=09=09=09=09=09=20=20=20= &nscanned);=0A+=09XLogFileName(lower_fname,=20= segments[lower_candidate].tli,=0A+=09=09=09=09=20= segments[lower_candidate].segno,=20wal_segment_size);=0A+=09= XLogFileName(upper_fname,=20segments[upper_candidate].tli,=0A+=09=09=09=09= =20segments[upper_candidate].segno,=20wal_segment_size);=0A+=09= ereport(DEBUG1,=0A+=09=09=09errmsg_internal("WAL=20time=20search=20= selected=20lower=20segment=20%s=20and=20upper=20segment=20%s=20from=20%d=20= retained=20segments",=0A+=09=09=09=09=09=09=09lower_fname,=20= upper_fname,=0A+=09=09=09=09=09=09=09nsegments));=0A+=0A+=09/*=0A+=09=20= *=20Allow=20for=20limited=20timestamp=20reordering=20by=20examining=20= one=20preceding=0A+=09=20*=20segment=20for=20the=20lower=20boundary=20= and=20one=20following=20segment=20for=20the=20upper=0A+=09=20*=20= boundary.=20=20Do=20not=20extend=20across=20a=20missing=20segment.=0A+=09= =20*/=0A+=09lower_start=20=3D=20lower_candidate;=0A+=09if=20(lower_start=20= >=200=20&&=0A+=09=09segments[lower_start=20-=201].segno=20+=201=20=3D=3D=20= segments[lower_start].segno)=0A+=09=09lower_start--;=0A+=09upper_end=20=3D= =20upper_candidate;=0A+=09if=20(upper_end=20+=201=20<=20nsegments=20&&=0A= +=09=09segments[upper_end].segno=20+=201=20=3D=3D=20segments[upper_end=20= +=201].segno)=0A+=09=09upper_end++;=0A+=0A+=09for=20(int=20i=20=3D=20= lower_start;=20i=20<=3D=20lower_candidate;=20i++)=0A+=09{=0A+=09=09if=20= (!segments[i].scanned)=0A+=09=09{=0A+=09=09=09= ScanWalTimeSegment(&segments[i],=20i,=20wanted_start,=20wanted_end);=0A+=09= =09=09nscanned++;=0A+=09=09}=0A+=09=09MergeWalTimeSegment(&segments[i],=20= &lower,=20NULL);=0A+=09}=0A+=09for=20(int=20i=20=3D=20upper_candidate;=20= i=20<=3D=20upper_end;=20i++)=0A+=09{=0A+=09=09if=20= (!segments[i].scanned)=0A+=09=09{=0A+=09=09=09= ScanWalTimeSegment(&segments[i],=20i,=20wanted_start,=20wanted_end);=0A+=09= =09=09nscanned++;=0A+=09=09}=0A+=09=09MergeWalTimeSegment(&segments[i],=20= NULL,=20&upper);=0A+=09}=0A+=0A+=09ereport(DEBUG1,=0A+=09=09=09= errmsg_internal("WAL=20time=20search=20decoded=20%d=20of=20%d=20retained=20= segments",=0A+=09=09=09=09=09=09=09nscanned,=20nsegments));=0A+=0A+=09if=20= (!lower.found)=0A+=09=09ereport(ERROR,=0A+=09=09=09=09= errcode(ERRCODE_INVALID_PARAMETER_VALUE),=0A+=09=09=09=09errmsg("could=20= not=20locate=20a=20WAL=20time=20boundary"),=0A+=09=09=09=09= errdetail("The=20WAL=20search=20did=20not=20find=20a=20timestamped=20= record=20at=20or=20before=20the=20requested=20lower=20bound."));=0A+=0A+=09= /*=0A+=09=20*=20There=20may=20be=20no=20timestamped=20record=20after=20= the=20requested=20upper=20bound=20on=20a=0A+=09=20*=20quiet=20system.=20=20= In=20that=20case,=20use=20the=20current=20WAL=20position=20so=20that=20= the=0A+=09=20*=20returned=20range=20still=20includes=20all=20WAL=20= currently=20available.=0A+=09=20*/=0A+=09if=20(!upper.found)=0A+=09{=0A+=09= =09upper.lsn=20=3D=20current_lsn;=0A+=0A+=09=09/*=0A+=09=09=20*=20The=20= last=20enumerated=20segment=20should=20contain=20current_lsn.=20=20= Verify=0A+=09=09=20*=20this=20because=20pg_wal=20can=20change=20while=20= it=20is=20being=20enumerated;=0A+=09=09=20*=20otherwise=20the=20= continuity=20check=20below=20would=20not=20cover=20a=20missing=20WAL=0A+=09= =09=20*=20tail.=0A+=09=09=20*/=0A+=09=09upper_segment_index=20=3D=20= nsegments=20-=201;=0A+=09=09if=20(segments[upper_segment_index].segno=20= !=3D=20current_segno)=0A+=09=09=09ereport(ERROR,=0A+=09=09=09=09=09= errcode(ERRCODE_DATA_EXCEPTION),=0A+=09=09=09=09=09errmsg("WAL=20segment=20= needed=20for=20the=20time=20search=20is=20missing"),=0A+=09=09=09=09=09= errdetail("The=20start=20LSN=20is=20%X/%08X,=20the=20end=20LSN=20is=20= %X/%08X,=20and=20segment=20"=20UINT64_FORMAT=20"=20is=20not=20present=20= in=20pg_wal.",=0A+=09=09=09=09=09=09=09=20=20LSN_FORMAT_ARGS(lower.lsn),=0A= +=09=09=09=09=09=09=09=20=20LSN_FORMAT_ARGS(upper.lsn),=0A+=09=09=09=09=09= =09=09=20=20(uint64)=20current_segno));=0A+=09}=0A+=09else=0A+=09=09= upper_segment_index=20=3D=20upper.segment_index;=0A+=0A+=09if=20= (lower.lsn=20>=3D=20upper.lsn)=0A+=09=09ereport(ERROR,=0A+=09=09=09=09= errcode(ERRCODE_DATA_EXCEPTION),=0A+=09=09=09=09errmsg("could=20not=20= find=20a=20valid=20WAL=20range=20for=20the=20requested=20time=20= window"),=0A+=09=09=09=09errdetail("The=20matching=20lower=20boundary=20= does=20not=20precede=20the=20upper=20boundary=20in=20WAL."));=0A+=0A+=09= Assert(lower.segment_index=20>=3D=200=20&&=20lower.segment_index=20<=20= nsegments);=0A+=09Assert(upper_segment_index=20>=3D=200=20&&=20= upper_segment_index=20<=20nsegments);=0A+=09for=20(int=20i=20=3D=20= lower.segment_index=20+=201;=20i=20<=3D=20upper_segment_index;=20i++)=0A= +=09{=0A+=09=09/*=0A+=09=09=20*=20The=20returned=20LSN=20range=20must=20= be=20continuously=20readable=20from=20pg_wal;=0A+=09=09=20*=20otherwise,=20= functions=20such=20as=20pg_get_wal_records_info()=20would=20fail=0A+=09=09= =20*=20when=20scanning=20the=20range=20across=20a=20missing=20segment.=0A= +=09=09=20*/=0A+=09=09if=20(segments[i=20-=201].segno=20+=201=20!=3D=20= segments[i].segno)=0A+=09=09=09ereport(ERROR,=0A+=09=09=09=09=09= errcode(ERRCODE_DATA_EXCEPTION),=0A+=09=09=09=09=09errmsg("WAL=20segment=20= needed=20for=20the=20time=20search=20is=20missing"),=0A+=09=09=09=09=09= errdetail("The=20start=20LSN=20is=20%X/%08X,=20the=20end=20LSN=20is=20= %X/%08X,=20and=20segment=20"=20UINT64_FORMAT=20"=20is=20not=20present=20= in=20pg_wal.",=0A+=09=09=09=09=09=09=09=20=20LSN_FORMAT_ARGS(lower.lsn),=0A= +=09=09=09=09=09=09=09=20=20LSN_FORMAT_ARGS(upper.lsn),=0A+=09=09=09=09=09= =09=09=20=20(uint64)=20(segments[i=20-=201].segno=20+=201)));=0A+=09}=0A= +=0A+=09values[0]=20=3D=20TimestampTzGetDatum(lower.time);=0A+=09= values[1]=20=3D=20LSNGetDatum(lower.lsn);=0A+=09if=20(upper.found)=0A+=09= =09values[2]=20=3D=20TimestampTzGetDatum(upper.time);=0A+=09else=0A+=09=09= nulls[2]=20=3D=20true;=0A+=09values[3]=20=3D=20LSNGetDatum(upper.lsn);=0A= +=0A+=09pfree(segments);=0A+=09tuple=20=3D=20heap_form_tuple(tupdesc,=20= values,=20nulls);=0A+=09PG_RETURN_DATUM(HeapTupleGetDatum(tuple));=0A= +#undef=20PG_GET_WAL_LOCATION_AT_TIME_COLS=0A+}=0A+=0A=20/*=0A=20=20*=20= List=20the=20retained=20WAL=20segment=20files=20intersecting=20= [start_lsn,=20end_lsn),=20or=0A=20=20*=20the=20segment=20containing=20= start_lsn=20when=20end_lsn=20is=20omitted=20or=20equal=20to=20it.=0A@@=20= -676,7=20+1155,7=20@@=20pg_get_wal_files(PG_FUNCTION_ARGS)=0A=20=09=09= last_segno=20=3D=20first_segno;=0A=20=09else=0A=20=09=09= XLByteToPrevSeg(end_lsn,=20last_segno,=20wal_segment_size);=0A-=09= segments=20=3D=20GetWalTimeSegments(&nsegments);=0A+=09segments=20=3D=20= GetWalTimeSegments(&nsegments,=20NULL);=0A=20=0A=20=09for=20(XLogSegNo=20= segno=20=3D=20first_segno;;=20segno++)=0A=20=09{=0Adiff=20--git=20= a/contrib/pg_walinspect/sql/pg_walinspect.sql=20= b/contrib/pg_walinspect/sql/pg_walinspect.sql=0Aindex=20= 3176a17d855..4b37a25fa41=20100644=0A---=20= a/contrib/pg_walinspect/sql/pg_walinspect.sql=0A+++=20= b/contrib/pg_walinspect/sql/pg_walinspect.sql=0A@@=20-75,6=20+75,117=20= @@=20SELECT=20count(*)=20=3D=201=20AS=20future_end_ok=0A=20FROM=20= pg_get_wal_files(pg_current_wal_lsn(),=20'FFFFFFFF/FFFFFFFF');=0A=20= SELECT=20*=20FROM=20pg_get_wal_files('0/0',=20'0/1');=0A=20=0A+--=20= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A+--=20Tests=20for=20= locating=20WAL=20by=20timestamps=20stored=20in=20WAL=20records=0A+--=20= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A+=0A+--=20Put=20= two=20WAL-logged=20transaction=20commits=20between=20the=20requested=20= boundaries.=0A+INSERT=20INTO=20sample_tbl=20VALUES=20(5,=205);=0A+SELECT=20= clock_timestamp()=20AS=20wal_time_lower=20\gset=0A+INSERT=20INTO=20= sample_tbl=20VALUES=20(6,=206);=0A+INSERT=20INTO=20sample_tbl=20VALUES=20= (10,=2010);=0A+SELECT=20clock_timestamp()=20AS=20wal_time_upper=20\gset=0A= +INSERT=20INTO=20sample_tbl=20VALUES=20(13,=2013);=0A+=0A+SELECT=20= start_timestamp=20<=3D=20:'wal_time_lower'::timestamptz=20-=20interval=20= '1=20microsecond'=0A+=20=20=20=20=20=20=20=20=20AS=20start_ok,=0A+=20=20=20= =20=20=20=20end_timestamp=20>=3D=20:'wal_time_upper'::timestamptz=20AS=20= end_ok,=0A+=20=20=20=20=20=20=20start_lsn=20<=20end_lsn=20AS=20lsn_ok=0A= +FROM=20pg_get_wal_location_at_time(:'wal_time_lower',=0A+=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20before=20=3D>=20interval=20'1=20microsecond',=0A+=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20after=20=3D>=20:'wal_time_upper'::timestamptz=20-=0A+=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20:'wal_time_lower'::timestamptz);=0A= +=0A+--=20A=20window=20containing=20one=20timestamped=20record=20is=20= enclosed=20by=20outer=20anchors.=0A+SELECT=20clock_timestamp()=20AS=20= single_time_lower=20\gset=0A+INSERT=20INTO=20sample_tbl=20VALUES=20(12,=20= 12);=0A+SELECT=20clock_timestamp()=20AS=20single_time_upper=20\gset=0A= +INSERT=20INTO=20sample_tbl=20VALUES=20(14,=2014);=0A+SELECT=20= location.start_timestamp=20<=3D=20:'single_time_lower'::timestamptz=0A+=20= =20=20=20=20=20=20=20=20AS=20start_ok,=0A+=20=20=20=20=20=20=20= location.end_timestamp=20>=3D=20:'single_time_upper'::timestamptz=0A+=20=20= =20=20=20=20=20=20=20AS=20end_ok,=0A+=20=20=20=20=20=20=20= location.start_lsn=20<=20location.end_lsn=20AS=20lsn_ok=0A+FROM=20= pg_get_wal_location_at_time(:'single_time_lower',=0A+=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20interval=20'1=20microsecond',=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= :'single_time_upper'::timestamptz=20-=0A+=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= :'single_time_lower'::timestamptz)=20AS=20location;=0A+=0A+--=20Exercise=20= a=20time=20window=20containing=20a=20COMMIT=20PREPARED=20record.=20=20= Concurrent=0A+--=20activity=20can=20cause=20another=20timestamped=20= record=20to=20be=20selected=20as=20the=20anchor.=0A+INSERT=20INTO=20= sample_tbl=20VALUES=20(11,=2011);=0A+BEGIN;=0A+INSERT=20INTO=20= sample_tbl=20VALUES=20(7,=207);=0A+PREPARE=20TRANSACTION=20= 'regress_pg_walinspect_time';=0A+SELECT=20clock_timestamp()=20AS=20= prepared_time_target=20\gset=0A+COMMIT=20PREPARED=20= 'regress_pg_walinspect_time';=0A+SELECT=20clock_timestamp()=20AS=20= prepared_time_upper=20\gset=0A+INSERT=20INTO=20sample_tbl=20VALUES=20= (15,=2015);=0A+=0A+SELECT=20record_type=20IN=20('COMMIT',=20= 'COMMIT_PREPARED',=20'ABORT',=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20'ABORT_PREPARED',=20'RESTORE_POINT')=20AS=20= timestamped_ok=0A+FROM=20= pg_get_wal_location_at_time(:'prepared_time_target',=0A+=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20:'prepared_time_target'::timestamptz=20-=0A+=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20:'wal_time_upper'::timestamptz,=0A+=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= :'prepared_time_upper'::timestamptz=20-=0A+=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= :'prepared_time_target'::timestamptz)=20AS=20location,=0A+=20=20=20=20=20= LATERAL=20pg_get_wal_record_info(location.end_lsn);=0A+=0A+--=20Exercise=20= a=20time=20window=20containing=20restore=20points,=20allowing=20for=20= other=0A+--=20timestamped=20WAL=20records=20generated=20concurrently.=0A= +SELECT=20pg_create_restore_point('regress_wal_time_lower')=20AS=20= restore_lsn=20\gset=0A+SELECT=20clock_timestamp()=20AS=20= restore_time_target=20\gset=0A+SELECT=20= pg_create_restore_point('regress_wal_time_upper')=20AS=20restore_lsn=20= \gset=0A+SELECT=20clock_timestamp()=20AS=20restore_time_upper=20\gset=0A= +INSERT=20INTO=20sample_tbl=20VALUES=20(8,=208);=0A+=0A+SELECT=20= start_info.record_type=20IN=20('COMMIT',=20'COMMIT_PREPARED',=20'ABORT',=0A= +=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20'ABORT_PREPARED',=20'RESTORE_POINT')=20AS=20= start_ok,=0A+=20=20=20=20=20=20=20end_info.record_type=20IN=20('COMMIT',=20= 'COMMIT_PREPARED',=20'ABORT',=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20'ABORT_PREPARED',=20= 'RESTORE_POINT')=20AS=20end_ok=0A+FROM=20= pg_get_wal_location_at_time(:'restore_time_target',=0A+=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20:'restore_time_target'::timestamptz=20-=0A+=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20:'wal_time_upper'::timestamptz,=0A+=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= :'restore_time_upper'::timestamptz=20-=0A+=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= :'restore_time_target'::timestamptz)=20AS=20location,=0A+=20=20=20=20=20= LATERAL=20pg_get_wal_record_info(location.start_lsn)=20AS=20start_info,=0A= +=20=20=20=20=20LATERAL=20pg_get_wal_record_info(location.end_lsn)=20AS=20= end_info;=0A+=0A+--=20A=20future=20upper=20bound=20falls=20back=20to=20= the=20current=20WAL=20position.=0A+SELECT=20clock_timestamp()=20AS=20= current_time_target=20\gset=0A+INSERT=20INTO=20sample_tbl=20VALUES=20(9,=20= 9);=0A+SELECT=20location.start_timestamp=20<=3D=20= :'restore_time_upper'::timestamptz=0A+=20=20=20=20=20=20=20=20=20AS=20= start_ok,=0A+=20=20=20=20=20=20=20location.end_timestamp=20IS=20NULL=20= AS=20current_end_ok,=0A+=20=20=20=20=20=20=20location.end_lsn=20<=3D=20= pg_current_wal_flush_lsn()=20AS=20end_lsn_ok,=0A+=20=20=20=20=20=20=20= location.start_lsn=20<=20location.end_lsn=20AS=20lsn_ok,=0A+=20=20=20=20=20= =20=20EXISTS=20(SELECT=20FROM=20= pg_get_wal_records_info(location.start_lsn,=0A+=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20location.end_lsn)=0A+=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20WHERE=20resource_manager=20=3D=20= 'Heap'=20AND=20record_type=20=3D=20'INSERT')=0A+=20=20=20=20=20=20=20=20=20= AS=20records_ok=0A+FROM=20= pg_get_wal_location_at_time(:'current_time_target',=0A+=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20:'current_time_target'::timestamptz=20-=0A+=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20:'restore_time_upper'::timestamptz,=0A+=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= interval=20'1=20day')=20AS=20location;=0A+=0A+SELECT=20= pg_get_function_arguments(=0A+=20=20= 'pg_get_wal_location_at_time(timestamptz,=20interval,=20= interval)'::regprocedure)=0A+=20=20LIKE=20'%before=20interval=20DEFAULT=20= ''@=201=20min''::interval,=20after=20interval=20DEFAULT=20''@=201=20= min''::interval%'=0A+=20=20AS=20defaults_ok;=0A+SELECT=20*=20FROM=20= pg_get_wal_location_at_time(:'wal_time_lower',=0A+=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20interval=20'0',=20interval=20'1=20second');=0A= +SELECT=20*=20FROM=20pg_get_wal_location_at_time(:'wal_time_lower',=0A+=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20interval=20'1=20second',=20= interval=20'0');=0A+SELECT=20*=20FROM=20= pg_get_wal_location_at_time(:'wal_time_lower',=20interval=20'-1=20= second');=0A+SELECT=20*=20FROM=20= pg_get_wal_location_at_time(:'wal_time_lower',=0A+=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20after=20=3D>=20interval=20'-1=20second');=0A= +SELECT=20*=20FROM=20pg_get_wal_location_at_time(:'wal_time_lower',=0A+=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20before=20=3D>=20interval=20= '1=20day=201=20microsecond');=0A+SELECT=20*=20FROM=20= pg_get_wal_location_at_time(:'wal_time_lower',=0A+=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20after=20=3D>=20interval=20'1=20day=201=20= microsecond');=0A+SELECT=20*=20FROM=20= pg_get_wal_location_at_time(clock_timestamp()=20-=20interval=20'100=20= years');=0A+SELECT=20*=20FROM=20= pg_get_wal_location_at_time(clock_timestamp()=20+=20interval=20'100=20= years');=0A+=0A=20--=20= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A=20--=20Test=20for=20= filtering=20out=20WAL=20records=20of=20a=20particular=20table=0A=20--=20= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A@@=20-134,6=20= +245,8=20@@=20SELECT=20has_function_privilege('regress_pg_walinspect',=0A= =20=20=20'pg_get_wal_stats(pg_lsn,=20pg_lsn,=20boolean)=20',=20= 'EXECUTE');=20--=20no=0A=20SELECT=20= has_function_privilege('regress_pg_walinspect',=0A=20=20=20= 'pg_get_wal_block_info(pg_lsn,=20pg_lsn,=20boolean)=20',=20'EXECUTE');=20= --=20no=0A+SELECT=20has_function_privilege('regress_pg_walinspect',=0A+=20= =20'pg_get_wal_location_at_time(timestamptz,=20interval,=20interval)',=20= 'EXECUTE');=20--=20no=0A=20SELECT=20= has_function_privilege('regress_pg_walinspect',=0A=20=20=20= 'pg_get_wal_files(pg_lsn,=20pg_lsn)',=20'EXECUTE');=20--=20no=0A=20=0A@@=20= -148,6=20+261,8=20@@=20SELECT=20= has_function_privilege('regress_pg_walinspect',=0A=20=20=20= 'pg_get_wal_stats(pg_lsn,=20pg_lsn,=20boolean)=20',=20'EXECUTE');=20--=20= yes=0A=20SELECT=20has_function_privilege('regress_pg_walinspect',=0A=20=20= =20'pg_get_wal_block_info(pg_lsn,=20pg_lsn,=20boolean)=20',=20= 'EXECUTE');=20--=20yes=0A+SELECT=20= has_function_privilege('regress_pg_walinspect',=0A+=20=20= 'pg_get_wal_location_at_time(timestamptz,=20interval,=20interval)',=20= 'EXECUTE');=20--=20yes=0A=20SELECT=20= has_function_privilege('regress_pg_walinspect',=0A=20=20=20= 'pg_get_wal_files(pg_lsn,=20pg_lsn)',=20'EXECUTE');=20--=20yes=0A=20=0A= @@=20-162,6=20+277,8=20@@=20GRANT=20EXECUTE=20ON=20FUNCTION=20= pg_get_wal_stats(pg_lsn,=20pg_lsn,=20boolean)=0A=20=20=20TO=20= regress_pg_walinspect;=0A=20GRANT=20EXECUTE=20ON=20FUNCTION=20= pg_get_wal_block_info(pg_lsn,=20pg_lsn,=20boolean)=0A=20=20=20TO=20= regress_pg_walinspect;=0A+GRANT=20EXECUTE=20ON=20FUNCTION=20= pg_get_wal_location_at_time(timestamptz,=20interval,=20interval)=0A+=20=20= TO=20regress_pg_walinspect;=0A=20GRANT=20EXECUTE=20ON=20FUNCTION=20= pg_get_wal_files(pg_lsn,=20pg_lsn)=0A=20=20=20TO=20= regress_pg_walinspect;=0A=20=0A@@=20-173,6=20+290,8=20@@=20SELECT=20= has_function_privilege('regress_pg_walinspect',=0A=20=20=20= 'pg_get_wal_stats(pg_lsn,=20pg_lsn,=20boolean)=20',=20'EXECUTE');=20--=20= yes=0A=20SELECT=20has_function_privilege('regress_pg_walinspect',=0A=20=20= =20'pg_get_wal_block_info(pg_lsn,=20pg_lsn,=20boolean)=20',=20= 'EXECUTE');=20--=20yes=0A+SELECT=20= has_function_privilege('regress_pg_walinspect',=0A+=20=20= 'pg_get_wal_location_at_time(timestamptz,=20interval,=20interval)',=20= 'EXECUTE');=20--=20yes=0A=20SELECT=20= has_function_privilege('regress_pg_walinspect',=0A=20=20=20= 'pg_get_wal_files(pg_lsn,=20pg_lsn)',=20'EXECUTE');=20--=20yes=0A=20=0A= @@=20-184,6=20+303,8=20@@=20REVOKE=20EXECUTE=20ON=20FUNCTION=20= pg_get_wal_stats(pg_lsn,=20pg_lsn,=20boolean)=0A=20=20=20FROM=20= regress_pg_walinspect;=0A=20REVOKE=20EXECUTE=20ON=20FUNCTION=20= pg_get_wal_block_info(pg_lsn,=20pg_lsn,=20boolean)=0A=20=20=20FROM=20= regress_pg_walinspect;=0A+REVOKE=20EXECUTE=20ON=20FUNCTION=20= pg_get_wal_location_at_time(timestamptz,=20interval,=20interval)=0A+=20=20= FROM=20regress_pg_walinspect;=0A=20REVOKE=20EXECUTE=20ON=20FUNCTION=20= pg_get_wal_files(pg_lsn,=20pg_lsn)=0A=20=20=20FROM=20= regress_pg_walinspect;=0A=20=0Adiff=20--git=20= a/contrib/pg_walinspect/t/002_time_search.pl=20= b/contrib/pg_walinspect/t/002_time_search.pl=0Anew=20file=20mode=20= 100644=0Aindex=2000000000000..96a5c06eb76=0A---=20/dev/null=0A+++=20= b/contrib/pg_walinspect/t/002_time_search.pl=0A@@=20-0,0=20+1,98=20@@=0A= +#=20Copyright=20(c)=202026,=20PostgreSQL=20Global=20Development=20Group=0A= +=0A+#=20Test=20the=20bounded=20binary=20search=20for=20WAL=20time=20= boundaries=20across=20segments.=0A+use=20strict;=0A+use=20warnings=20= FATAL=20=3D>=20'all';=0A+=0A+use=20PostgreSQL::Test::Cluster;=0A+use=20= PostgreSQL::Test::Utils;=0A+use=20Test::More;=0A+=0A+my=20$node=20=3D=20= PostgreSQL::Test::Cluster->new('time_search');=0A+$node->init(extra=20=3D>= =20['--wal-segsize=3D1']);=0A+$node->append_conf('postgresql.conf',=20= "autovacuum=20=3D=20off\n");=0A+$node->start;=0A= +$node->safe_psql('postgres',=0A+=09'CREATE=20EXTENSION=20pg_walinspect;=20= CREATE=20TABLE=20test_table=20(a=20int);');=0A= +$node->safe_psql('postgres',=20'SELECT=20pg_switch_wal()');=0A+=0A+my=20= ($lower_time,=20$upper_time);=0A+for=20my=20$i=20(0=20..=208)=0A+{=0A+=09= $node->safe_psql('postgres',=20"INSERT=20INTO=20test_table=20VALUES=20= ($i)");=0A+=09$lower_time=20=3D=20$node->safe_psql('postgres',=20'SELECT=20= clock_timestamp()')=0A+=09=20=20if=20$i=20=3D=3D=203;=0A+=09$upper_time=20= =3D=20$node->safe_psql('postgres',=20'SELECT=20clock_timestamp()')=0A+=09= =20=20if=20$i=20=3D=3D=205;=0A+=09$node->safe_psql('postgres',=20'SELECT=20= pg_switch_wal()')=20if=20$i=20<=208;=0A+}=0A+=0A+my=20$log_offset=20=3D=20= -s=20$node->logfile;=0A+my=20$result=20=3D=20$node->safe_psql(=0A+=09= 'postgres',=20qq{=0A+SET=20log_min_messages=20=3D=20debug1;=0A+SELECT=20= start_timestamp=20<=3D=20'$lower_time'::timestamptz=20-=20interval=20'1=20= microsecond',=0A+=20=20=20=20=20=20=20end_timestamp=20>=3D=20= '$upper_time'::timestamptz,=0A+=20=20=20=20=20=20=20start_lsn=20<=20= end_lsn,=0A+=20=20=20=20=20=20=20pg_walfile_name(start_lsn)=20<>=20= pg_walfile_name(end_lsn)=0A+FROM=20= pg_get_wal_location_at_time('$lower_time',=0A+=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= interval=20'1=20microsecond',=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= '$upper_time'::timestamptz=20-=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= '$lower_time'::timestamptz)});=0A+is($result,=20't|t|t|t',=20'binary=20= search=20finds=20outer=20boundaries=20across=20WAL=20segments');=0A+=0A= +my=20$log=20=3D=20slurp_file($node->logfile,=20$log_offset);=0A+$log=20= =3D~=20/WAL=20time=20search=20decoded=20(\d+)=20of=20(\d+)=20retained=20= segments/=0A+=20=20or=20die=20"could=20not=20find=20WAL=20time=20search=20= statistics=20in=20server=20log";=0A+cmp_ok($1,=20'<',=20$2,=20'binary=20= search=20does=20not=20decode=20all=20retained=20WAL');=0A+=0A+#=20A=20= window=20containing=20no=20timestamped=20record=20is=20enclosed=20by=20= the=20timestamped=0A+#=20records=20immediately=20outside=20it.=0A= +$result=20=3D=20$node->safe_psql(=0A+=09'postgres',=20q{=0A+SELECT=20= clock_timestamp()=20AS=20empty_window_start=20\gset=0A+SELECT=20count(*)=20= AS=20ignored=20FROM=20generate_series(1,=20100000)=20\gset=0A+SELECT=20= clock_timestamp()=20AS=20empty_window_end=20\gset=0A+INSERT=20INTO=20= test_table=20VALUES=20(9);=0A+=0A+SELECT=20location.start_timestamp=20<=20= :'empty_window_start'::timestamptz,=0A+=20=20=20=20=20=20=20= location.end_timestamp=20>=20:'empty_window_end'::timestamptz,=0A+=20=20=20= =20=20=20=20location.start_lsn=20<=20location.end_lsn=0A+FROM=20= pg_get_wal_location_at_time(=0A+=20=20=20=20=20=20=20= :'empty_window_start',=0A+=20=20=20=20=20=20=20interval=20'1=20= microsecond',=0A+=20=20=20=20=20=20=20:'empty_window_end'::timestamptz=20= -=0A+=20=20=20=20=20=20=20=20=20:'empty_window_start'::timestamptz)=20AS=20= location;});=0A+is($result,=20't|t|t',=0A+=09'outer=20anchors=20enclose=20= a=20window=20with=20no=20timestamped=20record');=0A+=0A+#=20With=20no=20= later=20timestamped=20record,=20use=20the=20current=20WAL=20position=20= as=20the=20upper=0A+#=20boundary.=20=20The=20returned=20range=20must=20= include=20WAL=20generated=20before=20the=20only=0A+#=20commit=20record=20= in=20the=20requested=20window.=0A+$result=20=3D=20$node->safe_psql(=0A+=09= 'postgres',=20q{=0A+SELECT=20clock_timestamp()=20AS=20window_start=20= \gset=0A+BEGIN;=0A+SELECT=20pg_current_wal_insert_lsn()=20AS=20= delete_lsn=20\gset=0A+DELETE=20FROM=20test_table=20WHERE=20a=20=3D=205;=0A= +COMMIT;=0A+SELECT=20clock_timestamp()=20AS=20window_end=20\gset=0A+=0A= +SELECT=20location.start_timestamp=20<=3D=0A+=20=20=20=20=20=20=20=20=20= :'window_start'::timestamptz=20-=20interval=20'1=20microsecond',=0A+=20=20= =20=20=20=20=20location.end_timestamp=20IS=20NULL,=0A+=20=20=20=20=20=20=20= location.start_lsn=20<=20:'delete_lsn'::pg_lsn,=0A+=20=20=20=20=20=20=20= location.end_lsn=20>=20:'delete_lsn'::pg_lsn,=0A+=20=20=20=20=20=20=20= EXISTS=20(SELECT=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20FROM=20= pg_get_wal_records_info(location.start_lsn,=0A+=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20location.end_lsn)=0A+=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20WHERE=20resource_manager=20=3D=20'Heap'=20AND=20= record_type=20=3D=20'DELETE')=0A+FROM=20pg_get_wal_location_at_time(=0A+=20= =20=20=20=20=20=20:'window_start',=0A+=20=20=20=20=20=20=20interval=20'1=20= microsecond',=0A+=20=20=20=20=20=20=20:'window_end'::timestamptz=20-=20= :'window_start'::timestamptz)=20AS=20location;});=0A+is($result,=20= 't|t|t|t|t',=0A+=09'current=20WAL=20fallback=20includes=20changes=20= preceding=20the=20only=20commit=20in=20the=20window');=0A+=0A= +$node->stop;=0A+done_testing();=0Adiff=20--git=20= a/doc/src/sgml/pgwalinspect.sgml=20b/doc/src/sgml/pgwalinspect.sgml=0A= index=202f708b32c60..daa5b7ed0b2=20100644=0A---=20= a/doc/src/sgml/pgwalinspect.sgml=0A+++=20= b/doc/src/sgml/pgwalinspect.sgml=0A@@=20-95,6=20+95,145=20@@=0A=20=20=20=20= =20=0A=20=20=20=20=0A=20=0A+=20=20=20= =0A= +=20=20=20=20=0A+=20=20=20=20=20= pg_get_wal_location_at_time(target_time=20timestamptz,=20= before=20interval=20DEFAULT=20'1=20minute',=20after=20interval=20DEFAULT=20= '1=20minute')=20returns=20record=0A+=20=20=20=20=0A+=0A= +=20=20=20=20=0A+=20=20=20=20=20=0A+=20=20=20=20=20=20= Locates=20a=20nearby=20WAL=20region=20using=20records=20containing=20= local=20event=0A+=20=20=20=20=20=20timestamps=20as=20historical=20time=20= anchors.=20=20The=20requested=20time=20range=20extends=0A+=20=20=20=20=20= =20from=20target_time=20minus=0A+=20=20=20=20=20= =20before=20through=0A+=20=20=20=20=20=20= target_time=20plus=0A+=20=20=20=20=20=20= after.=20=20It=20returns=0A+=20=20=20=20=20=20= start_timestamp,=0A+=20=20=20=20=20=20= start_lsn,=0A+=20=20=20=20=20=20= end_timestamp,=20and=0A+=20=20=20=20=20=20= end_lsn.=20=20The=20effective=20upper=20bound=20= is=20the=0A+=20=20=20=20=20=20earlier=20of=20= target_time=20plus=0A+=20=20=20=20=20=20= after=20and=20the=20current=20time.=20=20On=20= successful=0A+=20=20=20=20=20=20return,=20the=20following=20= relationships=20hold:=0A+=0A+start_timestamp=20<=3D=20= target_time=20-=20before=0A+end_timestamp=20=20=20>=3D=20effective=20= upper=20bound,=20or=20is=20null=0A+start_lsn=20=20=20=20=20=20=20<=20= end_lsn=0A+=0A+=20=20=20=20=20=20The=20start=20boundary=20= is=20the=20latest=20timestamped=20record=20found=20at=20or=20before=0A+=20= =20=20=20=20=20the=20requested=20start=20time,=20and=20the=20end=20= boundary=20is=20the=20earliest=0A+=20=20=20=20=20=20timestamped=20record=20= found=20at=20or=20after=20the=20requested=20end=20time.=20=20If=0A+=20=20= =20=20=20=20target_time=20plus=0A+=20=20=20=20= =20=20after=20is=20later=20than=20the=20= current=20time,=20the=0A+=20=20=20=20=20=20requested=20upper=20bound=20= is=20first=20capped=20at=20the=20current=20time.=20=20If=20no=0A+=20=20=20= =20=20=20timestamped=20record=20is=20available=20at=20or=20after=20the=20= upper=20bound,=0A+=20=20=20=20=20=20end_lsn=20= is=20the=20current=20flush=20or=20replay=0A+=20=20=20=20=20=20position=20= and=20end_timestamp=20is=20null.=20=20Both=0A= +=20=20=20=20=20=20interval=20arguments=20must=20be=20greater=20than=20= zero=20and=20not=20greater=20than=20one=0A+=20=20=20=20=20=20day.=0A+=20=20= =20=20=20=0A+=0A+=20=20=20=20=20=0A+=20=20=20=20=20=20Most=20= WAL=20records=20do=20not=20contain=20a=20wall-clock=20timestamp.=20=20= Historical=0A+=20=20=20=20=20=20anchors=20can=20be=20transaction=20= COMMIT,=0A+=20=20=20=20=20=20COMMIT=20= PREPARED,=20ABORT,=0A+=20=20=20=20=20=20or=20= ABORT=20PREPARED=20records,=20as=20well=20as=20= restore=20point=0A+=20=20=20=20=20=20records.=20=20These=20are=20the=20= WAL=20record=20types=20from=20which=20PostgreSQL=20recovery=0A+=20=20=20=20= =20=20can=20extract=20timestamps.=20=20Their=20timestamps=20describe=20= the=20corresponding=0A+=20=20=20=20=20=20event;=20they=20do=20not=20= assign=20timestamps=20to=20heap,=20index,=20or=20other=20records.=0A+=20=20= =20=20=20=0A+=0A+=20=20=20=20=20=0A+=20=20=20=20=20=20In=20= particular,=20a=20commit=20timestamp=20describes=20when=20a=20= transaction=0A+=20=20=20=20=20=20committed,=20not=20when=20its=20earlier=20= changes=20generated=20WAL.=20=20For=20example,=20a=0A+=20=20=20=20=20=20= transaction=20might=20update=20a=20row=20at=2014:00=20and=20commit=20at=20= 15:00;=20the=20heap=0A+=20=20=20=20=20=20WAL=20was=20generated=20around=20= 14:00,=20while=20the=20commit=20record=20is=20timestamped=0A+=20=20=20=20= =20=2015:00.=20=20Using=20timestamped=20records=20outside=20the=20= requested=20time=20window=20as=0A+=20=20=20=20=20=20boundaries=20helps=20= include=20the=20WAL=20generated=20by=20transactions=20that=20commit=0A+=20= =20=20=20=20=20within=20the=20window.=20=20However,=20the=20returned=20= LSNs=20do=20not=20identify=20the=20exact=0A+=20=20=20=20=20=20generation=20= time=20of=20heap,=20index,=20or=20other=20WAL=20records,=20and=20a=20= transaction=0A+=20=20=20=20=20=20can=20have=20generated=20WAL=20before=20= the=20selected=20start=20boundary.=20=20On=20a=20cluster=0A+=20=20=20=20=20= =20with=20little=20timestamped=20activity,=20the=20returned=20timestamps=20= can=20be=20far=0A+=20=20=20=20=20=20from=20the=20requested=20bounds.=0A+=20= =20=20=20=20=0A+=0A+=20=20=20=20=20=0A+=20=20=20=20=20=20= The=20function=20assumes=20that=20WAL=20record=20timestamps=20generally=20= increase=20with=0A+=20=20=20=20=20=20WAL=20position=20and=20uses=20an=20= approximate=20binary=20search=20to=20locate=20each=20time=0A+=20=20=20=20= =20=20boundary.=20=20WAL=20record=20timestamps=20are=20not=20guaranteed=20= to=20follow=20WAL=20order,=0A+=20=20=20=20=20=20for=20example=20because=20= of=20concurrent=20activity,=20clock=20adjustments,=20or=0A+=20=20=20=20=20= =20delayed=20WAL=20insertion.=20=20Such=20timestamp=20reordering=20can=20= cause=20relevant=0A+=20=20=20=20=20=20records=20to=20fall=20outside=20= the=20returned=20range.=20=20Therefore,=20the=20returned=0A+=20=20=20=20=20= =20records=20are=20not=20guaranteed=20to=20be=20the=20globally=20closest=20= timestamped=0A+=20=20=20=20=20=20records=20to=20either=20requested=20= time=20bound.=20=20If=20the=20returned=20range=20does=20not=0A+=20=20=20=20= =20=20contain=20the=20records=20of=20interest,=20the=20user=20can=20= widen=20the=20search=20range=20and=0A+=20=20=20=20=20=20repeat=20the=20= search.=20=20If=20the=20matching=20lower=20boundary=20follows=20the=20= upper=0A+=20=20=20=20=20=20boundary=20in=20WAL,=20the=20function=20= reports=20an=20error=20rather=20than=20returning=20a=0A+=20=20=20=20=20=20= range=20with=20the=20LSNs=20reversed.=0A+=20=20=20=20=20=0A+=0A+=20= =20=20=20=20=0A+=20=20=20=20=20=20Only=20WAL=20that=20is=20= currently=20retained=20in=20pg_wal=20can=0A+=20=20=20= =20=20=20be=20searched.=20=20The=20function=20reports=20an=20error=20= when=20a=20lower=20boundary=20cannot=0A+=20=20=20=20=20=20be=20found=20= by=20the=20bounded=20search=20or=20when=20the=20resulting=20range=20= would=20cross=20a=0A+=20=20=20=20=20=20missing=20WAL=20segment.=20=20= When=20an=20upper=20timestamped=20boundary=20cannot=20be=0A+=20=20=20=20=20= =20found,=20the=20current=20WAL=20position=20is=20returned=20instead,=20= as=20described=20above.=0A+=20=20=20=20=20=0A+=0A+=20=20=20=20=20= =0A+=20=20=20=20=20=20For=20example,=20a=20DBA=20can=20locate=20= WAL=20around=20activity=20near=20a=20given=20time=20and=0A+=20=20=20=20=20= =20then=20inspect=20the=20returned=20range:=0A+=0A= +SELECT=20*=0A+FROM=20pg_get_wal_location_at_time(=0A+=20=20=20=20= '2026-08-01=2014:35:00+08',=0A+=20=20=20=20before=20=3D>=20'10=20= minutes',=0A+=20=20=20=20after=20=20=3D>=20'10=20minutes');=0A+=0A= +SELECT=20*=0A+FROM=20= pg_get_wal_files('start_lsn',=0A+=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= 'end_lsn');=0A+=0A+SELECT=20*=0A+FROM=20= pg_get_wal_records_info('start_lsn',=0A+=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20'end_lsn');=0A+=0A+=20=20= =20=20=20=20The=20corresponding=20retained=20WAL=20files=20can=20be=20= obtained=20with=0A+=20=20=20=20=20=20= pg_get_wal_files.=20=20To=20widen=20the=20search=20= range,=0A+=20=20=20=20=20=20increase=20before=20= if=20the=20relevant=20activity=0A+=20=20=20=20=20=20might=20have=20= occurred=20earlier,=20or=20increase=0A+=20=20=20=20=20=20= after=20if=20it=20might=20have=20occurred=20= later,=20and=0A+=20=20=20=20=20=20repeat=20the=20search.=20=20Failure=20= to=20find=20a=20record=20in=20the=20first=20returned=20range=0A+=20=20=20= =20=20=20does=20not=20necessarily=20mean=20that=20the=20record=20is=20= absent=20from=20retained=20WAL.=0A+=20=20=20=20=20=0A+=0A+=20=20=20= =20=20=0A+=20=20=20=20=20=20=0A+=20=20=20=20=20=20=20When=20= end_timestamp=20is=20not=20null,=0A+=20=20=20=20= =20=20=20end_lsn=20points=20to=20the=20start=20= of=20the=20end-anchor=0A+=20=20=20=20=20=20=20record.=20=20Therefore,=20= passing=20the=20returned=20LSN=20range=20directly=20to=0A+=20=20=20=20=20= =20=20pg_get_wal_records_info=20does=20not=20= include=20that=0A+=20=20=20=20=20=20=20record.=20=20For=20example,=20if=20= the=20end=20anchor=20happens=20to=20be=20a=20transaction=0A+=20=20=20=20=20= =20=20commit,=20the=20range=20can=20contain=20the=20transaction's=20= earlier=20changes=20but=20not=0A+=20=20=20=20=20=20=20its=20commit=20= record.=0A+=20=20=20=20=20=20=0A+=0A+=20=20=20=20=20=20=0A+=20= =20=20=20=20=20=20To=20include=20the=20end-anchor=20record,=20obtain=20= its=20ending=20LSN=20with=0A+=20=20=20=20=20=20=20= pg_get_wal_record_info=20and=20use=20that=20as=20= the=20range=0A+=20=20=20=20=20=20=20endpoint:=0A+=0A= +SELECT=20*=0A+FROM=20pg_get_wal_records_info(=0A+=20=20=20=20= 'start_lsn',=0A+=20=20=20=20(SELECT=20end_lsn=0A= +=20=20=20=20=20FROM=20= pg_get_wal_record_info('end_lsn')));=0A= +=0A+=20=20=20=20=20=20=0A+=20=20=20=20=20=0A= +=20=20=20=20=0A+=20=20=20=0A+=0A=20=20=20=20= =0A=20=20= =20=20=20=0A=20=20=20=20=20=20= pg_get_wal_record_info(in_lsn=20pg_lsn)=20returns=20= record=0Adiff=20--git=20= a/src/backend/access/transam/xlogreader.c=20= b/src/backend/access/transam/xlogreader.c=0Aindex=20= 1db5ca48c3f..b91458b9636=20100644=0A---=20= a/src/backend/access/transam/xlogreader.c=0A+++=20= b/src/backend/access/transam/xlogreader.c=0A@@=20-26,6=20+26,7=20@@=0A=20= #endif=0A=20=0A=20#include=20"access/transam.h"=0A+#include=20= "access/xact.h"=0A=20#include=20"access/xlog_internal.h"=0A=20#include=20= "access/xlogreader.h"=0A=20#include=20"access/xlogrecord.h"=0A@@=20-72,6=20= +73,41=20@@=20static=20void=20XLogReaderFreeZstdContext(void=20*arg);=0A=20= =20*/=0A=20#define=20DEFAULT_DECODE_BUFFER_SIZE=20(64=20*=201024)=0A=20=0A= +/*=0A+=20*=20Extract=20timestamp=20from=20WAL=20record.=0A+=20*=0A+=20*=20= If=20the=20record=20contains=20a=20timestamp,=20returns=20true,=20and=20= saves=20the=20timestamp=0A+=20*=20in=20*recordXtime.=20If=20the=20record=20= type=20has=20no=20timestamp,=20returns=20false.=0A+=20*=20Currently,=20= only=20transaction=20commit/abort=20records=20and=20restore=20points=20= contain=0A+=20*=20timestamps.=0A+=20*/=0A+bool=0A= +GetXLogRecordTimestamp(XLogReaderState=20*record,=20TimestampTz=20= *recordXtime)=0A+{=0A+=09uint8=09=09info=20=3D=20XLogRecGetInfo(record)=20= &=20~XLR_INFO_MASK;=0A+=09uint8=09=09xact_info=20=3D=20info=20&=20= XLOG_XACT_OPMASK;=0A+=09uint8=09=09rmid=20=3D=20XLogRecGetRmid(record);=0A= +=0A+=09if=20(rmid=20=3D=3D=20RM_XLOG_ID=20&&=20info=20=3D=3D=20= XLOG_RESTORE_POINT)=0A+=09{=0A+=09=09*recordXtime=20=3D=20= ((xl_restore_point=20*)=20XLogRecGetData(record))->rp_time;=0A+=09=09= return=20true;=0A+=09}=0A+=09if=20(rmid=20=3D=3D=20RM_XACT_ID=20&&=20= (xact_info=20=3D=3D=20XLOG_XACT_COMMIT=20||=0A+=09=09=09=09=09=09=09=20=20= =20xact_info=20=3D=3D=20XLOG_XACT_COMMIT_PREPARED))=0A+=09{=0A+=09=09= *recordXtime=20=3D=20((xl_xact_commit=20*)=20= XLogRecGetData(record))->xact_time;=0A+=09=09return=20true;=0A+=09}=0A+=09= if=20(rmid=20=3D=3D=20RM_XACT_ID=20&&=20(xact_info=20=3D=3D=20= XLOG_XACT_ABORT=20||=0A+=09=09=09=09=09=09=09=20=20=20xact_info=20=3D=3D=20= XLOG_XACT_ABORT_PREPARED))=0A+=09{=0A+=09=09*recordXtime=20=3D=20= ((xl_xact_abort=20*)=20XLogRecGetData(record))->xact_time;=0A+=09=09= return=20true;=0A+=09}=0A+=09return=20false;=0A+}=0A+=0A=20/*=0A=20=20*=20= Construct=20a=20string=20in=20state->errormsg_buf=20explaining=20what's=20= wrong=20with=0A=20=20*=20the=20current=20record=20being=20read.=0Adiff=20= --git=20a/src/backend/access/transam/xlogrecovery.c=20= b/src/backend/access/transam/xlogrecovery.c=0Aindex=20= 54aaec9529f..06a5b10d092=20100644=0A---=20= a/src/backend/access/transam/xlogrecovery.c=0A+++=20= b/src/backend/access/transam/xlogrecovery.c=0A@@=20-356,7=20+356,6=20@@=20= static=20void=20xlog_outrec(StringInfo=20buf,=20XLogReaderState=20= *record);=0A=20static=20void=20xlog_block_info(StringInfo=20buf,=20= XLogReaderState=20*record);=0A=20static=20void=20= checkTimeLineSwitch(XLogRecPtr=20lsn,=20TimeLineID=20newTLI,=0A=20=09=09=09= =09=09=09=09=09TimeLineID=20prevTLI,=20TimeLineID=20replayTLI);=0A= -static=20bool=20getRecordTimestamp(XLogReaderState=20*record,=20= TimestampTz=20*recordXtime);=0A=20static=20void=20= verifyBackupPageConsistency(XLogReaderState=20*record);=0A=20=0A=20= static=20bool=20recoveryStopsBefore(XLogReaderState=20*record);=0A@@=20= -2405,41=20+2404,6=20@@=20checkTimeLineSwitch(XLogRecPtr=20lsn,=20= TimeLineID=20newTLI,=20TimeLineID=20prevTLI,=0A=20}=0A=20=0A=20=0A-/*=0A= -=20*=20Extract=20timestamp=20from=20WAL=20record.=0A-=20*=0A-=20*=20If=20= the=20record=20contains=20a=20timestamp,=20returns=20true,=20and=20saves=20= the=20timestamp=0A-=20*=20in=20*recordXtime.=20If=20the=20record=20type=20= has=20no=20timestamp,=20returns=20false.=0A-=20*=20Currently,=20only=20= transaction=20commit/abort=20records=20and=20restore=20points=20contain=0A= -=20*=20timestamps.=0A-=20*/=0A-static=20bool=0A= -getRecordTimestamp(XLogReaderState=20*record,=20TimestampTz=20= *recordXtime)=0A-{=0A-=09uint8=09=09info=20=3D=20XLogRecGetInfo(record)=20= &=20~XLR_INFO_MASK;=0A-=09uint8=09=09xact_info=20=3D=20info=20&=20= XLOG_XACT_OPMASK;=0A-=09uint8=09=09rmid=20=3D=20XLogRecGetRmid(record);=0A= -=0A-=09if=20(rmid=20=3D=3D=20RM_XLOG_ID=20&&=20info=20=3D=3D=20= XLOG_RESTORE_POINT)=0A-=09{=0A-=09=09*recordXtime=20=3D=20= ((xl_restore_point=20*)=20XLogRecGetData(record))->rp_time;=0A-=09=09= return=20true;=0A-=09}=0A-=09if=20(rmid=20=3D=3D=20RM_XACT_ID=20&&=20= (xact_info=20=3D=3D=20XLOG_XACT_COMMIT=20||=0A-=09=09=09=09=09=09=09=20=20= =20xact_info=20=3D=3D=20XLOG_XACT_COMMIT_PREPARED))=0A-=09{=0A-=09=09= *recordXtime=20=3D=20((xl_xact_commit=20*)=20= XLogRecGetData(record))->xact_time;=0A-=09=09return=20true;=0A-=09}=0A-=09= if=20(rmid=20=3D=3D=20RM_XACT_ID=20&&=20(xact_info=20=3D=3D=20= XLOG_XACT_ABORT=20||=0A-=09=09=09=09=09=09=09=20=20=20xact_info=20=3D=3D=20= XLOG_XACT_ABORT_PREPARED))=0A-=09{=0A-=09=09*recordXtime=20=3D=20= ((xl_xact_abort=20*)=20XLogRecGetData(record))->xact_time;=0A-=09=09= return=20true;=0A-=09}=0A-=09return=20false;=0A-}=0A-=0A=20/*=0A=20=20*=20= Checks=20whether=20the=20current=20buffer=20page=20and=20backup=20page=20= stored=20in=20the=0A=20=20*=20WAL=20record=20are=20consistent=20or=20= not.=20Before=20comparing=20the=20two=20pages,=20a=0A@@=20-2663,10=20= +2627,10=20@@=20recoveryStopsBefore(XLogReaderState=20*record)=0A=20=0A=20= =09/*=0A=20=09=20*=20Note:=20we=20must=20fetch=20recordXtime=20= regardless=20of=20recoveryTarget=20setting.=0A-=09=20*=20We=20don't=20= expect=20getRecordTimestamp=20ever=20to=20fail,=20since=20we=20already=20= know=0A-=09=20*=20this=20is=20a=20commit=20or=20abort=20record;=20but=20= test=20its=20result=20anyway.=0A+=09=20*=20We=20don't=20expect=20= GetXLogRecordTimestamp=20ever=20to=20fail,=20since=20we=20already=0A+=09=20= *=20know=20this=20is=20a=20commit=20or=20abort=20record;=20but=20test=20= its=20result=20anyway.=0A=20=09=20*/=0A-=09if=20= (getRecordTimestamp(record,=20&recordXtime)=20&&=0A+=09if=20= (GetXLogRecordTimestamp(record,=20&recordXtime)=20&&=0A=20=09=09= recoveryTarget=20=3D=3D=20RECOVERY_TARGET_TIME)=0A=20=09{=0A=20=09=09/*=0A= @@=20-2747,7=20+2711,7=20@@=20recoveryStopsAfter(XLogReaderState=20= *record)=0A=20=09=09=09recoveryStopAfter=20=3D=20true;=0A=20=09=09=09= recoveryStopXid=20=3D=20InvalidTransactionId;=0A=20=09=09=09= recoveryStopLSN=20=3D=20InvalidXLogRecPtr;=0A-=09=09=09(void)=20= getRecordTimestamp(record,=20&recoveryStopTime);=0A+=09=09=09(void)=20= GetXLogRecordTimestamp(record,=20&recoveryStopTime);=0A=20=09=09=09= strlcpy(recoveryStopName,=20recordRestorePointData->rp_name,=20= MAXFNAMELEN);=0A=20=0A=20=09=09=09ereport(LOG,=0A@@=20-2787,7=20+2751,7=20= @@=20recoveryStopsAfter(XLogReaderState=20*record)=0A=20=09=09= TransactionId=20recordXid;=0A=20=0A=20=09=09/*=20Update=20the=20last=20= applied=20transaction=20timestamp=20*/=0A-=09=09if=20= (getRecordTimestamp(record,=20&recordXtime))=0A+=09=09if=20= (GetXLogRecordTimestamp(record,=20&recordXtime))=0A=20=09=09=09= SetLatestXTime(recordXtime);=0A=20=0A=20=09=09/*=20Extract=20the=20XID=20= of=20the=20committed/aborted=20transaction=20*/=0A@@=20-3006,7=20+2970,7=20= @@=20recoveryApplyDelay(XLogReaderState=20*record)=0A=20=09=09xact_info=20= !=3D=20XLOG_XACT_COMMIT_PREPARED)=0A=20=09=09return=20false;=0A=20=0A-=09= if=20(!getRecordTimestamp(record,=20&xtime))=0A+=09if=20= (!GetXLogRecordTimestamp(record,=20&xtime))=0A=20=09=09return=20false;=0A= =20=0A=20=09delayUntil=20=3D=20TimestampTzPlusMilliseconds(xtime,=20= recovery_min_apply_delay);=0Adiff=20--git=20= a/src/include/access/xlogreader.h=20b/src/include/access/xlogreader.h=0A= index=20e48a0db9ce9..43682a28272=20100644=0A---=20= a/src/include/access/xlogreader.h=0A+++=20= b/src/include/access/xlogreader.h=0A@@=20-39,6=20+39,7=20@@=0A=20#endif=0A= =20=0A=20#include=20"access/xlogrecord.h"=0A+#include=20= "datatype/timestamp.h"=0A=20#include=20"storage/buf.h"=0A=20=0A=20/*=20= WALOpenSegment=20represents=20a=20WAL=20segment=20being=20read.=20*/=0A= @@=20-462,5=20+463,7=20@@=20extern=20bool=20= XLogRecGetBlockTagExtended(XLogReaderState=20*record,=20uint8=20= block_id,=0A=20=09=09=09=09=09=09=09=09=09=20=20=20RelFileLocator=20= *rlocator,=20ForkNumber=20*forknum,=0A=20=09=09=09=09=09=09=09=09=09=20=20= =20BlockNumber=20*blknum,=0A=20=09=09=09=09=09=09=09=09=09=20=20=20= Buffer=20*prefetch_buffer);=0A+extern=20bool=20= GetXLogRecordTimestamp(XLogReaderState=20*record,=0A+=09=09=09=09=09=09=09= =09=20=20=20TimestampTz=20*recordXtime);=0A=20=0A=20#endif=09=09=09=09=09= =09=09/*=20XLOGREADER_H=20*/=0Adiff=20--git=20= a/src/tools/pgindent/typedefs.list=20b/src/tools/pgindent/typedefs.list=0A= index=2046da9e8a15c..8e555337a13=20100644=0A---=20= a/src/tools/pgindent/typedefs.list=0A+++=20= b/src/tools/pgindent/typedefs.list=0A@@=20-3429,6=20+3429,7=20@@=20= WalSndState=0A=20WalSummarizerData=0A=20WalSummaryFile=0A=20WalSummaryIO=0A= +WalTimeBoundary=0A=20WalTimeSample=0A=20WalTimeSegment=0A=20WalUsage=0A= --=20=0A2.50.1=20(Apple=20Git-155)=0A=0A= --Apple-Mail=_A1724A3D-C5C8-4ED1-AE94-3480FD42F6C1--