Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kz1jl-0006Is-D6 for pgsql-hackers@arkaria.postgresql.org; Mon, 11 Jan 2021 18:16:17 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kz1jk-0006i5-A4 for pgsql-hackers@arkaria.postgresql.org; Mon, 11 Jan 2021 18:16:16 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kz1jj-0006hx-CI for pgsql-hackers@lists.postgresql.org; Mon, 11 Jan 2021 18:16:16 +0000 Received: from mail-pl1-x62d.google.com ([2607:f8b0:4864:20::62d]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kz1jf-0007t6-KM for pgsql-hackers@postgresql.org; Mon, 11 Jan 2021 18:16:14 +0000 Received: by mail-pl1-x62d.google.com with SMTP id q4so264817plr.7 for ; Mon, 11 Jan 2021 10:16:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb-com.20150623.gappssmtp.com; s=20150623; h=from:message-id:mime-version:subject:date:in-reply-to:cc:to :references; bh=8jQbwN1YTD8edw8GGACtNk34rtZaWO/Q+0CDYm9VLX8=; b=Vj+WmHgsXFg5FLWuuPfzn52sR0eQ+8bzbYCyqPnXwurEAhbAUkoI0yvA/7S6ASdKg5 6hM4eBZItK/VfCWAt58PTccupz78gJ6tYLwMg/59yqqSqOPsTkOFaWddluXwQCEoxqEs syoQiztCTo/JzN29cW1z6zZRLLtHjV6WMuNWRu+bm1ZTCtoFjApCF13rWbA/dS8FH4rw dUshLjdUJM2UbWczFOXi1NM24ARRZLwMhjvtO2IKion1Y5cfZtr2UI8NK8wUB9OKAFi/ tb75Pitt3+Xy4f+/pSf3MHIg9tFcJ0LVoUEPq031eyZoA/d5//bY0nm8dHTGUhMrKFQF xiVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:message-id:mime-version:subject:date :in-reply-to:cc:to:references; bh=8jQbwN1YTD8edw8GGACtNk34rtZaWO/Q+0CDYm9VLX8=; b=owlwwD4rb/fqqVxAsMQO88qAWftM3NSRf320xdIvntL4wG8gi3r0Dy6wtCYFw2iaJc ijFSrXcIVkqVvKo3FUlQShWNbWIGij+DfSkROha/so2IxCiwu3UWHqPkmpnitaDZhxEG 2p3zavjZIDKWpiC91j+ViLv50ciUSat4dlVymwJRu3lPCYxK8m/U/A9gSAButfY0y+iO LOAHjiu14oMhGPnq8tnrmPUJNs4JWIpJ6MjSu16rALPRdUahZqynqsQ6GO1iL1QUxAoL qk5AhVM9bSHIEhq13jfvotCK+UIhGNQw4dtAZ2WuZUrsvvY1/eUTUUoUDJXmxZcltOne NgsA== X-Gm-Message-State: AOAM533x+K9j0NdDVVcAn2PArccsOAEdqQTQGOdQZgCyiQSo2I2tZzmQ uw5QuPa58VFJtrFhmXp46Br8651ogcUgk6vzt6SKvXUULAntYz15WrnMCdSRMkAWobjXVWEE8v8 /dEl3sYmuNryDuGqou5gVdJyeZf0Uq8kJtgWxjPrHiQm76vRfz0S4FEGhcUc3hEIm7cQ7Jaqgc9 oSXHQt89qfh4ei+jbsBxLzhVZQDwDjjRL5Td2E X-Google-Smtp-Source: ABdhPJziUVBLe61bmUNzXqc3vgzg91/z/SdfUdf0UVPsouCLwrGlVmFwm62aNsbKxbNdTcaJVLCsUA== X-Received: by 2002:a17:902:b203:b029:dc:973:3ad0 with SMTP id t3-20020a170902b203b02900dc09733ad0mr550108plr.44.1610388970306; Mon, 11 Jan 2021 10:16:10 -0800 (PST) Received: from [192.168.0.29] (24-113-193-150.wavecable.com. [24.113.193.150]) by smtp.gmail.com with ESMTPSA id l11sm359333pgt.79.2021.01.11.10.16.08 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 11 Jan 2021 10:16:08 -0800 (PST) From: Mark Dilger Message-Id: Content-Type: multipart/mixed; boundary="Apple-Mail=_8B07CFD0-2450-4CA2-BEE1-ACB2F7EEE33B" Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.120.23.2.1\)) Subject: Re: new heapcheck contrib module Date: Mon, 11 Jan 2021 10:16:07 -0800 In-Reply-To: Cc: Robert Haas , Tom Lane , Peter Geoghegan , "Andrey M. Borodin" , Stephen Frost , Michael Paquier , Amul Sul , Dilip Kumar , Andres Freund , PostgreSQL-development To: Thomas Munro References: <12ED3DA8-25F0-4B68-937D-D907CFBF08E7@enterprisedb.com> <20200420194210.sevnpi4lyghoanxi@alap3.anarazel.de> <23E60C3C-C20A-4508-84AC-E0CEA59E784A@enterprisedb.com> <5F743835-3399-419C-8324-2D424237E999@enterprisedb.com> <885D2EC9-7D06-4903-A17D-72C184A1E1C5@enterprisedb.com> <5CC85F28-F210-47AC-8DA8-EC4E82AF3FD5@enterprisedb.com> <0C0349EB-DD85-4DA8-82C7-DF70AB714592@enterprisedb.com> <9DF93B83-FE46-4EC4-A99D-77A60729FD2D@enterprisedb.com> <50F6468F-5A5E-412A-86EC-DF24B549D733@enterprisedb.com> <7D603B53-8078-4AF0-851B-803FF4416501@enterprisedb.com> <98265AA9-7BDC-4708-9348-CC1B173BBE1D@enterprisedb.com> <209783.1603313248@sss.pgh.pa.us> <77A60E99-6054-40FD-A5D6-769C287D4A0F@enterprisedb.com> <721BFA83-EA6F-463D-A9DF-CE78A318B73A@enterprisedb.com> <2A7DA1A8-C4AA-43DF-A985-3CA52F4DC775@enterprisedb.com> <146814.1603463293@sss.pgh.pa.us> <221029.1603476265@sss.pgh.pa.us> <153EEBAD-2673-4367-B36D-4A6AE8EE7A9F@enterprisedb.com> <85BE72E5-A926-4F23-9FD5-64239C0C6BA5@enterprisedb.com> <10677BFE-3B45-4EF3-82E5-E45CA1445CA6@enterprisedb.com> X-Mailer: Apple Mail (2.3608.120.23.2.1) X-CLOUD-SEC-AV-Info: enterprisedb,google_mail,monitor X-CLOUD-SEC-AV-Sent: true X-Gm-Spam: 0 X-Gm-Phishy: 0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --Apple-Mail=_8B07CFD0-2450-4CA2-BEE1-ACB2F7EEE33B Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii > On Jan 10, 2021, at 12:41 PM, Thomas Munro = wrote: >=20 > On Fri, Jan 8, 2021 at 6:33 AM Mark Dilger = wrote: >> The attached patches, v31, are mostly the same, but with = "getopt_long.h" included from pg_amcheck.c per Thomas's review, and a = .gitignore file added in contrib/pg_amcheck/ >=20 > I couple more little things from Windows CI: >=20 > C:\projects\postgresql\src\include\fe_utils/option_utils.h(19): > fatal error C1083: Cannot open include file: 'libpq-fe.h': No such > file or directory [C:\projects\postgresql\pg_amcheck.vcxproj] >=20 > Does contrib/amcheck/Makefile need to say "SHLIB_PREREQS =3D > submake-libpq" like other contrib modules that use libpq? Added in v32. > pg_backup_utils.obj : error LNK2001: unresolved external symbol > exit_nicely [C:\projects\postgresql\pg_dump.vcxproj] >=20 > I think this is probably because additions to src/fe_utils/Makefile's > OBJS list need to be manually replicated in > src/tools/msvc/Mkvcbuild.pm's @pgfeutilsfiles list. (If I'm right > about that, perhaps it needs a comment to remind us Unix hackers of > that, or perhaps it should be automated...) Added in v32, along with adding pg_amcheck to @contrib_uselibpq, = @contrib_uselibpgport, and @contrib_uselibpgcommon There are also a few additions in v32 to typedefs.list, and some = whitespace changes due to running pgindent. --Apple-Mail=_8B07CFD0-2450-4CA2-BEE1-ACB2F7EEE33B Content-Disposition: attachment; filename=v32-0001-Moving-exit_nicely-and-fatal-into-fe_utils.patch Content-Type: application/octet-stream; x-unix-mode=0644; name="v32-0001-Moving-exit_nicely-and-fatal-into-fe_utils.patch" Content-Transfer-Encoding: quoted-printable =46rom=20b4a3769891e3669c2b6e5c4b0db757f70fff6d84=20Mon=20Sep=2017=20= 00:00:00=202001=0AFrom:=20Mark=20Dilger=20=0A= Date:=20Wed,=2030=20Dec=202020=2012:50:41=20-0800=0ASubject:=20[PATCH=20= v32=201/9]=20Moving=20exit_nicely=20and=20fatal=20into=20fe_utils=0A=0A= In=20preparation=20for=20moving=20other=20pg_dump=20functionality=20into=20= fe_utils,=0Amoving=20the=20functions=20"on_exit_nicely"=20and=20= "exit_nicely",=20and=20the=0Amacro=20"fatal"=20from=20pg_dump=20into=20= fe_utils.=0A=0AVarious=20frontend=20executables=20in=20src/bin,=20= src/bin/scripts,=20and=0Acontrib/=20have=20logic=20for=20logging=20and=20= exiting=20under=20error=20conditions.=0AThe=20logging=20code=20itself=20= is=20already=20under=20common/,=20but=20executables=0Adiffer=20in=20= their=20calls=20to=20exit()=20vs.=20=20exit_nicely(),=20with=0A= exit_nicely()=20not=20uniformly=20defined,=20and=20sometimes=20all=20of=20= this=0Awrapped=20up=20under=20a=20macro=20named=20fatal(),=20the=20= definition=20of=20that=20macro=0Aalso=20not=20uniformly=20defined.=20=20= This=20makes=20it=20harder=20to=20move=20code=20out=0Aof=20these=20= executables=20into=20a=20shared=20library=20under=20fe_utils/.=0A= Standardizing=20all=20executables=20to=20define=20these=20things=20the=20= same=20way=20or=0Ato=20use=20a=20single=20fe_utils/=20library=20is=20= beyond=20the=20scope=20of=20this=20patch,=0Abut=20this=20patch=20should=20= get=20the=20ball=20rolling=20in=20that=20direction.=0A---=0A=20= src/bin/pg_dump/pg_backup_archiver.h=20|=20=201=20+=0A=20= src/bin/pg_dump/pg_backup_utils.c=20=20=20=20|=2059=20= -----------------------=0A=20src/bin/pg_dump/pg_backup_utils.h=20=20=20=20= |=20=208=20----=0A=20src/fe_utils/Makefile=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20|=20=201=20+=0A=20src/fe_utils/exit_utils.c=20=20=20=20=20= =20=20=20=20=20=20=20|=2071=20++++++++++++++++++++++++++++=0A=20= src/include/fe_utils/exit_utils.h=20=20=20=20|=2025=20++++++++++=0A=206=20= files=20changed,=2098=20insertions(+),=2067=20deletions(-)=0A=20create=20= mode=20100644=20src/fe_utils/exit_utils.c=0A=20create=20mode=20100644=20= src/include/fe_utils/exit_utils.h=0A=0Adiff=20--git=20= a/src/bin/pg_dump/pg_backup_archiver.h=20= b/src/bin/pg_dump/pg_backup_archiver.h=0Aindex=20a8ea5c7eae..37d157b7ad=20= 100644=0A---=20a/src/bin/pg_dump/pg_backup_archiver.h=0A+++=20= b/src/bin/pg_dump/pg_backup_archiver.h=0A@@=20-26,6=20+26,7=20@@=0A=20=0A= =20#include=20=0A=20=0A+#include=20"fe_utils/exit_utils.h"=0A=20= #include=20"libpq-fe.h"=0A=20#include=20"pg_backup.h"=0A=20#include=20= "pqexpbuffer.h"=0Adiff=20--git=20a/src/bin/pg_dump/pg_backup_utils.c=20= b/src/bin/pg_dump/pg_backup_utils.c=0Aindex=20c709a40e06..631e88f7db=20= 100644=0A---=20a/src/bin/pg_dump/pg_backup_utils.c=0A+++=20= b/src/bin/pg_dump/pg_backup_utils.c=0A@@=20-19,16=20+19,6=20@@=0A=20/*=20= Globals=20exported=20by=20this=20file=20*/=0A=20const=20char=20*progname=20= =3D=20NULL;=0A=20=0A-#define=20MAX_ON_EXIT_NICELY=09=09=09=0920=0A-=0A= -static=20struct=0A-{=0A-=09on_exit_nicely_callback=20function;=0A-=09= void=09=20=20=20*arg;=0A-}=09=09=09= on_exit_nicely_list[MAX_ON_EXIT_NICELY];=0A-=0A-static=20int=09= on_exit_nicely_index;=0A-=0A=20/*=0A=20=20*=20Parse=20a=20--section=3Dfoo=20= command=20line=20argument.=0A=20=20*=0A@@=20-57,52=20+47,3=20@@=20= set_dump_section(const=20char=20*arg,=20int=20*dumpSections)=0A=20=09=09= exit_nicely(1);=0A=20=09}=0A=20}=0A-=0A-=0A-/*=20Register=20a=20callback=20= to=20be=20run=20when=20exit_nicely=20is=20invoked.=20*/=0A-void=0A= -on_exit_nicely(on_exit_nicely_callback=20function,=20void=20*arg)=0A-{=0A= -=09if=20(on_exit_nicely_index=20>=3D=20MAX_ON_EXIT_NICELY)=0A-=09{=0A-=09= =09pg_log_fatal("out=20of=20on_exit_nicely=20slots");=0A-=09=09= exit_nicely(1);=0A-=09}=0A-=09= on_exit_nicely_list[on_exit_nicely_index].function=20=3D=20function;=0A-=09= on_exit_nicely_list[on_exit_nicely_index].arg=20=3D=20arg;=0A-=09= on_exit_nicely_index++;=0A-}=0A-=0A-/*=0A-=20*=20Run=20accumulated=20= on_exit_nicely=20callbacks=20in=20reverse=20order=20and=20then=20exit=0A= -=20*=20without=20printing=20any=20message.=0A-=20*=0A-=20*=20If=20= running=20in=20a=20parallel=20worker=20thread=20on=20Windows,=20we=20= only=20exit=20the=20thread,=0A-=20*=20not=20the=20whole=20process.=0A-=20= *=0A-=20*=20Note=20that=20in=20parallel=20operation=20on=20Windows,=20= the=20callback(s)=20will=20be=20run=0A-=20*=20by=20each=20thread=20since=20= the=20list=20state=20is=20necessarily=20shared=20by=20all=20threads;=0A-=20= *=20each=20callback=20must=20contain=20logic=20to=20ensure=20it=20does=20= only=20what's=20appropriate=0A-=20*=20for=20its=20thread.=20=20On=20= Unix,=20callbacks=20are=20also=20run=20by=20each=20process,=20but=20only=0A= -=20*=20for=20callbacks=20established=20before=20we=20fork=20off=20the=20= child=20processes.=20=20(It'd=0A-=20*=20be=20cleaner=20to=20reset=20the=20= list=20after=20fork(),=20and=20let=20each=20child=20establish=0A-=20*=20= its=20own=20callbacks;=20but=20then=20the=20behavior=20would=20be=20= completely=20inconsistent=0A-=20*=20between=20Windows=20and=20Unix.=20=20= For=20now,=20just=20be=20sure=20to=20establish=20callbacks=0A-=20*=20= before=20forking=20to=20avoid=20inconsistency.)=0A-=20*/=0A-void=0A= -exit_nicely(int=20code)=0A-{=0A-=09int=09=09=09i;=0A-=0A-=09for=20(i=20= =3D=20on_exit_nicely_index=20-=201;=20i=20>=3D=200;=20i--)=0A-=09=09= on_exit_nicely_list[i].function(code,=0A-=09=09=09=09=09=09=09=09=09=09= on_exit_nicely_list[i].arg);=0A-=0A-#ifdef=20WIN32=0A-=09if=20= (parallel_init_done=20&&=20GetCurrentThreadId()=20!=3D=20mainThreadId)=0A= -=09=09_endthreadex(code);=0A-#endif=0A-=0A-=09exit(code);=0A-}=0Adiff=20= --git=20a/src/bin/pg_dump/pg_backup_utils.h=20= b/src/bin/pg_dump/pg_backup_utils.h=0Aindex=20306798f9ac..ee4409c274=20= 100644=0A---=20a/src/bin/pg_dump/pg_backup_utils.h=0A+++=20= b/src/bin/pg_dump/pg_backup_utils.h=0A@@=20-15,22=20+15,14=20@@=0A=20= #ifndef=20PG_BACKUP_UTILS_H=0A=20#define=20PG_BACKUP_UTILS_H=0A=20=0A= -#include=20"common/logging.h"=0A-=0A=20/*=20bits=20returned=20by=20= set_dump_section=20*/=0A=20#define=20DUMP_PRE_DATA=09=090x01=0A=20= #define=20DUMP_DATA=09=09=090x02=0A=20#define=20DUMP_POST_DATA=09=090x04=0A= =20#define=20DUMP_UNSECTIONED=090xff=0A=20=0A-typedef=20void=20= (*on_exit_nicely_callback)=20(int=20code,=20void=20*arg);=0A-=0A=20= extern=20const=20char=20*progname;=0A=20=0A=20extern=20void=20= set_dump_section(const=20char=20*arg,=20int=20*dumpSections);=0A-extern=20= void=20on_exit_nicely(on_exit_nicely_callback=20function,=20void=20= *arg);=0A-extern=20void=20exit_nicely(int=20code)=20= pg_attribute_noreturn();=0A-=0A-#define=20fatal(...)=20do=20{=20= pg_log_error(__VA_ARGS__);=20exit_nicely(1);=20}=20while(0)=0A=20=0A=20= #endif=09=09=09=09=09=09=09/*=20PG_BACKUP_UTILS_H=20*/=0Adiff=20--git=20= a/src/fe_utils/Makefile=20b/src/fe_utils/Makefile=0Aindex=20= 10d6838cf9..d6c328faf1=20100644=0A---=20a/src/fe_utils/Makefile=0A+++=20= b/src/fe_utils/Makefile=0A@@=20-23,6=20+23,7=20@@=20OBJS=20=3D=20\=0A=20=09= archive.o=20\=0A=20=09cancel.o=20\=0A=20=09conditional.o=20\=0A+=09= exit_utils.o=20\=0A=20=09mbprint.o=20\=0A=20=09print.o=20\=0A=20=09= psqlscan.o=20\=0Adiff=20--git=20a/src/fe_utils/exit_utils.c=20= b/src/fe_utils/exit_utils.c=0Anew=20file=20mode=20100644=0Aindex=20= 0000000000..e61bd438fc=0A---=20/dev/null=0A+++=20= b/src/fe_utils/exit_utils.c=0A@@=20-0,0=20+1,71=20@@=0A= +/*-----------------------------------------------------------------------= --=0A+=20*=0A+=20*=20Exiting=20with=20cleanup=20callback=20facilities=20= for=20frontend=20code=0A+=20*=0A+=20*=20Portions=20Copyright=20(c)=20= 1996-2020,=20PostgreSQL=20Global=20Development=20Group=0A+=20*=20= Portions=20Copyright=20(c)=201994,=20Regents=20of=20the=20University=20= of=20California=0A+=20*=0A+=20*=20src/fe_utils/exit_utils.c=0A+=20*=0A+=20= *-------------------------------------------------------------------------= =0A+=20*/=0A+=0A+#include=20"fe_utils/exit_utils.h"=0A+=0A+#define=20= MAX_ON_EXIT_NICELY=09=09=09=0920=0A+=0A+static=20struct=0A+{=0A+=09= on_exit_nicely_callback=20function;=0A+=09void=09=20=20=20*arg;=0A+}=09=09= =09on_exit_nicely_list[MAX_ON_EXIT_NICELY];=0A+=0A+static=20int=09= on_exit_nicely_index;=0A+=0A+/*=20Register=20a=20callback=20to=20be=20= run=20when=20exit_nicely=20is=20invoked.=20*/=0A+void=0A= +on_exit_nicely(on_exit_nicely_callback=20function,=20void=20*arg)=0A+{=0A= +=09if=20(on_exit_nicely_index=20>=3D=20MAX_ON_EXIT_NICELY)=0A+=09{=0A+=09= =09pg_log_fatal("out=20of=20on_exit_nicely=20slots");=0A+=09=09= exit_nicely(1);=0A+=09}=0A+=09= on_exit_nicely_list[on_exit_nicely_index].function=20=3D=20function;=0A+=09= on_exit_nicely_list[on_exit_nicely_index].arg=20=3D=20arg;=0A+=09= on_exit_nicely_index++;=0A+}=0A+=0A+/*=0A+=20*=20Run=20accumulated=20= on_exit_nicely=20callbacks=20in=20reverse=20order=20and=20then=20exit=0A= +=20*=20without=20printing=20any=20message.=0A+=20*=0A+=20*=20If=20= running=20in=20a=20parallel=20worker=20thread=20on=20Windows,=20we=20= only=20exit=20the=20thread,=0A+=20*=20not=20the=20whole=20process.=0A+=20= *=0A+=20*=20Note=20that=20in=20parallel=20operation=20on=20Windows,=20= the=20callback(s)=20will=20be=20run=0A+=20*=20by=20each=20thread=20since=20= the=20list=20state=20is=20necessarily=20shared=20by=20all=20threads;=0A+=20= *=20each=20callback=20must=20contain=20logic=20to=20ensure=20it=20does=20= only=20what's=20appropriate=0A+=20*=20for=20its=20thread.=20=20On=20= Unix,=20callbacks=20are=20also=20run=20by=20each=20process,=20but=20only=0A= +=20*=20for=20callbacks=20established=20before=20we=20fork=20off=20the=20= child=20processes.=20=20(It'd=0A+=20*=20be=20cleaner=20to=20reset=20the=20= list=20after=20fork(),=20and=20let=20each=20child=20establish=0A+=20*=20= its=20own=20callbacks;=20but=20then=20the=20behavior=20would=20be=20= completely=20inconsistent=0A+=20*=20between=20Windows=20and=20Unix.=20=20= For=20now,=20just=20be=20sure=20to=20establish=20callbacks=0A+=20*=20= before=20forking=20to=20avoid=20inconsistency.)=0A+=20*/=0A+void=0A= +exit_nicely(int=20code)=0A+{=0A+=09int=09=09=09i;=0A+=0A+=09for=20(i=20= =3D=20on_exit_nicely_index=20-=201;=20i=20>=3D=200;=20i--)=0A+=09=09= on_exit_nicely_list[i].function(code,=0A+=09=09=09=09=09=09=09=09=09=09= on_exit_nicely_list[i].arg);=0A+=0A+#ifdef=20WIN32=0A+=09if=20= (parallel_init_done=20&&=20GetCurrentThreadId()=20!=3D=20mainThreadId)=0A= +=09=09_endthreadex(code);=0A+#endif=0A+=0A+=09exit(code);=0A+}=0Adiff=20= --git=20a/src/include/fe_utils/exit_utils.h=20= b/src/include/fe_utils/exit_utils.h=0Anew=20file=20mode=20100644=0Aindex=20= 0000000000..948d2fdb51=0A---=20/dev/null=0A+++=20= b/src/include/fe_utils/exit_utils.h=0A@@=20-0,0=20+1,25=20@@=0A= +/*-----------------------------------------------------------------------= --=0A+=20*=0A+=20*=20Exiting=20with=20cleanup=20callback=20facilities=20= for=20frontend=20code=0A+=20*=0A+=20*=20Portions=20Copyright=20(c)=20= 1996-2020,=20PostgreSQL=20Global=20Development=20Group=0A+=20*=20= Portions=20Copyright=20(c)=201994,=20Regents=20of=20the=20University=20= of=20California=0A+=20*=0A+=20*=20src/include/fe_utils/exit_utils.h=0A+=20= *=0A+=20= *-------------------------------------------------------------------------= =0A+=20*/=0A+#ifndef=20EXIT_UTILS_H=0A+#define=20EXIT_UTILS_H=0A+=0A= +#include=20"postgres_fe.h"=0A+#include=20"common/logging.h"=0A+=0A= +typedef=20void=20(*on_exit_nicely_callback)=20(int=20code,=20void=20= *arg);=0A+=0A+extern=20void=20on_exit_nicely(on_exit_nicely_callback=20= function,=20void=20*arg);=0A+extern=20void=20exit_nicely(int=20code)=20= pg_attribute_noreturn();=0A+=0A+#define=20fatal(...)=20do=20{=20= pg_log_error(__VA_ARGS__);=20exit_nicely(1);=20}=20while(0)=0A+=0A= +#endif=09=09=09=09=09=09=09/*=20EXIT_UTILS_H=20*/=0A--=20=0A2.21.1=20= (Apple=20Git-122.3)=0A=0A= --Apple-Mail=_8B07CFD0-2450-4CA2-BEE1-ACB2F7EEE33B Content-Disposition: attachment; filename=v32-0002-Refactoring-ExecuteSqlQuery-and-related-function.patch Content-Type: application/octet-stream; x-unix-mode=0644; name="v32-0002-Refactoring-ExecuteSqlQuery-and-related-function.patch" Content-Transfer-Encoding: quoted-printable =46rom=2019a006bf7841fa4405e42be790dd5fe6f24b14a8=20Mon=20Sep=2017=20= 00:00:00=202001=0AFrom:=20Mark=20Dilger=20=0A= Date:=20Mon,=204=20Jan=202021=2012:44:20=20-0800=0ASubject:=20[PATCH=20= v32=202/9]=20Refactoring=20ExecuteSqlQuery=20and=20related=20functions.=0A= =0AExecuteSqlQuery,=20ExecuteSqlQueryForSingleRow,=20and=0A= ExecuteSqlStatement=20in=20the=20pg_dump=20project=20were=20defined=20to=20= take=20a=0Apointer=20to=20struct=20Archive,=20which=20is=20a=20struct=20= unused=20outside=20pg_dump.=0AIn=20preparation=20for=20moving=20these=20= functions=20to=20fe_utils,=20refactoring=0Athese=20functions=20to=20take=20= a=20PGconn=20pointer.=20=20These=20functions=20also=0Aembedded=20pg_dump=20= assumptions=20about=20the=20correct=20error=20handling=0Abehavior,=20= specifically=20to=20do=20with=20logging=20error=20messages=20before=0A= calling=20exit_nicely().=20=20Refactoring=20the=20error=20handling=20= logic=20into=20a=0Ahandler=20function.=20=20The=20full=20design=20of=20= the=20handler=20is=20not=20yet=0Apresent,=20as=20it=20will=20be=20= developed=20further=20after=20moving=20to=20fe_utils,=0Abut=20the=20idea=20= is=20that=20callers=20will=20ultimately=20be=20able=20to=20override=20= the=0Aerror=20handling=20behavior=20by=20defining=20alternate=20= handlers.=0A=0ATo=20minimize=20changes=20to=20pg_dump=20and=20friends,=20= creating=20thin=20wrappers=0Aaround=20these=20functions=20that=20take=20= an=20Archive=20pointer.=20=20It=20might=20be=0Amarginally=20cleaner=20in=20= the=20long=20run=20to=20refactor=20pg_dump.c=20to=20call=0Awith=20a=20= PGconn=20pointer=20in=20all=20relevant=20call=20sites,=20but=20that=20= would=0Aresult=20in=20a=20nontrivially=20larger=20patch=20and=20more=20= code=20churn,=20so=20not=0Adoing=20that=20here.=20=20Another=20option=20= might=20be=20to=20define=20the=20thin=0Awrappers=20as=20static=20inline=20= functions,=20but=20that=20seems=20inconsistent=0Awith=20the=20rest=20of=20= the=20pg_dump=20project=20style,=20so=20not=20doing=20that=0Aeither.=20=20= Should=20we?=0A---=0A=20src/bin/pg_dump/pg_backup_db.c=20|=20144=20= ++++++++++++++-----=0A=20src/bin/pg_dump/pg_backup_db.h=20|=20=2026=20= +++-=0A=20src/bin/pg_dump/pg_dump.c=20=20=20=20=20=20|=20248=20= ++++++++++++++++-----------------=0A=203=20files=20changed,=20253=20= insertions(+),=20165=20deletions(-)=0A=0Adiff=20--git=20= a/src/bin/pg_dump/pg_backup_db.c=20b/src/bin/pg_dump/pg_backup_db.c=0A= index=205ba43441f5..b55a968da2=20100644=0A---=20= a/src/bin/pg_dump/pg_backup_db.c=0A+++=20= b/src/bin/pg_dump/pg_backup_db.c=0A@@=20-61,7=20+61,7=20@@=20= _check_database_version(ArchiveHandle=20*AH)=0A=20=09=20*/=0A=20=09if=20= (remoteversion=20>=3D=2090000)=0A=20=09{=0A-=09=09res=20=3D=20= ExecuteSqlQueryForSingleRow((Archive=20*)=20AH,=20"SELECT=20= pg_catalog.pg_is_in_recovery()");=0A+=09=09res=20=3D=20= ExecuteSqlQueryForSingleRowAH((Archive=20*)=20AH,=20"SELECT=20= pg_catalog.pg_is_in_recovery()");=0A=20=0A=20=09=09AH->public.isStandby=20= =3D=20(strcmp(PQgetvalue(res,=200,=200),=20"t")=20=3D=3D=200);=0A=20=09=09= PQclear(res);=0A@@=20-198,8=20+198,8=20@@=20ConnectDatabase(Archive=20= *AHX,=0A=20=09}=0A=20=0A=20=09/*=20Start=20strict;=20later=20phases=20= may=20override=20this.=20*/=0A-=09= PQclear(ExecuteSqlQueryForSingleRow((Archive=20*)=20AH,=0A-=09=09=09=09=09= =09=09=09=09=09ALWAYS_SECURE_SEARCH_PATH_SQL));=0A+=09= PQclear(ExecuteSqlQueryForSingleRowAH((Archive=20*)=20AH,=0A+=09=09=09=09= =09=09=09=09=09=09=20=20ALWAYS_SECURE_SEARCH_PATH_SQL));=0A=20=0A=20=09= if=20(password=20&&=20password=20!=3D=20AH->savedPassword)=0A=20=09=09= free(password);=0A@@=20-271,59=20+271,129=20@@=20notice_processor(void=20= *arg,=20const=20char=20*message)=0A=20=09pg_log_generic(PG_LOG_INFO,=20= "%s",=20message);=0A=20}=0A=20=0A-/*=20Like=20fatal(),=20but=20with=20a=20= complaint=20about=20a=20particular=20query.=20*/=0A-static=20void=0A= -die_on_query_failure(ArchiveHandle=20*AH,=20const=20char=20*query)=0A= +/*=0A+=20*=20The=20exiting=20query=20result=20handler=20embeds=20the=20= historical=20pg_dump=20behavior=0A+=20*=20under=20query=20error=20= conditions,=20including=20exiting=20nicely.=20=20The=20'conn'=20object=0A= +=20*=20is=20unused=20here,=20but=20is=20included=20in=20the=20interface=20= for=20alternate=20query=20result=0A+=20*=20handler=20implementations.=0A= +=20*=0A+=20*=20Whether=20the=20query=20was=20successful=20is=20= determined=20by=20comparing=20the=20returned=0A+=20*=20status=20code=20= against=20the=20expected=20status=20code,=20and=20by=20comparing=20the=20= number=20of=0A+=20*=20tuples=20returned=20from=20the=20query=20against=20= expected_ntups.=20=20Special=20negative=0A+=20*=20values=20of=20= expected_ntups=20can=20be=20used=20to=20require=20at=20least=20one=20row=20= or=20to=0A+=20*=20disables=20ntup=20checking.=0A+=20*=0A+=20*=20Exits=20= on=20failure.=20=20On=20successful=20query=20completion,=20returns=20the=20= 'res'=0A+=20*=20argument=20as=20a=20notational=20convenience.=0A+=20*/=0A= +PGresult=20*=0A+exiting_handler(PGresult=20*res,=20PGconn=20*conn,=20= ExecStatusType=20expected_status,=0A+=09=09=09=09=20=20int=20= expected_ntups,=20const=20char=20*query)=0A=20{=0A-=09= pg_log_error("query=20failed:=20%s",=0A-=09=09=09=09=20= PQerrorMessage(AH->connection));=0A-=09fatal("query=20was:=20%s",=20= query);=0A+=09if=20(PQresultStatus(res)=20!=3D=20expected_status)=0A+=09= {=0A+=09=09pg_log_error("query=20failed:=20%s",=20PQerrorMessage(conn));=0A= +=09=09pg_log_error("query=20was:=20%s",=20query);=0A+=09=09= PQfinish(conn);=0A+=09=09exit_nicely(1);=0A+=09}=0A+=09if=20= (expected_ntups=20=3D=3D=20POSITIVE_NTUPS=20||=20expected_ntups=20>=3D=20= 0)=0A+=09{=0A+=09=09int=20ntups=20=3D=20PQntuples(res);=0A+=0A+=09=09if=20= (expected_ntups=20=3D=3D=20POSITIVE_NTUPS)=0A+=09=09{=0A+=09=09=09if=20= (ntups=20=3D=3D=200)=0A+=09=09=09=09fatal("query=20returned=20no=20rows:=20= %s",=20query);=0A+=09=09}=0A+=09=09else=20if=20(ntups=20!=3D=20= expected_ntups)=0A+=09=09{=0A+=09=09=09/*=0A+=09=09=09=20*=20Preserve=20= historical=20message=20behavior=20of=20spelling=20"one"=20as=20the=0A+=09= =09=09=20*=20expected=20row=20count.=0A+=09=09=09=20*/=0A+=09=09=09if=20= (expected_ntups=20=3D=3D=201)=0A+=09=09=09=09fatal(ngettext("query=20= returned=20%d=20row=20instead=20of=20one:=20%s",=0A+=09=09=09=09=09=09=09= =20=20=20"query=20returned=20%d=20rows=20instead=20of=20one:=20%s",=0A+=09= =09=09=09=09=09=09=20=20=20ntups),=0A+=09=09=09=09=09ntups,=20query);=0A= +=09=09=09fatal(ngettext("query=20returned=20%d=20row=20instead=20of=20= %d:=20%s",=0A+=09=09=09=09=09=09=20=20=20"query=20returned=20%d=20rows=20= instead=20of=20%d:=20%s",=0A+=09=09=09=09=09=09=20=20=20ntups),=0A+=09=09= =09=09ntups,=20expected_ntups,=20query);=0A+=09=09}=0A+=09}=0A+=09return=20= res;=0A=20}=0A=20=0A+/*=0A+=20*=20Executes=20the=20given=20SQL=20query=20= statement.=0A+=20*=0A+=20*=20Invokes=20the=20exiting=20handler=20for=20= any=20but=20PGRES_COMMAND_OK=20status.=0A+=20*/=0A=20void=0A= -ExecuteSqlStatement(Archive=20*AHX,=20const=20char=20*query)=0A= +ExecuteSqlStatement(PGconn=20*conn,=20const=20char=20*query)=0A=20{=0A-=09= ArchiveHandle=20*AH=20=3D=20(ArchiveHandle=20*)=20AHX;=0A-=09PGresult=20=20= =20*res;=0A+=09PQclear(exiting_handler(PQexec(conn,=20query),=0A+=09=09=09= =09=09=09=09conn,=0A+=09=09=09=09=09=09=09PGRES_COMMAND_OK,=0A+=09=09=09=09= =09=09=09ANY_NTUPS,=0A+=09=09=09=09=09=09=09query));=0A+}=0A=20=0A-=09= res=20=3D=20PQexec(AH->connection,=20query);=0A-=09if=20= (PQresultStatus(res)=20!=3D=20PGRES_COMMAND_OK)=0A-=09=09= die_on_query_failure(AH,=20query);=0A-=09PQclear(res);=0A+/*=0A+=20*=20= Executes=20the=20given=20SQL=20query.=0A+=20*=0A+=20*=20Invokes=20the=20= exiting=20handler=20unless=20the=20given=20'status'=20results.=0A+=20*=0A= +=20*=20If=20successful,=20returns=20the=20query=20result.=0A+=20*/=0A= +PGresult=20*=0A+ExecuteSqlQuery(PGconn=20*conn,=20const=20char=20= *query,=20ExecStatusType=20status)=0A+{=0A+=09return=20= exiting_handler(PQexec(conn,=20query),=0A+=09=09=09=09=09=09=20=20=20= conn,=0A+=09=09=09=09=09=09=20=20=20status,=0A+=09=09=09=09=09=09=20=20=20= ANY_NTUPS,=0A+=09=09=09=09=09=09=20=20=20query);=0A=20}=0A=20=0A+/*=0A+=20= *=20Like=20ExecuteSqlQuery,=20but=20requires=20PGRES_TUPLES_OK=20status=20= and=0A+=20*=20requires=20that=20exactly=20one=20row=20be=20returned.=0A+=20= */=0A=20PGresult=20*=0A-ExecuteSqlQuery(Archive=20*AHX,=20const=20char=20= *query,=20ExecStatusType=20status)=0A+ExecuteSqlQueryForSingleRow(PGconn=20= *conn,=20const=20char=20*query)=0A+{=0A+=09return=20= exiting_handler(PQexec(conn,=20query),=0A+=09=09=09=09=09=09=20=20=20= conn,=0A+=09=09=09=09=09=09=20=20=20PGRES_TUPLES_OK,=0A+=09=09=09=09=09=09= =20=20=201,=0A+=09=09=09=09=09=09=20=20=20query);=0A+}=0A+=0A+void=0A= +ExecuteSqlStatementAH(Archive=20*AHX,=20const=20char=20*query)=0A=20{=0A= =20=09ArchiveHandle=20*AH=20=3D=20(ArchiveHandle=20*)=20AHX;=0A-=09= PGresult=20=20=20*res;=0A=20=0A-=09res=20=3D=20PQexec(AH->connection,=20= query);=0A-=09if=20(PQresultStatus(res)=20!=3D=20status)=0A-=09=09= die_on_query_failure(AH,=20query);=0A-=09return=20res;=0A+=09= ExecuteSqlStatement(AH->connection,=20query);=0A=20}=0A=20=0A-/*=0A-=20*=20= Execute=20an=20SQL=20query=20and=20verify=20that=20we=20got=20exactly=20= one=20row=20back.=0A-=20*/=0A=20PGresult=20*=0A= -ExecuteSqlQueryForSingleRow(Archive=20*fout,=20const=20char=20*query)=0A= +ExecuteSqlQueryAH(Archive=20*AHX,=20const=20char=20*query,=20= ExecStatusType=20status)=0A=20{=0A-=09PGresult=20=20=20*res;=0A-=09int=09= =09=09ntups;=0A+=09ArchiveHandle=20*AH=20=3D=20(ArchiveHandle=20*)=20= AHX;=0A=20=0A-=09res=20=3D=20ExecuteSqlQuery(fout,=20query,=20= PGRES_TUPLES_OK);=0A+=09return=20ExecuteSqlQuery(AH->connection,=20= query,=20status);=0A+}=0A=20=0A-=09/*=20Expecting=20a=20single=20result=20= only=20*/=0A-=09ntups=20=3D=20PQntuples(res);=0A-=09if=20(ntups=20!=3D=20= 1)=0A-=09=09fatal(ngettext("query=20returned=20%d=20row=20instead=20of=20= one:=20%s",=0A-=09=09=09=09=09=20=20=20"query=20returned=20%d=20rows=20= instead=20of=20one:=20%s",=0A-=09=09=09=09=09=20=20=20ntups),=0A-=09=09=09= =20=20ntups,=20query);=0A+PGresult=20*=0A= +ExecuteSqlQueryForSingleRowAH(Archive=20*AHX,=20const=20char=20*query)=0A= +{=0A+=09ArchiveHandle=20*AH=20=3D=20(ArchiveHandle=20*)=20AHX;=0A=20=0A= -=09return=20res;=0A+=09return=20= ExecuteSqlQueryForSingleRow(AH->connection,=20query);=0A=20}=0A=20=0A=20= /*=0Adiff=20--git=20a/src/bin/pg_dump/pg_backup_db.h=20= b/src/bin/pg_dump/pg_backup_db.h=0Aindex=208888dd34b9..1aac600ece=20= 100644=0A---=20a/src/bin/pg_dump/pg_backup_db.h=0A+++=20= b/src/bin/pg_dump/pg_backup_db.h=0A@@=20-13,10=20+13,28=20@@=0A=20=0A=20= extern=20int=09ExecuteSqlCommandBuf(Archive=20*AHX,=20const=20char=20= *buf,=20size_t=20bufLen);=0A=20=0A-extern=20void=20= ExecuteSqlStatement(Archive=20*AHX,=20const=20char=20*query);=0A-extern=20= PGresult=20*ExecuteSqlQuery(Archive=20*AHX,=20const=20char=20*query,=0A-=09= =09=09=09=09=09=09=09=20ExecStatusType=20status);=0A-extern=20PGresult=20= *ExecuteSqlQueryForSingleRow(Archive=20*fout,=20const=20char=20*query);=0A= +#define=20POSITIVE_NTUPS=20(-1)=0A+#define=20ANY_NTUPS=20(-2)=0A= +typedef=20PGresult=20*(*PGresultHandler)=20(PGresult=20*res,=0A+=09=09=09= =09=09=09=09=09=09=20=20PGconn=20*conn,=0A+=09=09=09=09=09=09=09=09=09=20= =20ExecStatusType=20expected_status,=0A+=09=09=09=09=09=09=09=09=09=20=20= int=20expected_ntups,=0A+=09=09=09=09=09=09=09=09=09=20=20const=20char=20= *query);=0A+=0A+extern=20PGresult=20*exiting_handler(PGresult=20*res,=20= PGconn=20*conn,=0A+=09=09=09=09=09=09=09=09=20ExecStatusType=20= expected_status,=0A+=09=09=09=09=09=09=09=09=20int=20expected_ntups,=20= const=20char=20*query);=0A+=0A+extern=20void=20= ExecuteSqlStatement(PGconn=20*conn,=20const=20char=20*query);=0A+extern=20= PGresult=20*ExecuteSqlQuery(PGconn=20*conn,=20const=20char=20*query,=0A+=09= =09=09=09=09=09=09=09=20ExecStatusType=20expected_status);=0A+extern=20= PGresult=20*ExecuteSqlQueryForSingleRow(PGconn=20*conn,=20const=20char=20= *query);=0A+=0A+extern=20void=20ExecuteSqlStatementAH(Archive=20*AHX,=20= const=20char=20*query);=0A+extern=20PGresult=20= *ExecuteSqlQueryAH(Archive=20*AHX,=20const=20char=20*query,=0A+=09=09=09=09= =09=09=09=09=20=20=20ExecStatusType=20status);=0A+extern=20PGresult=20= *ExecuteSqlQueryForSingleRowAH(Archive=20*fout,=0A+=09=09=09=09=09=09=09=09= =09=09=09=20=20=20const=20char=20*query);=0A=20=0A=20extern=20void=20= EndDBCopyMode(Archive=20*AHX,=20const=20char=20*tocEntryTag);=0A=20=0A= diff=20--git=20a/src/bin/pg_dump/pg_dump.c=20b/src/bin/pg_dump/pg_dump.c=0A= index=201f70653c02..e8985a834f=20100644=0A---=20= a/src/bin/pg_dump/pg_dump.c=0A+++=20b/src/bin/pg_dump/pg_dump.c=0A@@=20= -1084,7=20+1084,7=20@@=20setup_connection(Archive=20*AH,=20const=20char=20= *dumpencoding,=0A=20=09PGconn=09=20=20=20*conn=20=3D=20= GetConnection(AH);=0A=20=09const=20char=20*std_strings;=0A=20=0A-=09= PQclear(ExecuteSqlQueryForSingleRow(AH,=20= ALWAYS_SECURE_SEARCH_PATH_SQL));=0A+=09= PQclear(ExecuteSqlQueryForSingleRowAH(AH,=20= ALWAYS_SECURE_SEARCH_PATH_SQL));=0A=20=0A=20=09/*=0A=20=09=20*=20Set=20= the=20client=20encoding=20if=20requested.=0A@@=20-1119,7=20+1119,7=20@@=20= setup_connection(Archive=20*AH,=20const=20char=20*dumpencoding,=0A=20=09=09= PQExpBuffer=20query=20=3D=20createPQExpBuffer();=0A=20=0A=20=09=09= appendPQExpBuffer(query,=20"SET=20ROLE=20%s",=20fmtId(use_role));=0A-=09=09= ExecuteSqlStatement(AH,=20query->data);=0A+=09=09= ExecuteSqlStatementAH(AH,=20query->data);=0A=20=09=09= destroyPQExpBuffer(query);=0A=20=0A=20=09=09/*=20save=20it=20for=20= possible=20later=20use=20by=20parallel=20workers=20*/=0A@@=20-1128,11=20= +1128,11=20@@=20setup_connection(Archive=20*AH,=20const=20char=20= *dumpencoding,=0A=20=09}=0A=20=0A=20=09/*=20Set=20the=20datestyle=20to=20= ISO=20to=20ensure=20the=20dump's=20portability=20*/=0A-=09= ExecuteSqlStatement(AH,=20"SET=20DATESTYLE=20=3D=20ISO");=0A+=09= ExecuteSqlStatementAH(AH,=20"SET=20DATESTYLE=20=3D=20ISO");=0A=20=0A=20=09= /*=20Likewise,=20avoid=20using=20sql_standard=20intervalstyle=20*/=0A=20=09= if=20(AH->remoteVersion=20>=3D=2080400)=0A-=09=09ExecuteSqlStatement(AH,=20= "SET=20INTERVALSTYLE=20=3D=20POSTGRES");=0A+=09=09= ExecuteSqlStatementAH(AH,=20"SET=20INTERVALSTYLE=20=3D=20POSTGRES");=0A=20= =0A=20=09/*=0A=20=09=20*=20Use=20an=20explicitly=20specified=20= extra_float_digits=20if=20it=20has=20been=20provided.=0A@@=20-1145,35=20= +1145,35=20@@=20setup_connection(Archive=20*AH,=20const=20char=20= *dumpencoding,=0A=20=0A=20=09=09appendPQExpBuffer(q,=20"SET=20= extra_float_digits=20TO=20%d",=0A=20=09=09=09=09=09=09=20=20= extra_float_digits);=0A-=09=09ExecuteSqlStatement(AH,=20q->data);=0A+=09=09= ExecuteSqlStatementAH(AH,=20q->data);=0A=20=09=09destroyPQExpBuffer(q);=0A= =20=09}=0A=20=09else=20if=20(AH->remoteVersion=20>=3D=2090000)=0A-=09=09= ExecuteSqlStatement(AH,=20"SET=20extra_float_digits=20TO=203");=0A+=09=09= ExecuteSqlStatementAH(AH,=20"SET=20extra_float_digits=20TO=203");=0A=20=09= else=0A-=09=09ExecuteSqlStatement(AH,=20"SET=20extra_float_digits=20TO=20= 2");=0A+=09=09ExecuteSqlStatementAH(AH,=20"SET=20extra_float_digits=20TO=20= 2");=0A=20=0A=20=09/*=0A=20=09=20*=20If=20synchronized=20scanning=20is=20= supported,=20disable=20it,=20to=20prevent=0A=20=09=20*=20unpredictable=20= changes=20in=20row=20ordering=20across=20a=20dump=20and=20reload.=0A=20=09= =20*/=0A=20=09if=20(AH->remoteVersion=20>=3D=2080300)=0A-=09=09= ExecuteSqlStatement(AH,=20"SET=20synchronize_seqscans=20TO=20off");=0A+=09= =09ExecuteSqlStatementAH(AH,=20"SET=20synchronize_seqscans=20TO=20off");=0A= =20=0A=20=09/*=0A=20=09=20*=20Disable=20timeouts=20if=20supported.=0A=20=09= =20*/=0A-=09ExecuteSqlStatement(AH,=20"SET=20statement_timeout=20=3D=20= 0");=0A+=09ExecuteSqlStatementAH(AH,=20"SET=20statement_timeout=20=3D=20= 0");=0A=20=09if=20(AH->remoteVersion=20>=3D=2090300)=0A-=09=09= ExecuteSqlStatement(AH,=20"SET=20lock_timeout=20=3D=200");=0A+=09=09= ExecuteSqlStatementAH(AH,=20"SET=20lock_timeout=20=3D=200");=0A=20=09if=20= (AH->remoteVersion=20>=3D=2090600)=0A-=09=09ExecuteSqlStatement(AH,=20= "SET=20idle_in_transaction_session_timeout=20=3D=200");=0A+=09=09= ExecuteSqlStatementAH(AH,=20"SET=20idle_in_transaction_session_timeout=20= =3D=200");=0A=20=0A=20=09/*=0A=20=09=20*=20Quote=20all=20identifiers,=20= if=20requested.=0A=20=09=20*/=0A=20=09if=20(quote_all_identifiers=20&&=20= AH->remoteVersion=20>=3D=2090100)=0A-=09=09ExecuteSqlStatement(AH,=20= "SET=20quote_all_identifiers=20=3D=20true");=0A+=09=09= ExecuteSqlStatementAH(AH,=20"SET=20quote_all_identifiers=20=3D=20true");=0A= =20=0A=20=09/*=0A=20=09=20*=20Adjust=20row-security=20mode,=20if=20= supported.=0A@@=20-1181,15=20+1181,15=20@@=20setup_connection(Archive=20= *AH,=20const=20char=20*dumpencoding,=0A=20=09if=20(AH->remoteVersion=20= >=3D=2090500)=0A=20=09{=0A=20=09=09if=20(dopt->enable_row_security)=0A-=09= =09=09ExecuteSqlStatement(AH,=20"SET=20row_security=20=3D=20on");=0A+=09=09= =09ExecuteSqlStatementAH(AH,=20"SET=20row_security=20=3D=20on");=0A=20=09= =09else=0A-=09=09=09ExecuteSqlStatement(AH,=20"SET=20row_security=20=3D=20= off");=0A+=09=09=09ExecuteSqlStatementAH(AH,=20"SET=20row_security=20=3D=20= off");=0A=20=09}=0A=20=0A=20=09/*=0A=20=09=20*=20Start=20= transaction-snapshot=20mode=20transaction=20to=20dump=20consistent=20= data.=0A=20=09=20*/=0A-=09ExecuteSqlStatement(AH,=20"BEGIN");=0A+=09= ExecuteSqlStatementAH(AH,=20"BEGIN");=0A=20=09if=20(AH->remoteVersion=20= >=3D=2090100)=0A=20=09{=0A=20=09=09/*=0A@@=20-1201,17=20+1201,17=20@@=20= setup_connection(Archive=20*AH,=20const=20char=20*dumpencoding,=0A=20=09=09= =20*=20guarantees.=20=20This=20is=20a=20kluge,=20but=20safe=20for=20= back-patching.=0A=20=09=09=20*/=0A=20=09=09if=20= (dopt->serializable_deferrable=20&&=20AH->sync_snapshot_id=20=3D=3D=20= NULL)=0A-=09=09=09ExecuteSqlStatement(AH,=0A+=09=09=09= ExecuteSqlStatementAH(AH,=0A=20=09=09=09=09=09=09=09=09"SET=20= TRANSACTION=20ISOLATION=20LEVEL=20"=0A=20=09=09=09=09=09=09=09=09= "SERIALIZABLE,=20READ=20ONLY,=20DEFERRABLE");=0A=20=09=09else=0A-=09=09=09= ExecuteSqlStatement(AH,=0A+=09=09=09ExecuteSqlStatementAH(AH,=0A=20=09=09= =09=09=09=09=09=09"SET=20TRANSACTION=20ISOLATION=20LEVEL=20"=0A=20=09=09=09= =09=09=09=09=09"REPEATABLE=20READ,=20READ=20ONLY");=0A=20=09}=0A=20=09= else=0A=20=09{=0A-=09=09ExecuteSqlStatement(AH,=0A+=09=09= ExecuteSqlStatementAH(AH,=0A=20=09=09=09=09=09=09=09"SET=20TRANSACTION=20= ISOLATION=20LEVEL=20"=0A=20=09=09=09=09=09=09=09"SERIALIZABLE,=20READ=20= ONLY");=0A=20=09}=0A@@=20-1230,7=20+1230,7=20@@=20= setup_connection(Archive=20*AH,=20const=20char=20*dumpencoding,=0A=20=0A=20= =09=09appendPQExpBufferStr(query,=20"SET=20TRANSACTION=20SNAPSHOT=20");=0A= =20=09=09appendStringLiteralConn(query,=20AH->sync_snapshot_id,=20conn);=0A= -=09=09ExecuteSqlStatement(AH,=20query->data);=0A+=09=09= ExecuteSqlStatementAH(AH,=20query->data);=0A=20=09=09= destroyPQExpBuffer(query);=0A=20=09}=0A=20=09else=20if=20(AH->numWorkers=20= >=201=20&&=0A@@=20-1270,7=20+1270,7=20@@=20= get_synchronized_snapshot(Archive=20*fout)=0A=20=09char=09=20=20=20= *result;=0A=20=09PGresult=20=20=20*res;=0A=20=0A-=09res=20=3D=20= ExecuteSqlQueryForSingleRow(fout,=20query);=0A+=09res=20=3D=20= ExecuteSqlQueryForSingleRowAH(fout,=20query);=0A=20=09result=20=3D=20= pg_strdup(PQgetvalue(res,=200,=200));=0A=20=09PQclear(res);=0A=20=0A@@=20= -1343,7=20+1343,7=20@@=20expand_schema_name_patterns(Archive=20*fout,=0A=20= =09=09processSQLNamePattern(GetConnection(fout),=20query,=20cell->val,=20= false,=0A=20=09=09=09=09=09=09=09=20=20false,=20NULL,=20"n.nspname",=20= NULL,=20NULL);=0A=20=0A-=09=09res=20=3D=20ExecuteSqlQuery(fout,=20= query->data,=20PGRES_TUPLES_OK);=0A+=09=09res=20=3D=20= ExecuteSqlQueryAH(fout,=20query->data,=20PGRES_TUPLES_OK);=0A=20=09=09if=20= (strict_names=20&&=20PQntuples(res)=20=3D=3D=200)=0A=20=09=09=09= fatal("no=20matching=20schemas=20were=20found=20for=20pattern=20\"%s\"",=20= cell->val);=0A=20=0A@@=20-1390,7=20+1390,7=20@@=20= expand_foreign_server_name_patterns(Archive=20*fout,=0A=20=09=09= processSQLNamePattern(GetConnection(fout),=20query,=20cell->val,=20= false,=0A=20=09=09=09=09=09=09=09=20=20false,=20NULL,=20"s.srvname",=20= NULL,=20NULL);=0A=20=0A-=09=09res=20=3D=20ExecuteSqlQuery(fout,=20= query->data,=20PGRES_TUPLES_OK);=0A+=09=09res=20=3D=20= ExecuteSqlQueryAH(fout,=20query->data,=20PGRES_TUPLES_OK);=0A=20=09=09if=20= (PQntuples(res)=20=3D=3D=200)=0A=20=09=09=09fatal("no=20matching=20= foreign=20servers=20were=20found=20for=20pattern=20\"%s\"",=20= cell->val);=0A=20=0A@@=20-1450,9=20+1450,9=20@@=20= expand_table_name_patterns(Archive=20*fout,=0A=20=09=09=09=09=09=09=09=20= =20false,=20"n.nspname",=20"c.relname",=20NULL,=0A=20=09=09=09=09=09=09=09= =20=20"pg_catalog.pg_table_is_visible(c.oid)");=0A=20=0A-=09=09= ExecuteSqlStatement(fout,=20"RESET=20search_path");=0A-=09=09res=20=3D=20= ExecuteSqlQuery(fout,=20query->data,=20PGRES_TUPLES_OK);=0A-=09=09= PQclear(ExecuteSqlQueryForSingleRow(fout,=0A+=09=09= ExecuteSqlStatementAH(fout,=20"RESET=20search_path");=0A+=09=09res=20=3D=20= ExecuteSqlQueryAH(fout,=20query->data,=20PGRES_TUPLES_OK);=0A+=09=09= PQclear(ExecuteSqlQueryForSingleRowAH(fout,=0A=20=09=09=09=09=09=09=09=09= =09=09=09ALWAYS_SECURE_SEARCH_PATH_SQL));=0A=20=09=09if=20(strict_names=20= &&=20PQntuples(res)=20=3D=3D=200)=0A=20=09=09=09fatal("no=20matching=20= tables=20were=20found=20for=20pattern=20\"%s\"",=20cell->val);=0A@@=20= -1907,7=20+1907,7=20@@=20dumpTableData_copy(Archive=20*fout,=20void=20= *dcontext)=0A=20=09=09=09=09=09=09=20=20fmtQualifiedDumpable(tbinfo),=0A=20= =09=09=09=09=09=09=20=20column_list);=0A=20=09}=0A-=09res=20=3D=20= ExecuteSqlQuery(fout,=20q->data,=20PGRES_COPY_OUT);=0A+=09res=20=3D=20= ExecuteSqlQueryAH(fout,=20q->data,=20PGRES_COPY_OUT);=0A=20=09= PQclear(res);=0A=20=09destroyPQExpBuffer(clistBuf);=0A=20=0A@@=20= -2028,11=20+2028,11=20@@=20dumpTableData_insert(Archive=20*fout,=20void=20= *dcontext)=0A=20=09if=20(tdinfo->filtercond)=0A=20=09=09= appendPQExpBuffer(q,=20"=20%s",=20tdinfo->filtercond);=0A=20=0A-=09= ExecuteSqlStatement(fout,=20q->data);=0A+=09ExecuteSqlStatementAH(fout,=20= q->data);=0A=20=0A=20=09while=20(1)=0A=20=09{=0A-=09=09res=20=3D=20= ExecuteSqlQuery(fout,=20"FETCH=20100=20FROM=20_pg_dump_cursor",=0A+=09=09= res=20=3D=20ExecuteSqlQueryAH(fout,=20"FETCH=20100=20FROM=20= _pg_dump_cursor",=0A=20=09=09=09=09=09=09=09=20=20PGRES_TUPLES_OK);=0A=20= =09=09nfields=20=3D=20PQnfields(res);=0A=20=0A@@=20-2220,7=20+2220,7=20= @@=20dumpTableData_insert(Archive=20*fout,=20void=20*dcontext)=0A=20=0A=20= =09archputs("\n\n",=20fout);=0A=20=0A-=09ExecuteSqlStatement(fout,=20= "CLOSE=20_pg_dump_cursor");=0A+=09ExecuteSqlStatementAH(fout,=20"CLOSE=20= _pg_dump_cursor");=0A=20=0A=20=09destroyPQExpBuffer(q);=0A=20=09if=20= (insertStmt=20!=3D=20NULL)=0A@@=20-2520,7=20+2520,7=20@@=20= buildMatViewRefreshDependencies(Archive=20*fout)=0A=20=09=09=09=09=09=09=20= "FROM=20w=20"=0A=20=09=09=09=09=09=09=20"WHERE=20refrelkind=20=3D=20"=20= CppAsString2(RELKIND_MATVIEW));=0A=20=0A-=09res=20=3D=20= ExecuteSqlQuery(fout,=20query->data,=20PGRES_TUPLES_OK);=0A+=09res=20=3D=20= ExecuteSqlQueryAH(fout,=20query->data,=20PGRES_TUPLES_OK);=0A=20=0A=20=09= ntups=20=3D=20PQntuples(res);=0A=20=0A@@=20-2847,7=20+2847,7=20@@=20= dumpDatabase(Archive=20*fout)=0A=20=09=09=09=09=09=09=20=20= username_subquery);=0A=20=09}=0A=20=0A-=09res=20=3D=20= ExecuteSqlQueryForSingleRow(fout,=20dbQry->data);=0A+=09res=20=3D=20= ExecuteSqlQueryForSingleRowAH(fout,=20dbQry->data);=0A=20=0A=20=09= i_tableoid=20=3D=20PQfnumber(res,=20"tableoid");=0A=20=09i_oid=20=3D=20= PQfnumber(res,=20"oid");=0A@@=20-2992,7=20+2992,7=20@@=20= dumpDatabase(Archive=20*fout)=0A=20=09=09seclabelQry=20=3D=20= createPQExpBuffer();=0A=20=0A=20=09=09= buildShSecLabelQuery("pg_database",=20dbCatId.oid,=20seclabelQry);=0A-=09= =09shres=20=3D=20ExecuteSqlQuery(fout,=20seclabelQry->data,=20= PGRES_TUPLES_OK);=0A+=09=09shres=20=3D=20ExecuteSqlQueryAH(fout,=20= seclabelQry->data,=20PGRES_TUPLES_OK);=0A=20=09=09= resetPQExpBuffer(seclabelQry);=0A=20=09=09emitShSecLabels(conn,=20shres,=20= seclabelQry,=20"DATABASE",=20datname);=0A=20=09=09if=20(seclabelQry->len=20= >=200)=0A@@=20-3103,7=20+3103,7=20@@=20dumpDatabase(Archive=20*fout)=0A=20= =09=09=09=09=09=09=09=20=20"WHERE=20oid=20=3D=20%u;\n",=0A=20=09=09=09=09= =09=09=09=20=20LargeObjectRelationId);=0A=20=0A-=09=09lo_res=20=3D=20= ExecuteSqlQueryForSingleRow(fout,=20loFrozenQry->data);=0A+=09=09lo_res=20= =3D=20ExecuteSqlQueryForSingleRowAH(fout,=20loFrozenQry->data);=0A=20=0A=20= =09=09i_relfrozenxid=20=3D=20PQfnumber(lo_res,=20"relfrozenxid");=0A=20=09= =09i_relminmxid=20=3D=20PQfnumber(lo_res,=20"relminmxid");=0A@@=20= -3162,7=20+3162,7=20@@=20dumpDatabaseConfig(Archive=20*AH,=20PQExpBuffer=20= outbuf,=0A=20=09=09else=0A=20=09=09=09printfPQExpBuffer(buf,=20"SELECT=20= datconfig[%d]=20FROM=20pg_database=20WHERE=20oid=20=3D=20'%u'::oid",=20= count,=20dboid);=0A=20=0A-=09=09res=20=3D=20ExecuteSqlQuery(AH,=20= buf->data,=20PGRES_TUPLES_OK);=0A+=09=09res=20=3D=20= ExecuteSqlQueryAH(AH,=20buf->data,=20PGRES_TUPLES_OK);=0A=20=0A=20=09=09= if=20(PQntuples(res)=20=3D=3D=201=20&&=0A=20=09=09=09!PQgetisnull(res,=20= 0,=200))=0A@@=20-3189,7=20+3189,7=20@@=20dumpDatabaseConfig(Archive=20= *AH,=20PQExpBuffer=20outbuf,=0A=20=09=09=09=09=09=09=20=20"WHERE=20= setrole=20=3D=20r.oid=20AND=20setdatabase=20=3D=20'%u'::oid",=0A=20=09=09= =09=09=09=09=20=20dboid);=0A=20=0A-=09=09res=20=3D=20ExecuteSqlQuery(AH,=20= buf->data,=20PGRES_TUPLES_OK);=0A+=09=09res=20=3D=20= ExecuteSqlQueryAH(AH,=20buf->data,=20PGRES_TUPLES_OK);=0A=20=0A=20=09=09= if=20(PQntuples(res)=20>=200)=0A=20=09=09{=0A@@=20-3277,7=20+3277,7=20@@=20= dumpSearchPath(Archive=20*AH)=0A=20=09=20*=20listing=20schemas=20that=20= may=20appear=20in=20search_path=20but=20not=20actually=20exist,=0A=20=09=20= *=20which=20seems=20like=20a=20prudent=20exclusion.=0A=20=09=20*/=0A-=09= res=20=3D=20ExecuteSqlQueryForSingleRow(AH,=0A+=09res=20=3D=20= ExecuteSqlQueryForSingleRowAH(AH,=0A=20=09=09=09=09=09=09=09=09=09=20=20= "SELECT=20pg_catalog.current_schemas(false)");=0A=20=0A=20=09if=20= (!parsePGArray(PQgetvalue(res,=200,=200),=20&schemanames,=20= &nschemanames))=0A@@=20-3391,7=20+3391,7=20@@=20getBlobs(Archive=20= *fout)=0A=20=09=09=09=09=09=09=09=20"NULL::oid=20AS=20initrlomacl=20"=0A=20= =09=09=09=09=09=09=09=20"=20FROM=20pg_largeobject");=0A=20=0A-=09res=20=3D= =20ExecuteSqlQuery(fout,=20blobQry->data,=20PGRES_TUPLES_OK);=0A+=09res=20= =3D=20ExecuteSqlQueryAH(fout,=20blobQry->data,=20PGRES_TUPLES_OK);=0A=20=0A= =20=09i_oid=20=3D=20PQfnumber(res,=20"oid");=0A=20=09i_lomowner=20=3D=20= PQfnumber(res,=20"rolname");=0A@@=20-3537,7=20+3537,7=20@@=20= dumpBlobs(Archive=20*fout,=20void=20*arg)=0A=20=09=09=09"DECLARE=20= bloboid=20CURSOR=20FOR=20"=0A=20=09=09=09"SELECT=20DISTINCT=20loid=20= FROM=20pg_largeobject=20ORDER=20BY=201";=0A=20=0A-=09= ExecuteSqlStatement(fout,=20blobQry);=0A+=09ExecuteSqlStatementAH(fout,=20= blobQry);=0A=20=0A=20=09/*=20Command=20to=20fetch=20from=20cursor=20*/=0A= =20=09blobFetchQry=20=3D=20"FETCH=201000=20IN=20bloboid";=0A@@=20-3545,7=20= +3545,7=20@@=20dumpBlobs(Archive=20*fout,=20void=20*arg)=0A=20=09do=0A=20= =09{=0A=20=09=09/*=20Do=20a=20fetch=20*/=0A-=09=09res=20=3D=20= ExecuteSqlQuery(fout,=20blobFetchQry,=20PGRES_TUPLES_OK);=0A+=09=09res=20= =3D=20ExecuteSqlQueryAH(fout,=20blobFetchQry,=20PGRES_TUPLES_OK);=0A=20=0A= =20=09=09/*=20Process=20the=20tuples,=20if=20any=20*/=0A=20=09=09ntups=20= =3D=20PQntuples(res);=0A@@=20-3678,7=20+3678,7=20@@=20= getPolicies(Archive=20*fout,=20TableInfo=20tblinfo[],=20int=20numTables)=0A= =20=09=09=09=09=09=09=09=20=20"FROM=20pg_catalog.pg_policy=20pol=20"=0A=20= =09=09=09=09=09=09=09=20=20"WHERE=20polrelid=20=3D=20'%u'",=0A=20=09=09=09= =09=09=09=09=20=20tbinfo->dobj.catId.oid);=0A-=09=09res=20=3D=20= ExecuteSqlQuery(fout,=20query->data,=20PGRES_TUPLES_OK);=0A+=09=09res=20= =3D=20ExecuteSqlQueryAH(fout,=20query->data,=20PGRES_TUPLES_OK);=0A=20=0A= =20=09=09ntups=20=3D=20PQntuples(res);=0A=20=0A@@=20-3914,7=20+3914,7=20= @@=20getPublications(Archive=20*fout)=0A=20=09=09=09=09=09=09=20=20"FROM=20= pg_publication=20p",=0A=20=09=09=09=09=09=09=20=20username_subquery);=0A=20= =0A-=09res=20=3D=20ExecuteSqlQuery(fout,=20query->data,=20= PGRES_TUPLES_OK);=0A+=09res=20=3D=20ExecuteSqlQueryAH(fout,=20= query->data,=20PGRES_TUPLES_OK);=0A=20=0A=20=09ntups=20=3D=20= PQntuples(res);=0A=20=0A@@=20-4112,7=20+4112,7=20@@=20= getPublicationTables(Archive=20*fout,=20TableInfo=20tblinfo[],=20int=20= numTables)=0A=20=09=09=09=09=09=09=20=20"WHERE=20pr.prrelid=20=3D=20= '%u'"=0A=20=09=09=09=09=09=09=20=20"=20=20AND=20p.oid=20=3D=20= pr.prpubid",=0A=20=09=09=09=09=09=09=20=20tbinfo->dobj.catId.oid);=0A-=09= =09res=20=3D=20ExecuteSqlQuery(fout,=20query->data,=20PGRES_TUPLES_OK);=0A= +=09=09res=20=3D=20ExecuteSqlQueryAH(fout,=20query->data,=20= PGRES_TUPLES_OK);=0A=20=0A=20=09=09ntups=20=3D=20PQntuples(res);=0A=20=0A= @@=20-4237,7=20+4237,7=20@@=20getSubscriptions(Archive=20*fout)=0A=20=09= {=0A=20=09=09int=09=09=09n;=0A=20=0A-=09=09res=20=3D=20= ExecuteSqlQuery(fout,=0A+=09=09res=20=3D=20ExecuteSqlQueryAH(fout,=0A=20=09= =09=09=09=09=09=09=20=20"SELECT=20count(*)=20FROM=20pg_subscription=20"=0A= =20=09=09=09=09=09=09=09=20=20"WHERE=20subdbid=20=3D=20(SELECT=20oid=20= FROM=20pg_database"=0A=20=09=09=09=09=09=09=09=20=20"=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20WHERE=20datname=20=3D=20= current_database())",=0A@@=20-4274,7=20+4274,7=20@@=20= getSubscriptions(Archive=20*fout)=0A=20=09=09=09=09=09=09=20"WHERE=20= s.subdbid=20=3D=20(SELECT=20oid=20FROM=20pg_database\n"=0A=20=09=09=09=09= =09=09=20"=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20WHERE=20= datname=20=3D=20current_database())");=0A=20=0A-=09res=20=3D=20= ExecuteSqlQuery(fout,=20query->data,=20PGRES_TUPLES_OK);=0A+=09res=20=3D=20= ExecuteSqlQueryAH(fout,=20query->data,=20PGRES_TUPLES_OK);=0A=20=0A=20=09= ntups=20=3D=20PQntuples(res);=0A=20=0A@@=20-4446,7=20+4446,7=20@@=20= append_depends_on_extension(Archive=20*fout,=0A=20=09=09=09=09=09=09=20=20= "AND=20refclassid=20=3D=20= 'pg_catalog.pg_extension'::pg_catalog.regclass",=0A=20=09=09=09=09=09=09=20= =20catalog,=0A=20=09=09=09=09=09=09=20=20dobj->catId.oid);=0A-=09=09res=20= =3D=20ExecuteSqlQuery(fout,=20query->data,=20PGRES_TUPLES_OK);=0A+=09=09= res=20=3D=20ExecuteSqlQueryAH(fout,=20query->data,=20PGRES_TUPLES_OK);=0A= =20=09=09ntups=20=3D=20PQntuples(res);=0A=20=09=09i_extname=20=3D=20= PQfnumber(res,=20"extname");=0A=20=09=09for=20(i=20=3D=200;=20i=20<=20= ntups;=20i++)=0A@@=20-4485,7=20+4485,7=20@@=20= get_next_possible_free_pg_type_oid(Archive=20*fout,=20PQExpBuffer=20= upgrade_query)=0A=20=09=09=09=09=09=09=20=20"FROM=20pg_catalog.pg_type=20= "=0A=20=09=09=09=09=09=09=20=20"WHERE=20oid=20=3D=20= '%u'::pg_catalog.oid);",=0A=20=09=09=09=09=09=09=20=20= next_possible_free_oid);=0A-=09=09res=20=3D=20= ExecuteSqlQueryForSingleRow(fout,=20upgrade_query->data);=0A+=09=09res=20= =3D=20ExecuteSqlQueryForSingleRowAH(fout,=20upgrade_query->data);=0A=20=09= =09is_dup=20=3D=20(PQgetvalue(res,=200,=200)[0]=20=3D=3D=20't');=0A=20=09= =09PQclear(res);=0A=20=09}=20while=20(is_dup);=0A@@=20-4518,7=20+4518,7=20= @@=20binary_upgrade_set_type_oids_by_type_oid(Archive=20*fout,=0A=20=09=09= =09=09=09=20=20"WHERE=20oid=20=3D=20'%u'::pg_catalog.oid;",=0A=20=09=09=09= =09=09=20=20pg_type_oid);=0A=20=0A-=09res=20=3D=20= ExecuteSqlQueryForSingleRow(fout,=20upgrade_query->data);=0A+=09res=20=3D=20= ExecuteSqlQueryForSingleRowAH(fout,=20upgrade_query->data);=0A=20=0A=20=09= pg_type_array_oid=20=3D=20atooid(PQgetvalue(res,=200,=20PQfnumber(res,=20= "typarray")));=0A=20=0A@@=20-4551,7=20+4551,7=20@@=20= binary_upgrade_set_type_oids_by_type_oid(Archive=20*fout,=0A=20=09=09=09=09= =09=09=09=20=20"WHERE=20r.rngtypid=20=3D=20'%u'::pg_catalog.oid;",=0A=20=09= =09=09=09=09=09=09=20=20pg_type_oid);=0A=20=0A-=09=09=09res=20=3D=20= ExecuteSqlQueryForSingleRow(fout,=20upgrade_query->data);=0A+=09=09=09= res=20=3D=20ExecuteSqlQueryForSingleRowAH(fout,=20upgrade_query->data);=0A= =20=0A=20=09=09=09pg_type_multirange_oid=20=3D=20atooid(PQgetvalue(res,=20= 0,=20PQfnumber(res,=20"oid")));=0A=20=09=09=09= pg_type_multirange_array_oid=20=3D=20atooid(PQgetvalue(res,=200,=20= PQfnumber(res,=20"typarray")));=0A@@=20-4594,7=20+4594,7=20@@=20= binary_upgrade_set_type_oids_by_rel_oid(Archive=20*fout,=0A=20=09=09=09=09= =09=20=20"WHERE=20c.oid=20=3D=20'%u'::pg_catalog.oid;",=0A=20=09=09=09=09= =09=20=20pg_rel_oid);=0A=20=0A-=09upgrade_res=20=3D=20= ExecuteSqlQueryForSingleRow(fout,=20upgrade_query->data);=0A+=09= upgrade_res=20=3D=20ExecuteSqlQueryForSingleRowAH(fout,=20= upgrade_query->data);=0A=20=0A=20=09pg_type_oid=20=3D=20= atooid(PQgetvalue(upgrade_res,=200,=20PQfnumber(upgrade_res,=20= "crel")));=0A=20=0A@@=20-4645,7=20+4645,7=20@@=20= binary_upgrade_set_pg_class_oids(Archive=20*fout,=0A=20=09=09=09=09=09=09= =20=20"WHERE=20c.oid=20=3D=20'%u'::pg_catalog.oid;",=0A=20=09=09=09=09=09= =09=20=20pg_class_oid);=0A=20=0A-=09=09upgrade_res=20=3D=20= ExecuteSqlQueryForSingleRow(fout,=20upgrade_query->data);=0A+=09=09= upgrade_res=20=3D=20ExecuteSqlQueryForSingleRowAH(fout,=20= upgrade_query->data);=0A=20=0A=20=09=09pg_class_reltoastrelid=20=3D=20= atooid(PQgetvalue(upgrade_res,=200,=0A=20=09=09=09=09=09=09=09=09=09=09=09= =09=20=20=20PQfnumber(upgrade_res,=20"reltoastrelid")));=0A@@=20-4803,7=20= +4803,7=20@@=20getNamespaces(Archive=20*fout,=20int=20*numNamespaces)=0A=20= =09=09=09=09=09=09=20=20"FROM=20pg_namespace",=0A=20=09=09=09=09=09=09=20= =20username_subquery);=0A=20=0A-=09res=20=3D=20ExecuteSqlQuery(fout,=20= query->data,=20PGRES_TUPLES_OK);=0A+=09res=20=3D=20= ExecuteSqlQueryAH(fout,=20query->data,=20PGRES_TUPLES_OK);=0A=20=0A=20=09= ntups=20=3D=20PQntuples(res);=0A=20=0A@@=20-4916,7=20+4916,7=20@@=20= getExtensions(Archive=20*fout,=20int=20*numExtensions)=0A=20=09=09=09=09=09= =09=20"FROM=20pg_extension=20x=20"=0A=20=09=09=09=09=09=09=20"JOIN=20= pg_namespace=20n=20ON=20n.oid=20=3D=20x.extnamespace");=0A=20=0A-=09res=20= =3D=20ExecuteSqlQuery(fout,=20query->data,=20PGRES_TUPLES_OK);=0A+=09res=20= =3D=20ExecuteSqlQueryAH(fout,=20query->data,=20PGRES_TUPLES_OK);=0A=20=0A= =20=09ntups=20=3D=20PQntuples(res);=0A=20=0A@@=20-5093,7=20+5093,7=20@@=20= getTypes(Archive=20*fout,=20int=20*numTypes)=0A=20=09=09=09=09=09=09=20=20= username_subquery);=0A=20=09}=0A=20=0A-=09res=20=3D=20= ExecuteSqlQuery(fout,=20query->data,=20PGRES_TUPLES_OK);=0A+=09res=20=3D=20= ExecuteSqlQueryAH(fout,=20query->data,=20PGRES_TUPLES_OK);=0A=20=0A=20=09= ntups=20=3D=20PQntuples(res);=0A=20=0A@@=20-5249,7=20+5249,7=20@@=20= getOperators(Archive=20*fout,=20int=20*numOprs)=0A=20=09=09=09=09=09=20=20= "FROM=20pg_operator",=0A=20=09=09=09=09=09=20=20username_subquery);=0A=20= =0A-=09res=20=3D=20ExecuteSqlQuery(fout,=20query->data,=20= PGRES_TUPLES_OK);=0A+=09res=20=3D=20ExecuteSqlQueryAH(fout,=20= query->data,=20PGRES_TUPLES_OK);=0A=20=0A=20=09ntups=20=3D=20= PQntuples(res);=0A=20=09*numOprs=20=3D=20ntups;=0A@@=20-5336,7=20+5336,7=20= @@=20getCollations(Archive=20*fout,=20int=20*numCollations)=0A=20=09=09=09= =09=09=20=20"FROM=20pg_collation",=0A=20=09=09=09=09=09=20=20= username_subquery);=0A=20=0A-=09res=20=3D=20ExecuteSqlQuery(fout,=20= query->data,=20PGRES_TUPLES_OK);=0A+=09res=20=3D=20= ExecuteSqlQueryAH(fout,=20query->data,=20PGRES_TUPLES_OK);=0A=20=0A=20=09= ntups=20=3D=20PQntuples(res);=0A=20=09*numCollations=20=3D=20ntups;=0A@@=20= -5408,7=20+5408,7=20@@=20getConversions(Archive=20*fout,=20int=20= *numConversions)=0A=20=09=09=09=09=09=20=20"FROM=20pg_conversion",=0A=20=09= =09=09=09=09=20=20username_subquery);=0A=20=0A-=09res=20=3D=20= ExecuteSqlQuery(fout,=20query->data,=20PGRES_TUPLES_OK);=0A+=09res=20=3D=20= ExecuteSqlQueryAH(fout,=20query->data,=20PGRES_TUPLES_OK);=0A=20=0A=20=09= ntups=20=3D=20PQntuples(res);=0A=20=09*numConversions=20=3D=20ntups;=0A= @@=20-5481,7=20+5481,7=20@@=20getAccessMethods(Archive=20*fout,=20int=20= *numAccessMethods)=0A=20=09=09=09=09=09=09=20= "amhandler::pg_catalog.regproc=20AS=20amhandler=20"=0A=20=09=09=09=09=09=09= =20"FROM=20pg_am");=0A=20=0A-=09res=20=3D=20ExecuteSqlQuery(fout,=20= query->data,=20PGRES_TUPLES_OK);=0A+=09res=20=3D=20= ExecuteSqlQueryAH(fout,=20query->data,=20PGRES_TUPLES_OK);=0A=20=0A=20=09= ntups=20=3D=20PQntuples(res);=0A=20=09*numAccessMethods=20=3D=20ntups;=0A= @@=20-5552,7=20+5552,7=20@@=20getOpclasses(Archive=20*fout,=20int=20= *numOpclasses)=0A=20=09=09=09=09=09=20=20"FROM=20pg_opclass",=0A=20=09=09= =09=09=09=20=20username_subquery);=0A=20=0A-=09res=20=3D=20= ExecuteSqlQuery(fout,=20query->data,=20PGRES_TUPLES_OK);=0A+=09res=20=3D=20= ExecuteSqlQueryAH(fout,=20query->data,=20PGRES_TUPLES_OK);=0A=20=0A=20=09= ntups=20=3D=20PQntuples(res);=0A=20=09*numOpclasses=20=3D=20ntups;=0A@@=20= -5635,7=20+5635,7=20@@=20getOpfamilies(Archive=20*fout,=20int=20= *numOpfamilies)=0A=20=09=09=09=09=09=20=20"FROM=20pg_opfamily",=0A=20=09=09= =09=09=09=20=20username_subquery);=0A=20=0A-=09res=20=3D=20= ExecuteSqlQuery(fout,=20query->data,=20PGRES_TUPLES_OK);=0A+=09res=20=3D=20= ExecuteSqlQueryAH(fout,=20query->data,=20PGRES_TUPLES_OK);=0A=20=0A=20=09= ntups=20=3D=20PQntuples(res);=0A=20=09*numOpfamilies=20=3D=20ntups;=0A@@=20= -5804,7=20+5804,7=20@@=20getAggregates(Archive=20*fout,=20int=20= *numAggs)=0A=20=09=09=09=09=09=09=20=20username_subquery);=0A=20=09}=0A=20= =0A-=09res=20=3D=20ExecuteSqlQuery(fout,=20query->data,=20= PGRES_TUPLES_OK);=0A+=09res=20=3D=20ExecuteSqlQueryAH(fout,=20= query->data,=20PGRES_TUPLES_OK);=0A=20=0A=20=09ntups=20=3D=20= PQntuples(res);=0A=20=09*numAggs=20=3D=20ntups;=0A@@=20-6035,7=20+6035,7=20= @@=20getFuncs(Archive=20*fout,=20int=20*numFuncs)=0A=20=09=09= appendPQExpBufferChar(query,=20')');=0A=20=09}=0A=20=0A-=09res=20=3D=20= ExecuteSqlQuery(fout,=20query->data,=20PGRES_TUPLES_OK);=0A+=09res=20=3D=20= ExecuteSqlQueryAH(fout,=20query->data,=20PGRES_TUPLES_OK);=0A=20=0A=20=09= ntups=20=3D=20PQntuples(res);=0A=20=0A@@=20-6721,7=20+6721,7=20@@=20= getTables(Archive=20*fout,=20int=20*numTables)=0A=20=09=09=09=09=09=09=20= =20RELKIND_VIEW,=20RELKIND_COMPOSITE_TYPE);=0A=20=09}=0A=20=0A-=09res=20= =3D=20ExecuteSqlQuery(fout,=20query->data,=20PGRES_TUPLES_OK);=0A+=09res=20= =3D=20ExecuteSqlQueryAH(fout,=20query->data,=20PGRES_TUPLES_OK);=0A=20=0A= =20=09ntups=20=3D=20PQntuples(res);=0A=20=0A@@=20-6791,7=20+6791,7=20@@=20= getTables(Archive=20*fout,=20int=20*numTables)=0A=20=09=09= resetPQExpBuffer(query);=0A=20=09=09appendPQExpBufferStr(query,=20"SET=20= statement_timeout=20=3D=20");=0A=20=09=09appendStringLiteralConn(query,=20= dopt->lockWaitTimeout,=20GetConnection(fout));=0A-=09=09= ExecuteSqlStatement(fout,=20query->data);=0A+=09=09= ExecuteSqlStatementAH(fout,=20query->data);=0A=20=09}=0A=20=0A=20=09for=20= (i=20=3D=200;=20i=20<=20ntups;=20i++)=0A@@=20-6915,7=20+6915,7=20@@=20= getTables(Archive=20*fout,=20int=20*numTables)=0A=20=09=09=09= appendPQExpBuffer(query,=0A=20=09=09=09=09=09=09=09=20=20"LOCK=20TABLE=20= %s=20IN=20ACCESS=20SHARE=20MODE",=0A=20=09=09=09=09=09=09=09=20=20= fmtQualifiedDumpable(&tblinfo[i]));=0A-=09=09=09= ExecuteSqlStatement(fout,=20query->data);=0A+=09=09=09= ExecuteSqlStatementAH(fout,=20query->data);=0A=20=09=09}=0A=20=0A=20=09=09= /*=20Emit=20notice=20if=20join=20for=20owner=20failed=20*/=0A@@=20= -6926,7=20+6926,7=20@@=20getTables(Archive=20*fout,=20int=20*numTables)=0A= =20=0A=20=09if=20(dopt->lockWaitTimeout)=0A=20=09{=0A-=09=09= ExecuteSqlStatement(fout,=20"SET=20statement_timeout=20=3D=200");=0A+=09=09= ExecuteSqlStatementAH(fout,=20"SET=20statement_timeout=20=3D=200");=0A=20= =09}=0A=20=0A=20=09PQclear(res);=0A@@=20-7021,7=20+7021,7=20@@=20= getInherits(Archive=20*fout,=20int=20*numInherits)=0A=20=09/*=20find=20= all=20the=20inheritance=20information=20*/=0A=20=09= appendPQExpBufferStr(query,=20"SELECT=20inhrelid,=20inhparent=20FROM=20= pg_inherits");=0A=20=0A-=09res=20=3D=20ExecuteSqlQuery(fout,=20= query->data,=20PGRES_TUPLES_OK);=0A+=09res=20=3D=20= ExecuteSqlQueryAH(fout,=20query->data,=20PGRES_TUPLES_OK);=0A=20=0A=20=09= ntups=20=3D=20PQntuples(res);=0A=20=0A@@=20-7365,7=20+7365,7=20@@=20= getIndexes(Archive=20*fout,=20TableInfo=20tblinfo[],=20int=20numTables)=0A= =20=09=09=09=09=09=09=09=20=20tbinfo->dobj.catId.oid);=0A=20=09=09}=0A=20= =0A-=09=09res=20=3D=20ExecuteSqlQuery(fout,=20query->data,=20= PGRES_TUPLES_OK);=0A+=09=09res=20=3D=20ExecuteSqlQueryAH(fout,=20= query->data,=20PGRES_TUPLES_OK);=0A=20=0A=20=09=09ntups=20=3D=20= PQntuples(res);=0A=20=0A@@=20-7512,7=20+7512,7=20@@=20= getExtendedStatistics(Archive=20*fout)=0A=20=09=09=09=09=09=09=20=20= "FROM=20pg_catalog.pg_statistic_ext",=0A=20=09=09=09=09=09=09=20=20= username_subquery);=0A=20=0A-=09res=20=3D=20ExecuteSqlQuery(fout,=20= query->data,=20PGRES_TUPLES_OK);=0A+=09res=20=3D=20= ExecuteSqlQueryAH(fout,=20query->data,=20PGRES_TUPLES_OK);=0A=20=0A=20=09= ntups=20=3D=20PQntuples(res);=0A=20=0A@@=20-7610,7=20+7610,7=20@@=20= getConstraints(Archive=20*fout,=20TableInfo=20tblinfo[],=20int=20= numTables)=0A=20=09=09=09=09=09=09=09=20=20"WHERE=20conrelid=20=3D=20= '%u'::pg_catalog.oid=20"=0A=20=09=09=09=09=09=09=09=20=20"AND=20contype=20= =3D=20'f'",=0A=20=09=09=09=09=09=09=09=20=20tbinfo->dobj.catId.oid);=0A-=09= =09res=20=3D=20ExecuteSqlQuery(fout,=20query->data,=20PGRES_TUPLES_OK);=0A= +=09=09res=20=3D=20ExecuteSqlQueryAH(fout,=20query->data,=20= PGRES_TUPLES_OK);=0A=20=0A=20=09=09ntups=20=3D=20PQntuples(res);=0A=20=0A= @@=20-7746,7=20+7746,7=20@@=20getDomainConstraints(Archive=20*fout,=20= TypeInfo=20*tyinfo)=0A=20=09=09=09=09=09=09=20=20"ORDER=20BY=20conname",=0A= =20=09=09=09=09=09=09=20=20tyinfo->dobj.catId.oid);=0A=20=0A-=09res=20=3D=20= ExecuteSqlQuery(fout,=20query->data,=20PGRES_TUPLES_OK);=0A+=09res=20=3D=20= ExecuteSqlQueryAH(fout,=20query->data,=20PGRES_TUPLES_OK);=0A=20=0A=20=09= ntups=20=3D=20PQntuples(res);=0A=20=0A@@=20-7839,7=20+7839,7=20@@=20= getRules(Archive=20*fout,=20int=20*numRules)=0A=20=09=09=09=09=09=09=09=20= "ORDER=20BY=20oid");=0A=20=09}=0A=20=0A-=09res=20=3D=20= ExecuteSqlQuery(fout,=20query->data,=20PGRES_TUPLES_OK);=0A+=09res=20=3D=20= ExecuteSqlQueryAH(fout,=20query->data,=20PGRES_TUPLES_OK);=0A=20=0A=20=09= ntups=20=3D=20PQntuples(res);=0A=20=0A@@=20-8013,7=20+8013,7=20@@=20= getTriggers(Archive=20*fout,=20TableInfo=20tblinfo[],=20int=20numTables)=0A= =20=09=09=09=09=09=09=09=20=20tbinfo->dobj.catId.oid);=0A=20=09=09}=0A=20= =0A-=09=09res=20=3D=20ExecuteSqlQuery(fout,=20query->data,=20= PGRES_TUPLES_OK);=0A+=09=09res=20=3D=20ExecuteSqlQueryAH(fout,=20= query->data,=20PGRES_TUPLES_OK);=0A=20=0A=20=09=09ntups=20=3D=20= PQntuples(res);=0A=20=0A@@=20-8148,7=20+8148,7=20@@=20= getEventTriggers(Archive=20*fout,=20int=20*numEventTriggers)=0A=20=09=09=09= =09=09=20=20"ORDER=20BY=20e.oid",=0A=20=09=09=09=09=09=20=20= username_subquery);=0A=20=0A-=09res=20=3D=20ExecuteSqlQuery(fout,=20= query->data,=20PGRES_TUPLES_OK);=0A+=09res=20=3D=20= ExecuteSqlQueryAH(fout,=20query->data,=20PGRES_TUPLES_OK);=0A=20=0A=20=09= ntups=20=3D=20PQntuples(res);=0A=20=0A@@=20-8318,7=20+8318,7=20@@=20= getProcLangs(Archive=20*fout,=20int=20*numProcLangs)=0A=20=09=09=09=09=09= =09=20=20username_subquery);=0A=20=09}=0A=20=0A-=09res=20=3D=20= ExecuteSqlQuery(fout,=20query->data,=20PGRES_TUPLES_OK);=0A+=09res=20=3D=20= ExecuteSqlQueryAH(fout,=20query->data,=20PGRES_TUPLES_OK);=0A=20=0A=20=09= ntups=20=3D=20PQntuples(res);=0A=20=0A@@=20-8427,7=20+8427,7=20@@=20= getCasts(Archive=20*fout,=20int=20*numCasts)=0A=20=09=09=09=09=09=09=09=20= "FROM=20pg_cast=20ORDER=20BY=203,4");=0A=20=09}=0A=20=0A-=09res=20=3D=20= ExecuteSqlQuery(fout,=20query->data,=20PGRES_TUPLES_OK);=0A+=09res=20=3D=20= ExecuteSqlQueryAH(fout,=20query->data,=20PGRES_TUPLES_OK);=0A=20=0A=20=09= ntups=20=3D=20PQntuples(res);=0A=20=0A@@=20-8495,7=20+8495,7=20@@=20= get_language_name(Archive=20*fout,=20Oid=20langid)=0A=20=0A=20=09query=20= =3D=20createPQExpBuffer();=0A=20=09appendPQExpBuffer(query,=20"SELECT=20= lanname=20FROM=20pg_language=20WHERE=20oid=20=3D=20%u",=20langid);=0A-=09= res=20=3D=20ExecuteSqlQueryForSingleRow(fout,=20query->data);=0A+=09res=20= =3D=20ExecuteSqlQueryForSingleRowAH(fout,=20query->data);=0A=20=09= lanname=20=3D=20pg_strdup(fmtId(PQgetvalue(res,=200,=200)));=0A=20=09= destroyPQExpBuffer(query);=0A=20=09PQclear(res);=0A@@=20-8538,7=20= +8538,7=20@@=20getTransforms(Archive=20*fout,=20int=20*numTransforms)=0A=20= =09=09=09=09=09=09=20"FROM=20pg_transform=20"=0A=20=09=09=09=09=09=09=20= "ORDER=20BY=203,4");=0A=20=0A-=09res=20=3D=20ExecuteSqlQuery(fout,=20= query->data,=20PGRES_TUPLES_OK);=0A+=09res=20=3D=20= ExecuteSqlQueryAH(fout,=20query->data,=20PGRES_TUPLES_OK);=0A=20=0A=20=09= ntups=20=3D=20PQntuples(res);=0A=20=0A@@=20-8720,7=20+8720,7=20@@=20= getTableAttrs(Archive=20*fout,=20TableInfo=20*tblinfo,=20int=20= numTables)=0A=20=09=09=09=09=09=09=20=20"ORDER=20BY=20a.attnum",=0A=20=09= =09=09=09=09=09=20=20tbinfo->dobj.catId.oid);=0A=20=0A-=09=09res=20=3D=20= ExecuteSqlQuery(fout,=20q->data,=20PGRES_TUPLES_OK);=0A+=09=09res=20=3D=20= ExecuteSqlQueryAH(fout,=20q->data,=20PGRES_TUPLES_OK);=0A=20=0A=20=09=09= ntups=20=3D=20PQntuples(res);=0A=20=0A@@=20-8797,7=20+8797,7=20@@=20= getTableAttrs(Archive=20*fout,=20TableInfo=20*tblinfo,=20int=20= numTables)=0A=20=09=09=09=09=09=09=09=20=20"WHERE=20adrelid=20=3D=20= '%u'::pg_catalog.oid",=0A=20=09=09=09=09=09=09=09=20=20= tbinfo->dobj.catId.oid);=0A=20=0A-=09=09=09res=20=3D=20= ExecuteSqlQuery(fout,=20q->data,=20PGRES_TUPLES_OK);=0A+=09=09=09res=20=3D= =20ExecuteSqlQueryAH(fout,=20q->data,=20PGRES_TUPLES_OK);=0A=20=0A=20=09=09= =09numDefaults=20=3D=20PQntuples(res);=0A=20=09=09=09attrdefs=20=3D=20= (AttrDefInfo=20*)=20pg_malloc(numDefaults=20*=20sizeof(AttrDefInfo));=0A= @@=20-8919,7=20+8919,7=20@@=20getTableAttrs(Archive=20*fout,=20TableInfo=20= *tblinfo,=20int=20numTables)=0A=20=09=09=09=09=09=09=09=09=20=20= tbinfo->dobj.catId.oid);=0A=20=09=09=09}=0A=20=0A-=09=09=09res=20=3D=20= ExecuteSqlQuery(fout,=20q->data,=20PGRES_TUPLES_OK);=0A+=09=09=09res=20=3D= =20ExecuteSqlQueryAH(fout,=20q->data,=20PGRES_TUPLES_OK);=0A=20=0A=20=09=09= =09numConstrs=20=3D=20PQntuples(res);=0A=20=09=09=09if=20(numConstrs=20= !=3D=20tbinfo->ncheck)=0A@@=20-9062,7=20+9062,7=20@@=20= getTSParsers(Archive=20*fout,=20int=20*numTSParsers)=0A=20=09=09=09=09=09= =09=20"prsend::oid,=20prsheadline::oid,=20prslextype::oid=20"=0A=20=09=09= =09=09=09=09=20"FROM=20pg_ts_parser");=0A=20=0A-=09res=20=3D=20= ExecuteSqlQuery(fout,=20query->data,=20PGRES_TUPLES_OK);=0A+=09res=20=3D=20= ExecuteSqlQueryAH(fout,=20query->data,=20PGRES_TUPLES_OK);=0A=20=0A=20=09= ntups=20=3D=20PQntuples(res);=0A=20=09*numTSParsers=20=3D=20ntups;=0A@@=20= -9146,7=20+9146,7=20@@=20getTSDictionaries(Archive=20*fout,=20int=20= *numTSDicts)=0A=20=09=09=09=09=09=20=20"FROM=20pg_ts_dict",=0A=20=09=09=09= =09=09=20=20username_subquery);=0A=20=0A-=09res=20=3D=20= ExecuteSqlQuery(fout,=20query->data,=20PGRES_TUPLES_OK);=0A+=09res=20=3D=20= ExecuteSqlQueryAH(fout,=20query->data,=20PGRES_TUPLES_OK);=0A=20=0A=20=09= ntups=20=3D=20PQntuples(res);=0A=20=09*numTSDicts=20=3D=20ntups;=0A@@=20= -9226,7=20+9226,7=20@@=20getTSTemplates(Archive=20*fout,=20int=20= *numTSTemplates)=0A=20=09=09=09=09=09=09=20"tmplnamespace,=20= tmplinit::oid,=20tmpllexize::oid=20"=0A=20=09=09=09=09=09=09=20"FROM=20= pg_ts_template");=0A=20=0A-=09res=20=3D=20ExecuteSqlQuery(fout,=20= query->data,=20PGRES_TUPLES_OK);=0A+=09res=20=3D=20= ExecuteSqlQueryAH(fout,=20query->data,=20PGRES_TUPLES_OK);=0A=20=0A=20=09= ntups=20=3D=20PQntuples(res);=0A=20=09*numTSTemplates=20=3D=20ntups;=0A= @@=20-9302,7=20+9302,7=20@@=20getTSConfigurations(Archive=20*fout,=20int=20= *numTSConfigs)=0A=20=09=09=09=09=09=20=20"FROM=20pg_ts_config",=0A=20=09=09= =09=09=09=20=20username_subquery);=0A=20=0A-=09res=20=3D=20= ExecuteSqlQuery(fout,=20query->data,=20PGRES_TUPLES_OK);=0A+=09res=20=3D=20= ExecuteSqlQueryAH(fout,=20query->data,=20PGRES_TUPLES_OK);=0A=20=0A=20=09= ntups=20=3D=20PQntuples(res);=0A=20=09*numTSConfigs=20=3D=20ntups;=0A@@=20= -9455,7=20+9455,7=20@@=20getForeignDataWrappers(Archive=20*fout,=20int=20= *numForeignDataWrappers)=0A=20=09=09=09=09=09=09=20=20= username_subquery);=0A=20=09}=0A=20=0A-=09res=20=3D=20= ExecuteSqlQuery(fout,=20query->data,=20PGRES_TUPLES_OK);=0A+=09res=20=3D=20= ExecuteSqlQueryAH(fout,=20query->data,=20PGRES_TUPLES_OK);=0A=20=0A=20=09= ntups=20=3D=20PQntuples(res);=0A=20=09*numForeignDataWrappers=20=3D=20= ntups;=0A@@=20-9603,7=20+9603,7=20@@=20getForeignServers(Archive=20= *fout,=20int=20*numForeignServers)=0A=20=09=09=09=09=09=09=20=20= username_subquery);=0A=20=09}=0A=20=0A-=09res=20=3D=20= ExecuteSqlQuery(fout,=20query->data,=20PGRES_TUPLES_OK);=0A+=09res=20=3D=20= ExecuteSqlQueryAH(fout,=20query->data,=20PGRES_TUPLES_OK);=0A=20=0A=20=09= ntups=20=3D=20PQntuples(res);=0A=20=09*numForeignServers=20=3D=20ntups;=0A= @@=20-9742,7=20+9742,7=20@@=20getDefaultACLs(Archive=20*fout,=20int=20= *numDefaultACLs)=0A=20=09=09=09=09=09=09=20=20username_subquery);=0A=20=09= }=0A=20=0A-=09res=20=3D=20ExecuteSqlQuery(fout,=20query->data,=20= PGRES_TUPLES_OK);=0A+=09res=20=3D=20ExecuteSqlQueryAH(fout,=20= query->data,=20PGRES_TUPLES_OK);=0A=20=0A=20=09ntups=20=3D=20= PQntuples(res);=0A=20=09*numDefaultACLs=20=3D=20ntups;=0A@@=20-10098,7=20= +10098,7=20@@=20collectComments(Archive=20*fout,=20CommentItem=20= **items)=0A=20=09=09=09=09=09=09=20"FROM=20pg_catalog.pg_description=20"=0A= =20=09=09=09=09=09=09=20"ORDER=20BY=20classoid,=20objoid,=20objsubid");=0A= =20=0A-=09res=20=3D=20ExecuteSqlQuery(fout,=20query->data,=20= PGRES_TUPLES_OK);=0A+=09res=20=3D=20ExecuteSqlQueryAH(fout,=20= query->data,=20PGRES_TUPLES_OK);=0A=20=0A=20=09/*=20Construct=20lookup=20= table=20containing=20OIDs=20in=20numeric=20form=20*/=0A=20=0A@@=20= -10546,7=20+10546,7=20@@=20dumpEnumType(Archive=20*fout,=20TypeInfo=20= *tyinfo)=0A=20=09=09=09=09=09=09=20=20"ORDER=20BY=20oid",=0A=20=09=09=09=09= =09=09=20=20tyinfo->dobj.catId.oid);=0A=20=0A-=09res=20=3D=20= ExecuteSqlQuery(fout,=20query->data,=20PGRES_TUPLES_OK);=0A+=09res=20=3D=20= ExecuteSqlQueryAH(fout,=20query->data,=20PGRES_TUPLES_OK);=0A=20=0A=20=09= num=20=3D=20PQntuples(res);=0A=20=0A@@=20-10684,7=20+10684,7=20@@=20= dumpRangeType(Archive=20*fout,=20TypeInfo=20*tyinfo)=0A=20=09=09=09=09=09= =20=20"rngtypid=20=3D=20'%u'",=0A=20=09=09=09=09=09=20=20= tyinfo->dobj.catId.oid);=0A=20=0A-=09res=20=3D=20= ExecuteSqlQueryForSingleRow(fout,=20query->data);=0A+=09res=20=3D=20= ExecuteSqlQueryForSingleRowAH(fout,=20query->data);=0A=20=0A=20=09= qtypname=20=3D=20pg_strdup(fmtId(tyinfo->dobj.name));=0A=20=09= qualtypname=20=3D=20pg_strdup(fmtQualifiedDumpable(tyinfo));=0A@@=20= -10942,7=20+10942,7=20@@=20dumpBaseType(Archive=20*fout,=20TypeInfo=20= *tyinfo)=0A=20=09=09=09=09=09=20=20"WHERE=20oid=20=3D=20= '%u'::pg_catalog.oid",=0A=20=09=09=09=09=09=20=20= tyinfo->dobj.catId.oid);=0A=20=0A-=09res=20=3D=20= ExecuteSqlQueryForSingleRow(fout,=20query->data);=0A+=09res=20=3D=20= ExecuteSqlQueryForSingleRowAH(fout,=20query->data);=0A=20=0A=20=09typlen=20= =3D=20PQgetvalue(res,=200,=20PQfnumber(res,=20"typlen"));=0A=20=09= typinput=20=3D=20PQgetvalue(res,=200,=20PQfnumber(res,=20"typinput"));=0A= @@=20-11165,7=20+11165,7=20@@=20dumpDomain(Archive=20*fout,=20TypeInfo=20= *tyinfo)=0A=20=09=09=09=09=09=09=20=20tyinfo->dobj.catId.oid);=0A=20=09}=0A= =20=0A-=09res=20=3D=20ExecuteSqlQueryForSingleRow(fout,=20query->data);=0A= +=09res=20=3D=20ExecuteSqlQueryForSingleRowAH(fout,=20query->data);=0A=20= =0A=20=09typnotnull=20=3D=20PQgetvalue(res,=200,=20PQfnumber(res,=20= "typnotnull"));=0A=20=09typdefn=20=3D=20PQgetvalue(res,=200,=20= PQfnumber(res,=20"typdefn"));=0A@@=20-11357,7=20+11357,7=20@@=20= dumpCompositeType(Archive=20*fout,=20TypeInfo=20*tyinfo)=0A=20=09=09=09=09= =09=09=20=20tyinfo->dobj.catId.oid);=0A=20=09}=0A=20=0A-=09res=20=3D=20= ExecuteSqlQuery(fout,=20query->data,=20PGRES_TUPLES_OK);=0A+=09res=20=3D=20= ExecuteSqlQueryAH(fout,=20query->data,=20PGRES_TUPLES_OK);=0A=20=0A=20=09= ntups=20=3D=20PQntuples(res);=0A=20=0A@@=20-11536,7=20+11536,7=20@@=20= dumpCompositeTypeColComments(Archive=20*fout,=20TypeInfo=20*tyinfo)=0A=20= =09=09=09=09=09=20=20tyinfo->typrelid);=0A=20=0A=20=09/*=20Fetch=20= column=20attnames=20*/=0A-=09res=20=3D=20ExecuteSqlQuery(fout,=20= query->data,=20PGRES_TUPLES_OK);=0A+=09res=20=3D=20= ExecuteSqlQueryAH(fout,=20query->data,=20PGRES_TUPLES_OK);=0A=20=0A=20=09= ntups=20=3D=20PQntuples(res);=0A=20=09if=20(ntups=20<=201)=0A@@=20= -12064,7=20+12064,7=20@@=20dumpFunc(Archive=20*fout,=20FuncInfo=20= *finfo)=0A=20=09=09=09=09=09=20=20"WHERE=20oid=20=3D=20= '%u'::pg_catalog.oid",=0A=20=09=09=09=09=09=20=20finfo->dobj.catId.oid);=0A= =20=0A-=09res=20=3D=20ExecuteSqlQueryForSingleRow(fout,=20query->data);=0A= +=09res=20=3D=20ExecuteSqlQueryForSingleRowAH(fout,=20query->data);=0A=20= =0A=20=09proretset=20=3D=20PQgetvalue(res,=200,=20PQfnumber(res,=20= "proretset"));=0A=20=09prosrc=20=3D=20PQgetvalue(res,=200,=20= PQfnumber(res,=20"prosrc"));=0A@@=20-12754,7=20+12754,7=20@@=20= dumpOpr(Archive=20*fout,=20OprInfo=20*oprinfo)=0A=20=09=09=09=09=09=09=20= =20oprinfo->dobj.catId.oid);=0A=20=09}=0A=20=0A-=09res=20=3D=20= ExecuteSqlQueryForSingleRow(fout,=20query->data);=0A+=09res=20=3D=20= ExecuteSqlQueryForSingleRowAH(fout,=20query->data);=0A=20=0A=20=09= i_oprkind=20=3D=20PQfnumber(res,=20"oprkind");=0A=20=09i_oprcode=20=3D=20= PQfnumber(res,=20"oprcode");=0A@@=20-12977,7=20+12977,7=20@@=20= convertTSFunction(Archive=20*fout,=20Oid=20funcOid)=0A=20=0A=20=09= snprintf(query,=20sizeof(query),=0A=20=09=09=09=20"SELECT=20= '%u'::pg_catalog.regproc",=20funcOid);=0A-=09res=20=3D=20= ExecuteSqlQueryForSingleRow(fout,=20query);=0A+=09res=20=3D=20= ExecuteSqlQueryForSingleRowAH(fout,=20query);=0A=20=0A=20=09result=20=3D=20= pg_strdup(PQgetvalue(res,=200,=200));=0A=20=0A@@=20-13140,7=20+13140,7=20= @@=20dumpOpclass(Archive=20*fout,=20OpclassInfo=20*opcinfo)=0A=20=09=09=09= =09=09=09=20=20opcinfo->dobj.catId.oid);=0A=20=09}=0A=20=0A-=09res=20=3D=20= ExecuteSqlQueryForSingleRow(fout,=20query->data);=0A+=09res=20=3D=20= ExecuteSqlQueryForSingleRowAH(fout,=20query->data);=0A=20=0A=20=09= i_opcintype=20=3D=20PQfnumber(res,=20"opcintype");=0A=20=09i_opckeytype=20= =3D=20PQfnumber(res,=20"opckeytype");=0A@@=20-13268,7=20+13268,7=20@@=20= dumpOpclass(Archive=20*fout,=20OpclassInfo=20*opcinfo)=0A=20=09=09=09=09=09= =09=20=20opcinfo->dobj.catId.oid);=0A=20=09}=0A=20=0A-=09res=20=3D=20= ExecuteSqlQuery(fout,=20query->data,=20PGRES_TUPLES_OK);=0A+=09res=20=3D=20= ExecuteSqlQueryAH(fout,=20query->data,=20PGRES_TUPLES_OK);=0A=20=0A=20=09= ntups=20=3D=20PQntuples(res);=0A=20=0A@@=20-13347,7=20+13347,7=20@@=20= dumpOpclass(Archive=20*fout,=20OpclassInfo=20*opcinfo)=0A=20=09=09=09=09=09= =09=20=20opcinfo->dobj.catId.oid);=0A=20=09}=0A=20=0A-=09res=20=3D=20= ExecuteSqlQuery(fout,=20query->data,=20PGRES_TUPLES_OK);=0A+=09res=20=3D=20= ExecuteSqlQueryAH(fout,=20query->data,=20PGRES_TUPLES_OK);=0A=20=0A=20=09= ntups=20=3D=20PQntuples(res);=0A=20=0A@@=20-13530,7=20+13530,7=20@@=20= dumpOpfamily(Archive=20*fout,=20OpfamilyInfo=20*opfinfo)=0A=20=09=09=09=09= =09=09=20=20opfinfo->dobj.catId.oid);=0A=20=09}=0A=20=0A-=09res_ops=20=3D=20= ExecuteSqlQuery(fout,=20query->data,=20PGRES_TUPLES_OK);=0A+=09res_ops=20= =3D=20ExecuteSqlQueryAH(fout,=20query->data,=20PGRES_TUPLES_OK);=0A=20=0A= =20=09resetPQExpBuffer(query);=0A=20=0A@@=20-13546,7=20+13546,7=20@@=20= dumpOpfamily(Archive=20*fout,=20OpfamilyInfo=20*opfinfo)=0A=20=09=09=09=09= =09=20=20"ORDER=20BY=20amprocnum",=0A=20=09=09=09=09=09=20=20= opfinfo->dobj.catId.oid);=0A=20=0A-=09res_procs=20=3D=20= ExecuteSqlQuery(fout,=20query->data,=20PGRES_TUPLES_OK);=0A+=09res_procs=20= =3D=20ExecuteSqlQueryAH(fout,=20query->data,=20PGRES_TUPLES_OK);=0A=20=0A= =20=09/*=20Get=20additional=20fields=20from=20the=20pg_opfamily=20row=20= */=0A=20=09resetPQExpBuffer(query);=0A@@=20-13557,7=20+13557,7=20@@=20= dumpOpfamily(Archive=20*fout,=20OpfamilyInfo=20*opfinfo)=0A=20=09=09=09=09= =09=20=20"WHERE=20oid=20=3D=20'%u'::pg_catalog.oid",=0A=20=09=09=09=09=09= =20=20opfinfo->dobj.catId.oid);=0A=20=0A-=09res=20=3D=20= ExecuteSqlQueryForSingleRow(fout,=20query->data);=0A+=09res=20=3D=20= ExecuteSqlQueryForSingleRowAH(fout,=20query->data);=0A=20=0A=20=09= i_amname=20=3D=20PQfnumber(res,=20"amname");=0A=20=0A@@=20-13744,7=20= +13744,7=20@@=20dumpCollation(Archive=20*fout,=20CollInfo=20*collinfo)=0A= =20=09=09=09=09=09=20=20"WHERE=20c.oid=20=3D=20'%u'::pg_catalog.oid",=0A=20= =09=09=09=09=09=20=20collinfo->dobj.catId.oid);=0A=20=0A-=09res=20=3D=20= ExecuteSqlQueryForSingleRow(fout,=20query->data);=0A+=09res=20=3D=20= ExecuteSqlQueryForSingleRowAH(fout,=20query->data);=0A=20=0A=20=09= i_collprovider=20=3D=20PQfnumber(res,=20"collprovider");=0A=20=09= i_collisdeterministic=20=3D=20PQfnumber(res,=20"collisdeterministic");=0A= @@=20-13861,7=20+13861,7=20@@=20dumpConversion(Archive=20*fout,=20= ConvInfo=20*convinfo)=0A=20=09=09=09=09=09=20=20"WHERE=20c.oid=20=3D=20= '%u'::pg_catalog.oid",=0A=20=09=09=09=09=09=20=20= convinfo->dobj.catId.oid);=0A=20=0A-=09res=20=3D=20= ExecuteSqlQueryForSingleRow(fout,=20query->data);=0A+=09res=20=3D=20= ExecuteSqlQueryForSingleRowAH(fout,=20query->data);=0A=20=0A=20=09= i_conforencoding=20=3D=20PQfnumber(res,=20"conforencoding");=0A=20=09= i_contoencoding=20=3D=20PQfnumber(res,=20"contoencoding");=0A@@=20= -14078,7=20+14078,7=20@@=20dumpAgg(Archive=20*fout,=20AggInfo=20= *agginfo)=0A=20=09=09=09=09=09=20=20"AND=20p.oid=20=3D=20= '%u'::pg_catalog.oid",=0A=20=09=09=09=09=09=20=20= agginfo->aggfn.dobj.catId.oid);=0A=20=0A-=09res=20=3D=20= ExecuteSqlQueryForSingleRow(fout,=20query->data);=0A+=09res=20=3D=20= ExecuteSqlQueryForSingleRowAH(fout,=20query->data);=0A=20=0A=20=09= i_agginitval=20=3D=20PQfnumber(res,=20"agginitval");=0A=20=09= i_aggminitval=20=3D=20PQfnumber(res,=20"aggminitval");=0A@@=20-14413,7=20= +14413,7=20@@=20dumpTSDictionary(Archive=20*fout,=20TSDictInfo=20= *dictinfo)=0A=20=09=09=09=09=09=20=20"FROM=20pg_ts_template=20p,=20= pg_namespace=20n=20"=0A=20=09=09=09=09=09=20=20"WHERE=20p.oid=20=3D=20= '%u'=20AND=20n.oid=20=3D=20tmplnamespace",=0A=20=09=09=09=09=09=20=20= dictinfo->dicttemplate);=0A-=09res=20=3D=20= ExecuteSqlQueryForSingleRow(fout,=20query->data);=0A+=09res=20=3D=20= ExecuteSqlQueryForSingleRowAH(fout,=20query->data);=0A=20=09nspname=20=3D=20= PQgetvalue(res,=200,=200);=0A=20=09tmplname=20=3D=20PQgetvalue(res,=200,=20= 1);=0A=20=0A@@=20-14555,7=20+14555,7=20@@=20dumpTSConfig(Archive=20= *fout,=20TSConfigInfo=20*cfginfo)=0A=20=09=09=09=09=09=20=20"FROM=20= pg_ts_parser=20p,=20pg_namespace=20n=20"=0A=20=09=09=09=09=09=20=20= "WHERE=20p.oid=20=3D=20'%u'=20AND=20n.oid=20=3D=20prsnamespace",=0A=20=09= =09=09=09=09=20=20cfginfo->cfgparser);=0A-=09res=20=3D=20= ExecuteSqlQueryForSingleRow(fout,=20query->data);=0A+=09res=20=3D=20= ExecuteSqlQueryForSingleRowAH(fout,=20query->data);=0A=20=09nspname=20=3D=20= PQgetvalue(res,=200,=200);=0A=20=09prsname=20=3D=20PQgetvalue(res,=200,=20= 1);=0A=20=0A@@=20-14578,7=20+14578,7=20@@=20dumpTSConfig(Archive=20= *fout,=20TSConfigInfo=20*cfginfo)=0A=20=09=09=09=09=09=20=20"ORDER=20BY=20= m.mapcfg,=20m.maptokentype,=20m.mapseqno",=0A=20=09=09=09=09=09=20=20= cfginfo->cfgparser,=20cfginfo->dobj.catId.oid);=0A=20=0A-=09res=20=3D=20= ExecuteSqlQuery(fout,=20query->data,=20PGRES_TUPLES_OK);=0A+=09res=20=3D=20= ExecuteSqlQueryAH(fout,=20query->data,=20PGRES_TUPLES_OK);=0A=20=09ntups=20= =3D=20PQntuples(res);=0A=20=0A=20=09i_tokenname=20=3D=20PQfnumber(res,=20= "tokenname");=0A@@=20-14742,7=20+14742,7=20@@=20= dumpForeignServer(Archive=20*fout,=20ForeignServerInfo=20*srvinfo)=0A=20=09= =09=09=09=09=20=20"FROM=20pg_foreign_data_wrapper=20w=20"=0A=20=09=09=09=09= =09=20=20"WHERE=20w.oid=20=3D=20'%u'",=0A=20=09=09=09=09=09=20=20= srvinfo->srvfdw);=0A-=09res=20=3D=20ExecuteSqlQueryForSingleRow(fout,=20= query->data);=0A+=09res=20=3D=20ExecuteSqlQueryForSingleRowAH(fout,=20= query->data);=0A=20=09fdwname=20=3D=20PQgetvalue(res,=200,=200);=0A=20=0A= =20=09appendPQExpBuffer(q,=20"CREATE=20SERVER=20%s",=20qsrvname);=0A@@=20= -14858,7=20+14858,7=20@@=20dumpUserMappings(Archive=20*fout,=0A=20=09=09=09= =09=09=20=20"ORDER=20BY=20usename",=0A=20=09=09=09=09=09=20=20= catalogId.oid);=0A=20=0A-=09res=20=3D=20ExecuteSqlQuery(fout,=20= query->data,=20PGRES_TUPLES_OK);=0A+=09res=20=3D=20= ExecuteSqlQueryAH(fout,=20query->data,=20PGRES_TUPLES_OK);=0A=20=0A=20=09= ntups=20=3D=20PQntuples(res);=0A=20=09i_usename=20=3D=20PQfnumber(res,=20= "usename");=0A@@=20-15379,7=20+15379,7=20@@=20collectSecLabels(Archive=20= *fout,=20SecLabelItem=20**items)=0A=20=09=09=09=09=09=09=20"FROM=20= pg_catalog.pg_seclabel=20"=0A=20=09=09=09=09=09=09=20"ORDER=20BY=20= classoid,=20objoid,=20objsubid");=0A=20=0A-=09res=20=3D=20= ExecuteSqlQuery(fout,=20query->data,=20PGRES_TUPLES_OK);=0A+=09res=20=3D=20= ExecuteSqlQueryAH(fout,=20query->data,=20PGRES_TUPLES_OK);=0A=20=0A=20=09= /*=20Construct=20lookup=20table=20containing=20OIDs=20in=20numeric=20= form=20*/=0A=20=09i_label=20=3D=20PQfnumber(res,=20"label");=0A@@=20= -15515,7=20+15515,7=20@@=20dumpTable(Archive=20*fout,=20TableInfo=20= *tbinfo)=0A=20=09=09=09=09=09=09=09=20=20tbinfo->dobj.catId.oid);=0A=20=09= =09}=0A=20=0A-=09=09res=20=3D=20ExecuteSqlQuery(fout,=20query->data,=20= PGRES_TUPLES_OK);=0A+=09=09res=20=3D=20ExecuteSqlQueryAH(fout,=20= query->data,=20PGRES_TUPLES_OK);=0A=20=0A=20=09=09for=20(i=20=3D=200;=20= i=20<=20PQntuples(res);=20i++)=0A=20=09=09{=0A@@=20-15565,7=20+15565,7=20= @@=20createViewAsClause(Archive=20*fout,=20TableInfo=20*tbinfo)=0A=20=09=09= =09=09=09=20=20"SELECT=20pg_catalog.pg_get_viewdef('%u'::pg_catalog.oid)=20= AS=20viewdef",=0A=20=09=09=09=09=09=20=20tbinfo->dobj.catId.oid);=0A=20=0A= -=09res=20=3D=20ExecuteSqlQuery(fout,=20query->data,=20PGRES_TUPLES_OK);=0A= +=09res=20=3D=20ExecuteSqlQueryAH(fout,=20query->data,=20= PGRES_TUPLES_OK);=0A=20=0A=20=09if=20(PQntuples(res)=20!=3D=201)=0A=20=09= {=0A@@=20-15740,7=20+15740,7=20@@=20dumpTableSchema(Archive=20*fout,=20= TableInfo=20*tbinfo)=0A=20=09=09=09=09=09=09=09=09=09=20=20"ON=20(fs.oid=20= =3D=20ft.ftserver)=20"=0A=20=09=09=09=09=09=09=09=09=09=20=20"WHERE=20= ft.ftrelid=20=3D=20'%u'",=0A=20=09=09=09=09=09=09=09=09=09=20=20= tbinfo->dobj.catId.oid);=0A-=09=09=09=09=09res=20=3D=20= ExecuteSqlQueryForSingleRow(fout,=20query->data);=0A+=09=09=09=09=09res=20= =3D=20ExecuteSqlQueryForSingleRowAH(fout,=20query->data);=0A=20=09=09=09=09= =09i_srvname=20=3D=20PQfnumber(res,=20"srvname");=0A=20=09=09=09=09=09= i_ftoptions=20=3D=20PQfnumber(res,=20"ftoptions");=0A=20=09=09=09=09=09= srvname=20=3D=20pg_strdup(PQgetvalue(res,=200,=20i_srvname));=0A@@=20= -16693,7=20+16693,7=20@@=20dumpStatisticsExt(Archive=20*fout,=20= StatsExtInfo=20*statsextinfo)=0A=20=09=09=09=09=09=20=20= "pg_catalog.pg_get_statisticsobjdef('%u'::pg_catalog.oid)",=0A=20=09=09=09= =09=09=20=20statsextinfo->dobj.catId.oid);=0A=20=0A-=09res=20=3D=20= ExecuteSqlQueryForSingleRow(fout,=20query->data);=0A+=09res=20=3D=20= ExecuteSqlQueryForSingleRowAH(fout,=20query->data);=0A=20=0A=20=09stxdef=20= =3D=20PQgetvalue(res,=200,=200);=0A=20=0A@@=20-17061,7=20+17061,7=20@@=20= findLastBuiltinOid_V71(Archive=20*fout)=0A=20=09PGresult=20=20=20*res;=0A= =20=09Oid=09=09=09last_oid;=0A=20=0A-=09res=20=3D=20= ExecuteSqlQueryForSingleRow(fout,=0A+=09res=20=3D=20= ExecuteSqlQueryForSingleRowAH(fout,=0A=20=09=09=09=09=09=09=09=09=09=20=20= "SELECT=20datlastsysoid=20FROM=20pg_database=20WHERE=20datname=20=3D=20= current_database()");=0A=20=09last_oid=20=3D=20atooid(PQgetvalue(res,=20= 0,=20PQfnumber(res,=20"datlastsysoid")));=0A=20=09PQclear(res);=0A@@=20= -17130,7=20+17130,7=20@@=20dumpSequence(Archive=20*fout,=20TableInfo=20= *tbinfo)=0A=20=09=09=09=09=09=09=20=20fmtQualifiedDumpable(tbinfo));=0A=20= =09}=0A=20=0A-=09res=20=3D=20ExecuteSqlQuery(fout,=20query->data,=20= PGRES_TUPLES_OK);=0A+=09res=20=3D=20ExecuteSqlQueryAH(fout,=20= query->data,=20PGRES_TUPLES_OK);=0A=20=0A=20=09if=20(PQntuples(res)=20!=3D= =201)=0A=20=09{=0A@@=20-17353,7=20+17353,7=20@@=20= dumpSequenceData(Archive=20*fout,=20TableDataInfo=20*tdinfo)=0A=20=09=09=09= =09=09=20=20"SELECT=20last_value,=20is_called=20FROM=20%s",=0A=20=09=09=09= =09=09=20=20fmtQualifiedDumpable(tbinfo));=0A=20=0A-=09res=20=3D=20= ExecuteSqlQuery(fout,=20query->data,=20PGRES_TUPLES_OK);=0A+=09res=20=3D=20= ExecuteSqlQueryAH(fout,=20query->data,=20PGRES_TUPLES_OK);=0A=20=0A=20=09= if=20(PQntuples(res)=20!=3D=201)=0A=20=09{=0A@@=20-17761,7=20+17761,7=20= @@=20dumpRule(Archive=20*fout,=20RuleInfo=20*rinfo)=0A=20=09=09=09=09=09=09= =20=20"SELECT=20pg_catalog.pg_get_ruledef('%u'::pg_catalog.oid)",=0A=20=09= =09=09=09=09=09=20=20rinfo->dobj.catId.oid);=0A=20=0A-=09=09res=20=3D=20= ExecuteSqlQuery(fout,=20query->data,=20PGRES_TUPLES_OK);=0A+=09=09res=20= =3D=20ExecuteSqlQueryAH(fout,=20query->data,=20PGRES_TUPLES_OK);=0A=20=0A= =20=09=09if=20(PQntuples(res)=20!=3D=201)=0A=20=09=09{=0A@@=20-17891,7=20= +17891,7=20@@=20getExtensionMembership(Archive=20*fout,=20ExtensionInfo=20= extinfo[],=0A=20=09=09=09=09=09=09=20"AND=20deptype=20=3D=20'e'=20"=0A=20= =09=09=09=09=09=09=20"ORDER=20BY=203");=0A=20=0A-=09res=20=3D=20= ExecuteSqlQuery(fout,=20query->data,=20PGRES_TUPLES_OK);=0A+=09res=20=3D=20= ExecuteSqlQueryAH(fout,=20query->data,=20PGRES_TUPLES_OK);=0A=20=0A=20=09= ntups=20=3D=20PQntuples(res);=0A=20=0A@@=20-18090,7=20+18090,7=20@@=20= processExtensionTables(Archive=20*fout,=20ExtensionInfo=20extinfo[],=0A=20= =09=09=09=09=09=20=20"AND=20refclassid=20=3D=20'pg_extension'::regclass=20= "=0A=20=09=09=09=09=09=20=20"AND=20classid=20=3D=20= 'pg_class'::regclass;");=0A=20=0A-=09res=20=3D=20ExecuteSqlQuery(fout,=20= query->data,=20PGRES_TUPLES_OK);=0A+=09res=20=3D=20= ExecuteSqlQueryAH(fout,=20query->data,=20PGRES_TUPLES_OK);=0A=20=09ntups=20= =3D=20PQntuples(res);=0A=20=0A=20=09i_conrelid=20=3D=20PQfnumber(res,=20= "conrelid");=0A@@=20-18196,7=20+18196,7=20@@=20getDependencies(Archive=20= *fout)=0A=20=09/*=20Sort=20the=20output=20for=20efficiency=20below=20*/=0A= =20=09appendPQExpBufferStr(query,=20"ORDER=20BY=201,2");=0A=20=0A-=09res=20= =3D=20ExecuteSqlQuery(fout,=20query->data,=20PGRES_TUPLES_OK);=0A+=09res=20= =3D=20ExecuteSqlQueryAH(fout,=20query->data,=20PGRES_TUPLES_OK);=0A=20=0A= =20=09ntups=20=3D=20PQntuples(res);=0A=20=0A@@=20-18549,7=20+18549,7=20= @@=20getFormattedTypeName(Archive=20*fout,=20Oid=20oid,=20OidOptions=20= opts)=0A=20=09appendPQExpBuffer(query,=20"SELECT=20= pg_catalog.format_type('%u'::pg_catalog.oid,=20NULL)",=0A=20=09=09=09=09=09= =20=20oid);=0A=20=0A-=09res=20=3D=20ExecuteSqlQueryForSingleRow(fout,=20= query->data);=0A+=09res=20=3D=20ExecuteSqlQueryForSingleRowAH(fout,=20= query->data);=0A=20=0A=20=09/*=20result=20of=20format_type=20is=20= already=20quoted=20*/=0A=20=09result=20=3D=20pg_strdup(PQgetvalue(res,=20= 0,=200));=0A--=20=0A2.21.1=20(Apple=20Git-122.3)=0A=0A= --Apple-Mail=_8B07CFD0-2450-4CA2-BEE1-ACB2F7EEE33B Content-Disposition: attachment; filename=v32-0003-Creating-query_utils-frontend-utility.patch Content-Type: application/octet-stream; x-unix-mode=0644; name="v32-0003-Creating-query_utils-frontend-utility.patch" Content-Transfer-Encoding: quoted-printable =46rom=20a5c25a47a6ef095b190a6049b82569b35e126e78=20Mon=20Sep=2017=20= 00:00:00=202001=0AFrom:=20Mark=20Dilger=20=0A= Date:=20Wed,=206=20Jan=202021=2013:01:02=20-0800=0ASubject:=20[PATCH=20= v32=203/9]=20Creating=20query_utils=20frontend=20utility=0A=0AMoving=20= the=20ExecuteSqlQuery,=20ExecuteSqlQueryForSingleRow,=20and=0A= ExecuteSqlStatement=20out=20of=20the=20pg_dump=20project=20into=20a=20= new=20shared=0Alocation.=0A---=0A=20src/bin/pg_dump/pg_backup_db.c=20=20=20= =20=20|=20102=20+-------------------------=0A=20= src/bin/pg_dump/pg_backup_db.h=20=20=20=20=20|=20=2017=20-----=0A=20= src/fe_utils/Makefile=20=20=20=20=20=20=20=20=20=20=20=20=20=20|=20=20=20= 1=20+=0A=20src/fe_utils/query_utils.c=20=20=20=20=20=20=20=20=20|=20114=20= +++++++++++++++++++++++++++++=0A=20src/include/fe_utils/query_utils.h=20= |=20=2034=20+++++++++=0A=205=20files=20changed,=20150=20insertions(+),=20= 118=20deletions(-)=0A=20create=20mode=20100644=20= src/fe_utils/query_utils.c=0A=20create=20mode=20100644=20= src/include/fe_utils/query_utils.h=0A=0Adiff=20--git=20= a/src/bin/pg_dump/pg_backup_db.c=20b/src/bin/pg_dump/pg_backup_db.c=0A= index=20b55a968da2..38402d0831=20100644=0A---=20= a/src/bin/pg_dump/pg_backup_db.c=0A+++=20= b/src/bin/pg_dump/pg_backup_db.c=0A@@=20-20,6=20+20,7=20@@=0A=20#include=20= "common/connect.h"=0A=20#include=20"common/string.h"=0A=20#include=20= "dumputils.h"=0A+#include=20"fe_utils/query_utils.h"=0A=20#include=20= "fe_utils/string_utils.h"=0A=20#include=20"parallel.h"=0A=20#include=20= "pg_backup_archiver.h"=0A@@=20-271,107=20+272,6=20@@=20= notice_processor(void=20*arg,=20const=20char=20*message)=0A=20=09= pg_log_generic(PG_LOG_INFO,=20"%s",=20message);=0A=20}=0A=20=0A-/*=0A-=20= *=20The=20exiting=20query=20result=20handler=20embeds=20the=20historical=20= pg_dump=20behavior=0A-=20*=20under=20query=20error=20conditions,=20= including=20exiting=20nicely.=20=20The=20'conn'=20object=0A-=20*=20is=20= unused=20here,=20but=20is=20included=20in=20the=20interface=20for=20= alternate=20query=20result=0A-=20*=20handler=20implementations.=0A-=20*=0A= -=20*=20Whether=20the=20query=20was=20successful=20is=20determined=20by=20= comparing=20the=20returned=0A-=20*=20status=20code=20against=20the=20= expected=20status=20code,=20and=20by=20comparing=20the=20number=20of=0A-=20= *=20tuples=20returned=20from=20the=20query=20against=20expected_ntups.=20= =20Special=20negative=0A-=20*=20values=20of=20expected_ntups=20can=20be=20= used=20to=20require=20at=20least=20one=20row=20or=20to=0A-=20*=20= disables=20ntup=20checking.=0A-=20*=0A-=20*=20Exits=20on=20failure.=20=20= On=20successful=20query=20completion,=20returns=20the=20'res'=0A-=20*=20= argument=20as=20a=20notational=20convenience.=0A-=20*/=0A-PGresult=20*=0A= -exiting_handler(PGresult=20*res,=20PGconn=20*conn,=20ExecStatusType=20= expected_status,=0A-=09=09=09=09=20=20int=20expected_ntups,=20const=20= char=20*query)=0A-{=0A-=09if=20(PQresultStatus(res)=20!=3D=20= expected_status)=0A-=09{=0A-=09=09pg_log_error("query=20failed:=20%s",=20= PQerrorMessage(conn));=0A-=09=09pg_log_error("query=20was:=20%s",=20= query);=0A-=09=09PQfinish(conn);=0A-=09=09exit_nicely(1);=0A-=09}=0A-=09= if=20(expected_ntups=20=3D=3D=20POSITIVE_NTUPS=20||=20expected_ntups=20= >=3D=200)=0A-=09{=0A-=09=09int=20ntups=20=3D=20PQntuples(res);=0A-=0A-=09= =09if=20(expected_ntups=20=3D=3D=20POSITIVE_NTUPS)=0A-=09=09{=0A-=09=09=09= if=20(ntups=20=3D=3D=200)=0A-=09=09=09=09fatal("query=20returned=20no=20= rows:=20%s",=20query);=0A-=09=09}=0A-=09=09else=20if=20(ntups=20!=3D=20= expected_ntups)=0A-=09=09{=0A-=09=09=09/*=0A-=09=09=09=20*=20Preserve=20= historical=20message=20behavior=20of=20spelling=20"one"=20as=20the=0A-=09= =09=09=20*=20expected=20row=20count.=0A-=09=09=09=20*/=0A-=09=09=09if=20= (expected_ntups=20=3D=3D=201)=0A-=09=09=09=09fatal(ngettext("query=20= returned=20%d=20row=20instead=20of=20one:=20%s",=0A-=09=09=09=09=09=09=09= =20=20=20"query=20returned=20%d=20rows=20instead=20of=20one:=20%s",=0A-=09= =09=09=09=09=09=09=20=20=20ntups),=0A-=09=09=09=09=09ntups,=20query);=0A= -=09=09=09fatal(ngettext("query=20returned=20%d=20row=20instead=20of=20= %d:=20%s",=0A-=09=09=09=09=09=09=20=20=20"query=20returned=20%d=20rows=20= instead=20of=20%d:=20%s",=0A-=09=09=09=09=09=09=20=20=20ntups),=0A-=09=09= =09=09ntups,=20expected_ntups,=20query);=0A-=09=09}=0A-=09}=0A-=09return=20= res;=0A-}=0A-=0A-/*=0A-=20*=20Executes=20the=20given=20SQL=20query=20= statement.=0A-=20*=0A-=20*=20Invokes=20the=20exiting=20handler=20for=20= any=20but=20PGRES_COMMAND_OK=20status.=0A-=20*/=0A-void=0A= -ExecuteSqlStatement(PGconn=20*conn,=20const=20char=20*query)=0A-{=0A-=09= PQclear(exiting_handler(PQexec(conn,=20query),=0A-=09=09=09=09=09=09=09= conn,=0A-=09=09=09=09=09=09=09PGRES_COMMAND_OK,=0A-=09=09=09=09=09=09=09= ANY_NTUPS,=0A-=09=09=09=09=09=09=09query));=0A-}=0A-=0A-/*=0A-=20*=20= Executes=20the=20given=20SQL=20query.=0A-=20*=0A-=20*=20Invokes=20the=20= exiting=20handler=20unless=20the=20given=20'status'=20results.=0A-=20*=0A= -=20*=20If=20successful,=20returns=20the=20query=20result.=0A-=20*/=0A= -PGresult=20*=0A-ExecuteSqlQuery(PGconn=20*conn,=20const=20char=20= *query,=20ExecStatusType=20status)=0A-{=0A-=09return=20= exiting_handler(PQexec(conn,=20query),=0A-=09=09=09=09=09=09=20=20=20= conn,=0A-=09=09=09=09=09=09=20=20=20status,=0A-=09=09=09=09=09=09=20=20=20= ANY_NTUPS,=0A-=09=09=09=09=09=09=20=20=20query);=0A-}=0A-=0A-/*=0A-=20*=20= Like=20ExecuteSqlQuery,=20but=20requires=20PGRES_TUPLES_OK=20status=20= and=0A-=20*=20requires=20that=20exactly=20one=20row=20be=20returned.=0A-=20= */=0A-PGresult=20*=0A-ExecuteSqlQueryForSingleRow(PGconn=20*conn,=20= const=20char=20*query)=0A-{=0A-=09return=20exiting_handler(PQexec(conn,=20= query),=0A-=09=09=09=09=09=09=20=20=20conn,=0A-=09=09=09=09=09=09=20=20=20= PGRES_TUPLES_OK,=0A-=09=09=09=09=09=09=20=20=201,=0A-=09=09=09=09=09=09=20= =20=20query);=0A-}=0A-=0A=20void=0A=20ExecuteSqlStatementAH(Archive=20= *AHX,=20const=20char=20*query)=0A=20{=0Adiff=20--git=20= a/src/bin/pg_dump/pg_backup_db.h=20b/src/bin/pg_dump/pg_backup_db.h=0A= index=201aac600ece..018a28908e=20100644=0A---=20= a/src/bin/pg_dump/pg_backup_db.h=0A+++=20= b/src/bin/pg_dump/pg_backup_db.h=0A@@=20-13,23=20+13,6=20@@=0A=20=0A=20= extern=20int=09ExecuteSqlCommandBuf(Archive=20*AHX,=20const=20char=20= *buf,=20size_t=20bufLen);=0A=20=0A-#define=20POSITIVE_NTUPS=20(-1)=0A= -#define=20ANY_NTUPS=20(-2)=0A-typedef=20PGresult=20*(*PGresultHandler)=20= (PGresult=20*res,=0A-=09=09=09=09=09=09=09=09=09=20=20PGconn=20*conn,=0A= -=09=09=09=09=09=09=09=09=09=20=20ExecStatusType=20expected_status,=0A-=09= =09=09=09=09=09=09=09=09=20=20int=20expected_ntups,=0A-=09=09=09=09=09=09= =09=09=09=20=20const=20char=20*query);=0A-=0A-extern=20PGresult=20= *exiting_handler(PGresult=20*res,=20PGconn=20*conn,=0A-=09=09=09=09=09=09= =09=09=20ExecStatusType=20expected_status,=0A-=09=09=09=09=09=09=09=09=20= int=20expected_ntups,=20const=20char=20*query);=0A-=0A-extern=20void=20= ExecuteSqlStatement(PGconn=20*conn,=20const=20char=20*query);=0A-extern=20= PGresult=20*ExecuteSqlQuery(PGconn=20*conn,=20const=20char=20*query,=0A-=09= =09=09=09=09=09=09=09=20ExecStatusType=20expected_status);=0A-extern=20= PGresult=20*ExecuteSqlQueryForSingleRow(PGconn=20*conn,=20const=20char=20= *query);=0A-=0A=20extern=20void=20ExecuteSqlStatementAH(Archive=20*AHX,=20= const=20char=20*query);=0A=20extern=20PGresult=20= *ExecuteSqlQueryAH(Archive=20*AHX,=20const=20char=20*query,=0A=20=09=09=09= =09=09=09=09=09=20=20=20ExecStatusType=20status);=0Adiff=20--git=20= a/src/fe_utils/Makefile=20b/src/fe_utils/Makefile=0Aindex=20= d6c328faf1..7fdbe08e11=20100644=0A---=20a/src/fe_utils/Makefile=0A+++=20= b/src/fe_utils/Makefile=0A@@=20-27,6=20+27,7=20@@=20OBJS=20=3D=20\=0A=20=09= mbprint.o=20\=0A=20=09print.o=20\=0A=20=09psqlscan.o=20\=0A+=09= query_utils.o=20\=0A=20=09recovery_gen.o=20\=0A=20=09simple_list.o=20\=0A= =20=09string_utils.o=0Adiff=20--git=20a/src/fe_utils/query_utils.c=20= b/src/fe_utils/query_utils.c=0Anew=20file=20mode=20100644=0Aindex=20= 0000000000..b28750f4b2=0A---=20/dev/null=0A+++=20= b/src/fe_utils/query_utils.c=0A@@=20-0,0=20+1,114=20@@=0A= +/*-----------------------------------------------------------------------= --=0A+=20*=0A+=20*=20Query=20executing=20routines=20with=20facilities=20= for=20modular=20error=20handling.=0A+=20*=0A+=20*=20Portions=20Copyright=20= (c)=201996-2020,=20PostgreSQL=20Global=20Development=20Group=0A+=20*=20= Portions=20Copyright=20(c)=201994,=20Regents=20of=20the=20University=20= of=20California=0A+=20*=0A+=20*=20src/fe_utils/query_utils.c=0A+=20*=0A+=20= *-------------------------------------------------------------------------= =0A+=20*/=0A+#include=20"fe_utils/exit_utils.h"=0A+#include=20= "fe_utils/query_utils.h"=0A+=0A+/*=0A+=20*=20The=20exiting=20query=20= result=20handler=20embeds=20the=20historical=20pg_dump=20behavior=0A+=20= *=20under=20query=20error=20conditions,=20including=20exiting=20nicely.=20= =20The=20'conn'=20object=0A+=20*=20is=20unused=20here,=20but=20is=20= included=20in=20the=20interface=20for=20alternate=20query=20result=0A+=20= *=20handler=20implementations.=0A+=20*=0A+=20*=20Whether=20the=20query=20= was=20successful=20is=20determined=20by=20comparing=20the=20returned=0A+=20= *=20status=20code=20against=20the=20expected=20status=20code,=20and=20by=20= comparing=20the=20number=20of=0A+=20*=20tuples=20returned=20from=20the=20= query=20against=20expected_ntups.=20=20Special=20negative=0A+=20*=20= values=20of=20expected_ntups=20can=20be=20used=20to=20require=20at=20= least=20one=20row=20or=20to=0A+=20*=20disables=20ntup=20checking.=0A+=20= *=0A+=20*=20Exits=20on=20failure.=20=20On=20successful=20query=20= completion,=20returns=20the=20'res'=0A+=20*=20argument=20as=20a=20= notational=20convenience.=0A+=20*/=0A+PGresult=20*=0A= +exiting_handler(PGresult=20*res,=20PGconn=20*conn,=20ExecStatusType=20= expected_status,=0A+=09=09=09=09=20=20int=20expected_ntups,=20const=20= char=20*query)=0A+{=0A+=09if=20(PQresultStatus(res)=20!=3D=20= expected_status)=0A+=09{=0A+=09=09pg_log_error("query=20failed:=20%s",=20= PQerrorMessage(conn));=0A+=09=09pg_log_error("query=20was:=20%s",=20= query);=0A+=09=09PQfinish(conn);=0A+=09=09exit_nicely(1);=0A+=09}=0A+=09= if=20(expected_ntups=20=3D=3D=20POSITIVE_NTUPS=20||=20expected_ntups=20= >=3D=200)=0A+=09{=0A+=09=09int=20ntups=20=3D=20PQntuples(res);=0A+=0A+=09= =09if=20(expected_ntups=20=3D=3D=20POSITIVE_NTUPS)=0A+=09=09{=0A+=09=09=09= if=20(ntups=20=3D=3D=200)=0A+=09=09=09=09fatal("query=20returned=20no=20= rows:=20%s",=20query);=0A+=09=09}=0A+=09=09else=20if=20(ntups=20!=3D=20= expected_ntups)=0A+=09=09{=0A+=09=09=09/*=0A+=09=09=09=20*=20Preserve=20= historical=20message=20behavior=20of=20spelling=20"one"=20as=20the=0A+=09= =09=09=20*=20expected=20row=20count.=0A+=09=09=09=20*/=0A+=09=09=09if=20= (expected_ntups=20=3D=3D=201)=0A+=09=09=09=09fatal(ngettext("query=20= returned=20%d=20row=20instead=20of=20one:=20%s",=0A+=09=09=09=09=09=09=09= =20=20=20"query=20returned=20%d=20rows=20instead=20of=20one:=20%s",=0A+=09= =09=09=09=09=09=09=20=20=20ntups),=0A+=09=09=09=09=09ntups,=20query);=0A= +=09=09=09fatal(ngettext("query=20returned=20%d=20row=20instead=20of=20= %d:=20%s",=0A+=09=09=09=09=09=09=20=20=20"query=20returned=20%d=20rows=20= instead=20of=20%d:=20%s",=0A+=09=09=09=09=09=09=20=20=20ntups),=0A+=09=09= =09=09ntups,=20expected_ntups,=20query);=0A+=09=09}=0A+=09}=0A+=09return=20= res;=0A+}=0A+=0A+/*=0A+=20*=20Executes=20the=20given=20SQL=20query=20= statement.=0A+=20*=0A+=20*=20Invokes=20the=20exiting=20handler=20for=20= any=20but=20PGRES_COMMAND_OK=20status.=0A+=20*/=0A+void=0A= +ExecuteSqlStatement(PGconn=20*conn,=20const=20char=20*query)=0A+{=0A+=09= PQclear(exiting_handler(PQexec(conn,=20query),=0A+=09=09=09=09=09=09=09= conn,=0A+=09=09=09=09=09=09=09PGRES_COMMAND_OK,=0A+=09=09=09=09=09=09=09= ANY_NTUPS,=0A+=09=09=09=09=09=09=09query));=0A+}=0A+=0A+/*=0A+=20*=20= Executes=20the=20given=20SQL=20query.=0A+=20*=0A+=20*=20Invokes=20the=20= exiting=20handler=20unless=20the=20given=20'status'=20results.=0A+=20*=0A= +=20*=20If=20successful,=20returns=20the=20query=20result.=0A+=20*/=0A= +PGresult=20*=0A+ExecuteSqlQuery(PGconn=20*conn,=20const=20char=20= *query,=20ExecStatusType=20status)=0A+{=0A+=09return=20= exiting_handler(PQexec(conn,=20query),=0A+=09=09=09=09=09=09=20=20=20= conn,=0A+=09=09=09=09=09=09=20=20=20status,=0A+=09=09=09=09=09=09=20=20=20= ANY_NTUPS,=0A+=09=09=09=09=09=09=20=20=20query);=0A+}=0A+=0A+/*=0A+=20*=20= Like=20ExecuteSqlQuery,=20but=20requires=20PGRES_TUPLES_OK=20status=20= and=0A+=20*=20requires=20that=20exactly=20one=20row=20be=20returned.=0A+=20= */=0A+PGresult=20*=0A+ExecuteSqlQueryForSingleRow(PGconn=20*conn,=20= const=20char=20*query)=0A+{=0A+=09return=20exiting_handler(PQexec(conn,=20= query),=0A+=09=09=09=09=09=09=20=20=20conn,=0A+=09=09=09=09=09=09=20=20=20= PGRES_TUPLES_OK,=0A+=09=09=09=09=09=09=20=20=201,=0A+=09=09=09=09=09=09=20= =20=20query);=0A+}=0Adiff=20--git=20a/src/include/fe_utils/query_utils.h=20= b/src/include/fe_utils/query_utils.h=0Anew=20file=20mode=20100644=0A= index=200000000000..f03d17b1ed=0A---=20/dev/null=0A+++=20= b/src/include/fe_utils/query_utils.h=0A@@=20-0,0=20+1,34=20@@=0A= +/*-----------------------------------------------------------------------= --=0A+=20*=0A+=20*=20Query=20executing=20routines=20with=20facilities=20= for=20modular=20error=20handling.=0A+=20*=0A+=20*=20Portions=20Copyright=20= (c)=201996-2020,=20PostgreSQL=20Global=20Development=20Group=0A+=20*=20= Portions=20Copyright=20(c)=201994,=20Regents=20of=20the=20University=20= of=20California=0A+=20*=0A+=20*=20src/include/fe_utils/query_utils.h=0A+=20= *=0A+=20= *-------------------------------------------------------------------------= =0A+=20*/=0A+#ifndef=20QUERY_UTILS_H=0A+#define=20QUERY_UTILS_H=0A+=0A= +#include=20"libpq-fe.h"=0A+=0A+#define=20POSITIVE_NTUPS=20(-1)=0A= +#define=20ANY_NTUPS=20(-2)=0A+typedef=20PGresult=20*(*PGresultHandler)=20= (PGresult=20*res,=0A+=09=09=09=09=09=09=09=09=09=20=20PGconn=20*conn,=0A= +=09=09=09=09=09=09=09=09=09=20=20ExecStatusType=20expected_status,=0A+=09= =09=09=09=09=09=09=09=09=20=20int=20expected_ntups,=0A+=09=09=09=09=09=09= =09=09=09=20=20const=20char=20*query);=0A+=0A+extern=20PGresult=20= *exiting_handler(PGresult=20*res,=20PGconn=20*conn,=0A+=09=09=09=09=09=09= =09=09=20ExecStatusType=20expected_status,=0A+=09=09=09=09=09=09=09=09=20= int=20expected_ntups,=20const=20char=20*query);=0A+=0A+extern=20void=20= ExecuteSqlStatement(PGconn=20*conn,=20const=20char=20*query);=0A+extern=20= PGresult=20*ExecuteSqlQuery(PGconn=20*conn,=20const=20char=20*query,=0A+=09= =09=09=09=09=09=09=09=20ExecStatusType=20expected_status);=0A+extern=20= PGresult=20*ExecuteSqlQueryForSingleRow(PGconn=20*conn,=20const=20char=20= *query);=0A+=0A+#endif=09=09=09=09=09=09=09/*=20QUERY_UTILS_H=20*/=0A--=20= =0A2.21.1=20(Apple=20Git-122.3)=0A=0A= --Apple-Mail=_8B07CFD0-2450-4CA2-BEE1-ACB2F7EEE33B Content-Disposition: attachment; filename=v32-0004-Adding-CurrentQueryHandler-logic.patch Content-Type: application/octet-stream; x-unix-mode=0644; name="v32-0004-Adding-CurrentQueryHandler-logic.patch" Content-Transfer-Encoding: quoted-printable =46rom=2086a8078d2750a9ee42db5a341838fad6072252f5=20Mon=20Sep=2017=20= 00:00:00=202001=0AFrom:=20Mark=20Dilger=20=0A= Date:=20Wed,=206=20Jan=202021=2013:25:29=20-0800=0ASubject:=20[PATCH=20= v32=204/9]=20Adding=20CurrentQueryHandler=20logic.=0A=0AExtending=20the=20= default=20set=20of=20PGresultHandlers=20and=20creating=20a=0Amechanism=20= to=20switch=20between=20them=20using=20a=20new=20function=0A= ResultHandlerSwitchTo,=20analogous=20to=20MemoryContextSwithTo.=20=20In=0A= addition=20to=20the=20exiting_handler=20already=20created=20in=20a=20= prior=20commit=0A(which=20embeds=20the=20historical=20behavior=20from=20= pg_dump),=20adding=20a=0Aquiet_handler=20which=20cleans=20up=20and=20= exits=20without=20logging=20anything,=0Aand=20a=20noop_handler=20which=20= does=20nothing,=20leaving=20the=20responsibility=0Afor=20cleanup=20= handling=20to=20the=20caller.=0A---=0A=20src/fe_utils/query_utils.c=20=20= =20=20=20=20=20=20=20|=2081=20++++++++++++++++++++++--------=0A=20= src/include/fe_utils/query_utils.h=20|=2017=20+++++++=0A=202=20files=20= changed,=2076=20insertions(+),=2022=20deletions(-)=0A=0Adiff=20--git=20= a/src/fe_utils/query_utils.c=20b/src/fe_utils/query_utils.c=0Aindex=20= b28750f4b2..355da6edaf=20100644=0A---=20a/src/fe_utils/query_utils.c=0A= +++=20b/src/fe_utils/query_utils.c=0A@@=20-12,6=20+12,12=20@@=0A=20= #include=20"fe_utils/exit_utils.h"=0A=20#include=20= "fe_utils/query_utils.h"=0A=20=0A+/*=0A+=20*=20Global=20memory.=0A+=20*/=0A= +=0A+PGresultHandler=20CurrentResultHandler=20=3D=20exiting_handler;=0A+=0A= =20/*=0A=20=20*=20The=20exiting=20query=20result=20handler=20embeds=20= the=20historical=20pg_dump=20behavior=0A=20=20*=20under=20query=20error=20= conditions,=20including=20exiting=20nicely.=20=20The=20'conn'=20object=0A= @@=20-29,7=20+35,7=20@@=0A=20=20*/=0A=20PGresult=20*=0A=20= exiting_handler(PGresult=20*res,=20PGconn=20*conn,=20ExecStatusType=20= expected_status,=0A-=09=09=09=09=20=20int=20expected_ntups,=20const=20= char=20*query)=0A+=09=09=09=09int=20expected_ntups,=20const=20char=20= *query)=0A=20{=0A=20=09if=20(PQresultStatus(res)=20!=3D=20= expected_status)=0A=20=09{=0A@@=20-67,48=20+73,79=20@@=20= exiting_handler(PGresult=20*res,=20PGconn=20*conn,=20ExecStatusType=20= expected_status,=0A=20=09return=20res;=0A=20}=0A=20=0A+/*=0A+=20*=20= Quietly=20cleans=20up=20and=20exits=20nicely=20unless=20the=20expected=20= conditions=20were=20met.=0A+=20*/=0A+PGresult=20*=0A= +quiet_handler(PGresult=20*res,=20PGconn=20*conn,=20ExecStatusType=20= expected_status,=0A+=09=09=09=20=20int=20expected_ntups,=20const=20char=20= *query)=0A+{=0A+=09int=20ntups=20=3D=20PQntuples(res);=0A+=0A+=09if=20= ((PQresultStatus(res)=20!=3D=20expected_status)=20||=0A+=09=09= (expected_ntups=20=3D=3D=20POSITIVE_NTUPS=20&&=20ntups=20=3D=3D=200)=20= ||=0A+=09=09(expected_ntups=20>=3D=200=20&&=20ntups=20!=3D=20= expected_ntups))=0A+=09{=0A+=09=09PQfinish(conn);=0A+=09=09= exit_nicely(1);=0A+=09}=0A+=0A+=09return=20res;=0A+}=0A+=0A+/*=0A+=20*=20= Does=20nothing=20other=20than=20returning=20the=20'res'=20argument=20= back=20to=20the=20caller.=0A+=20*=20This=20handler=20is=20intended=20for=20= callers=20who=20prefer=20to=20perform=20the=20error=0A+=20*=20handling=20= themselves.=0A+=20*/=0A+PGresult=20*=0A+noop_handler(PGresult=20*res,=20= PGconn=20*conn,=20ExecStatusType=20expected_status,=0A+=09=09=09=20int=20= expected_ntups,=20const=20char=20*query)=0A+{=0A+=09return=20res;=0A+}=0A= +=0A=20/*=0A=20=20*=20Executes=20the=20given=20SQL=20query=20statement.=0A= =20=20*=0A-=20*=20Invokes=20the=20exiting=20handler=20for=20any=20but=20= PGRES_COMMAND_OK=20status.=0A+=20*=20Expects=20a=20PGRES_COMMAND_OK=20= status.=0A=20=20*/=0A=20void=0A=20ExecuteSqlStatement(PGconn=20*conn,=20= const=20char=20*query)=0A=20{=0A-=09PQclear(exiting_handler(PQexec(conn,=20= query),=0A-=09=09=09=09=09=09=09conn,=0A-=09=09=09=09=09=09=09= PGRES_COMMAND_OK,=0A-=09=09=09=09=09=09=09ANY_NTUPS,=0A-=09=09=09=09=09=09= =09query));=0A+=09PQclear(CurrentResultHandler(PQexec(conn,=20query),=0A= +=09=09=09=09=09=09=09=09=20conn,=0A+=09=09=09=09=09=09=09=09=20= PGRES_COMMAND_OK,=0A+=09=09=09=09=09=09=09=09=20ANY_NTUPS,=0A+=09=09=09=09= =09=09=09=09=20query));=0A=20}=0A=20=0A=20/*=0A=20=20*=20Executes=20the=20= given=20SQL=20query.=0A=20=20*=0A-=20*=20Invokes=20the=20exiting=20= handler=20unless=20the=20given=20'status'=20results.=0A-=20*=0A-=20*=20= If=20successful,=20returns=20the=20query=20result.=0A+=20*=20Expects=20= the=20given=20status.=0A=20=20*/=0A=20PGresult=20*=0A=20= ExecuteSqlQuery(PGconn=20*conn,=20const=20char=20*query,=20= ExecStatusType=20status)=0A=20{=0A-=09return=20= exiting_handler(PQexec(conn,=20query),=0A-=09=09=09=09=09=09=20=20=20= conn,=0A-=09=09=09=09=09=09=20=20=20status,=0A-=09=09=09=09=09=09=20=20=20= ANY_NTUPS,=0A-=09=09=09=09=09=09=20=20=20query);=0A+=09return=20= CurrentResultHandler(PQexec(conn,=20query),=0A+=09=09=09=09=09=09=09=09= conn,=0A+=09=09=09=09=09=09=09=09status,=0A+=09=09=09=09=09=09=09=09= ANY_NTUPS,=0A+=09=09=09=09=09=09=09=09query);=0A=20}=0A=20=0A=20/*=0A-=20= *=20Like=20ExecuteSqlQuery,=20but=20requires=20PGRES_TUPLES_OK=20status=20= and=0A-=20*=20requires=20that=20exactly=20one=20row=20be=20returned.=0A+=20= *=20Executes=20the=20given=20SQL=20query.=0A+=20*=0A+=20*=20Expects=20a=20= PGRES_TUPLES_OK=20status=20and=20precisely=20one=20row.=0A=20=20*/=0A=20= PGresult=20*=0A=20ExecuteSqlQueryForSingleRow(PGconn=20*conn,=20const=20= char=20*query)=0A=20{=0A-=09return=20exiting_handler(PQexec(conn,=20= query),=0A-=09=09=09=09=09=09=20=20=20conn,=0A-=09=09=09=09=09=09=20=20=20= PGRES_TUPLES_OK,=0A-=09=09=09=09=09=09=20=20=201,=0A-=09=09=09=09=09=09=20= =20=20query);=0A+=09return=20CurrentResultHandler(PQexec(conn,=20query),=0A= +=09=09=09=09=09=09=09=09conn,=0A+=09=09=09=09=09=09=09=09= PGRES_TUPLES_OK,=0A+=09=09=09=09=09=09=09=091,=0A+=09=09=09=09=09=09=09=09= query);=0A=20}=0Adiff=20--git=20a/src/include/fe_utils/query_utils.h=20= b/src/include/fe_utils/query_utils.h=0Aindex=20f03d17b1ed..80958e94fb=20= 100644=0A---=20a/src/include/fe_utils/query_utils.h=0A+++=20= b/src/include/fe_utils/query_utils.h=0A@@=20-22,9=20+22,26=20@@=20= typedef=20PGresult=20*(*PGresultHandler)=20(PGresult=20*res,=0A=20=09=09=09= =09=09=09=09=09=09=20=20int=20expected_ntups,=0A=20=09=09=09=09=09=09=09=09= =09=20=20const=20char=20*query);=0A=20=0A+extern=20PGresultHandler=20= CurrentResultHandler;=0A+=0A+static=20inline=20PGresultHandler=0A= +ResultHandlerSwitchTo(PGresultHandler=20handler)=0A+{=0A+=09= PGresultHandler=20old=20=3D=20CurrentResultHandler;=0A+=0A+=09= CurrentResultHandler=20=3D=20handler;=0A+=09return=20old;=0A+}=0A+=0A=20= extern=20PGresult=20*exiting_handler(PGresult=20*res,=20PGconn=20*conn,=0A= =20=09=09=09=09=09=09=09=09=20ExecStatusType=20expected_status,=0A=20=09=09= =09=09=09=09=09=09=20int=20expected_ntups,=20const=20char=20*query);=0A= +extern=20PGresult=20*quiet_handler(PGresult=20*res,=20PGconn=20*conn,=0A= +=09=09=09=09=09=09=09=20=20=20ExecStatusType=20expected_status,=0A+=09=09= =09=09=09=09=09=20=20=20int=20expected_ntups,=20const=20char=20*query);=0A= +extern=20PGresult=20*noop_handler(PGresult=20*res,=20PGconn=20*conn,=0A= +=09=09=09=09=09=09=09=20=20ExecStatusType=20expected_status,=0A+=09=09=09= =09=09=09=09=20=20int=20expected_ntups,=20const=20char=20*query);=0A=20=0A= =20extern=20void=20ExecuteSqlStatement(PGconn=20*conn,=20const=20char=20= *query);=0A=20extern=20PGresult=20*ExecuteSqlQuery(PGconn=20*conn,=20= const=20char=20*query,=0A--=20=0A2.21.1=20(Apple=20Git-122.3)=0A=0A= --Apple-Mail=_8B07CFD0-2450-4CA2-BEE1-ACB2F7EEE33B Content-Disposition: attachment; filename=v32-0005-Refactoring-pg_dumpall-functions.patch Content-Type: application/octet-stream; x-unix-mode=0644; name="v32-0005-Refactoring-pg_dumpall-functions.patch" Content-Transfer-Encoding: quoted-printable =46rom=2034718483db460517416a84d505ce9a166abd5ebb=20Mon=20Sep=2017=20= 00:00:00=202001=0AFrom:=20Mark=20Dilger=20=0A= Date:=20Wed,=206=20Jan=202021=2013:37:42=20-0800=0ASubject:=20[PATCH=20= v32=205/9]=20Refactoring=20pg_dumpall=20functions.=0A=0AThe=20functions=20= executeQuery=20and=20executeCommand=20in=20pg_dumpall.c=20were=0Anot=20= refactored=20in=20prior=20commits=20along=20with=20functions=20from=0A= pg_backup_db.c=20because=20they=20were=20in=20a=20separate=20file,=20but=20= now=20that=0Athe=20infrastructure=20has=20been=20moved=20to=20= fe_utils/query_utils,=0Arefactoring=20these=20two=20functions=20to=20use=20= it.=0A---=0A=20src/bin/pg_dump/pg_dumpall.c=20|=2031=20= +++----------------------------=0A=201=20file=20changed,=203=20= insertions(+),=2028=20deletions(-)=0A=0Adiff=20--git=20= a/src/bin/pg_dump/pg_dumpall.c=20b/src/bin/pg_dump/pg_dumpall.c=0Aindex=20= 85d08ad660..807226537a=20100644=0A---=20a/src/bin/pg_dump/pg_dumpall.c=0A= +++=20b/src/bin/pg_dump/pg_dumpall.c=0A@@=20-23,6=20+23,7=20@@=0A=20= #include=20"common/logging.h"=0A=20#include=20"common/string.h"=0A=20= #include=20"dumputils.h"=0A+#include=20"fe_utils/query_utils.h"=0A=20= #include=20"fe_utils/string_utils.h"=0A=20#include=20"getopt_long.h"=0A=20= #include=20"pg_backup.h"=0A@@=20-1874,21=20+1875,8=20@@=20= constructConnStr(const=20char=20**keywords,=20const=20char=20**values)=0A= =20static=20PGresult=20*=0A=20executeQuery(PGconn=20*conn,=20const=20= char=20*query)=0A=20{=0A-=09PGresult=20=20=20*res;=0A-=0A=20=09= pg_log_info("executing=20%s",=20query);=0A-=0A-=09res=20=3D=20= PQexec(conn,=20query);=0A-=09if=20(!res=20||=0A-=09=09= PQresultStatus(res)=20!=3D=20PGRES_TUPLES_OK)=0A-=09{=0A-=09=09= pg_log_error("query=20failed:=20%s",=20PQerrorMessage(conn));=0A-=09=09= pg_log_error("query=20was:=20%s",=20query);=0A-=09=09PQfinish(conn);=0A-=09= =09exit_nicely(1);=0A-=09}=0A-=0A-=09return=20res;=0A+=09return=20= ExecuteSqlQuery(conn,=20query,=20PGRES_TUPLES_OK);=0A=20}=0A=20=0A=20/*=0A= @@=20-1897,21=20+1885,8=20@@=20executeQuery(PGconn=20*conn,=20const=20= char=20*query)=0A=20static=20void=0A=20executeCommand(PGconn=20*conn,=20= const=20char=20*query)=0A=20{=0A-=09PGresult=20=20=20*res;=0A-=0A=20=09= pg_log_info("executing=20%s",=20query);=0A-=0A-=09res=20=3D=20= PQexec(conn,=20query);=0A-=09if=20(!res=20||=0A-=09=09= PQresultStatus(res)=20!=3D=20PGRES_COMMAND_OK)=0A-=09{=0A-=09=09= pg_log_error("query=20failed:=20%s",=20PQerrorMessage(conn));=0A-=09=09= pg_log_error("query=20was:=20%s",=20query);=0A-=09=09PQfinish(conn);=0A-=09= =09exit_nicely(1);=0A-=09}=0A-=0A-=09PQclear(res);=0A+=09= PQclear(ExecuteSqlQuery(conn,=20query,=20PGRES_COMMAND_OK));=0A=20}=0A=20= =0A=20=0A--=20=0A2.21.1=20(Apple=20Git-122.3)=0A=0A= --Apple-Mail=_8B07CFD0-2450-4CA2-BEE1-ACB2F7EEE33B Content-Disposition: attachment; filename=v32-0006-Refactoring-expand_schema_name_patterns-and-frie.patch Content-Type: application/octet-stream; x-unix-mode=0644; name="v32-0006-Refactoring-expand_schema_name_patterns-and-frie.patch" Content-Transfer-Encoding: quoted-printable =46rom=206d91a3031f28387fbc2a6d776278abfd2b04bb1e=20Mon=20Sep=2017=20= 00:00:00=202001=0AFrom:=20Mark=20Dilger=20=0A= Date:=20Wed,=206=20Jan=202021=2013:51:02=20-0800=0ASubject:=20[PATCH=20= v32=206/9]=20Refactoring=20expand_schema_name_patterns=20and=20friends.=0A= =0ARefactoring=20these=20functions=20to=20take=20a=20PGconn=20pointer=20= rather=20than=20an=0AArchive=20pointer=20in=20preparation=20for=20moving=20= these=20functions=20to=0Afe_utils.=20=20This=20is=20much=20like=20what=20= was=20previously=20done=20for=0AExecuteSqlQuery=20and=20friends,=20and=20= for=20the=20same=20reasons.=0A---=0A=20src/bin/pg_dump/pg_dump.c=20|=20= 47=20++++++++++++++++++++++-----------------=0A=201=20file=20changed,=20= 27=20insertions(+),=2020=20deletions(-)=0A=0Adiff=20--git=20= a/src/bin/pg_dump/pg_dump.c=20b/src/bin/pg_dump/pg_dump.c=0Aindex=20= e8985a834f..41ce4b7866=20100644=0A---=20a/src/bin/pg_dump/pg_dump.c=0A= +++=20b/src/bin/pg_dump/pg_dump.c=0A@@=20-55,6=20+55,7=20@@=0A=20= #include=20"catalog/pg_type_d.h"=0A=20#include=20"common/connect.h"=0A=20= #include=20"dumputils.h"=0A+#include=20"fe_utils/query_utils.h"=0A=20= #include=20"fe_utils/string_utils.h"=0A=20#include=20"getopt_long.h"=0A=20= #include=20"libpq/libpq-fs.h"=0A@@=20-147,14=20+148,14=20@@=20static=20= void=20setup_connection(Archive=20*AH,=0A=20=09=09=09=09=09=09=09=20= const=20char=20*dumpencoding,=20const=20char=20*dumpsnapshot,=0A=20=09=09= =09=09=09=09=09=20char=20*use_role);=0A=20static=20ArchiveFormat=20= parseArchiveFormat(const=20char=20*format,=20ArchiveMode=20*mode);=0A= -static=20void=20expand_schema_name_patterns(Archive=20*fout,=0A+static=20= void=20expand_schema_name_patterns(PGconn=20*conn,=0A=20=09=09=09=09=09=09= =09=09=09=09SimpleStringList=20*patterns,=0A=20=09=09=09=09=09=09=09=09=09= =09SimpleOidList=20*oids,=0A=20=09=09=09=09=09=09=09=09=09=09bool=20= strict_names);=0A-static=20void=20= expand_foreign_server_name_patterns(Archive=20*fout,=0A+static=20void=20= expand_foreign_server_name_patterns(PGconn=20*conn,=0A=20=09=09=09=09=09=09= =09=09=09=09=09=09SimpleStringList=20*patterns,=0A=20=09=09=09=09=09=09=09= =09=09=09=09=09SimpleOidList=20*oids);=0A-static=20void=20= expand_table_name_patterns(Archive=20*fout,=0A+static=20void=20= expand_table_name_patterns(PGconn=20*conn,=0A=20=09=09=09=09=09=09=09=09=09= =20=20=20SimpleStringList=20*patterns,=0A=20=09=09=09=09=09=09=09=09=09=20= =20=20SimpleOidList=20*oids,=0A=20=09=09=09=09=09=09=09=09=09=20=20=20= bool=20strict_names);=0A@@=20-798,13=20+799,15=20@@=20main(int=20argc,=20= char=20**argv)=0A=20=09/*=20Expand=20schema=20selection=20patterns=20= into=20OID=20lists=20*/=0A=20=09if=20(schema_include_patterns.head=20!=3D=20= NULL)=0A=20=09{=0A-=09=09expand_schema_name_patterns(fout,=20= &schema_include_patterns,=0A+=09=09= expand_schema_name_patterns(GetConnection(fout),=0A+=09=09=09=09=09=09=09= =09=09&schema_include_patterns,=0A=20=09=09=09=09=09=09=09=09=09= &schema_include_oids,=0A=20=09=09=09=09=09=09=09=09=09strict_names);=0A=20= =09=09if=20(schema_include_oids.head=20=3D=3D=20NULL)=0A=20=09=09=09= fatal("no=20matching=20schemas=20were=20found");=0A=20=09}=0A-=09= expand_schema_name_patterns(fout,=20&schema_exclude_patterns,=0A+=09= expand_schema_name_patterns(GetConnection(fout),=0A+=09=09=09=09=09=09=09= =09&schema_exclude_patterns,=0A=20=09=09=09=09=09=09=09=09= &schema_exclude_oids,=0A=20=09=09=09=09=09=09=09=09false);=0A=20=09/*=20= non-matching=20exclusion=20patterns=20aren't=20an=20error=20*/=0A@@=20= -812,21=20+815,25=20@@=20main(int=20argc,=20char=20**argv)=0A=20=09/*=20= Expand=20table=20selection=20patterns=20into=20OID=20lists=20*/=0A=20=09= if=20(table_include_patterns.head=20!=3D=20NULL)=0A=20=09{=0A-=09=09= expand_table_name_patterns(fout,=20&table_include_patterns,=0A+=09=09= expand_table_name_patterns(GetConnection(fout),=0A+=09=09=09=09=09=09=09=09= =20=20=20&table_include_patterns,=0A=20=09=09=09=09=09=09=09=09=20=20=20= &table_include_oids,=0A=20=09=09=09=09=09=09=09=09=20=20=20= strict_names);=0A=20=09=09if=20(table_include_oids.head=20=3D=3D=20NULL)=0A= =20=09=09=09fatal("no=20matching=20tables=20were=20found");=0A=20=09}=0A= -=09expand_table_name_patterns(fout,=20&table_exclude_patterns,=0A+=09= expand_table_name_patterns(GetConnection(fout),=0A+=09=09=09=09=09=09=09=20= =20=20&table_exclude_patterns,=0A=20=09=09=09=09=09=09=09=20=20=20= &table_exclude_oids,=0A=20=09=09=09=09=09=09=09=20=20=20false);=0A=20=0A= -=09expand_table_name_patterns(fout,=20&tabledata_exclude_patterns,=0A+=09= expand_table_name_patterns(GetConnection(fout),=0A+=09=09=09=09=09=09=09=20= =20=20&tabledata_exclude_patterns,=0A=20=09=09=09=09=09=09=09=20=20=20= &tabledata_exclude_oids,=0A=20=09=09=09=09=09=09=09=20=20=20false);=0A=20= =0A-=09expand_foreign_server_name_patterns(fout,=20= &foreign_servers_include_patterns,=0A+=09= expand_foreign_server_name_patterns(GetConnection(fout),=0A+=09=09=09=09=09= =09=09=09=09=09&foreign_servers_include_patterns,=0A=20=09=09=09=09=09=09= =09=09=09=09&foreign_servers_include_oids);=0A=20=0A=20=09/*=20= non-matching=20exclusion=20patterns=20aren't=20an=20error=20*/=0A@@=20= -1316,7=20+1323,7=20@@=20parseArchiveFormat(const=20char=20*format,=20= ArchiveMode=20*mode)=0A=20=20*=20and=20append=20them=20to=20the=20given=20= OID=20list.=0A=20=20*/=0A=20static=20void=0A= -expand_schema_name_patterns(Archive=20*fout,=0A= +expand_schema_name_patterns(PGconn=20*conn,=0A=20=09=09=09=09=09=09=09= SimpleStringList=20*patterns,=0A=20=09=09=09=09=09=09=09SimpleOidList=20= *oids,=0A=20=09=09=09=09=09=09=09bool=20strict_names)=0A@@=20-1340,10=20= +1347,10=20@@=20expand_schema_name_patterns(Archive=20*fout,=0A=20=09{=0A= =20=09=09appendPQExpBufferStr(query,=0A=20=09=09=09=09=09=09=09=20= "SELECT=20oid=20FROM=20pg_catalog.pg_namespace=20n\n");=0A-=09=09= processSQLNamePattern(GetConnection(fout),=20query,=20cell->val,=20= false,=0A+=09=09processSQLNamePattern(conn,=20query,=20cell->val,=20= false,=0A=20=09=09=09=09=09=09=09=20=20false,=20NULL,=20"n.nspname",=20= NULL,=20NULL);=0A=20=0A-=09=09res=20=3D=20ExecuteSqlQueryAH(fout,=20= query->data,=20PGRES_TUPLES_OK);=0A+=09=09res=20=3D=20= ExecuteSqlQuery(conn,=20query->data,=20PGRES_TUPLES_OK);=0A=20=09=09if=20= (strict_names=20&&=20PQntuples(res)=20=3D=3D=200)=0A=20=09=09=09= fatal("no=20matching=20schemas=20were=20found=20for=20pattern=20\"%s\"",=20= cell->val);=0A=20=0A@@=20-1364,7=20+1371,7=20@@=20= expand_schema_name_patterns(Archive=20*fout,=0A=20=20*=20and=20append=20= them=20to=20the=20given=20OID=20list.=0A=20=20*/=0A=20static=20void=0A= -expand_foreign_server_name_patterns(Archive=20*fout,=0A= +expand_foreign_server_name_patterns(PGconn=20*conn,=0A=20=09=09=09=09=09= =09=09=09=09SimpleStringList=20*patterns,=0A=20=09=09=09=09=09=09=09=09=09= SimpleOidList=20*oids)=0A=20{=0A@@=20-1387,10=20+1394,10=20@@=20= expand_foreign_server_name_patterns(Archive=20*fout,=0A=20=09{=0A=20=09=09= appendPQExpBufferStr(query,=0A=20=09=09=09=09=09=09=09=20"SELECT=20oid=20= FROM=20pg_catalog.pg_foreign_server=20s\n");=0A-=09=09= processSQLNamePattern(GetConnection(fout),=20query,=20cell->val,=20= false,=0A+=09=09processSQLNamePattern(conn,=20query,=20cell->val,=20= false,=0A=20=09=09=09=09=09=09=09=20=20false,=20NULL,=20"s.srvname",=20= NULL,=20NULL);=0A=20=0A-=09=09res=20=3D=20ExecuteSqlQueryAH(fout,=20= query->data,=20PGRES_TUPLES_OK);=0A+=09=09res=20=3D=20= ExecuteSqlQuery(conn,=20query->data,=20PGRES_TUPLES_OK);=0A=20=09=09if=20= (PQntuples(res)=20=3D=3D=200)=0A=20=09=09=09fatal("no=20matching=20= foreign=20servers=20were=20found=20for=20pattern=20\"%s\"",=20= cell->val);=0A=20=0A@@=20-1410,7=20+1417,7=20@@=20= expand_foreign_server_name_patterns(Archive=20*fout,=0A=20=20*=20in=20= pg_dumpall.c=0A=20=20*/=0A=20static=20void=0A= -expand_table_name_patterns(Archive=20*fout,=0A= +expand_table_name_patterns(PGconn=20*conn,=0A=20=09=09=09=09=09=09=20=20= =20SimpleStringList=20*patterns,=20SimpleOidList=20*oids,=0A=20=09=09=09=09= =09=09=20=20=20bool=20strict_names)=0A=20{=0A@@=20-1446,13=20+1453,13=20= @@=20expand_table_name_patterns(Archive=20*fout,=0A=20=09=09=09=09=09=09=20= =20RELKIND_RELATION,=20RELKIND_SEQUENCE,=20RELKIND_VIEW,=0A=20=09=09=09=09= =09=09=20=20RELKIND_MATVIEW,=20RELKIND_FOREIGN_TABLE,=0A=20=09=09=09=09=09= =09=20=20RELKIND_PARTITIONED_TABLE);=0A-=09=09= processSQLNamePattern(GetConnection(fout),=20query,=20cell->val,=20true,=0A= +=09=09processSQLNamePattern(conn,=20query,=20cell->val,=20true,=0A=20=09= =09=09=09=09=09=09=20=20false,=20"n.nspname",=20"c.relname",=20NULL,=0A=20= =09=09=09=09=09=09=09=20=20"pg_catalog.pg_table_is_visible(c.oid)");=0A=20= =0A-=09=09ExecuteSqlStatementAH(fout,=20"RESET=20search_path");=0A-=09=09= res=20=3D=20ExecuteSqlQueryAH(fout,=20query->data,=20PGRES_TUPLES_OK);=0A= -=09=09PQclear(ExecuteSqlQueryForSingleRowAH(fout,=0A+=09=09= ExecuteSqlStatement(conn,=20"RESET=20search_path");=0A+=09=09res=20=3D=20= ExecuteSqlQuery(conn,=20query->data,=20PGRES_TUPLES_OK);=0A+=09=09= PQclear(ExecuteSqlQueryForSingleRow(conn,=0A=20=09=09=09=09=09=09=09=09=09= =09=09ALWAYS_SECURE_SEARCH_PATH_SQL));=0A=20=09=09if=20(strict_names=20= &&=20PQntuples(res)=20=3D=3D=200)=0A=20=09=09=09fatal("no=20matching=20= tables=20were=20found=20for=20pattern=20\"%s\"",=20cell->val);=0A--=20=0A= 2.21.1=20(Apple=20Git-122.3)=0A=0A= --Apple-Mail=_8B07CFD0-2450-4CA2-BEE1-ACB2F7EEE33B Content-Disposition: attachment; filename=v32-0007-Moving-pg_dump-functions-to-new-file-option_util.patch Content-Type: application/octet-stream; x-unix-mode=0644; name="v32-0007-Moving-pg_dump-functions-to-new-file-option_util.patch" Content-Transfer-Encoding: quoted-printable =46rom=200ceafd8608c542ca21ce8b8ea111a1f5115bbc0a=20Mon=20Sep=2017=20= 00:00:00=202001=0AFrom:=20Mark=20Dilger=20=0A= Date:=20Wed,=206=20Jan=202021=2014:07:58=20-0800=0ASubject:=20[PATCH=20= v32=207/9]=20Moving=20pg_dump=20functions=20to=20new=20file=20= option_utils=0A=0AMoving=20the=20recently=20refactored=20functions=0A= expand_schema_name_patterns,=20expand_foreign_server_name_patterns,=0A= and=20expand_table_name_patterns=20from=20pg_dump.c,=20along=20with=20= the=0Afunction=20expand_dbname_patterns=20from=20pg_dumpall.c,=20into=20= the=20new=20file=0Afe_utils/option_utils.c=0A---=0A=20= src/bin/pg_dump/pg_dump.c=20=20=20=20=20=20=20=20=20=20=20|=20170=20= +--------------------=0A=20src/bin/pg_dump/pg_dumpall.c=20=20=20=20=20=20= =20=20|=20=2046=20+-----=0A=20src/fe_utils/Makefile=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20|=20=20=201=20+=0A=20src/fe_utils/option_utils.c=20=20= =20=20=20=20=20=20=20|=20225=20++++++++++++++++++++++++++++=0A=20= src/include/fe_utils/option_utils.h=20|=20=2035=20+++++=0A=205=20files=20= changed,=20263=20insertions(+),=20214=20deletions(-)=0A=20create=20mode=20= 100644=20src/fe_utils/option_utils.c=0A=20create=20mode=20100644=20= src/include/fe_utils/option_utils.h=0A=0Adiff=20--git=20= a/src/bin/pg_dump/pg_dump.c=20b/src/bin/pg_dump/pg_dump.c=0Aindex=20= 41ce4b7866..c334b9e829=20100644=0A---=20a/src/bin/pg_dump/pg_dump.c=0A= +++=20b/src/bin/pg_dump/pg_dump.c=0A@@=20-55,6=20+55,7=20@@=0A=20= #include=20"catalog/pg_type_d.h"=0A=20#include=20"common/connect.h"=0A=20= #include=20"dumputils.h"=0A+#include=20"fe_utils/option_utils.h"=0A=20= #include=20"fe_utils/query_utils.h"=0A=20#include=20= "fe_utils/string_utils.h"=0A=20#include=20"getopt_long.h"=0A@@=20-148,17=20= +149,6=20@@=20static=20void=20setup_connection(Archive=20*AH,=0A=20=09=09= =09=09=09=09=09=20const=20char=20*dumpencoding,=20const=20char=20= *dumpsnapshot,=0A=20=09=09=09=09=09=09=09=20char=20*use_role);=0A=20= static=20ArchiveFormat=20parseArchiveFormat(const=20char=20*format,=20= ArchiveMode=20*mode);=0A-static=20void=20= expand_schema_name_patterns(PGconn=20*conn,=0A-=09=09=09=09=09=09=09=09=09= =09SimpleStringList=20*patterns,=0A-=09=09=09=09=09=09=09=09=09=09= SimpleOidList=20*oids,=0A-=09=09=09=09=09=09=09=09=09=09bool=20= strict_names);=0A-static=20void=20= expand_foreign_server_name_patterns(PGconn=20*conn,=0A-=09=09=09=09=09=09= =09=09=09=09=09=09SimpleStringList=20*patterns,=0A-=09=09=09=09=09=09=09=09= =09=09=09=09SimpleOidList=20*oids);=0A-static=20void=20= expand_table_name_patterns(PGconn=20*conn,=0A-=09=09=09=09=09=09=09=09=09= =20=20=20SimpleStringList=20*patterns,=0A-=09=09=09=09=09=09=09=09=09=20=20= =20SimpleOidList=20*oids,=0A-=09=09=09=09=09=09=09=09=09=20=20=20bool=20= strict_names);=0A=20static=20NamespaceInfo=20*findNamespace(Oid=20= nsoid);=0A=20static=20void=20dumpTableData(Archive=20*fout,=20= TableDataInfo=20*tdinfo);=0A=20static=20void=20= refreshMatViewData(Archive=20*fout,=20TableDataInfo=20*tdinfo);=0A@@=20= -1318,164=20+1308,6=20@@=20parseArchiveFormat(const=20char=20*format,=20= ArchiveMode=20*mode)=0A=20=09return=20archiveFormat;=0A=20}=0A=20=0A-/*=0A= -=20*=20Find=20the=20OIDs=20of=20all=20schemas=20matching=20the=20given=20= list=20of=20patterns,=0A-=20*=20and=20append=20them=20to=20the=20given=20= OID=20list.=0A-=20*/=0A-static=20void=0A= -expand_schema_name_patterns(PGconn=20*conn,=0A-=09=09=09=09=09=09=09= SimpleStringList=20*patterns,=0A-=09=09=09=09=09=09=09SimpleOidList=20= *oids,=0A-=09=09=09=09=09=09=09bool=20strict_names)=0A-{=0A-=09= PQExpBuffer=20query;=0A-=09PGresult=20=20=20*res;=0A-=09= SimpleStringListCell=20*cell;=0A-=09int=09=09=09i;=0A-=0A-=09if=20= (patterns->head=20=3D=3D=20NULL)=0A-=09=09return;=09=09=09=09=09/*=20= nothing=20to=20do=20*/=0A-=0A-=09query=20=3D=20createPQExpBuffer();=0A-=0A= -=09/*=0A-=09=20*=20The=20loop=20below=20runs=20multiple=20SELECTs=20= might=20sometimes=20result=20in=0A-=09=20*=20duplicate=20entries=20in=20= the=20OID=20list,=20but=20we=20don't=20care.=0A-=09=20*/=0A-=0A-=09for=20= (cell=20=3D=20patterns->head;=20cell;=20cell=20=3D=20cell->next)=0A-=09{=0A= -=09=09appendPQExpBufferStr(query,=0A-=09=09=09=09=09=09=09=20"SELECT=20= oid=20FROM=20pg_catalog.pg_namespace=20n\n");=0A-=09=09= processSQLNamePattern(conn,=20query,=20cell->val,=20false,=0A-=09=09=09=09= =09=09=09=20=20false,=20NULL,=20"n.nspname",=20NULL,=20NULL);=0A-=0A-=09=09= res=20=3D=20ExecuteSqlQuery(conn,=20query->data,=20PGRES_TUPLES_OK);=0A-=09= =09if=20(strict_names=20&&=20PQntuples(res)=20=3D=3D=200)=0A-=09=09=09= fatal("no=20matching=20schemas=20were=20found=20for=20pattern=20\"%s\"",=20= cell->val);=0A-=0A-=09=09for=20(i=20=3D=200;=20i=20<=20PQntuples(res);=20= i++)=0A-=09=09{=0A-=09=09=09simple_oid_list_append(oids,=20= atooid(PQgetvalue(res,=20i,=200)));=0A-=09=09}=0A-=0A-=09=09= PQclear(res);=0A-=09=09resetPQExpBuffer(query);=0A-=09}=0A-=0A-=09= destroyPQExpBuffer(query);=0A-}=0A-=0A-/*=0A-=20*=20Find=20the=20OIDs=20= of=20all=20foreign=20servers=20matching=20the=20given=20list=20of=20= patterns,=0A-=20*=20and=20append=20them=20to=20the=20given=20OID=20list.=0A= -=20*/=0A-static=20void=0A-expand_foreign_server_name_patterns(PGconn=20= *conn,=0A-=09=09=09=09=09=09=09=09=09SimpleStringList=20*patterns,=0A-=09= =09=09=09=09=09=09=09=09SimpleOidList=20*oids)=0A-{=0A-=09PQExpBuffer=20= query;=0A-=09PGresult=20=20=20*res;=0A-=09SimpleStringListCell=20*cell;=0A= -=09int=09=09=09i;=0A-=0A-=09if=20(patterns->head=20=3D=3D=20NULL)=0A-=09= =09return;=09=09=09=09=09/*=20nothing=20to=20do=20*/=0A-=0A-=09query=20=3D= =20createPQExpBuffer();=0A-=0A-=09/*=0A-=09=20*=20The=20loop=20below=20= runs=20multiple=20SELECTs=20might=20sometimes=20result=20in=0A-=09=20*=20= duplicate=20entries=20in=20the=20OID=20list,=20but=20we=20don't=20care.=0A= -=09=20*/=0A-=0A-=09for=20(cell=20=3D=20patterns->head;=20cell;=20cell=20= =3D=20cell->next)=0A-=09{=0A-=09=09appendPQExpBufferStr(query,=0A-=09=09=09= =09=09=09=09=20"SELECT=20oid=20FROM=20pg_catalog.pg_foreign_server=20= s\n");=0A-=09=09processSQLNamePattern(conn,=20query,=20cell->val,=20= false,=0A-=09=09=09=09=09=09=09=20=20false,=20NULL,=20"s.srvname",=20= NULL,=20NULL);=0A-=0A-=09=09res=20=3D=20ExecuteSqlQuery(conn,=20= query->data,=20PGRES_TUPLES_OK);=0A-=09=09if=20(PQntuples(res)=20=3D=3D=20= 0)=0A-=09=09=09fatal("no=20matching=20foreign=20servers=20were=20found=20= for=20pattern=20\"%s\"",=20cell->val);=0A-=0A-=09=09for=20(i=20=3D=200;=20= i=20<=20PQntuples(res);=20i++)=0A-=09=09=09simple_oid_list_append(oids,=20= atooid(PQgetvalue(res,=20i,=200)));=0A-=0A-=09=09PQclear(res);=0A-=09=09= resetPQExpBuffer(query);=0A-=09}=0A-=0A-=09destroyPQExpBuffer(query);=0A= -}=0A-=0A-/*=0A-=20*=20Find=20the=20OIDs=20of=20all=20tables=20matching=20= the=20given=20list=20of=20patterns,=0A-=20*=20and=20append=20them=20to=20= the=20given=20OID=20list.=20See=20also=20expand_dbname_patterns()=0A-=20= *=20in=20pg_dumpall.c=0A-=20*/=0A-static=20void=0A= -expand_table_name_patterns(PGconn=20*conn,=0A-=09=09=09=09=09=09=20=20=20= SimpleStringList=20*patterns,=20SimpleOidList=20*oids,=0A-=09=09=09=09=09= =09=20=20=20bool=20strict_names)=0A-{=0A-=09PQExpBuffer=20query;=0A-=09= PGresult=20=20=20*res;=0A-=09SimpleStringListCell=20*cell;=0A-=09int=09=09= =09i;=0A-=0A-=09if=20(patterns->head=20=3D=3D=20NULL)=0A-=09=09return;=09= =09=09=09=09/*=20nothing=20to=20do=20*/=0A-=0A-=09query=20=3D=20= createPQExpBuffer();=0A-=0A-=09/*=0A-=09=20*=20this=20might=20sometimes=20= result=20in=20duplicate=20entries=20in=20the=20OID=20list,=20but=0A-=09=20= *=20we=20don't=20care.=0A-=09=20*/=0A-=0A-=09for=20(cell=20=3D=20= patterns->head;=20cell;=20cell=20=3D=20cell->next)=0A-=09{=0A-=09=09/*=0A= -=09=09=20*=20Query=20must=20remain=20ABSOLUTELY=20devoid=20of=20= unqualified=20names.=20=20This=0A-=09=09=20*=20would=20be=20unnecessary=20= given=20a=20pg_table_is_visible()=20variant=20taking=20a=0A-=09=09=20*=20= search_path=20argument.=0A-=09=09=20*/=0A-=09=09appendPQExpBuffer(query,=0A= -=09=09=09=09=09=09=20=20"SELECT=20c.oid"=0A-=09=09=09=09=09=09=20=20= "\nFROM=20pg_catalog.pg_class=20c"=0A-=09=09=09=09=09=09=20=20"\n=20=20=20= =20=20LEFT=20JOIN=20pg_catalog.pg_namespace=20n"=0A-=09=09=09=09=09=09=20= =20"\n=20=20=20=20=20ON=20n.oid=20OPERATOR(pg_catalog.=3D)=20= c.relnamespace"=0A-=09=09=09=09=09=09=20=20"\nWHERE=20c.relkind=20= OPERATOR(pg_catalog.=3D)=20ANY"=0A-=09=09=09=09=09=09=20=20"\n=20=20=20=20= (array['%c',=20'%c',=20'%c',=20'%c',=20'%c',=20'%c'])\n",=0A-=09=09=09=09= =09=09=20=20RELKIND_RELATION,=20RELKIND_SEQUENCE,=20RELKIND_VIEW,=0A-=09=09= =09=09=09=09=20=20RELKIND_MATVIEW,=20RELKIND_FOREIGN_TABLE,=0A-=09=09=09=09= =09=09=20=20RELKIND_PARTITIONED_TABLE);=0A-=09=09= processSQLNamePattern(conn,=20query,=20cell->val,=20true,=0A-=09=09=09=09= =09=09=09=20=20false,=20"n.nspname",=20"c.relname",=20NULL,=0A-=09=09=09=09= =09=09=09=20=20"pg_catalog.pg_table_is_visible(c.oid)");=0A-=0A-=09=09= ExecuteSqlStatement(conn,=20"RESET=20search_path");=0A-=09=09res=20=3D=20= ExecuteSqlQuery(conn,=20query->data,=20PGRES_TUPLES_OK);=0A-=09=09= PQclear(ExecuteSqlQueryForSingleRow(conn,=0A-=09=09=09=09=09=09=09=09=09=09= =09ALWAYS_SECURE_SEARCH_PATH_SQL));=0A-=09=09if=20(strict_names=20&&=20= PQntuples(res)=20=3D=3D=200)=0A-=09=09=09fatal("no=20matching=20tables=20= were=20found=20for=20pattern=20\"%s\"",=20cell->val);=0A-=0A-=09=09for=20= (i=20=3D=200;=20i=20<=20PQntuples(res);=20i++)=0A-=09=09{=0A-=09=09=09= simple_oid_list_append(oids,=20atooid(PQgetvalue(res,=20i,=200)));=0A-=09= =09}=0A-=0A-=09=09PQclear(res);=0A-=09=09resetPQExpBuffer(query);=0A-=09= }=0A-=0A-=09destroyPQExpBuffer(query);=0A-}=0A-=0A=20/*=0A=20=20*=20= checkExtensionMembership=0A=20=20*=09=09Determine=20whether=20object=20= is=20an=20extension=20member,=20and=20if=20so,=0Adiff=20--git=20= a/src/bin/pg_dump/pg_dumpall.c=20b/src/bin/pg_dump/pg_dumpall.c=0Aindex=20= 807226537a..01db15dfda=20100644=0A---=20a/src/bin/pg_dump/pg_dumpall.c=0A= +++=20b/src/bin/pg_dump/pg_dumpall.c=0A@@=20-23,6=20+23,7=20@@=0A=20= #include=20"common/logging.h"=0A=20#include=20"common/string.h"=0A=20= #include=20"dumputils.h"=0A+#include=20"fe_utils/option_utils.h"=0A=20= #include=20"fe_utils/query_utils.h"=0A=20#include=20= "fe_utils/string_utils.h"=0A=20#include=20"getopt_long.h"=0A@@=20-54,8=20= +55,6=20@@=20static=20PGconn=20*connectDatabase(const=20char=20*dbname,=20= const=20char=20*connstr,=20const=20ch=0A=20static=20char=20= *constructConnStr(const=20char=20**keywords,=20const=20char=20**values);=0A= =20static=20PGresult=20*executeQuery(PGconn=20*conn,=20const=20char=20= *query);=0A=20static=20void=20executeCommand(PGconn=20*conn,=20const=20= char=20*query);=0A-static=20void=20expand_dbname_patterns(PGconn=20= *conn,=20SimpleStringList=20*patterns,=0A-=09=09=09=09=09=09=09=09=20=20=20= SimpleStringList=20*names);=0A=20=0A=20static=20char=20= pg_dump_bin[MAXPGPATH];=0A=20static=20const=20char=20*progname;=0A@@=20= -1409,49=20+1408,6=20@@=20dumpUserConfig(PGconn=20*conn,=20const=20char=20= *username)=0A=20=09destroyPQExpBuffer(buf);=0A=20}=0A=20=0A-/*=0A-=20*=20= Find=20a=20list=20of=20database=20names=20that=20match=20the=20given=20= patterns.=0A-=20*=20See=20also=20expand_table_name_patterns()=20in=20= pg_dump.c=0A-=20*/=0A-static=20void=0A-expand_dbname_patterns(PGconn=20= *conn,=0A-=09=09=09=09=09=20=20=20SimpleStringList=20*patterns,=0A-=09=09= =09=09=09=20=20=20SimpleStringList=20*names)=0A-{=0A-=09PQExpBuffer=20= query;=0A-=09PGresult=20=20=20*res;=0A-=0A-=09if=20(patterns->head=20=3D=3D= =20NULL)=0A-=09=09return;=09=09=09=09=09/*=20nothing=20to=20do=20*/=0A-=0A= -=09query=20=3D=20createPQExpBuffer();=0A-=0A-=09/*=0A-=09=20*=20The=20= loop=20below=20runs=20multiple=20SELECTs,=20which=20might=20sometimes=20= result=20in=0A-=09=20*=20duplicate=20entries=20in=20the=20name=20list,=20= but=20we=20don't=20care,=20since=20all=20we're=0A-=09=20*=20going=20to=20= do=20is=20test=20membership=20of=20the=20list.=0A-=09=20*/=0A-=0A-=09for=20= (SimpleStringListCell=20*cell=20=3D=20patterns->head;=20cell;=20cell=20=3D= =20cell->next)=0A-=09{=0A-=09=09appendPQExpBufferStr(query,=0A-=09=09=09=09= =09=09=09=20"SELECT=20datname=20FROM=20pg_catalog.pg_database=20n\n");=0A= -=09=09processSQLNamePattern(conn,=20query,=20cell->val,=20false,=0A-=09=09= =09=09=09=09=09=20=20false,=20NULL,=20"datname",=20NULL,=20NULL);=0A-=0A= -=09=09res=20=3D=20executeQuery(conn,=20query->data);=0A-=09=09for=20= (int=20i=20=3D=200;=20i=20<=20PQntuples(res);=20i++)=0A-=09=09{=0A-=09=09= =09simple_string_list_append(names,=20PQgetvalue(res,=20i,=200));=0A-=09=09= }=0A-=0A-=09=09PQclear(res);=0A-=09=09resetPQExpBuffer(query);=0A-=09}=0A= -=0A-=09destroyPQExpBuffer(query);=0A-}=0A-=0A=20/*=0A=20=20*=20Dump=20= contents=20of=20databases.=0A=20=20*/=0Adiff=20--git=20= a/src/fe_utils/Makefile=20b/src/fe_utils/Makefile=0Aindex=20= 7fdbe08e11..eb937e4648=20100644=0A---=20a/src/fe_utils/Makefile=0A+++=20= b/src/fe_utils/Makefile=0A@@=20-25,6=20+25,7=20@@=20OBJS=20=3D=20\=0A=20=09= conditional.o=20\=0A=20=09exit_utils.o=20\=0A=20=09mbprint.o=20\=0A+=09= option_utils.o=20\=0A=20=09print.o=20\=0A=20=09psqlscan.o=20\=0A=20=09= query_utils.o=20\=0Adiff=20--git=20a/src/fe_utils/option_utils.c=20= b/src/fe_utils/option_utils.c=0Anew=20file=20mode=20100644=0Aindex=20= 0000000000..7893df77aa=0A---=20/dev/null=0A+++=20= b/src/fe_utils/option_utils.c=0A@@=20-0,0=20+1,225=20@@=0A= +/*-----------------------------------------------------------------------= --=0A+=20*=0A+=20*=20Command-line=20option=20facilities=20for=20frontend=20= code=0A+=20*=0A+=20*=20Functions=20for=20converting=20shell-style=20= patterns=20into=20simple=20lists=20of=20Oids=20for=0A+=20*=20database=20= objects=20that=20match=20the=20patterns.=0A+=20*=0A+=20*=20Portions=20= Copyright=20(c)=201996-2020,=20PostgreSQL=20Global=20Development=20Group=0A= +=20*=20Portions=20Copyright=20(c)=201994,=20Regents=20of=20the=20= University=20of=20California=0A+=20*=0A+=20*=20= src/fe_utils/option_utils.c=0A+=20*=0A+=20= *-------------------------------------------------------------------------= =0A+=20*/=0A+#include=20"postgres_fe.h"=0A+=0A+#include=20= "catalog/pg_class.h"=0A+#include=20"common/connect.h"=0A+#include=20= "fe_utils/exit_utils.h"=0A+#include=20"fe_utils/option_utils.h"=0A= +#include=20"fe_utils/query_utils.h"=0A+#include=20= "fe_utils/simple_list.h"=0A+#include=20"fe_utils/string_utils.h"=0A= +#include=20"libpq-fe.h"=0A+#include=20"pqexpbuffer.h"=0A+=0A+/*=0A+=20*=20= Find=20the=20OIDs=20of=20all=20schemas=20matching=20the=20given=20list=20= of=20patterns,=0A+=20*=20and=20append=20them=20to=20the=20given=20OID=20= list.=0A+=20*/=0A+void=0A+expand_schema_name_patterns(PGconn=20*conn,=0A= +=09=09=09=09=09=09=09SimpleStringList=20*patterns,=0A+=09=09=09=09=09=09= =09SimpleOidList=20*oids,=0A+=09=09=09=09=09=09=09bool=20strict_names)=0A= +{=0A+=09PQExpBuffer=20query;=0A+=09PGresult=20=20=20*res;=0A+=09= SimpleStringListCell=20*cell;=0A+=09int=09=09=09i;=0A+=0A+=09if=20= (patterns->head=20=3D=3D=20NULL)=0A+=09=09return;=09=09=09=09=09/*=20= nothing=20to=20do=20*/=0A+=0A+=09query=20=3D=20createPQExpBuffer();=0A+=0A= +=09/*=0A+=09=20*=20The=20loop=20below=20runs=20multiple=20SELECTs=20= might=20sometimes=20result=20in=0A+=09=20*=20duplicate=20entries=20in=20= the=20OID=20list,=20but=20we=20don't=20care.=0A+=09=20*/=0A+=0A+=09for=20= (cell=20=3D=20patterns->head;=20cell;=20cell=20=3D=20cell->next)=0A+=09{=0A= +=09=09appendPQExpBufferStr(query,=0A+=09=09=09=09=09=09=09=20"SELECT=20= oid=20FROM=20pg_catalog.pg_namespace=20n\n");=0A+=09=09= processSQLNamePattern(conn,=20query,=20cell->val,=20false,=0A+=09=09=09=09= =09=09=09=20=20false,=20NULL,=20"n.nspname",=20NULL,=20NULL);=0A+=0A+=09=09= res=20=3D=20ExecuteSqlQuery(conn,=20query->data,=20PGRES_TUPLES_OK);=0A+=09= =09if=20(strict_names=20&&=20PQntuples(res)=20=3D=3D=200)=0A+=09=09=09= fatal("no=20matching=20schemas=20were=20found=20for=20pattern=20\"%s\"",=20= cell->val);=0A+=0A+=09=09for=20(i=20=3D=200;=20i=20<=20PQntuples(res);=20= i++)=0A+=09=09{=0A+=09=09=09simple_oid_list_append(oids,=20= atooid(PQgetvalue(res,=20i,=200)));=0A+=09=09}=0A+=0A+=09=09= PQclear(res);=0A+=09=09resetPQExpBuffer(query);=0A+=09}=0A+=0A+=09= destroyPQExpBuffer(query);=0A+}=0A+=0A+/*=0A+=20*=20Find=20the=20OIDs=20= of=20all=20foreign=20servers=20matching=20the=20given=20list=20of=20= patterns,=0A+=20*=20and=20append=20them=20to=20the=20given=20OID=20list.=0A= +=20*/=0A+void=0A+expand_foreign_server_name_patterns(PGconn=20*conn,=0A= +=09=09=09=09=09=09=09=09=09SimpleStringList=20*patterns,=0A+=09=09=09=09= =09=09=09=09=09SimpleOidList=20*oids)=0A+{=0A+=09PQExpBuffer=20query;=0A= +=09PGresult=20=20=20*res;=0A+=09SimpleStringListCell=20*cell;=0A+=09int=09= =09=09i;=0A+=0A+=09if=20(patterns->head=20=3D=3D=20NULL)=0A+=09=09= return;=09=09=09=09=09/*=20nothing=20to=20do=20*/=0A+=0A+=09query=20=3D=20= createPQExpBuffer();=0A+=0A+=09/*=0A+=09=20*=20The=20loop=20below=20runs=20= multiple=20SELECTs=20might=20sometimes=20result=20in=0A+=09=20*=20= duplicate=20entries=20in=20the=20OID=20list,=20but=20we=20don't=20care.=0A= +=09=20*/=0A+=0A+=09for=20(cell=20=3D=20patterns->head;=20cell;=20cell=20= =3D=20cell->next)=0A+=09{=0A+=09=09appendPQExpBufferStr(query,=0A+=09=09=09= =09=09=09=09=20"SELECT=20oid=20FROM=20pg_catalog.pg_foreign_server=20= s\n");=0A+=09=09processSQLNamePattern(conn,=20query,=20cell->val,=20= false,=0A+=09=09=09=09=09=09=09=20=20false,=20NULL,=20"s.srvname",=20= NULL,=20NULL);=0A+=0A+=09=09res=20=3D=20ExecuteSqlQuery(conn,=20= query->data,=20PGRES_TUPLES_OK);=0A+=09=09if=20(PQntuples(res)=20=3D=3D=20= 0)=0A+=09=09=09fatal("no=20matching=20foreign=20servers=20were=20found=20= for=20pattern=20\"%s\"",=20cell->val);=0A+=0A+=09=09for=20(i=20=3D=200;=20= i=20<=20PQntuples(res);=20i++)=0A+=09=09=09simple_oid_list_append(oids,=20= atooid(PQgetvalue(res,=20i,=200)));=0A+=0A+=09=09PQclear(res);=0A+=09=09= resetPQExpBuffer(query);=0A+=09}=0A+=0A+=09destroyPQExpBuffer(query);=0A= +}=0A+=0A+/*=0A+=20*=20Find=20the=20OIDs=20of=20all=20tables=20matching=20= the=20given=20list=20of=20patterns,=0A+=20*=20and=20append=20them=20to=20= the=20given=20OID=20list.=0A+=20*/=0A+void=0A= +expand_table_name_patterns(PGconn=20*conn,=0A+=09=09=09=09=09=09=20=20=20= SimpleStringList=20*patterns,=20SimpleOidList=20*oids,=0A+=09=09=09=09=09= =09=20=20=20bool=20strict_names)=0A+{=0A+=09PQExpBuffer=20query;=0A+=09= PGresult=20=20=20*res;=0A+=09SimpleStringListCell=20*cell;=0A+=09int=09=09= =09i;=0A+=0A+=09if=20(patterns->head=20=3D=3D=20NULL)=0A+=09=09return;=09= =09=09=09=09/*=20nothing=20to=20do=20*/=0A+=0A+=09query=20=3D=20= createPQExpBuffer();=0A+=0A+=09/*=0A+=09=20*=20this=20might=20sometimes=20= result=20in=20duplicate=20entries=20in=20the=20OID=20list,=20but=0A+=09=20= *=20we=20don't=20care.=0A+=09=20*/=0A+=0A+=09for=20(cell=20=3D=20= patterns->head;=20cell;=20cell=20=3D=20cell->next)=0A+=09{=0A+=09=09/*=0A= +=09=09=20*=20Query=20must=20remain=20ABSOLUTELY=20devoid=20of=20= unqualified=20names.=20=20This=0A+=09=09=20*=20would=20be=20unnecessary=20= given=20a=20pg_table_is_visible()=20variant=20taking=20a=0A+=09=09=20*=20= search_path=20argument.=0A+=09=09=20*/=0A+=09=09appendPQExpBuffer(query,=0A= +=09=09=09=09=09=09=20=20"SELECT=20c.oid"=0A+=09=09=09=09=09=09=20=20= "\nFROM=20pg_catalog.pg_class=20c"=0A+=09=09=09=09=09=09=20=20"\n=20=20=20= =20=20LEFT=20JOIN=20pg_catalog.pg_namespace=20n"=0A+=09=09=09=09=09=09=20= =20"\n=20=20=20=20=20ON=20n.oid=20OPERATOR(pg_catalog.=3D)=20= c.relnamespace"=0A+=09=09=09=09=09=09=20=20"\nWHERE=20c.relkind=20= OPERATOR(pg_catalog.=3D)=20ANY"=0A+=09=09=09=09=09=09=20=20"\n=20=20=20=20= (array['%c',=20'%c',=20'%c',=20'%c',=20'%c',=20'%c'])\n",=0A+=09=09=09=09= =09=09=20=20RELKIND_RELATION,=20RELKIND_SEQUENCE,=20RELKIND_VIEW,=0A+=09=09= =09=09=09=09=20=20RELKIND_MATVIEW,=20RELKIND_FOREIGN_TABLE,=0A+=09=09=09=09= =09=09=20=20RELKIND_PARTITIONED_TABLE);=0A+=09=09= processSQLNamePattern(conn,=20query,=20cell->val,=20true,=0A+=09=09=09=09= =09=09=09=20=20false,=20"n.nspname",=20"c.relname",=20NULL,=0A+=09=09=09=09= =09=09=09=20=20"pg_catalog.pg_table_is_visible(c.oid)");=0A+=0A+=09=09= ExecuteSqlStatement(conn,=20"RESET=20search_path");=0A+=09=09res=20=3D=20= ExecuteSqlQuery(conn,=20query->data,=20PGRES_TUPLES_OK);=0A+=09=09= PQclear(ExecuteSqlQueryForSingleRow(conn,=0A+=09=09=09=09=09=09=09=09=09=09= =09ALWAYS_SECURE_SEARCH_PATH_SQL));=0A+=09=09if=20(strict_names=20&&=20= PQntuples(res)=20=3D=3D=200)=0A+=09=09=09fatal("no=20matching=20tables=20= were=20found=20for=20pattern=20\"%s\"",=20cell->val);=0A+=0A+=09=09for=20= (i=20=3D=200;=20i=20<=20PQntuples(res);=20i++)=0A+=09=09{=0A+=09=09=09= simple_oid_list_append(oids,=20atooid(PQgetvalue(res,=20i,=200)));=0A+=09= =09}=0A+=0A+=09=09PQclear(res);=0A+=09=09resetPQExpBuffer(query);=0A+=09= }=0A+=0A+=09destroyPQExpBuffer(query);=0A+}=0A+=0A+/*=0A+=20*=20Find=20a=20= list=20of=20database=20names=20that=20match=20the=20given=20patterns.=0A= +=20*/=0A+void=0A+expand_dbname_patterns(PGconn=20*conn,=0A+=09=09=09=09=09= =20=20=20SimpleStringList=20*patterns,=0A+=09=09=09=09=09=20=20=20= SimpleStringList=20*names)=0A+{=0A+=09PQExpBuffer=20query;=0A+=09= PGresult=20=20=20*res;=0A+=0A+=09if=20(patterns->head=20=3D=3D=20NULL)=0A= +=09=09return;=09=09=09=09=09/*=20nothing=20to=20do=20*/=0A+=0A+=09query=20= =3D=20createPQExpBuffer();=0A+=0A+=09/*=0A+=09=20*=20The=20loop=20below=20= runs=20multiple=20SELECTs,=20which=20might=20sometimes=20result=20in=0A+=09= =20*=20duplicate=20entries=20in=20the=20name=20list,=20but=20we=20don't=20= care,=20since=20all=20we're=0A+=09=20*=20going=20to=20do=20is=20test=20= membership=20of=20the=20list.=0A+=09=20*/=0A+=0A+=09for=20= (SimpleStringListCell=20*cell=20=3D=20patterns->head;=20cell;=20cell=20=3D= =20cell->next)=0A+=09{=0A+=09=09appendPQExpBufferStr(query,=0A+=09=09=09=09= =09=09=09=20"SELECT=20datname=20FROM=20pg_catalog.pg_database=20n\n");=0A= +=09=09processSQLNamePattern(conn,=20query,=20cell->val,=20false,=0A+=09=09= =09=09=09=09=09=20=20false,=20NULL,=20"datname",=20NULL,=20NULL);=0A+=0A= +=09=09pg_log_info("executing=20%s",=20query->data);=0A+=09=09res=20=3D=20= ExecuteSqlQuery(conn,=20query->data,=20PGRES_TUPLES_OK);=0A+=09=09for=20= (int=20i=20=3D=200;=20i=20<=20PQntuples(res);=20i++)=0A+=09=09{=0A+=09=09= =09simple_string_list_append(names,=20PQgetvalue(res,=20i,=200));=0A+=09=09= }=0A+=0A+=09=09PQclear(res);=0A+=09=09resetPQExpBuffer(query);=0A+=09}=0A= +=0A+=09destroyPQExpBuffer(query);=0A+}=0Adiff=20--git=20= a/src/include/fe_utils/option_utils.h=20= b/src/include/fe_utils/option_utils.h=0Anew=20file=20mode=20100644=0A= index=200000000000..d626a0bbc9=0A---=20/dev/null=0A+++=20= b/src/include/fe_utils/option_utils.h=0A@@=20-0,0=20+1,35=20@@=0A= +/*-----------------------------------------------------------------------= --=0A+=20*=0A+=20*=20Command-line=20option=20facilities=20for=20frontend=20= code=0A+=20*=0A+=20*=20Functions=20for=20converting=20shell-style=20= patterns=20into=20simple=20lists=20of=20Oids=20for=0A+=20*=20database=20= objects=20that=20match=20the=20patterns.=0A+=20*=0A+=20*=20Portions=20= Copyright=20(c)=201996-2020,=20PostgreSQL=20Global=20Development=20Group=0A= +=20*=20Portions=20Copyright=20(c)=201994,=20Regents=20of=20the=20= University=20of=20California=0A+=20*=0A+=20*=20= src/include/fe_utils/option_utils.h=0A+=20*=0A+=20= *-------------------------------------------------------------------------= =0A+=20*/=0A+#ifndef=20OPTION_UTILS_H=0A+#define=20OPTION_UTILS_H=0A+=0A= +#include=20"fe_utils/simple_list.h"=0A+#include=20"libpq-fe.h"=0A+=0A= +extern=20void=20expand_schema_name_patterns(PGconn=20*conn,=0A+=09=09=09= =09=09=09=09=09=09=09SimpleStringList=20*patterns,=0A+=09=09=09=09=09=09=09= =09=09=09SimpleOidList=20*oids,=0A+=09=09=09=09=09=09=09=09=09=09bool=20= strict_names);=0A+extern=20void=20= expand_foreign_server_name_patterns(PGconn=20*conn,=0A+=09=09=09=09=09=09= =09=09=09=09=09=09SimpleStringList=20*patterns,=0A+=09=09=09=09=09=09=09=09= =09=09=09=09SimpleOidList=20*oids);=0A+extern=20void=20= expand_table_name_patterns(PGconn=20*conn,=0A+=09=09=09=09=09=09=09=09=09= =20=20=20SimpleStringList=20*patterns,=0A+=09=09=09=09=09=09=09=09=09=20=20= =20SimpleOidList=20*oids,=0A+=09=09=09=09=09=09=09=09=09=20=20=20bool=20= strict_names);=0A+extern=20void=20expand_dbname_patterns(PGconn=20*conn,=20= SimpleStringList=20*patterns,=0A+=09=09=09=09=09=09=09=09=20=20=20= SimpleStringList=20*names);=0A+=0A+#endif=09=09=09=09=09=09=09/*=20= OPTION_UTILS_H=20*/=0A--=20=0A2.21.1=20(Apple=20Git-122.3)=0A=0A= --Apple-Mail=_8B07CFD0-2450-4CA2-BEE1-ACB2F7EEE33B Content-Disposition: attachment; filename=v32-0008-Normalizing-option_utils-interface.patch Content-Type: application/octet-stream; x-unix-mode=0644; name="v32-0008-Normalizing-option_utils-interface.patch" Content-Transfer-Encoding: quoted-printable =46rom=20521ccf1daff979b9beb5bd08f395217175d5f948=20Mon=20Sep=2017=20= 00:00:00=202001=0AFrom:=20Mark=20Dilger=20=0A= Date:=20Wed,=206=20Jan=202021=2014:37:44=20-0800=0ASubject:=20[PATCH=20= v32=208/9]=20Normalizing=20option_utils=20interface.=0A=0AThe=20= functions=20in=20option_utils=20were=20copied=20from=20pg_dump,=20mostly=20= preserving=0Athe=20function=20signatures.=20=20But=20the=20signatures=20= and=20corresponding=20functionality=0Awere=20originally=20written=20= based=20solely=20on=20pg_dump's=20needs,=20not=20with=20the=20goal=0Aof=20= creating=20a=20consistent=20interface.=20=20Fixing=20that.=0A---=0A=20= src/bin/pg_dump/pg_dump.c=20=20=20=20=20=20=20=20=20=20=20|=2058=20= +++++++++++++++++++------=0A=20src/bin/pg_dump/pg_dumpall.c=20=20=20=20=20= =20=20=20|=20=204=20+-=0A=20src/fe_utils/option_utils.c=20=20=20=20=20=20= =20=20=20|=2066=20++++++++++++++++++++---------=0A=20= src/fe_utils/string_utils.c=20=20=20=20=20=20=20=20=20|=2050=20= ++++++++++++++++++++++=0A=20src/include/fe_utils/option_utils.h=20|=2029=20= +++++++++----=0A=20src/include/fe_utils/string_utils.h=20|=20=206=20+++=0A= =206=20files=20changed,=20169=20insertions(+),=2044=20deletions(-)=0A=0A= diff=20--git=20a/src/bin/pg_dump/pg_dump.c=20b/src/bin/pg_dump/pg_dump.c=0A= index=20c334b9e829..5c446c0f24=20100644=0A---=20= a/src/bin/pg_dump/pg_dump.c=0A+++=20b/src/bin/pg_dump/pg_dump.c=0A@@=20= -125,6=20+125,17=20@@=20static=20SimpleOidList=20tabledata_exclude_oids=20= =3D=20{NULL,=20NULL};=0A=20static=20SimpleStringList=20= foreign_servers_include_patterns=20=3D=20{NULL,=20NULL};=0A=20static=20= SimpleOidList=20foreign_servers_include_oids=20=3D=20{NULL,=20NULL};=0A=20= =0A+/*=0A+=20*=20Cstring=20list=20of=20relkinds=20which=20qualify=20as=20= tables=20for=20our=20purposes=20when=0A+=20*=20processing=20table=20= inclusion=20or=20exclusion=20patterns.=0A+=20*/=0A+#define=20= TABLE_RELKIND_LIST=20CppAsString2(RELKIND_RELATION)=20",=20"=20\=0A+=09=09= =09=09=09=09=20=20=20CppAsString2(RELKIND_SEQUENCE)=20",=20"=20\=0A+=09=09= =09=09=09=09=20=20=20CppAsString2(RELKIND_VIEW)=20",=20"=20\=0A+=09=09=09= =09=09=09=20=20=20CppAsString2(RELKIND_MATVIEW)=20",=20"=20\=0A+=09=09=09= =09=09=09=20=20=20CppAsString2(RELKIND_FOREIGN_TABLE)=20",=20"=20\=0A+=09= =09=09=09=09=09=20=20=20CppAsString2(RELKIND_PARTITIONED_TABLE)=0A+=0A=20= static=20const=20CatalogId=20nilCatalogId=20=3D=20{0,=200};=0A=20=0A=20= /*=20override=20for=20standard=20extra_float_digits=20setting=20*/=0A@@=20= -791,6=20+802,7=20@@=20main(int=20argc,=20char=20**argv)=0A=20=09{=0A=20=09= =09expand_schema_name_patterns(GetConnection(fout),=0A=20=09=09=09=09=09=09= =09=09=09&schema_include_patterns,=0A+=09=09=09=09=09=09=09=09=09NULL,=0A= =20=09=09=09=09=09=09=09=09=09&schema_include_oids,=0A=20=09=09=09=09=09=09= =09=09=09strict_names);=0A=20=09=09if=20(schema_include_oids.head=20=3D=3D= =20NULL)=0A@@=20-798,6=20+810,7=20@@=20main(int=20argc,=20char=20**argv)=0A= =20=09}=0A=20=09expand_schema_name_patterns(GetConnection(fout),=0A=20=09= =09=09=09=09=09=09=09&schema_exclude_patterns,=0A+=09=09=09=09=09=09=09=09= NULL,=0A=20=09=09=09=09=09=09=09=09&schema_exclude_oids,=0A=20=09=09=09=09= =09=09=09=09false);=0A=20=09/*=20non-matching=20exclusion=20patterns=20= aren't=20an=20error=20*/=0A@@=20-805,26=20+818,43=20@@=20main(int=20= argc,=20char=20**argv)=0A=20=09/*=20Expand=20table=20selection=20= patterns=20into=20OID=20lists=20*/=0A=20=09if=20= (table_include_patterns.head=20!=3D=20NULL)=0A=20=09{=0A-=09=09= expand_table_name_patterns(GetConnection(fout),=0A-=09=09=09=09=09=09=09=09= =20=20=20&table_include_patterns,=0A-=09=09=09=09=09=09=09=09=20=20=20= &table_include_oids,=0A-=09=09=09=09=09=09=09=09=20=20=20strict_names);=0A= +=09=09expand_rel_name_patterns(GetConnection(fout),=0A+=09=09=09=09=09=09= =09=09=20&table_include_patterns,=0A+=09=09=09=09=09=09=09=09=20NULL,=0A= +=09=09=09=09=09=09=09=09=20NULL,=0A+=09=09=09=09=09=09=09=09=20= TABLE_RELKIND_LIST,=0A+=09=09=09=09=09=09=09=09=20AMTYPE_TABLE,=0A+=09=09= =09=09=09=09=09=09=20&table_include_oids,=0A+=09=09=09=09=09=09=09=09=20= strict_names,=0A+=09=09=09=09=09=09=09=09=20true);=0A=20=09=09if=20= (table_include_oids.head=20=3D=3D=20NULL)=0A=20=09=09=09fatal("no=20= matching=20tables=20were=20found");=0A=20=09}=0A-=09= expand_table_name_patterns(GetConnection(fout),=0A-=09=09=09=09=09=09=09=20= =20=20&table_exclude_patterns,=0A-=09=09=09=09=09=09=09=20=20=20= &table_exclude_oids,=0A-=09=09=09=09=09=09=09=20=20=20false);=0A-=0A-=09= expand_table_name_patterns(GetConnection(fout),=0A-=09=09=09=09=09=09=09=20= =20=20&tabledata_exclude_patterns,=0A-=09=09=09=09=09=09=09=20=20=20= &tabledata_exclude_oids,=0A-=09=09=09=09=09=09=09=20=20=20false);=0A+=09= expand_rel_name_patterns(GetConnection(fout),=0A+=09=09=09=09=09=09=09=20= &table_exclude_patterns,=0A+=09=09=09=09=09=09=09=20NULL,=0A+=09=09=09=09= =09=09=09=20NULL,=0A+=09=09=09=09=09=09=09=20TABLE_RELKIND_LIST,=0A+=09=09= =09=09=09=09=09=20AMTYPE_TABLE,=0A+=09=09=09=09=09=09=09=20= &table_exclude_oids,=0A+=09=09=09=09=09=09=09=20false,=0A+=09=09=09=09=09= =09=09=20true);=0A+=0A+=09expand_rel_name_patterns(GetConnection(fout),=0A= +=09=09=09=09=09=09=09=20&tabledata_exclude_patterns,=0A+=09=09=09=09=09=09= =09=20NULL,=0A+=09=09=09=09=09=09=09=20NULL,=0A+=09=09=09=09=09=09=09=20= TABLE_RELKIND_LIST,=0A+=09=09=09=09=09=09=09=20AMTYPE_TABLE,=0A+=09=09=09= =09=09=09=09=20&tabledata_exclude_oids,=0A+=09=09=09=09=09=09=09=20= false,=0A+=09=09=09=09=09=09=09=20true);=0A=20=0A=20=09= expand_foreign_server_name_patterns(GetConnection(fout),=0A=20=09=09=09=09= =09=09=09=09=09=09&foreign_servers_include_patterns,=0A-=09=09=09=09=09=09= =09=09=09=09&foreign_servers_include_oids);=0A+=09=09=09=09=09=09=09=09=09= =09NULL,=0A+=09=09=09=09=09=09=09=09=09=09&foreign_servers_include_oids,=0A= +=09=09=09=09=09=09=09=09=09=09true);=0A=20=0A=20=09/*=20non-matching=20= exclusion=20patterns=20aren't=20an=20error=20*/=0A=20=0Adiff=20--git=20= a/src/bin/pg_dump/pg_dumpall.c=20b/src/bin/pg_dump/pg_dumpall.c=0Aindex=20= 01db15dfda..2b3a4e3349=20100644=0A---=20a/src/bin/pg_dump/pg_dumpall.c=0A= +++=20b/src/bin/pg_dump/pg_dumpall.c=0A@@=20-471,8=20+471,8=20@@=20= main(int=20argc,=20char=20*argv[])=0A=20=09/*=0A=20=09=20*=20Get=20a=20= list=20of=20database=20names=20that=20match=20the=20exclude=20patterns=0A= =20=09=20*/=0A-=09expand_dbname_patterns(conn,=20= &database_exclude_patterns,=0A-=09=09=09=09=09=09=20=20=20= &database_exclude_names);=0A+=09expand_dbname_patterns(conn,=20= &database_exclude_patterns,=20NULL,=0A+=09=09=09=09=09=09=20=20=20= &database_exclude_names,=20false);=0A=20=0A=20=09/*=0A=20=09=20*=20Open=20= the=20output=20file=20if=20required,=20otherwise=20use=20stdout=0Adiff=20= --git=20a/src/fe_utils/option_utils.c=20b/src/fe_utils/option_utils.c=0A= index=207893df77aa..76ca456784=20100644=0A---=20= a/src/fe_utils/option_utils.c=0A+++=20b/src/fe_utils/option_utils.c=0A@@=20= -14,6=20+14,7=20@@=0A=20=20*/=0A=20#include=20"postgres_fe.h"=0A=20=0A= +#include=20"catalog/pg_am.h"=0A=20#include=20"catalog/pg_class.h"=0A=20= #include=20"common/connect.h"=0A=20#include=20"fe_utils/exit_utils.h"=0A= @@=20-30,7=20+31,8=20@@=0A=20=20*/=0A=20void=0A=20= expand_schema_name_patterns(PGconn=20*conn,=0A-=09=09=09=09=09=09=09= SimpleStringList=20*patterns,=0A+=09=09=09=09=09=09=09const=20= SimpleStringList=20*patterns,=0A+=09=09=09=09=09=09=09const=20= SimpleOidList=20*exclude_oids,=0A=20=09=09=09=09=09=09=09SimpleOidList=20= *oids,=0A=20=09=09=09=09=09=09=09bool=20strict_names)=0A=20{=0A@@=20= -55,6=20+57,7=20@@=20expand_schema_name_patterns(PGconn=20*conn,=0A=20=09= =09=09=09=09=09=09=20"SELECT=20oid=20FROM=20pg_catalog.pg_namespace=20= n\n");=0A=20=09=09processSQLNamePattern(conn,=20query,=20cell->val,=20= false,=0A=20=09=09=09=09=09=09=09=20=20false,=20NULL,=20"n.nspname",=20= NULL,=20NULL);=0A+=09=09exclude_filter(query,=20"n.oid",=20= exclude_oids);=0A=20=0A=20=09=09res=20=3D=20ExecuteSqlQuery(conn,=20= query->data,=20PGRES_TUPLES_OK);=0A=20=09=09if=20(strict_names=20&&=20= PQntuples(res)=20=3D=3D=200)=0A@@=20-78,8=20+81,10=20@@=20= expand_schema_name_patterns(PGconn=20*conn,=0A=20=20*/=0A=20void=0A=20= expand_foreign_server_name_patterns(PGconn=20*conn,=0A-=09=09=09=09=09=09= =09=09=09SimpleStringList=20*patterns,=0A-=09=09=09=09=09=09=09=09=09= SimpleOidList=20*oids)=0A+=09=09=09=09=09=09=09=09=09const=20= SimpleStringList=20*patterns,=0A+=09=09=09=09=09=09=09=09=09const=20= SimpleOidList=20*exclude_oids,=0A+=09=09=09=09=09=09=09=09=09= SimpleOidList=20*oids,=0A+=09=09=09=09=09=09=09=09=09bool=20= strict_names)=0A=20{=0A=20=09PQExpBuffer=20query;=0A=20=09PGresult=20=20=20= *res;=0A@@=20-102,9=20+107,10=20@@=20= expand_foreign_server_name_patterns(PGconn=20*conn,=0A=20=09=09=09=09=09=09= =09=20"SELECT=20oid=20FROM=20pg_catalog.pg_foreign_server=20s\n");=0A=20=09= =09processSQLNamePattern(conn,=20query,=20cell->val,=20false,=0A=20=09=09= =09=09=09=09=09=20=20false,=20NULL,=20"s.srvname",=20NULL,=20NULL);=0A+=09= =09exclude_filter(query,=20"s.oid",=20exclude_oids);=0A=20=0A=20=09=09= res=20=3D=20ExecuteSqlQuery(conn,=20query->data,=20PGRES_TUPLES_OK);=0A-=09= =09if=20(PQntuples(res)=20=3D=3D=200)=0A+=09=09if=20(strict_names=20&&=20= PQntuples(res)=20=3D=3D=200)=0A=20=09=09=09fatal("no=20matching=20= foreign=20servers=20were=20found=20for=20pattern=20\"%s\"",=20= cell->val);=0A=20=0A=20=09=09for=20(i=20=3D=200;=20i=20<=20= PQntuples(res);=20i++)=0A@@=20-118,18=20+124,32=20@@=20= expand_foreign_server_name_patterns(PGconn=20*conn,=0A=20}=0A=20=0A=20/*=0A= -=20*=20Find=20the=20OIDs=20of=20all=20tables=20matching=20the=20given=20= list=20of=20patterns,=0A-=20*=20and=20append=20them=20to=20the=20given=20= OID=20list.=0A+=20*=20Find=20the=20OIDs=20of=20all=20relations=20= matching=20the=20given=20list=20of=20patterns=0A+=20*=20and=20= restrictions,=20and=20append=20them=20to=20the=20given=20OID=20list.=0A=20= =20*/=0A=20void=0A-expand_table_name_patterns(PGconn=20*conn,=0A-=09=09=09= =09=09=09=20=20=20SimpleStringList=20*patterns,=20SimpleOidList=20*oids,=0A= -=09=09=09=09=09=09=20=20=20bool=20strict_names)=0A= +expand_rel_name_patterns(PGconn=20*conn,=0A+=09=09=09=09=09=09=20const=20= SimpleStringList=20*patterns,=0A+=09=09=09=09=09=09=20const=20= SimpleOidList=20*exclude_nsp_oids,=0A+=09=09=09=09=09=09=20const=20= SimpleOidList=20*exclude_oids,=0A+=09=09=09=09=09=09=20const=20char=20= *relkinds,=0A+=09=09=09=09=09=09=20char=20amtype,=0A+=09=09=09=09=09=09=20= SimpleOidList=20*oids,=0A+=09=09=09=09=09=09=20bool=20strict_names,=0A+=09= =09=09=09=09=09=20bool=20restrict_visible)=0A=20{=0A=20=09PQExpBuffer=20= query;=0A=20=09PGresult=20=20=20*res;=0A=20=09SimpleStringListCell=20= *cell;=0A=20=09int=09=09=09i;=0A+=09const=20char=20*visibility_rule;=0A+=0A= +=09Assert(amtype=20=3D=3D=20AMTYPE_TABLE=20||=20amtype=20=3D=3D=20= AMTYPE_INDEX);=0A+=0A+=09if=20(restrict_visible)=0A+=09=09= visibility_rule=20=3D=20"pg_catalog.pg_table_is_visible(c.oid)";=0A+=09= else=0A+=09=09visibility_rule=20=3D=20NULL;=0A=20=0A=20=09if=20= (patterns->head=20=3D=3D=20NULL)=0A=20=09=09return;=09=09=09=09=09/*=20= nothing=20to=20do=20*/=0A@@=20-154,20=20+174,22=20@@=20= expand_table_name_patterns(PGconn=20*conn,=0A=20=09=09=09=09=09=09=20=20= "\n=20=20=20=20=20LEFT=20JOIN=20pg_catalog.pg_namespace=20n"=0A=20=09=09=09= =09=09=09=20=20"\n=20=20=20=20=20ON=20n.oid=20OPERATOR(pg_catalog.=3D)=20= c.relnamespace"=0A=20=09=09=09=09=09=09=20=20"\nWHERE=20c.relkind=20= OPERATOR(pg_catalog.=3D)=20ANY"=0A-=09=09=09=09=09=09=20=20"\n=20=20=20=20= (array['%c',=20'%c',=20'%c',=20'%c',=20'%c',=20'%c'])\n",=0A-=09=09=09=09= =09=09=20=20RELKIND_RELATION,=20RELKIND_SEQUENCE,=20RELKIND_VIEW,=0A-=09=09= =09=09=09=09=20=20RELKIND_MATVIEW,=20RELKIND_FOREIGN_TABLE,=0A-=09=09=09=09= =09=09=20=20RELKIND_PARTITIONED_TABLE);=0A+=09=09=09=09=09=09=20=20"\n=20= =20=20=20(array[%s])\n",=20relkinds);=0A=20=09=09= processSQLNamePattern(conn,=20query,=20cell->val,=20true,=0A-=09=09=09=09= =09=09=09=20=20false,=20"n.nspname",=20"c.relname",=20NULL,=0A-=09=09=09=09= =09=09=09=20=20"pg_catalog.pg_table_is_visible(c.oid)");=0A+=09=09=09=09=09= =09=09=20=20false,=20"n.nspname",=20"c.relname",=20NULL,=20= visibility_rule);=0A+=09=09exclude_filter(query,=20"n.oid",=20= exclude_nsp_oids);=0A+=09=09exclude_filter(query,=20"c.oid",=20= exclude_oids);=0A=20=0A=20=09=09ExecuteSqlStatement(conn,=20"RESET=20= search_path");=0A=20=09=09res=20=3D=20ExecuteSqlQuery(conn,=20= query->data,=20PGRES_TUPLES_OK);=0A=20=09=09= PQclear(ExecuteSqlQueryForSingleRow(conn,=0A=20=09=09=09=09=09=09=09=09=09= =09=09ALWAYS_SECURE_SEARCH_PATH_SQL));=0A=20=09=09if=20(strict_names=20= &&=20PQntuples(res)=20=3D=3D=200)=0A-=09=09=09fatal("no=20matching=20= tables=20were=20found=20for=20pattern=20\"%s\"",=20cell->val);=0A+=09=09= {=0A+=09=09=09if=20(amtype=20=3D=3D=20AMTYPE_TABLE)=0A+=09=09=09=09= fatal("no=20matching=20tables=20were=20found=20for=20pattern=20\"%s\"",=20= cell->val);=0A+=09=09=09fatal("no=20matching=20indexes=20were=20found=20= for=20pattern=20\"%s\"",=20cell->val);=0A+=09=09}=0A=20=0A=20=09=09for=20= (i=20=3D=200;=20i=20<=20PQntuples(res);=20i++)=0A=20=09=09{=0A@@=20= -186,8=20+208,10=20@@=20expand_table_name_patterns(PGconn=20*conn,=0A=20=20= */=0A=20void=0A=20expand_dbname_patterns(PGconn=20*conn,=0A-=09=09=09=09=09= =20=20=20SimpleStringList=20*patterns,=0A-=09=09=09=09=09=20=20=20= SimpleStringList=20*names)=0A+=09=09=09=09=09=20=20=20const=20= SimpleStringList=20*patterns,=0A+=09=09=09=09=09=20=20=20const=20= SimpleOidList=20*exclude_oids,=0A+=09=09=09=09=09=20=20=20= SimpleStringList=20*names,=0A+=09=09=09=09=09=20=20=20bool=20= strict_names)=0A=20{=0A=20=09PQExpBuffer=20query;=0A=20=09PGresult=20=20=20= *res;=0A@@=20-206,12=20+230,16=20@@=20expand_dbname_patterns(PGconn=20= *conn,=0A=20=09for=20(SimpleStringListCell=20*cell=20=3D=20= patterns->head;=20cell;=20cell=20=3D=20cell->next)=0A=20=09{=0A=20=09=09= appendPQExpBufferStr(query,=0A-=09=09=09=09=09=09=09=20"SELECT=20datname=20= FROM=20pg_catalog.pg_database=20n\n");=0A+=09=09=09=09=09=09=09=20= "SELECT=20datname=20FROM=20pg_catalog.pg_database=20d\n");=0A=20=09=09= processSQLNamePattern(conn,=20query,=20cell->val,=20false,=0A=20=09=09=09= =09=09=09=09=20=20false,=20NULL,=20"datname",=20NULL,=20NULL);=0A+=09=09= exclude_filter(query,=20"d.oid",=20exclude_oids);=0A=20=0A=20=09=09= pg_log_info("executing=20%s",=20query->data);=0A=20=09=09res=20=3D=20= ExecuteSqlQuery(conn,=20query->data,=20PGRES_TUPLES_OK);=0A+=09=09if=20= (strict_names=20&&=20PQntuples(res)=20=3D=3D=200)=0A+=09=09=09fatal("no=20= matching=20databases=20were=20found=20for=20pattern=20\"%s\"",=20= cell->val);=0A+=0A=20=09=09for=20(int=20i=20=3D=200;=20i=20<=20= PQntuples(res);=20i++)=0A=20=09=09{=0A=20=09=09=09= simple_string_list_append(names,=20PQgetvalue(res,=20i,=200));=0Adiff=20= --git=20a/src/fe_utils/string_utils.c=20b/src/fe_utils/string_utils.c=0A= index=20a1a9d691d5..4e57a6f940=20100644=0A---=20= a/src/fe_utils/string_utils.c=0A+++=20b/src/fe_utils/string_utils.c=0A@@=20= -797,6=20+797,56=20@@=20appendReloptionsArray(PQExpBuffer=20buffer,=20= const=20char=20*reloptions,=0A=20=09return=20true;=0A=20}=0A=20=0A+/*=0A= +=20*=20Internal=20implementation=20of=20include_filter=20and=20= exclude_filter.=0A+=20*/=0A+static=20void=0A+apply_filter(PQExpBuffer=20= querybuf,=20const=20char=20*lval,=20const=20SimpleOidList=20*oids,=0A+=09= =09=09=20bool=20include)=0A+{=0A+=09const=20SimpleOidListCell=20*cell;=0A= +=09const=20char=20*comma;=0A+=0A+=09if=20(!oids=20||=20!oids->head)=0A+=09= =09return;=0A+=0A+=09if=20(include)=0A+=09=09appendPQExpBuffer(querybuf,=20= "\nAND=20%s=20OPERATOR(pg_catalog.=3D)=20ANY(array[",=20lval);=0A+=09= else=0A+=09=09appendPQExpBuffer(querybuf,=20"\nAND=20%s=20= OPERATOR(pg_catalog.!=3D)=20ALL(array[",=20lval);=0A+=0A+=09for=20(comma=20= =3D=20"",=20cell=20=3D=20oids->head;=20cell;=20comma=20=3D=20",=20",=20= cell=20=3D=20cell->next)=0A+=09=09appendPQExpBuffer(querybuf,=20"%s%u",=20= comma,=20cell->val);=0A+=09appendPQExpBuffer(querybuf,=20"]::OID[])");=0A= +}=0A+=0A+/*=0A+=20*=20Conditionally=20add=20a=20restriction=20to=20a=20= query=20such=20that=20lval=20must=20be=20an=20Oid=20in=0A+=20*=20the=20= given=20list=20of=20Oids,=20except=20that=20for=20a=20null=20or=20empty=20= oids=20list=20argument,=0A+=20*=20no=20filtering=20is=20done=20and=20we=20= return=20without=20having=20modified=20the=20query=20buffer.=0A+=20*=0A+=20= *=20The=20query=20argument=20must=20already=20have=20begun=20the=20WHERE=20= clause=20and=20must=20be=20in=20a=0A+=20*=20state=20where=20we=20can=20= append=20an=20AND=20clause.=20=20No=20checking=20of=20this=20requirement=20= is=0A+=20*=20done=20here.=0A+=20*=0A+=20*=20On=20return,=20the=20query=20= buffer=20will=20be=20extended=20with=20an=20AND=20clause=20that=20= filters=0A+=20*=20only=20those=20rows=20where=20the=20lval=20is=20an=20= Oid=20present=20in=20the=20given=20list=20of=20oids.=0A+=20*/=0A+void=0A= +include_filter(PQExpBuffer=20querybuf,=20const=20char=20*lval,=20const=20= SimpleOidList=20*oids)=0A+{=0A+=09apply_filter(querybuf,=20lval,=20oids,=20= true);=0A+}=0A+=0A+/*=0A+=20*=20Same=20as=20include_filter,=20above,=20= except=20that=20for=20a=20non-null,=20non-empty=20oids=0A+=20*=20list,=20= the=20lval=20is=20restricted=20to=20not=20be=20any=20of=20the=20values=20= in=20the=20list.=0A+=20*/=0A+void=0A+exclude_filter(PQExpBuffer=20= querybuf,=20const=20char=20*lval,=20const=20SimpleOidList=20*oids)=0A+{=0A= +=09apply_filter(querybuf,=20lval,=20oids,=20false);=0A+}=0A=20=0A=20/*=0A= =20=20*=20processSQLNamePattern=0Adiff=20--git=20= a/src/include/fe_utils/option_utils.h=20= b/src/include/fe_utils/option_utils.h=0Aindex=20d626a0bbc9..53da30754f=20= 100644=0A---=20a/src/include/fe_utils/option_utils.h=0A+++=20= b/src/include/fe_utils/option_utils.h=0A@@=20-19,17=20+19,28=20@@=0A=20= #include=20"libpq-fe.h"=0A=20=0A=20extern=20void=20= expand_schema_name_patterns(PGconn=20*conn,=0A-=09=09=09=09=09=09=09=09=09= =09SimpleStringList=20*patterns,=0A+=09=09=09=09=09=09=09=09=09=09const=20= SimpleStringList=20*patterns,=0A+=09=09=09=09=09=09=09=09=09=09const=20= SimpleOidList=20*exclude_oids,=0A=20=09=09=09=09=09=09=09=09=09=09= SimpleOidList=20*oids,=0A=20=09=09=09=09=09=09=09=09=09=09bool=20= strict_names);=0A=20extern=20void=20= expand_foreign_server_name_patterns(PGconn=20*conn,=0A-=09=09=09=09=09=09= =09=09=09=09=09=09SimpleStringList=20*patterns,=0A-=09=09=09=09=09=09=09=09= =09=09=09=09SimpleOidList=20*oids);=0A-extern=20void=20= expand_table_name_patterns(PGconn=20*conn,=0A-=09=09=09=09=09=09=09=09=09= =20=20=20SimpleStringList=20*patterns,=0A-=09=09=09=09=09=09=09=09=09=20=20= =20SimpleOidList=20*oids,=0A-=09=09=09=09=09=09=09=09=09=20=20=20bool=20= strict_names);=0A-extern=20void=20expand_dbname_patterns(PGconn=20*conn,=20= SimpleStringList=20*patterns,=0A-=09=09=09=09=09=09=09=09=20=20=20= SimpleStringList=20*names);=0A+=09=09=09=09=09=09=09=09=09=09=09=09const=20= SimpleStringList=20*patterns,=0A+=09=09=09=09=09=09=09=09=09=09=09=09= const=20SimpleOidList=20*exclude_oids,=0A+=09=09=09=09=09=09=09=09=09=09=09= =09SimpleOidList=20*oids,=0A+=09=09=09=09=09=09=09=09=09=09=09=09bool=20= strict_names);=0A+extern=20void=20expand_rel_name_patterns(PGconn=20= *conn,=0A+=09=09=09=09=09=09=09=09=09=20const=20SimpleStringList=20= *patterns,=0A+=09=09=09=09=09=09=09=09=09=20const=20SimpleOidList=20= *exclude_nsp_oids,=0A+=09=09=09=09=09=09=09=09=09=20const=20= SimpleOidList=20*exclude_oids,=0A+=09=09=09=09=09=09=09=09=09=20const=20= char=20*relkinds,=0A+=09=09=09=09=09=09=09=09=09=20char=20amtype,=0A+=09=09= =09=09=09=09=09=09=09=20SimpleOidList=20*oids,=0A+=09=09=09=09=09=09=09=09= =09=20bool=20strict_names,=0A+=09=09=09=09=09=09=09=09=09=20bool=20= restrict_visible);=0A+extern=20void=20expand_dbname_patterns(PGconn=20= *conn,=0A+=09=09=09=09=09=09=09=09=20=20=20const=20SimpleStringList=20= *patterns,=0A+=09=09=09=09=09=09=09=09=20=20=20const=20SimpleOidList=20= *exclude_oids,=0A+=09=09=09=09=09=09=09=09=20=20=20SimpleStringList=20= *names,=0A+=09=09=09=09=09=09=09=09=20=20=20bool=20strict_names);=0A=20=0A= =20#endif=09=09=09=09=09=09=09/*=20OPTION_UTILS_H=20*/=0Adiff=20--git=20= a/src/include/fe_utils/string_utils.h=20= b/src/include/fe_utils/string_utils.h=0Aindex=20c290c302f5..301a8eef4d=20= 100644=0A---=20a/src/include/fe_utils/string_utils.h=0A+++=20= b/src/include/fe_utils/string_utils.h=0A@@=20-16,6=20+16,7=20@@=0A=20= #ifndef=20STRING_UTILS_H=0A=20#define=20STRING_UTILS_H=0A=20=0A+#include=20= "fe_utils/simple_list.h"=0A=20#include=20"libpq-fe.h"=0A=20#include=20= "pqexpbuffer.h"=0A=20=0A@@=20-50,6=20+51,11=20@@=20extern=20bool=20= parsePGArray(const=20char=20*atext,=20char=20***itemarray,=20int=20= *nitems);=0A=20extern=20bool=20appendReloptionsArray(PQExpBuffer=20= buffer,=20const=20char=20*reloptions,=0A=20=09=09=09=09=09=09=09=09=20=20= const=20char=20*prefix,=20int=20encoding,=20bool=20std_strings);=0A=20=0A= +extern=20void=20include_filter(PQExpBuffer=20querybuf,=20const=20char=20= *lval,=0A+=09=09=09=09=09=09=20=20=20const=20SimpleOidList=20*oids);=0A= +extern=20void=20exclude_filter(PQExpBuffer=20querybuf,=20const=20char=20= *lval,=0A+=09=09=09=09=09=09=20=20=20const=20SimpleOidList=20*oids);=0A+=0A= =20extern=20bool=20processSQLNamePattern(PGconn=20*conn,=20PQExpBuffer=20= buf,=0A=20=09=09=09=09=09=09=09=09=20=20const=20char=20*pattern,=0A=20=09= =09=09=09=09=09=09=09=20=20bool=20have_where,=20bool=20force_escape,=0A= --=20=0A2.21.1=20(Apple=20Git-122.3)=0A=0A= --Apple-Mail=_8B07CFD0-2450-4CA2-BEE1-ACB2F7EEE33B Content-Disposition: attachment; filename=v32-0009-Adding-contrib-module-pg_amcheck.patch Content-Type: application/octet-stream; x-unix-mode=0644; name="v32-0009-Adding-contrib-module-pg_amcheck.patch" Content-Transfer-Encoding: quoted-printable =46rom=2001267b3ca3cf9651cd698342fe383fbe00028fde=20Mon=20Sep=2017=20= 00:00:00=202001=0AFrom:=20Mark=20Dilger=20=0A= Date:=20Wed,=206=20Jan=202021=2015:47:08=20-0800=0ASubject:=20[PATCH=20= v32=209/9]=20Adding=20contrib=20module=20pg_amcheck=0A=0AAdding=20new=20= contrib=20module=20pg_amcheck,=20which=20is=20a=20command=20line=0A= interface=20for=20running=20amcheck's=20verifications=20against=20tables=20= and=0Aindexes.=0A---=0A=20contrib/Makefile=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20|=20=20=201=20+=0A=20= contrib/pg_amcheck/.gitignore=20=20=20=20=20=20=20=20=20=20=20=20=20=20|=20= =20=203=20+=0A=20contrib/pg_amcheck/Makefile=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20|=20=2029=20+=0A=20contrib/pg_amcheck/pg_amcheck.c=20=20= =20=20=20=20=20=20=20=20=20=20|=20886=20+++++++++++++++++++++=0A=20= contrib/pg_amcheck/pg_amcheck.control=20=20=20=20=20=20|=20=20=205=20+=0A= =20contrib/pg_amcheck/t/001_basic.pl=20=20=20=20=20=20=20=20=20=20|=20=20= =209=20+=0A=20contrib/pg_amcheck/t/002_nonesuch.pl=20=20=20=20=20=20=20|=20= =2060=20++=0A=20contrib/pg_amcheck/t/003_check.pl=20=20=20=20=20=20=20=20= =20=20|=20248=20++++++=0A=20contrib/pg_amcheck/t/004_verify_heapam.pl=20=20= |=20496=20++++++++++++=0A=20contrib/pg_amcheck/t/005_opclass_damage.pl=20= |=20=2052=20++=0A=20doc/src/sgml/contrib.sgml=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20|=20=20=201=20+=0A=20doc/src/sgml/filelist.sgml=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20|=20=20=201=20+=0A=20= doc/src/sgml/pgamcheck.sgml=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= |=20493=20++++++++++++=0A=20src/fe_utils/query_utils.c=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20|=20=20=208=20+-=0A=20= src/tools/msvc/Mkvcbuild.pm=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= |=20=2010=20+-=0A=20src/tools/pgindent/typedefs.list=20=20=20=20=20=20=20= =20=20=20=20|=20=20=202=20+=0A=2016=20files=20changed,=202295=20= insertions(+),=209=20deletions(-)=0A=20create=20mode=20100644=20= contrib/pg_amcheck/.gitignore=0A=20create=20mode=20100644=20= contrib/pg_amcheck/Makefile=0A=20create=20mode=20100644=20= contrib/pg_amcheck/pg_amcheck.c=0A=20create=20mode=20100644=20= contrib/pg_amcheck/pg_amcheck.control=0A=20create=20mode=20100644=20= contrib/pg_amcheck/t/001_basic.pl=0A=20create=20mode=20100644=20= contrib/pg_amcheck/t/002_nonesuch.pl=0A=20create=20mode=20100644=20= contrib/pg_amcheck/t/003_check.pl=0A=20create=20mode=20100644=20= contrib/pg_amcheck/t/004_verify_heapam.pl=0A=20create=20mode=20100644=20= contrib/pg_amcheck/t/005_opclass_damage.pl=0A=20create=20mode=20100644=20= doc/src/sgml/pgamcheck.sgml=0A=0Adiff=20--git=20a/contrib/Makefile=20= b/contrib/Makefile=0Aindex=207a4866e338..0fd4125902=20100644=0A---=20= a/contrib/Makefile=0A+++=20b/contrib/Makefile=0A@@=20-30,6=20+30,7=20@@=20= SUBDIRS=20=3D=20\=0A=20=09=09old_snapshot=09\=0A=20=09=09pageinspect=09\=0A= =20=09=09passwordcheck=09\=0A+=09=09pg_amcheck=09\=0A=20=09=09= pg_buffercache=09\=0A=20=09=09pg_freespacemap=20\=0A=20=09=09pg_prewarm=09= \=0Adiff=20--git=20a/contrib/pg_amcheck/.gitignore=20= b/contrib/pg_amcheck/.gitignore=0Anew=20file=20mode=20100644=0Aindex=20= 0000000000..c21a14de31=0A---=20/dev/null=0A+++=20= b/contrib/pg_amcheck/.gitignore=0A@@=20-0,0=20+1,3=20@@=0A+pg_amcheck=0A= +=0A+/tmp_check/=0Adiff=20--git=20a/contrib/pg_amcheck/Makefile=20= b/contrib/pg_amcheck/Makefile=0Anew=20file=20mode=20100644=0Aindex=20= 0000000000..bc61ee7970=0A---=20/dev/null=0A+++=20= b/contrib/pg_amcheck/Makefile=0A@@=20-0,0=20+1,29=20@@=0A+#=20= contrib/pg_amcheck/Makefile=0A+=0A+PGFILEDESC=20=3D=20"pg_amcheck=20-=20= detects=20corruption=20within=20database=20relations"=0A+PGAPPICON=20=3D=20= win32=0A+=0A+PROGRAM=20=3D=20pg_amcheck=0A+OBJS=20=3D=20\=0A+=09= $(WIN32RES)=20\=0A+=09pg_amcheck.o=0A+=0A+REGRESS_OPTS=20+=3D=20= --load-extension=3Damcheck=20--load-extension=3Dpageinspect=0A= +EXTRA_INSTALL=20+=3D=20contrib/amcheck=20contrib/pageinspect=0A+=0A= +TAP_TESTS=20=3D=201=0A+=0A+PG_CPPFLAGS=20=3D=20-I$(libpq_srcdir)=0A= +PG_LIBS_INTERNAL=20=3D=20-L$(top_builddir)/src/fe_utils=20-lpgfeutils=20= $(libpq_pgport)=0A+=0A+ifdef=20USE_PGXS=0A+PG_CONFIG=20=3D=20pg_config=0A= +PGXS=20:=3D=20$(shell=20$(PG_CONFIG)=20--pgxs)=0A+include=20$(PGXS)=0A= +else=0A+SHLIB_PREREQS=20=3D=20submake-libpq=0A+subdir=20=3D=20= contrib/pg_amcheck=0A+top_builddir=20=3D=20../..=0A+include=20= $(top_builddir)/src/Makefile.global=0A+include=20= $(top_srcdir)/contrib/contrib-global.mk=0A+endif=0Adiff=20--git=20= a/contrib/pg_amcheck/pg_amcheck.c=20b/contrib/pg_amcheck/pg_amcheck.c=0A= new=20file=20mode=20100644=0Aindex=200000000000..97df1d1074=0A---=20= /dev/null=0A+++=20b/contrib/pg_amcheck/pg_amcheck.c=0A@@=20-0,0=20+1,886=20= @@=0A= +/*-----------------------------------------------------------------------= --=0A+=20*=0A+=20*=20pg_amcheck.c=0A+=20*=09=09Detects=20corruption=20= within=20database=20relations.=0A+=20*=0A+=20*=20Copyright=20(c)=20= 2017-2020,=20PostgreSQL=20Global=20Development=20Group=0A+=20*=0A+=20*=20= IDENTIFICATION=0A+=20*=09=20=20contrib/pg_amcheck/pg_amcheck.c=0A+=20*=0A= +=20= *-------------------------------------------------------------------------= =0A+=20*/=0A+#include=20"postgres_fe.h"=0A+=0A+#include=20= "catalog/pg_am.h"=0A+#include=20"catalog/pg_class.h"=0A+#include=20= "common/connect.h"=0A+#include=20"common/logging.h"=0A+#include=20= "common/string.h"=0A+#include=20"common/username.h"=0A+#include=20= "fe_utils/exit_utils.h"=0A+#include=20"fe_utils/option_utils.h"=0A= +#include=20"fe_utils/print.h"=0A+#include=20"fe_utils/query_utils.h"=0A= +#include=20"fe_utils/simple_list.h"=0A+#include=20= "fe_utils/string_utils.h"=0A+#include=20"getopt_long.h"=0A+#include=20= "pg_getopt.h"=0A+#include=20"storage/block.h"=0A+=0A+typedef=20struct=20= ConnectOptions=0A+{=0A+=09char=09=20=20=20*dbname;=0A+=09char=09=20=20=20= *host;=0A+=09char=09=20=20=20*port;=0A+=09char=09=20=20=20*username;=0A= +}=20ConnectOptions;=0A+=0A+typedef=20enum=20trivalue=0A+{=0A+=09= TRI_DEFAULT,=0A+=09TRI_NO,=0A+=09TRI_YES=0A+}=20trivalue;=0A+=0A+typedef=20= struct=0A+{=0A+=09bool=09=09notty;=09=09=09/*=20stdin=20or=20stdout=20is=20= not=20a=20tty=20(as=20determined=0A+=09=09=09=09=09=09=09=09=20*=20on=20= startup)=20*/=0A+=09trivalue=09getPassword;=09/*=20prompt=20for=20a=20= username=20and=20password=20*/=0A+=09const=20char=20*progname;=09=09/*=20= in=20case=20you=20renamed=20pg_amcheck=20*/=0A+=09bool=09=09= strict_names;=09/*=20The=20specified=20names/patterns=20should=20to=0A+=09= =09=09=09=09=09=09=09=20*=20match=20at=20least=20one=20entity=20*/=0A+=09= bool=09=09on_error_stop;=09/*=20The=20checking=20of=20each=20table=20= should=20stop=0A+=09=09=09=09=09=09=09=09=20*=20after=20the=20first=20= corrupt=20page=20is=20found.=20*/=0A+=09bool=09=09skip_frozen;=09/*=20Do=20= not=20check=20pages=20marked=20all=20frozen=20*/=0A+=09bool=09=09= skip_visible;=09/*=20Do=20not=20check=20pages=20marked=20all=20visible=20= */=0A+=09bool=09=09check_indexes;=09/*=20Check=20btree=20indexes=20*/=0A= +=09bool=09=09check_toast;=09/*=20Check=20associated=20toast=20tables=20= and=20indexes=20*/=0A+=09bool=09=09check_corrupt;=09/*=20Check=20indexes=20= even=20if=20table=20is=20corrupt=20*/=0A+=09bool=09=09heapallindexed;=20= /*=20Perform=20index=20to=20table=20reconciling=20checks=20*/=0A+=09bool=09= =09rootdescend;=09/*=20Perform=20index=20rootdescend=20checks=20*/=0A+=09= bool=09=09verbose;=0A+=09long=09=09startblock;=09=09/*=20Block=20number=20= where=20checking=20begins=20*/=0A+=09long=09=09endblock;=09=09/*=20Block=20= number=20where=20checking=20ends,=20inclusive=20*/=0A+}=20= AmCheckSettings;=0A+=0A+static=20AmCheckSettings=20settings;=0A+=0A+/*=20= Connection=20to=20backend=20*/=0A+static=20PGconn=20*conn;=0A+=0A+/*=0A+=20= *=20Object=20inclusion/exclusion=20lists=0A+=20*=0A+=20*=20The=20string=20= lists=20record=20the=20patterns=20given=20by=20command-line=20switches,=0A= +=20*=20which=20we=20then=20convert=20to=20lists=20of=20Oids=20of=20= matching=20objects.=0A+=20*/=0A+static=20SimpleStringList=20= schema_include_patterns=20=3D=20{NULL,=20NULL};=0A+static=20= SimpleOidList=20schema_include_oids=20=3D=20{NULL,=20NULL};=0A+static=20= SimpleStringList=20schema_exclude_patterns=20=3D=20{NULL,=20NULL};=0A= +static=20SimpleOidList=20schema_exclude_oids=20=3D=20{NULL,=20NULL};=0A= +=0A+static=20SimpleStringList=20table_include_patterns=20=3D=20{NULL,=20= NULL};=0A+static=20SimpleOidList=20table_include_oids=20=3D=20{NULL,=20= NULL};=0A+static=20SimpleStringList=20table_exclude_patterns=20=3D=20= {NULL,=20NULL};=0A+static=20SimpleOidList=20table_exclude_oids=20=3D=20= {NULL,=20NULL};=0A+=0A+static=20SimpleStringList=20= index_include_patterns=20=3D=20{NULL,=20NULL};=0A+static=20SimpleOidList=20= index_include_oids=20=3D=20{NULL,=20NULL};=0A+static=20SimpleStringList=20= index_exclude_patterns=20=3D=20{NULL,=20NULL};=0A+static=20SimpleOidList=20= index_exclude_oids=20=3D=20{NULL,=20NULL};=0A+=0A+/*=0A+=20*=20Cstring=20= list=20of=20relkinds=20which=20qualify=20as=20tables=20for=20our=20= purposes=20when=0A+=20*=20processing=20table=20inclusion=20or=20= exclusion=20patterns.=0A+=20*/=0A+#define=20TABLE_RELKIND_LIST=20= CppAsString2(RELKIND_RELATION)=20",=20"=20\=0A+=09=09=09=09=09=09=20=20=20= CppAsString2(RELKIND_MATVIEW)=20",=20"=20\=0A+=09=09=09=09=09=09=20=20=20= CppAsString2(RELKIND_PARTITIONED_TABLE)=0A+=0A+#define=20= INDEX_RELKIND_LIST=20CppAsString2(RELKIND_INDEX)=0A+=0A+/*=0A+=20*=20= List=20of=20main=20tables=20to=20be=20checked,=20compiled=20from=20above=20= lists,=20and=0A+=20*=20corresponding=20list=20of=20toast=20tables.=20=20= The=20lists=20should=20always=20be=0A+=20*=20the=20same=20length,=20with=20= InvalidOid=20in=20the=20toastlist=20for=20main=20relations=0A+=20*=20= without=20a=20corresponding=20toast=20relation.=0A+=20*/=0A+static=20= SimpleOidList=20mainlist=20=3D=20{NULL,=20NULL};=0A+static=20= SimpleOidList=20toastlist=20=3D=20{NULL,=20NULL};=0A+=0A+=0A+/*=0A+=20*=20= Functions=20for=20running=20the=20various=20corruption=20checks.=0A+=20= */=0A+static=20void=20check_tables(SimpleOidList=20*checklist);=0A= +static=20uint64=20check_table(Oid=20tbloid,=20long=20startblock,=20long=20= endblock,=0A+=09=09=09=09=09=09=20=20bool=20on_error_stop,=20bool=20= check_toast);=0A+static=20uint64=20check_indexes(Oid=20tbloid,=20const=20= SimpleOidList=20*include_oids,=0A+=09=09=09=09=09=09=09const=20= SimpleOidList=20*exclude_oids);=0A+static=20uint64=20check_index(const=20= char=20*idxoid,=20const=20char=20*idxname,=0A+=09=09=09=09=09=09=20=20= const=20char=20*tblname);=0A+=0A+/*=0A+=20*=20Functions=20implementing=20= standard=20command=20line=20behaviors.=0A+=20*/=0A+static=20void=20= parse_cli_options(int=20argc,=20char=20*argv[],=0A+=09=09=09=09=09=09=09=20= =20ConnectOptions=20*connOpts);=0A+static=20void=20usage(void);=0A= +static=20void=20showVersion(void);=0A+static=20void=20= NoticeProcessor(void=20*arg,=20const=20char=20*message);=0A+=0A+static=20= void=20get_table_check_list(const=20SimpleOidList=20*include_nsp,=0A+=09=09= =09=09=09=09=09=09=20const=20SimpleOidList=20*exclude_nsp,=0A+=09=09=09=09= =09=09=09=09=20const=20SimpleOidList=20*include_tbl,=0A+=09=09=09=09=09=09= =09=09=20const=20SimpleOidList=20*exclude_tbl);=0A+=0A+#define=20= EXIT_BADCONN=202=0A+=0A+int=0A+main(int=20argc,=20char=20**argv)=0A+{=0A= +=09ConnectOptions=20connOpts;=0A+=09bool=09=09have_password=20=3D=20= false;=0A+=09char=09=20=20=20*password=20=3D=20NULL;=0A+=09bool=09=09= new_pass;=0A+=0A+=09pg_logging_init(argv[0]);=0A+=09= set_pglocale_pgservice(argv[0],=20PG_TEXTDOMAIN("pg_amcheck"));=0A+=0A+=09= if=20(argc=20>=201)=0A+=09{=0A+=09=09if=20((strcmp(argv[1],=20"-?")=20=3D=3D= =200)=20||=0A+=09=09=09(argc=20=3D=3D=202=20&&=20(strcmp(argv[1],=20= "--help")=20=3D=3D=200)))=0A+=09=09{=0A+=09=09=09usage();=0A+=09=09=09= exit(EXIT_SUCCESS);=0A+=09=09}=0A+=09=09if=20(strcmp(argv[1],=20= "--version")=20=3D=3D=200=20||=20strcmp(argv[1],=20"-V")=20=3D=3D=200)=0A= +=09=09{=0A+=09=09=09showVersion();=0A+=09=09=09exit(EXIT_SUCCESS);=0A+=09= =09}=0A+=09}=0A+=0A+=09memset(&settings,=200,=20sizeof(settings));=0A+=09= settings.progname=20=3D=20get_progname(argv[0]);=0A+=0A+=09conn=20=3D=20= NULL;=0A+=09setDecimalLocale();=0A+=0A+=09settings.notty=20=3D=20= (!isatty(fileno(stdin))=20||=20!isatty(fileno(stdout)));=0A+=0A+=09= settings.getPassword=20=3D=20TRI_DEFAULT;=0A+=0A+=09settings.startblock=20= =3D=20-1;=0A+=09settings.endblock=20=3D=20-1;=0A+=0A+=09/*=0A+=09=20*=20= Default=20behaviors=20for=20user=20settable=20options.=20=20Note=20that=20= these=20default=0A+=09=20*=20to=20doing=20all=20the=20safe=20checks=20= and=20none=20of=20the=20unsafe=20ones,=20on=20the=20theory=0A+=09=20*=20= that=20if=20a=20user=20says=20"pg_amcheck=20mydb"=20without=20specifying=20= any=20additional=0A+=09=20*=20options,=20we=20should=20check=20= everything=20we=20know=20how=20to=20check=20without=0A+=09=20*=20risking=20= any=20backend=20aborts.=0A+=09=20*/=0A+=0A+=09settings.on_error_stop=20=3D= =20false;=0A+=09settings.skip_frozen=20=3D=20false;=0A+=09= settings.skip_visible=20=3D=20false;=0A+=0A+=09/*=20Index=20checking=20= options=20*/=0A+=09settings.check_indexes=20=3D=20true;=0A+=09= settings.check_corrupt=20=3D=20true;=0A+=09settings.heapallindexed=20=3D=20= false;=0A+=09settings.rootdescend=20=3D=20false;=0A+=0A+=09/*=0A+=09=20*=20= Reconciling=20toasted=20attributes=20from=20the=20main=20table=20against=20= the=20toast=0A+=09=20*=20table=20can=20crash=20the=20backend=20if=20the=20= toast=20table=20or=20index=20are=20corrupt.=20We=0A+=09=20*=20can=20= optionally=20check=20the=20toast=20table=20and=20then=20the=20toast=20= index=20prior=20to=0A+=09=20*=20checking=20the=20main=20table,=20but=20= if=20the=20toast=20table=20or=20index=20are=0A+=09=20*=20concurrently=20= corrupted=20after=20we=20conclude=20they=20are=20valid,=20the=20check=20= of=0A+=09=20*=20the=20main=20table=20can=20crash=20the=20backend.=20=20= The=20oneous=20is=20on=20any=20caller=20who=0A+=09=20*=20enables=20this=20= option=20to=20make=20certain=20the=20environment=20is=20sufficiently=0A+=09= =20*=20stable=20that=20concurrent=20corruptions=20of=20the=20toast=20is=20= not=20possible.=0A+=09=20*/=0A+=09settings.check_toast=20=3D=20false;=0A= +=0A+=09parse_cli_options(argc,=20argv,=20&connOpts);=0A+=0A+=09if=20= (settings.getPassword=20=3D=3D=20TRI_YES)=0A+=09{=0A+=09=09/*=0A+=09=09=20= *=20We=20can't=20be=20sure=20yet=20of=20the=20username=20that=20will=20= be=20used,=20so=20don't=0A+=09=09=20*=20offer=20a=20potentially=20wrong=20= one.=20=20Typical=20uses=20of=20this=20option=20are=0A+=09=09=20*=20= noninteractive=20anyway.=0A+=09=09=20*/=0A+=09=09password=20=3D=20= simple_prompt("Password:=20",=20false);=0A+=09=09have_password=20=3D=20= true;=0A+=09}=0A+=0A+=09/*=20loop=20until=20we=20have=20a=20password=20= if=20requested=20by=20backend=20*/=0A+=09do=0A+=09{=0A+#define=20= ARRAY_SIZE=098=0A+=09=09const=20char=20**keywords=20=3D=20= pg_malloc(ARRAY_SIZE=20*=20sizeof(*keywords));=0A+=09=09const=20char=20= **values=20=3D=20pg_malloc(ARRAY_SIZE=20*=20sizeof(*values));=0A+=0A+=09=09= keywords[0]=20=3D=20"host";=0A+=09=09values[0]=20=3D=20connOpts.host;=0A= +=09=09keywords[1]=20=3D=20"port";=0A+=09=09values[1]=20=3D=20= connOpts.port;=0A+=09=09keywords[2]=20=3D=20"user";=0A+=09=09values[2]=20= =3D=20connOpts.username;=0A+=09=09keywords[3]=20=3D=20"password";=0A+=09=09= values[3]=20=3D=20have_password=20?=20password=20:=20NULL;=0A+=09=09= keywords[4]=20=3D=20"dbname";=20/*=20see=20do_connect()=20*/=0A+=09=09if=20= (connOpts.dbname=20=3D=3D=20NULL)=0A+=09=09{=0A+=09=09=09if=20= (getenv("PGDATABASE"))=0A+=09=09=09=09values[4]=20=3D=20= getenv("PGDATABASE");=0A+=09=09=09else=20if=20(getenv("PGUSER"))=0A+=09=09= =09=09values[4]=20=3D=20getenv("PGUSER");=0A+=09=09=09else=0A+=09=09=09=09= values[4]=20=3D=20"postgres";=0A+=09=09}=0A+=09=09else=0A+=09=09=09= values[4]=20=3D=20connOpts.dbname;=0A+=09=09keywords[5]=20=3D=20= "fallback_application_name";=0A+=09=09values[5]=20=3D=20= settings.progname;=0A+=09=09keywords[6]=20=3D=20"client_encoding";=0A+=09= =09values[6]=20=3D=20(settings.notty=20||=0A+=09=09=09=09=09=20= getenv("PGCLIENTENCODING"))=20?=20NULL=20:=20"auto";=0A+=09=09= keywords[7]=20=3D=20NULL;=0A+=09=09values[7]=20=3D=20NULL;=0A+=0A+=09=09= new_pass=20=3D=20false;=0A+=09=09conn=20=3D=20= PQconnectdbParams(keywords,=20values,=20true);=0A+=09=09if=20(!conn)=0A+=09= =09=09fatal("could=20not=20connect=20to=20database=20%s:=20out=20of=20= memory",=20values[4]);=0A+=0A+=09=09free(keywords);=0A+=09=09= free(values);=0A+=0A+=09=09if=20(PQstatus(conn)=20=3D=3D=20= CONNECTION_BAD=20&&=0A+=09=09=09PQconnectionNeedsPassword(conn)=20&&=0A+=09= =09=09!have_password=20&&=0A+=09=09=09settings.getPassword=20!=3D=20= TRI_NO)=0A+=09=09{=0A+=09=09=09/*=0A+=09=09=09=20*=20Before=20closing=20= the=20old=20PGconn,=20extract=20the=20user=20name=20that=20was=0A+=09=09=09= =20*=20actually=20connected=20with.=0A+=09=09=09=20*/=0A+=09=09=09const=20= char=20*realusername=20=3D=20PQuser(conn);=0A+=09=09=09char=09=20=20=20= *password_prompt;=0A+=0A+=09=09=09if=20(realusername=20&&=20= realusername[0])=0A+=09=09=09=09password_prompt=20=3D=20= psprintf("Password=20for=20user=20%s:=20",=0A+=09=09=09=09=09=09=09=09=09= =09=20=20=20realusername);=0A+=09=09=09else=0A+=09=09=09=09= password_prompt=20=3D=20pg_strdup("Password:=20");=0A+=09=09=09= PQfinish(conn);=0A+=0A+=09=09=09password=20=3D=20= simple_prompt(password_prompt,=20false);=0A+=09=09=09= free(password_prompt);=0A+=09=09=09have_password=20=3D=20true;=0A+=09=09=09= new_pass=20=3D=20true;=0A+=09=09}=0A+=0A+=09=09if=20(!new_pass=20&&=20= PQstatus(conn)=20=3D=3D=20CONNECTION_BAD)=0A+=09=09{=0A+=09=09=09= pg_log_error("could=20not=20connect=20to=20database=20%s:=20%s",=0A+=09=09= =09=09=09=09=20values[4],=20PQerrorMessage(conn));=0A+=09=09=09= PQfinish(conn);=0A+=09=09=09exit(1);=0A+=09=09}=0A+=09}=20while=20= (new_pass);=0A+=0A+=09if=20(settings.verbose)=0A+=09=09= PQsetErrorVerbosity(conn,=20PQERRORS_VERBOSE);=0A+=0A+=09/*=0A+=09=20*=20= Expand=20schema,=20table,=20and=20index=20exclusion=20patterns,=20if=20= any.=20=20Note=20that=0A+=09=20*=20non-matching=20exclusion=20patterns=20= are=20not=20an=20error,=20even=20when=0A+=09=20*=20--strict-names=20was=20= specified.=0A+=09=20*/=0A+=09expand_schema_name_patterns(conn,=0A+=09=09=09= =09=09=09=09=09&schema_exclude_patterns,=0A+=09=09=09=09=09=09=09=09= NULL,=0A+=09=09=09=09=09=09=09=09&schema_exclude_oids,=0A+=09=09=09=09=09= =09=09=09false);=0A+=09expand_rel_name_patterns(conn,=0A+=09=09=09=09=09=09= =09=20&table_exclude_patterns,=0A+=09=09=09=09=09=09=09=20NULL,=0A+=09=09= =09=09=09=09=09=20NULL,=0A+=09=09=09=09=09=09=09=20TABLE_RELKIND_LIST,=0A= +=09=09=09=09=09=09=09=20AMTYPE_TABLE,=0A+=09=09=09=09=09=09=09=20= &table_exclude_oids,=0A+=09=09=09=09=09=09=09=20false,=0A+=09=09=09=09=09= =09=09=20false);=0A+=09expand_rel_name_patterns(conn,=0A+=09=09=09=09=09=09= =09=20&index_exclude_patterns,=0A+=09=09=09=09=09=09=09=20NULL,=0A+=09=09= =09=09=09=09=09=20NULL,=0A+=09=09=09=09=09=09=09=20INDEX_RELKIND_LIST,=0A= +=09=09=09=09=09=09=09=20AMTYPE_INDEX,=0A+=09=09=09=09=09=09=09=20= &index_exclude_oids,=0A+=09=09=09=09=09=09=09=20false,=0A+=09=09=09=09=09= =09=09=20false);=0A+=0A+=09/*=20Expand=20schema=20selection=20patterns=20= into=20Oid=20lists=20*/=0A+=09if=20(schema_include_patterns.head=20!=3D=20= NULL)=0A+=09{=0A+=09=09expand_schema_name_patterns(conn,=0A+=09=09=09=09=09= =09=09=09=09&schema_include_patterns,=0A+=09=09=09=09=09=09=09=09=09= &schema_exclude_oids,=0A+=09=09=09=09=09=09=09=09=09= &schema_include_oids,=0A+=09=09=09=09=09=09=09=09=09= settings.strict_names);=0A+=09=09if=20(schema_include_oids.head=20=3D=3D=20= NULL)=0A+=09=09=09fatal("no=20matching=20schemas=20were=20found");=0A+=09= }=0A+=0A+=09/*=20Expand=20table=20selection=20patterns=20into=20Oid=20= lists=20*/=0A+=09if=20(table_include_patterns.head=20!=3D=20NULL)=0A+=09= {=0A+=09=09expand_rel_name_patterns(conn,=0A+=09=09=09=09=09=09=09=09=20= &table_include_patterns,=0A+=09=09=09=09=09=09=09=09=20= &schema_exclude_oids,=0A+=09=09=09=09=09=09=09=09=20&table_exclude_oids,=0A= +=09=09=09=09=09=09=09=09=20TABLE_RELKIND_LIST,=0A+=09=09=09=09=09=09=09=09= =20AMTYPE_TABLE,=0A+=09=09=09=09=09=09=09=09=20&table_include_oids,=0A+=09= =09=09=09=09=09=09=09=20settings.strict_names,=0A+=09=09=09=09=09=09=09=09= =20false);=0A+=09=09if=20(table_include_oids.head=20=3D=3D=20NULL)=0A+=09= =09=09fatal("no=20matching=20tables=20were=20found");=0A+=09}=0A+=0A+=09= /*=20Expand=20index=20selection=20patterns=20into=20Oid=20lists=20*/=0A+=09= if=20(index_include_patterns.head=20!=3D=20NULL)=0A+=09{=0A+=09=09= expand_rel_name_patterns(conn,=0A+=09=09=09=09=09=09=09=09=20= &index_include_patterns,=0A+=09=09=09=09=09=09=09=09=20= &schema_exclude_oids,=0A+=09=09=09=09=09=09=09=09=20&index_exclude_oids,=0A= +=09=09=09=09=09=09=09=09=20INDEX_RELKIND_LIST,=0A+=09=09=09=09=09=09=09=09= =20AMTYPE_INDEX,=0A+=09=09=09=09=09=09=09=09=20&index_include_oids,=0A+=09= =09=09=09=09=09=09=09=20settings.strict_names,=0A+=09=09=09=09=09=09=09=09= =20false);=0A+=09=09if=20(index_include_oids.head=20=3D=3D=20NULL)=0A+=09= =09=09fatal("no=20matching=20indexes=20were=20found");=0A+=09}=0A+=0A+=09= /*=0A+=09=20*=20Compile=20list=20of=20all=20tables=20to=20be=20checked=20= based=20on=20namespace=20and=20table=0A+=09=20*=20includes=20and=20= excludes.=0A+=09=20*/=0A+=09get_table_check_list(&schema_include_oids,=20= &schema_exclude_oids,=0A+=09=09=09=09=09=09=20&table_include_oids,=20= &table_exclude_oids);=0A+=0A+=09PQsetNoticeProcessor(conn,=20= NoticeProcessor,=20NULL);=0A+=0A+=09if=20(settings.check_toast)=0A+=09=09= check_tables(&toastlist);=0A+=09check_tables(&mainlist);=0A+=0A+=09= return=200;=0A+}=0A+=0A+/*=0A+=20*=20Check=20each=20table=20from=20the=20= given=20checklist=20per=20the=20user=20specified=20options.=0A+=20*/=0A= +static=20void=0A+check_tables(SimpleOidList=20*checklist)=0A+{=0A+=09= const=20SimpleOidListCell=20*cell;=0A+=0A+=09for=20(cell=20=3D=20= checklist->head;=20cell;=20cell=20=3D=20cell->next)=0A+=09{=0A+=09=09= uint64=09=09corruptions=20=3D=200;=0A+=0A+=09=09if=20= (!OidIsValid(cell->val))=0A+=09=09=09continue;=0A+=0A+=09=09corruptions=20= =3D=20check_table(cell->val,=0A+=09=09=09=09=09=09=09=09=20=20= settings.startblock,=0A+=09=09=09=09=09=09=09=09=20=20settings.endblock,=0A= +=09=09=09=09=09=09=09=09=20=20settings.on_error_stop,=0A+=09=09=09=09=09= =09=09=09=20=20settings.check_toast);=0A+=0A+=09=09if=20= (settings.check_indexes)=0A+=09=09{=0A+=09=09=09/*=20Optionally=20skip=20= the=20index=20checks=20for=20a=20corrupt=20table.=20*/=0A+=09=09=09if=20= (corruptions=20&&=20!settings.check_corrupt)=0A+=09=09=09=09continue;=0A= +=0A+=09=09=09corruptions=20+=3D=20check_indexes(cell->val,=0A+=09=09=09=09= =09=09=09=09=09=09=20&index_include_oids,=0A+=09=09=09=09=09=09=09=09=09=09= =20&index_exclude_oids);=0A+=09=09}=0A+=09}=0A+}=0A+=0A+/*=0A+=20*=20= Checks=20the=20given=20table=20for=20corruption,=20returning=20the=20= number=20of=20corruptions=0A+=20*=20detected=20and=20printed=20to=20the=20= user.=0A+=20*/=0A+static=20uint64=0A+check_table(Oid=20tbloid,=20long=20= startblock,=20long=20endblock,=0A+=09=09=09bool=20on_error_stop,=20bool=20= check_toast)=0A+{=0A+=09PQExpBuffer=20querybuf;=0A+=09PGresult=20=20=20= *res;=0A+=09int=09=09=09i;=0A+=09char=09=20=20=20*skip;=0A+=09char=09=20=20= =20*toast;=0A+=09const=20char=20*stop;=0A+=09uint64=09=09corruption_cnt=20= =3D=200;=0A+=0A+=09if=20(settings.skip_frozen)=0A+=09=09skip=20=3D=20= pg_strdup("'all=20frozen'");=0A+=09else=20if=20(settings.skip_visible)=0A= +=09=09skip=20=3D=20pg_strdup("'all=20visible'");=0A+=09else=0A+=09=09= skip=20=3D=20pg_strdup("'none'");=0A+=09stop=20=3D=20on_error_stop=20?=20= "true"=20:=20"false";=0A+=09toast=20=3D=20check_toast=20?=20"true"=20:=20= "false";=0A+=0A+=09querybuf=20=3D=20createPQExpBuffer();=0A+=0A+=09= appendPQExpBuffer(querybuf,=0A+=09=09=09=09=09=20=20"SELECT=20c.relname,=20= v.blkno,=20v.offnum,=20v.attnum,=20v.msg=20"=0A+=09=09=09=09=09=20=20= "FROM=20public.verify_heapam("=0A+=09=09=09=09=09=20=20"relation=20:=3D=20= %u,=20"=0A+=09=09=09=09=09=20=20"on_error_stop=20:=3D=20%s,=20"=0A+=09=09= =09=09=09=20=20"skip=20:=3D=20%s,=20"=0A+=09=09=09=09=09=20=20= "check_toast=20:=3D=20%s,=20",=0A+=09=09=09=09=09=20=20tbloid,=20stop,=20= skip,=20toast);=0A+=09if=20(startblock=20<=200)=0A+=09=09= appendPQExpBuffer(querybuf,=20"startblock=20:=3D=20NULL,=20");=0A+=09= else=0A+=09=09appendPQExpBuffer(querybuf,=20"startblock=20:=3D=20%ld,=20= ",=20startblock);=0A+=0A+=09if=20(endblock=20<=200)=0A+=09=09= appendPQExpBuffer(querybuf,=20"endblock=20:=3D=20NULL");=0A+=09else=0A+=09= =09appendPQExpBuffer(querybuf,=20"endblock=20:=3D=20%ld",=20endblock);=0A= +=0A+=09appendPQExpBuffer(querybuf,=20")=20v,=20pg_catalog.pg_class=20c=20= "=0A+=09=09=09=09=09=20=20"WHERE=20c.oid=20=3D=20%u",=20tbloid);=0A+=0A+=09= res=20=3D=20PQexec(conn,=20querybuf->data);=0A+=09if=20= (PQresultStatus(res)=20=3D=3D=20PGRES_TUPLES_OK=20&&=20PQntuples(res)=20= >=200)=0A+=09{=0A+=09=09corruption_cnt=20+=3D=20PQntuples(res);=0A+=09=09= for=20(i=20=3D=200;=20i=20<=20PQntuples(res);=20i++)=0A+=09=09{=0A+=09=09= =09if=20(!PQgetisnull(res,=20i,=203))=0A+=09=09=09=09printf("relation=20= %s,=20block=20%s,=20offset=20%s,=20attribute=20%s\n=20=20=20=20%s\n",=0A= +=09=09=09=09=09=20=20=20PQgetvalue(res,=20i,=200),=09/*=20relname=20*/=0A= +=09=09=09=09=09=20=20=20PQgetvalue(res,=20i,=201),=09/*=20blkno=20*/=0A= +=09=09=09=09=09=20=20=20PQgetvalue(res,=20i,=202),=09/*=20offnum=20*/=0A= +=09=09=09=09=09=20=20=20PQgetvalue(res,=20i,=203),=09/*=20attnum=20*/=0A= +=09=09=09=09=09=20=20=20PQgetvalue(res,=20i,=204));=09/*=20msg=20*/=0A+=09= =09=09else=20if=20(!PQgetisnull(res,=20i,=202))=0A+=09=09=09=09= printf("relation=20%s,=20block=20%s,=20offset=20%s\n=20=20=20=20%s\n",=0A= +=09=09=09=09=09=20=20=20PQgetvalue(res,=20i,=200),=09/*=20relname=20*/=0A= +=09=09=09=09=09=20=20=20PQgetvalue(res,=20i,=201),=09/*=20blkno=20*/=0A= +=09=09=09=09=09=20=20=20PQgetvalue(res,=20i,=202),=09/*=20offnum=20*/=0A= +=09=09=09=09=09=20=20=20PQgetvalue(res,=20i,=204));=09/*=20msg=20*/=0A+=09= =09=09else=20if=20(!PQgetisnull(res,=20i,=201))=0A+=09=09=09=09= printf("relation=20%s,=20block=20%s\n=20=20=20=20%s\n",=0A+=09=09=09=09=09= =20=20=20PQgetvalue(res,=20i,=200),=09/*=20relname=20*/=0A+=09=09=09=09=09= =20=20=20PQgetvalue(res,=20i,=201),=09/*=20blkno=20*/=0A+=09=09=09=09=09=20= =20=20PQgetvalue(res,=20i,=204));=09/*=20msg=20*/=0A+=09=09=09else=20if=20= (!PQgetisnull(res,=20i,=200))=0A+=09=09=09=09printf("relation=20%s\n=20=20= =20=20%s\n",=0A+=09=09=09=09=09=20=20=20PQgetvalue(res,=20i,=200),=09/*=20= relname=20*/=0A+=09=09=09=09=09=20=20=20PQgetvalue(res,=20i,=204));=09/*=20= msg=20*/=0A+=09=09=09else=0A+=09=09=09=09printf("%s\n",=20= PQgetvalue(res,=20i,=204));=09/*=20msg=20*/=0A+=09=09}=0A+=09}=0A+=09= else=20if=20(PQresultStatus(res)=20!=3D=20PGRES_TUPLES_OK)=0A+=09{=0A+=09= =09corruption_cnt++;=0A+=09=09printf("relation=20with=20OID=20%u\n=20=20=20= =20%s\n",=20tbloid,=20PQerrorMessage(conn));=0A+=09}=0A+=0A+=09= PQclear(res);=0A+=09destroyPQExpBuffer(querybuf);=0A+=09return=20= corruption_cnt;=0A+}=0A+=0A+static=20uint64=0A+check_indexes(Oid=20= tbloid,=20const=20SimpleOidList=20*include_oids,=0A+=09=09=09=20=20const=20= SimpleOidList=20*exclude_oids)=0A+{=0A+=09PQExpBuffer=20querybuf;=0A+=09= PGresult=20=20=20*res;=0A+=09int=09=09=09i;=0A+=09uint64=09=09= corruption_cnt=20=3D=200;=0A+=0A+=09querybuf=20=3D=20= createPQExpBuffer();=0A+=09appendPQExpBuffer(querybuf,=0A+=09=09=09=09=09= =20=20"SELECT=20i.indexrelid,=20ci.relname,=20ct.relname"=0A+=09=09=09=09= =09=20=20"\nFROM=20pg_catalog.pg_index=20i,=20pg_catalog.pg_class=20ci,=20= "=0A+=09=09=09=09=09=20=20"pg_catalog.pg_class=20ct"=0A+=09=09=09=09=09=20= =20"\nWHERE=20i.indexrelid=20=3D=20ci.oid"=0A+=09=09=09=09=09=20=20"\n=20= =20=20=20AND=20i.indrelid=20=3D=20ct.oid"=0A+=09=09=09=09=09=20=20"\n=20=20= =20=20AND=20ci.relam=20=3D=20%u"=0A+=09=09=09=09=09=20=20"\n=20=20=20=20= AND=20i.indrelid=20=3D=20%u",=0A+=09=09=09=09=09=20=20BTREE_AM_OID,=20= tbloid);=0A+=09include_filter(querybuf,=20"i.indexrelid",=20= include_oids);=0A+=09exclude_filter(querybuf,=20"i.indexrelid",=20= exclude_oids);=0A+=0A+=09res=20=3D=20PQexec(conn,=20querybuf->data);=0A+=09= if=20(PQresultStatus(res)=20=3D=3D=20PGRES_TUPLES_OK)=0A+=09{=0A+=09=09= for=20(i=20=3D=200;=20i=20<=20PQntuples(res);=20i++)=0A+=09=09=09= corruption_cnt=20+=3D=20check_index(PQgetvalue(res,=20i,=200),=0A+=09=09=09= =09=09=09=09=09=09=09=20=20PQgetvalue(res,=20i,=201),=0A+=09=09=09=09=09=09= =09=09=09=09=20=20PQgetvalue(res,=20i,=202));=0A+=09}=0A+=09else=0A+=09{=0A= +=09=09corruption_cnt++;=0A+=09=09printf("%s\n",=20= PQerrorMessage(conn));=0A+=09}=0A+=0A+=09PQclear(res);=0A+=09= destroyPQExpBuffer(querybuf);=0A+=0A+=09return=20corruption_cnt;=0A+}=0A= +=0A+static=20uint64=0A+check_index(const=20char=20*idxoid,=20const=20= char=20*idxname,=20const=20char=20*tblname)=0A+{=0A+=09PQExpBuffer=20= querybuf;=0A+=09PGresult=20=20=20*res;=0A+=09uint64=09=09corruption_cnt=20= =3D=200;=0A+=0A+=09querybuf=20=3D=20createPQExpBuffer();=0A+=09= appendPQExpBuffer(querybuf,=0A+=09=09=09=09=09=20=20"SELECT=20= public.bt_index_parent_check('%s'::regclass,=20%s,=20%s)",=0A+=09=09=09=09= =09=20=20idxoid,=0A+=09=09=09=09=09=20=20settings.heapallindexed=20?=20= "true"=20:=20"false",=0A+=09=09=09=09=09=20=20settings.rootdescend=20?=20= "true"=20:=20"false");=0A+=09res=20=3D=20PQexec(conn,=20querybuf->data);=0A= +=09if=20(PQresultStatus(res)=20!=3D=20PGRES_TUPLES_OK)=0A+=09{=0A+=09=09= corruption_cnt++;=0A+=09=09printf("index=20check=20failed=20for=20index=20= %s=20of=20table=20%s:\n",=0A+=09=09=09=20=20=20idxname,=20tblname);=0A+=09= =09printf("%s",=20PQerrorMessage(conn));=0A+=09}=0A+=0A+=09PQclear(res);=0A= +=09destroyPQExpBuffer(querybuf);=0A+=0A+=09return=20corruption_cnt;=0A= +}=0A+=0A+static=20void=0A+parse_cli_options(int=20argc,=20char=20= *argv[],=20ConnectOptions=20*connOpts)=0A+{=0A+=09static=20struct=20= option=20long_options[]=20=3D=0A+=09{=0A+=09=09{"check-toast",=20= no_argument,=20NULL,=20'z'},=0A+=09=09{"dbname",=20required_argument,=20= NULL,=20'd'},=0A+=09=09{"endblock",=20required_argument,=20NULL,=20'e'},=0A= +=09=09{"exclude-index",=20required_argument,=20NULL,=20'I'},=0A+=09=09= {"exclude-schema",=20required_argument,=20NULL,=20'N'},=0A+=09=09= {"exclude-table",=20required_argument,=20NULL,=20'T'},=0A+=09=09= {"heapallindexed",=20no_argument,=20NULL,=20'a'},=0A+=09=09{"help",=20= optional_argument,=20NULL,=20'?'},=0A+=09=09{"host",=20= required_argument,=20NULL,=20'h'},=0A+=09=09{"index",=20= required_argument,=20NULL,=20'i'},=0A+=09=09{"no-password",=20= no_argument,=20NULL,=20'w'},=0A+=09=09{"on-error-stop",=20no_argument,=20= NULL,=20'o'},=0A+=09=09{"password",=20no_argument,=20NULL,=20'W'},=0A+=09= =09{"port",=20required_argument,=20NULL,=20'p'},=0A+=09=09= {"rootdescend",=20no_argument,=20NULL,=20'r'},=0A+=09=09{"schema",=20= required_argument,=20NULL,=20'n'},=0A+=09=09{"skip",=20= required_argument,=20NULL,=20'S'},=0A+=09=09{"skip-corrupt",=20= no_argument,=20NULL,=20'C'},=0A+=09=09{"skip-indexes",=20no_argument,=20= NULL,=20'X'},=0A+=09=09{"skip-toast",=20no_argument,=20NULL,=20'Z'},=0A+=09= =09{"startblock",=20required_argument,=20NULL,=20'b'},=0A+=09=09= {"strict-names",=20no_argument,=20NULL,=20's'},=0A+=09=09{"table",=20= required_argument,=20NULL,=20't'},=0A+=09=09{"toast-endblock",=20= required_argument,=20NULL,=20'E'},=0A+=09=09{"toast-startblock",=20= required_argument,=20NULL,=20'B'},=0A+=09=09{"username",=20= required_argument,=20NULL,=20'U'},=0A+=09=09{"verbose",=20no_argument,=20= NULL,=20'v'},=0A+=09=09{"version",=20no_argument,=20NULL,=20'V'},=0A+=09=09= {NULL,=200,=20NULL,=200}=0A+=09};=0A+=0A+=09int=09=09=09optindex;=0A+=09= int=09=09=09c;=0A+=0A+=09memset(connOpts,=200,=20sizeof=20*connOpts);=0A= +=0A+=09while=20((c=20=3D=20getopt_long(argc,=20argv,=20= "ab:Cd:e:h:i:I:n:N:op:rsS:t:T:U:vVwWXzZ?1",=0A+=09=09=09=09=09=09=09= long_options,=20&optindex))=20!=3D=20-1)=0A+=09{=0A+=09=09char=09=20=20=20= *endptr;=0A+=0A+=09=09switch=20(c)=0A+=09=09{=0A+=09=09=09case=20'a':=0A= +=09=09=09=09settings.heapallindexed=20=3D=20true;=0A+=09=09=09=09break;=0A= +=09=09=09case=20'b':=0A+=09=09=09=09settings.startblock=20=3D=20= strtol(optarg,=20&endptr,=2010);=0A+=09=09=09=09if=20(*endptr=20!=3D=20= '\0')=0A+=09=09=09=09=09fatal("relation=20starting=20block=20argument=20= contains=20garbage=20characters");=0A+=09=09=09=09if=20= (settings.startblock=20>=20(long)=20MaxBlockNumber)=0A+=09=09=09=09=09= fatal("relation=20starting=20block=20argument=20out=20of=20bounds");=0A+=09= =09=09=09break;=0A+=09=09=09case=20'C':=0A+=09=09=09=09= settings.check_corrupt=20=3D=20false;=0A+=09=09=09=09break;=0A+=09=09=09= case=20'd':=0A+=09=09=09=09connOpts->dbname=20=3D=20pg_strdup(optarg);=0A= +=09=09=09=09break;=0A+=09=09=09case=20'e':=0A+=09=09=09=09= settings.endblock=20=3D=20strtol(optarg,=20&endptr,=2010);=0A+=09=09=09=09= if=20(*endptr=20!=3D=20'\0')=0A+=09=09=09=09=09fatal("relation=20ending=20= block=20argument=20contains=20garbage=20characters");=0A+=09=09=09=09if=20= (settings.endblock=20>=20(long)=20MaxBlockNumber)=0A+=09=09=09=09=09= fatal("relation=20ending=20block=20argument=20out=20of=20bounds");=0A+=09= =09=09=09break;=0A+=09=09=09case=20'h':=0A+=09=09=09=09connOpts->host=20= =3D=20pg_strdup(optarg);=0A+=09=09=09=09break;=0A+=09=09=09case=20'i':=0A= +=09=09=09=09simple_string_list_append(&index_include_patterns,=20= optarg);=0A+=09=09=09=09break;=0A+=09=09=09case=20'I':=0A+=09=09=09=09= simple_string_list_append(&index_exclude_patterns,=20optarg);=0A+=09=09=09= =09break;=0A+=09=09=09case=20'n':=09=09=09/*=20include=20schema(s)=20*/=0A= +=09=09=09=09simple_string_list_append(&schema_include_patterns,=20= optarg);=0A+=09=09=09=09break;=0A+=09=09=09case=20'N':=09=09=09/*=20= exclude=20schema(s)=20*/=0A+=09=09=09=09= simple_string_list_append(&schema_exclude_patterns,=20optarg);=0A+=09=09=09= =09break;=0A+=09=09=09case=20'o':=0A+=09=09=09=09settings.on_error_stop=20= =3D=20true;=0A+=09=09=09=09break;=0A+=09=09=09case=20'p':=0A+=09=09=09=09= connOpts->port=20=3D=20pg_strdup(optarg);=0A+=09=09=09=09break;=0A+=09=09= =09case=20's':=0A+=09=09=09=09settings.strict_names=20=3D=20true;=0A+=09=09= =09=09break;=0A+=09=09=09case=20'S':=0A+=09=09=09=09if=20= (pg_strcasecmp(optarg,=20"all-visible")=20=3D=3D=200)=0A+=09=09=09=09{=0A= +=09=09=09=09=09settings.skip_visible=20=3D=20true;=0A+=09=09=09=09=09= settings.skip_frozen=20=3D=20false;=0A+=09=09=09=09}=0A+=09=09=09=09else=20= if=20(pg_strcasecmp(optarg,=20"all-frozen")=20=3D=3D=200)=0A+=09=09=09=09= {=0A+=09=09=09=09=09settings.skip_frozen=20=3D=20true;=0A+=09=09=09=09=09= settings.skip_visible=20=3D=20false;=0A+=09=09=09=09}=0A+=09=09=09=09= else=0A+=09=09=09=09{=0A+=09=09=09=09=09exit(EXIT_FAILURE);=0A+=09=09=09=09= =09pg_log_error("invalid=20skip=20option");=0A+=09=09=09=09}=0A+=09=09=09= =09break;=0A+=09=09=09case=20'r':=0A+=09=09=09=09settings.rootdescend=20= =3D=20true;=0A+=09=09=09=09break;=0A+=09=09=09case=20't':=09=09=09/*=20= include=20table(s)=20*/=0A+=09=09=09=09= simple_string_list_append(&table_include_patterns,=20optarg);=0A+=09=09=09= =09break;=0A+=09=09=09case=20'T':=09=09=09/*=20exclude=20table(s)=20*/=0A= +=09=09=09=09simple_string_list_append(&table_exclude_patterns,=20= optarg);=0A+=09=09=09=09break;=0A+=09=09=09case=20'U':=0A+=09=09=09=09= connOpts->username=20=3D=20pg_strdup(optarg);=0A+=09=09=09=09break;=0A+=09= =09=09case=20'V':=0A+=09=09=09=09showVersion();=0A+=09=09=09=09= exit(EXIT_SUCCESS);=0A+=09=09=09case=20'w':=0A+=09=09=09=09= settings.getPassword=20=3D=20TRI_NO;=0A+=09=09=09=09break;=0A+=09=09=09= case=20'W':=0A+=09=09=09=09settings.getPassword=20=3D=20TRI_YES;=0A+=09=09= =09=09break;=0A+=09=09=09case=20'X':=0A+=09=09=09=09= settings.check_indexes=20=3D=20false;=0A+=09=09=09=09break;=0A+=09=09=09= case=20'v':=0A+=09=09=09=09settings.verbose=20=3D=20true;=0A+=09=09=09=09= break;=0A+=09=09=09case=20'z':=0A+=09=09=09=09settings.check_toast=20=3D=20= true;=0A+=09=09=09=09break;=0A+=09=09=09case=20'Z':=0A+=09=09=09=09= settings.check_toast=20=3D=20false;=0A+=09=09=09=09break;=0A+=09=09=09= case=20'?':=0A+=09=09=09=09if=20(optind=20<=3D=20argc=20&&=0A+=09=09=09=09= =09strcmp(argv[optind=20-=201],=20"-?")=20=3D=3D=200)=0A+=09=09=09=09{=0A= +=09=09=09=09=09/*=20actual=20help=20option=20given=20*/=0A+=09=09=09=09=09= usage();=0A+=09=09=09=09=09exit(EXIT_SUCCESS);=0A+=09=09=09=09}=0A+=09=09= =09=09else=0A+=09=09=09=09{=0A+=09=09=09=09=09/*=20getopt=20error=20= (unknown=20option=20or=20missing=20argument)=20*/=0A+=09=09=09=09=09goto=20= unknown_option;=0A+=09=09=09=09}=0A+=09=09=09=09break;=0A+=09=09=09case=20= 1:=0A+=09=09=09=09{=0A+=09=09=09=09=09if=20(!optarg=20||=20= strcmp(optarg,=20"options")=20=3D=3D=200)=0A+=09=09=09=09=09=09usage();=0A= +=09=09=09=09=09else=0A+=09=09=09=09=09=09goto=20unknown_option;=0A+=0A+=09= =09=09=09=09exit(EXIT_SUCCESS);=0A+=09=09=09=09}=0A+=09=09=09=09break;=0A= +=09=09=09default:=0A+=09=09unknown_option:=0A+=09=09=09=09= fprintf(stderr,=20"Try=20\"%s=20--help\"=20for=20more=20information.\n",=0A= +=09=09=09=09=09=09settings.progname);=0A+=09=09=09=09= exit(EXIT_FAILURE);=0A+=09=09=09=09break;=0A+=09=09}=0A+=09}=0A+=0A+=09= /*=0A+=09=20*=20if=20we=20still=20have=20arguments,=20use=20it=20as=20= the=20database=20name=20and=20username=0A+=09=20*/=0A+=09while=20(argc=20= -=20optind=20>=3D=201)=0A+=09{=0A+=09=09if=20(!connOpts->dbname)=0A+=09=09= =09connOpts->dbname=20=3D=20argv[optind];=0A+=09=09else=20if=20= (!connOpts->username)=0A+=09=09=09connOpts->username=20=3D=20= argv[optind];=0A+=09=09else=0A+=09=09=09pg_log_warning("extra=20= command-line=20argument=20\"%s\"=20ignored",=0A+=09=09=09=09=09=09=20=20=20= argv[optind]);=0A+=0A+=09=09optind++;=0A+=09}=0A+=0A+=09if=20= (settings.endblock=20>=3D=200=20&&=20settings.endblock=20<=20= settings.startblock)=0A+=09=09fatal("relation=20ending=20block=20= argument=20precedes=20starting=20block=20argument");=0A+}=0A+=0A+/*=0A+=20= *=20usage=0A+=20*=0A+=20*=20print=20out=20command=20line=20arguments=0A+=20= */=0A+static=20void=0A+usage(void)=0A+{=0A+=09printf("pg_amcheck=20is=20= the=20PostgreSQL=20command=20line=20frontend=20for=20the=20amcheck=20= database=20corruption=20checker.\n");=0A+=09printf("\n");=0A+=09= printf("Usage:\n");=0A+=09printf("=20=20pg_amcheck=20[OPTION]...=20= [DBNAME=20[USERNAME]]\n");=0A+=09printf("\n");=0A+=09printf("General=20= options:\n");=0A+=09printf("=20=20-V,=20--version=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20output=20version=20information,=20then=20= exit\n");=0A+=09printf("=20=20-?,=20--help=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20show=20this=20help,=20then=20exit\n");=0A+=09= printf("=20=20-s,=20--strict-names=20=20=20=20=20=20=20=20=20=20=20= require=20include=20patterns=20to=20match=20at=20least=20one=20entity=20= each\n");=0A+=09printf("=20=20-o,=20--on-error-stop=20=20=20=20=20=20=20=20= =20=20stop=20checking=20at=20end=20of=20first=20corrupt=20page\n");=0A+=09= printf("=20=20-v,=20--verbose=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20output=20verbose=20messages\n");=0A+=09printf("\n");=0A+=09= printf("Schema=20checking=20options:\n");=0A+=09printf("=20=20-n,=20= --schema=3DPATTERN=20=20=20=20=20=20=20=20=20check=20relations=20in=20= the=20specified=20schema(s)=20only\n");=0A+=09printf("=20=20-N,=20= --exclude-schema=3DPATTERN=20do=20NOT=20check=20relations=20in=20the=20= specified=20schema(s)\n");=0A+=09printf("\n");=0A+=09printf("Table=20= checking=20options:\n");=0A+=09printf("=20=20-t,=20--table=3DPATTERN=20=20= =20=20=20=20=20=20=20=20check=20the=20specified=20table(s)=20only\n");=0A= +=09printf("=20=20-T,=20--exclude-table=3DPATTERN=20=20do=20NOT=20check=20= the=20specified=20table(s)\n");=0A+=09printf("=20=20-b,=20--startblock=20= =20=20=20=20=20=20=20=20=20=20=20=20begin=20checking=20table(s)=20at=20= the=20given=20starting=20block=20number\n");=0A+=09printf("=20=20-e,=20= --endblock=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20check=20table(s)=20= only=20up=20to=20the=20given=20ending=20block=20number\n");=0A+=09= printf("=20=20-S,=20--skip=3DOPTION=20=20=20=20=20=20=20=20=20=20=20=20= do=20NOT=20check=20\"all-frozen\"=20or=20\"all-visible\"=20blocks\n");=0A= +=09printf("\n");=0A+=09printf("TOAST=20table=20checking=20options:\n");=0A= +=09printf("=20=20-z,=20--check-toast=20=20=20=20=20=20=20=20=20=20=20=20= check=20associated=20toast=20tables=20and=20toast=20indexes\n");=0A+=09= printf("=20=20-Z,=20--skip-toast=20=20=20=20=20=20=20=20=20=20=20=20=20= do=20NOT=20check=20associated=20toast=20tables=20and=20toast=20= indexes\n");=0A+=09printf("\n");=0A+=09printf("Index=20checking=20= options:\n");=0A+=09printf("=20=20-X,=20--skip-indexes=20=20=20=20=20=20=20= =20=20=20=20do=20NOT=20check=20any=20btree=20indexes\n");=0A+=09printf("=20= =20-i,=20--index=3DPATTERN=20=20=20=20=20=20=20=20=20=20check=20the=20= specified=20index(es)=20only\n");=0A+=09printf("=20=20-I,=20= --exclude-index=3DPATTERN=20=20do=20NOT=20check=20the=20specified=20= index(es)\n");=0A+=09printf("=20=20-C,=20--skip-corrupt=20=20=20=20=20=20= =20=20=20=20=20do=20NOT=20check=20indexes=20if=20their=20associated=20= table=20is=20corrupt\n");=0A+=09printf("=20=20-a,=20--heapallindexed=20=20= =20=20=20=20=20=20=20check=20index=20tuples=20against=20the=20table=20= tuples\n");=0A+=09printf("=20=20-r,=20--rootdescend=20=20=20=20=20=20=20=20= =20=20=20=20search=20from=20the=20root=20page=20for=20each=20index=20= tuple\n");=0A+=09printf("\n");=0A+=09printf("Connection=20options:\n");=0A= +=09printf("=20=20-d,=20--dbname=3DDBNAME=20=20=20=20=20=20=20=20=20=20= database=20name=20to=20connect=20to\n");=0A+=09printf("=20=20-h,=20= --host=3DHOSTNAME=20=20=20=20=20=20=20=20=20=20database=20server=20host=20= or=20socket=20directory\n");=0A+=09printf("=20=20-p,=20--port=3DPORT=20=20= =20=20=20=20=20=20=20=20=20=20=20=20database=20server=20port\n");=0A+=09= printf("=20=20-U,=20--username=3DUSERNAME=20=20=20=20=20=20database=20= user=20name\n");=0A+=09printf("=20=20-w,=20--no-password=20=20=20=20=20=20= =20=20=20=20=20=20never=20prompt=20for=20password\n");=0A+=09printf("=20=20= -W,=20--password=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20force=20= password=20prompt=20(should=20happen=20automatically)\n");=0A+=09= printf("\n");=0A+=09printf("Report=20bugs=20to=20<%s>.\n",=20= PACKAGE_BUGREPORT);=0A+=09printf("%s=20home=20page:=20<%s>\n",=20= PACKAGE_NAME,=20PACKAGE_URL);=0A+}=0A+=0A+static=20void=0A= +showVersion(void)=0A+{=0A+=09puts("pg_amcheck=20(PostgreSQL)=20"=20= PG_VERSION);=0A+}=0A+=0A+/*=0A+=20*=20for=20backend=20Notice=20messages=20= (INFO,=20WARNING,=20etc)=0A+=20*/=0A+static=20void=0A= +NoticeProcessor(void=20*arg,=20const=20char=20*message)=0A+{=0A+=09= (void)=20arg;=09=09=09=09=09/*=20not=20used=20*/=0A+=09pg_log_info("%s",=20= message);=0A+}=0A+=0A+static=20void=0A+get_table_check_list(const=20= SimpleOidList=20*include_nsp,=20const=20SimpleOidList=20*exclude_nsp,=0A= +=09=09=09=09=09=20const=20SimpleOidList=20*include_tbl,=20const=20= SimpleOidList=20*exclude_tbl)=0A+{=0A+=09PQExpBuffer=20querybuf;=0A+=09= PGresult=20=20=20*res;=0A+=09int=09=09=09i;=0A+=0A+=09querybuf=20=3D=20= createPQExpBuffer();=0A+=0A+=09appendPQExpBuffer(querybuf,=0A+=09=09=09=09= =09=20=20"SELECT=20c.oid,=20c.reltoastrelid"=0A+=09=09=09=09=09=20=20= "\nFROM=20pg_catalog.pg_class=20c,=20pg_catalog.pg_namespace=20n"=0A+=09=09= =09=09=09=20=20"\nWHERE=20n.oid=20OPERATOR(pg_catalog.=3D)=20= c.relnamespace"=0A+=09=09=09=09=09=20=20"\n=09AND=20c.relkind=20= OPERATOR(pg_catalog.=3D)=20ANY(ARRAY[%s])\n",=0A+=09=09=09=09=09=20=20= TABLE_RELKIND_LIST);=0A+=09include_filter(querybuf,=20"n.oid",=20= include_nsp);=0A+=09exclude_filter(querybuf,=20"n.oid",=20exclude_nsp);=0A= +=09include_filter(querybuf,=20"c.oid",=20include_tbl);=0A+=09= exclude_filter(querybuf,=20"c.oid",=20exclude_tbl);=0A+=0A+=09res=20=3D=20= ExecuteSqlQuery(conn,=20querybuf->data,=20PGRES_TUPLES_OK);=0A+=09for=20= (i=20=3D=200;=20i=20<=20PQntuples(res);=20i++)=0A+=09{=0A+=09=09= simple_oid_list_append(&mainlist,=20atooid(PQgetvalue(res,=20i,=200)));=0A= +=09=09simple_oid_list_append(&toastlist,=20atooid(PQgetvalue(res,=20i,=20= 1)));=0A+=09}=0A+=0A+=09PQclear(res);=0A+=09= destroyPQExpBuffer(querybuf);=0A+}=0Adiff=20--git=20= a/contrib/pg_amcheck/pg_amcheck.control=20= b/contrib/pg_amcheck/pg_amcheck.control=0Anew=20file=20mode=20100644=0A= index=200000000000..395f368101=0A---=20/dev/null=0A+++=20= b/contrib/pg_amcheck/pg_amcheck.control=0A@@=20-0,0=20+1,5=20@@=0A+#=20= pg_amcheck=20extension=0A+comment=20=3D=20'command-line=20tool=20for=20= verifying=20relation=20integrity'=0A+default_version=20=3D=20'1.3'=0A= +module_pathname=20=3D=20'$libdir/pg_amcheck'=0A+relocatable=20=3D=20= true=0Adiff=20--git=20a/contrib/pg_amcheck/t/001_basic.pl=20= b/contrib/pg_amcheck/t/001_basic.pl=0Anew=20file=20mode=20100644=0Aindex=20= 0000000000..dfa0ae9e06=0A---=20/dev/null=0A+++=20= b/contrib/pg_amcheck/t/001_basic.pl=0A@@=20-0,0=20+1,9=20@@=0A+use=20= strict;=0A+use=20warnings;=0A+=0A+use=20TestLib;=0A+use=20Test::More=20= tests=20=3D>=208;=0A+=0A+program_help_ok('pg_amcheck');=0A= +program_version_ok('pg_amcheck');=0A= +program_options_handling_ok('pg_amcheck');=0Adiff=20--git=20= a/contrib/pg_amcheck/t/002_nonesuch.pl=20= b/contrib/pg_amcheck/t/002_nonesuch.pl=0Anew=20file=20mode=20100644=0A= index=200000000000..189f05ef0a=0A---=20/dev/null=0A+++=20= b/contrib/pg_amcheck/t/002_nonesuch.pl=0A@@=20-0,0=20+1,60=20@@=0A+use=20= strict;=0A+use=20warnings;=0A+=0A+use=20PostgresNode;=0A+use=20TestLib;=0A= +use=20Test::More=20tests=20=3D>=2014;=0A+=0A+#=20Test=20set-up=0A+my=20= ($node,=20$port);=0A+$node=20=3D=20get_new_node('test');=0A+$node->init;=0A= +$node->start;=0A+$port=20=3D=20$node->port;=0A+=0A+#=20Load=20the=20= amcheck=20extension,=20upon=20which=20pg_amcheck=20depends=0A= +$node->safe_psql('postgres',=20q(CREATE=20EXTENSION=20amcheck));=0A+=0A= +#########################################=0A+#=20Test=20connecting=20to=20= a=20non-existent=20database=0A+=0A+command_fails_like(=0A+=09[=20= 'pg_amcheck',=20'-p',=20"$port",=20'qqq'=20],=0A+=09qr/\Qpg_amcheck:=20= error:=20could=20not=20connect=20to=20database=20qqq:=20FATAL:=20=20= database=20"qqq"=20does=20not=20exist\E/,=0A+=09'connecting=20to=20a=20= non-existent=20database');=0A+=0A= +#########################################=0A+#=20Test=20connecting=20= with=20a=20non-existent=20user=0A+=0A+command_fails_like(=0A+=09[=20= 'pg_amcheck',=20'-p',=20"$port",=20'-U=3Dno_such_user',=20'postgres'=20= ],=0A+=09qr/\Qpg_amcheck:=20error:=20could=20not=20connect=20to=20= database=20postgres:=20FATAL:=20=20role=20"=3Dno_such_user"=20does=20not=20= exist\E/,=0A+=09'connecting=20with=20a=20non-existent=20user');=0A+=0A= +#########################################=0A+#=20Test=20checking=20a=20= non-existent=20schema,=20table,=20and=20patterns=20with=20--strict-names=0A= +=0A+command_fails_like(=0A+=09[=20'pg_amcheck',=20'-p',=20"$port",=20= '-n',=20'nonexistent'=20],=0A+=09qr/\Qpg_amcheck:=20error:=20no=20= matching=20schemas=20were=20found\E/,=0A+=09'checking=20a=20non-existent=20= schema');=0A+=0A+command_fails_like(=0A+=09[=20'pg_amcheck',=20'-p',=20= "$port",=20'-t',=20'nonexistent'=20],=0A+=09qr/\Qpg_amcheck:=20error:=20= no=20matching=20tables=20were=20found\E/,=0A+=09'checking=20a=20= non-existent=20table');=0A+=0A+command_fails_like(=0A+=09[=20= 'pg_amcheck',=20'-p',=20"$port",=20'--strict-names',=20'-n',=20= 'nonexistent*'=20],=0A+=09qr/\Qpg_amcheck:=20error:=20no=20matching=20= schemas=20were=20found=20for=20pattern\E/,=0A+=09'no=20matching=20= schemas');=0A+=0A+command_fails_like(=0A+=09[=20'pg_amcheck',=20'-p',=20= "$port",=20'--strict-names',=20'-t',=20'nonexistent*'=20],=0A+=09= qr/\Qpg_amcheck:=20error:=20no=20matching=20tables=20were=20found=20for=20= pattern\E/,=0A+=09'no=20matching=20tables');=0A+=0A+command_fails_like(=0A= +=09[=20'pg_amcheck',=20'-p',=20"$port",=20'--strict-names',=20'-i',=20= 'nonexistent*'=20],=0A+=09qr/\Qpg_amcheck:=20error:=20no=20matching=20= indexes=20were=20found=20for=20pattern\E/,=0A+=09'no=20matching=20= indexes');=0Adiff=20--git=20a/contrib/pg_amcheck/t/003_check.pl=20= b/contrib/pg_amcheck/t/003_check.pl=0Anew=20file=20mode=20100644=0Aindex=20= 0000000000..30bbbdeddd=0A---=20/dev/null=0A+++=20= b/contrib/pg_amcheck/t/003_check.pl=0A@@=20-0,0=20+1,248=20@@=0A+use=20= strict;=0A+use=20warnings;=0A+=0A+use=20PostgresNode;=0A+use=20TestLib;=0A= +use=20Test::More=20tests=20=3D>=2045;=0A+=0A+my=20($node,=20$port);=0A+=0A= +#=20Returns=20the=20filesystem=20path=20for=20the=20named=20relation.=0A= +#=0A+#=20Assumes=20the=20test=20node=20is=20running=0A+sub=20= relation_filepath($)=0A+{=0A+=09my=20($relname)=20=3D=20@_;=0A+=0A+=09my=20= $pgdata=20=3D=20$node->data_dir;=0A+=09my=20$rel=20=3D=20= $node->safe_psql('postgres',=0A+=09=09=09=09=09=09=09=20=20=20qq(SELECT=20= pg_relation_filepath('$relname')));=0A+=09die=20"path=20not=20found=20= for=20relation=20$relname"=20unless=20defined=20$rel;=0A+=09return=20= "$pgdata/$rel";=0A+}=0A+=0A+#=20Stops=20the=20test=20node,=20corrupts=20= the=20first=20page=20of=20the=20named=20relation,=20and=0A+#=20restarts=20= the=20node.=0A+#=0A+#=20Assumes=20the=20node=20is=20running.=0A+sub=20= corrupt_first_page($)=0A+{=0A+=09my=20($relname)=20=3D=20@_;=0A+=09my=20= $relpath=20=3D=20relation_filepath($relname);=0A+=0A+=09$node->stop;=0A+=09= my=20$fh;=0A+=09open($fh,=20'+<',=20$relpath);=0A+=09binmode=20$fh;=0A+=09= seek($fh,=2032,=200);=0A+=09syswrite($fh,=20'\x77\x77\x77\x77',=20500);=0A= +=09close($fh);=0A+=09$node->start;=0A+}=0A+=0A+#=20Stops=20the=20test=20= node,=20unlinks=20the=20file=20from=20the=20filesystem=20that=20backs=20= the=0A+#=20relation,=20and=20restarts=20the=20node.=0A+#=0A+#=20Assumes=20= the=20test=20node=20is=20running=0A+sub=20remove_relation_file($)=0A+{=0A= +=09my=20($relname)=20=3D=20@_;=0A+=09my=20$relpath=20=3D=20= relation_filepath($relname);=0A+=0A+=09$node->stop();=0A+=09= unlink($relpath);=0A+=09$node->start;=0A+}=0A+=0A+#=20Test=20set-up=0A= +$node=20=3D=20get_new_node('test');=0A+$node->init;=0A+$node->start;=0A= +$port=20=3D=20$node->port;=0A+=0A+#=20Load=20the=20amcheck=20extension,=20= upon=20which=20pg_amcheck=20depends=0A+$node->safe_psql('postgres',=20= q(CREATE=20EXTENSION=20amcheck));=0A+=0A+#=20Create=20schemas=20and=20= tables=20for=20checking=20pg_amcheck's=20include=0A+#=20and=20exclude=20= schema=20and=20table=20command=20line=20options=0A= +$node->safe_psql('postgres',=20q(=0A+--=20We'll=20corrupt=20all=20= indexes=20in=20s1=0A+CREATE=20SCHEMA=20s1;=0A+CREATE=20TABLE=20s1.t1=20= (a=20TEXT);=0A+CREATE=20TABLE=20s1.t2=20(a=20TEXT);=0A+CREATE=20INDEX=20= i1=20ON=20s1.t1(a);=0A+CREATE=20INDEX=20i2=20ON=20s1.t2(a);=0A+INSERT=20= INTO=20s1.t1=20(a)=20(SELECT=20gs::TEXT=20FROM=20= generate_series(1,10000)=20AS=20gs);=0A+INSERT=20INTO=20s1.t2=20(a)=20= (SELECT=20gs::TEXT=20FROM=20generate_series(1,10000)=20AS=20gs);=0A+=0A= +--=20We'll=20corrupt=20all=20tables=20in=20s2=0A+CREATE=20SCHEMA=20s2;=0A= +CREATE=20TABLE=20s2.t1=20(a=20TEXT);=0A+CREATE=20TABLE=20s2.t2=20(a=20= TEXT);=0A+CREATE=20INDEX=20i1=20ON=20s2.t1(a);=0A+CREATE=20INDEX=20i2=20= ON=20s2.t2(a);=0A+INSERT=20INTO=20s2.t1=20(a)=20(SELECT=20gs::TEXT=20= FROM=20generate_series(1,10000)=20AS=20gs);=0A+INSERT=20INTO=20s2.t2=20= (a)=20(SELECT=20gs::TEXT=20FROM=20generate_series(1,10000)=20AS=20gs);=0A= +=0A+--=20We'll=20corrupt=20all=20tables=20and=20indexes=20in=20s3=0A= +CREATE=20SCHEMA=20s3;=0A+CREATE=20TABLE=20s3.t1=20(a=20TEXT);=0A+CREATE=20= TABLE=20s3.t2=20(a=20TEXT);=0A+CREATE=20INDEX=20i1=20ON=20s3.t1(a);=0A= +CREATE=20INDEX=20i2=20ON=20s3.t2(a);=0A+INSERT=20INTO=20s3.t1=20(a)=20= (SELECT=20gs::TEXT=20FROM=20generate_series(1,10000)=20AS=20gs);=0A= +INSERT=20INTO=20s3.t2=20(a)=20(SELECT=20gs::TEXT=20FROM=20= generate_series(1,10000)=20AS=20gs);=0A+=0A+--=20We'll=20leave=20= everything=20in=20s4=20uncorrupted=0A+CREATE=20SCHEMA=20s4;=0A+CREATE=20= TABLE=20s4.t1=20(a=20TEXT);=0A+CREATE=20TABLE=20s4.t2=20(a=20TEXT);=0A= +CREATE=20INDEX=20i1=20ON=20s4.t1(a);=0A+CREATE=20INDEX=20i2=20ON=20= s4.t2(a);=0A+INSERT=20INTO=20s4.t1=20(a)=20(SELECT=20gs::TEXT=20FROM=20= generate_series(1,10000)=20AS=20gs);=0A+INSERT=20INTO=20s4.t2=20(a)=20= (SELECT=20gs::TEXT=20FROM=20generate_series(1,10000)=20AS=20gs);=0A+));=0A= +=0A+#=20Corrupt=20indexes=20in=20schema=20"s1"=0A= +remove_relation_file('s1.i1');=0A+corrupt_first_page('s1.i2');=0A+=0A+#=20= Corrupt=20tables=20in=20schema=20"s2"=0A+remove_relation_file('s2.t1');=0A= +corrupt_first_page('s2.t2');=0A+=0A+#=20Corrupt=20tables=20and=20= indexes=20in=20schema=20"s3"=0A+remove_relation_file('s3.i1');=0A= +corrupt_first_page('s3.i2');=0A+remove_relation_file('s3.t1');=0A= +corrupt_first_page('s3.t2');=0A+=0A+#=20Leave=20schema=20"s4"=20alone=0A= +=0A+=0A+#=20The=20pg_amcheck=20command=20itself=20should=20return=20a=20= success=20exit=20status,=20even=0A+#=20though=20tables=20and=20indexes=20= are=20corrupt.=20=20An=20error=20code=20returned=20would=20mean=20the=0A= +#=20pg_amcheck=20command=20itself=20failed,=20for=20example=20because=20= a=20connection=20to=20the=0A+#=20database=20could=20not=20be=20= established.=0A+#=0A+#=20For=20these=20checks,=20we're=20ignoring=20any=20= corruption=20reported=20and=20focusing=0A+#=20exclusively=20on=20the=20= exit=20code=20from=20pg_amcheck.=0A+#=0A+$node->command_ok(=0A+=09[=20= 'pg_amcheck',=20'-p',=20$port,=20'postgres'=20],=0A+=09'pg_amcheck=20all=20= schemas=20and=20tables');=0A+=0A+$node->command_ok(=0A+=09[=20= 'pg_amcheck',=20'-X',=20'-p',=20$port,=20'postgres'=20],=0A+=09= 'pg_amcheck=20all=20schemas,=20tables=20and=20indexes');=0A+=0A= +$node->command_ok(=0A+=09[=20'pg_amcheck',=20'-X',=20'-p',=20$port,=20= 'postgres',=20'-n',=20's1'=20],=0A+=09'pg_amcheck=20all=20objects=20in=20= schema=20s1');=0A+=0A+$node->command_ok(=0A+=09[=20'pg_amcheck',=20'-X',=20= '-p',=20$port,=20'postgres',=20'-n',=20's*',=20'-t',=20't1'=20],=0A+=09= 'pg_amcheck=20all=20tables=20named=20t1=20and=20their=20indexes');=0A+=0A= +$node->command_ok(=0A+=09[=20'pg_amcheck',=20'-p',=20$port,=20= 'postgres',=20'-T',=20't1'=20],=0A+=09'pg_amcheck=20all=20tables=20not=20= named=20t1');=0A+=0A+$node->command_ok(=0A+=09[=20'pg_amcheck',=20'-p',=20= $port,=20'postgres',=20'-N',=20's1',=20'-T',=20't1'=20],=0A+=09= 'pg_amcheck=20all=20tables=20not=20named=20t1=20nor=20in=20schema=20= s1');=0A+=0A+#=20Scans=20of=20indexes=20in=20s1=20should=20detect=20the=20= specific=20corruption=20that=20we=20created=0A+#=20above.=20=20For=20= missing=20relation=20forks,=20we=20know=20what=20the=20error=20message=20= looks=0A+#=20like.=20=20For=20corrupted=20index=20pages,=20the=20error=20= might=20vary=20depending=20on=20how=20the=0A+#=20page=20was=20formatted=20= on=20disk,=20including=20variations=20due=20to=20alignment=20differences=0A= +#=20between=20platforms,=20so=20we=20accept=20any=20non-empty=20error=20= message.=0A+#=0A+$node->command_like(=0A+=09[=20'pg_amcheck',=20'-p',=20= $port,=20'postgres',=20'-n',=20's1',=20'-i',=20'i1'=20],=0A+=09qr/index=20= "i1"=20lacks=20a=20main=20relation=20fork/,=0A+=09'pg_amcheck=20index=20= s1.i1=20reports=20missing=20main=20relation=20fork');=0A+=0A= +$node->command_like(=0A+=09[=20'pg_amcheck',=20'-p',=20$port,=20= 'postgres',=20'-n',=20's1',=20'-i',=20'i2'=20],=0A+=09qr/.+/,=09=09=09#=20= Any=20non-empty=20error=20message=20is=20acceptable=0A+=09'pg_amcheck=20= index=20s1.s2=20reports=20index=20corruption');=0A+=0A+=0A+#=20In=20= schema=20s3,=20the=20tables=20and=20indexes=20are=20both=20corrupt.=20=20= Ordinarily,=20checking=0A+#=20of=20indexes=20will=20not=20be=20performed=20= for=20corrupt=20tables,=20but=20the=20--check-corrupt=0A+#=20option=20= (-c)=20forces=20the=20indexes=20to=20also=20be=20checked.=0A+#=0A= +$node->command_like(=0A+=09[=20'pg_amcheck',=20'-p',=20$port,=20= 'postgres',=20'-n',=20's3',=20'-i',=20'i1'=20],=0A+=09qr/index=20"i1"=20= lacks=20a=20main=20relation=20fork/,=0A+=09'pg_amcheck=20index=20s3.i1=20= reports=20missing=20main=20relation=20fork');=0A+=0A= +$node->command_like(=0A+=09[=20'pg_amcheck',=20'-p',=20$port,=20= 'postgres',=20'-n',=20's3',=20'-i',=20'i2'=20],=0A+=09qr/.+/,=09=09=09#=20= Any=20non-empty=20error=20message=20is=20acceptable=0A+=09'pg_amcheck=20= index=20s3.s2=20reports=20index=20corruption');=0A+=0A+=0A+#=20Check=20= that=20'-x'=20and=20'-X'=20work=20as=20expected.=20=20Since=20only=20= index=20corruption=0A+#=20(and=20not=20table=20corruption)=20exists=20in=20= s1,=20'-X'=20should=20give=20no=20errors,=20and=0A+#=20'-x'=20should=20= give=20errors=20about=20index=20corruption.=0A+#=0A+$node->command_like(=0A= +=09[=20'pg_amcheck',=20'-p',=20$port,=20'postgres',=20'-n',=20's1'=20],=0A= +=09qr/.+/,=09=09=09#=20Any=20non-empty=20error=20message=20is=20= acceptable=0A+=09'pg_amcheck=20over=20tables=20and=20indexes=20in=20= schema=20s1=20reports=20corruption');=0A+=0A+$node->command_like(=0A+=09= [=20'pg_amcheck',=20'-X',=20'-p',=20$port,=20'postgres',=20'-n',=20's1'=20= ],=0A+=09qr/^$/,=09=09=09#=20Empty=0A+=09'pg_amcheck=20over=20only=20= tables=20in=20schema=20s1=20reports=20no=20corruption');=0A+=0A+=0A+#=20= Check=20that=20table=20corruption=20is=20reported=20as=20expected,=20= with=20or=20without=0A+#=20index=20checking=0A+#=0A+$node->command_like(=0A= +=09[=20'pg_amcheck',=20'-p',=20$port,=20'postgres',=20'-n',=20's2'=20],=0A= +=09qr/could=20not=20open=20file/,=0A+=09'pg_amcheck=20over=20tables=20= in=20schema=20s2=20reports=20table=20corruption');=0A+=0A= +$node->command_like(=0A+=09[=20'pg_amcheck',=20'-X',=20'-p',=20$port,=20= 'postgres',=20'-n',=20's2'=20],=0A+=09qr/could=20not=20open=20file/,=0A+=09= 'pg_amcheck=20over=20tables=20and=20indexes=20in=20schema=20s2=20reports=20= table=20corruption');=0A+=0A+#=20Check=20that=20no=20corruption=20is=20= reported=20in=20schema=20s4=0A+$node->command_like(=0A+=09[=20= 'pg_amcheck',=20'-X',=20'-p',=20$port,=20'postgres',=20'-n',=20's4'=20],=0A= +=09qr/^$/,=09=09=09#=20Empty=0A+=09'pg_amcheck=20over=20schema=20s4=20= reports=20no=20corruption');=0A+=0A+#=20Check=20that=20no=20corruption=20= is=20reported=20if=20we=20exclude=20corrupt=20schemas=0A= +$node->command_like(=0A+=09[=20'pg_amcheck',=20'-X',=20'-p',=20$port,=20= 'postgres',=20'-N',=20's1',=20'-N',=20's2',=20'-N',=20's3'=20],=0A+=09= qr/^$/,=09=09=09#=20Empty=0A+=09'pg_amcheck=20excluding=20corrupt=20= schemas=20reports=20no=20corruption');=0A+=0A+#=20Check=20that=20no=20= corruption=20is=20reported=20if=20we=20exclude=20corrupt=20tables=0A= +$node->command_like(=0A+=09[=20'pg_amcheck',=20'-X',=20'-p',=20$port,=20= 'postgres',=20'-T',=20't1',=20'-T',=20't2'=20],=0A+=09qr/^$/,=09=09=09#=20= Empty=0A+=09'pg_amcheck=20excluding=20corrupt=20tables=20reports=20no=20= corruption');=0A+=0A+#=20Check=20errors=20about=20bad=20block=20range=20= command=20line=20arguments.=20=20We=20use=20schema=20s4=0A+#=20to=20= avoid=20getting=20messages=20about=20corrupt=20tables=20or=20indexes.=0A= +command_fails_like(=0A+=09[=20'pg_amcheck',=20'-p',=20$port,=20= 'postgres',=20'-n',=20's4',=20'-b',=20'junk'=20],=0A+=09qr/\Qpg_amcheck:=20= error:=20relation=20starting=20block=20argument=20contains=20garbage=20= characters\E/,=0A+=09'pg_amcheck=20rejects=20garbage=20startblock');=0A+=0A= +command_fails_like(=0A+=09[=20'pg_amcheck',=20'-p',=20$port,=20= 'postgres',=20'-n',=20's4',=20'-e',=20'1234junk'=20],=0A+=09= qr/\Qpg_amcheck:=20error:=20relation=20ending=20block=20argument=20= contains=20garbage=20characters\E/,=0A+=09'pg_amcheck=20rejects=20= garbage=20endblock');=0A+=0A+command_fails_like(=0A+=09[=20'pg_amcheck',=20= '-p',=20$port,=20'postgres',=20'-n',=20's4',=20'-b',=20'5',=20'-e',=20= '4'=20],=0A+=09qr/\Qpg_amcheck:=20error:=20relation=20ending=20block=20= argument=20precedes=20starting=20block=20argument\E/,=0A+=09'pg_amcheck=20= rejects=20invalid=20block=20range');=0Adiff=20--git=20= a/contrib/pg_amcheck/t/004_verify_heapam.pl=20= b/contrib/pg_amcheck/t/004_verify_heapam.pl=0Anew=20file=20mode=20100644=0A= index=200000000000..271eca7da6=0A---=20/dev/null=0A+++=20= b/contrib/pg_amcheck/t/004_verify_heapam.pl=0A@@=20-0,0=20+1,496=20@@=0A= +use=20strict;=0A+use=20warnings;=0A+=0A+use=20PostgresNode;=0A+use=20= TestLib;=0A+=0A+use=20Test::More=20tests=20=3D>=2022;=0A+=0A+#=20This=20= regression=20test=20demonstrates=20that=20the=20pg_amcheck=20binary=20= supplied=20with=0A+#=20the=20pg_amcheck=20contrib=20module=20correctly=20= identifies=20specific=20kinds=20of=0A+#=20corruption=20within=20pages.=20= =20To=20test=20this,=20we=20need=20a=20mechanism=20to=20create=20corrupt=0A= +#=20pages=20with=20predictable,=20repeatable=20corruption.=20=20The=20= postgres=20backend=20cannot=0A+#=20be=20expected=20to=20help=20us=20with=20= this,=20as=20its=20design=20is=20not=20consistent=20with=20the=0A+#=20= goal=20of=20intentionally=20corrupting=20pages.=0A+#=0A+#=20Instead,=20= we=20create=20a=20table=20to=20corrupt,=20and=20with=20careful=20= consideration=20of=20how=0A+#=20postgresql=20lays=20out=20heap=20pages,=20= we=20seek=20to=20offsets=20within=20the=20page=20and=0A+#=20overwrite=20= deliberately=20chosen=20bytes=20with=20specific=20values=20calculated=20= to=0A+#=20corrupt=20the=20page=20in=20expected=20ways.=20=20We=20then=20= verify=20that=20pg_amcheck=20reports=0A+#=20the=20corruption,=20and=20= that=20it=20runs=20without=20crashing.=20=20Note=20that=20the=20backend=0A= +#=20cannot=20simply=20be=20started=20to=20run=20queries=20against=20the=20= corrupt=20table,=20as=20the=0A+#=20backend=20will=20crash,=20at=20least=20= for=20some=20of=20the=20corruption=20types=20we=20generate.=0A+#=0A+#=20= Autovacuum=20potentially=20touching=20the=20table=20in=20the=20= background=20makes=20the=20exact=0A+#=20behavior=20of=20this=20test=20= harder=20to=20reason=20about.=20=20We=20turn=20it=20off=20to=20keep=20= things=0A+#=20simpler.=20=20We=20use=20a=20"belt=20and=20suspenders"=20= approach,=20turning=20it=20off=20for=20the=0A+#=20system=20generally=20= in=20postgresql.conf,=20and=20turning=20it=20off=20specifically=20for=20= the=0A+#=20test=20table.=0A+#=0A+#=20This=20test=20depends=20on=20the=20= table=20being=20written=20to=20the=20heap=20file=20exactly=20as=20we=0A= +#=20expect=20it=20to=20be,=20so=20we=20take=20care=20to=20arrange=20the=20= columns=20of=20the=20table,=20and=0A+#=20insert=20rows=20of=20the=20= table,=20that=20give=20predictable=20sizes=20and=20locations=20within=0A= +#=20the=20table=20page.=0A+#=0A+#=20The=20HeapTupleHeaderData=20has=20= 23=20bytes=20of=20fixed=20size=20fields=20before=20the=20variable=0A+#=20= length=20t_bits[]=20array.=20=20We=20have=20exactly=203=20columns=20in=20= the=20table,=20so=20natts=20=3D=203,=0A+#=20t_bits=20is=201=20byte=20= long,=20and=20t_hoff=20=3D=20MAXALIGN(23=20+=201)=20=3D=2024.=0A+#=0A+#=20= We're=20not=20too=20fussy=20about=20which=20datatypes=20we=20use=20for=20= the=20test,=20but=20we=20do=20care=0A+#=20about=20some=20specific=20= properties.=20=20We'd=20like=20to=20test=20both=20fixed=20size=20and=0A= +#=20varlena=20types.=20=20We'd=20like=20some=20varlena=20data=20inline=20= and=20some=20toasted.=20=20And=0A+#=20we'd=20like=20the=20layout=20of=20= the=20table=20such=20that=20the=20datums=20land=20at=20predictable=0A+#=20= offsets=20within=20the=20tuple.=20=20We=20choose=20a=20structure=20= without=20padding=20on=20all=0A+#=20supported=20architectures:=0A+#=0A+#=20= =09a=20BIGINT=0A+#=09b=20TEXT=0A+#=09c=20TEXT=0A+#=0A+#=20We=20always=20= insert=20a=207-ascii=20character=20string=20into=20field=20'b',=20which=20= with=20a=0A+#=201-byte=20varlena=20header=20gives=20an=208=20byte=20= inline=20value.=20=20We=20always=20insert=20a=20long=0A+#=20text=20= string=20in=20field=20'c',=20long=20enough=20to=20force=20toast=20= storage.=0A+#=0A+#=20We=20choose=20to=20read=20and=20write=20binary=20= copies=20of=20our=20table's=20tuples,=20using=20perl's=0A+#=20pack()=20= and=20unpack()=20functions.=20=20Perl=20uses=20a=20packing=20code=20= system=20in=20which:=0A+#=0A+#=09L=20=3D=20"Unsigned=2032-bit=20Long",=0A= +#=09S=20=3D=20"Unsigned=2016-bit=20Short",=0A+#=09C=20=3D=20"Unsigned=20= 8-bit=20Octet",=0A+#=09c=20=3D=20"signed=208-bit=20octet",=0A+#=09q=20=3D=20= "signed=2064-bit=20quadword"=0A+#=0A+#=20Each=20tuple=20in=20our=20table=20= has=20a=20layout=20as=20follows:=0A+#=0A+#=20=20=20=20xx=20xx=20xx=20xx=20= =20=20=20=20=20=20=20=20=20=20=20t_xmin:=20xxxx=09=09offset=20=3D=200=09=09= L=0A+#=20=20=20=20xx=20xx=20xx=20xx=20=20=20=20=20=20=20=20=20=20=20=20= t_xmax:=20xxxx=09=09offset=20=3D=204=09=09L=0A+#=20=20=20=20xx=20xx=20xx=20= xx=20=20=20=20=20=20=20=20=20=20t_field3:=20xxxx=09=09offset=20=3D=208=09= =09L=0A+#=20=20=20=20xx=20xx=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20bi_hi:=20xx=09=09=09offset=20=3D=2012=09=09S=0A+#=20=20=20=20= xx=20xx=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20bi_lo:=20= xx=09=09=09offset=20=3D=2014=09=09S=0A+#=20=20=20=20xx=20xx=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20ip_posid:=20xx=09=09=09offset=20=3D=20= 16=09=09S=0A+#=20=20=20=20xx=20xx=20=20=20=20=20=20=20=20=20=20=20=20=20= t_infomask2:=20xx=09=09=09offset=20=3D=2018=09=09S=0A+#=20=20=20=20xx=20= xx=20=20=20=20=20=20=20=20=20=20=20=20=20=20t_infomask:=20xx=09=09=09= offset=20=3D=2020=09=09S=0A+#=20=20=20=20xx=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20t_hoff:=20x=09=09=09offset=20=3D=2022=09= =09C=0A+#=20=20=20=20xx=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20t_bits:=20x=09=09=09offset=20=3D=2023=09=09C=0A+#=20=20=20=20= xx=20xx=20xx=20xx=20xx=20xx=20xx=20xx=20=20=20'a':=20xxxxxxxx=09offset=20= =3D=2024=09=09q=0A+#=20=20=20=20xx=20xx=20xx=20xx=20xx=20xx=20xx=20xx=20=20= =20'b':=20xxxxxxxx=09offset=20=3D=2032=09=09Cccccccc=0A+#=20=20=20=20xx=20= xx=20xx=20xx=20xx=20xx=20xx=20xx=20=20=20'c':=20xxxxxxxx=09offset=20=3D=20= 40=09=09SSSS=0A+#=20=20=20=20xx=20xx=20xx=20xx=20xx=20xx=20xx=20xx=20=20=20= =20=20=20:=20xxxxxxxx=09=20...continued=09SSSS=0A+#=20=20=20=20xx=20xx=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20:=20= xx=20=20=20=20=20=20=09=20...continued=09S=0A+#=0A+#=20We=20could=20= choose=20to=20read=20and=20write=20columns=20'b'=20and=20'c'=20in=20= other=20ways,=20but=0A+#=20it=20is=20convenient=20enough=20to=20do=20it=20= this=20way.=20=20We=20define=20packing=20code=0A+#=20constants=20here,=20= where=20they=20can=20be=20compared=20easily=20against=20the=20layout.=0A= +=0A+use=20constant=20HEAPTUPLE_PACK_CODE=20=3D>=20= 'LLLSSSSSCCqCcccccccSSSSSSSSS';=0A+use=20constant=20= HEAPTUPLE_PACK_LENGTH=20=3D>=2058;=20=20=20=20=20#=20Total=20size=0A+=0A= +#=20Read=20a=20tuple=20of=20our=20table=20from=20a=20heap=20page.=0A+#=0A= +#=20Takes=20an=20open=20filehandle=20to=20the=20heap=20file,=20and=20= the=20offset=20of=20the=20tuple.=0A+#=0A+#=20Rather=20than=20returning=20= the=20binary=20data=20from=20the=20file,=20unpacks=20the=20data=20into=20= a=0A+#=20perl=20hash=20with=20named=20fields.=20=20These=20fields=20= exactly=20match=20the=20ones=20understood=0A+#=20by=20write_tuple(),=20= below.=20=20Returns=20a=20reference=20to=20this=20hash.=0A+#=0A+sub=20= read_tuple=20($$)=0A+{=0A+=09my=20($fh,=20$offset)=20=3D=20@_;=0A+=09my=20= ($buffer,=20%tup);=0A+=09seek($fh,=20$offset,=200);=0A+=09sysread($fh,=20= $buffer,=20HEAPTUPLE_PACK_LENGTH);=0A+=0A+=09@_=20=3D=20= unpack(HEAPTUPLE_PACK_CODE,=20$buffer);=0A+=09%tup=20=3D=20(t_xmin=20=3D>=20= shift,=0A+=09=09=09t_xmax=20=3D>=20shift,=0A+=09=09=09t_field3=20=3D>=20= shift,=0A+=09=09=09bi_hi=20=3D>=20shift,=0A+=09=09=09bi_lo=20=3D>=20= shift,=0A+=09=09=09ip_posid=20=3D>=20shift,=0A+=09=09=09t_infomask2=20=3D>= =20shift,=0A+=09=09=09t_infomask=20=3D>=20shift,=0A+=09=09=09t_hoff=20=3D>= =20shift,=0A+=09=09=09t_bits=20=3D>=20shift,=0A+=09=09=09a=20=3D>=20= shift,=0A+=09=09=09b_header=20=3D>=20shift,=0A+=09=09=09b_body1=20=3D>=20= shift,=0A+=09=09=09b_body2=20=3D>=20shift,=0A+=09=09=09b_body3=20=3D>=20= shift,=0A+=09=09=09b_body4=20=3D>=20shift,=0A+=09=09=09b_body5=20=3D>=20= shift,=0A+=09=09=09b_body6=20=3D>=20shift,=0A+=09=09=09b_body7=20=3D>=20= shift,=0A+=09=09=09c1=20=3D>=20shift,=0A+=09=09=09c2=20=3D>=20shift,=0A+=09= =09=09c3=20=3D>=20shift,=0A+=09=09=09c4=20=3D>=20shift,=0A+=09=09=09c5=20= =3D>=20shift,=0A+=09=09=09c6=20=3D>=20shift,=0A+=09=09=09c7=20=3D>=20= shift,=0A+=09=09=09c8=20=3D>=20shift,=0A+=09=09=09c9=20=3D>=20shift);=0A= +=09#=20Stitch=20together=20the=20text=20for=20column=20'b'=0A+=09= $tup{b}=20=3D=20join('',=20map=20{=20chr($tup{"b_body$_"})=20}=20= (1..7));=0A+=09return=20\%tup;=0A+}=0A+=0A+#=20Write=20a=20tuple=20of=20= our=20table=20to=20a=20heap=20page.=0A+#=0A+#=20Takes=20an=20open=20= filehandle=20to=20the=20heap=20file,=20the=20offset=20of=20the=20tuple,=20= and=20a=0A+#=20reference=20to=20a=20hash=20with=20the=20tuple=20values,=20= as=20returned=20by=20read_tuple().=0A+#=20Writes=20the=20tuple=20fields=20= from=20the=20hash=20into=20the=20heap=20file.=0A+#=0A+#=20The=20purpose=20= of=20this=20function=20is=20to=20write=20a=20tuple=20back=20to=20disk=20= with=20some=0A+#=20subset=20of=20fields=20modified.=20=20The=20function=20= does=20no=20error=20checking.=20=20Use=0A+#=20cautiously.=0A+#=0A+sub=20= write_tuple($$$)=0A+{=0A+=09my=20($fh,=20$offset,=20$tup)=20=3D=20@_;=0A= +=09my=20$buffer=20=3D=20pack(HEAPTUPLE_PACK_CODE,=0A+=09=09=09=09=09= $tup->{t_xmin},=0A+=09=09=09=09=09$tup->{t_xmax},=0A+=09=09=09=09=09= $tup->{t_field3},=0A+=09=09=09=09=09$tup->{bi_hi},=0A+=09=09=09=09=09= $tup->{bi_lo},=0A+=09=09=09=09=09$tup->{ip_posid},=0A+=09=09=09=09=09= $tup->{t_infomask2},=0A+=09=09=09=09=09$tup->{t_infomask},=0A+=09=09=09=09= =09$tup->{t_hoff},=0A+=09=09=09=09=09$tup->{t_bits},=0A+=09=09=09=09=09= $tup->{a},=0A+=09=09=09=09=09$tup->{b_header},=0A+=09=09=09=09=09= $tup->{b_body1},=0A+=09=09=09=09=09$tup->{b_body2},=0A+=09=09=09=09=09= $tup->{b_body3},=0A+=09=09=09=09=09$tup->{b_body4},=0A+=09=09=09=09=09= $tup->{b_body5},=0A+=09=09=09=09=09$tup->{b_body6},=0A+=09=09=09=09=09= $tup->{b_body7},=0A+=09=09=09=09=09$tup->{c1},=0A+=09=09=09=09=09= $tup->{c2},=0A+=09=09=09=09=09$tup->{c3},=0A+=09=09=09=09=09$tup->{c4},=0A= +=09=09=09=09=09$tup->{c5},=0A+=09=09=09=09=09$tup->{c6},=0A+=09=09=09=09= =09$tup->{c7},=0A+=09=09=09=09=09$tup->{c8},=0A+=09=09=09=09=09= $tup->{c9});=0A+=09seek($fh,=20$offset,=200);=0A+=09syswrite($fh,=20= $buffer,=20HEAPTUPLE_PACK_LENGTH);=0A+=09return;=0A+}=0A+=0A+#=20Set=20= umask=20so=20test=20directories=20and=20files=20are=20created=20with=20= default=20permissions=0A+umask(0077);=0A+=0A+#=20Set=20up=20the=20node.=20= =20Once=20we=20create=20and=20corrupt=20the=20table,=0A+#=20autovacuum=20= workers=20visiting=20the=20table=20could=20crash=20the=20backend.=0A+#=20= Disable=20autovacuum=20so=20that=20won't=20happen.=0A+my=20$node=20=3D=20= get_new_node('test');=0A+$node->init;=0A= +$node->append_conf('postgresql.conf',=20'autovacuum=3Doff');=0A+=0A+#=20= Start=20the=20node=20and=20load=20the=20extensions.=20=20We=20depend=20= on=20both=0A+#=20amcheck=20and=20pageinspect=20for=20this=20test.=0A= +$node->start;=0A+my=20$port=20=3D=20$node->port;=0A+my=20$pgdata=20=3D=20= $node->data_dir;=0A+$node->safe_psql('postgres',=20"CREATE=20EXTENSION=20= amcheck");=0A+$node->safe_psql('postgres',=20"CREATE=20EXTENSION=20= pageinspect");=0A+=0A+#=20Get=20a=20non-zero=20datfrozenxid=0A= +$node->safe_psql('postgres',=20qq(VACUUM=20FREEZE));=0A+=0A+#=20Create=20= the=20test=20table=20with=20precisely=20the=20schema=20that=20our=20= corruption=20function=0A+#=20expects.=0A+$node->safe_psql(=0A+=09= 'postgres',=20qq(=0A+=09=09CREATE=20TABLE=20public.test=20(a=20BIGINT,=20= b=20TEXT,=20c=20TEXT);=0A+=09=09ALTER=20TABLE=20public.test=20SET=20= (autovacuum_enabled=3Dfalse);=0A+=09=09ALTER=20TABLE=20public.test=20= ALTER=20COLUMN=20c=20SET=20STORAGE=20EXTERNAL;=0A+=09=09CREATE=20INDEX=20= test_idx=20ON=20public.test(a,=20b);=0A+=09));=0A+=0A+#=20We=20want=20(0=20= <=20datfrozenxid=20<=20test.relfrozenxid).=20=20To=20achieve=20this,=20= we=20freeze=0A+#=20an=20otherwise=20unused=20table,=20public.junk,=20= prior=20to=20inserting=20data=20and=20freezing=0A+#=20public.test=0A= +$node->safe_psql(=0A+=09'postgres',=20qq(=0A+=09=09CREATE=20TABLE=20= public.junk=20AS=20SELECT=20'junk'::TEXT=20AS=20junk_column;=0A+=09=09= ALTER=20TABLE=20public.junk=20SET=20(autovacuum_enabled=3Dfalse);=0A+=09=09= VACUUM=20FREEZE=20public.junk=0A+=09));=0A+=0A+my=20$rel=20=3D=20= $node->safe_psql('postgres',=20qq(SELECT=20= pg_relation_filepath('public.test')));=0A+my=20$relpath=20=3D=20= "$pgdata/$rel";=0A+=0A+#=20Insert=20data=20and=20freeze=20public.test=0A= +use=20constant=20ROWCOUNT=20=3D>=2016;=0A+$node->safe_psql('postgres',=20= qq(=0A+=09INSERT=20INTO=20public.test=20(a,=20b,=20c)=0A+=09=09VALUES=20= (=0A+=09=09=0912345678,=0A+=09=09=09'abcdefg',=0A+=09=09=09repeat('w',=20= 10000)=0A+=09=09);=0A+=09VACUUM=20FREEZE=20public.test=0A+=09))=20for=20= (1..ROWCOUNT);=0A+=0A+my=20$relfrozenxid=20=3D=20= $node->safe_psql('postgres',=0A+=09q(select=20relfrozenxid=20from=20= pg_class=20where=20relname=20=3D=20'test'));=0A+my=20$datfrozenxid=20=3D=20= $node->safe_psql('postgres',=0A+=09q(select=20datfrozenxid=20from=20= pg_database=20where=20datname=20=3D=20'postgres'));=0A+=0A+#=20Find=20= where=20each=20of=20the=20tuples=20is=20located=20on=20the=20page.=0A+my=20= @lp_off;=0A+for=20my=20$tup=20(0..ROWCOUNT-1)=0A+{=0A+=09push=20= (@lp_off,=20$node->safe_psql('postgres',=20qq(=0A+select=20lp_off=20from=20= heap_page_items(get_raw_page('test',=20'main',=200))=0A+=09offset=20$tup=20= limit=201)));=0A+}=0A+=0A+#=20Check=20that=20pg_amcheck=20runs=20against=20= the=20uncorrupted=20table=20without=20error.=0A= +$node->command_ok(['pg_amcheck',=20'-p',=20$port,=20'postgres'],=0A+=09=09= =09=09=20=20'pg_amcheck=20test=20table,=20prior=20to=20corruption');=0A+=0A= +#=20Check=20that=20pg_amcheck=20runs=20against=20the=20uncorrupted=20= table=20and=20index=20without=20error.=0A= +$node->command_ok(['pg_amcheck',=20'-p',=20$port,=20'postgres'],=0A+=09=09= =09=09=20=20'pg_amcheck=20test=20table=20and=20index,=20prior=20to=20= corruption');=0A+=0A+$node->stop;=0A+=0A+#=20Sanity=20check=20that=20our=20= 'test'=20table=20has=20a=20relfrozenxid=20newer=20than=20the=0A+#=20= datfrozenxid=20for=20the=20database,=20and=20that=20the=20datfrozenxid=20= is=20greater=20than=20the=0A+#=20first=20normal=20xid.=20=20We=20rely=20= on=20these=20invariants=20in=20some=20of=20our=20tests.=0A+if=20= ($datfrozenxid=20<=3D=203=20||=20$datfrozenxid=20>=3D=20$relfrozenxid)=0A= +{=0A+=09fail('Xid=20thresholds=20not=20as=20expected');=0A+=09= $node->clean_node;=0A+=09exit;=0A+}=0A+=0A+#=20Some=20#define=20= constants=20from=20access/htup_details.h=20for=20use=20while=20= corrupting.=0A+use=20constant=20HEAP_HASNULL=20=20=20=20=20=20=20=20=20=20= =20=20=3D>=200x0001;=0A+use=20constant=20HEAP_XMAX_LOCK_ONLY=20=20=20=20=20= =3D>=200x0080;=0A+use=20constant=20HEAP_XMIN_COMMITTED=20=20=20=20=20=3D>=20= 0x0100;=0A+use=20constant=20HEAP_XMIN_INVALID=20=20=20=20=20=20=20=3D>=20= 0x0200;=0A+use=20constant=20HEAP_XMAX_COMMITTED=20=20=20=20=20=3D>=20= 0x0400;=0A+use=20constant=20HEAP_XMAX_INVALID=20=20=20=20=20=20=20=3D>=20= 0x0800;=0A+use=20constant=20HEAP_NATTS_MASK=20=20=20=20=20=20=20=20=20=3D>= =200x07FF;=0A+use=20constant=20HEAP_XMAX_IS_MULTI=20=20=20=20=20=20=3D>=20= 0x1000;=0A+use=20constant=20HEAP_KEYS_UPDATED=20=20=20=20=20=20=20=3D>=20= 0x2000;=0A+=0A+#=20Helper=20function=20to=20generate=20a=20regular=20= expression=20matching=20the=20header=20we=0A+#=20expect=20= verify_heapam()=20to=20return=20given=20which=20fields=20we=20expect=20= to=20be=20non-null.=0A+sub=20header=0A+{=0A+=09my=20($blkno,=20$offnum,=20= $attnum)=20=3D=20@_;=0A+=09return=20qr/relation=20test,=20block=20= $blkno,=20offset=20$offnum,=20attribute=20$attnum\s+/ms=0A+=09=09if=20= (defined=20$attnum);=0A+=09return=20qr/relation=20test,=20block=20= $blkno,=20offset=20$offnum\s+/ms=0A+=09=09if=20(defined=20$offnum);=0A+=09= return=20qr/relation=20test\s+/ms=0A+=09=09if=20(defined=20$blkno);=0A+=09= return=20qr/relation=20test\s+/ms;=0A+}=0A+=0A+#=20Corrupt=20the=20= tuples,=20one=20type=20of=20corruption=20per=20tuple.=20=20Some=20types=20= of=0A+#=20corruption=20cause=20verify_heapam=20to=20skip=20to=20the=20= next=20tuple=20without=0A+#=20performing=20any=20remaining=20checks,=20= so=20we=20can't=20exercise=20the=20system=20properly=20if=0A+#=20we=20= focus=20all=20our=20corruption=20on=20a=20single=20tuple.=0A+#=0A+my=20= @expected;=0A+my=20$file;=0A+open($file,=20'+<',=20$relpath);=0A+binmode=20= $file;=0A+=0A+for=20(my=20$tupidx=20=3D=200;=20$tupidx=20<=20ROWCOUNT;=20= $tupidx++)=0A+{=0A+=09my=20$offnum=20=3D=20$tupidx=20+=201;=20=20#=20= offnum=20is=201-based,=20not=20zero-based=0A+=09my=20$offset=20=3D=20= $lp_off[$tupidx];=0A+=09my=20$tup=20=3D=20read_tuple($file,=20$offset);=0A= +=0A+=09#=20Sanity-check=20that=20the=20data=20appears=20on=20the=20page=20= where=20we=20expect.=0A+=09if=20($tup->{a}=20ne=20'12345678'=20||=20= $tup->{b}=20ne=20'abcdefg')=0A+=09{=0A+=09=09fail('Page=20layout=20= differs=20from=20our=20expectations');=0A+=09=09$node->clean_node;=0A+=09= =09exit;=0A+=09}=0A+=0A+=09my=20$header=20=3D=20header(0,=20$offnum,=20= undef);=0A+=09if=20($offnum=20=3D=3D=201)=0A+=09{=0A+=09=09#=20Corruptly=20= set=20xmin=20<=20relfrozenxid=0A+=09=09my=20$xmin=20=3D=20$relfrozenxid=20= -=201;=0A+=09=09$tup->{t_xmin}=20=3D=20$xmin;=0A+=09=09= $tup->{t_infomask}=20&=3D=20~HEAP_XMIN_COMMITTED;=0A+=09=09= $tup->{t_infomask}=20&=3D=20~HEAP_XMIN_INVALID;=0A+=0A+=09=09#=20= Expected=20corruption=20report=0A+=09=09push=20@expected,=0A+=09=09=09= qr/${header}xmin=20$xmin=20precedes=20relation=20freeze=20threshold=20= 0:\d+/;=0A+=09}=0A+=09if=20($offnum=20=3D=3D=202)=0A+=09{=0A+=09=09#=20= Corruptly=20set=20xmin=20<=20datfrozenxid=0A+=09=09my=20$xmin=20=3D=203;=0A= +=09=09$tup->{t_xmin}=20=3D=20$xmin;=0A+=09=09$tup->{t_infomask}=20&=3D=20= ~HEAP_XMIN_COMMITTED;=0A+=09=09$tup->{t_infomask}=20&=3D=20= ~HEAP_XMIN_INVALID;=0A+=0A+=09=09push=20@expected,=0A+=09=09=09= qr/${$header}xmin=20$xmin=20precedes=20oldest=20valid=20transaction=20ID=20= 0:\d+/;=0A+=09}=0A+=09elsif=20($offnum=20=3D=3D=203)=0A+=09{=0A+=09=09#=20= Corruptly=20set=20xmin=20<=20datfrozenxid,=20further=20back,=20noting=20= circularity=0A+=09=09#=20of=20xid=20comparison.=20=20For=20a=20new=20= cluster=20with=20epoch=20=3D=200,=20the=20corrupt=0A+=09=09#=20xmin=20= will=20be=20interpreted=20as=20in=20the=20future=0A+=09=09$tup->{t_xmin}=20= =3D=204026531839;=0A+=09=09$tup->{t_infomask}=20&=3D=20= ~HEAP_XMIN_COMMITTED;=0A+=09=09$tup->{t_infomask}=20&=3D=20= ~HEAP_XMIN_INVALID;=0A+=0A+=09=09push=20@expected,=0A+=09=09=09= qr/${$header}xmin=204026531839=20equals=20or=20exceeds=20next=20valid=20= transaction=20ID=200:\d+/;=0A+=09}=0A+=09elsif=20($offnum=20=3D=3D=204)=0A= +=09{=0A+=09=09#=20Corruptly=20set=20xmax=20<=20relminmxid;=0A+=09=09= $tup->{t_xmax}=20=3D=204026531839;=0A+=09=09$tup->{t_infomask}=20&=3D=20= ~HEAP_XMAX_INVALID;=0A+=0A+=09=09push=20@expected,=0A+=09=09=09= qr/${$header}xmax=204026531839=20equals=20or=20exceeds=20next=20valid=20= transaction=20ID=200:\d+/;=0A+=09}=0A+=09elsif=20($offnum=20=3D=3D=205)=0A= +=09{=0A+=09=09#=20Corrupt=20the=20tuple=20t_hoff,=20but=20keep=20it=20= aligned=20properly=0A+=09=09$tup->{t_hoff}=20+=3D=20128;=0A+=0A+=09=09= push=20@expected,=0A+=09=09=09qr/${$header}data=20begins=20at=20offset=20= 152=20beyond=20the=20tuple=20length=2058/,=0A+=09=09=09= qr/${$header}tuple=20data=20should=20begin=20at=20byte=2024,=20but=20= actually=20begins=20at=20byte=20152=20\(3=20attributes,=20no=20nulls\)/;=0A= +=09}=0A+=09elsif=20($offnum=20=3D=3D=206)=0A+=09{=0A+=09=09#=20Corrupt=20= the=20tuple=20t_hoff,=20wrong=20alignment=0A+=09=09$tup->{t_hoff}=20+=3D=20= 3;=0A+=0A+=09=09push=20@expected,=0A+=09=09=09qr/${$header}tuple=20data=20= should=20begin=20at=20byte=2024,=20but=20actually=20begins=20at=20byte=20= 27=20\(3=20attributes,=20no=20nulls\)/;=0A+=09}=0A+=09elsif=20($offnum=20= =3D=3D=207)=0A+=09{=0A+=09=09#=20Corrupt=20the=20tuple=20t_hoff,=20= underflow=20but=20correct=20alignment=0A+=09=09$tup->{t_hoff}=20-=3D=20= 8;=0A+=0A+=09=09push=20@expected,=0A+=09=09=09qr/${$header}tuple=20data=20= should=20begin=20at=20byte=2024,=20but=20actually=20begins=20at=20byte=20= 16=20\(3=20attributes,=20no=20nulls\)/;=0A+=09}=0A+=09elsif=20($offnum=20= =3D=3D=208)=0A+=09{=0A+=09=09#=20Corrupt=20the=20tuple=20t_hoff,=20= underflow=20and=20wrong=20alignment=0A+=09=09$tup->{t_hoff}=20-=3D=203;=0A= +=0A+=09=09push=20@expected,=0A+=09=09=09qr/${$header}tuple=20data=20= should=20begin=20at=20byte=2024,=20but=20actually=20begins=20at=20byte=20= 21=20\(3=20attributes,=20no=20nulls\)/;=0A+=09}=0A+=09elsif=20($offnum=20= =3D=3D=209)=0A+=09{=0A+=09=09#=20Corrupt=20the=20tuple=20to=20look=20= like=20it=20has=20lots=20of=20attributes,=20not=20just=203=0A+=09=09= $tup->{t_infomask2}=20|=3D=20HEAP_NATTS_MASK;=0A+=0A+=09=09push=20= @expected,=0A+=09=09=09qr/${$header}number=20of=20attributes=202047=20= exceeds=20maximum=20expected=20for=20table=203/;=0A+=09}=0A+=09elsif=20= ($offnum=20=3D=3D=2010)=0A+=09{=0A+=09=09#=20Corrupt=20the=20tuple=20to=20= look=20like=20it=20has=20lots=20of=20attributes,=20some=20of=0A+=09=09#=20= them=20null.=20=20This=20falsely=20creates=20the=20impression=20that=20= the=20t_bits=0A+=09=09#=20array=20is=20longer=20than=20just=20one=20= byte,=20but=20t_hoff=20still=20says=20otherwise.=0A+=09=09= $tup->{t_infomask}=20|=3D=20HEAP_HASNULL;=0A+=09=09$tup->{t_infomask2}=20= |=3D=20HEAP_NATTS_MASK;=0A+=09=09$tup->{t_bits}=20=3D=200xAA;=0A+=0A+=09=09= push=20@expected,=0A+=09=09=09qr/${$header}tuple=20data=20should=20begin=20= at=20byte=20280,=20but=20actually=20begins=20at=20byte=2024=20\(2047=20= attributes,=20has=20nulls\)/;=0A+=09}=0A+=09elsif=20($offnum=20=3D=3D=20= 11)=0A+=09{=0A+=09=09#=20Same=20as=20above,=20but=20this=20time=20t_hoff=20= plays=20along=0A+=09=09$tup->{t_infomask}=20|=3D=20HEAP_HASNULL;=0A+=09=09= $tup->{t_infomask2}=20|=3D=20(HEAP_NATTS_MASK=20&=200x40);=0A+=09=09= $tup->{t_bits}=20=3D=200xAA;=0A+=09=09$tup->{t_hoff}=20=3D=2032;=0A+=0A+=09= =09push=20@expected,=0A+=09=09=09qr/${$header}number=20of=20attributes=20= 67=20exceeds=20maximum=20expected=20for=20table=203/;=0A+=09}=0A+=09= elsif=20($offnum=20=3D=3D=2012)=0A+=09{=0A+=09=09#=20Corrupt=20the=20= bits=20in=20column=20'b'=201-byte=20varlena=20header=0A+=09=09= $tup->{b_header}=20=3D=200x80;=0A+=0A+=09=09$header=20=3D=20header(0,=20= $offnum,=201);=0A+=09=09push=20@expected,=0A+=09=09=09= qr/${header}attribute=201=20with=20length=204294967295=20ends=20at=20= offset=20416848000=20beyond=20total=20tuple=20length=2058/;=0A+=09}=0A+=09= elsif=20($offnum=20=3D=3D=2013)=0A+=09{=0A+=09=09#=20Corrupt=20the=20= bits=20in=20column=20'c'=20toast=20pointer=0A+=09=09$tup->{c6}=20=3D=20= 41;=0A+=09=09$tup->{c7}=20=3D=2041;=0A+=0A+=09=09$header=20=3D=20= header(0,=20$offnum,=202);=0A+=09=09push=20@expected,=0A+=09=09=09= qr/${header}final=20toast=20chunk=20number=200=20differs=20from=20= expected=20value=206/,=0A+=09=09=09qr/${header}toasted=20value=20for=20= attribute=202=20missing=20from=20toast=20table/;=0A+=09}=0A+=09elsif=20= ($offnum=20=3D=3D=2014)=0A+=09{=0A+=09=09#=20Set=20both=20= HEAP_XMAX_LOCK_ONLY=20and=20HEAP_KEYS_UPDATED=0A+=09=09= $tup->{t_infomask}=20|=3D=20HEAP_XMAX_LOCK_ONLY;=0A+=09=09= $tup->{t_infomask2}=20|=3D=20HEAP_KEYS_UPDATED;=0A+=0A+=09=09push=20= @expected,=0A+=09=09=09qr/${header}tuple=20is=20marked=20as=20only=20= locked,=20but=20also=20claims=20key=20columns=20were=20updated/;=0A+=09}=0A= +=09elsif=20($offnum=20=3D=3D=2015)=0A+=09{=0A+=09=09#=20Set=20both=20= HEAP_XMAX_COMMITTED=20and=20HEAP_XMAX_IS_MULTI=0A+=09=09= $tup->{t_infomask}=20|=3D=20HEAP_XMAX_COMMITTED;=0A+=09=09= $tup->{t_infomask}=20|=3D=20HEAP_XMAX_IS_MULTI;=0A+=09=09$tup->{t_xmax}=20= =3D=204;=0A+=0A+=09=09push=20@expected,=0A+=09=09=09= qr/${header}multitransaction=20ID=204=20equals=20or=20exceeds=20next=20= valid=20multitransaction=20ID=201/;=0A+=09}=0A+=09elsif=20($offnum=20=3D=3D= =2016)=09#=20Last=20offnum=20must=20equal=20ROWCOUNT=0A+=09{=0A+=09=09#=20= Set=20both=20HEAP_XMAX_COMMITTED=20and=20HEAP_XMAX_IS_MULTI=0A+=09=09= $tup->{t_infomask}=20|=3D=20HEAP_XMAX_COMMITTED;=0A+=09=09= $tup->{t_infomask}=20|=3D=20HEAP_XMAX_IS_MULTI;=0A+=09=09$tup->{t_xmax}=20= =3D=204000000000;=0A+=0A+=09=09push=20@expected,=0A+=09=09=09= qr/${header}multitransaction=20ID=204000000000=20precedes=20relation=20= minimum=20multitransaction=20ID=20threshold=201/;=0A+=09}=0A+=09= write_tuple($file,=20$offset,=20$tup);=0A+}=0A+close($file);=0A= +$node->start;=0A+=0A+#=20Run=20pg_amcheck=20against=20the=20corrupt=20= table=20with=20epoch=3D0,=20comparing=20actual=0A+#=20corruption=20= messages=20against=20the=20expected=20messages=0A= +$node->command_checks_all(=0A+=09['pg_amcheck',=20'--check-toast',=20= '--skip-indexes',=20'-p',=20$port,=20'postgres'],=0A+=090,=0A+=09[=20= @expected=20],=0A+=09[=20qr/^$/=20],=0A+=09'Expected=20corruption=20= message=20output');=0A+=0A+$node->teardown_node;=0A+$node->clean_node;=0A= diff=20--git=20a/contrib/pg_amcheck/t/005_opclass_damage.pl=20= b/contrib/pg_amcheck/t/005_opclass_damage.pl=0Anew=20file=20mode=20= 100644=0Aindex=200000000000..c24f154883=0A---=20/dev/null=0A+++=20= b/contrib/pg_amcheck/t/005_opclass_damage.pl=0A@@=20-0,0=20+1,52=20@@=0A= +#=20This=20regression=20test=20checks=20the=20behavior=20of=20the=20= btree=20validation=20in=20the=0A+#=20presence=20of=20breaking=20sort=20= order=20changes.=0A+#=0A+use=20strict;=0A+use=20warnings;=0A+use=20= PostgresNode;=0A+use=20TestLib;=0A+use=20Test::More=20tests=20=3D>=206;=0A= +=0A+my=20$node=20=3D=20get_new_node('test');=0A+$node->init;=0A= +$node->start;=0A+=0A+#=20Create=20a=20custom=20operator=20class=20and=20= an=20index=20which=20uses=20it.=0A+$node->safe_psql('postgres',=20q(=0A+=09= CREATE=20EXTENSION=20amcheck;=0A+=0A+=09CREATE=20FUNCTION=20int4_asc_cmp=20= (a=20int4,=20b=20int4)=20RETURNS=20int=20LANGUAGE=20sql=20AS=20$$=0A+=09=09= SELECT=20CASE=20WHEN=20$1=20=3D=20$2=20THEN=200=20WHEN=20$1=20>=20$2=20= THEN=201=20ELSE=20-1=20END;=20$$;=0A+=0A+=09CREATE=20OPERATOR=20CLASS=20= int4_fickle_ops=20FOR=20TYPE=20int4=20USING=20btree=20AS=0A+=09=20=20=20=20= OPERATOR=201=20<=20(int4,=20int4),=20OPERATOR=202=20<=3D=20(int4,=20= int4),=0A+=09=20=20=20=20OPERATOR=203=20=3D=20(int4,=20int4),=20OPERATOR=20= 4=20>=3D=20(int4,=20int4),=0A+=09=20=20=20=20OPERATOR=205=20>=20(int4,=20= int4),=20FUNCTION=201=20int4_asc_cmp(int4,=20int4);=0A+=0A+=09CREATE=20= TABLE=20int4tbl=20(i=20int4);=0A+=09INSERT=20INTO=20int4tbl=20(SELECT=20= *=20FROM=20generate_series(1,1000)=20gs);=0A+=09CREATE=20INDEX=20= fickleidx=20ON=20int4tbl=20USING=20btree=20(i=20int4_fickle_ops);=0A+));=0A= +=0A+#=20We=20have=20not=20yet=20broken=20the=20index,=20so=20we=20= should=20get=20no=20corruption=0A+$node->command_like(=0A+=09[=20= 'pg_amcheck',=20'-X',=20'-p',=20$node->port,=20'postgres'=20],=0A+=09= qr/^$/,=0A+=09'pg_amcheck=20all=20schemas,=20tables=20and=20indexes=20= reports=20no=20corruption');=0A+=0A+#=20Change=20the=20operator=20class=20= to=20use=20a=20function=20which=20sorts=20in=20a=20different=0A+#=20= order=20to=20corrupt=20the=20btree=20index=0A= +$node->safe_psql('postgres',=20q(=0A+=09CREATE=20FUNCTION=20= int4_desc_cmp=20(int4,=20int4)=20RETURNS=20int=20LANGUAGE=20sql=20AS=20= $$=0A+=09=09SELECT=20CASE=20WHEN=20$1=20=3D=20$2=20THEN=200=20WHEN=20$1=20= >=20$2=20THEN=20-1=20ELSE=201=20END;=20$$;=0A+=09UPDATE=20= pg_catalog.pg_amproc=0A+=09=09SET=20amproc=20=3D=20= 'int4_desc_cmp'::regproc=0A+=09=09WHERE=20amproc=20=3D=20= 'int4_asc_cmp'::regproc=0A+));=0A+=0A+#=20Index=20corruption=20should=20= now=20be=20reported=0A+$node->command_like(=0A+=09[=20'pg_amcheck',=20= '-p',=20$node->port,=20'postgres'=20],=0A+=09qr/item=20order=20invariant=20= violated=20for=20index=20"fickleidx"/,=0A+=09'pg_amcheck=20all=20= schemas,=20tables=20and=20indexes=20reports=20fickleidx=20corruption'=0A= +);=0Adiff=20--git=20a/doc/src/sgml/contrib.sgml=20= b/doc/src/sgml/contrib.sgml=0Aindex=20ae2759be55..797b4dc61e=20100644=0A= ---=20a/doc/src/sgml/contrib.sgml=0A+++=20b/doc/src/sgml/contrib.sgml=0A= @@=20-119,6=20+119,7=20@@=20CREATE=20EXTENSION=20= module_name;=0A=20=20&oldsnapshot;=0A=20=20= &pageinspect;=0A=20=20&passwordcheck;=0A+=20&pgamcheck;=0A=20=20= &pgbuffercache;=0A=20=20&pgcrypto;=0A=20=20&pgfreespacemap;=0Adiff=20= --git=20a/doc/src/sgml/filelist.sgml=20b/doc/src/sgml/filelist.sgml=0A= index=2038e8aa0bbf..a4e1b28b38=20100644=0A---=20= a/doc/src/sgml/filelist.sgml=0A+++=20b/doc/src/sgml/filelist.sgml=0A@@=20= -133,6=20+133,7=20@@=0A=20=0A=20=0A=20=0A+=0A=20=0A=20=0A=20=0Adiff=20--git=20a/doc/src/sgml/pgamcheck.sgml=20= b/doc/src/sgml/pgamcheck.sgml=0Anew=20file=20mode=20100644=0Aindex=20= 0000000000..00643d2e58=0A---=20/dev/null=0A+++=20= b/doc/src/sgml/pgamcheck.sgml=0A@@=20-0,0=20+1,493=20@@=0A+=0A+=0A+=0A+=20pg_amcheck=0A+=0A+=20= =0A+=20=20pg_amcheck=0A= +=20=0A+=0A+=20=0A+=20=20The=20= pg_amcheck=20module=20provides=20a=20command=20line=20= interface=0A+=20=20to=20the=20=20corruption=20= checking=20functionality.=0A+=20=0A+=0A+=20=0A+=20=20= pg_amcheck=20is=20a=20regular=0A+=20=20= PostgreSQL=20client=20application.=20You=20= can=20perform=0A+=20=20corruption=20checks=20from=20any=20remote=20host=20= that=20has=20access=20to=20the=20database=0A+=20=20connecting=20as=20a=20= user=20with=20sufficient=20privileges=20to=20check=20tables=20and=20= indexes.=0A+=20=20Currently,=20this=20requires=20execute=20privileges=20= on=20's=0A+=20=20= bt_index_parent_check=20and=20= verify_heapam=0A+=20=20functions.=0A+=20=0A+=0A= +=0A+pg_amcheck=20mydb=0A+=0A+=0A+=20=0A+=20=20= Options=0A+=0A+=20=20=0A+=20=20=20The=20following=20= command-line=20options=20for=20controlling=20general=20program=20= behavior=0A+=20=20=20are=20recognized.=0A+=0A+=20=20=20=0A= +=20=20=20=20=0A+=20=20=20=20=20= =0A+=20=20=20=20=20= =0A+=20=20=20=20=20=0A+=20= =20=20=20=20=0A+=20=20=20=20=20Show=20= pg_amcheck=20version=20number,=20and=20exit.=0A= +=20=20=20=20=20=0A+=20=20=20=20=20=0A+=20=20=20=20= =0A+=0A+=20=20=20=20=0A+=20=20=20=20=20= =0A+=20=20=20=20=20= =0A+=20=20=20=20=20=0A+=20=20= =20=20=20=0A+=20=20=20=20=20Show=20help=20about=20= pg_amcheck=20command=20line=0A+=20=20=20=20=20= arguments,=20and=20exit.=0A+=20=20=20=20=20=0A+=20=20=20=20=20= =0A+=20=20=20=20=0A+=0A+=20=20=20=20= =0A+=20=20=20=20=20=0A+=20=20= =20=20=20=0A+=20=20=20=20=20= =0A+=20=20=20=20=20=0A+=20=20=20=20=20Specifies=20= verbose=20mode.=20=20This=20will=20cause=0A+=20=20=20=20=20= pg_amcheck=20to=20output=20more=20detailed=20= information=0A+=20=20=20=20=20about=20its=20activities,=20mostly=20to=20= do=20with=20its=20communication=20with=20the=0A+=20=20=20=20=20database.=0A= +=20=20=20=20=20=0A+=20=20=20=20=20=0A+=20=20=20=20=20Note=20= that=20this=20does=20not=20increase=20the=20number=20of=20corruptions=20= reported=20nor=0A+=20=20=20=20=20the=20level=20of=20detail=20reported=20= about=20each=20of=20them.=0A+=20=20=20=20=20=0A+=20=20=20=20=20= =0A+=20=20=20=20=0A+=20=20=20=0A= +=20=20=0A+=0A+=20=20=0A+=20=20=20The=20following=20= command-line=20options=20control=20which=20datatabase=20objects=0A+=20=20= =20pg_amcheck=20checks=20and=20how=20such=20= options=0A+=20=20=20are=20interpreted.=0A+=20=20=0A+=20=20=20= =0A+=20=20=20=20=0A+=20=20=20=20=20= =0A+=20=20=20=20= =20=0A+=20=20=20=20= =20=0A+=20=20=20=20=20=20=0A+=20=20=20=20=20=20=20For=20= indexes=20associated=20with=20tables=20being=20checked,=20check=20only=20= those=0A+=20=20=20=20=20=20=20indexes=20with=20names=20matching=20= pattern.=20Multiple=20indexes=20can=20= be=0A+=20=20=20=20=20=20=20selected=20by=20writing=20multiple=20= =20switches.=20=20The=0A+=20=20=20=20=20=20=20= pattern=20parameter=20= is=0A+=20=20=20=20=20=20=20interpreted=20as=20a=20pattern=20according=20= to=20the=20same=20rules=20used=20by=0A+=20=20=20=20=20=20=20= psql's=20\d=20commands=20= (see=0A+=20=20=20=20=20=20=20),=20= so=20multiple=20indexes=20can=20also=0A+=20=20=20=20=20=20=20be=20= selected=20by=20writing=20wildcard=20characters=20in=20the=20pattern.=20=20= When=20using=0A+=20=20=20=20=20=20=20wildcards,=20be=20careful=20to=20= quote=20the=20pattern=20if=20needed=20to=20prevent=20the=0A+=20=20=20=20=20= =20=20shell=20from=20expanding=20the=20wildcards.=0A+=20=20=20=20=20=20= =0A+=20=20=20=20=20=0A+=20=20=20=20=0A+=0A= +=20=20=20=20=0A+=20=20=20=20=20=0A= +=20=20=20=20=20=0A+=20=20=20=20= =20=0A+=20=20=20=20=20=20=0A+=20=20=20=20=20=20=20Do=20= not=20check=20any=20indexes=20matching=20pattern.=20=20The=20pattern=20is=20= interpreted=0A+=20=20=20=20=20=20=20according=20to=20the=20same=20rules=20= as=20for=20.=0A+=20=20=20=20=20=20=20= =20can=20be=20given=20more=20than=20once=20to=20= exclude=20indexes=0A+=20=20=20=20=20=20=20matching=20any=20of=20several=20= patterns.=0A+=20=20=20=20=20=20=0A+=0A+=20=20=20=20=20=20=0A= +=20=20=20=20=20=20=20When=20both=20=20and=20= =20are=20given,=20the=0A+=20=20=20=20=20=20=20= behavior=20is=20to=20check=20just=20the=20indexes=20that=20match=20at=20= least=20one=0A+=20=20=20=20=20=20=20=20switch=20but=20= no=20=20switches.=20=20If=0A+=20=20=20=20=20=20=20= =20appears=20without=20,=20then=20= indexes=0A+=20=20=20=20=20=20=20matching=20=20are=20= excluded=20from=20what=20is=20otherwise=20a=20check=0A+=20=20=20=20=20=20= =20of=20all=20indexes=20associated=20with=20tables=20that=20are=20= checked.=0A+=20=20=20=20=20=20=0A+=20=20=20=20=20=0A+=20= =20=20=20=0A+=0A+=20=20=20=20=0A+=20=20=20=20= =20=0A+=20=20=20=20= =20=0A+=20=20=20=20= =20=0A+=20=20=20=20=20=20=0A+=20=20=20=20=20=20=20Dump=20= only=20schemas=20matching=20pattern;=20this=20selects=20both=20the=0A= +=20=20=20=20=20=20=20schema=20itself,=20and=20all=20its=20contained=20= objects.=20=20When=20this=20option=20is=0A+=20=20=20=20=20=20=20not=20= specified,=20all=20non-system=20schemas=20in=20the=20target=20database=20= will=20be=0A+=20=20=20=20=20=20=20checked.=20=20Multiple=20schemas=20can=20= be=0A+=20=20=20=20=20=20=20selected=20by=20writing=20multiple=20= =20switches.=20=20The=0A+=20=20=20=20=20=20=20= pattern=20parameter=20= is=0A+=20=20=20=20=20=20=20interpreted=20as=20a=20pattern=20according=20= to=20the=20same=20rules=20used=20by=0A+=20=20=20=20=20=20=20= psql's=20\d=20commands=0A+=20= =20=20=20=20=20=20(see=20),=0A+=20= =20=20=20=20=20=20so=20multiple=20schemas=20can=20also=20be=20selected=20= by=20writing=20wildcard=20characters=0A+=20=20=20=20=20=20=20in=20the=20= pattern.=20=20When=20using=20wildcards,=20be=20careful=20to=20quote=20= the=20pattern=0A+=20=20=20=20=20=20=20if=20needed=20to=20prevent=20the=20= shell=20from=20expanding=20the=20wildcards.=0A+=20=20=20=20=20=20=0A= +=20=20=20=20=20=0A+=20=20=20=20=0A+=0A+=20=20=20= =20=0A+=20=20=20=20=20=0A+=20=20=20=20= =20=0A+=20=20=20=20= =20=0A+=20=20=20=20=20=20=0A+=20=20=20=20=20=20=20Do=20= not=20check=20any=20schemas=20matching=20pattern.=20=20The=20pattern=20is=0A= +=20=20=20=20=20=20=20interpreted=20according=20to=20the=20same=20rules=20= as=20for=20.=0A+=20=20=20=20=20=20=20= =20can=20be=20given=20more=20than=20once=20to=20= exclude=20schemas=0A+=20=20=20=20=20=20=20matching=20any=20of=20several=20= patterns.=0A+=20=20=20=20=20=20=0A+=0A+=20=20=20=20=20=20=0A= +=20=20=20=20=20=20=20When=20both=20=20and=20= =20are=20given,=20the=20behavior=0A+=20=20=20=20=20=20= =20is=20to=20check=20just=20the=20schemas=20that=20match=20at=20least=20= one=20=0A+=20=20=20=20=20=20=20switch=20but=20no=20= =20switches.=20=20If=20=20appears=0A= +=20=20=20=20=20=20=20without=20,=20then=20schemas=20= matching=20=20are=0A+=20=20=20=20=20=20=20excluded=20= from=20what=20is=20otherwise=20a=20check=20of=20all=20schemas.=0A+=20=20=20= =20=20=20=0A+=20=20=20=20=20=0A+=20=20=20=20= =0A+=0A+=20=20=20=20=0A+=20=20=20=20=20= =0A+=20=20=20=20=20= =0A+=20=20=20=20=20= =0A+=20=20=20=20=20=20=0A+=20=20=20=20=20=20=20Requires=20= that=20each=20schema=0A+=20=20=20=20=20=20=20= (/),=20table=0A+=20=20=20=20=20= =20=20(/)=20and=20index=0A+=20= =20=20=20=20=20=20(/)=20= qualifier=20match=20at=20least=0A+=20=20=20=20=20=20=20one=20= schema/table/index=20in=20the=20database=20to=20be=20checked.=0A+=20=20=20= =20=20=20=0A+=20=20=20=20=20=20=0A+=20=20=20=20=20=20=20= This=20option=20has=20no=20effect=20on=0A+=20=20=20=20=20=20=20= /,=0A+=20=20=20=20=20= =20=20/,=0A+=20=20=20=20= =20=20=20or=20.=20=20= An=20exclude=0A+=20=20=20=20=20=20=20pattern=20failing=20to=20match=20= any=20objects=20is=20not=20considered=20an=20error.=0A+=20=20=20=20=20=20= =0A+=20=20=20=20=20=0A+=20=20=20=20=0A+=0A= +=20=20=20=20=0A+=20=20=20=20=20=0A= +=20=20=20=20=20=0A+=20=20=20=20= =20=0A+=20=20=20=20=20=20=0A+=20=20=20=20=20=20=20Check=20= only=20tables=20with=20names=20matching=0A+=20=20=20=20=20=20=20= pattern.=20Multiple=20= tables=0A+=20=20=20=20=20=20=20can=20be=20selected=20by=20writing=20= multiple=20=20switches.=20=20The=0A+=20=20=20=20=20=20= =20pattern=20parameter=20= is=0A+=20=20=20=20=20=20=20interpreted=20as=20a=20pattern=20according=20= to=20the=20same=20rules=20used=20by=0A+=20=20=20=20=20=20=20= psql's=20\d=20commands=0A+=20= =20=20=20=20=20=20(see=20),=0A+=20= =20=20=20=20=20=20so=20multiple=20tables=20can=20also=20be=20selected=20= by=20writing=20wildcard=20characters=0A+=20=20=20=20=20=20=20in=20the=20= pattern.=20=20When=20using=20wildcards,=20be=20careful=20to=20quote=20= the=20pattern=0A+=20=20=20=20=20=20=20if=20needed=20to=20prevent=20the=20= shell=20from=20expanding=20the=20wildcards.=0A+=20=20=20=20=20=20=0A= +=20=20=20=20=20=0A+=20=20=20=20=0A+=0A+=20=20=20= =20=0A+=20=20=20=20=20=0A+=20=20=20=20= =20=0A+=20=20=20=20= =20=0A+=20=20=20=20=20=20=0A+=20=20=20=20=20=20=20Do=20= not=20check=20any=20tables=20matching=20pattern.=20=20The=20pattern=20is=20= interpreted=0A+=20=20=20=20=20=20=20according=20to=20the=20same=20rules=20= as=20for=20.=0A+=20=20=20=20=20=20=20= =20can=20be=20given=20more=20than=20once=20to=20= exclude=20tables=0A+=20=20=20=20=20=20=20matching=20any=20of=20several=20= patterns.=0A+=20=20=20=20=20=20=0A+=0A+=20=20=20=20=20=20=0A= +=20=20=20=20=20=20=20When=20both=20=20and=20= =20are=20given,=20the=0A+=20=20=20=20=20=20=20= behavior=20is=20to=20check=20just=20the=20tables=20that=20match=20at=20= least=20one=0A+=20=20=20=20=20=20=20=20switch=20but=20= no=20=20switches.=20=20If=0A+=20=20=20=20=20=20=20= =20appears=20without=20,=20then=20= tables=0A+=20=20=20=20=20=20=20matching=20=20are=20= excluded=20from=20what=20is=20otherwise=20a=20check=0A+=20=20=20=20=20=20= =20of=20all=20tables.=0A+=20=20=20=20=20=20=0A+=20=20=20=20=20= =0A+=20=20=20=20=0A+=20=20=20=0A= +=20=20=0A+=0A+=20=20=0A+=20=20=20The=20following=20= command-line=20options=20control=20additional=20behaviors.=0A+=0A+=20=20=20= =0A+=20=20=20=20=0A+=20=20=20=20=20= =0A+=20=20=20=20=20= =0A+=20=20=20=20=20= =0A+=20=20=20=20=20=20=0A+=20=20=20=20=20=20=20When=20= checking=20indexes,=20additionally=20verify=20the=20presence=20of=20all=20= heap=0A+=20=20=20=20=20=20=20tuples=20as=20index=20tuples=20within=20the=20= index.=0A+=20=20=20=20=20=20=0A+=20=20=20=20=20=0A+=20=20= =20=20=0A+=0A+=20=20=20=20=0A+=20=20=20=20=20= =0A+=20=20=20=20=20= =0A+=20=20=20=20=20= =0A+=20=20=20=20=20=20=0A+=20=20=20=20=20=20=20Do=20not=20= check=20blocks=20prior=20to=20block,=20which=20should=20be=20a=20= non-negative=0A+=20=20=20=20=20=20=20integer.=20=20(Negative=20values=20= disable=20the=20option).=0A+=20=20=20=20=20=20=0A+=20=20=20=20=20=20= =0A+=20=20=20=20=20=20=20When=20both=20=20= =20and=0A+=20=20=20=20=20=20=20= =20=20are=20specified,=20= the=20end=0A+=20=20=20=20=20=20=20block=20must=20not=20be=20less=20than=20= the=20start=20block.=0A+=20=20=20=20=20=20=0A+=20=20=20=20=20=20= =0A+=20=20=20=20=20=20=20The=20=20= =20option=20will=20be=0A+=20=20=20=20=20=20=20= applied=20to=20all=20tables=20that=20are=20checked,=20including=20toast=20= tables.=20=20The=0A+=20=20=20=20=20=20=20option=20is=20most=20useful=20= when=20checking=20exactly=20one=20table,=20to=20focus=20the=0A+=20=20=20=20= =20=20=20checking=20on=20just=20specific=20blocks=20of=20that=20one=20= table.=0A+=20=20=20=20=20=20=0A+=20=20=20=20=20=0A+=20=20= =20=20=0A+=0A+=20=20=20=20=0A+=20=20=20=20=20= =0A+=20=20=20=20=20= =0A+=20=20=20=20=20= =0A+=20=20=20=20=20=20=0A+=20=20=20=20=20=20=20Skip=20= checking=20indexes=20for=20a=20table=20if=20the=20table=20is=20found=20= to=20be=20corrupt.=0A+=20=20=20=20=20=20=0A+=20=20=20=20=20= =0A+=20=20=20=20=0A+=0A+=20=20=20=20= =0A+=20=20=20=20=20=0A+=20=20=20=20=20= =0A+=20=20=20=20=20= =0A+=20=20=20=20=20=20=0A+=20=20=20=20=20=20=20Do=20not=20= check=20blocks=20after=20block,=20which=20should=20be=20a=20= non-negative=0A+=20=20=20=20=20=20=20integer.=20=20(Negative=20values=20= disable=20the=20option).=0A+=20=20=20=20=20=20=0A+=20=20=20=20=20=20= =0A+=20=20=20=20=20=20=20When=20both=20=20= =20and=0A+=20=20=20=20=20=20=20= =20=20are=20specified,=20= the=20end=0A+=20=20=20=20=20=20=20block=20must=20not=20be=20less=20than=20= the=20start=20block.=0A+=20=20=20=20=20=20=0A+=20=20=20=20=20=20= =0A+=20=20=20=20=20=20=20The=20=20= =20option=20will=20be=0A+=20=20=20=20=20=20=20= applied=20to=20all=20tables=20that=20are=20checked,=20including=20toast=20= tables.=20=20The=0A+=20=20=20=20=20=20=20option=20is=20most=20useful=20= when=20checking=20exactly=20one=20table,=20to=20focus=20the=0A+=20=20=20=20= =20=20=20checking=20on=20just=20specific=20blocks=20of=20that=20one=20= table.=0A+=20=20=20=20=20=20=0A+=20=20=20=20=20=0A+=20=20= =20=20=0A+=0A+=20=20=20=20=0A+=20=20=20=20=20= =0A+=20=20=20=20=20= =0A+=20=20=20=20=20= =0A+=20=20=20=20=20=20=0A+=20=20=20=20=20=20=20Stop=20= checking=20database=20objects=20at=20the=20end=20of=20the=20first=20page=20= on=0A+=20=20=20=20=20=20=20which=20the=20first=20corruption=20is=20= found.=20=20Note=20that=20even=20with=20this=20option=0A+=20=20=20=20=20=20= =20enabled,=20more=20than=20one=20corruption=20message=20may=20be=20= reported.=0A+=20=20=20=20=20=20=0A+=20=20=20=20=20=0A+=20= =20=20=20=0A+=0A+=20=20=20=20=0A+=20=20=20=20= =20=0A+=20=20=20=20=20= =0A+=20=20=20=20=20=0A= +=20=20=20=20=20=20=0A+=20=20=20=20=20=20=20When=20checking=20= indexes,=20for=20each=20tuple,=20perform=20addition=20verification=20by=0A= +=20=20=20=20=20=20=20re-finding=20the=20tuple=20on=20the=20leaf=20level=20= by=20performing=20a=20new=20search=20from=0A+=20=20=20=20=20=20=20the=20= root=20page.=0A+=20=20=20=20=20=20=0A+=20=20=20=20=20=20=0A= +=20=20=20=20=20=20=20This=20form=20of=20verification=20was=20originally=20= written=20to=20help=20in=20the=0A+=20=20=20=20=20=20=20development=20of=20= btree=20index=20features.=20=20It=20may=20be=20of=20limited=20or=20even=20= of=20no=0A+=20=20=20=20=20=20=20use=20in=20helping=20detect=20the=20= kinds=20of=20corruption=20that=20occur=20in=20practice.=0A+=20=20=20=20=20= =20=20In=20any=20event,=20it=20is=20known=20to=20be=20a=20rather=20= expensive=20check=20to=20perform.=0A+=20=20=20=20=20=20=0A+=20=20=20= =20=20=0A+=20=20=20=20=0A+=0A+=20=20=20=20= =0A+=20=20=20=20=20=0A+=20=20= =20=20=20=0A+=20=20=20=20=20= =0A+=20=20=20=20=20=20=0A+=20=20=20=20=20=20=20When=20= all-visible=20is=20given,=20skips=20= corruption=0A+=20=20=20=20=20=20=20checking=20of=20blocks=20marked=20as=20= all=20visible=20in=20the=20visibility=20map.=0A+=20=20=20=20=20=20= =0A+=20=20=20=20=20=20=0A+=20=20=20=20=20=20=20When=20= all-frozen=20is=20given,=20skips=20= corruption=0A+=20=20=20=20=20=20=20checking=20of=20blocks=20marked=20as=20= all=20frozen=20in=20the=20visibility=20map.=0A+=20=20=20=20=20=20=0A= +=20=20=20=20=20=20=0A+=20=20=20=20=20=20=20The=20default=20is=20= to=20check=20blocks=20without=20regard=20to=20their=20marking=20in=20the=0A= +=20=20=20=20=20=20=20visibility=20map.=0A+=20=20=20=20=20=20=0A+=20= =20=20=20=20=0A+=20=20=20=20=0A+=0A+=20=20=20=20= =0A+=20=20=20=20=20=0A+=20=20= =20=20=20=0A+=20=20=20=20=20= =0A+=20=20=20=20=20=20=0A+=20=20=20=20=20=20=20Check=20= only=20tables=20but=20not=20indexes.=0A+=20=20=20=20=20=20=0A+=20=20= =20=20=20=0A+=20=20=20=20=0A+=0A+=20=20=20=20= =0A+=20=20=20=20=20=0A+=20=20= =20=20=20=0A+=20=20=20=20=20= =0A+=20=20=20=20=20=20=0A+=20=20=20=20=20=20=20Do=20not=20= check=20toast=20tables=20nor=20their=20indexes.=0A+=20=20=20=20=20=20= =0A+=20=20=20=20=20=0A+=20=20=20=20=0A+=0A= +=20=20=20=0A+=20=20=0A+=0A+=20=20=0A+=20=20=20= The=20following=20additional=20command-line=20options=20control=20the=20= database=0A+=20=20=20connection=20parameters.=0A+=0A+=20=20=20= =0A+=20=20=20=20=0A+=20=20=20=20=20= =0A+=20=20=20=20=20= =0A+=20=20=20=20=20= =0A+=20=20=20=20=20=0A+=20=20=20=20=20=20Specifies=20the=20= name=20of=20the=20database=20to=20connect=20to.=20This=20is=0A+=20=20=20=20= =20=20equivalent=20to=20specifying=20dbname=20as=20the=20first=20non-option=0A= +=20=20=20=20=20=20argument=20on=20the=20command=20line.=20=20The=20= dbname=0A+=20=20=20=20=20=20can=20be=20a=20= connection=20string.=0A+=20=20= =20=20=20=20If=20so,=20connection=20string=20parameters=20will=20= override=20any=20conflicting=0A+=20=20=20=20=20=20command=20line=20= options.=0A+=20=20=20=20=20=0A+=20=20=20=20=20=0A+=20=20= =20=20=0A+=0A+=20=20=20=20=0A+=20=20=20=20=20= =0A+=20=20=20=20=20= =0A+=20=20=20=20=20= =0A+=20=20=20=20=20=20=0A+=20=20=20=20=20=20=20Specifies=20= the=20host=20name=20of=20the=20machine=20on=20which=20the=20server=20is=0A= +=20=20=20=20=20=20=20running.=20=20If=20the=20value=20begins=20with=20a=20= slash,=20it=20is=20used=20as=20the=0A+=20=20=20=20=20=20=20directory=20= for=20the=20Unix=20domain=20socket.=20The=20default=20is=20taken=0A+=20=20= =20=20=20=20=20from=20the=20PGHOST=20environment=20= variable,=20if=20set,=0A+=20=20=20=20=20=20=20else=20a=20Unix=20domain=20= socket=20connection=20is=20attempted.=0A+=20=20=20=20=20=20=0A+=20= =20=20=20=20=0A+=20=20=20=20=0A+=0A+=20=20=20=20= =0A+=20=20=20=20=20=0A+=20=20=20=20=20= =0A+=20=20=20=20=20= =0A+=20=20=20=20=20=20=0A+=20=20=20=20=20=20=20Specifies=20= the=20TCP=20port=20or=20local=20Unix=20domain=20socket=20file=0A+=20=20=20= =20=20=20=20extension=20on=20which=20the=20server=20is=20listening=20for=20= connections.=0A+=20=20=20=20=20=20=20Defaults=20to=20the=20= PGPORT=20environment=20variable,=20if=0A+=20=20=20=20=20=20= =20set,=20or=20a=20compiled-in=20default.=0A+=20=20=20=20=20=20=0A= +=20=20=20=20=20=0A+=20=20=20=20=0A+=0A+=20=20=20= =20=0A+=20=20=20=20=20=0A+=20=20=20=20=20= =0A+=20=20=20=20= =20=0A+=20=20=20=20=20=20=0A+=20=20=20=20=20=20=20User=20= name=20to=20connect=20as.=0A+=20=20=20=20=20=20=0A+=20=20=20=20=20= =0A+=20=20=20=20=0A+=0A+=20=20=20=20= =0A+=20=20=20=20=20=0A+=20=20= =20=20=20=0A+=20=20=20=20=20= =0A+=20=20=20=20=20=20=0A+=20=20=20=20=20=20=20Never=20= issue=20a=20password=20prompt.=20=20If=20the=20server=20requires=0A+=20=20= =20=20=20=20=20password=20authentication=20and=20a=20password=20is=20not=20= available=20by=0A+=20=20=20=20=20=20=20other=20means=20such=20as=20a=20= .pgpass=20file,=20the=0A+=20=20=20=20=20=20=20= connection=20attempt=20will=20fail.=20=20This=20option=20can=20be=20= useful=20in=0A+=20=20=20=20=20=20=20batch=20jobs=20and=20scripts=20where=20= no=20user=20is=20present=20to=20enter=20a=0A+=20=20=20=20=20=20=20= password.=0A+=20=20=20=20=20=20=0A+=20=20=20=20=20=0A+=20= =20=20=20=0A+=0A+=20=20=20=20=0A+=20=20=20=20= =20=0A+=20=20=20=20=20= =0A+=20=20=20=20=20=0A= +=20=20=20=20=20=20=0A+=20=20=20=20=20=20=20Force=20= pg_dump=20to=20prompt=20for=20a=0A+=20=20=20=20= =20=20=20password=20before=20connecting=20to=20a=20database.=0A+=20=20=20= =20=20=20=0A+=0A+=20=20=20=20=20=20=0A+=20=20=20=20=20=20=20= This=20option=20is=20never=20essential,=20since=0A+=20=20=20=20=20=20=20= pg_dump=20will=20automatically=20prompt=0A+=20= =20=20=20=20=20=20for=20a=20password=20if=20the=20server=20demands=20= password=20authentication.=0A+=20=20=20=20=20=20=20However,=20= pg_dump=20will=20waste=20a=0A+=20=20=20=20=20=20= =20connection=20attempt=20finding=20out=20that=20the=20server=20wants=20= a=20password.=0A+=20=20=20=20=20=20=20In=20some=20cases=20it=20is=20= worth=20typing=20=20to=20avoid=20the=20extra=0A+=20=20= =20=20=20=20=20connection=20attempt.=0A+=20=20=20=20=20=20=0A+=20=20= =20=20=20=0A+=20=20=20=20=0A+=0A+=20=20=20=20= =0A+=20=20=20=20=20=0A+=20=20=20=20= =20=0A+=20=20=20=20=20=20=0A+=20=20=20=20=20=20=20= Specifies=20a=20role=20name=20to=20be=20used=20to=20create=20the=20dump.=0A= +=20=20=20=20=20=20=20This=20option=20causes=20= pg_dump=20to=20issue=20a=0A+=20=20=20=20=20=20= =20SET=20ROLE=20rolename=0A+=20=20=20=20=20=20=20= command=20after=20connecting=20to=20the=20database.=20It=20is=20useful=20= when=20the=0A+=20=20=20=20=20=20=20authenticated=20user=20(specified=20= by=20)=20lacks=20privileges=0A+=20=20=20=20=20=20=20= needed=20by=20pg_dump,=20but=20can=20switch=20= to=20a=20role=20with=0A+=20=20=20=20=20=20=20the=20required=20rights.=20=20= Some=20installations=20have=20a=20policy=20against=0A+=20=20=20=20=20=20=20= logging=20in=20directly=20as=20a=20superuser,=20and=20use=20of=20this=20= option=20allows=0A+=20=20=20=20=20=20=20dumps=20to=20be=20made=20without=20= violating=20the=20policy.=0A+=20=20=20=20=20=20=0A+=20=20=20=20=20= =0A+=20=20=20=20=0A+=20=20=20=0A= +=20=20=0A+=20=0A+=0Adiff=20--git=20= a/src/fe_utils/query_utils.c=20b/src/fe_utils/query_utils.c=0Aindex=20= 355da6edaf..cbbc085698=20100644=0A---=20a/src/fe_utils/query_utils.c=0A= +++=20b/src/fe_utils/query_utils.c=0A@@=20-46,7=20+46,7=20@@=20= exiting_handler(PGresult=20*res,=20PGconn=20*conn,=20ExecStatusType=20= expected_status,=0A=20=09}=0A=20=09if=20(expected_ntups=20=3D=3D=20= POSITIVE_NTUPS=20||=20expected_ntups=20>=3D=200)=0A=20=09{=0A-=09=09int=20= ntups=20=3D=20PQntuples(res);=0A+=09=09int=09=09=09ntups=20=3D=20= PQntuples(res);=0A=20=0A=20=09=09if=20(expected_ntups=20=3D=3D=20= POSITIVE_NTUPS)=0A=20=09=09{=0A@@=20-63,11=20+63,11=20@@=20= exiting_handler(PGresult=20*res,=20PGconn=20*conn,=20ExecStatusType=20= expected_status,=0A=20=09=09=09=09fatal(ngettext("query=20returned=20%d=20= row=20instead=20of=20one:=20%s",=0A=20=09=09=09=09=09=09=09=20=20=20= "query=20returned=20%d=20rows=20instead=20of=20one:=20%s",=0A=20=09=09=09= =09=09=09=09=20=20=20ntups),=0A-=09=09=09=09=09ntups,=20query);=0A+=09=09= =09=09=09=20=20ntups,=20query);=0A=20=09=09=09fatal(ngettext("query=20= returned=20%d=20row=20instead=20of=20%d:=20%s",=0A=20=09=09=09=09=09=09=20= =20=20"query=20returned=20%d=20rows=20instead=20of=20%d:=20%s",=0A=20=09=09= =09=09=09=09=20=20=20ntups),=0A-=09=09=09=09ntups,=20expected_ntups,=20= query);=0A+=09=09=09=09=20=20ntups,=20expected_ntups,=20query);=0A=20=09=09= }=0A=20=09}=0A=20=09return=20res;=0A@@=20-80,7=20+80,7=20@@=20PGresult=20= *=0A=20quiet_handler(PGresult=20*res,=20PGconn=20*conn,=20ExecStatusType=20= expected_status,=0A=20=09=09=09=20=20int=20expected_ntups,=20const=20= char=20*query)=0A=20{=0A-=09int=20ntups=20=3D=20PQntuples(res);=0A+=09= int=09=09=09ntups=20=3D=20PQntuples(res);=0A=20=0A=20=09if=20= ((PQresultStatus(res)=20!=3D=20expected_status)=20||=0A=20=09=09= (expected_ntups=20=3D=3D=20POSITIVE_NTUPS=20&&=20ntups=20=3D=3D=200)=20= ||=0Adiff=20--git=20a/src/tools/msvc/Mkvcbuild.pm=20= b/src/tools/msvc/Mkvcbuild.pm=0Aindex=207f014a12c9..eef00320e7=20100644=0A= ---=20a/src/tools/msvc/Mkvcbuild.pm=0A+++=20= b/src/tools/msvc/Mkvcbuild.pm=0A@@=20-33,9=20+33,9=20@@=20my=20= @unlink_on_exit;=0A=20=0A=20#=20Set=20of=20variables=20for=20modules=20= in=20contrib/=20and=20src/test/modules/=0A=20my=20$contrib_defines=20=3D=20= {=20'refint'=20=3D>=20'REFINT_VERBOSE'=20};=0A-my=20@contrib_uselibpq=20= =3D=20('dblink',=20'oid2name',=20'postgres_fdw',=20'vacuumlo');=0A-my=20= @contrib_uselibpgport=20=20=20=3D=20('oid2name',=20'pg_standby',=20= 'vacuumlo');=0A-my=20@contrib_uselibpgcommon=20=3D=20('oid2name',=20= 'pg_standby',=20'vacuumlo');=0A+my=20@contrib_uselibpq=20=3D=20= ('dblink',=20'oid2name',=20'pg_amcheck',=20'postgres_fdw',=20= 'vacuumlo');=0A+my=20@contrib_uselibpgport=20=20=20=3D=20('oid2name',=20= 'pg_amcheck',=20'pg_standby',=20'vacuumlo');=0A+my=20= @contrib_uselibpgcommon=20=3D=20('oid2name',=20'pg_amcheck',=20= 'pg_standby',=20'vacuumlo');=0A=20my=20$contrib_extralibs=20=20=20=20=20=20= =3D=20undef;=0A=20my=20$contrib_extraincludes=20=3D=20{=20'dblink'=20=3D>=20= ['src/backend']=20};=0A=20my=20$contrib_extrasource=20=3D=20{=0A@@=20= -146,8=20+146,8=20@@=20sub=20mkvcbuild=0A=20=09our=20@pgcommonbkndfiles=20= =3D=20@pgcommonallfiles;=0A=20=0A=20=09our=20@pgfeutilsfiles=20=3D=20qw(=0A= -=09=20=20archive.c=20cancel.c=20conditional.c=20mbprint.c=20print.c=20= psqlscan.l=0A-=09=20=20psqlscan.c=20simple_list.c=20string_utils.c=20= recovery_gen.c);=0A+=09=20=20archive.c=20cancel.c=20conditional.c=20= exit_utils.c=20mbprint.c=20option_utils.c=20print.c=20psqlscan.l=0A+=09=20= =20psqlscan.c=20query_utils.c=20simple_list.c=20string_utils.c=20= recovery_gen.c);=0A=20=0A=20=09$libpgport=20=3D=20= $solution->AddProject('libpgport',=20'lib',=20'misc');=0A=20=09= $libpgport->AddDefine('FRONTEND');=0Adiff=20--git=20= a/src/tools/pgindent/typedefs.list=20b/src/tools/pgindent/typedefs.list=0A= index=20f3957bad6c..e4003b15a0=20100644=0A---=20= a/src/tools/pgindent/typedefs.list=0A+++=20= b/src/tools/pgindent/typedefs.list=0A@@=20-101,6=20+101,7=20@@=20= AlterUserMappingStmt=0A=20AlteredTableInfo=0A=20AlternativeSubPlan=0A=20= AlternativeSubPlanState=0A+AmCheckSettings=0A=20= AnalyzeAttrComputeStatsFunc=0A=20AnalyzeAttrFetchFunc=0A=20= AnalyzeForeignTable_function=0A@@=20-404,6=20+405,7=20@@=20= ConnCacheEntry=0A=20ConnCacheKey=0A=20ConnStatusType=0A=20ConnType=0A= +ConnectOptions=0A=20ConnectionStateEnum=0A=20ConsiderSplitContext=0A=20= Const=0A--=20=0A2.21.1=20(Apple=20Git-122.3)=0A=0A= --Apple-Mail=_8B07CFD0-2450-4CA2-BEE1-ACB2F7EEE33B Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 =E2=80=94 Mark Dilger EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company --Apple-Mail=_8B07CFD0-2450-4CA2-BEE1-ACB2F7EEE33B--