agora inbox for [email protected]help / color / mirror / Atom feed
[PATCH] Add pg_tablespace_avail() functions 59+ messages / 2 participants [nested] [flat]
* [PATCH] Add pg_tablespace_avail() functions @ 2019-11-08 13:12 Christoph Berg <[email protected]> 0 siblings, 0 replies; 59+ messages in thread From: Christoph Berg @ 2019-11-08 13:12 UTC (permalink / raw) This exposes the f_avail value from statvfs() on tablespace directories on the SQL level, allowing monitoring of free disk space from within the server. On windows, GetDiskFreeSpaceEx() is used. Permissions required match those from pg_tablespace_size. In psql, include a new "Free" column in \db+ output. --- doc/src/sgml/func.sgml | 21 ++++++++ doc/src/sgml/ref/psql-ref.sgml | 2 +- src/backend/utils/adt/dbsize.c | 94 +++++++++++++++++++++++++++++++++ src/bin/psql/describe.c | 11 ++-- src/include/catalog/pg_proc.dat | 8 +++ 5 files changed, 132 insertions(+), 4 deletions(-) diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml index 51dd8ad6571..0b4456ad958 100644 --- a/doc/src/sgml/func.sgml +++ b/doc/src/sgml/func.sgml @@ -30093,6 +30093,27 @@ postgres=# SELECT '0/0'::pg_lsn + pd.segment_number * ps.setting::int + :offset </para></entry> </row> + <row> + <entry role="func_table_entry"><para role="func_signature"> + <indexterm> + <primary>pg_tablespace_avail</primary> + </indexterm> + <function>pg_tablespace_avail</function> ( <type>name</type> ) + <returnvalue>bigint</returnvalue> + </para> + <para role="func_signature"> + <function>pg_tablespace_avail</function> ( <type>oid</type> ) + <returnvalue>bigint</returnvalue> + </para> + <para> + Returns the available disk space in the tablespace with the + specified name or OID. To use this function, you must + have <literal>CREATE</literal> privilege on the specified tablespace + or have privileges of the <literal>pg_read_all_stats</literal> role, + unless it is the default tablespace for the current database. + </para></entry> + </row> + <row> <entry role="func_table_entry"><para role="func_signature"> <indexterm> diff --git a/doc/src/sgml/ref/psql-ref.sgml b/doc/src/sgml/ref/psql-ref.sgml index cedccc14129..9e1bec0b422 100644 --- a/doc/src/sgml/ref/psql-ref.sgml +++ b/doc/src/sgml/ref/psql-ref.sgml @@ -1492,7 +1492,7 @@ SELECT $1 \parse stmt1 If <literal>x</literal> is appended to the command name, the results are displayed in expanded mode. If <literal>+</literal> is appended to the command name, each tablespace - is listed with its associated options, on-disk size, permissions and + is listed with its associated options, on-disk size and free disk space, permissions and description. </para> </listitem> diff --git a/src/backend/utils/adt/dbsize.c b/src/backend/utils/adt/dbsize.c index 25865b660ef..3a2f47c50ec 100644 --- a/src/backend/utils/adt/dbsize.c +++ b/src/backend/utils/adt/dbsize.c @@ -12,6 +12,11 @@ #include "postgres.h" #include <sys/stat.h> +#ifdef WIN32 +#include <fileapi.h> +#else +#include <sys/statvfs.h> +#endif #include "access/htup_details.h" #include "access/relation.h" @@ -316,6 +321,95 @@ pg_tablespace_size_name(PG_FUNCTION_ARGS) } +/* + * Return available disk space of tablespace. Returns -1 if the tablespace + * directory cannot be found. + */ +static int64 +calculate_tablespace_avail(Oid tblspcOid) +{ + char tblspcPath[MAXPGPATH]; + AclResult aclresult; +#ifdef WIN32 + ULARGE_INTEGER lpFreeBytesAvailable; +#else + struct statvfs fst; +#endif + + /* + * User must have privileges of pg_read_all_stats or have CREATE privilege + * for target tablespace, either explicitly granted or implicitly because + * it is default for current database. + */ + if (tblspcOid != MyDatabaseTableSpace && + !has_privs_of_role(GetUserId(), ROLE_PG_READ_ALL_STATS)) + { + aclresult = object_aclcheck(TableSpaceRelationId, tblspcOid, GetUserId(), ACL_CREATE); + if (aclresult != ACLCHECK_OK) + aclcheck_error(aclresult, OBJECT_TABLESPACE, + get_tablespace_name(tblspcOid)); + } + + if (tblspcOid == DEFAULTTABLESPACE_OID) + snprintf(tblspcPath, MAXPGPATH, "base"); + else if (tblspcOid == GLOBALTABLESPACE_OID) + snprintf(tblspcPath, MAXPGPATH, "global"); + else + snprintf(tblspcPath, MAXPGPATH, "%s/%u/%s", PG_TBLSPC_DIR, tblspcOid, + TABLESPACE_VERSION_DIRECTORY); + +#ifdef WIN32 + if (GetDiskFreeSpaceEx(tblspcPath, &lpFreeBytesAvailable, NULL, NULL) == false) + return -1; + + return lpFreeBytesAvailable.QuadPart; /* ULONGLONG part of ULARGE_INTEGER */ +#else + if (statvfs(tblspcPath, &fst) < 0) + return -1; + + return fst.f_bavail * fst.f_bsize; /* available blocks times block size */ +#endif +} + +Datum +pg_tablespace_avail_oid(PG_FUNCTION_ARGS) +{ + Oid tblspcOid = PG_GETARG_OID(0); + int64 avail; + + /* + * Not needed for correctness, but avoid non-user-facing error message + * later if the tablespace doesn't exist. + */ + if (!SearchSysCacheExists1(TABLESPACEOID, ObjectIdGetDatum(tblspcOid))) + ereport(ERROR, + errcode(ERRCODE_UNDEFINED_OBJECT), + errmsg("tablespace with OID %u does not exist", tblspcOid)); + + avail = calculate_tablespace_avail(tblspcOid); + + if (avail < 0) + PG_RETURN_NULL(); + + PG_RETURN_INT64(avail); +} + +Datum +pg_tablespace_avail_name(PG_FUNCTION_ARGS) +{ + Name tblspcName = PG_GETARG_NAME(0); + Oid tblspcOid = get_tablespace_oid(NameStr(*tblspcName), false); + int64 avail; + + avail = calculate_tablespace_avail(tblspcOid); + + if (avail < 0) + PG_RETURN_NULL(); + + PG_RETURN_INT64(avail); +} + + /* * calculate size of (one fork of) a relation * diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index e6cf468ac9e..8c52a126ac1 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -241,10 +241,15 @@ describeTablespaces(const char *pattern, bool verbose) printACLColumn(&buf, "spcacl"); appendPQExpBuffer(&buf, ",\n spcoptions AS \"%s\"" - ",\n pg_catalog.pg_size_pretty(pg_catalog.pg_tablespace_size(oid)) AS \"%s\"" - ",\n pg_catalog.shobj_description(oid, 'pg_tablespace') AS \"%s\"", + ",\n pg_catalog.pg_size_pretty(pg_catalog.pg_tablespace_size(oid)) AS \"%s\"", gettext_noop("Options"), - gettext_noop("Size"), + gettext_noop("Size")); + if (pset.sversion >= 180000) + appendPQExpBuffer(&buf, + ",\n pg_catalog.pg_size_pretty(pg_catalog.pg_tablespace_avail(oid)) AS \"%s\"", + gettext_noop("Free")); + appendPQExpBuffer(&buf, + ",\n pg_catalog.shobj_description(oid, 'pg_tablespace') AS \"%s\"", gettext_noop("Description")); } diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat index 42e427f8fe8..9d64da6bfb8 100644 --- a/src/include/catalog/pg_proc.dat +++ b/src/include/catalog/pg_proc.dat @@ -7680,6 +7680,14 @@ descr => 'total disk space usage for the specified tablespace', proname => 'pg_tablespace_size', provolatile => 'v', prorettype => 'int8', proargtypes => 'name', prosrc => 'pg_tablespace_size_name' }, +{ oid => '6015', + descr => 'disk stats for the specified tablespace', + proname => 'pg_tablespace_avail', provolatile => 'v', prorettype => 'int8', + proargtypes => 'oid', prosrc => 'pg_tablespace_avail_oid' }, +{ oid => '6016', + descr => 'disk stats for the specified tablespace', + proname => 'pg_tablespace_avail', provolatile => 'v', prorettype => 'int8', + proargtypes => 'name', prosrc => 'pg_tablespace_avail_name' }, { oid => '2324', descr => 'total disk space usage for the specified database', proname => 'pg_database_size', provolatile => 'v', prorettype => 'int8', proargtypes => 'oid', prosrc => 'pg_database_size_oid' }, -- 2.47.2 --vqKhBUYnSUFh3RIa-- ^ permalink raw reply [nested|flat] 59+ messages in thread
* [PATCH v1 1/1] micro-optimize nbtcompare.c routines @ 2024-09-26 20:03 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 59+ messages in thread From: Nathan Bossart @ 2024-09-26 20:03 UTC (permalink / raw) --- src/backend/access/nbtree/nbtcompare.c | 162 ++++++++++++------------- src/backend/storage/page/itemptr.c | 18 +-- src/backend/utils/sort/tuplesort.c | 21 ++-- 3 files changed, 96 insertions(+), 105 deletions(-) diff --git a/src/backend/access/nbtree/nbtcompare.c b/src/backend/access/nbtree/nbtcompare.c index 1c72867c84..2df0c5dbe0 100644 --- a/src/backend/access/nbtree/nbtcompare.c +++ b/src/backend/access/nbtree/nbtcompare.c @@ -57,17 +57,16 @@ #include <limits.h> +#include "common/int.h" #include "utils/fmgrprotos.h" #include "utils/sortsupport.h" -#ifdef STRESS_SORT_INT_MIN -#define A_LESS_THAN_B INT_MIN -#define A_GREATER_THAN_B INT_MAX -#else -#define A_LESS_THAN_B (-1) -#define A_GREATER_THAN_B 1 -#endif - +#define STRESS_SORT_INT_MIN_CMP(a, b) \ +( \ + ((a) > (b)) ? INT_MAX : \ + ((a) < (b)) ? INT_MIN : \ + 0 \ +) Datum btboolcmp(PG_FUNCTION_ARGS) @@ -84,7 +83,11 @@ btint2cmp(PG_FUNCTION_ARGS) int16 a = PG_GETARG_INT16(0); int16 b = PG_GETARG_INT16(1); - PG_RETURN_INT32((int32) a - (int32) b); +#ifdef STRESS_SORT_INT_MIN + PG_RETURN_INT32(STRESS_SORT_INT_MIN_CMP(a, b)); +#else + PG_RETURN_INT32(pg_cmp_s16(a, b)); +#endif } static int @@ -93,7 +96,11 @@ btint2fastcmp(Datum x, Datum y, SortSupport ssup) int16 a = DatumGetInt16(x); int16 b = DatumGetInt16(y); - return (int) a - (int) b; +#ifdef STRESS_SORT_INT_MIN + return STRESS_SORT_INT_MIN_CMP(a, b); +#else + return pg_cmp_s16(a, b); +#endif } Datum @@ -111,12 +118,11 @@ btint4cmp(PG_FUNCTION_ARGS) int32 a = PG_GETARG_INT32(0); int32 b = PG_GETARG_INT32(1); - if (a > b) - PG_RETURN_INT32(A_GREATER_THAN_B); - else if (a == b) - PG_RETURN_INT32(0); - else - PG_RETURN_INT32(A_LESS_THAN_B); +#ifdef STRESS_SORT_INT_MIN + PG_RETURN_INT32(STRESS_SORT_INT_MIN_CMP(a, b)); +#else + PG_RETURN_INT32(pg_cmp_s32(a, b)); +#endif } Datum @@ -134,12 +140,11 @@ btint8cmp(PG_FUNCTION_ARGS) int64 a = PG_GETARG_INT64(0); int64 b = PG_GETARG_INT64(1); - if (a > b) - PG_RETURN_INT32(A_GREATER_THAN_B); - else if (a == b) - PG_RETURN_INT32(0); - else - PG_RETURN_INT32(A_LESS_THAN_B); +#ifdef STRESS_SORT_INT_MIN + PG_RETURN_INT32(STRESS_SORT_INT_MIN_CMP(a, b)); +#else + PG_RETURN_INT32(pg_cmp_s64(a, b)); +#endif } #if SIZEOF_DATUM < 8 @@ -149,12 +154,11 @@ btint8fastcmp(Datum x, Datum y, SortSupport ssup) int64 a = DatumGetInt64(x); int64 b = DatumGetInt64(y); - if (a > b) - return A_GREATER_THAN_B; - else if (a == b) - return 0; - else - return A_LESS_THAN_B; +#ifdef STRESS_SORT_INT_MIN + return STRESS_SORT_INT_MIN_CMP(a, b); +#else + return pg_cmp_s64(a, b); +#endif } #endif @@ -177,12 +181,11 @@ btint48cmp(PG_FUNCTION_ARGS) int32 a = PG_GETARG_INT32(0); int64 b = PG_GETARG_INT64(1); - if (a > b) - PG_RETURN_INT32(A_GREATER_THAN_B); - else if (a == b) - PG_RETURN_INT32(0); - else - PG_RETURN_INT32(A_LESS_THAN_B); +#ifdef STRESS_SORT_INT_MIN + PG_RETURN_INT32(STRESS_SORT_INT_MIN_CMP(a, b)); +#else + PG_RETURN_INT32(pg_cmp_s64(a, b)); +#endif } Datum @@ -191,12 +194,11 @@ btint84cmp(PG_FUNCTION_ARGS) int64 a = PG_GETARG_INT64(0); int32 b = PG_GETARG_INT32(1); - if (a > b) - PG_RETURN_INT32(A_GREATER_THAN_B); - else if (a == b) - PG_RETURN_INT32(0); - else - PG_RETURN_INT32(A_LESS_THAN_B); +#ifdef STRESS_SORT_INT_MIN + PG_RETURN_INT32(STRESS_SORT_INT_MIN_CMP(a, b)); +#else + PG_RETURN_INT32(pg_cmp_s64(a, b)); +#endif } Datum @@ -205,12 +207,11 @@ btint24cmp(PG_FUNCTION_ARGS) int16 a = PG_GETARG_INT16(0); int32 b = PG_GETARG_INT32(1); - if (a > b) - PG_RETURN_INT32(A_GREATER_THAN_B); - else if (a == b) - PG_RETURN_INT32(0); - else - PG_RETURN_INT32(A_LESS_THAN_B); +#ifdef STRESS_SORT_INT_MIN + PG_RETURN_INT32(STRESS_SORT_INT_MIN_CMP(a, b)); +#else + PG_RETURN_INT32(pg_cmp_s32(a, b)); +#endif } Datum @@ -219,12 +220,11 @@ btint42cmp(PG_FUNCTION_ARGS) int32 a = PG_GETARG_INT32(0); int16 b = PG_GETARG_INT16(1); - if (a > b) - PG_RETURN_INT32(A_GREATER_THAN_B); - else if (a == b) - PG_RETURN_INT32(0); - else - PG_RETURN_INT32(A_LESS_THAN_B); +#ifdef STRESS_SORT_INT_MIN + PG_RETURN_INT32(STRESS_SORT_INT_MIN_CMP(a, b)); +#else + PG_RETURN_INT32(pg_cmp_s32(a, b)); +#endif } Datum @@ -233,12 +233,11 @@ btint28cmp(PG_FUNCTION_ARGS) int16 a = PG_GETARG_INT16(0); int64 b = PG_GETARG_INT64(1); - if (a > b) - PG_RETURN_INT32(A_GREATER_THAN_B); - else if (a == b) - PG_RETURN_INT32(0); - else - PG_RETURN_INT32(A_LESS_THAN_B); +#ifdef STRESS_SORT_INT_MIN + PG_RETURN_INT32(STRESS_SORT_INT_MIN_CMP(a, b)); +#else + PG_RETURN_INT32(pg_cmp_s64(a, b)); +#endif } Datum @@ -247,12 +246,11 @@ btint82cmp(PG_FUNCTION_ARGS) int64 a = PG_GETARG_INT64(0); int16 b = PG_GETARG_INT16(1); - if (a > b) - PG_RETURN_INT32(A_GREATER_THAN_B); - else if (a == b) - PG_RETURN_INT32(0); - else - PG_RETURN_INT32(A_LESS_THAN_B); +#ifdef STRESS_SORT_INT_MIN + PG_RETURN_INT32(STRESS_SORT_INT_MIN_CMP(a, b)); +#else + PG_RETURN_INT32(pg_cmp_s64(a, b)); +#endif } Datum @@ -261,12 +259,11 @@ btoidcmp(PG_FUNCTION_ARGS) Oid a = PG_GETARG_OID(0); Oid b = PG_GETARG_OID(1); - if (a > b) - PG_RETURN_INT32(A_GREATER_THAN_B); - else if (a == b) - PG_RETURN_INT32(0); - else - PG_RETURN_INT32(A_LESS_THAN_B); +#ifdef STRESS_SORT_INT_MIN + PG_RETURN_INT32(STRESS_SORT_INT_MIN_CMP(a, b)); +#else + PG_RETURN_INT32(pg_cmp_u32(a, b)); +#endif } static int @@ -275,12 +272,11 @@ btoidfastcmp(Datum x, Datum y, SortSupport ssup) Oid a = DatumGetObjectId(x); Oid b = DatumGetObjectId(y); - if (a > b) - return A_GREATER_THAN_B; - else if (a == b) - return 0; - else - return A_LESS_THAN_B; +#ifdef STRESS_SORT_INT_MIN + return STRESS_SORT_INT_MIN_CMP(a, b); +#else + return pg_cmp_u32(a, b); +#endif } Datum @@ -305,12 +301,16 @@ btoidvectorcmp(PG_FUNCTION_ARGS) for (i = 0; i < a->dim1; i++) { - if (a->values[i] != b->values[i]) + Oid aval = a->values[i]; + Oid bval = b->values[i]; + + if (aval != bval) { - if (a->values[i] > b->values[i]) - PG_RETURN_INT32(A_GREATER_THAN_B); - else - PG_RETURN_INT32(A_LESS_THAN_B); +#ifdef STRESS_SORT_INT_MIN + PG_RETURN_INT32(STRESS_SORT_INT_MIN_CMP(aval, bval)); +#else + PG_RETURN_INT32(pg_cmp_u32(aval, bval)); +#endif } } PG_RETURN_INT32(0); diff --git a/src/backend/storage/page/itemptr.c b/src/backend/storage/page/itemptr.c index af21170307..d85592951e 100644 --- a/src/backend/storage/page/itemptr.c +++ b/src/backend/storage/page/itemptr.c @@ -14,6 +14,7 @@ */ #include "postgres.h" +#include "common/int.h" #include "storage/itemptr.h" @@ -57,18 +58,11 @@ ItemPointerCompare(ItemPointer arg1, ItemPointer arg2) BlockNumber b1 = ItemPointerGetBlockNumberNoCheck(arg1); BlockNumber b2 = ItemPointerGetBlockNumberNoCheck(arg2); - if (b1 < b2) - return -1; - else if (b1 > b2) - return 1; - else if (ItemPointerGetOffsetNumberNoCheck(arg1) < - ItemPointerGetOffsetNumberNoCheck(arg2)) - return -1; - else if (ItemPointerGetOffsetNumberNoCheck(arg1) > - ItemPointerGetOffsetNumberNoCheck(arg2)) - return 1; - else - return 0; + if (b1 != b2) + return pg_cmp_u32(b1, b2); + + return pg_cmp_u16(ItemPointerGetOffsetNumberNoCheck(arg1), + ItemPointerGetOffsetNumberNoCheck(arg2)); } /* diff --git a/src/backend/utils/sort/tuplesort.c b/src/backend/utils/sort/tuplesort.c index c960cfa823..ec1ff3e656 100644 --- a/src/backend/utils/sort/tuplesort.c +++ b/src/backend/utils/sort/tuplesort.c @@ -102,6 +102,7 @@ #include <limits.h> #include "commands/tablespace.h" +#include "common/int.h" #include "miscadmin.h" #include "pg_trace.h" #include "storage/shmem.h" @@ -3138,12 +3139,18 @@ free_sort_tuple(Tuplesortstate *state, SortTuple *stup) int ssup_datum_unsigned_cmp(Datum x, Datum y, SortSupport ssup) { +#if SIZEOF_DATUM == 4 + return pg_cmp_u32(x, y); +#elif SIZEOF_DATUM == 8 + return pg_cmp_u64(x, y); +#else if (x < y) return -1; else if (x > y) return 1; else return 0; +#endif } #if SIZEOF_DATUM >= 8 @@ -3153,12 +3160,7 @@ ssup_datum_signed_cmp(Datum x, Datum y, SortSupport ssup) int64 xx = DatumGetInt64(x); int64 yy = DatumGetInt64(y); - if (xx < yy) - return -1; - else if (xx > yy) - return 1; - else - return 0; + return pg_cmp_s64(xx, yy); } #endif @@ -3168,10 +3170,5 @@ ssup_datum_int32_cmp(Datum x, Datum y, SortSupport ssup) int32 xx = DatumGetInt32(x); int32 yy = DatumGetInt32(y); - if (xx < yy) - return -1; - else if (xx > yy) - return 1; - else - return 0; + return pg_cmp_s32(xx, yy); } -- 2.39.5 (Apple Git-154) --STuNuYHiUS+fxQmC-- ^ permalink raw reply [nested|flat] 59+ messages in thread
* [PATCH v1 1/1] micro-optimize nbtcompare.c routines @ 2024-09-26 20:03 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 59+ messages in thread From: Nathan Bossart @ 2024-09-26 20:03 UTC (permalink / raw) --- src/backend/access/nbtree/nbtcompare.c | 162 ++++++++++++------------- src/backend/storage/page/itemptr.c | 18 +-- src/backend/utils/sort/tuplesort.c | 21 ++-- 3 files changed, 96 insertions(+), 105 deletions(-) diff --git a/src/backend/access/nbtree/nbtcompare.c b/src/backend/access/nbtree/nbtcompare.c index 1c72867c84..2df0c5dbe0 100644 --- a/src/backend/access/nbtree/nbtcompare.c +++ b/src/backend/access/nbtree/nbtcompare.c @@ -57,17 +57,16 @@ #include <limits.h> +#include "common/int.h" #include "utils/fmgrprotos.h" #include "utils/sortsupport.h" -#ifdef STRESS_SORT_INT_MIN -#define A_LESS_THAN_B INT_MIN -#define A_GREATER_THAN_B INT_MAX -#else -#define A_LESS_THAN_B (-1) -#define A_GREATER_THAN_B 1 -#endif - +#define STRESS_SORT_INT_MIN_CMP(a, b) \ +( \ + ((a) > (b)) ? INT_MAX : \ + ((a) < (b)) ? INT_MIN : \ + 0 \ +) Datum btboolcmp(PG_FUNCTION_ARGS) @@ -84,7 +83,11 @@ btint2cmp(PG_FUNCTION_ARGS) int16 a = PG_GETARG_INT16(0); int16 b = PG_GETARG_INT16(1); - PG_RETURN_INT32((int32) a - (int32) b); +#ifdef STRESS_SORT_INT_MIN + PG_RETURN_INT32(STRESS_SORT_INT_MIN_CMP(a, b)); +#else + PG_RETURN_INT32(pg_cmp_s16(a, b)); +#endif } static int @@ -93,7 +96,11 @@ btint2fastcmp(Datum x, Datum y, SortSupport ssup) int16 a = DatumGetInt16(x); int16 b = DatumGetInt16(y); - return (int) a - (int) b; +#ifdef STRESS_SORT_INT_MIN + return STRESS_SORT_INT_MIN_CMP(a, b); +#else + return pg_cmp_s16(a, b); +#endif } Datum @@ -111,12 +118,11 @@ btint4cmp(PG_FUNCTION_ARGS) int32 a = PG_GETARG_INT32(0); int32 b = PG_GETARG_INT32(1); - if (a > b) - PG_RETURN_INT32(A_GREATER_THAN_B); - else if (a == b) - PG_RETURN_INT32(0); - else - PG_RETURN_INT32(A_LESS_THAN_B); +#ifdef STRESS_SORT_INT_MIN + PG_RETURN_INT32(STRESS_SORT_INT_MIN_CMP(a, b)); +#else + PG_RETURN_INT32(pg_cmp_s32(a, b)); +#endif } Datum @@ -134,12 +140,11 @@ btint8cmp(PG_FUNCTION_ARGS) int64 a = PG_GETARG_INT64(0); int64 b = PG_GETARG_INT64(1); - if (a > b) - PG_RETURN_INT32(A_GREATER_THAN_B); - else if (a == b) - PG_RETURN_INT32(0); - else - PG_RETURN_INT32(A_LESS_THAN_B); +#ifdef STRESS_SORT_INT_MIN + PG_RETURN_INT32(STRESS_SORT_INT_MIN_CMP(a, b)); +#else + PG_RETURN_INT32(pg_cmp_s64(a, b)); +#endif } #if SIZEOF_DATUM < 8 @@ -149,12 +154,11 @@ btint8fastcmp(Datum x, Datum y, SortSupport ssup) int64 a = DatumGetInt64(x); int64 b = DatumGetInt64(y); - if (a > b) - return A_GREATER_THAN_B; - else if (a == b) - return 0; - else - return A_LESS_THAN_B; +#ifdef STRESS_SORT_INT_MIN + return STRESS_SORT_INT_MIN_CMP(a, b); +#else + return pg_cmp_s64(a, b); +#endif } #endif @@ -177,12 +181,11 @@ btint48cmp(PG_FUNCTION_ARGS) int32 a = PG_GETARG_INT32(0); int64 b = PG_GETARG_INT64(1); - if (a > b) - PG_RETURN_INT32(A_GREATER_THAN_B); - else if (a == b) - PG_RETURN_INT32(0); - else - PG_RETURN_INT32(A_LESS_THAN_B); +#ifdef STRESS_SORT_INT_MIN + PG_RETURN_INT32(STRESS_SORT_INT_MIN_CMP(a, b)); +#else + PG_RETURN_INT32(pg_cmp_s64(a, b)); +#endif } Datum @@ -191,12 +194,11 @@ btint84cmp(PG_FUNCTION_ARGS) int64 a = PG_GETARG_INT64(0); int32 b = PG_GETARG_INT32(1); - if (a > b) - PG_RETURN_INT32(A_GREATER_THAN_B); - else if (a == b) - PG_RETURN_INT32(0); - else - PG_RETURN_INT32(A_LESS_THAN_B); +#ifdef STRESS_SORT_INT_MIN + PG_RETURN_INT32(STRESS_SORT_INT_MIN_CMP(a, b)); +#else + PG_RETURN_INT32(pg_cmp_s64(a, b)); +#endif } Datum @@ -205,12 +207,11 @@ btint24cmp(PG_FUNCTION_ARGS) int16 a = PG_GETARG_INT16(0); int32 b = PG_GETARG_INT32(1); - if (a > b) - PG_RETURN_INT32(A_GREATER_THAN_B); - else if (a == b) - PG_RETURN_INT32(0); - else - PG_RETURN_INT32(A_LESS_THAN_B); +#ifdef STRESS_SORT_INT_MIN + PG_RETURN_INT32(STRESS_SORT_INT_MIN_CMP(a, b)); +#else + PG_RETURN_INT32(pg_cmp_s32(a, b)); +#endif } Datum @@ -219,12 +220,11 @@ btint42cmp(PG_FUNCTION_ARGS) int32 a = PG_GETARG_INT32(0); int16 b = PG_GETARG_INT16(1); - if (a > b) - PG_RETURN_INT32(A_GREATER_THAN_B); - else if (a == b) - PG_RETURN_INT32(0); - else - PG_RETURN_INT32(A_LESS_THAN_B); +#ifdef STRESS_SORT_INT_MIN + PG_RETURN_INT32(STRESS_SORT_INT_MIN_CMP(a, b)); +#else + PG_RETURN_INT32(pg_cmp_s32(a, b)); +#endif } Datum @@ -233,12 +233,11 @@ btint28cmp(PG_FUNCTION_ARGS) int16 a = PG_GETARG_INT16(0); int64 b = PG_GETARG_INT64(1); - if (a > b) - PG_RETURN_INT32(A_GREATER_THAN_B); - else if (a == b) - PG_RETURN_INT32(0); - else - PG_RETURN_INT32(A_LESS_THAN_B); +#ifdef STRESS_SORT_INT_MIN + PG_RETURN_INT32(STRESS_SORT_INT_MIN_CMP(a, b)); +#else + PG_RETURN_INT32(pg_cmp_s64(a, b)); +#endif } Datum @@ -247,12 +246,11 @@ btint82cmp(PG_FUNCTION_ARGS) int64 a = PG_GETARG_INT64(0); int16 b = PG_GETARG_INT16(1); - if (a > b) - PG_RETURN_INT32(A_GREATER_THAN_B); - else if (a == b) - PG_RETURN_INT32(0); - else - PG_RETURN_INT32(A_LESS_THAN_B); +#ifdef STRESS_SORT_INT_MIN + PG_RETURN_INT32(STRESS_SORT_INT_MIN_CMP(a, b)); +#else + PG_RETURN_INT32(pg_cmp_s64(a, b)); +#endif } Datum @@ -261,12 +259,11 @@ btoidcmp(PG_FUNCTION_ARGS) Oid a = PG_GETARG_OID(0); Oid b = PG_GETARG_OID(1); - if (a > b) - PG_RETURN_INT32(A_GREATER_THAN_B); - else if (a == b) - PG_RETURN_INT32(0); - else - PG_RETURN_INT32(A_LESS_THAN_B); +#ifdef STRESS_SORT_INT_MIN + PG_RETURN_INT32(STRESS_SORT_INT_MIN_CMP(a, b)); +#else + PG_RETURN_INT32(pg_cmp_u32(a, b)); +#endif } static int @@ -275,12 +272,11 @@ btoidfastcmp(Datum x, Datum y, SortSupport ssup) Oid a = DatumGetObjectId(x); Oid b = DatumGetObjectId(y); - if (a > b) - return A_GREATER_THAN_B; - else if (a == b) - return 0; - else - return A_LESS_THAN_B; +#ifdef STRESS_SORT_INT_MIN + return STRESS_SORT_INT_MIN_CMP(a, b); +#else + return pg_cmp_u32(a, b); +#endif } Datum @@ -305,12 +301,16 @@ btoidvectorcmp(PG_FUNCTION_ARGS) for (i = 0; i < a->dim1; i++) { - if (a->values[i] != b->values[i]) + Oid aval = a->values[i]; + Oid bval = b->values[i]; + + if (aval != bval) { - if (a->values[i] > b->values[i]) - PG_RETURN_INT32(A_GREATER_THAN_B); - else - PG_RETURN_INT32(A_LESS_THAN_B); +#ifdef STRESS_SORT_INT_MIN + PG_RETURN_INT32(STRESS_SORT_INT_MIN_CMP(aval, bval)); +#else + PG_RETURN_INT32(pg_cmp_u32(aval, bval)); +#endif } } PG_RETURN_INT32(0); diff --git a/src/backend/storage/page/itemptr.c b/src/backend/storage/page/itemptr.c index af21170307..d85592951e 100644 --- a/src/backend/storage/page/itemptr.c +++ b/src/backend/storage/page/itemptr.c @@ -14,6 +14,7 @@ */ #include "postgres.h" +#include "common/int.h" #include "storage/itemptr.h" @@ -57,18 +58,11 @@ ItemPointerCompare(ItemPointer arg1, ItemPointer arg2) BlockNumber b1 = ItemPointerGetBlockNumberNoCheck(arg1); BlockNumber b2 = ItemPointerGetBlockNumberNoCheck(arg2); - if (b1 < b2) - return -1; - else if (b1 > b2) - return 1; - else if (ItemPointerGetOffsetNumberNoCheck(arg1) < - ItemPointerGetOffsetNumberNoCheck(arg2)) - return -1; - else if (ItemPointerGetOffsetNumberNoCheck(arg1) > - ItemPointerGetOffsetNumberNoCheck(arg2)) - return 1; - else - return 0; + if (b1 != b2) + return pg_cmp_u32(b1, b2); + + return pg_cmp_u16(ItemPointerGetOffsetNumberNoCheck(arg1), + ItemPointerGetOffsetNumberNoCheck(arg2)); } /* diff --git a/src/backend/utils/sort/tuplesort.c b/src/backend/utils/sort/tuplesort.c index c960cfa823..ec1ff3e656 100644 --- a/src/backend/utils/sort/tuplesort.c +++ b/src/backend/utils/sort/tuplesort.c @@ -102,6 +102,7 @@ #include <limits.h> #include "commands/tablespace.h" +#include "common/int.h" #include "miscadmin.h" #include "pg_trace.h" #include "storage/shmem.h" @@ -3138,12 +3139,18 @@ free_sort_tuple(Tuplesortstate *state, SortTuple *stup) int ssup_datum_unsigned_cmp(Datum x, Datum y, SortSupport ssup) { +#if SIZEOF_DATUM == 4 + return pg_cmp_u32(x, y); +#elif SIZEOF_DATUM == 8 + return pg_cmp_u64(x, y); +#else if (x < y) return -1; else if (x > y) return 1; else return 0; +#endif } #if SIZEOF_DATUM >= 8 @@ -3153,12 +3160,7 @@ ssup_datum_signed_cmp(Datum x, Datum y, SortSupport ssup) int64 xx = DatumGetInt64(x); int64 yy = DatumGetInt64(y); - if (xx < yy) - return -1; - else if (xx > yy) - return 1; - else - return 0; + return pg_cmp_s64(xx, yy); } #endif @@ -3168,10 +3170,5 @@ ssup_datum_int32_cmp(Datum x, Datum y, SortSupport ssup) int32 xx = DatumGetInt32(x); int32 yy = DatumGetInt32(y); - if (xx < yy) - return -1; - else if (xx > yy) - return 1; - else - return 0; + return pg_cmp_s32(xx, yy); } -- 2.39.5 (Apple Git-154) --STuNuYHiUS+fxQmC-- ^ permalink raw reply [nested|flat] 59+ messages in thread
* [PATCH v6 4/4] run pgindent and pgperltidy @ 2026-06-30 18:24 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 59+ messages in thread From: Nathan Bossart @ 2026-06-30 18:24 UTC (permalink / raw) --- src/bin/pg_dump/pg_dump.c | 464 ++++++++++----------- src/bin/pg_dump/pg_dumpall.c | 30 +- src/bin/pg_upgrade/check.c | 16 +- src/bin/pg_upgrade/controldata.c | 2 +- src/bin/pg_upgrade/exec.c | 8 +- src/bin/pg_upgrade/multixact_rewrite.c | 80 ++-- src/bin/pg_upgrade/pg_upgrade.c | 34 +- src/bin/pg_upgrade/relfilenumber.c | 54 +-- src/bin/pg_upgrade/t/006_transfer_modes.pl | 33 +- src/bin/psql/command.c | 29 +- src/bin/psql/describe.c | 461 ++++++++++---------- 11 files changed, 601 insertions(+), 610 deletions(-) diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 65bd15ebfd2..5673268b467 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -1491,8 +1491,8 @@ setup_connection(Archive *AH, const char *dumpencoding, * Disable timeouts if supported. */ ExecuteSqlStatement(AH, "SET statement_timeout = 0"); - ExecuteSqlStatement(AH, "SET lock_timeout = 0"); - ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); + ExecuteSqlStatement(AH, "SET lock_timeout = 0"); + ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); if (AH->remoteVersion >= 170000) ExecuteSqlStatement(AH, "SET transaction_timeout = 0"); @@ -1505,10 +1505,10 @@ setup_connection(Archive *AH, const char *dumpencoding, /* * Adjust row-security mode, if supported. */ - if (dopt->enable_row_security) - ExecuteSqlStatement(AH, "SET row_security = on"); - else - ExecuteSqlStatement(AH, "SET row_security = off"); + if (dopt->enable_row_security) + ExecuteSqlStatement(AH, "SET row_security = on"); + else + ExecuteSqlStatement(AH, "SET row_security = off"); /* * For security reasons, we restrict the expansion of non-system views and @@ -1933,10 +1933,9 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) addObjectDependency(dobj, ext->dobj.dumpId); /* - * Mark the member object to have any non-initial ACLs - * dumped. (Any initial ACLs will be removed later, using data from - * pg_init_privs, so that we'll dump only the delta from the extension's - * initial setup.) + * Mark the member object to have any non-initial ACLs dumped. (Any + * initial ACLs will be removed later, using data from pg_init_privs, so + * that we'll dump only the delta from the extension's initial setup.) * * In binary upgrades, we still dump all components of the members * individually, since the idea is to exactly reproduce the database @@ -1953,7 +1952,7 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) if (fout->dopt->binary_upgrade) dobj->dump = ext->dobj.dump; else - dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); + dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); return true; } @@ -1987,9 +1986,9 @@ selectDumpableNamespace(NamespaceInfo *nsinfo, Archive *fout) else if (strcmp(nsinfo->dobj.name, "pg_catalog") == 0) { /* - * We dump out any ACLs defined in pg_catalog, if - * they are interesting (and not the original ACLs which were set at - * initdb time, see pg_init_privs). + * We dump out any ACLs defined in pg_catalog, if they are interesting + * (and not the original ACLs which were set at initdb time, see + * pg_init_privs). */ nsinfo->dobj.dump_contains = nsinfo->dobj.dump = DUMP_COMPONENT_ACL; } @@ -3296,7 +3295,7 @@ dumpDatabase(Archive *fout) "datcollate, datctype, datfrozenxid, " "datacl, acldefault('d', datdba) AS acldefault, " "datistemplate, datconnlimit, "); - appendPQExpBufferStr(dbQry, "datminmxid, "); + appendPQExpBufferStr(dbQry, "datminmxid, "); if (fout->remoteVersion >= 170000) appendPQExpBufferStr(dbQry, "datlocprovider, datlocale, datcollversion, "); else if (fout->remoteVersion >= 150000) @@ -3638,11 +3637,11 @@ dumpDatabase(Archive *fout) ii_oid, ii_relminmxid; - appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" - "FROM pg_catalog.pg_class\n" - "WHERE oid IN (%u, %u, %u, %u);\n", - LargeObjectRelationId, LargeObjectLOidPNIndexId, - LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); + appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" + "FROM pg_catalog.pg_class\n" + "WHERE oid IN (%u, %u, %u, %u);\n", + LargeObjectRelationId, LargeObjectLOidPNIndexId, + LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); lo_res = ExecuteSqlQuery(fout, loFrozenQry->data, PGRES_TUPLES_OK); @@ -4274,7 +4273,7 @@ getPolicies(Archive *fout, TableInfo tblinfo[], int numTables) printfPQExpBuffer(query, "SELECT pol.oid, pol.tableoid, pol.polrelid, pol.polname, pol.polcmd, "); - appendPQExpBufferStr(query, "pol.polpermissive, "); + appendPQExpBufferStr(query, "pol.polpermissive, "); appendPQExpBuffer(query, "CASE WHEN pol.polroles = '{0}' THEN NULL ELSE " " pg_catalog.array_to_string(ARRAY(SELECT pg_catalog.quote_ident(rolname) from pg_catalog.pg_roles WHERE oid = ANY(pol.polroles)), ', ') END AS polroles, " @@ -6633,9 +6632,9 @@ getAccessMethods(Archive *fout) * Select all access methods from pg_am table. */ appendPQExpBufferStr(query, "SELECT tableoid, oid, amname, "); - appendPQExpBufferStr(query, - "amtype, " - "amhandler::pg_catalog.regproc AS amhandler "); + appendPQExpBufferStr(query, + "amtype, " + "amhandler::pg_catalog.regproc AS amhandler "); appendPQExpBufferStr(query, "FROM pg_am"); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6827,35 +6826,35 @@ getAggregates(Archive *fout) * Find all interesting aggregates. See comment in getFuncs() for the * rationale behind the filtering logic. */ - agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" - : "p.proisagg"); + agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" + : "p.proisagg"); - appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " - "p.proname AS aggname, " - "p.pronamespace AS aggnamespace, " - "p.pronargs, p.proargtypes, " - "p.proowner, " - "p.proacl AS aggacl, " - "acldefault('f', p.proowner) AS acldefault " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s AND (" - "p.pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog') OR " - "p.proacl IS DISTINCT FROM pip.initprivs", - agg_check); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - " OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); - appendPQExpBufferChar(query, ')'); + appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " + "p.proname AS aggname, " + "p.pronamespace AS aggnamespace, " + "p.pronargs, p.proargtypes, " + "p.proowner, " + "p.proacl AS aggacl, " + "acldefault('f', p.proowner) AS acldefault " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s AND (" + "p.pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog') OR " + "p.proacl IS DISTINCT FROM pip.initprivs", + agg_check); + if (dopt->binary_upgrade) + appendPQExpBufferStr(query, + " OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6957,53 +6956,53 @@ getFuncs(Archive *fout) * include them, since we want to dump extension members individually in * that mode. Also, if they are used by casts or transforms then we need * to gather the information about them, though they won't be dumped if - * they are built-in. Also, include functions in - * pg_catalog if they have an ACL different from what's shown in - * pg_init_privs (so we have to join to pg_init_privs; annoying). + * they are built-in. Also, include functions in pg_catalog if they have + * an ACL different from what's shown in pg_init_privs (so we have to join + * to pg_init_privs; annoying). */ - not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" - : "NOT p.proisagg"); + not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" + : "NOT p.proisagg"); - appendPQExpBuffer(query, - "SELECT p.tableoid, p.oid, p.proname, p.prolang, " - "p.pronargs, p.proargtypes, p.prorettype, " - "p.proacl, " - "acldefault('f', p.proowner) AS acldefault, " - "p.pronamespace, " - "p.proowner " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s" - "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " - "WHERE classid = 'pg_proc'::regclass AND " - "objid = p.oid AND deptype = 'i')" - "\n AND (" - "\n pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog')" - "\n OR EXISTS (SELECT 1 FROM pg_cast" - "\n WHERE pg_cast.oid > %u " - "\n AND p.oid = pg_cast.castfunc)" - "\n OR EXISTS (SELECT 1 FROM pg_transform" - "\n WHERE pg_transform.oid > %u AND " - "\n (p.oid = pg_transform.trffromsql" - "\n OR p.oid = pg_transform.trftosql))", - not_agg_check, - g_last_builtin_oid, - g_last_builtin_oid); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); + appendPQExpBuffer(query, + "SELECT p.tableoid, p.oid, p.proname, p.prolang, " + "p.pronargs, p.proargtypes, p.prorettype, " + "p.proacl, " + "acldefault('f', p.proowner) AS acldefault, " + "p.pronamespace, " + "p.proowner " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s" + "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " + "WHERE classid = 'pg_proc'::regclass AND " + "objid = p.oid AND deptype = 'i')" + "\n AND (" + "\n pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog')" + "\n OR EXISTS (SELECT 1 FROM pg_cast" + "\n WHERE pg_cast.oid > %u " + "\n AND p.oid = pg_cast.castfunc)" + "\n OR EXISTS (SELECT 1 FROM pg_transform" + "\n WHERE pg_transform.oid > %u AND " + "\n (p.oid = pg_transform.trffromsql" + "\n OR p.oid = pg_transform.trftosql))", + not_agg_check, + g_last_builtin_oid, + g_last_builtin_oid); + if (dopt->binary_upgrade) appendPQExpBufferStr(query, - "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); - appendPQExpBufferChar(query, ')'); + "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferStr(query, + "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -7252,31 +7251,31 @@ getTables(Archive *fout, int *numTables) appendPQExpBufferStr(query, "c.relhasoids, "); - appendPQExpBufferStr(query, - "c.relispopulated, "); + appendPQExpBufferStr(query, + "c.relispopulated, "); - appendPQExpBufferStr(query, - "c.relreplident, "); + appendPQExpBufferStr(query, + "c.relreplident, "); - appendPQExpBufferStr(query, - "c.relrowsecurity, c.relforcerowsecurity, "); + appendPQExpBufferStr(query, + "c.relrowsecurity, c.relforcerowsecurity, "); - appendPQExpBufferStr(query, - "c.relminmxid, tc.relminmxid AS tminmxid, "); + appendPQExpBufferStr(query, + "c.relminmxid, tc.relminmxid AS tminmxid, "); - appendPQExpBufferStr(query, - "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); + appendPQExpBufferStr(query, + "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); - appendPQExpBufferStr(query, - "am.amname, "); + appendPQExpBufferStr(query, + "am.amname, "); - appendPQExpBufferStr(query, - "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); + appendPQExpBufferStr(query, + "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); - appendPQExpBufferStr(query, - "c.relispartition AS ispartition "); + appendPQExpBufferStr(query, + "c.relispartition AS ispartition "); /* * Left join to pg_depend to pick up dependency info linking sequences to @@ -7296,8 +7295,8 @@ getTables(Archive *fout, int *numTables) /* * Left join to pg_am to pick up the amname. */ - appendPQExpBufferStr(query, - "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); + appendPQExpBufferStr(query, + "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); /* * We purposefully ignore toast OIDs for partitioned tables; the reason is @@ -7868,8 +7867,8 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables) "t.reloptions AS indreloptions, "); - appendPQExpBufferStr(query, - "i.indisreplident, "); + appendPQExpBufferStr(query, + "i.indisreplident, "); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -9313,8 +9312,8 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables) appendPQExpBufferStr(q, "'' AS attcompression,\n"); - appendPQExpBufferStr(q, - "a.attidentity,\n"); + appendPQExpBufferStr(q, + "a.attidentity,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(q, @@ -10717,73 +10716,73 @@ getAdditionalACLs(Archive *fout) PQclear(res); /* Fetch initial-privileges data */ - printfPQExpBuffer(query, - "SELECT objoid, classoid, objsubid, privtype, initprivs " - "FROM pg_init_privs"); + printfPQExpBuffer(query, + "SELECT objoid, classoid, objsubid, privtype, initprivs " + "FROM pg_init_privs"); - res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); + res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); - ntups = PQntuples(res); - for (i = 0; i < ntups; i++) - { - Oid objoid = atooid(PQgetvalue(res, i, 0)); - Oid classoid = atooid(PQgetvalue(res, i, 1)); - int objsubid = atoi(PQgetvalue(res, i, 2)); - char privtype = *(PQgetvalue(res, i, 3)); - char *initprivs = PQgetvalue(res, i, 4); - CatalogId objId; - DumpableObject *dobj; + ntups = PQntuples(res); + for (i = 0; i < ntups; i++) + { + Oid objoid = atooid(PQgetvalue(res, i, 0)); + Oid classoid = atooid(PQgetvalue(res, i, 1)); + int objsubid = atoi(PQgetvalue(res, i, 2)); + char privtype = *(PQgetvalue(res, i, 3)); + char *initprivs = PQgetvalue(res, i, 4); + CatalogId objId; + DumpableObject *dobj; - objId.tableoid = classoid; - objId.oid = objoid; - dobj = findObjectByCatalogId(objId); - /* OK to ignore entries we haven't got a DumpableObject for */ - if (dobj) + objId.tableoid = classoid; + objId.oid = objoid; + dobj = findObjectByCatalogId(objId); + /* OK to ignore entries we haven't got a DumpableObject for */ + if (dobj) + { + /* Cope with sub-object initprivs */ + if (objsubid != 0) { - /* Cope with sub-object initprivs */ - if (objsubid != 0) - { - if (dobj->objType == DO_TABLE) - { - /* For a column initprivs, set the table's ACL flags */ - dobj->components |= DUMP_COMPONENT_ACL; - ((TableInfo *) dobj)->hascolumnACLs = true; - } - else - pg_log_warning("unsupported pg_init_privs entry: %u %u %d", - classoid, objoid, objsubid); - continue; - } - - /* - * We ignore any pg_init_privs.initprivs entry for the public - * schema, as explained in getNamespaces(). - */ - if (dobj->objType == DO_NAMESPACE && - strcmp(dobj->name, "public") == 0) - continue; - - /* Else it had better be of a type we think has ACLs */ - if (dobj->objType == DO_NAMESPACE || - dobj->objType == DO_TYPE || - dobj->objType == DO_FUNC || - dobj->objType == DO_AGG || - dobj->objType == DO_TABLE || - dobj->objType == DO_PROCLANG || - dobj->objType == DO_FDW || - dobj->objType == DO_FOREIGN_SERVER) + if (dobj->objType == DO_TABLE) { - DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; - - daobj->dacl.privtype = privtype; - daobj->dacl.initprivs = pstrdup(initprivs); + /* For a column initprivs, set the table's ACL flags */ + dobj->components |= DUMP_COMPONENT_ACL; + ((TableInfo *) dobj)->hascolumnACLs = true; } else pg_log_warning("unsupported pg_init_privs entry: %u %u %d", classoid, objoid, objsubid); + continue; + } + + /* + * We ignore any pg_init_privs.initprivs entry for the public + * schema, as explained in getNamespaces(). + */ + if (dobj->objType == DO_NAMESPACE && + strcmp(dobj->name, "public") == 0) + continue; + + /* Else it had better be of a type we think has ACLs */ + if (dobj->objType == DO_NAMESPACE || + dobj->objType == DO_TYPE || + dobj->objType == DO_FUNC || + dobj->objType == DO_AGG || + dobj->objType == DO_TABLE || + dobj->objType == DO_PROCLANG || + dobj->objType == DO_FDW || + dobj->objType == DO_FOREIGN_SERVER) + { + DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; + + daobj->dacl.privtype = privtype; + daobj->dacl.initprivs = pstrdup(initprivs); } + else + pg_log_warning("unsupported pg_init_privs entry: %u %u %d", + classoid, objoid, objsubid); } - PQclear(res); + } + PQclear(res); destroyPQExpBuffer(query); } @@ -11128,8 +11127,8 @@ dumpRelationStats_dumper(Archive *fout, const void *userArg, const TocEntry *te) * The results must be in the order of the relations supplied in the * parameters to ensure we remain in sync as we walk through the TOC. * - * For versions before 19, the redundant filter clause on s.tablename = - * ANY(...) seems sufficient to convince the planner to use + * For versions before 19, the redundant filter clause on s.tablename + * = ANY(...) seems sufficient to convince the planner to use * pg_class_relname_nsp_index, which avoids a full scan of pg_stats. * In newer versions, pg_stats returns the table OIDs, eliminating the * need for that hack. @@ -13469,11 +13468,11 @@ dumpFunc(Archive *fout, const FuncInfo *finfo) "pg_catalog.pg_get_function_result(p.oid) AS funcresult,\n" "proleakproof,\n"); - appendPQExpBufferStr(query, - "array_to_string(protrftypes, ' ') AS protrftypes,\n"); + appendPQExpBufferStr(query, + "array_to_string(protrftypes, ' ') AS protrftypes,\n"); - appendPQExpBufferStr(query, - "proparallel,\n"); + appendPQExpBufferStr(query, + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -14963,9 +14962,9 @@ dumpCollation(Archive *fout, const CollInfo *collinfo) /* Get collation-specific details */ appendPQExpBufferStr(query, "SELECT "); - appendPQExpBufferStr(query, - "collprovider, " - "collversion, "); + appendPQExpBufferStr(query, + "collprovider, " + "collversion, "); if (fout->remoteVersion >= 120000) appendPQExpBufferStr(query, @@ -15372,23 +15371,23 @@ dumpAgg(Archive *fout, const AggInfo *agginfo) "pg_catalog.pg_get_function_arguments(p.oid) AS funcargs,\n" "pg_catalog.pg_get_function_identity_arguments(p.oid) AS funciargs,\n"); - appendPQExpBufferStr(query, - "aggkind,\n" - "aggmtransfn,\n" - "aggminvtransfn,\n" - "aggmfinalfn,\n" - "aggmtranstype::pg_catalog.regtype,\n" - "aggfinalextra,\n" - "aggmfinalextra,\n" - "aggtransspace,\n" - "aggmtransspace,\n" - "aggminitval,\n"); + appendPQExpBufferStr(query, + "aggkind,\n" + "aggmtransfn,\n" + "aggminvtransfn,\n" + "aggmfinalfn,\n" + "aggmtranstype::pg_catalog.regtype,\n" + "aggfinalextra,\n" + "aggmfinalextra,\n" + "aggtransspace,\n" + "aggmtransspace,\n" + "aggminitval,\n"); - appendPQExpBufferStr(query, - "aggcombinefn,\n" - "aggserialfn,\n" - "aggdeserialfn,\n" - "proparallel,\n"); + appendPQExpBufferStr(query, + "aggcombinefn,\n" + "aggserialfn,\n" + "aggdeserialfn,\n" + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -16848,30 +16847,30 @@ dumpTable(Archive *fout, const TableInfo *tbinfo) appendPQExpBufferStr(query, "PREPARE getColumnACLs(pg_catalog.oid) AS\n"); - /* - * In principle we should call acldefault('c', relowner) to - * get the default ACL for a column. However, we don't - * currently store the numeric OID of the relowner in - * TableInfo. We could convert the owner name using regrole, - * but that creates a risk of failure due to concurrent role - * renames. Given that the default ACL for columns is empty - * and is likely to stay that way, it's not worth extra cycles - * and risk to avoid hard-wiring that knowledge here. - */ - appendPQExpBufferStr(query, - "SELECT at.attname, " - "at.attacl, " - "'{}' AS acldefault, " - "pip.privtype, pip.initprivs " - "FROM pg_catalog.pg_attribute at " - "LEFT JOIN pg_catalog.pg_init_privs pip ON " - "(at.attrelid = pip.objoid " - "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " - "AND at.attnum = pip.objsubid) " - "WHERE at.attrelid = $1 AND " - "NOT at.attisdropped " - "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " - "ORDER BY at.attnum"); + /* + * In principle we should call acldefault('c', relowner) to get + * the default ACL for a column. However, we don't currently + * store the numeric OID of the relowner in TableInfo. We could + * convert the owner name using regrole, but that creates a risk + * of failure due to concurrent role renames. Given that the + * default ACL for columns is empty and is likely to stay that + * way, it's not worth extra cycles and risk to avoid hard-wiring + * that knowledge here. + */ + appendPQExpBufferStr(query, + "SELECT at.attname, " + "at.attacl, " + "'{}' AS acldefault, " + "pip.privtype, pip.initprivs " + "FROM pg_catalog.pg_attribute at " + "LEFT JOIN pg_catalog.pg_init_privs pip ON " + "(at.attrelid = pip.objoid " + "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " + "AND at.attnum = pip.objsubid) " + "WHERE at.attrelid = $1 AND " + "NOT at.attisdropped " + "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " + "ORDER BY at.attnum"); ExecuteSqlStatement(fout, query->data); @@ -19165,7 +19164,7 @@ collectSequences(Archive *fout) * pg_get_sequence_data(), but we only do so for non-schema-only dumps. */ if (fout->remoteVersion < 180000 || - (!fout->dopt->dumpData && !fout->dopt->sequence_data)) + (!fout->dopt->dumpData && !fout->dopt->sequence_data)) query = "SELECT seqrelid, format_type(seqtypid, NULL), " "seqstart, seqincrement, " "seqmax, seqmin, " @@ -19227,15 +19226,14 @@ dumpSequence(Archive *fout, const TableInfo *tbinfo) qseqname = pg_strdup(fmtId(tbinfo->dobj.name)); /* - * The sequence information is gathered in a sorted - * table before any calls to dumpSequence(). See collectSequences() for - * more information. + * The sequence information is gathered in a sorted table before any calls + * to dumpSequence(). See collectSequences() for more information. */ - Assert(sequences); + Assert(sequences); - key.oid = tbinfo->dobj.catId.oid; - seq = bsearch(&key, sequences, nsequences, - sizeof(SequenceItem), SequenceItemCmp); + key.oid = tbinfo->dobj.catId.oid; + seq = bsearch(&key, sequences, nsequences, + sizeof(SequenceItem), SequenceItemCmp); /* Calculate default limits for a sequence of this type */ is_ascending = (seq->incby >= 0); diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c index e68937c9934..afcd9a218d8 100644 --- a/src/bin/pg_dump/pg_dumpall.c +++ b/src/bin/pg_dump/pg_dumpall.c @@ -785,11 +785,11 @@ dropRoles(PGconn *conn) int i_rolname; int i; - printfPQExpBuffer(buf, - "SELECT rolname " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 1", role_catalog); + printfPQExpBuffer(buf, + "SELECT rolname " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 1", role_catalog); res = executeQuery(conn, buf->data); @@ -843,16 +843,16 @@ dumpRoles(PGconn *conn) * Notes: rolconfig is dumped later, and pg_authid must be used for * extracting rolcomment regardless of role_catalog. */ - printfPQExpBuffer(buf, - "SELECT oid, rolname, rolsuper, rolinherit, " - "rolcreaterole, rolcreatedb, " - "rolcanlogin, rolconnlimit, rolpassword, " - "rolvaliduntil, rolreplication, rolbypassrls, " - "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " - "rolname = current_user AS is_current_user " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 2", role_catalog); + printfPQExpBuffer(buf, + "SELECT oid, rolname, rolsuper, rolinherit, " + "rolcreaterole, rolcreatedb, " + "rolcanlogin, rolconnlimit, rolpassword, " + "rolvaliduntil, rolreplication, rolbypassrls, " + "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " + "rolname = current_user AS is_current_user " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 2", role_catalog); res = executeQuery(conn, buf->data); diff --git a/src/bin/pg_upgrade/check.c b/src/bin/pg_upgrade/check.c index 786c1474829..f725f5ee3e2 100644 --- a/src/bin/pg_upgrade/check.c +++ b/src/bin/pg_upgrade/check.c @@ -1475,15 +1475,15 @@ check_for_incompatible_polymorphics(ClusterInfo *cluster) ", 'array_cat(anyarray,anyarray)'" ", 'array_prepend(anyelement,anyarray)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_remove(anyarray,anyelement)'" - ", 'array_replace(anyarray,anyelement,anyelement)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_remove(anyarray,anyelement)'" + ", 'array_replace(anyarray,anyelement,anyelement)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_position(anyarray,anyelement)'" - ", 'array_position(anyarray,anyelement,integer)'" - ", 'array_positions(anyarray,anyelement)'" - ", 'width_bucket(anyelement,anyarray)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_position(anyarray,anyelement)'" + ", 'array_position(anyarray,anyelement,integer)'" + ", 'array_positions(anyarray,anyelement)'" + ", 'width_bucket(anyelement,anyarray)'"); /* * The query below hardcodes FirstNormalObjectId as 16384 rather than diff --git a/src/bin/pg_upgrade/controldata.c b/src/bin/pg_upgrade/controldata.c index 8f81c9e9582..02ea02df60f 100644 --- a/src/bin/pg_upgrade/controldata.c +++ b/src/bin/pg_upgrade/controldata.c @@ -228,7 +228,7 @@ get_control_data(ClusterInfo *cluster) p++; /* remove ':' char */ cluster->controldata.chkpnt_nxtepoch = str2uint(p); - p = strchr(p, ':'); + p = strchr(p, ':'); if (p == NULL || strlen(p) <= 1) pg_fatal("%d: controldata retrieval problem", __LINE__); diff --git a/src/bin/pg_upgrade/exec.c b/src/bin/pg_upgrade/exec.c index 44355feea30..a1bdbf373e3 100644 --- a/src/bin/pg_upgrade/exec.c +++ b/src/bin/pg_upgrade/exec.c @@ -55,7 +55,7 @@ get_bin_version(ClusterInfo *cluster) if (sscanf(cmd_output, "%*s %*s %d.%d", &v1, &v2) < 1) pg_fatal("could not get pg_ctl version output from %s", cmd); - cluster->bin_version = v1 * 10000; + cluster->bin_version = v1 * 10000; } @@ -344,8 +344,8 @@ check_data_dir(ClusterInfo *cluster) check_single_dir(pg_data, "pg_subtrans"); check_single_dir(pg_data, PG_TBLSPC_DIR); check_single_dir(pg_data, "pg_twophase"); - check_single_dir(pg_data, "pg_wal"); - check_single_dir(pg_data, "pg_xact"); + check_single_dir(pg_data, "pg_wal"); + check_single_dir(pg_data, "pg_xact"); } @@ -385,7 +385,7 @@ check_bin_dir(ClusterInfo *cluster, bool check_versions) */ get_bin_version(cluster); - check_exec(cluster->bindir, "pg_resetwal", check_versions); + check_exec(cluster->bindir, "pg_resetwal", check_versions); if (cluster == &new_cluster) { diff --git a/src/bin/pg_upgrade/multixact_rewrite.c b/src/bin/pg_upgrade/multixact_rewrite.c index c45b3183684..c7a1416494d 100644 --- a/src/bin/pg_upgrade/multixact_rewrite.c +++ b/src/bin/pg_upgrade/multixact_rewrite.c @@ -61,52 +61,52 @@ rewrite_multixacts(MultiXactId from_multi, MultiXactId to_multi) * Convert old multixids, if needed, by reading them one-by-one from the * old cluster. */ - old_reader = AllocOldMultiXactRead(old_cluster.pgdata, - old_cluster.controldata.chkpnt_nxtmulti, - old_cluster.controldata.chkpnt_nxtmxoff); + old_reader = AllocOldMultiXactRead(old_cluster.pgdata, + old_cluster.controldata.chkpnt_nxtmulti, + old_cluster.controldata.chkpnt_nxtmxoff); - for (MultiXactId multi = from_multi; multi != to_multi;) - { - MultiXactMember member; - bool multixid_valid; - - /* - * Read this multixid's members. - * - * Locking-only XIDs that may be part of multi-xids don't matter - * after upgrade, as there can be no transactions running across - * upgrade. So as a small optimization, we only read one member - * from each multixid: the one updating one, or if there was no - * update, arbitrarily the first locking xid. - */ - multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); + for (MultiXactId multi = from_multi; multi != to_multi;) + { + MultiXactMember member; + bool multixid_valid; - /* - * Write the new offset to pg_multixact/offsets. - * - * Even if this multixid is invalid, we still need to write its - * offset if the *previous* multixid was valid. That's because - * when reading a multixid, the number of members is calculated - * from the difference between the two offsets. - */ - RecordMultiXactOffset(offsets_writer, multi, - (multixid_valid || prev_multixid_valid) ? next_offset : 0); + /* + * Read this multixid's members. + * + * Locking-only XIDs that may be part of multi-xids don't matter after + * upgrade, as there can be no transactions running across upgrade. So + * as a small optimization, we only read one member from each + * multixid: the one updating one, or if there was no update, + * arbitrarily the first locking xid. + */ + multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); - /* Write the members */ - if (multixid_valid) - { - RecordMultiXactMembers(members_writer, next_offset, 1, &member); - next_offset += 1; - } + /* + * Write the new offset to pg_multixact/offsets. + * + * Even if this multixid is invalid, we still need to write its offset + * if the *previous* multixid was valid. That's because when reading + * a multixid, the number of members is calculated from the difference + * between the two offsets. + */ + RecordMultiXactOffset(offsets_writer, multi, + (multixid_valid || prev_multixid_valid) ? next_offset : 0); - /* Advance to next multixid, handling wraparound */ - multi++; - if (multi < FirstMultiXactId) - multi = FirstMultiXactId; - prev_multixid_valid = multixid_valid; + /* Write the members */ + if (multixid_valid) + { + RecordMultiXactMembers(members_writer, next_offset, 1, &member); + next_offset += 1; } - FreeOldMultiXactReader(old_reader); + /* Advance to next multixid, handling wraparound */ + multi++; + if (multi < FirstMultiXactId) + multi = FirstMultiXactId; + prev_multixid_valid = multixid_valid; + } + + FreeOldMultiXactReader(old_reader); /* Write the final 'next' offset to the last SLRU page */ RecordMultiXactOffset(offsets_writer, to_multi, diff --git a/src/bin/pg_upgrade/pg_upgrade.c b/src/bin/pg_upgrade/pg_upgrade.c index c6af9035665..7366fd4627c 100644 --- a/src/bin/pg_upgrade/pg_upgrade.c +++ b/src/bin/pg_upgrade/pg_upgrade.c @@ -833,7 +833,7 @@ copy_xact_xlog_xid(void) * Determine the range of multixacts to convert. */ nxtmulti = old_cluster.controldata.chkpnt_nxtmulti; - oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; + oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; /* handle wraparound */ if (nxtmulti < FirstMultiXactId) nxtmulti = FirstMultiXactId; @@ -898,15 +898,15 @@ set_frozenxids(void) int i_datname; int i_datallowconn; - prep_status("Setting frozenxid and minmxid counters in new cluster"); + prep_status("Setting frozenxid and minmxid counters in new cluster"); conn_template1 = connectToServer(&new_cluster, "template1"); - /* set pg_database.datfrozenxid */ - PQclear(executeQueryOrDie(conn_template1, - "UPDATE pg_catalog.pg_database " - "SET datfrozenxid = '%u'", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_database.datfrozenxid */ + PQclear(executeQueryOrDie(conn_template1, + "UPDATE pg_catalog.pg_database " + "SET datfrozenxid = '%u'", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_database.datminmxid */ PQclear(executeQueryOrDie(conn_template1, @@ -942,16 +942,16 @@ set_frozenxids(void) conn = connectToServer(&new_cluster, datname); - /* set pg_class.relfrozenxid */ - PQclear(executeQueryOrDie(conn, - "UPDATE pg_catalog.pg_class " - "SET relfrozenxid = '%u' " - /* only heap, materialized view, and TOAST are vacuumed */ - "WHERE relkind IN (" - CppAsString2(RELKIND_RELATION) ", " - CppAsString2(RELKIND_MATVIEW) ", " - CppAsString2(RELKIND_TOASTVALUE) ")", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_class.relfrozenxid */ + PQclear(executeQueryOrDie(conn, + "UPDATE pg_catalog.pg_class " + "SET relfrozenxid = '%u' " + /* only heap, materialized view, and TOAST are vacuumed */ + "WHERE relkind IN (" + CppAsString2(RELKIND_RELATION) ", " + CppAsString2(RELKIND_MATVIEW) ", " + CppAsString2(RELKIND_TOASTVALUE) ")", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_class.relminmxid */ PQclear(executeQueryOrDie(conn, diff --git a/src/bin/pg_upgrade/relfilenumber.c b/src/bin/pg_upgrade/relfilenumber.c index ec2ff7acb21..6c467bdc8a5 100644 --- a/src/bin/pg_upgrade/relfilenumber.c +++ b/src/bin/pg_upgrade/relfilenumber.c @@ -587,32 +587,32 @@ transfer_relfile(FileNameMap *map, const char *type_suffix) /* Copying files might take some time, so give feedback. */ pg_log(PG_STATUS, "%s", old_file); - switch (user_opts.transfer_mode) - { - case TRANSFER_MODE_CLONE: - pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", - old_file, new_file); - cloneFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", - old_file, new_file); - copyFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY_FILE_RANGE: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", - old_file, new_file); - copyFileByRange(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_LINK: - pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", - old_file, new_file); - linkFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_SWAP: - /* swap mode is handled in its own code path */ - pg_fatal("should never happen"); - break; - } + switch (user_opts.transfer_mode) + { + case TRANSFER_MODE_CLONE: + pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", + old_file, new_file); + cloneFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", + old_file, new_file); + copyFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY_FILE_RANGE: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", + old_file, new_file); + copyFileByRange(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_LINK: + pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", + old_file, new_file); + linkFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_SWAP: + /* swap mode is handled in its own code path */ + pg_fatal("should never happen"); + break; + } } } diff --git a/src/bin/pg_upgrade/t/006_transfer_modes.pl b/src/bin/pg_upgrade/t/006_transfer_modes.pl index 9efa5dc863c..360d05c4b68 100644 --- a/src/bin/pg_upgrade/t/006_transfer_modes.pl +++ b/src/bin/pg_upgrade/t/006_transfer_modes.pl @@ -29,10 +29,8 @@ sub test_mode } $new->init(); - $new->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); - $old->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); + $new->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); + $old->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); # We can only test security labels if both the old and new installations # have dummy_seclabel. @@ -76,15 +74,14 @@ sub test_mode "CREATE TABLE test4 AS SELECT generate_series(400, 502)"); } - $old->safe_psql('postgres', - "CREATE TABLESPACE inplc_tblspc LOCATION ''"); - $old->safe_psql('postgres', - "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); - $old->safe_psql('postgres', - "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" - ); - $old->safe_psql('testdb3', - "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); + $old->safe_psql('postgres', "CREATE TABLESPACE inplc_tblspc LOCATION ''"); + $old->safe_psql('postgres', + "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); + $old->safe_psql('postgres', + "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" + ); + $old->safe_psql('testdb3', + "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); # While we are here, test handling of large objects. $old->safe_psql( @@ -152,12 +149,10 @@ sub test_mode } # Tests for in-place tablespaces. - $result = - $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); - is($result, '104', "test5 data after pg_upgrade $mode"); - $result = - $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); - is($result, '105', "test6 data after pg_upgrade $mode"); + $result = $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); + is($result, '104', "test5 data after pg_upgrade $mode"); + $result = $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); + is($result, '105', "test6 data after pg_upgrade $mode"); # Tests for large objects $result = $new->safe_psql('postgres', "SELECT lo_get(4532)"); diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index 44ef11d980e..c90bf8bbde2 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -6278,23 +6278,22 @@ get_create_object_cmd(EditableObjectType obj_type, Oid oid, * ensure the right view gets replaced. Also, check relation kind * to be sure it's a view. * - * Views may have WITH [LOCAL|CASCADED] - * CHECK OPTION. These are not part of the view definition - * returned by pg_get_viewdef() and so need to be retrieved - * separately. Materialized views may have - * arbitrary storage parameter reloptions. + * Views may have WITH [LOCAL|CASCADED] CHECK OPTION. These are + * not part of the view definition returned by pg_get_viewdef() + * and so need to be retrieved separately. Materialized views may + * have arbitrary storage parameter reloptions. */ printfPQExpBuffer(query, "/* %s */\n", _("Get view's definition and details")); - appendPQExpBuffer(query, - "SELECT nspname, relname, relkind, " - "pg_catalog.pg_get_viewdef(c.oid, true), " - "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " - "FROM pg_catalog.pg_class c " - "LEFT JOIN pg_catalog.pg_namespace n " - "ON c.relnamespace = n.oid WHERE c.oid = %u", - oid); + appendPQExpBuffer(query, + "SELECT nspname, relname, relkind, " + "pg_catalog.pg_get_viewdef(c.oid, true), " + "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " + "FROM pg_catalog.pg_class c " + "LEFT JOIN pg_catalog.pg_namespace n " + "ON c.relnamespace = n.oid WHERE c.oid = %u", + oid); break; } diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index ce99137c613..ac0c55e7aa5 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -387,19 +387,19 @@ describeFunctions(const char *functypes, const char *func_pattern, gettext_noop("stable"), gettext_noop("volatile"), gettext_noop("Volatility")); - appendPQExpBuffer(&buf, - ",\n CASE\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" - " END as \"%s\"", - gettext_noop("restricted"), - gettext_noop("safe"), - gettext_noop("unsafe"), - gettext_noop("Parallel")); + appendPQExpBuffer(&buf, + ",\n CASE\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" + " END as \"%s\"", + gettext_noop("restricted"), + gettext_noop("safe"), + gettext_noop("unsafe"), + gettext_noop("Parallel")); appendPQExpBuffer(&buf, ",\n pg_catalog.pg_get_userbyid(p.proowner) as \"%s\"" ",\n CASE WHEN prosecdef THEN '%s' ELSE '%s' END AS \"%s\"" @@ -599,8 +599,8 @@ describeFunctions(const char *functypes, const char *func_pattern, myopt.title = _("List of functions"); myopt.translate_header = true; - myopt.translate_columns = translate_columns; - myopt.n_translate_columns = lengthof(translate_columns); + myopt.translate_columns = translate_columns; + myopt.n_translate_columns = lengthof(translate_columns); printQuery(res, &myopt, pset.queryFout, false, pset.logfile); @@ -1086,38 +1086,38 @@ permissionsList(const char *pattern, bool showSystem) " ), E'\\n') AS \"%s\"", gettext_noop("Column privileges")); - appendPQExpBuffer(&buf, - ",\n pg_catalog.array_to_string(ARRAY(\n" - " SELECT polname\n" - " || CASE WHEN NOT polpermissive THEN\n" - " E' (RESTRICTIVE)'\n" - " ELSE '' END\n" - " || CASE WHEN polcmd != '*' THEN\n" - " E' (' || polcmd::pg_catalog.text || E'):'\n" - " ELSE E':'\n" - " END\n" - " || CASE WHEN polqual IS NOT NULL THEN\n" - " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" - " ELSE E''\n" - " END\n" - " || CASE WHEN polwithcheck IS NOT NULL THEN\n" - " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" - " ELSE E''\n" - " END" - " || CASE WHEN polroles <> '{0}' THEN\n" - " E'\\n to: ' || pg_catalog.array_to_string(\n" - " ARRAY(\n" - " SELECT rolname\n" - " FROM pg_catalog.pg_roles\n" - " WHERE oid = ANY (polroles)\n" - " ORDER BY 1\n" - " ), E', ')\n" - " ELSE E''\n" - " END\n" - " FROM pg_catalog.pg_policy pol\n" - " WHERE polrelid = c.oid), E'\\n')\n" - " AS \"%s\"", - gettext_noop("Policies")); + appendPQExpBuffer(&buf, + ",\n pg_catalog.array_to_string(ARRAY(\n" + " SELECT polname\n" + " || CASE WHEN NOT polpermissive THEN\n" + " E' (RESTRICTIVE)'\n" + " ELSE '' END\n" + " || CASE WHEN polcmd != '*' THEN\n" + " E' (' || polcmd::pg_catalog.text || E'):'\n" + " ELSE E':'\n" + " END\n" + " || CASE WHEN polqual IS NOT NULL THEN\n" + " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" + " ELSE E''\n" + " END\n" + " || CASE WHEN polwithcheck IS NOT NULL THEN\n" + " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" + " ELSE E''\n" + " END" + " || CASE WHEN polroles <> '{0}' THEN\n" + " E'\\n to: ' || pg_catalog.array_to_string(\n" + " ARRAY(\n" + " SELECT rolname\n" + " FROM pg_catalog.pg_roles\n" + " WHERE oid = ANY (polroles)\n" + " ORDER BY 1\n" + " ), E', ')\n" + " ELSE E''\n" + " END\n" + " FROM pg_catalog.pg_policy pol\n" + " WHERE polrelid = c.oid), E'\\n')\n" + " AS \"%s\"", + gettext_noop("Policies")); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_class c\n" " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n" @@ -1675,27 +1675,27 @@ describeOneTableDetails(const char *schemaname, char *footers[3] = {NULL, NULL, NULL}; printfPQExpBuffer(&buf, "/* %s */\n", _("Get sequence information")); - appendPQExpBuffer(&buf, - "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" - " seqstart AS \"%s\",\n" - " seqmin AS \"%s\",\n" - " seqmax AS \"%s\",\n" - " seqincrement AS \"%s\",\n" - " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" - " seqcache AS \"%s\"\n", - gettext_noop("Type"), - gettext_noop("Start"), - gettext_noop("Minimum"), - gettext_noop("Maximum"), - gettext_noop("Increment"), - gettext_noop("yes"), - gettext_noop("no"), - gettext_noop("Cycles?"), - gettext_noop("Cache")); - appendPQExpBuffer(&buf, - "FROM pg_catalog.pg_sequence\n" - "WHERE seqrelid = '%s';", - oid); + appendPQExpBuffer(&buf, + "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" + " seqstart AS \"%s\",\n" + " seqmin AS \"%s\",\n" + " seqmax AS \"%s\",\n" + " seqincrement AS \"%s\",\n" + " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" + " seqcache AS \"%s\"\n", + gettext_noop("Type"), + gettext_noop("Start"), + gettext_noop("Minimum"), + gettext_noop("Maximum"), + gettext_noop("Increment"), + gettext_noop("yes"), + gettext_noop("no"), + gettext_noop("Cycles?"), + gettext_noop("Cache")); + appendPQExpBuffer(&buf, + "FROM pg_catalog.pg_sequence\n" + "WHERE seqrelid = '%s';", + oid); res = PSQLexec(buf.data); if (!res) @@ -1913,7 +1913,7 @@ describeOneTableDetails(const char *schemaname, appendPQExpBufferStr(&buf, ",\n (SELECT c.collname FROM pg_catalog.pg_collation c, pg_catalog.pg_type t\n" " WHERE c.oid = a.attcollation AND t.oid = a.atttypid AND a.attcollation <> t.typcollation) AS attcollation"); attcoll_col = cols++; - appendPQExpBufferStr(&buf, ",\n a.attidentity"); + appendPQExpBufferStr(&buf, ",\n a.attidentity"); attidentity_col = cols++; if (pset.sversion >= 120000) appendPQExpBufferStr(&buf, ",\n a.attgenerated"); @@ -2326,7 +2326,7 @@ describeOneTableDetails(const char *schemaname, CppAsString2(CONSTRAINT_EXCLUSION) ") AND " "condeferred) AS condeferred,\n"); - appendPQExpBufferStr(&buf, "i.indisreplident,\n"); + appendPQExpBufferStr(&buf, "i.indisreplident,\n"); if (pset.sversion >= 150000) appendPQExpBufferStr(&buf, "i.indnullsnotdistinct,\n"); @@ -2431,7 +2431,7 @@ describeOneTableDetails(const char *schemaname, "pg_catalog.pg_get_indexdef(i.indexrelid, 0, true),\n " "pg_catalog.pg_get_constraintdef(con.oid, true), " "contype, condeferrable, condeferred"); - appendPQExpBufferStr(&buf, ", i.indisreplident"); + appendPQExpBufferStr(&buf, ", i.indisreplident"); appendPQExpBufferStr(&buf, ", c2.reltablespace"); if (pset.sversion >= 180000) appendPQExpBufferStr(&buf, ", con.conperiod"); @@ -2682,81 +2682,80 @@ describeOneTableDetails(const char *schemaname, PQclear(result); /* print any row-level policies */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get row-level policies for this table")); - appendPQExpBufferStr(&buf, "SELECT pol.polname,"); - appendPQExpBufferStr(&buf, - " pol.polpermissive,\n"); - appendPQExpBuffer(&buf, - " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" - " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" - " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" - " CASE pol.polcmd\n" - " WHEN 'r' THEN 'SELECT'\n" - " WHEN 'a' THEN 'INSERT'\n" - " WHEN 'w' THEN 'UPDATE'\n" - " WHEN 'd' THEN 'DELETE'\n" - " END AS cmd\n" - "FROM pg_catalog.pg_policy pol\n" - "WHERE pol.polrelid = '%s' ORDER BY 1;", - oid); + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get row-level policies for this table")); + appendPQExpBufferStr(&buf, "SELECT pol.polname,"); + appendPQExpBufferStr(&buf, + " pol.polpermissive,\n"); + appendPQExpBuffer(&buf, + " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" + " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" + " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" + " CASE pol.polcmd\n" + " WHEN 'r' THEN 'SELECT'\n" + " WHEN 'a' THEN 'INSERT'\n" + " WHEN 'w' THEN 'UPDATE'\n" + " WHEN 'd' THEN 'DELETE'\n" + " END AS cmd\n" + "FROM pg_catalog.pg_policy pol\n" + "WHERE pol.polrelid = '%s' ORDER BY 1;", + oid); - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - /* - * Handle cases where RLS is enabled and there are policies, or - * there aren't policies, or RLS isn't enabled but there are - * policies - */ - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies:")); + /* + * Handle cases where RLS is enabled and there are policies, or there + * aren't policies, or RLS isn't enabled but there are policies + */ + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies:")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled):")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled):")); - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); - if (!tableinfo.rowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (row security disabled):")); + if (!tableinfo.rowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (row security disabled):")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " POLICY \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " POLICY \"%s\"", + PQgetvalue(result, i, 0)); - if (*(PQgetvalue(result, i, 1)) == 'f') - appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); + if (*(PQgetvalue(result, i, 1)) == 'f') + appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); - if (!PQgetisnull(result, i, 5)) - appendPQExpBuffer(&buf, " FOR %s", - PQgetvalue(result, i, 5)); + if (!PQgetisnull(result, i, 5)) + appendPQExpBuffer(&buf, " FOR %s", + PQgetvalue(result, i, 5)); - if (!PQgetisnull(result, i, 2)) - { - appendPQExpBuffer(&buf, "\n TO %s", - PQgetvalue(result, i, 2)); - } + if (!PQgetisnull(result, i, 2)) + { + appendPQExpBuffer(&buf, "\n TO %s", + PQgetvalue(result, i, 2)); + } - if (!PQgetisnull(result, i, 3)) - appendPQExpBuffer(&buf, "\n USING (%s)", - PQgetvalue(result, i, 3)); + if (!PQgetisnull(result, i, 3)) + appendPQExpBuffer(&buf, "\n USING (%s)", + PQgetvalue(result, i, 3)); - if (!PQgetisnull(result, i, 4)) - appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", - PQgetvalue(result, i, 4)); + if (!PQgetisnull(result, i, 4)) + appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", + PQgetvalue(result, i, 4)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* print any extended statistics */ if (pset.sversion >= 140000) @@ -3025,115 +3024,115 @@ describeOneTableDetails(const char *schemaname, } /* print any publications */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get publications that publish this table")); - if (pset.sversion >= 150000) + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get publications that publish this table")); + if (pset.sversion >= 150000) + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" + " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" + "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" + "UNION\n" + "SELECT pubname\n" + " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" + " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" + " (SELECT pg_catalog.string_agg(attname, ', ')\n" + " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" + " pg_catalog.pg_attribute\n" + " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" + " ELSE NULL END) " + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" + "WHERE pr.prrelid = '%s'\n", + oid, oid, oid); + + if (pset.sversion >= 190000) { + /* + * Skip entries where this relation appears in the + * publication's EXCEPT list. + */ appendPQExpBuffer(&buf, + " AND NOT pr.prexcept\n" + "UNION\n" "SELECT pubname\n" " , NULL\n" " , NULL\n" "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" - " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" - "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" - "UNION\n" - "SELECT pubname\n" - " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" - " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" - " (SELECT pg_catalog.string_agg(attname, ', ')\n" - " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" - " pg_catalog.pg_attribute\n" - " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" - " ELSE NULL END) " - "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" - "WHERE pr.prrelid = '%s'\n", + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + " AND NOT EXISTS (\n" + " SELECT 1\n" + " FROM pg_catalog.pg_publication_rel pr\n" + " WHERE pr.prpubid = p.oid AND\n" + " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" + "ORDER BY 1;", oid, oid, oid); - - if (pset.sversion >= 190000) - { - /* - * Skip entries where this relation appears in the - * publication's EXCEPT list. - */ - appendPQExpBuffer(&buf, - " AND NOT pr.prexcept\n" - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - " AND NOT EXISTS (\n" - " SELECT 1\n" - " FROM pg_catalog.pg_publication_rel pr\n" - " WHERE pr.prpubid = p.oid AND\n" - " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" - "ORDER BY 1;", - oid, oid, oid); - } - else - { - appendPQExpBuffer(&buf, - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - "ORDER BY 1;", - oid); - } } else { appendPQExpBuffer(&buf, + "UNION\n" "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - "WHERE pr.prrelid = '%s'\n" - "UNION ALL\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" + " , NULL\n" + " , NULL\n" "FROM pg_catalog.pg_publication p\n" "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" "ORDER BY 1;", - oid, oid); + oid); } + } + else + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + "WHERE pr.prrelid = '%s'\n" + "UNION ALL\n" + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + "ORDER BY 1;", + oid, oid); + } - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - if (tuples > 0) - printTableAddFooter(&cont, _("Included in publications:")); + if (tuples > 0) + printTableAddFooter(&cont, _("Included in publications:")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " \"%s\"", + PQgetvalue(result, i, 0)); - /* column list (if any) */ - if (!PQgetisnull(result, i, 2)) - appendPQExpBuffer(&buf, " (%s)", - PQgetvalue(result, i, 2)); + /* column list (if any) */ + if (!PQgetisnull(result, i, 2)) + appendPQExpBuffer(&buf, " (%s)", + PQgetvalue(result, i, 2)); - /* row filter (if any) */ - if (!PQgetisnull(result, i, 1)) - appendPQExpBuffer(&buf, " WHERE %s", - PQgetvalue(result, i, 1)); + /* row filter (if any) */ + if (!PQgetisnull(result, i, 1)) + appendPQExpBuffer(&buf, " WHERE %s", + PQgetvalue(result, i, 1)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* Print publications where the table is in the EXCEPT clause */ if (pset.sversion >= 190000) @@ -3805,7 +3804,7 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) ncols++; } appendPQExpBufferStr(&buf, "\n, r.rolreplication"); - appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); + appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_roles r\n"); @@ -3860,8 +3859,8 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) if (strcmp(PQgetvalue(res, i, (verbose ? 9 : 8)), "t") == 0) add_role_attribute(&buf, _("Replication")); - if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) - add_role_attribute(&buf, _("Bypass RLS")); + if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) + add_role_attribute(&buf, _("Bypass RLS")); conns = atoi(PQgetvalue(res, i, 6)); if (conns >= 0) @@ -5155,14 +5154,14 @@ listCollations(const char *pattern, bool verbose, bool showSystem) gettext_noop("Schema"), gettext_noop("Name")); - appendPQExpBuffer(&buf, - " CASE c.collprovider " - "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " - "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " - "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " - "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " - "END AS \"%s\",\n", - gettext_noop("Provider")); + appendPQExpBuffer(&buf, + " CASE c.collprovider " + "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " + "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " + "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " + "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " + "END AS \"%s\",\n", + gettext_noop("Provider")); appendPQExpBuffer(&buf, " c.collcollate AS \"%s\",\n" -- 2.50.1 (Apple Git-155) --aHl3HfeiUuO3zeNC-- ^ permalink raw reply [nested|flat] 59+ messages in thread
* [PATCH v6 4/4] run pgindent and pgperltidy @ 2026-06-30 18:24 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 59+ messages in thread From: Nathan Bossart @ 2026-06-30 18:24 UTC (permalink / raw) --- src/bin/pg_dump/pg_dump.c | 464 ++++++++++----------- src/bin/pg_dump/pg_dumpall.c | 30 +- src/bin/pg_upgrade/check.c | 16 +- src/bin/pg_upgrade/controldata.c | 2 +- src/bin/pg_upgrade/exec.c | 8 +- src/bin/pg_upgrade/multixact_rewrite.c | 80 ++-- src/bin/pg_upgrade/pg_upgrade.c | 34 +- src/bin/pg_upgrade/relfilenumber.c | 54 +-- src/bin/pg_upgrade/t/006_transfer_modes.pl | 33 +- src/bin/psql/command.c | 29 +- src/bin/psql/describe.c | 461 ++++++++++---------- 11 files changed, 601 insertions(+), 610 deletions(-) diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 65bd15ebfd2..5673268b467 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -1491,8 +1491,8 @@ setup_connection(Archive *AH, const char *dumpencoding, * Disable timeouts if supported. */ ExecuteSqlStatement(AH, "SET statement_timeout = 0"); - ExecuteSqlStatement(AH, "SET lock_timeout = 0"); - ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); + ExecuteSqlStatement(AH, "SET lock_timeout = 0"); + ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); if (AH->remoteVersion >= 170000) ExecuteSqlStatement(AH, "SET transaction_timeout = 0"); @@ -1505,10 +1505,10 @@ setup_connection(Archive *AH, const char *dumpencoding, /* * Adjust row-security mode, if supported. */ - if (dopt->enable_row_security) - ExecuteSqlStatement(AH, "SET row_security = on"); - else - ExecuteSqlStatement(AH, "SET row_security = off"); + if (dopt->enable_row_security) + ExecuteSqlStatement(AH, "SET row_security = on"); + else + ExecuteSqlStatement(AH, "SET row_security = off"); /* * For security reasons, we restrict the expansion of non-system views and @@ -1933,10 +1933,9 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) addObjectDependency(dobj, ext->dobj.dumpId); /* - * Mark the member object to have any non-initial ACLs - * dumped. (Any initial ACLs will be removed later, using data from - * pg_init_privs, so that we'll dump only the delta from the extension's - * initial setup.) + * Mark the member object to have any non-initial ACLs dumped. (Any + * initial ACLs will be removed later, using data from pg_init_privs, so + * that we'll dump only the delta from the extension's initial setup.) * * In binary upgrades, we still dump all components of the members * individually, since the idea is to exactly reproduce the database @@ -1953,7 +1952,7 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) if (fout->dopt->binary_upgrade) dobj->dump = ext->dobj.dump; else - dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); + dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); return true; } @@ -1987,9 +1986,9 @@ selectDumpableNamespace(NamespaceInfo *nsinfo, Archive *fout) else if (strcmp(nsinfo->dobj.name, "pg_catalog") == 0) { /* - * We dump out any ACLs defined in pg_catalog, if - * they are interesting (and not the original ACLs which were set at - * initdb time, see pg_init_privs). + * We dump out any ACLs defined in pg_catalog, if they are interesting + * (and not the original ACLs which were set at initdb time, see + * pg_init_privs). */ nsinfo->dobj.dump_contains = nsinfo->dobj.dump = DUMP_COMPONENT_ACL; } @@ -3296,7 +3295,7 @@ dumpDatabase(Archive *fout) "datcollate, datctype, datfrozenxid, " "datacl, acldefault('d', datdba) AS acldefault, " "datistemplate, datconnlimit, "); - appendPQExpBufferStr(dbQry, "datminmxid, "); + appendPQExpBufferStr(dbQry, "datminmxid, "); if (fout->remoteVersion >= 170000) appendPQExpBufferStr(dbQry, "datlocprovider, datlocale, datcollversion, "); else if (fout->remoteVersion >= 150000) @@ -3638,11 +3637,11 @@ dumpDatabase(Archive *fout) ii_oid, ii_relminmxid; - appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" - "FROM pg_catalog.pg_class\n" - "WHERE oid IN (%u, %u, %u, %u);\n", - LargeObjectRelationId, LargeObjectLOidPNIndexId, - LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); + appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" + "FROM pg_catalog.pg_class\n" + "WHERE oid IN (%u, %u, %u, %u);\n", + LargeObjectRelationId, LargeObjectLOidPNIndexId, + LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); lo_res = ExecuteSqlQuery(fout, loFrozenQry->data, PGRES_TUPLES_OK); @@ -4274,7 +4273,7 @@ getPolicies(Archive *fout, TableInfo tblinfo[], int numTables) printfPQExpBuffer(query, "SELECT pol.oid, pol.tableoid, pol.polrelid, pol.polname, pol.polcmd, "); - appendPQExpBufferStr(query, "pol.polpermissive, "); + appendPQExpBufferStr(query, "pol.polpermissive, "); appendPQExpBuffer(query, "CASE WHEN pol.polroles = '{0}' THEN NULL ELSE " " pg_catalog.array_to_string(ARRAY(SELECT pg_catalog.quote_ident(rolname) from pg_catalog.pg_roles WHERE oid = ANY(pol.polroles)), ', ') END AS polroles, " @@ -6633,9 +6632,9 @@ getAccessMethods(Archive *fout) * Select all access methods from pg_am table. */ appendPQExpBufferStr(query, "SELECT tableoid, oid, amname, "); - appendPQExpBufferStr(query, - "amtype, " - "amhandler::pg_catalog.regproc AS amhandler "); + appendPQExpBufferStr(query, + "amtype, " + "amhandler::pg_catalog.regproc AS amhandler "); appendPQExpBufferStr(query, "FROM pg_am"); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6827,35 +6826,35 @@ getAggregates(Archive *fout) * Find all interesting aggregates. See comment in getFuncs() for the * rationale behind the filtering logic. */ - agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" - : "p.proisagg"); + agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" + : "p.proisagg"); - appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " - "p.proname AS aggname, " - "p.pronamespace AS aggnamespace, " - "p.pronargs, p.proargtypes, " - "p.proowner, " - "p.proacl AS aggacl, " - "acldefault('f', p.proowner) AS acldefault " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s AND (" - "p.pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog') OR " - "p.proacl IS DISTINCT FROM pip.initprivs", - agg_check); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - " OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); - appendPQExpBufferChar(query, ')'); + appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " + "p.proname AS aggname, " + "p.pronamespace AS aggnamespace, " + "p.pronargs, p.proargtypes, " + "p.proowner, " + "p.proacl AS aggacl, " + "acldefault('f', p.proowner) AS acldefault " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s AND (" + "p.pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog') OR " + "p.proacl IS DISTINCT FROM pip.initprivs", + agg_check); + if (dopt->binary_upgrade) + appendPQExpBufferStr(query, + " OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6957,53 +6956,53 @@ getFuncs(Archive *fout) * include them, since we want to dump extension members individually in * that mode. Also, if they are used by casts or transforms then we need * to gather the information about them, though they won't be dumped if - * they are built-in. Also, include functions in - * pg_catalog if they have an ACL different from what's shown in - * pg_init_privs (so we have to join to pg_init_privs; annoying). + * they are built-in. Also, include functions in pg_catalog if they have + * an ACL different from what's shown in pg_init_privs (so we have to join + * to pg_init_privs; annoying). */ - not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" - : "NOT p.proisagg"); + not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" + : "NOT p.proisagg"); - appendPQExpBuffer(query, - "SELECT p.tableoid, p.oid, p.proname, p.prolang, " - "p.pronargs, p.proargtypes, p.prorettype, " - "p.proacl, " - "acldefault('f', p.proowner) AS acldefault, " - "p.pronamespace, " - "p.proowner " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s" - "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " - "WHERE classid = 'pg_proc'::regclass AND " - "objid = p.oid AND deptype = 'i')" - "\n AND (" - "\n pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog')" - "\n OR EXISTS (SELECT 1 FROM pg_cast" - "\n WHERE pg_cast.oid > %u " - "\n AND p.oid = pg_cast.castfunc)" - "\n OR EXISTS (SELECT 1 FROM pg_transform" - "\n WHERE pg_transform.oid > %u AND " - "\n (p.oid = pg_transform.trffromsql" - "\n OR p.oid = pg_transform.trftosql))", - not_agg_check, - g_last_builtin_oid, - g_last_builtin_oid); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); + appendPQExpBuffer(query, + "SELECT p.tableoid, p.oid, p.proname, p.prolang, " + "p.pronargs, p.proargtypes, p.prorettype, " + "p.proacl, " + "acldefault('f', p.proowner) AS acldefault, " + "p.pronamespace, " + "p.proowner " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s" + "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " + "WHERE classid = 'pg_proc'::regclass AND " + "objid = p.oid AND deptype = 'i')" + "\n AND (" + "\n pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog')" + "\n OR EXISTS (SELECT 1 FROM pg_cast" + "\n WHERE pg_cast.oid > %u " + "\n AND p.oid = pg_cast.castfunc)" + "\n OR EXISTS (SELECT 1 FROM pg_transform" + "\n WHERE pg_transform.oid > %u AND " + "\n (p.oid = pg_transform.trffromsql" + "\n OR p.oid = pg_transform.trftosql))", + not_agg_check, + g_last_builtin_oid, + g_last_builtin_oid); + if (dopt->binary_upgrade) appendPQExpBufferStr(query, - "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); - appendPQExpBufferChar(query, ')'); + "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferStr(query, + "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -7252,31 +7251,31 @@ getTables(Archive *fout, int *numTables) appendPQExpBufferStr(query, "c.relhasoids, "); - appendPQExpBufferStr(query, - "c.relispopulated, "); + appendPQExpBufferStr(query, + "c.relispopulated, "); - appendPQExpBufferStr(query, - "c.relreplident, "); + appendPQExpBufferStr(query, + "c.relreplident, "); - appendPQExpBufferStr(query, - "c.relrowsecurity, c.relforcerowsecurity, "); + appendPQExpBufferStr(query, + "c.relrowsecurity, c.relforcerowsecurity, "); - appendPQExpBufferStr(query, - "c.relminmxid, tc.relminmxid AS tminmxid, "); + appendPQExpBufferStr(query, + "c.relminmxid, tc.relminmxid AS tminmxid, "); - appendPQExpBufferStr(query, - "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); + appendPQExpBufferStr(query, + "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); - appendPQExpBufferStr(query, - "am.amname, "); + appendPQExpBufferStr(query, + "am.amname, "); - appendPQExpBufferStr(query, - "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); + appendPQExpBufferStr(query, + "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); - appendPQExpBufferStr(query, - "c.relispartition AS ispartition "); + appendPQExpBufferStr(query, + "c.relispartition AS ispartition "); /* * Left join to pg_depend to pick up dependency info linking sequences to @@ -7296,8 +7295,8 @@ getTables(Archive *fout, int *numTables) /* * Left join to pg_am to pick up the amname. */ - appendPQExpBufferStr(query, - "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); + appendPQExpBufferStr(query, + "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); /* * We purposefully ignore toast OIDs for partitioned tables; the reason is @@ -7868,8 +7867,8 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables) "t.reloptions AS indreloptions, "); - appendPQExpBufferStr(query, - "i.indisreplident, "); + appendPQExpBufferStr(query, + "i.indisreplident, "); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -9313,8 +9312,8 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables) appendPQExpBufferStr(q, "'' AS attcompression,\n"); - appendPQExpBufferStr(q, - "a.attidentity,\n"); + appendPQExpBufferStr(q, + "a.attidentity,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(q, @@ -10717,73 +10716,73 @@ getAdditionalACLs(Archive *fout) PQclear(res); /* Fetch initial-privileges data */ - printfPQExpBuffer(query, - "SELECT objoid, classoid, objsubid, privtype, initprivs " - "FROM pg_init_privs"); + printfPQExpBuffer(query, + "SELECT objoid, classoid, objsubid, privtype, initprivs " + "FROM pg_init_privs"); - res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); + res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); - ntups = PQntuples(res); - for (i = 0; i < ntups; i++) - { - Oid objoid = atooid(PQgetvalue(res, i, 0)); - Oid classoid = atooid(PQgetvalue(res, i, 1)); - int objsubid = atoi(PQgetvalue(res, i, 2)); - char privtype = *(PQgetvalue(res, i, 3)); - char *initprivs = PQgetvalue(res, i, 4); - CatalogId objId; - DumpableObject *dobj; + ntups = PQntuples(res); + for (i = 0; i < ntups; i++) + { + Oid objoid = atooid(PQgetvalue(res, i, 0)); + Oid classoid = atooid(PQgetvalue(res, i, 1)); + int objsubid = atoi(PQgetvalue(res, i, 2)); + char privtype = *(PQgetvalue(res, i, 3)); + char *initprivs = PQgetvalue(res, i, 4); + CatalogId objId; + DumpableObject *dobj; - objId.tableoid = classoid; - objId.oid = objoid; - dobj = findObjectByCatalogId(objId); - /* OK to ignore entries we haven't got a DumpableObject for */ - if (dobj) + objId.tableoid = classoid; + objId.oid = objoid; + dobj = findObjectByCatalogId(objId); + /* OK to ignore entries we haven't got a DumpableObject for */ + if (dobj) + { + /* Cope with sub-object initprivs */ + if (objsubid != 0) { - /* Cope with sub-object initprivs */ - if (objsubid != 0) - { - if (dobj->objType == DO_TABLE) - { - /* For a column initprivs, set the table's ACL flags */ - dobj->components |= DUMP_COMPONENT_ACL; - ((TableInfo *) dobj)->hascolumnACLs = true; - } - else - pg_log_warning("unsupported pg_init_privs entry: %u %u %d", - classoid, objoid, objsubid); - continue; - } - - /* - * We ignore any pg_init_privs.initprivs entry for the public - * schema, as explained in getNamespaces(). - */ - if (dobj->objType == DO_NAMESPACE && - strcmp(dobj->name, "public") == 0) - continue; - - /* Else it had better be of a type we think has ACLs */ - if (dobj->objType == DO_NAMESPACE || - dobj->objType == DO_TYPE || - dobj->objType == DO_FUNC || - dobj->objType == DO_AGG || - dobj->objType == DO_TABLE || - dobj->objType == DO_PROCLANG || - dobj->objType == DO_FDW || - dobj->objType == DO_FOREIGN_SERVER) + if (dobj->objType == DO_TABLE) { - DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; - - daobj->dacl.privtype = privtype; - daobj->dacl.initprivs = pstrdup(initprivs); + /* For a column initprivs, set the table's ACL flags */ + dobj->components |= DUMP_COMPONENT_ACL; + ((TableInfo *) dobj)->hascolumnACLs = true; } else pg_log_warning("unsupported pg_init_privs entry: %u %u %d", classoid, objoid, objsubid); + continue; + } + + /* + * We ignore any pg_init_privs.initprivs entry for the public + * schema, as explained in getNamespaces(). + */ + if (dobj->objType == DO_NAMESPACE && + strcmp(dobj->name, "public") == 0) + continue; + + /* Else it had better be of a type we think has ACLs */ + if (dobj->objType == DO_NAMESPACE || + dobj->objType == DO_TYPE || + dobj->objType == DO_FUNC || + dobj->objType == DO_AGG || + dobj->objType == DO_TABLE || + dobj->objType == DO_PROCLANG || + dobj->objType == DO_FDW || + dobj->objType == DO_FOREIGN_SERVER) + { + DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; + + daobj->dacl.privtype = privtype; + daobj->dacl.initprivs = pstrdup(initprivs); } + else + pg_log_warning("unsupported pg_init_privs entry: %u %u %d", + classoid, objoid, objsubid); } - PQclear(res); + } + PQclear(res); destroyPQExpBuffer(query); } @@ -11128,8 +11127,8 @@ dumpRelationStats_dumper(Archive *fout, const void *userArg, const TocEntry *te) * The results must be in the order of the relations supplied in the * parameters to ensure we remain in sync as we walk through the TOC. * - * For versions before 19, the redundant filter clause on s.tablename = - * ANY(...) seems sufficient to convince the planner to use + * For versions before 19, the redundant filter clause on s.tablename + * = ANY(...) seems sufficient to convince the planner to use * pg_class_relname_nsp_index, which avoids a full scan of pg_stats. * In newer versions, pg_stats returns the table OIDs, eliminating the * need for that hack. @@ -13469,11 +13468,11 @@ dumpFunc(Archive *fout, const FuncInfo *finfo) "pg_catalog.pg_get_function_result(p.oid) AS funcresult,\n" "proleakproof,\n"); - appendPQExpBufferStr(query, - "array_to_string(protrftypes, ' ') AS protrftypes,\n"); + appendPQExpBufferStr(query, + "array_to_string(protrftypes, ' ') AS protrftypes,\n"); - appendPQExpBufferStr(query, - "proparallel,\n"); + appendPQExpBufferStr(query, + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -14963,9 +14962,9 @@ dumpCollation(Archive *fout, const CollInfo *collinfo) /* Get collation-specific details */ appendPQExpBufferStr(query, "SELECT "); - appendPQExpBufferStr(query, - "collprovider, " - "collversion, "); + appendPQExpBufferStr(query, + "collprovider, " + "collversion, "); if (fout->remoteVersion >= 120000) appendPQExpBufferStr(query, @@ -15372,23 +15371,23 @@ dumpAgg(Archive *fout, const AggInfo *agginfo) "pg_catalog.pg_get_function_arguments(p.oid) AS funcargs,\n" "pg_catalog.pg_get_function_identity_arguments(p.oid) AS funciargs,\n"); - appendPQExpBufferStr(query, - "aggkind,\n" - "aggmtransfn,\n" - "aggminvtransfn,\n" - "aggmfinalfn,\n" - "aggmtranstype::pg_catalog.regtype,\n" - "aggfinalextra,\n" - "aggmfinalextra,\n" - "aggtransspace,\n" - "aggmtransspace,\n" - "aggminitval,\n"); + appendPQExpBufferStr(query, + "aggkind,\n" + "aggmtransfn,\n" + "aggminvtransfn,\n" + "aggmfinalfn,\n" + "aggmtranstype::pg_catalog.regtype,\n" + "aggfinalextra,\n" + "aggmfinalextra,\n" + "aggtransspace,\n" + "aggmtransspace,\n" + "aggminitval,\n"); - appendPQExpBufferStr(query, - "aggcombinefn,\n" - "aggserialfn,\n" - "aggdeserialfn,\n" - "proparallel,\n"); + appendPQExpBufferStr(query, + "aggcombinefn,\n" + "aggserialfn,\n" + "aggdeserialfn,\n" + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -16848,30 +16847,30 @@ dumpTable(Archive *fout, const TableInfo *tbinfo) appendPQExpBufferStr(query, "PREPARE getColumnACLs(pg_catalog.oid) AS\n"); - /* - * In principle we should call acldefault('c', relowner) to - * get the default ACL for a column. However, we don't - * currently store the numeric OID of the relowner in - * TableInfo. We could convert the owner name using regrole, - * but that creates a risk of failure due to concurrent role - * renames. Given that the default ACL for columns is empty - * and is likely to stay that way, it's not worth extra cycles - * and risk to avoid hard-wiring that knowledge here. - */ - appendPQExpBufferStr(query, - "SELECT at.attname, " - "at.attacl, " - "'{}' AS acldefault, " - "pip.privtype, pip.initprivs " - "FROM pg_catalog.pg_attribute at " - "LEFT JOIN pg_catalog.pg_init_privs pip ON " - "(at.attrelid = pip.objoid " - "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " - "AND at.attnum = pip.objsubid) " - "WHERE at.attrelid = $1 AND " - "NOT at.attisdropped " - "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " - "ORDER BY at.attnum"); + /* + * In principle we should call acldefault('c', relowner) to get + * the default ACL for a column. However, we don't currently + * store the numeric OID of the relowner in TableInfo. We could + * convert the owner name using regrole, but that creates a risk + * of failure due to concurrent role renames. Given that the + * default ACL for columns is empty and is likely to stay that + * way, it's not worth extra cycles and risk to avoid hard-wiring + * that knowledge here. + */ + appendPQExpBufferStr(query, + "SELECT at.attname, " + "at.attacl, " + "'{}' AS acldefault, " + "pip.privtype, pip.initprivs " + "FROM pg_catalog.pg_attribute at " + "LEFT JOIN pg_catalog.pg_init_privs pip ON " + "(at.attrelid = pip.objoid " + "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " + "AND at.attnum = pip.objsubid) " + "WHERE at.attrelid = $1 AND " + "NOT at.attisdropped " + "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " + "ORDER BY at.attnum"); ExecuteSqlStatement(fout, query->data); @@ -19165,7 +19164,7 @@ collectSequences(Archive *fout) * pg_get_sequence_data(), but we only do so for non-schema-only dumps. */ if (fout->remoteVersion < 180000 || - (!fout->dopt->dumpData && !fout->dopt->sequence_data)) + (!fout->dopt->dumpData && !fout->dopt->sequence_data)) query = "SELECT seqrelid, format_type(seqtypid, NULL), " "seqstart, seqincrement, " "seqmax, seqmin, " @@ -19227,15 +19226,14 @@ dumpSequence(Archive *fout, const TableInfo *tbinfo) qseqname = pg_strdup(fmtId(tbinfo->dobj.name)); /* - * The sequence information is gathered in a sorted - * table before any calls to dumpSequence(). See collectSequences() for - * more information. + * The sequence information is gathered in a sorted table before any calls + * to dumpSequence(). See collectSequences() for more information. */ - Assert(sequences); + Assert(sequences); - key.oid = tbinfo->dobj.catId.oid; - seq = bsearch(&key, sequences, nsequences, - sizeof(SequenceItem), SequenceItemCmp); + key.oid = tbinfo->dobj.catId.oid; + seq = bsearch(&key, sequences, nsequences, + sizeof(SequenceItem), SequenceItemCmp); /* Calculate default limits for a sequence of this type */ is_ascending = (seq->incby >= 0); diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c index e68937c9934..afcd9a218d8 100644 --- a/src/bin/pg_dump/pg_dumpall.c +++ b/src/bin/pg_dump/pg_dumpall.c @@ -785,11 +785,11 @@ dropRoles(PGconn *conn) int i_rolname; int i; - printfPQExpBuffer(buf, - "SELECT rolname " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 1", role_catalog); + printfPQExpBuffer(buf, + "SELECT rolname " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 1", role_catalog); res = executeQuery(conn, buf->data); @@ -843,16 +843,16 @@ dumpRoles(PGconn *conn) * Notes: rolconfig is dumped later, and pg_authid must be used for * extracting rolcomment regardless of role_catalog. */ - printfPQExpBuffer(buf, - "SELECT oid, rolname, rolsuper, rolinherit, " - "rolcreaterole, rolcreatedb, " - "rolcanlogin, rolconnlimit, rolpassword, " - "rolvaliduntil, rolreplication, rolbypassrls, " - "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " - "rolname = current_user AS is_current_user " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 2", role_catalog); + printfPQExpBuffer(buf, + "SELECT oid, rolname, rolsuper, rolinherit, " + "rolcreaterole, rolcreatedb, " + "rolcanlogin, rolconnlimit, rolpassword, " + "rolvaliduntil, rolreplication, rolbypassrls, " + "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " + "rolname = current_user AS is_current_user " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 2", role_catalog); res = executeQuery(conn, buf->data); diff --git a/src/bin/pg_upgrade/check.c b/src/bin/pg_upgrade/check.c index 786c1474829..f725f5ee3e2 100644 --- a/src/bin/pg_upgrade/check.c +++ b/src/bin/pg_upgrade/check.c @@ -1475,15 +1475,15 @@ check_for_incompatible_polymorphics(ClusterInfo *cluster) ", 'array_cat(anyarray,anyarray)'" ", 'array_prepend(anyelement,anyarray)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_remove(anyarray,anyelement)'" - ", 'array_replace(anyarray,anyelement,anyelement)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_remove(anyarray,anyelement)'" + ", 'array_replace(anyarray,anyelement,anyelement)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_position(anyarray,anyelement)'" - ", 'array_position(anyarray,anyelement,integer)'" - ", 'array_positions(anyarray,anyelement)'" - ", 'width_bucket(anyelement,anyarray)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_position(anyarray,anyelement)'" + ", 'array_position(anyarray,anyelement,integer)'" + ", 'array_positions(anyarray,anyelement)'" + ", 'width_bucket(anyelement,anyarray)'"); /* * The query below hardcodes FirstNormalObjectId as 16384 rather than diff --git a/src/bin/pg_upgrade/controldata.c b/src/bin/pg_upgrade/controldata.c index 8f81c9e9582..02ea02df60f 100644 --- a/src/bin/pg_upgrade/controldata.c +++ b/src/bin/pg_upgrade/controldata.c @@ -228,7 +228,7 @@ get_control_data(ClusterInfo *cluster) p++; /* remove ':' char */ cluster->controldata.chkpnt_nxtepoch = str2uint(p); - p = strchr(p, ':'); + p = strchr(p, ':'); if (p == NULL || strlen(p) <= 1) pg_fatal("%d: controldata retrieval problem", __LINE__); diff --git a/src/bin/pg_upgrade/exec.c b/src/bin/pg_upgrade/exec.c index 44355feea30..a1bdbf373e3 100644 --- a/src/bin/pg_upgrade/exec.c +++ b/src/bin/pg_upgrade/exec.c @@ -55,7 +55,7 @@ get_bin_version(ClusterInfo *cluster) if (sscanf(cmd_output, "%*s %*s %d.%d", &v1, &v2) < 1) pg_fatal("could not get pg_ctl version output from %s", cmd); - cluster->bin_version = v1 * 10000; + cluster->bin_version = v1 * 10000; } @@ -344,8 +344,8 @@ check_data_dir(ClusterInfo *cluster) check_single_dir(pg_data, "pg_subtrans"); check_single_dir(pg_data, PG_TBLSPC_DIR); check_single_dir(pg_data, "pg_twophase"); - check_single_dir(pg_data, "pg_wal"); - check_single_dir(pg_data, "pg_xact"); + check_single_dir(pg_data, "pg_wal"); + check_single_dir(pg_data, "pg_xact"); } @@ -385,7 +385,7 @@ check_bin_dir(ClusterInfo *cluster, bool check_versions) */ get_bin_version(cluster); - check_exec(cluster->bindir, "pg_resetwal", check_versions); + check_exec(cluster->bindir, "pg_resetwal", check_versions); if (cluster == &new_cluster) { diff --git a/src/bin/pg_upgrade/multixact_rewrite.c b/src/bin/pg_upgrade/multixact_rewrite.c index c45b3183684..c7a1416494d 100644 --- a/src/bin/pg_upgrade/multixact_rewrite.c +++ b/src/bin/pg_upgrade/multixact_rewrite.c @@ -61,52 +61,52 @@ rewrite_multixacts(MultiXactId from_multi, MultiXactId to_multi) * Convert old multixids, if needed, by reading them one-by-one from the * old cluster. */ - old_reader = AllocOldMultiXactRead(old_cluster.pgdata, - old_cluster.controldata.chkpnt_nxtmulti, - old_cluster.controldata.chkpnt_nxtmxoff); + old_reader = AllocOldMultiXactRead(old_cluster.pgdata, + old_cluster.controldata.chkpnt_nxtmulti, + old_cluster.controldata.chkpnt_nxtmxoff); - for (MultiXactId multi = from_multi; multi != to_multi;) - { - MultiXactMember member; - bool multixid_valid; - - /* - * Read this multixid's members. - * - * Locking-only XIDs that may be part of multi-xids don't matter - * after upgrade, as there can be no transactions running across - * upgrade. So as a small optimization, we only read one member - * from each multixid: the one updating one, or if there was no - * update, arbitrarily the first locking xid. - */ - multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); + for (MultiXactId multi = from_multi; multi != to_multi;) + { + MultiXactMember member; + bool multixid_valid; - /* - * Write the new offset to pg_multixact/offsets. - * - * Even if this multixid is invalid, we still need to write its - * offset if the *previous* multixid was valid. That's because - * when reading a multixid, the number of members is calculated - * from the difference between the two offsets. - */ - RecordMultiXactOffset(offsets_writer, multi, - (multixid_valid || prev_multixid_valid) ? next_offset : 0); + /* + * Read this multixid's members. + * + * Locking-only XIDs that may be part of multi-xids don't matter after + * upgrade, as there can be no transactions running across upgrade. So + * as a small optimization, we only read one member from each + * multixid: the one updating one, or if there was no update, + * arbitrarily the first locking xid. + */ + multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); - /* Write the members */ - if (multixid_valid) - { - RecordMultiXactMembers(members_writer, next_offset, 1, &member); - next_offset += 1; - } + /* + * Write the new offset to pg_multixact/offsets. + * + * Even if this multixid is invalid, we still need to write its offset + * if the *previous* multixid was valid. That's because when reading + * a multixid, the number of members is calculated from the difference + * between the two offsets. + */ + RecordMultiXactOffset(offsets_writer, multi, + (multixid_valid || prev_multixid_valid) ? next_offset : 0); - /* Advance to next multixid, handling wraparound */ - multi++; - if (multi < FirstMultiXactId) - multi = FirstMultiXactId; - prev_multixid_valid = multixid_valid; + /* Write the members */ + if (multixid_valid) + { + RecordMultiXactMembers(members_writer, next_offset, 1, &member); + next_offset += 1; } - FreeOldMultiXactReader(old_reader); + /* Advance to next multixid, handling wraparound */ + multi++; + if (multi < FirstMultiXactId) + multi = FirstMultiXactId; + prev_multixid_valid = multixid_valid; + } + + FreeOldMultiXactReader(old_reader); /* Write the final 'next' offset to the last SLRU page */ RecordMultiXactOffset(offsets_writer, to_multi, diff --git a/src/bin/pg_upgrade/pg_upgrade.c b/src/bin/pg_upgrade/pg_upgrade.c index c6af9035665..7366fd4627c 100644 --- a/src/bin/pg_upgrade/pg_upgrade.c +++ b/src/bin/pg_upgrade/pg_upgrade.c @@ -833,7 +833,7 @@ copy_xact_xlog_xid(void) * Determine the range of multixacts to convert. */ nxtmulti = old_cluster.controldata.chkpnt_nxtmulti; - oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; + oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; /* handle wraparound */ if (nxtmulti < FirstMultiXactId) nxtmulti = FirstMultiXactId; @@ -898,15 +898,15 @@ set_frozenxids(void) int i_datname; int i_datallowconn; - prep_status("Setting frozenxid and minmxid counters in new cluster"); + prep_status("Setting frozenxid and minmxid counters in new cluster"); conn_template1 = connectToServer(&new_cluster, "template1"); - /* set pg_database.datfrozenxid */ - PQclear(executeQueryOrDie(conn_template1, - "UPDATE pg_catalog.pg_database " - "SET datfrozenxid = '%u'", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_database.datfrozenxid */ + PQclear(executeQueryOrDie(conn_template1, + "UPDATE pg_catalog.pg_database " + "SET datfrozenxid = '%u'", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_database.datminmxid */ PQclear(executeQueryOrDie(conn_template1, @@ -942,16 +942,16 @@ set_frozenxids(void) conn = connectToServer(&new_cluster, datname); - /* set pg_class.relfrozenxid */ - PQclear(executeQueryOrDie(conn, - "UPDATE pg_catalog.pg_class " - "SET relfrozenxid = '%u' " - /* only heap, materialized view, and TOAST are vacuumed */ - "WHERE relkind IN (" - CppAsString2(RELKIND_RELATION) ", " - CppAsString2(RELKIND_MATVIEW) ", " - CppAsString2(RELKIND_TOASTVALUE) ")", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_class.relfrozenxid */ + PQclear(executeQueryOrDie(conn, + "UPDATE pg_catalog.pg_class " + "SET relfrozenxid = '%u' " + /* only heap, materialized view, and TOAST are vacuumed */ + "WHERE relkind IN (" + CppAsString2(RELKIND_RELATION) ", " + CppAsString2(RELKIND_MATVIEW) ", " + CppAsString2(RELKIND_TOASTVALUE) ")", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_class.relminmxid */ PQclear(executeQueryOrDie(conn, diff --git a/src/bin/pg_upgrade/relfilenumber.c b/src/bin/pg_upgrade/relfilenumber.c index ec2ff7acb21..6c467bdc8a5 100644 --- a/src/bin/pg_upgrade/relfilenumber.c +++ b/src/bin/pg_upgrade/relfilenumber.c @@ -587,32 +587,32 @@ transfer_relfile(FileNameMap *map, const char *type_suffix) /* Copying files might take some time, so give feedback. */ pg_log(PG_STATUS, "%s", old_file); - switch (user_opts.transfer_mode) - { - case TRANSFER_MODE_CLONE: - pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", - old_file, new_file); - cloneFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", - old_file, new_file); - copyFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY_FILE_RANGE: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", - old_file, new_file); - copyFileByRange(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_LINK: - pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", - old_file, new_file); - linkFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_SWAP: - /* swap mode is handled in its own code path */ - pg_fatal("should never happen"); - break; - } + switch (user_opts.transfer_mode) + { + case TRANSFER_MODE_CLONE: + pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", + old_file, new_file); + cloneFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", + old_file, new_file); + copyFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY_FILE_RANGE: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", + old_file, new_file); + copyFileByRange(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_LINK: + pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", + old_file, new_file); + linkFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_SWAP: + /* swap mode is handled in its own code path */ + pg_fatal("should never happen"); + break; + } } } diff --git a/src/bin/pg_upgrade/t/006_transfer_modes.pl b/src/bin/pg_upgrade/t/006_transfer_modes.pl index 9efa5dc863c..360d05c4b68 100644 --- a/src/bin/pg_upgrade/t/006_transfer_modes.pl +++ b/src/bin/pg_upgrade/t/006_transfer_modes.pl @@ -29,10 +29,8 @@ sub test_mode } $new->init(); - $new->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); - $old->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); + $new->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); + $old->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); # We can only test security labels if both the old and new installations # have dummy_seclabel. @@ -76,15 +74,14 @@ sub test_mode "CREATE TABLE test4 AS SELECT generate_series(400, 502)"); } - $old->safe_psql('postgres', - "CREATE TABLESPACE inplc_tblspc LOCATION ''"); - $old->safe_psql('postgres', - "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); - $old->safe_psql('postgres', - "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" - ); - $old->safe_psql('testdb3', - "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); + $old->safe_psql('postgres', "CREATE TABLESPACE inplc_tblspc LOCATION ''"); + $old->safe_psql('postgres', + "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); + $old->safe_psql('postgres', + "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" + ); + $old->safe_psql('testdb3', + "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); # While we are here, test handling of large objects. $old->safe_psql( @@ -152,12 +149,10 @@ sub test_mode } # Tests for in-place tablespaces. - $result = - $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); - is($result, '104', "test5 data after pg_upgrade $mode"); - $result = - $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); - is($result, '105', "test6 data after pg_upgrade $mode"); + $result = $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); + is($result, '104', "test5 data after pg_upgrade $mode"); + $result = $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); + is($result, '105', "test6 data after pg_upgrade $mode"); # Tests for large objects $result = $new->safe_psql('postgres', "SELECT lo_get(4532)"); diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index 44ef11d980e..c90bf8bbde2 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -6278,23 +6278,22 @@ get_create_object_cmd(EditableObjectType obj_type, Oid oid, * ensure the right view gets replaced. Also, check relation kind * to be sure it's a view. * - * Views may have WITH [LOCAL|CASCADED] - * CHECK OPTION. These are not part of the view definition - * returned by pg_get_viewdef() and so need to be retrieved - * separately. Materialized views may have - * arbitrary storage parameter reloptions. + * Views may have WITH [LOCAL|CASCADED] CHECK OPTION. These are + * not part of the view definition returned by pg_get_viewdef() + * and so need to be retrieved separately. Materialized views may + * have arbitrary storage parameter reloptions. */ printfPQExpBuffer(query, "/* %s */\n", _("Get view's definition and details")); - appendPQExpBuffer(query, - "SELECT nspname, relname, relkind, " - "pg_catalog.pg_get_viewdef(c.oid, true), " - "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " - "FROM pg_catalog.pg_class c " - "LEFT JOIN pg_catalog.pg_namespace n " - "ON c.relnamespace = n.oid WHERE c.oid = %u", - oid); + appendPQExpBuffer(query, + "SELECT nspname, relname, relkind, " + "pg_catalog.pg_get_viewdef(c.oid, true), " + "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " + "FROM pg_catalog.pg_class c " + "LEFT JOIN pg_catalog.pg_namespace n " + "ON c.relnamespace = n.oid WHERE c.oid = %u", + oid); break; } diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index ce99137c613..ac0c55e7aa5 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -387,19 +387,19 @@ describeFunctions(const char *functypes, const char *func_pattern, gettext_noop("stable"), gettext_noop("volatile"), gettext_noop("Volatility")); - appendPQExpBuffer(&buf, - ",\n CASE\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" - " END as \"%s\"", - gettext_noop("restricted"), - gettext_noop("safe"), - gettext_noop("unsafe"), - gettext_noop("Parallel")); + appendPQExpBuffer(&buf, + ",\n CASE\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" + " END as \"%s\"", + gettext_noop("restricted"), + gettext_noop("safe"), + gettext_noop("unsafe"), + gettext_noop("Parallel")); appendPQExpBuffer(&buf, ",\n pg_catalog.pg_get_userbyid(p.proowner) as \"%s\"" ",\n CASE WHEN prosecdef THEN '%s' ELSE '%s' END AS \"%s\"" @@ -599,8 +599,8 @@ describeFunctions(const char *functypes, const char *func_pattern, myopt.title = _("List of functions"); myopt.translate_header = true; - myopt.translate_columns = translate_columns; - myopt.n_translate_columns = lengthof(translate_columns); + myopt.translate_columns = translate_columns; + myopt.n_translate_columns = lengthof(translate_columns); printQuery(res, &myopt, pset.queryFout, false, pset.logfile); @@ -1086,38 +1086,38 @@ permissionsList(const char *pattern, bool showSystem) " ), E'\\n') AS \"%s\"", gettext_noop("Column privileges")); - appendPQExpBuffer(&buf, - ",\n pg_catalog.array_to_string(ARRAY(\n" - " SELECT polname\n" - " || CASE WHEN NOT polpermissive THEN\n" - " E' (RESTRICTIVE)'\n" - " ELSE '' END\n" - " || CASE WHEN polcmd != '*' THEN\n" - " E' (' || polcmd::pg_catalog.text || E'):'\n" - " ELSE E':'\n" - " END\n" - " || CASE WHEN polqual IS NOT NULL THEN\n" - " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" - " ELSE E''\n" - " END\n" - " || CASE WHEN polwithcheck IS NOT NULL THEN\n" - " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" - " ELSE E''\n" - " END" - " || CASE WHEN polroles <> '{0}' THEN\n" - " E'\\n to: ' || pg_catalog.array_to_string(\n" - " ARRAY(\n" - " SELECT rolname\n" - " FROM pg_catalog.pg_roles\n" - " WHERE oid = ANY (polroles)\n" - " ORDER BY 1\n" - " ), E', ')\n" - " ELSE E''\n" - " END\n" - " FROM pg_catalog.pg_policy pol\n" - " WHERE polrelid = c.oid), E'\\n')\n" - " AS \"%s\"", - gettext_noop("Policies")); + appendPQExpBuffer(&buf, + ",\n pg_catalog.array_to_string(ARRAY(\n" + " SELECT polname\n" + " || CASE WHEN NOT polpermissive THEN\n" + " E' (RESTRICTIVE)'\n" + " ELSE '' END\n" + " || CASE WHEN polcmd != '*' THEN\n" + " E' (' || polcmd::pg_catalog.text || E'):'\n" + " ELSE E':'\n" + " END\n" + " || CASE WHEN polqual IS NOT NULL THEN\n" + " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" + " ELSE E''\n" + " END\n" + " || CASE WHEN polwithcheck IS NOT NULL THEN\n" + " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" + " ELSE E''\n" + " END" + " || CASE WHEN polroles <> '{0}' THEN\n" + " E'\\n to: ' || pg_catalog.array_to_string(\n" + " ARRAY(\n" + " SELECT rolname\n" + " FROM pg_catalog.pg_roles\n" + " WHERE oid = ANY (polroles)\n" + " ORDER BY 1\n" + " ), E', ')\n" + " ELSE E''\n" + " END\n" + " FROM pg_catalog.pg_policy pol\n" + " WHERE polrelid = c.oid), E'\\n')\n" + " AS \"%s\"", + gettext_noop("Policies")); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_class c\n" " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n" @@ -1675,27 +1675,27 @@ describeOneTableDetails(const char *schemaname, char *footers[3] = {NULL, NULL, NULL}; printfPQExpBuffer(&buf, "/* %s */\n", _("Get sequence information")); - appendPQExpBuffer(&buf, - "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" - " seqstart AS \"%s\",\n" - " seqmin AS \"%s\",\n" - " seqmax AS \"%s\",\n" - " seqincrement AS \"%s\",\n" - " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" - " seqcache AS \"%s\"\n", - gettext_noop("Type"), - gettext_noop("Start"), - gettext_noop("Minimum"), - gettext_noop("Maximum"), - gettext_noop("Increment"), - gettext_noop("yes"), - gettext_noop("no"), - gettext_noop("Cycles?"), - gettext_noop("Cache")); - appendPQExpBuffer(&buf, - "FROM pg_catalog.pg_sequence\n" - "WHERE seqrelid = '%s';", - oid); + appendPQExpBuffer(&buf, + "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" + " seqstart AS \"%s\",\n" + " seqmin AS \"%s\",\n" + " seqmax AS \"%s\",\n" + " seqincrement AS \"%s\",\n" + " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" + " seqcache AS \"%s\"\n", + gettext_noop("Type"), + gettext_noop("Start"), + gettext_noop("Minimum"), + gettext_noop("Maximum"), + gettext_noop("Increment"), + gettext_noop("yes"), + gettext_noop("no"), + gettext_noop("Cycles?"), + gettext_noop("Cache")); + appendPQExpBuffer(&buf, + "FROM pg_catalog.pg_sequence\n" + "WHERE seqrelid = '%s';", + oid); res = PSQLexec(buf.data); if (!res) @@ -1913,7 +1913,7 @@ describeOneTableDetails(const char *schemaname, appendPQExpBufferStr(&buf, ",\n (SELECT c.collname FROM pg_catalog.pg_collation c, pg_catalog.pg_type t\n" " WHERE c.oid = a.attcollation AND t.oid = a.atttypid AND a.attcollation <> t.typcollation) AS attcollation"); attcoll_col = cols++; - appendPQExpBufferStr(&buf, ",\n a.attidentity"); + appendPQExpBufferStr(&buf, ",\n a.attidentity"); attidentity_col = cols++; if (pset.sversion >= 120000) appendPQExpBufferStr(&buf, ",\n a.attgenerated"); @@ -2326,7 +2326,7 @@ describeOneTableDetails(const char *schemaname, CppAsString2(CONSTRAINT_EXCLUSION) ") AND " "condeferred) AS condeferred,\n"); - appendPQExpBufferStr(&buf, "i.indisreplident,\n"); + appendPQExpBufferStr(&buf, "i.indisreplident,\n"); if (pset.sversion >= 150000) appendPQExpBufferStr(&buf, "i.indnullsnotdistinct,\n"); @@ -2431,7 +2431,7 @@ describeOneTableDetails(const char *schemaname, "pg_catalog.pg_get_indexdef(i.indexrelid, 0, true),\n " "pg_catalog.pg_get_constraintdef(con.oid, true), " "contype, condeferrable, condeferred"); - appendPQExpBufferStr(&buf, ", i.indisreplident"); + appendPQExpBufferStr(&buf, ", i.indisreplident"); appendPQExpBufferStr(&buf, ", c2.reltablespace"); if (pset.sversion >= 180000) appendPQExpBufferStr(&buf, ", con.conperiod"); @@ -2682,81 +2682,80 @@ describeOneTableDetails(const char *schemaname, PQclear(result); /* print any row-level policies */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get row-level policies for this table")); - appendPQExpBufferStr(&buf, "SELECT pol.polname,"); - appendPQExpBufferStr(&buf, - " pol.polpermissive,\n"); - appendPQExpBuffer(&buf, - " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" - " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" - " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" - " CASE pol.polcmd\n" - " WHEN 'r' THEN 'SELECT'\n" - " WHEN 'a' THEN 'INSERT'\n" - " WHEN 'w' THEN 'UPDATE'\n" - " WHEN 'd' THEN 'DELETE'\n" - " END AS cmd\n" - "FROM pg_catalog.pg_policy pol\n" - "WHERE pol.polrelid = '%s' ORDER BY 1;", - oid); + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get row-level policies for this table")); + appendPQExpBufferStr(&buf, "SELECT pol.polname,"); + appendPQExpBufferStr(&buf, + " pol.polpermissive,\n"); + appendPQExpBuffer(&buf, + " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" + " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" + " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" + " CASE pol.polcmd\n" + " WHEN 'r' THEN 'SELECT'\n" + " WHEN 'a' THEN 'INSERT'\n" + " WHEN 'w' THEN 'UPDATE'\n" + " WHEN 'd' THEN 'DELETE'\n" + " END AS cmd\n" + "FROM pg_catalog.pg_policy pol\n" + "WHERE pol.polrelid = '%s' ORDER BY 1;", + oid); - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - /* - * Handle cases where RLS is enabled and there are policies, or - * there aren't policies, or RLS isn't enabled but there are - * policies - */ - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies:")); + /* + * Handle cases where RLS is enabled and there are policies, or there + * aren't policies, or RLS isn't enabled but there are policies + */ + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies:")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled):")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled):")); - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); - if (!tableinfo.rowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (row security disabled):")); + if (!tableinfo.rowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (row security disabled):")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " POLICY \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " POLICY \"%s\"", + PQgetvalue(result, i, 0)); - if (*(PQgetvalue(result, i, 1)) == 'f') - appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); + if (*(PQgetvalue(result, i, 1)) == 'f') + appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); - if (!PQgetisnull(result, i, 5)) - appendPQExpBuffer(&buf, " FOR %s", - PQgetvalue(result, i, 5)); + if (!PQgetisnull(result, i, 5)) + appendPQExpBuffer(&buf, " FOR %s", + PQgetvalue(result, i, 5)); - if (!PQgetisnull(result, i, 2)) - { - appendPQExpBuffer(&buf, "\n TO %s", - PQgetvalue(result, i, 2)); - } + if (!PQgetisnull(result, i, 2)) + { + appendPQExpBuffer(&buf, "\n TO %s", + PQgetvalue(result, i, 2)); + } - if (!PQgetisnull(result, i, 3)) - appendPQExpBuffer(&buf, "\n USING (%s)", - PQgetvalue(result, i, 3)); + if (!PQgetisnull(result, i, 3)) + appendPQExpBuffer(&buf, "\n USING (%s)", + PQgetvalue(result, i, 3)); - if (!PQgetisnull(result, i, 4)) - appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", - PQgetvalue(result, i, 4)); + if (!PQgetisnull(result, i, 4)) + appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", + PQgetvalue(result, i, 4)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* print any extended statistics */ if (pset.sversion >= 140000) @@ -3025,115 +3024,115 @@ describeOneTableDetails(const char *schemaname, } /* print any publications */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get publications that publish this table")); - if (pset.sversion >= 150000) + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get publications that publish this table")); + if (pset.sversion >= 150000) + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" + " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" + "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" + "UNION\n" + "SELECT pubname\n" + " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" + " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" + " (SELECT pg_catalog.string_agg(attname, ', ')\n" + " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" + " pg_catalog.pg_attribute\n" + " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" + " ELSE NULL END) " + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" + "WHERE pr.prrelid = '%s'\n", + oid, oid, oid); + + if (pset.sversion >= 190000) { + /* + * Skip entries where this relation appears in the + * publication's EXCEPT list. + */ appendPQExpBuffer(&buf, + " AND NOT pr.prexcept\n" + "UNION\n" "SELECT pubname\n" " , NULL\n" " , NULL\n" "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" - " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" - "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" - "UNION\n" - "SELECT pubname\n" - " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" - " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" - " (SELECT pg_catalog.string_agg(attname, ', ')\n" - " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" - " pg_catalog.pg_attribute\n" - " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" - " ELSE NULL END) " - "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" - "WHERE pr.prrelid = '%s'\n", + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + " AND NOT EXISTS (\n" + " SELECT 1\n" + " FROM pg_catalog.pg_publication_rel pr\n" + " WHERE pr.prpubid = p.oid AND\n" + " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" + "ORDER BY 1;", oid, oid, oid); - - if (pset.sversion >= 190000) - { - /* - * Skip entries where this relation appears in the - * publication's EXCEPT list. - */ - appendPQExpBuffer(&buf, - " AND NOT pr.prexcept\n" - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - " AND NOT EXISTS (\n" - " SELECT 1\n" - " FROM pg_catalog.pg_publication_rel pr\n" - " WHERE pr.prpubid = p.oid AND\n" - " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" - "ORDER BY 1;", - oid, oid, oid); - } - else - { - appendPQExpBuffer(&buf, - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - "ORDER BY 1;", - oid); - } } else { appendPQExpBuffer(&buf, + "UNION\n" "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - "WHERE pr.prrelid = '%s'\n" - "UNION ALL\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" + " , NULL\n" + " , NULL\n" "FROM pg_catalog.pg_publication p\n" "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" "ORDER BY 1;", - oid, oid); + oid); } + } + else + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + "WHERE pr.prrelid = '%s'\n" + "UNION ALL\n" + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + "ORDER BY 1;", + oid, oid); + } - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - if (tuples > 0) - printTableAddFooter(&cont, _("Included in publications:")); + if (tuples > 0) + printTableAddFooter(&cont, _("Included in publications:")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " \"%s\"", + PQgetvalue(result, i, 0)); - /* column list (if any) */ - if (!PQgetisnull(result, i, 2)) - appendPQExpBuffer(&buf, " (%s)", - PQgetvalue(result, i, 2)); + /* column list (if any) */ + if (!PQgetisnull(result, i, 2)) + appendPQExpBuffer(&buf, " (%s)", + PQgetvalue(result, i, 2)); - /* row filter (if any) */ - if (!PQgetisnull(result, i, 1)) - appendPQExpBuffer(&buf, " WHERE %s", - PQgetvalue(result, i, 1)); + /* row filter (if any) */ + if (!PQgetisnull(result, i, 1)) + appendPQExpBuffer(&buf, " WHERE %s", + PQgetvalue(result, i, 1)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* Print publications where the table is in the EXCEPT clause */ if (pset.sversion >= 190000) @@ -3805,7 +3804,7 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) ncols++; } appendPQExpBufferStr(&buf, "\n, r.rolreplication"); - appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); + appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_roles r\n"); @@ -3860,8 +3859,8 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) if (strcmp(PQgetvalue(res, i, (verbose ? 9 : 8)), "t") == 0) add_role_attribute(&buf, _("Replication")); - if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) - add_role_attribute(&buf, _("Bypass RLS")); + if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) + add_role_attribute(&buf, _("Bypass RLS")); conns = atoi(PQgetvalue(res, i, 6)); if (conns >= 0) @@ -5155,14 +5154,14 @@ listCollations(const char *pattern, bool verbose, bool showSystem) gettext_noop("Schema"), gettext_noop("Name")); - appendPQExpBuffer(&buf, - " CASE c.collprovider " - "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " - "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " - "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " - "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " - "END AS \"%s\",\n", - gettext_noop("Provider")); + appendPQExpBuffer(&buf, + " CASE c.collprovider " + "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " + "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " + "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " + "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " + "END AS \"%s\",\n", + gettext_noop("Provider")); appendPQExpBuffer(&buf, " c.collcollate AS \"%s\",\n" -- 2.50.1 (Apple Git-155) --aHl3HfeiUuO3zeNC-- ^ permalink raw reply [nested|flat] 59+ messages in thread
* [PATCH v6 4/4] run pgindent and pgperltidy @ 2026-06-30 18:24 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 59+ messages in thread From: Nathan Bossart @ 2026-06-30 18:24 UTC (permalink / raw) --- src/bin/pg_dump/pg_dump.c | 464 ++++++++++----------- src/bin/pg_dump/pg_dumpall.c | 30 +- src/bin/pg_upgrade/check.c | 16 +- src/bin/pg_upgrade/controldata.c | 2 +- src/bin/pg_upgrade/exec.c | 8 +- src/bin/pg_upgrade/multixact_rewrite.c | 80 ++-- src/bin/pg_upgrade/pg_upgrade.c | 34 +- src/bin/pg_upgrade/relfilenumber.c | 54 +-- src/bin/pg_upgrade/t/006_transfer_modes.pl | 33 +- src/bin/psql/command.c | 29 +- src/bin/psql/describe.c | 461 ++++++++++---------- 11 files changed, 601 insertions(+), 610 deletions(-) diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 65bd15ebfd2..5673268b467 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -1491,8 +1491,8 @@ setup_connection(Archive *AH, const char *dumpencoding, * Disable timeouts if supported. */ ExecuteSqlStatement(AH, "SET statement_timeout = 0"); - ExecuteSqlStatement(AH, "SET lock_timeout = 0"); - ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); + ExecuteSqlStatement(AH, "SET lock_timeout = 0"); + ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); if (AH->remoteVersion >= 170000) ExecuteSqlStatement(AH, "SET transaction_timeout = 0"); @@ -1505,10 +1505,10 @@ setup_connection(Archive *AH, const char *dumpencoding, /* * Adjust row-security mode, if supported. */ - if (dopt->enable_row_security) - ExecuteSqlStatement(AH, "SET row_security = on"); - else - ExecuteSqlStatement(AH, "SET row_security = off"); + if (dopt->enable_row_security) + ExecuteSqlStatement(AH, "SET row_security = on"); + else + ExecuteSqlStatement(AH, "SET row_security = off"); /* * For security reasons, we restrict the expansion of non-system views and @@ -1933,10 +1933,9 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) addObjectDependency(dobj, ext->dobj.dumpId); /* - * Mark the member object to have any non-initial ACLs - * dumped. (Any initial ACLs will be removed later, using data from - * pg_init_privs, so that we'll dump only the delta from the extension's - * initial setup.) + * Mark the member object to have any non-initial ACLs dumped. (Any + * initial ACLs will be removed later, using data from pg_init_privs, so + * that we'll dump only the delta from the extension's initial setup.) * * In binary upgrades, we still dump all components of the members * individually, since the idea is to exactly reproduce the database @@ -1953,7 +1952,7 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) if (fout->dopt->binary_upgrade) dobj->dump = ext->dobj.dump; else - dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); + dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); return true; } @@ -1987,9 +1986,9 @@ selectDumpableNamespace(NamespaceInfo *nsinfo, Archive *fout) else if (strcmp(nsinfo->dobj.name, "pg_catalog") == 0) { /* - * We dump out any ACLs defined in pg_catalog, if - * they are interesting (and not the original ACLs which were set at - * initdb time, see pg_init_privs). + * We dump out any ACLs defined in pg_catalog, if they are interesting + * (and not the original ACLs which were set at initdb time, see + * pg_init_privs). */ nsinfo->dobj.dump_contains = nsinfo->dobj.dump = DUMP_COMPONENT_ACL; } @@ -3296,7 +3295,7 @@ dumpDatabase(Archive *fout) "datcollate, datctype, datfrozenxid, " "datacl, acldefault('d', datdba) AS acldefault, " "datistemplate, datconnlimit, "); - appendPQExpBufferStr(dbQry, "datminmxid, "); + appendPQExpBufferStr(dbQry, "datminmxid, "); if (fout->remoteVersion >= 170000) appendPQExpBufferStr(dbQry, "datlocprovider, datlocale, datcollversion, "); else if (fout->remoteVersion >= 150000) @@ -3638,11 +3637,11 @@ dumpDatabase(Archive *fout) ii_oid, ii_relminmxid; - appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" - "FROM pg_catalog.pg_class\n" - "WHERE oid IN (%u, %u, %u, %u);\n", - LargeObjectRelationId, LargeObjectLOidPNIndexId, - LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); + appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" + "FROM pg_catalog.pg_class\n" + "WHERE oid IN (%u, %u, %u, %u);\n", + LargeObjectRelationId, LargeObjectLOidPNIndexId, + LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); lo_res = ExecuteSqlQuery(fout, loFrozenQry->data, PGRES_TUPLES_OK); @@ -4274,7 +4273,7 @@ getPolicies(Archive *fout, TableInfo tblinfo[], int numTables) printfPQExpBuffer(query, "SELECT pol.oid, pol.tableoid, pol.polrelid, pol.polname, pol.polcmd, "); - appendPQExpBufferStr(query, "pol.polpermissive, "); + appendPQExpBufferStr(query, "pol.polpermissive, "); appendPQExpBuffer(query, "CASE WHEN pol.polroles = '{0}' THEN NULL ELSE " " pg_catalog.array_to_string(ARRAY(SELECT pg_catalog.quote_ident(rolname) from pg_catalog.pg_roles WHERE oid = ANY(pol.polroles)), ', ') END AS polroles, " @@ -6633,9 +6632,9 @@ getAccessMethods(Archive *fout) * Select all access methods from pg_am table. */ appendPQExpBufferStr(query, "SELECT tableoid, oid, amname, "); - appendPQExpBufferStr(query, - "amtype, " - "amhandler::pg_catalog.regproc AS amhandler "); + appendPQExpBufferStr(query, + "amtype, " + "amhandler::pg_catalog.regproc AS amhandler "); appendPQExpBufferStr(query, "FROM pg_am"); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6827,35 +6826,35 @@ getAggregates(Archive *fout) * Find all interesting aggregates. See comment in getFuncs() for the * rationale behind the filtering logic. */ - agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" - : "p.proisagg"); + agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" + : "p.proisagg"); - appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " - "p.proname AS aggname, " - "p.pronamespace AS aggnamespace, " - "p.pronargs, p.proargtypes, " - "p.proowner, " - "p.proacl AS aggacl, " - "acldefault('f', p.proowner) AS acldefault " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s AND (" - "p.pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog') OR " - "p.proacl IS DISTINCT FROM pip.initprivs", - agg_check); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - " OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); - appendPQExpBufferChar(query, ')'); + appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " + "p.proname AS aggname, " + "p.pronamespace AS aggnamespace, " + "p.pronargs, p.proargtypes, " + "p.proowner, " + "p.proacl AS aggacl, " + "acldefault('f', p.proowner) AS acldefault " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s AND (" + "p.pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog') OR " + "p.proacl IS DISTINCT FROM pip.initprivs", + agg_check); + if (dopt->binary_upgrade) + appendPQExpBufferStr(query, + " OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6957,53 +6956,53 @@ getFuncs(Archive *fout) * include them, since we want to dump extension members individually in * that mode. Also, if they are used by casts or transforms then we need * to gather the information about them, though they won't be dumped if - * they are built-in. Also, include functions in - * pg_catalog if they have an ACL different from what's shown in - * pg_init_privs (so we have to join to pg_init_privs; annoying). + * they are built-in. Also, include functions in pg_catalog if they have + * an ACL different from what's shown in pg_init_privs (so we have to join + * to pg_init_privs; annoying). */ - not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" - : "NOT p.proisagg"); + not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" + : "NOT p.proisagg"); - appendPQExpBuffer(query, - "SELECT p.tableoid, p.oid, p.proname, p.prolang, " - "p.pronargs, p.proargtypes, p.prorettype, " - "p.proacl, " - "acldefault('f', p.proowner) AS acldefault, " - "p.pronamespace, " - "p.proowner " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s" - "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " - "WHERE classid = 'pg_proc'::regclass AND " - "objid = p.oid AND deptype = 'i')" - "\n AND (" - "\n pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog')" - "\n OR EXISTS (SELECT 1 FROM pg_cast" - "\n WHERE pg_cast.oid > %u " - "\n AND p.oid = pg_cast.castfunc)" - "\n OR EXISTS (SELECT 1 FROM pg_transform" - "\n WHERE pg_transform.oid > %u AND " - "\n (p.oid = pg_transform.trffromsql" - "\n OR p.oid = pg_transform.trftosql))", - not_agg_check, - g_last_builtin_oid, - g_last_builtin_oid); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); + appendPQExpBuffer(query, + "SELECT p.tableoid, p.oid, p.proname, p.prolang, " + "p.pronargs, p.proargtypes, p.prorettype, " + "p.proacl, " + "acldefault('f', p.proowner) AS acldefault, " + "p.pronamespace, " + "p.proowner " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s" + "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " + "WHERE classid = 'pg_proc'::regclass AND " + "objid = p.oid AND deptype = 'i')" + "\n AND (" + "\n pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog')" + "\n OR EXISTS (SELECT 1 FROM pg_cast" + "\n WHERE pg_cast.oid > %u " + "\n AND p.oid = pg_cast.castfunc)" + "\n OR EXISTS (SELECT 1 FROM pg_transform" + "\n WHERE pg_transform.oid > %u AND " + "\n (p.oid = pg_transform.trffromsql" + "\n OR p.oid = pg_transform.trftosql))", + not_agg_check, + g_last_builtin_oid, + g_last_builtin_oid); + if (dopt->binary_upgrade) appendPQExpBufferStr(query, - "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); - appendPQExpBufferChar(query, ')'); + "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferStr(query, + "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -7252,31 +7251,31 @@ getTables(Archive *fout, int *numTables) appendPQExpBufferStr(query, "c.relhasoids, "); - appendPQExpBufferStr(query, - "c.relispopulated, "); + appendPQExpBufferStr(query, + "c.relispopulated, "); - appendPQExpBufferStr(query, - "c.relreplident, "); + appendPQExpBufferStr(query, + "c.relreplident, "); - appendPQExpBufferStr(query, - "c.relrowsecurity, c.relforcerowsecurity, "); + appendPQExpBufferStr(query, + "c.relrowsecurity, c.relforcerowsecurity, "); - appendPQExpBufferStr(query, - "c.relminmxid, tc.relminmxid AS tminmxid, "); + appendPQExpBufferStr(query, + "c.relminmxid, tc.relminmxid AS tminmxid, "); - appendPQExpBufferStr(query, - "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); + appendPQExpBufferStr(query, + "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); - appendPQExpBufferStr(query, - "am.amname, "); + appendPQExpBufferStr(query, + "am.amname, "); - appendPQExpBufferStr(query, - "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); + appendPQExpBufferStr(query, + "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); - appendPQExpBufferStr(query, - "c.relispartition AS ispartition "); + appendPQExpBufferStr(query, + "c.relispartition AS ispartition "); /* * Left join to pg_depend to pick up dependency info linking sequences to @@ -7296,8 +7295,8 @@ getTables(Archive *fout, int *numTables) /* * Left join to pg_am to pick up the amname. */ - appendPQExpBufferStr(query, - "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); + appendPQExpBufferStr(query, + "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); /* * We purposefully ignore toast OIDs for partitioned tables; the reason is @@ -7868,8 +7867,8 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables) "t.reloptions AS indreloptions, "); - appendPQExpBufferStr(query, - "i.indisreplident, "); + appendPQExpBufferStr(query, + "i.indisreplident, "); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -9313,8 +9312,8 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables) appendPQExpBufferStr(q, "'' AS attcompression,\n"); - appendPQExpBufferStr(q, - "a.attidentity,\n"); + appendPQExpBufferStr(q, + "a.attidentity,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(q, @@ -10717,73 +10716,73 @@ getAdditionalACLs(Archive *fout) PQclear(res); /* Fetch initial-privileges data */ - printfPQExpBuffer(query, - "SELECT objoid, classoid, objsubid, privtype, initprivs " - "FROM pg_init_privs"); + printfPQExpBuffer(query, + "SELECT objoid, classoid, objsubid, privtype, initprivs " + "FROM pg_init_privs"); - res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); + res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); - ntups = PQntuples(res); - for (i = 0; i < ntups; i++) - { - Oid objoid = atooid(PQgetvalue(res, i, 0)); - Oid classoid = atooid(PQgetvalue(res, i, 1)); - int objsubid = atoi(PQgetvalue(res, i, 2)); - char privtype = *(PQgetvalue(res, i, 3)); - char *initprivs = PQgetvalue(res, i, 4); - CatalogId objId; - DumpableObject *dobj; + ntups = PQntuples(res); + for (i = 0; i < ntups; i++) + { + Oid objoid = atooid(PQgetvalue(res, i, 0)); + Oid classoid = atooid(PQgetvalue(res, i, 1)); + int objsubid = atoi(PQgetvalue(res, i, 2)); + char privtype = *(PQgetvalue(res, i, 3)); + char *initprivs = PQgetvalue(res, i, 4); + CatalogId objId; + DumpableObject *dobj; - objId.tableoid = classoid; - objId.oid = objoid; - dobj = findObjectByCatalogId(objId); - /* OK to ignore entries we haven't got a DumpableObject for */ - if (dobj) + objId.tableoid = classoid; + objId.oid = objoid; + dobj = findObjectByCatalogId(objId); + /* OK to ignore entries we haven't got a DumpableObject for */ + if (dobj) + { + /* Cope with sub-object initprivs */ + if (objsubid != 0) { - /* Cope with sub-object initprivs */ - if (objsubid != 0) - { - if (dobj->objType == DO_TABLE) - { - /* For a column initprivs, set the table's ACL flags */ - dobj->components |= DUMP_COMPONENT_ACL; - ((TableInfo *) dobj)->hascolumnACLs = true; - } - else - pg_log_warning("unsupported pg_init_privs entry: %u %u %d", - classoid, objoid, objsubid); - continue; - } - - /* - * We ignore any pg_init_privs.initprivs entry for the public - * schema, as explained in getNamespaces(). - */ - if (dobj->objType == DO_NAMESPACE && - strcmp(dobj->name, "public") == 0) - continue; - - /* Else it had better be of a type we think has ACLs */ - if (dobj->objType == DO_NAMESPACE || - dobj->objType == DO_TYPE || - dobj->objType == DO_FUNC || - dobj->objType == DO_AGG || - dobj->objType == DO_TABLE || - dobj->objType == DO_PROCLANG || - dobj->objType == DO_FDW || - dobj->objType == DO_FOREIGN_SERVER) + if (dobj->objType == DO_TABLE) { - DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; - - daobj->dacl.privtype = privtype; - daobj->dacl.initprivs = pstrdup(initprivs); + /* For a column initprivs, set the table's ACL flags */ + dobj->components |= DUMP_COMPONENT_ACL; + ((TableInfo *) dobj)->hascolumnACLs = true; } else pg_log_warning("unsupported pg_init_privs entry: %u %u %d", classoid, objoid, objsubid); + continue; + } + + /* + * We ignore any pg_init_privs.initprivs entry for the public + * schema, as explained in getNamespaces(). + */ + if (dobj->objType == DO_NAMESPACE && + strcmp(dobj->name, "public") == 0) + continue; + + /* Else it had better be of a type we think has ACLs */ + if (dobj->objType == DO_NAMESPACE || + dobj->objType == DO_TYPE || + dobj->objType == DO_FUNC || + dobj->objType == DO_AGG || + dobj->objType == DO_TABLE || + dobj->objType == DO_PROCLANG || + dobj->objType == DO_FDW || + dobj->objType == DO_FOREIGN_SERVER) + { + DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; + + daobj->dacl.privtype = privtype; + daobj->dacl.initprivs = pstrdup(initprivs); } + else + pg_log_warning("unsupported pg_init_privs entry: %u %u %d", + classoid, objoid, objsubid); } - PQclear(res); + } + PQclear(res); destroyPQExpBuffer(query); } @@ -11128,8 +11127,8 @@ dumpRelationStats_dumper(Archive *fout, const void *userArg, const TocEntry *te) * The results must be in the order of the relations supplied in the * parameters to ensure we remain in sync as we walk through the TOC. * - * For versions before 19, the redundant filter clause on s.tablename = - * ANY(...) seems sufficient to convince the planner to use + * For versions before 19, the redundant filter clause on s.tablename + * = ANY(...) seems sufficient to convince the planner to use * pg_class_relname_nsp_index, which avoids a full scan of pg_stats. * In newer versions, pg_stats returns the table OIDs, eliminating the * need for that hack. @@ -13469,11 +13468,11 @@ dumpFunc(Archive *fout, const FuncInfo *finfo) "pg_catalog.pg_get_function_result(p.oid) AS funcresult,\n" "proleakproof,\n"); - appendPQExpBufferStr(query, - "array_to_string(protrftypes, ' ') AS protrftypes,\n"); + appendPQExpBufferStr(query, + "array_to_string(protrftypes, ' ') AS protrftypes,\n"); - appendPQExpBufferStr(query, - "proparallel,\n"); + appendPQExpBufferStr(query, + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -14963,9 +14962,9 @@ dumpCollation(Archive *fout, const CollInfo *collinfo) /* Get collation-specific details */ appendPQExpBufferStr(query, "SELECT "); - appendPQExpBufferStr(query, - "collprovider, " - "collversion, "); + appendPQExpBufferStr(query, + "collprovider, " + "collversion, "); if (fout->remoteVersion >= 120000) appendPQExpBufferStr(query, @@ -15372,23 +15371,23 @@ dumpAgg(Archive *fout, const AggInfo *agginfo) "pg_catalog.pg_get_function_arguments(p.oid) AS funcargs,\n" "pg_catalog.pg_get_function_identity_arguments(p.oid) AS funciargs,\n"); - appendPQExpBufferStr(query, - "aggkind,\n" - "aggmtransfn,\n" - "aggminvtransfn,\n" - "aggmfinalfn,\n" - "aggmtranstype::pg_catalog.regtype,\n" - "aggfinalextra,\n" - "aggmfinalextra,\n" - "aggtransspace,\n" - "aggmtransspace,\n" - "aggminitval,\n"); + appendPQExpBufferStr(query, + "aggkind,\n" + "aggmtransfn,\n" + "aggminvtransfn,\n" + "aggmfinalfn,\n" + "aggmtranstype::pg_catalog.regtype,\n" + "aggfinalextra,\n" + "aggmfinalextra,\n" + "aggtransspace,\n" + "aggmtransspace,\n" + "aggminitval,\n"); - appendPQExpBufferStr(query, - "aggcombinefn,\n" - "aggserialfn,\n" - "aggdeserialfn,\n" - "proparallel,\n"); + appendPQExpBufferStr(query, + "aggcombinefn,\n" + "aggserialfn,\n" + "aggdeserialfn,\n" + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -16848,30 +16847,30 @@ dumpTable(Archive *fout, const TableInfo *tbinfo) appendPQExpBufferStr(query, "PREPARE getColumnACLs(pg_catalog.oid) AS\n"); - /* - * In principle we should call acldefault('c', relowner) to - * get the default ACL for a column. However, we don't - * currently store the numeric OID of the relowner in - * TableInfo. We could convert the owner name using regrole, - * but that creates a risk of failure due to concurrent role - * renames. Given that the default ACL for columns is empty - * and is likely to stay that way, it's not worth extra cycles - * and risk to avoid hard-wiring that knowledge here. - */ - appendPQExpBufferStr(query, - "SELECT at.attname, " - "at.attacl, " - "'{}' AS acldefault, " - "pip.privtype, pip.initprivs " - "FROM pg_catalog.pg_attribute at " - "LEFT JOIN pg_catalog.pg_init_privs pip ON " - "(at.attrelid = pip.objoid " - "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " - "AND at.attnum = pip.objsubid) " - "WHERE at.attrelid = $1 AND " - "NOT at.attisdropped " - "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " - "ORDER BY at.attnum"); + /* + * In principle we should call acldefault('c', relowner) to get + * the default ACL for a column. However, we don't currently + * store the numeric OID of the relowner in TableInfo. We could + * convert the owner name using regrole, but that creates a risk + * of failure due to concurrent role renames. Given that the + * default ACL for columns is empty and is likely to stay that + * way, it's not worth extra cycles and risk to avoid hard-wiring + * that knowledge here. + */ + appendPQExpBufferStr(query, + "SELECT at.attname, " + "at.attacl, " + "'{}' AS acldefault, " + "pip.privtype, pip.initprivs " + "FROM pg_catalog.pg_attribute at " + "LEFT JOIN pg_catalog.pg_init_privs pip ON " + "(at.attrelid = pip.objoid " + "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " + "AND at.attnum = pip.objsubid) " + "WHERE at.attrelid = $1 AND " + "NOT at.attisdropped " + "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " + "ORDER BY at.attnum"); ExecuteSqlStatement(fout, query->data); @@ -19165,7 +19164,7 @@ collectSequences(Archive *fout) * pg_get_sequence_data(), but we only do so for non-schema-only dumps. */ if (fout->remoteVersion < 180000 || - (!fout->dopt->dumpData && !fout->dopt->sequence_data)) + (!fout->dopt->dumpData && !fout->dopt->sequence_data)) query = "SELECT seqrelid, format_type(seqtypid, NULL), " "seqstart, seqincrement, " "seqmax, seqmin, " @@ -19227,15 +19226,14 @@ dumpSequence(Archive *fout, const TableInfo *tbinfo) qseqname = pg_strdup(fmtId(tbinfo->dobj.name)); /* - * The sequence information is gathered in a sorted - * table before any calls to dumpSequence(). See collectSequences() for - * more information. + * The sequence information is gathered in a sorted table before any calls + * to dumpSequence(). See collectSequences() for more information. */ - Assert(sequences); + Assert(sequences); - key.oid = tbinfo->dobj.catId.oid; - seq = bsearch(&key, sequences, nsequences, - sizeof(SequenceItem), SequenceItemCmp); + key.oid = tbinfo->dobj.catId.oid; + seq = bsearch(&key, sequences, nsequences, + sizeof(SequenceItem), SequenceItemCmp); /* Calculate default limits for a sequence of this type */ is_ascending = (seq->incby >= 0); diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c index e68937c9934..afcd9a218d8 100644 --- a/src/bin/pg_dump/pg_dumpall.c +++ b/src/bin/pg_dump/pg_dumpall.c @@ -785,11 +785,11 @@ dropRoles(PGconn *conn) int i_rolname; int i; - printfPQExpBuffer(buf, - "SELECT rolname " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 1", role_catalog); + printfPQExpBuffer(buf, + "SELECT rolname " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 1", role_catalog); res = executeQuery(conn, buf->data); @@ -843,16 +843,16 @@ dumpRoles(PGconn *conn) * Notes: rolconfig is dumped later, and pg_authid must be used for * extracting rolcomment regardless of role_catalog. */ - printfPQExpBuffer(buf, - "SELECT oid, rolname, rolsuper, rolinherit, " - "rolcreaterole, rolcreatedb, " - "rolcanlogin, rolconnlimit, rolpassword, " - "rolvaliduntil, rolreplication, rolbypassrls, " - "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " - "rolname = current_user AS is_current_user " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 2", role_catalog); + printfPQExpBuffer(buf, + "SELECT oid, rolname, rolsuper, rolinherit, " + "rolcreaterole, rolcreatedb, " + "rolcanlogin, rolconnlimit, rolpassword, " + "rolvaliduntil, rolreplication, rolbypassrls, " + "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " + "rolname = current_user AS is_current_user " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 2", role_catalog); res = executeQuery(conn, buf->data); diff --git a/src/bin/pg_upgrade/check.c b/src/bin/pg_upgrade/check.c index 786c1474829..f725f5ee3e2 100644 --- a/src/bin/pg_upgrade/check.c +++ b/src/bin/pg_upgrade/check.c @@ -1475,15 +1475,15 @@ check_for_incompatible_polymorphics(ClusterInfo *cluster) ", 'array_cat(anyarray,anyarray)'" ", 'array_prepend(anyelement,anyarray)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_remove(anyarray,anyelement)'" - ", 'array_replace(anyarray,anyelement,anyelement)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_remove(anyarray,anyelement)'" + ", 'array_replace(anyarray,anyelement,anyelement)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_position(anyarray,anyelement)'" - ", 'array_position(anyarray,anyelement,integer)'" - ", 'array_positions(anyarray,anyelement)'" - ", 'width_bucket(anyelement,anyarray)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_position(anyarray,anyelement)'" + ", 'array_position(anyarray,anyelement,integer)'" + ", 'array_positions(anyarray,anyelement)'" + ", 'width_bucket(anyelement,anyarray)'"); /* * The query below hardcodes FirstNormalObjectId as 16384 rather than diff --git a/src/bin/pg_upgrade/controldata.c b/src/bin/pg_upgrade/controldata.c index 8f81c9e9582..02ea02df60f 100644 --- a/src/bin/pg_upgrade/controldata.c +++ b/src/bin/pg_upgrade/controldata.c @@ -228,7 +228,7 @@ get_control_data(ClusterInfo *cluster) p++; /* remove ':' char */ cluster->controldata.chkpnt_nxtepoch = str2uint(p); - p = strchr(p, ':'); + p = strchr(p, ':'); if (p == NULL || strlen(p) <= 1) pg_fatal("%d: controldata retrieval problem", __LINE__); diff --git a/src/bin/pg_upgrade/exec.c b/src/bin/pg_upgrade/exec.c index 44355feea30..a1bdbf373e3 100644 --- a/src/bin/pg_upgrade/exec.c +++ b/src/bin/pg_upgrade/exec.c @@ -55,7 +55,7 @@ get_bin_version(ClusterInfo *cluster) if (sscanf(cmd_output, "%*s %*s %d.%d", &v1, &v2) < 1) pg_fatal("could not get pg_ctl version output from %s", cmd); - cluster->bin_version = v1 * 10000; + cluster->bin_version = v1 * 10000; } @@ -344,8 +344,8 @@ check_data_dir(ClusterInfo *cluster) check_single_dir(pg_data, "pg_subtrans"); check_single_dir(pg_data, PG_TBLSPC_DIR); check_single_dir(pg_data, "pg_twophase"); - check_single_dir(pg_data, "pg_wal"); - check_single_dir(pg_data, "pg_xact"); + check_single_dir(pg_data, "pg_wal"); + check_single_dir(pg_data, "pg_xact"); } @@ -385,7 +385,7 @@ check_bin_dir(ClusterInfo *cluster, bool check_versions) */ get_bin_version(cluster); - check_exec(cluster->bindir, "pg_resetwal", check_versions); + check_exec(cluster->bindir, "pg_resetwal", check_versions); if (cluster == &new_cluster) { diff --git a/src/bin/pg_upgrade/multixact_rewrite.c b/src/bin/pg_upgrade/multixact_rewrite.c index c45b3183684..c7a1416494d 100644 --- a/src/bin/pg_upgrade/multixact_rewrite.c +++ b/src/bin/pg_upgrade/multixact_rewrite.c @@ -61,52 +61,52 @@ rewrite_multixacts(MultiXactId from_multi, MultiXactId to_multi) * Convert old multixids, if needed, by reading them one-by-one from the * old cluster. */ - old_reader = AllocOldMultiXactRead(old_cluster.pgdata, - old_cluster.controldata.chkpnt_nxtmulti, - old_cluster.controldata.chkpnt_nxtmxoff); + old_reader = AllocOldMultiXactRead(old_cluster.pgdata, + old_cluster.controldata.chkpnt_nxtmulti, + old_cluster.controldata.chkpnt_nxtmxoff); - for (MultiXactId multi = from_multi; multi != to_multi;) - { - MultiXactMember member; - bool multixid_valid; - - /* - * Read this multixid's members. - * - * Locking-only XIDs that may be part of multi-xids don't matter - * after upgrade, as there can be no transactions running across - * upgrade. So as a small optimization, we only read one member - * from each multixid: the one updating one, or if there was no - * update, arbitrarily the first locking xid. - */ - multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); + for (MultiXactId multi = from_multi; multi != to_multi;) + { + MultiXactMember member; + bool multixid_valid; - /* - * Write the new offset to pg_multixact/offsets. - * - * Even if this multixid is invalid, we still need to write its - * offset if the *previous* multixid was valid. That's because - * when reading a multixid, the number of members is calculated - * from the difference between the two offsets. - */ - RecordMultiXactOffset(offsets_writer, multi, - (multixid_valid || prev_multixid_valid) ? next_offset : 0); + /* + * Read this multixid's members. + * + * Locking-only XIDs that may be part of multi-xids don't matter after + * upgrade, as there can be no transactions running across upgrade. So + * as a small optimization, we only read one member from each + * multixid: the one updating one, or if there was no update, + * arbitrarily the first locking xid. + */ + multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); - /* Write the members */ - if (multixid_valid) - { - RecordMultiXactMembers(members_writer, next_offset, 1, &member); - next_offset += 1; - } + /* + * Write the new offset to pg_multixact/offsets. + * + * Even if this multixid is invalid, we still need to write its offset + * if the *previous* multixid was valid. That's because when reading + * a multixid, the number of members is calculated from the difference + * between the two offsets. + */ + RecordMultiXactOffset(offsets_writer, multi, + (multixid_valid || prev_multixid_valid) ? next_offset : 0); - /* Advance to next multixid, handling wraparound */ - multi++; - if (multi < FirstMultiXactId) - multi = FirstMultiXactId; - prev_multixid_valid = multixid_valid; + /* Write the members */ + if (multixid_valid) + { + RecordMultiXactMembers(members_writer, next_offset, 1, &member); + next_offset += 1; } - FreeOldMultiXactReader(old_reader); + /* Advance to next multixid, handling wraparound */ + multi++; + if (multi < FirstMultiXactId) + multi = FirstMultiXactId; + prev_multixid_valid = multixid_valid; + } + + FreeOldMultiXactReader(old_reader); /* Write the final 'next' offset to the last SLRU page */ RecordMultiXactOffset(offsets_writer, to_multi, diff --git a/src/bin/pg_upgrade/pg_upgrade.c b/src/bin/pg_upgrade/pg_upgrade.c index c6af9035665..7366fd4627c 100644 --- a/src/bin/pg_upgrade/pg_upgrade.c +++ b/src/bin/pg_upgrade/pg_upgrade.c @@ -833,7 +833,7 @@ copy_xact_xlog_xid(void) * Determine the range of multixacts to convert. */ nxtmulti = old_cluster.controldata.chkpnt_nxtmulti; - oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; + oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; /* handle wraparound */ if (nxtmulti < FirstMultiXactId) nxtmulti = FirstMultiXactId; @@ -898,15 +898,15 @@ set_frozenxids(void) int i_datname; int i_datallowconn; - prep_status("Setting frozenxid and minmxid counters in new cluster"); + prep_status("Setting frozenxid and minmxid counters in new cluster"); conn_template1 = connectToServer(&new_cluster, "template1"); - /* set pg_database.datfrozenxid */ - PQclear(executeQueryOrDie(conn_template1, - "UPDATE pg_catalog.pg_database " - "SET datfrozenxid = '%u'", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_database.datfrozenxid */ + PQclear(executeQueryOrDie(conn_template1, + "UPDATE pg_catalog.pg_database " + "SET datfrozenxid = '%u'", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_database.datminmxid */ PQclear(executeQueryOrDie(conn_template1, @@ -942,16 +942,16 @@ set_frozenxids(void) conn = connectToServer(&new_cluster, datname); - /* set pg_class.relfrozenxid */ - PQclear(executeQueryOrDie(conn, - "UPDATE pg_catalog.pg_class " - "SET relfrozenxid = '%u' " - /* only heap, materialized view, and TOAST are vacuumed */ - "WHERE relkind IN (" - CppAsString2(RELKIND_RELATION) ", " - CppAsString2(RELKIND_MATVIEW) ", " - CppAsString2(RELKIND_TOASTVALUE) ")", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_class.relfrozenxid */ + PQclear(executeQueryOrDie(conn, + "UPDATE pg_catalog.pg_class " + "SET relfrozenxid = '%u' " + /* only heap, materialized view, and TOAST are vacuumed */ + "WHERE relkind IN (" + CppAsString2(RELKIND_RELATION) ", " + CppAsString2(RELKIND_MATVIEW) ", " + CppAsString2(RELKIND_TOASTVALUE) ")", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_class.relminmxid */ PQclear(executeQueryOrDie(conn, diff --git a/src/bin/pg_upgrade/relfilenumber.c b/src/bin/pg_upgrade/relfilenumber.c index ec2ff7acb21..6c467bdc8a5 100644 --- a/src/bin/pg_upgrade/relfilenumber.c +++ b/src/bin/pg_upgrade/relfilenumber.c @@ -587,32 +587,32 @@ transfer_relfile(FileNameMap *map, const char *type_suffix) /* Copying files might take some time, so give feedback. */ pg_log(PG_STATUS, "%s", old_file); - switch (user_opts.transfer_mode) - { - case TRANSFER_MODE_CLONE: - pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", - old_file, new_file); - cloneFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", - old_file, new_file); - copyFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY_FILE_RANGE: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", - old_file, new_file); - copyFileByRange(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_LINK: - pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", - old_file, new_file); - linkFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_SWAP: - /* swap mode is handled in its own code path */ - pg_fatal("should never happen"); - break; - } + switch (user_opts.transfer_mode) + { + case TRANSFER_MODE_CLONE: + pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", + old_file, new_file); + cloneFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", + old_file, new_file); + copyFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY_FILE_RANGE: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", + old_file, new_file); + copyFileByRange(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_LINK: + pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", + old_file, new_file); + linkFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_SWAP: + /* swap mode is handled in its own code path */ + pg_fatal("should never happen"); + break; + } } } diff --git a/src/bin/pg_upgrade/t/006_transfer_modes.pl b/src/bin/pg_upgrade/t/006_transfer_modes.pl index 9efa5dc863c..360d05c4b68 100644 --- a/src/bin/pg_upgrade/t/006_transfer_modes.pl +++ b/src/bin/pg_upgrade/t/006_transfer_modes.pl @@ -29,10 +29,8 @@ sub test_mode } $new->init(); - $new->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); - $old->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); + $new->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); + $old->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); # We can only test security labels if both the old and new installations # have dummy_seclabel. @@ -76,15 +74,14 @@ sub test_mode "CREATE TABLE test4 AS SELECT generate_series(400, 502)"); } - $old->safe_psql('postgres', - "CREATE TABLESPACE inplc_tblspc LOCATION ''"); - $old->safe_psql('postgres', - "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); - $old->safe_psql('postgres', - "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" - ); - $old->safe_psql('testdb3', - "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); + $old->safe_psql('postgres', "CREATE TABLESPACE inplc_tblspc LOCATION ''"); + $old->safe_psql('postgres', + "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); + $old->safe_psql('postgres', + "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" + ); + $old->safe_psql('testdb3', + "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); # While we are here, test handling of large objects. $old->safe_psql( @@ -152,12 +149,10 @@ sub test_mode } # Tests for in-place tablespaces. - $result = - $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); - is($result, '104', "test5 data after pg_upgrade $mode"); - $result = - $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); - is($result, '105', "test6 data after pg_upgrade $mode"); + $result = $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); + is($result, '104', "test5 data after pg_upgrade $mode"); + $result = $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); + is($result, '105', "test6 data after pg_upgrade $mode"); # Tests for large objects $result = $new->safe_psql('postgres', "SELECT lo_get(4532)"); diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index 44ef11d980e..c90bf8bbde2 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -6278,23 +6278,22 @@ get_create_object_cmd(EditableObjectType obj_type, Oid oid, * ensure the right view gets replaced. Also, check relation kind * to be sure it's a view. * - * Views may have WITH [LOCAL|CASCADED] - * CHECK OPTION. These are not part of the view definition - * returned by pg_get_viewdef() and so need to be retrieved - * separately. Materialized views may have - * arbitrary storage parameter reloptions. + * Views may have WITH [LOCAL|CASCADED] CHECK OPTION. These are + * not part of the view definition returned by pg_get_viewdef() + * and so need to be retrieved separately. Materialized views may + * have arbitrary storage parameter reloptions. */ printfPQExpBuffer(query, "/* %s */\n", _("Get view's definition and details")); - appendPQExpBuffer(query, - "SELECT nspname, relname, relkind, " - "pg_catalog.pg_get_viewdef(c.oid, true), " - "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " - "FROM pg_catalog.pg_class c " - "LEFT JOIN pg_catalog.pg_namespace n " - "ON c.relnamespace = n.oid WHERE c.oid = %u", - oid); + appendPQExpBuffer(query, + "SELECT nspname, relname, relkind, " + "pg_catalog.pg_get_viewdef(c.oid, true), " + "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " + "FROM pg_catalog.pg_class c " + "LEFT JOIN pg_catalog.pg_namespace n " + "ON c.relnamespace = n.oid WHERE c.oid = %u", + oid); break; } diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index ce99137c613..ac0c55e7aa5 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -387,19 +387,19 @@ describeFunctions(const char *functypes, const char *func_pattern, gettext_noop("stable"), gettext_noop("volatile"), gettext_noop("Volatility")); - appendPQExpBuffer(&buf, - ",\n CASE\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" - " END as \"%s\"", - gettext_noop("restricted"), - gettext_noop("safe"), - gettext_noop("unsafe"), - gettext_noop("Parallel")); + appendPQExpBuffer(&buf, + ",\n CASE\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" + " END as \"%s\"", + gettext_noop("restricted"), + gettext_noop("safe"), + gettext_noop("unsafe"), + gettext_noop("Parallel")); appendPQExpBuffer(&buf, ",\n pg_catalog.pg_get_userbyid(p.proowner) as \"%s\"" ",\n CASE WHEN prosecdef THEN '%s' ELSE '%s' END AS \"%s\"" @@ -599,8 +599,8 @@ describeFunctions(const char *functypes, const char *func_pattern, myopt.title = _("List of functions"); myopt.translate_header = true; - myopt.translate_columns = translate_columns; - myopt.n_translate_columns = lengthof(translate_columns); + myopt.translate_columns = translate_columns; + myopt.n_translate_columns = lengthof(translate_columns); printQuery(res, &myopt, pset.queryFout, false, pset.logfile); @@ -1086,38 +1086,38 @@ permissionsList(const char *pattern, bool showSystem) " ), E'\\n') AS \"%s\"", gettext_noop("Column privileges")); - appendPQExpBuffer(&buf, - ",\n pg_catalog.array_to_string(ARRAY(\n" - " SELECT polname\n" - " || CASE WHEN NOT polpermissive THEN\n" - " E' (RESTRICTIVE)'\n" - " ELSE '' END\n" - " || CASE WHEN polcmd != '*' THEN\n" - " E' (' || polcmd::pg_catalog.text || E'):'\n" - " ELSE E':'\n" - " END\n" - " || CASE WHEN polqual IS NOT NULL THEN\n" - " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" - " ELSE E''\n" - " END\n" - " || CASE WHEN polwithcheck IS NOT NULL THEN\n" - " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" - " ELSE E''\n" - " END" - " || CASE WHEN polroles <> '{0}' THEN\n" - " E'\\n to: ' || pg_catalog.array_to_string(\n" - " ARRAY(\n" - " SELECT rolname\n" - " FROM pg_catalog.pg_roles\n" - " WHERE oid = ANY (polroles)\n" - " ORDER BY 1\n" - " ), E', ')\n" - " ELSE E''\n" - " END\n" - " FROM pg_catalog.pg_policy pol\n" - " WHERE polrelid = c.oid), E'\\n')\n" - " AS \"%s\"", - gettext_noop("Policies")); + appendPQExpBuffer(&buf, + ",\n pg_catalog.array_to_string(ARRAY(\n" + " SELECT polname\n" + " || CASE WHEN NOT polpermissive THEN\n" + " E' (RESTRICTIVE)'\n" + " ELSE '' END\n" + " || CASE WHEN polcmd != '*' THEN\n" + " E' (' || polcmd::pg_catalog.text || E'):'\n" + " ELSE E':'\n" + " END\n" + " || CASE WHEN polqual IS NOT NULL THEN\n" + " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" + " ELSE E''\n" + " END\n" + " || CASE WHEN polwithcheck IS NOT NULL THEN\n" + " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" + " ELSE E''\n" + " END" + " || CASE WHEN polroles <> '{0}' THEN\n" + " E'\\n to: ' || pg_catalog.array_to_string(\n" + " ARRAY(\n" + " SELECT rolname\n" + " FROM pg_catalog.pg_roles\n" + " WHERE oid = ANY (polroles)\n" + " ORDER BY 1\n" + " ), E', ')\n" + " ELSE E''\n" + " END\n" + " FROM pg_catalog.pg_policy pol\n" + " WHERE polrelid = c.oid), E'\\n')\n" + " AS \"%s\"", + gettext_noop("Policies")); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_class c\n" " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n" @@ -1675,27 +1675,27 @@ describeOneTableDetails(const char *schemaname, char *footers[3] = {NULL, NULL, NULL}; printfPQExpBuffer(&buf, "/* %s */\n", _("Get sequence information")); - appendPQExpBuffer(&buf, - "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" - " seqstart AS \"%s\",\n" - " seqmin AS \"%s\",\n" - " seqmax AS \"%s\",\n" - " seqincrement AS \"%s\",\n" - " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" - " seqcache AS \"%s\"\n", - gettext_noop("Type"), - gettext_noop("Start"), - gettext_noop("Minimum"), - gettext_noop("Maximum"), - gettext_noop("Increment"), - gettext_noop("yes"), - gettext_noop("no"), - gettext_noop("Cycles?"), - gettext_noop("Cache")); - appendPQExpBuffer(&buf, - "FROM pg_catalog.pg_sequence\n" - "WHERE seqrelid = '%s';", - oid); + appendPQExpBuffer(&buf, + "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" + " seqstart AS \"%s\",\n" + " seqmin AS \"%s\",\n" + " seqmax AS \"%s\",\n" + " seqincrement AS \"%s\",\n" + " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" + " seqcache AS \"%s\"\n", + gettext_noop("Type"), + gettext_noop("Start"), + gettext_noop("Minimum"), + gettext_noop("Maximum"), + gettext_noop("Increment"), + gettext_noop("yes"), + gettext_noop("no"), + gettext_noop("Cycles?"), + gettext_noop("Cache")); + appendPQExpBuffer(&buf, + "FROM pg_catalog.pg_sequence\n" + "WHERE seqrelid = '%s';", + oid); res = PSQLexec(buf.data); if (!res) @@ -1913,7 +1913,7 @@ describeOneTableDetails(const char *schemaname, appendPQExpBufferStr(&buf, ",\n (SELECT c.collname FROM pg_catalog.pg_collation c, pg_catalog.pg_type t\n" " WHERE c.oid = a.attcollation AND t.oid = a.atttypid AND a.attcollation <> t.typcollation) AS attcollation"); attcoll_col = cols++; - appendPQExpBufferStr(&buf, ",\n a.attidentity"); + appendPQExpBufferStr(&buf, ",\n a.attidentity"); attidentity_col = cols++; if (pset.sversion >= 120000) appendPQExpBufferStr(&buf, ",\n a.attgenerated"); @@ -2326,7 +2326,7 @@ describeOneTableDetails(const char *schemaname, CppAsString2(CONSTRAINT_EXCLUSION) ") AND " "condeferred) AS condeferred,\n"); - appendPQExpBufferStr(&buf, "i.indisreplident,\n"); + appendPQExpBufferStr(&buf, "i.indisreplident,\n"); if (pset.sversion >= 150000) appendPQExpBufferStr(&buf, "i.indnullsnotdistinct,\n"); @@ -2431,7 +2431,7 @@ describeOneTableDetails(const char *schemaname, "pg_catalog.pg_get_indexdef(i.indexrelid, 0, true),\n " "pg_catalog.pg_get_constraintdef(con.oid, true), " "contype, condeferrable, condeferred"); - appendPQExpBufferStr(&buf, ", i.indisreplident"); + appendPQExpBufferStr(&buf, ", i.indisreplident"); appendPQExpBufferStr(&buf, ", c2.reltablespace"); if (pset.sversion >= 180000) appendPQExpBufferStr(&buf, ", con.conperiod"); @@ -2682,81 +2682,80 @@ describeOneTableDetails(const char *schemaname, PQclear(result); /* print any row-level policies */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get row-level policies for this table")); - appendPQExpBufferStr(&buf, "SELECT pol.polname,"); - appendPQExpBufferStr(&buf, - " pol.polpermissive,\n"); - appendPQExpBuffer(&buf, - " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" - " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" - " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" - " CASE pol.polcmd\n" - " WHEN 'r' THEN 'SELECT'\n" - " WHEN 'a' THEN 'INSERT'\n" - " WHEN 'w' THEN 'UPDATE'\n" - " WHEN 'd' THEN 'DELETE'\n" - " END AS cmd\n" - "FROM pg_catalog.pg_policy pol\n" - "WHERE pol.polrelid = '%s' ORDER BY 1;", - oid); + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get row-level policies for this table")); + appendPQExpBufferStr(&buf, "SELECT pol.polname,"); + appendPQExpBufferStr(&buf, + " pol.polpermissive,\n"); + appendPQExpBuffer(&buf, + " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" + " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" + " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" + " CASE pol.polcmd\n" + " WHEN 'r' THEN 'SELECT'\n" + " WHEN 'a' THEN 'INSERT'\n" + " WHEN 'w' THEN 'UPDATE'\n" + " WHEN 'd' THEN 'DELETE'\n" + " END AS cmd\n" + "FROM pg_catalog.pg_policy pol\n" + "WHERE pol.polrelid = '%s' ORDER BY 1;", + oid); - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - /* - * Handle cases where RLS is enabled and there are policies, or - * there aren't policies, or RLS isn't enabled but there are - * policies - */ - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies:")); + /* + * Handle cases where RLS is enabled and there are policies, or there + * aren't policies, or RLS isn't enabled but there are policies + */ + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies:")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled):")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled):")); - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); - if (!tableinfo.rowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (row security disabled):")); + if (!tableinfo.rowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (row security disabled):")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " POLICY \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " POLICY \"%s\"", + PQgetvalue(result, i, 0)); - if (*(PQgetvalue(result, i, 1)) == 'f') - appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); + if (*(PQgetvalue(result, i, 1)) == 'f') + appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); - if (!PQgetisnull(result, i, 5)) - appendPQExpBuffer(&buf, " FOR %s", - PQgetvalue(result, i, 5)); + if (!PQgetisnull(result, i, 5)) + appendPQExpBuffer(&buf, " FOR %s", + PQgetvalue(result, i, 5)); - if (!PQgetisnull(result, i, 2)) - { - appendPQExpBuffer(&buf, "\n TO %s", - PQgetvalue(result, i, 2)); - } + if (!PQgetisnull(result, i, 2)) + { + appendPQExpBuffer(&buf, "\n TO %s", + PQgetvalue(result, i, 2)); + } - if (!PQgetisnull(result, i, 3)) - appendPQExpBuffer(&buf, "\n USING (%s)", - PQgetvalue(result, i, 3)); + if (!PQgetisnull(result, i, 3)) + appendPQExpBuffer(&buf, "\n USING (%s)", + PQgetvalue(result, i, 3)); - if (!PQgetisnull(result, i, 4)) - appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", - PQgetvalue(result, i, 4)); + if (!PQgetisnull(result, i, 4)) + appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", + PQgetvalue(result, i, 4)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* print any extended statistics */ if (pset.sversion >= 140000) @@ -3025,115 +3024,115 @@ describeOneTableDetails(const char *schemaname, } /* print any publications */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get publications that publish this table")); - if (pset.sversion >= 150000) + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get publications that publish this table")); + if (pset.sversion >= 150000) + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" + " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" + "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" + "UNION\n" + "SELECT pubname\n" + " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" + " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" + " (SELECT pg_catalog.string_agg(attname, ', ')\n" + " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" + " pg_catalog.pg_attribute\n" + " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" + " ELSE NULL END) " + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" + "WHERE pr.prrelid = '%s'\n", + oid, oid, oid); + + if (pset.sversion >= 190000) { + /* + * Skip entries where this relation appears in the + * publication's EXCEPT list. + */ appendPQExpBuffer(&buf, + " AND NOT pr.prexcept\n" + "UNION\n" "SELECT pubname\n" " , NULL\n" " , NULL\n" "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" - " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" - "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" - "UNION\n" - "SELECT pubname\n" - " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" - " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" - " (SELECT pg_catalog.string_agg(attname, ', ')\n" - " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" - " pg_catalog.pg_attribute\n" - " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" - " ELSE NULL END) " - "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" - "WHERE pr.prrelid = '%s'\n", + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + " AND NOT EXISTS (\n" + " SELECT 1\n" + " FROM pg_catalog.pg_publication_rel pr\n" + " WHERE pr.prpubid = p.oid AND\n" + " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" + "ORDER BY 1;", oid, oid, oid); - - if (pset.sversion >= 190000) - { - /* - * Skip entries where this relation appears in the - * publication's EXCEPT list. - */ - appendPQExpBuffer(&buf, - " AND NOT pr.prexcept\n" - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - " AND NOT EXISTS (\n" - " SELECT 1\n" - " FROM pg_catalog.pg_publication_rel pr\n" - " WHERE pr.prpubid = p.oid AND\n" - " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" - "ORDER BY 1;", - oid, oid, oid); - } - else - { - appendPQExpBuffer(&buf, - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - "ORDER BY 1;", - oid); - } } else { appendPQExpBuffer(&buf, + "UNION\n" "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - "WHERE pr.prrelid = '%s'\n" - "UNION ALL\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" + " , NULL\n" + " , NULL\n" "FROM pg_catalog.pg_publication p\n" "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" "ORDER BY 1;", - oid, oid); + oid); } + } + else + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + "WHERE pr.prrelid = '%s'\n" + "UNION ALL\n" + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + "ORDER BY 1;", + oid, oid); + } - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - if (tuples > 0) - printTableAddFooter(&cont, _("Included in publications:")); + if (tuples > 0) + printTableAddFooter(&cont, _("Included in publications:")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " \"%s\"", + PQgetvalue(result, i, 0)); - /* column list (if any) */ - if (!PQgetisnull(result, i, 2)) - appendPQExpBuffer(&buf, " (%s)", - PQgetvalue(result, i, 2)); + /* column list (if any) */ + if (!PQgetisnull(result, i, 2)) + appendPQExpBuffer(&buf, " (%s)", + PQgetvalue(result, i, 2)); - /* row filter (if any) */ - if (!PQgetisnull(result, i, 1)) - appendPQExpBuffer(&buf, " WHERE %s", - PQgetvalue(result, i, 1)); + /* row filter (if any) */ + if (!PQgetisnull(result, i, 1)) + appendPQExpBuffer(&buf, " WHERE %s", + PQgetvalue(result, i, 1)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* Print publications where the table is in the EXCEPT clause */ if (pset.sversion >= 190000) @@ -3805,7 +3804,7 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) ncols++; } appendPQExpBufferStr(&buf, "\n, r.rolreplication"); - appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); + appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_roles r\n"); @@ -3860,8 +3859,8 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) if (strcmp(PQgetvalue(res, i, (verbose ? 9 : 8)), "t") == 0) add_role_attribute(&buf, _("Replication")); - if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) - add_role_attribute(&buf, _("Bypass RLS")); + if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) + add_role_attribute(&buf, _("Bypass RLS")); conns = atoi(PQgetvalue(res, i, 6)); if (conns >= 0) @@ -5155,14 +5154,14 @@ listCollations(const char *pattern, bool verbose, bool showSystem) gettext_noop("Schema"), gettext_noop("Name")); - appendPQExpBuffer(&buf, - " CASE c.collprovider " - "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " - "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " - "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " - "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " - "END AS \"%s\",\n", - gettext_noop("Provider")); + appendPQExpBuffer(&buf, + " CASE c.collprovider " + "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " + "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " + "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " + "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " + "END AS \"%s\",\n", + gettext_noop("Provider")); appendPQExpBuffer(&buf, " c.collcollate AS \"%s\",\n" -- 2.50.1 (Apple Git-155) --aHl3HfeiUuO3zeNC-- ^ permalink raw reply [nested|flat] 59+ messages in thread
* [PATCH v6 4/4] run pgindent and pgperltidy @ 2026-06-30 18:24 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 59+ messages in thread From: Nathan Bossart @ 2026-06-30 18:24 UTC (permalink / raw) --- src/bin/pg_dump/pg_dump.c | 464 ++++++++++----------- src/bin/pg_dump/pg_dumpall.c | 30 +- src/bin/pg_upgrade/check.c | 16 +- src/bin/pg_upgrade/controldata.c | 2 +- src/bin/pg_upgrade/exec.c | 8 +- src/bin/pg_upgrade/multixact_rewrite.c | 80 ++-- src/bin/pg_upgrade/pg_upgrade.c | 34 +- src/bin/pg_upgrade/relfilenumber.c | 54 +-- src/bin/pg_upgrade/t/006_transfer_modes.pl | 33 +- src/bin/psql/command.c | 29 +- src/bin/psql/describe.c | 461 ++++++++++---------- 11 files changed, 601 insertions(+), 610 deletions(-) diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 65bd15ebfd2..5673268b467 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -1491,8 +1491,8 @@ setup_connection(Archive *AH, const char *dumpencoding, * Disable timeouts if supported. */ ExecuteSqlStatement(AH, "SET statement_timeout = 0"); - ExecuteSqlStatement(AH, "SET lock_timeout = 0"); - ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); + ExecuteSqlStatement(AH, "SET lock_timeout = 0"); + ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); if (AH->remoteVersion >= 170000) ExecuteSqlStatement(AH, "SET transaction_timeout = 0"); @@ -1505,10 +1505,10 @@ setup_connection(Archive *AH, const char *dumpencoding, /* * Adjust row-security mode, if supported. */ - if (dopt->enable_row_security) - ExecuteSqlStatement(AH, "SET row_security = on"); - else - ExecuteSqlStatement(AH, "SET row_security = off"); + if (dopt->enable_row_security) + ExecuteSqlStatement(AH, "SET row_security = on"); + else + ExecuteSqlStatement(AH, "SET row_security = off"); /* * For security reasons, we restrict the expansion of non-system views and @@ -1933,10 +1933,9 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) addObjectDependency(dobj, ext->dobj.dumpId); /* - * Mark the member object to have any non-initial ACLs - * dumped. (Any initial ACLs will be removed later, using data from - * pg_init_privs, so that we'll dump only the delta from the extension's - * initial setup.) + * Mark the member object to have any non-initial ACLs dumped. (Any + * initial ACLs will be removed later, using data from pg_init_privs, so + * that we'll dump only the delta from the extension's initial setup.) * * In binary upgrades, we still dump all components of the members * individually, since the idea is to exactly reproduce the database @@ -1953,7 +1952,7 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) if (fout->dopt->binary_upgrade) dobj->dump = ext->dobj.dump; else - dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); + dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); return true; } @@ -1987,9 +1986,9 @@ selectDumpableNamespace(NamespaceInfo *nsinfo, Archive *fout) else if (strcmp(nsinfo->dobj.name, "pg_catalog") == 0) { /* - * We dump out any ACLs defined in pg_catalog, if - * they are interesting (and not the original ACLs which were set at - * initdb time, see pg_init_privs). + * We dump out any ACLs defined in pg_catalog, if they are interesting + * (and not the original ACLs which were set at initdb time, see + * pg_init_privs). */ nsinfo->dobj.dump_contains = nsinfo->dobj.dump = DUMP_COMPONENT_ACL; } @@ -3296,7 +3295,7 @@ dumpDatabase(Archive *fout) "datcollate, datctype, datfrozenxid, " "datacl, acldefault('d', datdba) AS acldefault, " "datistemplate, datconnlimit, "); - appendPQExpBufferStr(dbQry, "datminmxid, "); + appendPQExpBufferStr(dbQry, "datminmxid, "); if (fout->remoteVersion >= 170000) appendPQExpBufferStr(dbQry, "datlocprovider, datlocale, datcollversion, "); else if (fout->remoteVersion >= 150000) @@ -3638,11 +3637,11 @@ dumpDatabase(Archive *fout) ii_oid, ii_relminmxid; - appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" - "FROM pg_catalog.pg_class\n" - "WHERE oid IN (%u, %u, %u, %u);\n", - LargeObjectRelationId, LargeObjectLOidPNIndexId, - LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); + appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" + "FROM pg_catalog.pg_class\n" + "WHERE oid IN (%u, %u, %u, %u);\n", + LargeObjectRelationId, LargeObjectLOidPNIndexId, + LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); lo_res = ExecuteSqlQuery(fout, loFrozenQry->data, PGRES_TUPLES_OK); @@ -4274,7 +4273,7 @@ getPolicies(Archive *fout, TableInfo tblinfo[], int numTables) printfPQExpBuffer(query, "SELECT pol.oid, pol.tableoid, pol.polrelid, pol.polname, pol.polcmd, "); - appendPQExpBufferStr(query, "pol.polpermissive, "); + appendPQExpBufferStr(query, "pol.polpermissive, "); appendPQExpBuffer(query, "CASE WHEN pol.polroles = '{0}' THEN NULL ELSE " " pg_catalog.array_to_string(ARRAY(SELECT pg_catalog.quote_ident(rolname) from pg_catalog.pg_roles WHERE oid = ANY(pol.polroles)), ', ') END AS polroles, " @@ -6633,9 +6632,9 @@ getAccessMethods(Archive *fout) * Select all access methods from pg_am table. */ appendPQExpBufferStr(query, "SELECT tableoid, oid, amname, "); - appendPQExpBufferStr(query, - "amtype, " - "amhandler::pg_catalog.regproc AS amhandler "); + appendPQExpBufferStr(query, + "amtype, " + "amhandler::pg_catalog.regproc AS amhandler "); appendPQExpBufferStr(query, "FROM pg_am"); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6827,35 +6826,35 @@ getAggregates(Archive *fout) * Find all interesting aggregates. See comment in getFuncs() for the * rationale behind the filtering logic. */ - agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" - : "p.proisagg"); + agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" + : "p.proisagg"); - appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " - "p.proname AS aggname, " - "p.pronamespace AS aggnamespace, " - "p.pronargs, p.proargtypes, " - "p.proowner, " - "p.proacl AS aggacl, " - "acldefault('f', p.proowner) AS acldefault " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s AND (" - "p.pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog') OR " - "p.proacl IS DISTINCT FROM pip.initprivs", - agg_check); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - " OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); - appendPQExpBufferChar(query, ')'); + appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " + "p.proname AS aggname, " + "p.pronamespace AS aggnamespace, " + "p.pronargs, p.proargtypes, " + "p.proowner, " + "p.proacl AS aggacl, " + "acldefault('f', p.proowner) AS acldefault " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s AND (" + "p.pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog') OR " + "p.proacl IS DISTINCT FROM pip.initprivs", + agg_check); + if (dopt->binary_upgrade) + appendPQExpBufferStr(query, + " OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6957,53 +6956,53 @@ getFuncs(Archive *fout) * include them, since we want to dump extension members individually in * that mode. Also, if they are used by casts or transforms then we need * to gather the information about them, though they won't be dumped if - * they are built-in. Also, include functions in - * pg_catalog if they have an ACL different from what's shown in - * pg_init_privs (so we have to join to pg_init_privs; annoying). + * they are built-in. Also, include functions in pg_catalog if they have + * an ACL different from what's shown in pg_init_privs (so we have to join + * to pg_init_privs; annoying). */ - not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" - : "NOT p.proisagg"); + not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" + : "NOT p.proisagg"); - appendPQExpBuffer(query, - "SELECT p.tableoid, p.oid, p.proname, p.prolang, " - "p.pronargs, p.proargtypes, p.prorettype, " - "p.proacl, " - "acldefault('f', p.proowner) AS acldefault, " - "p.pronamespace, " - "p.proowner " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s" - "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " - "WHERE classid = 'pg_proc'::regclass AND " - "objid = p.oid AND deptype = 'i')" - "\n AND (" - "\n pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog')" - "\n OR EXISTS (SELECT 1 FROM pg_cast" - "\n WHERE pg_cast.oid > %u " - "\n AND p.oid = pg_cast.castfunc)" - "\n OR EXISTS (SELECT 1 FROM pg_transform" - "\n WHERE pg_transform.oid > %u AND " - "\n (p.oid = pg_transform.trffromsql" - "\n OR p.oid = pg_transform.trftosql))", - not_agg_check, - g_last_builtin_oid, - g_last_builtin_oid); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); + appendPQExpBuffer(query, + "SELECT p.tableoid, p.oid, p.proname, p.prolang, " + "p.pronargs, p.proargtypes, p.prorettype, " + "p.proacl, " + "acldefault('f', p.proowner) AS acldefault, " + "p.pronamespace, " + "p.proowner " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s" + "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " + "WHERE classid = 'pg_proc'::regclass AND " + "objid = p.oid AND deptype = 'i')" + "\n AND (" + "\n pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog')" + "\n OR EXISTS (SELECT 1 FROM pg_cast" + "\n WHERE pg_cast.oid > %u " + "\n AND p.oid = pg_cast.castfunc)" + "\n OR EXISTS (SELECT 1 FROM pg_transform" + "\n WHERE pg_transform.oid > %u AND " + "\n (p.oid = pg_transform.trffromsql" + "\n OR p.oid = pg_transform.trftosql))", + not_agg_check, + g_last_builtin_oid, + g_last_builtin_oid); + if (dopt->binary_upgrade) appendPQExpBufferStr(query, - "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); - appendPQExpBufferChar(query, ')'); + "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferStr(query, + "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -7252,31 +7251,31 @@ getTables(Archive *fout, int *numTables) appendPQExpBufferStr(query, "c.relhasoids, "); - appendPQExpBufferStr(query, - "c.relispopulated, "); + appendPQExpBufferStr(query, + "c.relispopulated, "); - appendPQExpBufferStr(query, - "c.relreplident, "); + appendPQExpBufferStr(query, + "c.relreplident, "); - appendPQExpBufferStr(query, - "c.relrowsecurity, c.relforcerowsecurity, "); + appendPQExpBufferStr(query, + "c.relrowsecurity, c.relforcerowsecurity, "); - appendPQExpBufferStr(query, - "c.relminmxid, tc.relminmxid AS tminmxid, "); + appendPQExpBufferStr(query, + "c.relminmxid, tc.relminmxid AS tminmxid, "); - appendPQExpBufferStr(query, - "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); + appendPQExpBufferStr(query, + "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); - appendPQExpBufferStr(query, - "am.amname, "); + appendPQExpBufferStr(query, + "am.amname, "); - appendPQExpBufferStr(query, - "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); + appendPQExpBufferStr(query, + "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); - appendPQExpBufferStr(query, - "c.relispartition AS ispartition "); + appendPQExpBufferStr(query, + "c.relispartition AS ispartition "); /* * Left join to pg_depend to pick up dependency info linking sequences to @@ -7296,8 +7295,8 @@ getTables(Archive *fout, int *numTables) /* * Left join to pg_am to pick up the amname. */ - appendPQExpBufferStr(query, - "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); + appendPQExpBufferStr(query, + "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); /* * We purposefully ignore toast OIDs for partitioned tables; the reason is @@ -7868,8 +7867,8 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables) "t.reloptions AS indreloptions, "); - appendPQExpBufferStr(query, - "i.indisreplident, "); + appendPQExpBufferStr(query, + "i.indisreplident, "); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -9313,8 +9312,8 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables) appendPQExpBufferStr(q, "'' AS attcompression,\n"); - appendPQExpBufferStr(q, - "a.attidentity,\n"); + appendPQExpBufferStr(q, + "a.attidentity,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(q, @@ -10717,73 +10716,73 @@ getAdditionalACLs(Archive *fout) PQclear(res); /* Fetch initial-privileges data */ - printfPQExpBuffer(query, - "SELECT objoid, classoid, objsubid, privtype, initprivs " - "FROM pg_init_privs"); + printfPQExpBuffer(query, + "SELECT objoid, classoid, objsubid, privtype, initprivs " + "FROM pg_init_privs"); - res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); + res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); - ntups = PQntuples(res); - for (i = 0; i < ntups; i++) - { - Oid objoid = atooid(PQgetvalue(res, i, 0)); - Oid classoid = atooid(PQgetvalue(res, i, 1)); - int objsubid = atoi(PQgetvalue(res, i, 2)); - char privtype = *(PQgetvalue(res, i, 3)); - char *initprivs = PQgetvalue(res, i, 4); - CatalogId objId; - DumpableObject *dobj; + ntups = PQntuples(res); + for (i = 0; i < ntups; i++) + { + Oid objoid = atooid(PQgetvalue(res, i, 0)); + Oid classoid = atooid(PQgetvalue(res, i, 1)); + int objsubid = atoi(PQgetvalue(res, i, 2)); + char privtype = *(PQgetvalue(res, i, 3)); + char *initprivs = PQgetvalue(res, i, 4); + CatalogId objId; + DumpableObject *dobj; - objId.tableoid = classoid; - objId.oid = objoid; - dobj = findObjectByCatalogId(objId); - /* OK to ignore entries we haven't got a DumpableObject for */ - if (dobj) + objId.tableoid = classoid; + objId.oid = objoid; + dobj = findObjectByCatalogId(objId); + /* OK to ignore entries we haven't got a DumpableObject for */ + if (dobj) + { + /* Cope with sub-object initprivs */ + if (objsubid != 0) { - /* Cope with sub-object initprivs */ - if (objsubid != 0) - { - if (dobj->objType == DO_TABLE) - { - /* For a column initprivs, set the table's ACL flags */ - dobj->components |= DUMP_COMPONENT_ACL; - ((TableInfo *) dobj)->hascolumnACLs = true; - } - else - pg_log_warning("unsupported pg_init_privs entry: %u %u %d", - classoid, objoid, objsubid); - continue; - } - - /* - * We ignore any pg_init_privs.initprivs entry for the public - * schema, as explained in getNamespaces(). - */ - if (dobj->objType == DO_NAMESPACE && - strcmp(dobj->name, "public") == 0) - continue; - - /* Else it had better be of a type we think has ACLs */ - if (dobj->objType == DO_NAMESPACE || - dobj->objType == DO_TYPE || - dobj->objType == DO_FUNC || - dobj->objType == DO_AGG || - dobj->objType == DO_TABLE || - dobj->objType == DO_PROCLANG || - dobj->objType == DO_FDW || - dobj->objType == DO_FOREIGN_SERVER) + if (dobj->objType == DO_TABLE) { - DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; - - daobj->dacl.privtype = privtype; - daobj->dacl.initprivs = pstrdup(initprivs); + /* For a column initprivs, set the table's ACL flags */ + dobj->components |= DUMP_COMPONENT_ACL; + ((TableInfo *) dobj)->hascolumnACLs = true; } else pg_log_warning("unsupported pg_init_privs entry: %u %u %d", classoid, objoid, objsubid); + continue; + } + + /* + * We ignore any pg_init_privs.initprivs entry for the public + * schema, as explained in getNamespaces(). + */ + if (dobj->objType == DO_NAMESPACE && + strcmp(dobj->name, "public") == 0) + continue; + + /* Else it had better be of a type we think has ACLs */ + if (dobj->objType == DO_NAMESPACE || + dobj->objType == DO_TYPE || + dobj->objType == DO_FUNC || + dobj->objType == DO_AGG || + dobj->objType == DO_TABLE || + dobj->objType == DO_PROCLANG || + dobj->objType == DO_FDW || + dobj->objType == DO_FOREIGN_SERVER) + { + DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; + + daobj->dacl.privtype = privtype; + daobj->dacl.initprivs = pstrdup(initprivs); } + else + pg_log_warning("unsupported pg_init_privs entry: %u %u %d", + classoid, objoid, objsubid); } - PQclear(res); + } + PQclear(res); destroyPQExpBuffer(query); } @@ -11128,8 +11127,8 @@ dumpRelationStats_dumper(Archive *fout, const void *userArg, const TocEntry *te) * The results must be in the order of the relations supplied in the * parameters to ensure we remain in sync as we walk through the TOC. * - * For versions before 19, the redundant filter clause on s.tablename = - * ANY(...) seems sufficient to convince the planner to use + * For versions before 19, the redundant filter clause on s.tablename + * = ANY(...) seems sufficient to convince the planner to use * pg_class_relname_nsp_index, which avoids a full scan of pg_stats. * In newer versions, pg_stats returns the table OIDs, eliminating the * need for that hack. @@ -13469,11 +13468,11 @@ dumpFunc(Archive *fout, const FuncInfo *finfo) "pg_catalog.pg_get_function_result(p.oid) AS funcresult,\n" "proleakproof,\n"); - appendPQExpBufferStr(query, - "array_to_string(protrftypes, ' ') AS protrftypes,\n"); + appendPQExpBufferStr(query, + "array_to_string(protrftypes, ' ') AS protrftypes,\n"); - appendPQExpBufferStr(query, - "proparallel,\n"); + appendPQExpBufferStr(query, + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -14963,9 +14962,9 @@ dumpCollation(Archive *fout, const CollInfo *collinfo) /* Get collation-specific details */ appendPQExpBufferStr(query, "SELECT "); - appendPQExpBufferStr(query, - "collprovider, " - "collversion, "); + appendPQExpBufferStr(query, + "collprovider, " + "collversion, "); if (fout->remoteVersion >= 120000) appendPQExpBufferStr(query, @@ -15372,23 +15371,23 @@ dumpAgg(Archive *fout, const AggInfo *agginfo) "pg_catalog.pg_get_function_arguments(p.oid) AS funcargs,\n" "pg_catalog.pg_get_function_identity_arguments(p.oid) AS funciargs,\n"); - appendPQExpBufferStr(query, - "aggkind,\n" - "aggmtransfn,\n" - "aggminvtransfn,\n" - "aggmfinalfn,\n" - "aggmtranstype::pg_catalog.regtype,\n" - "aggfinalextra,\n" - "aggmfinalextra,\n" - "aggtransspace,\n" - "aggmtransspace,\n" - "aggminitval,\n"); + appendPQExpBufferStr(query, + "aggkind,\n" + "aggmtransfn,\n" + "aggminvtransfn,\n" + "aggmfinalfn,\n" + "aggmtranstype::pg_catalog.regtype,\n" + "aggfinalextra,\n" + "aggmfinalextra,\n" + "aggtransspace,\n" + "aggmtransspace,\n" + "aggminitval,\n"); - appendPQExpBufferStr(query, - "aggcombinefn,\n" - "aggserialfn,\n" - "aggdeserialfn,\n" - "proparallel,\n"); + appendPQExpBufferStr(query, + "aggcombinefn,\n" + "aggserialfn,\n" + "aggdeserialfn,\n" + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -16848,30 +16847,30 @@ dumpTable(Archive *fout, const TableInfo *tbinfo) appendPQExpBufferStr(query, "PREPARE getColumnACLs(pg_catalog.oid) AS\n"); - /* - * In principle we should call acldefault('c', relowner) to - * get the default ACL for a column. However, we don't - * currently store the numeric OID of the relowner in - * TableInfo. We could convert the owner name using regrole, - * but that creates a risk of failure due to concurrent role - * renames. Given that the default ACL for columns is empty - * and is likely to stay that way, it's not worth extra cycles - * and risk to avoid hard-wiring that knowledge here. - */ - appendPQExpBufferStr(query, - "SELECT at.attname, " - "at.attacl, " - "'{}' AS acldefault, " - "pip.privtype, pip.initprivs " - "FROM pg_catalog.pg_attribute at " - "LEFT JOIN pg_catalog.pg_init_privs pip ON " - "(at.attrelid = pip.objoid " - "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " - "AND at.attnum = pip.objsubid) " - "WHERE at.attrelid = $1 AND " - "NOT at.attisdropped " - "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " - "ORDER BY at.attnum"); + /* + * In principle we should call acldefault('c', relowner) to get + * the default ACL for a column. However, we don't currently + * store the numeric OID of the relowner in TableInfo. We could + * convert the owner name using regrole, but that creates a risk + * of failure due to concurrent role renames. Given that the + * default ACL for columns is empty and is likely to stay that + * way, it's not worth extra cycles and risk to avoid hard-wiring + * that knowledge here. + */ + appendPQExpBufferStr(query, + "SELECT at.attname, " + "at.attacl, " + "'{}' AS acldefault, " + "pip.privtype, pip.initprivs " + "FROM pg_catalog.pg_attribute at " + "LEFT JOIN pg_catalog.pg_init_privs pip ON " + "(at.attrelid = pip.objoid " + "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " + "AND at.attnum = pip.objsubid) " + "WHERE at.attrelid = $1 AND " + "NOT at.attisdropped " + "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " + "ORDER BY at.attnum"); ExecuteSqlStatement(fout, query->data); @@ -19165,7 +19164,7 @@ collectSequences(Archive *fout) * pg_get_sequence_data(), but we only do so for non-schema-only dumps. */ if (fout->remoteVersion < 180000 || - (!fout->dopt->dumpData && !fout->dopt->sequence_data)) + (!fout->dopt->dumpData && !fout->dopt->sequence_data)) query = "SELECT seqrelid, format_type(seqtypid, NULL), " "seqstart, seqincrement, " "seqmax, seqmin, " @@ -19227,15 +19226,14 @@ dumpSequence(Archive *fout, const TableInfo *tbinfo) qseqname = pg_strdup(fmtId(tbinfo->dobj.name)); /* - * The sequence information is gathered in a sorted - * table before any calls to dumpSequence(). See collectSequences() for - * more information. + * The sequence information is gathered in a sorted table before any calls + * to dumpSequence(). See collectSequences() for more information. */ - Assert(sequences); + Assert(sequences); - key.oid = tbinfo->dobj.catId.oid; - seq = bsearch(&key, sequences, nsequences, - sizeof(SequenceItem), SequenceItemCmp); + key.oid = tbinfo->dobj.catId.oid; + seq = bsearch(&key, sequences, nsequences, + sizeof(SequenceItem), SequenceItemCmp); /* Calculate default limits for a sequence of this type */ is_ascending = (seq->incby >= 0); diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c index e68937c9934..afcd9a218d8 100644 --- a/src/bin/pg_dump/pg_dumpall.c +++ b/src/bin/pg_dump/pg_dumpall.c @@ -785,11 +785,11 @@ dropRoles(PGconn *conn) int i_rolname; int i; - printfPQExpBuffer(buf, - "SELECT rolname " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 1", role_catalog); + printfPQExpBuffer(buf, + "SELECT rolname " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 1", role_catalog); res = executeQuery(conn, buf->data); @@ -843,16 +843,16 @@ dumpRoles(PGconn *conn) * Notes: rolconfig is dumped later, and pg_authid must be used for * extracting rolcomment regardless of role_catalog. */ - printfPQExpBuffer(buf, - "SELECT oid, rolname, rolsuper, rolinherit, " - "rolcreaterole, rolcreatedb, " - "rolcanlogin, rolconnlimit, rolpassword, " - "rolvaliduntil, rolreplication, rolbypassrls, " - "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " - "rolname = current_user AS is_current_user " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 2", role_catalog); + printfPQExpBuffer(buf, + "SELECT oid, rolname, rolsuper, rolinherit, " + "rolcreaterole, rolcreatedb, " + "rolcanlogin, rolconnlimit, rolpassword, " + "rolvaliduntil, rolreplication, rolbypassrls, " + "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " + "rolname = current_user AS is_current_user " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 2", role_catalog); res = executeQuery(conn, buf->data); diff --git a/src/bin/pg_upgrade/check.c b/src/bin/pg_upgrade/check.c index 786c1474829..f725f5ee3e2 100644 --- a/src/bin/pg_upgrade/check.c +++ b/src/bin/pg_upgrade/check.c @@ -1475,15 +1475,15 @@ check_for_incompatible_polymorphics(ClusterInfo *cluster) ", 'array_cat(anyarray,anyarray)'" ", 'array_prepend(anyelement,anyarray)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_remove(anyarray,anyelement)'" - ", 'array_replace(anyarray,anyelement,anyelement)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_remove(anyarray,anyelement)'" + ", 'array_replace(anyarray,anyelement,anyelement)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_position(anyarray,anyelement)'" - ", 'array_position(anyarray,anyelement,integer)'" - ", 'array_positions(anyarray,anyelement)'" - ", 'width_bucket(anyelement,anyarray)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_position(anyarray,anyelement)'" + ", 'array_position(anyarray,anyelement,integer)'" + ", 'array_positions(anyarray,anyelement)'" + ", 'width_bucket(anyelement,anyarray)'"); /* * The query below hardcodes FirstNormalObjectId as 16384 rather than diff --git a/src/bin/pg_upgrade/controldata.c b/src/bin/pg_upgrade/controldata.c index 8f81c9e9582..02ea02df60f 100644 --- a/src/bin/pg_upgrade/controldata.c +++ b/src/bin/pg_upgrade/controldata.c @@ -228,7 +228,7 @@ get_control_data(ClusterInfo *cluster) p++; /* remove ':' char */ cluster->controldata.chkpnt_nxtepoch = str2uint(p); - p = strchr(p, ':'); + p = strchr(p, ':'); if (p == NULL || strlen(p) <= 1) pg_fatal("%d: controldata retrieval problem", __LINE__); diff --git a/src/bin/pg_upgrade/exec.c b/src/bin/pg_upgrade/exec.c index 44355feea30..a1bdbf373e3 100644 --- a/src/bin/pg_upgrade/exec.c +++ b/src/bin/pg_upgrade/exec.c @@ -55,7 +55,7 @@ get_bin_version(ClusterInfo *cluster) if (sscanf(cmd_output, "%*s %*s %d.%d", &v1, &v2) < 1) pg_fatal("could not get pg_ctl version output from %s", cmd); - cluster->bin_version = v1 * 10000; + cluster->bin_version = v1 * 10000; } @@ -344,8 +344,8 @@ check_data_dir(ClusterInfo *cluster) check_single_dir(pg_data, "pg_subtrans"); check_single_dir(pg_data, PG_TBLSPC_DIR); check_single_dir(pg_data, "pg_twophase"); - check_single_dir(pg_data, "pg_wal"); - check_single_dir(pg_data, "pg_xact"); + check_single_dir(pg_data, "pg_wal"); + check_single_dir(pg_data, "pg_xact"); } @@ -385,7 +385,7 @@ check_bin_dir(ClusterInfo *cluster, bool check_versions) */ get_bin_version(cluster); - check_exec(cluster->bindir, "pg_resetwal", check_versions); + check_exec(cluster->bindir, "pg_resetwal", check_versions); if (cluster == &new_cluster) { diff --git a/src/bin/pg_upgrade/multixact_rewrite.c b/src/bin/pg_upgrade/multixact_rewrite.c index c45b3183684..c7a1416494d 100644 --- a/src/bin/pg_upgrade/multixact_rewrite.c +++ b/src/bin/pg_upgrade/multixact_rewrite.c @@ -61,52 +61,52 @@ rewrite_multixacts(MultiXactId from_multi, MultiXactId to_multi) * Convert old multixids, if needed, by reading them one-by-one from the * old cluster. */ - old_reader = AllocOldMultiXactRead(old_cluster.pgdata, - old_cluster.controldata.chkpnt_nxtmulti, - old_cluster.controldata.chkpnt_nxtmxoff); + old_reader = AllocOldMultiXactRead(old_cluster.pgdata, + old_cluster.controldata.chkpnt_nxtmulti, + old_cluster.controldata.chkpnt_nxtmxoff); - for (MultiXactId multi = from_multi; multi != to_multi;) - { - MultiXactMember member; - bool multixid_valid; - - /* - * Read this multixid's members. - * - * Locking-only XIDs that may be part of multi-xids don't matter - * after upgrade, as there can be no transactions running across - * upgrade. So as a small optimization, we only read one member - * from each multixid: the one updating one, or if there was no - * update, arbitrarily the first locking xid. - */ - multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); + for (MultiXactId multi = from_multi; multi != to_multi;) + { + MultiXactMember member; + bool multixid_valid; - /* - * Write the new offset to pg_multixact/offsets. - * - * Even if this multixid is invalid, we still need to write its - * offset if the *previous* multixid was valid. That's because - * when reading a multixid, the number of members is calculated - * from the difference between the two offsets. - */ - RecordMultiXactOffset(offsets_writer, multi, - (multixid_valid || prev_multixid_valid) ? next_offset : 0); + /* + * Read this multixid's members. + * + * Locking-only XIDs that may be part of multi-xids don't matter after + * upgrade, as there can be no transactions running across upgrade. So + * as a small optimization, we only read one member from each + * multixid: the one updating one, or if there was no update, + * arbitrarily the first locking xid. + */ + multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); - /* Write the members */ - if (multixid_valid) - { - RecordMultiXactMembers(members_writer, next_offset, 1, &member); - next_offset += 1; - } + /* + * Write the new offset to pg_multixact/offsets. + * + * Even if this multixid is invalid, we still need to write its offset + * if the *previous* multixid was valid. That's because when reading + * a multixid, the number of members is calculated from the difference + * between the two offsets. + */ + RecordMultiXactOffset(offsets_writer, multi, + (multixid_valid || prev_multixid_valid) ? next_offset : 0); - /* Advance to next multixid, handling wraparound */ - multi++; - if (multi < FirstMultiXactId) - multi = FirstMultiXactId; - prev_multixid_valid = multixid_valid; + /* Write the members */ + if (multixid_valid) + { + RecordMultiXactMembers(members_writer, next_offset, 1, &member); + next_offset += 1; } - FreeOldMultiXactReader(old_reader); + /* Advance to next multixid, handling wraparound */ + multi++; + if (multi < FirstMultiXactId) + multi = FirstMultiXactId; + prev_multixid_valid = multixid_valid; + } + + FreeOldMultiXactReader(old_reader); /* Write the final 'next' offset to the last SLRU page */ RecordMultiXactOffset(offsets_writer, to_multi, diff --git a/src/bin/pg_upgrade/pg_upgrade.c b/src/bin/pg_upgrade/pg_upgrade.c index c6af9035665..7366fd4627c 100644 --- a/src/bin/pg_upgrade/pg_upgrade.c +++ b/src/bin/pg_upgrade/pg_upgrade.c @@ -833,7 +833,7 @@ copy_xact_xlog_xid(void) * Determine the range of multixacts to convert. */ nxtmulti = old_cluster.controldata.chkpnt_nxtmulti; - oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; + oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; /* handle wraparound */ if (nxtmulti < FirstMultiXactId) nxtmulti = FirstMultiXactId; @@ -898,15 +898,15 @@ set_frozenxids(void) int i_datname; int i_datallowconn; - prep_status("Setting frozenxid and minmxid counters in new cluster"); + prep_status("Setting frozenxid and minmxid counters in new cluster"); conn_template1 = connectToServer(&new_cluster, "template1"); - /* set pg_database.datfrozenxid */ - PQclear(executeQueryOrDie(conn_template1, - "UPDATE pg_catalog.pg_database " - "SET datfrozenxid = '%u'", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_database.datfrozenxid */ + PQclear(executeQueryOrDie(conn_template1, + "UPDATE pg_catalog.pg_database " + "SET datfrozenxid = '%u'", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_database.datminmxid */ PQclear(executeQueryOrDie(conn_template1, @@ -942,16 +942,16 @@ set_frozenxids(void) conn = connectToServer(&new_cluster, datname); - /* set pg_class.relfrozenxid */ - PQclear(executeQueryOrDie(conn, - "UPDATE pg_catalog.pg_class " - "SET relfrozenxid = '%u' " - /* only heap, materialized view, and TOAST are vacuumed */ - "WHERE relkind IN (" - CppAsString2(RELKIND_RELATION) ", " - CppAsString2(RELKIND_MATVIEW) ", " - CppAsString2(RELKIND_TOASTVALUE) ")", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_class.relfrozenxid */ + PQclear(executeQueryOrDie(conn, + "UPDATE pg_catalog.pg_class " + "SET relfrozenxid = '%u' " + /* only heap, materialized view, and TOAST are vacuumed */ + "WHERE relkind IN (" + CppAsString2(RELKIND_RELATION) ", " + CppAsString2(RELKIND_MATVIEW) ", " + CppAsString2(RELKIND_TOASTVALUE) ")", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_class.relminmxid */ PQclear(executeQueryOrDie(conn, diff --git a/src/bin/pg_upgrade/relfilenumber.c b/src/bin/pg_upgrade/relfilenumber.c index ec2ff7acb21..6c467bdc8a5 100644 --- a/src/bin/pg_upgrade/relfilenumber.c +++ b/src/bin/pg_upgrade/relfilenumber.c @@ -587,32 +587,32 @@ transfer_relfile(FileNameMap *map, const char *type_suffix) /* Copying files might take some time, so give feedback. */ pg_log(PG_STATUS, "%s", old_file); - switch (user_opts.transfer_mode) - { - case TRANSFER_MODE_CLONE: - pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", - old_file, new_file); - cloneFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", - old_file, new_file); - copyFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY_FILE_RANGE: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", - old_file, new_file); - copyFileByRange(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_LINK: - pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", - old_file, new_file); - linkFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_SWAP: - /* swap mode is handled in its own code path */ - pg_fatal("should never happen"); - break; - } + switch (user_opts.transfer_mode) + { + case TRANSFER_MODE_CLONE: + pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", + old_file, new_file); + cloneFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", + old_file, new_file); + copyFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY_FILE_RANGE: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", + old_file, new_file); + copyFileByRange(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_LINK: + pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", + old_file, new_file); + linkFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_SWAP: + /* swap mode is handled in its own code path */ + pg_fatal("should never happen"); + break; + } } } diff --git a/src/bin/pg_upgrade/t/006_transfer_modes.pl b/src/bin/pg_upgrade/t/006_transfer_modes.pl index 9efa5dc863c..360d05c4b68 100644 --- a/src/bin/pg_upgrade/t/006_transfer_modes.pl +++ b/src/bin/pg_upgrade/t/006_transfer_modes.pl @@ -29,10 +29,8 @@ sub test_mode } $new->init(); - $new->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); - $old->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); + $new->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); + $old->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); # We can only test security labels if both the old and new installations # have dummy_seclabel. @@ -76,15 +74,14 @@ sub test_mode "CREATE TABLE test4 AS SELECT generate_series(400, 502)"); } - $old->safe_psql('postgres', - "CREATE TABLESPACE inplc_tblspc LOCATION ''"); - $old->safe_psql('postgres', - "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); - $old->safe_psql('postgres', - "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" - ); - $old->safe_psql('testdb3', - "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); + $old->safe_psql('postgres', "CREATE TABLESPACE inplc_tblspc LOCATION ''"); + $old->safe_psql('postgres', + "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); + $old->safe_psql('postgres', + "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" + ); + $old->safe_psql('testdb3', + "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); # While we are here, test handling of large objects. $old->safe_psql( @@ -152,12 +149,10 @@ sub test_mode } # Tests for in-place tablespaces. - $result = - $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); - is($result, '104', "test5 data after pg_upgrade $mode"); - $result = - $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); - is($result, '105', "test6 data after pg_upgrade $mode"); + $result = $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); + is($result, '104', "test5 data after pg_upgrade $mode"); + $result = $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); + is($result, '105', "test6 data after pg_upgrade $mode"); # Tests for large objects $result = $new->safe_psql('postgres', "SELECT lo_get(4532)"); diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index 44ef11d980e..c90bf8bbde2 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -6278,23 +6278,22 @@ get_create_object_cmd(EditableObjectType obj_type, Oid oid, * ensure the right view gets replaced. Also, check relation kind * to be sure it's a view. * - * Views may have WITH [LOCAL|CASCADED] - * CHECK OPTION. These are not part of the view definition - * returned by pg_get_viewdef() and so need to be retrieved - * separately. Materialized views may have - * arbitrary storage parameter reloptions. + * Views may have WITH [LOCAL|CASCADED] CHECK OPTION. These are + * not part of the view definition returned by pg_get_viewdef() + * and so need to be retrieved separately. Materialized views may + * have arbitrary storage parameter reloptions. */ printfPQExpBuffer(query, "/* %s */\n", _("Get view's definition and details")); - appendPQExpBuffer(query, - "SELECT nspname, relname, relkind, " - "pg_catalog.pg_get_viewdef(c.oid, true), " - "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " - "FROM pg_catalog.pg_class c " - "LEFT JOIN pg_catalog.pg_namespace n " - "ON c.relnamespace = n.oid WHERE c.oid = %u", - oid); + appendPQExpBuffer(query, + "SELECT nspname, relname, relkind, " + "pg_catalog.pg_get_viewdef(c.oid, true), " + "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " + "FROM pg_catalog.pg_class c " + "LEFT JOIN pg_catalog.pg_namespace n " + "ON c.relnamespace = n.oid WHERE c.oid = %u", + oid); break; } diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index ce99137c613..ac0c55e7aa5 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -387,19 +387,19 @@ describeFunctions(const char *functypes, const char *func_pattern, gettext_noop("stable"), gettext_noop("volatile"), gettext_noop("Volatility")); - appendPQExpBuffer(&buf, - ",\n CASE\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" - " END as \"%s\"", - gettext_noop("restricted"), - gettext_noop("safe"), - gettext_noop("unsafe"), - gettext_noop("Parallel")); + appendPQExpBuffer(&buf, + ",\n CASE\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" + " END as \"%s\"", + gettext_noop("restricted"), + gettext_noop("safe"), + gettext_noop("unsafe"), + gettext_noop("Parallel")); appendPQExpBuffer(&buf, ",\n pg_catalog.pg_get_userbyid(p.proowner) as \"%s\"" ",\n CASE WHEN prosecdef THEN '%s' ELSE '%s' END AS \"%s\"" @@ -599,8 +599,8 @@ describeFunctions(const char *functypes, const char *func_pattern, myopt.title = _("List of functions"); myopt.translate_header = true; - myopt.translate_columns = translate_columns; - myopt.n_translate_columns = lengthof(translate_columns); + myopt.translate_columns = translate_columns; + myopt.n_translate_columns = lengthof(translate_columns); printQuery(res, &myopt, pset.queryFout, false, pset.logfile); @@ -1086,38 +1086,38 @@ permissionsList(const char *pattern, bool showSystem) " ), E'\\n') AS \"%s\"", gettext_noop("Column privileges")); - appendPQExpBuffer(&buf, - ",\n pg_catalog.array_to_string(ARRAY(\n" - " SELECT polname\n" - " || CASE WHEN NOT polpermissive THEN\n" - " E' (RESTRICTIVE)'\n" - " ELSE '' END\n" - " || CASE WHEN polcmd != '*' THEN\n" - " E' (' || polcmd::pg_catalog.text || E'):'\n" - " ELSE E':'\n" - " END\n" - " || CASE WHEN polqual IS NOT NULL THEN\n" - " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" - " ELSE E''\n" - " END\n" - " || CASE WHEN polwithcheck IS NOT NULL THEN\n" - " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" - " ELSE E''\n" - " END" - " || CASE WHEN polroles <> '{0}' THEN\n" - " E'\\n to: ' || pg_catalog.array_to_string(\n" - " ARRAY(\n" - " SELECT rolname\n" - " FROM pg_catalog.pg_roles\n" - " WHERE oid = ANY (polroles)\n" - " ORDER BY 1\n" - " ), E', ')\n" - " ELSE E''\n" - " END\n" - " FROM pg_catalog.pg_policy pol\n" - " WHERE polrelid = c.oid), E'\\n')\n" - " AS \"%s\"", - gettext_noop("Policies")); + appendPQExpBuffer(&buf, + ",\n pg_catalog.array_to_string(ARRAY(\n" + " SELECT polname\n" + " || CASE WHEN NOT polpermissive THEN\n" + " E' (RESTRICTIVE)'\n" + " ELSE '' END\n" + " || CASE WHEN polcmd != '*' THEN\n" + " E' (' || polcmd::pg_catalog.text || E'):'\n" + " ELSE E':'\n" + " END\n" + " || CASE WHEN polqual IS NOT NULL THEN\n" + " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" + " ELSE E''\n" + " END\n" + " || CASE WHEN polwithcheck IS NOT NULL THEN\n" + " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" + " ELSE E''\n" + " END" + " || CASE WHEN polroles <> '{0}' THEN\n" + " E'\\n to: ' || pg_catalog.array_to_string(\n" + " ARRAY(\n" + " SELECT rolname\n" + " FROM pg_catalog.pg_roles\n" + " WHERE oid = ANY (polroles)\n" + " ORDER BY 1\n" + " ), E', ')\n" + " ELSE E''\n" + " END\n" + " FROM pg_catalog.pg_policy pol\n" + " WHERE polrelid = c.oid), E'\\n')\n" + " AS \"%s\"", + gettext_noop("Policies")); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_class c\n" " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n" @@ -1675,27 +1675,27 @@ describeOneTableDetails(const char *schemaname, char *footers[3] = {NULL, NULL, NULL}; printfPQExpBuffer(&buf, "/* %s */\n", _("Get sequence information")); - appendPQExpBuffer(&buf, - "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" - " seqstart AS \"%s\",\n" - " seqmin AS \"%s\",\n" - " seqmax AS \"%s\",\n" - " seqincrement AS \"%s\",\n" - " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" - " seqcache AS \"%s\"\n", - gettext_noop("Type"), - gettext_noop("Start"), - gettext_noop("Minimum"), - gettext_noop("Maximum"), - gettext_noop("Increment"), - gettext_noop("yes"), - gettext_noop("no"), - gettext_noop("Cycles?"), - gettext_noop("Cache")); - appendPQExpBuffer(&buf, - "FROM pg_catalog.pg_sequence\n" - "WHERE seqrelid = '%s';", - oid); + appendPQExpBuffer(&buf, + "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" + " seqstart AS \"%s\",\n" + " seqmin AS \"%s\",\n" + " seqmax AS \"%s\",\n" + " seqincrement AS \"%s\",\n" + " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" + " seqcache AS \"%s\"\n", + gettext_noop("Type"), + gettext_noop("Start"), + gettext_noop("Minimum"), + gettext_noop("Maximum"), + gettext_noop("Increment"), + gettext_noop("yes"), + gettext_noop("no"), + gettext_noop("Cycles?"), + gettext_noop("Cache")); + appendPQExpBuffer(&buf, + "FROM pg_catalog.pg_sequence\n" + "WHERE seqrelid = '%s';", + oid); res = PSQLexec(buf.data); if (!res) @@ -1913,7 +1913,7 @@ describeOneTableDetails(const char *schemaname, appendPQExpBufferStr(&buf, ",\n (SELECT c.collname FROM pg_catalog.pg_collation c, pg_catalog.pg_type t\n" " WHERE c.oid = a.attcollation AND t.oid = a.atttypid AND a.attcollation <> t.typcollation) AS attcollation"); attcoll_col = cols++; - appendPQExpBufferStr(&buf, ",\n a.attidentity"); + appendPQExpBufferStr(&buf, ",\n a.attidentity"); attidentity_col = cols++; if (pset.sversion >= 120000) appendPQExpBufferStr(&buf, ",\n a.attgenerated"); @@ -2326,7 +2326,7 @@ describeOneTableDetails(const char *schemaname, CppAsString2(CONSTRAINT_EXCLUSION) ") AND " "condeferred) AS condeferred,\n"); - appendPQExpBufferStr(&buf, "i.indisreplident,\n"); + appendPQExpBufferStr(&buf, "i.indisreplident,\n"); if (pset.sversion >= 150000) appendPQExpBufferStr(&buf, "i.indnullsnotdistinct,\n"); @@ -2431,7 +2431,7 @@ describeOneTableDetails(const char *schemaname, "pg_catalog.pg_get_indexdef(i.indexrelid, 0, true),\n " "pg_catalog.pg_get_constraintdef(con.oid, true), " "contype, condeferrable, condeferred"); - appendPQExpBufferStr(&buf, ", i.indisreplident"); + appendPQExpBufferStr(&buf, ", i.indisreplident"); appendPQExpBufferStr(&buf, ", c2.reltablespace"); if (pset.sversion >= 180000) appendPQExpBufferStr(&buf, ", con.conperiod"); @@ -2682,81 +2682,80 @@ describeOneTableDetails(const char *schemaname, PQclear(result); /* print any row-level policies */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get row-level policies for this table")); - appendPQExpBufferStr(&buf, "SELECT pol.polname,"); - appendPQExpBufferStr(&buf, - " pol.polpermissive,\n"); - appendPQExpBuffer(&buf, - " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" - " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" - " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" - " CASE pol.polcmd\n" - " WHEN 'r' THEN 'SELECT'\n" - " WHEN 'a' THEN 'INSERT'\n" - " WHEN 'w' THEN 'UPDATE'\n" - " WHEN 'd' THEN 'DELETE'\n" - " END AS cmd\n" - "FROM pg_catalog.pg_policy pol\n" - "WHERE pol.polrelid = '%s' ORDER BY 1;", - oid); + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get row-level policies for this table")); + appendPQExpBufferStr(&buf, "SELECT pol.polname,"); + appendPQExpBufferStr(&buf, + " pol.polpermissive,\n"); + appendPQExpBuffer(&buf, + " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" + " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" + " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" + " CASE pol.polcmd\n" + " WHEN 'r' THEN 'SELECT'\n" + " WHEN 'a' THEN 'INSERT'\n" + " WHEN 'w' THEN 'UPDATE'\n" + " WHEN 'd' THEN 'DELETE'\n" + " END AS cmd\n" + "FROM pg_catalog.pg_policy pol\n" + "WHERE pol.polrelid = '%s' ORDER BY 1;", + oid); - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - /* - * Handle cases where RLS is enabled and there are policies, or - * there aren't policies, or RLS isn't enabled but there are - * policies - */ - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies:")); + /* + * Handle cases where RLS is enabled and there are policies, or there + * aren't policies, or RLS isn't enabled but there are policies + */ + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies:")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled):")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled):")); - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); - if (!tableinfo.rowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (row security disabled):")); + if (!tableinfo.rowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (row security disabled):")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " POLICY \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " POLICY \"%s\"", + PQgetvalue(result, i, 0)); - if (*(PQgetvalue(result, i, 1)) == 'f') - appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); + if (*(PQgetvalue(result, i, 1)) == 'f') + appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); - if (!PQgetisnull(result, i, 5)) - appendPQExpBuffer(&buf, " FOR %s", - PQgetvalue(result, i, 5)); + if (!PQgetisnull(result, i, 5)) + appendPQExpBuffer(&buf, " FOR %s", + PQgetvalue(result, i, 5)); - if (!PQgetisnull(result, i, 2)) - { - appendPQExpBuffer(&buf, "\n TO %s", - PQgetvalue(result, i, 2)); - } + if (!PQgetisnull(result, i, 2)) + { + appendPQExpBuffer(&buf, "\n TO %s", + PQgetvalue(result, i, 2)); + } - if (!PQgetisnull(result, i, 3)) - appendPQExpBuffer(&buf, "\n USING (%s)", - PQgetvalue(result, i, 3)); + if (!PQgetisnull(result, i, 3)) + appendPQExpBuffer(&buf, "\n USING (%s)", + PQgetvalue(result, i, 3)); - if (!PQgetisnull(result, i, 4)) - appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", - PQgetvalue(result, i, 4)); + if (!PQgetisnull(result, i, 4)) + appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", + PQgetvalue(result, i, 4)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* print any extended statistics */ if (pset.sversion >= 140000) @@ -3025,115 +3024,115 @@ describeOneTableDetails(const char *schemaname, } /* print any publications */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get publications that publish this table")); - if (pset.sversion >= 150000) + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get publications that publish this table")); + if (pset.sversion >= 150000) + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" + " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" + "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" + "UNION\n" + "SELECT pubname\n" + " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" + " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" + " (SELECT pg_catalog.string_agg(attname, ', ')\n" + " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" + " pg_catalog.pg_attribute\n" + " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" + " ELSE NULL END) " + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" + "WHERE pr.prrelid = '%s'\n", + oid, oid, oid); + + if (pset.sversion >= 190000) { + /* + * Skip entries where this relation appears in the + * publication's EXCEPT list. + */ appendPQExpBuffer(&buf, + " AND NOT pr.prexcept\n" + "UNION\n" "SELECT pubname\n" " , NULL\n" " , NULL\n" "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" - " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" - "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" - "UNION\n" - "SELECT pubname\n" - " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" - " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" - " (SELECT pg_catalog.string_agg(attname, ', ')\n" - " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" - " pg_catalog.pg_attribute\n" - " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" - " ELSE NULL END) " - "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" - "WHERE pr.prrelid = '%s'\n", + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + " AND NOT EXISTS (\n" + " SELECT 1\n" + " FROM pg_catalog.pg_publication_rel pr\n" + " WHERE pr.prpubid = p.oid AND\n" + " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" + "ORDER BY 1;", oid, oid, oid); - - if (pset.sversion >= 190000) - { - /* - * Skip entries where this relation appears in the - * publication's EXCEPT list. - */ - appendPQExpBuffer(&buf, - " AND NOT pr.prexcept\n" - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - " AND NOT EXISTS (\n" - " SELECT 1\n" - " FROM pg_catalog.pg_publication_rel pr\n" - " WHERE pr.prpubid = p.oid AND\n" - " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" - "ORDER BY 1;", - oid, oid, oid); - } - else - { - appendPQExpBuffer(&buf, - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - "ORDER BY 1;", - oid); - } } else { appendPQExpBuffer(&buf, + "UNION\n" "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - "WHERE pr.prrelid = '%s'\n" - "UNION ALL\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" + " , NULL\n" + " , NULL\n" "FROM pg_catalog.pg_publication p\n" "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" "ORDER BY 1;", - oid, oid); + oid); } + } + else + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + "WHERE pr.prrelid = '%s'\n" + "UNION ALL\n" + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + "ORDER BY 1;", + oid, oid); + } - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - if (tuples > 0) - printTableAddFooter(&cont, _("Included in publications:")); + if (tuples > 0) + printTableAddFooter(&cont, _("Included in publications:")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " \"%s\"", + PQgetvalue(result, i, 0)); - /* column list (if any) */ - if (!PQgetisnull(result, i, 2)) - appendPQExpBuffer(&buf, " (%s)", - PQgetvalue(result, i, 2)); + /* column list (if any) */ + if (!PQgetisnull(result, i, 2)) + appendPQExpBuffer(&buf, " (%s)", + PQgetvalue(result, i, 2)); - /* row filter (if any) */ - if (!PQgetisnull(result, i, 1)) - appendPQExpBuffer(&buf, " WHERE %s", - PQgetvalue(result, i, 1)); + /* row filter (if any) */ + if (!PQgetisnull(result, i, 1)) + appendPQExpBuffer(&buf, " WHERE %s", + PQgetvalue(result, i, 1)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* Print publications where the table is in the EXCEPT clause */ if (pset.sversion >= 190000) @@ -3805,7 +3804,7 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) ncols++; } appendPQExpBufferStr(&buf, "\n, r.rolreplication"); - appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); + appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_roles r\n"); @@ -3860,8 +3859,8 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) if (strcmp(PQgetvalue(res, i, (verbose ? 9 : 8)), "t") == 0) add_role_attribute(&buf, _("Replication")); - if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) - add_role_attribute(&buf, _("Bypass RLS")); + if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) + add_role_attribute(&buf, _("Bypass RLS")); conns = atoi(PQgetvalue(res, i, 6)); if (conns >= 0) @@ -5155,14 +5154,14 @@ listCollations(const char *pattern, bool verbose, bool showSystem) gettext_noop("Schema"), gettext_noop("Name")); - appendPQExpBuffer(&buf, - " CASE c.collprovider " - "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " - "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " - "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " - "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " - "END AS \"%s\",\n", - gettext_noop("Provider")); + appendPQExpBuffer(&buf, + " CASE c.collprovider " + "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " + "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " + "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " + "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " + "END AS \"%s\",\n", + gettext_noop("Provider")); appendPQExpBuffer(&buf, " c.collcollate AS \"%s\",\n" -- 2.50.1 (Apple Git-155) --aHl3HfeiUuO3zeNC-- ^ permalink raw reply [nested|flat] 59+ messages in thread
* [PATCH v6 4/4] run pgindent and pgperltidy @ 2026-06-30 18:24 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 59+ messages in thread From: Nathan Bossart @ 2026-06-30 18:24 UTC (permalink / raw) --- src/bin/pg_dump/pg_dump.c | 464 ++++++++++----------- src/bin/pg_dump/pg_dumpall.c | 30 +- src/bin/pg_upgrade/check.c | 16 +- src/bin/pg_upgrade/controldata.c | 2 +- src/bin/pg_upgrade/exec.c | 8 +- src/bin/pg_upgrade/multixact_rewrite.c | 80 ++-- src/bin/pg_upgrade/pg_upgrade.c | 34 +- src/bin/pg_upgrade/relfilenumber.c | 54 +-- src/bin/pg_upgrade/t/006_transfer_modes.pl | 33 +- src/bin/psql/command.c | 29 +- src/bin/psql/describe.c | 461 ++++++++++---------- 11 files changed, 601 insertions(+), 610 deletions(-) diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 65bd15ebfd2..5673268b467 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -1491,8 +1491,8 @@ setup_connection(Archive *AH, const char *dumpencoding, * Disable timeouts if supported. */ ExecuteSqlStatement(AH, "SET statement_timeout = 0"); - ExecuteSqlStatement(AH, "SET lock_timeout = 0"); - ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); + ExecuteSqlStatement(AH, "SET lock_timeout = 0"); + ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); if (AH->remoteVersion >= 170000) ExecuteSqlStatement(AH, "SET transaction_timeout = 0"); @@ -1505,10 +1505,10 @@ setup_connection(Archive *AH, const char *dumpencoding, /* * Adjust row-security mode, if supported. */ - if (dopt->enable_row_security) - ExecuteSqlStatement(AH, "SET row_security = on"); - else - ExecuteSqlStatement(AH, "SET row_security = off"); + if (dopt->enable_row_security) + ExecuteSqlStatement(AH, "SET row_security = on"); + else + ExecuteSqlStatement(AH, "SET row_security = off"); /* * For security reasons, we restrict the expansion of non-system views and @@ -1933,10 +1933,9 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) addObjectDependency(dobj, ext->dobj.dumpId); /* - * Mark the member object to have any non-initial ACLs - * dumped. (Any initial ACLs will be removed later, using data from - * pg_init_privs, so that we'll dump only the delta from the extension's - * initial setup.) + * Mark the member object to have any non-initial ACLs dumped. (Any + * initial ACLs will be removed later, using data from pg_init_privs, so + * that we'll dump only the delta from the extension's initial setup.) * * In binary upgrades, we still dump all components of the members * individually, since the idea is to exactly reproduce the database @@ -1953,7 +1952,7 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) if (fout->dopt->binary_upgrade) dobj->dump = ext->dobj.dump; else - dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); + dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); return true; } @@ -1987,9 +1986,9 @@ selectDumpableNamespace(NamespaceInfo *nsinfo, Archive *fout) else if (strcmp(nsinfo->dobj.name, "pg_catalog") == 0) { /* - * We dump out any ACLs defined in pg_catalog, if - * they are interesting (and not the original ACLs which were set at - * initdb time, see pg_init_privs). + * We dump out any ACLs defined in pg_catalog, if they are interesting + * (and not the original ACLs which were set at initdb time, see + * pg_init_privs). */ nsinfo->dobj.dump_contains = nsinfo->dobj.dump = DUMP_COMPONENT_ACL; } @@ -3296,7 +3295,7 @@ dumpDatabase(Archive *fout) "datcollate, datctype, datfrozenxid, " "datacl, acldefault('d', datdba) AS acldefault, " "datistemplate, datconnlimit, "); - appendPQExpBufferStr(dbQry, "datminmxid, "); + appendPQExpBufferStr(dbQry, "datminmxid, "); if (fout->remoteVersion >= 170000) appendPQExpBufferStr(dbQry, "datlocprovider, datlocale, datcollversion, "); else if (fout->remoteVersion >= 150000) @@ -3638,11 +3637,11 @@ dumpDatabase(Archive *fout) ii_oid, ii_relminmxid; - appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" - "FROM pg_catalog.pg_class\n" - "WHERE oid IN (%u, %u, %u, %u);\n", - LargeObjectRelationId, LargeObjectLOidPNIndexId, - LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); + appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" + "FROM pg_catalog.pg_class\n" + "WHERE oid IN (%u, %u, %u, %u);\n", + LargeObjectRelationId, LargeObjectLOidPNIndexId, + LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); lo_res = ExecuteSqlQuery(fout, loFrozenQry->data, PGRES_TUPLES_OK); @@ -4274,7 +4273,7 @@ getPolicies(Archive *fout, TableInfo tblinfo[], int numTables) printfPQExpBuffer(query, "SELECT pol.oid, pol.tableoid, pol.polrelid, pol.polname, pol.polcmd, "); - appendPQExpBufferStr(query, "pol.polpermissive, "); + appendPQExpBufferStr(query, "pol.polpermissive, "); appendPQExpBuffer(query, "CASE WHEN pol.polroles = '{0}' THEN NULL ELSE " " pg_catalog.array_to_string(ARRAY(SELECT pg_catalog.quote_ident(rolname) from pg_catalog.pg_roles WHERE oid = ANY(pol.polroles)), ', ') END AS polroles, " @@ -6633,9 +6632,9 @@ getAccessMethods(Archive *fout) * Select all access methods from pg_am table. */ appendPQExpBufferStr(query, "SELECT tableoid, oid, amname, "); - appendPQExpBufferStr(query, - "amtype, " - "amhandler::pg_catalog.regproc AS amhandler "); + appendPQExpBufferStr(query, + "amtype, " + "amhandler::pg_catalog.regproc AS amhandler "); appendPQExpBufferStr(query, "FROM pg_am"); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6827,35 +6826,35 @@ getAggregates(Archive *fout) * Find all interesting aggregates. See comment in getFuncs() for the * rationale behind the filtering logic. */ - agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" - : "p.proisagg"); + agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" + : "p.proisagg"); - appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " - "p.proname AS aggname, " - "p.pronamespace AS aggnamespace, " - "p.pronargs, p.proargtypes, " - "p.proowner, " - "p.proacl AS aggacl, " - "acldefault('f', p.proowner) AS acldefault " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s AND (" - "p.pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog') OR " - "p.proacl IS DISTINCT FROM pip.initprivs", - agg_check); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - " OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); - appendPQExpBufferChar(query, ')'); + appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " + "p.proname AS aggname, " + "p.pronamespace AS aggnamespace, " + "p.pronargs, p.proargtypes, " + "p.proowner, " + "p.proacl AS aggacl, " + "acldefault('f', p.proowner) AS acldefault " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s AND (" + "p.pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog') OR " + "p.proacl IS DISTINCT FROM pip.initprivs", + agg_check); + if (dopt->binary_upgrade) + appendPQExpBufferStr(query, + " OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6957,53 +6956,53 @@ getFuncs(Archive *fout) * include them, since we want to dump extension members individually in * that mode. Also, if they are used by casts or transforms then we need * to gather the information about them, though they won't be dumped if - * they are built-in. Also, include functions in - * pg_catalog if they have an ACL different from what's shown in - * pg_init_privs (so we have to join to pg_init_privs; annoying). + * they are built-in. Also, include functions in pg_catalog if they have + * an ACL different from what's shown in pg_init_privs (so we have to join + * to pg_init_privs; annoying). */ - not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" - : "NOT p.proisagg"); + not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" + : "NOT p.proisagg"); - appendPQExpBuffer(query, - "SELECT p.tableoid, p.oid, p.proname, p.prolang, " - "p.pronargs, p.proargtypes, p.prorettype, " - "p.proacl, " - "acldefault('f', p.proowner) AS acldefault, " - "p.pronamespace, " - "p.proowner " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s" - "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " - "WHERE classid = 'pg_proc'::regclass AND " - "objid = p.oid AND deptype = 'i')" - "\n AND (" - "\n pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog')" - "\n OR EXISTS (SELECT 1 FROM pg_cast" - "\n WHERE pg_cast.oid > %u " - "\n AND p.oid = pg_cast.castfunc)" - "\n OR EXISTS (SELECT 1 FROM pg_transform" - "\n WHERE pg_transform.oid > %u AND " - "\n (p.oid = pg_transform.trffromsql" - "\n OR p.oid = pg_transform.trftosql))", - not_agg_check, - g_last_builtin_oid, - g_last_builtin_oid); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); + appendPQExpBuffer(query, + "SELECT p.tableoid, p.oid, p.proname, p.prolang, " + "p.pronargs, p.proargtypes, p.prorettype, " + "p.proacl, " + "acldefault('f', p.proowner) AS acldefault, " + "p.pronamespace, " + "p.proowner " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s" + "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " + "WHERE classid = 'pg_proc'::regclass AND " + "objid = p.oid AND deptype = 'i')" + "\n AND (" + "\n pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog')" + "\n OR EXISTS (SELECT 1 FROM pg_cast" + "\n WHERE pg_cast.oid > %u " + "\n AND p.oid = pg_cast.castfunc)" + "\n OR EXISTS (SELECT 1 FROM pg_transform" + "\n WHERE pg_transform.oid > %u AND " + "\n (p.oid = pg_transform.trffromsql" + "\n OR p.oid = pg_transform.trftosql))", + not_agg_check, + g_last_builtin_oid, + g_last_builtin_oid); + if (dopt->binary_upgrade) appendPQExpBufferStr(query, - "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); - appendPQExpBufferChar(query, ')'); + "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferStr(query, + "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -7252,31 +7251,31 @@ getTables(Archive *fout, int *numTables) appendPQExpBufferStr(query, "c.relhasoids, "); - appendPQExpBufferStr(query, - "c.relispopulated, "); + appendPQExpBufferStr(query, + "c.relispopulated, "); - appendPQExpBufferStr(query, - "c.relreplident, "); + appendPQExpBufferStr(query, + "c.relreplident, "); - appendPQExpBufferStr(query, - "c.relrowsecurity, c.relforcerowsecurity, "); + appendPQExpBufferStr(query, + "c.relrowsecurity, c.relforcerowsecurity, "); - appendPQExpBufferStr(query, - "c.relminmxid, tc.relminmxid AS tminmxid, "); + appendPQExpBufferStr(query, + "c.relminmxid, tc.relminmxid AS tminmxid, "); - appendPQExpBufferStr(query, - "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); + appendPQExpBufferStr(query, + "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); - appendPQExpBufferStr(query, - "am.amname, "); + appendPQExpBufferStr(query, + "am.amname, "); - appendPQExpBufferStr(query, - "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); + appendPQExpBufferStr(query, + "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); - appendPQExpBufferStr(query, - "c.relispartition AS ispartition "); + appendPQExpBufferStr(query, + "c.relispartition AS ispartition "); /* * Left join to pg_depend to pick up dependency info linking sequences to @@ -7296,8 +7295,8 @@ getTables(Archive *fout, int *numTables) /* * Left join to pg_am to pick up the amname. */ - appendPQExpBufferStr(query, - "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); + appendPQExpBufferStr(query, + "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); /* * We purposefully ignore toast OIDs for partitioned tables; the reason is @@ -7868,8 +7867,8 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables) "t.reloptions AS indreloptions, "); - appendPQExpBufferStr(query, - "i.indisreplident, "); + appendPQExpBufferStr(query, + "i.indisreplident, "); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -9313,8 +9312,8 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables) appendPQExpBufferStr(q, "'' AS attcompression,\n"); - appendPQExpBufferStr(q, - "a.attidentity,\n"); + appendPQExpBufferStr(q, + "a.attidentity,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(q, @@ -10717,73 +10716,73 @@ getAdditionalACLs(Archive *fout) PQclear(res); /* Fetch initial-privileges data */ - printfPQExpBuffer(query, - "SELECT objoid, classoid, objsubid, privtype, initprivs " - "FROM pg_init_privs"); + printfPQExpBuffer(query, + "SELECT objoid, classoid, objsubid, privtype, initprivs " + "FROM pg_init_privs"); - res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); + res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); - ntups = PQntuples(res); - for (i = 0; i < ntups; i++) - { - Oid objoid = atooid(PQgetvalue(res, i, 0)); - Oid classoid = atooid(PQgetvalue(res, i, 1)); - int objsubid = atoi(PQgetvalue(res, i, 2)); - char privtype = *(PQgetvalue(res, i, 3)); - char *initprivs = PQgetvalue(res, i, 4); - CatalogId objId; - DumpableObject *dobj; + ntups = PQntuples(res); + for (i = 0; i < ntups; i++) + { + Oid objoid = atooid(PQgetvalue(res, i, 0)); + Oid classoid = atooid(PQgetvalue(res, i, 1)); + int objsubid = atoi(PQgetvalue(res, i, 2)); + char privtype = *(PQgetvalue(res, i, 3)); + char *initprivs = PQgetvalue(res, i, 4); + CatalogId objId; + DumpableObject *dobj; - objId.tableoid = classoid; - objId.oid = objoid; - dobj = findObjectByCatalogId(objId); - /* OK to ignore entries we haven't got a DumpableObject for */ - if (dobj) + objId.tableoid = classoid; + objId.oid = objoid; + dobj = findObjectByCatalogId(objId); + /* OK to ignore entries we haven't got a DumpableObject for */ + if (dobj) + { + /* Cope with sub-object initprivs */ + if (objsubid != 0) { - /* Cope with sub-object initprivs */ - if (objsubid != 0) - { - if (dobj->objType == DO_TABLE) - { - /* For a column initprivs, set the table's ACL flags */ - dobj->components |= DUMP_COMPONENT_ACL; - ((TableInfo *) dobj)->hascolumnACLs = true; - } - else - pg_log_warning("unsupported pg_init_privs entry: %u %u %d", - classoid, objoid, objsubid); - continue; - } - - /* - * We ignore any pg_init_privs.initprivs entry for the public - * schema, as explained in getNamespaces(). - */ - if (dobj->objType == DO_NAMESPACE && - strcmp(dobj->name, "public") == 0) - continue; - - /* Else it had better be of a type we think has ACLs */ - if (dobj->objType == DO_NAMESPACE || - dobj->objType == DO_TYPE || - dobj->objType == DO_FUNC || - dobj->objType == DO_AGG || - dobj->objType == DO_TABLE || - dobj->objType == DO_PROCLANG || - dobj->objType == DO_FDW || - dobj->objType == DO_FOREIGN_SERVER) + if (dobj->objType == DO_TABLE) { - DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; - - daobj->dacl.privtype = privtype; - daobj->dacl.initprivs = pstrdup(initprivs); + /* For a column initprivs, set the table's ACL flags */ + dobj->components |= DUMP_COMPONENT_ACL; + ((TableInfo *) dobj)->hascolumnACLs = true; } else pg_log_warning("unsupported pg_init_privs entry: %u %u %d", classoid, objoid, objsubid); + continue; + } + + /* + * We ignore any pg_init_privs.initprivs entry for the public + * schema, as explained in getNamespaces(). + */ + if (dobj->objType == DO_NAMESPACE && + strcmp(dobj->name, "public") == 0) + continue; + + /* Else it had better be of a type we think has ACLs */ + if (dobj->objType == DO_NAMESPACE || + dobj->objType == DO_TYPE || + dobj->objType == DO_FUNC || + dobj->objType == DO_AGG || + dobj->objType == DO_TABLE || + dobj->objType == DO_PROCLANG || + dobj->objType == DO_FDW || + dobj->objType == DO_FOREIGN_SERVER) + { + DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; + + daobj->dacl.privtype = privtype; + daobj->dacl.initprivs = pstrdup(initprivs); } + else + pg_log_warning("unsupported pg_init_privs entry: %u %u %d", + classoid, objoid, objsubid); } - PQclear(res); + } + PQclear(res); destroyPQExpBuffer(query); } @@ -11128,8 +11127,8 @@ dumpRelationStats_dumper(Archive *fout, const void *userArg, const TocEntry *te) * The results must be in the order of the relations supplied in the * parameters to ensure we remain in sync as we walk through the TOC. * - * For versions before 19, the redundant filter clause on s.tablename = - * ANY(...) seems sufficient to convince the planner to use + * For versions before 19, the redundant filter clause on s.tablename + * = ANY(...) seems sufficient to convince the planner to use * pg_class_relname_nsp_index, which avoids a full scan of pg_stats. * In newer versions, pg_stats returns the table OIDs, eliminating the * need for that hack. @@ -13469,11 +13468,11 @@ dumpFunc(Archive *fout, const FuncInfo *finfo) "pg_catalog.pg_get_function_result(p.oid) AS funcresult,\n" "proleakproof,\n"); - appendPQExpBufferStr(query, - "array_to_string(protrftypes, ' ') AS protrftypes,\n"); + appendPQExpBufferStr(query, + "array_to_string(protrftypes, ' ') AS protrftypes,\n"); - appendPQExpBufferStr(query, - "proparallel,\n"); + appendPQExpBufferStr(query, + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -14963,9 +14962,9 @@ dumpCollation(Archive *fout, const CollInfo *collinfo) /* Get collation-specific details */ appendPQExpBufferStr(query, "SELECT "); - appendPQExpBufferStr(query, - "collprovider, " - "collversion, "); + appendPQExpBufferStr(query, + "collprovider, " + "collversion, "); if (fout->remoteVersion >= 120000) appendPQExpBufferStr(query, @@ -15372,23 +15371,23 @@ dumpAgg(Archive *fout, const AggInfo *agginfo) "pg_catalog.pg_get_function_arguments(p.oid) AS funcargs,\n" "pg_catalog.pg_get_function_identity_arguments(p.oid) AS funciargs,\n"); - appendPQExpBufferStr(query, - "aggkind,\n" - "aggmtransfn,\n" - "aggminvtransfn,\n" - "aggmfinalfn,\n" - "aggmtranstype::pg_catalog.regtype,\n" - "aggfinalextra,\n" - "aggmfinalextra,\n" - "aggtransspace,\n" - "aggmtransspace,\n" - "aggminitval,\n"); + appendPQExpBufferStr(query, + "aggkind,\n" + "aggmtransfn,\n" + "aggminvtransfn,\n" + "aggmfinalfn,\n" + "aggmtranstype::pg_catalog.regtype,\n" + "aggfinalextra,\n" + "aggmfinalextra,\n" + "aggtransspace,\n" + "aggmtransspace,\n" + "aggminitval,\n"); - appendPQExpBufferStr(query, - "aggcombinefn,\n" - "aggserialfn,\n" - "aggdeserialfn,\n" - "proparallel,\n"); + appendPQExpBufferStr(query, + "aggcombinefn,\n" + "aggserialfn,\n" + "aggdeserialfn,\n" + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -16848,30 +16847,30 @@ dumpTable(Archive *fout, const TableInfo *tbinfo) appendPQExpBufferStr(query, "PREPARE getColumnACLs(pg_catalog.oid) AS\n"); - /* - * In principle we should call acldefault('c', relowner) to - * get the default ACL for a column. However, we don't - * currently store the numeric OID of the relowner in - * TableInfo. We could convert the owner name using regrole, - * but that creates a risk of failure due to concurrent role - * renames. Given that the default ACL for columns is empty - * and is likely to stay that way, it's not worth extra cycles - * and risk to avoid hard-wiring that knowledge here. - */ - appendPQExpBufferStr(query, - "SELECT at.attname, " - "at.attacl, " - "'{}' AS acldefault, " - "pip.privtype, pip.initprivs " - "FROM pg_catalog.pg_attribute at " - "LEFT JOIN pg_catalog.pg_init_privs pip ON " - "(at.attrelid = pip.objoid " - "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " - "AND at.attnum = pip.objsubid) " - "WHERE at.attrelid = $1 AND " - "NOT at.attisdropped " - "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " - "ORDER BY at.attnum"); + /* + * In principle we should call acldefault('c', relowner) to get + * the default ACL for a column. However, we don't currently + * store the numeric OID of the relowner in TableInfo. We could + * convert the owner name using regrole, but that creates a risk + * of failure due to concurrent role renames. Given that the + * default ACL for columns is empty and is likely to stay that + * way, it's not worth extra cycles and risk to avoid hard-wiring + * that knowledge here. + */ + appendPQExpBufferStr(query, + "SELECT at.attname, " + "at.attacl, " + "'{}' AS acldefault, " + "pip.privtype, pip.initprivs " + "FROM pg_catalog.pg_attribute at " + "LEFT JOIN pg_catalog.pg_init_privs pip ON " + "(at.attrelid = pip.objoid " + "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " + "AND at.attnum = pip.objsubid) " + "WHERE at.attrelid = $1 AND " + "NOT at.attisdropped " + "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " + "ORDER BY at.attnum"); ExecuteSqlStatement(fout, query->data); @@ -19165,7 +19164,7 @@ collectSequences(Archive *fout) * pg_get_sequence_data(), but we only do so for non-schema-only dumps. */ if (fout->remoteVersion < 180000 || - (!fout->dopt->dumpData && !fout->dopt->sequence_data)) + (!fout->dopt->dumpData && !fout->dopt->sequence_data)) query = "SELECT seqrelid, format_type(seqtypid, NULL), " "seqstart, seqincrement, " "seqmax, seqmin, " @@ -19227,15 +19226,14 @@ dumpSequence(Archive *fout, const TableInfo *tbinfo) qseqname = pg_strdup(fmtId(tbinfo->dobj.name)); /* - * The sequence information is gathered in a sorted - * table before any calls to dumpSequence(). See collectSequences() for - * more information. + * The sequence information is gathered in a sorted table before any calls + * to dumpSequence(). See collectSequences() for more information. */ - Assert(sequences); + Assert(sequences); - key.oid = tbinfo->dobj.catId.oid; - seq = bsearch(&key, sequences, nsequences, - sizeof(SequenceItem), SequenceItemCmp); + key.oid = tbinfo->dobj.catId.oid; + seq = bsearch(&key, sequences, nsequences, + sizeof(SequenceItem), SequenceItemCmp); /* Calculate default limits for a sequence of this type */ is_ascending = (seq->incby >= 0); diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c index e68937c9934..afcd9a218d8 100644 --- a/src/bin/pg_dump/pg_dumpall.c +++ b/src/bin/pg_dump/pg_dumpall.c @@ -785,11 +785,11 @@ dropRoles(PGconn *conn) int i_rolname; int i; - printfPQExpBuffer(buf, - "SELECT rolname " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 1", role_catalog); + printfPQExpBuffer(buf, + "SELECT rolname " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 1", role_catalog); res = executeQuery(conn, buf->data); @@ -843,16 +843,16 @@ dumpRoles(PGconn *conn) * Notes: rolconfig is dumped later, and pg_authid must be used for * extracting rolcomment regardless of role_catalog. */ - printfPQExpBuffer(buf, - "SELECT oid, rolname, rolsuper, rolinherit, " - "rolcreaterole, rolcreatedb, " - "rolcanlogin, rolconnlimit, rolpassword, " - "rolvaliduntil, rolreplication, rolbypassrls, " - "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " - "rolname = current_user AS is_current_user " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 2", role_catalog); + printfPQExpBuffer(buf, + "SELECT oid, rolname, rolsuper, rolinherit, " + "rolcreaterole, rolcreatedb, " + "rolcanlogin, rolconnlimit, rolpassword, " + "rolvaliduntil, rolreplication, rolbypassrls, " + "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " + "rolname = current_user AS is_current_user " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 2", role_catalog); res = executeQuery(conn, buf->data); diff --git a/src/bin/pg_upgrade/check.c b/src/bin/pg_upgrade/check.c index 786c1474829..f725f5ee3e2 100644 --- a/src/bin/pg_upgrade/check.c +++ b/src/bin/pg_upgrade/check.c @@ -1475,15 +1475,15 @@ check_for_incompatible_polymorphics(ClusterInfo *cluster) ", 'array_cat(anyarray,anyarray)'" ", 'array_prepend(anyelement,anyarray)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_remove(anyarray,anyelement)'" - ", 'array_replace(anyarray,anyelement,anyelement)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_remove(anyarray,anyelement)'" + ", 'array_replace(anyarray,anyelement,anyelement)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_position(anyarray,anyelement)'" - ", 'array_position(anyarray,anyelement,integer)'" - ", 'array_positions(anyarray,anyelement)'" - ", 'width_bucket(anyelement,anyarray)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_position(anyarray,anyelement)'" + ", 'array_position(anyarray,anyelement,integer)'" + ", 'array_positions(anyarray,anyelement)'" + ", 'width_bucket(anyelement,anyarray)'"); /* * The query below hardcodes FirstNormalObjectId as 16384 rather than diff --git a/src/bin/pg_upgrade/controldata.c b/src/bin/pg_upgrade/controldata.c index 8f81c9e9582..02ea02df60f 100644 --- a/src/bin/pg_upgrade/controldata.c +++ b/src/bin/pg_upgrade/controldata.c @@ -228,7 +228,7 @@ get_control_data(ClusterInfo *cluster) p++; /* remove ':' char */ cluster->controldata.chkpnt_nxtepoch = str2uint(p); - p = strchr(p, ':'); + p = strchr(p, ':'); if (p == NULL || strlen(p) <= 1) pg_fatal("%d: controldata retrieval problem", __LINE__); diff --git a/src/bin/pg_upgrade/exec.c b/src/bin/pg_upgrade/exec.c index 44355feea30..a1bdbf373e3 100644 --- a/src/bin/pg_upgrade/exec.c +++ b/src/bin/pg_upgrade/exec.c @@ -55,7 +55,7 @@ get_bin_version(ClusterInfo *cluster) if (sscanf(cmd_output, "%*s %*s %d.%d", &v1, &v2) < 1) pg_fatal("could not get pg_ctl version output from %s", cmd); - cluster->bin_version = v1 * 10000; + cluster->bin_version = v1 * 10000; } @@ -344,8 +344,8 @@ check_data_dir(ClusterInfo *cluster) check_single_dir(pg_data, "pg_subtrans"); check_single_dir(pg_data, PG_TBLSPC_DIR); check_single_dir(pg_data, "pg_twophase"); - check_single_dir(pg_data, "pg_wal"); - check_single_dir(pg_data, "pg_xact"); + check_single_dir(pg_data, "pg_wal"); + check_single_dir(pg_data, "pg_xact"); } @@ -385,7 +385,7 @@ check_bin_dir(ClusterInfo *cluster, bool check_versions) */ get_bin_version(cluster); - check_exec(cluster->bindir, "pg_resetwal", check_versions); + check_exec(cluster->bindir, "pg_resetwal", check_versions); if (cluster == &new_cluster) { diff --git a/src/bin/pg_upgrade/multixact_rewrite.c b/src/bin/pg_upgrade/multixact_rewrite.c index c45b3183684..c7a1416494d 100644 --- a/src/bin/pg_upgrade/multixact_rewrite.c +++ b/src/bin/pg_upgrade/multixact_rewrite.c @@ -61,52 +61,52 @@ rewrite_multixacts(MultiXactId from_multi, MultiXactId to_multi) * Convert old multixids, if needed, by reading them one-by-one from the * old cluster. */ - old_reader = AllocOldMultiXactRead(old_cluster.pgdata, - old_cluster.controldata.chkpnt_nxtmulti, - old_cluster.controldata.chkpnt_nxtmxoff); + old_reader = AllocOldMultiXactRead(old_cluster.pgdata, + old_cluster.controldata.chkpnt_nxtmulti, + old_cluster.controldata.chkpnt_nxtmxoff); - for (MultiXactId multi = from_multi; multi != to_multi;) - { - MultiXactMember member; - bool multixid_valid; - - /* - * Read this multixid's members. - * - * Locking-only XIDs that may be part of multi-xids don't matter - * after upgrade, as there can be no transactions running across - * upgrade. So as a small optimization, we only read one member - * from each multixid: the one updating one, or if there was no - * update, arbitrarily the first locking xid. - */ - multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); + for (MultiXactId multi = from_multi; multi != to_multi;) + { + MultiXactMember member; + bool multixid_valid; - /* - * Write the new offset to pg_multixact/offsets. - * - * Even if this multixid is invalid, we still need to write its - * offset if the *previous* multixid was valid. That's because - * when reading a multixid, the number of members is calculated - * from the difference between the two offsets. - */ - RecordMultiXactOffset(offsets_writer, multi, - (multixid_valid || prev_multixid_valid) ? next_offset : 0); + /* + * Read this multixid's members. + * + * Locking-only XIDs that may be part of multi-xids don't matter after + * upgrade, as there can be no transactions running across upgrade. So + * as a small optimization, we only read one member from each + * multixid: the one updating one, or if there was no update, + * arbitrarily the first locking xid. + */ + multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); - /* Write the members */ - if (multixid_valid) - { - RecordMultiXactMembers(members_writer, next_offset, 1, &member); - next_offset += 1; - } + /* + * Write the new offset to pg_multixact/offsets. + * + * Even if this multixid is invalid, we still need to write its offset + * if the *previous* multixid was valid. That's because when reading + * a multixid, the number of members is calculated from the difference + * between the two offsets. + */ + RecordMultiXactOffset(offsets_writer, multi, + (multixid_valid || prev_multixid_valid) ? next_offset : 0); - /* Advance to next multixid, handling wraparound */ - multi++; - if (multi < FirstMultiXactId) - multi = FirstMultiXactId; - prev_multixid_valid = multixid_valid; + /* Write the members */ + if (multixid_valid) + { + RecordMultiXactMembers(members_writer, next_offset, 1, &member); + next_offset += 1; } - FreeOldMultiXactReader(old_reader); + /* Advance to next multixid, handling wraparound */ + multi++; + if (multi < FirstMultiXactId) + multi = FirstMultiXactId; + prev_multixid_valid = multixid_valid; + } + + FreeOldMultiXactReader(old_reader); /* Write the final 'next' offset to the last SLRU page */ RecordMultiXactOffset(offsets_writer, to_multi, diff --git a/src/bin/pg_upgrade/pg_upgrade.c b/src/bin/pg_upgrade/pg_upgrade.c index c6af9035665..7366fd4627c 100644 --- a/src/bin/pg_upgrade/pg_upgrade.c +++ b/src/bin/pg_upgrade/pg_upgrade.c @@ -833,7 +833,7 @@ copy_xact_xlog_xid(void) * Determine the range of multixacts to convert. */ nxtmulti = old_cluster.controldata.chkpnt_nxtmulti; - oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; + oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; /* handle wraparound */ if (nxtmulti < FirstMultiXactId) nxtmulti = FirstMultiXactId; @@ -898,15 +898,15 @@ set_frozenxids(void) int i_datname; int i_datallowconn; - prep_status("Setting frozenxid and minmxid counters in new cluster"); + prep_status("Setting frozenxid and minmxid counters in new cluster"); conn_template1 = connectToServer(&new_cluster, "template1"); - /* set pg_database.datfrozenxid */ - PQclear(executeQueryOrDie(conn_template1, - "UPDATE pg_catalog.pg_database " - "SET datfrozenxid = '%u'", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_database.datfrozenxid */ + PQclear(executeQueryOrDie(conn_template1, + "UPDATE pg_catalog.pg_database " + "SET datfrozenxid = '%u'", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_database.datminmxid */ PQclear(executeQueryOrDie(conn_template1, @@ -942,16 +942,16 @@ set_frozenxids(void) conn = connectToServer(&new_cluster, datname); - /* set pg_class.relfrozenxid */ - PQclear(executeQueryOrDie(conn, - "UPDATE pg_catalog.pg_class " - "SET relfrozenxid = '%u' " - /* only heap, materialized view, and TOAST are vacuumed */ - "WHERE relkind IN (" - CppAsString2(RELKIND_RELATION) ", " - CppAsString2(RELKIND_MATVIEW) ", " - CppAsString2(RELKIND_TOASTVALUE) ")", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_class.relfrozenxid */ + PQclear(executeQueryOrDie(conn, + "UPDATE pg_catalog.pg_class " + "SET relfrozenxid = '%u' " + /* only heap, materialized view, and TOAST are vacuumed */ + "WHERE relkind IN (" + CppAsString2(RELKIND_RELATION) ", " + CppAsString2(RELKIND_MATVIEW) ", " + CppAsString2(RELKIND_TOASTVALUE) ")", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_class.relminmxid */ PQclear(executeQueryOrDie(conn, diff --git a/src/bin/pg_upgrade/relfilenumber.c b/src/bin/pg_upgrade/relfilenumber.c index ec2ff7acb21..6c467bdc8a5 100644 --- a/src/bin/pg_upgrade/relfilenumber.c +++ b/src/bin/pg_upgrade/relfilenumber.c @@ -587,32 +587,32 @@ transfer_relfile(FileNameMap *map, const char *type_suffix) /* Copying files might take some time, so give feedback. */ pg_log(PG_STATUS, "%s", old_file); - switch (user_opts.transfer_mode) - { - case TRANSFER_MODE_CLONE: - pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", - old_file, new_file); - cloneFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", - old_file, new_file); - copyFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY_FILE_RANGE: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", - old_file, new_file); - copyFileByRange(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_LINK: - pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", - old_file, new_file); - linkFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_SWAP: - /* swap mode is handled in its own code path */ - pg_fatal("should never happen"); - break; - } + switch (user_opts.transfer_mode) + { + case TRANSFER_MODE_CLONE: + pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", + old_file, new_file); + cloneFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", + old_file, new_file); + copyFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY_FILE_RANGE: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", + old_file, new_file); + copyFileByRange(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_LINK: + pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", + old_file, new_file); + linkFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_SWAP: + /* swap mode is handled in its own code path */ + pg_fatal("should never happen"); + break; + } } } diff --git a/src/bin/pg_upgrade/t/006_transfer_modes.pl b/src/bin/pg_upgrade/t/006_transfer_modes.pl index 9efa5dc863c..360d05c4b68 100644 --- a/src/bin/pg_upgrade/t/006_transfer_modes.pl +++ b/src/bin/pg_upgrade/t/006_transfer_modes.pl @@ -29,10 +29,8 @@ sub test_mode } $new->init(); - $new->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); - $old->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); + $new->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); + $old->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); # We can only test security labels if both the old and new installations # have dummy_seclabel. @@ -76,15 +74,14 @@ sub test_mode "CREATE TABLE test4 AS SELECT generate_series(400, 502)"); } - $old->safe_psql('postgres', - "CREATE TABLESPACE inplc_tblspc LOCATION ''"); - $old->safe_psql('postgres', - "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); - $old->safe_psql('postgres', - "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" - ); - $old->safe_psql('testdb3', - "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); + $old->safe_psql('postgres', "CREATE TABLESPACE inplc_tblspc LOCATION ''"); + $old->safe_psql('postgres', + "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); + $old->safe_psql('postgres', + "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" + ); + $old->safe_psql('testdb3', + "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); # While we are here, test handling of large objects. $old->safe_psql( @@ -152,12 +149,10 @@ sub test_mode } # Tests for in-place tablespaces. - $result = - $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); - is($result, '104', "test5 data after pg_upgrade $mode"); - $result = - $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); - is($result, '105', "test6 data after pg_upgrade $mode"); + $result = $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); + is($result, '104', "test5 data after pg_upgrade $mode"); + $result = $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); + is($result, '105', "test6 data after pg_upgrade $mode"); # Tests for large objects $result = $new->safe_psql('postgres', "SELECT lo_get(4532)"); diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index 44ef11d980e..c90bf8bbde2 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -6278,23 +6278,22 @@ get_create_object_cmd(EditableObjectType obj_type, Oid oid, * ensure the right view gets replaced. Also, check relation kind * to be sure it's a view. * - * Views may have WITH [LOCAL|CASCADED] - * CHECK OPTION. These are not part of the view definition - * returned by pg_get_viewdef() and so need to be retrieved - * separately. Materialized views may have - * arbitrary storage parameter reloptions. + * Views may have WITH [LOCAL|CASCADED] CHECK OPTION. These are + * not part of the view definition returned by pg_get_viewdef() + * and so need to be retrieved separately. Materialized views may + * have arbitrary storage parameter reloptions. */ printfPQExpBuffer(query, "/* %s */\n", _("Get view's definition and details")); - appendPQExpBuffer(query, - "SELECT nspname, relname, relkind, " - "pg_catalog.pg_get_viewdef(c.oid, true), " - "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " - "FROM pg_catalog.pg_class c " - "LEFT JOIN pg_catalog.pg_namespace n " - "ON c.relnamespace = n.oid WHERE c.oid = %u", - oid); + appendPQExpBuffer(query, + "SELECT nspname, relname, relkind, " + "pg_catalog.pg_get_viewdef(c.oid, true), " + "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " + "FROM pg_catalog.pg_class c " + "LEFT JOIN pg_catalog.pg_namespace n " + "ON c.relnamespace = n.oid WHERE c.oid = %u", + oid); break; } diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index ce99137c613..ac0c55e7aa5 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -387,19 +387,19 @@ describeFunctions(const char *functypes, const char *func_pattern, gettext_noop("stable"), gettext_noop("volatile"), gettext_noop("Volatility")); - appendPQExpBuffer(&buf, - ",\n CASE\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" - " END as \"%s\"", - gettext_noop("restricted"), - gettext_noop("safe"), - gettext_noop("unsafe"), - gettext_noop("Parallel")); + appendPQExpBuffer(&buf, + ",\n CASE\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" + " END as \"%s\"", + gettext_noop("restricted"), + gettext_noop("safe"), + gettext_noop("unsafe"), + gettext_noop("Parallel")); appendPQExpBuffer(&buf, ",\n pg_catalog.pg_get_userbyid(p.proowner) as \"%s\"" ",\n CASE WHEN prosecdef THEN '%s' ELSE '%s' END AS \"%s\"" @@ -599,8 +599,8 @@ describeFunctions(const char *functypes, const char *func_pattern, myopt.title = _("List of functions"); myopt.translate_header = true; - myopt.translate_columns = translate_columns; - myopt.n_translate_columns = lengthof(translate_columns); + myopt.translate_columns = translate_columns; + myopt.n_translate_columns = lengthof(translate_columns); printQuery(res, &myopt, pset.queryFout, false, pset.logfile); @@ -1086,38 +1086,38 @@ permissionsList(const char *pattern, bool showSystem) " ), E'\\n') AS \"%s\"", gettext_noop("Column privileges")); - appendPQExpBuffer(&buf, - ",\n pg_catalog.array_to_string(ARRAY(\n" - " SELECT polname\n" - " || CASE WHEN NOT polpermissive THEN\n" - " E' (RESTRICTIVE)'\n" - " ELSE '' END\n" - " || CASE WHEN polcmd != '*' THEN\n" - " E' (' || polcmd::pg_catalog.text || E'):'\n" - " ELSE E':'\n" - " END\n" - " || CASE WHEN polqual IS NOT NULL THEN\n" - " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" - " ELSE E''\n" - " END\n" - " || CASE WHEN polwithcheck IS NOT NULL THEN\n" - " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" - " ELSE E''\n" - " END" - " || CASE WHEN polroles <> '{0}' THEN\n" - " E'\\n to: ' || pg_catalog.array_to_string(\n" - " ARRAY(\n" - " SELECT rolname\n" - " FROM pg_catalog.pg_roles\n" - " WHERE oid = ANY (polroles)\n" - " ORDER BY 1\n" - " ), E', ')\n" - " ELSE E''\n" - " END\n" - " FROM pg_catalog.pg_policy pol\n" - " WHERE polrelid = c.oid), E'\\n')\n" - " AS \"%s\"", - gettext_noop("Policies")); + appendPQExpBuffer(&buf, + ",\n pg_catalog.array_to_string(ARRAY(\n" + " SELECT polname\n" + " || CASE WHEN NOT polpermissive THEN\n" + " E' (RESTRICTIVE)'\n" + " ELSE '' END\n" + " || CASE WHEN polcmd != '*' THEN\n" + " E' (' || polcmd::pg_catalog.text || E'):'\n" + " ELSE E':'\n" + " END\n" + " || CASE WHEN polqual IS NOT NULL THEN\n" + " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" + " ELSE E''\n" + " END\n" + " || CASE WHEN polwithcheck IS NOT NULL THEN\n" + " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" + " ELSE E''\n" + " END" + " || CASE WHEN polroles <> '{0}' THEN\n" + " E'\\n to: ' || pg_catalog.array_to_string(\n" + " ARRAY(\n" + " SELECT rolname\n" + " FROM pg_catalog.pg_roles\n" + " WHERE oid = ANY (polroles)\n" + " ORDER BY 1\n" + " ), E', ')\n" + " ELSE E''\n" + " END\n" + " FROM pg_catalog.pg_policy pol\n" + " WHERE polrelid = c.oid), E'\\n')\n" + " AS \"%s\"", + gettext_noop("Policies")); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_class c\n" " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n" @@ -1675,27 +1675,27 @@ describeOneTableDetails(const char *schemaname, char *footers[3] = {NULL, NULL, NULL}; printfPQExpBuffer(&buf, "/* %s */\n", _("Get sequence information")); - appendPQExpBuffer(&buf, - "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" - " seqstart AS \"%s\",\n" - " seqmin AS \"%s\",\n" - " seqmax AS \"%s\",\n" - " seqincrement AS \"%s\",\n" - " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" - " seqcache AS \"%s\"\n", - gettext_noop("Type"), - gettext_noop("Start"), - gettext_noop("Minimum"), - gettext_noop("Maximum"), - gettext_noop("Increment"), - gettext_noop("yes"), - gettext_noop("no"), - gettext_noop("Cycles?"), - gettext_noop("Cache")); - appendPQExpBuffer(&buf, - "FROM pg_catalog.pg_sequence\n" - "WHERE seqrelid = '%s';", - oid); + appendPQExpBuffer(&buf, + "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" + " seqstart AS \"%s\",\n" + " seqmin AS \"%s\",\n" + " seqmax AS \"%s\",\n" + " seqincrement AS \"%s\",\n" + " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" + " seqcache AS \"%s\"\n", + gettext_noop("Type"), + gettext_noop("Start"), + gettext_noop("Minimum"), + gettext_noop("Maximum"), + gettext_noop("Increment"), + gettext_noop("yes"), + gettext_noop("no"), + gettext_noop("Cycles?"), + gettext_noop("Cache")); + appendPQExpBuffer(&buf, + "FROM pg_catalog.pg_sequence\n" + "WHERE seqrelid = '%s';", + oid); res = PSQLexec(buf.data); if (!res) @@ -1913,7 +1913,7 @@ describeOneTableDetails(const char *schemaname, appendPQExpBufferStr(&buf, ",\n (SELECT c.collname FROM pg_catalog.pg_collation c, pg_catalog.pg_type t\n" " WHERE c.oid = a.attcollation AND t.oid = a.atttypid AND a.attcollation <> t.typcollation) AS attcollation"); attcoll_col = cols++; - appendPQExpBufferStr(&buf, ",\n a.attidentity"); + appendPQExpBufferStr(&buf, ",\n a.attidentity"); attidentity_col = cols++; if (pset.sversion >= 120000) appendPQExpBufferStr(&buf, ",\n a.attgenerated"); @@ -2326,7 +2326,7 @@ describeOneTableDetails(const char *schemaname, CppAsString2(CONSTRAINT_EXCLUSION) ") AND " "condeferred) AS condeferred,\n"); - appendPQExpBufferStr(&buf, "i.indisreplident,\n"); + appendPQExpBufferStr(&buf, "i.indisreplident,\n"); if (pset.sversion >= 150000) appendPQExpBufferStr(&buf, "i.indnullsnotdistinct,\n"); @@ -2431,7 +2431,7 @@ describeOneTableDetails(const char *schemaname, "pg_catalog.pg_get_indexdef(i.indexrelid, 0, true),\n " "pg_catalog.pg_get_constraintdef(con.oid, true), " "contype, condeferrable, condeferred"); - appendPQExpBufferStr(&buf, ", i.indisreplident"); + appendPQExpBufferStr(&buf, ", i.indisreplident"); appendPQExpBufferStr(&buf, ", c2.reltablespace"); if (pset.sversion >= 180000) appendPQExpBufferStr(&buf, ", con.conperiod"); @@ -2682,81 +2682,80 @@ describeOneTableDetails(const char *schemaname, PQclear(result); /* print any row-level policies */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get row-level policies for this table")); - appendPQExpBufferStr(&buf, "SELECT pol.polname,"); - appendPQExpBufferStr(&buf, - " pol.polpermissive,\n"); - appendPQExpBuffer(&buf, - " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" - " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" - " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" - " CASE pol.polcmd\n" - " WHEN 'r' THEN 'SELECT'\n" - " WHEN 'a' THEN 'INSERT'\n" - " WHEN 'w' THEN 'UPDATE'\n" - " WHEN 'd' THEN 'DELETE'\n" - " END AS cmd\n" - "FROM pg_catalog.pg_policy pol\n" - "WHERE pol.polrelid = '%s' ORDER BY 1;", - oid); + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get row-level policies for this table")); + appendPQExpBufferStr(&buf, "SELECT pol.polname,"); + appendPQExpBufferStr(&buf, + " pol.polpermissive,\n"); + appendPQExpBuffer(&buf, + " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" + " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" + " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" + " CASE pol.polcmd\n" + " WHEN 'r' THEN 'SELECT'\n" + " WHEN 'a' THEN 'INSERT'\n" + " WHEN 'w' THEN 'UPDATE'\n" + " WHEN 'd' THEN 'DELETE'\n" + " END AS cmd\n" + "FROM pg_catalog.pg_policy pol\n" + "WHERE pol.polrelid = '%s' ORDER BY 1;", + oid); - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - /* - * Handle cases where RLS is enabled and there are policies, or - * there aren't policies, or RLS isn't enabled but there are - * policies - */ - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies:")); + /* + * Handle cases where RLS is enabled and there are policies, or there + * aren't policies, or RLS isn't enabled but there are policies + */ + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies:")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled):")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled):")); - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); - if (!tableinfo.rowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (row security disabled):")); + if (!tableinfo.rowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (row security disabled):")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " POLICY \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " POLICY \"%s\"", + PQgetvalue(result, i, 0)); - if (*(PQgetvalue(result, i, 1)) == 'f') - appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); + if (*(PQgetvalue(result, i, 1)) == 'f') + appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); - if (!PQgetisnull(result, i, 5)) - appendPQExpBuffer(&buf, " FOR %s", - PQgetvalue(result, i, 5)); + if (!PQgetisnull(result, i, 5)) + appendPQExpBuffer(&buf, " FOR %s", + PQgetvalue(result, i, 5)); - if (!PQgetisnull(result, i, 2)) - { - appendPQExpBuffer(&buf, "\n TO %s", - PQgetvalue(result, i, 2)); - } + if (!PQgetisnull(result, i, 2)) + { + appendPQExpBuffer(&buf, "\n TO %s", + PQgetvalue(result, i, 2)); + } - if (!PQgetisnull(result, i, 3)) - appendPQExpBuffer(&buf, "\n USING (%s)", - PQgetvalue(result, i, 3)); + if (!PQgetisnull(result, i, 3)) + appendPQExpBuffer(&buf, "\n USING (%s)", + PQgetvalue(result, i, 3)); - if (!PQgetisnull(result, i, 4)) - appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", - PQgetvalue(result, i, 4)); + if (!PQgetisnull(result, i, 4)) + appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", + PQgetvalue(result, i, 4)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* print any extended statistics */ if (pset.sversion >= 140000) @@ -3025,115 +3024,115 @@ describeOneTableDetails(const char *schemaname, } /* print any publications */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get publications that publish this table")); - if (pset.sversion >= 150000) + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get publications that publish this table")); + if (pset.sversion >= 150000) + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" + " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" + "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" + "UNION\n" + "SELECT pubname\n" + " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" + " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" + " (SELECT pg_catalog.string_agg(attname, ', ')\n" + " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" + " pg_catalog.pg_attribute\n" + " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" + " ELSE NULL END) " + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" + "WHERE pr.prrelid = '%s'\n", + oid, oid, oid); + + if (pset.sversion >= 190000) { + /* + * Skip entries where this relation appears in the + * publication's EXCEPT list. + */ appendPQExpBuffer(&buf, + " AND NOT pr.prexcept\n" + "UNION\n" "SELECT pubname\n" " , NULL\n" " , NULL\n" "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" - " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" - "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" - "UNION\n" - "SELECT pubname\n" - " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" - " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" - " (SELECT pg_catalog.string_agg(attname, ', ')\n" - " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" - " pg_catalog.pg_attribute\n" - " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" - " ELSE NULL END) " - "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" - "WHERE pr.prrelid = '%s'\n", + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + " AND NOT EXISTS (\n" + " SELECT 1\n" + " FROM pg_catalog.pg_publication_rel pr\n" + " WHERE pr.prpubid = p.oid AND\n" + " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" + "ORDER BY 1;", oid, oid, oid); - - if (pset.sversion >= 190000) - { - /* - * Skip entries where this relation appears in the - * publication's EXCEPT list. - */ - appendPQExpBuffer(&buf, - " AND NOT pr.prexcept\n" - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - " AND NOT EXISTS (\n" - " SELECT 1\n" - " FROM pg_catalog.pg_publication_rel pr\n" - " WHERE pr.prpubid = p.oid AND\n" - " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" - "ORDER BY 1;", - oid, oid, oid); - } - else - { - appendPQExpBuffer(&buf, - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - "ORDER BY 1;", - oid); - } } else { appendPQExpBuffer(&buf, + "UNION\n" "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - "WHERE pr.prrelid = '%s'\n" - "UNION ALL\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" + " , NULL\n" + " , NULL\n" "FROM pg_catalog.pg_publication p\n" "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" "ORDER BY 1;", - oid, oid); + oid); } + } + else + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + "WHERE pr.prrelid = '%s'\n" + "UNION ALL\n" + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + "ORDER BY 1;", + oid, oid); + } - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - if (tuples > 0) - printTableAddFooter(&cont, _("Included in publications:")); + if (tuples > 0) + printTableAddFooter(&cont, _("Included in publications:")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " \"%s\"", + PQgetvalue(result, i, 0)); - /* column list (if any) */ - if (!PQgetisnull(result, i, 2)) - appendPQExpBuffer(&buf, " (%s)", - PQgetvalue(result, i, 2)); + /* column list (if any) */ + if (!PQgetisnull(result, i, 2)) + appendPQExpBuffer(&buf, " (%s)", + PQgetvalue(result, i, 2)); - /* row filter (if any) */ - if (!PQgetisnull(result, i, 1)) - appendPQExpBuffer(&buf, " WHERE %s", - PQgetvalue(result, i, 1)); + /* row filter (if any) */ + if (!PQgetisnull(result, i, 1)) + appendPQExpBuffer(&buf, " WHERE %s", + PQgetvalue(result, i, 1)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* Print publications where the table is in the EXCEPT clause */ if (pset.sversion >= 190000) @@ -3805,7 +3804,7 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) ncols++; } appendPQExpBufferStr(&buf, "\n, r.rolreplication"); - appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); + appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_roles r\n"); @@ -3860,8 +3859,8 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) if (strcmp(PQgetvalue(res, i, (verbose ? 9 : 8)), "t") == 0) add_role_attribute(&buf, _("Replication")); - if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) - add_role_attribute(&buf, _("Bypass RLS")); + if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) + add_role_attribute(&buf, _("Bypass RLS")); conns = atoi(PQgetvalue(res, i, 6)); if (conns >= 0) @@ -5155,14 +5154,14 @@ listCollations(const char *pattern, bool verbose, bool showSystem) gettext_noop("Schema"), gettext_noop("Name")); - appendPQExpBuffer(&buf, - " CASE c.collprovider " - "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " - "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " - "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " - "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " - "END AS \"%s\",\n", - gettext_noop("Provider")); + appendPQExpBuffer(&buf, + " CASE c.collprovider " + "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " + "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " + "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " + "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " + "END AS \"%s\",\n", + gettext_noop("Provider")); appendPQExpBuffer(&buf, " c.collcollate AS \"%s\",\n" -- 2.50.1 (Apple Git-155) --aHl3HfeiUuO3zeNC-- ^ permalink raw reply [nested|flat] 59+ messages in thread
* [PATCH v6 4/4] run pgindent and pgperltidy @ 2026-06-30 18:24 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 59+ messages in thread From: Nathan Bossart @ 2026-06-30 18:24 UTC (permalink / raw) --- src/bin/pg_dump/pg_dump.c | 464 ++++++++++----------- src/bin/pg_dump/pg_dumpall.c | 30 +- src/bin/pg_upgrade/check.c | 16 +- src/bin/pg_upgrade/controldata.c | 2 +- src/bin/pg_upgrade/exec.c | 8 +- src/bin/pg_upgrade/multixact_rewrite.c | 80 ++-- src/bin/pg_upgrade/pg_upgrade.c | 34 +- src/bin/pg_upgrade/relfilenumber.c | 54 +-- src/bin/pg_upgrade/t/006_transfer_modes.pl | 33 +- src/bin/psql/command.c | 29 +- src/bin/psql/describe.c | 461 ++++++++++---------- 11 files changed, 601 insertions(+), 610 deletions(-) diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 65bd15ebfd2..5673268b467 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -1491,8 +1491,8 @@ setup_connection(Archive *AH, const char *dumpencoding, * Disable timeouts if supported. */ ExecuteSqlStatement(AH, "SET statement_timeout = 0"); - ExecuteSqlStatement(AH, "SET lock_timeout = 0"); - ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); + ExecuteSqlStatement(AH, "SET lock_timeout = 0"); + ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); if (AH->remoteVersion >= 170000) ExecuteSqlStatement(AH, "SET transaction_timeout = 0"); @@ -1505,10 +1505,10 @@ setup_connection(Archive *AH, const char *dumpencoding, /* * Adjust row-security mode, if supported. */ - if (dopt->enable_row_security) - ExecuteSqlStatement(AH, "SET row_security = on"); - else - ExecuteSqlStatement(AH, "SET row_security = off"); + if (dopt->enable_row_security) + ExecuteSqlStatement(AH, "SET row_security = on"); + else + ExecuteSqlStatement(AH, "SET row_security = off"); /* * For security reasons, we restrict the expansion of non-system views and @@ -1933,10 +1933,9 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) addObjectDependency(dobj, ext->dobj.dumpId); /* - * Mark the member object to have any non-initial ACLs - * dumped. (Any initial ACLs will be removed later, using data from - * pg_init_privs, so that we'll dump only the delta from the extension's - * initial setup.) + * Mark the member object to have any non-initial ACLs dumped. (Any + * initial ACLs will be removed later, using data from pg_init_privs, so + * that we'll dump only the delta from the extension's initial setup.) * * In binary upgrades, we still dump all components of the members * individually, since the idea is to exactly reproduce the database @@ -1953,7 +1952,7 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) if (fout->dopt->binary_upgrade) dobj->dump = ext->dobj.dump; else - dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); + dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); return true; } @@ -1987,9 +1986,9 @@ selectDumpableNamespace(NamespaceInfo *nsinfo, Archive *fout) else if (strcmp(nsinfo->dobj.name, "pg_catalog") == 0) { /* - * We dump out any ACLs defined in pg_catalog, if - * they are interesting (and not the original ACLs which were set at - * initdb time, see pg_init_privs). + * We dump out any ACLs defined in pg_catalog, if they are interesting + * (and not the original ACLs which were set at initdb time, see + * pg_init_privs). */ nsinfo->dobj.dump_contains = nsinfo->dobj.dump = DUMP_COMPONENT_ACL; } @@ -3296,7 +3295,7 @@ dumpDatabase(Archive *fout) "datcollate, datctype, datfrozenxid, " "datacl, acldefault('d', datdba) AS acldefault, " "datistemplate, datconnlimit, "); - appendPQExpBufferStr(dbQry, "datminmxid, "); + appendPQExpBufferStr(dbQry, "datminmxid, "); if (fout->remoteVersion >= 170000) appendPQExpBufferStr(dbQry, "datlocprovider, datlocale, datcollversion, "); else if (fout->remoteVersion >= 150000) @@ -3638,11 +3637,11 @@ dumpDatabase(Archive *fout) ii_oid, ii_relminmxid; - appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" - "FROM pg_catalog.pg_class\n" - "WHERE oid IN (%u, %u, %u, %u);\n", - LargeObjectRelationId, LargeObjectLOidPNIndexId, - LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); + appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" + "FROM pg_catalog.pg_class\n" + "WHERE oid IN (%u, %u, %u, %u);\n", + LargeObjectRelationId, LargeObjectLOidPNIndexId, + LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); lo_res = ExecuteSqlQuery(fout, loFrozenQry->data, PGRES_TUPLES_OK); @@ -4274,7 +4273,7 @@ getPolicies(Archive *fout, TableInfo tblinfo[], int numTables) printfPQExpBuffer(query, "SELECT pol.oid, pol.tableoid, pol.polrelid, pol.polname, pol.polcmd, "); - appendPQExpBufferStr(query, "pol.polpermissive, "); + appendPQExpBufferStr(query, "pol.polpermissive, "); appendPQExpBuffer(query, "CASE WHEN pol.polroles = '{0}' THEN NULL ELSE " " pg_catalog.array_to_string(ARRAY(SELECT pg_catalog.quote_ident(rolname) from pg_catalog.pg_roles WHERE oid = ANY(pol.polroles)), ', ') END AS polroles, " @@ -6633,9 +6632,9 @@ getAccessMethods(Archive *fout) * Select all access methods from pg_am table. */ appendPQExpBufferStr(query, "SELECT tableoid, oid, amname, "); - appendPQExpBufferStr(query, - "amtype, " - "amhandler::pg_catalog.regproc AS amhandler "); + appendPQExpBufferStr(query, + "amtype, " + "amhandler::pg_catalog.regproc AS amhandler "); appendPQExpBufferStr(query, "FROM pg_am"); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6827,35 +6826,35 @@ getAggregates(Archive *fout) * Find all interesting aggregates. See comment in getFuncs() for the * rationale behind the filtering logic. */ - agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" - : "p.proisagg"); + agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" + : "p.proisagg"); - appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " - "p.proname AS aggname, " - "p.pronamespace AS aggnamespace, " - "p.pronargs, p.proargtypes, " - "p.proowner, " - "p.proacl AS aggacl, " - "acldefault('f', p.proowner) AS acldefault " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s AND (" - "p.pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog') OR " - "p.proacl IS DISTINCT FROM pip.initprivs", - agg_check); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - " OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); - appendPQExpBufferChar(query, ')'); + appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " + "p.proname AS aggname, " + "p.pronamespace AS aggnamespace, " + "p.pronargs, p.proargtypes, " + "p.proowner, " + "p.proacl AS aggacl, " + "acldefault('f', p.proowner) AS acldefault " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s AND (" + "p.pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog') OR " + "p.proacl IS DISTINCT FROM pip.initprivs", + agg_check); + if (dopt->binary_upgrade) + appendPQExpBufferStr(query, + " OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6957,53 +6956,53 @@ getFuncs(Archive *fout) * include them, since we want to dump extension members individually in * that mode. Also, if they are used by casts or transforms then we need * to gather the information about them, though they won't be dumped if - * they are built-in. Also, include functions in - * pg_catalog if they have an ACL different from what's shown in - * pg_init_privs (so we have to join to pg_init_privs; annoying). + * they are built-in. Also, include functions in pg_catalog if they have + * an ACL different from what's shown in pg_init_privs (so we have to join + * to pg_init_privs; annoying). */ - not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" - : "NOT p.proisagg"); + not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" + : "NOT p.proisagg"); - appendPQExpBuffer(query, - "SELECT p.tableoid, p.oid, p.proname, p.prolang, " - "p.pronargs, p.proargtypes, p.prorettype, " - "p.proacl, " - "acldefault('f', p.proowner) AS acldefault, " - "p.pronamespace, " - "p.proowner " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s" - "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " - "WHERE classid = 'pg_proc'::regclass AND " - "objid = p.oid AND deptype = 'i')" - "\n AND (" - "\n pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog')" - "\n OR EXISTS (SELECT 1 FROM pg_cast" - "\n WHERE pg_cast.oid > %u " - "\n AND p.oid = pg_cast.castfunc)" - "\n OR EXISTS (SELECT 1 FROM pg_transform" - "\n WHERE pg_transform.oid > %u AND " - "\n (p.oid = pg_transform.trffromsql" - "\n OR p.oid = pg_transform.trftosql))", - not_agg_check, - g_last_builtin_oid, - g_last_builtin_oid); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); + appendPQExpBuffer(query, + "SELECT p.tableoid, p.oid, p.proname, p.prolang, " + "p.pronargs, p.proargtypes, p.prorettype, " + "p.proacl, " + "acldefault('f', p.proowner) AS acldefault, " + "p.pronamespace, " + "p.proowner " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s" + "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " + "WHERE classid = 'pg_proc'::regclass AND " + "objid = p.oid AND deptype = 'i')" + "\n AND (" + "\n pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog')" + "\n OR EXISTS (SELECT 1 FROM pg_cast" + "\n WHERE pg_cast.oid > %u " + "\n AND p.oid = pg_cast.castfunc)" + "\n OR EXISTS (SELECT 1 FROM pg_transform" + "\n WHERE pg_transform.oid > %u AND " + "\n (p.oid = pg_transform.trffromsql" + "\n OR p.oid = pg_transform.trftosql))", + not_agg_check, + g_last_builtin_oid, + g_last_builtin_oid); + if (dopt->binary_upgrade) appendPQExpBufferStr(query, - "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); - appendPQExpBufferChar(query, ')'); + "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferStr(query, + "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -7252,31 +7251,31 @@ getTables(Archive *fout, int *numTables) appendPQExpBufferStr(query, "c.relhasoids, "); - appendPQExpBufferStr(query, - "c.relispopulated, "); + appendPQExpBufferStr(query, + "c.relispopulated, "); - appendPQExpBufferStr(query, - "c.relreplident, "); + appendPQExpBufferStr(query, + "c.relreplident, "); - appendPQExpBufferStr(query, - "c.relrowsecurity, c.relforcerowsecurity, "); + appendPQExpBufferStr(query, + "c.relrowsecurity, c.relforcerowsecurity, "); - appendPQExpBufferStr(query, - "c.relminmxid, tc.relminmxid AS tminmxid, "); + appendPQExpBufferStr(query, + "c.relminmxid, tc.relminmxid AS tminmxid, "); - appendPQExpBufferStr(query, - "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); + appendPQExpBufferStr(query, + "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); - appendPQExpBufferStr(query, - "am.amname, "); + appendPQExpBufferStr(query, + "am.amname, "); - appendPQExpBufferStr(query, - "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); + appendPQExpBufferStr(query, + "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); - appendPQExpBufferStr(query, - "c.relispartition AS ispartition "); + appendPQExpBufferStr(query, + "c.relispartition AS ispartition "); /* * Left join to pg_depend to pick up dependency info linking sequences to @@ -7296,8 +7295,8 @@ getTables(Archive *fout, int *numTables) /* * Left join to pg_am to pick up the amname. */ - appendPQExpBufferStr(query, - "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); + appendPQExpBufferStr(query, + "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); /* * We purposefully ignore toast OIDs for partitioned tables; the reason is @@ -7868,8 +7867,8 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables) "t.reloptions AS indreloptions, "); - appendPQExpBufferStr(query, - "i.indisreplident, "); + appendPQExpBufferStr(query, + "i.indisreplident, "); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -9313,8 +9312,8 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables) appendPQExpBufferStr(q, "'' AS attcompression,\n"); - appendPQExpBufferStr(q, - "a.attidentity,\n"); + appendPQExpBufferStr(q, + "a.attidentity,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(q, @@ -10717,73 +10716,73 @@ getAdditionalACLs(Archive *fout) PQclear(res); /* Fetch initial-privileges data */ - printfPQExpBuffer(query, - "SELECT objoid, classoid, objsubid, privtype, initprivs " - "FROM pg_init_privs"); + printfPQExpBuffer(query, + "SELECT objoid, classoid, objsubid, privtype, initprivs " + "FROM pg_init_privs"); - res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); + res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); - ntups = PQntuples(res); - for (i = 0; i < ntups; i++) - { - Oid objoid = atooid(PQgetvalue(res, i, 0)); - Oid classoid = atooid(PQgetvalue(res, i, 1)); - int objsubid = atoi(PQgetvalue(res, i, 2)); - char privtype = *(PQgetvalue(res, i, 3)); - char *initprivs = PQgetvalue(res, i, 4); - CatalogId objId; - DumpableObject *dobj; + ntups = PQntuples(res); + for (i = 0; i < ntups; i++) + { + Oid objoid = atooid(PQgetvalue(res, i, 0)); + Oid classoid = atooid(PQgetvalue(res, i, 1)); + int objsubid = atoi(PQgetvalue(res, i, 2)); + char privtype = *(PQgetvalue(res, i, 3)); + char *initprivs = PQgetvalue(res, i, 4); + CatalogId objId; + DumpableObject *dobj; - objId.tableoid = classoid; - objId.oid = objoid; - dobj = findObjectByCatalogId(objId); - /* OK to ignore entries we haven't got a DumpableObject for */ - if (dobj) + objId.tableoid = classoid; + objId.oid = objoid; + dobj = findObjectByCatalogId(objId); + /* OK to ignore entries we haven't got a DumpableObject for */ + if (dobj) + { + /* Cope with sub-object initprivs */ + if (objsubid != 0) { - /* Cope with sub-object initprivs */ - if (objsubid != 0) - { - if (dobj->objType == DO_TABLE) - { - /* For a column initprivs, set the table's ACL flags */ - dobj->components |= DUMP_COMPONENT_ACL; - ((TableInfo *) dobj)->hascolumnACLs = true; - } - else - pg_log_warning("unsupported pg_init_privs entry: %u %u %d", - classoid, objoid, objsubid); - continue; - } - - /* - * We ignore any pg_init_privs.initprivs entry for the public - * schema, as explained in getNamespaces(). - */ - if (dobj->objType == DO_NAMESPACE && - strcmp(dobj->name, "public") == 0) - continue; - - /* Else it had better be of a type we think has ACLs */ - if (dobj->objType == DO_NAMESPACE || - dobj->objType == DO_TYPE || - dobj->objType == DO_FUNC || - dobj->objType == DO_AGG || - dobj->objType == DO_TABLE || - dobj->objType == DO_PROCLANG || - dobj->objType == DO_FDW || - dobj->objType == DO_FOREIGN_SERVER) + if (dobj->objType == DO_TABLE) { - DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; - - daobj->dacl.privtype = privtype; - daobj->dacl.initprivs = pstrdup(initprivs); + /* For a column initprivs, set the table's ACL flags */ + dobj->components |= DUMP_COMPONENT_ACL; + ((TableInfo *) dobj)->hascolumnACLs = true; } else pg_log_warning("unsupported pg_init_privs entry: %u %u %d", classoid, objoid, objsubid); + continue; + } + + /* + * We ignore any pg_init_privs.initprivs entry for the public + * schema, as explained in getNamespaces(). + */ + if (dobj->objType == DO_NAMESPACE && + strcmp(dobj->name, "public") == 0) + continue; + + /* Else it had better be of a type we think has ACLs */ + if (dobj->objType == DO_NAMESPACE || + dobj->objType == DO_TYPE || + dobj->objType == DO_FUNC || + dobj->objType == DO_AGG || + dobj->objType == DO_TABLE || + dobj->objType == DO_PROCLANG || + dobj->objType == DO_FDW || + dobj->objType == DO_FOREIGN_SERVER) + { + DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; + + daobj->dacl.privtype = privtype; + daobj->dacl.initprivs = pstrdup(initprivs); } + else + pg_log_warning("unsupported pg_init_privs entry: %u %u %d", + classoid, objoid, objsubid); } - PQclear(res); + } + PQclear(res); destroyPQExpBuffer(query); } @@ -11128,8 +11127,8 @@ dumpRelationStats_dumper(Archive *fout, const void *userArg, const TocEntry *te) * The results must be in the order of the relations supplied in the * parameters to ensure we remain in sync as we walk through the TOC. * - * For versions before 19, the redundant filter clause on s.tablename = - * ANY(...) seems sufficient to convince the planner to use + * For versions before 19, the redundant filter clause on s.tablename + * = ANY(...) seems sufficient to convince the planner to use * pg_class_relname_nsp_index, which avoids a full scan of pg_stats. * In newer versions, pg_stats returns the table OIDs, eliminating the * need for that hack. @@ -13469,11 +13468,11 @@ dumpFunc(Archive *fout, const FuncInfo *finfo) "pg_catalog.pg_get_function_result(p.oid) AS funcresult,\n" "proleakproof,\n"); - appendPQExpBufferStr(query, - "array_to_string(protrftypes, ' ') AS protrftypes,\n"); + appendPQExpBufferStr(query, + "array_to_string(protrftypes, ' ') AS protrftypes,\n"); - appendPQExpBufferStr(query, - "proparallel,\n"); + appendPQExpBufferStr(query, + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -14963,9 +14962,9 @@ dumpCollation(Archive *fout, const CollInfo *collinfo) /* Get collation-specific details */ appendPQExpBufferStr(query, "SELECT "); - appendPQExpBufferStr(query, - "collprovider, " - "collversion, "); + appendPQExpBufferStr(query, + "collprovider, " + "collversion, "); if (fout->remoteVersion >= 120000) appendPQExpBufferStr(query, @@ -15372,23 +15371,23 @@ dumpAgg(Archive *fout, const AggInfo *agginfo) "pg_catalog.pg_get_function_arguments(p.oid) AS funcargs,\n" "pg_catalog.pg_get_function_identity_arguments(p.oid) AS funciargs,\n"); - appendPQExpBufferStr(query, - "aggkind,\n" - "aggmtransfn,\n" - "aggminvtransfn,\n" - "aggmfinalfn,\n" - "aggmtranstype::pg_catalog.regtype,\n" - "aggfinalextra,\n" - "aggmfinalextra,\n" - "aggtransspace,\n" - "aggmtransspace,\n" - "aggminitval,\n"); + appendPQExpBufferStr(query, + "aggkind,\n" + "aggmtransfn,\n" + "aggminvtransfn,\n" + "aggmfinalfn,\n" + "aggmtranstype::pg_catalog.regtype,\n" + "aggfinalextra,\n" + "aggmfinalextra,\n" + "aggtransspace,\n" + "aggmtransspace,\n" + "aggminitval,\n"); - appendPQExpBufferStr(query, - "aggcombinefn,\n" - "aggserialfn,\n" - "aggdeserialfn,\n" - "proparallel,\n"); + appendPQExpBufferStr(query, + "aggcombinefn,\n" + "aggserialfn,\n" + "aggdeserialfn,\n" + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -16848,30 +16847,30 @@ dumpTable(Archive *fout, const TableInfo *tbinfo) appendPQExpBufferStr(query, "PREPARE getColumnACLs(pg_catalog.oid) AS\n"); - /* - * In principle we should call acldefault('c', relowner) to - * get the default ACL for a column. However, we don't - * currently store the numeric OID of the relowner in - * TableInfo. We could convert the owner name using regrole, - * but that creates a risk of failure due to concurrent role - * renames. Given that the default ACL for columns is empty - * and is likely to stay that way, it's not worth extra cycles - * and risk to avoid hard-wiring that knowledge here. - */ - appendPQExpBufferStr(query, - "SELECT at.attname, " - "at.attacl, " - "'{}' AS acldefault, " - "pip.privtype, pip.initprivs " - "FROM pg_catalog.pg_attribute at " - "LEFT JOIN pg_catalog.pg_init_privs pip ON " - "(at.attrelid = pip.objoid " - "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " - "AND at.attnum = pip.objsubid) " - "WHERE at.attrelid = $1 AND " - "NOT at.attisdropped " - "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " - "ORDER BY at.attnum"); + /* + * In principle we should call acldefault('c', relowner) to get + * the default ACL for a column. However, we don't currently + * store the numeric OID of the relowner in TableInfo. We could + * convert the owner name using regrole, but that creates a risk + * of failure due to concurrent role renames. Given that the + * default ACL for columns is empty and is likely to stay that + * way, it's not worth extra cycles and risk to avoid hard-wiring + * that knowledge here. + */ + appendPQExpBufferStr(query, + "SELECT at.attname, " + "at.attacl, " + "'{}' AS acldefault, " + "pip.privtype, pip.initprivs " + "FROM pg_catalog.pg_attribute at " + "LEFT JOIN pg_catalog.pg_init_privs pip ON " + "(at.attrelid = pip.objoid " + "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " + "AND at.attnum = pip.objsubid) " + "WHERE at.attrelid = $1 AND " + "NOT at.attisdropped " + "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " + "ORDER BY at.attnum"); ExecuteSqlStatement(fout, query->data); @@ -19165,7 +19164,7 @@ collectSequences(Archive *fout) * pg_get_sequence_data(), but we only do so for non-schema-only dumps. */ if (fout->remoteVersion < 180000 || - (!fout->dopt->dumpData && !fout->dopt->sequence_data)) + (!fout->dopt->dumpData && !fout->dopt->sequence_data)) query = "SELECT seqrelid, format_type(seqtypid, NULL), " "seqstart, seqincrement, " "seqmax, seqmin, " @@ -19227,15 +19226,14 @@ dumpSequence(Archive *fout, const TableInfo *tbinfo) qseqname = pg_strdup(fmtId(tbinfo->dobj.name)); /* - * The sequence information is gathered in a sorted - * table before any calls to dumpSequence(). See collectSequences() for - * more information. + * The sequence information is gathered in a sorted table before any calls + * to dumpSequence(). See collectSequences() for more information. */ - Assert(sequences); + Assert(sequences); - key.oid = tbinfo->dobj.catId.oid; - seq = bsearch(&key, sequences, nsequences, - sizeof(SequenceItem), SequenceItemCmp); + key.oid = tbinfo->dobj.catId.oid; + seq = bsearch(&key, sequences, nsequences, + sizeof(SequenceItem), SequenceItemCmp); /* Calculate default limits for a sequence of this type */ is_ascending = (seq->incby >= 0); diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c index e68937c9934..afcd9a218d8 100644 --- a/src/bin/pg_dump/pg_dumpall.c +++ b/src/bin/pg_dump/pg_dumpall.c @@ -785,11 +785,11 @@ dropRoles(PGconn *conn) int i_rolname; int i; - printfPQExpBuffer(buf, - "SELECT rolname " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 1", role_catalog); + printfPQExpBuffer(buf, + "SELECT rolname " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 1", role_catalog); res = executeQuery(conn, buf->data); @@ -843,16 +843,16 @@ dumpRoles(PGconn *conn) * Notes: rolconfig is dumped later, and pg_authid must be used for * extracting rolcomment regardless of role_catalog. */ - printfPQExpBuffer(buf, - "SELECT oid, rolname, rolsuper, rolinherit, " - "rolcreaterole, rolcreatedb, " - "rolcanlogin, rolconnlimit, rolpassword, " - "rolvaliduntil, rolreplication, rolbypassrls, " - "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " - "rolname = current_user AS is_current_user " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 2", role_catalog); + printfPQExpBuffer(buf, + "SELECT oid, rolname, rolsuper, rolinherit, " + "rolcreaterole, rolcreatedb, " + "rolcanlogin, rolconnlimit, rolpassword, " + "rolvaliduntil, rolreplication, rolbypassrls, " + "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " + "rolname = current_user AS is_current_user " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 2", role_catalog); res = executeQuery(conn, buf->data); diff --git a/src/bin/pg_upgrade/check.c b/src/bin/pg_upgrade/check.c index 786c1474829..f725f5ee3e2 100644 --- a/src/bin/pg_upgrade/check.c +++ b/src/bin/pg_upgrade/check.c @@ -1475,15 +1475,15 @@ check_for_incompatible_polymorphics(ClusterInfo *cluster) ", 'array_cat(anyarray,anyarray)'" ", 'array_prepend(anyelement,anyarray)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_remove(anyarray,anyelement)'" - ", 'array_replace(anyarray,anyelement,anyelement)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_remove(anyarray,anyelement)'" + ", 'array_replace(anyarray,anyelement,anyelement)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_position(anyarray,anyelement)'" - ", 'array_position(anyarray,anyelement,integer)'" - ", 'array_positions(anyarray,anyelement)'" - ", 'width_bucket(anyelement,anyarray)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_position(anyarray,anyelement)'" + ", 'array_position(anyarray,anyelement,integer)'" + ", 'array_positions(anyarray,anyelement)'" + ", 'width_bucket(anyelement,anyarray)'"); /* * The query below hardcodes FirstNormalObjectId as 16384 rather than diff --git a/src/bin/pg_upgrade/controldata.c b/src/bin/pg_upgrade/controldata.c index 8f81c9e9582..02ea02df60f 100644 --- a/src/bin/pg_upgrade/controldata.c +++ b/src/bin/pg_upgrade/controldata.c @@ -228,7 +228,7 @@ get_control_data(ClusterInfo *cluster) p++; /* remove ':' char */ cluster->controldata.chkpnt_nxtepoch = str2uint(p); - p = strchr(p, ':'); + p = strchr(p, ':'); if (p == NULL || strlen(p) <= 1) pg_fatal("%d: controldata retrieval problem", __LINE__); diff --git a/src/bin/pg_upgrade/exec.c b/src/bin/pg_upgrade/exec.c index 44355feea30..a1bdbf373e3 100644 --- a/src/bin/pg_upgrade/exec.c +++ b/src/bin/pg_upgrade/exec.c @@ -55,7 +55,7 @@ get_bin_version(ClusterInfo *cluster) if (sscanf(cmd_output, "%*s %*s %d.%d", &v1, &v2) < 1) pg_fatal("could not get pg_ctl version output from %s", cmd); - cluster->bin_version = v1 * 10000; + cluster->bin_version = v1 * 10000; } @@ -344,8 +344,8 @@ check_data_dir(ClusterInfo *cluster) check_single_dir(pg_data, "pg_subtrans"); check_single_dir(pg_data, PG_TBLSPC_DIR); check_single_dir(pg_data, "pg_twophase"); - check_single_dir(pg_data, "pg_wal"); - check_single_dir(pg_data, "pg_xact"); + check_single_dir(pg_data, "pg_wal"); + check_single_dir(pg_data, "pg_xact"); } @@ -385,7 +385,7 @@ check_bin_dir(ClusterInfo *cluster, bool check_versions) */ get_bin_version(cluster); - check_exec(cluster->bindir, "pg_resetwal", check_versions); + check_exec(cluster->bindir, "pg_resetwal", check_versions); if (cluster == &new_cluster) { diff --git a/src/bin/pg_upgrade/multixact_rewrite.c b/src/bin/pg_upgrade/multixact_rewrite.c index c45b3183684..c7a1416494d 100644 --- a/src/bin/pg_upgrade/multixact_rewrite.c +++ b/src/bin/pg_upgrade/multixact_rewrite.c @@ -61,52 +61,52 @@ rewrite_multixacts(MultiXactId from_multi, MultiXactId to_multi) * Convert old multixids, if needed, by reading them one-by-one from the * old cluster. */ - old_reader = AllocOldMultiXactRead(old_cluster.pgdata, - old_cluster.controldata.chkpnt_nxtmulti, - old_cluster.controldata.chkpnt_nxtmxoff); + old_reader = AllocOldMultiXactRead(old_cluster.pgdata, + old_cluster.controldata.chkpnt_nxtmulti, + old_cluster.controldata.chkpnt_nxtmxoff); - for (MultiXactId multi = from_multi; multi != to_multi;) - { - MultiXactMember member; - bool multixid_valid; - - /* - * Read this multixid's members. - * - * Locking-only XIDs that may be part of multi-xids don't matter - * after upgrade, as there can be no transactions running across - * upgrade. So as a small optimization, we only read one member - * from each multixid: the one updating one, or if there was no - * update, arbitrarily the first locking xid. - */ - multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); + for (MultiXactId multi = from_multi; multi != to_multi;) + { + MultiXactMember member; + bool multixid_valid; - /* - * Write the new offset to pg_multixact/offsets. - * - * Even if this multixid is invalid, we still need to write its - * offset if the *previous* multixid was valid. That's because - * when reading a multixid, the number of members is calculated - * from the difference between the two offsets. - */ - RecordMultiXactOffset(offsets_writer, multi, - (multixid_valid || prev_multixid_valid) ? next_offset : 0); + /* + * Read this multixid's members. + * + * Locking-only XIDs that may be part of multi-xids don't matter after + * upgrade, as there can be no transactions running across upgrade. So + * as a small optimization, we only read one member from each + * multixid: the one updating one, or if there was no update, + * arbitrarily the first locking xid. + */ + multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); - /* Write the members */ - if (multixid_valid) - { - RecordMultiXactMembers(members_writer, next_offset, 1, &member); - next_offset += 1; - } + /* + * Write the new offset to pg_multixact/offsets. + * + * Even if this multixid is invalid, we still need to write its offset + * if the *previous* multixid was valid. That's because when reading + * a multixid, the number of members is calculated from the difference + * between the two offsets. + */ + RecordMultiXactOffset(offsets_writer, multi, + (multixid_valid || prev_multixid_valid) ? next_offset : 0); - /* Advance to next multixid, handling wraparound */ - multi++; - if (multi < FirstMultiXactId) - multi = FirstMultiXactId; - prev_multixid_valid = multixid_valid; + /* Write the members */ + if (multixid_valid) + { + RecordMultiXactMembers(members_writer, next_offset, 1, &member); + next_offset += 1; } - FreeOldMultiXactReader(old_reader); + /* Advance to next multixid, handling wraparound */ + multi++; + if (multi < FirstMultiXactId) + multi = FirstMultiXactId; + prev_multixid_valid = multixid_valid; + } + + FreeOldMultiXactReader(old_reader); /* Write the final 'next' offset to the last SLRU page */ RecordMultiXactOffset(offsets_writer, to_multi, diff --git a/src/bin/pg_upgrade/pg_upgrade.c b/src/bin/pg_upgrade/pg_upgrade.c index c6af9035665..7366fd4627c 100644 --- a/src/bin/pg_upgrade/pg_upgrade.c +++ b/src/bin/pg_upgrade/pg_upgrade.c @@ -833,7 +833,7 @@ copy_xact_xlog_xid(void) * Determine the range of multixacts to convert. */ nxtmulti = old_cluster.controldata.chkpnt_nxtmulti; - oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; + oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; /* handle wraparound */ if (nxtmulti < FirstMultiXactId) nxtmulti = FirstMultiXactId; @@ -898,15 +898,15 @@ set_frozenxids(void) int i_datname; int i_datallowconn; - prep_status("Setting frozenxid and minmxid counters in new cluster"); + prep_status("Setting frozenxid and minmxid counters in new cluster"); conn_template1 = connectToServer(&new_cluster, "template1"); - /* set pg_database.datfrozenxid */ - PQclear(executeQueryOrDie(conn_template1, - "UPDATE pg_catalog.pg_database " - "SET datfrozenxid = '%u'", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_database.datfrozenxid */ + PQclear(executeQueryOrDie(conn_template1, + "UPDATE pg_catalog.pg_database " + "SET datfrozenxid = '%u'", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_database.datminmxid */ PQclear(executeQueryOrDie(conn_template1, @@ -942,16 +942,16 @@ set_frozenxids(void) conn = connectToServer(&new_cluster, datname); - /* set pg_class.relfrozenxid */ - PQclear(executeQueryOrDie(conn, - "UPDATE pg_catalog.pg_class " - "SET relfrozenxid = '%u' " - /* only heap, materialized view, and TOAST are vacuumed */ - "WHERE relkind IN (" - CppAsString2(RELKIND_RELATION) ", " - CppAsString2(RELKIND_MATVIEW) ", " - CppAsString2(RELKIND_TOASTVALUE) ")", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_class.relfrozenxid */ + PQclear(executeQueryOrDie(conn, + "UPDATE pg_catalog.pg_class " + "SET relfrozenxid = '%u' " + /* only heap, materialized view, and TOAST are vacuumed */ + "WHERE relkind IN (" + CppAsString2(RELKIND_RELATION) ", " + CppAsString2(RELKIND_MATVIEW) ", " + CppAsString2(RELKIND_TOASTVALUE) ")", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_class.relminmxid */ PQclear(executeQueryOrDie(conn, diff --git a/src/bin/pg_upgrade/relfilenumber.c b/src/bin/pg_upgrade/relfilenumber.c index ec2ff7acb21..6c467bdc8a5 100644 --- a/src/bin/pg_upgrade/relfilenumber.c +++ b/src/bin/pg_upgrade/relfilenumber.c @@ -587,32 +587,32 @@ transfer_relfile(FileNameMap *map, const char *type_suffix) /* Copying files might take some time, so give feedback. */ pg_log(PG_STATUS, "%s", old_file); - switch (user_opts.transfer_mode) - { - case TRANSFER_MODE_CLONE: - pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", - old_file, new_file); - cloneFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", - old_file, new_file); - copyFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY_FILE_RANGE: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", - old_file, new_file); - copyFileByRange(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_LINK: - pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", - old_file, new_file); - linkFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_SWAP: - /* swap mode is handled in its own code path */ - pg_fatal("should never happen"); - break; - } + switch (user_opts.transfer_mode) + { + case TRANSFER_MODE_CLONE: + pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", + old_file, new_file); + cloneFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", + old_file, new_file); + copyFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY_FILE_RANGE: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", + old_file, new_file); + copyFileByRange(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_LINK: + pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", + old_file, new_file); + linkFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_SWAP: + /* swap mode is handled in its own code path */ + pg_fatal("should never happen"); + break; + } } } diff --git a/src/bin/pg_upgrade/t/006_transfer_modes.pl b/src/bin/pg_upgrade/t/006_transfer_modes.pl index 9efa5dc863c..360d05c4b68 100644 --- a/src/bin/pg_upgrade/t/006_transfer_modes.pl +++ b/src/bin/pg_upgrade/t/006_transfer_modes.pl @@ -29,10 +29,8 @@ sub test_mode } $new->init(); - $new->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); - $old->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); + $new->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); + $old->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); # We can only test security labels if both the old and new installations # have dummy_seclabel. @@ -76,15 +74,14 @@ sub test_mode "CREATE TABLE test4 AS SELECT generate_series(400, 502)"); } - $old->safe_psql('postgres', - "CREATE TABLESPACE inplc_tblspc LOCATION ''"); - $old->safe_psql('postgres', - "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); - $old->safe_psql('postgres', - "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" - ); - $old->safe_psql('testdb3', - "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); + $old->safe_psql('postgres', "CREATE TABLESPACE inplc_tblspc LOCATION ''"); + $old->safe_psql('postgres', + "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); + $old->safe_psql('postgres', + "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" + ); + $old->safe_psql('testdb3', + "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); # While we are here, test handling of large objects. $old->safe_psql( @@ -152,12 +149,10 @@ sub test_mode } # Tests for in-place tablespaces. - $result = - $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); - is($result, '104', "test5 data after pg_upgrade $mode"); - $result = - $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); - is($result, '105', "test6 data after pg_upgrade $mode"); + $result = $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); + is($result, '104', "test5 data after pg_upgrade $mode"); + $result = $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); + is($result, '105', "test6 data after pg_upgrade $mode"); # Tests for large objects $result = $new->safe_psql('postgres', "SELECT lo_get(4532)"); diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index 44ef11d980e..c90bf8bbde2 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -6278,23 +6278,22 @@ get_create_object_cmd(EditableObjectType obj_type, Oid oid, * ensure the right view gets replaced. Also, check relation kind * to be sure it's a view. * - * Views may have WITH [LOCAL|CASCADED] - * CHECK OPTION. These are not part of the view definition - * returned by pg_get_viewdef() and so need to be retrieved - * separately. Materialized views may have - * arbitrary storage parameter reloptions. + * Views may have WITH [LOCAL|CASCADED] CHECK OPTION. These are + * not part of the view definition returned by pg_get_viewdef() + * and so need to be retrieved separately. Materialized views may + * have arbitrary storage parameter reloptions. */ printfPQExpBuffer(query, "/* %s */\n", _("Get view's definition and details")); - appendPQExpBuffer(query, - "SELECT nspname, relname, relkind, " - "pg_catalog.pg_get_viewdef(c.oid, true), " - "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " - "FROM pg_catalog.pg_class c " - "LEFT JOIN pg_catalog.pg_namespace n " - "ON c.relnamespace = n.oid WHERE c.oid = %u", - oid); + appendPQExpBuffer(query, + "SELECT nspname, relname, relkind, " + "pg_catalog.pg_get_viewdef(c.oid, true), " + "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " + "FROM pg_catalog.pg_class c " + "LEFT JOIN pg_catalog.pg_namespace n " + "ON c.relnamespace = n.oid WHERE c.oid = %u", + oid); break; } diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index ce99137c613..ac0c55e7aa5 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -387,19 +387,19 @@ describeFunctions(const char *functypes, const char *func_pattern, gettext_noop("stable"), gettext_noop("volatile"), gettext_noop("Volatility")); - appendPQExpBuffer(&buf, - ",\n CASE\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" - " END as \"%s\"", - gettext_noop("restricted"), - gettext_noop("safe"), - gettext_noop("unsafe"), - gettext_noop("Parallel")); + appendPQExpBuffer(&buf, + ",\n CASE\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" + " END as \"%s\"", + gettext_noop("restricted"), + gettext_noop("safe"), + gettext_noop("unsafe"), + gettext_noop("Parallel")); appendPQExpBuffer(&buf, ",\n pg_catalog.pg_get_userbyid(p.proowner) as \"%s\"" ",\n CASE WHEN prosecdef THEN '%s' ELSE '%s' END AS \"%s\"" @@ -599,8 +599,8 @@ describeFunctions(const char *functypes, const char *func_pattern, myopt.title = _("List of functions"); myopt.translate_header = true; - myopt.translate_columns = translate_columns; - myopt.n_translate_columns = lengthof(translate_columns); + myopt.translate_columns = translate_columns; + myopt.n_translate_columns = lengthof(translate_columns); printQuery(res, &myopt, pset.queryFout, false, pset.logfile); @@ -1086,38 +1086,38 @@ permissionsList(const char *pattern, bool showSystem) " ), E'\\n') AS \"%s\"", gettext_noop("Column privileges")); - appendPQExpBuffer(&buf, - ",\n pg_catalog.array_to_string(ARRAY(\n" - " SELECT polname\n" - " || CASE WHEN NOT polpermissive THEN\n" - " E' (RESTRICTIVE)'\n" - " ELSE '' END\n" - " || CASE WHEN polcmd != '*' THEN\n" - " E' (' || polcmd::pg_catalog.text || E'):'\n" - " ELSE E':'\n" - " END\n" - " || CASE WHEN polqual IS NOT NULL THEN\n" - " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" - " ELSE E''\n" - " END\n" - " || CASE WHEN polwithcheck IS NOT NULL THEN\n" - " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" - " ELSE E''\n" - " END" - " || CASE WHEN polroles <> '{0}' THEN\n" - " E'\\n to: ' || pg_catalog.array_to_string(\n" - " ARRAY(\n" - " SELECT rolname\n" - " FROM pg_catalog.pg_roles\n" - " WHERE oid = ANY (polroles)\n" - " ORDER BY 1\n" - " ), E', ')\n" - " ELSE E''\n" - " END\n" - " FROM pg_catalog.pg_policy pol\n" - " WHERE polrelid = c.oid), E'\\n')\n" - " AS \"%s\"", - gettext_noop("Policies")); + appendPQExpBuffer(&buf, + ",\n pg_catalog.array_to_string(ARRAY(\n" + " SELECT polname\n" + " || CASE WHEN NOT polpermissive THEN\n" + " E' (RESTRICTIVE)'\n" + " ELSE '' END\n" + " || CASE WHEN polcmd != '*' THEN\n" + " E' (' || polcmd::pg_catalog.text || E'):'\n" + " ELSE E':'\n" + " END\n" + " || CASE WHEN polqual IS NOT NULL THEN\n" + " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" + " ELSE E''\n" + " END\n" + " || CASE WHEN polwithcheck IS NOT NULL THEN\n" + " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" + " ELSE E''\n" + " END" + " || CASE WHEN polroles <> '{0}' THEN\n" + " E'\\n to: ' || pg_catalog.array_to_string(\n" + " ARRAY(\n" + " SELECT rolname\n" + " FROM pg_catalog.pg_roles\n" + " WHERE oid = ANY (polroles)\n" + " ORDER BY 1\n" + " ), E', ')\n" + " ELSE E''\n" + " END\n" + " FROM pg_catalog.pg_policy pol\n" + " WHERE polrelid = c.oid), E'\\n')\n" + " AS \"%s\"", + gettext_noop("Policies")); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_class c\n" " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n" @@ -1675,27 +1675,27 @@ describeOneTableDetails(const char *schemaname, char *footers[3] = {NULL, NULL, NULL}; printfPQExpBuffer(&buf, "/* %s */\n", _("Get sequence information")); - appendPQExpBuffer(&buf, - "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" - " seqstart AS \"%s\",\n" - " seqmin AS \"%s\",\n" - " seqmax AS \"%s\",\n" - " seqincrement AS \"%s\",\n" - " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" - " seqcache AS \"%s\"\n", - gettext_noop("Type"), - gettext_noop("Start"), - gettext_noop("Minimum"), - gettext_noop("Maximum"), - gettext_noop("Increment"), - gettext_noop("yes"), - gettext_noop("no"), - gettext_noop("Cycles?"), - gettext_noop("Cache")); - appendPQExpBuffer(&buf, - "FROM pg_catalog.pg_sequence\n" - "WHERE seqrelid = '%s';", - oid); + appendPQExpBuffer(&buf, + "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" + " seqstart AS \"%s\",\n" + " seqmin AS \"%s\",\n" + " seqmax AS \"%s\",\n" + " seqincrement AS \"%s\",\n" + " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" + " seqcache AS \"%s\"\n", + gettext_noop("Type"), + gettext_noop("Start"), + gettext_noop("Minimum"), + gettext_noop("Maximum"), + gettext_noop("Increment"), + gettext_noop("yes"), + gettext_noop("no"), + gettext_noop("Cycles?"), + gettext_noop("Cache")); + appendPQExpBuffer(&buf, + "FROM pg_catalog.pg_sequence\n" + "WHERE seqrelid = '%s';", + oid); res = PSQLexec(buf.data); if (!res) @@ -1913,7 +1913,7 @@ describeOneTableDetails(const char *schemaname, appendPQExpBufferStr(&buf, ",\n (SELECT c.collname FROM pg_catalog.pg_collation c, pg_catalog.pg_type t\n" " WHERE c.oid = a.attcollation AND t.oid = a.atttypid AND a.attcollation <> t.typcollation) AS attcollation"); attcoll_col = cols++; - appendPQExpBufferStr(&buf, ",\n a.attidentity"); + appendPQExpBufferStr(&buf, ",\n a.attidentity"); attidentity_col = cols++; if (pset.sversion >= 120000) appendPQExpBufferStr(&buf, ",\n a.attgenerated"); @@ -2326,7 +2326,7 @@ describeOneTableDetails(const char *schemaname, CppAsString2(CONSTRAINT_EXCLUSION) ") AND " "condeferred) AS condeferred,\n"); - appendPQExpBufferStr(&buf, "i.indisreplident,\n"); + appendPQExpBufferStr(&buf, "i.indisreplident,\n"); if (pset.sversion >= 150000) appendPQExpBufferStr(&buf, "i.indnullsnotdistinct,\n"); @@ -2431,7 +2431,7 @@ describeOneTableDetails(const char *schemaname, "pg_catalog.pg_get_indexdef(i.indexrelid, 0, true),\n " "pg_catalog.pg_get_constraintdef(con.oid, true), " "contype, condeferrable, condeferred"); - appendPQExpBufferStr(&buf, ", i.indisreplident"); + appendPQExpBufferStr(&buf, ", i.indisreplident"); appendPQExpBufferStr(&buf, ", c2.reltablespace"); if (pset.sversion >= 180000) appendPQExpBufferStr(&buf, ", con.conperiod"); @@ -2682,81 +2682,80 @@ describeOneTableDetails(const char *schemaname, PQclear(result); /* print any row-level policies */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get row-level policies for this table")); - appendPQExpBufferStr(&buf, "SELECT pol.polname,"); - appendPQExpBufferStr(&buf, - " pol.polpermissive,\n"); - appendPQExpBuffer(&buf, - " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" - " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" - " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" - " CASE pol.polcmd\n" - " WHEN 'r' THEN 'SELECT'\n" - " WHEN 'a' THEN 'INSERT'\n" - " WHEN 'w' THEN 'UPDATE'\n" - " WHEN 'd' THEN 'DELETE'\n" - " END AS cmd\n" - "FROM pg_catalog.pg_policy pol\n" - "WHERE pol.polrelid = '%s' ORDER BY 1;", - oid); + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get row-level policies for this table")); + appendPQExpBufferStr(&buf, "SELECT pol.polname,"); + appendPQExpBufferStr(&buf, + " pol.polpermissive,\n"); + appendPQExpBuffer(&buf, + " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" + " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" + " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" + " CASE pol.polcmd\n" + " WHEN 'r' THEN 'SELECT'\n" + " WHEN 'a' THEN 'INSERT'\n" + " WHEN 'w' THEN 'UPDATE'\n" + " WHEN 'd' THEN 'DELETE'\n" + " END AS cmd\n" + "FROM pg_catalog.pg_policy pol\n" + "WHERE pol.polrelid = '%s' ORDER BY 1;", + oid); - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - /* - * Handle cases where RLS is enabled and there are policies, or - * there aren't policies, or RLS isn't enabled but there are - * policies - */ - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies:")); + /* + * Handle cases where RLS is enabled and there are policies, or there + * aren't policies, or RLS isn't enabled but there are policies + */ + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies:")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled):")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled):")); - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); - if (!tableinfo.rowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (row security disabled):")); + if (!tableinfo.rowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (row security disabled):")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " POLICY \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " POLICY \"%s\"", + PQgetvalue(result, i, 0)); - if (*(PQgetvalue(result, i, 1)) == 'f') - appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); + if (*(PQgetvalue(result, i, 1)) == 'f') + appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); - if (!PQgetisnull(result, i, 5)) - appendPQExpBuffer(&buf, " FOR %s", - PQgetvalue(result, i, 5)); + if (!PQgetisnull(result, i, 5)) + appendPQExpBuffer(&buf, " FOR %s", + PQgetvalue(result, i, 5)); - if (!PQgetisnull(result, i, 2)) - { - appendPQExpBuffer(&buf, "\n TO %s", - PQgetvalue(result, i, 2)); - } + if (!PQgetisnull(result, i, 2)) + { + appendPQExpBuffer(&buf, "\n TO %s", + PQgetvalue(result, i, 2)); + } - if (!PQgetisnull(result, i, 3)) - appendPQExpBuffer(&buf, "\n USING (%s)", - PQgetvalue(result, i, 3)); + if (!PQgetisnull(result, i, 3)) + appendPQExpBuffer(&buf, "\n USING (%s)", + PQgetvalue(result, i, 3)); - if (!PQgetisnull(result, i, 4)) - appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", - PQgetvalue(result, i, 4)); + if (!PQgetisnull(result, i, 4)) + appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", + PQgetvalue(result, i, 4)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* print any extended statistics */ if (pset.sversion >= 140000) @@ -3025,115 +3024,115 @@ describeOneTableDetails(const char *schemaname, } /* print any publications */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get publications that publish this table")); - if (pset.sversion >= 150000) + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get publications that publish this table")); + if (pset.sversion >= 150000) + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" + " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" + "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" + "UNION\n" + "SELECT pubname\n" + " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" + " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" + " (SELECT pg_catalog.string_agg(attname, ', ')\n" + " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" + " pg_catalog.pg_attribute\n" + " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" + " ELSE NULL END) " + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" + "WHERE pr.prrelid = '%s'\n", + oid, oid, oid); + + if (pset.sversion >= 190000) { + /* + * Skip entries where this relation appears in the + * publication's EXCEPT list. + */ appendPQExpBuffer(&buf, + " AND NOT pr.prexcept\n" + "UNION\n" "SELECT pubname\n" " , NULL\n" " , NULL\n" "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" - " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" - "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" - "UNION\n" - "SELECT pubname\n" - " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" - " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" - " (SELECT pg_catalog.string_agg(attname, ', ')\n" - " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" - " pg_catalog.pg_attribute\n" - " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" - " ELSE NULL END) " - "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" - "WHERE pr.prrelid = '%s'\n", + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + " AND NOT EXISTS (\n" + " SELECT 1\n" + " FROM pg_catalog.pg_publication_rel pr\n" + " WHERE pr.prpubid = p.oid AND\n" + " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" + "ORDER BY 1;", oid, oid, oid); - - if (pset.sversion >= 190000) - { - /* - * Skip entries where this relation appears in the - * publication's EXCEPT list. - */ - appendPQExpBuffer(&buf, - " AND NOT pr.prexcept\n" - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - " AND NOT EXISTS (\n" - " SELECT 1\n" - " FROM pg_catalog.pg_publication_rel pr\n" - " WHERE pr.prpubid = p.oid AND\n" - " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" - "ORDER BY 1;", - oid, oid, oid); - } - else - { - appendPQExpBuffer(&buf, - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - "ORDER BY 1;", - oid); - } } else { appendPQExpBuffer(&buf, + "UNION\n" "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - "WHERE pr.prrelid = '%s'\n" - "UNION ALL\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" + " , NULL\n" + " , NULL\n" "FROM pg_catalog.pg_publication p\n" "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" "ORDER BY 1;", - oid, oid); + oid); } + } + else + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + "WHERE pr.prrelid = '%s'\n" + "UNION ALL\n" + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + "ORDER BY 1;", + oid, oid); + } - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - if (tuples > 0) - printTableAddFooter(&cont, _("Included in publications:")); + if (tuples > 0) + printTableAddFooter(&cont, _("Included in publications:")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " \"%s\"", + PQgetvalue(result, i, 0)); - /* column list (if any) */ - if (!PQgetisnull(result, i, 2)) - appendPQExpBuffer(&buf, " (%s)", - PQgetvalue(result, i, 2)); + /* column list (if any) */ + if (!PQgetisnull(result, i, 2)) + appendPQExpBuffer(&buf, " (%s)", + PQgetvalue(result, i, 2)); - /* row filter (if any) */ - if (!PQgetisnull(result, i, 1)) - appendPQExpBuffer(&buf, " WHERE %s", - PQgetvalue(result, i, 1)); + /* row filter (if any) */ + if (!PQgetisnull(result, i, 1)) + appendPQExpBuffer(&buf, " WHERE %s", + PQgetvalue(result, i, 1)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* Print publications where the table is in the EXCEPT clause */ if (pset.sversion >= 190000) @@ -3805,7 +3804,7 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) ncols++; } appendPQExpBufferStr(&buf, "\n, r.rolreplication"); - appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); + appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_roles r\n"); @@ -3860,8 +3859,8 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) if (strcmp(PQgetvalue(res, i, (verbose ? 9 : 8)), "t") == 0) add_role_attribute(&buf, _("Replication")); - if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) - add_role_attribute(&buf, _("Bypass RLS")); + if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) + add_role_attribute(&buf, _("Bypass RLS")); conns = atoi(PQgetvalue(res, i, 6)); if (conns >= 0) @@ -5155,14 +5154,14 @@ listCollations(const char *pattern, bool verbose, bool showSystem) gettext_noop("Schema"), gettext_noop("Name")); - appendPQExpBuffer(&buf, - " CASE c.collprovider " - "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " - "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " - "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " - "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " - "END AS \"%s\",\n", - gettext_noop("Provider")); + appendPQExpBuffer(&buf, + " CASE c.collprovider " + "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " + "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " + "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " + "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " + "END AS \"%s\",\n", + gettext_noop("Provider")); appendPQExpBuffer(&buf, " c.collcollate AS \"%s\",\n" -- 2.50.1 (Apple Git-155) --aHl3HfeiUuO3zeNC-- ^ permalink raw reply [nested|flat] 59+ messages in thread
* [PATCH v6 4/4] run pgindent and pgperltidy @ 2026-06-30 18:24 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 59+ messages in thread From: Nathan Bossart @ 2026-06-30 18:24 UTC (permalink / raw) --- src/bin/pg_dump/pg_dump.c | 464 ++++++++++----------- src/bin/pg_dump/pg_dumpall.c | 30 +- src/bin/pg_upgrade/check.c | 16 +- src/bin/pg_upgrade/controldata.c | 2 +- src/bin/pg_upgrade/exec.c | 8 +- src/bin/pg_upgrade/multixact_rewrite.c | 80 ++-- src/bin/pg_upgrade/pg_upgrade.c | 34 +- src/bin/pg_upgrade/relfilenumber.c | 54 +-- src/bin/pg_upgrade/t/006_transfer_modes.pl | 33 +- src/bin/psql/command.c | 29 +- src/bin/psql/describe.c | 461 ++++++++++---------- 11 files changed, 601 insertions(+), 610 deletions(-) diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 65bd15ebfd2..5673268b467 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -1491,8 +1491,8 @@ setup_connection(Archive *AH, const char *dumpencoding, * Disable timeouts if supported. */ ExecuteSqlStatement(AH, "SET statement_timeout = 0"); - ExecuteSqlStatement(AH, "SET lock_timeout = 0"); - ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); + ExecuteSqlStatement(AH, "SET lock_timeout = 0"); + ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); if (AH->remoteVersion >= 170000) ExecuteSqlStatement(AH, "SET transaction_timeout = 0"); @@ -1505,10 +1505,10 @@ setup_connection(Archive *AH, const char *dumpencoding, /* * Adjust row-security mode, if supported. */ - if (dopt->enable_row_security) - ExecuteSqlStatement(AH, "SET row_security = on"); - else - ExecuteSqlStatement(AH, "SET row_security = off"); + if (dopt->enable_row_security) + ExecuteSqlStatement(AH, "SET row_security = on"); + else + ExecuteSqlStatement(AH, "SET row_security = off"); /* * For security reasons, we restrict the expansion of non-system views and @@ -1933,10 +1933,9 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) addObjectDependency(dobj, ext->dobj.dumpId); /* - * Mark the member object to have any non-initial ACLs - * dumped. (Any initial ACLs will be removed later, using data from - * pg_init_privs, so that we'll dump only the delta from the extension's - * initial setup.) + * Mark the member object to have any non-initial ACLs dumped. (Any + * initial ACLs will be removed later, using data from pg_init_privs, so + * that we'll dump only the delta from the extension's initial setup.) * * In binary upgrades, we still dump all components of the members * individually, since the idea is to exactly reproduce the database @@ -1953,7 +1952,7 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) if (fout->dopt->binary_upgrade) dobj->dump = ext->dobj.dump; else - dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); + dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); return true; } @@ -1987,9 +1986,9 @@ selectDumpableNamespace(NamespaceInfo *nsinfo, Archive *fout) else if (strcmp(nsinfo->dobj.name, "pg_catalog") == 0) { /* - * We dump out any ACLs defined in pg_catalog, if - * they are interesting (and not the original ACLs which were set at - * initdb time, see pg_init_privs). + * We dump out any ACLs defined in pg_catalog, if they are interesting + * (and not the original ACLs which were set at initdb time, see + * pg_init_privs). */ nsinfo->dobj.dump_contains = nsinfo->dobj.dump = DUMP_COMPONENT_ACL; } @@ -3296,7 +3295,7 @@ dumpDatabase(Archive *fout) "datcollate, datctype, datfrozenxid, " "datacl, acldefault('d', datdba) AS acldefault, " "datistemplate, datconnlimit, "); - appendPQExpBufferStr(dbQry, "datminmxid, "); + appendPQExpBufferStr(dbQry, "datminmxid, "); if (fout->remoteVersion >= 170000) appendPQExpBufferStr(dbQry, "datlocprovider, datlocale, datcollversion, "); else if (fout->remoteVersion >= 150000) @@ -3638,11 +3637,11 @@ dumpDatabase(Archive *fout) ii_oid, ii_relminmxid; - appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" - "FROM pg_catalog.pg_class\n" - "WHERE oid IN (%u, %u, %u, %u);\n", - LargeObjectRelationId, LargeObjectLOidPNIndexId, - LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); + appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" + "FROM pg_catalog.pg_class\n" + "WHERE oid IN (%u, %u, %u, %u);\n", + LargeObjectRelationId, LargeObjectLOidPNIndexId, + LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); lo_res = ExecuteSqlQuery(fout, loFrozenQry->data, PGRES_TUPLES_OK); @@ -4274,7 +4273,7 @@ getPolicies(Archive *fout, TableInfo tblinfo[], int numTables) printfPQExpBuffer(query, "SELECT pol.oid, pol.tableoid, pol.polrelid, pol.polname, pol.polcmd, "); - appendPQExpBufferStr(query, "pol.polpermissive, "); + appendPQExpBufferStr(query, "pol.polpermissive, "); appendPQExpBuffer(query, "CASE WHEN pol.polroles = '{0}' THEN NULL ELSE " " pg_catalog.array_to_string(ARRAY(SELECT pg_catalog.quote_ident(rolname) from pg_catalog.pg_roles WHERE oid = ANY(pol.polroles)), ', ') END AS polroles, " @@ -6633,9 +6632,9 @@ getAccessMethods(Archive *fout) * Select all access methods from pg_am table. */ appendPQExpBufferStr(query, "SELECT tableoid, oid, amname, "); - appendPQExpBufferStr(query, - "amtype, " - "amhandler::pg_catalog.regproc AS amhandler "); + appendPQExpBufferStr(query, + "amtype, " + "amhandler::pg_catalog.regproc AS amhandler "); appendPQExpBufferStr(query, "FROM pg_am"); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6827,35 +6826,35 @@ getAggregates(Archive *fout) * Find all interesting aggregates. See comment in getFuncs() for the * rationale behind the filtering logic. */ - agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" - : "p.proisagg"); + agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" + : "p.proisagg"); - appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " - "p.proname AS aggname, " - "p.pronamespace AS aggnamespace, " - "p.pronargs, p.proargtypes, " - "p.proowner, " - "p.proacl AS aggacl, " - "acldefault('f', p.proowner) AS acldefault " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s AND (" - "p.pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog') OR " - "p.proacl IS DISTINCT FROM pip.initprivs", - agg_check); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - " OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); - appendPQExpBufferChar(query, ')'); + appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " + "p.proname AS aggname, " + "p.pronamespace AS aggnamespace, " + "p.pronargs, p.proargtypes, " + "p.proowner, " + "p.proacl AS aggacl, " + "acldefault('f', p.proowner) AS acldefault " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s AND (" + "p.pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog') OR " + "p.proacl IS DISTINCT FROM pip.initprivs", + agg_check); + if (dopt->binary_upgrade) + appendPQExpBufferStr(query, + " OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6957,53 +6956,53 @@ getFuncs(Archive *fout) * include them, since we want to dump extension members individually in * that mode. Also, if they are used by casts or transforms then we need * to gather the information about them, though they won't be dumped if - * they are built-in. Also, include functions in - * pg_catalog if they have an ACL different from what's shown in - * pg_init_privs (so we have to join to pg_init_privs; annoying). + * they are built-in. Also, include functions in pg_catalog if they have + * an ACL different from what's shown in pg_init_privs (so we have to join + * to pg_init_privs; annoying). */ - not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" - : "NOT p.proisagg"); + not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" + : "NOT p.proisagg"); - appendPQExpBuffer(query, - "SELECT p.tableoid, p.oid, p.proname, p.prolang, " - "p.pronargs, p.proargtypes, p.prorettype, " - "p.proacl, " - "acldefault('f', p.proowner) AS acldefault, " - "p.pronamespace, " - "p.proowner " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s" - "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " - "WHERE classid = 'pg_proc'::regclass AND " - "objid = p.oid AND deptype = 'i')" - "\n AND (" - "\n pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog')" - "\n OR EXISTS (SELECT 1 FROM pg_cast" - "\n WHERE pg_cast.oid > %u " - "\n AND p.oid = pg_cast.castfunc)" - "\n OR EXISTS (SELECT 1 FROM pg_transform" - "\n WHERE pg_transform.oid > %u AND " - "\n (p.oid = pg_transform.trffromsql" - "\n OR p.oid = pg_transform.trftosql))", - not_agg_check, - g_last_builtin_oid, - g_last_builtin_oid); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); + appendPQExpBuffer(query, + "SELECT p.tableoid, p.oid, p.proname, p.prolang, " + "p.pronargs, p.proargtypes, p.prorettype, " + "p.proacl, " + "acldefault('f', p.proowner) AS acldefault, " + "p.pronamespace, " + "p.proowner " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s" + "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " + "WHERE classid = 'pg_proc'::regclass AND " + "objid = p.oid AND deptype = 'i')" + "\n AND (" + "\n pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog')" + "\n OR EXISTS (SELECT 1 FROM pg_cast" + "\n WHERE pg_cast.oid > %u " + "\n AND p.oid = pg_cast.castfunc)" + "\n OR EXISTS (SELECT 1 FROM pg_transform" + "\n WHERE pg_transform.oid > %u AND " + "\n (p.oid = pg_transform.trffromsql" + "\n OR p.oid = pg_transform.trftosql))", + not_agg_check, + g_last_builtin_oid, + g_last_builtin_oid); + if (dopt->binary_upgrade) appendPQExpBufferStr(query, - "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); - appendPQExpBufferChar(query, ')'); + "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferStr(query, + "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -7252,31 +7251,31 @@ getTables(Archive *fout, int *numTables) appendPQExpBufferStr(query, "c.relhasoids, "); - appendPQExpBufferStr(query, - "c.relispopulated, "); + appendPQExpBufferStr(query, + "c.relispopulated, "); - appendPQExpBufferStr(query, - "c.relreplident, "); + appendPQExpBufferStr(query, + "c.relreplident, "); - appendPQExpBufferStr(query, - "c.relrowsecurity, c.relforcerowsecurity, "); + appendPQExpBufferStr(query, + "c.relrowsecurity, c.relforcerowsecurity, "); - appendPQExpBufferStr(query, - "c.relminmxid, tc.relminmxid AS tminmxid, "); + appendPQExpBufferStr(query, + "c.relminmxid, tc.relminmxid AS tminmxid, "); - appendPQExpBufferStr(query, - "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); + appendPQExpBufferStr(query, + "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); - appendPQExpBufferStr(query, - "am.amname, "); + appendPQExpBufferStr(query, + "am.amname, "); - appendPQExpBufferStr(query, - "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); + appendPQExpBufferStr(query, + "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); - appendPQExpBufferStr(query, - "c.relispartition AS ispartition "); + appendPQExpBufferStr(query, + "c.relispartition AS ispartition "); /* * Left join to pg_depend to pick up dependency info linking sequences to @@ -7296,8 +7295,8 @@ getTables(Archive *fout, int *numTables) /* * Left join to pg_am to pick up the amname. */ - appendPQExpBufferStr(query, - "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); + appendPQExpBufferStr(query, + "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); /* * We purposefully ignore toast OIDs for partitioned tables; the reason is @@ -7868,8 +7867,8 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables) "t.reloptions AS indreloptions, "); - appendPQExpBufferStr(query, - "i.indisreplident, "); + appendPQExpBufferStr(query, + "i.indisreplident, "); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -9313,8 +9312,8 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables) appendPQExpBufferStr(q, "'' AS attcompression,\n"); - appendPQExpBufferStr(q, - "a.attidentity,\n"); + appendPQExpBufferStr(q, + "a.attidentity,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(q, @@ -10717,73 +10716,73 @@ getAdditionalACLs(Archive *fout) PQclear(res); /* Fetch initial-privileges data */ - printfPQExpBuffer(query, - "SELECT objoid, classoid, objsubid, privtype, initprivs " - "FROM pg_init_privs"); + printfPQExpBuffer(query, + "SELECT objoid, classoid, objsubid, privtype, initprivs " + "FROM pg_init_privs"); - res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); + res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); - ntups = PQntuples(res); - for (i = 0; i < ntups; i++) - { - Oid objoid = atooid(PQgetvalue(res, i, 0)); - Oid classoid = atooid(PQgetvalue(res, i, 1)); - int objsubid = atoi(PQgetvalue(res, i, 2)); - char privtype = *(PQgetvalue(res, i, 3)); - char *initprivs = PQgetvalue(res, i, 4); - CatalogId objId; - DumpableObject *dobj; + ntups = PQntuples(res); + for (i = 0; i < ntups; i++) + { + Oid objoid = atooid(PQgetvalue(res, i, 0)); + Oid classoid = atooid(PQgetvalue(res, i, 1)); + int objsubid = atoi(PQgetvalue(res, i, 2)); + char privtype = *(PQgetvalue(res, i, 3)); + char *initprivs = PQgetvalue(res, i, 4); + CatalogId objId; + DumpableObject *dobj; - objId.tableoid = classoid; - objId.oid = objoid; - dobj = findObjectByCatalogId(objId); - /* OK to ignore entries we haven't got a DumpableObject for */ - if (dobj) + objId.tableoid = classoid; + objId.oid = objoid; + dobj = findObjectByCatalogId(objId); + /* OK to ignore entries we haven't got a DumpableObject for */ + if (dobj) + { + /* Cope with sub-object initprivs */ + if (objsubid != 0) { - /* Cope with sub-object initprivs */ - if (objsubid != 0) - { - if (dobj->objType == DO_TABLE) - { - /* For a column initprivs, set the table's ACL flags */ - dobj->components |= DUMP_COMPONENT_ACL; - ((TableInfo *) dobj)->hascolumnACLs = true; - } - else - pg_log_warning("unsupported pg_init_privs entry: %u %u %d", - classoid, objoid, objsubid); - continue; - } - - /* - * We ignore any pg_init_privs.initprivs entry for the public - * schema, as explained in getNamespaces(). - */ - if (dobj->objType == DO_NAMESPACE && - strcmp(dobj->name, "public") == 0) - continue; - - /* Else it had better be of a type we think has ACLs */ - if (dobj->objType == DO_NAMESPACE || - dobj->objType == DO_TYPE || - dobj->objType == DO_FUNC || - dobj->objType == DO_AGG || - dobj->objType == DO_TABLE || - dobj->objType == DO_PROCLANG || - dobj->objType == DO_FDW || - dobj->objType == DO_FOREIGN_SERVER) + if (dobj->objType == DO_TABLE) { - DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; - - daobj->dacl.privtype = privtype; - daobj->dacl.initprivs = pstrdup(initprivs); + /* For a column initprivs, set the table's ACL flags */ + dobj->components |= DUMP_COMPONENT_ACL; + ((TableInfo *) dobj)->hascolumnACLs = true; } else pg_log_warning("unsupported pg_init_privs entry: %u %u %d", classoid, objoid, objsubid); + continue; + } + + /* + * We ignore any pg_init_privs.initprivs entry for the public + * schema, as explained in getNamespaces(). + */ + if (dobj->objType == DO_NAMESPACE && + strcmp(dobj->name, "public") == 0) + continue; + + /* Else it had better be of a type we think has ACLs */ + if (dobj->objType == DO_NAMESPACE || + dobj->objType == DO_TYPE || + dobj->objType == DO_FUNC || + dobj->objType == DO_AGG || + dobj->objType == DO_TABLE || + dobj->objType == DO_PROCLANG || + dobj->objType == DO_FDW || + dobj->objType == DO_FOREIGN_SERVER) + { + DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; + + daobj->dacl.privtype = privtype; + daobj->dacl.initprivs = pstrdup(initprivs); } + else + pg_log_warning("unsupported pg_init_privs entry: %u %u %d", + classoid, objoid, objsubid); } - PQclear(res); + } + PQclear(res); destroyPQExpBuffer(query); } @@ -11128,8 +11127,8 @@ dumpRelationStats_dumper(Archive *fout, const void *userArg, const TocEntry *te) * The results must be in the order of the relations supplied in the * parameters to ensure we remain in sync as we walk through the TOC. * - * For versions before 19, the redundant filter clause on s.tablename = - * ANY(...) seems sufficient to convince the planner to use + * For versions before 19, the redundant filter clause on s.tablename + * = ANY(...) seems sufficient to convince the planner to use * pg_class_relname_nsp_index, which avoids a full scan of pg_stats. * In newer versions, pg_stats returns the table OIDs, eliminating the * need for that hack. @@ -13469,11 +13468,11 @@ dumpFunc(Archive *fout, const FuncInfo *finfo) "pg_catalog.pg_get_function_result(p.oid) AS funcresult,\n" "proleakproof,\n"); - appendPQExpBufferStr(query, - "array_to_string(protrftypes, ' ') AS protrftypes,\n"); + appendPQExpBufferStr(query, + "array_to_string(protrftypes, ' ') AS protrftypes,\n"); - appendPQExpBufferStr(query, - "proparallel,\n"); + appendPQExpBufferStr(query, + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -14963,9 +14962,9 @@ dumpCollation(Archive *fout, const CollInfo *collinfo) /* Get collation-specific details */ appendPQExpBufferStr(query, "SELECT "); - appendPQExpBufferStr(query, - "collprovider, " - "collversion, "); + appendPQExpBufferStr(query, + "collprovider, " + "collversion, "); if (fout->remoteVersion >= 120000) appendPQExpBufferStr(query, @@ -15372,23 +15371,23 @@ dumpAgg(Archive *fout, const AggInfo *agginfo) "pg_catalog.pg_get_function_arguments(p.oid) AS funcargs,\n" "pg_catalog.pg_get_function_identity_arguments(p.oid) AS funciargs,\n"); - appendPQExpBufferStr(query, - "aggkind,\n" - "aggmtransfn,\n" - "aggminvtransfn,\n" - "aggmfinalfn,\n" - "aggmtranstype::pg_catalog.regtype,\n" - "aggfinalextra,\n" - "aggmfinalextra,\n" - "aggtransspace,\n" - "aggmtransspace,\n" - "aggminitval,\n"); + appendPQExpBufferStr(query, + "aggkind,\n" + "aggmtransfn,\n" + "aggminvtransfn,\n" + "aggmfinalfn,\n" + "aggmtranstype::pg_catalog.regtype,\n" + "aggfinalextra,\n" + "aggmfinalextra,\n" + "aggtransspace,\n" + "aggmtransspace,\n" + "aggminitval,\n"); - appendPQExpBufferStr(query, - "aggcombinefn,\n" - "aggserialfn,\n" - "aggdeserialfn,\n" - "proparallel,\n"); + appendPQExpBufferStr(query, + "aggcombinefn,\n" + "aggserialfn,\n" + "aggdeserialfn,\n" + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -16848,30 +16847,30 @@ dumpTable(Archive *fout, const TableInfo *tbinfo) appendPQExpBufferStr(query, "PREPARE getColumnACLs(pg_catalog.oid) AS\n"); - /* - * In principle we should call acldefault('c', relowner) to - * get the default ACL for a column. However, we don't - * currently store the numeric OID of the relowner in - * TableInfo. We could convert the owner name using regrole, - * but that creates a risk of failure due to concurrent role - * renames. Given that the default ACL for columns is empty - * and is likely to stay that way, it's not worth extra cycles - * and risk to avoid hard-wiring that knowledge here. - */ - appendPQExpBufferStr(query, - "SELECT at.attname, " - "at.attacl, " - "'{}' AS acldefault, " - "pip.privtype, pip.initprivs " - "FROM pg_catalog.pg_attribute at " - "LEFT JOIN pg_catalog.pg_init_privs pip ON " - "(at.attrelid = pip.objoid " - "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " - "AND at.attnum = pip.objsubid) " - "WHERE at.attrelid = $1 AND " - "NOT at.attisdropped " - "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " - "ORDER BY at.attnum"); + /* + * In principle we should call acldefault('c', relowner) to get + * the default ACL for a column. However, we don't currently + * store the numeric OID of the relowner in TableInfo. We could + * convert the owner name using regrole, but that creates a risk + * of failure due to concurrent role renames. Given that the + * default ACL for columns is empty and is likely to stay that + * way, it's not worth extra cycles and risk to avoid hard-wiring + * that knowledge here. + */ + appendPQExpBufferStr(query, + "SELECT at.attname, " + "at.attacl, " + "'{}' AS acldefault, " + "pip.privtype, pip.initprivs " + "FROM pg_catalog.pg_attribute at " + "LEFT JOIN pg_catalog.pg_init_privs pip ON " + "(at.attrelid = pip.objoid " + "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " + "AND at.attnum = pip.objsubid) " + "WHERE at.attrelid = $1 AND " + "NOT at.attisdropped " + "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " + "ORDER BY at.attnum"); ExecuteSqlStatement(fout, query->data); @@ -19165,7 +19164,7 @@ collectSequences(Archive *fout) * pg_get_sequence_data(), but we only do so for non-schema-only dumps. */ if (fout->remoteVersion < 180000 || - (!fout->dopt->dumpData && !fout->dopt->sequence_data)) + (!fout->dopt->dumpData && !fout->dopt->sequence_data)) query = "SELECT seqrelid, format_type(seqtypid, NULL), " "seqstart, seqincrement, " "seqmax, seqmin, " @@ -19227,15 +19226,14 @@ dumpSequence(Archive *fout, const TableInfo *tbinfo) qseqname = pg_strdup(fmtId(tbinfo->dobj.name)); /* - * The sequence information is gathered in a sorted - * table before any calls to dumpSequence(). See collectSequences() for - * more information. + * The sequence information is gathered in a sorted table before any calls + * to dumpSequence(). See collectSequences() for more information. */ - Assert(sequences); + Assert(sequences); - key.oid = tbinfo->dobj.catId.oid; - seq = bsearch(&key, sequences, nsequences, - sizeof(SequenceItem), SequenceItemCmp); + key.oid = tbinfo->dobj.catId.oid; + seq = bsearch(&key, sequences, nsequences, + sizeof(SequenceItem), SequenceItemCmp); /* Calculate default limits for a sequence of this type */ is_ascending = (seq->incby >= 0); diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c index e68937c9934..afcd9a218d8 100644 --- a/src/bin/pg_dump/pg_dumpall.c +++ b/src/bin/pg_dump/pg_dumpall.c @@ -785,11 +785,11 @@ dropRoles(PGconn *conn) int i_rolname; int i; - printfPQExpBuffer(buf, - "SELECT rolname " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 1", role_catalog); + printfPQExpBuffer(buf, + "SELECT rolname " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 1", role_catalog); res = executeQuery(conn, buf->data); @@ -843,16 +843,16 @@ dumpRoles(PGconn *conn) * Notes: rolconfig is dumped later, and pg_authid must be used for * extracting rolcomment regardless of role_catalog. */ - printfPQExpBuffer(buf, - "SELECT oid, rolname, rolsuper, rolinherit, " - "rolcreaterole, rolcreatedb, " - "rolcanlogin, rolconnlimit, rolpassword, " - "rolvaliduntil, rolreplication, rolbypassrls, " - "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " - "rolname = current_user AS is_current_user " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 2", role_catalog); + printfPQExpBuffer(buf, + "SELECT oid, rolname, rolsuper, rolinherit, " + "rolcreaterole, rolcreatedb, " + "rolcanlogin, rolconnlimit, rolpassword, " + "rolvaliduntil, rolreplication, rolbypassrls, " + "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " + "rolname = current_user AS is_current_user " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 2", role_catalog); res = executeQuery(conn, buf->data); diff --git a/src/bin/pg_upgrade/check.c b/src/bin/pg_upgrade/check.c index 786c1474829..f725f5ee3e2 100644 --- a/src/bin/pg_upgrade/check.c +++ b/src/bin/pg_upgrade/check.c @@ -1475,15 +1475,15 @@ check_for_incompatible_polymorphics(ClusterInfo *cluster) ", 'array_cat(anyarray,anyarray)'" ", 'array_prepend(anyelement,anyarray)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_remove(anyarray,anyelement)'" - ", 'array_replace(anyarray,anyelement,anyelement)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_remove(anyarray,anyelement)'" + ", 'array_replace(anyarray,anyelement,anyelement)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_position(anyarray,anyelement)'" - ", 'array_position(anyarray,anyelement,integer)'" - ", 'array_positions(anyarray,anyelement)'" - ", 'width_bucket(anyelement,anyarray)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_position(anyarray,anyelement)'" + ", 'array_position(anyarray,anyelement,integer)'" + ", 'array_positions(anyarray,anyelement)'" + ", 'width_bucket(anyelement,anyarray)'"); /* * The query below hardcodes FirstNormalObjectId as 16384 rather than diff --git a/src/bin/pg_upgrade/controldata.c b/src/bin/pg_upgrade/controldata.c index 8f81c9e9582..02ea02df60f 100644 --- a/src/bin/pg_upgrade/controldata.c +++ b/src/bin/pg_upgrade/controldata.c @@ -228,7 +228,7 @@ get_control_data(ClusterInfo *cluster) p++; /* remove ':' char */ cluster->controldata.chkpnt_nxtepoch = str2uint(p); - p = strchr(p, ':'); + p = strchr(p, ':'); if (p == NULL || strlen(p) <= 1) pg_fatal("%d: controldata retrieval problem", __LINE__); diff --git a/src/bin/pg_upgrade/exec.c b/src/bin/pg_upgrade/exec.c index 44355feea30..a1bdbf373e3 100644 --- a/src/bin/pg_upgrade/exec.c +++ b/src/bin/pg_upgrade/exec.c @@ -55,7 +55,7 @@ get_bin_version(ClusterInfo *cluster) if (sscanf(cmd_output, "%*s %*s %d.%d", &v1, &v2) < 1) pg_fatal("could not get pg_ctl version output from %s", cmd); - cluster->bin_version = v1 * 10000; + cluster->bin_version = v1 * 10000; } @@ -344,8 +344,8 @@ check_data_dir(ClusterInfo *cluster) check_single_dir(pg_data, "pg_subtrans"); check_single_dir(pg_data, PG_TBLSPC_DIR); check_single_dir(pg_data, "pg_twophase"); - check_single_dir(pg_data, "pg_wal"); - check_single_dir(pg_data, "pg_xact"); + check_single_dir(pg_data, "pg_wal"); + check_single_dir(pg_data, "pg_xact"); } @@ -385,7 +385,7 @@ check_bin_dir(ClusterInfo *cluster, bool check_versions) */ get_bin_version(cluster); - check_exec(cluster->bindir, "pg_resetwal", check_versions); + check_exec(cluster->bindir, "pg_resetwal", check_versions); if (cluster == &new_cluster) { diff --git a/src/bin/pg_upgrade/multixact_rewrite.c b/src/bin/pg_upgrade/multixact_rewrite.c index c45b3183684..c7a1416494d 100644 --- a/src/bin/pg_upgrade/multixact_rewrite.c +++ b/src/bin/pg_upgrade/multixact_rewrite.c @@ -61,52 +61,52 @@ rewrite_multixacts(MultiXactId from_multi, MultiXactId to_multi) * Convert old multixids, if needed, by reading them one-by-one from the * old cluster. */ - old_reader = AllocOldMultiXactRead(old_cluster.pgdata, - old_cluster.controldata.chkpnt_nxtmulti, - old_cluster.controldata.chkpnt_nxtmxoff); + old_reader = AllocOldMultiXactRead(old_cluster.pgdata, + old_cluster.controldata.chkpnt_nxtmulti, + old_cluster.controldata.chkpnt_nxtmxoff); - for (MultiXactId multi = from_multi; multi != to_multi;) - { - MultiXactMember member; - bool multixid_valid; - - /* - * Read this multixid's members. - * - * Locking-only XIDs that may be part of multi-xids don't matter - * after upgrade, as there can be no transactions running across - * upgrade. So as a small optimization, we only read one member - * from each multixid: the one updating one, or if there was no - * update, arbitrarily the first locking xid. - */ - multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); + for (MultiXactId multi = from_multi; multi != to_multi;) + { + MultiXactMember member; + bool multixid_valid; - /* - * Write the new offset to pg_multixact/offsets. - * - * Even if this multixid is invalid, we still need to write its - * offset if the *previous* multixid was valid. That's because - * when reading a multixid, the number of members is calculated - * from the difference between the two offsets. - */ - RecordMultiXactOffset(offsets_writer, multi, - (multixid_valid || prev_multixid_valid) ? next_offset : 0); + /* + * Read this multixid's members. + * + * Locking-only XIDs that may be part of multi-xids don't matter after + * upgrade, as there can be no transactions running across upgrade. So + * as a small optimization, we only read one member from each + * multixid: the one updating one, or if there was no update, + * arbitrarily the first locking xid. + */ + multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); - /* Write the members */ - if (multixid_valid) - { - RecordMultiXactMembers(members_writer, next_offset, 1, &member); - next_offset += 1; - } + /* + * Write the new offset to pg_multixact/offsets. + * + * Even if this multixid is invalid, we still need to write its offset + * if the *previous* multixid was valid. That's because when reading + * a multixid, the number of members is calculated from the difference + * between the two offsets. + */ + RecordMultiXactOffset(offsets_writer, multi, + (multixid_valid || prev_multixid_valid) ? next_offset : 0); - /* Advance to next multixid, handling wraparound */ - multi++; - if (multi < FirstMultiXactId) - multi = FirstMultiXactId; - prev_multixid_valid = multixid_valid; + /* Write the members */ + if (multixid_valid) + { + RecordMultiXactMembers(members_writer, next_offset, 1, &member); + next_offset += 1; } - FreeOldMultiXactReader(old_reader); + /* Advance to next multixid, handling wraparound */ + multi++; + if (multi < FirstMultiXactId) + multi = FirstMultiXactId; + prev_multixid_valid = multixid_valid; + } + + FreeOldMultiXactReader(old_reader); /* Write the final 'next' offset to the last SLRU page */ RecordMultiXactOffset(offsets_writer, to_multi, diff --git a/src/bin/pg_upgrade/pg_upgrade.c b/src/bin/pg_upgrade/pg_upgrade.c index c6af9035665..7366fd4627c 100644 --- a/src/bin/pg_upgrade/pg_upgrade.c +++ b/src/bin/pg_upgrade/pg_upgrade.c @@ -833,7 +833,7 @@ copy_xact_xlog_xid(void) * Determine the range of multixacts to convert. */ nxtmulti = old_cluster.controldata.chkpnt_nxtmulti; - oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; + oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; /* handle wraparound */ if (nxtmulti < FirstMultiXactId) nxtmulti = FirstMultiXactId; @@ -898,15 +898,15 @@ set_frozenxids(void) int i_datname; int i_datallowconn; - prep_status("Setting frozenxid and minmxid counters in new cluster"); + prep_status("Setting frozenxid and minmxid counters in new cluster"); conn_template1 = connectToServer(&new_cluster, "template1"); - /* set pg_database.datfrozenxid */ - PQclear(executeQueryOrDie(conn_template1, - "UPDATE pg_catalog.pg_database " - "SET datfrozenxid = '%u'", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_database.datfrozenxid */ + PQclear(executeQueryOrDie(conn_template1, + "UPDATE pg_catalog.pg_database " + "SET datfrozenxid = '%u'", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_database.datminmxid */ PQclear(executeQueryOrDie(conn_template1, @@ -942,16 +942,16 @@ set_frozenxids(void) conn = connectToServer(&new_cluster, datname); - /* set pg_class.relfrozenxid */ - PQclear(executeQueryOrDie(conn, - "UPDATE pg_catalog.pg_class " - "SET relfrozenxid = '%u' " - /* only heap, materialized view, and TOAST are vacuumed */ - "WHERE relkind IN (" - CppAsString2(RELKIND_RELATION) ", " - CppAsString2(RELKIND_MATVIEW) ", " - CppAsString2(RELKIND_TOASTVALUE) ")", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_class.relfrozenxid */ + PQclear(executeQueryOrDie(conn, + "UPDATE pg_catalog.pg_class " + "SET relfrozenxid = '%u' " + /* only heap, materialized view, and TOAST are vacuumed */ + "WHERE relkind IN (" + CppAsString2(RELKIND_RELATION) ", " + CppAsString2(RELKIND_MATVIEW) ", " + CppAsString2(RELKIND_TOASTVALUE) ")", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_class.relminmxid */ PQclear(executeQueryOrDie(conn, diff --git a/src/bin/pg_upgrade/relfilenumber.c b/src/bin/pg_upgrade/relfilenumber.c index ec2ff7acb21..6c467bdc8a5 100644 --- a/src/bin/pg_upgrade/relfilenumber.c +++ b/src/bin/pg_upgrade/relfilenumber.c @@ -587,32 +587,32 @@ transfer_relfile(FileNameMap *map, const char *type_suffix) /* Copying files might take some time, so give feedback. */ pg_log(PG_STATUS, "%s", old_file); - switch (user_opts.transfer_mode) - { - case TRANSFER_MODE_CLONE: - pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", - old_file, new_file); - cloneFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", - old_file, new_file); - copyFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY_FILE_RANGE: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", - old_file, new_file); - copyFileByRange(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_LINK: - pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", - old_file, new_file); - linkFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_SWAP: - /* swap mode is handled in its own code path */ - pg_fatal("should never happen"); - break; - } + switch (user_opts.transfer_mode) + { + case TRANSFER_MODE_CLONE: + pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", + old_file, new_file); + cloneFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", + old_file, new_file); + copyFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY_FILE_RANGE: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", + old_file, new_file); + copyFileByRange(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_LINK: + pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", + old_file, new_file); + linkFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_SWAP: + /* swap mode is handled in its own code path */ + pg_fatal("should never happen"); + break; + } } } diff --git a/src/bin/pg_upgrade/t/006_transfer_modes.pl b/src/bin/pg_upgrade/t/006_transfer_modes.pl index 9efa5dc863c..360d05c4b68 100644 --- a/src/bin/pg_upgrade/t/006_transfer_modes.pl +++ b/src/bin/pg_upgrade/t/006_transfer_modes.pl @@ -29,10 +29,8 @@ sub test_mode } $new->init(); - $new->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); - $old->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); + $new->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); + $old->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); # We can only test security labels if both the old and new installations # have dummy_seclabel. @@ -76,15 +74,14 @@ sub test_mode "CREATE TABLE test4 AS SELECT generate_series(400, 502)"); } - $old->safe_psql('postgres', - "CREATE TABLESPACE inplc_tblspc LOCATION ''"); - $old->safe_psql('postgres', - "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); - $old->safe_psql('postgres', - "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" - ); - $old->safe_psql('testdb3', - "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); + $old->safe_psql('postgres', "CREATE TABLESPACE inplc_tblspc LOCATION ''"); + $old->safe_psql('postgres', + "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); + $old->safe_psql('postgres', + "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" + ); + $old->safe_psql('testdb3', + "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); # While we are here, test handling of large objects. $old->safe_psql( @@ -152,12 +149,10 @@ sub test_mode } # Tests for in-place tablespaces. - $result = - $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); - is($result, '104', "test5 data after pg_upgrade $mode"); - $result = - $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); - is($result, '105', "test6 data after pg_upgrade $mode"); + $result = $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); + is($result, '104', "test5 data after pg_upgrade $mode"); + $result = $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); + is($result, '105', "test6 data after pg_upgrade $mode"); # Tests for large objects $result = $new->safe_psql('postgres', "SELECT lo_get(4532)"); diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index 44ef11d980e..c90bf8bbde2 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -6278,23 +6278,22 @@ get_create_object_cmd(EditableObjectType obj_type, Oid oid, * ensure the right view gets replaced. Also, check relation kind * to be sure it's a view. * - * Views may have WITH [LOCAL|CASCADED] - * CHECK OPTION. These are not part of the view definition - * returned by pg_get_viewdef() and so need to be retrieved - * separately. Materialized views may have - * arbitrary storage parameter reloptions. + * Views may have WITH [LOCAL|CASCADED] CHECK OPTION. These are + * not part of the view definition returned by pg_get_viewdef() + * and so need to be retrieved separately. Materialized views may + * have arbitrary storage parameter reloptions. */ printfPQExpBuffer(query, "/* %s */\n", _("Get view's definition and details")); - appendPQExpBuffer(query, - "SELECT nspname, relname, relkind, " - "pg_catalog.pg_get_viewdef(c.oid, true), " - "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " - "FROM pg_catalog.pg_class c " - "LEFT JOIN pg_catalog.pg_namespace n " - "ON c.relnamespace = n.oid WHERE c.oid = %u", - oid); + appendPQExpBuffer(query, + "SELECT nspname, relname, relkind, " + "pg_catalog.pg_get_viewdef(c.oid, true), " + "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " + "FROM pg_catalog.pg_class c " + "LEFT JOIN pg_catalog.pg_namespace n " + "ON c.relnamespace = n.oid WHERE c.oid = %u", + oid); break; } diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index ce99137c613..ac0c55e7aa5 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -387,19 +387,19 @@ describeFunctions(const char *functypes, const char *func_pattern, gettext_noop("stable"), gettext_noop("volatile"), gettext_noop("Volatility")); - appendPQExpBuffer(&buf, - ",\n CASE\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" - " END as \"%s\"", - gettext_noop("restricted"), - gettext_noop("safe"), - gettext_noop("unsafe"), - gettext_noop("Parallel")); + appendPQExpBuffer(&buf, + ",\n CASE\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" + " END as \"%s\"", + gettext_noop("restricted"), + gettext_noop("safe"), + gettext_noop("unsafe"), + gettext_noop("Parallel")); appendPQExpBuffer(&buf, ",\n pg_catalog.pg_get_userbyid(p.proowner) as \"%s\"" ",\n CASE WHEN prosecdef THEN '%s' ELSE '%s' END AS \"%s\"" @@ -599,8 +599,8 @@ describeFunctions(const char *functypes, const char *func_pattern, myopt.title = _("List of functions"); myopt.translate_header = true; - myopt.translate_columns = translate_columns; - myopt.n_translate_columns = lengthof(translate_columns); + myopt.translate_columns = translate_columns; + myopt.n_translate_columns = lengthof(translate_columns); printQuery(res, &myopt, pset.queryFout, false, pset.logfile); @@ -1086,38 +1086,38 @@ permissionsList(const char *pattern, bool showSystem) " ), E'\\n') AS \"%s\"", gettext_noop("Column privileges")); - appendPQExpBuffer(&buf, - ",\n pg_catalog.array_to_string(ARRAY(\n" - " SELECT polname\n" - " || CASE WHEN NOT polpermissive THEN\n" - " E' (RESTRICTIVE)'\n" - " ELSE '' END\n" - " || CASE WHEN polcmd != '*' THEN\n" - " E' (' || polcmd::pg_catalog.text || E'):'\n" - " ELSE E':'\n" - " END\n" - " || CASE WHEN polqual IS NOT NULL THEN\n" - " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" - " ELSE E''\n" - " END\n" - " || CASE WHEN polwithcheck IS NOT NULL THEN\n" - " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" - " ELSE E''\n" - " END" - " || CASE WHEN polroles <> '{0}' THEN\n" - " E'\\n to: ' || pg_catalog.array_to_string(\n" - " ARRAY(\n" - " SELECT rolname\n" - " FROM pg_catalog.pg_roles\n" - " WHERE oid = ANY (polroles)\n" - " ORDER BY 1\n" - " ), E', ')\n" - " ELSE E''\n" - " END\n" - " FROM pg_catalog.pg_policy pol\n" - " WHERE polrelid = c.oid), E'\\n')\n" - " AS \"%s\"", - gettext_noop("Policies")); + appendPQExpBuffer(&buf, + ",\n pg_catalog.array_to_string(ARRAY(\n" + " SELECT polname\n" + " || CASE WHEN NOT polpermissive THEN\n" + " E' (RESTRICTIVE)'\n" + " ELSE '' END\n" + " || CASE WHEN polcmd != '*' THEN\n" + " E' (' || polcmd::pg_catalog.text || E'):'\n" + " ELSE E':'\n" + " END\n" + " || CASE WHEN polqual IS NOT NULL THEN\n" + " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" + " ELSE E''\n" + " END\n" + " || CASE WHEN polwithcheck IS NOT NULL THEN\n" + " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" + " ELSE E''\n" + " END" + " || CASE WHEN polroles <> '{0}' THEN\n" + " E'\\n to: ' || pg_catalog.array_to_string(\n" + " ARRAY(\n" + " SELECT rolname\n" + " FROM pg_catalog.pg_roles\n" + " WHERE oid = ANY (polroles)\n" + " ORDER BY 1\n" + " ), E', ')\n" + " ELSE E''\n" + " END\n" + " FROM pg_catalog.pg_policy pol\n" + " WHERE polrelid = c.oid), E'\\n')\n" + " AS \"%s\"", + gettext_noop("Policies")); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_class c\n" " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n" @@ -1675,27 +1675,27 @@ describeOneTableDetails(const char *schemaname, char *footers[3] = {NULL, NULL, NULL}; printfPQExpBuffer(&buf, "/* %s */\n", _("Get sequence information")); - appendPQExpBuffer(&buf, - "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" - " seqstart AS \"%s\",\n" - " seqmin AS \"%s\",\n" - " seqmax AS \"%s\",\n" - " seqincrement AS \"%s\",\n" - " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" - " seqcache AS \"%s\"\n", - gettext_noop("Type"), - gettext_noop("Start"), - gettext_noop("Minimum"), - gettext_noop("Maximum"), - gettext_noop("Increment"), - gettext_noop("yes"), - gettext_noop("no"), - gettext_noop("Cycles?"), - gettext_noop("Cache")); - appendPQExpBuffer(&buf, - "FROM pg_catalog.pg_sequence\n" - "WHERE seqrelid = '%s';", - oid); + appendPQExpBuffer(&buf, + "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" + " seqstart AS \"%s\",\n" + " seqmin AS \"%s\",\n" + " seqmax AS \"%s\",\n" + " seqincrement AS \"%s\",\n" + " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" + " seqcache AS \"%s\"\n", + gettext_noop("Type"), + gettext_noop("Start"), + gettext_noop("Minimum"), + gettext_noop("Maximum"), + gettext_noop("Increment"), + gettext_noop("yes"), + gettext_noop("no"), + gettext_noop("Cycles?"), + gettext_noop("Cache")); + appendPQExpBuffer(&buf, + "FROM pg_catalog.pg_sequence\n" + "WHERE seqrelid = '%s';", + oid); res = PSQLexec(buf.data); if (!res) @@ -1913,7 +1913,7 @@ describeOneTableDetails(const char *schemaname, appendPQExpBufferStr(&buf, ",\n (SELECT c.collname FROM pg_catalog.pg_collation c, pg_catalog.pg_type t\n" " WHERE c.oid = a.attcollation AND t.oid = a.atttypid AND a.attcollation <> t.typcollation) AS attcollation"); attcoll_col = cols++; - appendPQExpBufferStr(&buf, ",\n a.attidentity"); + appendPQExpBufferStr(&buf, ",\n a.attidentity"); attidentity_col = cols++; if (pset.sversion >= 120000) appendPQExpBufferStr(&buf, ",\n a.attgenerated"); @@ -2326,7 +2326,7 @@ describeOneTableDetails(const char *schemaname, CppAsString2(CONSTRAINT_EXCLUSION) ") AND " "condeferred) AS condeferred,\n"); - appendPQExpBufferStr(&buf, "i.indisreplident,\n"); + appendPQExpBufferStr(&buf, "i.indisreplident,\n"); if (pset.sversion >= 150000) appendPQExpBufferStr(&buf, "i.indnullsnotdistinct,\n"); @@ -2431,7 +2431,7 @@ describeOneTableDetails(const char *schemaname, "pg_catalog.pg_get_indexdef(i.indexrelid, 0, true),\n " "pg_catalog.pg_get_constraintdef(con.oid, true), " "contype, condeferrable, condeferred"); - appendPQExpBufferStr(&buf, ", i.indisreplident"); + appendPQExpBufferStr(&buf, ", i.indisreplident"); appendPQExpBufferStr(&buf, ", c2.reltablespace"); if (pset.sversion >= 180000) appendPQExpBufferStr(&buf, ", con.conperiod"); @@ -2682,81 +2682,80 @@ describeOneTableDetails(const char *schemaname, PQclear(result); /* print any row-level policies */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get row-level policies for this table")); - appendPQExpBufferStr(&buf, "SELECT pol.polname,"); - appendPQExpBufferStr(&buf, - " pol.polpermissive,\n"); - appendPQExpBuffer(&buf, - " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" - " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" - " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" - " CASE pol.polcmd\n" - " WHEN 'r' THEN 'SELECT'\n" - " WHEN 'a' THEN 'INSERT'\n" - " WHEN 'w' THEN 'UPDATE'\n" - " WHEN 'd' THEN 'DELETE'\n" - " END AS cmd\n" - "FROM pg_catalog.pg_policy pol\n" - "WHERE pol.polrelid = '%s' ORDER BY 1;", - oid); + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get row-level policies for this table")); + appendPQExpBufferStr(&buf, "SELECT pol.polname,"); + appendPQExpBufferStr(&buf, + " pol.polpermissive,\n"); + appendPQExpBuffer(&buf, + " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" + " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" + " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" + " CASE pol.polcmd\n" + " WHEN 'r' THEN 'SELECT'\n" + " WHEN 'a' THEN 'INSERT'\n" + " WHEN 'w' THEN 'UPDATE'\n" + " WHEN 'd' THEN 'DELETE'\n" + " END AS cmd\n" + "FROM pg_catalog.pg_policy pol\n" + "WHERE pol.polrelid = '%s' ORDER BY 1;", + oid); - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - /* - * Handle cases where RLS is enabled and there are policies, or - * there aren't policies, or RLS isn't enabled but there are - * policies - */ - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies:")); + /* + * Handle cases where RLS is enabled and there are policies, or there + * aren't policies, or RLS isn't enabled but there are policies + */ + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies:")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled):")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled):")); - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); - if (!tableinfo.rowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (row security disabled):")); + if (!tableinfo.rowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (row security disabled):")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " POLICY \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " POLICY \"%s\"", + PQgetvalue(result, i, 0)); - if (*(PQgetvalue(result, i, 1)) == 'f') - appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); + if (*(PQgetvalue(result, i, 1)) == 'f') + appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); - if (!PQgetisnull(result, i, 5)) - appendPQExpBuffer(&buf, " FOR %s", - PQgetvalue(result, i, 5)); + if (!PQgetisnull(result, i, 5)) + appendPQExpBuffer(&buf, " FOR %s", + PQgetvalue(result, i, 5)); - if (!PQgetisnull(result, i, 2)) - { - appendPQExpBuffer(&buf, "\n TO %s", - PQgetvalue(result, i, 2)); - } + if (!PQgetisnull(result, i, 2)) + { + appendPQExpBuffer(&buf, "\n TO %s", + PQgetvalue(result, i, 2)); + } - if (!PQgetisnull(result, i, 3)) - appendPQExpBuffer(&buf, "\n USING (%s)", - PQgetvalue(result, i, 3)); + if (!PQgetisnull(result, i, 3)) + appendPQExpBuffer(&buf, "\n USING (%s)", + PQgetvalue(result, i, 3)); - if (!PQgetisnull(result, i, 4)) - appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", - PQgetvalue(result, i, 4)); + if (!PQgetisnull(result, i, 4)) + appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", + PQgetvalue(result, i, 4)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* print any extended statistics */ if (pset.sversion >= 140000) @@ -3025,115 +3024,115 @@ describeOneTableDetails(const char *schemaname, } /* print any publications */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get publications that publish this table")); - if (pset.sversion >= 150000) + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get publications that publish this table")); + if (pset.sversion >= 150000) + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" + " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" + "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" + "UNION\n" + "SELECT pubname\n" + " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" + " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" + " (SELECT pg_catalog.string_agg(attname, ', ')\n" + " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" + " pg_catalog.pg_attribute\n" + " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" + " ELSE NULL END) " + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" + "WHERE pr.prrelid = '%s'\n", + oid, oid, oid); + + if (pset.sversion >= 190000) { + /* + * Skip entries where this relation appears in the + * publication's EXCEPT list. + */ appendPQExpBuffer(&buf, + " AND NOT pr.prexcept\n" + "UNION\n" "SELECT pubname\n" " , NULL\n" " , NULL\n" "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" - " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" - "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" - "UNION\n" - "SELECT pubname\n" - " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" - " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" - " (SELECT pg_catalog.string_agg(attname, ', ')\n" - " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" - " pg_catalog.pg_attribute\n" - " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" - " ELSE NULL END) " - "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" - "WHERE pr.prrelid = '%s'\n", + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + " AND NOT EXISTS (\n" + " SELECT 1\n" + " FROM pg_catalog.pg_publication_rel pr\n" + " WHERE pr.prpubid = p.oid AND\n" + " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" + "ORDER BY 1;", oid, oid, oid); - - if (pset.sversion >= 190000) - { - /* - * Skip entries where this relation appears in the - * publication's EXCEPT list. - */ - appendPQExpBuffer(&buf, - " AND NOT pr.prexcept\n" - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - " AND NOT EXISTS (\n" - " SELECT 1\n" - " FROM pg_catalog.pg_publication_rel pr\n" - " WHERE pr.prpubid = p.oid AND\n" - " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" - "ORDER BY 1;", - oid, oid, oid); - } - else - { - appendPQExpBuffer(&buf, - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - "ORDER BY 1;", - oid); - } } else { appendPQExpBuffer(&buf, + "UNION\n" "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - "WHERE pr.prrelid = '%s'\n" - "UNION ALL\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" + " , NULL\n" + " , NULL\n" "FROM pg_catalog.pg_publication p\n" "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" "ORDER BY 1;", - oid, oid); + oid); } + } + else + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + "WHERE pr.prrelid = '%s'\n" + "UNION ALL\n" + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + "ORDER BY 1;", + oid, oid); + } - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - if (tuples > 0) - printTableAddFooter(&cont, _("Included in publications:")); + if (tuples > 0) + printTableAddFooter(&cont, _("Included in publications:")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " \"%s\"", + PQgetvalue(result, i, 0)); - /* column list (if any) */ - if (!PQgetisnull(result, i, 2)) - appendPQExpBuffer(&buf, " (%s)", - PQgetvalue(result, i, 2)); + /* column list (if any) */ + if (!PQgetisnull(result, i, 2)) + appendPQExpBuffer(&buf, " (%s)", + PQgetvalue(result, i, 2)); - /* row filter (if any) */ - if (!PQgetisnull(result, i, 1)) - appendPQExpBuffer(&buf, " WHERE %s", - PQgetvalue(result, i, 1)); + /* row filter (if any) */ + if (!PQgetisnull(result, i, 1)) + appendPQExpBuffer(&buf, " WHERE %s", + PQgetvalue(result, i, 1)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* Print publications where the table is in the EXCEPT clause */ if (pset.sversion >= 190000) @@ -3805,7 +3804,7 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) ncols++; } appendPQExpBufferStr(&buf, "\n, r.rolreplication"); - appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); + appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_roles r\n"); @@ -3860,8 +3859,8 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) if (strcmp(PQgetvalue(res, i, (verbose ? 9 : 8)), "t") == 0) add_role_attribute(&buf, _("Replication")); - if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) - add_role_attribute(&buf, _("Bypass RLS")); + if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) + add_role_attribute(&buf, _("Bypass RLS")); conns = atoi(PQgetvalue(res, i, 6)); if (conns >= 0) @@ -5155,14 +5154,14 @@ listCollations(const char *pattern, bool verbose, bool showSystem) gettext_noop("Schema"), gettext_noop("Name")); - appendPQExpBuffer(&buf, - " CASE c.collprovider " - "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " - "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " - "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " - "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " - "END AS \"%s\",\n", - gettext_noop("Provider")); + appendPQExpBuffer(&buf, + " CASE c.collprovider " + "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " + "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " + "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " + "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " + "END AS \"%s\",\n", + gettext_noop("Provider")); appendPQExpBuffer(&buf, " c.collcollate AS \"%s\",\n" -- 2.50.1 (Apple Git-155) --aHl3HfeiUuO3zeNC-- ^ permalink raw reply [nested|flat] 59+ messages in thread
* [PATCH v6 4/4] run pgindent and pgperltidy @ 2026-06-30 18:24 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 59+ messages in thread From: Nathan Bossart @ 2026-06-30 18:24 UTC (permalink / raw) --- src/bin/pg_dump/pg_dump.c | 464 ++++++++++----------- src/bin/pg_dump/pg_dumpall.c | 30 +- src/bin/pg_upgrade/check.c | 16 +- src/bin/pg_upgrade/controldata.c | 2 +- src/bin/pg_upgrade/exec.c | 8 +- src/bin/pg_upgrade/multixact_rewrite.c | 80 ++-- src/bin/pg_upgrade/pg_upgrade.c | 34 +- src/bin/pg_upgrade/relfilenumber.c | 54 +-- src/bin/pg_upgrade/t/006_transfer_modes.pl | 33 +- src/bin/psql/command.c | 29 +- src/bin/psql/describe.c | 461 ++++++++++---------- 11 files changed, 601 insertions(+), 610 deletions(-) diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 65bd15ebfd2..5673268b467 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -1491,8 +1491,8 @@ setup_connection(Archive *AH, const char *dumpencoding, * Disable timeouts if supported. */ ExecuteSqlStatement(AH, "SET statement_timeout = 0"); - ExecuteSqlStatement(AH, "SET lock_timeout = 0"); - ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); + ExecuteSqlStatement(AH, "SET lock_timeout = 0"); + ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); if (AH->remoteVersion >= 170000) ExecuteSqlStatement(AH, "SET transaction_timeout = 0"); @@ -1505,10 +1505,10 @@ setup_connection(Archive *AH, const char *dumpencoding, /* * Adjust row-security mode, if supported. */ - if (dopt->enable_row_security) - ExecuteSqlStatement(AH, "SET row_security = on"); - else - ExecuteSqlStatement(AH, "SET row_security = off"); + if (dopt->enable_row_security) + ExecuteSqlStatement(AH, "SET row_security = on"); + else + ExecuteSqlStatement(AH, "SET row_security = off"); /* * For security reasons, we restrict the expansion of non-system views and @@ -1933,10 +1933,9 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) addObjectDependency(dobj, ext->dobj.dumpId); /* - * Mark the member object to have any non-initial ACLs - * dumped. (Any initial ACLs will be removed later, using data from - * pg_init_privs, so that we'll dump only the delta from the extension's - * initial setup.) + * Mark the member object to have any non-initial ACLs dumped. (Any + * initial ACLs will be removed later, using data from pg_init_privs, so + * that we'll dump only the delta from the extension's initial setup.) * * In binary upgrades, we still dump all components of the members * individually, since the idea is to exactly reproduce the database @@ -1953,7 +1952,7 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) if (fout->dopt->binary_upgrade) dobj->dump = ext->dobj.dump; else - dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); + dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); return true; } @@ -1987,9 +1986,9 @@ selectDumpableNamespace(NamespaceInfo *nsinfo, Archive *fout) else if (strcmp(nsinfo->dobj.name, "pg_catalog") == 0) { /* - * We dump out any ACLs defined in pg_catalog, if - * they are interesting (and not the original ACLs which were set at - * initdb time, see pg_init_privs). + * We dump out any ACLs defined in pg_catalog, if they are interesting + * (and not the original ACLs which were set at initdb time, see + * pg_init_privs). */ nsinfo->dobj.dump_contains = nsinfo->dobj.dump = DUMP_COMPONENT_ACL; } @@ -3296,7 +3295,7 @@ dumpDatabase(Archive *fout) "datcollate, datctype, datfrozenxid, " "datacl, acldefault('d', datdba) AS acldefault, " "datistemplate, datconnlimit, "); - appendPQExpBufferStr(dbQry, "datminmxid, "); + appendPQExpBufferStr(dbQry, "datminmxid, "); if (fout->remoteVersion >= 170000) appendPQExpBufferStr(dbQry, "datlocprovider, datlocale, datcollversion, "); else if (fout->remoteVersion >= 150000) @@ -3638,11 +3637,11 @@ dumpDatabase(Archive *fout) ii_oid, ii_relminmxid; - appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" - "FROM pg_catalog.pg_class\n" - "WHERE oid IN (%u, %u, %u, %u);\n", - LargeObjectRelationId, LargeObjectLOidPNIndexId, - LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); + appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" + "FROM pg_catalog.pg_class\n" + "WHERE oid IN (%u, %u, %u, %u);\n", + LargeObjectRelationId, LargeObjectLOidPNIndexId, + LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); lo_res = ExecuteSqlQuery(fout, loFrozenQry->data, PGRES_TUPLES_OK); @@ -4274,7 +4273,7 @@ getPolicies(Archive *fout, TableInfo tblinfo[], int numTables) printfPQExpBuffer(query, "SELECT pol.oid, pol.tableoid, pol.polrelid, pol.polname, pol.polcmd, "); - appendPQExpBufferStr(query, "pol.polpermissive, "); + appendPQExpBufferStr(query, "pol.polpermissive, "); appendPQExpBuffer(query, "CASE WHEN pol.polroles = '{0}' THEN NULL ELSE " " pg_catalog.array_to_string(ARRAY(SELECT pg_catalog.quote_ident(rolname) from pg_catalog.pg_roles WHERE oid = ANY(pol.polroles)), ', ') END AS polroles, " @@ -6633,9 +6632,9 @@ getAccessMethods(Archive *fout) * Select all access methods from pg_am table. */ appendPQExpBufferStr(query, "SELECT tableoid, oid, amname, "); - appendPQExpBufferStr(query, - "amtype, " - "amhandler::pg_catalog.regproc AS amhandler "); + appendPQExpBufferStr(query, + "amtype, " + "amhandler::pg_catalog.regproc AS amhandler "); appendPQExpBufferStr(query, "FROM pg_am"); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6827,35 +6826,35 @@ getAggregates(Archive *fout) * Find all interesting aggregates. See comment in getFuncs() for the * rationale behind the filtering logic. */ - agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" - : "p.proisagg"); + agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" + : "p.proisagg"); - appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " - "p.proname AS aggname, " - "p.pronamespace AS aggnamespace, " - "p.pronargs, p.proargtypes, " - "p.proowner, " - "p.proacl AS aggacl, " - "acldefault('f', p.proowner) AS acldefault " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s AND (" - "p.pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog') OR " - "p.proacl IS DISTINCT FROM pip.initprivs", - agg_check); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - " OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); - appendPQExpBufferChar(query, ')'); + appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " + "p.proname AS aggname, " + "p.pronamespace AS aggnamespace, " + "p.pronargs, p.proargtypes, " + "p.proowner, " + "p.proacl AS aggacl, " + "acldefault('f', p.proowner) AS acldefault " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s AND (" + "p.pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog') OR " + "p.proacl IS DISTINCT FROM pip.initprivs", + agg_check); + if (dopt->binary_upgrade) + appendPQExpBufferStr(query, + " OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6957,53 +6956,53 @@ getFuncs(Archive *fout) * include them, since we want to dump extension members individually in * that mode. Also, if they are used by casts or transforms then we need * to gather the information about them, though they won't be dumped if - * they are built-in. Also, include functions in - * pg_catalog if they have an ACL different from what's shown in - * pg_init_privs (so we have to join to pg_init_privs; annoying). + * they are built-in. Also, include functions in pg_catalog if they have + * an ACL different from what's shown in pg_init_privs (so we have to join + * to pg_init_privs; annoying). */ - not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" - : "NOT p.proisagg"); + not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" + : "NOT p.proisagg"); - appendPQExpBuffer(query, - "SELECT p.tableoid, p.oid, p.proname, p.prolang, " - "p.pronargs, p.proargtypes, p.prorettype, " - "p.proacl, " - "acldefault('f', p.proowner) AS acldefault, " - "p.pronamespace, " - "p.proowner " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s" - "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " - "WHERE classid = 'pg_proc'::regclass AND " - "objid = p.oid AND deptype = 'i')" - "\n AND (" - "\n pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog')" - "\n OR EXISTS (SELECT 1 FROM pg_cast" - "\n WHERE pg_cast.oid > %u " - "\n AND p.oid = pg_cast.castfunc)" - "\n OR EXISTS (SELECT 1 FROM pg_transform" - "\n WHERE pg_transform.oid > %u AND " - "\n (p.oid = pg_transform.trffromsql" - "\n OR p.oid = pg_transform.trftosql))", - not_agg_check, - g_last_builtin_oid, - g_last_builtin_oid); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); + appendPQExpBuffer(query, + "SELECT p.tableoid, p.oid, p.proname, p.prolang, " + "p.pronargs, p.proargtypes, p.prorettype, " + "p.proacl, " + "acldefault('f', p.proowner) AS acldefault, " + "p.pronamespace, " + "p.proowner " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s" + "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " + "WHERE classid = 'pg_proc'::regclass AND " + "objid = p.oid AND deptype = 'i')" + "\n AND (" + "\n pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog')" + "\n OR EXISTS (SELECT 1 FROM pg_cast" + "\n WHERE pg_cast.oid > %u " + "\n AND p.oid = pg_cast.castfunc)" + "\n OR EXISTS (SELECT 1 FROM pg_transform" + "\n WHERE pg_transform.oid > %u AND " + "\n (p.oid = pg_transform.trffromsql" + "\n OR p.oid = pg_transform.trftosql))", + not_agg_check, + g_last_builtin_oid, + g_last_builtin_oid); + if (dopt->binary_upgrade) appendPQExpBufferStr(query, - "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); - appendPQExpBufferChar(query, ')'); + "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferStr(query, + "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -7252,31 +7251,31 @@ getTables(Archive *fout, int *numTables) appendPQExpBufferStr(query, "c.relhasoids, "); - appendPQExpBufferStr(query, - "c.relispopulated, "); + appendPQExpBufferStr(query, + "c.relispopulated, "); - appendPQExpBufferStr(query, - "c.relreplident, "); + appendPQExpBufferStr(query, + "c.relreplident, "); - appendPQExpBufferStr(query, - "c.relrowsecurity, c.relforcerowsecurity, "); + appendPQExpBufferStr(query, + "c.relrowsecurity, c.relforcerowsecurity, "); - appendPQExpBufferStr(query, - "c.relminmxid, tc.relminmxid AS tminmxid, "); + appendPQExpBufferStr(query, + "c.relminmxid, tc.relminmxid AS tminmxid, "); - appendPQExpBufferStr(query, - "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); + appendPQExpBufferStr(query, + "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); - appendPQExpBufferStr(query, - "am.amname, "); + appendPQExpBufferStr(query, + "am.amname, "); - appendPQExpBufferStr(query, - "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); + appendPQExpBufferStr(query, + "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); - appendPQExpBufferStr(query, - "c.relispartition AS ispartition "); + appendPQExpBufferStr(query, + "c.relispartition AS ispartition "); /* * Left join to pg_depend to pick up dependency info linking sequences to @@ -7296,8 +7295,8 @@ getTables(Archive *fout, int *numTables) /* * Left join to pg_am to pick up the amname. */ - appendPQExpBufferStr(query, - "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); + appendPQExpBufferStr(query, + "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); /* * We purposefully ignore toast OIDs for partitioned tables; the reason is @@ -7868,8 +7867,8 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables) "t.reloptions AS indreloptions, "); - appendPQExpBufferStr(query, - "i.indisreplident, "); + appendPQExpBufferStr(query, + "i.indisreplident, "); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -9313,8 +9312,8 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables) appendPQExpBufferStr(q, "'' AS attcompression,\n"); - appendPQExpBufferStr(q, - "a.attidentity,\n"); + appendPQExpBufferStr(q, + "a.attidentity,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(q, @@ -10717,73 +10716,73 @@ getAdditionalACLs(Archive *fout) PQclear(res); /* Fetch initial-privileges data */ - printfPQExpBuffer(query, - "SELECT objoid, classoid, objsubid, privtype, initprivs " - "FROM pg_init_privs"); + printfPQExpBuffer(query, + "SELECT objoid, classoid, objsubid, privtype, initprivs " + "FROM pg_init_privs"); - res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); + res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); - ntups = PQntuples(res); - for (i = 0; i < ntups; i++) - { - Oid objoid = atooid(PQgetvalue(res, i, 0)); - Oid classoid = atooid(PQgetvalue(res, i, 1)); - int objsubid = atoi(PQgetvalue(res, i, 2)); - char privtype = *(PQgetvalue(res, i, 3)); - char *initprivs = PQgetvalue(res, i, 4); - CatalogId objId; - DumpableObject *dobj; + ntups = PQntuples(res); + for (i = 0; i < ntups; i++) + { + Oid objoid = atooid(PQgetvalue(res, i, 0)); + Oid classoid = atooid(PQgetvalue(res, i, 1)); + int objsubid = atoi(PQgetvalue(res, i, 2)); + char privtype = *(PQgetvalue(res, i, 3)); + char *initprivs = PQgetvalue(res, i, 4); + CatalogId objId; + DumpableObject *dobj; - objId.tableoid = classoid; - objId.oid = objoid; - dobj = findObjectByCatalogId(objId); - /* OK to ignore entries we haven't got a DumpableObject for */ - if (dobj) + objId.tableoid = classoid; + objId.oid = objoid; + dobj = findObjectByCatalogId(objId); + /* OK to ignore entries we haven't got a DumpableObject for */ + if (dobj) + { + /* Cope with sub-object initprivs */ + if (objsubid != 0) { - /* Cope with sub-object initprivs */ - if (objsubid != 0) - { - if (dobj->objType == DO_TABLE) - { - /* For a column initprivs, set the table's ACL flags */ - dobj->components |= DUMP_COMPONENT_ACL; - ((TableInfo *) dobj)->hascolumnACLs = true; - } - else - pg_log_warning("unsupported pg_init_privs entry: %u %u %d", - classoid, objoid, objsubid); - continue; - } - - /* - * We ignore any pg_init_privs.initprivs entry for the public - * schema, as explained in getNamespaces(). - */ - if (dobj->objType == DO_NAMESPACE && - strcmp(dobj->name, "public") == 0) - continue; - - /* Else it had better be of a type we think has ACLs */ - if (dobj->objType == DO_NAMESPACE || - dobj->objType == DO_TYPE || - dobj->objType == DO_FUNC || - dobj->objType == DO_AGG || - dobj->objType == DO_TABLE || - dobj->objType == DO_PROCLANG || - dobj->objType == DO_FDW || - dobj->objType == DO_FOREIGN_SERVER) + if (dobj->objType == DO_TABLE) { - DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; - - daobj->dacl.privtype = privtype; - daobj->dacl.initprivs = pstrdup(initprivs); + /* For a column initprivs, set the table's ACL flags */ + dobj->components |= DUMP_COMPONENT_ACL; + ((TableInfo *) dobj)->hascolumnACLs = true; } else pg_log_warning("unsupported pg_init_privs entry: %u %u %d", classoid, objoid, objsubid); + continue; + } + + /* + * We ignore any pg_init_privs.initprivs entry for the public + * schema, as explained in getNamespaces(). + */ + if (dobj->objType == DO_NAMESPACE && + strcmp(dobj->name, "public") == 0) + continue; + + /* Else it had better be of a type we think has ACLs */ + if (dobj->objType == DO_NAMESPACE || + dobj->objType == DO_TYPE || + dobj->objType == DO_FUNC || + dobj->objType == DO_AGG || + dobj->objType == DO_TABLE || + dobj->objType == DO_PROCLANG || + dobj->objType == DO_FDW || + dobj->objType == DO_FOREIGN_SERVER) + { + DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; + + daobj->dacl.privtype = privtype; + daobj->dacl.initprivs = pstrdup(initprivs); } + else + pg_log_warning("unsupported pg_init_privs entry: %u %u %d", + classoid, objoid, objsubid); } - PQclear(res); + } + PQclear(res); destroyPQExpBuffer(query); } @@ -11128,8 +11127,8 @@ dumpRelationStats_dumper(Archive *fout, const void *userArg, const TocEntry *te) * The results must be in the order of the relations supplied in the * parameters to ensure we remain in sync as we walk through the TOC. * - * For versions before 19, the redundant filter clause on s.tablename = - * ANY(...) seems sufficient to convince the planner to use + * For versions before 19, the redundant filter clause on s.tablename + * = ANY(...) seems sufficient to convince the planner to use * pg_class_relname_nsp_index, which avoids a full scan of pg_stats. * In newer versions, pg_stats returns the table OIDs, eliminating the * need for that hack. @@ -13469,11 +13468,11 @@ dumpFunc(Archive *fout, const FuncInfo *finfo) "pg_catalog.pg_get_function_result(p.oid) AS funcresult,\n" "proleakproof,\n"); - appendPQExpBufferStr(query, - "array_to_string(protrftypes, ' ') AS protrftypes,\n"); + appendPQExpBufferStr(query, + "array_to_string(protrftypes, ' ') AS protrftypes,\n"); - appendPQExpBufferStr(query, - "proparallel,\n"); + appendPQExpBufferStr(query, + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -14963,9 +14962,9 @@ dumpCollation(Archive *fout, const CollInfo *collinfo) /* Get collation-specific details */ appendPQExpBufferStr(query, "SELECT "); - appendPQExpBufferStr(query, - "collprovider, " - "collversion, "); + appendPQExpBufferStr(query, + "collprovider, " + "collversion, "); if (fout->remoteVersion >= 120000) appendPQExpBufferStr(query, @@ -15372,23 +15371,23 @@ dumpAgg(Archive *fout, const AggInfo *agginfo) "pg_catalog.pg_get_function_arguments(p.oid) AS funcargs,\n" "pg_catalog.pg_get_function_identity_arguments(p.oid) AS funciargs,\n"); - appendPQExpBufferStr(query, - "aggkind,\n" - "aggmtransfn,\n" - "aggminvtransfn,\n" - "aggmfinalfn,\n" - "aggmtranstype::pg_catalog.regtype,\n" - "aggfinalextra,\n" - "aggmfinalextra,\n" - "aggtransspace,\n" - "aggmtransspace,\n" - "aggminitval,\n"); + appendPQExpBufferStr(query, + "aggkind,\n" + "aggmtransfn,\n" + "aggminvtransfn,\n" + "aggmfinalfn,\n" + "aggmtranstype::pg_catalog.regtype,\n" + "aggfinalextra,\n" + "aggmfinalextra,\n" + "aggtransspace,\n" + "aggmtransspace,\n" + "aggminitval,\n"); - appendPQExpBufferStr(query, - "aggcombinefn,\n" - "aggserialfn,\n" - "aggdeserialfn,\n" - "proparallel,\n"); + appendPQExpBufferStr(query, + "aggcombinefn,\n" + "aggserialfn,\n" + "aggdeserialfn,\n" + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -16848,30 +16847,30 @@ dumpTable(Archive *fout, const TableInfo *tbinfo) appendPQExpBufferStr(query, "PREPARE getColumnACLs(pg_catalog.oid) AS\n"); - /* - * In principle we should call acldefault('c', relowner) to - * get the default ACL for a column. However, we don't - * currently store the numeric OID of the relowner in - * TableInfo. We could convert the owner name using regrole, - * but that creates a risk of failure due to concurrent role - * renames. Given that the default ACL for columns is empty - * and is likely to stay that way, it's not worth extra cycles - * and risk to avoid hard-wiring that knowledge here. - */ - appendPQExpBufferStr(query, - "SELECT at.attname, " - "at.attacl, " - "'{}' AS acldefault, " - "pip.privtype, pip.initprivs " - "FROM pg_catalog.pg_attribute at " - "LEFT JOIN pg_catalog.pg_init_privs pip ON " - "(at.attrelid = pip.objoid " - "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " - "AND at.attnum = pip.objsubid) " - "WHERE at.attrelid = $1 AND " - "NOT at.attisdropped " - "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " - "ORDER BY at.attnum"); + /* + * In principle we should call acldefault('c', relowner) to get + * the default ACL for a column. However, we don't currently + * store the numeric OID of the relowner in TableInfo. We could + * convert the owner name using regrole, but that creates a risk + * of failure due to concurrent role renames. Given that the + * default ACL for columns is empty and is likely to stay that + * way, it's not worth extra cycles and risk to avoid hard-wiring + * that knowledge here. + */ + appendPQExpBufferStr(query, + "SELECT at.attname, " + "at.attacl, " + "'{}' AS acldefault, " + "pip.privtype, pip.initprivs " + "FROM pg_catalog.pg_attribute at " + "LEFT JOIN pg_catalog.pg_init_privs pip ON " + "(at.attrelid = pip.objoid " + "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " + "AND at.attnum = pip.objsubid) " + "WHERE at.attrelid = $1 AND " + "NOT at.attisdropped " + "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " + "ORDER BY at.attnum"); ExecuteSqlStatement(fout, query->data); @@ -19165,7 +19164,7 @@ collectSequences(Archive *fout) * pg_get_sequence_data(), but we only do so for non-schema-only dumps. */ if (fout->remoteVersion < 180000 || - (!fout->dopt->dumpData && !fout->dopt->sequence_data)) + (!fout->dopt->dumpData && !fout->dopt->sequence_data)) query = "SELECT seqrelid, format_type(seqtypid, NULL), " "seqstart, seqincrement, " "seqmax, seqmin, " @@ -19227,15 +19226,14 @@ dumpSequence(Archive *fout, const TableInfo *tbinfo) qseqname = pg_strdup(fmtId(tbinfo->dobj.name)); /* - * The sequence information is gathered in a sorted - * table before any calls to dumpSequence(). See collectSequences() for - * more information. + * The sequence information is gathered in a sorted table before any calls + * to dumpSequence(). See collectSequences() for more information. */ - Assert(sequences); + Assert(sequences); - key.oid = tbinfo->dobj.catId.oid; - seq = bsearch(&key, sequences, nsequences, - sizeof(SequenceItem), SequenceItemCmp); + key.oid = tbinfo->dobj.catId.oid; + seq = bsearch(&key, sequences, nsequences, + sizeof(SequenceItem), SequenceItemCmp); /* Calculate default limits for a sequence of this type */ is_ascending = (seq->incby >= 0); diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c index e68937c9934..afcd9a218d8 100644 --- a/src/bin/pg_dump/pg_dumpall.c +++ b/src/bin/pg_dump/pg_dumpall.c @@ -785,11 +785,11 @@ dropRoles(PGconn *conn) int i_rolname; int i; - printfPQExpBuffer(buf, - "SELECT rolname " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 1", role_catalog); + printfPQExpBuffer(buf, + "SELECT rolname " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 1", role_catalog); res = executeQuery(conn, buf->data); @@ -843,16 +843,16 @@ dumpRoles(PGconn *conn) * Notes: rolconfig is dumped later, and pg_authid must be used for * extracting rolcomment regardless of role_catalog. */ - printfPQExpBuffer(buf, - "SELECT oid, rolname, rolsuper, rolinherit, " - "rolcreaterole, rolcreatedb, " - "rolcanlogin, rolconnlimit, rolpassword, " - "rolvaliduntil, rolreplication, rolbypassrls, " - "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " - "rolname = current_user AS is_current_user " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 2", role_catalog); + printfPQExpBuffer(buf, + "SELECT oid, rolname, rolsuper, rolinherit, " + "rolcreaterole, rolcreatedb, " + "rolcanlogin, rolconnlimit, rolpassword, " + "rolvaliduntil, rolreplication, rolbypassrls, " + "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " + "rolname = current_user AS is_current_user " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 2", role_catalog); res = executeQuery(conn, buf->data); diff --git a/src/bin/pg_upgrade/check.c b/src/bin/pg_upgrade/check.c index 786c1474829..f725f5ee3e2 100644 --- a/src/bin/pg_upgrade/check.c +++ b/src/bin/pg_upgrade/check.c @@ -1475,15 +1475,15 @@ check_for_incompatible_polymorphics(ClusterInfo *cluster) ", 'array_cat(anyarray,anyarray)'" ", 'array_prepend(anyelement,anyarray)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_remove(anyarray,anyelement)'" - ", 'array_replace(anyarray,anyelement,anyelement)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_remove(anyarray,anyelement)'" + ", 'array_replace(anyarray,anyelement,anyelement)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_position(anyarray,anyelement)'" - ", 'array_position(anyarray,anyelement,integer)'" - ", 'array_positions(anyarray,anyelement)'" - ", 'width_bucket(anyelement,anyarray)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_position(anyarray,anyelement)'" + ", 'array_position(anyarray,anyelement,integer)'" + ", 'array_positions(anyarray,anyelement)'" + ", 'width_bucket(anyelement,anyarray)'"); /* * The query below hardcodes FirstNormalObjectId as 16384 rather than diff --git a/src/bin/pg_upgrade/controldata.c b/src/bin/pg_upgrade/controldata.c index 8f81c9e9582..02ea02df60f 100644 --- a/src/bin/pg_upgrade/controldata.c +++ b/src/bin/pg_upgrade/controldata.c @@ -228,7 +228,7 @@ get_control_data(ClusterInfo *cluster) p++; /* remove ':' char */ cluster->controldata.chkpnt_nxtepoch = str2uint(p); - p = strchr(p, ':'); + p = strchr(p, ':'); if (p == NULL || strlen(p) <= 1) pg_fatal("%d: controldata retrieval problem", __LINE__); diff --git a/src/bin/pg_upgrade/exec.c b/src/bin/pg_upgrade/exec.c index 44355feea30..a1bdbf373e3 100644 --- a/src/bin/pg_upgrade/exec.c +++ b/src/bin/pg_upgrade/exec.c @@ -55,7 +55,7 @@ get_bin_version(ClusterInfo *cluster) if (sscanf(cmd_output, "%*s %*s %d.%d", &v1, &v2) < 1) pg_fatal("could not get pg_ctl version output from %s", cmd); - cluster->bin_version = v1 * 10000; + cluster->bin_version = v1 * 10000; } @@ -344,8 +344,8 @@ check_data_dir(ClusterInfo *cluster) check_single_dir(pg_data, "pg_subtrans"); check_single_dir(pg_data, PG_TBLSPC_DIR); check_single_dir(pg_data, "pg_twophase"); - check_single_dir(pg_data, "pg_wal"); - check_single_dir(pg_data, "pg_xact"); + check_single_dir(pg_data, "pg_wal"); + check_single_dir(pg_data, "pg_xact"); } @@ -385,7 +385,7 @@ check_bin_dir(ClusterInfo *cluster, bool check_versions) */ get_bin_version(cluster); - check_exec(cluster->bindir, "pg_resetwal", check_versions); + check_exec(cluster->bindir, "pg_resetwal", check_versions); if (cluster == &new_cluster) { diff --git a/src/bin/pg_upgrade/multixact_rewrite.c b/src/bin/pg_upgrade/multixact_rewrite.c index c45b3183684..c7a1416494d 100644 --- a/src/bin/pg_upgrade/multixact_rewrite.c +++ b/src/bin/pg_upgrade/multixact_rewrite.c @@ -61,52 +61,52 @@ rewrite_multixacts(MultiXactId from_multi, MultiXactId to_multi) * Convert old multixids, if needed, by reading them one-by-one from the * old cluster. */ - old_reader = AllocOldMultiXactRead(old_cluster.pgdata, - old_cluster.controldata.chkpnt_nxtmulti, - old_cluster.controldata.chkpnt_nxtmxoff); + old_reader = AllocOldMultiXactRead(old_cluster.pgdata, + old_cluster.controldata.chkpnt_nxtmulti, + old_cluster.controldata.chkpnt_nxtmxoff); - for (MultiXactId multi = from_multi; multi != to_multi;) - { - MultiXactMember member; - bool multixid_valid; - - /* - * Read this multixid's members. - * - * Locking-only XIDs that may be part of multi-xids don't matter - * after upgrade, as there can be no transactions running across - * upgrade. So as a small optimization, we only read one member - * from each multixid: the one updating one, or if there was no - * update, arbitrarily the first locking xid. - */ - multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); + for (MultiXactId multi = from_multi; multi != to_multi;) + { + MultiXactMember member; + bool multixid_valid; - /* - * Write the new offset to pg_multixact/offsets. - * - * Even if this multixid is invalid, we still need to write its - * offset if the *previous* multixid was valid. That's because - * when reading a multixid, the number of members is calculated - * from the difference between the two offsets. - */ - RecordMultiXactOffset(offsets_writer, multi, - (multixid_valid || prev_multixid_valid) ? next_offset : 0); + /* + * Read this multixid's members. + * + * Locking-only XIDs that may be part of multi-xids don't matter after + * upgrade, as there can be no transactions running across upgrade. So + * as a small optimization, we only read one member from each + * multixid: the one updating one, or if there was no update, + * arbitrarily the first locking xid. + */ + multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); - /* Write the members */ - if (multixid_valid) - { - RecordMultiXactMembers(members_writer, next_offset, 1, &member); - next_offset += 1; - } + /* + * Write the new offset to pg_multixact/offsets. + * + * Even if this multixid is invalid, we still need to write its offset + * if the *previous* multixid was valid. That's because when reading + * a multixid, the number of members is calculated from the difference + * between the two offsets. + */ + RecordMultiXactOffset(offsets_writer, multi, + (multixid_valid || prev_multixid_valid) ? next_offset : 0); - /* Advance to next multixid, handling wraparound */ - multi++; - if (multi < FirstMultiXactId) - multi = FirstMultiXactId; - prev_multixid_valid = multixid_valid; + /* Write the members */ + if (multixid_valid) + { + RecordMultiXactMembers(members_writer, next_offset, 1, &member); + next_offset += 1; } - FreeOldMultiXactReader(old_reader); + /* Advance to next multixid, handling wraparound */ + multi++; + if (multi < FirstMultiXactId) + multi = FirstMultiXactId; + prev_multixid_valid = multixid_valid; + } + + FreeOldMultiXactReader(old_reader); /* Write the final 'next' offset to the last SLRU page */ RecordMultiXactOffset(offsets_writer, to_multi, diff --git a/src/bin/pg_upgrade/pg_upgrade.c b/src/bin/pg_upgrade/pg_upgrade.c index c6af9035665..7366fd4627c 100644 --- a/src/bin/pg_upgrade/pg_upgrade.c +++ b/src/bin/pg_upgrade/pg_upgrade.c @@ -833,7 +833,7 @@ copy_xact_xlog_xid(void) * Determine the range of multixacts to convert. */ nxtmulti = old_cluster.controldata.chkpnt_nxtmulti; - oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; + oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; /* handle wraparound */ if (nxtmulti < FirstMultiXactId) nxtmulti = FirstMultiXactId; @@ -898,15 +898,15 @@ set_frozenxids(void) int i_datname; int i_datallowconn; - prep_status("Setting frozenxid and minmxid counters in new cluster"); + prep_status("Setting frozenxid and minmxid counters in new cluster"); conn_template1 = connectToServer(&new_cluster, "template1"); - /* set pg_database.datfrozenxid */ - PQclear(executeQueryOrDie(conn_template1, - "UPDATE pg_catalog.pg_database " - "SET datfrozenxid = '%u'", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_database.datfrozenxid */ + PQclear(executeQueryOrDie(conn_template1, + "UPDATE pg_catalog.pg_database " + "SET datfrozenxid = '%u'", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_database.datminmxid */ PQclear(executeQueryOrDie(conn_template1, @@ -942,16 +942,16 @@ set_frozenxids(void) conn = connectToServer(&new_cluster, datname); - /* set pg_class.relfrozenxid */ - PQclear(executeQueryOrDie(conn, - "UPDATE pg_catalog.pg_class " - "SET relfrozenxid = '%u' " - /* only heap, materialized view, and TOAST are vacuumed */ - "WHERE relkind IN (" - CppAsString2(RELKIND_RELATION) ", " - CppAsString2(RELKIND_MATVIEW) ", " - CppAsString2(RELKIND_TOASTVALUE) ")", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_class.relfrozenxid */ + PQclear(executeQueryOrDie(conn, + "UPDATE pg_catalog.pg_class " + "SET relfrozenxid = '%u' " + /* only heap, materialized view, and TOAST are vacuumed */ + "WHERE relkind IN (" + CppAsString2(RELKIND_RELATION) ", " + CppAsString2(RELKIND_MATVIEW) ", " + CppAsString2(RELKIND_TOASTVALUE) ")", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_class.relminmxid */ PQclear(executeQueryOrDie(conn, diff --git a/src/bin/pg_upgrade/relfilenumber.c b/src/bin/pg_upgrade/relfilenumber.c index ec2ff7acb21..6c467bdc8a5 100644 --- a/src/bin/pg_upgrade/relfilenumber.c +++ b/src/bin/pg_upgrade/relfilenumber.c @@ -587,32 +587,32 @@ transfer_relfile(FileNameMap *map, const char *type_suffix) /* Copying files might take some time, so give feedback. */ pg_log(PG_STATUS, "%s", old_file); - switch (user_opts.transfer_mode) - { - case TRANSFER_MODE_CLONE: - pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", - old_file, new_file); - cloneFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", - old_file, new_file); - copyFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY_FILE_RANGE: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", - old_file, new_file); - copyFileByRange(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_LINK: - pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", - old_file, new_file); - linkFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_SWAP: - /* swap mode is handled in its own code path */ - pg_fatal("should never happen"); - break; - } + switch (user_opts.transfer_mode) + { + case TRANSFER_MODE_CLONE: + pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", + old_file, new_file); + cloneFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", + old_file, new_file); + copyFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY_FILE_RANGE: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", + old_file, new_file); + copyFileByRange(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_LINK: + pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", + old_file, new_file); + linkFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_SWAP: + /* swap mode is handled in its own code path */ + pg_fatal("should never happen"); + break; + } } } diff --git a/src/bin/pg_upgrade/t/006_transfer_modes.pl b/src/bin/pg_upgrade/t/006_transfer_modes.pl index 9efa5dc863c..360d05c4b68 100644 --- a/src/bin/pg_upgrade/t/006_transfer_modes.pl +++ b/src/bin/pg_upgrade/t/006_transfer_modes.pl @@ -29,10 +29,8 @@ sub test_mode } $new->init(); - $new->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); - $old->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); + $new->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); + $old->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); # We can only test security labels if both the old and new installations # have dummy_seclabel. @@ -76,15 +74,14 @@ sub test_mode "CREATE TABLE test4 AS SELECT generate_series(400, 502)"); } - $old->safe_psql('postgres', - "CREATE TABLESPACE inplc_tblspc LOCATION ''"); - $old->safe_psql('postgres', - "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); - $old->safe_psql('postgres', - "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" - ); - $old->safe_psql('testdb3', - "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); + $old->safe_psql('postgres', "CREATE TABLESPACE inplc_tblspc LOCATION ''"); + $old->safe_psql('postgres', + "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); + $old->safe_psql('postgres', + "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" + ); + $old->safe_psql('testdb3', + "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); # While we are here, test handling of large objects. $old->safe_psql( @@ -152,12 +149,10 @@ sub test_mode } # Tests for in-place tablespaces. - $result = - $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); - is($result, '104', "test5 data after pg_upgrade $mode"); - $result = - $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); - is($result, '105', "test6 data after pg_upgrade $mode"); + $result = $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); + is($result, '104', "test5 data after pg_upgrade $mode"); + $result = $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); + is($result, '105', "test6 data after pg_upgrade $mode"); # Tests for large objects $result = $new->safe_psql('postgres', "SELECT lo_get(4532)"); diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index 44ef11d980e..c90bf8bbde2 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -6278,23 +6278,22 @@ get_create_object_cmd(EditableObjectType obj_type, Oid oid, * ensure the right view gets replaced. Also, check relation kind * to be sure it's a view. * - * Views may have WITH [LOCAL|CASCADED] - * CHECK OPTION. These are not part of the view definition - * returned by pg_get_viewdef() and so need to be retrieved - * separately. Materialized views may have - * arbitrary storage parameter reloptions. + * Views may have WITH [LOCAL|CASCADED] CHECK OPTION. These are + * not part of the view definition returned by pg_get_viewdef() + * and so need to be retrieved separately. Materialized views may + * have arbitrary storage parameter reloptions. */ printfPQExpBuffer(query, "/* %s */\n", _("Get view's definition and details")); - appendPQExpBuffer(query, - "SELECT nspname, relname, relkind, " - "pg_catalog.pg_get_viewdef(c.oid, true), " - "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " - "FROM pg_catalog.pg_class c " - "LEFT JOIN pg_catalog.pg_namespace n " - "ON c.relnamespace = n.oid WHERE c.oid = %u", - oid); + appendPQExpBuffer(query, + "SELECT nspname, relname, relkind, " + "pg_catalog.pg_get_viewdef(c.oid, true), " + "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " + "FROM pg_catalog.pg_class c " + "LEFT JOIN pg_catalog.pg_namespace n " + "ON c.relnamespace = n.oid WHERE c.oid = %u", + oid); break; } diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index ce99137c613..ac0c55e7aa5 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -387,19 +387,19 @@ describeFunctions(const char *functypes, const char *func_pattern, gettext_noop("stable"), gettext_noop("volatile"), gettext_noop("Volatility")); - appendPQExpBuffer(&buf, - ",\n CASE\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" - " END as \"%s\"", - gettext_noop("restricted"), - gettext_noop("safe"), - gettext_noop("unsafe"), - gettext_noop("Parallel")); + appendPQExpBuffer(&buf, + ",\n CASE\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" + " END as \"%s\"", + gettext_noop("restricted"), + gettext_noop("safe"), + gettext_noop("unsafe"), + gettext_noop("Parallel")); appendPQExpBuffer(&buf, ",\n pg_catalog.pg_get_userbyid(p.proowner) as \"%s\"" ",\n CASE WHEN prosecdef THEN '%s' ELSE '%s' END AS \"%s\"" @@ -599,8 +599,8 @@ describeFunctions(const char *functypes, const char *func_pattern, myopt.title = _("List of functions"); myopt.translate_header = true; - myopt.translate_columns = translate_columns; - myopt.n_translate_columns = lengthof(translate_columns); + myopt.translate_columns = translate_columns; + myopt.n_translate_columns = lengthof(translate_columns); printQuery(res, &myopt, pset.queryFout, false, pset.logfile); @@ -1086,38 +1086,38 @@ permissionsList(const char *pattern, bool showSystem) " ), E'\\n') AS \"%s\"", gettext_noop("Column privileges")); - appendPQExpBuffer(&buf, - ",\n pg_catalog.array_to_string(ARRAY(\n" - " SELECT polname\n" - " || CASE WHEN NOT polpermissive THEN\n" - " E' (RESTRICTIVE)'\n" - " ELSE '' END\n" - " || CASE WHEN polcmd != '*' THEN\n" - " E' (' || polcmd::pg_catalog.text || E'):'\n" - " ELSE E':'\n" - " END\n" - " || CASE WHEN polqual IS NOT NULL THEN\n" - " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" - " ELSE E''\n" - " END\n" - " || CASE WHEN polwithcheck IS NOT NULL THEN\n" - " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" - " ELSE E''\n" - " END" - " || CASE WHEN polroles <> '{0}' THEN\n" - " E'\\n to: ' || pg_catalog.array_to_string(\n" - " ARRAY(\n" - " SELECT rolname\n" - " FROM pg_catalog.pg_roles\n" - " WHERE oid = ANY (polroles)\n" - " ORDER BY 1\n" - " ), E', ')\n" - " ELSE E''\n" - " END\n" - " FROM pg_catalog.pg_policy pol\n" - " WHERE polrelid = c.oid), E'\\n')\n" - " AS \"%s\"", - gettext_noop("Policies")); + appendPQExpBuffer(&buf, + ",\n pg_catalog.array_to_string(ARRAY(\n" + " SELECT polname\n" + " || CASE WHEN NOT polpermissive THEN\n" + " E' (RESTRICTIVE)'\n" + " ELSE '' END\n" + " || CASE WHEN polcmd != '*' THEN\n" + " E' (' || polcmd::pg_catalog.text || E'):'\n" + " ELSE E':'\n" + " END\n" + " || CASE WHEN polqual IS NOT NULL THEN\n" + " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" + " ELSE E''\n" + " END\n" + " || CASE WHEN polwithcheck IS NOT NULL THEN\n" + " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" + " ELSE E''\n" + " END" + " || CASE WHEN polroles <> '{0}' THEN\n" + " E'\\n to: ' || pg_catalog.array_to_string(\n" + " ARRAY(\n" + " SELECT rolname\n" + " FROM pg_catalog.pg_roles\n" + " WHERE oid = ANY (polroles)\n" + " ORDER BY 1\n" + " ), E', ')\n" + " ELSE E''\n" + " END\n" + " FROM pg_catalog.pg_policy pol\n" + " WHERE polrelid = c.oid), E'\\n')\n" + " AS \"%s\"", + gettext_noop("Policies")); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_class c\n" " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n" @@ -1675,27 +1675,27 @@ describeOneTableDetails(const char *schemaname, char *footers[3] = {NULL, NULL, NULL}; printfPQExpBuffer(&buf, "/* %s */\n", _("Get sequence information")); - appendPQExpBuffer(&buf, - "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" - " seqstart AS \"%s\",\n" - " seqmin AS \"%s\",\n" - " seqmax AS \"%s\",\n" - " seqincrement AS \"%s\",\n" - " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" - " seqcache AS \"%s\"\n", - gettext_noop("Type"), - gettext_noop("Start"), - gettext_noop("Minimum"), - gettext_noop("Maximum"), - gettext_noop("Increment"), - gettext_noop("yes"), - gettext_noop("no"), - gettext_noop("Cycles?"), - gettext_noop("Cache")); - appendPQExpBuffer(&buf, - "FROM pg_catalog.pg_sequence\n" - "WHERE seqrelid = '%s';", - oid); + appendPQExpBuffer(&buf, + "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" + " seqstart AS \"%s\",\n" + " seqmin AS \"%s\",\n" + " seqmax AS \"%s\",\n" + " seqincrement AS \"%s\",\n" + " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" + " seqcache AS \"%s\"\n", + gettext_noop("Type"), + gettext_noop("Start"), + gettext_noop("Minimum"), + gettext_noop("Maximum"), + gettext_noop("Increment"), + gettext_noop("yes"), + gettext_noop("no"), + gettext_noop("Cycles?"), + gettext_noop("Cache")); + appendPQExpBuffer(&buf, + "FROM pg_catalog.pg_sequence\n" + "WHERE seqrelid = '%s';", + oid); res = PSQLexec(buf.data); if (!res) @@ -1913,7 +1913,7 @@ describeOneTableDetails(const char *schemaname, appendPQExpBufferStr(&buf, ",\n (SELECT c.collname FROM pg_catalog.pg_collation c, pg_catalog.pg_type t\n" " WHERE c.oid = a.attcollation AND t.oid = a.atttypid AND a.attcollation <> t.typcollation) AS attcollation"); attcoll_col = cols++; - appendPQExpBufferStr(&buf, ",\n a.attidentity"); + appendPQExpBufferStr(&buf, ",\n a.attidentity"); attidentity_col = cols++; if (pset.sversion >= 120000) appendPQExpBufferStr(&buf, ",\n a.attgenerated"); @@ -2326,7 +2326,7 @@ describeOneTableDetails(const char *schemaname, CppAsString2(CONSTRAINT_EXCLUSION) ") AND " "condeferred) AS condeferred,\n"); - appendPQExpBufferStr(&buf, "i.indisreplident,\n"); + appendPQExpBufferStr(&buf, "i.indisreplident,\n"); if (pset.sversion >= 150000) appendPQExpBufferStr(&buf, "i.indnullsnotdistinct,\n"); @@ -2431,7 +2431,7 @@ describeOneTableDetails(const char *schemaname, "pg_catalog.pg_get_indexdef(i.indexrelid, 0, true),\n " "pg_catalog.pg_get_constraintdef(con.oid, true), " "contype, condeferrable, condeferred"); - appendPQExpBufferStr(&buf, ", i.indisreplident"); + appendPQExpBufferStr(&buf, ", i.indisreplident"); appendPQExpBufferStr(&buf, ", c2.reltablespace"); if (pset.sversion >= 180000) appendPQExpBufferStr(&buf, ", con.conperiod"); @@ -2682,81 +2682,80 @@ describeOneTableDetails(const char *schemaname, PQclear(result); /* print any row-level policies */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get row-level policies for this table")); - appendPQExpBufferStr(&buf, "SELECT pol.polname,"); - appendPQExpBufferStr(&buf, - " pol.polpermissive,\n"); - appendPQExpBuffer(&buf, - " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" - " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" - " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" - " CASE pol.polcmd\n" - " WHEN 'r' THEN 'SELECT'\n" - " WHEN 'a' THEN 'INSERT'\n" - " WHEN 'w' THEN 'UPDATE'\n" - " WHEN 'd' THEN 'DELETE'\n" - " END AS cmd\n" - "FROM pg_catalog.pg_policy pol\n" - "WHERE pol.polrelid = '%s' ORDER BY 1;", - oid); + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get row-level policies for this table")); + appendPQExpBufferStr(&buf, "SELECT pol.polname,"); + appendPQExpBufferStr(&buf, + " pol.polpermissive,\n"); + appendPQExpBuffer(&buf, + " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" + " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" + " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" + " CASE pol.polcmd\n" + " WHEN 'r' THEN 'SELECT'\n" + " WHEN 'a' THEN 'INSERT'\n" + " WHEN 'w' THEN 'UPDATE'\n" + " WHEN 'd' THEN 'DELETE'\n" + " END AS cmd\n" + "FROM pg_catalog.pg_policy pol\n" + "WHERE pol.polrelid = '%s' ORDER BY 1;", + oid); - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - /* - * Handle cases where RLS is enabled and there are policies, or - * there aren't policies, or RLS isn't enabled but there are - * policies - */ - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies:")); + /* + * Handle cases where RLS is enabled and there are policies, or there + * aren't policies, or RLS isn't enabled but there are policies + */ + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies:")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled):")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled):")); - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); - if (!tableinfo.rowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (row security disabled):")); + if (!tableinfo.rowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (row security disabled):")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " POLICY \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " POLICY \"%s\"", + PQgetvalue(result, i, 0)); - if (*(PQgetvalue(result, i, 1)) == 'f') - appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); + if (*(PQgetvalue(result, i, 1)) == 'f') + appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); - if (!PQgetisnull(result, i, 5)) - appendPQExpBuffer(&buf, " FOR %s", - PQgetvalue(result, i, 5)); + if (!PQgetisnull(result, i, 5)) + appendPQExpBuffer(&buf, " FOR %s", + PQgetvalue(result, i, 5)); - if (!PQgetisnull(result, i, 2)) - { - appendPQExpBuffer(&buf, "\n TO %s", - PQgetvalue(result, i, 2)); - } + if (!PQgetisnull(result, i, 2)) + { + appendPQExpBuffer(&buf, "\n TO %s", + PQgetvalue(result, i, 2)); + } - if (!PQgetisnull(result, i, 3)) - appendPQExpBuffer(&buf, "\n USING (%s)", - PQgetvalue(result, i, 3)); + if (!PQgetisnull(result, i, 3)) + appendPQExpBuffer(&buf, "\n USING (%s)", + PQgetvalue(result, i, 3)); - if (!PQgetisnull(result, i, 4)) - appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", - PQgetvalue(result, i, 4)); + if (!PQgetisnull(result, i, 4)) + appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", + PQgetvalue(result, i, 4)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* print any extended statistics */ if (pset.sversion >= 140000) @@ -3025,115 +3024,115 @@ describeOneTableDetails(const char *schemaname, } /* print any publications */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get publications that publish this table")); - if (pset.sversion >= 150000) + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get publications that publish this table")); + if (pset.sversion >= 150000) + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" + " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" + "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" + "UNION\n" + "SELECT pubname\n" + " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" + " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" + " (SELECT pg_catalog.string_agg(attname, ', ')\n" + " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" + " pg_catalog.pg_attribute\n" + " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" + " ELSE NULL END) " + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" + "WHERE pr.prrelid = '%s'\n", + oid, oid, oid); + + if (pset.sversion >= 190000) { + /* + * Skip entries where this relation appears in the + * publication's EXCEPT list. + */ appendPQExpBuffer(&buf, + " AND NOT pr.prexcept\n" + "UNION\n" "SELECT pubname\n" " , NULL\n" " , NULL\n" "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" - " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" - "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" - "UNION\n" - "SELECT pubname\n" - " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" - " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" - " (SELECT pg_catalog.string_agg(attname, ', ')\n" - " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" - " pg_catalog.pg_attribute\n" - " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" - " ELSE NULL END) " - "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" - "WHERE pr.prrelid = '%s'\n", + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + " AND NOT EXISTS (\n" + " SELECT 1\n" + " FROM pg_catalog.pg_publication_rel pr\n" + " WHERE pr.prpubid = p.oid AND\n" + " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" + "ORDER BY 1;", oid, oid, oid); - - if (pset.sversion >= 190000) - { - /* - * Skip entries where this relation appears in the - * publication's EXCEPT list. - */ - appendPQExpBuffer(&buf, - " AND NOT pr.prexcept\n" - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - " AND NOT EXISTS (\n" - " SELECT 1\n" - " FROM pg_catalog.pg_publication_rel pr\n" - " WHERE pr.prpubid = p.oid AND\n" - " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" - "ORDER BY 1;", - oid, oid, oid); - } - else - { - appendPQExpBuffer(&buf, - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - "ORDER BY 1;", - oid); - } } else { appendPQExpBuffer(&buf, + "UNION\n" "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - "WHERE pr.prrelid = '%s'\n" - "UNION ALL\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" + " , NULL\n" + " , NULL\n" "FROM pg_catalog.pg_publication p\n" "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" "ORDER BY 1;", - oid, oid); + oid); } + } + else + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + "WHERE pr.prrelid = '%s'\n" + "UNION ALL\n" + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + "ORDER BY 1;", + oid, oid); + } - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - if (tuples > 0) - printTableAddFooter(&cont, _("Included in publications:")); + if (tuples > 0) + printTableAddFooter(&cont, _("Included in publications:")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " \"%s\"", + PQgetvalue(result, i, 0)); - /* column list (if any) */ - if (!PQgetisnull(result, i, 2)) - appendPQExpBuffer(&buf, " (%s)", - PQgetvalue(result, i, 2)); + /* column list (if any) */ + if (!PQgetisnull(result, i, 2)) + appendPQExpBuffer(&buf, " (%s)", + PQgetvalue(result, i, 2)); - /* row filter (if any) */ - if (!PQgetisnull(result, i, 1)) - appendPQExpBuffer(&buf, " WHERE %s", - PQgetvalue(result, i, 1)); + /* row filter (if any) */ + if (!PQgetisnull(result, i, 1)) + appendPQExpBuffer(&buf, " WHERE %s", + PQgetvalue(result, i, 1)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* Print publications where the table is in the EXCEPT clause */ if (pset.sversion >= 190000) @@ -3805,7 +3804,7 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) ncols++; } appendPQExpBufferStr(&buf, "\n, r.rolreplication"); - appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); + appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_roles r\n"); @@ -3860,8 +3859,8 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) if (strcmp(PQgetvalue(res, i, (verbose ? 9 : 8)), "t") == 0) add_role_attribute(&buf, _("Replication")); - if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) - add_role_attribute(&buf, _("Bypass RLS")); + if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) + add_role_attribute(&buf, _("Bypass RLS")); conns = atoi(PQgetvalue(res, i, 6)); if (conns >= 0) @@ -5155,14 +5154,14 @@ listCollations(const char *pattern, bool verbose, bool showSystem) gettext_noop("Schema"), gettext_noop("Name")); - appendPQExpBuffer(&buf, - " CASE c.collprovider " - "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " - "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " - "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " - "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " - "END AS \"%s\",\n", - gettext_noop("Provider")); + appendPQExpBuffer(&buf, + " CASE c.collprovider " + "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " + "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " + "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " + "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " + "END AS \"%s\",\n", + gettext_noop("Provider")); appendPQExpBuffer(&buf, " c.collcollate AS \"%s\",\n" -- 2.50.1 (Apple Git-155) --aHl3HfeiUuO3zeNC-- ^ permalink raw reply [nested|flat] 59+ messages in thread
* [PATCH v6 4/4] run pgindent and pgperltidy @ 2026-06-30 18:24 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 59+ messages in thread From: Nathan Bossart @ 2026-06-30 18:24 UTC (permalink / raw) --- src/bin/pg_dump/pg_dump.c | 464 ++++++++++----------- src/bin/pg_dump/pg_dumpall.c | 30 +- src/bin/pg_upgrade/check.c | 16 +- src/bin/pg_upgrade/controldata.c | 2 +- src/bin/pg_upgrade/exec.c | 8 +- src/bin/pg_upgrade/multixact_rewrite.c | 80 ++-- src/bin/pg_upgrade/pg_upgrade.c | 34 +- src/bin/pg_upgrade/relfilenumber.c | 54 +-- src/bin/pg_upgrade/t/006_transfer_modes.pl | 33 +- src/bin/psql/command.c | 29 +- src/bin/psql/describe.c | 461 ++++++++++---------- 11 files changed, 601 insertions(+), 610 deletions(-) diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 65bd15ebfd2..5673268b467 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -1491,8 +1491,8 @@ setup_connection(Archive *AH, const char *dumpencoding, * Disable timeouts if supported. */ ExecuteSqlStatement(AH, "SET statement_timeout = 0"); - ExecuteSqlStatement(AH, "SET lock_timeout = 0"); - ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); + ExecuteSqlStatement(AH, "SET lock_timeout = 0"); + ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); if (AH->remoteVersion >= 170000) ExecuteSqlStatement(AH, "SET transaction_timeout = 0"); @@ -1505,10 +1505,10 @@ setup_connection(Archive *AH, const char *dumpencoding, /* * Adjust row-security mode, if supported. */ - if (dopt->enable_row_security) - ExecuteSqlStatement(AH, "SET row_security = on"); - else - ExecuteSqlStatement(AH, "SET row_security = off"); + if (dopt->enable_row_security) + ExecuteSqlStatement(AH, "SET row_security = on"); + else + ExecuteSqlStatement(AH, "SET row_security = off"); /* * For security reasons, we restrict the expansion of non-system views and @@ -1933,10 +1933,9 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) addObjectDependency(dobj, ext->dobj.dumpId); /* - * Mark the member object to have any non-initial ACLs - * dumped. (Any initial ACLs will be removed later, using data from - * pg_init_privs, so that we'll dump only the delta from the extension's - * initial setup.) + * Mark the member object to have any non-initial ACLs dumped. (Any + * initial ACLs will be removed later, using data from pg_init_privs, so + * that we'll dump only the delta from the extension's initial setup.) * * In binary upgrades, we still dump all components of the members * individually, since the idea is to exactly reproduce the database @@ -1953,7 +1952,7 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) if (fout->dopt->binary_upgrade) dobj->dump = ext->dobj.dump; else - dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); + dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); return true; } @@ -1987,9 +1986,9 @@ selectDumpableNamespace(NamespaceInfo *nsinfo, Archive *fout) else if (strcmp(nsinfo->dobj.name, "pg_catalog") == 0) { /* - * We dump out any ACLs defined in pg_catalog, if - * they are interesting (and not the original ACLs which were set at - * initdb time, see pg_init_privs). + * We dump out any ACLs defined in pg_catalog, if they are interesting + * (and not the original ACLs which were set at initdb time, see + * pg_init_privs). */ nsinfo->dobj.dump_contains = nsinfo->dobj.dump = DUMP_COMPONENT_ACL; } @@ -3296,7 +3295,7 @@ dumpDatabase(Archive *fout) "datcollate, datctype, datfrozenxid, " "datacl, acldefault('d', datdba) AS acldefault, " "datistemplate, datconnlimit, "); - appendPQExpBufferStr(dbQry, "datminmxid, "); + appendPQExpBufferStr(dbQry, "datminmxid, "); if (fout->remoteVersion >= 170000) appendPQExpBufferStr(dbQry, "datlocprovider, datlocale, datcollversion, "); else if (fout->remoteVersion >= 150000) @@ -3638,11 +3637,11 @@ dumpDatabase(Archive *fout) ii_oid, ii_relminmxid; - appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" - "FROM pg_catalog.pg_class\n" - "WHERE oid IN (%u, %u, %u, %u);\n", - LargeObjectRelationId, LargeObjectLOidPNIndexId, - LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); + appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" + "FROM pg_catalog.pg_class\n" + "WHERE oid IN (%u, %u, %u, %u);\n", + LargeObjectRelationId, LargeObjectLOidPNIndexId, + LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); lo_res = ExecuteSqlQuery(fout, loFrozenQry->data, PGRES_TUPLES_OK); @@ -4274,7 +4273,7 @@ getPolicies(Archive *fout, TableInfo tblinfo[], int numTables) printfPQExpBuffer(query, "SELECT pol.oid, pol.tableoid, pol.polrelid, pol.polname, pol.polcmd, "); - appendPQExpBufferStr(query, "pol.polpermissive, "); + appendPQExpBufferStr(query, "pol.polpermissive, "); appendPQExpBuffer(query, "CASE WHEN pol.polroles = '{0}' THEN NULL ELSE " " pg_catalog.array_to_string(ARRAY(SELECT pg_catalog.quote_ident(rolname) from pg_catalog.pg_roles WHERE oid = ANY(pol.polroles)), ', ') END AS polroles, " @@ -6633,9 +6632,9 @@ getAccessMethods(Archive *fout) * Select all access methods from pg_am table. */ appendPQExpBufferStr(query, "SELECT tableoid, oid, amname, "); - appendPQExpBufferStr(query, - "amtype, " - "amhandler::pg_catalog.regproc AS amhandler "); + appendPQExpBufferStr(query, + "amtype, " + "amhandler::pg_catalog.regproc AS amhandler "); appendPQExpBufferStr(query, "FROM pg_am"); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6827,35 +6826,35 @@ getAggregates(Archive *fout) * Find all interesting aggregates. See comment in getFuncs() for the * rationale behind the filtering logic. */ - agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" - : "p.proisagg"); + agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" + : "p.proisagg"); - appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " - "p.proname AS aggname, " - "p.pronamespace AS aggnamespace, " - "p.pronargs, p.proargtypes, " - "p.proowner, " - "p.proacl AS aggacl, " - "acldefault('f', p.proowner) AS acldefault " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s AND (" - "p.pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog') OR " - "p.proacl IS DISTINCT FROM pip.initprivs", - agg_check); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - " OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); - appendPQExpBufferChar(query, ')'); + appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " + "p.proname AS aggname, " + "p.pronamespace AS aggnamespace, " + "p.pronargs, p.proargtypes, " + "p.proowner, " + "p.proacl AS aggacl, " + "acldefault('f', p.proowner) AS acldefault " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s AND (" + "p.pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog') OR " + "p.proacl IS DISTINCT FROM pip.initprivs", + agg_check); + if (dopt->binary_upgrade) + appendPQExpBufferStr(query, + " OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6957,53 +6956,53 @@ getFuncs(Archive *fout) * include them, since we want to dump extension members individually in * that mode. Also, if they are used by casts or transforms then we need * to gather the information about them, though they won't be dumped if - * they are built-in. Also, include functions in - * pg_catalog if they have an ACL different from what's shown in - * pg_init_privs (so we have to join to pg_init_privs; annoying). + * they are built-in. Also, include functions in pg_catalog if they have + * an ACL different from what's shown in pg_init_privs (so we have to join + * to pg_init_privs; annoying). */ - not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" - : "NOT p.proisagg"); + not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" + : "NOT p.proisagg"); - appendPQExpBuffer(query, - "SELECT p.tableoid, p.oid, p.proname, p.prolang, " - "p.pronargs, p.proargtypes, p.prorettype, " - "p.proacl, " - "acldefault('f', p.proowner) AS acldefault, " - "p.pronamespace, " - "p.proowner " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s" - "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " - "WHERE classid = 'pg_proc'::regclass AND " - "objid = p.oid AND deptype = 'i')" - "\n AND (" - "\n pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog')" - "\n OR EXISTS (SELECT 1 FROM pg_cast" - "\n WHERE pg_cast.oid > %u " - "\n AND p.oid = pg_cast.castfunc)" - "\n OR EXISTS (SELECT 1 FROM pg_transform" - "\n WHERE pg_transform.oid > %u AND " - "\n (p.oid = pg_transform.trffromsql" - "\n OR p.oid = pg_transform.trftosql))", - not_agg_check, - g_last_builtin_oid, - g_last_builtin_oid); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); + appendPQExpBuffer(query, + "SELECT p.tableoid, p.oid, p.proname, p.prolang, " + "p.pronargs, p.proargtypes, p.prorettype, " + "p.proacl, " + "acldefault('f', p.proowner) AS acldefault, " + "p.pronamespace, " + "p.proowner " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s" + "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " + "WHERE classid = 'pg_proc'::regclass AND " + "objid = p.oid AND deptype = 'i')" + "\n AND (" + "\n pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog')" + "\n OR EXISTS (SELECT 1 FROM pg_cast" + "\n WHERE pg_cast.oid > %u " + "\n AND p.oid = pg_cast.castfunc)" + "\n OR EXISTS (SELECT 1 FROM pg_transform" + "\n WHERE pg_transform.oid > %u AND " + "\n (p.oid = pg_transform.trffromsql" + "\n OR p.oid = pg_transform.trftosql))", + not_agg_check, + g_last_builtin_oid, + g_last_builtin_oid); + if (dopt->binary_upgrade) appendPQExpBufferStr(query, - "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); - appendPQExpBufferChar(query, ')'); + "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferStr(query, + "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -7252,31 +7251,31 @@ getTables(Archive *fout, int *numTables) appendPQExpBufferStr(query, "c.relhasoids, "); - appendPQExpBufferStr(query, - "c.relispopulated, "); + appendPQExpBufferStr(query, + "c.relispopulated, "); - appendPQExpBufferStr(query, - "c.relreplident, "); + appendPQExpBufferStr(query, + "c.relreplident, "); - appendPQExpBufferStr(query, - "c.relrowsecurity, c.relforcerowsecurity, "); + appendPQExpBufferStr(query, + "c.relrowsecurity, c.relforcerowsecurity, "); - appendPQExpBufferStr(query, - "c.relminmxid, tc.relminmxid AS tminmxid, "); + appendPQExpBufferStr(query, + "c.relminmxid, tc.relminmxid AS tminmxid, "); - appendPQExpBufferStr(query, - "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); + appendPQExpBufferStr(query, + "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); - appendPQExpBufferStr(query, - "am.amname, "); + appendPQExpBufferStr(query, + "am.amname, "); - appendPQExpBufferStr(query, - "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); + appendPQExpBufferStr(query, + "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); - appendPQExpBufferStr(query, - "c.relispartition AS ispartition "); + appendPQExpBufferStr(query, + "c.relispartition AS ispartition "); /* * Left join to pg_depend to pick up dependency info linking sequences to @@ -7296,8 +7295,8 @@ getTables(Archive *fout, int *numTables) /* * Left join to pg_am to pick up the amname. */ - appendPQExpBufferStr(query, - "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); + appendPQExpBufferStr(query, + "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); /* * We purposefully ignore toast OIDs for partitioned tables; the reason is @@ -7868,8 +7867,8 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables) "t.reloptions AS indreloptions, "); - appendPQExpBufferStr(query, - "i.indisreplident, "); + appendPQExpBufferStr(query, + "i.indisreplident, "); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -9313,8 +9312,8 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables) appendPQExpBufferStr(q, "'' AS attcompression,\n"); - appendPQExpBufferStr(q, - "a.attidentity,\n"); + appendPQExpBufferStr(q, + "a.attidentity,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(q, @@ -10717,73 +10716,73 @@ getAdditionalACLs(Archive *fout) PQclear(res); /* Fetch initial-privileges data */ - printfPQExpBuffer(query, - "SELECT objoid, classoid, objsubid, privtype, initprivs " - "FROM pg_init_privs"); + printfPQExpBuffer(query, + "SELECT objoid, classoid, objsubid, privtype, initprivs " + "FROM pg_init_privs"); - res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); + res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); - ntups = PQntuples(res); - for (i = 0; i < ntups; i++) - { - Oid objoid = atooid(PQgetvalue(res, i, 0)); - Oid classoid = atooid(PQgetvalue(res, i, 1)); - int objsubid = atoi(PQgetvalue(res, i, 2)); - char privtype = *(PQgetvalue(res, i, 3)); - char *initprivs = PQgetvalue(res, i, 4); - CatalogId objId; - DumpableObject *dobj; + ntups = PQntuples(res); + for (i = 0; i < ntups; i++) + { + Oid objoid = atooid(PQgetvalue(res, i, 0)); + Oid classoid = atooid(PQgetvalue(res, i, 1)); + int objsubid = atoi(PQgetvalue(res, i, 2)); + char privtype = *(PQgetvalue(res, i, 3)); + char *initprivs = PQgetvalue(res, i, 4); + CatalogId objId; + DumpableObject *dobj; - objId.tableoid = classoid; - objId.oid = objoid; - dobj = findObjectByCatalogId(objId); - /* OK to ignore entries we haven't got a DumpableObject for */ - if (dobj) + objId.tableoid = classoid; + objId.oid = objoid; + dobj = findObjectByCatalogId(objId); + /* OK to ignore entries we haven't got a DumpableObject for */ + if (dobj) + { + /* Cope with sub-object initprivs */ + if (objsubid != 0) { - /* Cope with sub-object initprivs */ - if (objsubid != 0) - { - if (dobj->objType == DO_TABLE) - { - /* For a column initprivs, set the table's ACL flags */ - dobj->components |= DUMP_COMPONENT_ACL; - ((TableInfo *) dobj)->hascolumnACLs = true; - } - else - pg_log_warning("unsupported pg_init_privs entry: %u %u %d", - classoid, objoid, objsubid); - continue; - } - - /* - * We ignore any pg_init_privs.initprivs entry for the public - * schema, as explained in getNamespaces(). - */ - if (dobj->objType == DO_NAMESPACE && - strcmp(dobj->name, "public") == 0) - continue; - - /* Else it had better be of a type we think has ACLs */ - if (dobj->objType == DO_NAMESPACE || - dobj->objType == DO_TYPE || - dobj->objType == DO_FUNC || - dobj->objType == DO_AGG || - dobj->objType == DO_TABLE || - dobj->objType == DO_PROCLANG || - dobj->objType == DO_FDW || - dobj->objType == DO_FOREIGN_SERVER) + if (dobj->objType == DO_TABLE) { - DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; - - daobj->dacl.privtype = privtype; - daobj->dacl.initprivs = pstrdup(initprivs); + /* For a column initprivs, set the table's ACL flags */ + dobj->components |= DUMP_COMPONENT_ACL; + ((TableInfo *) dobj)->hascolumnACLs = true; } else pg_log_warning("unsupported pg_init_privs entry: %u %u %d", classoid, objoid, objsubid); + continue; + } + + /* + * We ignore any pg_init_privs.initprivs entry for the public + * schema, as explained in getNamespaces(). + */ + if (dobj->objType == DO_NAMESPACE && + strcmp(dobj->name, "public") == 0) + continue; + + /* Else it had better be of a type we think has ACLs */ + if (dobj->objType == DO_NAMESPACE || + dobj->objType == DO_TYPE || + dobj->objType == DO_FUNC || + dobj->objType == DO_AGG || + dobj->objType == DO_TABLE || + dobj->objType == DO_PROCLANG || + dobj->objType == DO_FDW || + dobj->objType == DO_FOREIGN_SERVER) + { + DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; + + daobj->dacl.privtype = privtype; + daobj->dacl.initprivs = pstrdup(initprivs); } + else + pg_log_warning("unsupported pg_init_privs entry: %u %u %d", + classoid, objoid, objsubid); } - PQclear(res); + } + PQclear(res); destroyPQExpBuffer(query); } @@ -11128,8 +11127,8 @@ dumpRelationStats_dumper(Archive *fout, const void *userArg, const TocEntry *te) * The results must be in the order of the relations supplied in the * parameters to ensure we remain in sync as we walk through the TOC. * - * For versions before 19, the redundant filter clause on s.tablename = - * ANY(...) seems sufficient to convince the planner to use + * For versions before 19, the redundant filter clause on s.tablename + * = ANY(...) seems sufficient to convince the planner to use * pg_class_relname_nsp_index, which avoids a full scan of pg_stats. * In newer versions, pg_stats returns the table OIDs, eliminating the * need for that hack. @@ -13469,11 +13468,11 @@ dumpFunc(Archive *fout, const FuncInfo *finfo) "pg_catalog.pg_get_function_result(p.oid) AS funcresult,\n" "proleakproof,\n"); - appendPQExpBufferStr(query, - "array_to_string(protrftypes, ' ') AS protrftypes,\n"); + appendPQExpBufferStr(query, + "array_to_string(protrftypes, ' ') AS protrftypes,\n"); - appendPQExpBufferStr(query, - "proparallel,\n"); + appendPQExpBufferStr(query, + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -14963,9 +14962,9 @@ dumpCollation(Archive *fout, const CollInfo *collinfo) /* Get collation-specific details */ appendPQExpBufferStr(query, "SELECT "); - appendPQExpBufferStr(query, - "collprovider, " - "collversion, "); + appendPQExpBufferStr(query, + "collprovider, " + "collversion, "); if (fout->remoteVersion >= 120000) appendPQExpBufferStr(query, @@ -15372,23 +15371,23 @@ dumpAgg(Archive *fout, const AggInfo *agginfo) "pg_catalog.pg_get_function_arguments(p.oid) AS funcargs,\n" "pg_catalog.pg_get_function_identity_arguments(p.oid) AS funciargs,\n"); - appendPQExpBufferStr(query, - "aggkind,\n" - "aggmtransfn,\n" - "aggminvtransfn,\n" - "aggmfinalfn,\n" - "aggmtranstype::pg_catalog.regtype,\n" - "aggfinalextra,\n" - "aggmfinalextra,\n" - "aggtransspace,\n" - "aggmtransspace,\n" - "aggminitval,\n"); + appendPQExpBufferStr(query, + "aggkind,\n" + "aggmtransfn,\n" + "aggminvtransfn,\n" + "aggmfinalfn,\n" + "aggmtranstype::pg_catalog.regtype,\n" + "aggfinalextra,\n" + "aggmfinalextra,\n" + "aggtransspace,\n" + "aggmtransspace,\n" + "aggminitval,\n"); - appendPQExpBufferStr(query, - "aggcombinefn,\n" - "aggserialfn,\n" - "aggdeserialfn,\n" - "proparallel,\n"); + appendPQExpBufferStr(query, + "aggcombinefn,\n" + "aggserialfn,\n" + "aggdeserialfn,\n" + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -16848,30 +16847,30 @@ dumpTable(Archive *fout, const TableInfo *tbinfo) appendPQExpBufferStr(query, "PREPARE getColumnACLs(pg_catalog.oid) AS\n"); - /* - * In principle we should call acldefault('c', relowner) to - * get the default ACL for a column. However, we don't - * currently store the numeric OID of the relowner in - * TableInfo. We could convert the owner name using regrole, - * but that creates a risk of failure due to concurrent role - * renames. Given that the default ACL for columns is empty - * and is likely to stay that way, it's not worth extra cycles - * and risk to avoid hard-wiring that knowledge here. - */ - appendPQExpBufferStr(query, - "SELECT at.attname, " - "at.attacl, " - "'{}' AS acldefault, " - "pip.privtype, pip.initprivs " - "FROM pg_catalog.pg_attribute at " - "LEFT JOIN pg_catalog.pg_init_privs pip ON " - "(at.attrelid = pip.objoid " - "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " - "AND at.attnum = pip.objsubid) " - "WHERE at.attrelid = $1 AND " - "NOT at.attisdropped " - "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " - "ORDER BY at.attnum"); + /* + * In principle we should call acldefault('c', relowner) to get + * the default ACL for a column. However, we don't currently + * store the numeric OID of the relowner in TableInfo. We could + * convert the owner name using regrole, but that creates a risk + * of failure due to concurrent role renames. Given that the + * default ACL for columns is empty and is likely to stay that + * way, it's not worth extra cycles and risk to avoid hard-wiring + * that knowledge here. + */ + appendPQExpBufferStr(query, + "SELECT at.attname, " + "at.attacl, " + "'{}' AS acldefault, " + "pip.privtype, pip.initprivs " + "FROM pg_catalog.pg_attribute at " + "LEFT JOIN pg_catalog.pg_init_privs pip ON " + "(at.attrelid = pip.objoid " + "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " + "AND at.attnum = pip.objsubid) " + "WHERE at.attrelid = $1 AND " + "NOT at.attisdropped " + "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " + "ORDER BY at.attnum"); ExecuteSqlStatement(fout, query->data); @@ -19165,7 +19164,7 @@ collectSequences(Archive *fout) * pg_get_sequence_data(), but we only do so for non-schema-only dumps. */ if (fout->remoteVersion < 180000 || - (!fout->dopt->dumpData && !fout->dopt->sequence_data)) + (!fout->dopt->dumpData && !fout->dopt->sequence_data)) query = "SELECT seqrelid, format_type(seqtypid, NULL), " "seqstart, seqincrement, " "seqmax, seqmin, " @@ -19227,15 +19226,14 @@ dumpSequence(Archive *fout, const TableInfo *tbinfo) qseqname = pg_strdup(fmtId(tbinfo->dobj.name)); /* - * The sequence information is gathered in a sorted - * table before any calls to dumpSequence(). See collectSequences() for - * more information. + * The sequence information is gathered in a sorted table before any calls + * to dumpSequence(). See collectSequences() for more information. */ - Assert(sequences); + Assert(sequences); - key.oid = tbinfo->dobj.catId.oid; - seq = bsearch(&key, sequences, nsequences, - sizeof(SequenceItem), SequenceItemCmp); + key.oid = tbinfo->dobj.catId.oid; + seq = bsearch(&key, sequences, nsequences, + sizeof(SequenceItem), SequenceItemCmp); /* Calculate default limits for a sequence of this type */ is_ascending = (seq->incby >= 0); diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c index e68937c9934..afcd9a218d8 100644 --- a/src/bin/pg_dump/pg_dumpall.c +++ b/src/bin/pg_dump/pg_dumpall.c @@ -785,11 +785,11 @@ dropRoles(PGconn *conn) int i_rolname; int i; - printfPQExpBuffer(buf, - "SELECT rolname " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 1", role_catalog); + printfPQExpBuffer(buf, + "SELECT rolname " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 1", role_catalog); res = executeQuery(conn, buf->data); @@ -843,16 +843,16 @@ dumpRoles(PGconn *conn) * Notes: rolconfig is dumped later, and pg_authid must be used for * extracting rolcomment regardless of role_catalog. */ - printfPQExpBuffer(buf, - "SELECT oid, rolname, rolsuper, rolinherit, " - "rolcreaterole, rolcreatedb, " - "rolcanlogin, rolconnlimit, rolpassword, " - "rolvaliduntil, rolreplication, rolbypassrls, " - "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " - "rolname = current_user AS is_current_user " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 2", role_catalog); + printfPQExpBuffer(buf, + "SELECT oid, rolname, rolsuper, rolinherit, " + "rolcreaterole, rolcreatedb, " + "rolcanlogin, rolconnlimit, rolpassword, " + "rolvaliduntil, rolreplication, rolbypassrls, " + "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " + "rolname = current_user AS is_current_user " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 2", role_catalog); res = executeQuery(conn, buf->data); diff --git a/src/bin/pg_upgrade/check.c b/src/bin/pg_upgrade/check.c index 786c1474829..f725f5ee3e2 100644 --- a/src/bin/pg_upgrade/check.c +++ b/src/bin/pg_upgrade/check.c @@ -1475,15 +1475,15 @@ check_for_incompatible_polymorphics(ClusterInfo *cluster) ", 'array_cat(anyarray,anyarray)'" ", 'array_prepend(anyelement,anyarray)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_remove(anyarray,anyelement)'" - ", 'array_replace(anyarray,anyelement,anyelement)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_remove(anyarray,anyelement)'" + ", 'array_replace(anyarray,anyelement,anyelement)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_position(anyarray,anyelement)'" - ", 'array_position(anyarray,anyelement,integer)'" - ", 'array_positions(anyarray,anyelement)'" - ", 'width_bucket(anyelement,anyarray)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_position(anyarray,anyelement)'" + ", 'array_position(anyarray,anyelement,integer)'" + ", 'array_positions(anyarray,anyelement)'" + ", 'width_bucket(anyelement,anyarray)'"); /* * The query below hardcodes FirstNormalObjectId as 16384 rather than diff --git a/src/bin/pg_upgrade/controldata.c b/src/bin/pg_upgrade/controldata.c index 8f81c9e9582..02ea02df60f 100644 --- a/src/bin/pg_upgrade/controldata.c +++ b/src/bin/pg_upgrade/controldata.c @@ -228,7 +228,7 @@ get_control_data(ClusterInfo *cluster) p++; /* remove ':' char */ cluster->controldata.chkpnt_nxtepoch = str2uint(p); - p = strchr(p, ':'); + p = strchr(p, ':'); if (p == NULL || strlen(p) <= 1) pg_fatal("%d: controldata retrieval problem", __LINE__); diff --git a/src/bin/pg_upgrade/exec.c b/src/bin/pg_upgrade/exec.c index 44355feea30..a1bdbf373e3 100644 --- a/src/bin/pg_upgrade/exec.c +++ b/src/bin/pg_upgrade/exec.c @@ -55,7 +55,7 @@ get_bin_version(ClusterInfo *cluster) if (sscanf(cmd_output, "%*s %*s %d.%d", &v1, &v2) < 1) pg_fatal("could not get pg_ctl version output from %s", cmd); - cluster->bin_version = v1 * 10000; + cluster->bin_version = v1 * 10000; } @@ -344,8 +344,8 @@ check_data_dir(ClusterInfo *cluster) check_single_dir(pg_data, "pg_subtrans"); check_single_dir(pg_data, PG_TBLSPC_DIR); check_single_dir(pg_data, "pg_twophase"); - check_single_dir(pg_data, "pg_wal"); - check_single_dir(pg_data, "pg_xact"); + check_single_dir(pg_data, "pg_wal"); + check_single_dir(pg_data, "pg_xact"); } @@ -385,7 +385,7 @@ check_bin_dir(ClusterInfo *cluster, bool check_versions) */ get_bin_version(cluster); - check_exec(cluster->bindir, "pg_resetwal", check_versions); + check_exec(cluster->bindir, "pg_resetwal", check_versions); if (cluster == &new_cluster) { diff --git a/src/bin/pg_upgrade/multixact_rewrite.c b/src/bin/pg_upgrade/multixact_rewrite.c index c45b3183684..c7a1416494d 100644 --- a/src/bin/pg_upgrade/multixact_rewrite.c +++ b/src/bin/pg_upgrade/multixact_rewrite.c @@ -61,52 +61,52 @@ rewrite_multixacts(MultiXactId from_multi, MultiXactId to_multi) * Convert old multixids, if needed, by reading them one-by-one from the * old cluster. */ - old_reader = AllocOldMultiXactRead(old_cluster.pgdata, - old_cluster.controldata.chkpnt_nxtmulti, - old_cluster.controldata.chkpnt_nxtmxoff); + old_reader = AllocOldMultiXactRead(old_cluster.pgdata, + old_cluster.controldata.chkpnt_nxtmulti, + old_cluster.controldata.chkpnt_nxtmxoff); - for (MultiXactId multi = from_multi; multi != to_multi;) - { - MultiXactMember member; - bool multixid_valid; - - /* - * Read this multixid's members. - * - * Locking-only XIDs that may be part of multi-xids don't matter - * after upgrade, as there can be no transactions running across - * upgrade. So as a small optimization, we only read one member - * from each multixid: the one updating one, or if there was no - * update, arbitrarily the first locking xid. - */ - multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); + for (MultiXactId multi = from_multi; multi != to_multi;) + { + MultiXactMember member; + bool multixid_valid; - /* - * Write the new offset to pg_multixact/offsets. - * - * Even if this multixid is invalid, we still need to write its - * offset if the *previous* multixid was valid. That's because - * when reading a multixid, the number of members is calculated - * from the difference between the two offsets. - */ - RecordMultiXactOffset(offsets_writer, multi, - (multixid_valid || prev_multixid_valid) ? next_offset : 0); + /* + * Read this multixid's members. + * + * Locking-only XIDs that may be part of multi-xids don't matter after + * upgrade, as there can be no transactions running across upgrade. So + * as a small optimization, we only read one member from each + * multixid: the one updating one, or if there was no update, + * arbitrarily the first locking xid. + */ + multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); - /* Write the members */ - if (multixid_valid) - { - RecordMultiXactMembers(members_writer, next_offset, 1, &member); - next_offset += 1; - } + /* + * Write the new offset to pg_multixact/offsets. + * + * Even if this multixid is invalid, we still need to write its offset + * if the *previous* multixid was valid. That's because when reading + * a multixid, the number of members is calculated from the difference + * between the two offsets. + */ + RecordMultiXactOffset(offsets_writer, multi, + (multixid_valid || prev_multixid_valid) ? next_offset : 0); - /* Advance to next multixid, handling wraparound */ - multi++; - if (multi < FirstMultiXactId) - multi = FirstMultiXactId; - prev_multixid_valid = multixid_valid; + /* Write the members */ + if (multixid_valid) + { + RecordMultiXactMembers(members_writer, next_offset, 1, &member); + next_offset += 1; } - FreeOldMultiXactReader(old_reader); + /* Advance to next multixid, handling wraparound */ + multi++; + if (multi < FirstMultiXactId) + multi = FirstMultiXactId; + prev_multixid_valid = multixid_valid; + } + + FreeOldMultiXactReader(old_reader); /* Write the final 'next' offset to the last SLRU page */ RecordMultiXactOffset(offsets_writer, to_multi, diff --git a/src/bin/pg_upgrade/pg_upgrade.c b/src/bin/pg_upgrade/pg_upgrade.c index c6af9035665..7366fd4627c 100644 --- a/src/bin/pg_upgrade/pg_upgrade.c +++ b/src/bin/pg_upgrade/pg_upgrade.c @@ -833,7 +833,7 @@ copy_xact_xlog_xid(void) * Determine the range of multixacts to convert. */ nxtmulti = old_cluster.controldata.chkpnt_nxtmulti; - oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; + oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; /* handle wraparound */ if (nxtmulti < FirstMultiXactId) nxtmulti = FirstMultiXactId; @@ -898,15 +898,15 @@ set_frozenxids(void) int i_datname; int i_datallowconn; - prep_status("Setting frozenxid and minmxid counters in new cluster"); + prep_status("Setting frozenxid and minmxid counters in new cluster"); conn_template1 = connectToServer(&new_cluster, "template1"); - /* set pg_database.datfrozenxid */ - PQclear(executeQueryOrDie(conn_template1, - "UPDATE pg_catalog.pg_database " - "SET datfrozenxid = '%u'", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_database.datfrozenxid */ + PQclear(executeQueryOrDie(conn_template1, + "UPDATE pg_catalog.pg_database " + "SET datfrozenxid = '%u'", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_database.datminmxid */ PQclear(executeQueryOrDie(conn_template1, @@ -942,16 +942,16 @@ set_frozenxids(void) conn = connectToServer(&new_cluster, datname); - /* set pg_class.relfrozenxid */ - PQclear(executeQueryOrDie(conn, - "UPDATE pg_catalog.pg_class " - "SET relfrozenxid = '%u' " - /* only heap, materialized view, and TOAST are vacuumed */ - "WHERE relkind IN (" - CppAsString2(RELKIND_RELATION) ", " - CppAsString2(RELKIND_MATVIEW) ", " - CppAsString2(RELKIND_TOASTVALUE) ")", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_class.relfrozenxid */ + PQclear(executeQueryOrDie(conn, + "UPDATE pg_catalog.pg_class " + "SET relfrozenxid = '%u' " + /* only heap, materialized view, and TOAST are vacuumed */ + "WHERE relkind IN (" + CppAsString2(RELKIND_RELATION) ", " + CppAsString2(RELKIND_MATVIEW) ", " + CppAsString2(RELKIND_TOASTVALUE) ")", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_class.relminmxid */ PQclear(executeQueryOrDie(conn, diff --git a/src/bin/pg_upgrade/relfilenumber.c b/src/bin/pg_upgrade/relfilenumber.c index ec2ff7acb21..6c467bdc8a5 100644 --- a/src/bin/pg_upgrade/relfilenumber.c +++ b/src/bin/pg_upgrade/relfilenumber.c @@ -587,32 +587,32 @@ transfer_relfile(FileNameMap *map, const char *type_suffix) /* Copying files might take some time, so give feedback. */ pg_log(PG_STATUS, "%s", old_file); - switch (user_opts.transfer_mode) - { - case TRANSFER_MODE_CLONE: - pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", - old_file, new_file); - cloneFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", - old_file, new_file); - copyFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY_FILE_RANGE: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", - old_file, new_file); - copyFileByRange(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_LINK: - pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", - old_file, new_file); - linkFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_SWAP: - /* swap mode is handled in its own code path */ - pg_fatal("should never happen"); - break; - } + switch (user_opts.transfer_mode) + { + case TRANSFER_MODE_CLONE: + pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", + old_file, new_file); + cloneFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", + old_file, new_file); + copyFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY_FILE_RANGE: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", + old_file, new_file); + copyFileByRange(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_LINK: + pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", + old_file, new_file); + linkFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_SWAP: + /* swap mode is handled in its own code path */ + pg_fatal("should never happen"); + break; + } } } diff --git a/src/bin/pg_upgrade/t/006_transfer_modes.pl b/src/bin/pg_upgrade/t/006_transfer_modes.pl index 9efa5dc863c..360d05c4b68 100644 --- a/src/bin/pg_upgrade/t/006_transfer_modes.pl +++ b/src/bin/pg_upgrade/t/006_transfer_modes.pl @@ -29,10 +29,8 @@ sub test_mode } $new->init(); - $new->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); - $old->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); + $new->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); + $old->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); # We can only test security labels if both the old and new installations # have dummy_seclabel. @@ -76,15 +74,14 @@ sub test_mode "CREATE TABLE test4 AS SELECT generate_series(400, 502)"); } - $old->safe_psql('postgres', - "CREATE TABLESPACE inplc_tblspc LOCATION ''"); - $old->safe_psql('postgres', - "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); - $old->safe_psql('postgres', - "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" - ); - $old->safe_psql('testdb3', - "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); + $old->safe_psql('postgres', "CREATE TABLESPACE inplc_tblspc LOCATION ''"); + $old->safe_psql('postgres', + "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); + $old->safe_psql('postgres', + "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" + ); + $old->safe_psql('testdb3', + "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); # While we are here, test handling of large objects. $old->safe_psql( @@ -152,12 +149,10 @@ sub test_mode } # Tests for in-place tablespaces. - $result = - $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); - is($result, '104', "test5 data after pg_upgrade $mode"); - $result = - $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); - is($result, '105', "test6 data after pg_upgrade $mode"); + $result = $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); + is($result, '104', "test5 data after pg_upgrade $mode"); + $result = $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); + is($result, '105', "test6 data after pg_upgrade $mode"); # Tests for large objects $result = $new->safe_psql('postgres', "SELECT lo_get(4532)"); diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index 44ef11d980e..c90bf8bbde2 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -6278,23 +6278,22 @@ get_create_object_cmd(EditableObjectType obj_type, Oid oid, * ensure the right view gets replaced. Also, check relation kind * to be sure it's a view. * - * Views may have WITH [LOCAL|CASCADED] - * CHECK OPTION. These are not part of the view definition - * returned by pg_get_viewdef() and so need to be retrieved - * separately. Materialized views may have - * arbitrary storage parameter reloptions. + * Views may have WITH [LOCAL|CASCADED] CHECK OPTION. These are + * not part of the view definition returned by pg_get_viewdef() + * and so need to be retrieved separately. Materialized views may + * have arbitrary storage parameter reloptions. */ printfPQExpBuffer(query, "/* %s */\n", _("Get view's definition and details")); - appendPQExpBuffer(query, - "SELECT nspname, relname, relkind, " - "pg_catalog.pg_get_viewdef(c.oid, true), " - "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " - "FROM pg_catalog.pg_class c " - "LEFT JOIN pg_catalog.pg_namespace n " - "ON c.relnamespace = n.oid WHERE c.oid = %u", - oid); + appendPQExpBuffer(query, + "SELECT nspname, relname, relkind, " + "pg_catalog.pg_get_viewdef(c.oid, true), " + "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " + "FROM pg_catalog.pg_class c " + "LEFT JOIN pg_catalog.pg_namespace n " + "ON c.relnamespace = n.oid WHERE c.oid = %u", + oid); break; } diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index ce99137c613..ac0c55e7aa5 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -387,19 +387,19 @@ describeFunctions(const char *functypes, const char *func_pattern, gettext_noop("stable"), gettext_noop("volatile"), gettext_noop("Volatility")); - appendPQExpBuffer(&buf, - ",\n CASE\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" - " END as \"%s\"", - gettext_noop("restricted"), - gettext_noop("safe"), - gettext_noop("unsafe"), - gettext_noop("Parallel")); + appendPQExpBuffer(&buf, + ",\n CASE\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" + " END as \"%s\"", + gettext_noop("restricted"), + gettext_noop("safe"), + gettext_noop("unsafe"), + gettext_noop("Parallel")); appendPQExpBuffer(&buf, ",\n pg_catalog.pg_get_userbyid(p.proowner) as \"%s\"" ",\n CASE WHEN prosecdef THEN '%s' ELSE '%s' END AS \"%s\"" @@ -599,8 +599,8 @@ describeFunctions(const char *functypes, const char *func_pattern, myopt.title = _("List of functions"); myopt.translate_header = true; - myopt.translate_columns = translate_columns; - myopt.n_translate_columns = lengthof(translate_columns); + myopt.translate_columns = translate_columns; + myopt.n_translate_columns = lengthof(translate_columns); printQuery(res, &myopt, pset.queryFout, false, pset.logfile); @@ -1086,38 +1086,38 @@ permissionsList(const char *pattern, bool showSystem) " ), E'\\n') AS \"%s\"", gettext_noop("Column privileges")); - appendPQExpBuffer(&buf, - ",\n pg_catalog.array_to_string(ARRAY(\n" - " SELECT polname\n" - " || CASE WHEN NOT polpermissive THEN\n" - " E' (RESTRICTIVE)'\n" - " ELSE '' END\n" - " || CASE WHEN polcmd != '*' THEN\n" - " E' (' || polcmd::pg_catalog.text || E'):'\n" - " ELSE E':'\n" - " END\n" - " || CASE WHEN polqual IS NOT NULL THEN\n" - " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" - " ELSE E''\n" - " END\n" - " || CASE WHEN polwithcheck IS NOT NULL THEN\n" - " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" - " ELSE E''\n" - " END" - " || CASE WHEN polroles <> '{0}' THEN\n" - " E'\\n to: ' || pg_catalog.array_to_string(\n" - " ARRAY(\n" - " SELECT rolname\n" - " FROM pg_catalog.pg_roles\n" - " WHERE oid = ANY (polroles)\n" - " ORDER BY 1\n" - " ), E', ')\n" - " ELSE E''\n" - " END\n" - " FROM pg_catalog.pg_policy pol\n" - " WHERE polrelid = c.oid), E'\\n')\n" - " AS \"%s\"", - gettext_noop("Policies")); + appendPQExpBuffer(&buf, + ",\n pg_catalog.array_to_string(ARRAY(\n" + " SELECT polname\n" + " || CASE WHEN NOT polpermissive THEN\n" + " E' (RESTRICTIVE)'\n" + " ELSE '' END\n" + " || CASE WHEN polcmd != '*' THEN\n" + " E' (' || polcmd::pg_catalog.text || E'):'\n" + " ELSE E':'\n" + " END\n" + " || CASE WHEN polqual IS NOT NULL THEN\n" + " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" + " ELSE E''\n" + " END\n" + " || CASE WHEN polwithcheck IS NOT NULL THEN\n" + " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" + " ELSE E''\n" + " END" + " || CASE WHEN polroles <> '{0}' THEN\n" + " E'\\n to: ' || pg_catalog.array_to_string(\n" + " ARRAY(\n" + " SELECT rolname\n" + " FROM pg_catalog.pg_roles\n" + " WHERE oid = ANY (polroles)\n" + " ORDER BY 1\n" + " ), E', ')\n" + " ELSE E''\n" + " END\n" + " FROM pg_catalog.pg_policy pol\n" + " WHERE polrelid = c.oid), E'\\n')\n" + " AS \"%s\"", + gettext_noop("Policies")); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_class c\n" " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n" @@ -1675,27 +1675,27 @@ describeOneTableDetails(const char *schemaname, char *footers[3] = {NULL, NULL, NULL}; printfPQExpBuffer(&buf, "/* %s */\n", _("Get sequence information")); - appendPQExpBuffer(&buf, - "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" - " seqstart AS \"%s\",\n" - " seqmin AS \"%s\",\n" - " seqmax AS \"%s\",\n" - " seqincrement AS \"%s\",\n" - " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" - " seqcache AS \"%s\"\n", - gettext_noop("Type"), - gettext_noop("Start"), - gettext_noop("Minimum"), - gettext_noop("Maximum"), - gettext_noop("Increment"), - gettext_noop("yes"), - gettext_noop("no"), - gettext_noop("Cycles?"), - gettext_noop("Cache")); - appendPQExpBuffer(&buf, - "FROM pg_catalog.pg_sequence\n" - "WHERE seqrelid = '%s';", - oid); + appendPQExpBuffer(&buf, + "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" + " seqstart AS \"%s\",\n" + " seqmin AS \"%s\",\n" + " seqmax AS \"%s\",\n" + " seqincrement AS \"%s\",\n" + " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" + " seqcache AS \"%s\"\n", + gettext_noop("Type"), + gettext_noop("Start"), + gettext_noop("Minimum"), + gettext_noop("Maximum"), + gettext_noop("Increment"), + gettext_noop("yes"), + gettext_noop("no"), + gettext_noop("Cycles?"), + gettext_noop("Cache")); + appendPQExpBuffer(&buf, + "FROM pg_catalog.pg_sequence\n" + "WHERE seqrelid = '%s';", + oid); res = PSQLexec(buf.data); if (!res) @@ -1913,7 +1913,7 @@ describeOneTableDetails(const char *schemaname, appendPQExpBufferStr(&buf, ",\n (SELECT c.collname FROM pg_catalog.pg_collation c, pg_catalog.pg_type t\n" " WHERE c.oid = a.attcollation AND t.oid = a.atttypid AND a.attcollation <> t.typcollation) AS attcollation"); attcoll_col = cols++; - appendPQExpBufferStr(&buf, ",\n a.attidentity"); + appendPQExpBufferStr(&buf, ",\n a.attidentity"); attidentity_col = cols++; if (pset.sversion >= 120000) appendPQExpBufferStr(&buf, ",\n a.attgenerated"); @@ -2326,7 +2326,7 @@ describeOneTableDetails(const char *schemaname, CppAsString2(CONSTRAINT_EXCLUSION) ") AND " "condeferred) AS condeferred,\n"); - appendPQExpBufferStr(&buf, "i.indisreplident,\n"); + appendPQExpBufferStr(&buf, "i.indisreplident,\n"); if (pset.sversion >= 150000) appendPQExpBufferStr(&buf, "i.indnullsnotdistinct,\n"); @@ -2431,7 +2431,7 @@ describeOneTableDetails(const char *schemaname, "pg_catalog.pg_get_indexdef(i.indexrelid, 0, true),\n " "pg_catalog.pg_get_constraintdef(con.oid, true), " "contype, condeferrable, condeferred"); - appendPQExpBufferStr(&buf, ", i.indisreplident"); + appendPQExpBufferStr(&buf, ", i.indisreplident"); appendPQExpBufferStr(&buf, ", c2.reltablespace"); if (pset.sversion >= 180000) appendPQExpBufferStr(&buf, ", con.conperiod"); @@ -2682,81 +2682,80 @@ describeOneTableDetails(const char *schemaname, PQclear(result); /* print any row-level policies */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get row-level policies for this table")); - appendPQExpBufferStr(&buf, "SELECT pol.polname,"); - appendPQExpBufferStr(&buf, - " pol.polpermissive,\n"); - appendPQExpBuffer(&buf, - " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" - " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" - " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" - " CASE pol.polcmd\n" - " WHEN 'r' THEN 'SELECT'\n" - " WHEN 'a' THEN 'INSERT'\n" - " WHEN 'w' THEN 'UPDATE'\n" - " WHEN 'd' THEN 'DELETE'\n" - " END AS cmd\n" - "FROM pg_catalog.pg_policy pol\n" - "WHERE pol.polrelid = '%s' ORDER BY 1;", - oid); + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get row-level policies for this table")); + appendPQExpBufferStr(&buf, "SELECT pol.polname,"); + appendPQExpBufferStr(&buf, + " pol.polpermissive,\n"); + appendPQExpBuffer(&buf, + " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" + " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" + " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" + " CASE pol.polcmd\n" + " WHEN 'r' THEN 'SELECT'\n" + " WHEN 'a' THEN 'INSERT'\n" + " WHEN 'w' THEN 'UPDATE'\n" + " WHEN 'd' THEN 'DELETE'\n" + " END AS cmd\n" + "FROM pg_catalog.pg_policy pol\n" + "WHERE pol.polrelid = '%s' ORDER BY 1;", + oid); - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - /* - * Handle cases where RLS is enabled and there are policies, or - * there aren't policies, or RLS isn't enabled but there are - * policies - */ - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies:")); + /* + * Handle cases where RLS is enabled and there are policies, or there + * aren't policies, or RLS isn't enabled but there are policies + */ + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies:")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled):")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled):")); - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); - if (!tableinfo.rowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (row security disabled):")); + if (!tableinfo.rowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (row security disabled):")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " POLICY \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " POLICY \"%s\"", + PQgetvalue(result, i, 0)); - if (*(PQgetvalue(result, i, 1)) == 'f') - appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); + if (*(PQgetvalue(result, i, 1)) == 'f') + appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); - if (!PQgetisnull(result, i, 5)) - appendPQExpBuffer(&buf, " FOR %s", - PQgetvalue(result, i, 5)); + if (!PQgetisnull(result, i, 5)) + appendPQExpBuffer(&buf, " FOR %s", + PQgetvalue(result, i, 5)); - if (!PQgetisnull(result, i, 2)) - { - appendPQExpBuffer(&buf, "\n TO %s", - PQgetvalue(result, i, 2)); - } + if (!PQgetisnull(result, i, 2)) + { + appendPQExpBuffer(&buf, "\n TO %s", + PQgetvalue(result, i, 2)); + } - if (!PQgetisnull(result, i, 3)) - appendPQExpBuffer(&buf, "\n USING (%s)", - PQgetvalue(result, i, 3)); + if (!PQgetisnull(result, i, 3)) + appendPQExpBuffer(&buf, "\n USING (%s)", + PQgetvalue(result, i, 3)); - if (!PQgetisnull(result, i, 4)) - appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", - PQgetvalue(result, i, 4)); + if (!PQgetisnull(result, i, 4)) + appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", + PQgetvalue(result, i, 4)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* print any extended statistics */ if (pset.sversion >= 140000) @@ -3025,115 +3024,115 @@ describeOneTableDetails(const char *schemaname, } /* print any publications */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get publications that publish this table")); - if (pset.sversion >= 150000) + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get publications that publish this table")); + if (pset.sversion >= 150000) + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" + " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" + "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" + "UNION\n" + "SELECT pubname\n" + " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" + " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" + " (SELECT pg_catalog.string_agg(attname, ', ')\n" + " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" + " pg_catalog.pg_attribute\n" + " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" + " ELSE NULL END) " + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" + "WHERE pr.prrelid = '%s'\n", + oid, oid, oid); + + if (pset.sversion >= 190000) { + /* + * Skip entries where this relation appears in the + * publication's EXCEPT list. + */ appendPQExpBuffer(&buf, + " AND NOT pr.prexcept\n" + "UNION\n" "SELECT pubname\n" " , NULL\n" " , NULL\n" "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" - " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" - "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" - "UNION\n" - "SELECT pubname\n" - " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" - " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" - " (SELECT pg_catalog.string_agg(attname, ', ')\n" - " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" - " pg_catalog.pg_attribute\n" - " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" - " ELSE NULL END) " - "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" - "WHERE pr.prrelid = '%s'\n", + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + " AND NOT EXISTS (\n" + " SELECT 1\n" + " FROM pg_catalog.pg_publication_rel pr\n" + " WHERE pr.prpubid = p.oid AND\n" + " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" + "ORDER BY 1;", oid, oid, oid); - - if (pset.sversion >= 190000) - { - /* - * Skip entries where this relation appears in the - * publication's EXCEPT list. - */ - appendPQExpBuffer(&buf, - " AND NOT pr.prexcept\n" - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - " AND NOT EXISTS (\n" - " SELECT 1\n" - " FROM pg_catalog.pg_publication_rel pr\n" - " WHERE pr.prpubid = p.oid AND\n" - " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" - "ORDER BY 1;", - oid, oid, oid); - } - else - { - appendPQExpBuffer(&buf, - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - "ORDER BY 1;", - oid); - } } else { appendPQExpBuffer(&buf, + "UNION\n" "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - "WHERE pr.prrelid = '%s'\n" - "UNION ALL\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" + " , NULL\n" + " , NULL\n" "FROM pg_catalog.pg_publication p\n" "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" "ORDER BY 1;", - oid, oid); + oid); } + } + else + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + "WHERE pr.prrelid = '%s'\n" + "UNION ALL\n" + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + "ORDER BY 1;", + oid, oid); + } - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - if (tuples > 0) - printTableAddFooter(&cont, _("Included in publications:")); + if (tuples > 0) + printTableAddFooter(&cont, _("Included in publications:")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " \"%s\"", + PQgetvalue(result, i, 0)); - /* column list (if any) */ - if (!PQgetisnull(result, i, 2)) - appendPQExpBuffer(&buf, " (%s)", - PQgetvalue(result, i, 2)); + /* column list (if any) */ + if (!PQgetisnull(result, i, 2)) + appendPQExpBuffer(&buf, " (%s)", + PQgetvalue(result, i, 2)); - /* row filter (if any) */ - if (!PQgetisnull(result, i, 1)) - appendPQExpBuffer(&buf, " WHERE %s", - PQgetvalue(result, i, 1)); + /* row filter (if any) */ + if (!PQgetisnull(result, i, 1)) + appendPQExpBuffer(&buf, " WHERE %s", + PQgetvalue(result, i, 1)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* Print publications where the table is in the EXCEPT clause */ if (pset.sversion >= 190000) @@ -3805,7 +3804,7 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) ncols++; } appendPQExpBufferStr(&buf, "\n, r.rolreplication"); - appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); + appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_roles r\n"); @@ -3860,8 +3859,8 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) if (strcmp(PQgetvalue(res, i, (verbose ? 9 : 8)), "t") == 0) add_role_attribute(&buf, _("Replication")); - if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) - add_role_attribute(&buf, _("Bypass RLS")); + if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) + add_role_attribute(&buf, _("Bypass RLS")); conns = atoi(PQgetvalue(res, i, 6)); if (conns >= 0) @@ -5155,14 +5154,14 @@ listCollations(const char *pattern, bool verbose, bool showSystem) gettext_noop("Schema"), gettext_noop("Name")); - appendPQExpBuffer(&buf, - " CASE c.collprovider " - "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " - "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " - "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " - "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " - "END AS \"%s\",\n", - gettext_noop("Provider")); + appendPQExpBuffer(&buf, + " CASE c.collprovider " + "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " + "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " + "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " + "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " + "END AS \"%s\",\n", + gettext_noop("Provider")); appendPQExpBuffer(&buf, " c.collcollate AS \"%s\",\n" -- 2.50.1 (Apple Git-155) --aHl3HfeiUuO3zeNC-- ^ permalink raw reply [nested|flat] 59+ messages in thread
* [PATCH v6 4/4] run pgindent and pgperltidy @ 2026-06-30 18:24 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 59+ messages in thread From: Nathan Bossart @ 2026-06-30 18:24 UTC (permalink / raw) --- src/bin/pg_dump/pg_dump.c | 464 ++++++++++----------- src/bin/pg_dump/pg_dumpall.c | 30 +- src/bin/pg_upgrade/check.c | 16 +- src/bin/pg_upgrade/controldata.c | 2 +- src/bin/pg_upgrade/exec.c | 8 +- src/bin/pg_upgrade/multixact_rewrite.c | 80 ++-- src/bin/pg_upgrade/pg_upgrade.c | 34 +- src/bin/pg_upgrade/relfilenumber.c | 54 +-- src/bin/pg_upgrade/t/006_transfer_modes.pl | 33 +- src/bin/psql/command.c | 29 +- src/bin/psql/describe.c | 461 ++++++++++---------- 11 files changed, 601 insertions(+), 610 deletions(-) diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 65bd15ebfd2..5673268b467 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -1491,8 +1491,8 @@ setup_connection(Archive *AH, const char *dumpencoding, * Disable timeouts if supported. */ ExecuteSqlStatement(AH, "SET statement_timeout = 0"); - ExecuteSqlStatement(AH, "SET lock_timeout = 0"); - ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); + ExecuteSqlStatement(AH, "SET lock_timeout = 0"); + ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); if (AH->remoteVersion >= 170000) ExecuteSqlStatement(AH, "SET transaction_timeout = 0"); @@ -1505,10 +1505,10 @@ setup_connection(Archive *AH, const char *dumpencoding, /* * Adjust row-security mode, if supported. */ - if (dopt->enable_row_security) - ExecuteSqlStatement(AH, "SET row_security = on"); - else - ExecuteSqlStatement(AH, "SET row_security = off"); + if (dopt->enable_row_security) + ExecuteSqlStatement(AH, "SET row_security = on"); + else + ExecuteSqlStatement(AH, "SET row_security = off"); /* * For security reasons, we restrict the expansion of non-system views and @@ -1933,10 +1933,9 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) addObjectDependency(dobj, ext->dobj.dumpId); /* - * Mark the member object to have any non-initial ACLs - * dumped. (Any initial ACLs will be removed later, using data from - * pg_init_privs, so that we'll dump only the delta from the extension's - * initial setup.) + * Mark the member object to have any non-initial ACLs dumped. (Any + * initial ACLs will be removed later, using data from pg_init_privs, so + * that we'll dump only the delta from the extension's initial setup.) * * In binary upgrades, we still dump all components of the members * individually, since the idea is to exactly reproduce the database @@ -1953,7 +1952,7 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) if (fout->dopt->binary_upgrade) dobj->dump = ext->dobj.dump; else - dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); + dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); return true; } @@ -1987,9 +1986,9 @@ selectDumpableNamespace(NamespaceInfo *nsinfo, Archive *fout) else if (strcmp(nsinfo->dobj.name, "pg_catalog") == 0) { /* - * We dump out any ACLs defined in pg_catalog, if - * they are interesting (and not the original ACLs which were set at - * initdb time, see pg_init_privs). + * We dump out any ACLs defined in pg_catalog, if they are interesting + * (and not the original ACLs which were set at initdb time, see + * pg_init_privs). */ nsinfo->dobj.dump_contains = nsinfo->dobj.dump = DUMP_COMPONENT_ACL; } @@ -3296,7 +3295,7 @@ dumpDatabase(Archive *fout) "datcollate, datctype, datfrozenxid, " "datacl, acldefault('d', datdba) AS acldefault, " "datistemplate, datconnlimit, "); - appendPQExpBufferStr(dbQry, "datminmxid, "); + appendPQExpBufferStr(dbQry, "datminmxid, "); if (fout->remoteVersion >= 170000) appendPQExpBufferStr(dbQry, "datlocprovider, datlocale, datcollversion, "); else if (fout->remoteVersion >= 150000) @@ -3638,11 +3637,11 @@ dumpDatabase(Archive *fout) ii_oid, ii_relminmxid; - appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" - "FROM pg_catalog.pg_class\n" - "WHERE oid IN (%u, %u, %u, %u);\n", - LargeObjectRelationId, LargeObjectLOidPNIndexId, - LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); + appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" + "FROM pg_catalog.pg_class\n" + "WHERE oid IN (%u, %u, %u, %u);\n", + LargeObjectRelationId, LargeObjectLOidPNIndexId, + LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); lo_res = ExecuteSqlQuery(fout, loFrozenQry->data, PGRES_TUPLES_OK); @@ -4274,7 +4273,7 @@ getPolicies(Archive *fout, TableInfo tblinfo[], int numTables) printfPQExpBuffer(query, "SELECT pol.oid, pol.tableoid, pol.polrelid, pol.polname, pol.polcmd, "); - appendPQExpBufferStr(query, "pol.polpermissive, "); + appendPQExpBufferStr(query, "pol.polpermissive, "); appendPQExpBuffer(query, "CASE WHEN pol.polroles = '{0}' THEN NULL ELSE " " pg_catalog.array_to_string(ARRAY(SELECT pg_catalog.quote_ident(rolname) from pg_catalog.pg_roles WHERE oid = ANY(pol.polroles)), ', ') END AS polroles, " @@ -6633,9 +6632,9 @@ getAccessMethods(Archive *fout) * Select all access methods from pg_am table. */ appendPQExpBufferStr(query, "SELECT tableoid, oid, amname, "); - appendPQExpBufferStr(query, - "amtype, " - "amhandler::pg_catalog.regproc AS amhandler "); + appendPQExpBufferStr(query, + "amtype, " + "amhandler::pg_catalog.regproc AS amhandler "); appendPQExpBufferStr(query, "FROM pg_am"); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6827,35 +6826,35 @@ getAggregates(Archive *fout) * Find all interesting aggregates. See comment in getFuncs() for the * rationale behind the filtering logic. */ - agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" - : "p.proisagg"); + agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" + : "p.proisagg"); - appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " - "p.proname AS aggname, " - "p.pronamespace AS aggnamespace, " - "p.pronargs, p.proargtypes, " - "p.proowner, " - "p.proacl AS aggacl, " - "acldefault('f', p.proowner) AS acldefault " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s AND (" - "p.pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog') OR " - "p.proacl IS DISTINCT FROM pip.initprivs", - agg_check); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - " OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); - appendPQExpBufferChar(query, ')'); + appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " + "p.proname AS aggname, " + "p.pronamespace AS aggnamespace, " + "p.pronargs, p.proargtypes, " + "p.proowner, " + "p.proacl AS aggacl, " + "acldefault('f', p.proowner) AS acldefault " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s AND (" + "p.pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog') OR " + "p.proacl IS DISTINCT FROM pip.initprivs", + agg_check); + if (dopt->binary_upgrade) + appendPQExpBufferStr(query, + " OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6957,53 +6956,53 @@ getFuncs(Archive *fout) * include them, since we want to dump extension members individually in * that mode. Also, if they are used by casts or transforms then we need * to gather the information about them, though they won't be dumped if - * they are built-in. Also, include functions in - * pg_catalog if they have an ACL different from what's shown in - * pg_init_privs (so we have to join to pg_init_privs; annoying). + * they are built-in. Also, include functions in pg_catalog if they have + * an ACL different from what's shown in pg_init_privs (so we have to join + * to pg_init_privs; annoying). */ - not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" - : "NOT p.proisagg"); + not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" + : "NOT p.proisagg"); - appendPQExpBuffer(query, - "SELECT p.tableoid, p.oid, p.proname, p.prolang, " - "p.pronargs, p.proargtypes, p.prorettype, " - "p.proacl, " - "acldefault('f', p.proowner) AS acldefault, " - "p.pronamespace, " - "p.proowner " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s" - "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " - "WHERE classid = 'pg_proc'::regclass AND " - "objid = p.oid AND deptype = 'i')" - "\n AND (" - "\n pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog')" - "\n OR EXISTS (SELECT 1 FROM pg_cast" - "\n WHERE pg_cast.oid > %u " - "\n AND p.oid = pg_cast.castfunc)" - "\n OR EXISTS (SELECT 1 FROM pg_transform" - "\n WHERE pg_transform.oid > %u AND " - "\n (p.oid = pg_transform.trffromsql" - "\n OR p.oid = pg_transform.trftosql))", - not_agg_check, - g_last_builtin_oid, - g_last_builtin_oid); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); + appendPQExpBuffer(query, + "SELECT p.tableoid, p.oid, p.proname, p.prolang, " + "p.pronargs, p.proargtypes, p.prorettype, " + "p.proacl, " + "acldefault('f', p.proowner) AS acldefault, " + "p.pronamespace, " + "p.proowner " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s" + "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " + "WHERE classid = 'pg_proc'::regclass AND " + "objid = p.oid AND deptype = 'i')" + "\n AND (" + "\n pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog')" + "\n OR EXISTS (SELECT 1 FROM pg_cast" + "\n WHERE pg_cast.oid > %u " + "\n AND p.oid = pg_cast.castfunc)" + "\n OR EXISTS (SELECT 1 FROM pg_transform" + "\n WHERE pg_transform.oid > %u AND " + "\n (p.oid = pg_transform.trffromsql" + "\n OR p.oid = pg_transform.trftosql))", + not_agg_check, + g_last_builtin_oid, + g_last_builtin_oid); + if (dopt->binary_upgrade) appendPQExpBufferStr(query, - "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); - appendPQExpBufferChar(query, ')'); + "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferStr(query, + "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -7252,31 +7251,31 @@ getTables(Archive *fout, int *numTables) appendPQExpBufferStr(query, "c.relhasoids, "); - appendPQExpBufferStr(query, - "c.relispopulated, "); + appendPQExpBufferStr(query, + "c.relispopulated, "); - appendPQExpBufferStr(query, - "c.relreplident, "); + appendPQExpBufferStr(query, + "c.relreplident, "); - appendPQExpBufferStr(query, - "c.relrowsecurity, c.relforcerowsecurity, "); + appendPQExpBufferStr(query, + "c.relrowsecurity, c.relforcerowsecurity, "); - appendPQExpBufferStr(query, - "c.relminmxid, tc.relminmxid AS tminmxid, "); + appendPQExpBufferStr(query, + "c.relminmxid, tc.relminmxid AS tminmxid, "); - appendPQExpBufferStr(query, - "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); + appendPQExpBufferStr(query, + "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); - appendPQExpBufferStr(query, - "am.amname, "); + appendPQExpBufferStr(query, + "am.amname, "); - appendPQExpBufferStr(query, - "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); + appendPQExpBufferStr(query, + "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); - appendPQExpBufferStr(query, - "c.relispartition AS ispartition "); + appendPQExpBufferStr(query, + "c.relispartition AS ispartition "); /* * Left join to pg_depend to pick up dependency info linking sequences to @@ -7296,8 +7295,8 @@ getTables(Archive *fout, int *numTables) /* * Left join to pg_am to pick up the amname. */ - appendPQExpBufferStr(query, - "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); + appendPQExpBufferStr(query, + "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); /* * We purposefully ignore toast OIDs for partitioned tables; the reason is @@ -7868,8 +7867,8 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables) "t.reloptions AS indreloptions, "); - appendPQExpBufferStr(query, - "i.indisreplident, "); + appendPQExpBufferStr(query, + "i.indisreplident, "); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -9313,8 +9312,8 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables) appendPQExpBufferStr(q, "'' AS attcompression,\n"); - appendPQExpBufferStr(q, - "a.attidentity,\n"); + appendPQExpBufferStr(q, + "a.attidentity,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(q, @@ -10717,73 +10716,73 @@ getAdditionalACLs(Archive *fout) PQclear(res); /* Fetch initial-privileges data */ - printfPQExpBuffer(query, - "SELECT objoid, classoid, objsubid, privtype, initprivs " - "FROM pg_init_privs"); + printfPQExpBuffer(query, + "SELECT objoid, classoid, objsubid, privtype, initprivs " + "FROM pg_init_privs"); - res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); + res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); - ntups = PQntuples(res); - for (i = 0; i < ntups; i++) - { - Oid objoid = atooid(PQgetvalue(res, i, 0)); - Oid classoid = atooid(PQgetvalue(res, i, 1)); - int objsubid = atoi(PQgetvalue(res, i, 2)); - char privtype = *(PQgetvalue(res, i, 3)); - char *initprivs = PQgetvalue(res, i, 4); - CatalogId objId; - DumpableObject *dobj; + ntups = PQntuples(res); + for (i = 0; i < ntups; i++) + { + Oid objoid = atooid(PQgetvalue(res, i, 0)); + Oid classoid = atooid(PQgetvalue(res, i, 1)); + int objsubid = atoi(PQgetvalue(res, i, 2)); + char privtype = *(PQgetvalue(res, i, 3)); + char *initprivs = PQgetvalue(res, i, 4); + CatalogId objId; + DumpableObject *dobj; - objId.tableoid = classoid; - objId.oid = objoid; - dobj = findObjectByCatalogId(objId); - /* OK to ignore entries we haven't got a DumpableObject for */ - if (dobj) + objId.tableoid = classoid; + objId.oid = objoid; + dobj = findObjectByCatalogId(objId); + /* OK to ignore entries we haven't got a DumpableObject for */ + if (dobj) + { + /* Cope with sub-object initprivs */ + if (objsubid != 0) { - /* Cope with sub-object initprivs */ - if (objsubid != 0) - { - if (dobj->objType == DO_TABLE) - { - /* For a column initprivs, set the table's ACL flags */ - dobj->components |= DUMP_COMPONENT_ACL; - ((TableInfo *) dobj)->hascolumnACLs = true; - } - else - pg_log_warning("unsupported pg_init_privs entry: %u %u %d", - classoid, objoid, objsubid); - continue; - } - - /* - * We ignore any pg_init_privs.initprivs entry for the public - * schema, as explained in getNamespaces(). - */ - if (dobj->objType == DO_NAMESPACE && - strcmp(dobj->name, "public") == 0) - continue; - - /* Else it had better be of a type we think has ACLs */ - if (dobj->objType == DO_NAMESPACE || - dobj->objType == DO_TYPE || - dobj->objType == DO_FUNC || - dobj->objType == DO_AGG || - dobj->objType == DO_TABLE || - dobj->objType == DO_PROCLANG || - dobj->objType == DO_FDW || - dobj->objType == DO_FOREIGN_SERVER) + if (dobj->objType == DO_TABLE) { - DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; - - daobj->dacl.privtype = privtype; - daobj->dacl.initprivs = pstrdup(initprivs); + /* For a column initprivs, set the table's ACL flags */ + dobj->components |= DUMP_COMPONENT_ACL; + ((TableInfo *) dobj)->hascolumnACLs = true; } else pg_log_warning("unsupported pg_init_privs entry: %u %u %d", classoid, objoid, objsubid); + continue; + } + + /* + * We ignore any pg_init_privs.initprivs entry for the public + * schema, as explained in getNamespaces(). + */ + if (dobj->objType == DO_NAMESPACE && + strcmp(dobj->name, "public") == 0) + continue; + + /* Else it had better be of a type we think has ACLs */ + if (dobj->objType == DO_NAMESPACE || + dobj->objType == DO_TYPE || + dobj->objType == DO_FUNC || + dobj->objType == DO_AGG || + dobj->objType == DO_TABLE || + dobj->objType == DO_PROCLANG || + dobj->objType == DO_FDW || + dobj->objType == DO_FOREIGN_SERVER) + { + DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; + + daobj->dacl.privtype = privtype; + daobj->dacl.initprivs = pstrdup(initprivs); } + else + pg_log_warning("unsupported pg_init_privs entry: %u %u %d", + classoid, objoid, objsubid); } - PQclear(res); + } + PQclear(res); destroyPQExpBuffer(query); } @@ -11128,8 +11127,8 @@ dumpRelationStats_dumper(Archive *fout, const void *userArg, const TocEntry *te) * The results must be in the order of the relations supplied in the * parameters to ensure we remain in sync as we walk through the TOC. * - * For versions before 19, the redundant filter clause on s.tablename = - * ANY(...) seems sufficient to convince the planner to use + * For versions before 19, the redundant filter clause on s.tablename + * = ANY(...) seems sufficient to convince the planner to use * pg_class_relname_nsp_index, which avoids a full scan of pg_stats. * In newer versions, pg_stats returns the table OIDs, eliminating the * need for that hack. @@ -13469,11 +13468,11 @@ dumpFunc(Archive *fout, const FuncInfo *finfo) "pg_catalog.pg_get_function_result(p.oid) AS funcresult,\n" "proleakproof,\n"); - appendPQExpBufferStr(query, - "array_to_string(protrftypes, ' ') AS protrftypes,\n"); + appendPQExpBufferStr(query, + "array_to_string(protrftypes, ' ') AS protrftypes,\n"); - appendPQExpBufferStr(query, - "proparallel,\n"); + appendPQExpBufferStr(query, + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -14963,9 +14962,9 @@ dumpCollation(Archive *fout, const CollInfo *collinfo) /* Get collation-specific details */ appendPQExpBufferStr(query, "SELECT "); - appendPQExpBufferStr(query, - "collprovider, " - "collversion, "); + appendPQExpBufferStr(query, + "collprovider, " + "collversion, "); if (fout->remoteVersion >= 120000) appendPQExpBufferStr(query, @@ -15372,23 +15371,23 @@ dumpAgg(Archive *fout, const AggInfo *agginfo) "pg_catalog.pg_get_function_arguments(p.oid) AS funcargs,\n" "pg_catalog.pg_get_function_identity_arguments(p.oid) AS funciargs,\n"); - appendPQExpBufferStr(query, - "aggkind,\n" - "aggmtransfn,\n" - "aggminvtransfn,\n" - "aggmfinalfn,\n" - "aggmtranstype::pg_catalog.regtype,\n" - "aggfinalextra,\n" - "aggmfinalextra,\n" - "aggtransspace,\n" - "aggmtransspace,\n" - "aggminitval,\n"); + appendPQExpBufferStr(query, + "aggkind,\n" + "aggmtransfn,\n" + "aggminvtransfn,\n" + "aggmfinalfn,\n" + "aggmtranstype::pg_catalog.regtype,\n" + "aggfinalextra,\n" + "aggmfinalextra,\n" + "aggtransspace,\n" + "aggmtransspace,\n" + "aggminitval,\n"); - appendPQExpBufferStr(query, - "aggcombinefn,\n" - "aggserialfn,\n" - "aggdeserialfn,\n" - "proparallel,\n"); + appendPQExpBufferStr(query, + "aggcombinefn,\n" + "aggserialfn,\n" + "aggdeserialfn,\n" + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -16848,30 +16847,30 @@ dumpTable(Archive *fout, const TableInfo *tbinfo) appendPQExpBufferStr(query, "PREPARE getColumnACLs(pg_catalog.oid) AS\n"); - /* - * In principle we should call acldefault('c', relowner) to - * get the default ACL for a column. However, we don't - * currently store the numeric OID of the relowner in - * TableInfo. We could convert the owner name using regrole, - * but that creates a risk of failure due to concurrent role - * renames. Given that the default ACL for columns is empty - * and is likely to stay that way, it's not worth extra cycles - * and risk to avoid hard-wiring that knowledge here. - */ - appendPQExpBufferStr(query, - "SELECT at.attname, " - "at.attacl, " - "'{}' AS acldefault, " - "pip.privtype, pip.initprivs " - "FROM pg_catalog.pg_attribute at " - "LEFT JOIN pg_catalog.pg_init_privs pip ON " - "(at.attrelid = pip.objoid " - "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " - "AND at.attnum = pip.objsubid) " - "WHERE at.attrelid = $1 AND " - "NOT at.attisdropped " - "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " - "ORDER BY at.attnum"); + /* + * In principle we should call acldefault('c', relowner) to get + * the default ACL for a column. However, we don't currently + * store the numeric OID of the relowner in TableInfo. We could + * convert the owner name using regrole, but that creates a risk + * of failure due to concurrent role renames. Given that the + * default ACL for columns is empty and is likely to stay that + * way, it's not worth extra cycles and risk to avoid hard-wiring + * that knowledge here. + */ + appendPQExpBufferStr(query, + "SELECT at.attname, " + "at.attacl, " + "'{}' AS acldefault, " + "pip.privtype, pip.initprivs " + "FROM pg_catalog.pg_attribute at " + "LEFT JOIN pg_catalog.pg_init_privs pip ON " + "(at.attrelid = pip.objoid " + "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " + "AND at.attnum = pip.objsubid) " + "WHERE at.attrelid = $1 AND " + "NOT at.attisdropped " + "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " + "ORDER BY at.attnum"); ExecuteSqlStatement(fout, query->data); @@ -19165,7 +19164,7 @@ collectSequences(Archive *fout) * pg_get_sequence_data(), but we only do so for non-schema-only dumps. */ if (fout->remoteVersion < 180000 || - (!fout->dopt->dumpData && !fout->dopt->sequence_data)) + (!fout->dopt->dumpData && !fout->dopt->sequence_data)) query = "SELECT seqrelid, format_type(seqtypid, NULL), " "seqstart, seqincrement, " "seqmax, seqmin, " @@ -19227,15 +19226,14 @@ dumpSequence(Archive *fout, const TableInfo *tbinfo) qseqname = pg_strdup(fmtId(tbinfo->dobj.name)); /* - * The sequence information is gathered in a sorted - * table before any calls to dumpSequence(). See collectSequences() for - * more information. + * The sequence information is gathered in a sorted table before any calls + * to dumpSequence(). See collectSequences() for more information. */ - Assert(sequences); + Assert(sequences); - key.oid = tbinfo->dobj.catId.oid; - seq = bsearch(&key, sequences, nsequences, - sizeof(SequenceItem), SequenceItemCmp); + key.oid = tbinfo->dobj.catId.oid; + seq = bsearch(&key, sequences, nsequences, + sizeof(SequenceItem), SequenceItemCmp); /* Calculate default limits for a sequence of this type */ is_ascending = (seq->incby >= 0); diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c index e68937c9934..afcd9a218d8 100644 --- a/src/bin/pg_dump/pg_dumpall.c +++ b/src/bin/pg_dump/pg_dumpall.c @@ -785,11 +785,11 @@ dropRoles(PGconn *conn) int i_rolname; int i; - printfPQExpBuffer(buf, - "SELECT rolname " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 1", role_catalog); + printfPQExpBuffer(buf, + "SELECT rolname " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 1", role_catalog); res = executeQuery(conn, buf->data); @@ -843,16 +843,16 @@ dumpRoles(PGconn *conn) * Notes: rolconfig is dumped later, and pg_authid must be used for * extracting rolcomment regardless of role_catalog. */ - printfPQExpBuffer(buf, - "SELECT oid, rolname, rolsuper, rolinherit, " - "rolcreaterole, rolcreatedb, " - "rolcanlogin, rolconnlimit, rolpassword, " - "rolvaliduntil, rolreplication, rolbypassrls, " - "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " - "rolname = current_user AS is_current_user " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 2", role_catalog); + printfPQExpBuffer(buf, + "SELECT oid, rolname, rolsuper, rolinherit, " + "rolcreaterole, rolcreatedb, " + "rolcanlogin, rolconnlimit, rolpassword, " + "rolvaliduntil, rolreplication, rolbypassrls, " + "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " + "rolname = current_user AS is_current_user " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 2", role_catalog); res = executeQuery(conn, buf->data); diff --git a/src/bin/pg_upgrade/check.c b/src/bin/pg_upgrade/check.c index 786c1474829..f725f5ee3e2 100644 --- a/src/bin/pg_upgrade/check.c +++ b/src/bin/pg_upgrade/check.c @@ -1475,15 +1475,15 @@ check_for_incompatible_polymorphics(ClusterInfo *cluster) ", 'array_cat(anyarray,anyarray)'" ", 'array_prepend(anyelement,anyarray)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_remove(anyarray,anyelement)'" - ", 'array_replace(anyarray,anyelement,anyelement)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_remove(anyarray,anyelement)'" + ", 'array_replace(anyarray,anyelement,anyelement)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_position(anyarray,anyelement)'" - ", 'array_position(anyarray,anyelement,integer)'" - ", 'array_positions(anyarray,anyelement)'" - ", 'width_bucket(anyelement,anyarray)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_position(anyarray,anyelement)'" + ", 'array_position(anyarray,anyelement,integer)'" + ", 'array_positions(anyarray,anyelement)'" + ", 'width_bucket(anyelement,anyarray)'"); /* * The query below hardcodes FirstNormalObjectId as 16384 rather than diff --git a/src/bin/pg_upgrade/controldata.c b/src/bin/pg_upgrade/controldata.c index 8f81c9e9582..02ea02df60f 100644 --- a/src/bin/pg_upgrade/controldata.c +++ b/src/bin/pg_upgrade/controldata.c @@ -228,7 +228,7 @@ get_control_data(ClusterInfo *cluster) p++; /* remove ':' char */ cluster->controldata.chkpnt_nxtepoch = str2uint(p); - p = strchr(p, ':'); + p = strchr(p, ':'); if (p == NULL || strlen(p) <= 1) pg_fatal("%d: controldata retrieval problem", __LINE__); diff --git a/src/bin/pg_upgrade/exec.c b/src/bin/pg_upgrade/exec.c index 44355feea30..a1bdbf373e3 100644 --- a/src/bin/pg_upgrade/exec.c +++ b/src/bin/pg_upgrade/exec.c @@ -55,7 +55,7 @@ get_bin_version(ClusterInfo *cluster) if (sscanf(cmd_output, "%*s %*s %d.%d", &v1, &v2) < 1) pg_fatal("could not get pg_ctl version output from %s", cmd); - cluster->bin_version = v1 * 10000; + cluster->bin_version = v1 * 10000; } @@ -344,8 +344,8 @@ check_data_dir(ClusterInfo *cluster) check_single_dir(pg_data, "pg_subtrans"); check_single_dir(pg_data, PG_TBLSPC_DIR); check_single_dir(pg_data, "pg_twophase"); - check_single_dir(pg_data, "pg_wal"); - check_single_dir(pg_data, "pg_xact"); + check_single_dir(pg_data, "pg_wal"); + check_single_dir(pg_data, "pg_xact"); } @@ -385,7 +385,7 @@ check_bin_dir(ClusterInfo *cluster, bool check_versions) */ get_bin_version(cluster); - check_exec(cluster->bindir, "pg_resetwal", check_versions); + check_exec(cluster->bindir, "pg_resetwal", check_versions); if (cluster == &new_cluster) { diff --git a/src/bin/pg_upgrade/multixact_rewrite.c b/src/bin/pg_upgrade/multixact_rewrite.c index c45b3183684..c7a1416494d 100644 --- a/src/bin/pg_upgrade/multixact_rewrite.c +++ b/src/bin/pg_upgrade/multixact_rewrite.c @@ -61,52 +61,52 @@ rewrite_multixacts(MultiXactId from_multi, MultiXactId to_multi) * Convert old multixids, if needed, by reading them one-by-one from the * old cluster. */ - old_reader = AllocOldMultiXactRead(old_cluster.pgdata, - old_cluster.controldata.chkpnt_nxtmulti, - old_cluster.controldata.chkpnt_nxtmxoff); + old_reader = AllocOldMultiXactRead(old_cluster.pgdata, + old_cluster.controldata.chkpnt_nxtmulti, + old_cluster.controldata.chkpnt_nxtmxoff); - for (MultiXactId multi = from_multi; multi != to_multi;) - { - MultiXactMember member; - bool multixid_valid; - - /* - * Read this multixid's members. - * - * Locking-only XIDs that may be part of multi-xids don't matter - * after upgrade, as there can be no transactions running across - * upgrade. So as a small optimization, we only read one member - * from each multixid: the one updating one, or if there was no - * update, arbitrarily the first locking xid. - */ - multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); + for (MultiXactId multi = from_multi; multi != to_multi;) + { + MultiXactMember member; + bool multixid_valid; - /* - * Write the new offset to pg_multixact/offsets. - * - * Even if this multixid is invalid, we still need to write its - * offset if the *previous* multixid was valid. That's because - * when reading a multixid, the number of members is calculated - * from the difference between the two offsets. - */ - RecordMultiXactOffset(offsets_writer, multi, - (multixid_valid || prev_multixid_valid) ? next_offset : 0); + /* + * Read this multixid's members. + * + * Locking-only XIDs that may be part of multi-xids don't matter after + * upgrade, as there can be no transactions running across upgrade. So + * as a small optimization, we only read one member from each + * multixid: the one updating one, or if there was no update, + * arbitrarily the first locking xid. + */ + multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); - /* Write the members */ - if (multixid_valid) - { - RecordMultiXactMembers(members_writer, next_offset, 1, &member); - next_offset += 1; - } + /* + * Write the new offset to pg_multixact/offsets. + * + * Even if this multixid is invalid, we still need to write its offset + * if the *previous* multixid was valid. That's because when reading + * a multixid, the number of members is calculated from the difference + * between the two offsets. + */ + RecordMultiXactOffset(offsets_writer, multi, + (multixid_valid || prev_multixid_valid) ? next_offset : 0); - /* Advance to next multixid, handling wraparound */ - multi++; - if (multi < FirstMultiXactId) - multi = FirstMultiXactId; - prev_multixid_valid = multixid_valid; + /* Write the members */ + if (multixid_valid) + { + RecordMultiXactMembers(members_writer, next_offset, 1, &member); + next_offset += 1; } - FreeOldMultiXactReader(old_reader); + /* Advance to next multixid, handling wraparound */ + multi++; + if (multi < FirstMultiXactId) + multi = FirstMultiXactId; + prev_multixid_valid = multixid_valid; + } + + FreeOldMultiXactReader(old_reader); /* Write the final 'next' offset to the last SLRU page */ RecordMultiXactOffset(offsets_writer, to_multi, diff --git a/src/bin/pg_upgrade/pg_upgrade.c b/src/bin/pg_upgrade/pg_upgrade.c index c6af9035665..7366fd4627c 100644 --- a/src/bin/pg_upgrade/pg_upgrade.c +++ b/src/bin/pg_upgrade/pg_upgrade.c @@ -833,7 +833,7 @@ copy_xact_xlog_xid(void) * Determine the range of multixacts to convert. */ nxtmulti = old_cluster.controldata.chkpnt_nxtmulti; - oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; + oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; /* handle wraparound */ if (nxtmulti < FirstMultiXactId) nxtmulti = FirstMultiXactId; @@ -898,15 +898,15 @@ set_frozenxids(void) int i_datname; int i_datallowconn; - prep_status("Setting frozenxid and minmxid counters in new cluster"); + prep_status("Setting frozenxid and minmxid counters in new cluster"); conn_template1 = connectToServer(&new_cluster, "template1"); - /* set pg_database.datfrozenxid */ - PQclear(executeQueryOrDie(conn_template1, - "UPDATE pg_catalog.pg_database " - "SET datfrozenxid = '%u'", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_database.datfrozenxid */ + PQclear(executeQueryOrDie(conn_template1, + "UPDATE pg_catalog.pg_database " + "SET datfrozenxid = '%u'", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_database.datminmxid */ PQclear(executeQueryOrDie(conn_template1, @@ -942,16 +942,16 @@ set_frozenxids(void) conn = connectToServer(&new_cluster, datname); - /* set pg_class.relfrozenxid */ - PQclear(executeQueryOrDie(conn, - "UPDATE pg_catalog.pg_class " - "SET relfrozenxid = '%u' " - /* only heap, materialized view, and TOAST are vacuumed */ - "WHERE relkind IN (" - CppAsString2(RELKIND_RELATION) ", " - CppAsString2(RELKIND_MATVIEW) ", " - CppAsString2(RELKIND_TOASTVALUE) ")", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_class.relfrozenxid */ + PQclear(executeQueryOrDie(conn, + "UPDATE pg_catalog.pg_class " + "SET relfrozenxid = '%u' " + /* only heap, materialized view, and TOAST are vacuumed */ + "WHERE relkind IN (" + CppAsString2(RELKIND_RELATION) ", " + CppAsString2(RELKIND_MATVIEW) ", " + CppAsString2(RELKIND_TOASTVALUE) ")", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_class.relminmxid */ PQclear(executeQueryOrDie(conn, diff --git a/src/bin/pg_upgrade/relfilenumber.c b/src/bin/pg_upgrade/relfilenumber.c index ec2ff7acb21..6c467bdc8a5 100644 --- a/src/bin/pg_upgrade/relfilenumber.c +++ b/src/bin/pg_upgrade/relfilenumber.c @@ -587,32 +587,32 @@ transfer_relfile(FileNameMap *map, const char *type_suffix) /* Copying files might take some time, so give feedback. */ pg_log(PG_STATUS, "%s", old_file); - switch (user_opts.transfer_mode) - { - case TRANSFER_MODE_CLONE: - pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", - old_file, new_file); - cloneFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", - old_file, new_file); - copyFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY_FILE_RANGE: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", - old_file, new_file); - copyFileByRange(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_LINK: - pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", - old_file, new_file); - linkFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_SWAP: - /* swap mode is handled in its own code path */ - pg_fatal("should never happen"); - break; - } + switch (user_opts.transfer_mode) + { + case TRANSFER_MODE_CLONE: + pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", + old_file, new_file); + cloneFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", + old_file, new_file); + copyFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY_FILE_RANGE: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", + old_file, new_file); + copyFileByRange(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_LINK: + pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", + old_file, new_file); + linkFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_SWAP: + /* swap mode is handled in its own code path */ + pg_fatal("should never happen"); + break; + } } } diff --git a/src/bin/pg_upgrade/t/006_transfer_modes.pl b/src/bin/pg_upgrade/t/006_transfer_modes.pl index 9efa5dc863c..360d05c4b68 100644 --- a/src/bin/pg_upgrade/t/006_transfer_modes.pl +++ b/src/bin/pg_upgrade/t/006_transfer_modes.pl @@ -29,10 +29,8 @@ sub test_mode } $new->init(); - $new->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); - $old->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); + $new->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); + $old->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); # We can only test security labels if both the old and new installations # have dummy_seclabel. @@ -76,15 +74,14 @@ sub test_mode "CREATE TABLE test4 AS SELECT generate_series(400, 502)"); } - $old->safe_psql('postgres', - "CREATE TABLESPACE inplc_tblspc LOCATION ''"); - $old->safe_psql('postgres', - "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); - $old->safe_psql('postgres', - "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" - ); - $old->safe_psql('testdb3', - "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); + $old->safe_psql('postgres', "CREATE TABLESPACE inplc_tblspc LOCATION ''"); + $old->safe_psql('postgres', + "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); + $old->safe_psql('postgres', + "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" + ); + $old->safe_psql('testdb3', + "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); # While we are here, test handling of large objects. $old->safe_psql( @@ -152,12 +149,10 @@ sub test_mode } # Tests for in-place tablespaces. - $result = - $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); - is($result, '104', "test5 data after pg_upgrade $mode"); - $result = - $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); - is($result, '105', "test6 data after pg_upgrade $mode"); + $result = $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); + is($result, '104', "test5 data after pg_upgrade $mode"); + $result = $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); + is($result, '105', "test6 data after pg_upgrade $mode"); # Tests for large objects $result = $new->safe_psql('postgres', "SELECT lo_get(4532)"); diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index 44ef11d980e..c90bf8bbde2 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -6278,23 +6278,22 @@ get_create_object_cmd(EditableObjectType obj_type, Oid oid, * ensure the right view gets replaced. Also, check relation kind * to be sure it's a view. * - * Views may have WITH [LOCAL|CASCADED] - * CHECK OPTION. These are not part of the view definition - * returned by pg_get_viewdef() and so need to be retrieved - * separately. Materialized views may have - * arbitrary storage parameter reloptions. + * Views may have WITH [LOCAL|CASCADED] CHECK OPTION. These are + * not part of the view definition returned by pg_get_viewdef() + * and so need to be retrieved separately. Materialized views may + * have arbitrary storage parameter reloptions. */ printfPQExpBuffer(query, "/* %s */\n", _("Get view's definition and details")); - appendPQExpBuffer(query, - "SELECT nspname, relname, relkind, " - "pg_catalog.pg_get_viewdef(c.oid, true), " - "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " - "FROM pg_catalog.pg_class c " - "LEFT JOIN pg_catalog.pg_namespace n " - "ON c.relnamespace = n.oid WHERE c.oid = %u", - oid); + appendPQExpBuffer(query, + "SELECT nspname, relname, relkind, " + "pg_catalog.pg_get_viewdef(c.oid, true), " + "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " + "FROM pg_catalog.pg_class c " + "LEFT JOIN pg_catalog.pg_namespace n " + "ON c.relnamespace = n.oid WHERE c.oid = %u", + oid); break; } diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index ce99137c613..ac0c55e7aa5 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -387,19 +387,19 @@ describeFunctions(const char *functypes, const char *func_pattern, gettext_noop("stable"), gettext_noop("volatile"), gettext_noop("Volatility")); - appendPQExpBuffer(&buf, - ",\n CASE\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" - " END as \"%s\"", - gettext_noop("restricted"), - gettext_noop("safe"), - gettext_noop("unsafe"), - gettext_noop("Parallel")); + appendPQExpBuffer(&buf, + ",\n CASE\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" + " END as \"%s\"", + gettext_noop("restricted"), + gettext_noop("safe"), + gettext_noop("unsafe"), + gettext_noop("Parallel")); appendPQExpBuffer(&buf, ",\n pg_catalog.pg_get_userbyid(p.proowner) as \"%s\"" ",\n CASE WHEN prosecdef THEN '%s' ELSE '%s' END AS \"%s\"" @@ -599,8 +599,8 @@ describeFunctions(const char *functypes, const char *func_pattern, myopt.title = _("List of functions"); myopt.translate_header = true; - myopt.translate_columns = translate_columns; - myopt.n_translate_columns = lengthof(translate_columns); + myopt.translate_columns = translate_columns; + myopt.n_translate_columns = lengthof(translate_columns); printQuery(res, &myopt, pset.queryFout, false, pset.logfile); @@ -1086,38 +1086,38 @@ permissionsList(const char *pattern, bool showSystem) " ), E'\\n') AS \"%s\"", gettext_noop("Column privileges")); - appendPQExpBuffer(&buf, - ",\n pg_catalog.array_to_string(ARRAY(\n" - " SELECT polname\n" - " || CASE WHEN NOT polpermissive THEN\n" - " E' (RESTRICTIVE)'\n" - " ELSE '' END\n" - " || CASE WHEN polcmd != '*' THEN\n" - " E' (' || polcmd::pg_catalog.text || E'):'\n" - " ELSE E':'\n" - " END\n" - " || CASE WHEN polqual IS NOT NULL THEN\n" - " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" - " ELSE E''\n" - " END\n" - " || CASE WHEN polwithcheck IS NOT NULL THEN\n" - " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" - " ELSE E''\n" - " END" - " || CASE WHEN polroles <> '{0}' THEN\n" - " E'\\n to: ' || pg_catalog.array_to_string(\n" - " ARRAY(\n" - " SELECT rolname\n" - " FROM pg_catalog.pg_roles\n" - " WHERE oid = ANY (polroles)\n" - " ORDER BY 1\n" - " ), E', ')\n" - " ELSE E''\n" - " END\n" - " FROM pg_catalog.pg_policy pol\n" - " WHERE polrelid = c.oid), E'\\n')\n" - " AS \"%s\"", - gettext_noop("Policies")); + appendPQExpBuffer(&buf, + ",\n pg_catalog.array_to_string(ARRAY(\n" + " SELECT polname\n" + " || CASE WHEN NOT polpermissive THEN\n" + " E' (RESTRICTIVE)'\n" + " ELSE '' END\n" + " || CASE WHEN polcmd != '*' THEN\n" + " E' (' || polcmd::pg_catalog.text || E'):'\n" + " ELSE E':'\n" + " END\n" + " || CASE WHEN polqual IS NOT NULL THEN\n" + " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" + " ELSE E''\n" + " END\n" + " || CASE WHEN polwithcheck IS NOT NULL THEN\n" + " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" + " ELSE E''\n" + " END" + " || CASE WHEN polroles <> '{0}' THEN\n" + " E'\\n to: ' || pg_catalog.array_to_string(\n" + " ARRAY(\n" + " SELECT rolname\n" + " FROM pg_catalog.pg_roles\n" + " WHERE oid = ANY (polroles)\n" + " ORDER BY 1\n" + " ), E', ')\n" + " ELSE E''\n" + " END\n" + " FROM pg_catalog.pg_policy pol\n" + " WHERE polrelid = c.oid), E'\\n')\n" + " AS \"%s\"", + gettext_noop("Policies")); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_class c\n" " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n" @@ -1675,27 +1675,27 @@ describeOneTableDetails(const char *schemaname, char *footers[3] = {NULL, NULL, NULL}; printfPQExpBuffer(&buf, "/* %s */\n", _("Get sequence information")); - appendPQExpBuffer(&buf, - "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" - " seqstart AS \"%s\",\n" - " seqmin AS \"%s\",\n" - " seqmax AS \"%s\",\n" - " seqincrement AS \"%s\",\n" - " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" - " seqcache AS \"%s\"\n", - gettext_noop("Type"), - gettext_noop("Start"), - gettext_noop("Minimum"), - gettext_noop("Maximum"), - gettext_noop("Increment"), - gettext_noop("yes"), - gettext_noop("no"), - gettext_noop("Cycles?"), - gettext_noop("Cache")); - appendPQExpBuffer(&buf, - "FROM pg_catalog.pg_sequence\n" - "WHERE seqrelid = '%s';", - oid); + appendPQExpBuffer(&buf, + "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" + " seqstart AS \"%s\",\n" + " seqmin AS \"%s\",\n" + " seqmax AS \"%s\",\n" + " seqincrement AS \"%s\",\n" + " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" + " seqcache AS \"%s\"\n", + gettext_noop("Type"), + gettext_noop("Start"), + gettext_noop("Minimum"), + gettext_noop("Maximum"), + gettext_noop("Increment"), + gettext_noop("yes"), + gettext_noop("no"), + gettext_noop("Cycles?"), + gettext_noop("Cache")); + appendPQExpBuffer(&buf, + "FROM pg_catalog.pg_sequence\n" + "WHERE seqrelid = '%s';", + oid); res = PSQLexec(buf.data); if (!res) @@ -1913,7 +1913,7 @@ describeOneTableDetails(const char *schemaname, appendPQExpBufferStr(&buf, ",\n (SELECT c.collname FROM pg_catalog.pg_collation c, pg_catalog.pg_type t\n" " WHERE c.oid = a.attcollation AND t.oid = a.atttypid AND a.attcollation <> t.typcollation) AS attcollation"); attcoll_col = cols++; - appendPQExpBufferStr(&buf, ",\n a.attidentity"); + appendPQExpBufferStr(&buf, ",\n a.attidentity"); attidentity_col = cols++; if (pset.sversion >= 120000) appendPQExpBufferStr(&buf, ",\n a.attgenerated"); @@ -2326,7 +2326,7 @@ describeOneTableDetails(const char *schemaname, CppAsString2(CONSTRAINT_EXCLUSION) ") AND " "condeferred) AS condeferred,\n"); - appendPQExpBufferStr(&buf, "i.indisreplident,\n"); + appendPQExpBufferStr(&buf, "i.indisreplident,\n"); if (pset.sversion >= 150000) appendPQExpBufferStr(&buf, "i.indnullsnotdistinct,\n"); @@ -2431,7 +2431,7 @@ describeOneTableDetails(const char *schemaname, "pg_catalog.pg_get_indexdef(i.indexrelid, 0, true),\n " "pg_catalog.pg_get_constraintdef(con.oid, true), " "contype, condeferrable, condeferred"); - appendPQExpBufferStr(&buf, ", i.indisreplident"); + appendPQExpBufferStr(&buf, ", i.indisreplident"); appendPQExpBufferStr(&buf, ", c2.reltablespace"); if (pset.sversion >= 180000) appendPQExpBufferStr(&buf, ", con.conperiod"); @@ -2682,81 +2682,80 @@ describeOneTableDetails(const char *schemaname, PQclear(result); /* print any row-level policies */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get row-level policies for this table")); - appendPQExpBufferStr(&buf, "SELECT pol.polname,"); - appendPQExpBufferStr(&buf, - " pol.polpermissive,\n"); - appendPQExpBuffer(&buf, - " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" - " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" - " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" - " CASE pol.polcmd\n" - " WHEN 'r' THEN 'SELECT'\n" - " WHEN 'a' THEN 'INSERT'\n" - " WHEN 'w' THEN 'UPDATE'\n" - " WHEN 'd' THEN 'DELETE'\n" - " END AS cmd\n" - "FROM pg_catalog.pg_policy pol\n" - "WHERE pol.polrelid = '%s' ORDER BY 1;", - oid); + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get row-level policies for this table")); + appendPQExpBufferStr(&buf, "SELECT pol.polname,"); + appendPQExpBufferStr(&buf, + " pol.polpermissive,\n"); + appendPQExpBuffer(&buf, + " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" + " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" + " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" + " CASE pol.polcmd\n" + " WHEN 'r' THEN 'SELECT'\n" + " WHEN 'a' THEN 'INSERT'\n" + " WHEN 'w' THEN 'UPDATE'\n" + " WHEN 'd' THEN 'DELETE'\n" + " END AS cmd\n" + "FROM pg_catalog.pg_policy pol\n" + "WHERE pol.polrelid = '%s' ORDER BY 1;", + oid); - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - /* - * Handle cases where RLS is enabled and there are policies, or - * there aren't policies, or RLS isn't enabled but there are - * policies - */ - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies:")); + /* + * Handle cases where RLS is enabled and there are policies, or there + * aren't policies, or RLS isn't enabled but there are policies + */ + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies:")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled):")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled):")); - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); - if (!tableinfo.rowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (row security disabled):")); + if (!tableinfo.rowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (row security disabled):")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " POLICY \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " POLICY \"%s\"", + PQgetvalue(result, i, 0)); - if (*(PQgetvalue(result, i, 1)) == 'f') - appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); + if (*(PQgetvalue(result, i, 1)) == 'f') + appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); - if (!PQgetisnull(result, i, 5)) - appendPQExpBuffer(&buf, " FOR %s", - PQgetvalue(result, i, 5)); + if (!PQgetisnull(result, i, 5)) + appendPQExpBuffer(&buf, " FOR %s", + PQgetvalue(result, i, 5)); - if (!PQgetisnull(result, i, 2)) - { - appendPQExpBuffer(&buf, "\n TO %s", - PQgetvalue(result, i, 2)); - } + if (!PQgetisnull(result, i, 2)) + { + appendPQExpBuffer(&buf, "\n TO %s", + PQgetvalue(result, i, 2)); + } - if (!PQgetisnull(result, i, 3)) - appendPQExpBuffer(&buf, "\n USING (%s)", - PQgetvalue(result, i, 3)); + if (!PQgetisnull(result, i, 3)) + appendPQExpBuffer(&buf, "\n USING (%s)", + PQgetvalue(result, i, 3)); - if (!PQgetisnull(result, i, 4)) - appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", - PQgetvalue(result, i, 4)); + if (!PQgetisnull(result, i, 4)) + appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", + PQgetvalue(result, i, 4)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* print any extended statistics */ if (pset.sversion >= 140000) @@ -3025,115 +3024,115 @@ describeOneTableDetails(const char *schemaname, } /* print any publications */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get publications that publish this table")); - if (pset.sversion >= 150000) + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get publications that publish this table")); + if (pset.sversion >= 150000) + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" + " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" + "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" + "UNION\n" + "SELECT pubname\n" + " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" + " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" + " (SELECT pg_catalog.string_agg(attname, ', ')\n" + " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" + " pg_catalog.pg_attribute\n" + " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" + " ELSE NULL END) " + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" + "WHERE pr.prrelid = '%s'\n", + oid, oid, oid); + + if (pset.sversion >= 190000) { + /* + * Skip entries where this relation appears in the + * publication's EXCEPT list. + */ appendPQExpBuffer(&buf, + " AND NOT pr.prexcept\n" + "UNION\n" "SELECT pubname\n" " , NULL\n" " , NULL\n" "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" - " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" - "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" - "UNION\n" - "SELECT pubname\n" - " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" - " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" - " (SELECT pg_catalog.string_agg(attname, ', ')\n" - " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" - " pg_catalog.pg_attribute\n" - " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" - " ELSE NULL END) " - "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" - "WHERE pr.prrelid = '%s'\n", + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + " AND NOT EXISTS (\n" + " SELECT 1\n" + " FROM pg_catalog.pg_publication_rel pr\n" + " WHERE pr.prpubid = p.oid AND\n" + " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" + "ORDER BY 1;", oid, oid, oid); - - if (pset.sversion >= 190000) - { - /* - * Skip entries where this relation appears in the - * publication's EXCEPT list. - */ - appendPQExpBuffer(&buf, - " AND NOT pr.prexcept\n" - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - " AND NOT EXISTS (\n" - " SELECT 1\n" - " FROM pg_catalog.pg_publication_rel pr\n" - " WHERE pr.prpubid = p.oid AND\n" - " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" - "ORDER BY 1;", - oid, oid, oid); - } - else - { - appendPQExpBuffer(&buf, - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - "ORDER BY 1;", - oid); - } } else { appendPQExpBuffer(&buf, + "UNION\n" "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - "WHERE pr.prrelid = '%s'\n" - "UNION ALL\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" + " , NULL\n" + " , NULL\n" "FROM pg_catalog.pg_publication p\n" "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" "ORDER BY 1;", - oid, oid); + oid); } + } + else + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + "WHERE pr.prrelid = '%s'\n" + "UNION ALL\n" + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + "ORDER BY 1;", + oid, oid); + } - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - if (tuples > 0) - printTableAddFooter(&cont, _("Included in publications:")); + if (tuples > 0) + printTableAddFooter(&cont, _("Included in publications:")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " \"%s\"", + PQgetvalue(result, i, 0)); - /* column list (if any) */ - if (!PQgetisnull(result, i, 2)) - appendPQExpBuffer(&buf, " (%s)", - PQgetvalue(result, i, 2)); + /* column list (if any) */ + if (!PQgetisnull(result, i, 2)) + appendPQExpBuffer(&buf, " (%s)", + PQgetvalue(result, i, 2)); - /* row filter (if any) */ - if (!PQgetisnull(result, i, 1)) - appendPQExpBuffer(&buf, " WHERE %s", - PQgetvalue(result, i, 1)); + /* row filter (if any) */ + if (!PQgetisnull(result, i, 1)) + appendPQExpBuffer(&buf, " WHERE %s", + PQgetvalue(result, i, 1)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* Print publications where the table is in the EXCEPT clause */ if (pset.sversion >= 190000) @@ -3805,7 +3804,7 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) ncols++; } appendPQExpBufferStr(&buf, "\n, r.rolreplication"); - appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); + appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_roles r\n"); @@ -3860,8 +3859,8 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) if (strcmp(PQgetvalue(res, i, (verbose ? 9 : 8)), "t") == 0) add_role_attribute(&buf, _("Replication")); - if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) - add_role_attribute(&buf, _("Bypass RLS")); + if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) + add_role_attribute(&buf, _("Bypass RLS")); conns = atoi(PQgetvalue(res, i, 6)); if (conns >= 0) @@ -5155,14 +5154,14 @@ listCollations(const char *pattern, bool verbose, bool showSystem) gettext_noop("Schema"), gettext_noop("Name")); - appendPQExpBuffer(&buf, - " CASE c.collprovider " - "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " - "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " - "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " - "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " - "END AS \"%s\",\n", - gettext_noop("Provider")); + appendPQExpBuffer(&buf, + " CASE c.collprovider " + "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " + "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " + "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " + "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " + "END AS \"%s\",\n", + gettext_noop("Provider")); appendPQExpBuffer(&buf, " c.collcollate AS \"%s\",\n" -- 2.50.1 (Apple Git-155) --aHl3HfeiUuO3zeNC-- ^ permalink raw reply [nested|flat] 59+ messages in thread
* [PATCH v6 4/4] run pgindent and pgperltidy @ 2026-06-30 18:24 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 59+ messages in thread From: Nathan Bossart @ 2026-06-30 18:24 UTC (permalink / raw) --- src/bin/pg_dump/pg_dump.c | 464 ++++++++++----------- src/bin/pg_dump/pg_dumpall.c | 30 +- src/bin/pg_upgrade/check.c | 16 +- src/bin/pg_upgrade/controldata.c | 2 +- src/bin/pg_upgrade/exec.c | 8 +- src/bin/pg_upgrade/multixact_rewrite.c | 80 ++-- src/bin/pg_upgrade/pg_upgrade.c | 34 +- src/bin/pg_upgrade/relfilenumber.c | 54 +-- src/bin/pg_upgrade/t/006_transfer_modes.pl | 33 +- src/bin/psql/command.c | 29 +- src/bin/psql/describe.c | 461 ++++++++++---------- 11 files changed, 601 insertions(+), 610 deletions(-) diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 65bd15ebfd2..5673268b467 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -1491,8 +1491,8 @@ setup_connection(Archive *AH, const char *dumpencoding, * Disable timeouts if supported. */ ExecuteSqlStatement(AH, "SET statement_timeout = 0"); - ExecuteSqlStatement(AH, "SET lock_timeout = 0"); - ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); + ExecuteSqlStatement(AH, "SET lock_timeout = 0"); + ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); if (AH->remoteVersion >= 170000) ExecuteSqlStatement(AH, "SET transaction_timeout = 0"); @@ -1505,10 +1505,10 @@ setup_connection(Archive *AH, const char *dumpencoding, /* * Adjust row-security mode, if supported. */ - if (dopt->enable_row_security) - ExecuteSqlStatement(AH, "SET row_security = on"); - else - ExecuteSqlStatement(AH, "SET row_security = off"); + if (dopt->enable_row_security) + ExecuteSqlStatement(AH, "SET row_security = on"); + else + ExecuteSqlStatement(AH, "SET row_security = off"); /* * For security reasons, we restrict the expansion of non-system views and @@ -1933,10 +1933,9 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) addObjectDependency(dobj, ext->dobj.dumpId); /* - * Mark the member object to have any non-initial ACLs - * dumped. (Any initial ACLs will be removed later, using data from - * pg_init_privs, so that we'll dump only the delta from the extension's - * initial setup.) + * Mark the member object to have any non-initial ACLs dumped. (Any + * initial ACLs will be removed later, using data from pg_init_privs, so + * that we'll dump only the delta from the extension's initial setup.) * * In binary upgrades, we still dump all components of the members * individually, since the idea is to exactly reproduce the database @@ -1953,7 +1952,7 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) if (fout->dopt->binary_upgrade) dobj->dump = ext->dobj.dump; else - dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); + dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); return true; } @@ -1987,9 +1986,9 @@ selectDumpableNamespace(NamespaceInfo *nsinfo, Archive *fout) else if (strcmp(nsinfo->dobj.name, "pg_catalog") == 0) { /* - * We dump out any ACLs defined in pg_catalog, if - * they are interesting (and not the original ACLs which were set at - * initdb time, see pg_init_privs). + * We dump out any ACLs defined in pg_catalog, if they are interesting + * (and not the original ACLs which were set at initdb time, see + * pg_init_privs). */ nsinfo->dobj.dump_contains = nsinfo->dobj.dump = DUMP_COMPONENT_ACL; } @@ -3296,7 +3295,7 @@ dumpDatabase(Archive *fout) "datcollate, datctype, datfrozenxid, " "datacl, acldefault('d', datdba) AS acldefault, " "datistemplate, datconnlimit, "); - appendPQExpBufferStr(dbQry, "datminmxid, "); + appendPQExpBufferStr(dbQry, "datminmxid, "); if (fout->remoteVersion >= 170000) appendPQExpBufferStr(dbQry, "datlocprovider, datlocale, datcollversion, "); else if (fout->remoteVersion >= 150000) @@ -3638,11 +3637,11 @@ dumpDatabase(Archive *fout) ii_oid, ii_relminmxid; - appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" - "FROM pg_catalog.pg_class\n" - "WHERE oid IN (%u, %u, %u, %u);\n", - LargeObjectRelationId, LargeObjectLOidPNIndexId, - LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); + appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" + "FROM pg_catalog.pg_class\n" + "WHERE oid IN (%u, %u, %u, %u);\n", + LargeObjectRelationId, LargeObjectLOidPNIndexId, + LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); lo_res = ExecuteSqlQuery(fout, loFrozenQry->data, PGRES_TUPLES_OK); @@ -4274,7 +4273,7 @@ getPolicies(Archive *fout, TableInfo tblinfo[], int numTables) printfPQExpBuffer(query, "SELECT pol.oid, pol.tableoid, pol.polrelid, pol.polname, pol.polcmd, "); - appendPQExpBufferStr(query, "pol.polpermissive, "); + appendPQExpBufferStr(query, "pol.polpermissive, "); appendPQExpBuffer(query, "CASE WHEN pol.polroles = '{0}' THEN NULL ELSE " " pg_catalog.array_to_string(ARRAY(SELECT pg_catalog.quote_ident(rolname) from pg_catalog.pg_roles WHERE oid = ANY(pol.polroles)), ', ') END AS polroles, " @@ -6633,9 +6632,9 @@ getAccessMethods(Archive *fout) * Select all access methods from pg_am table. */ appendPQExpBufferStr(query, "SELECT tableoid, oid, amname, "); - appendPQExpBufferStr(query, - "amtype, " - "amhandler::pg_catalog.regproc AS amhandler "); + appendPQExpBufferStr(query, + "amtype, " + "amhandler::pg_catalog.regproc AS amhandler "); appendPQExpBufferStr(query, "FROM pg_am"); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6827,35 +6826,35 @@ getAggregates(Archive *fout) * Find all interesting aggregates. See comment in getFuncs() for the * rationale behind the filtering logic. */ - agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" - : "p.proisagg"); + agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" + : "p.proisagg"); - appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " - "p.proname AS aggname, " - "p.pronamespace AS aggnamespace, " - "p.pronargs, p.proargtypes, " - "p.proowner, " - "p.proacl AS aggacl, " - "acldefault('f', p.proowner) AS acldefault " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s AND (" - "p.pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog') OR " - "p.proacl IS DISTINCT FROM pip.initprivs", - agg_check); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - " OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); - appendPQExpBufferChar(query, ')'); + appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " + "p.proname AS aggname, " + "p.pronamespace AS aggnamespace, " + "p.pronargs, p.proargtypes, " + "p.proowner, " + "p.proacl AS aggacl, " + "acldefault('f', p.proowner) AS acldefault " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s AND (" + "p.pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog') OR " + "p.proacl IS DISTINCT FROM pip.initprivs", + agg_check); + if (dopt->binary_upgrade) + appendPQExpBufferStr(query, + " OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6957,53 +6956,53 @@ getFuncs(Archive *fout) * include them, since we want to dump extension members individually in * that mode. Also, if they are used by casts or transforms then we need * to gather the information about them, though they won't be dumped if - * they are built-in. Also, include functions in - * pg_catalog if they have an ACL different from what's shown in - * pg_init_privs (so we have to join to pg_init_privs; annoying). + * they are built-in. Also, include functions in pg_catalog if they have + * an ACL different from what's shown in pg_init_privs (so we have to join + * to pg_init_privs; annoying). */ - not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" - : "NOT p.proisagg"); + not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" + : "NOT p.proisagg"); - appendPQExpBuffer(query, - "SELECT p.tableoid, p.oid, p.proname, p.prolang, " - "p.pronargs, p.proargtypes, p.prorettype, " - "p.proacl, " - "acldefault('f', p.proowner) AS acldefault, " - "p.pronamespace, " - "p.proowner " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s" - "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " - "WHERE classid = 'pg_proc'::regclass AND " - "objid = p.oid AND deptype = 'i')" - "\n AND (" - "\n pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog')" - "\n OR EXISTS (SELECT 1 FROM pg_cast" - "\n WHERE pg_cast.oid > %u " - "\n AND p.oid = pg_cast.castfunc)" - "\n OR EXISTS (SELECT 1 FROM pg_transform" - "\n WHERE pg_transform.oid > %u AND " - "\n (p.oid = pg_transform.trffromsql" - "\n OR p.oid = pg_transform.trftosql))", - not_agg_check, - g_last_builtin_oid, - g_last_builtin_oid); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); + appendPQExpBuffer(query, + "SELECT p.tableoid, p.oid, p.proname, p.prolang, " + "p.pronargs, p.proargtypes, p.prorettype, " + "p.proacl, " + "acldefault('f', p.proowner) AS acldefault, " + "p.pronamespace, " + "p.proowner " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s" + "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " + "WHERE classid = 'pg_proc'::regclass AND " + "objid = p.oid AND deptype = 'i')" + "\n AND (" + "\n pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog')" + "\n OR EXISTS (SELECT 1 FROM pg_cast" + "\n WHERE pg_cast.oid > %u " + "\n AND p.oid = pg_cast.castfunc)" + "\n OR EXISTS (SELECT 1 FROM pg_transform" + "\n WHERE pg_transform.oid > %u AND " + "\n (p.oid = pg_transform.trffromsql" + "\n OR p.oid = pg_transform.trftosql))", + not_agg_check, + g_last_builtin_oid, + g_last_builtin_oid); + if (dopt->binary_upgrade) appendPQExpBufferStr(query, - "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); - appendPQExpBufferChar(query, ')'); + "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferStr(query, + "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -7252,31 +7251,31 @@ getTables(Archive *fout, int *numTables) appendPQExpBufferStr(query, "c.relhasoids, "); - appendPQExpBufferStr(query, - "c.relispopulated, "); + appendPQExpBufferStr(query, + "c.relispopulated, "); - appendPQExpBufferStr(query, - "c.relreplident, "); + appendPQExpBufferStr(query, + "c.relreplident, "); - appendPQExpBufferStr(query, - "c.relrowsecurity, c.relforcerowsecurity, "); + appendPQExpBufferStr(query, + "c.relrowsecurity, c.relforcerowsecurity, "); - appendPQExpBufferStr(query, - "c.relminmxid, tc.relminmxid AS tminmxid, "); + appendPQExpBufferStr(query, + "c.relminmxid, tc.relminmxid AS tminmxid, "); - appendPQExpBufferStr(query, - "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); + appendPQExpBufferStr(query, + "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); - appendPQExpBufferStr(query, - "am.amname, "); + appendPQExpBufferStr(query, + "am.amname, "); - appendPQExpBufferStr(query, - "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); + appendPQExpBufferStr(query, + "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); - appendPQExpBufferStr(query, - "c.relispartition AS ispartition "); + appendPQExpBufferStr(query, + "c.relispartition AS ispartition "); /* * Left join to pg_depend to pick up dependency info linking sequences to @@ -7296,8 +7295,8 @@ getTables(Archive *fout, int *numTables) /* * Left join to pg_am to pick up the amname. */ - appendPQExpBufferStr(query, - "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); + appendPQExpBufferStr(query, + "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); /* * We purposefully ignore toast OIDs for partitioned tables; the reason is @@ -7868,8 +7867,8 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables) "t.reloptions AS indreloptions, "); - appendPQExpBufferStr(query, - "i.indisreplident, "); + appendPQExpBufferStr(query, + "i.indisreplident, "); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -9313,8 +9312,8 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables) appendPQExpBufferStr(q, "'' AS attcompression,\n"); - appendPQExpBufferStr(q, - "a.attidentity,\n"); + appendPQExpBufferStr(q, + "a.attidentity,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(q, @@ -10717,73 +10716,73 @@ getAdditionalACLs(Archive *fout) PQclear(res); /* Fetch initial-privileges data */ - printfPQExpBuffer(query, - "SELECT objoid, classoid, objsubid, privtype, initprivs " - "FROM pg_init_privs"); + printfPQExpBuffer(query, + "SELECT objoid, classoid, objsubid, privtype, initprivs " + "FROM pg_init_privs"); - res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); + res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); - ntups = PQntuples(res); - for (i = 0; i < ntups; i++) - { - Oid objoid = atooid(PQgetvalue(res, i, 0)); - Oid classoid = atooid(PQgetvalue(res, i, 1)); - int objsubid = atoi(PQgetvalue(res, i, 2)); - char privtype = *(PQgetvalue(res, i, 3)); - char *initprivs = PQgetvalue(res, i, 4); - CatalogId objId; - DumpableObject *dobj; + ntups = PQntuples(res); + for (i = 0; i < ntups; i++) + { + Oid objoid = atooid(PQgetvalue(res, i, 0)); + Oid classoid = atooid(PQgetvalue(res, i, 1)); + int objsubid = atoi(PQgetvalue(res, i, 2)); + char privtype = *(PQgetvalue(res, i, 3)); + char *initprivs = PQgetvalue(res, i, 4); + CatalogId objId; + DumpableObject *dobj; - objId.tableoid = classoid; - objId.oid = objoid; - dobj = findObjectByCatalogId(objId); - /* OK to ignore entries we haven't got a DumpableObject for */ - if (dobj) + objId.tableoid = classoid; + objId.oid = objoid; + dobj = findObjectByCatalogId(objId); + /* OK to ignore entries we haven't got a DumpableObject for */ + if (dobj) + { + /* Cope with sub-object initprivs */ + if (objsubid != 0) { - /* Cope with sub-object initprivs */ - if (objsubid != 0) - { - if (dobj->objType == DO_TABLE) - { - /* For a column initprivs, set the table's ACL flags */ - dobj->components |= DUMP_COMPONENT_ACL; - ((TableInfo *) dobj)->hascolumnACLs = true; - } - else - pg_log_warning("unsupported pg_init_privs entry: %u %u %d", - classoid, objoid, objsubid); - continue; - } - - /* - * We ignore any pg_init_privs.initprivs entry for the public - * schema, as explained in getNamespaces(). - */ - if (dobj->objType == DO_NAMESPACE && - strcmp(dobj->name, "public") == 0) - continue; - - /* Else it had better be of a type we think has ACLs */ - if (dobj->objType == DO_NAMESPACE || - dobj->objType == DO_TYPE || - dobj->objType == DO_FUNC || - dobj->objType == DO_AGG || - dobj->objType == DO_TABLE || - dobj->objType == DO_PROCLANG || - dobj->objType == DO_FDW || - dobj->objType == DO_FOREIGN_SERVER) + if (dobj->objType == DO_TABLE) { - DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; - - daobj->dacl.privtype = privtype; - daobj->dacl.initprivs = pstrdup(initprivs); + /* For a column initprivs, set the table's ACL flags */ + dobj->components |= DUMP_COMPONENT_ACL; + ((TableInfo *) dobj)->hascolumnACLs = true; } else pg_log_warning("unsupported pg_init_privs entry: %u %u %d", classoid, objoid, objsubid); + continue; + } + + /* + * We ignore any pg_init_privs.initprivs entry for the public + * schema, as explained in getNamespaces(). + */ + if (dobj->objType == DO_NAMESPACE && + strcmp(dobj->name, "public") == 0) + continue; + + /* Else it had better be of a type we think has ACLs */ + if (dobj->objType == DO_NAMESPACE || + dobj->objType == DO_TYPE || + dobj->objType == DO_FUNC || + dobj->objType == DO_AGG || + dobj->objType == DO_TABLE || + dobj->objType == DO_PROCLANG || + dobj->objType == DO_FDW || + dobj->objType == DO_FOREIGN_SERVER) + { + DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; + + daobj->dacl.privtype = privtype; + daobj->dacl.initprivs = pstrdup(initprivs); } + else + pg_log_warning("unsupported pg_init_privs entry: %u %u %d", + classoid, objoid, objsubid); } - PQclear(res); + } + PQclear(res); destroyPQExpBuffer(query); } @@ -11128,8 +11127,8 @@ dumpRelationStats_dumper(Archive *fout, const void *userArg, const TocEntry *te) * The results must be in the order of the relations supplied in the * parameters to ensure we remain in sync as we walk through the TOC. * - * For versions before 19, the redundant filter clause on s.tablename = - * ANY(...) seems sufficient to convince the planner to use + * For versions before 19, the redundant filter clause on s.tablename + * = ANY(...) seems sufficient to convince the planner to use * pg_class_relname_nsp_index, which avoids a full scan of pg_stats. * In newer versions, pg_stats returns the table OIDs, eliminating the * need for that hack. @@ -13469,11 +13468,11 @@ dumpFunc(Archive *fout, const FuncInfo *finfo) "pg_catalog.pg_get_function_result(p.oid) AS funcresult,\n" "proleakproof,\n"); - appendPQExpBufferStr(query, - "array_to_string(protrftypes, ' ') AS protrftypes,\n"); + appendPQExpBufferStr(query, + "array_to_string(protrftypes, ' ') AS protrftypes,\n"); - appendPQExpBufferStr(query, - "proparallel,\n"); + appendPQExpBufferStr(query, + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -14963,9 +14962,9 @@ dumpCollation(Archive *fout, const CollInfo *collinfo) /* Get collation-specific details */ appendPQExpBufferStr(query, "SELECT "); - appendPQExpBufferStr(query, - "collprovider, " - "collversion, "); + appendPQExpBufferStr(query, + "collprovider, " + "collversion, "); if (fout->remoteVersion >= 120000) appendPQExpBufferStr(query, @@ -15372,23 +15371,23 @@ dumpAgg(Archive *fout, const AggInfo *agginfo) "pg_catalog.pg_get_function_arguments(p.oid) AS funcargs,\n" "pg_catalog.pg_get_function_identity_arguments(p.oid) AS funciargs,\n"); - appendPQExpBufferStr(query, - "aggkind,\n" - "aggmtransfn,\n" - "aggminvtransfn,\n" - "aggmfinalfn,\n" - "aggmtranstype::pg_catalog.regtype,\n" - "aggfinalextra,\n" - "aggmfinalextra,\n" - "aggtransspace,\n" - "aggmtransspace,\n" - "aggminitval,\n"); + appendPQExpBufferStr(query, + "aggkind,\n" + "aggmtransfn,\n" + "aggminvtransfn,\n" + "aggmfinalfn,\n" + "aggmtranstype::pg_catalog.regtype,\n" + "aggfinalextra,\n" + "aggmfinalextra,\n" + "aggtransspace,\n" + "aggmtransspace,\n" + "aggminitval,\n"); - appendPQExpBufferStr(query, - "aggcombinefn,\n" - "aggserialfn,\n" - "aggdeserialfn,\n" - "proparallel,\n"); + appendPQExpBufferStr(query, + "aggcombinefn,\n" + "aggserialfn,\n" + "aggdeserialfn,\n" + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -16848,30 +16847,30 @@ dumpTable(Archive *fout, const TableInfo *tbinfo) appendPQExpBufferStr(query, "PREPARE getColumnACLs(pg_catalog.oid) AS\n"); - /* - * In principle we should call acldefault('c', relowner) to - * get the default ACL for a column. However, we don't - * currently store the numeric OID of the relowner in - * TableInfo. We could convert the owner name using regrole, - * but that creates a risk of failure due to concurrent role - * renames. Given that the default ACL for columns is empty - * and is likely to stay that way, it's not worth extra cycles - * and risk to avoid hard-wiring that knowledge here. - */ - appendPQExpBufferStr(query, - "SELECT at.attname, " - "at.attacl, " - "'{}' AS acldefault, " - "pip.privtype, pip.initprivs " - "FROM pg_catalog.pg_attribute at " - "LEFT JOIN pg_catalog.pg_init_privs pip ON " - "(at.attrelid = pip.objoid " - "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " - "AND at.attnum = pip.objsubid) " - "WHERE at.attrelid = $1 AND " - "NOT at.attisdropped " - "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " - "ORDER BY at.attnum"); + /* + * In principle we should call acldefault('c', relowner) to get + * the default ACL for a column. However, we don't currently + * store the numeric OID of the relowner in TableInfo. We could + * convert the owner name using regrole, but that creates a risk + * of failure due to concurrent role renames. Given that the + * default ACL for columns is empty and is likely to stay that + * way, it's not worth extra cycles and risk to avoid hard-wiring + * that knowledge here. + */ + appendPQExpBufferStr(query, + "SELECT at.attname, " + "at.attacl, " + "'{}' AS acldefault, " + "pip.privtype, pip.initprivs " + "FROM pg_catalog.pg_attribute at " + "LEFT JOIN pg_catalog.pg_init_privs pip ON " + "(at.attrelid = pip.objoid " + "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " + "AND at.attnum = pip.objsubid) " + "WHERE at.attrelid = $1 AND " + "NOT at.attisdropped " + "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " + "ORDER BY at.attnum"); ExecuteSqlStatement(fout, query->data); @@ -19165,7 +19164,7 @@ collectSequences(Archive *fout) * pg_get_sequence_data(), but we only do so for non-schema-only dumps. */ if (fout->remoteVersion < 180000 || - (!fout->dopt->dumpData && !fout->dopt->sequence_data)) + (!fout->dopt->dumpData && !fout->dopt->sequence_data)) query = "SELECT seqrelid, format_type(seqtypid, NULL), " "seqstart, seqincrement, " "seqmax, seqmin, " @@ -19227,15 +19226,14 @@ dumpSequence(Archive *fout, const TableInfo *tbinfo) qseqname = pg_strdup(fmtId(tbinfo->dobj.name)); /* - * The sequence information is gathered in a sorted - * table before any calls to dumpSequence(). See collectSequences() for - * more information. + * The sequence information is gathered in a sorted table before any calls + * to dumpSequence(). See collectSequences() for more information. */ - Assert(sequences); + Assert(sequences); - key.oid = tbinfo->dobj.catId.oid; - seq = bsearch(&key, sequences, nsequences, - sizeof(SequenceItem), SequenceItemCmp); + key.oid = tbinfo->dobj.catId.oid; + seq = bsearch(&key, sequences, nsequences, + sizeof(SequenceItem), SequenceItemCmp); /* Calculate default limits for a sequence of this type */ is_ascending = (seq->incby >= 0); diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c index e68937c9934..afcd9a218d8 100644 --- a/src/bin/pg_dump/pg_dumpall.c +++ b/src/bin/pg_dump/pg_dumpall.c @@ -785,11 +785,11 @@ dropRoles(PGconn *conn) int i_rolname; int i; - printfPQExpBuffer(buf, - "SELECT rolname " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 1", role_catalog); + printfPQExpBuffer(buf, + "SELECT rolname " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 1", role_catalog); res = executeQuery(conn, buf->data); @@ -843,16 +843,16 @@ dumpRoles(PGconn *conn) * Notes: rolconfig is dumped later, and pg_authid must be used for * extracting rolcomment regardless of role_catalog. */ - printfPQExpBuffer(buf, - "SELECT oid, rolname, rolsuper, rolinherit, " - "rolcreaterole, rolcreatedb, " - "rolcanlogin, rolconnlimit, rolpassword, " - "rolvaliduntil, rolreplication, rolbypassrls, " - "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " - "rolname = current_user AS is_current_user " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 2", role_catalog); + printfPQExpBuffer(buf, + "SELECT oid, rolname, rolsuper, rolinherit, " + "rolcreaterole, rolcreatedb, " + "rolcanlogin, rolconnlimit, rolpassword, " + "rolvaliduntil, rolreplication, rolbypassrls, " + "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " + "rolname = current_user AS is_current_user " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 2", role_catalog); res = executeQuery(conn, buf->data); diff --git a/src/bin/pg_upgrade/check.c b/src/bin/pg_upgrade/check.c index 786c1474829..f725f5ee3e2 100644 --- a/src/bin/pg_upgrade/check.c +++ b/src/bin/pg_upgrade/check.c @@ -1475,15 +1475,15 @@ check_for_incompatible_polymorphics(ClusterInfo *cluster) ", 'array_cat(anyarray,anyarray)'" ", 'array_prepend(anyelement,anyarray)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_remove(anyarray,anyelement)'" - ", 'array_replace(anyarray,anyelement,anyelement)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_remove(anyarray,anyelement)'" + ", 'array_replace(anyarray,anyelement,anyelement)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_position(anyarray,anyelement)'" - ", 'array_position(anyarray,anyelement,integer)'" - ", 'array_positions(anyarray,anyelement)'" - ", 'width_bucket(anyelement,anyarray)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_position(anyarray,anyelement)'" + ", 'array_position(anyarray,anyelement,integer)'" + ", 'array_positions(anyarray,anyelement)'" + ", 'width_bucket(anyelement,anyarray)'"); /* * The query below hardcodes FirstNormalObjectId as 16384 rather than diff --git a/src/bin/pg_upgrade/controldata.c b/src/bin/pg_upgrade/controldata.c index 8f81c9e9582..02ea02df60f 100644 --- a/src/bin/pg_upgrade/controldata.c +++ b/src/bin/pg_upgrade/controldata.c @@ -228,7 +228,7 @@ get_control_data(ClusterInfo *cluster) p++; /* remove ':' char */ cluster->controldata.chkpnt_nxtepoch = str2uint(p); - p = strchr(p, ':'); + p = strchr(p, ':'); if (p == NULL || strlen(p) <= 1) pg_fatal("%d: controldata retrieval problem", __LINE__); diff --git a/src/bin/pg_upgrade/exec.c b/src/bin/pg_upgrade/exec.c index 44355feea30..a1bdbf373e3 100644 --- a/src/bin/pg_upgrade/exec.c +++ b/src/bin/pg_upgrade/exec.c @@ -55,7 +55,7 @@ get_bin_version(ClusterInfo *cluster) if (sscanf(cmd_output, "%*s %*s %d.%d", &v1, &v2) < 1) pg_fatal("could not get pg_ctl version output from %s", cmd); - cluster->bin_version = v1 * 10000; + cluster->bin_version = v1 * 10000; } @@ -344,8 +344,8 @@ check_data_dir(ClusterInfo *cluster) check_single_dir(pg_data, "pg_subtrans"); check_single_dir(pg_data, PG_TBLSPC_DIR); check_single_dir(pg_data, "pg_twophase"); - check_single_dir(pg_data, "pg_wal"); - check_single_dir(pg_data, "pg_xact"); + check_single_dir(pg_data, "pg_wal"); + check_single_dir(pg_data, "pg_xact"); } @@ -385,7 +385,7 @@ check_bin_dir(ClusterInfo *cluster, bool check_versions) */ get_bin_version(cluster); - check_exec(cluster->bindir, "pg_resetwal", check_versions); + check_exec(cluster->bindir, "pg_resetwal", check_versions); if (cluster == &new_cluster) { diff --git a/src/bin/pg_upgrade/multixact_rewrite.c b/src/bin/pg_upgrade/multixact_rewrite.c index c45b3183684..c7a1416494d 100644 --- a/src/bin/pg_upgrade/multixact_rewrite.c +++ b/src/bin/pg_upgrade/multixact_rewrite.c @@ -61,52 +61,52 @@ rewrite_multixacts(MultiXactId from_multi, MultiXactId to_multi) * Convert old multixids, if needed, by reading them one-by-one from the * old cluster. */ - old_reader = AllocOldMultiXactRead(old_cluster.pgdata, - old_cluster.controldata.chkpnt_nxtmulti, - old_cluster.controldata.chkpnt_nxtmxoff); + old_reader = AllocOldMultiXactRead(old_cluster.pgdata, + old_cluster.controldata.chkpnt_nxtmulti, + old_cluster.controldata.chkpnt_nxtmxoff); - for (MultiXactId multi = from_multi; multi != to_multi;) - { - MultiXactMember member; - bool multixid_valid; - - /* - * Read this multixid's members. - * - * Locking-only XIDs that may be part of multi-xids don't matter - * after upgrade, as there can be no transactions running across - * upgrade. So as a small optimization, we only read one member - * from each multixid: the one updating one, or if there was no - * update, arbitrarily the first locking xid. - */ - multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); + for (MultiXactId multi = from_multi; multi != to_multi;) + { + MultiXactMember member; + bool multixid_valid; - /* - * Write the new offset to pg_multixact/offsets. - * - * Even if this multixid is invalid, we still need to write its - * offset if the *previous* multixid was valid. That's because - * when reading a multixid, the number of members is calculated - * from the difference between the two offsets. - */ - RecordMultiXactOffset(offsets_writer, multi, - (multixid_valid || prev_multixid_valid) ? next_offset : 0); + /* + * Read this multixid's members. + * + * Locking-only XIDs that may be part of multi-xids don't matter after + * upgrade, as there can be no transactions running across upgrade. So + * as a small optimization, we only read one member from each + * multixid: the one updating one, or if there was no update, + * arbitrarily the first locking xid. + */ + multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); - /* Write the members */ - if (multixid_valid) - { - RecordMultiXactMembers(members_writer, next_offset, 1, &member); - next_offset += 1; - } + /* + * Write the new offset to pg_multixact/offsets. + * + * Even if this multixid is invalid, we still need to write its offset + * if the *previous* multixid was valid. That's because when reading + * a multixid, the number of members is calculated from the difference + * between the two offsets. + */ + RecordMultiXactOffset(offsets_writer, multi, + (multixid_valid || prev_multixid_valid) ? next_offset : 0); - /* Advance to next multixid, handling wraparound */ - multi++; - if (multi < FirstMultiXactId) - multi = FirstMultiXactId; - prev_multixid_valid = multixid_valid; + /* Write the members */ + if (multixid_valid) + { + RecordMultiXactMembers(members_writer, next_offset, 1, &member); + next_offset += 1; } - FreeOldMultiXactReader(old_reader); + /* Advance to next multixid, handling wraparound */ + multi++; + if (multi < FirstMultiXactId) + multi = FirstMultiXactId; + prev_multixid_valid = multixid_valid; + } + + FreeOldMultiXactReader(old_reader); /* Write the final 'next' offset to the last SLRU page */ RecordMultiXactOffset(offsets_writer, to_multi, diff --git a/src/bin/pg_upgrade/pg_upgrade.c b/src/bin/pg_upgrade/pg_upgrade.c index c6af9035665..7366fd4627c 100644 --- a/src/bin/pg_upgrade/pg_upgrade.c +++ b/src/bin/pg_upgrade/pg_upgrade.c @@ -833,7 +833,7 @@ copy_xact_xlog_xid(void) * Determine the range of multixacts to convert. */ nxtmulti = old_cluster.controldata.chkpnt_nxtmulti; - oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; + oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; /* handle wraparound */ if (nxtmulti < FirstMultiXactId) nxtmulti = FirstMultiXactId; @@ -898,15 +898,15 @@ set_frozenxids(void) int i_datname; int i_datallowconn; - prep_status("Setting frozenxid and minmxid counters in new cluster"); + prep_status("Setting frozenxid and minmxid counters in new cluster"); conn_template1 = connectToServer(&new_cluster, "template1"); - /* set pg_database.datfrozenxid */ - PQclear(executeQueryOrDie(conn_template1, - "UPDATE pg_catalog.pg_database " - "SET datfrozenxid = '%u'", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_database.datfrozenxid */ + PQclear(executeQueryOrDie(conn_template1, + "UPDATE pg_catalog.pg_database " + "SET datfrozenxid = '%u'", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_database.datminmxid */ PQclear(executeQueryOrDie(conn_template1, @@ -942,16 +942,16 @@ set_frozenxids(void) conn = connectToServer(&new_cluster, datname); - /* set pg_class.relfrozenxid */ - PQclear(executeQueryOrDie(conn, - "UPDATE pg_catalog.pg_class " - "SET relfrozenxid = '%u' " - /* only heap, materialized view, and TOAST are vacuumed */ - "WHERE relkind IN (" - CppAsString2(RELKIND_RELATION) ", " - CppAsString2(RELKIND_MATVIEW) ", " - CppAsString2(RELKIND_TOASTVALUE) ")", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_class.relfrozenxid */ + PQclear(executeQueryOrDie(conn, + "UPDATE pg_catalog.pg_class " + "SET relfrozenxid = '%u' " + /* only heap, materialized view, and TOAST are vacuumed */ + "WHERE relkind IN (" + CppAsString2(RELKIND_RELATION) ", " + CppAsString2(RELKIND_MATVIEW) ", " + CppAsString2(RELKIND_TOASTVALUE) ")", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_class.relminmxid */ PQclear(executeQueryOrDie(conn, diff --git a/src/bin/pg_upgrade/relfilenumber.c b/src/bin/pg_upgrade/relfilenumber.c index ec2ff7acb21..6c467bdc8a5 100644 --- a/src/bin/pg_upgrade/relfilenumber.c +++ b/src/bin/pg_upgrade/relfilenumber.c @@ -587,32 +587,32 @@ transfer_relfile(FileNameMap *map, const char *type_suffix) /* Copying files might take some time, so give feedback. */ pg_log(PG_STATUS, "%s", old_file); - switch (user_opts.transfer_mode) - { - case TRANSFER_MODE_CLONE: - pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", - old_file, new_file); - cloneFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", - old_file, new_file); - copyFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY_FILE_RANGE: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", - old_file, new_file); - copyFileByRange(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_LINK: - pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", - old_file, new_file); - linkFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_SWAP: - /* swap mode is handled in its own code path */ - pg_fatal("should never happen"); - break; - } + switch (user_opts.transfer_mode) + { + case TRANSFER_MODE_CLONE: + pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", + old_file, new_file); + cloneFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", + old_file, new_file); + copyFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY_FILE_RANGE: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", + old_file, new_file); + copyFileByRange(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_LINK: + pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", + old_file, new_file); + linkFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_SWAP: + /* swap mode is handled in its own code path */ + pg_fatal("should never happen"); + break; + } } } diff --git a/src/bin/pg_upgrade/t/006_transfer_modes.pl b/src/bin/pg_upgrade/t/006_transfer_modes.pl index 9efa5dc863c..360d05c4b68 100644 --- a/src/bin/pg_upgrade/t/006_transfer_modes.pl +++ b/src/bin/pg_upgrade/t/006_transfer_modes.pl @@ -29,10 +29,8 @@ sub test_mode } $new->init(); - $new->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); - $old->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); + $new->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); + $old->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); # We can only test security labels if both the old and new installations # have dummy_seclabel. @@ -76,15 +74,14 @@ sub test_mode "CREATE TABLE test4 AS SELECT generate_series(400, 502)"); } - $old->safe_psql('postgres', - "CREATE TABLESPACE inplc_tblspc LOCATION ''"); - $old->safe_psql('postgres', - "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); - $old->safe_psql('postgres', - "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" - ); - $old->safe_psql('testdb3', - "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); + $old->safe_psql('postgres', "CREATE TABLESPACE inplc_tblspc LOCATION ''"); + $old->safe_psql('postgres', + "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); + $old->safe_psql('postgres', + "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" + ); + $old->safe_psql('testdb3', + "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); # While we are here, test handling of large objects. $old->safe_psql( @@ -152,12 +149,10 @@ sub test_mode } # Tests for in-place tablespaces. - $result = - $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); - is($result, '104', "test5 data after pg_upgrade $mode"); - $result = - $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); - is($result, '105', "test6 data after pg_upgrade $mode"); + $result = $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); + is($result, '104', "test5 data after pg_upgrade $mode"); + $result = $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); + is($result, '105', "test6 data after pg_upgrade $mode"); # Tests for large objects $result = $new->safe_psql('postgres', "SELECT lo_get(4532)"); diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index 44ef11d980e..c90bf8bbde2 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -6278,23 +6278,22 @@ get_create_object_cmd(EditableObjectType obj_type, Oid oid, * ensure the right view gets replaced. Also, check relation kind * to be sure it's a view. * - * Views may have WITH [LOCAL|CASCADED] - * CHECK OPTION. These are not part of the view definition - * returned by pg_get_viewdef() and so need to be retrieved - * separately. Materialized views may have - * arbitrary storage parameter reloptions. + * Views may have WITH [LOCAL|CASCADED] CHECK OPTION. These are + * not part of the view definition returned by pg_get_viewdef() + * and so need to be retrieved separately. Materialized views may + * have arbitrary storage parameter reloptions. */ printfPQExpBuffer(query, "/* %s */\n", _("Get view's definition and details")); - appendPQExpBuffer(query, - "SELECT nspname, relname, relkind, " - "pg_catalog.pg_get_viewdef(c.oid, true), " - "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " - "FROM pg_catalog.pg_class c " - "LEFT JOIN pg_catalog.pg_namespace n " - "ON c.relnamespace = n.oid WHERE c.oid = %u", - oid); + appendPQExpBuffer(query, + "SELECT nspname, relname, relkind, " + "pg_catalog.pg_get_viewdef(c.oid, true), " + "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " + "FROM pg_catalog.pg_class c " + "LEFT JOIN pg_catalog.pg_namespace n " + "ON c.relnamespace = n.oid WHERE c.oid = %u", + oid); break; } diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index ce99137c613..ac0c55e7aa5 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -387,19 +387,19 @@ describeFunctions(const char *functypes, const char *func_pattern, gettext_noop("stable"), gettext_noop("volatile"), gettext_noop("Volatility")); - appendPQExpBuffer(&buf, - ",\n CASE\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" - " END as \"%s\"", - gettext_noop("restricted"), - gettext_noop("safe"), - gettext_noop("unsafe"), - gettext_noop("Parallel")); + appendPQExpBuffer(&buf, + ",\n CASE\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" + " END as \"%s\"", + gettext_noop("restricted"), + gettext_noop("safe"), + gettext_noop("unsafe"), + gettext_noop("Parallel")); appendPQExpBuffer(&buf, ",\n pg_catalog.pg_get_userbyid(p.proowner) as \"%s\"" ",\n CASE WHEN prosecdef THEN '%s' ELSE '%s' END AS \"%s\"" @@ -599,8 +599,8 @@ describeFunctions(const char *functypes, const char *func_pattern, myopt.title = _("List of functions"); myopt.translate_header = true; - myopt.translate_columns = translate_columns; - myopt.n_translate_columns = lengthof(translate_columns); + myopt.translate_columns = translate_columns; + myopt.n_translate_columns = lengthof(translate_columns); printQuery(res, &myopt, pset.queryFout, false, pset.logfile); @@ -1086,38 +1086,38 @@ permissionsList(const char *pattern, bool showSystem) " ), E'\\n') AS \"%s\"", gettext_noop("Column privileges")); - appendPQExpBuffer(&buf, - ",\n pg_catalog.array_to_string(ARRAY(\n" - " SELECT polname\n" - " || CASE WHEN NOT polpermissive THEN\n" - " E' (RESTRICTIVE)'\n" - " ELSE '' END\n" - " || CASE WHEN polcmd != '*' THEN\n" - " E' (' || polcmd::pg_catalog.text || E'):'\n" - " ELSE E':'\n" - " END\n" - " || CASE WHEN polqual IS NOT NULL THEN\n" - " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" - " ELSE E''\n" - " END\n" - " || CASE WHEN polwithcheck IS NOT NULL THEN\n" - " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" - " ELSE E''\n" - " END" - " || CASE WHEN polroles <> '{0}' THEN\n" - " E'\\n to: ' || pg_catalog.array_to_string(\n" - " ARRAY(\n" - " SELECT rolname\n" - " FROM pg_catalog.pg_roles\n" - " WHERE oid = ANY (polroles)\n" - " ORDER BY 1\n" - " ), E', ')\n" - " ELSE E''\n" - " END\n" - " FROM pg_catalog.pg_policy pol\n" - " WHERE polrelid = c.oid), E'\\n')\n" - " AS \"%s\"", - gettext_noop("Policies")); + appendPQExpBuffer(&buf, + ",\n pg_catalog.array_to_string(ARRAY(\n" + " SELECT polname\n" + " || CASE WHEN NOT polpermissive THEN\n" + " E' (RESTRICTIVE)'\n" + " ELSE '' END\n" + " || CASE WHEN polcmd != '*' THEN\n" + " E' (' || polcmd::pg_catalog.text || E'):'\n" + " ELSE E':'\n" + " END\n" + " || CASE WHEN polqual IS NOT NULL THEN\n" + " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" + " ELSE E''\n" + " END\n" + " || CASE WHEN polwithcheck IS NOT NULL THEN\n" + " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" + " ELSE E''\n" + " END" + " || CASE WHEN polroles <> '{0}' THEN\n" + " E'\\n to: ' || pg_catalog.array_to_string(\n" + " ARRAY(\n" + " SELECT rolname\n" + " FROM pg_catalog.pg_roles\n" + " WHERE oid = ANY (polroles)\n" + " ORDER BY 1\n" + " ), E', ')\n" + " ELSE E''\n" + " END\n" + " FROM pg_catalog.pg_policy pol\n" + " WHERE polrelid = c.oid), E'\\n')\n" + " AS \"%s\"", + gettext_noop("Policies")); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_class c\n" " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n" @@ -1675,27 +1675,27 @@ describeOneTableDetails(const char *schemaname, char *footers[3] = {NULL, NULL, NULL}; printfPQExpBuffer(&buf, "/* %s */\n", _("Get sequence information")); - appendPQExpBuffer(&buf, - "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" - " seqstart AS \"%s\",\n" - " seqmin AS \"%s\",\n" - " seqmax AS \"%s\",\n" - " seqincrement AS \"%s\",\n" - " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" - " seqcache AS \"%s\"\n", - gettext_noop("Type"), - gettext_noop("Start"), - gettext_noop("Minimum"), - gettext_noop("Maximum"), - gettext_noop("Increment"), - gettext_noop("yes"), - gettext_noop("no"), - gettext_noop("Cycles?"), - gettext_noop("Cache")); - appendPQExpBuffer(&buf, - "FROM pg_catalog.pg_sequence\n" - "WHERE seqrelid = '%s';", - oid); + appendPQExpBuffer(&buf, + "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" + " seqstart AS \"%s\",\n" + " seqmin AS \"%s\",\n" + " seqmax AS \"%s\",\n" + " seqincrement AS \"%s\",\n" + " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" + " seqcache AS \"%s\"\n", + gettext_noop("Type"), + gettext_noop("Start"), + gettext_noop("Minimum"), + gettext_noop("Maximum"), + gettext_noop("Increment"), + gettext_noop("yes"), + gettext_noop("no"), + gettext_noop("Cycles?"), + gettext_noop("Cache")); + appendPQExpBuffer(&buf, + "FROM pg_catalog.pg_sequence\n" + "WHERE seqrelid = '%s';", + oid); res = PSQLexec(buf.data); if (!res) @@ -1913,7 +1913,7 @@ describeOneTableDetails(const char *schemaname, appendPQExpBufferStr(&buf, ",\n (SELECT c.collname FROM pg_catalog.pg_collation c, pg_catalog.pg_type t\n" " WHERE c.oid = a.attcollation AND t.oid = a.atttypid AND a.attcollation <> t.typcollation) AS attcollation"); attcoll_col = cols++; - appendPQExpBufferStr(&buf, ",\n a.attidentity"); + appendPQExpBufferStr(&buf, ",\n a.attidentity"); attidentity_col = cols++; if (pset.sversion >= 120000) appendPQExpBufferStr(&buf, ",\n a.attgenerated"); @@ -2326,7 +2326,7 @@ describeOneTableDetails(const char *schemaname, CppAsString2(CONSTRAINT_EXCLUSION) ") AND " "condeferred) AS condeferred,\n"); - appendPQExpBufferStr(&buf, "i.indisreplident,\n"); + appendPQExpBufferStr(&buf, "i.indisreplident,\n"); if (pset.sversion >= 150000) appendPQExpBufferStr(&buf, "i.indnullsnotdistinct,\n"); @@ -2431,7 +2431,7 @@ describeOneTableDetails(const char *schemaname, "pg_catalog.pg_get_indexdef(i.indexrelid, 0, true),\n " "pg_catalog.pg_get_constraintdef(con.oid, true), " "contype, condeferrable, condeferred"); - appendPQExpBufferStr(&buf, ", i.indisreplident"); + appendPQExpBufferStr(&buf, ", i.indisreplident"); appendPQExpBufferStr(&buf, ", c2.reltablespace"); if (pset.sversion >= 180000) appendPQExpBufferStr(&buf, ", con.conperiod"); @@ -2682,81 +2682,80 @@ describeOneTableDetails(const char *schemaname, PQclear(result); /* print any row-level policies */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get row-level policies for this table")); - appendPQExpBufferStr(&buf, "SELECT pol.polname,"); - appendPQExpBufferStr(&buf, - " pol.polpermissive,\n"); - appendPQExpBuffer(&buf, - " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" - " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" - " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" - " CASE pol.polcmd\n" - " WHEN 'r' THEN 'SELECT'\n" - " WHEN 'a' THEN 'INSERT'\n" - " WHEN 'w' THEN 'UPDATE'\n" - " WHEN 'd' THEN 'DELETE'\n" - " END AS cmd\n" - "FROM pg_catalog.pg_policy pol\n" - "WHERE pol.polrelid = '%s' ORDER BY 1;", - oid); + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get row-level policies for this table")); + appendPQExpBufferStr(&buf, "SELECT pol.polname,"); + appendPQExpBufferStr(&buf, + " pol.polpermissive,\n"); + appendPQExpBuffer(&buf, + " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" + " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" + " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" + " CASE pol.polcmd\n" + " WHEN 'r' THEN 'SELECT'\n" + " WHEN 'a' THEN 'INSERT'\n" + " WHEN 'w' THEN 'UPDATE'\n" + " WHEN 'd' THEN 'DELETE'\n" + " END AS cmd\n" + "FROM pg_catalog.pg_policy pol\n" + "WHERE pol.polrelid = '%s' ORDER BY 1;", + oid); - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - /* - * Handle cases where RLS is enabled and there are policies, or - * there aren't policies, or RLS isn't enabled but there are - * policies - */ - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies:")); + /* + * Handle cases where RLS is enabled and there are policies, or there + * aren't policies, or RLS isn't enabled but there are policies + */ + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies:")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled):")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled):")); - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); - if (!tableinfo.rowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (row security disabled):")); + if (!tableinfo.rowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (row security disabled):")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " POLICY \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " POLICY \"%s\"", + PQgetvalue(result, i, 0)); - if (*(PQgetvalue(result, i, 1)) == 'f') - appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); + if (*(PQgetvalue(result, i, 1)) == 'f') + appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); - if (!PQgetisnull(result, i, 5)) - appendPQExpBuffer(&buf, " FOR %s", - PQgetvalue(result, i, 5)); + if (!PQgetisnull(result, i, 5)) + appendPQExpBuffer(&buf, " FOR %s", + PQgetvalue(result, i, 5)); - if (!PQgetisnull(result, i, 2)) - { - appendPQExpBuffer(&buf, "\n TO %s", - PQgetvalue(result, i, 2)); - } + if (!PQgetisnull(result, i, 2)) + { + appendPQExpBuffer(&buf, "\n TO %s", + PQgetvalue(result, i, 2)); + } - if (!PQgetisnull(result, i, 3)) - appendPQExpBuffer(&buf, "\n USING (%s)", - PQgetvalue(result, i, 3)); + if (!PQgetisnull(result, i, 3)) + appendPQExpBuffer(&buf, "\n USING (%s)", + PQgetvalue(result, i, 3)); - if (!PQgetisnull(result, i, 4)) - appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", - PQgetvalue(result, i, 4)); + if (!PQgetisnull(result, i, 4)) + appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", + PQgetvalue(result, i, 4)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* print any extended statistics */ if (pset.sversion >= 140000) @@ -3025,115 +3024,115 @@ describeOneTableDetails(const char *schemaname, } /* print any publications */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get publications that publish this table")); - if (pset.sversion >= 150000) + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get publications that publish this table")); + if (pset.sversion >= 150000) + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" + " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" + "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" + "UNION\n" + "SELECT pubname\n" + " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" + " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" + " (SELECT pg_catalog.string_agg(attname, ', ')\n" + " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" + " pg_catalog.pg_attribute\n" + " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" + " ELSE NULL END) " + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" + "WHERE pr.prrelid = '%s'\n", + oid, oid, oid); + + if (pset.sversion >= 190000) { + /* + * Skip entries where this relation appears in the + * publication's EXCEPT list. + */ appendPQExpBuffer(&buf, + " AND NOT pr.prexcept\n" + "UNION\n" "SELECT pubname\n" " , NULL\n" " , NULL\n" "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" - " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" - "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" - "UNION\n" - "SELECT pubname\n" - " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" - " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" - " (SELECT pg_catalog.string_agg(attname, ', ')\n" - " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" - " pg_catalog.pg_attribute\n" - " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" - " ELSE NULL END) " - "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" - "WHERE pr.prrelid = '%s'\n", + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + " AND NOT EXISTS (\n" + " SELECT 1\n" + " FROM pg_catalog.pg_publication_rel pr\n" + " WHERE pr.prpubid = p.oid AND\n" + " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" + "ORDER BY 1;", oid, oid, oid); - - if (pset.sversion >= 190000) - { - /* - * Skip entries where this relation appears in the - * publication's EXCEPT list. - */ - appendPQExpBuffer(&buf, - " AND NOT pr.prexcept\n" - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - " AND NOT EXISTS (\n" - " SELECT 1\n" - " FROM pg_catalog.pg_publication_rel pr\n" - " WHERE pr.prpubid = p.oid AND\n" - " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" - "ORDER BY 1;", - oid, oid, oid); - } - else - { - appendPQExpBuffer(&buf, - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - "ORDER BY 1;", - oid); - } } else { appendPQExpBuffer(&buf, + "UNION\n" "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - "WHERE pr.prrelid = '%s'\n" - "UNION ALL\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" + " , NULL\n" + " , NULL\n" "FROM pg_catalog.pg_publication p\n" "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" "ORDER BY 1;", - oid, oid); + oid); } + } + else + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + "WHERE pr.prrelid = '%s'\n" + "UNION ALL\n" + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + "ORDER BY 1;", + oid, oid); + } - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - if (tuples > 0) - printTableAddFooter(&cont, _("Included in publications:")); + if (tuples > 0) + printTableAddFooter(&cont, _("Included in publications:")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " \"%s\"", + PQgetvalue(result, i, 0)); - /* column list (if any) */ - if (!PQgetisnull(result, i, 2)) - appendPQExpBuffer(&buf, " (%s)", - PQgetvalue(result, i, 2)); + /* column list (if any) */ + if (!PQgetisnull(result, i, 2)) + appendPQExpBuffer(&buf, " (%s)", + PQgetvalue(result, i, 2)); - /* row filter (if any) */ - if (!PQgetisnull(result, i, 1)) - appendPQExpBuffer(&buf, " WHERE %s", - PQgetvalue(result, i, 1)); + /* row filter (if any) */ + if (!PQgetisnull(result, i, 1)) + appendPQExpBuffer(&buf, " WHERE %s", + PQgetvalue(result, i, 1)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* Print publications where the table is in the EXCEPT clause */ if (pset.sversion >= 190000) @@ -3805,7 +3804,7 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) ncols++; } appendPQExpBufferStr(&buf, "\n, r.rolreplication"); - appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); + appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_roles r\n"); @@ -3860,8 +3859,8 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) if (strcmp(PQgetvalue(res, i, (verbose ? 9 : 8)), "t") == 0) add_role_attribute(&buf, _("Replication")); - if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) - add_role_attribute(&buf, _("Bypass RLS")); + if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) + add_role_attribute(&buf, _("Bypass RLS")); conns = atoi(PQgetvalue(res, i, 6)); if (conns >= 0) @@ -5155,14 +5154,14 @@ listCollations(const char *pattern, bool verbose, bool showSystem) gettext_noop("Schema"), gettext_noop("Name")); - appendPQExpBuffer(&buf, - " CASE c.collprovider " - "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " - "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " - "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " - "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " - "END AS \"%s\",\n", - gettext_noop("Provider")); + appendPQExpBuffer(&buf, + " CASE c.collprovider " + "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " + "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " + "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " + "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " + "END AS \"%s\",\n", + gettext_noop("Provider")); appendPQExpBuffer(&buf, " c.collcollate AS \"%s\",\n" -- 2.50.1 (Apple Git-155) --aHl3HfeiUuO3zeNC-- ^ permalink raw reply [nested|flat] 59+ messages in thread
* [PATCH v6 4/4] run pgindent and pgperltidy @ 2026-06-30 18:24 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 59+ messages in thread From: Nathan Bossart @ 2026-06-30 18:24 UTC (permalink / raw) --- src/bin/pg_dump/pg_dump.c | 464 ++++++++++----------- src/bin/pg_dump/pg_dumpall.c | 30 +- src/bin/pg_upgrade/check.c | 16 +- src/bin/pg_upgrade/controldata.c | 2 +- src/bin/pg_upgrade/exec.c | 8 +- src/bin/pg_upgrade/multixact_rewrite.c | 80 ++-- src/bin/pg_upgrade/pg_upgrade.c | 34 +- src/bin/pg_upgrade/relfilenumber.c | 54 +-- src/bin/pg_upgrade/t/006_transfer_modes.pl | 33 +- src/bin/psql/command.c | 29 +- src/bin/psql/describe.c | 461 ++++++++++---------- 11 files changed, 601 insertions(+), 610 deletions(-) diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 65bd15ebfd2..5673268b467 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -1491,8 +1491,8 @@ setup_connection(Archive *AH, const char *dumpencoding, * Disable timeouts if supported. */ ExecuteSqlStatement(AH, "SET statement_timeout = 0"); - ExecuteSqlStatement(AH, "SET lock_timeout = 0"); - ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); + ExecuteSqlStatement(AH, "SET lock_timeout = 0"); + ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); if (AH->remoteVersion >= 170000) ExecuteSqlStatement(AH, "SET transaction_timeout = 0"); @@ -1505,10 +1505,10 @@ setup_connection(Archive *AH, const char *dumpencoding, /* * Adjust row-security mode, if supported. */ - if (dopt->enable_row_security) - ExecuteSqlStatement(AH, "SET row_security = on"); - else - ExecuteSqlStatement(AH, "SET row_security = off"); + if (dopt->enable_row_security) + ExecuteSqlStatement(AH, "SET row_security = on"); + else + ExecuteSqlStatement(AH, "SET row_security = off"); /* * For security reasons, we restrict the expansion of non-system views and @@ -1933,10 +1933,9 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) addObjectDependency(dobj, ext->dobj.dumpId); /* - * Mark the member object to have any non-initial ACLs - * dumped. (Any initial ACLs will be removed later, using data from - * pg_init_privs, so that we'll dump only the delta from the extension's - * initial setup.) + * Mark the member object to have any non-initial ACLs dumped. (Any + * initial ACLs will be removed later, using data from pg_init_privs, so + * that we'll dump only the delta from the extension's initial setup.) * * In binary upgrades, we still dump all components of the members * individually, since the idea is to exactly reproduce the database @@ -1953,7 +1952,7 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) if (fout->dopt->binary_upgrade) dobj->dump = ext->dobj.dump; else - dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); + dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); return true; } @@ -1987,9 +1986,9 @@ selectDumpableNamespace(NamespaceInfo *nsinfo, Archive *fout) else if (strcmp(nsinfo->dobj.name, "pg_catalog") == 0) { /* - * We dump out any ACLs defined in pg_catalog, if - * they are interesting (and not the original ACLs which were set at - * initdb time, see pg_init_privs). + * We dump out any ACLs defined in pg_catalog, if they are interesting + * (and not the original ACLs which were set at initdb time, see + * pg_init_privs). */ nsinfo->dobj.dump_contains = nsinfo->dobj.dump = DUMP_COMPONENT_ACL; } @@ -3296,7 +3295,7 @@ dumpDatabase(Archive *fout) "datcollate, datctype, datfrozenxid, " "datacl, acldefault('d', datdba) AS acldefault, " "datistemplate, datconnlimit, "); - appendPQExpBufferStr(dbQry, "datminmxid, "); + appendPQExpBufferStr(dbQry, "datminmxid, "); if (fout->remoteVersion >= 170000) appendPQExpBufferStr(dbQry, "datlocprovider, datlocale, datcollversion, "); else if (fout->remoteVersion >= 150000) @@ -3638,11 +3637,11 @@ dumpDatabase(Archive *fout) ii_oid, ii_relminmxid; - appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" - "FROM pg_catalog.pg_class\n" - "WHERE oid IN (%u, %u, %u, %u);\n", - LargeObjectRelationId, LargeObjectLOidPNIndexId, - LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); + appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" + "FROM pg_catalog.pg_class\n" + "WHERE oid IN (%u, %u, %u, %u);\n", + LargeObjectRelationId, LargeObjectLOidPNIndexId, + LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); lo_res = ExecuteSqlQuery(fout, loFrozenQry->data, PGRES_TUPLES_OK); @@ -4274,7 +4273,7 @@ getPolicies(Archive *fout, TableInfo tblinfo[], int numTables) printfPQExpBuffer(query, "SELECT pol.oid, pol.tableoid, pol.polrelid, pol.polname, pol.polcmd, "); - appendPQExpBufferStr(query, "pol.polpermissive, "); + appendPQExpBufferStr(query, "pol.polpermissive, "); appendPQExpBuffer(query, "CASE WHEN pol.polroles = '{0}' THEN NULL ELSE " " pg_catalog.array_to_string(ARRAY(SELECT pg_catalog.quote_ident(rolname) from pg_catalog.pg_roles WHERE oid = ANY(pol.polroles)), ', ') END AS polroles, " @@ -6633,9 +6632,9 @@ getAccessMethods(Archive *fout) * Select all access methods from pg_am table. */ appendPQExpBufferStr(query, "SELECT tableoid, oid, amname, "); - appendPQExpBufferStr(query, - "amtype, " - "amhandler::pg_catalog.regproc AS amhandler "); + appendPQExpBufferStr(query, + "amtype, " + "amhandler::pg_catalog.regproc AS amhandler "); appendPQExpBufferStr(query, "FROM pg_am"); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6827,35 +6826,35 @@ getAggregates(Archive *fout) * Find all interesting aggregates. See comment in getFuncs() for the * rationale behind the filtering logic. */ - agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" - : "p.proisagg"); + agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" + : "p.proisagg"); - appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " - "p.proname AS aggname, " - "p.pronamespace AS aggnamespace, " - "p.pronargs, p.proargtypes, " - "p.proowner, " - "p.proacl AS aggacl, " - "acldefault('f', p.proowner) AS acldefault " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s AND (" - "p.pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog') OR " - "p.proacl IS DISTINCT FROM pip.initprivs", - agg_check); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - " OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); - appendPQExpBufferChar(query, ')'); + appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " + "p.proname AS aggname, " + "p.pronamespace AS aggnamespace, " + "p.pronargs, p.proargtypes, " + "p.proowner, " + "p.proacl AS aggacl, " + "acldefault('f', p.proowner) AS acldefault " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s AND (" + "p.pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog') OR " + "p.proacl IS DISTINCT FROM pip.initprivs", + agg_check); + if (dopt->binary_upgrade) + appendPQExpBufferStr(query, + " OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6957,53 +6956,53 @@ getFuncs(Archive *fout) * include them, since we want to dump extension members individually in * that mode. Also, if they are used by casts or transforms then we need * to gather the information about them, though they won't be dumped if - * they are built-in. Also, include functions in - * pg_catalog if they have an ACL different from what's shown in - * pg_init_privs (so we have to join to pg_init_privs; annoying). + * they are built-in. Also, include functions in pg_catalog if they have + * an ACL different from what's shown in pg_init_privs (so we have to join + * to pg_init_privs; annoying). */ - not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" - : "NOT p.proisagg"); + not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" + : "NOT p.proisagg"); - appendPQExpBuffer(query, - "SELECT p.tableoid, p.oid, p.proname, p.prolang, " - "p.pronargs, p.proargtypes, p.prorettype, " - "p.proacl, " - "acldefault('f', p.proowner) AS acldefault, " - "p.pronamespace, " - "p.proowner " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s" - "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " - "WHERE classid = 'pg_proc'::regclass AND " - "objid = p.oid AND deptype = 'i')" - "\n AND (" - "\n pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog')" - "\n OR EXISTS (SELECT 1 FROM pg_cast" - "\n WHERE pg_cast.oid > %u " - "\n AND p.oid = pg_cast.castfunc)" - "\n OR EXISTS (SELECT 1 FROM pg_transform" - "\n WHERE pg_transform.oid > %u AND " - "\n (p.oid = pg_transform.trffromsql" - "\n OR p.oid = pg_transform.trftosql))", - not_agg_check, - g_last_builtin_oid, - g_last_builtin_oid); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); + appendPQExpBuffer(query, + "SELECT p.tableoid, p.oid, p.proname, p.prolang, " + "p.pronargs, p.proargtypes, p.prorettype, " + "p.proacl, " + "acldefault('f', p.proowner) AS acldefault, " + "p.pronamespace, " + "p.proowner " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s" + "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " + "WHERE classid = 'pg_proc'::regclass AND " + "objid = p.oid AND deptype = 'i')" + "\n AND (" + "\n pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog')" + "\n OR EXISTS (SELECT 1 FROM pg_cast" + "\n WHERE pg_cast.oid > %u " + "\n AND p.oid = pg_cast.castfunc)" + "\n OR EXISTS (SELECT 1 FROM pg_transform" + "\n WHERE pg_transform.oid > %u AND " + "\n (p.oid = pg_transform.trffromsql" + "\n OR p.oid = pg_transform.trftosql))", + not_agg_check, + g_last_builtin_oid, + g_last_builtin_oid); + if (dopt->binary_upgrade) appendPQExpBufferStr(query, - "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); - appendPQExpBufferChar(query, ')'); + "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferStr(query, + "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -7252,31 +7251,31 @@ getTables(Archive *fout, int *numTables) appendPQExpBufferStr(query, "c.relhasoids, "); - appendPQExpBufferStr(query, - "c.relispopulated, "); + appendPQExpBufferStr(query, + "c.relispopulated, "); - appendPQExpBufferStr(query, - "c.relreplident, "); + appendPQExpBufferStr(query, + "c.relreplident, "); - appendPQExpBufferStr(query, - "c.relrowsecurity, c.relforcerowsecurity, "); + appendPQExpBufferStr(query, + "c.relrowsecurity, c.relforcerowsecurity, "); - appendPQExpBufferStr(query, - "c.relminmxid, tc.relminmxid AS tminmxid, "); + appendPQExpBufferStr(query, + "c.relminmxid, tc.relminmxid AS tminmxid, "); - appendPQExpBufferStr(query, - "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); + appendPQExpBufferStr(query, + "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); - appendPQExpBufferStr(query, - "am.amname, "); + appendPQExpBufferStr(query, + "am.amname, "); - appendPQExpBufferStr(query, - "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); + appendPQExpBufferStr(query, + "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); - appendPQExpBufferStr(query, - "c.relispartition AS ispartition "); + appendPQExpBufferStr(query, + "c.relispartition AS ispartition "); /* * Left join to pg_depend to pick up dependency info linking sequences to @@ -7296,8 +7295,8 @@ getTables(Archive *fout, int *numTables) /* * Left join to pg_am to pick up the amname. */ - appendPQExpBufferStr(query, - "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); + appendPQExpBufferStr(query, + "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); /* * We purposefully ignore toast OIDs for partitioned tables; the reason is @@ -7868,8 +7867,8 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables) "t.reloptions AS indreloptions, "); - appendPQExpBufferStr(query, - "i.indisreplident, "); + appendPQExpBufferStr(query, + "i.indisreplident, "); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -9313,8 +9312,8 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables) appendPQExpBufferStr(q, "'' AS attcompression,\n"); - appendPQExpBufferStr(q, - "a.attidentity,\n"); + appendPQExpBufferStr(q, + "a.attidentity,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(q, @@ -10717,73 +10716,73 @@ getAdditionalACLs(Archive *fout) PQclear(res); /* Fetch initial-privileges data */ - printfPQExpBuffer(query, - "SELECT objoid, classoid, objsubid, privtype, initprivs " - "FROM pg_init_privs"); + printfPQExpBuffer(query, + "SELECT objoid, classoid, objsubid, privtype, initprivs " + "FROM pg_init_privs"); - res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); + res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); - ntups = PQntuples(res); - for (i = 0; i < ntups; i++) - { - Oid objoid = atooid(PQgetvalue(res, i, 0)); - Oid classoid = atooid(PQgetvalue(res, i, 1)); - int objsubid = atoi(PQgetvalue(res, i, 2)); - char privtype = *(PQgetvalue(res, i, 3)); - char *initprivs = PQgetvalue(res, i, 4); - CatalogId objId; - DumpableObject *dobj; + ntups = PQntuples(res); + for (i = 0; i < ntups; i++) + { + Oid objoid = atooid(PQgetvalue(res, i, 0)); + Oid classoid = atooid(PQgetvalue(res, i, 1)); + int objsubid = atoi(PQgetvalue(res, i, 2)); + char privtype = *(PQgetvalue(res, i, 3)); + char *initprivs = PQgetvalue(res, i, 4); + CatalogId objId; + DumpableObject *dobj; - objId.tableoid = classoid; - objId.oid = objoid; - dobj = findObjectByCatalogId(objId); - /* OK to ignore entries we haven't got a DumpableObject for */ - if (dobj) + objId.tableoid = classoid; + objId.oid = objoid; + dobj = findObjectByCatalogId(objId); + /* OK to ignore entries we haven't got a DumpableObject for */ + if (dobj) + { + /* Cope with sub-object initprivs */ + if (objsubid != 0) { - /* Cope with sub-object initprivs */ - if (objsubid != 0) - { - if (dobj->objType == DO_TABLE) - { - /* For a column initprivs, set the table's ACL flags */ - dobj->components |= DUMP_COMPONENT_ACL; - ((TableInfo *) dobj)->hascolumnACLs = true; - } - else - pg_log_warning("unsupported pg_init_privs entry: %u %u %d", - classoid, objoid, objsubid); - continue; - } - - /* - * We ignore any pg_init_privs.initprivs entry for the public - * schema, as explained in getNamespaces(). - */ - if (dobj->objType == DO_NAMESPACE && - strcmp(dobj->name, "public") == 0) - continue; - - /* Else it had better be of a type we think has ACLs */ - if (dobj->objType == DO_NAMESPACE || - dobj->objType == DO_TYPE || - dobj->objType == DO_FUNC || - dobj->objType == DO_AGG || - dobj->objType == DO_TABLE || - dobj->objType == DO_PROCLANG || - dobj->objType == DO_FDW || - dobj->objType == DO_FOREIGN_SERVER) + if (dobj->objType == DO_TABLE) { - DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; - - daobj->dacl.privtype = privtype; - daobj->dacl.initprivs = pstrdup(initprivs); + /* For a column initprivs, set the table's ACL flags */ + dobj->components |= DUMP_COMPONENT_ACL; + ((TableInfo *) dobj)->hascolumnACLs = true; } else pg_log_warning("unsupported pg_init_privs entry: %u %u %d", classoid, objoid, objsubid); + continue; + } + + /* + * We ignore any pg_init_privs.initprivs entry for the public + * schema, as explained in getNamespaces(). + */ + if (dobj->objType == DO_NAMESPACE && + strcmp(dobj->name, "public") == 0) + continue; + + /* Else it had better be of a type we think has ACLs */ + if (dobj->objType == DO_NAMESPACE || + dobj->objType == DO_TYPE || + dobj->objType == DO_FUNC || + dobj->objType == DO_AGG || + dobj->objType == DO_TABLE || + dobj->objType == DO_PROCLANG || + dobj->objType == DO_FDW || + dobj->objType == DO_FOREIGN_SERVER) + { + DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; + + daobj->dacl.privtype = privtype; + daobj->dacl.initprivs = pstrdup(initprivs); } + else + pg_log_warning("unsupported pg_init_privs entry: %u %u %d", + classoid, objoid, objsubid); } - PQclear(res); + } + PQclear(res); destroyPQExpBuffer(query); } @@ -11128,8 +11127,8 @@ dumpRelationStats_dumper(Archive *fout, const void *userArg, const TocEntry *te) * The results must be in the order of the relations supplied in the * parameters to ensure we remain in sync as we walk through the TOC. * - * For versions before 19, the redundant filter clause on s.tablename = - * ANY(...) seems sufficient to convince the planner to use + * For versions before 19, the redundant filter clause on s.tablename + * = ANY(...) seems sufficient to convince the planner to use * pg_class_relname_nsp_index, which avoids a full scan of pg_stats. * In newer versions, pg_stats returns the table OIDs, eliminating the * need for that hack. @@ -13469,11 +13468,11 @@ dumpFunc(Archive *fout, const FuncInfo *finfo) "pg_catalog.pg_get_function_result(p.oid) AS funcresult,\n" "proleakproof,\n"); - appendPQExpBufferStr(query, - "array_to_string(protrftypes, ' ') AS protrftypes,\n"); + appendPQExpBufferStr(query, + "array_to_string(protrftypes, ' ') AS protrftypes,\n"); - appendPQExpBufferStr(query, - "proparallel,\n"); + appendPQExpBufferStr(query, + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -14963,9 +14962,9 @@ dumpCollation(Archive *fout, const CollInfo *collinfo) /* Get collation-specific details */ appendPQExpBufferStr(query, "SELECT "); - appendPQExpBufferStr(query, - "collprovider, " - "collversion, "); + appendPQExpBufferStr(query, + "collprovider, " + "collversion, "); if (fout->remoteVersion >= 120000) appendPQExpBufferStr(query, @@ -15372,23 +15371,23 @@ dumpAgg(Archive *fout, const AggInfo *agginfo) "pg_catalog.pg_get_function_arguments(p.oid) AS funcargs,\n" "pg_catalog.pg_get_function_identity_arguments(p.oid) AS funciargs,\n"); - appendPQExpBufferStr(query, - "aggkind,\n" - "aggmtransfn,\n" - "aggminvtransfn,\n" - "aggmfinalfn,\n" - "aggmtranstype::pg_catalog.regtype,\n" - "aggfinalextra,\n" - "aggmfinalextra,\n" - "aggtransspace,\n" - "aggmtransspace,\n" - "aggminitval,\n"); + appendPQExpBufferStr(query, + "aggkind,\n" + "aggmtransfn,\n" + "aggminvtransfn,\n" + "aggmfinalfn,\n" + "aggmtranstype::pg_catalog.regtype,\n" + "aggfinalextra,\n" + "aggmfinalextra,\n" + "aggtransspace,\n" + "aggmtransspace,\n" + "aggminitval,\n"); - appendPQExpBufferStr(query, - "aggcombinefn,\n" - "aggserialfn,\n" - "aggdeserialfn,\n" - "proparallel,\n"); + appendPQExpBufferStr(query, + "aggcombinefn,\n" + "aggserialfn,\n" + "aggdeserialfn,\n" + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -16848,30 +16847,30 @@ dumpTable(Archive *fout, const TableInfo *tbinfo) appendPQExpBufferStr(query, "PREPARE getColumnACLs(pg_catalog.oid) AS\n"); - /* - * In principle we should call acldefault('c', relowner) to - * get the default ACL for a column. However, we don't - * currently store the numeric OID of the relowner in - * TableInfo. We could convert the owner name using regrole, - * but that creates a risk of failure due to concurrent role - * renames. Given that the default ACL for columns is empty - * and is likely to stay that way, it's not worth extra cycles - * and risk to avoid hard-wiring that knowledge here. - */ - appendPQExpBufferStr(query, - "SELECT at.attname, " - "at.attacl, " - "'{}' AS acldefault, " - "pip.privtype, pip.initprivs " - "FROM pg_catalog.pg_attribute at " - "LEFT JOIN pg_catalog.pg_init_privs pip ON " - "(at.attrelid = pip.objoid " - "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " - "AND at.attnum = pip.objsubid) " - "WHERE at.attrelid = $1 AND " - "NOT at.attisdropped " - "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " - "ORDER BY at.attnum"); + /* + * In principle we should call acldefault('c', relowner) to get + * the default ACL for a column. However, we don't currently + * store the numeric OID of the relowner in TableInfo. We could + * convert the owner name using regrole, but that creates a risk + * of failure due to concurrent role renames. Given that the + * default ACL for columns is empty and is likely to stay that + * way, it's not worth extra cycles and risk to avoid hard-wiring + * that knowledge here. + */ + appendPQExpBufferStr(query, + "SELECT at.attname, " + "at.attacl, " + "'{}' AS acldefault, " + "pip.privtype, pip.initprivs " + "FROM pg_catalog.pg_attribute at " + "LEFT JOIN pg_catalog.pg_init_privs pip ON " + "(at.attrelid = pip.objoid " + "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " + "AND at.attnum = pip.objsubid) " + "WHERE at.attrelid = $1 AND " + "NOT at.attisdropped " + "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " + "ORDER BY at.attnum"); ExecuteSqlStatement(fout, query->data); @@ -19165,7 +19164,7 @@ collectSequences(Archive *fout) * pg_get_sequence_data(), but we only do so for non-schema-only dumps. */ if (fout->remoteVersion < 180000 || - (!fout->dopt->dumpData && !fout->dopt->sequence_data)) + (!fout->dopt->dumpData && !fout->dopt->sequence_data)) query = "SELECT seqrelid, format_type(seqtypid, NULL), " "seqstart, seqincrement, " "seqmax, seqmin, " @@ -19227,15 +19226,14 @@ dumpSequence(Archive *fout, const TableInfo *tbinfo) qseqname = pg_strdup(fmtId(tbinfo->dobj.name)); /* - * The sequence information is gathered in a sorted - * table before any calls to dumpSequence(). See collectSequences() for - * more information. + * The sequence information is gathered in a sorted table before any calls + * to dumpSequence(). See collectSequences() for more information. */ - Assert(sequences); + Assert(sequences); - key.oid = tbinfo->dobj.catId.oid; - seq = bsearch(&key, sequences, nsequences, - sizeof(SequenceItem), SequenceItemCmp); + key.oid = tbinfo->dobj.catId.oid; + seq = bsearch(&key, sequences, nsequences, + sizeof(SequenceItem), SequenceItemCmp); /* Calculate default limits for a sequence of this type */ is_ascending = (seq->incby >= 0); diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c index e68937c9934..afcd9a218d8 100644 --- a/src/bin/pg_dump/pg_dumpall.c +++ b/src/bin/pg_dump/pg_dumpall.c @@ -785,11 +785,11 @@ dropRoles(PGconn *conn) int i_rolname; int i; - printfPQExpBuffer(buf, - "SELECT rolname " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 1", role_catalog); + printfPQExpBuffer(buf, + "SELECT rolname " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 1", role_catalog); res = executeQuery(conn, buf->data); @@ -843,16 +843,16 @@ dumpRoles(PGconn *conn) * Notes: rolconfig is dumped later, and pg_authid must be used for * extracting rolcomment regardless of role_catalog. */ - printfPQExpBuffer(buf, - "SELECT oid, rolname, rolsuper, rolinherit, " - "rolcreaterole, rolcreatedb, " - "rolcanlogin, rolconnlimit, rolpassword, " - "rolvaliduntil, rolreplication, rolbypassrls, " - "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " - "rolname = current_user AS is_current_user " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 2", role_catalog); + printfPQExpBuffer(buf, + "SELECT oid, rolname, rolsuper, rolinherit, " + "rolcreaterole, rolcreatedb, " + "rolcanlogin, rolconnlimit, rolpassword, " + "rolvaliduntil, rolreplication, rolbypassrls, " + "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " + "rolname = current_user AS is_current_user " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 2", role_catalog); res = executeQuery(conn, buf->data); diff --git a/src/bin/pg_upgrade/check.c b/src/bin/pg_upgrade/check.c index 786c1474829..f725f5ee3e2 100644 --- a/src/bin/pg_upgrade/check.c +++ b/src/bin/pg_upgrade/check.c @@ -1475,15 +1475,15 @@ check_for_incompatible_polymorphics(ClusterInfo *cluster) ", 'array_cat(anyarray,anyarray)'" ", 'array_prepend(anyelement,anyarray)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_remove(anyarray,anyelement)'" - ", 'array_replace(anyarray,anyelement,anyelement)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_remove(anyarray,anyelement)'" + ", 'array_replace(anyarray,anyelement,anyelement)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_position(anyarray,anyelement)'" - ", 'array_position(anyarray,anyelement,integer)'" - ", 'array_positions(anyarray,anyelement)'" - ", 'width_bucket(anyelement,anyarray)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_position(anyarray,anyelement)'" + ", 'array_position(anyarray,anyelement,integer)'" + ", 'array_positions(anyarray,anyelement)'" + ", 'width_bucket(anyelement,anyarray)'"); /* * The query below hardcodes FirstNormalObjectId as 16384 rather than diff --git a/src/bin/pg_upgrade/controldata.c b/src/bin/pg_upgrade/controldata.c index 8f81c9e9582..02ea02df60f 100644 --- a/src/bin/pg_upgrade/controldata.c +++ b/src/bin/pg_upgrade/controldata.c @@ -228,7 +228,7 @@ get_control_data(ClusterInfo *cluster) p++; /* remove ':' char */ cluster->controldata.chkpnt_nxtepoch = str2uint(p); - p = strchr(p, ':'); + p = strchr(p, ':'); if (p == NULL || strlen(p) <= 1) pg_fatal("%d: controldata retrieval problem", __LINE__); diff --git a/src/bin/pg_upgrade/exec.c b/src/bin/pg_upgrade/exec.c index 44355feea30..a1bdbf373e3 100644 --- a/src/bin/pg_upgrade/exec.c +++ b/src/bin/pg_upgrade/exec.c @@ -55,7 +55,7 @@ get_bin_version(ClusterInfo *cluster) if (sscanf(cmd_output, "%*s %*s %d.%d", &v1, &v2) < 1) pg_fatal("could not get pg_ctl version output from %s", cmd); - cluster->bin_version = v1 * 10000; + cluster->bin_version = v1 * 10000; } @@ -344,8 +344,8 @@ check_data_dir(ClusterInfo *cluster) check_single_dir(pg_data, "pg_subtrans"); check_single_dir(pg_data, PG_TBLSPC_DIR); check_single_dir(pg_data, "pg_twophase"); - check_single_dir(pg_data, "pg_wal"); - check_single_dir(pg_data, "pg_xact"); + check_single_dir(pg_data, "pg_wal"); + check_single_dir(pg_data, "pg_xact"); } @@ -385,7 +385,7 @@ check_bin_dir(ClusterInfo *cluster, bool check_versions) */ get_bin_version(cluster); - check_exec(cluster->bindir, "pg_resetwal", check_versions); + check_exec(cluster->bindir, "pg_resetwal", check_versions); if (cluster == &new_cluster) { diff --git a/src/bin/pg_upgrade/multixact_rewrite.c b/src/bin/pg_upgrade/multixact_rewrite.c index c45b3183684..c7a1416494d 100644 --- a/src/bin/pg_upgrade/multixact_rewrite.c +++ b/src/bin/pg_upgrade/multixact_rewrite.c @@ -61,52 +61,52 @@ rewrite_multixacts(MultiXactId from_multi, MultiXactId to_multi) * Convert old multixids, if needed, by reading them one-by-one from the * old cluster. */ - old_reader = AllocOldMultiXactRead(old_cluster.pgdata, - old_cluster.controldata.chkpnt_nxtmulti, - old_cluster.controldata.chkpnt_nxtmxoff); + old_reader = AllocOldMultiXactRead(old_cluster.pgdata, + old_cluster.controldata.chkpnt_nxtmulti, + old_cluster.controldata.chkpnt_nxtmxoff); - for (MultiXactId multi = from_multi; multi != to_multi;) - { - MultiXactMember member; - bool multixid_valid; - - /* - * Read this multixid's members. - * - * Locking-only XIDs that may be part of multi-xids don't matter - * after upgrade, as there can be no transactions running across - * upgrade. So as a small optimization, we only read one member - * from each multixid: the one updating one, or if there was no - * update, arbitrarily the first locking xid. - */ - multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); + for (MultiXactId multi = from_multi; multi != to_multi;) + { + MultiXactMember member; + bool multixid_valid; - /* - * Write the new offset to pg_multixact/offsets. - * - * Even if this multixid is invalid, we still need to write its - * offset if the *previous* multixid was valid. That's because - * when reading a multixid, the number of members is calculated - * from the difference between the two offsets. - */ - RecordMultiXactOffset(offsets_writer, multi, - (multixid_valid || prev_multixid_valid) ? next_offset : 0); + /* + * Read this multixid's members. + * + * Locking-only XIDs that may be part of multi-xids don't matter after + * upgrade, as there can be no transactions running across upgrade. So + * as a small optimization, we only read one member from each + * multixid: the one updating one, or if there was no update, + * arbitrarily the first locking xid. + */ + multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); - /* Write the members */ - if (multixid_valid) - { - RecordMultiXactMembers(members_writer, next_offset, 1, &member); - next_offset += 1; - } + /* + * Write the new offset to pg_multixact/offsets. + * + * Even if this multixid is invalid, we still need to write its offset + * if the *previous* multixid was valid. That's because when reading + * a multixid, the number of members is calculated from the difference + * between the two offsets. + */ + RecordMultiXactOffset(offsets_writer, multi, + (multixid_valid || prev_multixid_valid) ? next_offset : 0); - /* Advance to next multixid, handling wraparound */ - multi++; - if (multi < FirstMultiXactId) - multi = FirstMultiXactId; - prev_multixid_valid = multixid_valid; + /* Write the members */ + if (multixid_valid) + { + RecordMultiXactMembers(members_writer, next_offset, 1, &member); + next_offset += 1; } - FreeOldMultiXactReader(old_reader); + /* Advance to next multixid, handling wraparound */ + multi++; + if (multi < FirstMultiXactId) + multi = FirstMultiXactId; + prev_multixid_valid = multixid_valid; + } + + FreeOldMultiXactReader(old_reader); /* Write the final 'next' offset to the last SLRU page */ RecordMultiXactOffset(offsets_writer, to_multi, diff --git a/src/bin/pg_upgrade/pg_upgrade.c b/src/bin/pg_upgrade/pg_upgrade.c index c6af9035665..7366fd4627c 100644 --- a/src/bin/pg_upgrade/pg_upgrade.c +++ b/src/bin/pg_upgrade/pg_upgrade.c @@ -833,7 +833,7 @@ copy_xact_xlog_xid(void) * Determine the range of multixacts to convert. */ nxtmulti = old_cluster.controldata.chkpnt_nxtmulti; - oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; + oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; /* handle wraparound */ if (nxtmulti < FirstMultiXactId) nxtmulti = FirstMultiXactId; @@ -898,15 +898,15 @@ set_frozenxids(void) int i_datname; int i_datallowconn; - prep_status("Setting frozenxid and minmxid counters in new cluster"); + prep_status("Setting frozenxid and minmxid counters in new cluster"); conn_template1 = connectToServer(&new_cluster, "template1"); - /* set pg_database.datfrozenxid */ - PQclear(executeQueryOrDie(conn_template1, - "UPDATE pg_catalog.pg_database " - "SET datfrozenxid = '%u'", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_database.datfrozenxid */ + PQclear(executeQueryOrDie(conn_template1, + "UPDATE pg_catalog.pg_database " + "SET datfrozenxid = '%u'", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_database.datminmxid */ PQclear(executeQueryOrDie(conn_template1, @@ -942,16 +942,16 @@ set_frozenxids(void) conn = connectToServer(&new_cluster, datname); - /* set pg_class.relfrozenxid */ - PQclear(executeQueryOrDie(conn, - "UPDATE pg_catalog.pg_class " - "SET relfrozenxid = '%u' " - /* only heap, materialized view, and TOAST are vacuumed */ - "WHERE relkind IN (" - CppAsString2(RELKIND_RELATION) ", " - CppAsString2(RELKIND_MATVIEW) ", " - CppAsString2(RELKIND_TOASTVALUE) ")", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_class.relfrozenxid */ + PQclear(executeQueryOrDie(conn, + "UPDATE pg_catalog.pg_class " + "SET relfrozenxid = '%u' " + /* only heap, materialized view, and TOAST are vacuumed */ + "WHERE relkind IN (" + CppAsString2(RELKIND_RELATION) ", " + CppAsString2(RELKIND_MATVIEW) ", " + CppAsString2(RELKIND_TOASTVALUE) ")", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_class.relminmxid */ PQclear(executeQueryOrDie(conn, diff --git a/src/bin/pg_upgrade/relfilenumber.c b/src/bin/pg_upgrade/relfilenumber.c index ec2ff7acb21..6c467bdc8a5 100644 --- a/src/bin/pg_upgrade/relfilenumber.c +++ b/src/bin/pg_upgrade/relfilenumber.c @@ -587,32 +587,32 @@ transfer_relfile(FileNameMap *map, const char *type_suffix) /* Copying files might take some time, so give feedback. */ pg_log(PG_STATUS, "%s", old_file); - switch (user_opts.transfer_mode) - { - case TRANSFER_MODE_CLONE: - pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", - old_file, new_file); - cloneFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", - old_file, new_file); - copyFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY_FILE_RANGE: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", - old_file, new_file); - copyFileByRange(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_LINK: - pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", - old_file, new_file); - linkFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_SWAP: - /* swap mode is handled in its own code path */ - pg_fatal("should never happen"); - break; - } + switch (user_opts.transfer_mode) + { + case TRANSFER_MODE_CLONE: + pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", + old_file, new_file); + cloneFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", + old_file, new_file); + copyFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY_FILE_RANGE: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", + old_file, new_file); + copyFileByRange(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_LINK: + pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", + old_file, new_file); + linkFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_SWAP: + /* swap mode is handled in its own code path */ + pg_fatal("should never happen"); + break; + } } } diff --git a/src/bin/pg_upgrade/t/006_transfer_modes.pl b/src/bin/pg_upgrade/t/006_transfer_modes.pl index 9efa5dc863c..360d05c4b68 100644 --- a/src/bin/pg_upgrade/t/006_transfer_modes.pl +++ b/src/bin/pg_upgrade/t/006_transfer_modes.pl @@ -29,10 +29,8 @@ sub test_mode } $new->init(); - $new->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); - $old->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); + $new->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); + $old->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); # We can only test security labels if both the old and new installations # have dummy_seclabel. @@ -76,15 +74,14 @@ sub test_mode "CREATE TABLE test4 AS SELECT generate_series(400, 502)"); } - $old->safe_psql('postgres', - "CREATE TABLESPACE inplc_tblspc LOCATION ''"); - $old->safe_psql('postgres', - "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); - $old->safe_psql('postgres', - "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" - ); - $old->safe_psql('testdb3', - "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); + $old->safe_psql('postgres', "CREATE TABLESPACE inplc_tblspc LOCATION ''"); + $old->safe_psql('postgres', + "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); + $old->safe_psql('postgres', + "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" + ); + $old->safe_psql('testdb3', + "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); # While we are here, test handling of large objects. $old->safe_psql( @@ -152,12 +149,10 @@ sub test_mode } # Tests for in-place tablespaces. - $result = - $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); - is($result, '104', "test5 data after pg_upgrade $mode"); - $result = - $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); - is($result, '105', "test6 data after pg_upgrade $mode"); + $result = $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); + is($result, '104', "test5 data after pg_upgrade $mode"); + $result = $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); + is($result, '105', "test6 data after pg_upgrade $mode"); # Tests for large objects $result = $new->safe_psql('postgres', "SELECT lo_get(4532)"); diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index 44ef11d980e..c90bf8bbde2 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -6278,23 +6278,22 @@ get_create_object_cmd(EditableObjectType obj_type, Oid oid, * ensure the right view gets replaced. Also, check relation kind * to be sure it's a view. * - * Views may have WITH [LOCAL|CASCADED] - * CHECK OPTION. These are not part of the view definition - * returned by pg_get_viewdef() and so need to be retrieved - * separately. Materialized views may have - * arbitrary storage parameter reloptions. + * Views may have WITH [LOCAL|CASCADED] CHECK OPTION. These are + * not part of the view definition returned by pg_get_viewdef() + * and so need to be retrieved separately. Materialized views may + * have arbitrary storage parameter reloptions. */ printfPQExpBuffer(query, "/* %s */\n", _("Get view's definition and details")); - appendPQExpBuffer(query, - "SELECT nspname, relname, relkind, " - "pg_catalog.pg_get_viewdef(c.oid, true), " - "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " - "FROM pg_catalog.pg_class c " - "LEFT JOIN pg_catalog.pg_namespace n " - "ON c.relnamespace = n.oid WHERE c.oid = %u", - oid); + appendPQExpBuffer(query, + "SELECT nspname, relname, relkind, " + "pg_catalog.pg_get_viewdef(c.oid, true), " + "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " + "FROM pg_catalog.pg_class c " + "LEFT JOIN pg_catalog.pg_namespace n " + "ON c.relnamespace = n.oid WHERE c.oid = %u", + oid); break; } diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index ce99137c613..ac0c55e7aa5 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -387,19 +387,19 @@ describeFunctions(const char *functypes, const char *func_pattern, gettext_noop("stable"), gettext_noop("volatile"), gettext_noop("Volatility")); - appendPQExpBuffer(&buf, - ",\n CASE\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" - " END as \"%s\"", - gettext_noop("restricted"), - gettext_noop("safe"), - gettext_noop("unsafe"), - gettext_noop("Parallel")); + appendPQExpBuffer(&buf, + ",\n CASE\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" + " END as \"%s\"", + gettext_noop("restricted"), + gettext_noop("safe"), + gettext_noop("unsafe"), + gettext_noop("Parallel")); appendPQExpBuffer(&buf, ",\n pg_catalog.pg_get_userbyid(p.proowner) as \"%s\"" ",\n CASE WHEN prosecdef THEN '%s' ELSE '%s' END AS \"%s\"" @@ -599,8 +599,8 @@ describeFunctions(const char *functypes, const char *func_pattern, myopt.title = _("List of functions"); myopt.translate_header = true; - myopt.translate_columns = translate_columns; - myopt.n_translate_columns = lengthof(translate_columns); + myopt.translate_columns = translate_columns; + myopt.n_translate_columns = lengthof(translate_columns); printQuery(res, &myopt, pset.queryFout, false, pset.logfile); @@ -1086,38 +1086,38 @@ permissionsList(const char *pattern, bool showSystem) " ), E'\\n') AS \"%s\"", gettext_noop("Column privileges")); - appendPQExpBuffer(&buf, - ",\n pg_catalog.array_to_string(ARRAY(\n" - " SELECT polname\n" - " || CASE WHEN NOT polpermissive THEN\n" - " E' (RESTRICTIVE)'\n" - " ELSE '' END\n" - " || CASE WHEN polcmd != '*' THEN\n" - " E' (' || polcmd::pg_catalog.text || E'):'\n" - " ELSE E':'\n" - " END\n" - " || CASE WHEN polqual IS NOT NULL THEN\n" - " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" - " ELSE E''\n" - " END\n" - " || CASE WHEN polwithcheck IS NOT NULL THEN\n" - " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" - " ELSE E''\n" - " END" - " || CASE WHEN polroles <> '{0}' THEN\n" - " E'\\n to: ' || pg_catalog.array_to_string(\n" - " ARRAY(\n" - " SELECT rolname\n" - " FROM pg_catalog.pg_roles\n" - " WHERE oid = ANY (polroles)\n" - " ORDER BY 1\n" - " ), E', ')\n" - " ELSE E''\n" - " END\n" - " FROM pg_catalog.pg_policy pol\n" - " WHERE polrelid = c.oid), E'\\n')\n" - " AS \"%s\"", - gettext_noop("Policies")); + appendPQExpBuffer(&buf, + ",\n pg_catalog.array_to_string(ARRAY(\n" + " SELECT polname\n" + " || CASE WHEN NOT polpermissive THEN\n" + " E' (RESTRICTIVE)'\n" + " ELSE '' END\n" + " || CASE WHEN polcmd != '*' THEN\n" + " E' (' || polcmd::pg_catalog.text || E'):'\n" + " ELSE E':'\n" + " END\n" + " || CASE WHEN polqual IS NOT NULL THEN\n" + " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" + " ELSE E''\n" + " END\n" + " || CASE WHEN polwithcheck IS NOT NULL THEN\n" + " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" + " ELSE E''\n" + " END" + " || CASE WHEN polroles <> '{0}' THEN\n" + " E'\\n to: ' || pg_catalog.array_to_string(\n" + " ARRAY(\n" + " SELECT rolname\n" + " FROM pg_catalog.pg_roles\n" + " WHERE oid = ANY (polroles)\n" + " ORDER BY 1\n" + " ), E', ')\n" + " ELSE E''\n" + " END\n" + " FROM pg_catalog.pg_policy pol\n" + " WHERE polrelid = c.oid), E'\\n')\n" + " AS \"%s\"", + gettext_noop("Policies")); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_class c\n" " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n" @@ -1675,27 +1675,27 @@ describeOneTableDetails(const char *schemaname, char *footers[3] = {NULL, NULL, NULL}; printfPQExpBuffer(&buf, "/* %s */\n", _("Get sequence information")); - appendPQExpBuffer(&buf, - "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" - " seqstart AS \"%s\",\n" - " seqmin AS \"%s\",\n" - " seqmax AS \"%s\",\n" - " seqincrement AS \"%s\",\n" - " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" - " seqcache AS \"%s\"\n", - gettext_noop("Type"), - gettext_noop("Start"), - gettext_noop("Minimum"), - gettext_noop("Maximum"), - gettext_noop("Increment"), - gettext_noop("yes"), - gettext_noop("no"), - gettext_noop("Cycles?"), - gettext_noop("Cache")); - appendPQExpBuffer(&buf, - "FROM pg_catalog.pg_sequence\n" - "WHERE seqrelid = '%s';", - oid); + appendPQExpBuffer(&buf, + "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" + " seqstart AS \"%s\",\n" + " seqmin AS \"%s\",\n" + " seqmax AS \"%s\",\n" + " seqincrement AS \"%s\",\n" + " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" + " seqcache AS \"%s\"\n", + gettext_noop("Type"), + gettext_noop("Start"), + gettext_noop("Minimum"), + gettext_noop("Maximum"), + gettext_noop("Increment"), + gettext_noop("yes"), + gettext_noop("no"), + gettext_noop("Cycles?"), + gettext_noop("Cache")); + appendPQExpBuffer(&buf, + "FROM pg_catalog.pg_sequence\n" + "WHERE seqrelid = '%s';", + oid); res = PSQLexec(buf.data); if (!res) @@ -1913,7 +1913,7 @@ describeOneTableDetails(const char *schemaname, appendPQExpBufferStr(&buf, ",\n (SELECT c.collname FROM pg_catalog.pg_collation c, pg_catalog.pg_type t\n" " WHERE c.oid = a.attcollation AND t.oid = a.atttypid AND a.attcollation <> t.typcollation) AS attcollation"); attcoll_col = cols++; - appendPQExpBufferStr(&buf, ",\n a.attidentity"); + appendPQExpBufferStr(&buf, ",\n a.attidentity"); attidentity_col = cols++; if (pset.sversion >= 120000) appendPQExpBufferStr(&buf, ",\n a.attgenerated"); @@ -2326,7 +2326,7 @@ describeOneTableDetails(const char *schemaname, CppAsString2(CONSTRAINT_EXCLUSION) ") AND " "condeferred) AS condeferred,\n"); - appendPQExpBufferStr(&buf, "i.indisreplident,\n"); + appendPQExpBufferStr(&buf, "i.indisreplident,\n"); if (pset.sversion >= 150000) appendPQExpBufferStr(&buf, "i.indnullsnotdistinct,\n"); @@ -2431,7 +2431,7 @@ describeOneTableDetails(const char *schemaname, "pg_catalog.pg_get_indexdef(i.indexrelid, 0, true),\n " "pg_catalog.pg_get_constraintdef(con.oid, true), " "contype, condeferrable, condeferred"); - appendPQExpBufferStr(&buf, ", i.indisreplident"); + appendPQExpBufferStr(&buf, ", i.indisreplident"); appendPQExpBufferStr(&buf, ", c2.reltablespace"); if (pset.sversion >= 180000) appendPQExpBufferStr(&buf, ", con.conperiod"); @@ -2682,81 +2682,80 @@ describeOneTableDetails(const char *schemaname, PQclear(result); /* print any row-level policies */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get row-level policies for this table")); - appendPQExpBufferStr(&buf, "SELECT pol.polname,"); - appendPQExpBufferStr(&buf, - " pol.polpermissive,\n"); - appendPQExpBuffer(&buf, - " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" - " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" - " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" - " CASE pol.polcmd\n" - " WHEN 'r' THEN 'SELECT'\n" - " WHEN 'a' THEN 'INSERT'\n" - " WHEN 'w' THEN 'UPDATE'\n" - " WHEN 'd' THEN 'DELETE'\n" - " END AS cmd\n" - "FROM pg_catalog.pg_policy pol\n" - "WHERE pol.polrelid = '%s' ORDER BY 1;", - oid); + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get row-level policies for this table")); + appendPQExpBufferStr(&buf, "SELECT pol.polname,"); + appendPQExpBufferStr(&buf, + " pol.polpermissive,\n"); + appendPQExpBuffer(&buf, + " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" + " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" + " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" + " CASE pol.polcmd\n" + " WHEN 'r' THEN 'SELECT'\n" + " WHEN 'a' THEN 'INSERT'\n" + " WHEN 'w' THEN 'UPDATE'\n" + " WHEN 'd' THEN 'DELETE'\n" + " END AS cmd\n" + "FROM pg_catalog.pg_policy pol\n" + "WHERE pol.polrelid = '%s' ORDER BY 1;", + oid); - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - /* - * Handle cases where RLS is enabled and there are policies, or - * there aren't policies, or RLS isn't enabled but there are - * policies - */ - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies:")); + /* + * Handle cases where RLS is enabled and there are policies, or there + * aren't policies, or RLS isn't enabled but there are policies + */ + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies:")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled):")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled):")); - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); - if (!tableinfo.rowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (row security disabled):")); + if (!tableinfo.rowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (row security disabled):")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " POLICY \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " POLICY \"%s\"", + PQgetvalue(result, i, 0)); - if (*(PQgetvalue(result, i, 1)) == 'f') - appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); + if (*(PQgetvalue(result, i, 1)) == 'f') + appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); - if (!PQgetisnull(result, i, 5)) - appendPQExpBuffer(&buf, " FOR %s", - PQgetvalue(result, i, 5)); + if (!PQgetisnull(result, i, 5)) + appendPQExpBuffer(&buf, " FOR %s", + PQgetvalue(result, i, 5)); - if (!PQgetisnull(result, i, 2)) - { - appendPQExpBuffer(&buf, "\n TO %s", - PQgetvalue(result, i, 2)); - } + if (!PQgetisnull(result, i, 2)) + { + appendPQExpBuffer(&buf, "\n TO %s", + PQgetvalue(result, i, 2)); + } - if (!PQgetisnull(result, i, 3)) - appendPQExpBuffer(&buf, "\n USING (%s)", - PQgetvalue(result, i, 3)); + if (!PQgetisnull(result, i, 3)) + appendPQExpBuffer(&buf, "\n USING (%s)", + PQgetvalue(result, i, 3)); - if (!PQgetisnull(result, i, 4)) - appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", - PQgetvalue(result, i, 4)); + if (!PQgetisnull(result, i, 4)) + appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", + PQgetvalue(result, i, 4)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* print any extended statistics */ if (pset.sversion >= 140000) @@ -3025,115 +3024,115 @@ describeOneTableDetails(const char *schemaname, } /* print any publications */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get publications that publish this table")); - if (pset.sversion >= 150000) + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get publications that publish this table")); + if (pset.sversion >= 150000) + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" + " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" + "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" + "UNION\n" + "SELECT pubname\n" + " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" + " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" + " (SELECT pg_catalog.string_agg(attname, ', ')\n" + " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" + " pg_catalog.pg_attribute\n" + " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" + " ELSE NULL END) " + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" + "WHERE pr.prrelid = '%s'\n", + oid, oid, oid); + + if (pset.sversion >= 190000) { + /* + * Skip entries where this relation appears in the + * publication's EXCEPT list. + */ appendPQExpBuffer(&buf, + " AND NOT pr.prexcept\n" + "UNION\n" "SELECT pubname\n" " , NULL\n" " , NULL\n" "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" - " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" - "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" - "UNION\n" - "SELECT pubname\n" - " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" - " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" - " (SELECT pg_catalog.string_agg(attname, ', ')\n" - " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" - " pg_catalog.pg_attribute\n" - " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" - " ELSE NULL END) " - "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" - "WHERE pr.prrelid = '%s'\n", + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + " AND NOT EXISTS (\n" + " SELECT 1\n" + " FROM pg_catalog.pg_publication_rel pr\n" + " WHERE pr.prpubid = p.oid AND\n" + " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" + "ORDER BY 1;", oid, oid, oid); - - if (pset.sversion >= 190000) - { - /* - * Skip entries where this relation appears in the - * publication's EXCEPT list. - */ - appendPQExpBuffer(&buf, - " AND NOT pr.prexcept\n" - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - " AND NOT EXISTS (\n" - " SELECT 1\n" - " FROM pg_catalog.pg_publication_rel pr\n" - " WHERE pr.prpubid = p.oid AND\n" - " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" - "ORDER BY 1;", - oid, oid, oid); - } - else - { - appendPQExpBuffer(&buf, - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - "ORDER BY 1;", - oid); - } } else { appendPQExpBuffer(&buf, + "UNION\n" "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - "WHERE pr.prrelid = '%s'\n" - "UNION ALL\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" + " , NULL\n" + " , NULL\n" "FROM pg_catalog.pg_publication p\n" "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" "ORDER BY 1;", - oid, oid); + oid); } + } + else + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + "WHERE pr.prrelid = '%s'\n" + "UNION ALL\n" + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + "ORDER BY 1;", + oid, oid); + } - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - if (tuples > 0) - printTableAddFooter(&cont, _("Included in publications:")); + if (tuples > 0) + printTableAddFooter(&cont, _("Included in publications:")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " \"%s\"", + PQgetvalue(result, i, 0)); - /* column list (if any) */ - if (!PQgetisnull(result, i, 2)) - appendPQExpBuffer(&buf, " (%s)", - PQgetvalue(result, i, 2)); + /* column list (if any) */ + if (!PQgetisnull(result, i, 2)) + appendPQExpBuffer(&buf, " (%s)", + PQgetvalue(result, i, 2)); - /* row filter (if any) */ - if (!PQgetisnull(result, i, 1)) - appendPQExpBuffer(&buf, " WHERE %s", - PQgetvalue(result, i, 1)); + /* row filter (if any) */ + if (!PQgetisnull(result, i, 1)) + appendPQExpBuffer(&buf, " WHERE %s", + PQgetvalue(result, i, 1)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* Print publications where the table is in the EXCEPT clause */ if (pset.sversion >= 190000) @@ -3805,7 +3804,7 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) ncols++; } appendPQExpBufferStr(&buf, "\n, r.rolreplication"); - appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); + appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_roles r\n"); @@ -3860,8 +3859,8 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) if (strcmp(PQgetvalue(res, i, (verbose ? 9 : 8)), "t") == 0) add_role_attribute(&buf, _("Replication")); - if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) - add_role_attribute(&buf, _("Bypass RLS")); + if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) + add_role_attribute(&buf, _("Bypass RLS")); conns = atoi(PQgetvalue(res, i, 6)); if (conns >= 0) @@ -5155,14 +5154,14 @@ listCollations(const char *pattern, bool verbose, bool showSystem) gettext_noop("Schema"), gettext_noop("Name")); - appendPQExpBuffer(&buf, - " CASE c.collprovider " - "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " - "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " - "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " - "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " - "END AS \"%s\",\n", - gettext_noop("Provider")); + appendPQExpBuffer(&buf, + " CASE c.collprovider " + "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " + "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " + "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " + "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " + "END AS \"%s\",\n", + gettext_noop("Provider")); appendPQExpBuffer(&buf, " c.collcollate AS \"%s\",\n" -- 2.50.1 (Apple Git-155) --aHl3HfeiUuO3zeNC-- ^ permalink raw reply [nested|flat] 59+ messages in thread
* [PATCH v6 4/4] run pgindent and pgperltidy @ 2026-06-30 18:24 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 59+ messages in thread From: Nathan Bossart @ 2026-06-30 18:24 UTC (permalink / raw) --- src/bin/pg_dump/pg_dump.c | 464 ++++++++++----------- src/bin/pg_dump/pg_dumpall.c | 30 +- src/bin/pg_upgrade/check.c | 16 +- src/bin/pg_upgrade/controldata.c | 2 +- src/bin/pg_upgrade/exec.c | 8 +- src/bin/pg_upgrade/multixact_rewrite.c | 80 ++-- src/bin/pg_upgrade/pg_upgrade.c | 34 +- src/bin/pg_upgrade/relfilenumber.c | 54 +-- src/bin/pg_upgrade/t/006_transfer_modes.pl | 33 +- src/bin/psql/command.c | 29 +- src/bin/psql/describe.c | 461 ++++++++++---------- 11 files changed, 601 insertions(+), 610 deletions(-) diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 65bd15ebfd2..5673268b467 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -1491,8 +1491,8 @@ setup_connection(Archive *AH, const char *dumpencoding, * Disable timeouts if supported. */ ExecuteSqlStatement(AH, "SET statement_timeout = 0"); - ExecuteSqlStatement(AH, "SET lock_timeout = 0"); - ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); + ExecuteSqlStatement(AH, "SET lock_timeout = 0"); + ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); if (AH->remoteVersion >= 170000) ExecuteSqlStatement(AH, "SET transaction_timeout = 0"); @@ -1505,10 +1505,10 @@ setup_connection(Archive *AH, const char *dumpencoding, /* * Adjust row-security mode, if supported. */ - if (dopt->enable_row_security) - ExecuteSqlStatement(AH, "SET row_security = on"); - else - ExecuteSqlStatement(AH, "SET row_security = off"); + if (dopt->enable_row_security) + ExecuteSqlStatement(AH, "SET row_security = on"); + else + ExecuteSqlStatement(AH, "SET row_security = off"); /* * For security reasons, we restrict the expansion of non-system views and @@ -1933,10 +1933,9 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) addObjectDependency(dobj, ext->dobj.dumpId); /* - * Mark the member object to have any non-initial ACLs - * dumped. (Any initial ACLs will be removed later, using data from - * pg_init_privs, so that we'll dump only the delta from the extension's - * initial setup.) + * Mark the member object to have any non-initial ACLs dumped. (Any + * initial ACLs will be removed later, using data from pg_init_privs, so + * that we'll dump only the delta from the extension's initial setup.) * * In binary upgrades, we still dump all components of the members * individually, since the idea is to exactly reproduce the database @@ -1953,7 +1952,7 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) if (fout->dopt->binary_upgrade) dobj->dump = ext->dobj.dump; else - dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); + dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); return true; } @@ -1987,9 +1986,9 @@ selectDumpableNamespace(NamespaceInfo *nsinfo, Archive *fout) else if (strcmp(nsinfo->dobj.name, "pg_catalog") == 0) { /* - * We dump out any ACLs defined in pg_catalog, if - * they are interesting (and not the original ACLs which were set at - * initdb time, see pg_init_privs). + * We dump out any ACLs defined in pg_catalog, if they are interesting + * (and not the original ACLs which were set at initdb time, see + * pg_init_privs). */ nsinfo->dobj.dump_contains = nsinfo->dobj.dump = DUMP_COMPONENT_ACL; } @@ -3296,7 +3295,7 @@ dumpDatabase(Archive *fout) "datcollate, datctype, datfrozenxid, " "datacl, acldefault('d', datdba) AS acldefault, " "datistemplate, datconnlimit, "); - appendPQExpBufferStr(dbQry, "datminmxid, "); + appendPQExpBufferStr(dbQry, "datminmxid, "); if (fout->remoteVersion >= 170000) appendPQExpBufferStr(dbQry, "datlocprovider, datlocale, datcollversion, "); else if (fout->remoteVersion >= 150000) @@ -3638,11 +3637,11 @@ dumpDatabase(Archive *fout) ii_oid, ii_relminmxid; - appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" - "FROM pg_catalog.pg_class\n" - "WHERE oid IN (%u, %u, %u, %u);\n", - LargeObjectRelationId, LargeObjectLOidPNIndexId, - LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); + appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" + "FROM pg_catalog.pg_class\n" + "WHERE oid IN (%u, %u, %u, %u);\n", + LargeObjectRelationId, LargeObjectLOidPNIndexId, + LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); lo_res = ExecuteSqlQuery(fout, loFrozenQry->data, PGRES_TUPLES_OK); @@ -4274,7 +4273,7 @@ getPolicies(Archive *fout, TableInfo tblinfo[], int numTables) printfPQExpBuffer(query, "SELECT pol.oid, pol.tableoid, pol.polrelid, pol.polname, pol.polcmd, "); - appendPQExpBufferStr(query, "pol.polpermissive, "); + appendPQExpBufferStr(query, "pol.polpermissive, "); appendPQExpBuffer(query, "CASE WHEN pol.polroles = '{0}' THEN NULL ELSE " " pg_catalog.array_to_string(ARRAY(SELECT pg_catalog.quote_ident(rolname) from pg_catalog.pg_roles WHERE oid = ANY(pol.polroles)), ', ') END AS polroles, " @@ -6633,9 +6632,9 @@ getAccessMethods(Archive *fout) * Select all access methods from pg_am table. */ appendPQExpBufferStr(query, "SELECT tableoid, oid, amname, "); - appendPQExpBufferStr(query, - "amtype, " - "amhandler::pg_catalog.regproc AS amhandler "); + appendPQExpBufferStr(query, + "amtype, " + "amhandler::pg_catalog.regproc AS amhandler "); appendPQExpBufferStr(query, "FROM pg_am"); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6827,35 +6826,35 @@ getAggregates(Archive *fout) * Find all interesting aggregates. See comment in getFuncs() for the * rationale behind the filtering logic. */ - agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" - : "p.proisagg"); + agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" + : "p.proisagg"); - appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " - "p.proname AS aggname, " - "p.pronamespace AS aggnamespace, " - "p.pronargs, p.proargtypes, " - "p.proowner, " - "p.proacl AS aggacl, " - "acldefault('f', p.proowner) AS acldefault " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s AND (" - "p.pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog') OR " - "p.proacl IS DISTINCT FROM pip.initprivs", - agg_check); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - " OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); - appendPQExpBufferChar(query, ')'); + appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " + "p.proname AS aggname, " + "p.pronamespace AS aggnamespace, " + "p.pronargs, p.proargtypes, " + "p.proowner, " + "p.proacl AS aggacl, " + "acldefault('f', p.proowner) AS acldefault " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s AND (" + "p.pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog') OR " + "p.proacl IS DISTINCT FROM pip.initprivs", + agg_check); + if (dopt->binary_upgrade) + appendPQExpBufferStr(query, + " OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6957,53 +6956,53 @@ getFuncs(Archive *fout) * include them, since we want to dump extension members individually in * that mode. Also, if they are used by casts or transforms then we need * to gather the information about them, though they won't be dumped if - * they are built-in. Also, include functions in - * pg_catalog if they have an ACL different from what's shown in - * pg_init_privs (so we have to join to pg_init_privs; annoying). + * they are built-in. Also, include functions in pg_catalog if they have + * an ACL different from what's shown in pg_init_privs (so we have to join + * to pg_init_privs; annoying). */ - not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" - : "NOT p.proisagg"); + not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" + : "NOT p.proisagg"); - appendPQExpBuffer(query, - "SELECT p.tableoid, p.oid, p.proname, p.prolang, " - "p.pronargs, p.proargtypes, p.prorettype, " - "p.proacl, " - "acldefault('f', p.proowner) AS acldefault, " - "p.pronamespace, " - "p.proowner " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s" - "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " - "WHERE classid = 'pg_proc'::regclass AND " - "objid = p.oid AND deptype = 'i')" - "\n AND (" - "\n pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog')" - "\n OR EXISTS (SELECT 1 FROM pg_cast" - "\n WHERE pg_cast.oid > %u " - "\n AND p.oid = pg_cast.castfunc)" - "\n OR EXISTS (SELECT 1 FROM pg_transform" - "\n WHERE pg_transform.oid > %u AND " - "\n (p.oid = pg_transform.trffromsql" - "\n OR p.oid = pg_transform.trftosql))", - not_agg_check, - g_last_builtin_oid, - g_last_builtin_oid); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); + appendPQExpBuffer(query, + "SELECT p.tableoid, p.oid, p.proname, p.prolang, " + "p.pronargs, p.proargtypes, p.prorettype, " + "p.proacl, " + "acldefault('f', p.proowner) AS acldefault, " + "p.pronamespace, " + "p.proowner " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s" + "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " + "WHERE classid = 'pg_proc'::regclass AND " + "objid = p.oid AND deptype = 'i')" + "\n AND (" + "\n pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog')" + "\n OR EXISTS (SELECT 1 FROM pg_cast" + "\n WHERE pg_cast.oid > %u " + "\n AND p.oid = pg_cast.castfunc)" + "\n OR EXISTS (SELECT 1 FROM pg_transform" + "\n WHERE pg_transform.oid > %u AND " + "\n (p.oid = pg_transform.trffromsql" + "\n OR p.oid = pg_transform.trftosql))", + not_agg_check, + g_last_builtin_oid, + g_last_builtin_oid); + if (dopt->binary_upgrade) appendPQExpBufferStr(query, - "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); - appendPQExpBufferChar(query, ')'); + "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferStr(query, + "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -7252,31 +7251,31 @@ getTables(Archive *fout, int *numTables) appendPQExpBufferStr(query, "c.relhasoids, "); - appendPQExpBufferStr(query, - "c.relispopulated, "); + appendPQExpBufferStr(query, + "c.relispopulated, "); - appendPQExpBufferStr(query, - "c.relreplident, "); + appendPQExpBufferStr(query, + "c.relreplident, "); - appendPQExpBufferStr(query, - "c.relrowsecurity, c.relforcerowsecurity, "); + appendPQExpBufferStr(query, + "c.relrowsecurity, c.relforcerowsecurity, "); - appendPQExpBufferStr(query, - "c.relminmxid, tc.relminmxid AS tminmxid, "); + appendPQExpBufferStr(query, + "c.relminmxid, tc.relminmxid AS tminmxid, "); - appendPQExpBufferStr(query, - "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); + appendPQExpBufferStr(query, + "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); - appendPQExpBufferStr(query, - "am.amname, "); + appendPQExpBufferStr(query, + "am.amname, "); - appendPQExpBufferStr(query, - "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); + appendPQExpBufferStr(query, + "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); - appendPQExpBufferStr(query, - "c.relispartition AS ispartition "); + appendPQExpBufferStr(query, + "c.relispartition AS ispartition "); /* * Left join to pg_depend to pick up dependency info linking sequences to @@ -7296,8 +7295,8 @@ getTables(Archive *fout, int *numTables) /* * Left join to pg_am to pick up the amname. */ - appendPQExpBufferStr(query, - "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); + appendPQExpBufferStr(query, + "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); /* * We purposefully ignore toast OIDs for partitioned tables; the reason is @@ -7868,8 +7867,8 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables) "t.reloptions AS indreloptions, "); - appendPQExpBufferStr(query, - "i.indisreplident, "); + appendPQExpBufferStr(query, + "i.indisreplident, "); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -9313,8 +9312,8 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables) appendPQExpBufferStr(q, "'' AS attcompression,\n"); - appendPQExpBufferStr(q, - "a.attidentity,\n"); + appendPQExpBufferStr(q, + "a.attidentity,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(q, @@ -10717,73 +10716,73 @@ getAdditionalACLs(Archive *fout) PQclear(res); /* Fetch initial-privileges data */ - printfPQExpBuffer(query, - "SELECT objoid, classoid, objsubid, privtype, initprivs " - "FROM pg_init_privs"); + printfPQExpBuffer(query, + "SELECT objoid, classoid, objsubid, privtype, initprivs " + "FROM pg_init_privs"); - res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); + res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); - ntups = PQntuples(res); - for (i = 0; i < ntups; i++) - { - Oid objoid = atooid(PQgetvalue(res, i, 0)); - Oid classoid = atooid(PQgetvalue(res, i, 1)); - int objsubid = atoi(PQgetvalue(res, i, 2)); - char privtype = *(PQgetvalue(res, i, 3)); - char *initprivs = PQgetvalue(res, i, 4); - CatalogId objId; - DumpableObject *dobj; + ntups = PQntuples(res); + for (i = 0; i < ntups; i++) + { + Oid objoid = atooid(PQgetvalue(res, i, 0)); + Oid classoid = atooid(PQgetvalue(res, i, 1)); + int objsubid = atoi(PQgetvalue(res, i, 2)); + char privtype = *(PQgetvalue(res, i, 3)); + char *initprivs = PQgetvalue(res, i, 4); + CatalogId objId; + DumpableObject *dobj; - objId.tableoid = classoid; - objId.oid = objoid; - dobj = findObjectByCatalogId(objId); - /* OK to ignore entries we haven't got a DumpableObject for */ - if (dobj) + objId.tableoid = classoid; + objId.oid = objoid; + dobj = findObjectByCatalogId(objId); + /* OK to ignore entries we haven't got a DumpableObject for */ + if (dobj) + { + /* Cope with sub-object initprivs */ + if (objsubid != 0) { - /* Cope with sub-object initprivs */ - if (objsubid != 0) - { - if (dobj->objType == DO_TABLE) - { - /* For a column initprivs, set the table's ACL flags */ - dobj->components |= DUMP_COMPONENT_ACL; - ((TableInfo *) dobj)->hascolumnACLs = true; - } - else - pg_log_warning("unsupported pg_init_privs entry: %u %u %d", - classoid, objoid, objsubid); - continue; - } - - /* - * We ignore any pg_init_privs.initprivs entry for the public - * schema, as explained in getNamespaces(). - */ - if (dobj->objType == DO_NAMESPACE && - strcmp(dobj->name, "public") == 0) - continue; - - /* Else it had better be of a type we think has ACLs */ - if (dobj->objType == DO_NAMESPACE || - dobj->objType == DO_TYPE || - dobj->objType == DO_FUNC || - dobj->objType == DO_AGG || - dobj->objType == DO_TABLE || - dobj->objType == DO_PROCLANG || - dobj->objType == DO_FDW || - dobj->objType == DO_FOREIGN_SERVER) + if (dobj->objType == DO_TABLE) { - DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; - - daobj->dacl.privtype = privtype; - daobj->dacl.initprivs = pstrdup(initprivs); + /* For a column initprivs, set the table's ACL flags */ + dobj->components |= DUMP_COMPONENT_ACL; + ((TableInfo *) dobj)->hascolumnACLs = true; } else pg_log_warning("unsupported pg_init_privs entry: %u %u %d", classoid, objoid, objsubid); + continue; + } + + /* + * We ignore any pg_init_privs.initprivs entry for the public + * schema, as explained in getNamespaces(). + */ + if (dobj->objType == DO_NAMESPACE && + strcmp(dobj->name, "public") == 0) + continue; + + /* Else it had better be of a type we think has ACLs */ + if (dobj->objType == DO_NAMESPACE || + dobj->objType == DO_TYPE || + dobj->objType == DO_FUNC || + dobj->objType == DO_AGG || + dobj->objType == DO_TABLE || + dobj->objType == DO_PROCLANG || + dobj->objType == DO_FDW || + dobj->objType == DO_FOREIGN_SERVER) + { + DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; + + daobj->dacl.privtype = privtype; + daobj->dacl.initprivs = pstrdup(initprivs); } + else + pg_log_warning("unsupported pg_init_privs entry: %u %u %d", + classoid, objoid, objsubid); } - PQclear(res); + } + PQclear(res); destroyPQExpBuffer(query); } @@ -11128,8 +11127,8 @@ dumpRelationStats_dumper(Archive *fout, const void *userArg, const TocEntry *te) * The results must be in the order of the relations supplied in the * parameters to ensure we remain in sync as we walk through the TOC. * - * For versions before 19, the redundant filter clause on s.tablename = - * ANY(...) seems sufficient to convince the planner to use + * For versions before 19, the redundant filter clause on s.tablename + * = ANY(...) seems sufficient to convince the planner to use * pg_class_relname_nsp_index, which avoids a full scan of pg_stats. * In newer versions, pg_stats returns the table OIDs, eliminating the * need for that hack. @@ -13469,11 +13468,11 @@ dumpFunc(Archive *fout, const FuncInfo *finfo) "pg_catalog.pg_get_function_result(p.oid) AS funcresult,\n" "proleakproof,\n"); - appendPQExpBufferStr(query, - "array_to_string(protrftypes, ' ') AS protrftypes,\n"); + appendPQExpBufferStr(query, + "array_to_string(protrftypes, ' ') AS protrftypes,\n"); - appendPQExpBufferStr(query, - "proparallel,\n"); + appendPQExpBufferStr(query, + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -14963,9 +14962,9 @@ dumpCollation(Archive *fout, const CollInfo *collinfo) /* Get collation-specific details */ appendPQExpBufferStr(query, "SELECT "); - appendPQExpBufferStr(query, - "collprovider, " - "collversion, "); + appendPQExpBufferStr(query, + "collprovider, " + "collversion, "); if (fout->remoteVersion >= 120000) appendPQExpBufferStr(query, @@ -15372,23 +15371,23 @@ dumpAgg(Archive *fout, const AggInfo *agginfo) "pg_catalog.pg_get_function_arguments(p.oid) AS funcargs,\n" "pg_catalog.pg_get_function_identity_arguments(p.oid) AS funciargs,\n"); - appendPQExpBufferStr(query, - "aggkind,\n" - "aggmtransfn,\n" - "aggminvtransfn,\n" - "aggmfinalfn,\n" - "aggmtranstype::pg_catalog.regtype,\n" - "aggfinalextra,\n" - "aggmfinalextra,\n" - "aggtransspace,\n" - "aggmtransspace,\n" - "aggminitval,\n"); + appendPQExpBufferStr(query, + "aggkind,\n" + "aggmtransfn,\n" + "aggminvtransfn,\n" + "aggmfinalfn,\n" + "aggmtranstype::pg_catalog.regtype,\n" + "aggfinalextra,\n" + "aggmfinalextra,\n" + "aggtransspace,\n" + "aggmtransspace,\n" + "aggminitval,\n"); - appendPQExpBufferStr(query, - "aggcombinefn,\n" - "aggserialfn,\n" - "aggdeserialfn,\n" - "proparallel,\n"); + appendPQExpBufferStr(query, + "aggcombinefn,\n" + "aggserialfn,\n" + "aggdeserialfn,\n" + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -16848,30 +16847,30 @@ dumpTable(Archive *fout, const TableInfo *tbinfo) appendPQExpBufferStr(query, "PREPARE getColumnACLs(pg_catalog.oid) AS\n"); - /* - * In principle we should call acldefault('c', relowner) to - * get the default ACL for a column. However, we don't - * currently store the numeric OID of the relowner in - * TableInfo. We could convert the owner name using regrole, - * but that creates a risk of failure due to concurrent role - * renames. Given that the default ACL for columns is empty - * and is likely to stay that way, it's not worth extra cycles - * and risk to avoid hard-wiring that knowledge here. - */ - appendPQExpBufferStr(query, - "SELECT at.attname, " - "at.attacl, " - "'{}' AS acldefault, " - "pip.privtype, pip.initprivs " - "FROM pg_catalog.pg_attribute at " - "LEFT JOIN pg_catalog.pg_init_privs pip ON " - "(at.attrelid = pip.objoid " - "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " - "AND at.attnum = pip.objsubid) " - "WHERE at.attrelid = $1 AND " - "NOT at.attisdropped " - "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " - "ORDER BY at.attnum"); + /* + * In principle we should call acldefault('c', relowner) to get + * the default ACL for a column. However, we don't currently + * store the numeric OID of the relowner in TableInfo. We could + * convert the owner name using regrole, but that creates a risk + * of failure due to concurrent role renames. Given that the + * default ACL for columns is empty and is likely to stay that + * way, it's not worth extra cycles and risk to avoid hard-wiring + * that knowledge here. + */ + appendPQExpBufferStr(query, + "SELECT at.attname, " + "at.attacl, " + "'{}' AS acldefault, " + "pip.privtype, pip.initprivs " + "FROM pg_catalog.pg_attribute at " + "LEFT JOIN pg_catalog.pg_init_privs pip ON " + "(at.attrelid = pip.objoid " + "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " + "AND at.attnum = pip.objsubid) " + "WHERE at.attrelid = $1 AND " + "NOT at.attisdropped " + "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " + "ORDER BY at.attnum"); ExecuteSqlStatement(fout, query->data); @@ -19165,7 +19164,7 @@ collectSequences(Archive *fout) * pg_get_sequence_data(), but we only do so for non-schema-only dumps. */ if (fout->remoteVersion < 180000 || - (!fout->dopt->dumpData && !fout->dopt->sequence_data)) + (!fout->dopt->dumpData && !fout->dopt->sequence_data)) query = "SELECT seqrelid, format_type(seqtypid, NULL), " "seqstart, seqincrement, " "seqmax, seqmin, " @@ -19227,15 +19226,14 @@ dumpSequence(Archive *fout, const TableInfo *tbinfo) qseqname = pg_strdup(fmtId(tbinfo->dobj.name)); /* - * The sequence information is gathered in a sorted - * table before any calls to dumpSequence(). See collectSequences() for - * more information. + * The sequence information is gathered in a sorted table before any calls + * to dumpSequence(). See collectSequences() for more information. */ - Assert(sequences); + Assert(sequences); - key.oid = tbinfo->dobj.catId.oid; - seq = bsearch(&key, sequences, nsequences, - sizeof(SequenceItem), SequenceItemCmp); + key.oid = tbinfo->dobj.catId.oid; + seq = bsearch(&key, sequences, nsequences, + sizeof(SequenceItem), SequenceItemCmp); /* Calculate default limits for a sequence of this type */ is_ascending = (seq->incby >= 0); diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c index e68937c9934..afcd9a218d8 100644 --- a/src/bin/pg_dump/pg_dumpall.c +++ b/src/bin/pg_dump/pg_dumpall.c @@ -785,11 +785,11 @@ dropRoles(PGconn *conn) int i_rolname; int i; - printfPQExpBuffer(buf, - "SELECT rolname " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 1", role_catalog); + printfPQExpBuffer(buf, + "SELECT rolname " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 1", role_catalog); res = executeQuery(conn, buf->data); @@ -843,16 +843,16 @@ dumpRoles(PGconn *conn) * Notes: rolconfig is dumped later, and pg_authid must be used for * extracting rolcomment regardless of role_catalog. */ - printfPQExpBuffer(buf, - "SELECT oid, rolname, rolsuper, rolinherit, " - "rolcreaterole, rolcreatedb, " - "rolcanlogin, rolconnlimit, rolpassword, " - "rolvaliduntil, rolreplication, rolbypassrls, " - "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " - "rolname = current_user AS is_current_user " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 2", role_catalog); + printfPQExpBuffer(buf, + "SELECT oid, rolname, rolsuper, rolinherit, " + "rolcreaterole, rolcreatedb, " + "rolcanlogin, rolconnlimit, rolpassword, " + "rolvaliduntil, rolreplication, rolbypassrls, " + "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " + "rolname = current_user AS is_current_user " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 2", role_catalog); res = executeQuery(conn, buf->data); diff --git a/src/bin/pg_upgrade/check.c b/src/bin/pg_upgrade/check.c index 786c1474829..f725f5ee3e2 100644 --- a/src/bin/pg_upgrade/check.c +++ b/src/bin/pg_upgrade/check.c @@ -1475,15 +1475,15 @@ check_for_incompatible_polymorphics(ClusterInfo *cluster) ", 'array_cat(anyarray,anyarray)'" ", 'array_prepend(anyelement,anyarray)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_remove(anyarray,anyelement)'" - ", 'array_replace(anyarray,anyelement,anyelement)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_remove(anyarray,anyelement)'" + ", 'array_replace(anyarray,anyelement,anyelement)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_position(anyarray,anyelement)'" - ", 'array_position(anyarray,anyelement,integer)'" - ", 'array_positions(anyarray,anyelement)'" - ", 'width_bucket(anyelement,anyarray)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_position(anyarray,anyelement)'" + ", 'array_position(anyarray,anyelement,integer)'" + ", 'array_positions(anyarray,anyelement)'" + ", 'width_bucket(anyelement,anyarray)'"); /* * The query below hardcodes FirstNormalObjectId as 16384 rather than diff --git a/src/bin/pg_upgrade/controldata.c b/src/bin/pg_upgrade/controldata.c index 8f81c9e9582..02ea02df60f 100644 --- a/src/bin/pg_upgrade/controldata.c +++ b/src/bin/pg_upgrade/controldata.c @@ -228,7 +228,7 @@ get_control_data(ClusterInfo *cluster) p++; /* remove ':' char */ cluster->controldata.chkpnt_nxtepoch = str2uint(p); - p = strchr(p, ':'); + p = strchr(p, ':'); if (p == NULL || strlen(p) <= 1) pg_fatal("%d: controldata retrieval problem", __LINE__); diff --git a/src/bin/pg_upgrade/exec.c b/src/bin/pg_upgrade/exec.c index 44355feea30..a1bdbf373e3 100644 --- a/src/bin/pg_upgrade/exec.c +++ b/src/bin/pg_upgrade/exec.c @@ -55,7 +55,7 @@ get_bin_version(ClusterInfo *cluster) if (sscanf(cmd_output, "%*s %*s %d.%d", &v1, &v2) < 1) pg_fatal("could not get pg_ctl version output from %s", cmd); - cluster->bin_version = v1 * 10000; + cluster->bin_version = v1 * 10000; } @@ -344,8 +344,8 @@ check_data_dir(ClusterInfo *cluster) check_single_dir(pg_data, "pg_subtrans"); check_single_dir(pg_data, PG_TBLSPC_DIR); check_single_dir(pg_data, "pg_twophase"); - check_single_dir(pg_data, "pg_wal"); - check_single_dir(pg_data, "pg_xact"); + check_single_dir(pg_data, "pg_wal"); + check_single_dir(pg_data, "pg_xact"); } @@ -385,7 +385,7 @@ check_bin_dir(ClusterInfo *cluster, bool check_versions) */ get_bin_version(cluster); - check_exec(cluster->bindir, "pg_resetwal", check_versions); + check_exec(cluster->bindir, "pg_resetwal", check_versions); if (cluster == &new_cluster) { diff --git a/src/bin/pg_upgrade/multixact_rewrite.c b/src/bin/pg_upgrade/multixact_rewrite.c index c45b3183684..c7a1416494d 100644 --- a/src/bin/pg_upgrade/multixact_rewrite.c +++ b/src/bin/pg_upgrade/multixact_rewrite.c @@ -61,52 +61,52 @@ rewrite_multixacts(MultiXactId from_multi, MultiXactId to_multi) * Convert old multixids, if needed, by reading them one-by-one from the * old cluster. */ - old_reader = AllocOldMultiXactRead(old_cluster.pgdata, - old_cluster.controldata.chkpnt_nxtmulti, - old_cluster.controldata.chkpnt_nxtmxoff); + old_reader = AllocOldMultiXactRead(old_cluster.pgdata, + old_cluster.controldata.chkpnt_nxtmulti, + old_cluster.controldata.chkpnt_nxtmxoff); - for (MultiXactId multi = from_multi; multi != to_multi;) - { - MultiXactMember member; - bool multixid_valid; - - /* - * Read this multixid's members. - * - * Locking-only XIDs that may be part of multi-xids don't matter - * after upgrade, as there can be no transactions running across - * upgrade. So as a small optimization, we only read one member - * from each multixid: the one updating one, or if there was no - * update, arbitrarily the first locking xid. - */ - multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); + for (MultiXactId multi = from_multi; multi != to_multi;) + { + MultiXactMember member; + bool multixid_valid; - /* - * Write the new offset to pg_multixact/offsets. - * - * Even if this multixid is invalid, we still need to write its - * offset if the *previous* multixid was valid. That's because - * when reading a multixid, the number of members is calculated - * from the difference between the two offsets. - */ - RecordMultiXactOffset(offsets_writer, multi, - (multixid_valid || prev_multixid_valid) ? next_offset : 0); + /* + * Read this multixid's members. + * + * Locking-only XIDs that may be part of multi-xids don't matter after + * upgrade, as there can be no transactions running across upgrade. So + * as a small optimization, we only read one member from each + * multixid: the one updating one, or if there was no update, + * arbitrarily the first locking xid. + */ + multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); - /* Write the members */ - if (multixid_valid) - { - RecordMultiXactMembers(members_writer, next_offset, 1, &member); - next_offset += 1; - } + /* + * Write the new offset to pg_multixact/offsets. + * + * Even if this multixid is invalid, we still need to write its offset + * if the *previous* multixid was valid. That's because when reading + * a multixid, the number of members is calculated from the difference + * between the two offsets. + */ + RecordMultiXactOffset(offsets_writer, multi, + (multixid_valid || prev_multixid_valid) ? next_offset : 0); - /* Advance to next multixid, handling wraparound */ - multi++; - if (multi < FirstMultiXactId) - multi = FirstMultiXactId; - prev_multixid_valid = multixid_valid; + /* Write the members */ + if (multixid_valid) + { + RecordMultiXactMembers(members_writer, next_offset, 1, &member); + next_offset += 1; } - FreeOldMultiXactReader(old_reader); + /* Advance to next multixid, handling wraparound */ + multi++; + if (multi < FirstMultiXactId) + multi = FirstMultiXactId; + prev_multixid_valid = multixid_valid; + } + + FreeOldMultiXactReader(old_reader); /* Write the final 'next' offset to the last SLRU page */ RecordMultiXactOffset(offsets_writer, to_multi, diff --git a/src/bin/pg_upgrade/pg_upgrade.c b/src/bin/pg_upgrade/pg_upgrade.c index c6af9035665..7366fd4627c 100644 --- a/src/bin/pg_upgrade/pg_upgrade.c +++ b/src/bin/pg_upgrade/pg_upgrade.c @@ -833,7 +833,7 @@ copy_xact_xlog_xid(void) * Determine the range of multixacts to convert. */ nxtmulti = old_cluster.controldata.chkpnt_nxtmulti; - oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; + oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; /* handle wraparound */ if (nxtmulti < FirstMultiXactId) nxtmulti = FirstMultiXactId; @@ -898,15 +898,15 @@ set_frozenxids(void) int i_datname; int i_datallowconn; - prep_status("Setting frozenxid and minmxid counters in new cluster"); + prep_status("Setting frozenxid and minmxid counters in new cluster"); conn_template1 = connectToServer(&new_cluster, "template1"); - /* set pg_database.datfrozenxid */ - PQclear(executeQueryOrDie(conn_template1, - "UPDATE pg_catalog.pg_database " - "SET datfrozenxid = '%u'", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_database.datfrozenxid */ + PQclear(executeQueryOrDie(conn_template1, + "UPDATE pg_catalog.pg_database " + "SET datfrozenxid = '%u'", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_database.datminmxid */ PQclear(executeQueryOrDie(conn_template1, @@ -942,16 +942,16 @@ set_frozenxids(void) conn = connectToServer(&new_cluster, datname); - /* set pg_class.relfrozenxid */ - PQclear(executeQueryOrDie(conn, - "UPDATE pg_catalog.pg_class " - "SET relfrozenxid = '%u' " - /* only heap, materialized view, and TOAST are vacuumed */ - "WHERE relkind IN (" - CppAsString2(RELKIND_RELATION) ", " - CppAsString2(RELKIND_MATVIEW) ", " - CppAsString2(RELKIND_TOASTVALUE) ")", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_class.relfrozenxid */ + PQclear(executeQueryOrDie(conn, + "UPDATE pg_catalog.pg_class " + "SET relfrozenxid = '%u' " + /* only heap, materialized view, and TOAST are vacuumed */ + "WHERE relkind IN (" + CppAsString2(RELKIND_RELATION) ", " + CppAsString2(RELKIND_MATVIEW) ", " + CppAsString2(RELKIND_TOASTVALUE) ")", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_class.relminmxid */ PQclear(executeQueryOrDie(conn, diff --git a/src/bin/pg_upgrade/relfilenumber.c b/src/bin/pg_upgrade/relfilenumber.c index ec2ff7acb21..6c467bdc8a5 100644 --- a/src/bin/pg_upgrade/relfilenumber.c +++ b/src/bin/pg_upgrade/relfilenumber.c @@ -587,32 +587,32 @@ transfer_relfile(FileNameMap *map, const char *type_suffix) /* Copying files might take some time, so give feedback. */ pg_log(PG_STATUS, "%s", old_file); - switch (user_opts.transfer_mode) - { - case TRANSFER_MODE_CLONE: - pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", - old_file, new_file); - cloneFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", - old_file, new_file); - copyFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY_FILE_RANGE: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", - old_file, new_file); - copyFileByRange(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_LINK: - pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", - old_file, new_file); - linkFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_SWAP: - /* swap mode is handled in its own code path */ - pg_fatal("should never happen"); - break; - } + switch (user_opts.transfer_mode) + { + case TRANSFER_MODE_CLONE: + pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", + old_file, new_file); + cloneFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", + old_file, new_file); + copyFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY_FILE_RANGE: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", + old_file, new_file); + copyFileByRange(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_LINK: + pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", + old_file, new_file); + linkFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_SWAP: + /* swap mode is handled in its own code path */ + pg_fatal("should never happen"); + break; + } } } diff --git a/src/bin/pg_upgrade/t/006_transfer_modes.pl b/src/bin/pg_upgrade/t/006_transfer_modes.pl index 9efa5dc863c..360d05c4b68 100644 --- a/src/bin/pg_upgrade/t/006_transfer_modes.pl +++ b/src/bin/pg_upgrade/t/006_transfer_modes.pl @@ -29,10 +29,8 @@ sub test_mode } $new->init(); - $new->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); - $old->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); + $new->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); + $old->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); # We can only test security labels if both the old and new installations # have dummy_seclabel. @@ -76,15 +74,14 @@ sub test_mode "CREATE TABLE test4 AS SELECT generate_series(400, 502)"); } - $old->safe_psql('postgres', - "CREATE TABLESPACE inplc_tblspc LOCATION ''"); - $old->safe_psql('postgres', - "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); - $old->safe_psql('postgres', - "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" - ); - $old->safe_psql('testdb3', - "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); + $old->safe_psql('postgres', "CREATE TABLESPACE inplc_tblspc LOCATION ''"); + $old->safe_psql('postgres', + "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); + $old->safe_psql('postgres', + "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" + ); + $old->safe_psql('testdb3', + "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); # While we are here, test handling of large objects. $old->safe_psql( @@ -152,12 +149,10 @@ sub test_mode } # Tests for in-place tablespaces. - $result = - $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); - is($result, '104', "test5 data after pg_upgrade $mode"); - $result = - $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); - is($result, '105', "test6 data after pg_upgrade $mode"); + $result = $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); + is($result, '104', "test5 data after pg_upgrade $mode"); + $result = $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); + is($result, '105', "test6 data after pg_upgrade $mode"); # Tests for large objects $result = $new->safe_psql('postgres', "SELECT lo_get(4532)"); diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index 44ef11d980e..c90bf8bbde2 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -6278,23 +6278,22 @@ get_create_object_cmd(EditableObjectType obj_type, Oid oid, * ensure the right view gets replaced. Also, check relation kind * to be sure it's a view. * - * Views may have WITH [LOCAL|CASCADED] - * CHECK OPTION. These are not part of the view definition - * returned by pg_get_viewdef() and so need to be retrieved - * separately. Materialized views may have - * arbitrary storage parameter reloptions. + * Views may have WITH [LOCAL|CASCADED] CHECK OPTION. These are + * not part of the view definition returned by pg_get_viewdef() + * and so need to be retrieved separately. Materialized views may + * have arbitrary storage parameter reloptions. */ printfPQExpBuffer(query, "/* %s */\n", _("Get view's definition and details")); - appendPQExpBuffer(query, - "SELECT nspname, relname, relkind, " - "pg_catalog.pg_get_viewdef(c.oid, true), " - "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " - "FROM pg_catalog.pg_class c " - "LEFT JOIN pg_catalog.pg_namespace n " - "ON c.relnamespace = n.oid WHERE c.oid = %u", - oid); + appendPQExpBuffer(query, + "SELECT nspname, relname, relkind, " + "pg_catalog.pg_get_viewdef(c.oid, true), " + "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " + "FROM pg_catalog.pg_class c " + "LEFT JOIN pg_catalog.pg_namespace n " + "ON c.relnamespace = n.oid WHERE c.oid = %u", + oid); break; } diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index ce99137c613..ac0c55e7aa5 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -387,19 +387,19 @@ describeFunctions(const char *functypes, const char *func_pattern, gettext_noop("stable"), gettext_noop("volatile"), gettext_noop("Volatility")); - appendPQExpBuffer(&buf, - ",\n CASE\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" - " END as \"%s\"", - gettext_noop("restricted"), - gettext_noop("safe"), - gettext_noop("unsafe"), - gettext_noop("Parallel")); + appendPQExpBuffer(&buf, + ",\n CASE\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" + " END as \"%s\"", + gettext_noop("restricted"), + gettext_noop("safe"), + gettext_noop("unsafe"), + gettext_noop("Parallel")); appendPQExpBuffer(&buf, ",\n pg_catalog.pg_get_userbyid(p.proowner) as \"%s\"" ",\n CASE WHEN prosecdef THEN '%s' ELSE '%s' END AS \"%s\"" @@ -599,8 +599,8 @@ describeFunctions(const char *functypes, const char *func_pattern, myopt.title = _("List of functions"); myopt.translate_header = true; - myopt.translate_columns = translate_columns; - myopt.n_translate_columns = lengthof(translate_columns); + myopt.translate_columns = translate_columns; + myopt.n_translate_columns = lengthof(translate_columns); printQuery(res, &myopt, pset.queryFout, false, pset.logfile); @@ -1086,38 +1086,38 @@ permissionsList(const char *pattern, bool showSystem) " ), E'\\n') AS \"%s\"", gettext_noop("Column privileges")); - appendPQExpBuffer(&buf, - ",\n pg_catalog.array_to_string(ARRAY(\n" - " SELECT polname\n" - " || CASE WHEN NOT polpermissive THEN\n" - " E' (RESTRICTIVE)'\n" - " ELSE '' END\n" - " || CASE WHEN polcmd != '*' THEN\n" - " E' (' || polcmd::pg_catalog.text || E'):'\n" - " ELSE E':'\n" - " END\n" - " || CASE WHEN polqual IS NOT NULL THEN\n" - " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" - " ELSE E''\n" - " END\n" - " || CASE WHEN polwithcheck IS NOT NULL THEN\n" - " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" - " ELSE E''\n" - " END" - " || CASE WHEN polroles <> '{0}' THEN\n" - " E'\\n to: ' || pg_catalog.array_to_string(\n" - " ARRAY(\n" - " SELECT rolname\n" - " FROM pg_catalog.pg_roles\n" - " WHERE oid = ANY (polroles)\n" - " ORDER BY 1\n" - " ), E', ')\n" - " ELSE E''\n" - " END\n" - " FROM pg_catalog.pg_policy pol\n" - " WHERE polrelid = c.oid), E'\\n')\n" - " AS \"%s\"", - gettext_noop("Policies")); + appendPQExpBuffer(&buf, + ",\n pg_catalog.array_to_string(ARRAY(\n" + " SELECT polname\n" + " || CASE WHEN NOT polpermissive THEN\n" + " E' (RESTRICTIVE)'\n" + " ELSE '' END\n" + " || CASE WHEN polcmd != '*' THEN\n" + " E' (' || polcmd::pg_catalog.text || E'):'\n" + " ELSE E':'\n" + " END\n" + " || CASE WHEN polqual IS NOT NULL THEN\n" + " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" + " ELSE E''\n" + " END\n" + " || CASE WHEN polwithcheck IS NOT NULL THEN\n" + " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" + " ELSE E''\n" + " END" + " || CASE WHEN polroles <> '{0}' THEN\n" + " E'\\n to: ' || pg_catalog.array_to_string(\n" + " ARRAY(\n" + " SELECT rolname\n" + " FROM pg_catalog.pg_roles\n" + " WHERE oid = ANY (polroles)\n" + " ORDER BY 1\n" + " ), E', ')\n" + " ELSE E''\n" + " END\n" + " FROM pg_catalog.pg_policy pol\n" + " WHERE polrelid = c.oid), E'\\n')\n" + " AS \"%s\"", + gettext_noop("Policies")); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_class c\n" " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n" @@ -1675,27 +1675,27 @@ describeOneTableDetails(const char *schemaname, char *footers[3] = {NULL, NULL, NULL}; printfPQExpBuffer(&buf, "/* %s */\n", _("Get sequence information")); - appendPQExpBuffer(&buf, - "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" - " seqstart AS \"%s\",\n" - " seqmin AS \"%s\",\n" - " seqmax AS \"%s\",\n" - " seqincrement AS \"%s\",\n" - " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" - " seqcache AS \"%s\"\n", - gettext_noop("Type"), - gettext_noop("Start"), - gettext_noop("Minimum"), - gettext_noop("Maximum"), - gettext_noop("Increment"), - gettext_noop("yes"), - gettext_noop("no"), - gettext_noop("Cycles?"), - gettext_noop("Cache")); - appendPQExpBuffer(&buf, - "FROM pg_catalog.pg_sequence\n" - "WHERE seqrelid = '%s';", - oid); + appendPQExpBuffer(&buf, + "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" + " seqstart AS \"%s\",\n" + " seqmin AS \"%s\",\n" + " seqmax AS \"%s\",\n" + " seqincrement AS \"%s\",\n" + " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" + " seqcache AS \"%s\"\n", + gettext_noop("Type"), + gettext_noop("Start"), + gettext_noop("Minimum"), + gettext_noop("Maximum"), + gettext_noop("Increment"), + gettext_noop("yes"), + gettext_noop("no"), + gettext_noop("Cycles?"), + gettext_noop("Cache")); + appendPQExpBuffer(&buf, + "FROM pg_catalog.pg_sequence\n" + "WHERE seqrelid = '%s';", + oid); res = PSQLexec(buf.data); if (!res) @@ -1913,7 +1913,7 @@ describeOneTableDetails(const char *schemaname, appendPQExpBufferStr(&buf, ",\n (SELECT c.collname FROM pg_catalog.pg_collation c, pg_catalog.pg_type t\n" " WHERE c.oid = a.attcollation AND t.oid = a.atttypid AND a.attcollation <> t.typcollation) AS attcollation"); attcoll_col = cols++; - appendPQExpBufferStr(&buf, ",\n a.attidentity"); + appendPQExpBufferStr(&buf, ",\n a.attidentity"); attidentity_col = cols++; if (pset.sversion >= 120000) appendPQExpBufferStr(&buf, ",\n a.attgenerated"); @@ -2326,7 +2326,7 @@ describeOneTableDetails(const char *schemaname, CppAsString2(CONSTRAINT_EXCLUSION) ") AND " "condeferred) AS condeferred,\n"); - appendPQExpBufferStr(&buf, "i.indisreplident,\n"); + appendPQExpBufferStr(&buf, "i.indisreplident,\n"); if (pset.sversion >= 150000) appendPQExpBufferStr(&buf, "i.indnullsnotdistinct,\n"); @@ -2431,7 +2431,7 @@ describeOneTableDetails(const char *schemaname, "pg_catalog.pg_get_indexdef(i.indexrelid, 0, true),\n " "pg_catalog.pg_get_constraintdef(con.oid, true), " "contype, condeferrable, condeferred"); - appendPQExpBufferStr(&buf, ", i.indisreplident"); + appendPQExpBufferStr(&buf, ", i.indisreplident"); appendPQExpBufferStr(&buf, ", c2.reltablespace"); if (pset.sversion >= 180000) appendPQExpBufferStr(&buf, ", con.conperiod"); @@ -2682,81 +2682,80 @@ describeOneTableDetails(const char *schemaname, PQclear(result); /* print any row-level policies */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get row-level policies for this table")); - appendPQExpBufferStr(&buf, "SELECT pol.polname,"); - appendPQExpBufferStr(&buf, - " pol.polpermissive,\n"); - appendPQExpBuffer(&buf, - " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" - " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" - " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" - " CASE pol.polcmd\n" - " WHEN 'r' THEN 'SELECT'\n" - " WHEN 'a' THEN 'INSERT'\n" - " WHEN 'w' THEN 'UPDATE'\n" - " WHEN 'd' THEN 'DELETE'\n" - " END AS cmd\n" - "FROM pg_catalog.pg_policy pol\n" - "WHERE pol.polrelid = '%s' ORDER BY 1;", - oid); + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get row-level policies for this table")); + appendPQExpBufferStr(&buf, "SELECT pol.polname,"); + appendPQExpBufferStr(&buf, + " pol.polpermissive,\n"); + appendPQExpBuffer(&buf, + " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" + " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" + " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" + " CASE pol.polcmd\n" + " WHEN 'r' THEN 'SELECT'\n" + " WHEN 'a' THEN 'INSERT'\n" + " WHEN 'w' THEN 'UPDATE'\n" + " WHEN 'd' THEN 'DELETE'\n" + " END AS cmd\n" + "FROM pg_catalog.pg_policy pol\n" + "WHERE pol.polrelid = '%s' ORDER BY 1;", + oid); - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - /* - * Handle cases where RLS is enabled and there are policies, or - * there aren't policies, or RLS isn't enabled but there are - * policies - */ - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies:")); + /* + * Handle cases where RLS is enabled and there are policies, or there + * aren't policies, or RLS isn't enabled but there are policies + */ + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies:")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled):")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled):")); - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); - if (!tableinfo.rowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (row security disabled):")); + if (!tableinfo.rowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (row security disabled):")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " POLICY \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " POLICY \"%s\"", + PQgetvalue(result, i, 0)); - if (*(PQgetvalue(result, i, 1)) == 'f') - appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); + if (*(PQgetvalue(result, i, 1)) == 'f') + appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); - if (!PQgetisnull(result, i, 5)) - appendPQExpBuffer(&buf, " FOR %s", - PQgetvalue(result, i, 5)); + if (!PQgetisnull(result, i, 5)) + appendPQExpBuffer(&buf, " FOR %s", + PQgetvalue(result, i, 5)); - if (!PQgetisnull(result, i, 2)) - { - appendPQExpBuffer(&buf, "\n TO %s", - PQgetvalue(result, i, 2)); - } + if (!PQgetisnull(result, i, 2)) + { + appendPQExpBuffer(&buf, "\n TO %s", + PQgetvalue(result, i, 2)); + } - if (!PQgetisnull(result, i, 3)) - appendPQExpBuffer(&buf, "\n USING (%s)", - PQgetvalue(result, i, 3)); + if (!PQgetisnull(result, i, 3)) + appendPQExpBuffer(&buf, "\n USING (%s)", + PQgetvalue(result, i, 3)); - if (!PQgetisnull(result, i, 4)) - appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", - PQgetvalue(result, i, 4)); + if (!PQgetisnull(result, i, 4)) + appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", + PQgetvalue(result, i, 4)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* print any extended statistics */ if (pset.sversion >= 140000) @@ -3025,115 +3024,115 @@ describeOneTableDetails(const char *schemaname, } /* print any publications */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get publications that publish this table")); - if (pset.sversion >= 150000) + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get publications that publish this table")); + if (pset.sversion >= 150000) + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" + " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" + "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" + "UNION\n" + "SELECT pubname\n" + " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" + " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" + " (SELECT pg_catalog.string_agg(attname, ', ')\n" + " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" + " pg_catalog.pg_attribute\n" + " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" + " ELSE NULL END) " + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" + "WHERE pr.prrelid = '%s'\n", + oid, oid, oid); + + if (pset.sversion >= 190000) { + /* + * Skip entries where this relation appears in the + * publication's EXCEPT list. + */ appendPQExpBuffer(&buf, + " AND NOT pr.prexcept\n" + "UNION\n" "SELECT pubname\n" " , NULL\n" " , NULL\n" "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" - " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" - "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" - "UNION\n" - "SELECT pubname\n" - " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" - " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" - " (SELECT pg_catalog.string_agg(attname, ', ')\n" - " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" - " pg_catalog.pg_attribute\n" - " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" - " ELSE NULL END) " - "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" - "WHERE pr.prrelid = '%s'\n", + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + " AND NOT EXISTS (\n" + " SELECT 1\n" + " FROM pg_catalog.pg_publication_rel pr\n" + " WHERE pr.prpubid = p.oid AND\n" + " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" + "ORDER BY 1;", oid, oid, oid); - - if (pset.sversion >= 190000) - { - /* - * Skip entries where this relation appears in the - * publication's EXCEPT list. - */ - appendPQExpBuffer(&buf, - " AND NOT pr.prexcept\n" - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - " AND NOT EXISTS (\n" - " SELECT 1\n" - " FROM pg_catalog.pg_publication_rel pr\n" - " WHERE pr.prpubid = p.oid AND\n" - " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" - "ORDER BY 1;", - oid, oid, oid); - } - else - { - appendPQExpBuffer(&buf, - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - "ORDER BY 1;", - oid); - } } else { appendPQExpBuffer(&buf, + "UNION\n" "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - "WHERE pr.prrelid = '%s'\n" - "UNION ALL\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" + " , NULL\n" + " , NULL\n" "FROM pg_catalog.pg_publication p\n" "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" "ORDER BY 1;", - oid, oid); + oid); } + } + else + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + "WHERE pr.prrelid = '%s'\n" + "UNION ALL\n" + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + "ORDER BY 1;", + oid, oid); + } - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - if (tuples > 0) - printTableAddFooter(&cont, _("Included in publications:")); + if (tuples > 0) + printTableAddFooter(&cont, _("Included in publications:")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " \"%s\"", + PQgetvalue(result, i, 0)); - /* column list (if any) */ - if (!PQgetisnull(result, i, 2)) - appendPQExpBuffer(&buf, " (%s)", - PQgetvalue(result, i, 2)); + /* column list (if any) */ + if (!PQgetisnull(result, i, 2)) + appendPQExpBuffer(&buf, " (%s)", + PQgetvalue(result, i, 2)); - /* row filter (if any) */ - if (!PQgetisnull(result, i, 1)) - appendPQExpBuffer(&buf, " WHERE %s", - PQgetvalue(result, i, 1)); + /* row filter (if any) */ + if (!PQgetisnull(result, i, 1)) + appendPQExpBuffer(&buf, " WHERE %s", + PQgetvalue(result, i, 1)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* Print publications where the table is in the EXCEPT clause */ if (pset.sversion >= 190000) @@ -3805,7 +3804,7 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) ncols++; } appendPQExpBufferStr(&buf, "\n, r.rolreplication"); - appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); + appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_roles r\n"); @@ -3860,8 +3859,8 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) if (strcmp(PQgetvalue(res, i, (verbose ? 9 : 8)), "t") == 0) add_role_attribute(&buf, _("Replication")); - if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) - add_role_attribute(&buf, _("Bypass RLS")); + if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) + add_role_attribute(&buf, _("Bypass RLS")); conns = atoi(PQgetvalue(res, i, 6)); if (conns >= 0) @@ -5155,14 +5154,14 @@ listCollations(const char *pattern, bool verbose, bool showSystem) gettext_noop("Schema"), gettext_noop("Name")); - appendPQExpBuffer(&buf, - " CASE c.collprovider " - "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " - "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " - "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " - "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " - "END AS \"%s\",\n", - gettext_noop("Provider")); + appendPQExpBuffer(&buf, + " CASE c.collprovider " + "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " + "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " + "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " + "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " + "END AS \"%s\",\n", + gettext_noop("Provider")); appendPQExpBuffer(&buf, " c.collcollate AS \"%s\",\n" -- 2.50.1 (Apple Git-155) --aHl3HfeiUuO3zeNC-- ^ permalink raw reply [nested|flat] 59+ messages in thread
* [PATCH v6 4/4] run pgindent and pgperltidy @ 2026-06-30 18:24 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 59+ messages in thread From: Nathan Bossart @ 2026-06-30 18:24 UTC (permalink / raw) --- src/bin/pg_dump/pg_dump.c | 464 ++++++++++----------- src/bin/pg_dump/pg_dumpall.c | 30 +- src/bin/pg_upgrade/check.c | 16 +- src/bin/pg_upgrade/controldata.c | 2 +- src/bin/pg_upgrade/exec.c | 8 +- src/bin/pg_upgrade/multixact_rewrite.c | 80 ++-- src/bin/pg_upgrade/pg_upgrade.c | 34 +- src/bin/pg_upgrade/relfilenumber.c | 54 +-- src/bin/pg_upgrade/t/006_transfer_modes.pl | 33 +- src/bin/psql/command.c | 29 +- src/bin/psql/describe.c | 461 ++++++++++---------- 11 files changed, 601 insertions(+), 610 deletions(-) diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 65bd15ebfd2..5673268b467 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -1491,8 +1491,8 @@ setup_connection(Archive *AH, const char *dumpencoding, * Disable timeouts if supported. */ ExecuteSqlStatement(AH, "SET statement_timeout = 0"); - ExecuteSqlStatement(AH, "SET lock_timeout = 0"); - ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); + ExecuteSqlStatement(AH, "SET lock_timeout = 0"); + ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); if (AH->remoteVersion >= 170000) ExecuteSqlStatement(AH, "SET transaction_timeout = 0"); @@ -1505,10 +1505,10 @@ setup_connection(Archive *AH, const char *dumpencoding, /* * Adjust row-security mode, if supported. */ - if (dopt->enable_row_security) - ExecuteSqlStatement(AH, "SET row_security = on"); - else - ExecuteSqlStatement(AH, "SET row_security = off"); + if (dopt->enable_row_security) + ExecuteSqlStatement(AH, "SET row_security = on"); + else + ExecuteSqlStatement(AH, "SET row_security = off"); /* * For security reasons, we restrict the expansion of non-system views and @@ -1933,10 +1933,9 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) addObjectDependency(dobj, ext->dobj.dumpId); /* - * Mark the member object to have any non-initial ACLs - * dumped. (Any initial ACLs will be removed later, using data from - * pg_init_privs, so that we'll dump only the delta from the extension's - * initial setup.) + * Mark the member object to have any non-initial ACLs dumped. (Any + * initial ACLs will be removed later, using data from pg_init_privs, so + * that we'll dump only the delta from the extension's initial setup.) * * In binary upgrades, we still dump all components of the members * individually, since the idea is to exactly reproduce the database @@ -1953,7 +1952,7 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) if (fout->dopt->binary_upgrade) dobj->dump = ext->dobj.dump; else - dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); + dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); return true; } @@ -1987,9 +1986,9 @@ selectDumpableNamespace(NamespaceInfo *nsinfo, Archive *fout) else if (strcmp(nsinfo->dobj.name, "pg_catalog") == 0) { /* - * We dump out any ACLs defined in pg_catalog, if - * they are interesting (and not the original ACLs which were set at - * initdb time, see pg_init_privs). + * We dump out any ACLs defined in pg_catalog, if they are interesting + * (and not the original ACLs which were set at initdb time, see + * pg_init_privs). */ nsinfo->dobj.dump_contains = nsinfo->dobj.dump = DUMP_COMPONENT_ACL; } @@ -3296,7 +3295,7 @@ dumpDatabase(Archive *fout) "datcollate, datctype, datfrozenxid, " "datacl, acldefault('d', datdba) AS acldefault, " "datistemplate, datconnlimit, "); - appendPQExpBufferStr(dbQry, "datminmxid, "); + appendPQExpBufferStr(dbQry, "datminmxid, "); if (fout->remoteVersion >= 170000) appendPQExpBufferStr(dbQry, "datlocprovider, datlocale, datcollversion, "); else if (fout->remoteVersion >= 150000) @@ -3638,11 +3637,11 @@ dumpDatabase(Archive *fout) ii_oid, ii_relminmxid; - appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" - "FROM pg_catalog.pg_class\n" - "WHERE oid IN (%u, %u, %u, %u);\n", - LargeObjectRelationId, LargeObjectLOidPNIndexId, - LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); + appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" + "FROM pg_catalog.pg_class\n" + "WHERE oid IN (%u, %u, %u, %u);\n", + LargeObjectRelationId, LargeObjectLOidPNIndexId, + LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); lo_res = ExecuteSqlQuery(fout, loFrozenQry->data, PGRES_TUPLES_OK); @@ -4274,7 +4273,7 @@ getPolicies(Archive *fout, TableInfo tblinfo[], int numTables) printfPQExpBuffer(query, "SELECT pol.oid, pol.tableoid, pol.polrelid, pol.polname, pol.polcmd, "); - appendPQExpBufferStr(query, "pol.polpermissive, "); + appendPQExpBufferStr(query, "pol.polpermissive, "); appendPQExpBuffer(query, "CASE WHEN pol.polroles = '{0}' THEN NULL ELSE " " pg_catalog.array_to_string(ARRAY(SELECT pg_catalog.quote_ident(rolname) from pg_catalog.pg_roles WHERE oid = ANY(pol.polroles)), ', ') END AS polroles, " @@ -6633,9 +6632,9 @@ getAccessMethods(Archive *fout) * Select all access methods from pg_am table. */ appendPQExpBufferStr(query, "SELECT tableoid, oid, amname, "); - appendPQExpBufferStr(query, - "amtype, " - "amhandler::pg_catalog.regproc AS amhandler "); + appendPQExpBufferStr(query, + "amtype, " + "amhandler::pg_catalog.regproc AS amhandler "); appendPQExpBufferStr(query, "FROM pg_am"); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6827,35 +6826,35 @@ getAggregates(Archive *fout) * Find all interesting aggregates. See comment in getFuncs() for the * rationale behind the filtering logic. */ - agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" - : "p.proisagg"); + agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" + : "p.proisagg"); - appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " - "p.proname AS aggname, " - "p.pronamespace AS aggnamespace, " - "p.pronargs, p.proargtypes, " - "p.proowner, " - "p.proacl AS aggacl, " - "acldefault('f', p.proowner) AS acldefault " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s AND (" - "p.pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog') OR " - "p.proacl IS DISTINCT FROM pip.initprivs", - agg_check); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - " OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); - appendPQExpBufferChar(query, ')'); + appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " + "p.proname AS aggname, " + "p.pronamespace AS aggnamespace, " + "p.pronargs, p.proargtypes, " + "p.proowner, " + "p.proacl AS aggacl, " + "acldefault('f', p.proowner) AS acldefault " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s AND (" + "p.pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog') OR " + "p.proacl IS DISTINCT FROM pip.initprivs", + agg_check); + if (dopt->binary_upgrade) + appendPQExpBufferStr(query, + " OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6957,53 +6956,53 @@ getFuncs(Archive *fout) * include them, since we want to dump extension members individually in * that mode. Also, if they are used by casts or transforms then we need * to gather the information about them, though they won't be dumped if - * they are built-in. Also, include functions in - * pg_catalog if they have an ACL different from what's shown in - * pg_init_privs (so we have to join to pg_init_privs; annoying). + * they are built-in. Also, include functions in pg_catalog if they have + * an ACL different from what's shown in pg_init_privs (so we have to join + * to pg_init_privs; annoying). */ - not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" - : "NOT p.proisagg"); + not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" + : "NOT p.proisagg"); - appendPQExpBuffer(query, - "SELECT p.tableoid, p.oid, p.proname, p.prolang, " - "p.pronargs, p.proargtypes, p.prorettype, " - "p.proacl, " - "acldefault('f', p.proowner) AS acldefault, " - "p.pronamespace, " - "p.proowner " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s" - "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " - "WHERE classid = 'pg_proc'::regclass AND " - "objid = p.oid AND deptype = 'i')" - "\n AND (" - "\n pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog')" - "\n OR EXISTS (SELECT 1 FROM pg_cast" - "\n WHERE pg_cast.oid > %u " - "\n AND p.oid = pg_cast.castfunc)" - "\n OR EXISTS (SELECT 1 FROM pg_transform" - "\n WHERE pg_transform.oid > %u AND " - "\n (p.oid = pg_transform.trffromsql" - "\n OR p.oid = pg_transform.trftosql))", - not_agg_check, - g_last_builtin_oid, - g_last_builtin_oid); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); + appendPQExpBuffer(query, + "SELECT p.tableoid, p.oid, p.proname, p.prolang, " + "p.pronargs, p.proargtypes, p.prorettype, " + "p.proacl, " + "acldefault('f', p.proowner) AS acldefault, " + "p.pronamespace, " + "p.proowner " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s" + "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " + "WHERE classid = 'pg_proc'::regclass AND " + "objid = p.oid AND deptype = 'i')" + "\n AND (" + "\n pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog')" + "\n OR EXISTS (SELECT 1 FROM pg_cast" + "\n WHERE pg_cast.oid > %u " + "\n AND p.oid = pg_cast.castfunc)" + "\n OR EXISTS (SELECT 1 FROM pg_transform" + "\n WHERE pg_transform.oid > %u AND " + "\n (p.oid = pg_transform.trffromsql" + "\n OR p.oid = pg_transform.trftosql))", + not_agg_check, + g_last_builtin_oid, + g_last_builtin_oid); + if (dopt->binary_upgrade) appendPQExpBufferStr(query, - "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); - appendPQExpBufferChar(query, ')'); + "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferStr(query, + "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -7252,31 +7251,31 @@ getTables(Archive *fout, int *numTables) appendPQExpBufferStr(query, "c.relhasoids, "); - appendPQExpBufferStr(query, - "c.relispopulated, "); + appendPQExpBufferStr(query, + "c.relispopulated, "); - appendPQExpBufferStr(query, - "c.relreplident, "); + appendPQExpBufferStr(query, + "c.relreplident, "); - appendPQExpBufferStr(query, - "c.relrowsecurity, c.relforcerowsecurity, "); + appendPQExpBufferStr(query, + "c.relrowsecurity, c.relforcerowsecurity, "); - appendPQExpBufferStr(query, - "c.relminmxid, tc.relminmxid AS tminmxid, "); + appendPQExpBufferStr(query, + "c.relminmxid, tc.relminmxid AS tminmxid, "); - appendPQExpBufferStr(query, - "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); + appendPQExpBufferStr(query, + "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); - appendPQExpBufferStr(query, - "am.amname, "); + appendPQExpBufferStr(query, + "am.amname, "); - appendPQExpBufferStr(query, - "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); + appendPQExpBufferStr(query, + "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); - appendPQExpBufferStr(query, - "c.relispartition AS ispartition "); + appendPQExpBufferStr(query, + "c.relispartition AS ispartition "); /* * Left join to pg_depend to pick up dependency info linking sequences to @@ -7296,8 +7295,8 @@ getTables(Archive *fout, int *numTables) /* * Left join to pg_am to pick up the amname. */ - appendPQExpBufferStr(query, - "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); + appendPQExpBufferStr(query, + "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); /* * We purposefully ignore toast OIDs for partitioned tables; the reason is @@ -7868,8 +7867,8 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables) "t.reloptions AS indreloptions, "); - appendPQExpBufferStr(query, - "i.indisreplident, "); + appendPQExpBufferStr(query, + "i.indisreplident, "); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -9313,8 +9312,8 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables) appendPQExpBufferStr(q, "'' AS attcompression,\n"); - appendPQExpBufferStr(q, - "a.attidentity,\n"); + appendPQExpBufferStr(q, + "a.attidentity,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(q, @@ -10717,73 +10716,73 @@ getAdditionalACLs(Archive *fout) PQclear(res); /* Fetch initial-privileges data */ - printfPQExpBuffer(query, - "SELECT objoid, classoid, objsubid, privtype, initprivs " - "FROM pg_init_privs"); + printfPQExpBuffer(query, + "SELECT objoid, classoid, objsubid, privtype, initprivs " + "FROM pg_init_privs"); - res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); + res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); - ntups = PQntuples(res); - for (i = 0; i < ntups; i++) - { - Oid objoid = atooid(PQgetvalue(res, i, 0)); - Oid classoid = atooid(PQgetvalue(res, i, 1)); - int objsubid = atoi(PQgetvalue(res, i, 2)); - char privtype = *(PQgetvalue(res, i, 3)); - char *initprivs = PQgetvalue(res, i, 4); - CatalogId objId; - DumpableObject *dobj; + ntups = PQntuples(res); + for (i = 0; i < ntups; i++) + { + Oid objoid = atooid(PQgetvalue(res, i, 0)); + Oid classoid = atooid(PQgetvalue(res, i, 1)); + int objsubid = atoi(PQgetvalue(res, i, 2)); + char privtype = *(PQgetvalue(res, i, 3)); + char *initprivs = PQgetvalue(res, i, 4); + CatalogId objId; + DumpableObject *dobj; - objId.tableoid = classoid; - objId.oid = objoid; - dobj = findObjectByCatalogId(objId); - /* OK to ignore entries we haven't got a DumpableObject for */ - if (dobj) + objId.tableoid = classoid; + objId.oid = objoid; + dobj = findObjectByCatalogId(objId); + /* OK to ignore entries we haven't got a DumpableObject for */ + if (dobj) + { + /* Cope with sub-object initprivs */ + if (objsubid != 0) { - /* Cope with sub-object initprivs */ - if (objsubid != 0) - { - if (dobj->objType == DO_TABLE) - { - /* For a column initprivs, set the table's ACL flags */ - dobj->components |= DUMP_COMPONENT_ACL; - ((TableInfo *) dobj)->hascolumnACLs = true; - } - else - pg_log_warning("unsupported pg_init_privs entry: %u %u %d", - classoid, objoid, objsubid); - continue; - } - - /* - * We ignore any pg_init_privs.initprivs entry for the public - * schema, as explained in getNamespaces(). - */ - if (dobj->objType == DO_NAMESPACE && - strcmp(dobj->name, "public") == 0) - continue; - - /* Else it had better be of a type we think has ACLs */ - if (dobj->objType == DO_NAMESPACE || - dobj->objType == DO_TYPE || - dobj->objType == DO_FUNC || - dobj->objType == DO_AGG || - dobj->objType == DO_TABLE || - dobj->objType == DO_PROCLANG || - dobj->objType == DO_FDW || - dobj->objType == DO_FOREIGN_SERVER) + if (dobj->objType == DO_TABLE) { - DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; - - daobj->dacl.privtype = privtype; - daobj->dacl.initprivs = pstrdup(initprivs); + /* For a column initprivs, set the table's ACL flags */ + dobj->components |= DUMP_COMPONENT_ACL; + ((TableInfo *) dobj)->hascolumnACLs = true; } else pg_log_warning("unsupported pg_init_privs entry: %u %u %d", classoid, objoid, objsubid); + continue; + } + + /* + * We ignore any pg_init_privs.initprivs entry for the public + * schema, as explained in getNamespaces(). + */ + if (dobj->objType == DO_NAMESPACE && + strcmp(dobj->name, "public") == 0) + continue; + + /* Else it had better be of a type we think has ACLs */ + if (dobj->objType == DO_NAMESPACE || + dobj->objType == DO_TYPE || + dobj->objType == DO_FUNC || + dobj->objType == DO_AGG || + dobj->objType == DO_TABLE || + dobj->objType == DO_PROCLANG || + dobj->objType == DO_FDW || + dobj->objType == DO_FOREIGN_SERVER) + { + DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; + + daobj->dacl.privtype = privtype; + daobj->dacl.initprivs = pstrdup(initprivs); } + else + pg_log_warning("unsupported pg_init_privs entry: %u %u %d", + classoid, objoid, objsubid); } - PQclear(res); + } + PQclear(res); destroyPQExpBuffer(query); } @@ -11128,8 +11127,8 @@ dumpRelationStats_dumper(Archive *fout, const void *userArg, const TocEntry *te) * The results must be in the order of the relations supplied in the * parameters to ensure we remain in sync as we walk through the TOC. * - * For versions before 19, the redundant filter clause on s.tablename = - * ANY(...) seems sufficient to convince the planner to use + * For versions before 19, the redundant filter clause on s.tablename + * = ANY(...) seems sufficient to convince the planner to use * pg_class_relname_nsp_index, which avoids a full scan of pg_stats. * In newer versions, pg_stats returns the table OIDs, eliminating the * need for that hack. @@ -13469,11 +13468,11 @@ dumpFunc(Archive *fout, const FuncInfo *finfo) "pg_catalog.pg_get_function_result(p.oid) AS funcresult,\n" "proleakproof,\n"); - appendPQExpBufferStr(query, - "array_to_string(protrftypes, ' ') AS protrftypes,\n"); + appendPQExpBufferStr(query, + "array_to_string(protrftypes, ' ') AS protrftypes,\n"); - appendPQExpBufferStr(query, - "proparallel,\n"); + appendPQExpBufferStr(query, + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -14963,9 +14962,9 @@ dumpCollation(Archive *fout, const CollInfo *collinfo) /* Get collation-specific details */ appendPQExpBufferStr(query, "SELECT "); - appendPQExpBufferStr(query, - "collprovider, " - "collversion, "); + appendPQExpBufferStr(query, + "collprovider, " + "collversion, "); if (fout->remoteVersion >= 120000) appendPQExpBufferStr(query, @@ -15372,23 +15371,23 @@ dumpAgg(Archive *fout, const AggInfo *agginfo) "pg_catalog.pg_get_function_arguments(p.oid) AS funcargs,\n" "pg_catalog.pg_get_function_identity_arguments(p.oid) AS funciargs,\n"); - appendPQExpBufferStr(query, - "aggkind,\n" - "aggmtransfn,\n" - "aggminvtransfn,\n" - "aggmfinalfn,\n" - "aggmtranstype::pg_catalog.regtype,\n" - "aggfinalextra,\n" - "aggmfinalextra,\n" - "aggtransspace,\n" - "aggmtransspace,\n" - "aggminitval,\n"); + appendPQExpBufferStr(query, + "aggkind,\n" + "aggmtransfn,\n" + "aggminvtransfn,\n" + "aggmfinalfn,\n" + "aggmtranstype::pg_catalog.regtype,\n" + "aggfinalextra,\n" + "aggmfinalextra,\n" + "aggtransspace,\n" + "aggmtransspace,\n" + "aggminitval,\n"); - appendPQExpBufferStr(query, - "aggcombinefn,\n" - "aggserialfn,\n" - "aggdeserialfn,\n" - "proparallel,\n"); + appendPQExpBufferStr(query, + "aggcombinefn,\n" + "aggserialfn,\n" + "aggdeserialfn,\n" + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -16848,30 +16847,30 @@ dumpTable(Archive *fout, const TableInfo *tbinfo) appendPQExpBufferStr(query, "PREPARE getColumnACLs(pg_catalog.oid) AS\n"); - /* - * In principle we should call acldefault('c', relowner) to - * get the default ACL for a column. However, we don't - * currently store the numeric OID of the relowner in - * TableInfo. We could convert the owner name using regrole, - * but that creates a risk of failure due to concurrent role - * renames. Given that the default ACL for columns is empty - * and is likely to stay that way, it's not worth extra cycles - * and risk to avoid hard-wiring that knowledge here. - */ - appendPQExpBufferStr(query, - "SELECT at.attname, " - "at.attacl, " - "'{}' AS acldefault, " - "pip.privtype, pip.initprivs " - "FROM pg_catalog.pg_attribute at " - "LEFT JOIN pg_catalog.pg_init_privs pip ON " - "(at.attrelid = pip.objoid " - "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " - "AND at.attnum = pip.objsubid) " - "WHERE at.attrelid = $1 AND " - "NOT at.attisdropped " - "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " - "ORDER BY at.attnum"); + /* + * In principle we should call acldefault('c', relowner) to get + * the default ACL for a column. However, we don't currently + * store the numeric OID of the relowner in TableInfo. We could + * convert the owner name using regrole, but that creates a risk + * of failure due to concurrent role renames. Given that the + * default ACL for columns is empty and is likely to stay that + * way, it's not worth extra cycles and risk to avoid hard-wiring + * that knowledge here. + */ + appendPQExpBufferStr(query, + "SELECT at.attname, " + "at.attacl, " + "'{}' AS acldefault, " + "pip.privtype, pip.initprivs " + "FROM pg_catalog.pg_attribute at " + "LEFT JOIN pg_catalog.pg_init_privs pip ON " + "(at.attrelid = pip.objoid " + "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " + "AND at.attnum = pip.objsubid) " + "WHERE at.attrelid = $1 AND " + "NOT at.attisdropped " + "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " + "ORDER BY at.attnum"); ExecuteSqlStatement(fout, query->data); @@ -19165,7 +19164,7 @@ collectSequences(Archive *fout) * pg_get_sequence_data(), but we only do so for non-schema-only dumps. */ if (fout->remoteVersion < 180000 || - (!fout->dopt->dumpData && !fout->dopt->sequence_data)) + (!fout->dopt->dumpData && !fout->dopt->sequence_data)) query = "SELECT seqrelid, format_type(seqtypid, NULL), " "seqstart, seqincrement, " "seqmax, seqmin, " @@ -19227,15 +19226,14 @@ dumpSequence(Archive *fout, const TableInfo *tbinfo) qseqname = pg_strdup(fmtId(tbinfo->dobj.name)); /* - * The sequence information is gathered in a sorted - * table before any calls to dumpSequence(). See collectSequences() for - * more information. + * The sequence information is gathered in a sorted table before any calls + * to dumpSequence(). See collectSequences() for more information. */ - Assert(sequences); + Assert(sequences); - key.oid = tbinfo->dobj.catId.oid; - seq = bsearch(&key, sequences, nsequences, - sizeof(SequenceItem), SequenceItemCmp); + key.oid = tbinfo->dobj.catId.oid; + seq = bsearch(&key, sequences, nsequences, + sizeof(SequenceItem), SequenceItemCmp); /* Calculate default limits for a sequence of this type */ is_ascending = (seq->incby >= 0); diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c index e68937c9934..afcd9a218d8 100644 --- a/src/bin/pg_dump/pg_dumpall.c +++ b/src/bin/pg_dump/pg_dumpall.c @@ -785,11 +785,11 @@ dropRoles(PGconn *conn) int i_rolname; int i; - printfPQExpBuffer(buf, - "SELECT rolname " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 1", role_catalog); + printfPQExpBuffer(buf, + "SELECT rolname " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 1", role_catalog); res = executeQuery(conn, buf->data); @@ -843,16 +843,16 @@ dumpRoles(PGconn *conn) * Notes: rolconfig is dumped later, and pg_authid must be used for * extracting rolcomment regardless of role_catalog. */ - printfPQExpBuffer(buf, - "SELECT oid, rolname, rolsuper, rolinherit, " - "rolcreaterole, rolcreatedb, " - "rolcanlogin, rolconnlimit, rolpassword, " - "rolvaliduntil, rolreplication, rolbypassrls, " - "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " - "rolname = current_user AS is_current_user " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 2", role_catalog); + printfPQExpBuffer(buf, + "SELECT oid, rolname, rolsuper, rolinherit, " + "rolcreaterole, rolcreatedb, " + "rolcanlogin, rolconnlimit, rolpassword, " + "rolvaliduntil, rolreplication, rolbypassrls, " + "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " + "rolname = current_user AS is_current_user " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 2", role_catalog); res = executeQuery(conn, buf->data); diff --git a/src/bin/pg_upgrade/check.c b/src/bin/pg_upgrade/check.c index 786c1474829..f725f5ee3e2 100644 --- a/src/bin/pg_upgrade/check.c +++ b/src/bin/pg_upgrade/check.c @@ -1475,15 +1475,15 @@ check_for_incompatible_polymorphics(ClusterInfo *cluster) ", 'array_cat(anyarray,anyarray)'" ", 'array_prepend(anyelement,anyarray)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_remove(anyarray,anyelement)'" - ", 'array_replace(anyarray,anyelement,anyelement)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_remove(anyarray,anyelement)'" + ", 'array_replace(anyarray,anyelement,anyelement)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_position(anyarray,anyelement)'" - ", 'array_position(anyarray,anyelement,integer)'" - ", 'array_positions(anyarray,anyelement)'" - ", 'width_bucket(anyelement,anyarray)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_position(anyarray,anyelement)'" + ", 'array_position(anyarray,anyelement,integer)'" + ", 'array_positions(anyarray,anyelement)'" + ", 'width_bucket(anyelement,anyarray)'"); /* * The query below hardcodes FirstNormalObjectId as 16384 rather than diff --git a/src/bin/pg_upgrade/controldata.c b/src/bin/pg_upgrade/controldata.c index 8f81c9e9582..02ea02df60f 100644 --- a/src/bin/pg_upgrade/controldata.c +++ b/src/bin/pg_upgrade/controldata.c @@ -228,7 +228,7 @@ get_control_data(ClusterInfo *cluster) p++; /* remove ':' char */ cluster->controldata.chkpnt_nxtepoch = str2uint(p); - p = strchr(p, ':'); + p = strchr(p, ':'); if (p == NULL || strlen(p) <= 1) pg_fatal("%d: controldata retrieval problem", __LINE__); diff --git a/src/bin/pg_upgrade/exec.c b/src/bin/pg_upgrade/exec.c index 44355feea30..a1bdbf373e3 100644 --- a/src/bin/pg_upgrade/exec.c +++ b/src/bin/pg_upgrade/exec.c @@ -55,7 +55,7 @@ get_bin_version(ClusterInfo *cluster) if (sscanf(cmd_output, "%*s %*s %d.%d", &v1, &v2) < 1) pg_fatal("could not get pg_ctl version output from %s", cmd); - cluster->bin_version = v1 * 10000; + cluster->bin_version = v1 * 10000; } @@ -344,8 +344,8 @@ check_data_dir(ClusterInfo *cluster) check_single_dir(pg_data, "pg_subtrans"); check_single_dir(pg_data, PG_TBLSPC_DIR); check_single_dir(pg_data, "pg_twophase"); - check_single_dir(pg_data, "pg_wal"); - check_single_dir(pg_data, "pg_xact"); + check_single_dir(pg_data, "pg_wal"); + check_single_dir(pg_data, "pg_xact"); } @@ -385,7 +385,7 @@ check_bin_dir(ClusterInfo *cluster, bool check_versions) */ get_bin_version(cluster); - check_exec(cluster->bindir, "pg_resetwal", check_versions); + check_exec(cluster->bindir, "pg_resetwal", check_versions); if (cluster == &new_cluster) { diff --git a/src/bin/pg_upgrade/multixact_rewrite.c b/src/bin/pg_upgrade/multixact_rewrite.c index c45b3183684..c7a1416494d 100644 --- a/src/bin/pg_upgrade/multixact_rewrite.c +++ b/src/bin/pg_upgrade/multixact_rewrite.c @@ -61,52 +61,52 @@ rewrite_multixacts(MultiXactId from_multi, MultiXactId to_multi) * Convert old multixids, if needed, by reading them one-by-one from the * old cluster. */ - old_reader = AllocOldMultiXactRead(old_cluster.pgdata, - old_cluster.controldata.chkpnt_nxtmulti, - old_cluster.controldata.chkpnt_nxtmxoff); + old_reader = AllocOldMultiXactRead(old_cluster.pgdata, + old_cluster.controldata.chkpnt_nxtmulti, + old_cluster.controldata.chkpnt_nxtmxoff); - for (MultiXactId multi = from_multi; multi != to_multi;) - { - MultiXactMember member; - bool multixid_valid; - - /* - * Read this multixid's members. - * - * Locking-only XIDs that may be part of multi-xids don't matter - * after upgrade, as there can be no transactions running across - * upgrade. So as a small optimization, we only read one member - * from each multixid: the one updating one, or if there was no - * update, arbitrarily the first locking xid. - */ - multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); + for (MultiXactId multi = from_multi; multi != to_multi;) + { + MultiXactMember member; + bool multixid_valid; - /* - * Write the new offset to pg_multixact/offsets. - * - * Even if this multixid is invalid, we still need to write its - * offset if the *previous* multixid was valid. That's because - * when reading a multixid, the number of members is calculated - * from the difference between the two offsets. - */ - RecordMultiXactOffset(offsets_writer, multi, - (multixid_valid || prev_multixid_valid) ? next_offset : 0); + /* + * Read this multixid's members. + * + * Locking-only XIDs that may be part of multi-xids don't matter after + * upgrade, as there can be no transactions running across upgrade. So + * as a small optimization, we only read one member from each + * multixid: the one updating one, or if there was no update, + * arbitrarily the first locking xid. + */ + multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); - /* Write the members */ - if (multixid_valid) - { - RecordMultiXactMembers(members_writer, next_offset, 1, &member); - next_offset += 1; - } + /* + * Write the new offset to pg_multixact/offsets. + * + * Even if this multixid is invalid, we still need to write its offset + * if the *previous* multixid was valid. That's because when reading + * a multixid, the number of members is calculated from the difference + * between the two offsets. + */ + RecordMultiXactOffset(offsets_writer, multi, + (multixid_valid || prev_multixid_valid) ? next_offset : 0); - /* Advance to next multixid, handling wraparound */ - multi++; - if (multi < FirstMultiXactId) - multi = FirstMultiXactId; - prev_multixid_valid = multixid_valid; + /* Write the members */ + if (multixid_valid) + { + RecordMultiXactMembers(members_writer, next_offset, 1, &member); + next_offset += 1; } - FreeOldMultiXactReader(old_reader); + /* Advance to next multixid, handling wraparound */ + multi++; + if (multi < FirstMultiXactId) + multi = FirstMultiXactId; + prev_multixid_valid = multixid_valid; + } + + FreeOldMultiXactReader(old_reader); /* Write the final 'next' offset to the last SLRU page */ RecordMultiXactOffset(offsets_writer, to_multi, diff --git a/src/bin/pg_upgrade/pg_upgrade.c b/src/bin/pg_upgrade/pg_upgrade.c index c6af9035665..7366fd4627c 100644 --- a/src/bin/pg_upgrade/pg_upgrade.c +++ b/src/bin/pg_upgrade/pg_upgrade.c @@ -833,7 +833,7 @@ copy_xact_xlog_xid(void) * Determine the range of multixacts to convert. */ nxtmulti = old_cluster.controldata.chkpnt_nxtmulti; - oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; + oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; /* handle wraparound */ if (nxtmulti < FirstMultiXactId) nxtmulti = FirstMultiXactId; @@ -898,15 +898,15 @@ set_frozenxids(void) int i_datname; int i_datallowconn; - prep_status("Setting frozenxid and minmxid counters in new cluster"); + prep_status("Setting frozenxid and minmxid counters in new cluster"); conn_template1 = connectToServer(&new_cluster, "template1"); - /* set pg_database.datfrozenxid */ - PQclear(executeQueryOrDie(conn_template1, - "UPDATE pg_catalog.pg_database " - "SET datfrozenxid = '%u'", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_database.datfrozenxid */ + PQclear(executeQueryOrDie(conn_template1, + "UPDATE pg_catalog.pg_database " + "SET datfrozenxid = '%u'", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_database.datminmxid */ PQclear(executeQueryOrDie(conn_template1, @@ -942,16 +942,16 @@ set_frozenxids(void) conn = connectToServer(&new_cluster, datname); - /* set pg_class.relfrozenxid */ - PQclear(executeQueryOrDie(conn, - "UPDATE pg_catalog.pg_class " - "SET relfrozenxid = '%u' " - /* only heap, materialized view, and TOAST are vacuumed */ - "WHERE relkind IN (" - CppAsString2(RELKIND_RELATION) ", " - CppAsString2(RELKIND_MATVIEW) ", " - CppAsString2(RELKIND_TOASTVALUE) ")", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_class.relfrozenxid */ + PQclear(executeQueryOrDie(conn, + "UPDATE pg_catalog.pg_class " + "SET relfrozenxid = '%u' " + /* only heap, materialized view, and TOAST are vacuumed */ + "WHERE relkind IN (" + CppAsString2(RELKIND_RELATION) ", " + CppAsString2(RELKIND_MATVIEW) ", " + CppAsString2(RELKIND_TOASTVALUE) ")", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_class.relminmxid */ PQclear(executeQueryOrDie(conn, diff --git a/src/bin/pg_upgrade/relfilenumber.c b/src/bin/pg_upgrade/relfilenumber.c index ec2ff7acb21..6c467bdc8a5 100644 --- a/src/bin/pg_upgrade/relfilenumber.c +++ b/src/bin/pg_upgrade/relfilenumber.c @@ -587,32 +587,32 @@ transfer_relfile(FileNameMap *map, const char *type_suffix) /* Copying files might take some time, so give feedback. */ pg_log(PG_STATUS, "%s", old_file); - switch (user_opts.transfer_mode) - { - case TRANSFER_MODE_CLONE: - pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", - old_file, new_file); - cloneFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", - old_file, new_file); - copyFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY_FILE_RANGE: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", - old_file, new_file); - copyFileByRange(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_LINK: - pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", - old_file, new_file); - linkFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_SWAP: - /* swap mode is handled in its own code path */ - pg_fatal("should never happen"); - break; - } + switch (user_opts.transfer_mode) + { + case TRANSFER_MODE_CLONE: + pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", + old_file, new_file); + cloneFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", + old_file, new_file); + copyFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY_FILE_RANGE: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", + old_file, new_file); + copyFileByRange(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_LINK: + pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", + old_file, new_file); + linkFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_SWAP: + /* swap mode is handled in its own code path */ + pg_fatal("should never happen"); + break; + } } } diff --git a/src/bin/pg_upgrade/t/006_transfer_modes.pl b/src/bin/pg_upgrade/t/006_transfer_modes.pl index 9efa5dc863c..360d05c4b68 100644 --- a/src/bin/pg_upgrade/t/006_transfer_modes.pl +++ b/src/bin/pg_upgrade/t/006_transfer_modes.pl @@ -29,10 +29,8 @@ sub test_mode } $new->init(); - $new->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); - $old->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); + $new->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); + $old->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); # We can only test security labels if both the old and new installations # have dummy_seclabel. @@ -76,15 +74,14 @@ sub test_mode "CREATE TABLE test4 AS SELECT generate_series(400, 502)"); } - $old->safe_psql('postgres', - "CREATE TABLESPACE inplc_tblspc LOCATION ''"); - $old->safe_psql('postgres', - "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); - $old->safe_psql('postgres', - "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" - ); - $old->safe_psql('testdb3', - "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); + $old->safe_psql('postgres', "CREATE TABLESPACE inplc_tblspc LOCATION ''"); + $old->safe_psql('postgres', + "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); + $old->safe_psql('postgres', + "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" + ); + $old->safe_psql('testdb3', + "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); # While we are here, test handling of large objects. $old->safe_psql( @@ -152,12 +149,10 @@ sub test_mode } # Tests for in-place tablespaces. - $result = - $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); - is($result, '104', "test5 data after pg_upgrade $mode"); - $result = - $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); - is($result, '105', "test6 data after pg_upgrade $mode"); + $result = $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); + is($result, '104', "test5 data after pg_upgrade $mode"); + $result = $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); + is($result, '105', "test6 data after pg_upgrade $mode"); # Tests for large objects $result = $new->safe_psql('postgres', "SELECT lo_get(4532)"); diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index 44ef11d980e..c90bf8bbde2 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -6278,23 +6278,22 @@ get_create_object_cmd(EditableObjectType obj_type, Oid oid, * ensure the right view gets replaced. Also, check relation kind * to be sure it's a view. * - * Views may have WITH [LOCAL|CASCADED] - * CHECK OPTION. These are not part of the view definition - * returned by pg_get_viewdef() and so need to be retrieved - * separately. Materialized views may have - * arbitrary storage parameter reloptions. + * Views may have WITH [LOCAL|CASCADED] CHECK OPTION. These are + * not part of the view definition returned by pg_get_viewdef() + * and so need to be retrieved separately. Materialized views may + * have arbitrary storage parameter reloptions. */ printfPQExpBuffer(query, "/* %s */\n", _("Get view's definition and details")); - appendPQExpBuffer(query, - "SELECT nspname, relname, relkind, " - "pg_catalog.pg_get_viewdef(c.oid, true), " - "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " - "FROM pg_catalog.pg_class c " - "LEFT JOIN pg_catalog.pg_namespace n " - "ON c.relnamespace = n.oid WHERE c.oid = %u", - oid); + appendPQExpBuffer(query, + "SELECT nspname, relname, relkind, " + "pg_catalog.pg_get_viewdef(c.oid, true), " + "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " + "FROM pg_catalog.pg_class c " + "LEFT JOIN pg_catalog.pg_namespace n " + "ON c.relnamespace = n.oid WHERE c.oid = %u", + oid); break; } diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index ce99137c613..ac0c55e7aa5 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -387,19 +387,19 @@ describeFunctions(const char *functypes, const char *func_pattern, gettext_noop("stable"), gettext_noop("volatile"), gettext_noop("Volatility")); - appendPQExpBuffer(&buf, - ",\n CASE\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" - " END as \"%s\"", - gettext_noop("restricted"), - gettext_noop("safe"), - gettext_noop("unsafe"), - gettext_noop("Parallel")); + appendPQExpBuffer(&buf, + ",\n CASE\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" + " END as \"%s\"", + gettext_noop("restricted"), + gettext_noop("safe"), + gettext_noop("unsafe"), + gettext_noop("Parallel")); appendPQExpBuffer(&buf, ",\n pg_catalog.pg_get_userbyid(p.proowner) as \"%s\"" ",\n CASE WHEN prosecdef THEN '%s' ELSE '%s' END AS \"%s\"" @@ -599,8 +599,8 @@ describeFunctions(const char *functypes, const char *func_pattern, myopt.title = _("List of functions"); myopt.translate_header = true; - myopt.translate_columns = translate_columns; - myopt.n_translate_columns = lengthof(translate_columns); + myopt.translate_columns = translate_columns; + myopt.n_translate_columns = lengthof(translate_columns); printQuery(res, &myopt, pset.queryFout, false, pset.logfile); @@ -1086,38 +1086,38 @@ permissionsList(const char *pattern, bool showSystem) " ), E'\\n') AS \"%s\"", gettext_noop("Column privileges")); - appendPQExpBuffer(&buf, - ",\n pg_catalog.array_to_string(ARRAY(\n" - " SELECT polname\n" - " || CASE WHEN NOT polpermissive THEN\n" - " E' (RESTRICTIVE)'\n" - " ELSE '' END\n" - " || CASE WHEN polcmd != '*' THEN\n" - " E' (' || polcmd::pg_catalog.text || E'):'\n" - " ELSE E':'\n" - " END\n" - " || CASE WHEN polqual IS NOT NULL THEN\n" - " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" - " ELSE E''\n" - " END\n" - " || CASE WHEN polwithcheck IS NOT NULL THEN\n" - " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" - " ELSE E''\n" - " END" - " || CASE WHEN polroles <> '{0}' THEN\n" - " E'\\n to: ' || pg_catalog.array_to_string(\n" - " ARRAY(\n" - " SELECT rolname\n" - " FROM pg_catalog.pg_roles\n" - " WHERE oid = ANY (polroles)\n" - " ORDER BY 1\n" - " ), E', ')\n" - " ELSE E''\n" - " END\n" - " FROM pg_catalog.pg_policy pol\n" - " WHERE polrelid = c.oid), E'\\n')\n" - " AS \"%s\"", - gettext_noop("Policies")); + appendPQExpBuffer(&buf, + ",\n pg_catalog.array_to_string(ARRAY(\n" + " SELECT polname\n" + " || CASE WHEN NOT polpermissive THEN\n" + " E' (RESTRICTIVE)'\n" + " ELSE '' END\n" + " || CASE WHEN polcmd != '*' THEN\n" + " E' (' || polcmd::pg_catalog.text || E'):'\n" + " ELSE E':'\n" + " END\n" + " || CASE WHEN polqual IS NOT NULL THEN\n" + " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" + " ELSE E''\n" + " END\n" + " || CASE WHEN polwithcheck IS NOT NULL THEN\n" + " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" + " ELSE E''\n" + " END" + " || CASE WHEN polroles <> '{0}' THEN\n" + " E'\\n to: ' || pg_catalog.array_to_string(\n" + " ARRAY(\n" + " SELECT rolname\n" + " FROM pg_catalog.pg_roles\n" + " WHERE oid = ANY (polroles)\n" + " ORDER BY 1\n" + " ), E', ')\n" + " ELSE E''\n" + " END\n" + " FROM pg_catalog.pg_policy pol\n" + " WHERE polrelid = c.oid), E'\\n')\n" + " AS \"%s\"", + gettext_noop("Policies")); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_class c\n" " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n" @@ -1675,27 +1675,27 @@ describeOneTableDetails(const char *schemaname, char *footers[3] = {NULL, NULL, NULL}; printfPQExpBuffer(&buf, "/* %s */\n", _("Get sequence information")); - appendPQExpBuffer(&buf, - "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" - " seqstart AS \"%s\",\n" - " seqmin AS \"%s\",\n" - " seqmax AS \"%s\",\n" - " seqincrement AS \"%s\",\n" - " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" - " seqcache AS \"%s\"\n", - gettext_noop("Type"), - gettext_noop("Start"), - gettext_noop("Minimum"), - gettext_noop("Maximum"), - gettext_noop("Increment"), - gettext_noop("yes"), - gettext_noop("no"), - gettext_noop("Cycles?"), - gettext_noop("Cache")); - appendPQExpBuffer(&buf, - "FROM pg_catalog.pg_sequence\n" - "WHERE seqrelid = '%s';", - oid); + appendPQExpBuffer(&buf, + "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" + " seqstart AS \"%s\",\n" + " seqmin AS \"%s\",\n" + " seqmax AS \"%s\",\n" + " seqincrement AS \"%s\",\n" + " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" + " seqcache AS \"%s\"\n", + gettext_noop("Type"), + gettext_noop("Start"), + gettext_noop("Minimum"), + gettext_noop("Maximum"), + gettext_noop("Increment"), + gettext_noop("yes"), + gettext_noop("no"), + gettext_noop("Cycles?"), + gettext_noop("Cache")); + appendPQExpBuffer(&buf, + "FROM pg_catalog.pg_sequence\n" + "WHERE seqrelid = '%s';", + oid); res = PSQLexec(buf.data); if (!res) @@ -1913,7 +1913,7 @@ describeOneTableDetails(const char *schemaname, appendPQExpBufferStr(&buf, ",\n (SELECT c.collname FROM pg_catalog.pg_collation c, pg_catalog.pg_type t\n" " WHERE c.oid = a.attcollation AND t.oid = a.atttypid AND a.attcollation <> t.typcollation) AS attcollation"); attcoll_col = cols++; - appendPQExpBufferStr(&buf, ",\n a.attidentity"); + appendPQExpBufferStr(&buf, ",\n a.attidentity"); attidentity_col = cols++; if (pset.sversion >= 120000) appendPQExpBufferStr(&buf, ",\n a.attgenerated"); @@ -2326,7 +2326,7 @@ describeOneTableDetails(const char *schemaname, CppAsString2(CONSTRAINT_EXCLUSION) ") AND " "condeferred) AS condeferred,\n"); - appendPQExpBufferStr(&buf, "i.indisreplident,\n"); + appendPQExpBufferStr(&buf, "i.indisreplident,\n"); if (pset.sversion >= 150000) appendPQExpBufferStr(&buf, "i.indnullsnotdistinct,\n"); @@ -2431,7 +2431,7 @@ describeOneTableDetails(const char *schemaname, "pg_catalog.pg_get_indexdef(i.indexrelid, 0, true),\n " "pg_catalog.pg_get_constraintdef(con.oid, true), " "contype, condeferrable, condeferred"); - appendPQExpBufferStr(&buf, ", i.indisreplident"); + appendPQExpBufferStr(&buf, ", i.indisreplident"); appendPQExpBufferStr(&buf, ", c2.reltablespace"); if (pset.sversion >= 180000) appendPQExpBufferStr(&buf, ", con.conperiod"); @@ -2682,81 +2682,80 @@ describeOneTableDetails(const char *schemaname, PQclear(result); /* print any row-level policies */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get row-level policies for this table")); - appendPQExpBufferStr(&buf, "SELECT pol.polname,"); - appendPQExpBufferStr(&buf, - " pol.polpermissive,\n"); - appendPQExpBuffer(&buf, - " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" - " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" - " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" - " CASE pol.polcmd\n" - " WHEN 'r' THEN 'SELECT'\n" - " WHEN 'a' THEN 'INSERT'\n" - " WHEN 'w' THEN 'UPDATE'\n" - " WHEN 'd' THEN 'DELETE'\n" - " END AS cmd\n" - "FROM pg_catalog.pg_policy pol\n" - "WHERE pol.polrelid = '%s' ORDER BY 1;", - oid); + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get row-level policies for this table")); + appendPQExpBufferStr(&buf, "SELECT pol.polname,"); + appendPQExpBufferStr(&buf, + " pol.polpermissive,\n"); + appendPQExpBuffer(&buf, + " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" + " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" + " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" + " CASE pol.polcmd\n" + " WHEN 'r' THEN 'SELECT'\n" + " WHEN 'a' THEN 'INSERT'\n" + " WHEN 'w' THEN 'UPDATE'\n" + " WHEN 'd' THEN 'DELETE'\n" + " END AS cmd\n" + "FROM pg_catalog.pg_policy pol\n" + "WHERE pol.polrelid = '%s' ORDER BY 1;", + oid); - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - /* - * Handle cases where RLS is enabled and there are policies, or - * there aren't policies, or RLS isn't enabled but there are - * policies - */ - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies:")); + /* + * Handle cases where RLS is enabled and there are policies, or there + * aren't policies, or RLS isn't enabled but there are policies + */ + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies:")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled):")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled):")); - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); - if (!tableinfo.rowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (row security disabled):")); + if (!tableinfo.rowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (row security disabled):")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " POLICY \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " POLICY \"%s\"", + PQgetvalue(result, i, 0)); - if (*(PQgetvalue(result, i, 1)) == 'f') - appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); + if (*(PQgetvalue(result, i, 1)) == 'f') + appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); - if (!PQgetisnull(result, i, 5)) - appendPQExpBuffer(&buf, " FOR %s", - PQgetvalue(result, i, 5)); + if (!PQgetisnull(result, i, 5)) + appendPQExpBuffer(&buf, " FOR %s", + PQgetvalue(result, i, 5)); - if (!PQgetisnull(result, i, 2)) - { - appendPQExpBuffer(&buf, "\n TO %s", - PQgetvalue(result, i, 2)); - } + if (!PQgetisnull(result, i, 2)) + { + appendPQExpBuffer(&buf, "\n TO %s", + PQgetvalue(result, i, 2)); + } - if (!PQgetisnull(result, i, 3)) - appendPQExpBuffer(&buf, "\n USING (%s)", - PQgetvalue(result, i, 3)); + if (!PQgetisnull(result, i, 3)) + appendPQExpBuffer(&buf, "\n USING (%s)", + PQgetvalue(result, i, 3)); - if (!PQgetisnull(result, i, 4)) - appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", - PQgetvalue(result, i, 4)); + if (!PQgetisnull(result, i, 4)) + appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", + PQgetvalue(result, i, 4)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* print any extended statistics */ if (pset.sversion >= 140000) @@ -3025,115 +3024,115 @@ describeOneTableDetails(const char *schemaname, } /* print any publications */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get publications that publish this table")); - if (pset.sversion >= 150000) + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get publications that publish this table")); + if (pset.sversion >= 150000) + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" + " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" + "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" + "UNION\n" + "SELECT pubname\n" + " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" + " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" + " (SELECT pg_catalog.string_agg(attname, ', ')\n" + " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" + " pg_catalog.pg_attribute\n" + " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" + " ELSE NULL END) " + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" + "WHERE pr.prrelid = '%s'\n", + oid, oid, oid); + + if (pset.sversion >= 190000) { + /* + * Skip entries where this relation appears in the + * publication's EXCEPT list. + */ appendPQExpBuffer(&buf, + " AND NOT pr.prexcept\n" + "UNION\n" "SELECT pubname\n" " , NULL\n" " , NULL\n" "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" - " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" - "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" - "UNION\n" - "SELECT pubname\n" - " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" - " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" - " (SELECT pg_catalog.string_agg(attname, ', ')\n" - " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" - " pg_catalog.pg_attribute\n" - " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" - " ELSE NULL END) " - "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" - "WHERE pr.prrelid = '%s'\n", + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + " AND NOT EXISTS (\n" + " SELECT 1\n" + " FROM pg_catalog.pg_publication_rel pr\n" + " WHERE pr.prpubid = p.oid AND\n" + " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" + "ORDER BY 1;", oid, oid, oid); - - if (pset.sversion >= 190000) - { - /* - * Skip entries where this relation appears in the - * publication's EXCEPT list. - */ - appendPQExpBuffer(&buf, - " AND NOT pr.prexcept\n" - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - " AND NOT EXISTS (\n" - " SELECT 1\n" - " FROM pg_catalog.pg_publication_rel pr\n" - " WHERE pr.prpubid = p.oid AND\n" - " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" - "ORDER BY 1;", - oid, oid, oid); - } - else - { - appendPQExpBuffer(&buf, - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - "ORDER BY 1;", - oid); - } } else { appendPQExpBuffer(&buf, + "UNION\n" "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - "WHERE pr.prrelid = '%s'\n" - "UNION ALL\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" + " , NULL\n" + " , NULL\n" "FROM pg_catalog.pg_publication p\n" "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" "ORDER BY 1;", - oid, oid); + oid); } + } + else + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + "WHERE pr.prrelid = '%s'\n" + "UNION ALL\n" + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + "ORDER BY 1;", + oid, oid); + } - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - if (tuples > 0) - printTableAddFooter(&cont, _("Included in publications:")); + if (tuples > 0) + printTableAddFooter(&cont, _("Included in publications:")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " \"%s\"", + PQgetvalue(result, i, 0)); - /* column list (if any) */ - if (!PQgetisnull(result, i, 2)) - appendPQExpBuffer(&buf, " (%s)", - PQgetvalue(result, i, 2)); + /* column list (if any) */ + if (!PQgetisnull(result, i, 2)) + appendPQExpBuffer(&buf, " (%s)", + PQgetvalue(result, i, 2)); - /* row filter (if any) */ - if (!PQgetisnull(result, i, 1)) - appendPQExpBuffer(&buf, " WHERE %s", - PQgetvalue(result, i, 1)); + /* row filter (if any) */ + if (!PQgetisnull(result, i, 1)) + appendPQExpBuffer(&buf, " WHERE %s", + PQgetvalue(result, i, 1)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* Print publications where the table is in the EXCEPT clause */ if (pset.sversion >= 190000) @@ -3805,7 +3804,7 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) ncols++; } appendPQExpBufferStr(&buf, "\n, r.rolreplication"); - appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); + appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_roles r\n"); @@ -3860,8 +3859,8 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) if (strcmp(PQgetvalue(res, i, (verbose ? 9 : 8)), "t") == 0) add_role_attribute(&buf, _("Replication")); - if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) - add_role_attribute(&buf, _("Bypass RLS")); + if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) + add_role_attribute(&buf, _("Bypass RLS")); conns = atoi(PQgetvalue(res, i, 6)); if (conns >= 0) @@ -5155,14 +5154,14 @@ listCollations(const char *pattern, bool verbose, bool showSystem) gettext_noop("Schema"), gettext_noop("Name")); - appendPQExpBuffer(&buf, - " CASE c.collprovider " - "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " - "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " - "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " - "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " - "END AS \"%s\",\n", - gettext_noop("Provider")); + appendPQExpBuffer(&buf, + " CASE c.collprovider " + "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " + "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " + "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " + "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " + "END AS \"%s\",\n", + gettext_noop("Provider")); appendPQExpBuffer(&buf, " c.collcollate AS \"%s\",\n" -- 2.50.1 (Apple Git-155) --aHl3HfeiUuO3zeNC-- ^ permalink raw reply [nested|flat] 59+ messages in thread
* [PATCH v6 4/4] run pgindent and pgperltidy @ 2026-06-30 18:24 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 59+ messages in thread From: Nathan Bossart @ 2026-06-30 18:24 UTC (permalink / raw) --- src/bin/pg_dump/pg_dump.c | 464 ++++++++++----------- src/bin/pg_dump/pg_dumpall.c | 30 +- src/bin/pg_upgrade/check.c | 16 +- src/bin/pg_upgrade/controldata.c | 2 +- src/bin/pg_upgrade/exec.c | 8 +- src/bin/pg_upgrade/multixact_rewrite.c | 80 ++-- src/bin/pg_upgrade/pg_upgrade.c | 34 +- src/bin/pg_upgrade/relfilenumber.c | 54 +-- src/bin/pg_upgrade/t/006_transfer_modes.pl | 33 +- src/bin/psql/command.c | 29 +- src/bin/psql/describe.c | 461 ++++++++++---------- 11 files changed, 601 insertions(+), 610 deletions(-) diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 65bd15ebfd2..5673268b467 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -1491,8 +1491,8 @@ setup_connection(Archive *AH, const char *dumpencoding, * Disable timeouts if supported. */ ExecuteSqlStatement(AH, "SET statement_timeout = 0"); - ExecuteSqlStatement(AH, "SET lock_timeout = 0"); - ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); + ExecuteSqlStatement(AH, "SET lock_timeout = 0"); + ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); if (AH->remoteVersion >= 170000) ExecuteSqlStatement(AH, "SET transaction_timeout = 0"); @@ -1505,10 +1505,10 @@ setup_connection(Archive *AH, const char *dumpencoding, /* * Adjust row-security mode, if supported. */ - if (dopt->enable_row_security) - ExecuteSqlStatement(AH, "SET row_security = on"); - else - ExecuteSqlStatement(AH, "SET row_security = off"); + if (dopt->enable_row_security) + ExecuteSqlStatement(AH, "SET row_security = on"); + else + ExecuteSqlStatement(AH, "SET row_security = off"); /* * For security reasons, we restrict the expansion of non-system views and @@ -1933,10 +1933,9 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) addObjectDependency(dobj, ext->dobj.dumpId); /* - * Mark the member object to have any non-initial ACLs - * dumped. (Any initial ACLs will be removed later, using data from - * pg_init_privs, so that we'll dump only the delta from the extension's - * initial setup.) + * Mark the member object to have any non-initial ACLs dumped. (Any + * initial ACLs will be removed later, using data from pg_init_privs, so + * that we'll dump only the delta from the extension's initial setup.) * * In binary upgrades, we still dump all components of the members * individually, since the idea is to exactly reproduce the database @@ -1953,7 +1952,7 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) if (fout->dopt->binary_upgrade) dobj->dump = ext->dobj.dump; else - dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); + dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); return true; } @@ -1987,9 +1986,9 @@ selectDumpableNamespace(NamespaceInfo *nsinfo, Archive *fout) else if (strcmp(nsinfo->dobj.name, "pg_catalog") == 0) { /* - * We dump out any ACLs defined in pg_catalog, if - * they are interesting (and not the original ACLs which were set at - * initdb time, see pg_init_privs). + * We dump out any ACLs defined in pg_catalog, if they are interesting + * (and not the original ACLs which were set at initdb time, see + * pg_init_privs). */ nsinfo->dobj.dump_contains = nsinfo->dobj.dump = DUMP_COMPONENT_ACL; } @@ -3296,7 +3295,7 @@ dumpDatabase(Archive *fout) "datcollate, datctype, datfrozenxid, " "datacl, acldefault('d', datdba) AS acldefault, " "datistemplate, datconnlimit, "); - appendPQExpBufferStr(dbQry, "datminmxid, "); + appendPQExpBufferStr(dbQry, "datminmxid, "); if (fout->remoteVersion >= 170000) appendPQExpBufferStr(dbQry, "datlocprovider, datlocale, datcollversion, "); else if (fout->remoteVersion >= 150000) @@ -3638,11 +3637,11 @@ dumpDatabase(Archive *fout) ii_oid, ii_relminmxid; - appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" - "FROM pg_catalog.pg_class\n" - "WHERE oid IN (%u, %u, %u, %u);\n", - LargeObjectRelationId, LargeObjectLOidPNIndexId, - LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); + appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" + "FROM pg_catalog.pg_class\n" + "WHERE oid IN (%u, %u, %u, %u);\n", + LargeObjectRelationId, LargeObjectLOidPNIndexId, + LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); lo_res = ExecuteSqlQuery(fout, loFrozenQry->data, PGRES_TUPLES_OK); @@ -4274,7 +4273,7 @@ getPolicies(Archive *fout, TableInfo tblinfo[], int numTables) printfPQExpBuffer(query, "SELECT pol.oid, pol.tableoid, pol.polrelid, pol.polname, pol.polcmd, "); - appendPQExpBufferStr(query, "pol.polpermissive, "); + appendPQExpBufferStr(query, "pol.polpermissive, "); appendPQExpBuffer(query, "CASE WHEN pol.polroles = '{0}' THEN NULL ELSE " " pg_catalog.array_to_string(ARRAY(SELECT pg_catalog.quote_ident(rolname) from pg_catalog.pg_roles WHERE oid = ANY(pol.polroles)), ', ') END AS polroles, " @@ -6633,9 +6632,9 @@ getAccessMethods(Archive *fout) * Select all access methods from pg_am table. */ appendPQExpBufferStr(query, "SELECT tableoid, oid, amname, "); - appendPQExpBufferStr(query, - "amtype, " - "amhandler::pg_catalog.regproc AS amhandler "); + appendPQExpBufferStr(query, + "amtype, " + "amhandler::pg_catalog.regproc AS amhandler "); appendPQExpBufferStr(query, "FROM pg_am"); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6827,35 +6826,35 @@ getAggregates(Archive *fout) * Find all interesting aggregates. See comment in getFuncs() for the * rationale behind the filtering logic. */ - agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" - : "p.proisagg"); + agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" + : "p.proisagg"); - appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " - "p.proname AS aggname, " - "p.pronamespace AS aggnamespace, " - "p.pronargs, p.proargtypes, " - "p.proowner, " - "p.proacl AS aggacl, " - "acldefault('f', p.proowner) AS acldefault " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s AND (" - "p.pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog') OR " - "p.proacl IS DISTINCT FROM pip.initprivs", - agg_check); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - " OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); - appendPQExpBufferChar(query, ')'); + appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " + "p.proname AS aggname, " + "p.pronamespace AS aggnamespace, " + "p.pronargs, p.proargtypes, " + "p.proowner, " + "p.proacl AS aggacl, " + "acldefault('f', p.proowner) AS acldefault " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s AND (" + "p.pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog') OR " + "p.proacl IS DISTINCT FROM pip.initprivs", + agg_check); + if (dopt->binary_upgrade) + appendPQExpBufferStr(query, + " OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6957,53 +6956,53 @@ getFuncs(Archive *fout) * include them, since we want to dump extension members individually in * that mode. Also, if they are used by casts or transforms then we need * to gather the information about them, though they won't be dumped if - * they are built-in. Also, include functions in - * pg_catalog if they have an ACL different from what's shown in - * pg_init_privs (so we have to join to pg_init_privs; annoying). + * they are built-in. Also, include functions in pg_catalog if they have + * an ACL different from what's shown in pg_init_privs (so we have to join + * to pg_init_privs; annoying). */ - not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" - : "NOT p.proisagg"); + not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" + : "NOT p.proisagg"); - appendPQExpBuffer(query, - "SELECT p.tableoid, p.oid, p.proname, p.prolang, " - "p.pronargs, p.proargtypes, p.prorettype, " - "p.proacl, " - "acldefault('f', p.proowner) AS acldefault, " - "p.pronamespace, " - "p.proowner " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s" - "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " - "WHERE classid = 'pg_proc'::regclass AND " - "objid = p.oid AND deptype = 'i')" - "\n AND (" - "\n pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog')" - "\n OR EXISTS (SELECT 1 FROM pg_cast" - "\n WHERE pg_cast.oid > %u " - "\n AND p.oid = pg_cast.castfunc)" - "\n OR EXISTS (SELECT 1 FROM pg_transform" - "\n WHERE pg_transform.oid > %u AND " - "\n (p.oid = pg_transform.trffromsql" - "\n OR p.oid = pg_transform.trftosql))", - not_agg_check, - g_last_builtin_oid, - g_last_builtin_oid); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); + appendPQExpBuffer(query, + "SELECT p.tableoid, p.oid, p.proname, p.prolang, " + "p.pronargs, p.proargtypes, p.prorettype, " + "p.proacl, " + "acldefault('f', p.proowner) AS acldefault, " + "p.pronamespace, " + "p.proowner " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s" + "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " + "WHERE classid = 'pg_proc'::regclass AND " + "objid = p.oid AND deptype = 'i')" + "\n AND (" + "\n pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog')" + "\n OR EXISTS (SELECT 1 FROM pg_cast" + "\n WHERE pg_cast.oid > %u " + "\n AND p.oid = pg_cast.castfunc)" + "\n OR EXISTS (SELECT 1 FROM pg_transform" + "\n WHERE pg_transform.oid > %u AND " + "\n (p.oid = pg_transform.trffromsql" + "\n OR p.oid = pg_transform.trftosql))", + not_agg_check, + g_last_builtin_oid, + g_last_builtin_oid); + if (dopt->binary_upgrade) appendPQExpBufferStr(query, - "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); - appendPQExpBufferChar(query, ')'); + "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferStr(query, + "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -7252,31 +7251,31 @@ getTables(Archive *fout, int *numTables) appendPQExpBufferStr(query, "c.relhasoids, "); - appendPQExpBufferStr(query, - "c.relispopulated, "); + appendPQExpBufferStr(query, + "c.relispopulated, "); - appendPQExpBufferStr(query, - "c.relreplident, "); + appendPQExpBufferStr(query, + "c.relreplident, "); - appendPQExpBufferStr(query, - "c.relrowsecurity, c.relforcerowsecurity, "); + appendPQExpBufferStr(query, + "c.relrowsecurity, c.relforcerowsecurity, "); - appendPQExpBufferStr(query, - "c.relminmxid, tc.relminmxid AS tminmxid, "); + appendPQExpBufferStr(query, + "c.relminmxid, tc.relminmxid AS tminmxid, "); - appendPQExpBufferStr(query, - "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); + appendPQExpBufferStr(query, + "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); - appendPQExpBufferStr(query, - "am.amname, "); + appendPQExpBufferStr(query, + "am.amname, "); - appendPQExpBufferStr(query, - "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); + appendPQExpBufferStr(query, + "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); - appendPQExpBufferStr(query, - "c.relispartition AS ispartition "); + appendPQExpBufferStr(query, + "c.relispartition AS ispartition "); /* * Left join to pg_depend to pick up dependency info linking sequences to @@ -7296,8 +7295,8 @@ getTables(Archive *fout, int *numTables) /* * Left join to pg_am to pick up the amname. */ - appendPQExpBufferStr(query, - "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); + appendPQExpBufferStr(query, + "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); /* * We purposefully ignore toast OIDs for partitioned tables; the reason is @@ -7868,8 +7867,8 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables) "t.reloptions AS indreloptions, "); - appendPQExpBufferStr(query, - "i.indisreplident, "); + appendPQExpBufferStr(query, + "i.indisreplident, "); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -9313,8 +9312,8 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables) appendPQExpBufferStr(q, "'' AS attcompression,\n"); - appendPQExpBufferStr(q, - "a.attidentity,\n"); + appendPQExpBufferStr(q, + "a.attidentity,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(q, @@ -10717,73 +10716,73 @@ getAdditionalACLs(Archive *fout) PQclear(res); /* Fetch initial-privileges data */ - printfPQExpBuffer(query, - "SELECT objoid, classoid, objsubid, privtype, initprivs " - "FROM pg_init_privs"); + printfPQExpBuffer(query, + "SELECT objoid, classoid, objsubid, privtype, initprivs " + "FROM pg_init_privs"); - res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); + res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); - ntups = PQntuples(res); - for (i = 0; i < ntups; i++) - { - Oid objoid = atooid(PQgetvalue(res, i, 0)); - Oid classoid = atooid(PQgetvalue(res, i, 1)); - int objsubid = atoi(PQgetvalue(res, i, 2)); - char privtype = *(PQgetvalue(res, i, 3)); - char *initprivs = PQgetvalue(res, i, 4); - CatalogId objId; - DumpableObject *dobj; + ntups = PQntuples(res); + for (i = 0; i < ntups; i++) + { + Oid objoid = atooid(PQgetvalue(res, i, 0)); + Oid classoid = atooid(PQgetvalue(res, i, 1)); + int objsubid = atoi(PQgetvalue(res, i, 2)); + char privtype = *(PQgetvalue(res, i, 3)); + char *initprivs = PQgetvalue(res, i, 4); + CatalogId objId; + DumpableObject *dobj; - objId.tableoid = classoid; - objId.oid = objoid; - dobj = findObjectByCatalogId(objId); - /* OK to ignore entries we haven't got a DumpableObject for */ - if (dobj) + objId.tableoid = classoid; + objId.oid = objoid; + dobj = findObjectByCatalogId(objId); + /* OK to ignore entries we haven't got a DumpableObject for */ + if (dobj) + { + /* Cope with sub-object initprivs */ + if (objsubid != 0) { - /* Cope with sub-object initprivs */ - if (objsubid != 0) - { - if (dobj->objType == DO_TABLE) - { - /* For a column initprivs, set the table's ACL flags */ - dobj->components |= DUMP_COMPONENT_ACL; - ((TableInfo *) dobj)->hascolumnACLs = true; - } - else - pg_log_warning("unsupported pg_init_privs entry: %u %u %d", - classoid, objoid, objsubid); - continue; - } - - /* - * We ignore any pg_init_privs.initprivs entry for the public - * schema, as explained in getNamespaces(). - */ - if (dobj->objType == DO_NAMESPACE && - strcmp(dobj->name, "public") == 0) - continue; - - /* Else it had better be of a type we think has ACLs */ - if (dobj->objType == DO_NAMESPACE || - dobj->objType == DO_TYPE || - dobj->objType == DO_FUNC || - dobj->objType == DO_AGG || - dobj->objType == DO_TABLE || - dobj->objType == DO_PROCLANG || - dobj->objType == DO_FDW || - dobj->objType == DO_FOREIGN_SERVER) + if (dobj->objType == DO_TABLE) { - DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; - - daobj->dacl.privtype = privtype; - daobj->dacl.initprivs = pstrdup(initprivs); + /* For a column initprivs, set the table's ACL flags */ + dobj->components |= DUMP_COMPONENT_ACL; + ((TableInfo *) dobj)->hascolumnACLs = true; } else pg_log_warning("unsupported pg_init_privs entry: %u %u %d", classoid, objoid, objsubid); + continue; + } + + /* + * We ignore any pg_init_privs.initprivs entry for the public + * schema, as explained in getNamespaces(). + */ + if (dobj->objType == DO_NAMESPACE && + strcmp(dobj->name, "public") == 0) + continue; + + /* Else it had better be of a type we think has ACLs */ + if (dobj->objType == DO_NAMESPACE || + dobj->objType == DO_TYPE || + dobj->objType == DO_FUNC || + dobj->objType == DO_AGG || + dobj->objType == DO_TABLE || + dobj->objType == DO_PROCLANG || + dobj->objType == DO_FDW || + dobj->objType == DO_FOREIGN_SERVER) + { + DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; + + daobj->dacl.privtype = privtype; + daobj->dacl.initprivs = pstrdup(initprivs); } + else + pg_log_warning("unsupported pg_init_privs entry: %u %u %d", + classoid, objoid, objsubid); } - PQclear(res); + } + PQclear(res); destroyPQExpBuffer(query); } @@ -11128,8 +11127,8 @@ dumpRelationStats_dumper(Archive *fout, const void *userArg, const TocEntry *te) * The results must be in the order of the relations supplied in the * parameters to ensure we remain in sync as we walk through the TOC. * - * For versions before 19, the redundant filter clause on s.tablename = - * ANY(...) seems sufficient to convince the planner to use + * For versions before 19, the redundant filter clause on s.tablename + * = ANY(...) seems sufficient to convince the planner to use * pg_class_relname_nsp_index, which avoids a full scan of pg_stats. * In newer versions, pg_stats returns the table OIDs, eliminating the * need for that hack. @@ -13469,11 +13468,11 @@ dumpFunc(Archive *fout, const FuncInfo *finfo) "pg_catalog.pg_get_function_result(p.oid) AS funcresult,\n" "proleakproof,\n"); - appendPQExpBufferStr(query, - "array_to_string(protrftypes, ' ') AS protrftypes,\n"); + appendPQExpBufferStr(query, + "array_to_string(protrftypes, ' ') AS protrftypes,\n"); - appendPQExpBufferStr(query, - "proparallel,\n"); + appendPQExpBufferStr(query, + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -14963,9 +14962,9 @@ dumpCollation(Archive *fout, const CollInfo *collinfo) /* Get collation-specific details */ appendPQExpBufferStr(query, "SELECT "); - appendPQExpBufferStr(query, - "collprovider, " - "collversion, "); + appendPQExpBufferStr(query, + "collprovider, " + "collversion, "); if (fout->remoteVersion >= 120000) appendPQExpBufferStr(query, @@ -15372,23 +15371,23 @@ dumpAgg(Archive *fout, const AggInfo *agginfo) "pg_catalog.pg_get_function_arguments(p.oid) AS funcargs,\n" "pg_catalog.pg_get_function_identity_arguments(p.oid) AS funciargs,\n"); - appendPQExpBufferStr(query, - "aggkind,\n" - "aggmtransfn,\n" - "aggminvtransfn,\n" - "aggmfinalfn,\n" - "aggmtranstype::pg_catalog.regtype,\n" - "aggfinalextra,\n" - "aggmfinalextra,\n" - "aggtransspace,\n" - "aggmtransspace,\n" - "aggminitval,\n"); + appendPQExpBufferStr(query, + "aggkind,\n" + "aggmtransfn,\n" + "aggminvtransfn,\n" + "aggmfinalfn,\n" + "aggmtranstype::pg_catalog.regtype,\n" + "aggfinalextra,\n" + "aggmfinalextra,\n" + "aggtransspace,\n" + "aggmtransspace,\n" + "aggminitval,\n"); - appendPQExpBufferStr(query, - "aggcombinefn,\n" - "aggserialfn,\n" - "aggdeserialfn,\n" - "proparallel,\n"); + appendPQExpBufferStr(query, + "aggcombinefn,\n" + "aggserialfn,\n" + "aggdeserialfn,\n" + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -16848,30 +16847,30 @@ dumpTable(Archive *fout, const TableInfo *tbinfo) appendPQExpBufferStr(query, "PREPARE getColumnACLs(pg_catalog.oid) AS\n"); - /* - * In principle we should call acldefault('c', relowner) to - * get the default ACL for a column. However, we don't - * currently store the numeric OID of the relowner in - * TableInfo. We could convert the owner name using regrole, - * but that creates a risk of failure due to concurrent role - * renames. Given that the default ACL for columns is empty - * and is likely to stay that way, it's not worth extra cycles - * and risk to avoid hard-wiring that knowledge here. - */ - appendPQExpBufferStr(query, - "SELECT at.attname, " - "at.attacl, " - "'{}' AS acldefault, " - "pip.privtype, pip.initprivs " - "FROM pg_catalog.pg_attribute at " - "LEFT JOIN pg_catalog.pg_init_privs pip ON " - "(at.attrelid = pip.objoid " - "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " - "AND at.attnum = pip.objsubid) " - "WHERE at.attrelid = $1 AND " - "NOT at.attisdropped " - "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " - "ORDER BY at.attnum"); + /* + * In principle we should call acldefault('c', relowner) to get + * the default ACL for a column. However, we don't currently + * store the numeric OID of the relowner in TableInfo. We could + * convert the owner name using regrole, but that creates a risk + * of failure due to concurrent role renames. Given that the + * default ACL for columns is empty and is likely to stay that + * way, it's not worth extra cycles and risk to avoid hard-wiring + * that knowledge here. + */ + appendPQExpBufferStr(query, + "SELECT at.attname, " + "at.attacl, " + "'{}' AS acldefault, " + "pip.privtype, pip.initprivs " + "FROM pg_catalog.pg_attribute at " + "LEFT JOIN pg_catalog.pg_init_privs pip ON " + "(at.attrelid = pip.objoid " + "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " + "AND at.attnum = pip.objsubid) " + "WHERE at.attrelid = $1 AND " + "NOT at.attisdropped " + "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " + "ORDER BY at.attnum"); ExecuteSqlStatement(fout, query->data); @@ -19165,7 +19164,7 @@ collectSequences(Archive *fout) * pg_get_sequence_data(), but we only do so for non-schema-only dumps. */ if (fout->remoteVersion < 180000 || - (!fout->dopt->dumpData && !fout->dopt->sequence_data)) + (!fout->dopt->dumpData && !fout->dopt->sequence_data)) query = "SELECT seqrelid, format_type(seqtypid, NULL), " "seqstart, seqincrement, " "seqmax, seqmin, " @@ -19227,15 +19226,14 @@ dumpSequence(Archive *fout, const TableInfo *tbinfo) qseqname = pg_strdup(fmtId(tbinfo->dobj.name)); /* - * The sequence information is gathered in a sorted - * table before any calls to dumpSequence(). See collectSequences() for - * more information. + * The sequence information is gathered in a sorted table before any calls + * to dumpSequence(). See collectSequences() for more information. */ - Assert(sequences); + Assert(sequences); - key.oid = tbinfo->dobj.catId.oid; - seq = bsearch(&key, sequences, nsequences, - sizeof(SequenceItem), SequenceItemCmp); + key.oid = tbinfo->dobj.catId.oid; + seq = bsearch(&key, sequences, nsequences, + sizeof(SequenceItem), SequenceItemCmp); /* Calculate default limits for a sequence of this type */ is_ascending = (seq->incby >= 0); diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c index e68937c9934..afcd9a218d8 100644 --- a/src/bin/pg_dump/pg_dumpall.c +++ b/src/bin/pg_dump/pg_dumpall.c @@ -785,11 +785,11 @@ dropRoles(PGconn *conn) int i_rolname; int i; - printfPQExpBuffer(buf, - "SELECT rolname " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 1", role_catalog); + printfPQExpBuffer(buf, + "SELECT rolname " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 1", role_catalog); res = executeQuery(conn, buf->data); @@ -843,16 +843,16 @@ dumpRoles(PGconn *conn) * Notes: rolconfig is dumped later, and pg_authid must be used for * extracting rolcomment regardless of role_catalog. */ - printfPQExpBuffer(buf, - "SELECT oid, rolname, rolsuper, rolinherit, " - "rolcreaterole, rolcreatedb, " - "rolcanlogin, rolconnlimit, rolpassword, " - "rolvaliduntil, rolreplication, rolbypassrls, " - "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " - "rolname = current_user AS is_current_user " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 2", role_catalog); + printfPQExpBuffer(buf, + "SELECT oid, rolname, rolsuper, rolinherit, " + "rolcreaterole, rolcreatedb, " + "rolcanlogin, rolconnlimit, rolpassword, " + "rolvaliduntil, rolreplication, rolbypassrls, " + "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " + "rolname = current_user AS is_current_user " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 2", role_catalog); res = executeQuery(conn, buf->data); diff --git a/src/bin/pg_upgrade/check.c b/src/bin/pg_upgrade/check.c index 786c1474829..f725f5ee3e2 100644 --- a/src/bin/pg_upgrade/check.c +++ b/src/bin/pg_upgrade/check.c @@ -1475,15 +1475,15 @@ check_for_incompatible_polymorphics(ClusterInfo *cluster) ", 'array_cat(anyarray,anyarray)'" ", 'array_prepend(anyelement,anyarray)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_remove(anyarray,anyelement)'" - ", 'array_replace(anyarray,anyelement,anyelement)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_remove(anyarray,anyelement)'" + ", 'array_replace(anyarray,anyelement,anyelement)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_position(anyarray,anyelement)'" - ", 'array_position(anyarray,anyelement,integer)'" - ", 'array_positions(anyarray,anyelement)'" - ", 'width_bucket(anyelement,anyarray)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_position(anyarray,anyelement)'" + ", 'array_position(anyarray,anyelement,integer)'" + ", 'array_positions(anyarray,anyelement)'" + ", 'width_bucket(anyelement,anyarray)'"); /* * The query below hardcodes FirstNormalObjectId as 16384 rather than diff --git a/src/bin/pg_upgrade/controldata.c b/src/bin/pg_upgrade/controldata.c index 8f81c9e9582..02ea02df60f 100644 --- a/src/bin/pg_upgrade/controldata.c +++ b/src/bin/pg_upgrade/controldata.c @@ -228,7 +228,7 @@ get_control_data(ClusterInfo *cluster) p++; /* remove ':' char */ cluster->controldata.chkpnt_nxtepoch = str2uint(p); - p = strchr(p, ':'); + p = strchr(p, ':'); if (p == NULL || strlen(p) <= 1) pg_fatal("%d: controldata retrieval problem", __LINE__); diff --git a/src/bin/pg_upgrade/exec.c b/src/bin/pg_upgrade/exec.c index 44355feea30..a1bdbf373e3 100644 --- a/src/bin/pg_upgrade/exec.c +++ b/src/bin/pg_upgrade/exec.c @@ -55,7 +55,7 @@ get_bin_version(ClusterInfo *cluster) if (sscanf(cmd_output, "%*s %*s %d.%d", &v1, &v2) < 1) pg_fatal("could not get pg_ctl version output from %s", cmd); - cluster->bin_version = v1 * 10000; + cluster->bin_version = v1 * 10000; } @@ -344,8 +344,8 @@ check_data_dir(ClusterInfo *cluster) check_single_dir(pg_data, "pg_subtrans"); check_single_dir(pg_data, PG_TBLSPC_DIR); check_single_dir(pg_data, "pg_twophase"); - check_single_dir(pg_data, "pg_wal"); - check_single_dir(pg_data, "pg_xact"); + check_single_dir(pg_data, "pg_wal"); + check_single_dir(pg_data, "pg_xact"); } @@ -385,7 +385,7 @@ check_bin_dir(ClusterInfo *cluster, bool check_versions) */ get_bin_version(cluster); - check_exec(cluster->bindir, "pg_resetwal", check_versions); + check_exec(cluster->bindir, "pg_resetwal", check_versions); if (cluster == &new_cluster) { diff --git a/src/bin/pg_upgrade/multixact_rewrite.c b/src/bin/pg_upgrade/multixact_rewrite.c index c45b3183684..c7a1416494d 100644 --- a/src/bin/pg_upgrade/multixact_rewrite.c +++ b/src/bin/pg_upgrade/multixact_rewrite.c @@ -61,52 +61,52 @@ rewrite_multixacts(MultiXactId from_multi, MultiXactId to_multi) * Convert old multixids, if needed, by reading them one-by-one from the * old cluster. */ - old_reader = AllocOldMultiXactRead(old_cluster.pgdata, - old_cluster.controldata.chkpnt_nxtmulti, - old_cluster.controldata.chkpnt_nxtmxoff); + old_reader = AllocOldMultiXactRead(old_cluster.pgdata, + old_cluster.controldata.chkpnt_nxtmulti, + old_cluster.controldata.chkpnt_nxtmxoff); - for (MultiXactId multi = from_multi; multi != to_multi;) - { - MultiXactMember member; - bool multixid_valid; - - /* - * Read this multixid's members. - * - * Locking-only XIDs that may be part of multi-xids don't matter - * after upgrade, as there can be no transactions running across - * upgrade. So as a small optimization, we only read one member - * from each multixid: the one updating one, or if there was no - * update, arbitrarily the first locking xid. - */ - multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); + for (MultiXactId multi = from_multi; multi != to_multi;) + { + MultiXactMember member; + bool multixid_valid; - /* - * Write the new offset to pg_multixact/offsets. - * - * Even if this multixid is invalid, we still need to write its - * offset if the *previous* multixid was valid. That's because - * when reading a multixid, the number of members is calculated - * from the difference between the two offsets. - */ - RecordMultiXactOffset(offsets_writer, multi, - (multixid_valid || prev_multixid_valid) ? next_offset : 0); + /* + * Read this multixid's members. + * + * Locking-only XIDs that may be part of multi-xids don't matter after + * upgrade, as there can be no transactions running across upgrade. So + * as a small optimization, we only read one member from each + * multixid: the one updating one, or if there was no update, + * arbitrarily the first locking xid. + */ + multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); - /* Write the members */ - if (multixid_valid) - { - RecordMultiXactMembers(members_writer, next_offset, 1, &member); - next_offset += 1; - } + /* + * Write the new offset to pg_multixact/offsets. + * + * Even if this multixid is invalid, we still need to write its offset + * if the *previous* multixid was valid. That's because when reading + * a multixid, the number of members is calculated from the difference + * between the two offsets. + */ + RecordMultiXactOffset(offsets_writer, multi, + (multixid_valid || prev_multixid_valid) ? next_offset : 0); - /* Advance to next multixid, handling wraparound */ - multi++; - if (multi < FirstMultiXactId) - multi = FirstMultiXactId; - prev_multixid_valid = multixid_valid; + /* Write the members */ + if (multixid_valid) + { + RecordMultiXactMembers(members_writer, next_offset, 1, &member); + next_offset += 1; } - FreeOldMultiXactReader(old_reader); + /* Advance to next multixid, handling wraparound */ + multi++; + if (multi < FirstMultiXactId) + multi = FirstMultiXactId; + prev_multixid_valid = multixid_valid; + } + + FreeOldMultiXactReader(old_reader); /* Write the final 'next' offset to the last SLRU page */ RecordMultiXactOffset(offsets_writer, to_multi, diff --git a/src/bin/pg_upgrade/pg_upgrade.c b/src/bin/pg_upgrade/pg_upgrade.c index c6af9035665..7366fd4627c 100644 --- a/src/bin/pg_upgrade/pg_upgrade.c +++ b/src/bin/pg_upgrade/pg_upgrade.c @@ -833,7 +833,7 @@ copy_xact_xlog_xid(void) * Determine the range of multixacts to convert. */ nxtmulti = old_cluster.controldata.chkpnt_nxtmulti; - oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; + oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; /* handle wraparound */ if (nxtmulti < FirstMultiXactId) nxtmulti = FirstMultiXactId; @@ -898,15 +898,15 @@ set_frozenxids(void) int i_datname; int i_datallowconn; - prep_status("Setting frozenxid and minmxid counters in new cluster"); + prep_status("Setting frozenxid and minmxid counters in new cluster"); conn_template1 = connectToServer(&new_cluster, "template1"); - /* set pg_database.datfrozenxid */ - PQclear(executeQueryOrDie(conn_template1, - "UPDATE pg_catalog.pg_database " - "SET datfrozenxid = '%u'", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_database.datfrozenxid */ + PQclear(executeQueryOrDie(conn_template1, + "UPDATE pg_catalog.pg_database " + "SET datfrozenxid = '%u'", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_database.datminmxid */ PQclear(executeQueryOrDie(conn_template1, @@ -942,16 +942,16 @@ set_frozenxids(void) conn = connectToServer(&new_cluster, datname); - /* set pg_class.relfrozenxid */ - PQclear(executeQueryOrDie(conn, - "UPDATE pg_catalog.pg_class " - "SET relfrozenxid = '%u' " - /* only heap, materialized view, and TOAST are vacuumed */ - "WHERE relkind IN (" - CppAsString2(RELKIND_RELATION) ", " - CppAsString2(RELKIND_MATVIEW) ", " - CppAsString2(RELKIND_TOASTVALUE) ")", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_class.relfrozenxid */ + PQclear(executeQueryOrDie(conn, + "UPDATE pg_catalog.pg_class " + "SET relfrozenxid = '%u' " + /* only heap, materialized view, and TOAST are vacuumed */ + "WHERE relkind IN (" + CppAsString2(RELKIND_RELATION) ", " + CppAsString2(RELKIND_MATVIEW) ", " + CppAsString2(RELKIND_TOASTVALUE) ")", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_class.relminmxid */ PQclear(executeQueryOrDie(conn, diff --git a/src/bin/pg_upgrade/relfilenumber.c b/src/bin/pg_upgrade/relfilenumber.c index ec2ff7acb21..6c467bdc8a5 100644 --- a/src/bin/pg_upgrade/relfilenumber.c +++ b/src/bin/pg_upgrade/relfilenumber.c @@ -587,32 +587,32 @@ transfer_relfile(FileNameMap *map, const char *type_suffix) /* Copying files might take some time, so give feedback. */ pg_log(PG_STATUS, "%s", old_file); - switch (user_opts.transfer_mode) - { - case TRANSFER_MODE_CLONE: - pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", - old_file, new_file); - cloneFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", - old_file, new_file); - copyFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY_FILE_RANGE: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", - old_file, new_file); - copyFileByRange(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_LINK: - pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", - old_file, new_file); - linkFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_SWAP: - /* swap mode is handled in its own code path */ - pg_fatal("should never happen"); - break; - } + switch (user_opts.transfer_mode) + { + case TRANSFER_MODE_CLONE: + pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", + old_file, new_file); + cloneFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", + old_file, new_file); + copyFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY_FILE_RANGE: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", + old_file, new_file); + copyFileByRange(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_LINK: + pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", + old_file, new_file); + linkFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_SWAP: + /* swap mode is handled in its own code path */ + pg_fatal("should never happen"); + break; + } } } diff --git a/src/bin/pg_upgrade/t/006_transfer_modes.pl b/src/bin/pg_upgrade/t/006_transfer_modes.pl index 9efa5dc863c..360d05c4b68 100644 --- a/src/bin/pg_upgrade/t/006_transfer_modes.pl +++ b/src/bin/pg_upgrade/t/006_transfer_modes.pl @@ -29,10 +29,8 @@ sub test_mode } $new->init(); - $new->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); - $old->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); + $new->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); + $old->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); # We can only test security labels if both the old and new installations # have dummy_seclabel. @@ -76,15 +74,14 @@ sub test_mode "CREATE TABLE test4 AS SELECT generate_series(400, 502)"); } - $old->safe_psql('postgres', - "CREATE TABLESPACE inplc_tblspc LOCATION ''"); - $old->safe_psql('postgres', - "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); - $old->safe_psql('postgres', - "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" - ); - $old->safe_psql('testdb3', - "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); + $old->safe_psql('postgres', "CREATE TABLESPACE inplc_tblspc LOCATION ''"); + $old->safe_psql('postgres', + "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); + $old->safe_psql('postgres', + "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" + ); + $old->safe_psql('testdb3', + "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); # While we are here, test handling of large objects. $old->safe_psql( @@ -152,12 +149,10 @@ sub test_mode } # Tests for in-place tablespaces. - $result = - $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); - is($result, '104', "test5 data after pg_upgrade $mode"); - $result = - $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); - is($result, '105', "test6 data after pg_upgrade $mode"); + $result = $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); + is($result, '104', "test5 data after pg_upgrade $mode"); + $result = $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); + is($result, '105', "test6 data after pg_upgrade $mode"); # Tests for large objects $result = $new->safe_psql('postgres', "SELECT lo_get(4532)"); diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index 44ef11d980e..c90bf8bbde2 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -6278,23 +6278,22 @@ get_create_object_cmd(EditableObjectType obj_type, Oid oid, * ensure the right view gets replaced. Also, check relation kind * to be sure it's a view. * - * Views may have WITH [LOCAL|CASCADED] - * CHECK OPTION. These are not part of the view definition - * returned by pg_get_viewdef() and so need to be retrieved - * separately. Materialized views may have - * arbitrary storage parameter reloptions. + * Views may have WITH [LOCAL|CASCADED] CHECK OPTION. These are + * not part of the view definition returned by pg_get_viewdef() + * and so need to be retrieved separately. Materialized views may + * have arbitrary storage parameter reloptions. */ printfPQExpBuffer(query, "/* %s */\n", _("Get view's definition and details")); - appendPQExpBuffer(query, - "SELECT nspname, relname, relkind, " - "pg_catalog.pg_get_viewdef(c.oid, true), " - "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " - "FROM pg_catalog.pg_class c " - "LEFT JOIN pg_catalog.pg_namespace n " - "ON c.relnamespace = n.oid WHERE c.oid = %u", - oid); + appendPQExpBuffer(query, + "SELECT nspname, relname, relkind, " + "pg_catalog.pg_get_viewdef(c.oid, true), " + "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " + "FROM pg_catalog.pg_class c " + "LEFT JOIN pg_catalog.pg_namespace n " + "ON c.relnamespace = n.oid WHERE c.oid = %u", + oid); break; } diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index ce99137c613..ac0c55e7aa5 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -387,19 +387,19 @@ describeFunctions(const char *functypes, const char *func_pattern, gettext_noop("stable"), gettext_noop("volatile"), gettext_noop("Volatility")); - appendPQExpBuffer(&buf, - ",\n CASE\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" - " END as \"%s\"", - gettext_noop("restricted"), - gettext_noop("safe"), - gettext_noop("unsafe"), - gettext_noop("Parallel")); + appendPQExpBuffer(&buf, + ",\n CASE\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" + " END as \"%s\"", + gettext_noop("restricted"), + gettext_noop("safe"), + gettext_noop("unsafe"), + gettext_noop("Parallel")); appendPQExpBuffer(&buf, ",\n pg_catalog.pg_get_userbyid(p.proowner) as \"%s\"" ",\n CASE WHEN prosecdef THEN '%s' ELSE '%s' END AS \"%s\"" @@ -599,8 +599,8 @@ describeFunctions(const char *functypes, const char *func_pattern, myopt.title = _("List of functions"); myopt.translate_header = true; - myopt.translate_columns = translate_columns; - myopt.n_translate_columns = lengthof(translate_columns); + myopt.translate_columns = translate_columns; + myopt.n_translate_columns = lengthof(translate_columns); printQuery(res, &myopt, pset.queryFout, false, pset.logfile); @@ -1086,38 +1086,38 @@ permissionsList(const char *pattern, bool showSystem) " ), E'\\n') AS \"%s\"", gettext_noop("Column privileges")); - appendPQExpBuffer(&buf, - ",\n pg_catalog.array_to_string(ARRAY(\n" - " SELECT polname\n" - " || CASE WHEN NOT polpermissive THEN\n" - " E' (RESTRICTIVE)'\n" - " ELSE '' END\n" - " || CASE WHEN polcmd != '*' THEN\n" - " E' (' || polcmd::pg_catalog.text || E'):'\n" - " ELSE E':'\n" - " END\n" - " || CASE WHEN polqual IS NOT NULL THEN\n" - " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" - " ELSE E''\n" - " END\n" - " || CASE WHEN polwithcheck IS NOT NULL THEN\n" - " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" - " ELSE E''\n" - " END" - " || CASE WHEN polroles <> '{0}' THEN\n" - " E'\\n to: ' || pg_catalog.array_to_string(\n" - " ARRAY(\n" - " SELECT rolname\n" - " FROM pg_catalog.pg_roles\n" - " WHERE oid = ANY (polroles)\n" - " ORDER BY 1\n" - " ), E', ')\n" - " ELSE E''\n" - " END\n" - " FROM pg_catalog.pg_policy pol\n" - " WHERE polrelid = c.oid), E'\\n')\n" - " AS \"%s\"", - gettext_noop("Policies")); + appendPQExpBuffer(&buf, + ",\n pg_catalog.array_to_string(ARRAY(\n" + " SELECT polname\n" + " || CASE WHEN NOT polpermissive THEN\n" + " E' (RESTRICTIVE)'\n" + " ELSE '' END\n" + " || CASE WHEN polcmd != '*' THEN\n" + " E' (' || polcmd::pg_catalog.text || E'):'\n" + " ELSE E':'\n" + " END\n" + " || CASE WHEN polqual IS NOT NULL THEN\n" + " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" + " ELSE E''\n" + " END\n" + " || CASE WHEN polwithcheck IS NOT NULL THEN\n" + " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" + " ELSE E''\n" + " END" + " || CASE WHEN polroles <> '{0}' THEN\n" + " E'\\n to: ' || pg_catalog.array_to_string(\n" + " ARRAY(\n" + " SELECT rolname\n" + " FROM pg_catalog.pg_roles\n" + " WHERE oid = ANY (polroles)\n" + " ORDER BY 1\n" + " ), E', ')\n" + " ELSE E''\n" + " END\n" + " FROM pg_catalog.pg_policy pol\n" + " WHERE polrelid = c.oid), E'\\n')\n" + " AS \"%s\"", + gettext_noop("Policies")); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_class c\n" " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n" @@ -1675,27 +1675,27 @@ describeOneTableDetails(const char *schemaname, char *footers[3] = {NULL, NULL, NULL}; printfPQExpBuffer(&buf, "/* %s */\n", _("Get sequence information")); - appendPQExpBuffer(&buf, - "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" - " seqstart AS \"%s\",\n" - " seqmin AS \"%s\",\n" - " seqmax AS \"%s\",\n" - " seqincrement AS \"%s\",\n" - " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" - " seqcache AS \"%s\"\n", - gettext_noop("Type"), - gettext_noop("Start"), - gettext_noop("Minimum"), - gettext_noop("Maximum"), - gettext_noop("Increment"), - gettext_noop("yes"), - gettext_noop("no"), - gettext_noop("Cycles?"), - gettext_noop("Cache")); - appendPQExpBuffer(&buf, - "FROM pg_catalog.pg_sequence\n" - "WHERE seqrelid = '%s';", - oid); + appendPQExpBuffer(&buf, + "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" + " seqstart AS \"%s\",\n" + " seqmin AS \"%s\",\n" + " seqmax AS \"%s\",\n" + " seqincrement AS \"%s\",\n" + " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" + " seqcache AS \"%s\"\n", + gettext_noop("Type"), + gettext_noop("Start"), + gettext_noop("Minimum"), + gettext_noop("Maximum"), + gettext_noop("Increment"), + gettext_noop("yes"), + gettext_noop("no"), + gettext_noop("Cycles?"), + gettext_noop("Cache")); + appendPQExpBuffer(&buf, + "FROM pg_catalog.pg_sequence\n" + "WHERE seqrelid = '%s';", + oid); res = PSQLexec(buf.data); if (!res) @@ -1913,7 +1913,7 @@ describeOneTableDetails(const char *schemaname, appendPQExpBufferStr(&buf, ",\n (SELECT c.collname FROM pg_catalog.pg_collation c, pg_catalog.pg_type t\n" " WHERE c.oid = a.attcollation AND t.oid = a.atttypid AND a.attcollation <> t.typcollation) AS attcollation"); attcoll_col = cols++; - appendPQExpBufferStr(&buf, ",\n a.attidentity"); + appendPQExpBufferStr(&buf, ",\n a.attidentity"); attidentity_col = cols++; if (pset.sversion >= 120000) appendPQExpBufferStr(&buf, ",\n a.attgenerated"); @@ -2326,7 +2326,7 @@ describeOneTableDetails(const char *schemaname, CppAsString2(CONSTRAINT_EXCLUSION) ") AND " "condeferred) AS condeferred,\n"); - appendPQExpBufferStr(&buf, "i.indisreplident,\n"); + appendPQExpBufferStr(&buf, "i.indisreplident,\n"); if (pset.sversion >= 150000) appendPQExpBufferStr(&buf, "i.indnullsnotdistinct,\n"); @@ -2431,7 +2431,7 @@ describeOneTableDetails(const char *schemaname, "pg_catalog.pg_get_indexdef(i.indexrelid, 0, true),\n " "pg_catalog.pg_get_constraintdef(con.oid, true), " "contype, condeferrable, condeferred"); - appendPQExpBufferStr(&buf, ", i.indisreplident"); + appendPQExpBufferStr(&buf, ", i.indisreplident"); appendPQExpBufferStr(&buf, ", c2.reltablespace"); if (pset.sversion >= 180000) appendPQExpBufferStr(&buf, ", con.conperiod"); @@ -2682,81 +2682,80 @@ describeOneTableDetails(const char *schemaname, PQclear(result); /* print any row-level policies */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get row-level policies for this table")); - appendPQExpBufferStr(&buf, "SELECT pol.polname,"); - appendPQExpBufferStr(&buf, - " pol.polpermissive,\n"); - appendPQExpBuffer(&buf, - " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" - " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" - " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" - " CASE pol.polcmd\n" - " WHEN 'r' THEN 'SELECT'\n" - " WHEN 'a' THEN 'INSERT'\n" - " WHEN 'w' THEN 'UPDATE'\n" - " WHEN 'd' THEN 'DELETE'\n" - " END AS cmd\n" - "FROM pg_catalog.pg_policy pol\n" - "WHERE pol.polrelid = '%s' ORDER BY 1;", - oid); + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get row-level policies for this table")); + appendPQExpBufferStr(&buf, "SELECT pol.polname,"); + appendPQExpBufferStr(&buf, + " pol.polpermissive,\n"); + appendPQExpBuffer(&buf, + " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" + " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" + " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" + " CASE pol.polcmd\n" + " WHEN 'r' THEN 'SELECT'\n" + " WHEN 'a' THEN 'INSERT'\n" + " WHEN 'w' THEN 'UPDATE'\n" + " WHEN 'd' THEN 'DELETE'\n" + " END AS cmd\n" + "FROM pg_catalog.pg_policy pol\n" + "WHERE pol.polrelid = '%s' ORDER BY 1;", + oid); - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - /* - * Handle cases where RLS is enabled and there are policies, or - * there aren't policies, or RLS isn't enabled but there are - * policies - */ - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies:")); + /* + * Handle cases where RLS is enabled and there are policies, or there + * aren't policies, or RLS isn't enabled but there are policies + */ + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies:")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled):")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled):")); - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); - if (!tableinfo.rowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (row security disabled):")); + if (!tableinfo.rowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (row security disabled):")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " POLICY \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " POLICY \"%s\"", + PQgetvalue(result, i, 0)); - if (*(PQgetvalue(result, i, 1)) == 'f') - appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); + if (*(PQgetvalue(result, i, 1)) == 'f') + appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); - if (!PQgetisnull(result, i, 5)) - appendPQExpBuffer(&buf, " FOR %s", - PQgetvalue(result, i, 5)); + if (!PQgetisnull(result, i, 5)) + appendPQExpBuffer(&buf, " FOR %s", + PQgetvalue(result, i, 5)); - if (!PQgetisnull(result, i, 2)) - { - appendPQExpBuffer(&buf, "\n TO %s", - PQgetvalue(result, i, 2)); - } + if (!PQgetisnull(result, i, 2)) + { + appendPQExpBuffer(&buf, "\n TO %s", + PQgetvalue(result, i, 2)); + } - if (!PQgetisnull(result, i, 3)) - appendPQExpBuffer(&buf, "\n USING (%s)", - PQgetvalue(result, i, 3)); + if (!PQgetisnull(result, i, 3)) + appendPQExpBuffer(&buf, "\n USING (%s)", + PQgetvalue(result, i, 3)); - if (!PQgetisnull(result, i, 4)) - appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", - PQgetvalue(result, i, 4)); + if (!PQgetisnull(result, i, 4)) + appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", + PQgetvalue(result, i, 4)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* print any extended statistics */ if (pset.sversion >= 140000) @@ -3025,115 +3024,115 @@ describeOneTableDetails(const char *schemaname, } /* print any publications */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get publications that publish this table")); - if (pset.sversion >= 150000) + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get publications that publish this table")); + if (pset.sversion >= 150000) + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" + " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" + "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" + "UNION\n" + "SELECT pubname\n" + " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" + " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" + " (SELECT pg_catalog.string_agg(attname, ', ')\n" + " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" + " pg_catalog.pg_attribute\n" + " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" + " ELSE NULL END) " + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" + "WHERE pr.prrelid = '%s'\n", + oid, oid, oid); + + if (pset.sversion >= 190000) { + /* + * Skip entries where this relation appears in the + * publication's EXCEPT list. + */ appendPQExpBuffer(&buf, + " AND NOT pr.prexcept\n" + "UNION\n" "SELECT pubname\n" " , NULL\n" " , NULL\n" "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" - " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" - "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" - "UNION\n" - "SELECT pubname\n" - " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" - " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" - " (SELECT pg_catalog.string_agg(attname, ', ')\n" - " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" - " pg_catalog.pg_attribute\n" - " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" - " ELSE NULL END) " - "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" - "WHERE pr.prrelid = '%s'\n", + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + " AND NOT EXISTS (\n" + " SELECT 1\n" + " FROM pg_catalog.pg_publication_rel pr\n" + " WHERE pr.prpubid = p.oid AND\n" + " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" + "ORDER BY 1;", oid, oid, oid); - - if (pset.sversion >= 190000) - { - /* - * Skip entries where this relation appears in the - * publication's EXCEPT list. - */ - appendPQExpBuffer(&buf, - " AND NOT pr.prexcept\n" - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - " AND NOT EXISTS (\n" - " SELECT 1\n" - " FROM pg_catalog.pg_publication_rel pr\n" - " WHERE pr.prpubid = p.oid AND\n" - " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" - "ORDER BY 1;", - oid, oid, oid); - } - else - { - appendPQExpBuffer(&buf, - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - "ORDER BY 1;", - oid); - } } else { appendPQExpBuffer(&buf, + "UNION\n" "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - "WHERE pr.prrelid = '%s'\n" - "UNION ALL\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" + " , NULL\n" + " , NULL\n" "FROM pg_catalog.pg_publication p\n" "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" "ORDER BY 1;", - oid, oid); + oid); } + } + else + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + "WHERE pr.prrelid = '%s'\n" + "UNION ALL\n" + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + "ORDER BY 1;", + oid, oid); + } - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - if (tuples > 0) - printTableAddFooter(&cont, _("Included in publications:")); + if (tuples > 0) + printTableAddFooter(&cont, _("Included in publications:")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " \"%s\"", + PQgetvalue(result, i, 0)); - /* column list (if any) */ - if (!PQgetisnull(result, i, 2)) - appendPQExpBuffer(&buf, " (%s)", - PQgetvalue(result, i, 2)); + /* column list (if any) */ + if (!PQgetisnull(result, i, 2)) + appendPQExpBuffer(&buf, " (%s)", + PQgetvalue(result, i, 2)); - /* row filter (if any) */ - if (!PQgetisnull(result, i, 1)) - appendPQExpBuffer(&buf, " WHERE %s", - PQgetvalue(result, i, 1)); + /* row filter (if any) */ + if (!PQgetisnull(result, i, 1)) + appendPQExpBuffer(&buf, " WHERE %s", + PQgetvalue(result, i, 1)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* Print publications where the table is in the EXCEPT clause */ if (pset.sversion >= 190000) @@ -3805,7 +3804,7 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) ncols++; } appendPQExpBufferStr(&buf, "\n, r.rolreplication"); - appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); + appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_roles r\n"); @@ -3860,8 +3859,8 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) if (strcmp(PQgetvalue(res, i, (verbose ? 9 : 8)), "t") == 0) add_role_attribute(&buf, _("Replication")); - if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) - add_role_attribute(&buf, _("Bypass RLS")); + if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) + add_role_attribute(&buf, _("Bypass RLS")); conns = atoi(PQgetvalue(res, i, 6)); if (conns >= 0) @@ -5155,14 +5154,14 @@ listCollations(const char *pattern, bool verbose, bool showSystem) gettext_noop("Schema"), gettext_noop("Name")); - appendPQExpBuffer(&buf, - " CASE c.collprovider " - "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " - "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " - "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " - "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " - "END AS \"%s\",\n", - gettext_noop("Provider")); + appendPQExpBuffer(&buf, + " CASE c.collprovider " + "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " + "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " + "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " + "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " + "END AS \"%s\",\n", + gettext_noop("Provider")); appendPQExpBuffer(&buf, " c.collcollate AS \"%s\",\n" -- 2.50.1 (Apple Git-155) --aHl3HfeiUuO3zeNC-- ^ permalink raw reply [nested|flat] 59+ messages in thread
* [PATCH v6 4/4] run pgindent and pgperltidy @ 2026-06-30 18:24 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 59+ messages in thread From: Nathan Bossart @ 2026-06-30 18:24 UTC (permalink / raw) --- src/bin/pg_dump/pg_dump.c | 464 ++++++++++----------- src/bin/pg_dump/pg_dumpall.c | 30 +- src/bin/pg_upgrade/check.c | 16 +- src/bin/pg_upgrade/controldata.c | 2 +- src/bin/pg_upgrade/exec.c | 8 +- src/bin/pg_upgrade/multixact_rewrite.c | 80 ++-- src/bin/pg_upgrade/pg_upgrade.c | 34 +- src/bin/pg_upgrade/relfilenumber.c | 54 +-- src/bin/pg_upgrade/t/006_transfer_modes.pl | 33 +- src/bin/psql/command.c | 29 +- src/bin/psql/describe.c | 461 ++++++++++---------- 11 files changed, 601 insertions(+), 610 deletions(-) diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 65bd15ebfd2..5673268b467 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -1491,8 +1491,8 @@ setup_connection(Archive *AH, const char *dumpencoding, * Disable timeouts if supported. */ ExecuteSqlStatement(AH, "SET statement_timeout = 0"); - ExecuteSqlStatement(AH, "SET lock_timeout = 0"); - ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); + ExecuteSqlStatement(AH, "SET lock_timeout = 0"); + ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); if (AH->remoteVersion >= 170000) ExecuteSqlStatement(AH, "SET transaction_timeout = 0"); @@ -1505,10 +1505,10 @@ setup_connection(Archive *AH, const char *dumpencoding, /* * Adjust row-security mode, if supported. */ - if (dopt->enable_row_security) - ExecuteSqlStatement(AH, "SET row_security = on"); - else - ExecuteSqlStatement(AH, "SET row_security = off"); + if (dopt->enable_row_security) + ExecuteSqlStatement(AH, "SET row_security = on"); + else + ExecuteSqlStatement(AH, "SET row_security = off"); /* * For security reasons, we restrict the expansion of non-system views and @@ -1933,10 +1933,9 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) addObjectDependency(dobj, ext->dobj.dumpId); /* - * Mark the member object to have any non-initial ACLs - * dumped. (Any initial ACLs will be removed later, using data from - * pg_init_privs, so that we'll dump only the delta from the extension's - * initial setup.) + * Mark the member object to have any non-initial ACLs dumped. (Any + * initial ACLs will be removed later, using data from pg_init_privs, so + * that we'll dump only the delta from the extension's initial setup.) * * In binary upgrades, we still dump all components of the members * individually, since the idea is to exactly reproduce the database @@ -1953,7 +1952,7 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) if (fout->dopt->binary_upgrade) dobj->dump = ext->dobj.dump; else - dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); + dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); return true; } @@ -1987,9 +1986,9 @@ selectDumpableNamespace(NamespaceInfo *nsinfo, Archive *fout) else if (strcmp(nsinfo->dobj.name, "pg_catalog") == 0) { /* - * We dump out any ACLs defined in pg_catalog, if - * they are interesting (and not the original ACLs which were set at - * initdb time, see pg_init_privs). + * We dump out any ACLs defined in pg_catalog, if they are interesting + * (and not the original ACLs which were set at initdb time, see + * pg_init_privs). */ nsinfo->dobj.dump_contains = nsinfo->dobj.dump = DUMP_COMPONENT_ACL; } @@ -3296,7 +3295,7 @@ dumpDatabase(Archive *fout) "datcollate, datctype, datfrozenxid, " "datacl, acldefault('d', datdba) AS acldefault, " "datistemplate, datconnlimit, "); - appendPQExpBufferStr(dbQry, "datminmxid, "); + appendPQExpBufferStr(dbQry, "datminmxid, "); if (fout->remoteVersion >= 170000) appendPQExpBufferStr(dbQry, "datlocprovider, datlocale, datcollversion, "); else if (fout->remoteVersion >= 150000) @@ -3638,11 +3637,11 @@ dumpDatabase(Archive *fout) ii_oid, ii_relminmxid; - appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" - "FROM pg_catalog.pg_class\n" - "WHERE oid IN (%u, %u, %u, %u);\n", - LargeObjectRelationId, LargeObjectLOidPNIndexId, - LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); + appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" + "FROM pg_catalog.pg_class\n" + "WHERE oid IN (%u, %u, %u, %u);\n", + LargeObjectRelationId, LargeObjectLOidPNIndexId, + LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); lo_res = ExecuteSqlQuery(fout, loFrozenQry->data, PGRES_TUPLES_OK); @@ -4274,7 +4273,7 @@ getPolicies(Archive *fout, TableInfo tblinfo[], int numTables) printfPQExpBuffer(query, "SELECT pol.oid, pol.tableoid, pol.polrelid, pol.polname, pol.polcmd, "); - appendPQExpBufferStr(query, "pol.polpermissive, "); + appendPQExpBufferStr(query, "pol.polpermissive, "); appendPQExpBuffer(query, "CASE WHEN pol.polroles = '{0}' THEN NULL ELSE " " pg_catalog.array_to_string(ARRAY(SELECT pg_catalog.quote_ident(rolname) from pg_catalog.pg_roles WHERE oid = ANY(pol.polroles)), ', ') END AS polroles, " @@ -6633,9 +6632,9 @@ getAccessMethods(Archive *fout) * Select all access methods from pg_am table. */ appendPQExpBufferStr(query, "SELECT tableoid, oid, amname, "); - appendPQExpBufferStr(query, - "amtype, " - "amhandler::pg_catalog.regproc AS amhandler "); + appendPQExpBufferStr(query, + "amtype, " + "amhandler::pg_catalog.regproc AS amhandler "); appendPQExpBufferStr(query, "FROM pg_am"); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6827,35 +6826,35 @@ getAggregates(Archive *fout) * Find all interesting aggregates. See comment in getFuncs() for the * rationale behind the filtering logic. */ - agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" - : "p.proisagg"); + agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" + : "p.proisagg"); - appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " - "p.proname AS aggname, " - "p.pronamespace AS aggnamespace, " - "p.pronargs, p.proargtypes, " - "p.proowner, " - "p.proacl AS aggacl, " - "acldefault('f', p.proowner) AS acldefault " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s AND (" - "p.pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog') OR " - "p.proacl IS DISTINCT FROM pip.initprivs", - agg_check); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - " OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); - appendPQExpBufferChar(query, ')'); + appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " + "p.proname AS aggname, " + "p.pronamespace AS aggnamespace, " + "p.pronargs, p.proargtypes, " + "p.proowner, " + "p.proacl AS aggacl, " + "acldefault('f', p.proowner) AS acldefault " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s AND (" + "p.pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog') OR " + "p.proacl IS DISTINCT FROM pip.initprivs", + agg_check); + if (dopt->binary_upgrade) + appendPQExpBufferStr(query, + " OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6957,53 +6956,53 @@ getFuncs(Archive *fout) * include them, since we want to dump extension members individually in * that mode. Also, if they are used by casts or transforms then we need * to gather the information about them, though they won't be dumped if - * they are built-in. Also, include functions in - * pg_catalog if they have an ACL different from what's shown in - * pg_init_privs (so we have to join to pg_init_privs; annoying). + * they are built-in. Also, include functions in pg_catalog if they have + * an ACL different from what's shown in pg_init_privs (so we have to join + * to pg_init_privs; annoying). */ - not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" - : "NOT p.proisagg"); + not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" + : "NOT p.proisagg"); - appendPQExpBuffer(query, - "SELECT p.tableoid, p.oid, p.proname, p.prolang, " - "p.pronargs, p.proargtypes, p.prorettype, " - "p.proacl, " - "acldefault('f', p.proowner) AS acldefault, " - "p.pronamespace, " - "p.proowner " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s" - "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " - "WHERE classid = 'pg_proc'::regclass AND " - "objid = p.oid AND deptype = 'i')" - "\n AND (" - "\n pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog')" - "\n OR EXISTS (SELECT 1 FROM pg_cast" - "\n WHERE pg_cast.oid > %u " - "\n AND p.oid = pg_cast.castfunc)" - "\n OR EXISTS (SELECT 1 FROM pg_transform" - "\n WHERE pg_transform.oid > %u AND " - "\n (p.oid = pg_transform.trffromsql" - "\n OR p.oid = pg_transform.trftosql))", - not_agg_check, - g_last_builtin_oid, - g_last_builtin_oid); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); + appendPQExpBuffer(query, + "SELECT p.tableoid, p.oid, p.proname, p.prolang, " + "p.pronargs, p.proargtypes, p.prorettype, " + "p.proacl, " + "acldefault('f', p.proowner) AS acldefault, " + "p.pronamespace, " + "p.proowner " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s" + "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " + "WHERE classid = 'pg_proc'::regclass AND " + "objid = p.oid AND deptype = 'i')" + "\n AND (" + "\n pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog')" + "\n OR EXISTS (SELECT 1 FROM pg_cast" + "\n WHERE pg_cast.oid > %u " + "\n AND p.oid = pg_cast.castfunc)" + "\n OR EXISTS (SELECT 1 FROM pg_transform" + "\n WHERE pg_transform.oid > %u AND " + "\n (p.oid = pg_transform.trffromsql" + "\n OR p.oid = pg_transform.trftosql))", + not_agg_check, + g_last_builtin_oid, + g_last_builtin_oid); + if (dopt->binary_upgrade) appendPQExpBufferStr(query, - "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); - appendPQExpBufferChar(query, ')'); + "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferStr(query, + "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -7252,31 +7251,31 @@ getTables(Archive *fout, int *numTables) appendPQExpBufferStr(query, "c.relhasoids, "); - appendPQExpBufferStr(query, - "c.relispopulated, "); + appendPQExpBufferStr(query, + "c.relispopulated, "); - appendPQExpBufferStr(query, - "c.relreplident, "); + appendPQExpBufferStr(query, + "c.relreplident, "); - appendPQExpBufferStr(query, - "c.relrowsecurity, c.relforcerowsecurity, "); + appendPQExpBufferStr(query, + "c.relrowsecurity, c.relforcerowsecurity, "); - appendPQExpBufferStr(query, - "c.relminmxid, tc.relminmxid AS tminmxid, "); + appendPQExpBufferStr(query, + "c.relminmxid, tc.relminmxid AS tminmxid, "); - appendPQExpBufferStr(query, - "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); + appendPQExpBufferStr(query, + "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); - appendPQExpBufferStr(query, - "am.amname, "); + appendPQExpBufferStr(query, + "am.amname, "); - appendPQExpBufferStr(query, - "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); + appendPQExpBufferStr(query, + "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); - appendPQExpBufferStr(query, - "c.relispartition AS ispartition "); + appendPQExpBufferStr(query, + "c.relispartition AS ispartition "); /* * Left join to pg_depend to pick up dependency info linking sequences to @@ -7296,8 +7295,8 @@ getTables(Archive *fout, int *numTables) /* * Left join to pg_am to pick up the amname. */ - appendPQExpBufferStr(query, - "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); + appendPQExpBufferStr(query, + "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); /* * We purposefully ignore toast OIDs for partitioned tables; the reason is @@ -7868,8 +7867,8 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables) "t.reloptions AS indreloptions, "); - appendPQExpBufferStr(query, - "i.indisreplident, "); + appendPQExpBufferStr(query, + "i.indisreplident, "); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -9313,8 +9312,8 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables) appendPQExpBufferStr(q, "'' AS attcompression,\n"); - appendPQExpBufferStr(q, - "a.attidentity,\n"); + appendPQExpBufferStr(q, + "a.attidentity,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(q, @@ -10717,73 +10716,73 @@ getAdditionalACLs(Archive *fout) PQclear(res); /* Fetch initial-privileges data */ - printfPQExpBuffer(query, - "SELECT objoid, classoid, objsubid, privtype, initprivs " - "FROM pg_init_privs"); + printfPQExpBuffer(query, + "SELECT objoid, classoid, objsubid, privtype, initprivs " + "FROM pg_init_privs"); - res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); + res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); - ntups = PQntuples(res); - for (i = 0; i < ntups; i++) - { - Oid objoid = atooid(PQgetvalue(res, i, 0)); - Oid classoid = atooid(PQgetvalue(res, i, 1)); - int objsubid = atoi(PQgetvalue(res, i, 2)); - char privtype = *(PQgetvalue(res, i, 3)); - char *initprivs = PQgetvalue(res, i, 4); - CatalogId objId; - DumpableObject *dobj; + ntups = PQntuples(res); + for (i = 0; i < ntups; i++) + { + Oid objoid = atooid(PQgetvalue(res, i, 0)); + Oid classoid = atooid(PQgetvalue(res, i, 1)); + int objsubid = atoi(PQgetvalue(res, i, 2)); + char privtype = *(PQgetvalue(res, i, 3)); + char *initprivs = PQgetvalue(res, i, 4); + CatalogId objId; + DumpableObject *dobj; - objId.tableoid = classoid; - objId.oid = objoid; - dobj = findObjectByCatalogId(objId); - /* OK to ignore entries we haven't got a DumpableObject for */ - if (dobj) + objId.tableoid = classoid; + objId.oid = objoid; + dobj = findObjectByCatalogId(objId); + /* OK to ignore entries we haven't got a DumpableObject for */ + if (dobj) + { + /* Cope with sub-object initprivs */ + if (objsubid != 0) { - /* Cope with sub-object initprivs */ - if (objsubid != 0) - { - if (dobj->objType == DO_TABLE) - { - /* For a column initprivs, set the table's ACL flags */ - dobj->components |= DUMP_COMPONENT_ACL; - ((TableInfo *) dobj)->hascolumnACLs = true; - } - else - pg_log_warning("unsupported pg_init_privs entry: %u %u %d", - classoid, objoid, objsubid); - continue; - } - - /* - * We ignore any pg_init_privs.initprivs entry for the public - * schema, as explained in getNamespaces(). - */ - if (dobj->objType == DO_NAMESPACE && - strcmp(dobj->name, "public") == 0) - continue; - - /* Else it had better be of a type we think has ACLs */ - if (dobj->objType == DO_NAMESPACE || - dobj->objType == DO_TYPE || - dobj->objType == DO_FUNC || - dobj->objType == DO_AGG || - dobj->objType == DO_TABLE || - dobj->objType == DO_PROCLANG || - dobj->objType == DO_FDW || - dobj->objType == DO_FOREIGN_SERVER) + if (dobj->objType == DO_TABLE) { - DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; - - daobj->dacl.privtype = privtype; - daobj->dacl.initprivs = pstrdup(initprivs); + /* For a column initprivs, set the table's ACL flags */ + dobj->components |= DUMP_COMPONENT_ACL; + ((TableInfo *) dobj)->hascolumnACLs = true; } else pg_log_warning("unsupported pg_init_privs entry: %u %u %d", classoid, objoid, objsubid); + continue; + } + + /* + * We ignore any pg_init_privs.initprivs entry for the public + * schema, as explained in getNamespaces(). + */ + if (dobj->objType == DO_NAMESPACE && + strcmp(dobj->name, "public") == 0) + continue; + + /* Else it had better be of a type we think has ACLs */ + if (dobj->objType == DO_NAMESPACE || + dobj->objType == DO_TYPE || + dobj->objType == DO_FUNC || + dobj->objType == DO_AGG || + dobj->objType == DO_TABLE || + dobj->objType == DO_PROCLANG || + dobj->objType == DO_FDW || + dobj->objType == DO_FOREIGN_SERVER) + { + DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; + + daobj->dacl.privtype = privtype; + daobj->dacl.initprivs = pstrdup(initprivs); } + else + pg_log_warning("unsupported pg_init_privs entry: %u %u %d", + classoid, objoid, objsubid); } - PQclear(res); + } + PQclear(res); destroyPQExpBuffer(query); } @@ -11128,8 +11127,8 @@ dumpRelationStats_dumper(Archive *fout, const void *userArg, const TocEntry *te) * The results must be in the order of the relations supplied in the * parameters to ensure we remain in sync as we walk through the TOC. * - * For versions before 19, the redundant filter clause on s.tablename = - * ANY(...) seems sufficient to convince the planner to use + * For versions before 19, the redundant filter clause on s.tablename + * = ANY(...) seems sufficient to convince the planner to use * pg_class_relname_nsp_index, which avoids a full scan of pg_stats. * In newer versions, pg_stats returns the table OIDs, eliminating the * need for that hack. @@ -13469,11 +13468,11 @@ dumpFunc(Archive *fout, const FuncInfo *finfo) "pg_catalog.pg_get_function_result(p.oid) AS funcresult,\n" "proleakproof,\n"); - appendPQExpBufferStr(query, - "array_to_string(protrftypes, ' ') AS protrftypes,\n"); + appendPQExpBufferStr(query, + "array_to_string(protrftypes, ' ') AS protrftypes,\n"); - appendPQExpBufferStr(query, - "proparallel,\n"); + appendPQExpBufferStr(query, + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -14963,9 +14962,9 @@ dumpCollation(Archive *fout, const CollInfo *collinfo) /* Get collation-specific details */ appendPQExpBufferStr(query, "SELECT "); - appendPQExpBufferStr(query, - "collprovider, " - "collversion, "); + appendPQExpBufferStr(query, + "collprovider, " + "collversion, "); if (fout->remoteVersion >= 120000) appendPQExpBufferStr(query, @@ -15372,23 +15371,23 @@ dumpAgg(Archive *fout, const AggInfo *agginfo) "pg_catalog.pg_get_function_arguments(p.oid) AS funcargs,\n" "pg_catalog.pg_get_function_identity_arguments(p.oid) AS funciargs,\n"); - appendPQExpBufferStr(query, - "aggkind,\n" - "aggmtransfn,\n" - "aggminvtransfn,\n" - "aggmfinalfn,\n" - "aggmtranstype::pg_catalog.regtype,\n" - "aggfinalextra,\n" - "aggmfinalextra,\n" - "aggtransspace,\n" - "aggmtransspace,\n" - "aggminitval,\n"); + appendPQExpBufferStr(query, + "aggkind,\n" + "aggmtransfn,\n" + "aggminvtransfn,\n" + "aggmfinalfn,\n" + "aggmtranstype::pg_catalog.regtype,\n" + "aggfinalextra,\n" + "aggmfinalextra,\n" + "aggtransspace,\n" + "aggmtransspace,\n" + "aggminitval,\n"); - appendPQExpBufferStr(query, - "aggcombinefn,\n" - "aggserialfn,\n" - "aggdeserialfn,\n" - "proparallel,\n"); + appendPQExpBufferStr(query, + "aggcombinefn,\n" + "aggserialfn,\n" + "aggdeserialfn,\n" + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -16848,30 +16847,30 @@ dumpTable(Archive *fout, const TableInfo *tbinfo) appendPQExpBufferStr(query, "PREPARE getColumnACLs(pg_catalog.oid) AS\n"); - /* - * In principle we should call acldefault('c', relowner) to - * get the default ACL for a column. However, we don't - * currently store the numeric OID of the relowner in - * TableInfo. We could convert the owner name using regrole, - * but that creates a risk of failure due to concurrent role - * renames. Given that the default ACL for columns is empty - * and is likely to stay that way, it's not worth extra cycles - * and risk to avoid hard-wiring that knowledge here. - */ - appendPQExpBufferStr(query, - "SELECT at.attname, " - "at.attacl, " - "'{}' AS acldefault, " - "pip.privtype, pip.initprivs " - "FROM pg_catalog.pg_attribute at " - "LEFT JOIN pg_catalog.pg_init_privs pip ON " - "(at.attrelid = pip.objoid " - "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " - "AND at.attnum = pip.objsubid) " - "WHERE at.attrelid = $1 AND " - "NOT at.attisdropped " - "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " - "ORDER BY at.attnum"); + /* + * In principle we should call acldefault('c', relowner) to get + * the default ACL for a column. However, we don't currently + * store the numeric OID of the relowner in TableInfo. We could + * convert the owner name using regrole, but that creates a risk + * of failure due to concurrent role renames. Given that the + * default ACL for columns is empty and is likely to stay that + * way, it's not worth extra cycles and risk to avoid hard-wiring + * that knowledge here. + */ + appendPQExpBufferStr(query, + "SELECT at.attname, " + "at.attacl, " + "'{}' AS acldefault, " + "pip.privtype, pip.initprivs " + "FROM pg_catalog.pg_attribute at " + "LEFT JOIN pg_catalog.pg_init_privs pip ON " + "(at.attrelid = pip.objoid " + "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " + "AND at.attnum = pip.objsubid) " + "WHERE at.attrelid = $1 AND " + "NOT at.attisdropped " + "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " + "ORDER BY at.attnum"); ExecuteSqlStatement(fout, query->data); @@ -19165,7 +19164,7 @@ collectSequences(Archive *fout) * pg_get_sequence_data(), but we only do so for non-schema-only dumps. */ if (fout->remoteVersion < 180000 || - (!fout->dopt->dumpData && !fout->dopt->sequence_data)) + (!fout->dopt->dumpData && !fout->dopt->sequence_data)) query = "SELECT seqrelid, format_type(seqtypid, NULL), " "seqstart, seqincrement, " "seqmax, seqmin, " @@ -19227,15 +19226,14 @@ dumpSequence(Archive *fout, const TableInfo *tbinfo) qseqname = pg_strdup(fmtId(tbinfo->dobj.name)); /* - * The sequence information is gathered in a sorted - * table before any calls to dumpSequence(). See collectSequences() for - * more information. + * The sequence information is gathered in a sorted table before any calls + * to dumpSequence(). See collectSequences() for more information. */ - Assert(sequences); + Assert(sequences); - key.oid = tbinfo->dobj.catId.oid; - seq = bsearch(&key, sequences, nsequences, - sizeof(SequenceItem), SequenceItemCmp); + key.oid = tbinfo->dobj.catId.oid; + seq = bsearch(&key, sequences, nsequences, + sizeof(SequenceItem), SequenceItemCmp); /* Calculate default limits for a sequence of this type */ is_ascending = (seq->incby >= 0); diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c index e68937c9934..afcd9a218d8 100644 --- a/src/bin/pg_dump/pg_dumpall.c +++ b/src/bin/pg_dump/pg_dumpall.c @@ -785,11 +785,11 @@ dropRoles(PGconn *conn) int i_rolname; int i; - printfPQExpBuffer(buf, - "SELECT rolname " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 1", role_catalog); + printfPQExpBuffer(buf, + "SELECT rolname " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 1", role_catalog); res = executeQuery(conn, buf->data); @@ -843,16 +843,16 @@ dumpRoles(PGconn *conn) * Notes: rolconfig is dumped later, and pg_authid must be used for * extracting rolcomment regardless of role_catalog. */ - printfPQExpBuffer(buf, - "SELECT oid, rolname, rolsuper, rolinherit, " - "rolcreaterole, rolcreatedb, " - "rolcanlogin, rolconnlimit, rolpassword, " - "rolvaliduntil, rolreplication, rolbypassrls, " - "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " - "rolname = current_user AS is_current_user " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 2", role_catalog); + printfPQExpBuffer(buf, + "SELECT oid, rolname, rolsuper, rolinherit, " + "rolcreaterole, rolcreatedb, " + "rolcanlogin, rolconnlimit, rolpassword, " + "rolvaliduntil, rolreplication, rolbypassrls, " + "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " + "rolname = current_user AS is_current_user " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 2", role_catalog); res = executeQuery(conn, buf->data); diff --git a/src/bin/pg_upgrade/check.c b/src/bin/pg_upgrade/check.c index 786c1474829..f725f5ee3e2 100644 --- a/src/bin/pg_upgrade/check.c +++ b/src/bin/pg_upgrade/check.c @@ -1475,15 +1475,15 @@ check_for_incompatible_polymorphics(ClusterInfo *cluster) ", 'array_cat(anyarray,anyarray)'" ", 'array_prepend(anyelement,anyarray)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_remove(anyarray,anyelement)'" - ", 'array_replace(anyarray,anyelement,anyelement)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_remove(anyarray,anyelement)'" + ", 'array_replace(anyarray,anyelement,anyelement)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_position(anyarray,anyelement)'" - ", 'array_position(anyarray,anyelement,integer)'" - ", 'array_positions(anyarray,anyelement)'" - ", 'width_bucket(anyelement,anyarray)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_position(anyarray,anyelement)'" + ", 'array_position(anyarray,anyelement,integer)'" + ", 'array_positions(anyarray,anyelement)'" + ", 'width_bucket(anyelement,anyarray)'"); /* * The query below hardcodes FirstNormalObjectId as 16384 rather than diff --git a/src/bin/pg_upgrade/controldata.c b/src/bin/pg_upgrade/controldata.c index 8f81c9e9582..02ea02df60f 100644 --- a/src/bin/pg_upgrade/controldata.c +++ b/src/bin/pg_upgrade/controldata.c @@ -228,7 +228,7 @@ get_control_data(ClusterInfo *cluster) p++; /* remove ':' char */ cluster->controldata.chkpnt_nxtepoch = str2uint(p); - p = strchr(p, ':'); + p = strchr(p, ':'); if (p == NULL || strlen(p) <= 1) pg_fatal("%d: controldata retrieval problem", __LINE__); diff --git a/src/bin/pg_upgrade/exec.c b/src/bin/pg_upgrade/exec.c index 44355feea30..a1bdbf373e3 100644 --- a/src/bin/pg_upgrade/exec.c +++ b/src/bin/pg_upgrade/exec.c @@ -55,7 +55,7 @@ get_bin_version(ClusterInfo *cluster) if (sscanf(cmd_output, "%*s %*s %d.%d", &v1, &v2) < 1) pg_fatal("could not get pg_ctl version output from %s", cmd); - cluster->bin_version = v1 * 10000; + cluster->bin_version = v1 * 10000; } @@ -344,8 +344,8 @@ check_data_dir(ClusterInfo *cluster) check_single_dir(pg_data, "pg_subtrans"); check_single_dir(pg_data, PG_TBLSPC_DIR); check_single_dir(pg_data, "pg_twophase"); - check_single_dir(pg_data, "pg_wal"); - check_single_dir(pg_data, "pg_xact"); + check_single_dir(pg_data, "pg_wal"); + check_single_dir(pg_data, "pg_xact"); } @@ -385,7 +385,7 @@ check_bin_dir(ClusterInfo *cluster, bool check_versions) */ get_bin_version(cluster); - check_exec(cluster->bindir, "pg_resetwal", check_versions); + check_exec(cluster->bindir, "pg_resetwal", check_versions); if (cluster == &new_cluster) { diff --git a/src/bin/pg_upgrade/multixact_rewrite.c b/src/bin/pg_upgrade/multixact_rewrite.c index c45b3183684..c7a1416494d 100644 --- a/src/bin/pg_upgrade/multixact_rewrite.c +++ b/src/bin/pg_upgrade/multixact_rewrite.c @@ -61,52 +61,52 @@ rewrite_multixacts(MultiXactId from_multi, MultiXactId to_multi) * Convert old multixids, if needed, by reading them one-by-one from the * old cluster. */ - old_reader = AllocOldMultiXactRead(old_cluster.pgdata, - old_cluster.controldata.chkpnt_nxtmulti, - old_cluster.controldata.chkpnt_nxtmxoff); + old_reader = AllocOldMultiXactRead(old_cluster.pgdata, + old_cluster.controldata.chkpnt_nxtmulti, + old_cluster.controldata.chkpnt_nxtmxoff); - for (MultiXactId multi = from_multi; multi != to_multi;) - { - MultiXactMember member; - bool multixid_valid; - - /* - * Read this multixid's members. - * - * Locking-only XIDs that may be part of multi-xids don't matter - * after upgrade, as there can be no transactions running across - * upgrade. So as a small optimization, we only read one member - * from each multixid: the one updating one, or if there was no - * update, arbitrarily the first locking xid. - */ - multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); + for (MultiXactId multi = from_multi; multi != to_multi;) + { + MultiXactMember member; + bool multixid_valid; - /* - * Write the new offset to pg_multixact/offsets. - * - * Even if this multixid is invalid, we still need to write its - * offset if the *previous* multixid was valid. That's because - * when reading a multixid, the number of members is calculated - * from the difference between the two offsets. - */ - RecordMultiXactOffset(offsets_writer, multi, - (multixid_valid || prev_multixid_valid) ? next_offset : 0); + /* + * Read this multixid's members. + * + * Locking-only XIDs that may be part of multi-xids don't matter after + * upgrade, as there can be no transactions running across upgrade. So + * as a small optimization, we only read one member from each + * multixid: the one updating one, or if there was no update, + * arbitrarily the first locking xid. + */ + multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); - /* Write the members */ - if (multixid_valid) - { - RecordMultiXactMembers(members_writer, next_offset, 1, &member); - next_offset += 1; - } + /* + * Write the new offset to pg_multixact/offsets. + * + * Even if this multixid is invalid, we still need to write its offset + * if the *previous* multixid was valid. That's because when reading + * a multixid, the number of members is calculated from the difference + * between the two offsets. + */ + RecordMultiXactOffset(offsets_writer, multi, + (multixid_valid || prev_multixid_valid) ? next_offset : 0); - /* Advance to next multixid, handling wraparound */ - multi++; - if (multi < FirstMultiXactId) - multi = FirstMultiXactId; - prev_multixid_valid = multixid_valid; + /* Write the members */ + if (multixid_valid) + { + RecordMultiXactMembers(members_writer, next_offset, 1, &member); + next_offset += 1; } - FreeOldMultiXactReader(old_reader); + /* Advance to next multixid, handling wraparound */ + multi++; + if (multi < FirstMultiXactId) + multi = FirstMultiXactId; + prev_multixid_valid = multixid_valid; + } + + FreeOldMultiXactReader(old_reader); /* Write the final 'next' offset to the last SLRU page */ RecordMultiXactOffset(offsets_writer, to_multi, diff --git a/src/bin/pg_upgrade/pg_upgrade.c b/src/bin/pg_upgrade/pg_upgrade.c index c6af9035665..7366fd4627c 100644 --- a/src/bin/pg_upgrade/pg_upgrade.c +++ b/src/bin/pg_upgrade/pg_upgrade.c @@ -833,7 +833,7 @@ copy_xact_xlog_xid(void) * Determine the range of multixacts to convert. */ nxtmulti = old_cluster.controldata.chkpnt_nxtmulti; - oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; + oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; /* handle wraparound */ if (nxtmulti < FirstMultiXactId) nxtmulti = FirstMultiXactId; @@ -898,15 +898,15 @@ set_frozenxids(void) int i_datname; int i_datallowconn; - prep_status("Setting frozenxid and minmxid counters in new cluster"); + prep_status("Setting frozenxid and minmxid counters in new cluster"); conn_template1 = connectToServer(&new_cluster, "template1"); - /* set pg_database.datfrozenxid */ - PQclear(executeQueryOrDie(conn_template1, - "UPDATE pg_catalog.pg_database " - "SET datfrozenxid = '%u'", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_database.datfrozenxid */ + PQclear(executeQueryOrDie(conn_template1, + "UPDATE pg_catalog.pg_database " + "SET datfrozenxid = '%u'", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_database.datminmxid */ PQclear(executeQueryOrDie(conn_template1, @@ -942,16 +942,16 @@ set_frozenxids(void) conn = connectToServer(&new_cluster, datname); - /* set pg_class.relfrozenxid */ - PQclear(executeQueryOrDie(conn, - "UPDATE pg_catalog.pg_class " - "SET relfrozenxid = '%u' " - /* only heap, materialized view, and TOAST are vacuumed */ - "WHERE relkind IN (" - CppAsString2(RELKIND_RELATION) ", " - CppAsString2(RELKIND_MATVIEW) ", " - CppAsString2(RELKIND_TOASTVALUE) ")", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_class.relfrozenxid */ + PQclear(executeQueryOrDie(conn, + "UPDATE pg_catalog.pg_class " + "SET relfrozenxid = '%u' " + /* only heap, materialized view, and TOAST are vacuumed */ + "WHERE relkind IN (" + CppAsString2(RELKIND_RELATION) ", " + CppAsString2(RELKIND_MATVIEW) ", " + CppAsString2(RELKIND_TOASTVALUE) ")", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_class.relminmxid */ PQclear(executeQueryOrDie(conn, diff --git a/src/bin/pg_upgrade/relfilenumber.c b/src/bin/pg_upgrade/relfilenumber.c index ec2ff7acb21..6c467bdc8a5 100644 --- a/src/bin/pg_upgrade/relfilenumber.c +++ b/src/bin/pg_upgrade/relfilenumber.c @@ -587,32 +587,32 @@ transfer_relfile(FileNameMap *map, const char *type_suffix) /* Copying files might take some time, so give feedback. */ pg_log(PG_STATUS, "%s", old_file); - switch (user_opts.transfer_mode) - { - case TRANSFER_MODE_CLONE: - pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", - old_file, new_file); - cloneFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", - old_file, new_file); - copyFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY_FILE_RANGE: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", - old_file, new_file); - copyFileByRange(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_LINK: - pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", - old_file, new_file); - linkFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_SWAP: - /* swap mode is handled in its own code path */ - pg_fatal("should never happen"); - break; - } + switch (user_opts.transfer_mode) + { + case TRANSFER_MODE_CLONE: + pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", + old_file, new_file); + cloneFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", + old_file, new_file); + copyFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY_FILE_RANGE: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", + old_file, new_file); + copyFileByRange(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_LINK: + pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", + old_file, new_file); + linkFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_SWAP: + /* swap mode is handled in its own code path */ + pg_fatal("should never happen"); + break; + } } } diff --git a/src/bin/pg_upgrade/t/006_transfer_modes.pl b/src/bin/pg_upgrade/t/006_transfer_modes.pl index 9efa5dc863c..360d05c4b68 100644 --- a/src/bin/pg_upgrade/t/006_transfer_modes.pl +++ b/src/bin/pg_upgrade/t/006_transfer_modes.pl @@ -29,10 +29,8 @@ sub test_mode } $new->init(); - $new->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); - $old->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); + $new->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); + $old->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); # We can only test security labels if both the old and new installations # have dummy_seclabel. @@ -76,15 +74,14 @@ sub test_mode "CREATE TABLE test4 AS SELECT generate_series(400, 502)"); } - $old->safe_psql('postgres', - "CREATE TABLESPACE inplc_tblspc LOCATION ''"); - $old->safe_psql('postgres', - "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); - $old->safe_psql('postgres', - "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" - ); - $old->safe_psql('testdb3', - "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); + $old->safe_psql('postgres', "CREATE TABLESPACE inplc_tblspc LOCATION ''"); + $old->safe_psql('postgres', + "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); + $old->safe_psql('postgres', + "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" + ); + $old->safe_psql('testdb3', + "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); # While we are here, test handling of large objects. $old->safe_psql( @@ -152,12 +149,10 @@ sub test_mode } # Tests for in-place tablespaces. - $result = - $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); - is($result, '104', "test5 data after pg_upgrade $mode"); - $result = - $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); - is($result, '105', "test6 data after pg_upgrade $mode"); + $result = $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); + is($result, '104', "test5 data after pg_upgrade $mode"); + $result = $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); + is($result, '105', "test6 data after pg_upgrade $mode"); # Tests for large objects $result = $new->safe_psql('postgres', "SELECT lo_get(4532)"); diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index 44ef11d980e..c90bf8bbde2 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -6278,23 +6278,22 @@ get_create_object_cmd(EditableObjectType obj_type, Oid oid, * ensure the right view gets replaced. Also, check relation kind * to be sure it's a view. * - * Views may have WITH [LOCAL|CASCADED] - * CHECK OPTION. These are not part of the view definition - * returned by pg_get_viewdef() and so need to be retrieved - * separately. Materialized views may have - * arbitrary storage parameter reloptions. + * Views may have WITH [LOCAL|CASCADED] CHECK OPTION. These are + * not part of the view definition returned by pg_get_viewdef() + * and so need to be retrieved separately. Materialized views may + * have arbitrary storage parameter reloptions. */ printfPQExpBuffer(query, "/* %s */\n", _("Get view's definition and details")); - appendPQExpBuffer(query, - "SELECT nspname, relname, relkind, " - "pg_catalog.pg_get_viewdef(c.oid, true), " - "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " - "FROM pg_catalog.pg_class c " - "LEFT JOIN pg_catalog.pg_namespace n " - "ON c.relnamespace = n.oid WHERE c.oid = %u", - oid); + appendPQExpBuffer(query, + "SELECT nspname, relname, relkind, " + "pg_catalog.pg_get_viewdef(c.oid, true), " + "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " + "FROM pg_catalog.pg_class c " + "LEFT JOIN pg_catalog.pg_namespace n " + "ON c.relnamespace = n.oid WHERE c.oid = %u", + oid); break; } diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index ce99137c613..ac0c55e7aa5 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -387,19 +387,19 @@ describeFunctions(const char *functypes, const char *func_pattern, gettext_noop("stable"), gettext_noop("volatile"), gettext_noop("Volatility")); - appendPQExpBuffer(&buf, - ",\n CASE\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" - " END as \"%s\"", - gettext_noop("restricted"), - gettext_noop("safe"), - gettext_noop("unsafe"), - gettext_noop("Parallel")); + appendPQExpBuffer(&buf, + ",\n CASE\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" + " END as \"%s\"", + gettext_noop("restricted"), + gettext_noop("safe"), + gettext_noop("unsafe"), + gettext_noop("Parallel")); appendPQExpBuffer(&buf, ",\n pg_catalog.pg_get_userbyid(p.proowner) as \"%s\"" ",\n CASE WHEN prosecdef THEN '%s' ELSE '%s' END AS \"%s\"" @@ -599,8 +599,8 @@ describeFunctions(const char *functypes, const char *func_pattern, myopt.title = _("List of functions"); myopt.translate_header = true; - myopt.translate_columns = translate_columns; - myopt.n_translate_columns = lengthof(translate_columns); + myopt.translate_columns = translate_columns; + myopt.n_translate_columns = lengthof(translate_columns); printQuery(res, &myopt, pset.queryFout, false, pset.logfile); @@ -1086,38 +1086,38 @@ permissionsList(const char *pattern, bool showSystem) " ), E'\\n') AS \"%s\"", gettext_noop("Column privileges")); - appendPQExpBuffer(&buf, - ",\n pg_catalog.array_to_string(ARRAY(\n" - " SELECT polname\n" - " || CASE WHEN NOT polpermissive THEN\n" - " E' (RESTRICTIVE)'\n" - " ELSE '' END\n" - " || CASE WHEN polcmd != '*' THEN\n" - " E' (' || polcmd::pg_catalog.text || E'):'\n" - " ELSE E':'\n" - " END\n" - " || CASE WHEN polqual IS NOT NULL THEN\n" - " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" - " ELSE E''\n" - " END\n" - " || CASE WHEN polwithcheck IS NOT NULL THEN\n" - " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" - " ELSE E''\n" - " END" - " || CASE WHEN polroles <> '{0}' THEN\n" - " E'\\n to: ' || pg_catalog.array_to_string(\n" - " ARRAY(\n" - " SELECT rolname\n" - " FROM pg_catalog.pg_roles\n" - " WHERE oid = ANY (polroles)\n" - " ORDER BY 1\n" - " ), E', ')\n" - " ELSE E''\n" - " END\n" - " FROM pg_catalog.pg_policy pol\n" - " WHERE polrelid = c.oid), E'\\n')\n" - " AS \"%s\"", - gettext_noop("Policies")); + appendPQExpBuffer(&buf, + ",\n pg_catalog.array_to_string(ARRAY(\n" + " SELECT polname\n" + " || CASE WHEN NOT polpermissive THEN\n" + " E' (RESTRICTIVE)'\n" + " ELSE '' END\n" + " || CASE WHEN polcmd != '*' THEN\n" + " E' (' || polcmd::pg_catalog.text || E'):'\n" + " ELSE E':'\n" + " END\n" + " || CASE WHEN polqual IS NOT NULL THEN\n" + " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" + " ELSE E''\n" + " END\n" + " || CASE WHEN polwithcheck IS NOT NULL THEN\n" + " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" + " ELSE E''\n" + " END" + " || CASE WHEN polroles <> '{0}' THEN\n" + " E'\\n to: ' || pg_catalog.array_to_string(\n" + " ARRAY(\n" + " SELECT rolname\n" + " FROM pg_catalog.pg_roles\n" + " WHERE oid = ANY (polroles)\n" + " ORDER BY 1\n" + " ), E', ')\n" + " ELSE E''\n" + " END\n" + " FROM pg_catalog.pg_policy pol\n" + " WHERE polrelid = c.oid), E'\\n')\n" + " AS \"%s\"", + gettext_noop("Policies")); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_class c\n" " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n" @@ -1675,27 +1675,27 @@ describeOneTableDetails(const char *schemaname, char *footers[3] = {NULL, NULL, NULL}; printfPQExpBuffer(&buf, "/* %s */\n", _("Get sequence information")); - appendPQExpBuffer(&buf, - "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" - " seqstart AS \"%s\",\n" - " seqmin AS \"%s\",\n" - " seqmax AS \"%s\",\n" - " seqincrement AS \"%s\",\n" - " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" - " seqcache AS \"%s\"\n", - gettext_noop("Type"), - gettext_noop("Start"), - gettext_noop("Minimum"), - gettext_noop("Maximum"), - gettext_noop("Increment"), - gettext_noop("yes"), - gettext_noop("no"), - gettext_noop("Cycles?"), - gettext_noop("Cache")); - appendPQExpBuffer(&buf, - "FROM pg_catalog.pg_sequence\n" - "WHERE seqrelid = '%s';", - oid); + appendPQExpBuffer(&buf, + "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" + " seqstart AS \"%s\",\n" + " seqmin AS \"%s\",\n" + " seqmax AS \"%s\",\n" + " seqincrement AS \"%s\",\n" + " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" + " seqcache AS \"%s\"\n", + gettext_noop("Type"), + gettext_noop("Start"), + gettext_noop("Minimum"), + gettext_noop("Maximum"), + gettext_noop("Increment"), + gettext_noop("yes"), + gettext_noop("no"), + gettext_noop("Cycles?"), + gettext_noop("Cache")); + appendPQExpBuffer(&buf, + "FROM pg_catalog.pg_sequence\n" + "WHERE seqrelid = '%s';", + oid); res = PSQLexec(buf.data); if (!res) @@ -1913,7 +1913,7 @@ describeOneTableDetails(const char *schemaname, appendPQExpBufferStr(&buf, ",\n (SELECT c.collname FROM pg_catalog.pg_collation c, pg_catalog.pg_type t\n" " WHERE c.oid = a.attcollation AND t.oid = a.atttypid AND a.attcollation <> t.typcollation) AS attcollation"); attcoll_col = cols++; - appendPQExpBufferStr(&buf, ",\n a.attidentity"); + appendPQExpBufferStr(&buf, ",\n a.attidentity"); attidentity_col = cols++; if (pset.sversion >= 120000) appendPQExpBufferStr(&buf, ",\n a.attgenerated"); @@ -2326,7 +2326,7 @@ describeOneTableDetails(const char *schemaname, CppAsString2(CONSTRAINT_EXCLUSION) ") AND " "condeferred) AS condeferred,\n"); - appendPQExpBufferStr(&buf, "i.indisreplident,\n"); + appendPQExpBufferStr(&buf, "i.indisreplident,\n"); if (pset.sversion >= 150000) appendPQExpBufferStr(&buf, "i.indnullsnotdistinct,\n"); @@ -2431,7 +2431,7 @@ describeOneTableDetails(const char *schemaname, "pg_catalog.pg_get_indexdef(i.indexrelid, 0, true),\n " "pg_catalog.pg_get_constraintdef(con.oid, true), " "contype, condeferrable, condeferred"); - appendPQExpBufferStr(&buf, ", i.indisreplident"); + appendPQExpBufferStr(&buf, ", i.indisreplident"); appendPQExpBufferStr(&buf, ", c2.reltablespace"); if (pset.sversion >= 180000) appendPQExpBufferStr(&buf, ", con.conperiod"); @@ -2682,81 +2682,80 @@ describeOneTableDetails(const char *schemaname, PQclear(result); /* print any row-level policies */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get row-level policies for this table")); - appendPQExpBufferStr(&buf, "SELECT pol.polname,"); - appendPQExpBufferStr(&buf, - " pol.polpermissive,\n"); - appendPQExpBuffer(&buf, - " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" - " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" - " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" - " CASE pol.polcmd\n" - " WHEN 'r' THEN 'SELECT'\n" - " WHEN 'a' THEN 'INSERT'\n" - " WHEN 'w' THEN 'UPDATE'\n" - " WHEN 'd' THEN 'DELETE'\n" - " END AS cmd\n" - "FROM pg_catalog.pg_policy pol\n" - "WHERE pol.polrelid = '%s' ORDER BY 1;", - oid); + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get row-level policies for this table")); + appendPQExpBufferStr(&buf, "SELECT pol.polname,"); + appendPQExpBufferStr(&buf, + " pol.polpermissive,\n"); + appendPQExpBuffer(&buf, + " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" + " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" + " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" + " CASE pol.polcmd\n" + " WHEN 'r' THEN 'SELECT'\n" + " WHEN 'a' THEN 'INSERT'\n" + " WHEN 'w' THEN 'UPDATE'\n" + " WHEN 'd' THEN 'DELETE'\n" + " END AS cmd\n" + "FROM pg_catalog.pg_policy pol\n" + "WHERE pol.polrelid = '%s' ORDER BY 1;", + oid); - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - /* - * Handle cases where RLS is enabled and there are policies, or - * there aren't policies, or RLS isn't enabled but there are - * policies - */ - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies:")); + /* + * Handle cases where RLS is enabled and there are policies, or there + * aren't policies, or RLS isn't enabled but there are policies + */ + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies:")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled):")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled):")); - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); - if (!tableinfo.rowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (row security disabled):")); + if (!tableinfo.rowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (row security disabled):")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " POLICY \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " POLICY \"%s\"", + PQgetvalue(result, i, 0)); - if (*(PQgetvalue(result, i, 1)) == 'f') - appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); + if (*(PQgetvalue(result, i, 1)) == 'f') + appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); - if (!PQgetisnull(result, i, 5)) - appendPQExpBuffer(&buf, " FOR %s", - PQgetvalue(result, i, 5)); + if (!PQgetisnull(result, i, 5)) + appendPQExpBuffer(&buf, " FOR %s", + PQgetvalue(result, i, 5)); - if (!PQgetisnull(result, i, 2)) - { - appendPQExpBuffer(&buf, "\n TO %s", - PQgetvalue(result, i, 2)); - } + if (!PQgetisnull(result, i, 2)) + { + appendPQExpBuffer(&buf, "\n TO %s", + PQgetvalue(result, i, 2)); + } - if (!PQgetisnull(result, i, 3)) - appendPQExpBuffer(&buf, "\n USING (%s)", - PQgetvalue(result, i, 3)); + if (!PQgetisnull(result, i, 3)) + appendPQExpBuffer(&buf, "\n USING (%s)", + PQgetvalue(result, i, 3)); - if (!PQgetisnull(result, i, 4)) - appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", - PQgetvalue(result, i, 4)); + if (!PQgetisnull(result, i, 4)) + appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", + PQgetvalue(result, i, 4)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* print any extended statistics */ if (pset.sversion >= 140000) @@ -3025,115 +3024,115 @@ describeOneTableDetails(const char *schemaname, } /* print any publications */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get publications that publish this table")); - if (pset.sversion >= 150000) + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get publications that publish this table")); + if (pset.sversion >= 150000) + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" + " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" + "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" + "UNION\n" + "SELECT pubname\n" + " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" + " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" + " (SELECT pg_catalog.string_agg(attname, ', ')\n" + " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" + " pg_catalog.pg_attribute\n" + " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" + " ELSE NULL END) " + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" + "WHERE pr.prrelid = '%s'\n", + oid, oid, oid); + + if (pset.sversion >= 190000) { + /* + * Skip entries where this relation appears in the + * publication's EXCEPT list. + */ appendPQExpBuffer(&buf, + " AND NOT pr.prexcept\n" + "UNION\n" "SELECT pubname\n" " , NULL\n" " , NULL\n" "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" - " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" - "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" - "UNION\n" - "SELECT pubname\n" - " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" - " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" - " (SELECT pg_catalog.string_agg(attname, ', ')\n" - " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" - " pg_catalog.pg_attribute\n" - " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" - " ELSE NULL END) " - "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" - "WHERE pr.prrelid = '%s'\n", + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + " AND NOT EXISTS (\n" + " SELECT 1\n" + " FROM pg_catalog.pg_publication_rel pr\n" + " WHERE pr.prpubid = p.oid AND\n" + " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" + "ORDER BY 1;", oid, oid, oid); - - if (pset.sversion >= 190000) - { - /* - * Skip entries where this relation appears in the - * publication's EXCEPT list. - */ - appendPQExpBuffer(&buf, - " AND NOT pr.prexcept\n" - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - " AND NOT EXISTS (\n" - " SELECT 1\n" - " FROM pg_catalog.pg_publication_rel pr\n" - " WHERE pr.prpubid = p.oid AND\n" - " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" - "ORDER BY 1;", - oid, oid, oid); - } - else - { - appendPQExpBuffer(&buf, - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - "ORDER BY 1;", - oid); - } } else { appendPQExpBuffer(&buf, + "UNION\n" "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - "WHERE pr.prrelid = '%s'\n" - "UNION ALL\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" + " , NULL\n" + " , NULL\n" "FROM pg_catalog.pg_publication p\n" "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" "ORDER BY 1;", - oid, oid); + oid); } + } + else + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + "WHERE pr.prrelid = '%s'\n" + "UNION ALL\n" + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + "ORDER BY 1;", + oid, oid); + } - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - if (tuples > 0) - printTableAddFooter(&cont, _("Included in publications:")); + if (tuples > 0) + printTableAddFooter(&cont, _("Included in publications:")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " \"%s\"", + PQgetvalue(result, i, 0)); - /* column list (if any) */ - if (!PQgetisnull(result, i, 2)) - appendPQExpBuffer(&buf, " (%s)", - PQgetvalue(result, i, 2)); + /* column list (if any) */ + if (!PQgetisnull(result, i, 2)) + appendPQExpBuffer(&buf, " (%s)", + PQgetvalue(result, i, 2)); - /* row filter (if any) */ - if (!PQgetisnull(result, i, 1)) - appendPQExpBuffer(&buf, " WHERE %s", - PQgetvalue(result, i, 1)); + /* row filter (if any) */ + if (!PQgetisnull(result, i, 1)) + appendPQExpBuffer(&buf, " WHERE %s", + PQgetvalue(result, i, 1)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* Print publications where the table is in the EXCEPT clause */ if (pset.sversion >= 190000) @@ -3805,7 +3804,7 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) ncols++; } appendPQExpBufferStr(&buf, "\n, r.rolreplication"); - appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); + appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_roles r\n"); @@ -3860,8 +3859,8 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) if (strcmp(PQgetvalue(res, i, (verbose ? 9 : 8)), "t") == 0) add_role_attribute(&buf, _("Replication")); - if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) - add_role_attribute(&buf, _("Bypass RLS")); + if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) + add_role_attribute(&buf, _("Bypass RLS")); conns = atoi(PQgetvalue(res, i, 6)); if (conns >= 0) @@ -5155,14 +5154,14 @@ listCollations(const char *pattern, bool verbose, bool showSystem) gettext_noop("Schema"), gettext_noop("Name")); - appendPQExpBuffer(&buf, - " CASE c.collprovider " - "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " - "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " - "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " - "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " - "END AS \"%s\",\n", - gettext_noop("Provider")); + appendPQExpBuffer(&buf, + " CASE c.collprovider " + "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " + "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " + "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " + "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " + "END AS \"%s\",\n", + gettext_noop("Provider")); appendPQExpBuffer(&buf, " c.collcollate AS \"%s\",\n" -- 2.50.1 (Apple Git-155) --aHl3HfeiUuO3zeNC-- ^ permalink raw reply [nested|flat] 59+ messages in thread
* [PATCH v6 4/4] run pgindent and pgperltidy @ 2026-06-30 18:24 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 59+ messages in thread From: Nathan Bossart @ 2026-06-30 18:24 UTC (permalink / raw) --- src/bin/pg_dump/pg_dump.c | 464 ++++++++++----------- src/bin/pg_dump/pg_dumpall.c | 30 +- src/bin/pg_upgrade/check.c | 16 +- src/bin/pg_upgrade/controldata.c | 2 +- src/bin/pg_upgrade/exec.c | 8 +- src/bin/pg_upgrade/multixact_rewrite.c | 80 ++-- src/bin/pg_upgrade/pg_upgrade.c | 34 +- src/bin/pg_upgrade/relfilenumber.c | 54 +-- src/bin/pg_upgrade/t/006_transfer_modes.pl | 33 +- src/bin/psql/command.c | 29 +- src/bin/psql/describe.c | 461 ++++++++++---------- 11 files changed, 601 insertions(+), 610 deletions(-) diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 65bd15ebfd2..5673268b467 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -1491,8 +1491,8 @@ setup_connection(Archive *AH, const char *dumpencoding, * Disable timeouts if supported. */ ExecuteSqlStatement(AH, "SET statement_timeout = 0"); - ExecuteSqlStatement(AH, "SET lock_timeout = 0"); - ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); + ExecuteSqlStatement(AH, "SET lock_timeout = 0"); + ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); if (AH->remoteVersion >= 170000) ExecuteSqlStatement(AH, "SET transaction_timeout = 0"); @@ -1505,10 +1505,10 @@ setup_connection(Archive *AH, const char *dumpencoding, /* * Adjust row-security mode, if supported. */ - if (dopt->enable_row_security) - ExecuteSqlStatement(AH, "SET row_security = on"); - else - ExecuteSqlStatement(AH, "SET row_security = off"); + if (dopt->enable_row_security) + ExecuteSqlStatement(AH, "SET row_security = on"); + else + ExecuteSqlStatement(AH, "SET row_security = off"); /* * For security reasons, we restrict the expansion of non-system views and @@ -1933,10 +1933,9 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) addObjectDependency(dobj, ext->dobj.dumpId); /* - * Mark the member object to have any non-initial ACLs - * dumped. (Any initial ACLs will be removed later, using data from - * pg_init_privs, so that we'll dump only the delta from the extension's - * initial setup.) + * Mark the member object to have any non-initial ACLs dumped. (Any + * initial ACLs will be removed later, using data from pg_init_privs, so + * that we'll dump only the delta from the extension's initial setup.) * * In binary upgrades, we still dump all components of the members * individually, since the idea is to exactly reproduce the database @@ -1953,7 +1952,7 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) if (fout->dopt->binary_upgrade) dobj->dump = ext->dobj.dump; else - dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); + dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); return true; } @@ -1987,9 +1986,9 @@ selectDumpableNamespace(NamespaceInfo *nsinfo, Archive *fout) else if (strcmp(nsinfo->dobj.name, "pg_catalog") == 0) { /* - * We dump out any ACLs defined in pg_catalog, if - * they are interesting (and not the original ACLs which were set at - * initdb time, see pg_init_privs). + * We dump out any ACLs defined in pg_catalog, if they are interesting + * (and not the original ACLs which were set at initdb time, see + * pg_init_privs). */ nsinfo->dobj.dump_contains = nsinfo->dobj.dump = DUMP_COMPONENT_ACL; } @@ -3296,7 +3295,7 @@ dumpDatabase(Archive *fout) "datcollate, datctype, datfrozenxid, " "datacl, acldefault('d', datdba) AS acldefault, " "datistemplate, datconnlimit, "); - appendPQExpBufferStr(dbQry, "datminmxid, "); + appendPQExpBufferStr(dbQry, "datminmxid, "); if (fout->remoteVersion >= 170000) appendPQExpBufferStr(dbQry, "datlocprovider, datlocale, datcollversion, "); else if (fout->remoteVersion >= 150000) @@ -3638,11 +3637,11 @@ dumpDatabase(Archive *fout) ii_oid, ii_relminmxid; - appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" - "FROM pg_catalog.pg_class\n" - "WHERE oid IN (%u, %u, %u, %u);\n", - LargeObjectRelationId, LargeObjectLOidPNIndexId, - LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); + appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" + "FROM pg_catalog.pg_class\n" + "WHERE oid IN (%u, %u, %u, %u);\n", + LargeObjectRelationId, LargeObjectLOidPNIndexId, + LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); lo_res = ExecuteSqlQuery(fout, loFrozenQry->data, PGRES_TUPLES_OK); @@ -4274,7 +4273,7 @@ getPolicies(Archive *fout, TableInfo tblinfo[], int numTables) printfPQExpBuffer(query, "SELECT pol.oid, pol.tableoid, pol.polrelid, pol.polname, pol.polcmd, "); - appendPQExpBufferStr(query, "pol.polpermissive, "); + appendPQExpBufferStr(query, "pol.polpermissive, "); appendPQExpBuffer(query, "CASE WHEN pol.polroles = '{0}' THEN NULL ELSE " " pg_catalog.array_to_string(ARRAY(SELECT pg_catalog.quote_ident(rolname) from pg_catalog.pg_roles WHERE oid = ANY(pol.polroles)), ', ') END AS polroles, " @@ -6633,9 +6632,9 @@ getAccessMethods(Archive *fout) * Select all access methods from pg_am table. */ appendPQExpBufferStr(query, "SELECT tableoid, oid, amname, "); - appendPQExpBufferStr(query, - "amtype, " - "amhandler::pg_catalog.regproc AS amhandler "); + appendPQExpBufferStr(query, + "amtype, " + "amhandler::pg_catalog.regproc AS amhandler "); appendPQExpBufferStr(query, "FROM pg_am"); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6827,35 +6826,35 @@ getAggregates(Archive *fout) * Find all interesting aggregates. See comment in getFuncs() for the * rationale behind the filtering logic. */ - agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" - : "p.proisagg"); + agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" + : "p.proisagg"); - appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " - "p.proname AS aggname, " - "p.pronamespace AS aggnamespace, " - "p.pronargs, p.proargtypes, " - "p.proowner, " - "p.proacl AS aggacl, " - "acldefault('f', p.proowner) AS acldefault " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s AND (" - "p.pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog') OR " - "p.proacl IS DISTINCT FROM pip.initprivs", - agg_check); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - " OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); - appendPQExpBufferChar(query, ')'); + appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " + "p.proname AS aggname, " + "p.pronamespace AS aggnamespace, " + "p.pronargs, p.proargtypes, " + "p.proowner, " + "p.proacl AS aggacl, " + "acldefault('f', p.proowner) AS acldefault " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s AND (" + "p.pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog') OR " + "p.proacl IS DISTINCT FROM pip.initprivs", + agg_check); + if (dopt->binary_upgrade) + appendPQExpBufferStr(query, + " OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6957,53 +6956,53 @@ getFuncs(Archive *fout) * include them, since we want to dump extension members individually in * that mode. Also, if they are used by casts or transforms then we need * to gather the information about them, though they won't be dumped if - * they are built-in. Also, include functions in - * pg_catalog if they have an ACL different from what's shown in - * pg_init_privs (so we have to join to pg_init_privs; annoying). + * they are built-in. Also, include functions in pg_catalog if they have + * an ACL different from what's shown in pg_init_privs (so we have to join + * to pg_init_privs; annoying). */ - not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" - : "NOT p.proisagg"); + not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" + : "NOT p.proisagg"); - appendPQExpBuffer(query, - "SELECT p.tableoid, p.oid, p.proname, p.prolang, " - "p.pronargs, p.proargtypes, p.prorettype, " - "p.proacl, " - "acldefault('f', p.proowner) AS acldefault, " - "p.pronamespace, " - "p.proowner " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s" - "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " - "WHERE classid = 'pg_proc'::regclass AND " - "objid = p.oid AND deptype = 'i')" - "\n AND (" - "\n pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog')" - "\n OR EXISTS (SELECT 1 FROM pg_cast" - "\n WHERE pg_cast.oid > %u " - "\n AND p.oid = pg_cast.castfunc)" - "\n OR EXISTS (SELECT 1 FROM pg_transform" - "\n WHERE pg_transform.oid > %u AND " - "\n (p.oid = pg_transform.trffromsql" - "\n OR p.oid = pg_transform.trftosql))", - not_agg_check, - g_last_builtin_oid, - g_last_builtin_oid); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); + appendPQExpBuffer(query, + "SELECT p.tableoid, p.oid, p.proname, p.prolang, " + "p.pronargs, p.proargtypes, p.prorettype, " + "p.proacl, " + "acldefault('f', p.proowner) AS acldefault, " + "p.pronamespace, " + "p.proowner " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s" + "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " + "WHERE classid = 'pg_proc'::regclass AND " + "objid = p.oid AND deptype = 'i')" + "\n AND (" + "\n pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog')" + "\n OR EXISTS (SELECT 1 FROM pg_cast" + "\n WHERE pg_cast.oid > %u " + "\n AND p.oid = pg_cast.castfunc)" + "\n OR EXISTS (SELECT 1 FROM pg_transform" + "\n WHERE pg_transform.oid > %u AND " + "\n (p.oid = pg_transform.trffromsql" + "\n OR p.oid = pg_transform.trftosql))", + not_agg_check, + g_last_builtin_oid, + g_last_builtin_oid); + if (dopt->binary_upgrade) appendPQExpBufferStr(query, - "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); - appendPQExpBufferChar(query, ')'); + "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferStr(query, + "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -7252,31 +7251,31 @@ getTables(Archive *fout, int *numTables) appendPQExpBufferStr(query, "c.relhasoids, "); - appendPQExpBufferStr(query, - "c.relispopulated, "); + appendPQExpBufferStr(query, + "c.relispopulated, "); - appendPQExpBufferStr(query, - "c.relreplident, "); + appendPQExpBufferStr(query, + "c.relreplident, "); - appendPQExpBufferStr(query, - "c.relrowsecurity, c.relforcerowsecurity, "); + appendPQExpBufferStr(query, + "c.relrowsecurity, c.relforcerowsecurity, "); - appendPQExpBufferStr(query, - "c.relminmxid, tc.relminmxid AS tminmxid, "); + appendPQExpBufferStr(query, + "c.relminmxid, tc.relminmxid AS tminmxid, "); - appendPQExpBufferStr(query, - "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); + appendPQExpBufferStr(query, + "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); - appendPQExpBufferStr(query, - "am.amname, "); + appendPQExpBufferStr(query, + "am.amname, "); - appendPQExpBufferStr(query, - "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); + appendPQExpBufferStr(query, + "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); - appendPQExpBufferStr(query, - "c.relispartition AS ispartition "); + appendPQExpBufferStr(query, + "c.relispartition AS ispartition "); /* * Left join to pg_depend to pick up dependency info linking sequences to @@ -7296,8 +7295,8 @@ getTables(Archive *fout, int *numTables) /* * Left join to pg_am to pick up the amname. */ - appendPQExpBufferStr(query, - "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); + appendPQExpBufferStr(query, + "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); /* * We purposefully ignore toast OIDs for partitioned tables; the reason is @@ -7868,8 +7867,8 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables) "t.reloptions AS indreloptions, "); - appendPQExpBufferStr(query, - "i.indisreplident, "); + appendPQExpBufferStr(query, + "i.indisreplident, "); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -9313,8 +9312,8 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables) appendPQExpBufferStr(q, "'' AS attcompression,\n"); - appendPQExpBufferStr(q, - "a.attidentity,\n"); + appendPQExpBufferStr(q, + "a.attidentity,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(q, @@ -10717,73 +10716,73 @@ getAdditionalACLs(Archive *fout) PQclear(res); /* Fetch initial-privileges data */ - printfPQExpBuffer(query, - "SELECT objoid, classoid, objsubid, privtype, initprivs " - "FROM pg_init_privs"); + printfPQExpBuffer(query, + "SELECT objoid, classoid, objsubid, privtype, initprivs " + "FROM pg_init_privs"); - res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); + res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); - ntups = PQntuples(res); - for (i = 0; i < ntups; i++) - { - Oid objoid = atooid(PQgetvalue(res, i, 0)); - Oid classoid = atooid(PQgetvalue(res, i, 1)); - int objsubid = atoi(PQgetvalue(res, i, 2)); - char privtype = *(PQgetvalue(res, i, 3)); - char *initprivs = PQgetvalue(res, i, 4); - CatalogId objId; - DumpableObject *dobj; + ntups = PQntuples(res); + for (i = 0; i < ntups; i++) + { + Oid objoid = atooid(PQgetvalue(res, i, 0)); + Oid classoid = atooid(PQgetvalue(res, i, 1)); + int objsubid = atoi(PQgetvalue(res, i, 2)); + char privtype = *(PQgetvalue(res, i, 3)); + char *initprivs = PQgetvalue(res, i, 4); + CatalogId objId; + DumpableObject *dobj; - objId.tableoid = classoid; - objId.oid = objoid; - dobj = findObjectByCatalogId(objId); - /* OK to ignore entries we haven't got a DumpableObject for */ - if (dobj) + objId.tableoid = classoid; + objId.oid = objoid; + dobj = findObjectByCatalogId(objId); + /* OK to ignore entries we haven't got a DumpableObject for */ + if (dobj) + { + /* Cope with sub-object initprivs */ + if (objsubid != 0) { - /* Cope with sub-object initprivs */ - if (objsubid != 0) - { - if (dobj->objType == DO_TABLE) - { - /* For a column initprivs, set the table's ACL flags */ - dobj->components |= DUMP_COMPONENT_ACL; - ((TableInfo *) dobj)->hascolumnACLs = true; - } - else - pg_log_warning("unsupported pg_init_privs entry: %u %u %d", - classoid, objoid, objsubid); - continue; - } - - /* - * We ignore any pg_init_privs.initprivs entry for the public - * schema, as explained in getNamespaces(). - */ - if (dobj->objType == DO_NAMESPACE && - strcmp(dobj->name, "public") == 0) - continue; - - /* Else it had better be of a type we think has ACLs */ - if (dobj->objType == DO_NAMESPACE || - dobj->objType == DO_TYPE || - dobj->objType == DO_FUNC || - dobj->objType == DO_AGG || - dobj->objType == DO_TABLE || - dobj->objType == DO_PROCLANG || - dobj->objType == DO_FDW || - dobj->objType == DO_FOREIGN_SERVER) + if (dobj->objType == DO_TABLE) { - DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; - - daobj->dacl.privtype = privtype; - daobj->dacl.initprivs = pstrdup(initprivs); + /* For a column initprivs, set the table's ACL flags */ + dobj->components |= DUMP_COMPONENT_ACL; + ((TableInfo *) dobj)->hascolumnACLs = true; } else pg_log_warning("unsupported pg_init_privs entry: %u %u %d", classoid, objoid, objsubid); + continue; + } + + /* + * We ignore any pg_init_privs.initprivs entry for the public + * schema, as explained in getNamespaces(). + */ + if (dobj->objType == DO_NAMESPACE && + strcmp(dobj->name, "public") == 0) + continue; + + /* Else it had better be of a type we think has ACLs */ + if (dobj->objType == DO_NAMESPACE || + dobj->objType == DO_TYPE || + dobj->objType == DO_FUNC || + dobj->objType == DO_AGG || + dobj->objType == DO_TABLE || + dobj->objType == DO_PROCLANG || + dobj->objType == DO_FDW || + dobj->objType == DO_FOREIGN_SERVER) + { + DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; + + daobj->dacl.privtype = privtype; + daobj->dacl.initprivs = pstrdup(initprivs); } + else + pg_log_warning("unsupported pg_init_privs entry: %u %u %d", + classoid, objoid, objsubid); } - PQclear(res); + } + PQclear(res); destroyPQExpBuffer(query); } @@ -11128,8 +11127,8 @@ dumpRelationStats_dumper(Archive *fout, const void *userArg, const TocEntry *te) * The results must be in the order of the relations supplied in the * parameters to ensure we remain in sync as we walk through the TOC. * - * For versions before 19, the redundant filter clause on s.tablename = - * ANY(...) seems sufficient to convince the planner to use + * For versions before 19, the redundant filter clause on s.tablename + * = ANY(...) seems sufficient to convince the planner to use * pg_class_relname_nsp_index, which avoids a full scan of pg_stats. * In newer versions, pg_stats returns the table OIDs, eliminating the * need for that hack. @@ -13469,11 +13468,11 @@ dumpFunc(Archive *fout, const FuncInfo *finfo) "pg_catalog.pg_get_function_result(p.oid) AS funcresult,\n" "proleakproof,\n"); - appendPQExpBufferStr(query, - "array_to_string(protrftypes, ' ') AS protrftypes,\n"); + appendPQExpBufferStr(query, + "array_to_string(protrftypes, ' ') AS protrftypes,\n"); - appendPQExpBufferStr(query, - "proparallel,\n"); + appendPQExpBufferStr(query, + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -14963,9 +14962,9 @@ dumpCollation(Archive *fout, const CollInfo *collinfo) /* Get collation-specific details */ appendPQExpBufferStr(query, "SELECT "); - appendPQExpBufferStr(query, - "collprovider, " - "collversion, "); + appendPQExpBufferStr(query, + "collprovider, " + "collversion, "); if (fout->remoteVersion >= 120000) appendPQExpBufferStr(query, @@ -15372,23 +15371,23 @@ dumpAgg(Archive *fout, const AggInfo *agginfo) "pg_catalog.pg_get_function_arguments(p.oid) AS funcargs,\n" "pg_catalog.pg_get_function_identity_arguments(p.oid) AS funciargs,\n"); - appendPQExpBufferStr(query, - "aggkind,\n" - "aggmtransfn,\n" - "aggminvtransfn,\n" - "aggmfinalfn,\n" - "aggmtranstype::pg_catalog.regtype,\n" - "aggfinalextra,\n" - "aggmfinalextra,\n" - "aggtransspace,\n" - "aggmtransspace,\n" - "aggminitval,\n"); + appendPQExpBufferStr(query, + "aggkind,\n" + "aggmtransfn,\n" + "aggminvtransfn,\n" + "aggmfinalfn,\n" + "aggmtranstype::pg_catalog.regtype,\n" + "aggfinalextra,\n" + "aggmfinalextra,\n" + "aggtransspace,\n" + "aggmtransspace,\n" + "aggminitval,\n"); - appendPQExpBufferStr(query, - "aggcombinefn,\n" - "aggserialfn,\n" - "aggdeserialfn,\n" - "proparallel,\n"); + appendPQExpBufferStr(query, + "aggcombinefn,\n" + "aggserialfn,\n" + "aggdeserialfn,\n" + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -16848,30 +16847,30 @@ dumpTable(Archive *fout, const TableInfo *tbinfo) appendPQExpBufferStr(query, "PREPARE getColumnACLs(pg_catalog.oid) AS\n"); - /* - * In principle we should call acldefault('c', relowner) to - * get the default ACL for a column. However, we don't - * currently store the numeric OID of the relowner in - * TableInfo. We could convert the owner name using regrole, - * but that creates a risk of failure due to concurrent role - * renames. Given that the default ACL for columns is empty - * and is likely to stay that way, it's not worth extra cycles - * and risk to avoid hard-wiring that knowledge here. - */ - appendPQExpBufferStr(query, - "SELECT at.attname, " - "at.attacl, " - "'{}' AS acldefault, " - "pip.privtype, pip.initprivs " - "FROM pg_catalog.pg_attribute at " - "LEFT JOIN pg_catalog.pg_init_privs pip ON " - "(at.attrelid = pip.objoid " - "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " - "AND at.attnum = pip.objsubid) " - "WHERE at.attrelid = $1 AND " - "NOT at.attisdropped " - "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " - "ORDER BY at.attnum"); + /* + * In principle we should call acldefault('c', relowner) to get + * the default ACL for a column. However, we don't currently + * store the numeric OID of the relowner in TableInfo. We could + * convert the owner name using regrole, but that creates a risk + * of failure due to concurrent role renames. Given that the + * default ACL for columns is empty and is likely to stay that + * way, it's not worth extra cycles and risk to avoid hard-wiring + * that knowledge here. + */ + appendPQExpBufferStr(query, + "SELECT at.attname, " + "at.attacl, " + "'{}' AS acldefault, " + "pip.privtype, pip.initprivs " + "FROM pg_catalog.pg_attribute at " + "LEFT JOIN pg_catalog.pg_init_privs pip ON " + "(at.attrelid = pip.objoid " + "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " + "AND at.attnum = pip.objsubid) " + "WHERE at.attrelid = $1 AND " + "NOT at.attisdropped " + "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " + "ORDER BY at.attnum"); ExecuteSqlStatement(fout, query->data); @@ -19165,7 +19164,7 @@ collectSequences(Archive *fout) * pg_get_sequence_data(), but we only do so for non-schema-only dumps. */ if (fout->remoteVersion < 180000 || - (!fout->dopt->dumpData && !fout->dopt->sequence_data)) + (!fout->dopt->dumpData && !fout->dopt->sequence_data)) query = "SELECT seqrelid, format_type(seqtypid, NULL), " "seqstart, seqincrement, " "seqmax, seqmin, " @@ -19227,15 +19226,14 @@ dumpSequence(Archive *fout, const TableInfo *tbinfo) qseqname = pg_strdup(fmtId(tbinfo->dobj.name)); /* - * The sequence information is gathered in a sorted - * table before any calls to dumpSequence(). See collectSequences() for - * more information. + * The sequence information is gathered in a sorted table before any calls + * to dumpSequence(). See collectSequences() for more information. */ - Assert(sequences); + Assert(sequences); - key.oid = tbinfo->dobj.catId.oid; - seq = bsearch(&key, sequences, nsequences, - sizeof(SequenceItem), SequenceItemCmp); + key.oid = tbinfo->dobj.catId.oid; + seq = bsearch(&key, sequences, nsequences, + sizeof(SequenceItem), SequenceItemCmp); /* Calculate default limits for a sequence of this type */ is_ascending = (seq->incby >= 0); diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c index e68937c9934..afcd9a218d8 100644 --- a/src/bin/pg_dump/pg_dumpall.c +++ b/src/bin/pg_dump/pg_dumpall.c @@ -785,11 +785,11 @@ dropRoles(PGconn *conn) int i_rolname; int i; - printfPQExpBuffer(buf, - "SELECT rolname " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 1", role_catalog); + printfPQExpBuffer(buf, + "SELECT rolname " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 1", role_catalog); res = executeQuery(conn, buf->data); @@ -843,16 +843,16 @@ dumpRoles(PGconn *conn) * Notes: rolconfig is dumped later, and pg_authid must be used for * extracting rolcomment regardless of role_catalog. */ - printfPQExpBuffer(buf, - "SELECT oid, rolname, rolsuper, rolinherit, " - "rolcreaterole, rolcreatedb, " - "rolcanlogin, rolconnlimit, rolpassword, " - "rolvaliduntil, rolreplication, rolbypassrls, " - "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " - "rolname = current_user AS is_current_user " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 2", role_catalog); + printfPQExpBuffer(buf, + "SELECT oid, rolname, rolsuper, rolinherit, " + "rolcreaterole, rolcreatedb, " + "rolcanlogin, rolconnlimit, rolpassword, " + "rolvaliduntil, rolreplication, rolbypassrls, " + "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " + "rolname = current_user AS is_current_user " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 2", role_catalog); res = executeQuery(conn, buf->data); diff --git a/src/bin/pg_upgrade/check.c b/src/bin/pg_upgrade/check.c index 786c1474829..f725f5ee3e2 100644 --- a/src/bin/pg_upgrade/check.c +++ b/src/bin/pg_upgrade/check.c @@ -1475,15 +1475,15 @@ check_for_incompatible_polymorphics(ClusterInfo *cluster) ", 'array_cat(anyarray,anyarray)'" ", 'array_prepend(anyelement,anyarray)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_remove(anyarray,anyelement)'" - ", 'array_replace(anyarray,anyelement,anyelement)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_remove(anyarray,anyelement)'" + ", 'array_replace(anyarray,anyelement,anyelement)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_position(anyarray,anyelement)'" - ", 'array_position(anyarray,anyelement,integer)'" - ", 'array_positions(anyarray,anyelement)'" - ", 'width_bucket(anyelement,anyarray)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_position(anyarray,anyelement)'" + ", 'array_position(anyarray,anyelement,integer)'" + ", 'array_positions(anyarray,anyelement)'" + ", 'width_bucket(anyelement,anyarray)'"); /* * The query below hardcodes FirstNormalObjectId as 16384 rather than diff --git a/src/bin/pg_upgrade/controldata.c b/src/bin/pg_upgrade/controldata.c index 8f81c9e9582..02ea02df60f 100644 --- a/src/bin/pg_upgrade/controldata.c +++ b/src/bin/pg_upgrade/controldata.c @@ -228,7 +228,7 @@ get_control_data(ClusterInfo *cluster) p++; /* remove ':' char */ cluster->controldata.chkpnt_nxtepoch = str2uint(p); - p = strchr(p, ':'); + p = strchr(p, ':'); if (p == NULL || strlen(p) <= 1) pg_fatal("%d: controldata retrieval problem", __LINE__); diff --git a/src/bin/pg_upgrade/exec.c b/src/bin/pg_upgrade/exec.c index 44355feea30..a1bdbf373e3 100644 --- a/src/bin/pg_upgrade/exec.c +++ b/src/bin/pg_upgrade/exec.c @@ -55,7 +55,7 @@ get_bin_version(ClusterInfo *cluster) if (sscanf(cmd_output, "%*s %*s %d.%d", &v1, &v2) < 1) pg_fatal("could not get pg_ctl version output from %s", cmd); - cluster->bin_version = v1 * 10000; + cluster->bin_version = v1 * 10000; } @@ -344,8 +344,8 @@ check_data_dir(ClusterInfo *cluster) check_single_dir(pg_data, "pg_subtrans"); check_single_dir(pg_data, PG_TBLSPC_DIR); check_single_dir(pg_data, "pg_twophase"); - check_single_dir(pg_data, "pg_wal"); - check_single_dir(pg_data, "pg_xact"); + check_single_dir(pg_data, "pg_wal"); + check_single_dir(pg_data, "pg_xact"); } @@ -385,7 +385,7 @@ check_bin_dir(ClusterInfo *cluster, bool check_versions) */ get_bin_version(cluster); - check_exec(cluster->bindir, "pg_resetwal", check_versions); + check_exec(cluster->bindir, "pg_resetwal", check_versions); if (cluster == &new_cluster) { diff --git a/src/bin/pg_upgrade/multixact_rewrite.c b/src/bin/pg_upgrade/multixact_rewrite.c index c45b3183684..c7a1416494d 100644 --- a/src/bin/pg_upgrade/multixact_rewrite.c +++ b/src/bin/pg_upgrade/multixact_rewrite.c @@ -61,52 +61,52 @@ rewrite_multixacts(MultiXactId from_multi, MultiXactId to_multi) * Convert old multixids, if needed, by reading them one-by-one from the * old cluster. */ - old_reader = AllocOldMultiXactRead(old_cluster.pgdata, - old_cluster.controldata.chkpnt_nxtmulti, - old_cluster.controldata.chkpnt_nxtmxoff); + old_reader = AllocOldMultiXactRead(old_cluster.pgdata, + old_cluster.controldata.chkpnt_nxtmulti, + old_cluster.controldata.chkpnt_nxtmxoff); - for (MultiXactId multi = from_multi; multi != to_multi;) - { - MultiXactMember member; - bool multixid_valid; - - /* - * Read this multixid's members. - * - * Locking-only XIDs that may be part of multi-xids don't matter - * after upgrade, as there can be no transactions running across - * upgrade. So as a small optimization, we only read one member - * from each multixid: the one updating one, or if there was no - * update, arbitrarily the first locking xid. - */ - multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); + for (MultiXactId multi = from_multi; multi != to_multi;) + { + MultiXactMember member; + bool multixid_valid; - /* - * Write the new offset to pg_multixact/offsets. - * - * Even if this multixid is invalid, we still need to write its - * offset if the *previous* multixid was valid. That's because - * when reading a multixid, the number of members is calculated - * from the difference between the two offsets. - */ - RecordMultiXactOffset(offsets_writer, multi, - (multixid_valid || prev_multixid_valid) ? next_offset : 0); + /* + * Read this multixid's members. + * + * Locking-only XIDs that may be part of multi-xids don't matter after + * upgrade, as there can be no transactions running across upgrade. So + * as a small optimization, we only read one member from each + * multixid: the one updating one, or if there was no update, + * arbitrarily the first locking xid. + */ + multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); - /* Write the members */ - if (multixid_valid) - { - RecordMultiXactMembers(members_writer, next_offset, 1, &member); - next_offset += 1; - } + /* + * Write the new offset to pg_multixact/offsets. + * + * Even if this multixid is invalid, we still need to write its offset + * if the *previous* multixid was valid. That's because when reading + * a multixid, the number of members is calculated from the difference + * between the two offsets. + */ + RecordMultiXactOffset(offsets_writer, multi, + (multixid_valid || prev_multixid_valid) ? next_offset : 0); - /* Advance to next multixid, handling wraparound */ - multi++; - if (multi < FirstMultiXactId) - multi = FirstMultiXactId; - prev_multixid_valid = multixid_valid; + /* Write the members */ + if (multixid_valid) + { + RecordMultiXactMembers(members_writer, next_offset, 1, &member); + next_offset += 1; } - FreeOldMultiXactReader(old_reader); + /* Advance to next multixid, handling wraparound */ + multi++; + if (multi < FirstMultiXactId) + multi = FirstMultiXactId; + prev_multixid_valid = multixid_valid; + } + + FreeOldMultiXactReader(old_reader); /* Write the final 'next' offset to the last SLRU page */ RecordMultiXactOffset(offsets_writer, to_multi, diff --git a/src/bin/pg_upgrade/pg_upgrade.c b/src/bin/pg_upgrade/pg_upgrade.c index c6af9035665..7366fd4627c 100644 --- a/src/bin/pg_upgrade/pg_upgrade.c +++ b/src/bin/pg_upgrade/pg_upgrade.c @@ -833,7 +833,7 @@ copy_xact_xlog_xid(void) * Determine the range of multixacts to convert. */ nxtmulti = old_cluster.controldata.chkpnt_nxtmulti; - oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; + oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; /* handle wraparound */ if (nxtmulti < FirstMultiXactId) nxtmulti = FirstMultiXactId; @@ -898,15 +898,15 @@ set_frozenxids(void) int i_datname; int i_datallowconn; - prep_status("Setting frozenxid and minmxid counters in new cluster"); + prep_status("Setting frozenxid and minmxid counters in new cluster"); conn_template1 = connectToServer(&new_cluster, "template1"); - /* set pg_database.datfrozenxid */ - PQclear(executeQueryOrDie(conn_template1, - "UPDATE pg_catalog.pg_database " - "SET datfrozenxid = '%u'", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_database.datfrozenxid */ + PQclear(executeQueryOrDie(conn_template1, + "UPDATE pg_catalog.pg_database " + "SET datfrozenxid = '%u'", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_database.datminmxid */ PQclear(executeQueryOrDie(conn_template1, @@ -942,16 +942,16 @@ set_frozenxids(void) conn = connectToServer(&new_cluster, datname); - /* set pg_class.relfrozenxid */ - PQclear(executeQueryOrDie(conn, - "UPDATE pg_catalog.pg_class " - "SET relfrozenxid = '%u' " - /* only heap, materialized view, and TOAST are vacuumed */ - "WHERE relkind IN (" - CppAsString2(RELKIND_RELATION) ", " - CppAsString2(RELKIND_MATVIEW) ", " - CppAsString2(RELKIND_TOASTVALUE) ")", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_class.relfrozenxid */ + PQclear(executeQueryOrDie(conn, + "UPDATE pg_catalog.pg_class " + "SET relfrozenxid = '%u' " + /* only heap, materialized view, and TOAST are vacuumed */ + "WHERE relkind IN (" + CppAsString2(RELKIND_RELATION) ", " + CppAsString2(RELKIND_MATVIEW) ", " + CppAsString2(RELKIND_TOASTVALUE) ")", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_class.relminmxid */ PQclear(executeQueryOrDie(conn, diff --git a/src/bin/pg_upgrade/relfilenumber.c b/src/bin/pg_upgrade/relfilenumber.c index ec2ff7acb21..6c467bdc8a5 100644 --- a/src/bin/pg_upgrade/relfilenumber.c +++ b/src/bin/pg_upgrade/relfilenumber.c @@ -587,32 +587,32 @@ transfer_relfile(FileNameMap *map, const char *type_suffix) /* Copying files might take some time, so give feedback. */ pg_log(PG_STATUS, "%s", old_file); - switch (user_opts.transfer_mode) - { - case TRANSFER_MODE_CLONE: - pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", - old_file, new_file); - cloneFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", - old_file, new_file); - copyFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY_FILE_RANGE: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", - old_file, new_file); - copyFileByRange(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_LINK: - pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", - old_file, new_file); - linkFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_SWAP: - /* swap mode is handled in its own code path */ - pg_fatal("should never happen"); - break; - } + switch (user_opts.transfer_mode) + { + case TRANSFER_MODE_CLONE: + pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", + old_file, new_file); + cloneFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", + old_file, new_file); + copyFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY_FILE_RANGE: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", + old_file, new_file); + copyFileByRange(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_LINK: + pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", + old_file, new_file); + linkFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_SWAP: + /* swap mode is handled in its own code path */ + pg_fatal("should never happen"); + break; + } } } diff --git a/src/bin/pg_upgrade/t/006_transfer_modes.pl b/src/bin/pg_upgrade/t/006_transfer_modes.pl index 9efa5dc863c..360d05c4b68 100644 --- a/src/bin/pg_upgrade/t/006_transfer_modes.pl +++ b/src/bin/pg_upgrade/t/006_transfer_modes.pl @@ -29,10 +29,8 @@ sub test_mode } $new->init(); - $new->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); - $old->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); + $new->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); + $old->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); # We can only test security labels if both the old and new installations # have dummy_seclabel. @@ -76,15 +74,14 @@ sub test_mode "CREATE TABLE test4 AS SELECT generate_series(400, 502)"); } - $old->safe_psql('postgres', - "CREATE TABLESPACE inplc_tblspc LOCATION ''"); - $old->safe_psql('postgres', - "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); - $old->safe_psql('postgres', - "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" - ); - $old->safe_psql('testdb3', - "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); + $old->safe_psql('postgres', "CREATE TABLESPACE inplc_tblspc LOCATION ''"); + $old->safe_psql('postgres', + "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); + $old->safe_psql('postgres', + "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" + ); + $old->safe_psql('testdb3', + "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); # While we are here, test handling of large objects. $old->safe_psql( @@ -152,12 +149,10 @@ sub test_mode } # Tests for in-place tablespaces. - $result = - $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); - is($result, '104', "test5 data after pg_upgrade $mode"); - $result = - $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); - is($result, '105', "test6 data after pg_upgrade $mode"); + $result = $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); + is($result, '104', "test5 data after pg_upgrade $mode"); + $result = $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); + is($result, '105', "test6 data after pg_upgrade $mode"); # Tests for large objects $result = $new->safe_psql('postgres', "SELECT lo_get(4532)"); diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index 44ef11d980e..c90bf8bbde2 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -6278,23 +6278,22 @@ get_create_object_cmd(EditableObjectType obj_type, Oid oid, * ensure the right view gets replaced. Also, check relation kind * to be sure it's a view. * - * Views may have WITH [LOCAL|CASCADED] - * CHECK OPTION. These are not part of the view definition - * returned by pg_get_viewdef() and so need to be retrieved - * separately. Materialized views may have - * arbitrary storage parameter reloptions. + * Views may have WITH [LOCAL|CASCADED] CHECK OPTION. These are + * not part of the view definition returned by pg_get_viewdef() + * and so need to be retrieved separately. Materialized views may + * have arbitrary storage parameter reloptions. */ printfPQExpBuffer(query, "/* %s */\n", _("Get view's definition and details")); - appendPQExpBuffer(query, - "SELECT nspname, relname, relkind, " - "pg_catalog.pg_get_viewdef(c.oid, true), " - "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " - "FROM pg_catalog.pg_class c " - "LEFT JOIN pg_catalog.pg_namespace n " - "ON c.relnamespace = n.oid WHERE c.oid = %u", - oid); + appendPQExpBuffer(query, + "SELECT nspname, relname, relkind, " + "pg_catalog.pg_get_viewdef(c.oid, true), " + "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " + "FROM pg_catalog.pg_class c " + "LEFT JOIN pg_catalog.pg_namespace n " + "ON c.relnamespace = n.oid WHERE c.oid = %u", + oid); break; } diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index ce99137c613..ac0c55e7aa5 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -387,19 +387,19 @@ describeFunctions(const char *functypes, const char *func_pattern, gettext_noop("stable"), gettext_noop("volatile"), gettext_noop("Volatility")); - appendPQExpBuffer(&buf, - ",\n CASE\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" - " END as \"%s\"", - gettext_noop("restricted"), - gettext_noop("safe"), - gettext_noop("unsafe"), - gettext_noop("Parallel")); + appendPQExpBuffer(&buf, + ",\n CASE\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" + " END as \"%s\"", + gettext_noop("restricted"), + gettext_noop("safe"), + gettext_noop("unsafe"), + gettext_noop("Parallel")); appendPQExpBuffer(&buf, ",\n pg_catalog.pg_get_userbyid(p.proowner) as \"%s\"" ",\n CASE WHEN prosecdef THEN '%s' ELSE '%s' END AS \"%s\"" @@ -599,8 +599,8 @@ describeFunctions(const char *functypes, const char *func_pattern, myopt.title = _("List of functions"); myopt.translate_header = true; - myopt.translate_columns = translate_columns; - myopt.n_translate_columns = lengthof(translate_columns); + myopt.translate_columns = translate_columns; + myopt.n_translate_columns = lengthof(translate_columns); printQuery(res, &myopt, pset.queryFout, false, pset.logfile); @@ -1086,38 +1086,38 @@ permissionsList(const char *pattern, bool showSystem) " ), E'\\n') AS \"%s\"", gettext_noop("Column privileges")); - appendPQExpBuffer(&buf, - ",\n pg_catalog.array_to_string(ARRAY(\n" - " SELECT polname\n" - " || CASE WHEN NOT polpermissive THEN\n" - " E' (RESTRICTIVE)'\n" - " ELSE '' END\n" - " || CASE WHEN polcmd != '*' THEN\n" - " E' (' || polcmd::pg_catalog.text || E'):'\n" - " ELSE E':'\n" - " END\n" - " || CASE WHEN polqual IS NOT NULL THEN\n" - " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" - " ELSE E''\n" - " END\n" - " || CASE WHEN polwithcheck IS NOT NULL THEN\n" - " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" - " ELSE E''\n" - " END" - " || CASE WHEN polroles <> '{0}' THEN\n" - " E'\\n to: ' || pg_catalog.array_to_string(\n" - " ARRAY(\n" - " SELECT rolname\n" - " FROM pg_catalog.pg_roles\n" - " WHERE oid = ANY (polroles)\n" - " ORDER BY 1\n" - " ), E', ')\n" - " ELSE E''\n" - " END\n" - " FROM pg_catalog.pg_policy pol\n" - " WHERE polrelid = c.oid), E'\\n')\n" - " AS \"%s\"", - gettext_noop("Policies")); + appendPQExpBuffer(&buf, + ",\n pg_catalog.array_to_string(ARRAY(\n" + " SELECT polname\n" + " || CASE WHEN NOT polpermissive THEN\n" + " E' (RESTRICTIVE)'\n" + " ELSE '' END\n" + " || CASE WHEN polcmd != '*' THEN\n" + " E' (' || polcmd::pg_catalog.text || E'):'\n" + " ELSE E':'\n" + " END\n" + " || CASE WHEN polqual IS NOT NULL THEN\n" + " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" + " ELSE E''\n" + " END\n" + " || CASE WHEN polwithcheck IS NOT NULL THEN\n" + " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" + " ELSE E''\n" + " END" + " || CASE WHEN polroles <> '{0}' THEN\n" + " E'\\n to: ' || pg_catalog.array_to_string(\n" + " ARRAY(\n" + " SELECT rolname\n" + " FROM pg_catalog.pg_roles\n" + " WHERE oid = ANY (polroles)\n" + " ORDER BY 1\n" + " ), E', ')\n" + " ELSE E''\n" + " END\n" + " FROM pg_catalog.pg_policy pol\n" + " WHERE polrelid = c.oid), E'\\n')\n" + " AS \"%s\"", + gettext_noop("Policies")); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_class c\n" " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n" @@ -1675,27 +1675,27 @@ describeOneTableDetails(const char *schemaname, char *footers[3] = {NULL, NULL, NULL}; printfPQExpBuffer(&buf, "/* %s */\n", _("Get sequence information")); - appendPQExpBuffer(&buf, - "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" - " seqstart AS \"%s\",\n" - " seqmin AS \"%s\",\n" - " seqmax AS \"%s\",\n" - " seqincrement AS \"%s\",\n" - " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" - " seqcache AS \"%s\"\n", - gettext_noop("Type"), - gettext_noop("Start"), - gettext_noop("Minimum"), - gettext_noop("Maximum"), - gettext_noop("Increment"), - gettext_noop("yes"), - gettext_noop("no"), - gettext_noop("Cycles?"), - gettext_noop("Cache")); - appendPQExpBuffer(&buf, - "FROM pg_catalog.pg_sequence\n" - "WHERE seqrelid = '%s';", - oid); + appendPQExpBuffer(&buf, + "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" + " seqstart AS \"%s\",\n" + " seqmin AS \"%s\",\n" + " seqmax AS \"%s\",\n" + " seqincrement AS \"%s\",\n" + " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" + " seqcache AS \"%s\"\n", + gettext_noop("Type"), + gettext_noop("Start"), + gettext_noop("Minimum"), + gettext_noop("Maximum"), + gettext_noop("Increment"), + gettext_noop("yes"), + gettext_noop("no"), + gettext_noop("Cycles?"), + gettext_noop("Cache")); + appendPQExpBuffer(&buf, + "FROM pg_catalog.pg_sequence\n" + "WHERE seqrelid = '%s';", + oid); res = PSQLexec(buf.data); if (!res) @@ -1913,7 +1913,7 @@ describeOneTableDetails(const char *schemaname, appendPQExpBufferStr(&buf, ",\n (SELECT c.collname FROM pg_catalog.pg_collation c, pg_catalog.pg_type t\n" " WHERE c.oid = a.attcollation AND t.oid = a.atttypid AND a.attcollation <> t.typcollation) AS attcollation"); attcoll_col = cols++; - appendPQExpBufferStr(&buf, ",\n a.attidentity"); + appendPQExpBufferStr(&buf, ",\n a.attidentity"); attidentity_col = cols++; if (pset.sversion >= 120000) appendPQExpBufferStr(&buf, ",\n a.attgenerated"); @@ -2326,7 +2326,7 @@ describeOneTableDetails(const char *schemaname, CppAsString2(CONSTRAINT_EXCLUSION) ") AND " "condeferred) AS condeferred,\n"); - appendPQExpBufferStr(&buf, "i.indisreplident,\n"); + appendPQExpBufferStr(&buf, "i.indisreplident,\n"); if (pset.sversion >= 150000) appendPQExpBufferStr(&buf, "i.indnullsnotdistinct,\n"); @@ -2431,7 +2431,7 @@ describeOneTableDetails(const char *schemaname, "pg_catalog.pg_get_indexdef(i.indexrelid, 0, true),\n " "pg_catalog.pg_get_constraintdef(con.oid, true), " "contype, condeferrable, condeferred"); - appendPQExpBufferStr(&buf, ", i.indisreplident"); + appendPQExpBufferStr(&buf, ", i.indisreplident"); appendPQExpBufferStr(&buf, ", c2.reltablespace"); if (pset.sversion >= 180000) appendPQExpBufferStr(&buf, ", con.conperiod"); @@ -2682,81 +2682,80 @@ describeOneTableDetails(const char *schemaname, PQclear(result); /* print any row-level policies */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get row-level policies for this table")); - appendPQExpBufferStr(&buf, "SELECT pol.polname,"); - appendPQExpBufferStr(&buf, - " pol.polpermissive,\n"); - appendPQExpBuffer(&buf, - " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" - " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" - " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" - " CASE pol.polcmd\n" - " WHEN 'r' THEN 'SELECT'\n" - " WHEN 'a' THEN 'INSERT'\n" - " WHEN 'w' THEN 'UPDATE'\n" - " WHEN 'd' THEN 'DELETE'\n" - " END AS cmd\n" - "FROM pg_catalog.pg_policy pol\n" - "WHERE pol.polrelid = '%s' ORDER BY 1;", - oid); + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get row-level policies for this table")); + appendPQExpBufferStr(&buf, "SELECT pol.polname,"); + appendPQExpBufferStr(&buf, + " pol.polpermissive,\n"); + appendPQExpBuffer(&buf, + " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" + " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" + " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" + " CASE pol.polcmd\n" + " WHEN 'r' THEN 'SELECT'\n" + " WHEN 'a' THEN 'INSERT'\n" + " WHEN 'w' THEN 'UPDATE'\n" + " WHEN 'd' THEN 'DELETE'\n" + " END AS cmd\n" + "FROM pg_catalog.pg_policy pol\n" + "WHERE pol.polrelid = '%s' ORDER BY 1;", + oid); - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - /* - * Handle cases where RLS is enabled and there are policies, or - * there aren't policies, or RLS isn't enabled but there are - * policies - */ - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies:")); + /* + * Handle cases where RLS is enabled and there are policies, or there + * aren't policies, or RLS isn't enabled but there are policies + */ + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies:")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled):")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled):")); - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); - if (!tableinfo.rowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (row security disabled):")); + if (!tableinfo.rowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (row security disabled):")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " POLICY \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " POLICY \"%s\"", + PQgetvalue(result, i, 0)); - if (*(PQgetvalue(result, i, 1)) == 'f') - appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); + if (*(PQgetvalue(result, i, 1)) == 'f') + appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); - if (!PQgetisnull(result, i, 5)) - appendPQExpBuffer(&buf, " FOR %s", - PQgetvalue(result, i, 5)); + if (!PQgetisnull(result, i, 5)) + appendPQExpBuffer(&buf, " FOR %s", + PQgetvalue(result, i, 5)); - if (!PQgetisnull(result, i, 2)) - { - appendPQExpBuffer(&buf, "\n TO %s", - PQgetvalue(result, i, 2)); - } + if (!PQgetisnull(result, i, 2)) + { + appendPQExpBuffer(&buf, "\n TO %s", + PQgetvalue(result, i, 2)); + } - if (!PQgetisnull(result, i, 3)) - appendPQExpBuffer(&buf, "\n USING (%s)", - PQgetvalue(result, i, 3)); + if (!PQgetisnull(result, i, 3)) + appendPQExpBuffer(&buf, "\n USING (%s)", + PQgetvalue(result, i, 3)); - if (!PQgetisnull(result, i, 4)) - appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", - PQgetvalue(result, i, 4)); + if (!PQgetisnull(result, i, 4)) + appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", + PQgetvalue(result, i, 4)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* print any extended statistics */ if (pset.sversion >= 140000) @@ -3025,115 +3024,115 @@ describeOneTableDetails(const char *schemaname, } /* print any publications */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get publications that publish this table")); - if (pset.sversion >= 150000) + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get publications that publish this table")); + if (pset.sversion >= 150000) + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" + " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" + "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" + "UNION\n" + "SELECT pubname\n" + " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" + " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" + " (SELECT pg_catalog.string_agg(attname, ', ')\n" + " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" + " pg_catalog.pg_attribute\n" + " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" + " ELSE NULL END) " + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" + "WHERE pr.prrelid = '%s'\n", + oid, oid, oid); + + if (pset.sversion >= 190000) { + /* + * Skip entries where this relation appears in the + * publication's EXCEPT list. + */ appendPQExpBuffer(&buf, + " AND NOT pr.prexcept\n" + "UNION\n" "SELECT pubname\n" " , NULL\n" " , NULL\n" "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" - " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" - "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" - "UNION\n" - "SELECT pubname\n" - " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" - " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" - " (SELECT pg_catalog.string_agg(attname, ', ')\n" - " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" - " pg_catalog.pg_attribute\n" - " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" - " ELSE NULL END) " - "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" - "WHERE pr.prrelid = '%s'\n", + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + " AND NOT EXISTS (\n" + " SELECT 1\n" + " FROM pg_catalog.pg_publication_rel pr\n" + " WHERE pr.prpubid = p.oid AND\n" + " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" + "ORDER BY 1;", oid, oid, oid); - - if (pset.sversion >= 190000) - { - /* - * Skip entries where this relation appears in the - * publication's EXCEPT list. - */ - appendPQExpBuffer(&buf, - " AND NOT pr.prexcept\n" - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - " AND NOT EXISTS (\n" - " SELECT 1\n" - " FROM pg_catalog.pg_publication_rel pr\n" - " WHERE pr.prpubid = p.oid AND\n" - " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" - "ORDER BY 1;", - oid, oid, oid); - } - else - { - appendPQExpBuffer(&buf, - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - "ORDER BY 1;", - oid); - } } else { appendPQExpBuffer(&buf, + "UNION\n" "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - "WHERE pr.prrelid = '%s'\n" - "UNION ALL\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" + " , NULL\n" + " , NULL\n" "FROM pg_catalog.pg_publication p\n" "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" "ORDER BY 1;", - oid, oid); + oid); } + } + else + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + "WHERE pr.prrelid = '%s'\n" + "UNION ALL\n" + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + "ORDER BY 1;", + oid, oid); + } - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - if (tuples > 0) - printTableAddFooter(&cont, _("Included in publications:")); + if (tuples > 0) + printTableAddFooter(&cont, _("Included in publications:")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " \"%s\"", + PQgetvalue(result, i, 0)); - /* column list (if any) */ - if (!PQgetisnull(result, i, 2)) - appendPQExpBuffer(&buf, " (%s)", - PQgetvalue(result, i, 2)); + /* column list (if any) */ + if (!PQgetisnull(result, i, 2)) + appendPQExpBuffer(&buf, " (%s)", + PQgetvalue(result, i, 2)); - /* row filter (if any) */ - if (!PQgetisnull(result, i, 1)) - appendPQExpBuffer(&buf, " WHERE %s", - PQgetvalue(result, i, 1)); + /* row filter (if any) */ + if (!PQgetisnull(result, i, 1)) + appendPQExpBuffer(&buf, " WHERE %s", + PQgetvalue(result, i, 1)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* Print publications where the table is in the EXCEPT clause */ if (pset.sversion >= 190000) @@ -3805,7 +3804,7 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) ncols++; } appendPQExpBufferStr(&buf, "\n, r.rolreplication"); - appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); + appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_roles r\n"); @@ -3860,8 +3859,8 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) if (strcmp(PQgetvalue(res, i, (verbose ? 9 : 8)), "t") == 0) add_role_attribute(&buf, _("Replication")); - if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) - add_role_attribute(&buf, _("Bypass RLS")); + if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) + add_role_attribute(&buf, _("Bypass RLS")); conns = atoi(PQgetvalue(res, i, 6)); if (conns >= 0) @@ -5155,14 +5154,14 @@ listCollations(const char *pattern, bool verbose, bool showSystem) gettext_noop("Schema"), gettext_noop("Name")); - appendPQExpBuffer(&buf, - " CASE c.collprovider " - "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " - "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " - "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " - "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " - "END AS \"%s\",\n", - gettext_noop("Provider")); + appendPQExpBuffer(&buf, + " CASE c.collprovider " + "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " + "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " + "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " + "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " + "END AS \"%s\",\n", + gettext_noop("Provider")); appendPQExpBuffer(&buf, " c.collcollate AS \"%s\",\n" -- 2.50.1 (Apple Git-155) --aHl3HfeiUuO3zeNC-- ^ permalink raw reply [nested|flat] 59+ messages in thread
* [PATCH v6 4/4] run pgindent and pgperltidy @ 2026-06-30 18:24 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 59+ messages in thread From: Nathan Bossart @ 2026-06-30 18:24 UTC (permalink / raw) --- src/bin/pg_dump/pg_dump.c | 464 ++++++++++----------- src/bin/pg_dump/pg_dumpall.c | 30 +- src/bin/pg_upgrade/check.c | 16 +- src/bin/pg_upgrade/controldata.c | 2 +- src/bin/pg_upgrade/exec.c | 8 +- src/bin/pg_upgrade/multixact_rewrite.c | 80 ++-- src/bin/pg_upgrade/pg_upgrade.c | 34 +- src/bin/pg_upgrade/relfilenumber.c | 54 +-- src/bin/pg_upgrade/t/006_transfer_modes.pl | 33 +- src/bin/psql/command.c | 29 +- src/bin/psql/describe.c | 461 ++++++++++---------- 11 files changed, 601 insertions(+), 610 deletions(-) diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 65bd15ebfd2..5673268b467 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -1491,8 +1491,8 @@ setup_connection(Archive *AH, const char *dumpencoding, * Disable timeouts if supported. */ ExecuteSqlStatement(AH, "SET statement_timeout = 0"); - ExecuteSqlStatement(AH, "SET lock_timeout = 0"); - ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); + ExecuteSqlStatement(AH, "SET lock_timeout = 0"); + ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); if (AH->remoteVersion >= 170000) ExecuteSqlStatement(AH, "SET transaction_timeout = 0"); @@ -1505,10 +1505,10 @@ setup_connection(Archive *AH, const char *dumpencoding, /* * Adjust row-security mode, if supported. */ - if (dopt->enable_row_security) - ExecuteSqlStatement(AH, "SET row_security = on"); - else - ExecuteSqlStatement(AH, "SET row_security = off"); + if (dopt->enable_row_security) + ExecuteSqlStatement(AH, "SET row_security = on"); + else + ExecuteSqlStatement(AH, "SET row_security = off"); /* * For security reasons, we restrict the expansion of non-system views and @@ -1933,10 +1933,9 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) addObjectDependency(dobj, ext->dobj.dumpId); /* - * Mark the member object to have any non-initial ACLs - * dumped. (Any initial ACLs will be removed later, using data from - * pg_init_privs, so that we'll dump only the delta from the extension's - * initial setup.) + * Mark the member object to have any non-initial ACLs dumped. (Any + * initial ACLs will be removed later, using data from pg_init_privs, so + * that we'll dump only the delta from the extension's initial setup.) * * In binary upgrades, we still dump all components of the members * individually, since the idea is to exactly reproduce the database @@ -1953,7 +1952,7 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) if (fout->dopt->binary_upgrade) dobj->dump = ext->dobj.dump; else - dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); + dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); return true; } @@ -1987,9 +1986,9 @@ selectDumpableNamespace(NamespaceInfo *nsinfo, Archive *fout) else if (strcmp(nsinfo->dobj.name, "pg_catalog") == 0) { /* - * We dump out any ACLs defined in pg_catalog, if - * they are interesting (and not the original ACLs which were set at - * initdb time, see pg_init_privs). + * We dump out any ACLs defined in pg_catalog, if they are interesting + * (and not the original ACLs which were set at initdb time, see + * pg_init_privs). */ nsinfo->dobj.dump_contains = nsinfo->dobj.dump = DUMP_COMPONENT_ACL; } @@ -3296,7 +3295,7 @@ dumpDatabase(Archive *fout) "datcollate, datctype, datfrozenxid, " "datacl, acldefault('d', datdba) AS acldefault, " "datistemplate, datconnlimit, "); - appendPQExpBufferStr(dbQry, "datminmxid, "); + appendPQExpBufferStr(dbQry, "datminmxid, "); if (fout->remoteVersion >= 170000) appendPQExpBufferStr(dbQry, "datlocprovider, datlocale, datcollversion, "); else if (fout->remoteVersion >= 150000) @@ -3638,11 +3637,11 @@ dumpDatabase(Archive *fout) ii_oid, ii_relminmxid; - appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" - "FROM pg_catalog.pg_class\n" - "WHERE oid IN (%u, %u, %u, %u);\n", - LargeObjectRelationId, LargeObjectLOidPNIndexId, - LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); + appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" + "FROM pg_catalog.pg_class\n" + "WHERE oid IN (%u, %u, %u, %u);\n", + LargeObjectRelationId, LargeObjectLOidPNIndexId, + LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); lo_res = ExecuteSqlQuery(fout, loFrozenQry->data, PGRES_TUPLES_OK); @@ -4274,7 +4273,7 @@ getPolicies(Archive *fout, TableInfo tblinfo[], int numTables) printfPQExpBuffer(query, "SELECT pol.oid, pol.tableoid, pol.polrelid, pol.polname, pol.polcmd, "); - appendPQExpBufferStr(query, "pol.polpermissive, "); + appendPQExpBufferStr(query, "pol.polpermissive, "); appendPQExpBuffer(query, "CASE WHEN pol.polroles = '{0}' THEN NULL ELSE " " pg_catalog.array_to_string(ARRAY(SELECT pg_catalog.quote_ident(rolname) from pg_catalog.pg_roles WHERE oid = ANY(pol.polroles)), ', ') END AS polroles, " @@ -6633,9 +6632,9 @@ getAccessMethods(Archive *fout) * Select all access methods from pg_am table. */ appendPQExpBufferStr(query, "SELECT tableoid, oid, amname, "); - appendPQExpBufferStr(query, - "amtype, " - "amhandler::pg_catalog.regproc AS amhandler "); + appendPQExpBufferStr(query, + "amtype, " + "amhandler::pg_catalog.regproc AS amhandler "); appendPQExpBufferStr(query, "FROM pg_am"); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6827,35 +6826,35 @@ getAggregates(Archive *fout) * Find all interesting aggregates. See comment in getFuncs() for the * rationale behind the filtering logic. */ - agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" - : "p.proisagg"); + agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" + : "p.proisagg"); - appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " - "p.proname AS aggname, " - "p.pronamespace AS aggnamespace, " - "p.pronargs, p.proargtypes, " - "p.proowner, " - "p.proacl AS aggacl, " - "acldefault('f', p.proowner) AS acldefault " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s AND (" - "p.pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog') OR " - "p.proacl IS DISTINCT FROM pip.initprivs", - agg_check); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - " OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); - appendPQExpBufferChar(query, ')'); + appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " + "p.proname AS aggname, " + "p.pronamespace AS aggnamespace, " + "p.pronargs, p.proargtypes, " + "p.proowner, " + "p.proacl AS aggacl, " + "acldefault('f', p.proowner) AS acldefault " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s AND (" + "p.pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog') OR " + "p.proacl IS DISTINCT FROM pip.initprivs", + agg_check); + if (dopt->binary_upgrade) + appendPQExpBufferStr(query, + " OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6957,53 +6956,53 @@ getFuncs(Archive *fout) * include them, since we want to dump extension members individually in * that mode. Also, if they are used by casts or transforms then we need * to gather the information about them, though they won't be dumped if - * they are built-in. Also, include functions in - * pg_catalog if they have an ACL different from what's shown in - * pg_init_privs (so we have to join to pg_init_privs; annoying). + * they are built-in. Also, include functions in pg_catalog if they have + * an ACL different from what's shown in pg_init_privs (so we have to join + * to pg_init_privs; annoying). */ - not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" - : "NOT p.proisagg"); + not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" + : "NOT p.proisagg"); - appendPQExpBuffer(query, - "SELECT p.tableoid, p.oid, p.proname, p.prolang, " - "p.pronargs, p.proargtypes, p.prorettype, " - "p.proacl, " - "acldefault('f', p.proowner) AS acldefault, " - "p.pronamespace, " - "p.proowner " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s" - "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " - "WHERE classid = 'pg_proc'::regclass AND " - "objid = p.oid AND deptype = 'i')" - "\n AND (" - "\n pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog')" - "\n OR EXISTS (SELECT 1 FROM pg_cast" - "\n WHERE pg_cast.oid > %u " - "\n AND p.oid = pg_cast.castfunc)" - "\n OR EXISTS (SELECT 1 FROM pg_transform" - "\n WHERE pg_transform.oid > %u AND " - "\n (p.oid = pg_transform.trffromsql" - "\n OR p.oid = pg_transform.trftosql))", - not_agg_check, - g_last_builtin_oid, - g_last_builtin_oid); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); + appendPQExpBuffer(query, + "SELECT p.tableoid, p.oid, p.proname, p.prolang, " + "p.pronargs, p.proargtypes, p.prorettype, " + "p.proacl, " + "acldefault('f', p.proowner) AS acldefault, " + "p.pronamespace, " + "p.proowner " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s" + "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " + "WHERE classid = 'pg_proc'::regclass AND " + "objid = p.oid AND deptype = 'i')" + "\n AND (" + "\n pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog')" + "\n OR EXISTS (SELECT 1 FROM pg_cast" + "\n WHERE pg_cast.oid > %u " + "\n AND p.oid = pg_cast.castfunc)" + "\n OR EXISTS (SELECT 1 FROM pg_transform" + "\n WHERE pg_transform.oid > %u AND " + "\n (p.oid = pg_transform.trffromsql" + "\n OR p.oid = pg_transform.trftosql))", + not_agg_check, + g_last_builtin_oid, + g_last_builtin_oid); + if (dopt->binary_upgrade) appendPQExpBufferStr(query, - "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); - appendPQExpBufferChar(query, ')'); + "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferStr(query, + "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -7252,31 +7251,31 @@ getTables(Archive *fout, int *numTables) appendPQExpBufferStr(query, "c.relhasoids, "); - appendPQExpBufferStr(query, - "c.relispopulated, "); + appendPQExpBufferStr(query, + "c.relispopulated, "); - appendPQExpBufferStr(query, - "c.relreplident, "); + appendPQExpBufferStr(query, + "c.relreplident, "); - appendPQExpBufferStr(query, - "c.relrowsecurity, c.relforcerowsecurity, "); + appendPQExpBufferStr(query, + "c.relrowsecurity, c.relforcerowsecurity, "); - appendPQExpBufferStr(query, - "c.relminmxid, tc.relminmxid AS tminmxid, "); + appendPQExpBufferStr(query, + "c.relminmxid, tc.relminmxid AS tminmxid, "); - appendPQExpBufferStr(query, - "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); + appendPQExpBufferStr(query, + "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); - appendPQExpBufferStr(query, - "am.amname, "); + appendPQExpBufferStr(query, + "am.amname, "); - appendPQExpBufferStr(query, - "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); + appendPQExpBufferStr(query, + "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); - appendPQExpBufferStr(query, - "c.relispartition AS ispartition "); + appendPQExpBufferStr(query, + "c.relispartition AS ispartition "); /* * Left join to pg_depend to pick up dependency info linking sequences to @@ -7296,8 +7295,8 @@ getTables(Archive *fout, int *numTables) /* * Left join to pg_am to pick up the amname. */ - appendPQExpBufferStr(query, - "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); + appendPQExpBufferStr(query, + "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); /* * We purposefully ignore toast OIDs for partitioned tables; the reason is @@ -7868,8 +7867,8 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables) "t.reloptions AS indreloptions, "); - appendPQExpBufferStr(query, - "i.indisreplident, "); + appendPQExpBufferStr(query, + "i.indisreplident, "); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -9313,8 +9312,8 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables) appendPQExpBufferStr(q, "'' AS attcompression,\n"); - appendPQExpBufferStr(q, - "a.attidentity,\n"); + appendPQExpBufferStr(q, + "a.attidentity,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(q, @@ -10717,73 +10716,73 @@ getAdditionalACLs(Archive *fout) PQclear(res); /* Fetch initial-privileges data */ - printfPQExpBuffer(query, - "SELECT objoid, classoid, objsubid, privtype, initprivs " - "FROM pg_init_privs"); + printfPQExpBuffer(query, + "SELECT objoid, classoid, objsubid, privtype, initprivs " + "FROM pg_init_privs"); - res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); + res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); - ntups = PQntuples(res); - for (i = 0; i < ntups; i++) - { - Oid objoid = atooid(PQgetvalue(res, i, 0)); - Oid classoid = atooid(PQgetvalue(res, i, 1)); - int objsubid = atoi(PQgetvalue(res, i, 2)); - char privtype = *(PQgetvalue(res, i, 3)); - char *initprivs = PQgetvalue(res, i, 4); - CatalogId objId; - DumpableObject *dobj; + ntups = PQntuples(res); + for (i = 0; i < ntups; i++) + { + Oid objoid = atooid(PQgetvalue(res, i, 0)); + Oid classoid = atooid(PQgetvalue(res, i, 1)); + int objsubid = atoi(PQgetvalue(res, i, 2)); + char privtype = *(PQgetvalue(res, i, 3)); + char *initprivs = PQgetvalue(res, i, 4); + CatalogId objId; + DumpableObject *dobj; - objId.tableoid = classoid; - objId.oid = objoid; - dobj = findObjectByCatalogId(objId); - /* OK to ignore entries we haven't got a DumpableObject for */ - if (dobj) + objId.tableoid = classoid; + objId.oid = objoid; + dobj = findObjectByCatalogId(objId); + /* OK to ignore entries we haven't got a DumpableObject for */ + if (dobj) + { + /* Cope with sub-object initprivs */ + if (objsubid != 0) { - /* Cope with sub-object initprivs */ - if (objsubid != 0) - { - if (dobj->objType == DO_TABLE) - { - /* For a column initprivs, set the table's ACL flags */ - dobj->components |= DUMP_COMPONENT_ACL; - ((TableInfo *) dobj)->hascolumnACLs = true; - } - else - pg_log_warning("unsupported pg_init_privs entry: %u %u %d", - classoid, objoid, objsubid); - continue; - } - - /* - * We ignore any pg_init_privs.initprivs entry for the public - * schema, as explained in getNamespaces(). - */ - if (dobj->objType == DO_NAMESPACE && - strcmp(dobj->name, "public") == 0) - continue; - - /* Else it had better be of a type we think has ACLs */ - if (dobj->objType == DO_NAMESPACE || - dobj->objType == DO_TYPE || - dobj->objType == DO_FUNC || - dobj->objType == DO_AGG || - dobj->objType == DO_TABLE || - dobj->objType == DO_PROCLANG || - dobj->objType == DO_FDW || - dobj->objType == DO_FOREIGN_SERVER) + if (dobj->objType == DO_TABLE) { - DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; - - daobj->dacl.privtype = privtype; - daobj->dacl.initprivs = pstrdup(initprivs); + /* For a column initprivs, set the table's ACL flags */ + dobj->components |= DUMP_COMPONENT_ACL; + ((TableInfo *) dobj)->hascolumnACLs = true; } else pg_log_warning("unsupported pg_init_privs entry: %u %u %d", classoid, objoid, objsubid); + continue; + } + + /* + * We ignore any pg_init_privs.initprivs entry for the public + * schema, as explained in getNamespaces(). + */ + if (dobj->objType == DO_NAMESPACE && + strcmp(dobj->name, "public") == 0) + continue; + + /* Else it had better be of a type we think has ACLs */ + if (dobj->objType == DO_NAMESPACE || + dobj->objType == DO_TYPE || + dobj->objType == DO_FUNC || + dobj->objType == DO_AGG || + dobj->objType == DO_TABLE || + dobj->objType == DO_PROCLANG || + dobj->objType == DO_FDW || + dobj->objType == DO_FOREIGN_SERVER) + { + DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; + + daobj->dacl.privtype = privtype; + daobj->dacl.initprivs = pstrdup(initprivs); } + else + pg_log_warning("unsupported pg_init_privs entry: %u %u %d", + classoid, objoid, objsubid); } - PQclear(res); + } + PQclear(res); destroyPQExpBuffer(query); } @@ -11128,8 +11127,8 @@ dumpRelationStats_dumper(Archive *fout, const void *userArg, const TocEntry *te) * The results must be in the order of the relations supplied in the * parameters to ensure we remain in sync as we walk through the TOC. * - * For versions before 19, the redundant filter clause on s.tablename = - * ANY(...) seems sufficient to convince the planner to use + * For versions before 19, the redundant filter clause on s.tablename + * = ANY(...) seems sufficient to convince the planner to use * pg_class_relname_nsp_index, which avoids a full scan of pg_stats. * In newer versions, pg_stats returns the table OIDs, eliminating the * need for that hack. @@ -13469,11 +13468,11 @@ dumpFunc(Archive *fout, const FuncInfo *finfo) "pg_catalog.pg_get_function_result(p.oid) AS funcresult,\n" "proleakproof,\n"); - appendPQExpBufferStr(query, - "array_to_string(protrftypes, ' ') AS protrftypes,\n"); + appendPQExpBufferStr(query, + "array_to_string(protrftypes, ' ') AS protrftypes,\n"); - appendPQExpBufferStr(query, - "proparallel,\n"); + appendPQExpBufferStr(query, + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -14963,9 +14962,9 @@ dumpCollation(Archive *fout, const CollInfo *collinfo) /* Get collation-specific details */ appendPQExpBufferStr(query, "SELECT "); - appendPQExpBufferStr(query, - "collprovider, " - "collversion, "); + appendPQExpBufferStr(query, + "collprovider, " + "collversion, "); if (fout->remoteVersion >= 120000) appendPQExpBufferStr(query, @@ -15372,23 +15371,23 @@ dumpAgg(Archive *fout, const AggInfo *agginfo) "pg_catalog.pg_get_function_arguments(p.oid) AS funcargs,\n" "pg_catalog.pg_get_function_identity_arguments(p.oid) AS funciargs,\n"); - appendPQExpBufferStr(query, - "aggkind,\n" - "aggmtransfn,\n" - "aggminvtransfn,\n" - "aggmfinalfn,\n" - "aggmtranstype::pg_catalog.regtype,\n" - "aggfinalextra,\n" - "aggmfinalextra,\n" - "aggtransspace,\n" - "aggmtransspace,\n" - "aggminitval,\n"); + appendPQExpBufferStr(query, + "aggkind,\n" + "aggmtransfn,\n" + "aggminvtransfn,\n" + "aggmfinalfn,\n" + "aggmtranstype::pg_catalog.regtype,\n" + "aggfinalextra,\n" + "aggmfinalextra,\n" + "aggtransspace,\n" + "aggmtransspace,\n" + "aggminitval,\n"); - appendPQExpBufferStr(query, - "aggcombinefn,\n" - "aggserialfn,\n" - "aggdeserialfn,\n" - "proparallel,\n"); + appendPQExpBufferStr(query, + "aggcombinefn,\n" + "aggserialfn,\n" + "aggdeserialfn,\n" + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -16848,30 +16847,30 @@ dumpTable(Archive *fout, const TableInfo *tbinfo) appendPQExpBufferStr(query, "PREPARE getColumnACLs(pg_catalog.oid) AS\n"); - /* - * In principle we should call acldefault('c', relowner) to - * get the default ACL for a column. However, we don't - * currently store the numeric OID of the relowner in - * TableInfo. We could convert the owner name using regrole, - * but that creates a risk of failure due to concurrent role - * renames. Given that the default ACL for columns is empty - * and is likely to stay that way, it's not worth extra cycles - * and risk to avoid hard-wiring that knowledge here. - */ - appendPQExpBufferStr(query, - "SELECT at.attname, " - "at.attacl, " - "'{}' AS acldefault, " - "pip.privtype, pip.initprivs " - "FROM pg_catalog.pg_attribute at " - "LEFT JOIN pg_catalog.pg_init_privs pip ON " - "(at.attrelid = pip.objoid " - "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " - "AND at.attnum = pip.objsubid) " - "WHERE at.attrelid = $1 AND " - "NOT at.attisdropped " - "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " - "ORDER BY at.attnum"); + /* + * In principle we should call acldefault('c', relowner) to get + * the default ACL for a column. However, we don't currently + * store the numeric OID of the relowner in TableInfo. We could + * convert the owner name using regrole, but that creates a risk + * of failure due to concurrent role renames. Given that the + * default ACL for columns is empty and is likely to stay that + * way, it's not worth extra cycles and risk to avoid hard-wiring + * that knowledge here. + */ + appendPQExpBufferStr(query, + "SELECT at.attname, " + "at.attacl, " + "'{}' AS acldefault, " + "pip.privtype, pip.initprivs " + "FROM pg_catalog.pg_attribute at " + "LEFT JOIN pg_catalog.pg_init_privs pip ON " + "(at.attrelid = pip.objoid " + "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " + "AND at.attnum = pip.objsubid) " + "WHERE at.attrelid = $1 AND " + "NOT at.attisdropped " + "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " + "ORDER BY at.attnum"); ExecuteSqlStatement(fout, query->data); @@ -19165,7 +19164,7 @@ collectSequences(Archive *fout) * pg_get_sequence_data(), but we only do so for non-schema-only dumps. */ if (fout->remoteVersion < 180000 || - (!fout->dopt->dumpData && !fout->dopt->sequence_data)) + (!fout->dopt->dumpData && !fout->dopt->sequence_data)) query = "SELECT seqrelid, format_type(seqtypid, NULL), " "seqstart, seqincrement, " "seqmax, seqmin, " @@ -19227,15 +19226,14 @@ dumpSequence(Archive *fout, const TableInfo *tbinfo) qseqname = pg_strdup(fmtId(tbinfo->dobj.name)); /* - * The sequence information is gathered in a sorted - * table before any calls to dumpSequence(). See collectSequences() for - * more information. + * The sequence information is gathered in a sorted table before any calls + * to dumpSequence(). See collectSequences() for more information. */ - Assert(sequences); + Assert(sequences); - key.oid = tbinfo->dobj.catId.oid; - seq = bsearch(&key, sequences, nsequences, - sizeof(SequenceItem), SequenceItemCmp); + key.oid = tbinfo->dobj.catId.oid; + seq = bsearch(&key, sequences, nsequences, + sizeof(SequenceItem), SequenceItemCmp); /* Calculate default limits for a sequence of this type */ is_ascending = (seq->incby >= 0); diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c index e68937c9934..afcd9a218d8 100644 --- a/src/bin/pg_dump/pg_dumpall.c +++ b/src/bin/pg_dump/pg_dumpall.c @@ -785,11 +785,11 @@ dropRoles(PGconn *conn) int i_rolname; int i; - printfPQExpBuffer(buf, - "SELECT rolname " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 1", role_catalog); + printfPQExpBuffer(buf, + "SELECT rolname " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 1", role_catalog); res = executeQuery(conn, buf->data); @@ -843,16 +843,16 @@ dumpRoles(PGconn *conn) * Notes: rolconfig is dumped later, and pg_authid must be used for * extracting rolcomment regardless of role_catalog. */ - printfPQExpBuffer(buf, - "SELECT oid, rolname, rolsuper, rolinherit, " - "rolcreaterole, rolcreatedb, " - "rolcanlogin, rolconnlimit, rolpassword, " - "rolvaliduntil, rolreplication, rolbypassrls, " - "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " - "rolname = current_user AS is_current_user " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 2", role_catalog); + printfPQExpBuffer(buf, + "SELECT oid, rolname, rolsuper, rolinherit, " + "rolcreaterole, rolcreatedb, " + "rolcanlogin, rolconnlimit, rolpassword, " + "rolvaliduntil, rolreplication, rolbypassrls, " + "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " + "rolname = current_user AS is_current_user " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 2", role_catalog); res = executeQuery(conn, buf->data); diff --git a/src/bin/pg_upgrade/check.c b/src/bin/pg_upgrade/check.c index 786c1474829..f725f5ee3e2 100644 --- a/src/bin/pg_upgrade/check.c +++ b/src/bin/pg_upgrade/check.c @@ -1475,15 +1475,15 @@ check_for_incompatible_polymorphics(ClusterInfo *cluster) ", 'array_cat(anyarray,anyarray)'" ", 'array_prepend(anyelement,anyarray)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_remove(anyarray,anyelement)'" - ", 'array_replace(anyarray,anyelement,anyelement)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_remove(anyarray,anyelement)'" + ", 'array_replace(anyarray,anyelement,anyelement)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_position(anyarray,anyelement)'" - ", 'array_position(anyarray,anyelement,integer)'" - ", 'array_positions(anyarray,anyelement)'" - ", 'width_bucket(anyelement,anyarray)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_position(anyarray,anyelement)'" + ", 'array_position(anyarray,anyelement,integer)'" + ", 'array_positions(anyarray,anyelement)'" + ", 'width_bucket(anyelement,anyarray)'"); /* * The query below hardcodes FirstNormalObjectId as 16384 rather than diff --git a/src/bin/pg_upgrade/controldata.c b/src/bin/pg_upgrade/controldata.c index 8f81c9e9582..02ea02df60f 100644 --- a/src/bin/pg_upgrade/controldata.c +++ b/src/bin/pg_upgrade/controldata.c @@ -228,7 +228,7 @@ get_control_data(ClusterInfo *cluster) p++; /* remove ':' char */ cluster->controldata.chkpnt_nxtepoch = str2uint(p); - p = strchr(p, ':'); + p = strchr(p, ':'); if (p == NULL || strlen(p) <= 1) pg_fatal("%d: controldata retrieval problem", __LINE__); diff --git a/src/bin/pg_upgrade/exec.c b/src/bin/pg_upgrade/exec.c index 44355feea30..a1bdbf373e3 100644 --- a/src/bin/pg_upgrade/exec.c +++ b/src/bin/pg_upgrade/exec.c @@ -55,7 +55,7 @@ get_bin_version(ClusterInfo *cluster) if (sscanf(cmd_output, "%*s %*s %d.%d", &v1, &v2) < 1) pg_fatal("could not get pg_ctl version output from %s", cmd); - cluster->bin_version = v1 * 10000; + cluster->bin_version = v1 * 10000; } @@ -344,8 +344,8 @@ check_data_dir(ClusterInfo *cluster) check_single_dir(pg_data, "pg_subtrans"); check_single_dir(pg_data, PG_TBLSPC_DIR); check_single_dir(pg_data, "pg_twophase"); - check_single_dir(pg_data, "pg_wal"); - check_single_dir(pg_data, "pg_xact"); + check_single_dir(pg_data, "pg_wal"); + check_single_dir(pg_data, "pg_xact"); } @@ -385,7 +385,7 @@ check_bin_dir(ClusterInfo *cluster, bool check_versions) */ get_bin_version(cluster); - check_exec(cluster->bindir, "pg_resetwal", check_versions); + check_exec(cluster->bindir, "pg_resetwal", check_versions); if (cluster == &new_cluster) { diff --git a/src/bin/pg_upgrade/multixact_rewrite.c b/src/bin/pg_upgrade/multixact_rewrite.c index c45b3183684..c7a1416494d 100644 --- a/src/bin/pg_upgrade/multixact_rewrite.c +++ b/src/bin/pg_upgrade/multixact_rewrite.c @@ -61,52 +61,52 @@ rewrite_multixacts(MultiXactId from_multi, MultiXactId to_multi) * Convert old multixids, if needed, by reading them one-by-one from the * old cluster. */ - old_reader = AllocOldMultiXactRead(old_cluster.pgdata, - old_cluster.controldata.chkpnt_nxtmulti, - old_cluster.controldata.chkpnt_nxtmxoff); + old_reader = AllocOldMultiXactRead(old_cluster.pgdata, + old_cluster.controldata.chkpnt_nxtmulti, + old_cluster.controldata.chkpnt_nxtmxoff); - for (MultiXactId multi = from_multi; multi != to_multi;) - { - MultiXactMember member; - bool multixid_valid; - - /* - * Read this multixid's members. - * - * Locking-only XIDs that may be part of multi-xids don't matter - * after upgrade, as there can be no transactions running across - * upgrade. So as a small optimization, we only read one member - * from each multixid: the one updating one, or if there was no - * update, arbitrarily the first locking xid. - */ - multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); + for (MultiXactId multi = from_multi; multi != to_multi;) + { + MultiXactMember member; + bool multixid_valid; - /* - * Write the new offset to pg_multixact/offsets. - * - * Even if this multixid is invalid, we still need to write its - * offset if the *previous* multixid was valid. That's because - * when reading a multixid, the number of members is calculated - * from the difference between the two offsets. - */ - RecordMultiXactOffset(offsets_writer, multi, - (multixid_valid || prev_multixid_valid) ? next_offset : 0); + /* + * Read this multixid's members. + * + * Locking-only XIDs that may be part of multi-xids don't matter after + * upgrade, as there can be no transactions running across upgrade. So + * as a small optimization, we only read one member from each + * multixid: the one updating one, or if there was no update, + * arbitrarily the first locking xid. + */ + multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); - /* Write the members */ - if (multixid_valid) - { - RecordMultiXactMembers(members_writer, next_offset, 1, &member); - next_offset += 1; - } + /* + * Write the new offset to pg_multixact/offsets. + * + * Even if this multixid is invalid, we still need to write its offset + * if the *previous* multixid was valid. That's because when reading + * a multixid, the number of members is calculated from the difference + * between the two offsets. + */ + RecordMultiXactOffset(offsets_writer, multi, + (multixid_valid || prev_multixid_valid) ? next_offset : 0); - /* Advance to next multixid, handling wraparound */ - multi++; - if (multi < FirstMultiXactId) - multi = FirstMultiXactId; - prev_multixid_valid = multixid_valid; + /* Write the members */ + if (multixid_valid) + { + RecordMultiXactMembers(members_writer, next_offset, 1, &member); + next_offset += 1; } - FreeOldMultiXactReader(old_reader); + /* Advance to next multixid, handling wraparound */ + multi++; + if (multi < FirstMultiXactId) + multi = FirstMultiXactId; + prev_multixid_valid = multixid_valid; + } + + FreeOldMultiXactReader(old_reader); /* Write the final 'next' offset to the last SLRU page */ RecordMultiXactOffset(offsets_writer, to_multi, diff --git a/src/bin/pg_upgrade/pg_upgrade.c b/src/bin/pg_upgrade/pg_upgrade.c index c6af9035665..7366fd4627c 100644 --- a/src/bin/pg_upgrade/pg_upgrade.c +++ b/src/bin/pg_upgrade/pg_upgrade.c @@ -833,7 +833,7 @@ copy_xact_xlog_xid(void) * Determine the range of multixacts to convert. */ nxtmulti = old_cluster.controldata.chkpnt_nxtmulti; - oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; + oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; /* handle wraparound */ if (nxtmulti < FirstMultiXactId) nxtmulti = FirstMultiXactId; @@ -898,15 +898,15 @@ set_frozenxids(void) int i_datname; int i_datallowconn; - prep_status("Setting frozenxid and minmxid counters in new cluster"); + prep_status("Setting frozenxid and minmxid counters in new cluster"); conn_template1 = connectToServer(&new_cluster, "template1"); - /* set pg_database.datfrozenxid */ - PQclear(executeQueryOrDie(conn_template1, - "UPDATE pg_catalog.pg_database " - "SET datfrozenxid = '%u'", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_database.datfrozenxid */ + PQclear(executeQueryOrDie(conn_template1, + "UPDATE pg_catalog.pg_database " + "SET datfrozenxid = '%u'", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_database.datminmxid */ PQclear(executeQueryOrDie(conn_template1, @@ -942,16 +942,16 @@ set_frozenxids(void) conn = connectToServer(&new_cluster, datname); - /* set pg_class.relfrozenxid */ - PQclear(executeQueryOrDie(conn, - "UPDATE pg_catalog.pg_class " - "SET relfrozenxid = '%u' " - /* only heap, materialized view, and TOAST are vacuumed */ - "WHERE relkind IN (" - CppAsString2(RELKIND_RELATION) ", " - CppAsString2(RELKIND_MATVIEW) ", " - CppAsString2(RELKIND_TOASTVALUE) ")", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_class.relfrozenxid */ + PQclear(executeQueryOrDie(conn, + "UPDATE pg_catalog.pg_class " + "SET relfrozenxid = '%u' " + /* only heap, materialized view, and TOAST are vacuumed */ + "WHERE relkind IN (" + CppAsString2(RELKIND_RELATION) ", " + CppAsString2(RELKIND_MATVIEW) ", " + CppAsString2(RELKIND_TOASTVALUE) ")", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_class.relminmxid */ PQclear(executeQueryOrDie(conn, diff --git a/src/bin/pg_upgrade/relfilenumber.c b/src/bin/pg_upgrade/relfilenumber.c index ec2ff7acb21..6c467bdc8a5 100644 --- a/src/bin/pg_upgrade/relfilenumber.c +++ b/src/bin/pg_upgrade/relfilenumber.c @@ -587,32 +587,32 @@ transfer_relfile(FileNameMap *map, const char *type_suffix) /* Copying files might take some time, so give feedback. */ pg_log(PG_STATUS, "%s", old_file); - switch (user_opts.transfer_mode) - { - case TRANSFER_MODE_CLONE: - pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", - old_file, new_file); - cloneFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", - old_file, new_file); - copyFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY_FILE_RANGE: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", - old_file, new_file); - copyFileByRange(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_LINK: - pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", - old_file, new_file); - linkFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_SWAP: - /* swap mode is handled in its own code path */ - pg_fatal("should never happen"); - break; - } + switch (user_opts.transfer_mode) + { + case TRANSFER_MODE_CLONE: + pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", + old_file, new_file); + cloneFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", + old_file, new_file); + copyFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY_FILE_RANGE: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", + old_file, new_file); + copyFileByRange(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_LINK: + pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", + old_file, new_file); + linkFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_SWAP: + /* swap mode is handled in its own code path */ + pg_fatal("should never happen"); + break; + } } } diff --git a/src/bin/pg_upgrade/t/006_transfer_modes.pl b/src/bin/pg_upgrade/t/006_transfer_modes.pl index 9efa5dc863c..360d05c4b68 100644 --- a/src/bin/pg_upgrade/t/006_transfer_modes.pl +++ b/src/bin/pg_upgrade/t/006_transfer_modes.pl @@ -29,10 +29,8 @@ sub test_mode } $new->init(); - $new->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); - $old->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); + $new->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); + $old->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); # We can only test security labels if both the old and new installations # have dummy_seclabel. @@ -76,15 +74,14 @@ sub test_mode "CREATE TABLE test4 AS SELECT generate_series(400, 502)"); } - $old->safe_psql('postgres', - "CREATE TABLESPACE inplc_tblspc LOCATION ''"); - $old->safe_psql('postgres', - "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); - $old->safe_psql('postgres', - "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" - ); - $old->safe_psql('testdb3', - "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); + $old->safe_psql('postgres', "CREATE TABLESPACE inplc_tblspc LOCATION ''"); + $old->safe_psql('postgres', + "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); + $old->safe_psql('postgres', + "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" + ); + $old->safe_psql('testdb3', + "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); # While we are here, test handling of large objects. $old->safe_psql( @@ -152,12 +149,10 @@ sub test_mode } # Tests for in-place tablespaces. - $result = - $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); - is($result, '104', "test5 data after pg_upgrade $mode"); - $result = - $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); - is($result, '105', "test6 data after pg_upgrade $mode"); + $result = $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); + is($result, '104', "test5 data after pg_upgrade $mode"); + $result = $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); + is($result, '105', "test6 data after pg_upgrade $mode"); # Tests for large objects $result = $new->safe_psql('postgres', "SELECT lo_get(4532)"); diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index 44ef11d980e..c90bf8bbde2 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -6278,23 +6278,22 @@ get_create_object_cmd(EditableObjectType obj_type, Oid oid, * ensure the right view gets replaced. Also, check relation kind * to be sure it's a view. * - * Views may have WITH [LOCAL|CASCADED] - * CHECK OPTION. These are not part of the view definition - * returned by pg_get_viewdef() and so need to be retrieved - * separately. Materialized views may have - * arbitrary storage parameter reloptions. + * Views may have WITH [LOCAL|CASCADED] CHECK OPTION. These are + * not part of the view definition returned by pg_get_viewdef() + * and so need to be retrieved separately. Materialized views may + * have arbitrary storage parameter reloptions. */ printfPQExpBuffer(query, "/* %s */\n", _("Get view's definition and details")); - appendPQExpBuffer(query, - "SELECT nspname, relname, relkind, " - "pg_catalog.pg_get_viewdef(c.oid, true), " - "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " - "FROM pg_catalog.pg_class c " - "LEFT JOIN pg_catalog.pg_namespace n " - "ON c.relnamespace = n.oid WHERE c.oid = %u", - oid); + appendPQExpBuffer(query, + "SELECT nspname, relname, relkind, " + "pg_catalog.pg_get_viewdef(c.oid, true), " + "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " + "FROM pg_catalog.pg_class c " + "LEFT JOIN pg_catalog.pg_namespace n " + "ON c.relnamespace = n.oid WHERE c.oid = %u", + oid); break; } diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index ce99137c613..ac0c55e7aa5 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -387,19 +387,19 @@ describeFunctions(const char *functypes, const char *func_pattern, gettext_noop("stable"), gettext_noop("volatile"), gettext_noop("Volatility")); - appendPQExpBuffer(&buf, - ",\n CASE\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" - " END as \"%s\"", - gettext_noop("restricted"), - gettext_noop("safe"), - gettext_noop("unsafe"), - gettext_noop("Parallel")); + appendPQExpBuffer(&buf, + ",\n CASE\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" + " END as \"%s\"", + gettext_noop("restricted"), + gettext_noop("safe"), + gettext_noop("unsafe"), + gettext_noop("Parallel")); appendPQExpBuffer(&buf, ",\n pg_catalog.pg_get_userbyid(p.proowner) as \"%s\"" ",\n CASE WHEN prosecdef THEN '%s' ELSE '%s' END AS \"%s\"" @@ -599,8 +599,8 @@ describeFunctions(const char *functypes, const char *func_pattern, myopt.title = _("List of functions"); myopt.translate_header = true; - myopt.translate_columns = translate_columns; - myopt.n_translate_columns = lengthof(translate_columns); + myopt.translate_columns = translate_columns; + myopt.n_translate_columns = lengthof(translate_columns); printQuery(res, &myopt, pset.queryFout, false, pset.logfile); @@ -1086,38 +1086,38 @@ permissionsList(const char *pattern, bool showSystem) " ), E'\\n') AS \"%s\"", gettext_noop("Column privileges")); - appendPQExpBuffer(&buf, - ",\n pg_catalog.array_to_string(ARRAY(\n" - " SELECT polname\n" - " || CASE WHEN NOT polpermissive THEN\n" - " E' (RESTRICTIVE)'\n" - " ELSE '' END\n" - " || CASE WHEN polcmd != '*' THEN\n" - " E' (' || polcmd::pg_catalog.text || E'):'\n" - " ELSE E':'\n" - " END\n" - " || CASE WHEN polqual IS NOT NULL THEN\n" - " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" - " ELSE E''\n" - " END\n" - " || CASE WHEN polwithcheck IS NOT NULL THEN\n" - " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" - " ELSE E''\n" - " END" - " || CASE WHEN polroles <> '{0}' THEN\n" - " E'\\n to: ' || pg_catalog.array_to_string(\n" - " ARRAY(\n" - " SELECT rolname\n" - " FROM pg_catalog.pg_roles\n" - " WHERE oid = ANY (polroles)\n" - " ORDER BY 1\n" - " ), E', ')\n" - " ELSE E''\n" - " END\n" - " FROM pg_catalog.pg_policy pol\n" - " WHERE polrelid = c.oid), E'\\n')\n" - " AS \"%s\"", - gettext_noop("Policies")); + appendPQExpBuffer(&buf, + ",\n pg_catalog.array_to_string(ARRAY(\n" + " SELECT polname\n" + " || CASE WHEN NOT polpermissive THEN\n" + " E' (RESTRICTIVE)'\n" + " ELSE '' END\n" + " || CASE WHEN polcmd != '*' THEN\n" + " E' (' || polcmd::pg_catalog.text || E'):'\n" + " ELSE E':'\n" + " END\n" + " || CASE WHEN polqual IS NOT NULL THEN\n" + " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" + " ELSE E''\n" + " END\n" + " || CASE WHEN polwithcheck IS NOT NULL THEN\n" + " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" + " ELSE E''\n" + " END" + " || CASE WHEN polroles <> '{0}' THEN\n" + " E'\\n to: ' || pg_catalog.array_to_string(\n" + " ARRAY(\n" + " SELECT rolname\n" + " FROM pg_catalog.pg_roles\n" + " WHERE oid = ANY (polroles)\n" + " ORDER BY 1\n" + " ), E', ')\n" + " ELSE E''\n" + " END\n" + " FROM pg_catalog.pg_policy pol\n" + " WHERE polrelid = c.oid), E'\\n')\n" + " AS \"%s\"", + gettext_noop("Policies")); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_class c\n" " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n" @@ -1675,27 +1675,27 @@ describeOneTableDetails(const char *schemaname, char *footers[3] = {NULL, NULL, NULL}; printfPQExpBuffer(&buf, "/* %s */\n", _("Get sequence information")); - appendPQExpBuffer(&buf, - "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" - " seqstart AS \"%s\",\n" - " seqmin AS \"%s\",\n" - " seqmax AS \"%s\",\n" - " seqincrement AS \"%s\",\n" - " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" - " seqcache AS \"%s\"\n", - gettext_noop("Type"), - gettext_noop("Start"), - gettext_noop("Minimum"), - gettext_noop("Maximum"), - gettext_noop("Increment"), - gettext_noop("yes"), - gettext_noop("no"), - gettext_noop("Cycles?"), - gettext_noop("Cache")); - appendPQExpBuffer(&buf, - "FROM pg_catalog.pg_sequence\n" - "WHERE seqrelid = '%s';", - oid); + appendPQExpBuffer(&buf, + "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" + " seqstart AS \"%s\",\n" + " seqmin AS \"%s\",\n" + " seqmax AS \"%s\",\n" + " seqincrement AS \"%s\",\n" + " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" + " seqcache AS \"%s\"\n", + gettext_noop("Type"), + gettext_noop("Start"), + gettext_noop("Minimum"), + gettext_noop("Maximum"), + gettext_noop("Increment"), + gettext_noop("yes"), + gettext_noop("no"), + gettext_noop("Cycles?"), + gettext_noop("Cache")); + appendPQExpBuffer(&buf, + "FROM pg_catalog.pg_sequence\n" + "WHERE seqrelid = '%s';", + oid); res = PSQLexec(buf.data); if (!res) @@ -1913,7 +1913,7 @@ describeOneTableDetails(const char *schemaname, appendPQExpBufferStr(&buf, ",\n (SELECT c.collname FROM pg_catalog.pg_collation c, pg_catalog.pg_type t\n" " WHERE c.oid = a.attcollation AND t.oid = a.atttypid AND a.attcollation <> t.typcollation) AS attcollation"); attcoll_col = cols++; - appendPQExpBufferStr(&buf, ",\n a.attidentity"); + appendPQExpBufferStr(&buf, ",\n a.attidentity"); attidentity_col = cols++; if (pset.sversion >= 120000) appendPQExpBufferStr(&buf, ",\n a.attgenerated"); @@ -2326,7 +2326,7 @@ describeOneTableDetails(const char *schemaname, CppAsString2(CONSTRAINT_EXCLUSION) ") AND " "condeferred) AS condeferred,\n"); - appendPQExpBufferStr(&buf, "i.indisreplident,\n"); + appendPQExpBufferStr(&buf, "i.indisreplident,\n"); if (pset.sversion >= 150000) appendPQExpBufferStr(&buf, "i.indnullsnotdistinct,\n"); @@ -2431,7 +2431,7 @@ describeOneTableDetails(const char *schemaname, "pg_catalog.pg_get_indexdef(i.indexrelid, 0, true),\n " "pg_catalog.pg_get_constraintdef(con.oid, true), " "contype, condeferrable, condeferred"); - appendPQExpBufferStr(&buf, ", i.indisreplident"); + appendPQExpBufferStr(&buf, ", i.indisreplident"); appendPQExpBufferStr(&buf, ", c2.reltablespace"); if (pset.sversion >= 180000) appendPQExpBufferStr(&buf, ", con.conperiod"); @@ -2682,81 +2682,80 @@ describeOneTableDetails(const char *schemaname, PQclear(result); /* print any row-level policies */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get row-level policies for this table")); - appendPQExpBufferStr(&buf, "SELECT pol.polname,"); - appendPQExpBufferStr(&buf, - " pol.polpermissive,\n"); - appendPQExpBuffer(&buf, - " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" - " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" - " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" - " CASE pol.polcmd\n" - " WHEN 'r' THEN 'SELECT'\n" - " WHEN 'a' THEN 'INSERT'\n" - " WHEN 'w' THEN 'UPDATE'\n" - " WHEN 'd' THEN 'DELETE'\n" - " END AS cmd\n" - "FROM pg_catalog.pg_policy pol\n" - "WHERE pol.polrelid = '%s' ORDER BY 1;", - oid); + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get row-level policies for this table")); + appendPQExpBufferStr(&buf, "SELECT pol.polname,"); + appendPQExpBufferStr(&buf, + " pol.polpermissive,\n"); + appendPQExpBuffer(&buf, + " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" + " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" + " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" + " CASE pol.polcmd\n" + " WHEN 'r' THEN 'SELECT'\n" + " WHEN 'a' THEN 'INSERT'\n" + " WHEN 'w' THEN 'UPDATE'\n" + " WHEN 'd' THEN 'DELETE'\n" + " END AS cmd\n" + "FROM pg_catalog.pg_policy pol\n" + "WHERE pol.polrelid = '%s' ORDER BY 1;", + oid); - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - /* - * Handle cases where RLS is enabled and there are policies, or - * there aren't policies, or RLS isn't enabled but there are - * policies - */ - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies:")); + /* + * Handle cases where RLS is enabled and there are policies, or there + * aren't policies, or RLS isn't enabled but there are policies + */ + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies:")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled):")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled):")); - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); - if (!tableinfo.rowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (row security disabled):")); + if (!tableinfo.rowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (row security disabled):")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " POLICY \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " POLICY \"%s\"", + PQgetvalue(result, i, 0)); - if (*(PQgetvalue(result, i, 1)) == 'f') - appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); + if (*(PQgetvalue(result, i, 1)) == 'f') + appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); - if (!PQgetisnull(result, i, 5)) - appendPQExpBuffer(&buf, " FOR %s", - PQgetvalue(result, i, 5)); + if (!PQgetisnull(result, i, 5)) + appendPQExpBuffer(&buf, " FOR %s", + PQgetvalue(result, i, 5)); - if (!PQgetisnull(result, i, 2)) - { - appendPQExpBuffer(&buf, "\n TO %s", - PQgetvalue(result, i, 2)); - } + if (!PQgetisnull(result, i, 2)) + { + appendPQExpBuffer(&buf, "\n TO %s", + PQgetvalue(result, i, 2)); + } - if (!PQgetisnull(result, i, 3)) - appendPQExpBuffer(&buf, "\n USING (%s)", - PQgetvalue(result, i, 3)); + if (!PQgetisnull(result, i, 3)) + appendPQExpBuffer(&buf, "\n USING (%s)", + PQgetvalue(result, i, 3)); - if (!PQgetisnull(result, i, 4)) - appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", - PQgetvalue(result, i, 4)); + if (!PQgetisnull(result, i, 4)) + appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", + PQgetvalue(result, i, 4)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* print any extended statistics */ if (pset.sversion >= 140000) @@ -3025,115 +3024,115 @@ describeOneTableDetails(const char *schemaname, } /* print any publications */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get publications that publish this table")); - if (pset.sversion >= 150000) + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get publications that publish this table")); + if (pset.sversion >= 150000) + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" + " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" + "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" + "UNION\n" + "SELECT pubname\n" + " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" + " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" + " (SELECT pg_catalog.string_agg(attname, ', ')\n" + " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" + " pg_catalog.pg_attribute\n" + " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" + " ELSE NULL END) " + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" + "WHERE pr.prrelid = '%s'\n", + oid, oid, oid); + + if (pset.sversion >= 190000) { + /* + * Skip entries where this relation appears in the + * publication's EXCEPT list. + */ appendPQExpBuffer(&buf, + " AND NOT pr.prexcept\n" + "UNION\n" "SELECT pubname\n" " , NULL\n" " , NULL\n" "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" - " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" - "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" - "UNION\n" - "SELECT pubname\n" - " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" - " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" - " (SELECT pg_catalog.string_agg(attname, ', ')\n" - " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" - " pg_catalog.pg_attribute\n" - " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" - " ELSE NULL END) " - "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" - "WHERE pr.prrelid = '%s'\n", + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + " AND NOT EXISTS (\n" + " SELECT 1\n" + " FROM pg_catalog.pg_publication_rel pr\n" + " WHERE pr.prpubid = p.oid AND\n" + " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" + "ORDER BY 1;", oid, oid, oid); - - if (pset.sversion >= 190000) - { - /* - * Skip entries where this relation appears in the - * publication's EXCEPT list. - */ - appendPQExpBuffer(&buf, - " AND NOT pr.prexcept\n" - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - " AND NOT EXISTS (\n" - " SELECT 1\n" - " FROM pg_catalog.pg_publication_rel pr\n" - " WHERE pr.prpubid = p.oid AND\n" - " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" - "ORDER BY 1;", - oid, oid, oid); - } - else - { - appendPQExpBuffer(&buf, - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - "ORDER BY 1;", - oid); - } } else { appendPQExpBuffer(&buf, + "UNION\n" "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - "WHERE pr.prrelid = '%s'\n" - "UNION ALL\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" + " , NULL\n" + " , NULL\n" "FROM pg_catalog.pg_publication p\n" "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" "ORDER BY 1;", - oid, oid); + oid); } + } + else + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + "WHERE pr.prrelid = '%s'\n" + "UNION ALL\n" + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + "ORDER BY 1;", + oid, oid); + } - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - if (tuples > 0) - printTableAddFooter(&cont, _("Included in publications:")); + if (tuples > 0) + printTableAddFooter(&cont, _("Included in publications:")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " \"%s\"", + PQgetvalue(result, i, 0)); - /* column list (if any) */ - if (!PQgetisnull(result, i, 2)) - appendPQExpBuffer(&buf, " (%s)", - PQgetvalue(result, i, 2)); + /* column list (if any) */ + if (!PQgetisnull(result, i, 2)) + appendPQExpBuffer(&buf, " (%s)", + PQgetvalue(result, i, 2)); - /* row filter (if any) */ - if (!PQgetisnull(result, i, 1)) - appendPQExpBuffer(&buf, " WHERE %s", - PQgetvalue(result, i, 1)); + /* row filter (if any) */ + if (!PQgetisnull(result, i, 1)) + appendPQExpBuffer(&buf, " WHERE %s", + PQgetvalue(result, i, 1)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* Print publications where the table is in the EXCEPT clause */ if (pset.sversion >= 190000) @@ -3805,7 +3804,7 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) ncols++; } appendPQExpBufferStr(&buf, "\n, r.rolreplication"); - appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); + appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_roles r\n"); @@ -3860,8 +3859,8 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) if (strcmp(PQgetvalue(res, i, (verbose ? 9 : 8)), "t") == 0) add_role_attribute(&buf, _("Replication")); - if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) - add_role_attribute(&buf, _("Bypass RLS")); + if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) + add_role_attribute(&buf, _("Bypass RLS")); conns = atoi(PQgetvalue(res, i, 6)); if (conns >= 0) @@ -5155,14 +5154,14 @@ listCollations(const char *pattern, bool verbose, bool showSystem) gettext_noop("Schema"), gettext_noop("Name")); - appendPQExpBuffer(&buf, - " CASE c.collprovider " - "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " - "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " - "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " - "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " - "END AS \"%s\",\n", - gettext_noop("Provider")); + appendPQExpBuffer(&buf, + " CASE c.collprovider " + "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " + "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " + "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " + "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " + "END AS \"%s\",\n", + gettext_noop("Provider")); appendPQExpBuffer(&buf, " c.collcollate AS \"%s\",\n" -- 2.50.1 (Apple Git-155) --aHl3HfeiUuO3zeNC-- ^ permalink raw reply [nested|flat] 59+ messages in thread
* [PATCH v6 4/4] run pgindent and pgperltidy @ 2026-06-30 18:24 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 59+ messages in thread From: Nathan Bossart @ 2026-06-30 18:24 UTC (permalink / raw) --- src/bin/pg_dump/pg_dump.c | 464 ++++++++++----------- src/bin/pg_dump/pg_dumpall.c | 30 +- src/bin/pg_upgrade/check.c | 16 +- src/bin/pg_upgrade/controldata.c | 2 +- src/bin/pg_upgrade/exec.c | 8 +- src/bin/pg_upgrade/multixact_rewrite.c | 80 ++-- src/bin/pg_upgrade/pg_upgrade.c | 34 +- src/bin/pg_upgrade/relfilenumber.c | 54 +-- src/bin/pg_upgrade/t/006_transfer_modes.pl | 33 +- src/bin/psql/command.c | 29 +- src/bin/psql/describe.c | 461 ++++++++++---------- 11 files changed, 601 insertions(+), 610 deletions(-) diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 65bd15ebfd2..5673268b467 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -1491,8 +1491,8 @@ setup_connection(Archive *AH, const char *dumpencoding, * Disable timeouts if supported. */ ExecuteSqlStatement(AH, "SET statement_timeout = 0"); - ExecuteSqlStatement(AH, "SET lock_timeout = 0"); - ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); + ExecuteSqlStatement(AH, "SET lock_timeout = 0"); + ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); if (AH->remoteVersion >= 170000) ExecuteSqlStatement(AH, "SET transaction_timeout = 0"); @@ -1505,10 +1505,10 @@ setup_connection(Archive *AH, const char *dumpencoding, /* * Adjust row-security mode, if supported. */ - if (dopt->enable_row_security) - ExecuteSqlStatement(AH, "SET row_security = on"); - else - ExecuteSqlStatement(AH, "SET row_security = off"); + if (dopt->enable_row_security) + ExecuteSqlStatement(AH, "SET row_security = on"); + else + ExecuteSqlStatement(AH, "SET row_security = off"); /* * For security reasons, we restrict the expansion of non-system views and @@ -1933,10 +1933,9 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) addObjectDependency(dobj, ext->dobj.dumpId); /* - * Mark the member object to have any non-initial ACLs - * dumped. (Any initial ACLs will be removed later, using data from - * pg_init_privs, so that we'll dump only the delta from the extension's - * initial setup.) + * Mark the member object to have any non-initial ACLs dumped. (Any + * initial ACLs will be removed later, using data from pg_init_privs, so + * that we'll dump only the delta from the extension's initial setup.) * * In binary upgrades, we still dump all components of the members * individually, since the idea is to exactly reproduce the database @@ -1953,7 +1952,7 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) if (fout->dopt->binary_upgrade) dobj->dump = ext->dobj.dump; else - dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); + dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); return true; } @@ -1987,9 +1986,9 @@ selectDumpableNamespace(NamespaceInfo *nsinfo, Archive *fout) else if (strcmp(nsinfo->dobj.name, "pg_catalog") == 0) { /* - * We dump out any ACLs defined in pg_catalog, if - * they are interesting (and not the original ACLs which were set at - * initdb time, see pg_init_privs). + * We dump out any ACLs defined in pg_catalog, if they are interesting + * (and not the original ACLs which were set at initdb time, see + * pg_init_privs). */ nsinfo->dobj.dump_contains = nsinfo->dobj.dump = DUMP_COMPONENT_ACL; } @@ -3296,7 +3295,7 @@ dumpDatabase(Archive *fout) "datcollate, datctype, datfrozenxid, " "datacl, acldefault('d', datdba) AS acldefault, " "datistemplate, datconnlimit, "); - appendPQExpBufferStr(dbQry, "datminmxid, "); + appendPQExpBufferStr(dbQry, "datminmxid, "); if (fout->remoteVersion >= 170000) appendPQExpBufferStr(dbQry, "datlocprovider, datlocale, datcollversion, "); else if (fout->remoteVersion >= 150000) @@ -3638,11 +3637,11 @@ dumpDatabase(Archive *fout) ii_oid, ii_relminmxid; - appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" - "FROM pg_catalog.pg_class\n" - "WHERE oid IN (%u, %u, %u, %u);\n", - LargeObjectRelationId, LargeObjectLOidPNIndexId, - LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); + appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" + "FROM pg_catalog.pg_class\n" + "WHERE oid IN (%u, %u, %u, %u);\n", + LargeObjectRelationId, LargeObjectLOidPNIndexId, + LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); lo_res = ExecuteSqlQuery(fout, loFrozenQry->data, PGRES_TUPLES_OK); @@ -4274,7 +4273,7 @@ getPolicies(Archive *fout, TableInfo tblinfo[], int numTables) printfPQExpBuffer(query, "SELECT pol.oid, pol.tableoid, pol.polrelid, pol.polname, pol.polcmd, "); - appendPQExpBufferStr(query, "pol.polpermissive, "); + appendPQExpBufferStr(query, "pol.polpermissive, "); appendPQExpBuffer(query, "CASE WHEN pol.polroles = '{0}' THEN NULL ELSE " " pg_catalog.array_to_string(ARRAY(SELECT pg_catalog.quote_ident(rolname) from pg_catalog.pg_roles WHERE oid = ANY(pol.polroles)), ', ') END AS polroles, " @@ -6633,9 +6632,9 @@ getAccessMethods(Archive *fout) * Select all access methods from pg_am table. */ appendPQExpBufferStr(query, "SELECT tableoid, oid, amname, "); - appendPQExpBufferStr(query, - "amtype, " - "amhandler::pg_catalog.regproc AS amhandler "); + appendPQExpBufferStr(query, + "amtype, " + "amhandler::pg_catalog.regproc AS amhandler "); appendPQExpBufferStr(query, "FROM pg_am"); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6827,35 +6826,35 @@ getAggregates(Archive *fout) * Find all interesting aggregates. See comment in getFuncs() for the * rationale behind the filtering logic. */ - agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" - : "p.proisagg"); + agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" + : "p.proisagg"); - appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " - "p.proname AS aggname, " - "p.pronamespace AS aggnamespace, " - "p.pronargs, p.proargtypes, " - "p.proowner, " - "p.proacl AS aggacl, " - "acldefault('f', p.proowner) AS acldefault " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s AND (" - "p.pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog') OR " - "p.proacl IS DISTINCT FROM pip.initprivs", - agg_check); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - " OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); - appendPQExpBufferChar(query, ')'); + appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " + "p.proname AS aggname, " + "p.pronamespace AS aggnamespace, " + "p.pronargs, p.proargtypes, " + "p.proowner, " + "p.proacl AS aggacl, " + "acldefault('f', p.proowner) AS acldefault " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s AND (" + "p.pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog') OR " + "p.proacl IS DISTINCT FROM pip.initprivs", + agg_check); + if (dopt->binary_upgrade) + appendPQExpBufferStr(query, + " OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6957,53 +6956,53 @@ getFuncs(Archive *fout) * include them, since we want to dump extension members individually in * that mode. Also, if they are used by casts or transforms then we need * to gather the information about them, though they won't be dumped if - * they are built-in. Also, include functions in - * pg_catalog if they have an ACL different from what's shown in - * pg_init_privs (so we have to join to pg_init_privs; annoying). + * they are built-in. Also, include functions in pg_catalog if they have + * an ACL different from what's shown in pg_init_privs (so we have to join + * to pg_init_privs; annoying). */ - not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" - : "NOT p.proisagg"); + not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" + : "NOT p.proisagg"); - appendPQExpBuffer(query, - "SELECT p.tableoid, p.oid, p.proname, p.prolang, " - "p.pronargs, p.proargtypes, p.prorettype, " - "p.proacl, " - "acldefault('f', p.proowner) AS acldefault, " - "p.pronamespace, " - "p.proowner " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s" - "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " - "WHERE classid = 'pg_proc'::regclass AND " - "objid = p.oid AND deptype = 'i')" - "\n AND (" - "\n pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog')" - "\n OR EXISTS (SELECT 1 FROM pg_cast" - "\n WHERE pg_cast.oid > %u " - "\n AND p.oid = pg_cast.castfunc)" - "\n OR EXISTS (SELECT 1 FROM pg_transform" - "\n WHERE pg_transform.oid > %u AND " - "\n (p.oid = pg_transform.trffromsql" - "\n OR p.oid = pg_transform.trftosql))", - not_agg_check, - g_last_builtin_oid, - g_last_builtin_oid); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); + appendPQExpBuffer(query, + "SELECT p.tableoid, p.oid, p.proname, p.prolang, " + "p.pronargs, p.proargtypes, p.prorettype, " + "p.proacl, " + "acldefault('f', p.proowner) AS acldefault, " + "p.pronamespace, " + "p.proowner " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s" + "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " + "WHERE classid = 'pg_proc'::regclass AND " + "objid = p.oid AND deptype = 'i')" + "\n AND (" + "\n pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog')" + "\n OR EXISTS (SELECT 1 FROM pg_cast" + "\n WHERE pg_cast.oid > %u " + "\n AND p.oid = pg_cast.castfunc)" + "\n OR EXISTS (SELECT 1 FROM pg_transform" + "\n WHERE pg_transform.oid > %u AND " + "\n (p.oid = pg_transform.trffromsql" + "\n OR p.oid = pg_transform.trftosql))", + not_agg_check, + g_last_builtin_oid, + g_last_builtin_oid); + if (dopt->binary_upgrade) appendPQExpBufferStr(query, - "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); - appendPQExpBufferChar(query, ')'); + "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferStr(query, + "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -7252,31 +7251,31 @@ getTables(Archive *fout, int *numTables) appendPQExpBufferStr(query, "c.relhasoids, "); - appendPQExpBufferStr(query, - "c.relispopulated, "); + appendPQExpBufferStr(query, + "c.relispopulated, "); - appendPQExpBufferStr(query, - "c.relreplident, "); + appendPQExpBufferStr(query, + "c.relreplident, "); - appendPQExpBufferStr(query, - "c.relrowsecurity, c.relforcerowsecurity, "); + appendPQExpBufferStr(query, + "c.relrowsecurity, c.relforcerowsecurity, "); - appendPQExpBufferStr(query, - "c.relminmxid, tc.relminmxid AS tminmxid, "); + appendPQExpBufferStr(query, + "c.relminmxid, tc.relminmxid AS tminmxid, "); - appendPQExpBufferStr(query, - "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); + appendPQExpBufferStr(query, + "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); - appendPQExpBufferStr(query, - "am.amname, "); + appendPQExpBufferStr(query, + "am.amname, "); - appendPQExpBufferStr(query, - "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); + appendPQExpBufferStr(query, + "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); - appendPQExpBufferStr(query, - "c.relispartition AS ispartition "); + appendPQExpBufferStr(query, + "c.relispartition AS ispartition "); /* * Left join to pg_depend to pick up dependency info linking sequences to @@ -7296,8 +7295,8 @@ getTables(Archive *fout, int *numTables) /* * Left join to pg_am to pick up the amname. */ - appendPQExpBufferStr(query, - "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); + appendPQExpBufferStr(query, + "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); /* * We purposefully ignore toast OIDs for partitioned tables; the reason is @@ -7868,8 +7867,8 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables) "t.reloptions AS indreloptions, "); - appendPQExpBufferStr(query, - "i.indisreplident, "); + appendPQExpBufferStr(query, + "i.indisreplident, "); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -9313,8 +9312,8 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables) appendPQExpBufferStr(q, "'' AS attcompression,\n"); - appendPQExpBufferStr(q, - "a.attidentity,\n"); + appendPQExpBufferStr(q, + "a.attidentity,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(q, @@ -10717,73 +10716,73 @@ getAdditionalACLs(Archive *fout) PQclear(res); /* Fetch initial-privileges data */ - printfPQExpBuffer(query, - "SELECT objoid, classoid, objsubid, privtype, initprivs " - "FROM pg_init_privs"); + printfPQExpBuffer(query, + "SELECT objoid, classoid, objsubid, privtype, initprivs " + "FROM pg_init_privs"); - res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); + res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); - ntups = PQntuples(res); - for (i = 0; i < ntups; i++) - { - Oid objoid = atooid(PQgetvalue(res, i, 0)); - Oid classoid = atooid(PQgetvalue(res, i, 1)); - int objsubid = atoi(PQgetvalue(res, i, 2)); - char privtype = *(PQgetvalue(res, i, 3)); - char *initprivs = PQgetvalue(res, i, 4); - CatalogId objId; - DumpableObject *dobj; + ntups = PQntuples(res); + for (i = 0; i < ntups; i++) + { + Oid objoid = atooid(PQgetvalue(res, i, 0)); + Oid classoid = atooid(PQgetvalue(res, i, 1)); + int objsubid = atoi(PQgetvalue(res, i, 2)); + char privtype = *(PQgetvalue(res, i, 3)); + char *initprivs = PQgetvalue(res, i, 4); + CatalogId objId; + DumpableObject *dobj; - objId.tableoid = classoid; - objId.oid = objoid; - dobj = findObjectByCatalogId(objId); - /* OK to ignore entries we haven't got a DumpableObject for */ - if (dobj) + objId.tableoid = classoid; + objId.oid = objoid; + dobj = findObjectByCatalogId(objId); + /* OK to ignore entries we haven't got a DumpableObject for */ + if (dobj) + { + /* Cope with sub-object initprivs */ + if (objsubid != 0) { - /* Cope with sub-object initprivs */ - if (objsubid != 0) - { - if (dobj->objType == DO_TABLE) - { - /* For a column initprivs, set the table's ACL flags */ - dobj->components |= DUMP_COMPONENT_ACL; - ((TableInfo *) dobj)->hascolumnACLs = true; - } - else - pg_log_warning("unsupported pg_init_privs entry: %u %u %d", - classoid, objoid, objsubid); - continue; - } - - /* - * We ignore any pg_init_privs.initprivs entry for the public - * schema, as explained in getNamespaces(). - */ - if (dobj->objType == DO_NAMESPACE && - strcmp(dobj->name, "public") == 0) - continue; - - /* Else it had better be of a type we think has ACLs */ - if (dobj->objType == DO_NAMESPACE || - dobj->objType == DO_TYPE || - dobj->objType == DO_FUNC || - dobj->objType == DO_AGG || - dobj->objType == DO_TABLE || - dobj->objType == DO_PROCLANG || - dobj->objType == DO_FDW || - dobj->objType == DO_FOREIGN_SERVER) + if (dobj->objType == DO_TABLE) { - DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; - - daobj->dacl.privtype = privtype; - daobj->dacl.initprivs = pstrdup(initprivs); + /* For a column initprivs, set the table's ACL flags */ + dobj->components |= DUMP_COMPONENT_ACL; + ((TableInfo *) dobj)->hascolumnACLs = true; } else pg_log_warning("unsupported pg_init_privs entry: %u %u %d", classoid, objoid, objsubid); + continue; + } + + /* + * We ignore any pg_init_privs.initprivs entry for the public + * schema, as explained in getNamespaces(). + */ + if (dobj->objType == DO_NAMESPACE && + strcmp(dobj->name, "public") == 0) + continue; + + /* Else it had better be of a type we think has ACLs */ + if (dobj->objType == DO_NAMESPACE || + dobj->objType == DO_TYPE || + dobj->objType == DO_FUNC || + dobj->objType == DO_AGG || + dobj->objType == DO_TABLE || + dobj->objType == DO_PROCLANG || + dobj->objType == DO_FDW || + dobj->objType == DO_FOREIGN_SERVER) + { + DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; + + daobj->dacl.privtype = privtype; + daobj->dacl.initprivs = pstrdup(initprivs); } + else + pg_log_warning("unsupported pg_init_privs entry: %u %u %d", + classoid, objoid, objsubid); } - PQclear(res); + } + PQclear(res); destroyPQExpBuffer(query); } @@ -11128,8 +11127,8 @@ dumpRelationStats_dumper(Archive *fout, const void *userArg, const TocEntry *te) * The results must be in the order of the relations supplied in the * parameters to ensure we remain in sync as we walk through the TOC. * - * For versions before 19, the redundant filter clause on s.tablename = - * ANY(...) seems sufficient to convince the planner to use + * For versions before 19, the redundant filter clause on s.tablename + * = ANY(...) seems sufficient to convince the planner to use * pg_class_relname_nsp_index, which avoids a full scan of pg_stats. * In newer versions, pg_stats returns the table OIDs, eliminating the * need for that hack. @@ -13469,11 +13468,11 @@ dumpFunc(Archive *fout, const FuncInfo *finfo) "pg_catalog.pg_get_function_result(p.oid) AS funcresult,\n" "proleakproof,\n"); - appendPQExpBufferStr(query, - "array_to_string(protrftypes, ' ') AS protrftypes,\n"); + appendPQExpBufferStr(query, + "array_to_string(protrftypes, ' ') AS protrftypes,\n"); - appendPQExpBufferStr(query, - "proparallel,\n"); + appendPQExpBufferStr(query, + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -14963,9 +14962,9 @@ dumpCollation(Archive *fout, const CollInfo *collinfo) /* Get collation-specific details */ appendPQExpBufferStr(query, "SELECT "); - appendPQExpBufferStr(query, - "collprovider, " - "collversion, "); + appendPQExpBufferStr(query, + "collprovider, " + "collversion, "); if (fout->remoteVersion >= 120000) appendPQExpBufferStr(query, @@ -15372,23 +15371,23 @@ dumpAgg(Archive *fout, const AggInfo *agginfo) "pg_catalog.pg_get_function_arguments(p.oid) AS funcargs,\n" "pg_catalog.pg_get_function_identity_arguments(p.oid) AS funciargs,\n"); - appendPQExpBufferStr(query, - "aggkind,\n" - "aggmtransfn,\n" - "aggminvtransfn,\n" - "aggmfinalfn,\n" - "aggmtranstype::pg_catalog.regtype,\n" - "aggfinalextra,\n" - "aggmfinalextra,\n" - "aggtransspace,\n" - "aggmtransspace,\n" - "aggminitval,\n"); + appendPQExpBufferStr(query, + "aggkind,\n" + "aggmtransfn,\n" + "aggminvtransfn,\n" + "aggmfinalfn,\n" + "aggmtranstype::pg_catalog.regtype,\n" + "aggfinalextra,\n" + "aggmfinalextra,\n" + "aggtransspace,\n" + "aggmtransspace,\n" + "aggminitval,\n"); - appendPQExpBufferStr(query, - "aggcombinefn,\n" - "aggserialfn,\n" - "aggdeserialfn,\n" - "proparallel,\n"); + appendPQExpBufferStr(query, + "aggcombinefn,\n" + "aggserialfn,\n" + "aggdeserialfn,\n" + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -16848,30 +16847,30 @@ dumpTable(Archive *fout, const TableInfo *tbinfo) appendPQExpBufferStr(query, "PREPARE getColumnACLs(pg_catalog.oid) AS\n"); - /* - * In principle we should call acldefault('c', relowner) to - * get the default ACL for a column. However, we don't - * currently store the numeric OID of the relowner in - * TableInfo. We could convert the owner name using regrole, - * but that creates a risk of failure due to concurrent role - * renames. Given that the default ACL for columns is empty - * and is likely to stay that way, it's not worth extra cycles - * and risk to avoid hard-wiring that knowledge here. - */ - appendPQExpBufferStr(query, - "SELECT at.attname, " - "at.attacl, " - "'{}' AS acldefault, " - "pip.privtype, pip.initprivs " - "FROM pg_catalog.pg_attribute at " - "LEFT JOIN pg_catalog.pg_init_privs pip ON " - "(at.attrelid = pip.objoid " - "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " - "AND at.attnum = pip.objsubid) " - "WHERE at.attrelid = $1 AND " - "NOT at.attisdropped " - "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " - "ORDER BY at.attnum"); + /* + * In principle we should call acldefault('c', relowner) to get + * the default ACL for a column. However, we don't currently + * store the numeric OID of the relowner in TableInfo. We could + * convert the owner name using regrole, but that creates a risk + * of failure due to concurrent role renames. Given that the + * default ACL for columns is empty and is likely to stay that + * way, it's not worth extra cycles and risk to avoid hard-wiring + * that knowledge here. + */ + appendPQExpBufferStr(query, + "SELECT at.attname, " + "at.attacl, " + "'{}' AS acldefault, " + "pip.privtype, pip.initprivs " + "FROM pg_catalog.pg_attribute at " + "LEFT JOIN pg_catalog.pg_init_privs pip ON " + "(at.attrelid = pip.objoid " + "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " + "AND at.attnum = pip.objsubid) " + "WHERE at.attrelid = $1 AND " + "NOT at.attisdropped " + "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " + "ORDER BY at.attnum"); ExecuteSqlStatement(fout, query->data); @@ -19165,7 +19164,7 @@ collectSequences(Archive *fout) * pg_get_sequence_data(), but we only do so for non-schema-only dumps. */ if (fout->remoteVersion < 180000 || - (!fout->dopt->dumpData && !fout->dopt->sequence_data)) + (!fout->dopt->dumpData && !fout->dopt->sequence_data)) query = "SELECT seqrelid, format_type(seqtypid, NULL), " "seqstart, seqincrement, " "seqmax, seqmin, " @@ -19227,15 +19226,14 @@ dumpSequence(Archive *fout, const TableInfo *tbinfo) qseqname = pg_strdup(fmtId(tbinfo->dobj.name)); /* - * The sequence information is gathered in a sorted - * table before any calls to dumpSequence(). See collectSequences() for - * more information. + * The sequence information is gathered in a sorted table before any calls + * to dumpSequence(). See collectSequences() for more information. */ - Assert(sequences); + Assert(sequences); - key.oid = tbinfo->dobj.catId.oid; - seq = bsearch(&key, sequences, nsequences, - sizeof(SequenceItem), SequenceItemCmp); + key.oid = tbinfo->dobj.catId.oid; + seq = bsearch(&key, sequences, nsequences, + sizeof(SequenceItem), SequenceItemCmp); /* Calculate default limits for a sequence of this type */ is_ascending = (seq->incby >= 0); diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c index e68937c9934..afcd9a218d8 100644 --- a/src/bin/pg_dump/pg_dumpall.c +++ b/src/bin/pg_dump/pg_dumpall.c @@ -785,11 +785,11 @@ dropRoles(PGconn *conn) int i_rolname; int i; - printfPQExpBuffer(buf, - "SELECT rolname " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 1", role_catalog); + printfPQExpBuffer(buf, + "SELECT rolname " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 1", role_catalog); res = executeQuery(conn, buf->data); @@ -843,16 +843,16 @@ dumpRoles(PGconn *conn) * Notes: rolconfig is dumped later, and pg_authid must be used for * extracting rolcomment regardless of role_catalog. */ - printfPQExpBuffer(buf, - "SELECT oid, rolname, rolsuper, rolinherit, " - "rolcreaterole, rolcreatedb, " - "rolcanlogin, rolconnlimit, rolpassword, " - "rolvaliduntil, rolreplication, rolbypassrls, " - "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " - "rolname = current_user AS is_current_user " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 2", role_catalog); + printfPQExpBuffer(buf, + "SELECT oid, rolname, rolsuper, rolinherit, " + "rolcreaterole, rolcreatedb, " + "rolcanlogin, rolconnlimit, rolpassword, " + "rolvaliduntil, rolreplication, rolbypassrls, " + "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " + "rolname = current_user AS is_current_user " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 2", role_catalog); res = executeQuery(conn, buf->data); diff --git a/src/bin/pg_upgrade/check.c b/src/bin/pg_upgrade/check.c index 786c1474829..f725f5ee3e2 100644 --- a/src/bin/pg_upgrade/check.c +++ b/src/bin/pg_upgrade/check.c @@ -1475,15 +1475,15 @@ check_for_incompatible_polymorphics(ClusterInfo *cluster) ", 'array_cat(anyarray,anyarray)'" ", 'array_prepend(anyelement,anyarray)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_remove(anyarray,anyelement)'" - ", 'array_replace(anyarray,anyelement,anyelement)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_remove(anyarray,anyelement)'" + ", 'array_replace(anyarray,anyelement,anyelement)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_position(anyarray,anyelement)'" - ", 'array_position(anyarray,anyelement,integer)'" - ", 'array_positions(anyarray,anyelement)'" - ", 'width_bucket(anyelement,anyarray)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_position(anyarray,anyelement)'" + ", 'array_position(anyarray,anyelement,integer)'" + ", 'array_positions(anyarray,anyelement)'" + ", 'width_bucket(anyelement,anyarray)'"); /* * The query below hardcodes FirstNormalObjectId as 16384 rather than diff --git a/src/bin/pg_upgrade/controldata.c b/src/bin/pg_upgrade/controldata.c index 8f81c9e9582..02ea02df60f 100644 --- a/src/bin/pg_upgrade/controldata.c +++ b/src/bin/pg_upgrade/controldata.c @@ -228,7 +228,7 @@ get_control_data(ClusterInfo *cluster) p++; /* remove ':' char */ cluster->controldata.chkpnt_nxtepoch = str2uint(p); - p = strchr(p, ':'); + p = strchr(p, ':'); if (p == NULL || strlen(p) <= 1) pg_fatal("%d: controldata retrieval problem", __LINE__); diff --git a/src/bin/pg_upgrade/exec.c b/src/bin/pg_upgrade/exec.c index 44355feea30..a1bdbf373e3 100644 --- a/src/bin/pg_upgrade/exec.c +++ b/src/bin/pg_upgrade/exec.c @@ -55,7 +55,7 @@ get_bin_version(ClusterInfo *cluster) if (sscanf(cmd_output, "%*s %*s %d.%d", &v1, &v2) < 1) pg_fatal("could not get pg_ctl version output from %s", cmd); - cluster->bin_version = v1 * 10000; + cluster->bin_version = v1 * 10000; } @@ -344,8 +344,8 @@ check_data_dir(ClusterInfo *cluster) check_single_dir(pg_data, "pg_subtrans"); check_single_dir(pg_data, PG_TBLSPC_DIR); check_single_dir(pg_data, "pg_twophase"); - check_single_dir(pg_data, "pg_wal"); - check_single_dir(pg_data, "pg_xact"); + check_single_dir(pg_data, "pg_wal"); + check_single_dir(pg_data, "pg_xact"); } @@ -385,7 +385,7 @@ check_bin_dir(ClusterInfo *cluster, bool check_versions) */ get_bin_version(cluster); - check_exec(cluster->bindir, "pg_resetwal", check_versions); + check_exec(cluster->bindir, "pg_resetwal", check_versions); if (cluster == &new_cluster) { diff --git a/src/bin/pg_upgrade/multixact_rewrite.c b/src/bin/pg_upgrade/multixact_rewrite.c index c45b3183684..c7a1416494d 100644 --- a/src/bin/pg_upgrade/multixact_rewrite.c +++ b/src/bin/pg_upgrade/multixact_rewrite.c @@ -61,52 +61,52 @@ rewrite_multixacts(MultiXactId from_multi, MultiXactId to_multi) * Convert old multixids, if needed, by reading them one-by-one from the * old cluster. */ - old_reader = AllocOldMultiXactRead(old_cluster.pgdata, - old_cluster.controldata.chkpnt_nxtmulti, - old_cluster.controldata.chkpnt_nxtmxoff); + old_reader = AllocOldMultiXactRead(old_cluster.pgdata, + old_cluster.controldata.chkpnt_nxtmulti, + old_cluster.controldata.chkpnt_nxtmxoff); - for (MultiXactId multi = from_multi; multi != to_multi;) - { - MultiXactMember member; - bool multixid_valid; - - /* - * Read this multixid's members. - * - * Locking-only XIDs that may be part of multi-xids don't matter - * after upgrade, as there can be no transactions running across - * upgrade. So as a small optimization, we only read one member - * from each multixid: the one updating one, or if there was no - * update, arbitrarily the first locking xid. - */ - multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); + for (MultiXactId multi = from_multi; multi != to_multi;) + { + MultiXactMember member; + bool multixid_valid; - /* - * Write the new offset to pg_multixact/offsets. - * - * Even if this multixid is invalid, we still need to write its - * offset if the *previous* multixid was valid. That's because - * when reading a multixid, the number of members is calculated - * from the difference between the two offsets. - */ - RecordMultiXactOffset(offsets_writer, multi, - (multixid_valid || prev_multixid_valid) ? next_offset : 0); + /* + * Read this multixid's members. + * + * Locking-only XIDs that may be part of multi-xids don't matter after + * upgrade, as there can be no transactions running across upgrade. So + * as a small optimization, we only read one member from each + * multixid: the one updating one, or if there was no update, + * arbitrarily the first locking xid. + */ + multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); - /* Write the members */ - if (multixid_valid) - { - RecordMultiXactMembers(members_writer, next_offset, 1, &member); - next_offset += 1; - } + /* + * Write the new offset to pg_multixact/offsets. + * + * Even if this multixid is invalid, we still need to write its offset + * if the *previous* multixid was valid. That's because when reading + * a multixid, the number of members is calculated from the difference + * between the two offsets. + */ + RecordMultiXactOffset(offsets_writer, multi, + (multixid_valid || prev_multixid_valid) ? next_offset : 0); - /* Advance to next multixid, handling wraparound */ - multi++; - if (multi < FirstMultiXactId) - multi = FirstMultiXactId; - prev_multixid_valid = multixid_valid; + /* Write the members */ + if (multixid_valid) + { + RecordMultiXactMembers(members_writer, next_offset, 1, &member); + next_offset += 1; } - FreeOldMultiXactReader(old_reader); + /* Advance to next multixid, handling wraparound */ + multi++; + if (multi < FirstMultiXactId) + multi = FirstMultiXactId; + prev_multixid_valid = multixid_valid; + } + + FreeOldMultiXactReader(old_reader); /* Write the final 'next' offset to the last SLRU page */ RecordMultiXactOffset(offsets_writer, to_multi, diff --git a/src/bin/pg_upgrade/pg_upgrade.c b/src/bin/pg_upgrade/pg_upgrade.c index c6af9035665..7366fd4627c 100644 --- a/src/bin/pg_upgrade/pg_upgrade.c +++ b/src/bin/pg_upgrade/pg_upgrade.c @@ -833,7 +833,7 @@ copy_xact_xlog_xid(void) * Determine the range of multixacts to convert. */ nxtmulti = old_cluster.controldata.chkpnt_nxtmulti; - oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; + oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; /* handle wraparound */ if (nxtmulti < FirstMultiXactId) nxtmulti = FirstMultiXactId; @@ -898,15 +898,15 @@ set_frozenxids(void) int i_datname; int i_datallowconn; - prep_status("Setting frozenxid and minmxid counters in new cluster"); + prep_status("Setting frozenxid and minmxid counters in new cluster"); conn_template1 = connectToServer(&new_cluster, "template1"); - /* set pg_database.datfrozenxid */ - PQclear(executeQueryOrDie(conn_template1, - "UPDATE pg_catalog.pg_database " - "SET datfrozenxid = '%u'", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_database.datfrozenxid */ + PQclear(executeQueryOrDie(conn_template1, + "UPDATE pg_catalog.pg_database " + "SET datfrozenxid = '%u'", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_database.datminmxid */ PQclear(executeQueryOrDie(conn_template1, @@ -942,16 +942,16 @@ set_frozenxids(void) conn = connectToServer(&new_cluster, datname); - /* set pg_class.relfrozenxid */ - PQclear(executeQueryOrDie(conn, - "UPDATE pg_catalog.pg_class " - "SET relfrozenxid = '%u' " - /* only heap, materialized view, and TOAST are vacuumed */ - "WHERE relkind IN (" - CppAsString2(RELKIND_RELATION) ", " - CppAsString2(RELKIND_MATVIEW) ", " - CppAsString2(RELKIND_TOASTVALUE) ")", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_class.relfrozenxid */ + PQclear(executeQueryOrDie(conn, + "UPDATE pg_catalog.pg_class " + "SET relfrozenxid = '%u' " + /* only heap, materialized view, and TOAST are vacuumed */ + "WHERE relkind IN (" + CppAsString2(RELKIND_RELATION) ", " + CppAsString2(RELKIND_MATVIEW) ", " + CppAsString2(RELKIND_TOASTVALUE) ")", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_class.relminmxid */ PQclear(executeQueryOrDie(conn, diff --git a/src/bin/pg_upgrade/relfilenumber.c b/src/bin/pg_upgrade/relfilenumber.c index ec2ff7acb21..6c467bdc8a5 100644 --- a/src/bin/pg_upgrade/relfilenumber.c +++ b/src/bin/pg_upgrade/relfilenumber.c @@ -587,32 +587,32 @@ transfer_relfile(FileNameMap *map, const char *type_suffix) /* Copying files might take some time, so give feedback. */ pg_log(PG_STATUS, "%s", old_file); - switch (user_opts.transfer_mode) - { - case TRANSFER_MODE_CLONE: - pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", - old_file, new_file); - cloneFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", - old_file, new_file); - copyFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY_FILE_RANGE: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", - old_file, new_file); - copyFileByRange(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_LINK: - pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", - old_file, new_file); - linkFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_SWAP: - /* swap mode is handled in its own code path */ - pg_fatal("should never happen"); - break; - } + switch (user_opts.transfer_mode) + { + case TRANSFER_MODE_CLONE: + pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", + old_file, new_file); + cloneFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", + old_file, new_file); + copyFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY_FILE_RANGE: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", + old_file, new_file); + copyFileByRange(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_LINK: + pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", + old_file, new_file); + linkFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_SWAP: + /* swap mode is handled in its own code path */ + pg_fatal("should never happen"); + break; + } } } diff --git a/src/bin/pg_upgrade/t/006_transfer_modes.pl b/src/bin/pg_upgrade/t/006_transfer_modes.pl index 9efa5dc863c..360d05c4b68 100644 --- a/src/bin/pg_upgrade/t/006_transfer_modes.pl +++ b/src/bin/pg_upgrade/t/006_transfer_modes.pl @@ -29,10 +29,8 @@ sub test_mode } $new->init(); - $new->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); - $old->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); + $new->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); + $old->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); # We can only test security labels if both the old and new installations # have dummy_seclabel. @@ -76,15 +74,14 @@ sub test_mode "CREATE TABLE test4 AS SELECT generate_series(400, 502)"); } - $old->safe_psql('postgres', - "CREATE TABLESPACE inplc_tblspc LOCATION ''"); - $old->safe_psql('postgres', - "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); - $old->safe_psql('postgres', - "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" - ); - $old->safe_psql('testdb3', - "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); + $old->safe_psql('postgres', "CREATE TABLESPACE inplc_tblspc LOCATION ''"); + $old->safe_psql('postgres', + "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); + $old->safe_psql('postgres', + "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" + ); + $old->safe_psql('testdb3', + "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); # While we are here, test handling of large objects. $old->safe_psql( @@ -152,12 +149,10 @@ sub test_mode } # Tests for in-place tablespaces. - $result = - $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); - is($result, '104', "test5 data after pg_upgrade $mode"); - $result = - $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); - is($result, '105', "test6 data after pg_upgrade $mode"); + $result = $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); + is($result, '104', "test5 data after pg_upgrade $mode"); + $result = $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); + is($result, '105', "test6 data after pg_upgrade $mode"); # Tests for large objects $result = $new->safe_psql('postgres', "SELECT lo_get(4532)"); diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index 44ef11d980e..c90bf8bbde2 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -6278,23 +6278,22 @@ get_create_object_cmd(EditableObjectType obj_type, Oid oid, * ensure the right view gets replaced. Also, check relation kind * to be sure it's a view. * - * Views may have WITH [LOCAL|CASCADED] - * CHECK OPTION. These are not part of the view definition - * returned by pg_get_viewdef() and so need to be retrieved - * separately. Materialized views may have - * arbitrary storage parameter reloptions. + * Views may have WITH [LOCAL|CASCADED] CHECK OPTION. These are + * not part of the view definition returned by pg_get_viewdef() + * and so need to be retrieved separately. Materialized views may + * have arbitrary storage parameter reloptions. */ printfPQExpBuffer(query, "/* %s */\n", _("Get view's definition and details")); - appendPQExpBuffer(query, - "SELECT nspname, relname, relkind, " - "pg_catalog.pg_get_viewdef(c.oid, true), " - "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " - "FROM pg_catalog.pg_class c " - "LEFT JOIN pg_catalog.pg_namespace n " - "ON c.relnamespace = n.oid WHERE c.oid = %u", - oid); + appendPQExpBuffer(query, + "SELECT nspname, relname, relkind, " + "pg_catalog.pg_get_viewdef(c.oid, true), " + "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " + "FROM pg_catalog.pg_class c " + "LEFT JOIN pg_catalog.pg_namespace n " + "ON c.relnamespace = n.oid WHERE c.oid = %u", + oid); break; } diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index ce99137c613..ac0c55e7aa5 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -387,19 +387,19 @@ describeFunctions(const char *functypes, const char *func_pattern, gettext_noop("stable"), gettext_noop("volatile"), gettext_noop("Volatility")); - appendPQExpBuffer(&buf, - ",\n CASE\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" - " END as \"%s\"", - gettext_noop("restricted"), - gettext_noop("safe"), - gettext_noop("unsafe"), - gettext_noop("Parallel")); + appendPQExpBuffer(&buf, + ",\n CASE\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" + " END as \"%s\"", + gettext_noop("restricted"), + gettext_noop("safe"), + gettext_noop("unsafe"), + gettext_noop("Parallel")); appendPQExpBuffer(&buf, ",\n pg_catalog.pg_get_userbyid(p.proowner) as \"%s\"" ",\n CASE WHEN prosecdef THEN '%s' ELSE '%s' END AS \"%s\"" @@ -599,8 +599,8 @@ describeFunctions(const char *functypes, const char *func_pattern, myopt.title = _("List of functions"); myopt.translate_header = true; - myopt.translate_columns = translate_columns; - myopt.n_translate_columns = lengthof(translate_columns); + myopt.translate_columns = translate_columns; + myopt.n_translate_columns = lengthof(translate_columns); printQuery(res, &myopt, pset.queryFout, false, pset.logfile); @@ -1086,38 +1086,38 @@ permissionsList(const char *pattern, bool showSystem) " ), E'\\n') AS \"%s\"", gettext_noop("Column privileges")); - appendPQExpBuffer(&buf, - ",\n pg_catalog.array_to_string(ARRAY(\n" - " SELECT polname\n" - " || CASE WHEN NOT polpermissive THEN\n" - " E' (RESTRICTIVE)'\n" - " ELSE '' END\n" - " || CASE WHEN polcmd != '*' THEN\n" - " E' (' || polcmd::pg_catalog.text || E'):'\n" - " ELSE E':'\n" - " END\n" - " || CASE WHEN polqual IS NOT NULL THEN\n" - " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" - " ELSE E''\n" - " END\n" - " || CASE WHEN polwithcheck IS NOT NULL THEN\n" - " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" - " ELSE E''\n" - " END" - " || CASE WHEN polroles <> '{0}' THEN\n" - " E'\\n to: ' || pg_catalog.array_to_string(\n" - " ARRAY(\n" - " SELECT rolname\n" - " FROM pg_catalog.pg_roles\n" - " WHERE oid = ANY (polroles)\n" - " ORDER BY 1\n" - " ), E', ')\n" - " ELSE E''\n" - " END\n" - " FROM pg_catalog.pg_policy pol\n" - " WHERE polrelid = c.oid), E'\\n')\n" - " AS \"%s\"", - gettext_noop("Policies")); + appendPQExpBuffer(&buf, + ",\n pg_catalog.array_to_string(ARRAY(\n" + " SELECT polname\n" + " || CASE WHEN NOT polpermissive THEN\n" + " E' (RESTRICTIVE)'\n" + " ELSE '' END\n" + " || CASE WHEN polcmd != '*' THEN\n" + " E' (' || polcmd::pg_catalog.text || E'):'\n" + " ELSE E':'\n" + " END\n" + " || CASE WHEN polqual IS NOT NULL THEN\n" + " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" + " ELSE E''\n" + " END\n" + " || CASE WHEN polwithcheck IS NOT NULL THEN\n" + " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" + " ELSE E''\n" + " END" + " || CASE WHEN polroles <> '{0}' THEN\n" + " E'\\n to: ' || pg_catalog.array_to_string(\n" + " ARRAY(\n" + " SELECT rolname\n" + " FROM pg_catalog.pg_roles\n" + " WHERE oid = ANY (polroles)\n" + " ORDER BY 1\n" + " ), E', ')\n" + " ELSE E''\n" + " END\n" + " FROM pg_catalog.pg_policy pol\n" + " WHERE polrelid = c.oid), E'\\n')\n" + " AS \"%s\"", + gettext_noop("Policies")); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_class c\n" " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n" @@ -1675,27 +1675,27 @@ describeOneTableDetails(const char *schemaname, char *footers[3] = {NULL, NULL, NULL}; printfPQExpBuffer(&buf, "/* %s */\n", _("Get sequence information")); - appendPQExpBuffer(&buf, - "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" - " seqstart AS \"%s\",\n" - " seqmin AS \"%s\",\n" - " seqmax AS \"%s\",\n" - " seqincrement AS \"%s\",\n" - " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" - " seqcache AS \"%s\"\n", - gettext_noop("Type"), - gettext_noop("Start"), - gettext_noop("Minimum"), - gettext_noop("Maximum"), - gettext_noop("Increment"), - gettext_noop("yes"), - gettext_noop("no"), - gettext_noop("Cycles?"), - gettext_noop("Cache")); - appendPQExpBuffer(&buf, - "FROM pg_catalog.pg_sequence\n" - "WHERE seqrelid = '%s';", - oid); + appendPQExpBuffer(&buf, + "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" + " seqstart AS \"%s\",\n" + " seqmin AS \"%s\",\n" + " seqmax AS \"%s\",\n" + " seqincrement AS \"%s\",\n" + " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" + " seqcache AS \"%s\"\n", + gettext_noop("Type"), + gettext_noop("Start"), + gettext_noop("Minimum"), + gettext_noop("Maximum"), + gettext_noop("Increment"), + gettext_noop("yes"), + gettext_noop("no"), + gettext_noop("Cycles?"), + gettext_noop("Cache")); + appendPQExpBuffer(&buf, + "FROM pg_catalog.pg_sequence\n" + "WHERE seqrelid = '%s';", + oid); res = PSQLexec(buf.data); if (!res) @@ -1913,7 +1913,7 @@ describeOneTableDetails(const char *schemaname, appendPQExpBufferStr(&buf, ",\n (SELECT c.collname FROM pg_catalog.pg_collation c, pg_catalog.pg_type t\n" " WHERE c.oid = a.attcollation AND t.oid = a.atttypid AND a.attcollation <> t.typcollation) AS attcollation"); attcoll_col = cols++; - appendPQExpBufferStr(&buf, ",\n a.attidentity"); + appendPQExpBufferStr(&buf, ",\n a.attidentity"); attidentity_col = cols++; if (pset.sversion >= 120000) appendPQExpBufferStr(&buf, ",\n a.attgenerated"); @@ -2326,7 +2326,7 @@ describeOneTableDetails(const char *schemaname, CppAsString2(CONSTRAINT_EXCLUSION) ") AND " "condeferred) AS condeferred,\n"); - appendPQExpBufferStr(&buf, "i.indisreplident,\n"); + appendPQExpBufferStr(&buf, "i.indisreplident,\n"); if (pset.sversion >= 150000) appendPQExpBufferStr(&buf, "i.indnullsnotdistinct,\n"); @@ -2431,7 +2431,7 @@ describeOneTableDetails(const char *schemaname, "pg_catalog.pg_get_indexdef(i.indexrelid, 0, true),\n " "pg_catalog.pg_get_constraintdef(con.oid, true), " "contype, condeferrable, condeferred"); - appendPQExpBufferStr(&buf, ", i.indisreplident"); + appendPQExpBufferStr(&buf, ", i.indisreplident"); appendPQExpBufferStr(&buf, ", c2.reltablespace"); if (pset.sversion >= 180000) appendPQExpBufferStr(&buf, ", con.conperiod"); @@ -2682,81 +2682,80 @@ describeOneTableDetails(const char *schemaname, PQclear(result); /* print any row-level policies */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get row-level policies for this table")); - appendPQExpBufferStr(&buf, "SELECT pol.polname,"); - appendPQExpBufferStr(&buf, - " pol.polpermissive,\n"); - appendPQExpBuffer(&buf, - " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" - " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" - " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" - " CASE pol.polcmd\n" - " WHEN 'r' THEN 'SELECT'\n" - " WHEN 'a' THEN 'INSERT'\n" - " WHEN 'w' THEN 'UPDATE'\n" - " WHEN 'd' THEN 'DELETE'\n" - " END AS cmd\n" - "FROM pg_catalog.pg_policy pol\n" - "WHERE pol.polrelid = '%s' ORDER BY 1;", - oid); + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get row-level policies for this table")); + appendPQExpBufferStr(&buf, "SELECT pol.polname,"); + appendPQExpBufferStr(&buf, + " pol.polpermissive,\n"); + appendPQExpBuffer(&buf, + " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" + " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" + " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" + " CASE pol.polcmd\n" + " WHEN 'r' THEN 'SELECT'\n" + " WHEN 'a' THEN 'INSERT'\n" + " WHEN 'w' THEN 'UPDATE'\n" + " WHEN 'd' THEN 'DELETE'\n" + " END AS cmd\n" + "FROM pg_catalog.pg_policy pol\n" + "WHERE pol.polrelid = '%s' ORDER BY 1;", + oid); - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - /* - * Handle cases where RLS is enabled and there are policies, or - * there aren't policies, or RLS isn't enabled but there are - * policies - */ - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies:")); + /* + * Handle cases where RLS is enabled and there are policies, or there + * aren't policies, or RLS isn't enabled but there are policies + */ + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies:")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled):")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled):")); - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); - if (!tableinfo.rowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (row security disabled):")); + if (!tableinfo.rowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (row security disabled):")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " POLICY \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " POLICY \"%s\"", + PQgetvalue(result, i, 0)); - if (*(PQgetvalue(result, i, 1)) == 'f') - appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); + if (*(PQgetvalue(result, i, 1)) == 'f') + appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); - if (!PQgetisnull(result, i, 5)) - appendPQExpBuffer(&buf, " FOR %s", - PQgetvalue(result, i, 5)); + if (!PQgetisnull(result, i, 5)) + appendPQExpBuffer(&buf, " FOR %s", + PQgetvalue(result, i, 5)); - if (!PQgetisnull(result, i, 2)) - { - appendPQExpBuffer(&buf, "\n TO %s", - PQgetvalue(result, i, 2)); - } + if (!PQgetisnull(result, i, 2)) + { + appendPQExpBuffer(&buf, "\n TO %s", + PQgetvalue(result, i, 2)); + } - if (!PQgetisnull(result, i, 3)) - appendPQExpBuffer(&buf, "\n USING (%s)", - PQgetvalue(result, i, 3)); + if (!PQgetisnull(result, i, 3)) + appendPQExpBuffer(&buf, "\n USING (%s)", + PQgetvalue(result, i, 3)); - if (!PQgetisnull(result, i, 4)) - appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", - PQgetvalue(result, i, 4)); + if (!PQgetisnull(result, i, 4)) + appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", + PQgetvalue(result, i, 4)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* print any extended statistics */ if (pset.sversion >= 140000) @@ -3025,115 +3024,115 @@ describeOneTableDetails(const char *schemaname, } /* print any publications */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get publications that publish this table")); - if (pset.sversion >= 150000) + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get publications that publish this table")); + if (pset.sversion >= 150000) + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" + " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" + "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" + "UNION\n" + "SELECT pubname\n" + " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" + " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" + " (SELECT pg_catalog.string_agg(attname, ', ')\n" + " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" + " pg_catalog.pg_attribute\n" + " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" + " ELSE NULL END) " + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" + "WHERE pr.prrelid = '%s'\n", + oid, oid, oid); + + if (pset.sversion >= 190000) { + /* + * Skip entries where this relation appears in the + * publication's EXCEPT list. + */ appendPQExpBuffer(&buf, + " AND NOT pr.prexcept\n" + "UNION\n" "SELECT pubname\n" " , NULL\n" " , NULL\n" "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" - " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" - "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" - "UNION\n" - "SELECT pubname\n" - " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" - " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" - " (SELECT pg_catalog.string_agg(attname, ', ')\n" - " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" - " pg_catalog.pg_attribute\n" - " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" - " ELSE NULL END) " - "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" - "WHERE pr.prrelid = '%s'\n", + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + " AND NOT EXISTS (\n" + " SELECT 1\n" + " FROM pg_catalog.pg_publication_rel pr\n" + " WHERE pr.prpubid = p.oid AND\n" + " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" + "ORDER BY 1;", oid, oid, oid); - - if (pset.sversion >= 190000) - { - /* - * Skip entries where this relation appears in the - * publication's EXCEPT list. - */ - appendPQExpBuffer(&buf, - " AND NOT pr.prexcept\n" - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - " AND NOT EXISTS (\n" - " SELECT 1\n" - " FROM pg_catalog.pg_publication_rel pr\n" - " WHERE pr.prpubid = p.oid AND\n" - " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" - "ORDER BY 1;", - oid, oid, oid); - } - else - { - appendPQExpBuffer(&buf, - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - "ORDER BY 1;", - oid); - } } else { appendPQExpBuffer(&buf, + "UNION\n" "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - "WHERE pr.prrelid = '%s'\n" - "UNION ALL\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" + " , NULL\n" + " , NULL\n" "FROM pg_catalog.pg_publication p\n" "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" "ORDER BY 1;", - oid, oid); + oid); } + } + else + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + "WHERE pr.prrelid = '%s'\n" + "UNION ALL\n" + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + "ORDER BY 1;", + oid, oid); + } - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - if (tuples > 0) - printTableAddFooter(&cont, _("Included in publications:")); + if (tuples > 0) + printTableAddFooter(&cont, _("Included in publications:")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " \"%s\"", + PQgetvalue(result, i, 0)); - /* column list (if any) */ - if (!PQgetisnull(result, i, 2)) - appendPQExpBuffer(&buf, " (%s)", - PQgetvalue(result, i, 2)); + /* column list (if any) */ + if (!PQgetisnull(result, i, 2)) + appendPQExpBuffer(&buf, " (%s)", + PQgetvalue(result, i, 2)); - /* row filter (if any) */ - if (!PQgetisnull(result, i, 1)) - appendPQExpBuffer(&buf, " WHERE %s", - PQgetvalue(result, i, 1)); + /* row filter (if any) */ + if (!PQgetisnull(result, i, 1)) + appendPQExpBuffer(&buf, " WHERE %s", + PQgetvalue(result, i, 1)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* Print publications where the table is in the EXCEPT clause */ if (pset.sversion >= 190000) @@ -3805,7 +3804,7 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) ncols++; } appendPQExpBufferStr(&buf, "\n, r.rolreplication"); - appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); + appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_roles r\n"); @@ -3860,8 +3859,8 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) if (strcmp(PQgetvalue(res, i, (verbose ? 9 : 8)), "t") == 0) add_role_attribute(&buf, _("Replication")); - if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) - add_role_attribute(&buf, _("Bypass RLS")); + if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) + add_role_attribute(&buf, _("Bypass RLS")); conns = atoi(PQgetvalue(res, i, 6)); if (conns >= 0) @@ -5155,14 +5154,14 @@ listCollations(const char *pattern, bool verbose, bool showSystem) gettext_noop("Schema"), gettext_noop("Name")); - appendPQExpBuffer(&buf, - " CASE c.collprovider " - "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " - "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " - "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " - "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " - "END AS \"%s\",\n", - gettext_noop("Provider")); + appendPQExpBuffer(&buf, + " CASE c.collprovider " + "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " + "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " + "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " + "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " + "END AS \"%s\",\n", + gettext_noop("Provider")); appendPQExpBuffer(&buf, " c.collcollate AS \"%s\",\n" -- 2.50.1 (Apple Git-155) --aHl3HfeiUuO3zeNC-- ^ permalink raw reply [nested|flat] 59+ messages in thread
* [PATCH v6 4/4] run pgindent and pgperltidy @ 2026-06-30 18:24 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 59+ messages in thread From: Nathan Bossart @ 2026-06-30 18:24 UTC (permalink / raw) --- src/bin/pg_dump/pg_dump.c | 464 ++++++++++----------- src/bin/pg_dump/pg_dumpall.c | 30 +- src/bin/pg_upgrade/check.c | 16 +- src/bin/pg_upgrade/controldata.c | 2 +- src/bin/pg_upgrade/exec.c | 8 +- src/bin/pg_upgrade/multixact_rewrite.c | 80 ++-- src/bin/pg_upgrade/pg_upgrade.c | 34 +- src/bin/pg_upgrade/relfilenumber.c | 54 +-- src/bin/pg_upgrade/t/006_transfer_modes.pl | 33 +- src/bin/psql/command.c | 29 +- src/bin/psql/describe.c | 461 ++++++++++---------- 11 files changed, 601 insertions(+), 610 deletions(-) diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 65bd15ebfd2..5673268b467 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -1491,8 +1491,8 @@ setup_connection(Archive *AH, const char *dumpencoding, * Disable timeouts if supported. */ ExecuteSqlStatement(AH, "SET statement_timeout = 0"); - ExecuteSqlStatement(AH, "SET lock_timeout = 0"); - ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); + ExecuteSqlStatement(AH, "SET lock_timeout = 0"); + ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); if (AH->remoteVersion >= 170000) ExecuteSqlStatement(AH, "SET transaction_timeout = 0"); @@ -1505,10 +1505,10 @@ setup_connection(Archive *AH, const char *dumpencoding, /* * Adjust row-security mode, if supported. */ - if (dopt->enable_row_security) - ExecuteSqlStatement(AH, "SET row_security = on"); - else - ExecuteSqlStatement(AH, "SET row_security = off"); + if (dopt->enable_row_security) + ExecuteSqlStatement(AH, "SET row_security = on"); + else + ExecuteSqlStatement(AH, "SET row_security = off"); /* * For security reasons, we restrict the expansion of non-system views and @@ -1933,10 +1933,9 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) addObjectDependency(dobj, ext->dobj.dumpId); /* - * Mark the member object to have any non-initial ACLs - * dumped. (Any initial ACLs will be removed later, using data from - * pg_init_privs, so that we'll dump only the delta from the extension's - * initial setup.) + * Mark the member object to have any non-initial ACLs dumped. (Any + * initial ACLs will be removed later, using data from pg_init_privs, so + * that we'll dump only the delta from the extension's initial setup.) * * In binary upgrades, we still dump all components of the members * individually, since the idea is to exactly reproduce the database @@ -1953,7 +1952,7 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) if (fout->dopt->binary_upgrade) dobj->dump = ext->dobj.dump; else - dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); + dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); return true; } @@ -1987,9 +1986,9 @@ selectDumpableNamespace(NamespaceInfo *nsinfo, Archive *fout) else if (strcmp(nsinfo->dobj.name, "pg_catalog") == 0) { /* - * We dump out any ACLs defined in pg_catalog, if - * they are interesting (and not the original ACLs which were set at - * initdb time, see pg_init_privs). + * We dump out any ACLs defined in pg_catalog, if they are interesting + * (and not the original ACLs which were set at initdb time, see + * pg_init_privs). */ nsinfo->dobj.dump_contains = nsinfo->dobj.dump = DUMP_COMPONENT_ACL; } @@ -3296,7 +3295,7 @@ dumpDatabase(Archive *fout) "datcollate, datctype, datfrozenxid, " "datacl, acldefault('d', datdba) AS acldefault, " "datistemplate, datconnlimit, "); - appendPQExpBufferStr(dbQry, "datminmxid, "); + appendPQExpBufferStr(dbQry, "datminmxid, "); if (fout->remoteVersion >= 170000) appendPQExpBufferStr(dbQry, "datlocprovider, datlocale, datcollversion, "); else if (fout->remoteVersion >= 150000) @@ -3638,11 +3637,11 @@ dumpDatabase(Archive *fout) ii_oid, ii_relminmxid; - appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" - "FROM pg_catalog.pg_class\n" - "WHERE oid IN (%u, %u, %u, %u);\n", - LargeObjectRelationId, LargeObjectLOidPNIndexId, - LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); + appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" + "FROM pg_catalog.pg_class\n" + "WHERE oid IN (%u, %u, %u, %u);\n", + LargeObjectRelationId, LargeObjectLOidPNIndexId, + LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); lo_res = ExecuteSqlQuery(fout, loFrozenQry->data, PGRES_TUPLES_OK); @@ -4274,7 +4273,7 @@ getPolicies(Archive *fout, TableInfo tblinfo[], int numTables) printfPQExpBuffer(query, "SELECT pol.oid, pol.tableoid, pol.polrelid, pol.polname, pol.polcmd, "); - appendPQExpBufferStr(query, "pol.polpermissive, "); + appendPQExpBufferStr(query, "pol.polpermissive, "); appendPQExpBuffer(query, "CASE WHEN pol.polroles = '{0}' THEN NULL ELSE " " pg_catalog.array_to_string(ARRAY(SELECT pg_catalog.quote_ident(rolname) from pg_catalog.pg_roles WHERE oid = ANY(pol.polroles)), ', ') END AS polroles, " @@ -6633,9 +6632,9 @@ getAccessMethods(Archive *fout) * Select all access methods from pg_am table. */ appendPQExpBufferStr(query, "SELECT tableoid, oid, amname, "); - appendPQExpBufferStr(query, - "amtype, " - "amhandler::pg_catalog.regproc AS amhandler "); + appendPQExpBufferStr(query, + "amtype, " + "amhandler::pg_catalog.regproc AS amhandler "); appendPQExpBufferStr(query, "FROM pg_am"); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6827,35 +6826,35 @@ getAggregates(Archive *fout) * Find all interesting aggregates. See comment in getFuncs() for the * rationale behind the filtering logic. */ - agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" - : "p.proisagg"); + agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" + : "p.proisagg"); - appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " - "p.proname AS aggname, " - "p.pronamespace AS aggnamespace, " - "p.pronargs, p.proargtypes, " - "p.proowner, " - "p.proacl AS aggacl, " - "acldefault('f', p.proowner) AS acldefault " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s AND (" - "p.pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog') OR " - "p.proacl IS DISTINCT FROM pip.initprivs", - agg_check); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - " OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); - appendPQExpBufferChar(query, ')'); + appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " + "p.proname AS aggname, " + "p.pronamespace AS aggnamespace, " + "p.pronargs, p.proargtypes, " + "p.proowner, " + "p.proacl AS aggacl, " + "acldefault('f', p.proowner) AS acldefault " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s AND (" + "p.pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog') OR " + "p.proacl IS DISTINCT FROM pip.initprivs", + agg_check); + if (dopt->binary_upgrade) + appendPQExpBufferStr(query, + " OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6957,53 +6956,53 @@ getFuncs(Archive *fout) * include them, since we want to dump extension members individually in * that mode. Also, if they are used by casts or transforms then we need * to gather the information about them, though they won't be dumped if - * they are built-in. Also, include functions in - * pg_catalog if they have an ACL different from what's shown in - * pg_init_privs (so we have to join to pg_init_privs; annoying). + * they are built-in. Also, include functions in pg_catalog if they have + * an ACL different from what's shown in pg_init_privs (so we have to join + * to pg_init_privs; annoying). */ - not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" - : "NOT p.proisagg"); + not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" + : "NOT p.proisagg"); - appendPQExpBuffer(query, - "SELECT p.tableoid, p.oid, p.proname, p.prolang, " - "p.pronargs, p.proargtypes, p.prorettype, " - "p.proacl, " - "acldefault('f', p.proowner) AS acldefault, " - "p.pronamespace, " - "p.proowner " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s" - "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " - "WHERE classid = 'pg_proc'::regclass AND " - "objid = p.oid AND deptype = 'i')" - "\n AND (" - "\n pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog')" - "\n OR EXISTS (SELECT 1 FROM pg_cast" - "\n WHERE pg_cast.oid > %u " - "\n AND p.oid = pg_cast.castfunc)" - "\n OR EXISTS (SELECT 1 FROM pg_transform" - "\n WHERE pg_transform.oid > %u AND " - "\n (p.oid = pg_transform.trffromsql" - "\n OR p.oid = pg_transform.trftosql))", - not_agg_check, - g_last_builtin_oid, - g_last_builtin_oid); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); + appendPQExpBuffer(query, + "SELECT p.tableoid, p.oid, p.proname, p.prolang, " + "p.pronargs, p.proargtypes, p.prorettype, " + "p.proacl, " + "acldefault('f', p.proowner) AS acldefault, " + "p.pronamespace, " + "p.proowner " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s" + "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " + "WHERE classid = 'pg_proc'::regclass AND " + "objid = p.oid AND deptype = 'i')" + "\n AND (" + "\n pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog')" + "\n OR EXISTS (SELECT 1 FROM pg_cast" + "\n WHERE pg_cast.oid > %u " + "\n AND p.oid = pg_cast.castfunc)" + "\n OR EXISTS (SELECT 1 FROM pg_transform" + "\n WHERE pg_transform.oid > %u AND " + "\n (p.oid = pg_transform.trffromsql" + "\n OR p.oid = pg_transform.trftosql))", + not_agg_check, + g_last_builtin_oid, + g_last_builtin_oid); + if (dopt->binary_upgrade) appendPQExpBufferStr(query, - "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); - appendPQExpBufferChar(query, ')'); + "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferStr(query, + "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -7252,31 +7251,31 @@ getTables(Archive *fout, int *numTables) appendPQExpBufferStr(query, "c.relhasoids, "); - appendPQExpBufferStr(query, - "c.relispopulated, "); + appendPQExpBufferStr(query, + "c.relispopulated, "); - appendPQExpBufferStr(query, - "c.relreplident, "); + appendPQExpBufferStr(query, + "c.relreplident, "); - appendPQExpBufferStr(query, - "c.relrowsecurity, c.relforcerowsecurity, "); + appendPQExpBufferStr(query, + "c.relrowsecurity, c.relforcerowsecurity, "); - appendPQExpBufferStr(query, - "c.relminmxid, tc.relminmxid AS tminmxid, "); + appendPQExpBufferStr(query, + "c.relminmxid, tc.relminmxid AS tminmxid, "); - appendPQExpBufferStr(query, - "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); + appendPQExpBufferStr(query, + "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); - appendPQExpBufferStr(query, - "am.amname, "); + appendPQExpBufferStr(query, + "am.amname, "); - appendPQExpBufferStr(query, - "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); + appendPQExpBufferStr(query, + "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); - appendPQExpBufferStr(query, - "c.relispartition AS ispartition "); + appendPQExpBufferStr(query, + "c.relispartition AS ispartition "); /* * Left join to pg_depend to pick up dependency info linking sequences to @@ -7296,8 +7295,8 @@ getTables(Archive *fout, int *numTables) /* * Left join to pg_am to pick up the amname. */ - appendPQExpBufferStr(query, - "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); + appendPQExpBufferStr(query, + "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); /* * We purposefully ignore toast OIDs for partitioned tables; the reason is @@ -7868,8 +7867,8 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables) "t.reloptions AS indreloptions, "); - appendPQExpBufferStr(query, - "i.indisreplident, "); + appendPQExpBufferStr(query, + "i.indisreplident, "); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -9313,8 +9312,8 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables) appendPQExpBufferStr(q, "'' AS attcompression,\n"); - appendPQExpBufferStr(q, - "a.attidentity,\n"); + appendPQExpBufferStr(q, + "a.attidentity,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(q, @@ -10717,73 +10716,73 @@ getAdditionalACLs(Archive *fout) PQclear(res); /* Fetch initial-privileges data */ - printfPQExpBuffer(query, - "SELECT objoid, classoid, objsubid, privtype, initprivs " - "FROM pg_init_privs"); + printfPQExpBuffer(query, + "SELECT objoid, classoid, objsubid, privtype, initprivs " + "FROM pg_init_privs"); - res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); + res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); - ntups = PQntuples(res); - for (i = 0; i < ntups; i++) - { - Oid objoid = atooid(PQgetvalue(res, i, 0)); - Oid classoid = atooid(PQgetvalue(res, i, 1)); - int objsubid = atoi(PQgetvalue(res, i, 2)); - char privtype = *(PQgetvalue(res, i, 3)); - char *initprivs = PQgetvalue(res, i, 4); - CatalogId objId; - DumpableObject *dobj; + ntups = PQntuples(res); + for (i = 0; i < ntups; i++) + { + Oid objoid = atooid(PQgetvalue(res, i, 0)); + Oid classoid = atooid(PQgetvalue(res, i, 1)); + int objsubid = atoi(PQgetvalue(res, i, 2)); + char privtype = *(PQgetvalue(res, i, 3)); + char *initprivs = PQgetvalue(res, i, 4); + CatalogId objId; + DumpableObject *dobj; - objId.tableoid = classoid; - objId.oid = objoid; - dobj = findObjectByCatalogId(objId); - /* OK to ignore entries we haven't got a DumpableObject for */ - if (dobj) + objId.tableoid = classoid; + objId.oid = objoid; + dobj = findObjectByCatalogId(objId); + /* OK to ignore entries we haven't got a DumpableObject for */ + if (dobj) + { + /* Cope with sub-object initprivs */ + if (objsubid != 0) { - /* Cope with sub-object initprivs */ - if (objsubid != 0) - { - if (dobj->objType == DO_TABLE) - { - /* For a column initprivs, set the table's ACL flags */ - dobj->components |= DUMP_COMPONENT_ACL; - ((TableInfo *) dobj)->hascolumnACLs = true; - } - else - pg_log_warning("unsupported pg_init_privs entry: %u %u %d", - classoid, objoid, objsubid); - continue; - } - - /* - * We ignore any pg_init_privs.initprivs entry for the public - * schema, as explained in getNamespaces(). - */ - if (dobj->objType == DO_NAMESPACE && - strcmp(dobj->name, "public") == 0) - continue; - - /* Else it had better be of a type we think has ACLs */ - if (dobj->objType == DO_NAMESPACE || - dobj->objType == DO_TYPE || - dobj->objType == DO_FUNC || - dobj->objType == DO_AGG || - dobj->objType == DO_TABLE || - dobj->objType == DO_PROCLANG || - dobj->objType == DO_FDW || - dobj->objType == DO_FOREIGN_SERVER) + if (dobj->objType == DO_TABLE) { - DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; - - daobj->dacl.privtype = privtype; - daobj->dacl.initprivs = pstrdup(initprivs); + /* For a column initprivs, set the table's ACL flags */ + dobj->components |= DUMP_COMPONENT_ACL; + ((TableInfo *) dobj)->hascolumnACLs = true; } else pg_log_warning("unsupported pg_init_privs entry: %u %u %d", classoid, objoid, objsubid); + continue; + } + + /* + * We ignore any pg_init_privs.initprivs entry for the public + * schema, as explained in getNamespaces(). + */ + if (dobj->objType == DO_NAMESPACE && + strcmp(dobj->name, "public") == 0) + continue; + + /* Else it had better be of a type we think has ACLs */ + if (dobj->objType == DO_NAMESPACE || + dobj->objType == DO_TYPE || + dobj->objType == DO_FUNC || + dobj->objType == DO_AGG || + dobj->objType == DO_TABLE || + dobj->objType == DO_PROCLANG || + dobj->objType == DO_FDW || + dobj->objType == DO_FOREIGN_SERVER) + { + DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; + + daobj->dacl.privtype = privtype; + daobj->dacl.initprivs = pstrdup(initprivs); } + else + pg_log_warning("unsupported pg_init_privs entry: %u %u %d", + classoid, objoid, objsubid); } - PQclear(res); + } + PQclear(res); destroyPQExpBuffer(query); } @@ -11128,8 +11127,8 @@ dumpRelationStats_dumper(Archive *fout, const void *userArg, const TocEntry *te) * The results must be in the order of the relations supplied in the * parameters to ensure we remain in sync as we walk through the TOC. * - * For versions before 19, the redundant filter clause on s.tablename = - * ANY(...) seems sufficient to convince the planner to use + * For versions before 19, the redundant filter clause on s.tablename + * = ANY(...) seems sufficient to convince the planner to use * pg_class_relname_nsp_index, which avoids a full scan of pg_stats. * In newer versions, pg_stats returns the table OIDs, eliminating the * need for that hack. @@ -13469,11 +13468,11 @@ dumpFunc(Archive *fout, const FuncInfo *finfo) "pg_catalog.pg_get_function_result(p.oid) AS funcresult,\n" "proleakproof,\n"); - appendPQExpBufferStr(query, - "array_to_string(protrftypes, ' ') AS protrftypes,\n"); + appendPQExpBufferStr(query, + "array_to_string(protrftypes, ' ') AS protrftypes,\n"); - appendPQExpBufferStr(query, - "proparallel,\n"); + appendPQExpBufferStr(query, + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -14963,9 +14962,9 @@ dumpCollation(Archive *fout, const CollInfo *collinfo) /* Get collation-specific details */ appendPQExpBufferStr(query, "SELECT "); - appendPQExpBufferStr(query, - "collprovider, " - "collversion, "); + appendPQExpBufferStr(query, + "collprovider, " + "collversion, "); if (fout->remoteVersion >= 120000) appendPQExpBufferStr(query, @@ -15372,23 +15371,23 @@ dumpAgg(Archive *fout, const AggInfo *agginfo) "pg_catalog.pg_get_function_arguments(p.oid) AS funcargs,\n" "pg_catalog.pg_get_function_identity_arguments(p.oid) AS funciargs,\n"); - appendPQExpBufferStr(query, - "aggkind,\n" - "aggmtransfn,\n" - "aggminvtransfn,\n" - "aggmfinalfn,\n" - "aggmtranstype::pg_catalog.regtype,\n" - "aggfinalextra,\n" - "aggmfinalextra,\n" - "aggtransspace,\n" - "aggmtransspace,\n" - "aggminitval,\n"); + appendPQExpBufferStr(query, + "aggkind,\n" + "aggmtransfn,\n" + "aggminvtransfn,\n" + "aggmfinalfn,\n" + "aggmtranstype::pg_catalog.regtype,\n" + "aggfinalextra,\n" + "aggmfinalextra,\n" + "aggtransspace,\n" + "aggmtransspace,\n" + "aggminitval,\n"); - appendPQExpBufferStr(query, - "aggcombinefn,\n" - "aggserialfn,\n" - "aggdeserialfn,\n" - "proparallel,\n"); + appendPQExpBufferStr(query, + "aggcombinefn,\n" + "aggserialfn,\n" + "aggdeserialfn,\n" + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -16848,30 +16847,30 @@ dumpTable(Archive *fout, const TableInfo *tbinfo) appendPQExpBufferStr(query, "PREPARE getColumnACLs(pg_catalog.oid) AS\n"); - /* - * In principle we should call acldefault('c', relowner) to - * get the default ACL for a column. However, we don't - * currently store the numeric OID of the relowner in - * TableInfo. We could convert the owner name using regrole, - * but that creates a risk of failure due to concurrent role - * renames. Given that the default ACL for columns is empty - * and is likely to stay that way, it's not worth extra cycles - * and risk to avoid hard-wiring that knowledge here. - */ - appendPQExpBufferStr(query, - "SELECT at.attname, " - "at.attacl, " - "'{}' AS acldefault, " - "pip.privtype, pip.initprivs " - "FROM pg_catalog.pg_attribute at " - "LEFT JOIN pg_catalog.pg_init_privs pip ON " - "(at.attrelid = pip.objoid " - "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " - "AND at.attnum = pip.objsubid) " - "WHERE at.attrelid = $1 AND " - "NOT at.attisdropped " - "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " - "ORDER BY at.attnum"); + /* + * In principle we should call acldefault('c', relowner) to get + * the default ACL for a column. However, we don't currently + * store the numeric OID of the relowner in TableInfo. We could + * convert the owner name using regrole, but that creates a risk + * of failure due to concurrent role renames. Given that the + * default ACL for columns is empty and is likely to stay that + * way, it's not worth extra cycles and risk to avoid hard-wiring + * that knowledge here. + */ + appendPQExpBufferStr(query, + "SELECT at.attname, " + "at.attacl, " + "'{}' AS acldefault, " + "pip.privtype, pip.initprivs " + "FROM pg_catalog.pg_attribute at " + "LEFT JOIN pg_catalog.pg_init_privs pip ON " + "(at.attrelid = pip.objoid " + "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " + "AND at.attnum = pip.objsubid) " + "WHERE at.attrelid = $1 AND " + "NOT at.attisdropped " + "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " + "ORDER BY at.attnum"); ExecuteSqlStatement(fout, query->data); @@ -19165,7 +19164,7 @@ collectSequences(Archive *fout) * pg_get_sequence_data(), but we only do so for non-schema-only dumps. */ if (fout->remoteVersion < 180000 || - (!fout->dopt->dumpData && !fout->dopt->sequence_data)) + (!fout->dopt->dumpData && !fout->dopt->sequence_data)) query = "SELECT seqrelid, format_type(seqtypid, NULL), " "seqstart, seqincrement, " "seqmax, seqmin, " @@ -19227,15 +19226,14 @@ dumpSequence(Archive *fout, const TableInfo *tbinfo) qseqname = pg_strdup(fmtId(tbinfo->dobj.name)); /* - * The sequence information is gathered in a sorted - * table before any calls to dumpSequence(). See collectSequences() for - * more information. + * The sequence information is gathered in a sorted table before any calls + * to dumpSequence(). See collectSequences() for more information. */ - Assert(sequences); + Assert(sequences); - key.oid = tbinfo->dobj.catId.oid; - seq = bsearch(&key, sequences, nsequences, - sizeof(SequenceItem), SequenceItemCmp); + key.oid = tbinfo->dobj.catId.oid; + seq = bsearch(&key, sequences, nsequences, + sizeof(SequenceItem), SequenceItemCmp); /* Calculate default limits for a sequence of this type */ is_ascending = (seq->incby >= 0); diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c index e68937c9934..afcd9a218d8 100644 --- a/src/bin/pg_dump/pg_dumpall.c +++ b/src/bin/pg_dump/pg_dumpall.c @@ -785,11 +785,11 @@ dropRoles(PGconn *conn) int i_rolname; int i; - printfPQExpBuffer(buf, - "SELECT rolname " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 1", role_catalog); + printfPQExpBuffer(buf, + "SELECT rolname " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 1", role_catalog); res = executeQuery(conn, buf->data); @@ -843,16 +843,16 @@ dumpRoles(PGconn *conn) * Notes: rolconfig is dumped later, and pg_authid must be used for * extracting rolcomment regardless of role_catalog. */ - printfPQExpBuffer(buf, - "SELECT oid, rolname, rolsuper, rolinherit, " - "rolcreaterole, rolcreatedb, " - "rolcanlogin, rolconnlimit, rolpassword, " - "rolvaliduntil, rolreplication, rolbypassrls, " - "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " - "rolname = current_user AS is_current_user " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 2", role_catalog); + printfPQExpBuffer(buf, + "SELECT oid, rolname, rolsuper, rolinherit, " + "rolcreaterole, rolcreatedb, " + "rolcanlogin, rolconnlimit, rolpassword, " + "rolvaliduntil, rolreplication, rolbypassrls, " + "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " + "rolname = current_user AS is_current_user " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 2", role_catalog); res = executeQuery(conn, buf->data); diff --git a/src/bin/pg_upgrade/check.c b/src/bin/pg_upgrade/check.c index 786c1474829..f725f5ee3e2 100644 --- a/src/bin/pg_upgrade/check.c +++ b/src/bin/pg_upgrade/check.c @@ -1475,15 +1475,15 @@ check_for_incompatible_polymorphics(ClusterInfo *cluster) ", 'array_cat(anyarray,anyarray)'" ", 'array_prepend(anyelement,anyarray)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_remove(anyarray,anyelement)'" - ", 'array_replace(anyarray,anyelement,anyelement)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_remove(anyarray,anyelement)'" + ", 'array_replace(anyarray,anyelement,anyelement)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_position(anyarray,anyelement)'" - ", 'array_position(anyarray,anyelement,integer)'" - ", 'array_positions(anyarray,anyelement)'" - ", 'width_bucket(anyelement,anyarray)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_position(anyarray,anyelement)'" + ", 'array_position(anyarray,anyelement,integer)'" + ", 'array_positions(anyarray,anyelement)'" + ", 'width_bucket(anyelement,anyarray)'"); /* * The query below hardcodes FirstNormalObjectId as 16384 rather than diff --git a/src/bin/pg_upgrade/controldata.c b/src/bin/pg_upgrade/controldata.c index 8f81c9e9582..02ea02df60f 100644 --- a/src/bin/pg_upgrade/controldata.c +++ b/src/bin/pg_upgrade/controldata.c @@ -228,7 +228,7 @@ get_control_data(ClusterInfo *cluster) p++; /* remove ':' char */ cluster->controldata.chkpnt_nxtepoch = str2uint(p); - p = strchr(p, ':'); + p = strchr(p, ':'); if (p == NULL || strlen(p) <= 1) pg_fatal("%d: controldata retrieval problem", __LINE__); diff --git a/src/bin/pg_upgrade/exec.c b/src/bin/pg_upgrade/exec.c index 44355feea30..a1bdbf373e3 100644 --- a/src/bin/pg_upgrade/exec.c +++ b/src/bin/pg_upgrade/exec.c @@ -55,7 +55,7 @@ get_bin_version(ClusterInfo *cluster) if (sscanf(cmd_output, "%*s %*s %d.%d", &v1, &v2) < 1) pg_fatal("could not get pg_ctl version output from %s", cmd); - cluster->bin_version = v1 * 10000; + cluster->bin_version = v1 * 10000; } @@ -344,8 +344,8 @@ check_data_dir(ClusterInfo *cluster) check_single_dir(pg_data, "pg_subtrans"); check_single_dir(pg_data, PG_TBLSPC_DIR); check_single_dir(pg_data, "pg_twophase"); - check_single_dir(pg_data, "pg_wal"); - check_single_dir(pg_data, "pg_xact"); + check_single_dir(pg_data, "pg_wal"); + check_single_dir(pg_data, "pg_xact"); } @@ -385,7 +385,7 @@ check_bin_dir(ClusterInfo *cluster, bool check_versions) */ get_bin_version(cluster); - check_exec(cluster->bindir, "pg_resetwal", check_versions); + check_exec(cluster->bindir, "pg_resetwal", check_versions); if (cluster == &new_cluster) { diff --git a/src/bin/pg_upgrade/multixact_rewrite.c b/src/bin/pg_upgrade/multixact_rewrite.c index c45b3183684..c7a1416494d 100644 --- a/src/bin/pg_upgrade/multixact_rewrite.c +++ b/src/bin/pg_upgrade/multixact_rewrite.c @@ -61,52 +61,52 @@ rewrite_multixacts(MultiXactId from_multi, MultiXactId to_multi) * Convert old multixids, if needed, by reading them one-by-one from the * old cluster. */ - old_reader = AllocOldMultiXactRead(old_cluster.pgdata, - old_cluster.controldata.chkpnt_nxtmulti, - old_cluster.controldata.chkpnt_nxtmxoff); + old_reader = AllocOldMultiXactRead(old_cluster.pgdata, + old_cluster.controldata.chkpnt_nxtmulti, + old_cluster.controldata.chkpnt_nxtmxoff); - for (MultiXactId multi = from_multi; multi != to_multi;) - { - MultiXactMember member; - bool multixid_valid; - - /* - * Read this multixid's members. - * - * Locking-only XIDs that may be part of multi-xids don't matter - * after upgrade, as there can be no transactions running across - * upgrade. So as a small optimization, we only read one member - * from each multixid: the one updating one, or if there was no - * update, arbitrarily the first locking xid. - */ - multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); + for (MultiXactId multi = from_multi; multi != to_multi;) + { + MultiXactMember member; + bool multixid_valid; - /* - * Write the new offset to pg_multixact/offsets. - * - * Even if this multixid is invalid, we still need to write its - * offset if the *previous* multixid was valid. That's because - * when reading a multixid, the number of members is calculated - * from the difference between the two offsets. - */ - RecordMultiXactOffset(offsets_writer, multi, - (multixid_valid || prev_multixid_valid) ? next_offset : 0); + /* + * Read this multixid's members. + * + * Locking-only XIDs that may be part of multi-xids don't matter after + * upgrade, as there can be no transactions running across upgrade. So + * as a small optimization, we only read one member from each + * multixid: the one updating one, or if there was no update, + * arbitrarily the first locking xid. + */ + multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); - /* Write the members */ - if (multixid_valid) - { - RecordMultiXactMembers(members_writer, next_offset, 1, &member); - next_offset += 1; - } + /* + * Write the new offset to pg_multixact/offsets. + * + * Even if this multixid is invalid, we still need to write its offset + * if the *previous* multixid was valid. That's because when reading + * a multixid, the number of members is calculated from the difference + * between the two offsets. + */ + RecordMultiXactOffset(offsets_writer, multi, + (multixid_valid || prev_multixid_valid) ? next_offset : 0); - /* Advance to next multixid, handling wraparound */ - multi++; - if (multi < FirstMultiXactId) - multi = FirstMultiXactId; - prev_multixid_valid = multixid_valid; + /* Write the members */ + if (multixid_valid) + { + RecordMultiXactMembers(members_writer, next_offset, 1, &member); + next_offset += 1; } - FreeOldMultiXactReader(old_reader); + /* Advance to next multixid, handling wraparound */ + multi++; + if (multi < FirstMultiXactId) + multi = FirstMultiXactId; + prev_multixid_valid = multixid_valid; + } + + FreeOldMultiXactReader(old_reader); /* Write the final 'next' offset to the last SLRU page */ RecordMultiXactOffset(offsets_writer, to_multi, diff --git a/src/bin/pg_upgrade/pg_upgrade.c b/src/bin/pg_upgrade/pg_upgrade.c index c6af9035665..7366fd4627c 100644 --- a/src/bin/pg_upgrade/pg_upgrade.c +++ b/src/bin/pg_upgrade/pg_upgrade.c @@ -833,7 +833,7 @@ copy_xact_xlog_xid(void) * Determine the range of multixacts to convert. */ nxtmulti = old_cluster.controldata.chkpnt_nxtmulti; - oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; + oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; /* handle wraparound */ if (nxtmulti < FirstMultiXactId) nxtmulti = FirstMultiXactId; @@ -898,15 +898,15 @@ set_frozenxids(void) int i_datname; int i_datallowconn; - prep_status("Setting frozenxid and minmxid counters in new cluster"); + prep_status("Setting frozenxid and minmxid counters in new cluster"); conn_template1 = connectToServer(&new_cluster, "template1"); - /* set pg_database.datfrozenxid */ - PQclear(executeQueryOrDie(conn_template1, - "UPDATE pg_catalog.pg_database " - "SET datfrozenxid = '%u'", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_database.datfrozenxid */ + PQclear(executeQueryOrDie(conn_template1, + "UPDATE pg_catalog.pg_database " + "SET datfrozenxid = '%u'", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_database.datminmxid */ PQclear(executeQueryOrDie(conn_template1, @@ -942,16 +942,16 @@ set_frozenxids(void) conn = connectToServer(&new_cluster, datname); - /* set pg_class.relfrozenxid */ - PQclear(executeQueryOrDie(conn, - "UPDATE pg_catalog.pg_class " - "SET relfrozenxid = '%u' " - /* only heap, materialized view, and TOAST are vacuumed */ - "WHERE relkind IN (" - CppAsString2(RELKIND_RELATION) ", " - CppAsString2(RELKIND_MATVIEW) ", " - CppAsString2(RELKIND_TOASTVALUE) ")", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_class.relfrozenxid */ + PQclear(executeQueryOrDie(conn, + "UPDATE pg_catalog.pg_class " + "SET relfrozenxid = '%u' " + /* only heap, materialized view, and TOAST are vacuumed */ + "WHERE relkind IN (" + CppAsString2(RELKIND_RELATION) ", " + CppAsString2(RELKIND_MATVIEW) ", " + CppAsString2(RELKIND_TOASTVALUE) ")", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_class.relminmxid */ PQclear(executeQueryOrDie(conn, diff --git a/src/bin/pg_upgrade/relfilenumber.c b/src/bin/pg_upgrade/relfilenumber.c index ec2ff7acb21..6c467bdc8a5 100644 --- a/src/bin/pg_upgrade/relfilenumber.c +++ b/src/bin/pg_upgrade/relfilenumber.c @@ -587,32 +587,32 @@ transfer_relfile(FileNameMap *map, const char *type_suffix) /* Copying files might take some time, so give feedback. */ pg_log(PG_STATUS, "%s", old_file); - switch (user_opts.transfer_mode) - { - case TRANSFER_MODE_CLONE: - pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", - old_file, new_file); - cloneFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", - old_file, new_file); - copyFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY_FILE_RANGE: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", - old_file, new_file); - copyFileByRange(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_LINK: - pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", - old_file, new_file); - linkFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_SWAP: - /* swap mode is handled in its own code path */ - pg_fatal("should never happen"); - break; - } + switch (user_opts.transfer_mode) + { + case TRANSFER_MODE_CLONE: + pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", + old_file, new_file); + cloneFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", + old_file, new_file); + copyFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY_FILE_RANGE: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", + old_file, new_file); + copyFileByRange(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_LINK: + pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", + old_file, new_file); + linkFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_SWAP: + /* swap mode is handled in its own code path */ + pg_fatal("should never happen"); + break; + } } } diff --git a/src/bin/pg_upgrade/t/006_transfer_modes.pl b/src/bin/pg_upgrade/t/006_transfer_modes.pl index 9efa5dc863c..360d05c4b68 100644 --- a/src/bin/pg_upgrade/t/006_transfer_modes.pl +++ b/src/bin/pg_upgrade/t/006_transfer_modes.pl @@ -29,10 +29,8 @@ sub test_mode } $new->init(); - $new->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); - $old->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); + $new->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); + $old->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); # We can only test security labels if both the old and new installations # have dummy_seclabel. @@ -76,15 +74,14 @@ sub test_mode "CREATE TABLE test4 AS SELECT generate_series(400, 502)"); } - $old->safe_psql('postgres', - "CREATE TABLESPACE inplc_tblspc LOCATION ''"); - $old->safe_psql('postgres', - "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); - $old->safe_psql('postgres', - "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" - ); - $old->safe_psql('testdb3', - "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); + $old->safe_psql('postgres', "CREATE TABLESPACE inplc_tblspc LOCATION ''"); + $old->safe_psql('postgres', + "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); + $old->safe_psql('postgres', + "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" + ); + $old->safe_psql('testdb3', + "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); # While we are here, test handling of large objects. $old->safe_psql( @@ -152,12 +149,10 @@ sub test_mode } # Tests for in-place tablespaces. - $result = - $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); - is($result, '104', "test5 data after pg_upgrade $mode"); - $result = - $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); - is($result, '105', "test6 data after pg_upgrade $mode"); + $result = $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); + is($result, '104', "test5 data after pg_upgrade $mode"); + $result = $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); + is($result, '105', "test6 data after pg_upgrade $mode"); # Tests for large objects $result = $new->safe_psql('postgres', "SELECT lo_get(4532)"); diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index 44ef11d980e..c90bf8bbde2 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -6278,23 +6278,22 @@ get_create_object_cmd(EditableObjectType obj_type, Oid oid, * ensure the right view gets replaced. Also, check relation kind * to be sure it's a view. * - * Views may have WITH [LOCAL|CASCADED] - * CHECK OPTION. These are not part of the view definition - * returned by pg_get_viewdef() and so need to be retrieved - * separately. Materialized views may have - * arbitrary storage parameter reloptions. + * Views may have WITH [LOCAL|CASCADED] CHECK OPTION. These are + * not part of the view definition returned by pg_get_viewdef() + * and so need to be retrieved separately. Materialized views may + * have arbitrary storage parameter reloptions. */ printfPQExpBuffer(query, "/* %s */\n", _("Get view's definition and details")); - appendPQExpBuffer(query, - "SELECT nspname, relname, relkind, " - "pg_catalog.pg_get_viewdef(c.oid, true), " - "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " - "FROM pg_catalog.pg_class c " - "LEFT JOIN pg_catalog.pg_namespace n " - "ON c.relnamespace = n.oid WHERE c.oid = %u", - oid); + appendPQExpBuffer(query, + "SELECT nspname, relname, relkind, " + "pg_catalog.pg_get_viewdef(c.oid, true), " + "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " + "FROM pg_catalog.pg_class c " + "LEFT JOIN pg_catalog.pg_namespace n " + "ON c.relnamespace = n.oid WHERE c.oid = %u", + oid); break; } diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index ce99137c613..ac0c55e7aa5 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -387,19 +387,19 @@ describeFunctions(const char *functypes, const char *func_pattern, gettext_noop("stable"), gettext_noop("volatile"), gettext_noop("Volatility")); - appendPQExpBuffer(&buf, - ",\n CASE\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" - " END as \"%s\"", - gettext_noop("restricted"), - gettext_noop("safe"), - gettext_noop("unsafe"), - gettext_noop("Parallel")); + appendPQExpBuffer(&buf, + ",\n CASE\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" + " END as \"%s\"", + gettext_noop("restricted"), + gettext_noop("safe"), + gettext_noop("unsafe"), + gettext_noop("Parallel")); appendPQExpBuffer(&buf, ",\n pg_catalog.pg_get_userbyid(p.proowner) as \"%s\"" ",\n CASE WHEN prosecdef THEN '%s' ELSE '%s' END AS \"%s\"" @@ -599,8 +599,8 @@ describeFunctions(const char *functypes, const char *func_pattern, myopt.title = _("List of functions"); myopt.translate_header = true; - myopt.translate_columns = translate_columns; - myopt.n_translate_columns = lengthof(translate_columns); + myopt.translate_columns = translate_columns; + myopt.n_translate_columns = lengthof(translate_columns); printQuery(res, &myopt, pset.queryFout, false, pset.logfile); @@ -1086,38 +1086,38 @@ permissionsList(const char *pattern, bool showSystem) " ), E'\\n') AS \"%s\"", gettext_noop("Column privileges")); - appendPQExpBuffer(&buf, - ",\n pg_catalog.array_to_string(ARRAY(\n" - " SELECT polname\n" - " || CASE WHEN NOT polpermissive THEN\n" - " E' (RESTRICTIVE)'\n" - " ELSE '' END\n" - " || CASE WHEN polcmd != '*' THEN\n" - " E' (' || polcmd::pg_catalog.text || E'):'\n" - " ELSE E':'\n" - " END\n" - " || CASE WHEN polqual IS NOT NULL THEN\n" - " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" - " ELSE E''\n" - " END\n" - " || CASE WHEN polwithcheck IS NOT NULL THEN\n" - " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" - " ELSE E''\n" - " END" - " || CASE WHEN polroles <> '{0}' THEN\n" - " E'\\n to: ' || pg_catalog.array_to_string(\n" - " ARRAY(\n" - " SELECT rolname\n" - " FROM pg_catalog.pg_roles\n" - " WHERE oid = ANY (polroles)\n" - " ORDER BY 1\n" - " ), E', ')\n" - " ELSE E''\n" - " END\n" - " FROM pg_catalog.pg_policy pol\n" - " WHERE polrelid = c.oid), E'\\n')\n" - " AS \"%s\"", - gettext_noop("Policies")); + appendPQExpBuffer(&buf, + ",\n pg_catalog.array_to_string(ARRAY(\n" + " SELECT polname\n" + " || CASE WHEN NOT polpermissive THEN\n" + " E' (RESTRICTIVE)'\n" + " ELSE '' END\n" + " || CASE WHEN polcmd != '*' THEN\n" + " E' (' || polcmd::pg_catalog.text || E'):'\n" + " ELSE E':'\n" + " END\n" + " || CASE WHEN polqual IS NOT NULL THEN\n" + " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" + " ELSE E''\n" + " END\n" + " || CASE WHEN polwithcheck IS NOT NULL THEN\n" + " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" + " ELSE E''\n" + " END" + " || CASE WHEN polroles <> '{0}' THEN\n" + " E'\\n to: ' || pg_catalog.array_to_string(\n" + " ARRAY(\n" + " SELECT rolname\n" + " FROM pg_catalog.pg_roles\n" + " WHERE oid = ANY (polroles)\n" + " ORDER BY 1\n" + " ), E', ')\n" + " ELSE E''\n" + " END\n" + " FROM pg_catalog.pg_policy pol\n" + " WHERE polrelid = c.oid), E'\\n')\n" + " AS \"%s\"", + gettext_noop("Policies")); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_class c\n" " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n" @@ -1675,27 +1675,27 @@ describeOneTableDetails(const char *schemaname, char *footers[3] = {NULL, NULL, NULL}; printfPQExpBuffer(&buf, "/* %s */\n", _("Get sequence information")); - appendPQExpBuffer(&buf, - "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" - " seqstart AS \"%s\",\n" - " seqmin AS \"%s\",\n" - " seqmax AS \"%s\",\n" - " seqincrement AS \"%s\",\n" - " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" - " seqcache AS \"%s\"\n", - gettext_noop("Type"), - gettext_noop("Start"), - gettext_noop("Minimum"), - gettext_noop("Maximum"), - gettext_noop("Increment"), - gettext_noop("yes"), - gettext_noop("no"), - gettext_noop("Cycles?"), - gettext_noop("Cache")); - appendPQExpBuffer(&buf, - "FROM pg_catalog.pg_sequence\n" - "WHERE seqrelid = '%s';", - oid); + appendPQExpBuffer(&buf, + "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" + " seqstart AS \"%s\",\n" + " seqmin AS \"%s\",\n" + " seqmax AS \"%s\",\n" + " seqincrement AS \"%s\",\n" + " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" + " seqcache AS \"%s\"\n", + gettext_noop("Type"), + gettext_noop("Start"), + gettext_noop("Minimum"), + gettext_noop("Maximum"), + gettext_noop("Increment"), + gettext_noop("yes"), + gettext_noop("no"), + gettext_noop("Cycles?"), + gettext_noop("Cache")); + appendPQExpBuffer(&buf, + "FROM pg_catalog.pg_sequence\n" + "WHERE seqrelid = '%s';", + oid); res = PSQLexec(buf.data); if (!res) @@ -1913,7 +1913,7 @@ describeOneTableDetails(const char *schemaname, appendPQExpBufferStr(&buf, ",\n (SELECT c.collname FROM pg_catalog.pg_collation c, pg_catalog.pg_type t\n" " WHERE c.oid = a.attcollation AND t.oid = a.atttypid AND a.attcollation <> t.typcollation) AS attcollation"); attcoll_col = cols++; - appendPQExpBufferStr(&buf, ",\n a.attidentity"); + appendPQExpBufferStr(&buf, ",\n a.attidentity"); attidentity_col = cols++; if (pset.sversion >= 120000) appendPQExpBufferStr(&buf, ",\n a.attgenerated"); @@ -2326,7 +2326,7 @@ describeOneTableDetails(const char *schemaname, CppAsString2(CONSTRAINT_EXCLUSION) ") AND " "condeferred) AS condeferred,\n"); - appendPQExpBufferStr(&buf, "i.indisreplident,\n"); + appendPQExpBufferStr(&buf, "i.indisreplident,\n"); if (pset.sversion >= 150000) appendPQExpBufferStr(&buf, "i.indnullsnotdistinct,\n"); @@ -2431,7 +2431,7 @@ describeOneTableDetails(const char *schemaname, "pg_catalog.pg_get_indexdef(i.indexrelid, 0, true),\n " "pg_catalog.pg_get_constraintdef(con.oid, true), " "contype, condeferrable, condeferred"); - appendPQExpBufferStr(&buf, ", i.indisreplident"); + appendPQExpBufferStr(&buf, ", i.indisreplident"); appendPQExpBufferStr(&buf, ", c2.reltablespace"); if (pset.sversion >= 180000) appendPQExpBufferStr(&buf, ", con.conperiod"); @@ -2682,81 +2682,80 @@ describeOneTableDetails(const char *schemaname, PQclear(result); /* print any row-level policies */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get row-level policies for this table")); - appendPQExpBufferStr(&buf, "SELECT pol.polname,"); - appendPQExpBufferStr(&buf, - " pol.polpermissive,\n"); - appendPQExpBuffer(&buf, - " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" - " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" - " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" - " CASE pol.polcmd\n" - " WHEN 'r' THEN 'SELECT'\n" - " WHEN 'a' THEN 'INSERT'\n" - " WHEN 'w' THEN 'UPDATE'\n" - " WHEN 'd' THEN 'DELETE'\n" - " END AS cmd\n" - "FROM pg_catalog.pg_policy pol\n" - "WHERE pol.polrelid = '%s' ORDER BY 1;", - oid); + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get row-level policies for this table")); + appendPQExpBufferStr(&buf, "SELECT pol.polname,"); + appendPQExpBufferStr(&buf, + " pol.polpermissive,\n"); + appendPQExpBuffer(&buf, + " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" + " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" + " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" + " CASE pol.polcmd\n" + " WHEN 'r' THEN 'SELECT'\n" + " WHEN 'a' THEN 'INSERT'\n" + " WHEN 'w' THEN 'UPDATE'\n" + " WHEN 'd' THEN 'DELETE'\n" + " END AS cmd\n" + "FROM pg_catalog.pg_policy pol\n" + "WHERE pol.polrelid = '%s' ORDER BY 1;", + oid); - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - /* - * Handle cases where RLS is enabled and there are policies, or - * there aren't policies, or RLS isn't enabled but there are - * policies - */ - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies:")); + /* + * Handle cases where RLS is enabled and there are policies, or there + * aren't policies, or RLS isn't enabled but there are policies + */ + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies:")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled):")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled):")); - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); - if (!tableinfo.rowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (row security disabled):")); + if (!tableinfo.rowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (row security disabled):")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " POLICY \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " POLICY \"%s\"", + PQgetvalue(result, i, 0)); - if (*(PQgetvalue(result, i, 1)) == 'f') - appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); + if (*(PQgetvalue(result, i, 1)) == 'f') + appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); - if (!PQgetisnull(result, i, 5)) - appendPQExpBuffer(&buf, " FOR %s", - PQgetvalue(result, i, 5)); + if (!PQgetisnull(result, i, 5)) + appendPQExpBuffer(&buf, " FOR %s", + PQgetvalue(result, i, 5)); - if (!PQgetisnull(result, i, 2)) - { - appendPQExpBuffer(&buf, "\n TO %s", - PQgetvalue(result, i, 2)); - } + if (!PQgetisnull(result, i, 2)) + { + appendPQExpBuffer(&buf, "\n TO %s", + PQgetvalue(result, i, 2)); + } - if (!PQgetisnull(result, i, 3)) - appendPQExpBuffer(&buf, "\n USING (%s)", - PQgetvalue(result, i, 3)); + if (!PQgetisnull(result, i, 3)) + appendPQExpBuffer(&buf, "\n USING (%s)", + PQgetvalue(result, i, 3)); - if (!PQgetisnull(result, i, 4)) - appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", - PQgetvalue(result, i, 4)); + if (!PQgetisnull(result, i, 4)) + appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", + PQgetvalue(result, i, 4)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* print any extended statistics */ if (pset.sversion >= 140000) @@ -3025,115 +3024,115 @@ describeOneTableDetails(const char *schemaname, } /* print any publications */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get publications that publish this table")); - if (pset.sversion >= 150000) + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get publications that publish this table")); + if (pset.sversion >= 150000) + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" + " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" + "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" + "UNION\n" + "SELECT pubname\n" + " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" + " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" + " (SELECT pg_catalog.string_agg(attname, ', ')\n" + " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" + " pg_catalog.pg_attribute\n" + " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" + " ELSE NULL END) " + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" + "WHERE pr.prrelid = '%s'\n", + oid, oid, oid); + + if (pset.sversion >= 190000) { + /* + * Skip entries where this relation appears in the + * publication's EXCEPT list. + */ appendPQExpBuffer(&buf, + " AND NOT pr.prexcept\n" + "UNION\n" "SELECT pubname\n" " , NULL\n" " , NULL\n" "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" - " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" - "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" - "UNION\n" - "SELECT pubname\n" - " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" - " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" - " (SELECT pg_catalog.string_agg(attname, ', ')\n" - " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" - " pg_catalog.pg_attribute\n" - " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" - " ELSE NULL END) " - "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" - "WHERE pr.prrelid = '%s'\n", + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + " AND NOT EXISTS (\n" + " SELECT 1\n" + " FROM pg_catalog.pg_publication_rel pr\n" + " WHERE pr.prpubid = p.oid AND\n" + " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" + "ORDER BY 1;", oid, oid, oid); - - if (pset.sversion >= 190000) - { - /* - * Skip entries where this relation appears in the - * publication's EXCEPT list. - */ - appendPQExpBuffer(&buf, - " AND NOT pr.prexcept\n" - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - " AND NOT EXISTS (\n" - " SELECT 1\n" - " FROM pg_catalog.pg_publication_rel pr\n" - " WHERE pr.prpubid = p.oid AND\n" - " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" - "ORDER BY 1;", - oid, oid, oid); - } - else - { - appendPQExpBuffer(&buf, - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - "ORDER BY 1;", - oid); - } } else { appendPQExpBuffer(&buf, + "UNION\n" "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - "WHERE pr.prrelid = '%s'\n" - "UNION ALL\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" + " , NULL\n" + " , NULL\n" "FROM pg_catalog.pg_publication p\n" "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" "ORDER BY 1;", - oid, oid); + oid); } + } + else + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + "WHERE pr.prrelid = '%s'\n" + "UNION ALL\n" + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + "ORDER BY 1;", + oid, oid); + } - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - if (tuples > 0) - printTableAddFooter(&cont, _("Included in publications:")); + if (tuples > 0) + printTableAddFooter(&cont, _("Included in publications:")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " \"%s\"", + PQgetvalue(result, i, 0)); - /* column list (if any) */ - if (!PQgetisnull(result, i, 2)) - appendPQExpBuffer(&buf, " (%s)", - PQgetvalue(result, i, 2)); + /* column list (if any) */ + if (!PQgetisnull(result, i, 2)) + appendPQExpBuffer(&buf, " (%s)", + PQgetvalue(result, i, 2)); - /* row filter (if any) */ - if (!PQgetisnull(result, i, 1)) - appendPQExpBuffer(&buf, " WHERE %s", - PQgetvalue(result, i, 1)); + /* row filter (if any) */ + if (!PQgetisnull(result, i, 1)) + appendPQExpBuffer(&buf, " WHERE %s", + PQgetvalue(result, i, 1)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* Print publications where the table is in the EXCEPT clause */ if (pset.sversion >= 190000) @@ -3805,7 +3804,7 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) ncols++; } appendPQExpBufferStr(&buf, "\n, r.rolreplication"); - appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); + appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_roles r\n"); @@ -3860,8 +3859,8 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) if (strcmp(PQgetvalue(res, i, (verbose ? 9 : 8)), "t") == 0) add_role_attribute(&buf, _("Replication")); - if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) - add_role_attribute(&buf, _("Bypass RLS")); + if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) + add_role_attribute(&buf, _("Bypass RLS")); conns = atoi(PQgetvalue(res, i, 6)); if (conns >= 0) @@ -5155,14 +5154,14 @@ listCollations(const char *pattern, bool verbose, bool showSystem) gettext_noop("Schema"), gettext_noop("Name")); - appendPQExpBuffer(&buf, - " CASE c.collprovider " - "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " - "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " - "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " - "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " - "END AS \"%s\",\n", - gettext_noop("Provider")); + appendPQExpBuffer(&buf, + " CASE c.collprovider " + "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " + "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " + "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " + "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " + "END AS \"%s\",\n", + gettext_noop("Provider")); appendPQExpBuffer(&buf, " c.collcollate AS \"%s\",\n" -- 2.50.1 (Apple Git-155) --aHl3HfeiUuO3zeNC-- ^ permalink raw reply [nested|flat] 59+ messages in thread
* [PATCH v6 4/4] run pgindent and pgperltidy @ 2026-06-30 18:24 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 59+ messages in thread From: Nathan Bossart @ 2026-06-30 18:24 UTC (permalink / raw) --- src/bin/pg_dump/pg_dump.c | 464 ++++++++++----------- src/bin/pg_dump/pg_dumpall.c | 30 +- src/bin/pg_upgrade/check.c | 16 +- src/bin/pg_upgrade/controldata.c | 2 +- src/bin/pg_upgrade/exec.c | 8 +- src/bin/pg_upgrade/multixact_rewrite.c | 80 ++-- src/bin/pg_upgrade/pg_upgrade.c | 34 +- src/bin/pg_upgrade/relfilenumber.c | 54 +-- src/bin/pg_upgrade/t/006_transfer_modes.pl | 33 +- src/bin/psql/command.c | 29 +- src/bin/psql/describe.c | 461 ++++++++++---------- 11 files changed, 601 insertions(+), 610 deletions(-) diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 65bd15ebfd2..5673268b467 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -1491,8 +1491,8 @@ setup_connection(Archive *AH, const char *dumpencoding, * Disable timeouts if supported. */ ExecuteSqlStatement(AH, "SET statement_timeout = 0"); - ExecuteSqlStatement(AH, "SET lock_timeout = 0"); - ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); + ExecuteSqlStatement(AH, "SET lock_timeout = 0"); + ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); if (AH->remoteVersion >= 170000) ExecuteSqlStatement(AH, "SET transaction_timeout = 0"); @@ -1505,10 +1505,10 @@ setup_connection(Archive *AH, const char *dumpencoding, /* * Adjust row-security mode, if supported. */ - if (dopt->enable_row_security) - ExecuteSqlStatement(AH, "SET row_security = on"); - else - ExecuteSqlStatement(AH, "SET row_security = off"); + if (dopt->enable_row_security) + ExecuteSqlStatement(AH, "SET row_security = on"); + else + ExecuteSqlStatement(AH, "SET row_security = off"); /* * For security reasons, we restrict the expansion of non-system views and @@ -1933,10 +1933,9 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) addObjectDependency(dobj, ext->dobj.dumpId); /* - * Mark the member object to have any non-initial ACLs - * dumped. (Any initial ACLs will be removed later, using data from - * pg_init_privs, so that we'll dump only the delta from the extension's - * initial setup.) + * Mark the member object to have any non-initial ACLs dumped. (Any + * initial ACLs will be removed later, using data from pg_init_privs, so + * that we'll dump only the delta from the extension's initial setup.) * * In binary upgrades, we still dump all components of the members * individually, since the idea is to exactly reproduce the database @@ -1953,7 +1952,7 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) if (fout->dopt->binary_upgrade) dobj->dump = ext->dobj.dump; else - dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); + dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); return true; } @@ -1987,9 +1986,9 @@ selectDumpableNamespace(NamespaceInfo *nsinfo, Archive *fout) else if (strcmp(nsinfo->dobj.name, "pg_catalog") == 0) { /* - * We dump out any ACLs defined in pg_catalog, if - * they are interesting (and not the original ACLs which were set at - * initdb time, see pg_init_privs). + * We dump out any ACLs defined in pg_catalog, if they are interesting + * (and not the original ACLs which were set at initdb time, see + * pg_init_privs). */ nsinfo->dobj.dump_contains = nsinfo->dobj.dump = DUMP_COMPONENT_ACL; } @@ -3296,7 +3295,7 @@ dumpDatabase(Archive *fout) "datcollate, datctype, datfrozenxid, " "datacl, acldefault('d', datdba) AS acldefault, " "datistemplate, datconnlimit, "); - appendPQExpBufferStr(dbQry, "datminmxid, "); + appendPQExpBufferStr(dbQry, "datminmxid, "); if (fout->remoteVersion >= 170000) appendPQExpBufferStr(dbQry, "datlocprovider, datlocale, datcollversion, "); else if (fout->remoteVersion >= 150000) @@ -3638,11 +3637,11 @@ dumpDatabase(Archive *fout) ii_oid, ii_relminmxid; - appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" - "FROM pg_catalog.pg_class\n" - "WHERE oid IN (%u, %u, %u, %u);\n", - LargeObjectRelationId, LargeObjectLOidPNIndexId, - LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); + appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" + "FROM pg_catalog.pg_class\n" + "WHERE oid IN (%u, %u, %u, %u);\n", + LargeObjectRelationId, LargeObjectLOidPNIndexId, + LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); lo_res = ExecuteSqlQuery(fout, loFrozenQry->data, PGRES_TUPLES_OK); @@ -4274,7 +4273,7 @@ getPolicies(Archive *fout, TableInfo tblinfo[], int numTables) printfPQExpBuffer(query, "SELECT pol.oid, pol.tableoid, pol.polrelid, pol.polname, pol.polcmd, "); - appendPQExpBufferStr(query, "pol.polpermissive, "); + appendPQExpBufferStr(query, "pol.polpermissive, "); appendPQExpBuffer(query, "CASE WHEN pol.polroles = '{0}' THEN NULL ELSE " " pg_catalog.array_to_string(ARRAY(SELECT pg_catalog.quote_ident(rolname) from pg_catalog.pg_roles WHERE oid = ANY(pol.polroles)), ', ') END AS polroles, " @@ -6633,9 +6632,9 @@ getAccessMethods(Archive *fout) * Select all access methods from pg_am table. */ appendPQExpBufferStr(query, "SELECT tableoid, oid, amname, "); - appendPQExpBufferStr(query, - "amtype, " - "amhandler::pg_catalog.regproc AS amhandler "); + appendPQExpBufferStr(query, + "amtype, " + "amhandler::pg_catalog.regproc AS amhandler "); appendPQExpBufferStr(query, "FROM pg_am"); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6827,35 +6826,35 @@ getAggregates(Archive *fout) * Find all interesting aggregates. See comment in getFuncs() for the * rationale behind the filtering logic. */ - agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" - : "p.proisagg"); + agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" + : "p.proisagg"); - appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " - "p.proname AS aggname, " - "p.pronamespace AS aggnamespace, " - "p.pronargs, p.proargtypes, " - "p.proowner, " - "p.proacl AS aggacl, " - "acldefault('f', p.proowner) AS acldefault " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s AND (" - "p.pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog') OR " - "p.proacl IS DISTINCT FROM pip.initprivs", - agg_check); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - " OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); - appendPQExpBufferChar(query, ')'); + appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " + "p.proname AS aggname, " + "p.pronamespace AS aggnamespace, " + "p.pronargs, p.proargtypes, " + "p.proowner, " + "p.proacl AS aggacl, " + "acldefault('f', p.proowner) AS acldefault " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s AND (" + "p.pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog') OR " + "p.proacl IS DISTINCT FROM pip.initprivs", + agg_check); + if (dopt->binary_upgrade) + appendPQExpBufferStr(query, + " OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6957,53 +6956,53 @@ getFuncs(Archive *fout) * include them, since we want to dump extension members individually in * that mode. Also, if they are used by casts or transforms then we need * to gather the information about them, though they won't be dumped if - * they are built-in. Also, include functions in - * pg_catalog if they have an ACL different from what's shown in - * pg_init_privs (so we have to join to pg_init_privs; annoying). + * they are built-in. Also, include functions in pg_catalog if they have + * an ACL different from what's shown in pg_init_privs (so we have to join + * to pg_init_privs; annoying). */ - not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" - : "NOT p.proisagg"); + not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" + : "NOT p.proisagg"); - appendPQExpBuffer(query, - "SELECT p.tableoid, p.oid, p.proname, p.prolang, " - "p.pronargs, p.proargtypes, p.prorettype, " - "p.proacl, " - "acldefault('f', p.proowner) AS acldefault, " - "p.pronamespace, " - "p.proowner " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s" - "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " - "WHERE classid = 'pg_proc'::regclass AND " - "objid = p.oid AND deptype = 'i')" - "\n AND (" - "\n pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog')" - "\n OR EXISTS (SELECT 1 FROM pg_cast" - "\n WHERE pg_cast.oid > %u " - "\n AND p.oid = pg_cast.castfunc)" - "\n OR EXISTS (SELECT 1 FROM pg_transform" - "\n WHERE pg_transform.oid > %u AND " - "\n (p.oid = pg_transform.trffromsql" - "\n OR p.oid = pg_transform.trftosql))", - not_agg_check, - g_last_builtin_oid, - g_last_builtin_oid); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); + appendPQExpBuffer(query, + "SELECT p.tableoid, p.oid, p.proname, p.prolang, " + "p.pronargs, p.proargtypes, p.prorettype, " + "p.proacl, " + "acldefault('f', p.proowner) AS acldefault, " + "p.pronamespace, " + "p.proowner " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s" + "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " + "WHERE classid = 'pg_proc'::regclass AND " + "objid = p.oid AND deptype = 'i')" + "\n AND (" + "\n pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog')" + "\n OR EXISTS (SELECT 1 FROM pg_cast" + "\n WHERE pg_cast.oid > %u " + "\n AND p.oid = pg_cast.castfunc)" + "\n OR EXISTS (SELECT 1 FROM pg_transform" + "\n WHERE pg_transform.oid > %u AND " + "\n (p.oid = pg_transform.trffromsql" + "\n OR p.oid = pg_transform.trftosql))", + not_agg_check, + g_last_builtin_oid, + g_last_builtin_oid); + if (dopt->binary_upgrade) appendPQExpBufferStr(query, - "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); - appendPQExpBufferChar(query, ')'); + "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferStr(query, + "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -7252,31 +7251,31 @@ getTables(Archive *fout, int *numTables) appendPQExpBufferStr(query, "c.relhasoids, "); - appendPQExpBufferStr(query, - "c.relispopulated, "); + appendPQExpBufferStr(query, + "c.relispopulated, "); - appendPQExpBufferStr(query, - "c.relreplident, "); + appendPQExpBufferStr(query, + "c.relreplident, "); - appendPQExpBufferStr(query, - "c.relrowsecurity, c.relforcerowsecurity, "); + appendPQExpBufferStr(query, + "c.relrowsecurity, c.relforcerowsecurity, "); - appendPQExpBufferStr(query, - "c.relminmxid, tc.relminmxid AS tminmxid, "); + appendPQExpBufferStr(query, + "c.relminmxid, tc.relminmxid AS tminmxid, "); - appendPQExpBufferStr(query, - "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); + appendPQExpBufferStr(query, + "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); - appendPQExpBufferStr(query, - "am.amname, "); + appendPQExpBufferStr(query, + "am.amname, "); - appendPQExpBufferStr(query, - "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); + appendPQExpBufferStr(query, + "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); - appendPQExpBufferStr(query, - "c.relispartition AS ispartition "); + appendPQExpBufferStr(query, + "c.relispartition AS ispartition "); /* * Left join to pg_depend to pick up dependency info linking sequences to @@ -7296,8 +7295,8 @@ getTables(Archive *fout, int *numTables) /* * Left join to pg_am to pick up the amname. */ - appendPQExpBufferStr(query, - "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); + appendPQExpBufferStr(query, + "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); /* * We purposefully ignore toast OIDs for partitioned tables; the reason is @@ -7868,8 +7867,8 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables) "t.reloptions AS indreloptions, "); - appendPQExpBufferStr(query, - "i.indisreplident, "); + appendPQExpBufferStr(query, + "i.indisreplident, "); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -9313,8 +9312,8 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables) appendPQExpBufferStr(q, "'' AS attcompression,\n"); - appendPQExpBufferStr(q, - "a.attidentity,\n"); + appendPQExpBufferStr(q, + "a.attidentity,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(q, @@ -10717,73 +10716,73 @@ getAdditionalACLs(Archive *fout) PQclear(res); /* Fetch initial-privileges data */ - printfPQExpBuffer(query, - "SELECT objoid, classoid, objsubid, privtype, initprivs " - "FROM pg_init_privs"); + printfPQExpBuffer(query, + "SELECT objoid, classoid, objsubid, privtype, initprivs " + "FROM pg_init_privs"); - res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); + res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); - ntups = PQntuples(res); - for (i = 0; i < ntups; i++) - { - Oid objoid = atooid(PQgetvalue(res, i, 0)); - Oid classoid = atooid(PQgetvalue(res, i, 1)); - int objsubid = atoi(PQgetvalue(res, i, 2)); - char privtype = *(PQgetvalue(res, i, 3)); - char *initprivs = PQgetvalue(res, i, 4); - CatalogId objId; - DumpableObject *dobj; + ntups = PQntuples(res); + for (i = 0; i < ntups; i++) + { + Oid objoid = atooid(PQgetvalue(res, i, 0)); + Oid classoid = atooid(PQgetvalue(res, i, 1)); + int objsubid = atoi(PQgetvalue(res, i, 2)); + char privtype = *(PQgetvalue(res, i, 3)); + char *initprivs = PQgetvalue(res, i, 4); + CatalogId objId; + DumpableObject *dobj; - objId.tableoid = classoid; - objId.oid = objoid; - dobj = findObjectByCatalogId(objId); - /* OK to ignore entries we haven't got a DumpableObject for */ - if (dobj) + objId.tableoid = classoid; + objId.oid = objoid; + dobj = findObjectByCatalogId(objId); + /* OK to ignore entries we haven't got a DumpableObject for */ + if (dobj) + { + /* Cope with sub-object initprivs */ + if (objsubid != 0) { - /* Cope with sub-object initprivs */ - if (objsubid != 0) - { - if (dobj->objType == DO_TABLE) - { - /* For a column initprivs, set the table's ACL flags */ - dobj->components |= DUMP_COMPONENT_ACL; - ((TableInfo *) dobj)->hascolumnACLs = true; - } - else - pg_log_warning("unsupported pg_init_privs entry: %u %u %d", - classoid, objoid, objsubid); - continue; - } - - /* - * We ignore any pg_init_privs.initprivs entry for the public - * schema, as explained in getNamespaces(). - */ - if (dobj->objType == DO_NAMESPACE && - strcmp(dobj->name, "public") == 0) - continue; - - /* Else it had better be of a type we think has ACLs */ - if (dobj->objType == DO_NAMESPACE || - dobj->objType == DO_TYPE || - dobj->objType == DO_FUNC || - dobj->objType == DO_AGG || - dobj->objType == DO_TABLE || - dobj->objType == DO_PROCLANG || - dobj->objType == DO_FDW || - dobj->objType == DO_FOREIGN_SERVER) + if (dobj->objType == DO_TABLE) { - DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; - - daobj->dacl.privtype = privtype; - daobj->dacl.initprivs = pstrdup(initprivs); + /* For a column initprivs, set the table's ACL flags */ + dobj->components |= DUMP_COMPONENT_ACL; + ((TableInfo *) dobj)->hascolumnACLs = true; } else pg_log_warning("unsupported pg_init_privs entry: %u %u %d", classoid, objoid, objsubid); + continue; + } + + /* + * We ignore any pg_init_privs.initprivs entry for the public + * schema, as explained in getNamespaces(). + */ + if (dobj->objType == DO_NAMESPACE && + strcmp(dobj->name, "public") == 0) + continue; + + /* Else it had better be of a type we think has ACLs */ + if (dobj->objType == DO_NAMESPACE || + dobj->objType == DO_TYPE || + dobj->objType == DO_FUNC || + dobj->objType == DO_AGG || + dobj->objType == DO_TABLE || + dobj->objType == DO_PROCLANG || + dobj->objType == DO_FDW || + dobj->objType == DO_FOREIGN_SERVER) + { + DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; + + daobj->dacl.privtype = privtype; + daobj->dacl.initprivs = pstrdup(initprivs); } + else + pg_log_warning("unsupported pg_init_privs entry: %u %u %d", + classoid, objoid, objsubid); } - PQclear(res); + } + PQclear(res); destroyPQExpBuffer(query); } @@ -11128,8 +11127,8 @@ dumpRelationStats_dumper(Archive *fout, const void *userArg, const TocEntry *te) * The results must be in the order of the relations supplied in the * parameters to ensure we remain in sync as we walk through the TOC. * - * For versions before 19, the redundant filter clause on s.tablename = - * ANY(...) seems sufficient to convince the planner to use + * For versions before 19, the redundant filter clause on s.tablename + * = ANY(...) seems sufficient to convince the planner to use * pg_class_relname_nsp_index, which avoids a full scan of pg_stats. * In newer versions, pg_stats returns the table OIDs, eliminating the * need for that hack. @@ -13469,11 +13468,11 @@ dumpFunc(Archive *fout, const FuncInfo *finfo) "pg_catalog.pg_get_function_result(p.oid) AS funcresult,\n" "proleakproof,\n"); - appendPQExpBufferStr(query, - "array_to_string(protrftypes, ' ') AS protrftypes,\n"); + appendPQExpBufferStr(query, + "array_to_string(protrftypes, ' ') AS protrftypes,\n"); - appendPQExpBufferStr(query, - "proparallel,\n"); + appendPQExpBufferStr(query, + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -14963,9 +14962,9 @@ dumpCollation(Archive *fout, const CollInfo *collinfo) /* Get collation-specific details */ appendPQExpBufferStr(query, "SELECT "); - appendPQExpBufferStr(query, - "collprovider, " - "collversion, "); + appendPQExpBufferStr(query, + "collprovider, " + "collversion, "); if (fout->remoteVersion >= 120000) appendPQExpBufferStr(query, @@ -15372,23 +15371,23 @@ dumpAgg(Archive *fout, const AggInfo *agginfo) "pg_catalog.pg_get_function_arguments(p.oid) AS funcargs,\n" "pg_catalog.pg_get_function_identity_arguments(p.oid) AS funciargs,\n"); - appendPQExpBufferStr(query, - "aggkind,\n" - "aggmtransfn,\n" - "aggminvtransfn,\n" - "aggmfinalfn,\n" - "aggmtranstype::pg_catalog.regtype,\n" - "aggfinalextra,\n" - "aggmfinalextra,\n" - "aggtransspace,\n" - "aggmtransspace,\n" - "aggminitval,\n"); + appendPQExpBufferStr(query, + "aggkind,\n" + "aggmtransfn,\n" + "aggminvtransfn,\n" + "aggmfinalfn,\n" + "aggmtranstype::pg_catalog.regtype,\n" + "aggfinalextra,\n" + "aggmfinalextra,\n" + "aggtransspace,\n" + "aggmtransspace,\n" + "aggminitval,\n"); - appendPQExpBufferStr(query, - "aggcombinefn,\n" - "aggserialfn,\n" - "aggdeserialfn,\n" - "proparallel,\n"); + appendPQExpBufferStr(query, + "aggcombinefn,\n" + "aggserialfn,\n" + "aggdeserialfn,\n" + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -16848,30 +16847,30 @@ dumpTable(Archive *fout, const TableInfo *tbinfo) appendPQExpBufferStr(query, "PREPARE getColumnACLs(pg_catalog.oid) AS\n"); - /* - * In principle we should call acldefault('c', relowner) to - * get the default ACL for a column. However, we don't - * currently store the numeric OID of the relowner in - * TableInfo. We could convert the owner name using regrole, - * but that creates a risk of failure due to concurrent role - * renames. Given that the default ACL for columns is empty - * and is likely to stay that way, it's not worth extra cycles - * and risk to avoid hard-wiring that knowledge here. - */ - appendPQExpBufferStr(query, - "SELECT at.attname, " - "at.attacl, " - "'{}' AS acldefault, " - "pip.privtype, pip.initprivs " - "FROM pg_catalog.pg_attribute at " - "LEFT JOIN pg_catalog.pg_init_privs pip ON " - "(at.attrelid = pip.objoid " - "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " - "AND at.attnum = pip.objsubid) " - "WHERE at.attrelid = $1 AND " - "NOT at.attisdropped " - "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " - "ORDER BY at.attnum"); + /* + * In principle we should call acldefault('c', relowner) to get + * the default ACL for a column. However, we don't currently + * store the numeric OID of the relowner in TableInfo. We could + * convert the owner name using regrole, but that creates a risk + * of failure due to concurrent role renames. Given that the + * default ACL for columns is empty and is likely to stay that + * way, it's not worth extra cycles and risk to avoid hard-wiring + * that knowledge here. + */ + appendPQExpBufferStr(query, + "SELECT at.attname, " + "at.attacl, " + "'{}' AS acldefault, " + "pip.privtype, pip.initprivs " + "FROM pg_catalog.pg_attribute at " + "LEFT JOIN pg_catalog.pg_init_privs pip ON " + "(at.attrelid = pip.objoid " + "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " + "AND at.attnum = pip.objsubid) " + "WHERE at.attrelid = $1 AND " + "NOT at.attisdropped " + "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " + "ORDER BY at.attnum"); ExecuteSqlStatement(fout, query->data); @@ -19165,7 +19164,7 @@ collectSequences(Archive *fout) * pg_get_sequence_data(), but we only do so for non-schema-only dumps. */ if (fout->remoteVersion < 180000 || - (!fout->dopt->dumpData && !fout->dopt->sequence_data)) + (!fout->dopt->dumpData && !fout->dopt->sequence_data)) query = "SELECT seqrelid, format_type(seqtypid, NULL), " "seqstart, seqincrement, " "seqmax, seqmin, " @@ -19227,15 +19226,14 @@ dumpSequence(Archive *fout, const TableInfo *tbinfo) qseqname = pg_strdup(fmtId(tbinfo->dobj.name)); /* - * The sequence information is gathered in a sorted - * table before any calls to dumpSequence(). See collectSequences() for - * more information. + * The sequence information is gathered in a sorted table before any calls + * to dumpSequence(). See collectSequences() for more information. */ - Assert(sequences); + Assert(sequences); - key.oid = tbinfo->dobj.catId.oid; - seq = bsearch(&key, sequences, nsequences, - sizeof(SequenceItem), SequenceItemCmp); + key.oid = tbinfo->dobj.catId.oid; + seq = bsearch(&key, sequences, nsequences, + sizeof(SequenceItem), SequenceItemCmp); /* Calculate default limits for a sequence of this type */ is_ascending = (seq->incby >= 0); diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c index e68937c9934..afcd9a218d8 100644 --- a/src/bin/pg_dump/pg_dumpall.c +++ b/src/bin/pg_dump/pg_dumpall.c @@ -785,11 +785,11 @@ dropRoles(PGconn *conn) int i_rolname; int i; - printfPQExpBuffer(buf, - "SELECT rolname " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 1", role_catalog); + printfPQExpBuffer(buf, + "SELECT rolname " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 1", role_catalog); res = executeQuery(conn, buf->data); @@ -843,16 +843,16 @@ dumpRoles(PGconn *conn) * Notes: rolconfig is dumped later, and pg_authid must be used for * extracting rolcomment regardless of role_catalog. */ - printfPQExpBuffer(buf, - "SELECT oid, rolname, rolsuper, rolinherit, " - "rolcreaterole, rolcreatedb, " - "rolcanlogin, rolconnlimit, rolpassword, " - "rolvaliduntil, rolreplication, rolbypassrls, " - "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " - "rolname = current_user AS is_current_user " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 2", role_catalog); + printfPQExpBuffer(buf, + "SELECT oid, rolname, rolsuper, rolinherit, " + "rolcreaterole, rolcreatedb, " + "rolcanlogin, rolconnlimit, rolpassword, " + "rolvaliduntil, rolreplication, rolbypassrls, " + "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " + "rolname = current_user AS is_current_user " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 2", role_catalog); res = executeQuery(conn, buf->data); diff --git a/src/bin/pg_upgrade/check.c b/src/bin/pg_upgrade/check.c index 786c1474829..f725f5ee3e2 100644 --- a/src/bin/pg_upgrade/check.c +++ b/src/bin/pg_upgrade/check.c @@ -1475,15 +1475,15 @@ check_for_incompatible_polymorphics(ClusterInfo *cluster) ", 'array_cat(anyarray,anyarray)'" ", 'array_prepend(anyelement,anyarray)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_remove(anyarray,anyelement)'" - ", 'array_replace(anyarray,anyelement,anyelement)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_remove(anyarray,anyelement)'" + ", 'array_replace(anyarray,anyelement,anyelement)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_position(anyarray,anyelement)'" - ", 'array_position(anyarray,anyelement,integer)'" - ", 'array_positions(anyarray,anyelement)'" - ", 'width_bucket(anyelement,anyarray)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_position(anyarray,anyelement)'" + ", 'array_position(anyarray,anyelement,integer)'" + ", 'array_positions(anyarray,anyelement)'" + ", 'width_bucket(anyelement,anyarray)'"); /* * The query below hardcodes FirstNormalObjectId as 16384 rather than diff --git a/src/bin/pg_upgrade/controldata.c b/src/bin/pg_upgrade/controldata.c index 8f81c9e9582..02ea02df60f 100644 --- a/src/bin/pg_upgrade/controldata.c +++ b/src/bin/pg_upgrade/controldata.c @@ -228,7 +228,7 @@ get_control_data(ClusterInfo *cluster) p++; /* remove ':' char */ cluster->controldata.chkpnt_nxtepoch = str2uint(p); - p = strchr(p, ':'); + p = strchr(p, ':'); if (p == NULL || strlen(p) <= 1) pg_fatal("%d: controldata retrieval problem", __LINE__); diff --git a/src/bin/pg_upgrade/exec.c b/src/bin/pg_upgrade/exec.c index 44355feea30..a1bdbf373e3 100644 --- a/src/bin/pg_upgrade/exec.c +++ b/src/bin/pg_upgrade/exec.c @@ -55,7 +55,7 @@ get_bin_version(ClusterInfo *cluster) if (sscanf(cmd_output, "%*s %*s %d.%d", &v1, &v2) < 1) pg_fatal("could not get pg_ctl version output from %s", cmd); - cluster->bin_version = v1 * 10000; + cluster->bin_version = v1 * 10000; } @@ -344,8 +344,8 @@ check_data_dir(ClusterInfo *cluster) check_single_dir(pg_data, "pg_subtrans"); check_single_dir(pg_data, PG_TBLSPC_DIR); check_single_dir(pg_data, "pg_twophase"); - check_single_dir(pg_data, "pg_wal"); - check_single_dir(pg_data, "pg_xact"); + check_single_dir(pg_data, "pg_wal"); + check_single_dir(pg_data, "pg_xact"); } @@ -385,7 +385,7 @@ check_bin_dir(ClusterInfo *cluster, bool check_versions) */ get_bin_version(cluster); - check_exec(cluster->bindir, "pg_resetwal", check_versions); + check_exec(cluster->bindir, "pg_resetwal", check_versions); if (cluster == &new_cluster) { diff --git a/src/bin/pg_upgrade/multixact_rewrite.c b/src/bin/pg_upgrade/multixact_rewrite.c index c45b3183684..c7a1416494d 100644 --- a/src/bin/pg_upgrade/multixact_rewrite.c +++ b/src/bin/pg_upgrade/multixact_rewrite.c @@ -61,52 +61,52 @@ rewrite_multixacts(MultiXactId from_multi, MultiXactId to_multi) * Convert old multixids, if needed, by reading them one-by-one from the * old cluster. */ - old_reader = AllocOldMultiXactRead(old_cluster.pgdata, - old_cluster.controldata.chkpnt_nxtmulti, - old_cluster.controldata.chkpnt_nxtmxoff); + old_reader = AllocOldMultiXactRead(old_cluster.pgdata, + old_cluster.controldata.chkpnt_nxtmulti, + old_cluster.controldata.chkpnt_nxtmxoff); - for (MultiXactId multi = from_multi; multi != to_multi;) - { - MultiXactMember member; - bool multixid_valid; - - /* - * Read this multixid's members. - * - * Locking-only XIDs that may be part of multi-xids don't matter - * after upgrade, as there can be no transactions running across - * upgrade. So as a small optimization, we only read one member - * from each multixid: the one updating one, or if there was no - * update, arbitrarily the first locking xid. - */ - multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); + for (MultiXactId multi = from_multi; multi != to_multi;) + { + MultiXactMember member; + bool multixid_valid; - /* - * Write the new offset to pg_multixact/offsets. - * - * Even if this multixid is invalid, we still need to write its - * offset if the *previous* multixid was valid. That's because - * when reading a multixid, the number of members is calculated - * from the difference between the two offsets. - */ - RecordMultiXactOffset(offsets_writer, multi, - (multixid_valid || prev_multixid_valid) ? next_offset : 0); + /* + * Read this multixid's members. + * + * Locking-only XIDs that may be part of multi-xids don't matter after + * upgrade, as there can be no transactions running across upgrade. So + * as a small optimization, we only read one member from each + * multixid: the one updating one, or if there was no update, + * arbitrarily the first locking xid. + */ + multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); - /* Write the members */ - if (multixid_valid) - { - RecordMultiXactMembers(members_writer, next_offset, 1, &member); - next_offset += 1; - } + /* + * Write the new offset to pg_multixact/offsets. + * + * Even if this multixid is invalid, we still need to write its offset + * if the *previous* multixid was valid. That's because when reading + * a multixid, the number of members is calculated from the difference + * between the two offsets. + */ + RecordMultiXactOffset(offsets_writer, multi, + (multixid_valid || prev_multixid_valid) ? next_offset : 0); - /* Advance to next multixid, handling wraparound */ - multi++; - if (multi < FirstMultiXactId) - multi = FirstMultiXactId; - prev_multixid_valid = multixid_valid; + /* Write the members */ + if (multixid_valid) + { + RecordMultiXactMembers(members_writer, next_offset, 1, &member); + next_offset += 1; } - FreeOldMultiXactReader(old_reader); + /* Advance to next multixid, handling wraparound */ + multi++; + if (multi < FirstMultiXactId) + multi = FirstMultiXactId; + prev_multixid_valid = multixid_valid; + } + + FreeOldMultiXactReader(old_reader); /* Write the final 'next' offset to the last SLRU page */ RecordMultiXactOffset(offsets_writer, to_multi, diff --git a/src/bin/pg_upgrade/pg_upgrade.c b/src/bin/pg_upgrade/pg_upgrade.c index c6af9035665..7366fd4627c 100644 --- a/src/bin/pg_upgrade/pg_upgrade.c +++ b/src/bin/pg_upgrade/pg_upgrade.c @@ -833,7 +833,7 @@ copy_xact_xlog_xid(void) * Determine the range of multixacts to convert. */ nxtmulti = old_cluster.controldata.chkpnt_nxtmulti; - oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; + oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; /* handle wraparound */ if (nxtmulti < FirstMultiXactId) nxtmulti = FirstMultiXactId; @@ -898,15 +898,15 @@ set_frozenxids(void) int i_datname; int i_datallowconn; - prep_status("Setting frozenxid and minmxid counters in new cluster"); + prep_status("Setting frozenxid and minmxid counters in new cluster"); conn_template1 = connectToServer(&new_cluster, "template1"); - /* set pg_database.datfrozenxid */ - PQclear(executeQueryOrDie(conn_template1, - "UPDATE pg_catalog.pg_database " - "SET datfrozenxid = '%u'", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_database.datfrozenxid */ + PQclear(executeQueryOrDie(conn_template1, + "UPDATE pg_catalog.pg_database " + "SET datfrozenxid = '%u'", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_database.datminmxid */ PQclear(executeQueryOrDie(conn_template1, @@ -942,16 +942,16 @@ set_frozenxids(void) conn = connectToServer(&new_cluster, datname); - /* set pg_class.relfrozenxid */ - PQclear(executeQueryOrDie(conn, - "UPDATE pg_catalog.pg_class " - "SET relfrozenxid = '%u' " - /* only heap, materialized view, and TOAST are vacuumed */ - "WHERE relkind IN (" - CppAsString2(RELKIND_RELATION) ", " - CppAsString2(RELKIND_MATVIEW) ", " - CppAsString2(RELKIND_TOASTVALUE) ")", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_class.relfrozenxid */ + PQclear(executeQueryOrDie(conn, + "UPDATE pg_catalog.pg_class " + "SET relfrozenxid = '%u' " + /* only heap, materialized view, and TOAST are vacuumed */ + "WHERE relkind IN (" + CppAsString2(RELKIND_RELATION) ", " + CppAsString2(RELKIND_MATVIEW) ", " + CppAsString2(RELKIND_TOASTVALUE) ")", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_class.relminmxid */ PQclear(executeQueryOrDie(conn, diff --git a/src/bin/pg_upgrade/relfilenumber.c b/src/bin/pg_upgrade/relfilenumber.c index ec2ff7acb21..6c467bdc8a5 100644 --- a/src/bin/pg_upgrade/relfilenumber.c +++ b/src/bin/pg_upgrade/relfilenumber.c @@ -587,32 +587,32 @@ transfer_relfile(FileNameMap *map, const char *type_suffix) /* Copying files might take some time, so give feedback. */ pg_log(PG_STATUS, "%s", old_file); - switch (user_opts.transfer_mode) - { - case TRANSFER_MODE_CLONE: - pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", - old_file, new_file); - cloneFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", - old_file, new_file); - copyFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY_FILE_RANGE: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", - old_file, new_file); - copyFileByRange(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_LINK: - pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", - old_file, new_file); - linkFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_SWAP: - /* swap mode is handled in its own code path */ - pg_fatal("should never happen"); - break; - } + switch (user_opts.transfer_mode) + { + case TRANSFER_MODE_CLONE: + pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", + old_file, new_file); + cloneFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", + old_file, new_file); + copyFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY_FILE_RANGE: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", + old_file, new_file); + copyFileByRange(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_LINK: + pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", + old_file, new_file); + linkFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_SWAP: + /* swap mode is handled in its own code path */ + pg_fatal("should never happen"); + break; + } } } diff --git a/src/bin/pg_upgrade/t/006_transfer_modes.pl b/src/bin/pg_upgrade/t/006_transfer_modes.pl index 9efa5dc863c..360d05c4b68 100644 --- a/src/bin/pg_upgrade/t/006_transfer_modes.pl +++ b/src/bin/pg_upgrade/t/006_transfer_modes.pl @@ -29,10 +29,8 @@ sub test_mode } $new->init(); - $new->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); - $old->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); + $new->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); + $old->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); # We can only test security labels if both the old and new installations # have dummy_seclabel. @@ -76,15 +74,14 @@ sub test_mode "CREATE TABLE test4 AS SELECT generate_series(400, 502)"); } - $old->safe_psql('postgres', - "CREATE TABLESPACE inplc_tblspc LOCATION ''"); - $old->safe_psql('postgres', - "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); - $old->safe_psql('postgres', - "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" - ); - $old->safe_psql('testdb3', - "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); + $old->safe_psql('postgres', "CREATE TABLESPACE inplc_tblspc LOCATION ''"); + $old->safe_psql('postgres', + "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); + $old->safe_psql('postgres', + "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" + ); + $old->safe_psql('testdb3', + "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); # While we are here, test handling of large objects. $old->safe_psql( @@ -152,12 +149,10 @@ sub test_mode } # Tests for in-place tablespaces. - $result = - $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); - is($result, '104', "test5 data after pg_upgrade $mode"); - $result = - $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); - is($result, '105', "test6 data after pg_upgrade $mode"); + $result = $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); + is($result, '104', "test5 data after pg_upgrade $mode"); + $result = $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); + is($result, '105', "test6 data after pg_upgrade $mode"); # Tests for large objects $result = $new->safe_psql('postgres', "SELECT lo_get(4532)"); diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index 44ef11d980e..c90bf8bbde2 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -6278,23 +6278,22 @@ get_create_object_cmd(EditableObjectType obj_type, Oid oid, * ensure the right view gets replaced. Also, check relation kind * to be sure it's a view. * - * Views may have WITH [LOCAL|CASCADED] - * CHECK OPTION. These are not part of the view definition - * returned by pg_get_viewdef() and so need to be retrieved - * separately. Materialized views may have - * arbitrary storage parameter reloptions. + * Views may have WITH [LOCAL|CASCADED] CHECK OPTION. These are + * not part of the view definition returned by pg_get_viewdef() + * and so need to be retrieved separately. Materialized views may + * have arbitrary storage parameter reloptions. */ printfPQExpBuffer(query, "/* %s */\n", _("Get view's definition and details")); - appendPQExpBuffer(query, - "SELECT nspname, relname, relkind, " - "pg_catalog.pg_get_viewdef(c.oid, true), " - "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " - "FROM pg_catalog.pg_class c " - "LEFT JOIN pg_catalog.pg_namespace n " - "ON c.relnamespace = n.oid WHERE c.oid = %u", - oid); + appendPQExpBuffer(query, + "SELECT nspname, relname, relkind, " + "pg_catalog.pg_get_viewdef(c.oid, true), " + "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " + "FROM pg_catalog.pg_class c " + "LEFT JOIN pg_catalog.pg_namespace n " + "ON c.relnamespace = n.oid WHERE c.oid = %u", + oid); break; } diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index ce99137c613..ac0c55e7aa5 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -387,19 +387,19 @@ describeFunctions(const char *functypes, const char *func_pattern, gettext_noop("stable"), gettext_noop("volatile"), gettext_noop("Volatility")); - appendPQExpBuffer(&buf, - ",\n CASE\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" - " END as \"%s\"", - gettext_noop("restricted"), - gettext_noop("safe"), - gettext_noop("unsafe"), - gettext_noop("Parallel")); + appendPQExpBuffer(&buf, + ",\n CASE\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" + " END as \"%s\"", + gettext_noop("restricted"), + gettext_noop("safe"), + gettext_noop("unsafe"), + gettext_noop("Parallel")); appendPQExpBuffer(&buf, ",\n pg_catalog.pg_get_userbyid(p.proowner) as \"%s\"" ",\n CASE WHEN prosecdef THEN '%s' ELSE '%s' END AS \"%s\"" @@ -599,8 +599,8 @@ describeFunctions(const char *functypes, const char *func_pattern, myopt.title = _("List of functions"); myopt.translate_header = true; - myopt.translate_columns = translate_columns; - myopt.n_translate_columns = lengthof(translate_columns); + myopt.translate_columns = translate_columns; + myopt.n_translate_columns = lengthof(translate_columns); printQuery(res, &myopt, pset.queryFout, false, pset.logfile); @@ -1086,38 +1086,38 @@ permissionsList(const char *pattern, bool showSystem) " ), E'\\n') AS \"%s\"", gettext_noop("Column privileges")); - appendPQExpBuffer(&buf, - ",\n pg_catalog.array_to_string(ARRAY(\n" - " SELECT polname\n" - " || CASE WHEN NOT polpermissive THEN\n" - " E' (RESTRICTIVE)'\n" - " ELSE '' END\n" - " || CASE WHEN polcmd != '*' THEN\n" - " E' (' || polcmd::pg_catalog.text || E'):'\n" - " ELSE E':'\n" - " END\n" - " || CASE WHEN polqual IS NOT NULL THEN\n" - " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" - " ELSE E''\n" - " END\n" - " || CASE WHEN polwithcheck IS NOT NULL THEN\n" - " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" - " ELSE E''\n" - " END" - " || CASE WHEN polroles <> '{0}' THEN\n" - " E'\\n to: ' || pg_catalog.array_to_string(\n" - " ARRAY(\n" - " SELECT rolname\n" - " FROM pg_catalog.pg_roles\n" - " WHERE oid = ANY (polroles)\n" - " ORDER BY 1\n" - " ), E', ')\n" - " ELSE E''\n" - " END\n" - " FROM pg_catalog.pg_policy pol\n" - " WHERE polrelid = c.oid), E'\\n')\n" - " AS \"%s\"", - gettext_noop("Policies")); + appendPQExpBuffer(&buf, + ",\n pg_catalog.array_to_string(ARRAY(\n" + " SELECT polname\n" + " || CASE WHEN NOT polpermissive THEN\n" + " E' (RESTRICTIVE)'\n" + " ELSE '' END\n" + " || CASE WHEN polcmd != '*' THEN\n" + " E' (' || polcmd::pg_catalog.text || E'):'\n" + " ELSE E':'\n" + " END\n" + " || CASE WHEN polqual IS NOT NULL THEN\n" + " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" + " ELSE E''\n" + " END\n" + " || CASE WHEN polwithcheck IS NOT NULL THEN\n" + " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" + " ELSE E''\n" + " END" + " || CASE WHEN polroles <> '{0}' THEN\n" + " E'\\n to: ' || pg_catalog.array_to_string(\n" + " ARRAY(\n" + " SELECT rolname\n" + " FROM pg_catalog.pg_roles\n" + " WHERE oid = ANY (polroles)\n" + " ORDER BY 1\n" + " ), E', ')\n" + " ELSE E''\n" + " END\n" + " FROM pg_catalog.pg_policy pol\n" + " WHERE polrelid = c.oid), E'\\n')\n" + " AS \"%s\"", + gettext_noop("Policies")); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_class c\n" " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n" @@ -1675,27 +1675,27 @@ describeOneTableDetails(const char *schemaname, char *footers[3] = {NULL, NULL, NULL}; printfPQExpBuffer(&buf, "/* %s */\n", _("Get sequence information")); - appendPQExpBuffer(&buf, - "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" - " seqstart AS \"%s\",\n" - " seqmin AS \"%s\",\n" - " seqmax AS \"%s\",\n" - " seqincrement AS \"%s\",\n" - " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" - " seqcache AS \"%s\"\n", - gettext_noop("Type"), - gettext_noop("Start"), - gettext_noop("Minimum"), - gettext_noop("Maximum"), - gettext_noop("Increment"), - gettext_noop("yes"), - gettext_noop("no"), - gettext_noop("Cycles?"), - gettext_noop("Cache")); - appendPQExpBuffer(&buf, - "FROM pg_catalog.pg_sequence\n" - "WHERE seqrelid = '%s';", - oid); + appendPQExpBuffer(&buf, + "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" + " seqstart AS \"%s\",\n" + " seqmin AS \"%s\",\n" + " seqmax AS \"%s\",\n" + " seqincrement AS \"%s\",\n" + " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" + " seqcache AS \"%s\"\n", + gettext_noop("Type"), + gettext_noop("Start"), + gettext_noop("Minimum"), + gettext_noop("Maximum"), + gettext_noop("Increment"), + gettext_noop("yes"), + gettext_noop("no"), + gettext_noop("Cycles?"), + gettext_noop("Cache")); + appendPQExpBuffer(&buf, + "FROM pg_catalog.pg_sequence\n" + "WHERE seqrelid = '%s';", + oid); res = PSQLexec(buf.data); if (!res) @@ -1913,7 +1913,7 @@ describeOneTableDetails(const char *schemaname, appendPQExpBufferStr(&buf, ",\n (SELECT c.collname FROM pg_catalog.pg_collation c, pg_catalog.pg_type t\n" " WHERE c.oid = a.attcollation AND t.oid = a.atttypid AND a.attcollation <> t.typcollation) AS attcollation"); attcoll_col = cols++; - appendPQExpBufferStr(&buf, ",\n a.attidentity"); + appendPQExpBufferStr(&buf, ",\n a.attidentity"); attidentity_col = cols++; if (pset.sversion >= 120000) appendPQExpBufferStr(&buf, ",\n a.attgenerated"); @@ -2326,7 +2326,7 @@ describeOneTableDetails(const char *schemaname, CppAsString2(CONSTRAINT_EXCLUSION) ") AND " "condeferred) AS condeferred,\n"); - appendPQExpBufferStr(&buf, "i.indisreplident,\n"); + appendPQExpBufferStr(&buf, "i.indisreplident,\n"); if (pset.sversion >= 150000) appendPQExpBufferStr(&buf, "i.indnullsnotdistinct,\n"); @@ -2431,7 +2431,7 @@ describeOneTableDetails(const char *schemaname, "pg_catalog.pg_get_indexdef(i.indexrelid, 0, true),\n " "pg_catalog.pg_get_constraintdef(con.oid, true), " "contype, condeferrable, condeferred"); - appendPQExpBufferStr(&buf, ", i.indisreplident"); + appendPQExpBufferStr(&buf, ", i.indisreplident"); appendPQExpBufferStr(&buf, ", c2.reltablespace"); if (pset.sversion >= 180000) appendPQExpBufferStr(&buf, ", con.conperiod"); @@ -2682,81 +2682,80 @@ describeOneTableDetails(const char *schemaname, PQclear(result); /* print any row-level policies */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get row-level policies for this table")); - appendPQExpBufferStr(&buf, "SELECT pol.polname,"); - appendPQExpBufferStr(&buf, - " pol.polpermissive,\n"); - appendPQExpBuffer(&buf, - " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" - " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" - " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" - " CASE pol.polcmd\n" - " WHEN 'r' THEN 'SELECT'\n" - " WHEN 'a' THEN 'INSERT'\n" - " WHEN 'w' THEN 'UPDATE'\n" - " WHEN 'd' THEN 'DELETE'\n" - " END AS cmd\n" - "FROM pg_catalog.pg_policy pol\n" - "WHERE pol.polrelid = '%s' ORDER BY 1;", - oid); + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get row-level policies for this table")); + appendPQExpBufferStr(&buf, "SELECT pol.polname,"); + appendPQExpBufferStr(&buf, + " pol.polpermissive,\n"); + appendPQExpBuffer(&buf, + " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" + " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" + " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" + " CASE pol.polcmd\n" + " WHEN 'r' THEN 'SELECT'\n" + " WHEN 'a' THEN 'INSERT'\n" + " WHEN 'w' THEN 'UPDATE'\n" + " WHEN 'd' THEN 'DELETE'\n" + " END AS cmd\n" + "FROM pg_catalog.pg_policy pol\n" + "WHERE pol.polrelid = '%s' ORDER BY 1;", + oid); - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - /* - * Handle cases where RLS is enabled and there are policies, or - * there aren't policies, or RLS isn't enabled but there are - * policies - */ - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies:")); + /* + * Handle cases where RLS is enabled and there are policies, or there + * aren't policies, or RLS isn't enabled but there are policies + */ + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies:")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled):")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled):")); - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); - if (!tableinfo.rowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (row security disabled):")); + if (!tableinfo.rowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (row security disabled):")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " POLICY \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " POLICY \"%s\"", + PQgetvalue(result, i, 0)); - if (*(PQgetvalue(result, i, 1)) == 'f') - appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); + if (*(PQgetvalue(result, i, 1)) == 'f') + appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); - if (!PQgetisnull(result, i, 5)) - appendPQExpBuffer(&buf, " FOR %s", - PQgetvalue(result, i, 5)); + if (!PQgetisnull(result, i, 5)) + appendPQExpBuffer(&buf, " FOR %s", + PQgetvalue(result, i, 5)); - if (!PQgetisnull(result, i, 2)) - { - appendPQExpBuffer(&buf, "\n TO %s", - PQgetvalue(result, i, 2)); - } + if (!PQgetisnull(result, i, 2)) + { + appendPQExpBuffer(&buf, "\n TO %s", + PQgetvalue(result, i, 2)); + } - if (!PQgetisnull(result, i, 3)) - appendPQExpBuffer(&buf, "\n USING (%s)", - PQgetvalue(result, i, 3)); + if (!PQgetisnull(result, i, 3)) + appendPQExpBuffer(&buf, "\n USING (%s)", + PQgetvalue(result, i, 3)); - if (!PQgetisnull(result, i, 4)) - appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", - PQgetvalue(result, i, 4)); + if (!PQgetisnull(result, i, 4)) + appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", + PQgetvalue(result, i, 4)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* print any extended statistics */ if (pset.sversion >= 140000) @@ -3025,115 +3024,115 @@ describeOneTableDetails(const char *schemaname, } /* print any publications */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get publications that publish this table")); - if (pset.sversion >= 150000) + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get publications that publish this table")); + if (pset.sversion >= 150000) + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" + " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" + "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" + "UNION\n" + "SELECT pubname\n" + " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" + " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" + " (SELECT pg_catalog.string_agg(attname, ', ')\n" + " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" + " pg_catalog.pg_attribute\n" + " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" + " ELSE NULL END) " + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" + "WHERE pr.prrelid = '%s'\n", + oid, oid, oid); + + if (pset.sversion >= 190000) { + /* + * Skip entries where this relation appears in the + * publication's EXCEPT list. + */ appendPQExpBuffer(&buf, + " AND NOT pr.prexcept\n" + "UNION\n" "SELECT pubname\n" " , NULL\n" " , NULL\n" "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" - " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" - "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" - "UNION\n" - "SELECT pubname\n" - " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" - " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" - " (SELECT pg_catalog.string_agg(attname, ', ')\n" - " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" - " pg_catalog.pg_attribute\n" - " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" - " ELSE NULL END) " - "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" - "WHERE pr.prrelid = '%s'\n", + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + " AND NOT EXISTS (\n" + " SELECT 1\n" + " FROM pg_catalog.pg_publication_rel pr\n" + " WHERE pr.prpubid = p.oid AND\n" + " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" + "ORDER BY 1;", oid, oid, oid); - - if (pset.sversion >= 190000) - { - /* - * Skip entries where this relation appears in the - * publication's EXCEPT list. - */ - appendPQExpBuffer(&buf, - " AND NOT pr.prexcept\n" - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - " AND NOT EXISTS (\n" - " SELECT 1\n" - " FROM pg_catalog.pg_publication_rel pr\n" - " WHERE pr.prpubid = p.oid AND\n" - " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" - "ORDER BY 1;", - oid, oid, oid); - } - else - { - appendPQExpBuffer(&buf, - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - "ORDER BY 1;", - oid); - } } else { appendPQExpBuffer(&buf, + "UNION\n" "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - "WHERE pr.prrelid = '%s'\n" - "UNION ALL\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" + " , NULL\n" + " , NULL\n" "FROM pg_catalog.pg_publication p\n" "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" "ORDER BY 1;", - oid, oid); + oid); } + } + else + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + "WHERE pr.prrelid = '%s'\n" + "UNION ALL\n" + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + "ORDER BY 1;", + oid, oid); + } - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - if (tuples > 0) - printTableAddFooter(&cont, _("Included in publications:")); + if (tuples > 0) + printTableAddFooter(&cont, _("Included in publications:")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " \"%s\"", + PQgetvalue(result, i, 0)); - /* column list (if any) */ - if (!PQgetisnull(result, i, 2)) - appendPQExpBuffer(&buf, " (%s)", - PQgetvalue(result, i, 2)); + /* column list (if any) */ + if (!PQgetisnull(result, i, 2)) + appendPQExpBuffer(&buf, " (%s)", + PQgetvalue(result, i, 2)); - /* row filter (if any) */ - if (!PQgetisnull(result, i, 1)) - appendPQExpBuffer(&buf, " WHERE %s", - PQgetvalue(result, i, 1)); + /* row filter (if any) */ + if (!PQgetisnull(result, i, 1)) + appendPQExpBuffer(&buf, " WHERE %s", + PQgetvalue(result, i, 1)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* Print publications where the table is in the EXCEPT clause */ if (pset.sversion >= 190000) @@ -3805,7 +3804,7 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) ncols++; } appendPQExpBufferStr(&buf, "\n, r.rolreplication"); - appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); + appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_roles r\n"); @@ -3860,8 +3859,8 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) if (strcmp(PQgetvalue(res, i, (verbose ? 9 : 8)), "t") == 0) add_role_attribute(&buf, _("Replication")); - if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) - add_role_attribute(&buf, _("Bypass RLS")); + if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) + add_role_attribute(&buf, _("Bypass RLS")); conns = atoi(PQgetvalue(res, i, 6)); if (conns >= 0) @@ -5155,14 +5154,14 @@ listCollations(const char *pattern, bool verbose, bool showSystem) gettext_noop("Schema"), gettext_noop("Name")); - appendPQExpBuffer(&buf, - " CASE c.collprovider " - "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " - "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " - "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " - "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " - "END AS \"%s\",\n", - gettext_noop("Provider")); + appendPQExpBuffer(&buf, + " CASE c.collprovider " + "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " + "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " + "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " + "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " + "END AS \"%s\",\n", + gettext_noop("Provider")); appendPQExpBuffer(&buf, " c.collcollate AS \"%s\",\n" -- 2.50.1 (Apple Git-155) --aHl3HfeiUuO3zeNC-- ^ permalink raw reply [nested|flat] 59+ messages in thread
* [PATCH v6 4/4] run pgindent and pgperltidy @ 2026-06-30 18:24 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 59+ messages in thread From: Nathan Bossart @ 2026-06-30 18:24 UTC (permalink / raw) --- src/bin/pg_dump/pg_dump.c | 464 ++++++++++----------- src/bin/pg_dump/pg_dumpall.c | 30 +- src/bin/pg_upgrade/check.c | 16 +- src/bin/pg_upgrade/controldata.c | 2 +- src/bin/pg_upgrade/exec.c | 8 +- src/bin/pg_upgrade/multixact_rewrite.c | 80 ++-- src/bin/pg_upgrade/pg_upgrade.c | 34 +- src/bin/pg_upgrade/relfilenumber.c | 54 +-- src/bin/pg_upgrade/t/006_transfer_modes.pl | 33 +- src/bin/psql/command.c | 29 +- src/bin/psql/describe.c | 461 ++++++++++---------- 11 files changed, 601 insertions(+), 610 deletions(-) diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 65bd15ebfd2..5673268b467 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -1491,8 +1491,8 @@ setup_connection(Archive *AH, const char *dumpencoding, * Disable timeouts if supported. */ ExecuteSqlStatement(AH, "SET statement_timeout = 0"); - ExecuteSqlStatement(AH, "SET lock_timeout = 0"); - ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); + ExecuteSqlStatement(AH, "SET lock_timeout = 0"); + ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); if (AH->remoteVersion >= 170000) ExecuteSqlStatement(AH, "SET transaction_timeout = 0"); @@ -1505,10 +1505,10 @@ setup_connection(Archive *AH, const char *dumpencoding, /* * Adjust row-security mode, if supported. */ - if (dopt->enable_row_security) - ExecuteSqlStatement(AH, "SET row_security = on"); - else - ExecuteSqlStatement(AH, "SET row_security = off"); + if (dopt->enable_row_security) + ExecuteSqlStatement(AH, "SET row_security = on"); + else + ExecuteSqlStatement(AH, "SET row_security = off"); /* * For security reasons, we restrict the expansion of non-system views and @@ -1933,10 +1933,9 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) addObjectDependency(dobj, ext->dobj.dumpId); /* - * Mark the member object to have any non-initial ACLs - * dumped. (Any initial ACLs will be removed later, using data from - * pg_init_privs, so that we'll dump only the delta from the extension's - * initial setup.) + * Mark the member object to have any non-initial ACLs dumped. (Any + * initial ACLs will be removed later, using data from pg_init_privs, so + * that we'll dump only the delta from the extension's initial setup.) * * In binary upgrades, we still dump all components of the members * individually, since the idea is to exactly reproduce the database @@ -1953,7 +1952,7 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) if (fout->dopt->binary_upgrade) dobj->dump = ext->dobj.dump; else - dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); + dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); return true; } @@ -1987,9 +1986,9 @@ selectDumpableNamespace(NamespaceInfo *nsinfo, Archive *fout) else if (strcmp(nsinfo->dobj.name, "pg_catalog") == 0) { /* - * We dump out any ACLs defined in pg_catalog, if - * they are interesting (and not the original ACLs which were set at - * initdb time, see pg_init_privs). + * We dump out any ACLs defined in pg_catalog, if they are interesting + * (and not the original ACLs which were set at initdb time, see + * pg_init_privs). */ nsinfo->dobj.dump_contains = nsinfo->dobj.dump = DUMP_COMPONENT_ACL; } @@ -3296,7 +3295,7 @@ dumpDatabase(Archive *fout) "datcollate, datctype, datfrozenxid, " "datacl, acldefault('d', datdba) AS acldefault, " "datistemplate, datconnlimit, "); - appendPQExpBufferStr(dbQry, "datminmxid, "); + appendPQExpBufferStr(dbQry, "datminmxid, "); if (fout->remoteVersion >= 170000) appendPQExpBufferStr(dbQry, "datlocprovider, datlocale, datcollversion, "); else if (fout->remoteVersion >= 150000) @@ -3638,11 +3637,11 @@ dumpDatabase(Archive *fout) ii_oid, ii_relminmxid; - appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" - "FROM pg_catalog.pg_class\n" - "WHERE oid IN (%u, %u, %u, %u);\n", - LargeObjectRelationId, LargeObjectLOidPNIndexId, - LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); + appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" + "FROM pg_catalog.pg_class\n" + "WHERE oid IN (%u, %u, %u, %u);\n", + LargeObjectRelationId, LargeObjectLOidPNIndexId, + LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); lo_res = ExecuteSqlQuery(fout, loFrozenQry->data, PGRES_TUPLES_OK); @@ -4274,7 +4273,7 @@ getPolicies(Archive *fout, TableInfo tblinfo[], int numTables) printfPQExpBuffer(query, "SELECT pol.oid, pol.tableoid, pol.polrelid, pol.polname, pol.polcmd, "); - appendPQExpBufferStr(query, "pol.polpermissive, "); + appendPQExpBufferStr(query, "pol.polpermissive, "); appendPQExpBuffer(query, "CASE WHEN pol.polroles = '{0}' THEN NULL ELSE " " pg_catalog.array_to_string(ARRAY(SELECT pg_catalog.quote_ident(rolname) from pg_catalog.pg_roles WHERE oid = ANY(pol.polroles)), ', ') END AS polroles, " @@ -6633,9 +6632,9 @@ getAccessMethods(Archive *fout) * Select all access methods from pg_am table. */ appendPQExpBufferStr(query, "SELECT tableoid, oid, amname, "); - appendPQExpBufferStr(query, - "amtype, " - "amhandler::pg_catalog.regproc AS amhandler "); + appendPQExpBufferStr(query, + "amtype, " + "amhandler::pg_catalog.regproc AS amhandler "); appendPQExpBufferStr(query, "FROM pg_am"); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6827,35 +6826,35 @@ getAggregates(Archive *fout) * Find all interesting aggregates. See comment in getFuncs() for the * rationale behind the filtering logic. */ - agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" - : "p.proisagg"); + agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" + : "p.proisagg"); - appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " - "p.proname AS aggname, " - "p.pronamespace AS aggnamespace, " - "p.pronargs, p.proargtypes, " - "p.proowner, " - "p.proacl AS aggacl, " - "acldefault('f', p.proowner) AS acldefault " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s AND (" - "p.pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog') OR " - "p.proacl IS DISTINCT FROM pip.initprivs", - agg_check); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - " OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); - appendPQExpBufferChar(query, ')'); + appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " + "p.proname AS aggname, " + "p.pronamespace AS aggnamespace, " + "p.pronargs, p.proargtypes, " + "p.proowner, " + "p.proacl AS aggacl, " + "acldefault('f', p.proowner) AS acldefault " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s AND (" + "p.pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog') OR " + "p.proacl IS DISTINCT FROM pip.initprivs", + agg_check); + if (dopt->binary_upgrade) + appendPQExpBufferStr(query, + " OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6957,53 +6956,53 @@ getFuncs(Archive *fout) * include them, since we want to dump extension members individually in * that mode. Also, if they are used by casts or transforms then we need * to gather the information about them, though they won't be dumped if - * they are built-in. Also, include functions in - * pg_catalog if they have an ACL different from what's shown in - * pg_init_privs (so we have to join to pg_init_privs; annoying). + * they are built-in. Also, include functions in pg_catalog if they have + * an ACL different from what's shown in pg_init_privs (so we have to join + * to pg_init_privs; annoying). */ - not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" - : "NOT p.proisagg"); + not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" + : "NOT p.proisagg"); - appendPQExpBuffer(query, - "SELECT p.tableoid, p.oid, p.proname, p.prolang, " - "p.pronargs, p.proargtypes, p.prorettype, " - "p.proacl, " - "acldefault('f', p.proowner) AS acldefault, " - "p.pronamespace, " - "p.proowner " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s" - "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " - "WHERE classid = 'pg_proc'::regclass AND " - "objid = p.oid AND deptype = 'i')" - "\n AND (" - "\n pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog')" - "\n OR EXISTS (SELECT 1 FROM pg_cast" - "\n WHERE pg_cast.oid > %u " - "\n AND p.oid = pg_cast.castfunc)" - "\n OR EXISTS (SELECT 1 FROM pg_transform" - "\n WHERE pg_transform.oid > %u AND " - "\n (p.oid = pg_transform.trffromsql" - "\n OR p.oid = pg_transform.trftosql))", - not_agg_check, - g_last_builtin_oid, - g_last_builtin_oid); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); + appendPQExpBuffer(query, + "SELECT p.tableoid, p.oid, p.proname, p.prolang, " + "p.pronargs, p.proargtypes, p.prorettype, " + "p.proacl, " + "acldefault('f', p.proowner) AS acldefault, " + "p.pronamespace, " + "p.proowner " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s" + "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " + "WHERE classid = 'pg_proc'::regclass AND " + "objid = p.oid AND deptype = 'i')" + "\n AND (" + "\n pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog')" + "\n OR EXISTS (SELECT 1 FROM pg_cast" + "\n WHERE pg_cast.oid > %u " + "\n AND p.oid = pg_cast.castfunc)" + "\n OR EXISTS (SELECT 1 FROM pg_transform" + "\n WHERE pg_transform.oid > %u AND " + "\n (p.oid = pg_transform.trffromsql" + "\n OR p.oid = pg_transform.trftosql))", + not_agg_check, + g_last_builtin_oid, + g_last_builtin_oid); + if (dopt->binary_upgrade) appendPQExpBufferStr(query, - "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); - appendPQExpBufferChar(query, ')'); + "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferStr(query, + "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -7252,31 +7251,31 @@ getTables(Archive *fout, int *numTables) appendPQExpBufferStr(query, "c.relhasoids, "); - appendPQExpBufferStr(query, - "c.relispopulated, "); + appendPQExpBufferStr(query, + "c.relispopulated, "); - appendPQExpBufferStr(query, - "c.relreplident, "); + appendPQExpBufferStr(query, + "c.relreplident, "); - appendPQExpBufferStr(query, - "c.relrowsecurity, c.relforcerowsecurity, "); + appendPQExpBufferStr(query, + "c.relrowsecurity, c.relforcerowsecurity, "); - appendPQExpBufferStr(query, - "c.relminmxid, tc.relminmxid AS tminmxid, "); + appendPQExpBufferStr(query, + "c.relminmxid, tc.relminmxid AS tminmxid, "); - appendPQExpBufferStr(query, - "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); + appendPQExpBufferStr(query, + "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); - appendPQExpBufferStr(query, - "am.amname, "); + appendPQExpBufferStr(query, + "am.amname, "); - appendPQExpBufferStr(query, - "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); + appendPQExpBufferStr(query, + "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); - appendPQExpBufferStr(query, - "c.relispartition AS ispartition "); + appendPQExpBufferStr(query, + "c.relispartition AS ispartition "); /* * Left join to pg_depend to pick up dependency info linking sequences to @@ -7296,8 +7295,8 @@ getTables(Archive *fout, int *numTables) /* * Left join to pg_am to pick up the amname. */ - appendPQExpBufferStr(query, - "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); + appendPQExpBufferStr(query, + "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); /* * We purposefully ignore toast OIDs for partitioned tables; the reason is @@ -7868,8 +7867,8 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables) "t.reloptions AS indreloptions, "); - appendPQExpBufferStr(query, - "i.indisreplident, "); + appendPQExpBufferStr(query, + "i.indisreplident, "); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -9313,8 +9312,8 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables) appendPQExpBufferStr(q, "'' AS attcompression,\n"); - appendPQExpBufferStr(q, - "a.attidentity,\n"); + appendPQExpBufferStr(q, + "a.attidentity,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(q, @@ -10717,73 +10716,73 @@ getAdditionalACLs(Archive *fout) PQclear(res); /* Fetch initial-privileges data */ - printfPQExpBuffer(query, - "SELECT objoid, classoid, objsubid, privtype, initprivs " - "FROM pg_init_privs"); + printfPQExpBuffer(query, + "SELECT objoid, classoid, objsubid, privtype, initprivs " + "FROM pg_init_privs"); - res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); + res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); - ntups = PQntuples(res); - for (i = 0; i < ntups; i++) - { - Oid objoid = atooid(PQgetvalue(res, i, 0)); - Oid classoid = atooid(PQgetvalue(res, i, 1)); - int objsubid = atoi(PQgetvalue(res, i, 2)); - char privtype = *(PQgetvalue(res, i, 3)); - char *initprivs = PQgetvalue(res, i, 4); - CatalogId objId; - DumpableObject *dobj; + ntups = PQntuples(res); + for (i = 0; i < ntups; i++) + { + Oid objoid = atooid(PQgetvalue(res, i, 0)); + Oid classoid = atooid(PQgetvalue(res, i, 1)); + int objsubid = atoi(PQgetvalue(res, i, 2)); + char privtype = *(PQgetvalue(res, i, 3)); + char *initprivs = PQgetvalue(res, i, 4); + CatalogId objId; + DumpableObject *dobj; - objId.tableoid = classoid; - objId.oid = objoid; - dobj = findObjectByCatalogId(objId); - /* OK to ignore entries we haven't got a DumpableObject for */ - if (dobj) + objId.tableoid = classoid; + objId.oid = objoid; + dobj = findObjectByCatalogId(objId); + /* OK to ignore entries we haven't got a DumpableObject for */ + if (dobj) + { + /* Cope with sub-object initprivs */ + if (objsubid != 0) { - /* Cope with sub-object initprivs */ - if (objsubid != 0) - { - if (dobj->objType == DO_TABLE) - { - /* For a column initprivs, set the table's ACL flags */ - dobj->components |= DUMP_COMPONENT_ACL; - ((TableInfo *) dobj)->hascolumnACLs = true; - } - else - pg_log_warning("unsupported pg_init_privs entry: %u %u %d", - classoid, objoid, objsubid); - continue; - } - - /* - * We ignore any pg_init_privs.initprivs entry for the public - * schema, as explained in getNamespaces(). - */ - if (dobj->objType == DO_NAMESPACE && - strcmp(dobj->name, "public") == 0) - continue; - - /* Else it had better be of a type we think has ACLs */ - if (dobj->objType == DO_NAMESPACE || - dobj->objType == DO_TYPE || - dobj->objType == DO_FUNC || - dobj->objType == DO_AGG || - dobj->objType == DO_TABLE || - dobj->objType == DO_PROCLANG || - dobj->objType == DO_FDW || - dobj->objType == DO_FOREIGN_SERVER) + if (dobj->objType == DO_TABLE) { - DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; - - daobj->dacl.privtype = privtype; - daobj->dacl.initprivs = pstrdup(initprivs); + /* For a column initprivs, set the table's ACL flags */ + dobj->components |= DUMP_COMPONENT_ACL; + ((TableInfo *) dobj)->hascolumnACLs = true; } else pg_log_warning("unsupported pg_init_privs entry: %u %u %d", classoid, objoid, objsubid); + continue; + } + + /* + * We ignore any pg_init_privs.initprivs entry for the public + * schema, as explained in getNamespaces(). + */ + if (dobj->objType == DO_NAMESPACE && + strcmp(dobj->name, "public") == 0) + continue; + + /* Else it had better be of a type we think has ACLs */ + if (dobj->objType == DO_NAMESPACE || + dobj->objType == DO_TYPE || + dobj->objType == DO_FUNC || + dobj->objType == DO_AGG || + dobj->objType == DO_TABLE || + dobj->objType == DO_PROCLANG || + dobj->objType == DO_FDW || + dobj->objType == DO_FOREIGN_SERVER) + { + DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; + + daobj->dacl.privtype = privtype; + daobj->dacl.initprivs = pstrdup(initprivs); } + else + pg_log_warning("unsupported pg_init_privs entry: %u %u %d", + classoid, objoid, objsubid); } - PQclear(res); + } + PQclear(res); destroyPQExpBuffer(query); } @@ -11128,8 +11127,8 @@ dumpRelationStats_dumper(Archive *fout, const void *userArg, const TocEntry *te) * The results must be in the order of the relations supplied in the * parameters to ensure we remain in sync as we walk through the TOC. * - * For versions before 19, the redundant filter clause on s.tablename = - * ANY(...) seems sufficient to convince the planner to use + * For versions before 19, the redundant filter clause on s.tablename + * = ANY(...) seems sufficient to convince the planner to use * pg_class_relname_nsp_index, which avoids a full scan of pg_stats. * In newer versions, pg_stats returns the table OIDs, eliminating the * need for that hack. @@ -13469,11 +13468,11 @@ dumpFunc(Archive *fout, const FuncInfo *finfo) "pg_catalog.pg_get_function_result(p.oid) AS funcresult,\n" "proleakproof,\n"); - appendPQExpBufferStr(query, - "array_to_string(protrftypes, ' ') AS protrftypes,\n"); + appendPQExpBufferStr(query, + "array_to_string(protrftypes, ' ') AS protrftypes,\n"); - appendPQExpBufferStr(query, - "proparallel,\n"); + appendPQExpBufferStr(query, + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -14963,9 +14962,9 @@ dumpCollation(Archive *fout, const CollInfo *collinfo) /* Get collation-specific details */ appendPQExpBufferStr(query, "SELECT "); - appendPQExpBufferStr(query, - "collprovider, " - "collversion, "); + appendPQExpBufferStr(query, + "collprovider, " + "collversion, "); if (fout->remoteVersion >= 120000) appendPQExpBufferStr(query, @@ -15372,23 +15371,23 @@ dumpAgg(Archive *fout, const AggInfo *agginfo) "pg_catalog.pg_get_function_arguments(p.oid) AS funcargs,\n" "pg_catalog.pg_get_function_identity_arguments(p.oid) AS funciargs,\n"); - appendPQExpBufferStr(query, - "aggkind,\n" - "aggmtransfn,\n" - "aggminvtransfn,\n" - "aggmfinalfn,\n" - "aggmtranstype::pg_catalog.regtype,\n" - "aggfinalextra,\n" - "aggmfinalextra,\n" - "aggtransspace,\n" - "aggmtransspace,\n" - "aggminitval,\n"); + appendPQExpBufferStr(query, + "aggkind,\n" + "aggmtransfn,\n" + "aggminvtransfn,\n" + "aggmfinalfn,\n" + "aggmtranstype::pg_catalog.regtype,\n" + "aggfinalextra,\n" + "aggmfinalextra,\n" + "aggtransspace,\n" + "aggmtransspace,\n" + "aggminitval,\n"); - appendPQExpBufferStr(query, - "aggcombinefn,\n" - "aggserialfn,\n" - "aggdeserialfn,\n" - "proparallel,\n"); + appendPQExpBufferStr(query, + "aggcombinefn,\n" + "aggserialfn,\n" + "aggdeserialfn,\n" + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -16848,30 +16847,30 @@ dumpTable(Archive *fout, const TableInfo *tbinfo) appendPQExpBufferStr(query, "PREPARE getColumnACLs(pg_catalog.oid) AS\n"); - /* - * In principle we should call acldefault('c', relowner) to - * get the default ACL for a column. However, we don't - * currently store the numeric OID of the relowner in - * TableInfo. We could convert the owner name using regrole, - * but that creates a risk of failure due to concurrent role - * renames. Given that the default ACL for columns is empty - * and is likely to stay that way, it's not worth extra cycles - * and risk to avoid hard-wiring that knowledge here. - */ - appendPQExpBufferStr(query, - "SELECT at.attname, " - "at.attacl, " - "'{}' AS acldefault, " - "pip.privtype, pip.initprivs " - "FROM pg_catalog.pg_attribute at " - "LEFT JOIN pg_catalog.pg_init_privs pip ON " - "(at.attrelid = pip.objoid " - "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " - "AND at.attnum = pip.objsubid) " - "WHERE at.attrelid = $1 AND " - "NOT at.attisdropped " - "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " - "ORDER BY at.attnum"); + /* + * In principle we should call acldefault('c', relowner) to get + * the default ACL for a column. However, we don't currently + * store the numeric OID of the relowner in TableInfo. We could + * convert the owner name using regrole, but that creates a risk + * of failure due to concurrent role renames. Given that the + * default ACL for columns is empty and is likely to stay that + * way, it's not worth extra cycles and risk to avoid hard-wiring + * that knowledge here. + */ + appendPQExpBufferStr(query, + "SELECT at.attname, " + "at.attacl, " + "'{}' AS acldefault, " + "pip.privtype, pip.initprivs " + "FROM pg_catalog.pg_attribute at " + "LEFT JOIN pg_catalog.pg_init_privs pip ON " + "(at.attrelid = pip.objoid " + "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " + "AND at.attnum = pip.objsubid) " + "WHERE at.attrelid = $1 AND " + "NOT at.attisdropped " + "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " + "ORDER BY at.attnum"); ExecuteSqlStatement(fout, query->data); @@ -19165,7 +19164,7 @@ collectSequences(Archive *fout) * pg_get_sequence_data(), but we only do so for non-schema-only dumps. */ if (fout->remoteVersion < 180000 || - (!fout->dopt->dumpData && !fout->dopt->sequence_data)) + (!fout->dopt->dumpData && !fout->dopt->sequence_data)) query = "SELECT seqrelid, format_type(seqtypid, NULL), " "seqstart, seqincrement, " "seqmax, seqmin, " @@ -19227,15 +19226,14 @@ dumpSequence(Archive *fout, const TableInfo *tbinfo) qseqname = pg_strdup(fmtId(tbinfo->dobj.name)); /* - * The sequence information is gathered in a sorted - * table before any calls to dumpSequence(). See collectSequences() for - * more information. + * The sequence information is gathered in a sorted table before any calls + * to dumpSequence(). See collectSequences() for more information. */ - Assert(sequences); + Assert(sequences); - key.oid = tbinfo->dobj.catId.oid; - seq = bsearch(&key, sequences, nsequences, - sizeof(SequenceItem), SequenceItemCmp); + key.oid = tbinfo->dobj.catId.oid; + seq = bsearch(&key, sequences, nsequences, + sizeof(SequenceItem), SequenceItemCmp); /* Calculate default limits for a sequence of this type */ is_ascending = (seq->incby >= 0); diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c index e68937c9934..afcd9a218d8 100644 --- a/src/bin/pg_dump/pg_dumpall.c +++ b/src/bin/pg_dump/pg_dumpall.c @@ -785,11 +785,11 @@ dropRoles(PGconn *conn) int i_rolname; int i; - printfPQExpBuffer(buf, - "SELECT rolname " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 1", role_catalog); + printfPQExpBuffer(buf, + "SELECT rolname " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 1", role_catalog); res = executeQuery(conn, buf->data); @@ -843,16 +843,16 @@ dumpRoles(PGconn *conn) * Notes: rolconfig is dumped later, and pg_authid must be used for * extracting rolcomment regardless of role_catalog. */ - printfPQExpBuffer(buf, - "SELECT oid, rolname, rolsuper, rolinherit, " - "rolcreaterole, rolcreatedb, " - "rolcanlogin, rolconnlimit, rolpassword, " - "rolvaliduntil, rolreplication, rolbypassrls, " - "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " - "rolname = current_user AS is_current_user " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 2", role_catalog); + printfPQExpBuffer(buf, + "SELECT oid, rolname, rolsuper, rolinherit, " + "rolcreaterole, rolcreatedb, " + "rolcanlogin, rolconnlimit, rolpassword, " + "rolvaliduntil, rolreplication, rolbypassrls, " + "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " + "rolname = current_user AS is_current_user " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 2", role_catalog); res = executeQuery(conn, buf->data); diff --git a/src/bin/pg_upgrade/check.c b/src/bin/pg_upgrade/check.c index 786c1474829..f725f5ee3e2 100644 --- a/src/bin/pg_upgrade/check.c +++ b/src/bin/pg_upgrade/check.c @@ -1475,15 +1475,15 @@ check_for_incompatible_polymorphics(ClusterInfo *cluster) ", 'array_cat(anyarray,anyarray)'" ", 'array_prepend(anyelement,anyarray)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_remove(anyarray,anyelement)'" - ", 'array_replace(anyarray,anyelement,anyelement)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_remove(anyarray,anyelement)'" + ", 'array_replace(anyarray,anyelement,anyelement)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_position(anyarray,anyelement)'" - ", 'array_position(anyarray,anyelement,integer)'" - ", 'array_positions(anyarray,anyelement)'" - ", 'width_bucket(anyelement,anyarray)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_position(anyarray,anyelement)'" + ", 'array_position(anyarray,anyelement,integer)'" + ", 'array_positions(anyarray,anyelement)'" + ", 'width_bucket(anyelement,anyarray)'"); /* * The query below hardcodes FirstNormalObjectId as 16384 rather than diff --git a/src/bin/pg_upgrade/controldata.c b/src/bin/pg_upgrade/controldata.c index 8f81c9e9582..02ea02df60f 100644 --- a/src/bin/pg_upgrade/controldata.c +++ b/src/bin/pg_upgrade/controldata.c @@ -228,7 +228,7 @@ get_control_data(ClusterInfo *cluster) p++; /* remove ':' char */ cluster->controldata.chkpnt_nxtepoch = str2uint(p); - p = strchr(p, ':'); + p = strchr(p, ':'); if (p == NULL || strlen(p) <= 1) pg_fatal("%d: controldata retrieval problem", __LINE__); diff --git a/src/bin/pg_upgrade/exec.c b/src/bin/pg_upgrade/exec.c index 44355feea30..a1bdbf373e3 100644 --- a/src/bin/pg_upgrade/exec.c +++ b/src/bin/pg_upgrade/exec.c @@ -55,7 +55,7 @@ get_bin_version(ClusterInfo *cluster) if (sscanf(cmd_output, "%*s %*s %d.%d", &v1, &v2) < 1) pg_fatal("could not get pg_ctl version output from %s", cmd); - cluster->bin_version = v1 * 10000; + cluster->bin_version = v1 * 10000; } @@ -344,8 +344,8 @@ check_data_dir(ClusterInfo *cluster) check_single_dir(pg_data, "pg_subtrans"); check_single_dir(pg_data, PG_TBLSPC_DIR); check_single_dir(pg_data, "pg_twophase"); - check_single_dir(pg_data, "pg_wal"); - check_single_dir(pg_data, "pg_xact"); + check_single_dir(pg_data, "pg_wal"); + check_single_dir(pg_data, "pg_xact"); } @@ -385,7 +385,7 @@ check_bin_dir(ClusterInfo *cluster, bool check_versions) */ get_bin_version(cluster); - check_exec(cluster->bindir, "pg_resetwal", check_versions); + check_exec(cluster->bindir, "pg_resetwal", check_versions); if (cluster == &new_cluster) { diff --git a/src/bin/pg_upgrade/multixact_rewrite.c b/src/bin/pg_upgrade/multixact_rewrite.c index c45b3183684..c7a1416494d 100644 --- a/src/bin/pg_upgrade/multixact_rewrite.c +++ b/src/bin/pg_upgrade/multixact_rewrite.c @@ -61,52 +61,52 @@ rewrite_multixacts(MultiXactId from_multi, MultiXactId to_multi) * Convert old multixids, if needed, by reading them one-by-one from the * old cluster. */ - old_reader = AllocOldMultiXactRead(old_cluster.pgdata, - old_cluster.controldata.chkpnt_nxtmulti, - old_cluster.controldata.chkpnt_nxtmxoff); + old_reader = AllocOldMultiXactRead(old_cluster.pgdata, + old_cluster.controldata.chkpnt_nxtmulti, + old_cluster.controldata.chkpnt_nxtmxoff); - for (MultiXactId multi = from_multi; multi != to_multi;) - { - MultiXactMember member; - bool multixid_valid; - - /* - * Read this multixid's members. - * - * Locking-only XIDs that may be part of multi-xids don't matter - * after upgrade, as there can be no transactions running across - * upgrade. So as a small optimization, we only read one member - * from each multixid: the one updating one, or if there was no - * update, arbitrarily the first locking xid. - */ - multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); + for (MultiXactId multi = from_multi; multi != to_multi;) + { + MultiXactMember member; + bool multixid_valid; - /* - * Write the new offset to pg_multixact/offsets. - * - * Even if this multixid is invalid, we still need to write its - * offset if the *previous* multixid was valid. That's because - * when reading a multixid, the number of members is calculated - * from the difference between the two offsets. - */ - RecordMultiXactOffset(offsets_writer, multi, - (multixid_valid || prev_multixid_valid) ? next_offset : 0); + /* + * Read this multixid's members. + * + * Locking-only XIDs that may be part of multi-xids don't matter after + * upgrade, as there can be no transactions running across upgrade. So + * as a small optimization, we only read one member from each + * multixid: the one updating one, or if there was no update, + * arbitrarily the first locking xid. + */ + multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); - /* Write the members */ - if (multixid_valid) - { - RecordMultiXactMembers(members_writer, next_offset, 1, &member); - next_offset += 1; - } + /* + * Write the new offset to pg_multixact/offsets. + * + * Even if this multixid is invalid, we still need to write its offset + * if the *previous* multixid was valid. That's because when reading + * a multixid, the number of members is calculated from the difference + * between the two offsets. + */ + RecordMultiXactOffset(offsets_writer, multi, + (multixid_valid || prev_multixid_valid) ? next_offset : 0); - /* Advance to next multixid, handling wraparound */ - multi++; - if (multi < FirstMultiXactId) - multi = FirstMultiXactId; - prev_multixid_valid = multixid_valid; + /* Write the members */ + if (multixid_valid) + { + RecordMultiXactMembers(members_writer, next_offset, 1, &member); + next_offset += 1; } - FreeOldMultiXactReader(old_reader); + /* Advance to next multixid, handling wraparound */ + multi++; + if (multi < FirstMultiXactId) + multi = FirstMultiXactId; + prev_multixid_valid = multixid_valid; + } + + FreeOldMultiXactReader(old_reader); /* Write the final 'next' offset to the last SLRU page */ RecordMultiXactOffset(offsets_writer, to_multi, diff --git a/src/bin/pg_upgrade/pg_upgrade.c b/src/bin/pg_upgrade/pg_upgrade.c index c6af9035665..7366fd4627c 100644 --- a/src/bin/pg_upgrade/pg_upgrade.c +++ b/src/bin/pg_upgrade/pg_upgrade.c @@ -833,7 +833,7 @@ copy_xact_xlog_xid(void) * Determine the range of multixacts to convert. */ nxtmulti = old_cluster.controldata.chkpnt_nxtmulti; - oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; + oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; /* handle wraparound */ if (nxtmulti < FirstMultiXactId) nxtmulti = FirstMultiXactId; @@ -898,15 +898,15 @@ set_frozenxids(void) int i_datname; int i_datallowconn; - prep_status("Setting frozenxid and minmxid counters in new cluster"); + prep_status("Setting frozenxid and minmxid counters in new cluster"); conn_template1 = connectToServer(&new_cluster, "template1"); - /* set pg_database.datfrozenxid */ - PQclear(executeQueryOrDie(conn_template1, - "UPDATE pg_catalog.pg_database " - "SET datfrozenxid = '%u'", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_database.datfrozenxid */ + PQclear(executeQueryOrDie(conn_template1, + "UPDATE pg_catalog.pg_database " + "SET datfrozenxid = '%u'", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_database.datminmxid */ PQclear(executeQueryOrDie(conn_template1, @@ -942,16 +942,16 @@ set_frozenxids(void) conn = connectToServer(&new_cluster, datname); - /* set pg_class.relfrozenxid */ - PQclear(executeQueryOrDie(conn, - "UPDATE pg_catalog.pg_class " - "SET relfrozenxid = '%u' " - /* only heap, materialized view, and TOAST are vacuumed */ - "WHERE relkind IN (" - CppAsString2(RELKIND_RELATION) ", " - CppAsString2(RELKIND_MATVIEW) ", " - CppAsString2(RELKIND_TOASTVALUE) ")", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_class.relfrozenxid */ + PQclear(executeQueryOrDie(conn, + "UPDATE pg_catalog.pg_class " + "SET relfrozenxid = '%u' " + /* only heap, materialized view, and TOAST are vacuumed */ + "WHERE relkind IN (" + CppAsString2(RELKIND_RELATION) ", " + CppAsString2(RELKIND_MATVIEW) ", " + CppAsString2(RELKIND_TOASTVALUE) ")", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_class.relminmxid */ PQclear(executeQueryOrDie(conn, diff --git a/src/bin/pg_upgrade/relfilenumber.c b/src/bin/pg_upgrade/relfilenumber.c index ec2ff7acb21..6c467bdc8a5 100644 --- a/src/bin/pg_upgrade/relfilenumber.c +++ b/src/bin/pg_upgrade/relfilenumber.c @@ -587,32 +587,32 @@ transfer_relfile(FileNameMap *map, const char *type_suffix) /* Copying files might take some time, so give feedback. */ pg_log(PG_STATUS, "%s", old_file); - switch (user_opts.transfer_mode) - { - case TRANSFER_MODE_CLONE: - pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", - old_file, new_file); - cloneFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", - old_file, new_file); - copyFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY_FILE_RANGE: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", - old_file, new_file); - copyFileByRange(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_LINK: - pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", - old_file, new_file); - linkFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_SWAP: - /* swap mode is handled in its own code path */ - pg_fatal("should never happen"); - break; - } + switch (user_opts.transfer_mode) + { + case TRANSFER_MODE_CLONE: + pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", + old_file, new_file); + cloneFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", + old_file, new_file); + copyFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY_FILE_RANGE: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", + old_file, new_file); + copyFileByRange(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_LINK: + pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", + old_file, new_file); + linkFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_SWAP: + /* swap mode is handled in its own code path */ + pg_fatal("should never happen"); + break; + } } } diff --git a/src/bin/pg_upgrade/t/006_transfer_modes.pl b/src/bin/pg_upgrade/t/006_transfer_modes.pl index 9efa5dc863c..360d05c4b68 100644 --- a/src/bin/pg_upgrade/t/006_transfer_modes.pl +++ b/src/bin/pg_upgrade/t/006_transfer_modes.pl @@ -29,10 +29,8 @@ sub test_mode } $new->init(); - $new->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); - $old->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); + $new->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); + $old->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); # We can only test security labels if both the old and new installations # have dummy_seclabel. @@ -76,15 +74,14 @@ sub test_mode "CREATE TABLE test4 AS SELECT generate_series(400, 502)"); } - $old->safe_psql('postgres', - "CREATE TABLESPACE inplc_tblspc LOCATION ''"); - $old->safe_psql('postgres', - "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); - $old->safe_psql('postgres', - "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" - ); - $old->safe_psql('testdb3', - "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); + $old->safe_psql('postgres', "CREATE TABLESPACE inplc_tblspc LOCATION ''"); + $old->safe_psql('postgres', + "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); + $old->safe_psql('postgres', + "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" + ); + $old->safe_psql('testdb3', + "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); # While we are here, test handling of large objects. $old->safe_psql( @@ -152,12 +149,10 @@ sub test_mode } # Tests for in-place tablespaces. - $result = - $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); - is($result, '104', "test5 data after pg_upgrade $mode"); - $result = - $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); - is($result, '105', "test6 data after pg_upgrade $mode"); + $result = $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); + is($result, '104', "test5 data after pg_upgrade $mode"); + $result = $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); + is($result, '105', "test6 data after pg_upgrade $mode"); # Tests for large objects $result = $new->safe_psql('postgres', "SELECT lo_get(4532)"); diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index 44ef11d980e..c90bf8bbde2 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -6278,23 +6278,22 @@ get_create_object_cmd(EditableObjectType obj_type, Oid oid, * ensure the right view gets replaced. Also, check relation kind * to be sure it's a view. * - * Views may have WITH [LOCAL|CASCADED] - * CHECK OPTION. These are not part of the view definition - * returned by pg_get_viewdef() and so need to be retrieved - * separately. Materialized views may have - * arbitrary storage parameter reloptions. + * Views may have WITH [LOCAL|CASCADED] CHECK OPTION. These are + * not part of the view definition returned by pg_get_viewdef() + * and so need to be retrieved separately. Materialized views may + * have arbitrary storage parameter reloptions. */ printfPQExpBuffer(query, "/* %s */\n", _("Get view's definition and details")); - appendPQExpBuffer(query, - "SELECT nspname, relname, relkind, " - "pg_catalog.pg_get_viewdef(c.oid, true), " - "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " - "FROM pg_catalog.pg_class c " - "LEFT JOIN pg_catalog.pg_namespace n " - "ON c.relnamespace = n.oid WHERE c.oid = %u", - oid); + appendPQExpBuffer(query, + "SELECT nspname, relname, relkind, " + "pg_catalog.pg_get_viewdef(c.oid, true), " + "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " + "FROM pg_catalog.pg_class c " + "LEFT JOIN pg_catalog.pg_namespace n " + "ON c.relnamespace = n.oid WHERE c.oid = %u", + oid); break; } diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index ce99137c613..ac0c55e7aa5 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -387,19 +387,19 @@ describeFunctions(const char *functypes, const char *func_pattern, gettext_noop("stable"), gettext_noop("volatile"), gettext_noop("Volatility")); - appendPQExpBuffer(&buf, - ",\n CASE\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" - " END as \"%s\"", - gettext_noop("restricted"), - gettext_noop("safe"), - gettext_noop("unsafe"), - gettext_noop("Parallel")); + appendPQExpBuffer(&buf, + ",\n CASE\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" + " END as \"%s\"", + gettext_noop("restricted"), + gettext_noop("safe"), + gettext_noop("unsafe"), + gettext_noop("Parallel")); appendPQExpBuffer(&buf, ",\n pg_catalog.pg_get_userbyid(p.proowner) as \"%s\"" ",\n CASE WHEN prosecdef THEN '%s' ELSE '%s' END AS \"%s\"" @@ -599,8 +599,8 @@ describeFunctions(const char *functypes, const char *func_pattern, myopt.title = _("List of functions"); myopt.translate_header = true; - myopt.translate_columns = translate_columns; - myopt.n_translate_columns = lengthof(translate_columns); + myopt.translate_columns = translate_columns; + myopt.n_translate_columns = lengthof(translate_columns); printQuery(res, &myopt, pset.queryFout, false, pset.logfile); @@ -1086,38 +1086,38 @@ permissionsList(const char *pattern, bool showSystem) " ), E'\\n') AS \"%s\"", gettext_noop("Column privileges")); - appendPQExpBuffer(&buf, - ",\n pg_catalog.array_to_string(ARRAY(\n" - " SELECT polname\n" - " || CASE WHEN NOT polpermissive THEN\n" - " E' (RESTRICTIVE)'\n" - " ELSE '' END\n" - " || CASE WHEN polcmd != '*' THEN\n" - " E' (' || polcmd::pg_catalog.text || E'):'\n" - " ELSE E':'\n" - " END\n" - " || CASE WHEN polqual IS NOT NULL THEN\n" - " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" - " ELSE E''\n" - " END\n" - " || CASE WHEN polwithcheck IS NOT NULL THEN\n" - " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" - " ELSE E''\n" - " END" - " || CASE WHEN polroles <> '{0}' THEN\n" - " E'\\n to: ' || pg_catalog.array_to_string(\n" - " ARRAY(\n" - " SELECT rolname\n" - " FROM pg_catalog.pg_roles\n" - " WHERE oid = ANY (polroles)\n" - " ORDER BY 1\n" - " ), E', ')\n" - " ELSE E''\n" - " END\n" - " FROM pg_catalog.pg_policy pol\n" - " WHERE polrelid = c.oid), E'\\n')\n" - " AS \"%s\"", - gettext_noop("Policies")); + appendPQExpBuffer(&buf, + ",\n pg_catalog.array_to_string(ARRAY(\n" + " SELECT polname\n" + " || CASE WHEN NOT polpermissive THEN\n" + " E' (RESTRICTIVE)'\n" + " ELSE '' END\n" + " || CASE WHEN polcmd != '*' THEN\n" + " E' (' || polcmd::pg_catalog.text || E'):'\n" + " ELSE E':'\n" + " END\n" + " || CASE WHEN polqual IS NOT NULL THEN\n" + " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" + " ELSE E''\n" + " END\n" + " || CASE WHEN polwithcheck IS NOT NULL THEN\n" + " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" + " ELSE E''\n" + " END" + " || CASE WHEN polroles <> '{0}' THEN\n" + " E'\\n to: ' || pg_catalog.array_to_string(\n" + " ARRAY(\n" + " SELECT rolname\n" + " FROM pg_catalog.pg_roles\n" + " WHERE oid = ANY (polroles)\n" + " ORDER BY 1\n" + " ), E', ')\n" + " ELSE E''\n" + " END\n" + " FROM pg_catalog.pg_policy pol\n" + " WHERE polrelid = c.oid), E'\\n')\n" + " AS \"%s\"", + gettext_noop("Policies")); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_class c\n" " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n" @@ -1675,27 +1675,27 @@ describeOneTableDetails(const char *schemaname, char *footers[3] = {NULL, NULL, NULL}; printfPQExpBuffer(&buf, "/* %s */\n", _("Get sequence information")); - appendPQExpBuffer(&buf, - "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" - " seqstart AS \"%s\",\n" - " seqmin AS \"%s\",\n" - " seqmax AS \"%s\",\n" - " seqincrement AS \"%s\",\n" - " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" - " seqcache AS \"%s\"\n", - gettext_noop("Type"), - gettext_noop("Start"), - gettext_noop("Minimum"), - gettext_noop("Maximum"), - gettext_noop("Increment"), - gettext_noop("yes"), - gettext_noop("no"), - gettext_noop("Cycles?"), - gettext_noop("Cache")); - appendPQExpBuffer(&buf, - "FROM pg_catalog.pg_sequence\n" - "WHERE seqrelid = '%s';", - oid); + appendPQExpBuffer(&buf, + "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" + " seqstart AS \"%s\",\n" + " seqmin AS \"%s\",\n" + " seqmax AS \"%s\",\n" + " seqincrement AS \"%s\",\n" + " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" + " seqcache AS \"%s\"\n", + gettext_noop("Type"), + gettext_noop("Start"), + gettext_noop("Minimum"), + gettext_noop("Maximum"), + gettext_noop("Increment"), + gettext_noop("yes"), + gettext_noop("no"), + gettext_noop("Cycles?"), + gettext_noop("Cache")); + appendPQExpBuffer(&buf, + "FROM pg_catalog.pg_sequence\n" + "WHERE seqrelid = '%s';", + oid); res = PSQLexec(buf.data); if (!res) @@ -1913,7 +1913,7 @@ describeOneTableDetails(const char *schemaname, appendPQExpBufferStr(&buf, ",\n (SELECT c.collname FROM pg_catalog.pg_collation c, pg_catalog.pg_type t\n" " WHERE c.oid = a.attcollation AND t.oid = a.atttypid AND a.attcollation <> t.typcollation) AS attcollation"); attcoll_col = cols++; - appendPQExpBufferStr(&buf, ",\n a.attidentity"); + appendPQExpBufferStr(&buf, ",\n a.attidentity"); attidentity_col = cols++; if (pset.sversion >= 120000) appendPQExpBufferStr(&buf, ",\n a.attgenerated"); @@ -2326,7 +2326,7 @@ describeOneTableDetails(const char *schemaname, CppAsString2(CONSTRAINT_EXCLUSION) ") AND " "condeferred) AS condeferred,\n"); - appendPQExpBufferStr(&buf, "i.indisreplident,\n"); + appendPQExpBufferStr(&buf, "i.indisreplident,\n"); if (pset.sversion >= 150000) appendPQExpBufferStr(&buf, "i.indnullsnotdistinct,\n"); @@ -2431,7 +2431,7 @@ describeOneTableDetails(const char *schemaname, "pg_catalog.pg_get_indexdef(i.indexrelid, 0, true),\n " "pg_catalog.pg_get_constraintdef(con.oid, true), " "contype, condeferrable, condeferred"); - appendPQExpBufferStr(&buf, ", i.indisreplident"); + appendPQExpBufferStr(&buf, ", i.indisreplident"); appendPQExpBufferStr(&buf, ", c2.reltablespace"); if (pset.sversion >= 180000) appendPQExpBufferStr(&buf, ", con.conperiod"); @@ -2682,81 +2682,80 @@ describeOneTableDetails(const char *schemaname, PQclear(result); /* print any row-level policies */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get row-level policies for this table")); - appendPQExpBufferStr(&buf, "SELECT pol.polname,"); - appendPQExpBufferStr(&buf, - " pol.polpermissive,\n"); - appendPQExpBuffer(&buf, - " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" - " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" - " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" - " CASE pol.polcmd\n" - " WHEN 'r' THEN 'SELECT'\n" - " WHEN 'a' THEN 'INSERT'\n" - " WHEN 'w' THEN 'UPDATE'\n" - " WHEN 'd' THEN 'DELETE'\n" - " END AS cmd\n" - "FROM pg_catalog.pg_policy pol\n" - "WHERE pol.polrelid = '%s' ORDER BY 1;", - oid); + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get row-level policies for this table")); + appendPQExpBufferStr(&buf, "SELECT pol.polname,"); + appendPQExpBufferStr(&buf, + " pol.polpermissive,\n"); + appendPQExpBuffer(&buf, + " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" + " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" + " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" + " CASE pol.polcmd\n" + " WHEN 'r' THEN 'SELECT'\n" + " WHEN 'a' THEN 'INSERT'\n" + " WHEN 'w' THEN 'UPDATE'\n" + " WHEN 'd' THEN 'DELETE'\n" + " END AS cmd\n" + "FROM pg_catalog.pg_policy pol\n" + "WHERE pol.polrelid = '%s' ORDER BY 1;", + oid); - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - /* - * Handle cases where RLS is enabled and there are policies, or - * there aren't policies, or RLS isn't enabled but there are - * policies - */ - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies:")); + /* + * Handle cases where RLS is enabled and there are policies, or there + * aren't policies, or RLS isn't enabled but there are policies + */ + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies:")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled):")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled):")); - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); - if (!tableinfo.rowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (row security disabled):")); + if (!tableinfo.rowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (row security disabled):")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " POLICY \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " POLICY \"%s\"", + PQgetvalue(result, i, 0)); - if (*(PQgetvalue(result, i, 1)) == 'f') - appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); + if (*(PQgetvalue(result, i, 1)) == 'f') + appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); - if (!PQgetisnull(result, i, 5)) - appendPQExpBuffer(&buf, " FOR %s", - PQgetvalue(result, i, 5)); + if (!PQgetisnull(result, i, 5)) + appendPQExpBuffer(&buf, " FOR %s", + PQgetvalue(result, i, 5)); - if (!PQgetisnull(result, i, 2)) - { - appendPQExpBuffer(&buf, "\n TO %s", - PQgetvalue(result, i, 2)); - } + if (!PQgetisnull(result, i, 2)) + { + appendPQExpBuffer(&buf, "\n TO %s", + PQgetvalue(result, i, 2)); + } - if (!PQgetisnull(result, i, 3)) - appendPQExpBuffer(&buf, "\n USING (%s)", - PQgetvalue(result, i, 3)); + if (!PQgetisnull(result, i, 3)) + appendPQExpBuffer(&buf, "\n USING (%s)", + PQgetvalue(result, i, 3)); - if (!PQgetisnull(result, i, 4)) - appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", - PQgetvalue(result, i, 4)); + if (!PQgetisnull(result, i, 4)) + appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", + PQgetvalue(result, i, 4)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* print any extended statistics */ if (pset.sversion >= 140000) @@ -3025,115 +3024,115 @@ describeOneTableDetails(const char *schemaname, } /* print any publications */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get publications that publish this table")); - if (pset.sversion >= 150000) + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get publications that publish this table")); + if (pset.sversion >= 150000) + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" + " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" + "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" + "UNION\n" + "SELECT pubname\n" + " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" + " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" + " (SELECT pg_catalog.string_agg(attname, ', ')\n" + " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" + " pg_catalog.pg_attribute\n" + " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" + " ELSE NULL END) " + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" + "WHERE pr.prrelid = '%s'\n", + oid, oid, oid); + + if (pset.sversion >= 190000) { + /* + * Skip entries where this relation appears in the + * publication's EXCEPT list. + */ appendPQExpBuffer(&buf, + " AND NOT pr.prexcept\n" + "UNION\n" "SELECT pubname\n" " , NULL\n" " , NULL\n" "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" - " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" - "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" - "UNION\n" - "SELECT pubname\n" - " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" - " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" - " (SELECT pg_catalog.string_agg(attname, ', ')\n" - " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" - " pg_catalog.pg_attribute\n" - " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" - " ELSE NULL END) " - "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" - "WHERE pr.prrelid = '%s'\n", + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + " AND NOT EXISTS (\n" + " SELECT 1\n" + " FROM pg_catalog.pg_publication_rel pr\n" + " WHERE pr.prpubid = p.oid AND\n" + " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" + "ORDER BY 1;", oid, oid, oid); - - if (pset.sversion >= 190000) - { - /* - * Skip entries where this relation appears in the - * publication's EXCEPT list. - */ - appendPQExpBuffer(&buf, - " AND NOT pr.prexcept\n" - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - " AND NOT EXISTS (\n" - " SELECT 1\n" - " FROM pg_catalog.pg_publication_rel pr\n" - " WHERE pr.prpubid = p.oid AND\n" - " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" - "ORDER BY 1;", - oid, oid, oid); - } - else - { - appendPQExpBuffer(&buf, - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - "ORDER BY 1;", - oid); - } } else { appendPQExpBuffer(&buf, + "UNION\n" "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - "WHERE pr.prrelid = '%s'\n" - "UNION ALL\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" + " , NULL\n" + " , NULL\n" "FROM pg_catalog.pg_publication p\n" "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" "ORDER BY 1;", - oid, oid); + oid); } + } + else + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + "WHERE pr.prrelid = '%s'\n" + "UNION ALL\n" + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + "ORDER BY 1;", + oid, oid); + } - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - if (tuples > 0) - printTableAddFooter(&cont, _("Included in publications:")); + if (tuples > 0) + printTableAddFooter(&cont, _("Included in publications:")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " \"%s\"", + PQgetvalue(result, i, 0)); - /* column list (if any) */ - if (!PQgetisnull(result, i, 2)) - appendPQExpBuffer(&buf, " (%s)", - PQgetvalue(result, i, 2)); + /* column list (if any) */ + if (!PQgetisnull(result, i, 2)) + appendPQExpBuffer(&buf, " (%s)", + PQgetvalue(result, i, 2)); - /* row filter (if any) */ - if (!PQgetisnull(result, i, 1)) - appendPQExpBuffer(&buf, " WHERE %s", - PQgetvalue(result, i, 1)); + /* row filter (if any) */ + if (!PQgetisnull(result, i, 1)) + appendPQExpBuffer(&buf, " WHERE %s", + PQgetvalue(result, i, 1)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* Print publications where the table is in the EXCEPT clause */ if (pset.sversion >= 190000) @@ -3805,7 +3804,7 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) ncols++; } appendPQExpBufferStr(&buf, "\n, r.rolreplication"); - appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); + appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_roles r\n"); @@ -3860,8 +3859,8 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) if (strcmp(PQgetvalue(res, i, (verbose ? 9 : 8)), "t") == 0) add_role_attribute(&buf, _("Replication")); - if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) - add_role_attribute(&buf, _("Bypass RLS")); + if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) + add_role_attribute(&buf, _("Bypass RLS")); conns = atoi(PQgetvalue(res, i, 6)); if (conns >= 0) @@ -5155,14 +5154,14 @@ listCollations(const char *pattern, bool verbose, bool showSystem) gettext_noop("Schema"), gettext_noop("Name")); - appendPQExpBuffer(&buf, - " CASE c.collprovider " - "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " - "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " - "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " - "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " - "END AS \"%s\",\n", - gettext_noop("Provider")); + appendPQExpBuffer(&buf, + " CASE c.collprovider " + "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " + "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " + "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " + "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " + "END AS \"%s\",\n", + gettext_noop("Provider")); appendPQExpBuffer(&buf, " c.collcollate AS \"%s\",\n" -- 2.50.1 (Apple Git-155) --aHl3HfeiUuO3zeNC-- ^ permalink raw reply [nested|flat] 59+ messages in thread
* [PATCH v6 4/4] run pgindent and pgperltidy @ 2026-06-30 18:24 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 59+ messages in thread From: Nathan Bossart @ 2026-06-30 18:24 UTC (permalink / raw) --- src/bin/pg_dump/pg_dump.c | 464 ++++++++++----------- src/bin/pg_dump/pg_dumpall.c | 30 +- src/bin/pg_upgrade/check.c | 16 +- src/bin/pg_upgrade/controldata.c | 2 +- src/bin/pg_upgrade/exec.c | 8 +- src/bin/pg_upgrade/multixact_rewrite.c | 80 ++-- src/bin/pg_upgrade/pg_upgrade.c | 34 +- src/bin/pg_upgrade/relfilenumber.c | 54 +-- src/bin/pg_upgrade/t/006_transfer_modes.pl | 33 +- src/bin/psql/command.c | 29 +- src/bin/psql/describe.c | 461 ++++++++++---------- 11 files changed, 601 insertions(+), 610 deletions(-) diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 65bd15ebfd2..5673268b467 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -1491,8 +1491,8 @@ setup_connection(Archive *AH, const char *dumpencoding, * Disable timeouts if supported. */ ExecuteSqlStatement(AH, "SET statement_timeout = 0"); - ExecuteSqlStatement(AH, "SET lock_timeout = 0"); - ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); + ExecuteSqlStatement(AH, "SET lock_timeout = 0"); + ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); if (AH->remoteVersion >= 170000) ExecuteSqlStatement(AH, "SET transaction_timeout = 0"); @@ -1505,10 +1505,10 @@ setup_connection(Archive *AH, const char *dumpencoding, /* * Adjust row-security mode, if supported. */ - if (dopt->enable_row_security) - ExecuteSqlStatement(AH, "SET row_security = on"); - else - ExecuteSqlStatement(AH, "SET row_security = off"); + if (dopt->enable_row_security) + ExecuteSqlStatement(AH, "SET row_security = on"); + else + ExecuteSqlStatement(AH, "SET row_security = off"); /* * For security reasons, we restrict the expansion of non-system views and @@ -1933,10 +1933,9 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) addObjectDependency(dobj, ext->dobj.dumpId); /* - * Mark the member object to have any non-initial ACLs - * dumped. (Any initial ACLs will be removed later, using data from - * pg_init_privs, so that we'll dump only the delta from the extension's - * initial setup.) + * Mark the member object to have any non-initial ACLs dumped. (Any + * initial ACLs will be removed later, using data from pg_init_privs, so + * that we'll dump only the delta from the extension's initial setup.) * * In binary upgrades, we still dump all components of the members * individually, since the idea is to exactly reproduce the database @@ -1953,7 +1952,7 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) if (fout->dopt->binary_upgrade) dobj->dump = ext->dobj.dump; else - dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); + dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); return true; } @@ -1987,9 +1986,9 @@ selectDumpableNamespace(NamespaceInfo *nsinfo, Archive *fout) else if (strcmp(nsinfo->dobj.name, "pg_catalog") == 0) { /* - * We dump out any ACLs defined in pg_catalog, if - * they are interesting (and not the original ACLs which were set at - * initdb time, see pg_init_privs). + * We dump out any ACLs defined in pg_catalog, if they are interesting + * (and not the original ACLs which were set at initdb time, see + * pg_init_privs). */ nsinfo->dobj.dump_contains = nsinfo->dobj.dump = DUMP_COMPONENT_ACL; } @@ -3296,7 +3295,7 @@ dumpDatabase(Archive *fout) "datcollate, datctype, datfrozenxid, " "datacl, acldefault('d', datdba) AS acldefault, " "datistemplate, datconnlimit, "); - appendPQExpBufferStr(dbQry, "datminmxid, "); + appendPQExpBufferStr(dbQry, "datminmxid, "); if (fout->remoteVersion >= 170000) appendPQExpBufferStr(dbQry, "datlocprovider, datlocale, datcollversion, "); else if (fout->remoteVersion >= 150000) @@ -3638,11 +3637,11 @@ dumpDatabase(Archive *fout) ii_oid, ii_relminmxid; - appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" - "FROM pg_catalog.pg_class\n" - "WHERE oid IN (%u, %u, %u, %u);\n", - LargeObjectRelationId, LargeObjectLOidPNIndexId, - LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); + appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" + "FROM pg_catalog.pg_class\n" + "WHERE oid IN (%u, %u, %u, %u);\n", + LargeObjectRelationId, LargeObjectLOidPNIndexId, + LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); lo_res = ExecuteSqlQuery(fout, loFrozenQry->data, PGRES_TUPLES_OK); @@ -4274,7 +4273,7 @@ getPolicies(Archive *fout, TableInfo tblinfo[], int numTables) printfPQExpBuffer(query, "SELECT pol.oid, pol.tableoid, pol.polrelid, pol.polname, pol.polcmd, "); - appendPQExpBufferStr(query, "pol.polpermissive, "); + appendPQExpBufferStr(query, "pol.polpermissive, "); appendPQExpBuffer(query, "CASE WHEN pol.polroles = '{0}' THEN NULL ELSE " " pg_catalog.array_to_string(ARRAY(SELECT pg_catalog.quote_ident(rolname) from pg_catalog.pg_roles WHERE oid = ANY(pol.polroles)), ', ') END AS polroles, " @@ -6633,9 +6632,9 @@ getAccessMethods(Archive *fout) * Select all access methods from pg_am table. */ appendPQExpBufferStr(query, "SELECT tableoid, oid, amname, "); - appendPQExpBufferStr(query, - "amtype, " - "amhandler::pg_catalog.regproc AS amhandler "); + appendPQExpBufferStr(query, + "amtype, " + "amhandler::pg_catalog.regproc AS amhandler "); appendPQExpBufferStr(query, "FROM pg_am"); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6827,35 +6826,35 @@ getAggregates(Archive *fout) * Find all interesting aggregates. See comment in getFuncs() for the * rationale behind the filtering logic. */ - agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" - : "p.proisagg"); + agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" + : "p.proisagg"); - appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " - "p.proname AS aggname, " - "p.pronamespace AS aggnamespace, " - "p.pronargs, p.proargtypes, " - "p.proowner, " - "p.proacl AS aggacl, " - "acldefault('f', p.proowner) AS acldefault " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s AND (" - "p.pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog') OR " - "p.proacl IS DISTINCT FROM pip.initprivs", - agg_check); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - " OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); - appendPQExpBufferChar(query, ')'); + appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " + "p.proname AS aggname, " + "p.pronamespace AS aggnamespace, " + "p.pronargs, p.proargtypes, " + "p.proowner, " + "p.proacl AS aggacl, " + "acldefault('f', p.proowner) AS acldefault " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s AND (" + "p.pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog') OR " + "p.proacl IS DISTINCT FROM pip.initprivs", + agg_check); + if (dopt->binary_upgrade) + appendPQExpBufferStr(query, + " OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6957,53 +6956,53 @@ getFuncs(Archive *fout) * include them, since we want to dump extension members individually in * that mode. Also, if they are used by casts or transforms then we need * to gather the information about them, though they won't be dumped if - * they are built-in. Also, include functions in - * pg_catalog if they have an ACL different from what's shown in - * pg_init_privs (so we have to join to pg_init_privs; annoying). + * they are built-in. Also, include functions in pg_catalog if they have + * an ACL different from what's shown in pg_init_privs (so we have to join + * to pg_init_privs; annoying). */ - not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" - : "NOT p.proisagg"); + not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" + : "NOT p.proisagg"); - appendPQExpBuffer(query, - "SELECT p.tableoid, p.oid, p.proname, p.prolang, " - "p.pronargs, p.proargtypes, p.prorettype, " - "p.proacl, " - "acldefault('f', p.proowner) AS acldefault, " - "p.pronamespace, " - "p.proowner " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s" - "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " - "WHERE classid = 'pg_proc'::regclass AND " - "objid = p.oid AND deptype = 'i')" - "\n AND (" - "\n pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog')" - "\n OR EXISTS (SELECT 1 FROM pg_cast" - "\n WHERE pg_cast.oid > %u " - "\n AND p.oid = pg_cast.castfunc)" - "\n OR EXISTS (SELECT 1 FROM pg_transform" - "\n WHERE pg_transform.oid > %u AND " - "\n (p.oid = pg_transform.trffromsql" - "\n OR p.oid = pg_transform.trftosql))", - not_agg_check, - g_last_builtin_oid, - g_last_builtin_oid); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); + appendPQExpBuffer(query, + "SELECT p.tableoid, p.oid, p.proname, p.prolang, " + "p.pronargs, p.proargtypes, p.prorettype, " + "p.proacl, " + "acldefault('f', p.proowner) AS acldefault, " + "p.pronamespace, " + "p.proowner " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s" + "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " + "WHERE classid = 'pg_proc'::regclass AND " + "objid = p.oid AND deptype = 'i')" + "\n AND (" + "\n pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog')" + "\n OR EXISTS (SELECT 1 FROM pg_cast" + "\n WHERE pg_cast.oid > %u " + "\n AND p.oid = pg_cast.castfunc)" + "\n OR EXISTS (SELECT 1 FROM pg_transform" + "\n WHERE pg_transform.oid > %u AND " + "\n (p.oid = pg_transform.trffromsql" + "\n OR p.oid = pg_transform.trftosql))", + not_agg_check, + g_last_builtin_oid, + g_last_builtin_oid); + if (dopt->binary_upgrade) appendPQExpBufferStr(query, - "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); - appendPQExpBufferChar(query, ')'); + "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferStr(query, + "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -7252,31 +7251,31 @@ getTables(Archive *fout, int *numTables) appendPQExpBufferStr(query, "c.relhasoids, "); - appendPQExpBufferStr(query, - "c.relispopulated, "); + appendPQExpBufferStr(query, + "c.relispopulated, "); - appendPQExpBufferStr(query, - "c.relreplident, "); + appendPQExpBufferStr(query, + "c.relreplident, "); - appendPQExpBufferStr(query, - "c.relrowsecurity, c.relforcerowsecurity, "); + appendPQExpBufferStr(query, + "c.relrowsecurity, c.relforcerowsecurity, "); - appendPQExpBufferStr(query, - "c.relminmxid, tc.relminmxid AS tminmxid, "); + appendPQExpBufferStr(query, + "c.relminmxid, tc.relminmxid AS tminmxid, "); - appendPQExpBufferStr(query, - "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); + appendPQExpBufferStr(query, + "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); - appendPQExpBufferStr(query, - "am.amname, "); + appendPQExpBufferStr(query, + "am.amname, "); - appendPQExpBufferStr(query, - "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); + appendPQExpBufferStr(query, + "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); - appendPQExpBufferStr(query, - "c.relispartition AS ispartition "); + appendPQExpBufferStr(query, + "c.relispartition AS ispartition "); /* * Left join to pg_depend to pick up dependency info linking sequences to @@ -7296,8 +7295,8 @@ getTables(Archive *fout, int *numTables) /* * Left join to pg_am to pick up the amname. */ - appendPQExpBufferStr(query, - "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); + appendPQExpBufferStr(query, + "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); /* * We purposefully ignore toast OIDs for partitioned tables; the reason is @@ -7868,8 +7867,8 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables) "t.reloptions AS indreloptions, "); - appendPQExpBufferStr(query, - "i.indisreplident, "); + appendPQExpBufferStr(query, + "i.indisreplident, "); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -9313,8 +9312,8 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables) appendPQExpBufferStr(q, "'' AS attcompression,\n"); - appendPQExpBufferStr(q, - "a.attidentity,\n"); + appendPQExpBufferStr(q, + "a.attidentity,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(q, @@ -10717,73 +10716,73 @@ getAdditionalACLs(Archive *fout) PQclear(res); /* Fetch initial-privileges data */ - printfPQExpBuffer(query, - "SELECT objoid, classoid, objsubid, privtype, initprivs " - "FROM pg_init_privs"); + printfPQExpBuffer(query, + "SELECT objoid, classoid, objsubid, privtype, initprivs " + "FROM pg_init_privs"); - res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); + res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); - ntups = PQntuples(res); - for (i = 0; i < ntups; i++) - { - Oid objoid = atooid(PQgetvalue(res, i, 0)); - Oid classoid = atooid(PQgetvalue(res, i, 1)); - int objsubid = atoi(PQgetvalue(res, i, 2)); - char privtype = *(PQgetvalue(res, i, 3)); - char *initprivs = PQgetvalue(res, i, 4); - CatalogId objId; - DumpableObject *dobj; + ntups = PQntuples(res); + for (i = 0; i < ntups; i++) + { + Oid objoid = atooid(PQgetvalue(res, i, 0)); + Oid classoid = atooid(PQgetvalue(res, i, 1)); + int objsubid = atoi(PQgetvalue(res, i, 2)); + char privtype = *(PQgetvalue(res, i, 3)); + char *initprivs = PQgetvalue(res, i, 4); + CatalogId objId; + DumpableObject *dobj; - objId.tableoid = classoid; - objId.oid = objoid; - dobj = findObjectByCatalogId(objId); - /* OK to ignore entries we haven't got a DumpableObject for */ - if (dobj) + objId.tableoid = classoid; + objId.oid = objoid; + dobj = findObjectByCatalogId(objId); + /* OK to ignore entries we haven't got a DumpableObject for */ + if (dobj) + { + /* Cope with sub-object initprivs */ + if (objsubid != 0) { - /* Cope with sub-object initprivs */ - if (objsubid != 0) - { - if (dobj->objType == DO_TABLE) - { - /* For a column initprivs, set the table's ACL flags */ - dobj->components |= DUMP_COMPONENT_ACL; - ((TableInfo *) dobj)->hascolumnACLs = true; - } - else - pg_log_warning("unsupported pg_init_privs entry: %u %u %d", - classoid, objoid, objsubid); - continue; - } - - /* - * We ignore any pg_init_privs.initprivs entry for the public - * schema, as explained in getNamespaces(). - */ - if (dobj->objType == DO_NAMESPACE && - strcmp(dobj->name, "public") == 0) - continue; - - /* Else it had better be of a type we think has ACLs */ - if (dobj->objType == DO_NAMESPACE || - dobj->objType == DO_TYPE || - dobj->objType == DO_FUNC || - dobj->objType == DO_AGG || - dobj->objType == DO_TABLE || - dobj->objType == DO_PROCLANG || - dobj->objType == DO_FDW || - dobj->objType == DO_FOREIGN_SERVER) + if (dobj->objType == DO_TABLE) { - DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; - - daobj->dacl.privtype = privtype; - daobj->dacl.initprivs = pstrdup(initprivs); + /* For a column initprivs, set the table's ACL flags */ + dobj->components |= DUMP_COMPONENT_ACL; + ((TableInfo *) dobj)->hascolumnACLs = true; } else pg_log_warning("unsupported pg_init_privs entry: %u %u %d", classoid, objoid, objsubid); + continue; + } + + /* + * We ignore any pg_init_privs.initprivs entry for the public + * schema, as explained in getNamespaces(). + */ + if (dobj->objType == DO_NAMESPACE && + strcmp(dobj->name, "public") == 0) + continue; + + /* Else it had better be of a type we think has ACLs */ + if (dobj->objType == DO_NAMESPACE || + dobj->objType == DO_TYPE || + dobj->objType == DO_FUNC || + dobj->objType == DO_AGG || + dobj->objType == DO_TABLE || + dobj->objType == DO_PROCLANG || + dobj->objType == DO_FDW || + dobj->objType == DO_FOREIGN_SERVER) + { + DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; + + daobj->dacl.privtype = privtype; + daobj->dacl.initprivs = pstrdup(initprivs); } + else + pg_log_warning("unsupported pg_init_privs entry: %u %u %d", + classoid, objoid, objsubid); } - PQclear(res); + } + PQclear(res); destroyPQExpBuffer(query); } @@ -11128,8 +11127,8 @@ dumpRelationStats_dumper(Archive *fout, const void *userArg, const TocEntry *te) * The results must be in the order of the relations supplied in the * parameters to ensure we remain in sync as we walk through the TOC. * - * For versions before 19, the redundant filter clause on s.tablename = - * ANY(...) seems sufficient to convince the planner to use + * For versions before 19, the redundant filter clause on s.tablename + * = ANY(...) seems sufficient to convince the planner to use * pg_class_relname_nsp_index, which avoids a full scan of pg_stats. * In newer versions, pg_stats returns the table OIDs, eliminating the * need for that hack. @@ -13469,11 +13468,11 @@ dumpFunc(Archive *fout, const FuncInfo *finfo) "pg_catalog.pg_get_function_result(p.oid) AS funcresult,\n" "proleakproof,\n"); - appendPQExpBufferStr(query, - "array_to_string(protrftypes, ' ') AS protrftypes,\n"); + appendPQExpBufferStr(query, + "array_to_string(protrftypes, ' ') AS protrftypes,\n"); - appendPQExpBufferStr(query, - "proparallel,\n"); + appendPQExpBufferStr(query, + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -14963,9 +14962,9 @@ dumpCollation(Archive *fout, const CollInfo *collinfo) /* Get collation-specific details */ appendPQExpBufferStr(query, "SELECT "); - appendPQExpBufferStr(query, - "collprovider, " - "collversion, "); + appendPQExpBufferStr(query, + "collprovider, " + "collversion, "); if (fout->remoteVersion >= 120000) appendPQExpBufferStr(query, @@ -15372,23 +15371,23 @@ dumpAgg(Archive *fout, const AggInfo *agginfo) "pg_catalog.pg_get_function_arguments(p.oid) AS funcargs,\n" "pg_catalog.pg_get_function_identity_arguments(p.oid) AS funciargs,\n"); - appendPQExpBufferStr(query, - "aggkind,\n" - "aggmtransfn,\n" - "aggminvtransfn,\n" - "aggmfinalfn,\n" - "aggmtranstype::pg_catalog.regtype,\n" - "aggfinalextra,\n" - "aggmfinalextra,\n" - "aggtransspace,\n" - "aggmtransspace,\n" - "aggminitval,\n"); + appendPQExpBufferStr(query, + "aggkind,\n" + "aggmtransfn,\n" + "aggminvtransfn,\n" + "aggmfinalfn,\n" + "aggmtranstype::pg_catalog.regtype,\n" + "aggfinalextra,\n" + "aggmfinalextra,\n" + "aggtransspace,\n" + "aggmtransspace,\n" + "aggminitval,\n"); - appendPQExpBufferStr(query, - "aggcombinefn,\n" - "aggserialfn,\n" - "aggdeserialfn,\n" - "proparallel,\n"); + appendPQExpBufferStr(query, + "aggcombinefn,\n" + "aggserialfn,\n" + "aggdeserialfn,\n" + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -16848,30 +16847,30 @@ dumpTable(Archive *fout, const TableInfo *tbinfo) appendPQExpBufferStr(query, "PREPARE getColumnACLs(pg_catalog.oid) AS\n"); - /* - * In principle we should call acldefault('c', relowner) to - * get the default ACL for a column. However, we don't - * currently store the numeric OID of the relowner in - * TableInfo. We could convert the owner name using regrole, - * but that creates a risk of failure due to concurrent role - * renames. Given that the default ACL for columns is empty - * and is likely to stay that way, it's not worth extra cycles - * and risk to avoid hard-wiring that knowledge here. - */ - appendPQExpBufferStr(query, - "SELECT at.attname, " - "at.attacl, " - "'{}' AS acldefault, " - "pip.privtype, pip.initprivs " - "FROM pg_catalog.pg_attribute at " - "LEFT JOIN pg_catalog.pg_init_privs pip ON " - "(at.attrelid = pip.objoid " - "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " - "AND at.attnum = pip.objsubid) " - "WHERE at.attrelid = $1 AND " - "NOT at.attisdropped " - "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " - "ORDER BY at.attnum"); + /* + * In principle we should call acldefault('c', relowner) to get + * the default ACL for a column. However, we don't currently + * store the numeric OID of the relowner in TableInfo. We could + * convert the owner name using regrole, but that creates a risk + * of failure due to concurrent role renames. Given that the + * default ACL for columns is empty and is likely to stay that + * way, it's not worth extra cycles and risk to avoid hard-wiring + * that knowledge here. + */ + appendPQExpBufferStr(query, + "SELECT at.attname, " + "at.attacl, " + "'{}' AS acldefault, " + "pip.privtype, pip.initprivs " + "FROM pg_catalog.pg_attribute at " + "LEFT JOIN pg_catalog.pg_init_privs pip ON " + "(at.attrelid = pip.objoid " + "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " + "AND at.attnum = pip.objsubid) " + "WHERE at.attrelid = $1 AND " + "NOT at.attisdropped " + "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " + "ORDER BY at.attnum"); ExecuteSqlStatement(fout, query->data); @@ -19165,7 +19164,7 @@ collectSequences(Archive *fout) * pg_get_sequence_data(), but we only do so for non-schema-only dumps. */ if (fout->remoteVersion < 180000 || - (!fout->dopt->dumpData && !fout->dopt->sequence_data)) + (!fout->dopt->dumpData && !fout->dopt->sequence_data)) query = "SELECT seqrelid, format_type(seqtypid, NULL), " "seqstart, seqincrement, " "seqmax, seqmin, " @@ -19227,15 +19226,14 @@ dumpSequence(Archive *fout, const TableInfo *tbinfo) qseqname = pg_strdup(fmtId(tbinfo->dobj.name)); /* - * The sequence information is gathered in a sorted - * table before any calls to dumpSequence(). See collectSequences() for - * more information. + * The sequence information is gathered in a sorted table before any calls + * to dumpSequence(). See collectSequences() for more information. */ - Assert(sequences); + Assert(sequences); - key.oid = tbinfo->dobj.catId.oid; - seq = bsearch(&key, sequences, nsequences, - sizeof(SequenceItem), SequenceItemCmp); + key.oid = tbinfo->dobj.catId.oid; + seq = bsearch(&key, sequences, nsequences, + sizeof(SequenceItem), SequenceItemCmp); /* Calculate default limits for a sequence of this type */ is_ascending = (seq->incby >= 0); diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c index e68937c9934..afcd9a218d8 100644 --- a/src/bin/pg_dump/pg_dumpall.c +++ b/src/bin/pg_dump/pg_dumpall.c @@ -785,11 +785,11 @@ dropRoles(PGconn *conn) int i_rolname; int i; - printfPQExpBuffer(buf, - "SELECT rolname " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 1", role_catalog); + printfPQExpBuffer(buf, + "SELECT rolname " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 1", role_catalog); res = executeQuery(conn, buf->data); @@ -843,16 +843,16 @@ dumpRoles(PGconn *conn) * Notes: rolconfig is dumped later, and pg_authid must be used for * extracting rolcomment regardless of role_catalog. */ - printfPQExpBuffer(buf, - "SELECT oid, rolname, rolsuper, rolinherit, " - "rolcreaterole, rolcreatedb, " - "rolcanlogin, rolconnlimit, rolpassword, " - "rolvaliduntil, rolreplication, rolbypassrls, " - "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " - "rolname = current_user AS is_current_user " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 2", role_catalog); + printfPQExpBuffer(buf, + "SELECT oid, rolname, rolsuper, rolinherit, " + "rolcreaterole, rolcreatedb, " + "rolcanlogin, rolconnlimit, rolpassword, " + "rolvaliduntil, rolreplication, rolbypassrls, " + "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " + "rolname = current_user AS is_current_user " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 2", role_catalog); res = executeQuery(conn, buf->data); diff --git a/src/bin/pg_upgrade/check.c b/src/bin/pg_upgrade/check.c index 786c1474829..f725f5ee3e2 100644 --- a/src/bin/pg_upgrade/check.c +++ b/src/bin/pg_upgrade/check.c @@ -1475,15 +1475,15 @@ check_for_incompatible_polymorphics(ClusterInfo *cluster) ", 'array_cat(anyarray,anyarray)'" ", 'array_prepend(anyelement,anyarray)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_remove(anyarray,anyelement)'" - ", 'array_replace(anyarray,anyelement,anyelement)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_remove(anyarray,anyelement)'" + ", 'array_replace(anyarray,anyelement,anyelement)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_position(anyarray,anyelement)'" - ", 'array_position(anyarray,anyelement,integer)'" - ", 'array_positions(anyarray,anyelement)'" - ", 'width_bucket(anyelement,anyarray)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_position(anyarray,anyelement)'" + ", 'array_position(anyarray,anyelement,integer)'" + ", 'array_positions(anyarray,anyelement)'" + ", 'width_bucket(anyelement,anyarray)'"); /* * The query below hardcodes FirstNormalObjectId as 16384 rather than diff --git a/src/bin/pg_upgrade/controldata.c b/src/bin/pg_upgrade/controldata.c index 8f81c9e9582..02ea02df60f 100644 --- a/src/bin/pg_upgrade/controldata.c +++ b/src/bin/pg_upgrade/controldata.c @@ -228,7 +228,7 @@ get_control_data(ClusterInfo *cluster) p++; /* remove ':' char */ cluster->controldata.chkpnt_nxtepoch = str2uint(p); - p = strchr(p, ':'); + p = strchr(p, ':'); if (p == NULL || strlen(p) <= 1) pg_fatal("%d: controldata retrieval problem", __LINE__); diff --git a/src/bin/pg_upgrade/exec.c b/src/bin/pg_upgrade/exec.c index 44355feea30..a1bdbf373e3 100644 --- a/src/bin/pg_upgrade/exec.c +++ b/src/bin/pg_upgrade/exec.c @@ -55,7 +55,7 @@ get_bin_version(ClusterInfo *cluster) if (sscanf(cmd_output, "%*s %*s %d.%d", &v1, &v2) < 1) pg_fatal("could not get pg_ctl version output from %s", cmd); - cluster->bin_version = v1 * 10000; + cluster->bin_version = v1 * 10000; } @@ -344,8 +344,8 @@ check_data_dir(ClusterInfo *cluster) check_single_dir(pg_data, "pg_subtrans"); check_single_dir(pg_data, PG_TBLSPC_DIR); check_single_dir(pg_data, "pg_twophase"); - check_single_dir(pg_data, "pg_wal"); - check_single_dir(pg_data, "pg_xact"); + check_single_dir(pg_data, "pg_wal"); + check_single_dir(pg_data, "pg_xact"); } @@ -385,7 +385,7 @@ check_bin_dir(ClusterInfo *cluster, bool check_versions) */ get_bin_version(cluster); - check_exec(cluster->bindir, "pg_resetwal", check_versions); + check_exec(cluster->bindir, "pg_resetwal", check_versions); if (cluster == &new_cluster) { diff --git a/src/bin/pg_upgrade/multixact_rewrite.c b/src/bin/pg_upgrade/multixact_rewrite.c index c45b3183684..c7a1416494d 100644 --- a/src/bin/pg_upgrade/multixact_rewrite.c +++ b/src/bin/pg_upgrade/multixact_rewrite.c @@ -61,52 +61,52 @@ rewrite_multixacts(MultiXactId from_multi, MultiXactId to_multi) * Convert old multixids, if needed, by reading them one-by-one from the * old cluster. */ - old_reader = AllocOldMultiXactRead(old_cluster.pgdata, - old_cluster.controldata.chkpnt_nxtmulti, - old_cluster.controldata.chkpnt_nxtmxoff); + old_reader = AllocOldMultiXactRead(old_cluster.pgdata, + old_cluster.controldata.chkpnt_nxtmulti, + old_cluster.controldata.chkpnt_nxtmxoff); - for (MultiXactId multi = from_multi; multi != to_multi;) - { - MultiXactMember member; - bool multixid_valid; - - /* - * Read this multixid's members. - * - * Locking-only XIDs that may be part of multi-xids don't matter - * after upgrade, as there can be no transactions running across - * upgrade. So as a small optimization, we only read one member - * from each multixid: the one updating one, or if there was no - * update, arbitrarily the first locking xid. - */ - multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); + for (MultiXactId multi = from_multi; multi != to_multi;) + { + MultiXactMember member; + bool multixid_valid; - /* - * Write the new offset to pg_multixact/offsets. - * - * Even if this multixid is invalid, we still need to write its - * offset if the *previous* multixid was valid. That's because - * when reading a multixid, the number of members is calculated - * from the difference between the two offsets. - */ - RecordMultiXactOffset(offsets_writer, multi, - (multixid_valid || prev_multixid_valid) ? next_offset : 0); + /* + * Read this multixid's members. + * + * Locking-only XIDs that may be part of multi-xids don't matter after + * upgrade, as there can be no transactions running across upgrade. So + * as a small optimization, we only read one member from each + * multixid: the one updating one, or if there was no update, + * arbitrarily the first locking xid. + */ + multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); - /* Write the members */ - if (multixid_valid) - { - RecordMultiXactMembers(members_writer, next_offset, 1, &member); - next_offset += 1; - } + /* + * Write the new offset to pg_multixact/offsets. + * + * Even if this multixid is invalid, we still need to write its offset + * if the *previous* multixid was valid. That's because when reading + * a multixid, the number of members is calculated from the difference + * between the two offsets. + */ + RecordMultiXactOffset(offsets_writer, multi, + (multixid_valid || prev_multixid_valid) ? next_offset : 0); - /* Advance to next multixid, handling wraparound */ - multi++; - if (multi < FirstMultiXactId) - multi = FirstMultiXactId; - prev_multixid_valid = multixid_valid; + /* Write the members */ + if (multixid_valid) + { + RecordMultiXactMembers(members_writer, next_offset, 1, &member); + next_offset += 1; } - FreeOldMultiXactReader(old_reader); + /* Advance to next multixid, handling wraparound */ + multi++; + if (multi < FirstMultiXactId) + multi = FirstMultiXactId; + prev_multixid_valid = multixid_valid; + } + + FreeOldMultiXactReader(old_reader); /* Write the final 'next' offset to the last SLRU page */ RecordMultiXactOffset(offsets_writer, to_multi, diff --git a/src/bin/pg_upgrade/pg_upgrade.c b/src/bin/pg_upgrade/pg_upgrade.c index c6af9035665..7366fd4627c 100644 --- a/src/bin/pg_upgrade/pg_upgrade.c +++ b/src/bin/pg_upgrade/pg_upgrade.c @@ -833,7 +833,7 @@ copy_xact_xlog_xid(void) * Determine the range of multixacts to convert. */ nxtmulti = old_cluster.controldata.chkpnt_nxtmulti; - oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; + oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; /* handle wraparound */ if (nxtmulti < FirstMultiXactId) nxtmulti = FirstMultiXactId; @@ -898,15 +898,15 @@ set_frozenxids(void) int i_datname; int i_datallowconn; - prep_status("Setting frozenxid and minmxid counters in new cluster"); + prep_status("Setting frozenxid and minmxid counters in new cluster"); conn_template1 = connectToServer(&new_cluster, "template1"); - /* set pg_database.datfrozenxid */ - PQclear(executeQueryOrDie(conn_template1, - "UPDATE pg_catalog.pg_database " - "SET datfrozenxid = '%u'", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_database.datfrozenxid */ + PQclear(executeQueryOrDie(conn_template1, + "UPDATE pg_catalog.pg_database " + "SET datfrozenxid = '%u'", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_database.datminmxid */ PQclear(executeQueryOrDie(conn_template1, @@ -942,16 +942,16 @@ set_frozenxids(void) conn = connectToServer(&new_cluster, datname); - /* set pg_class.relfrozenxid */ - PQclear(executeQueryOrDie(conn, - "UPDATE pg_catalog.pg_class " - "SET relfrozenxid = '%u' " - /* only heap, materialized view, and TOAST are vacuumed */ - "WHERE relkind IN (" - CppAsString2(RELKIND_RELATION) ", " - CppAsString2(RELKIND_MATVIEW) ", " - CppAsString2(RELKIND_TOASTVALUE) ")", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_class.relfrozenxid */ + PQclear(executeQueryOrDie(conn, + "UPDATE pg_catalog.pg_class " + "SET relfrozenxid = '%u' " + /* only heap, materialized view, and TOAST are vacuumed */ + "WHERE relkind IN (" + CppAsString2(RELKIND_RELATION) ", " + CppAsString2(RELKIND_MATVIEW) ", " + CppAsString2(RELKIND_TOASTVALUE) ")", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_class.relminmxid */ PQclear(executeQueryOrDie(conn, diff --git a/src/bin/pg_upgrade/relfilenumber.c b/src/bin/pg_upgrade/relfilenumber.c index ec2ff7acb21..6c467bdc8a5 100644 --- a/src/bin/pg_upgrade/relfilenumber.c +++ b/src/bin/pg_upgrade/relfilenumber.c @@ -587,32 +587,32 @@ transfer_relfile(FileNameMap *map, const char *type_suffix) /* Copying files might take some time, so give feedback. */ pg_log(PG_STATUS, "%s", old_file); - switch (user_opts.transfer_mode) - { - case TRANSFER_MODE_CLONE: - pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", - old_file, new_file); - cloneFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", - old_file, new_file); - copyFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY_FILE_RANGE: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", - old_file, new_file); - copyFileByRange(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_LINK: - pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", - old_file, new_file); - linkFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_SWAP: - /* swap mode is handled in its own code path */ - pg_fatal("should never happen"); - break; - } + switch (user_opts.transfer_mode) + { + case TRANSFER_MODE_CLONE: + pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", + old_file, new_file); + cloneFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", + old_file, new_file); + copyFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY_FILE_RANGE: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", + old_file, new_file); + copyFileByRange(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_LINK: + pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", + old_file, new_file); + linkFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_SWAP: + /* swap mode is handled in its own code path */ + pg_fatal("should never happen"); + break; + } } } diff --git a/src/bin/pg_upgrade/t/006_transfer_modes.pl b/src/bin/pg_upgrade/t/006_transfer_modes.pl index 9efa5dc863c..360d05c4b68 100644 --- a/src/bin/pg_upgrade/t/006_transfer_modes.pl +++ b/src/bin/pg_upgrade/t/006_transfer_modes.pl @@ -29,10 +29,8 @@ sub test_mode } $new->init(); - $new->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); - $old->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); + $new->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); + $old->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); # We can only test security labels if both the old and new installations # have dummy_seclabel. @@ -76,15 +74,14 @@ sub test_mode "CREATE TABLE test4 AS SELECT generate_series(400, 502)"); } - $old->safe_psql('postgres', - "CREATE TABLESPACE inplc_tblspc LOCATION ''"); - $old->safe_psql('postgres', - "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); - $old->safe_psql('postgres', - "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" - ); - $old->safe_psql('testdb3', - "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); + $old->safe_psql('postgres', "CREATE TABLESPACE inplc_tblspc LOCATION ''"); + $old->safe_psql('postgres', + "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); + $old->safe_psql('postgres', + "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" + ); + $old->safe_psql('testdb3', + "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); # While we are here, test handling of large objects. $old->safe_psql( @@ -152,12 +149,10 @@ sub test_mode } # Tests for in-place tablespaces. - $result = - $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); - is($result, '104', "test5 data after pg_upgrade $mode"); - $result = - $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); - is($result, '105', "test6 data after pg_upgrade $mode"); + $result = $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); + is($result, '104', "test5 data after pg_upgrade $mode"); + $result = $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); + is($result, '105', "test6 data after pg_upgrade $mode"); # Tests for large objects $result = $new->safe_psql('postgres', "SELECT lo_get(4532)"); diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index 44ef11d980e..c90bf8bbde2 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -6278,23 +6278,22 @@ get_create_object_cmd(EditableObjectType obj_type, Oid oid, * ensure the right view gets replaced. Also, check relation kind * to be sure it's a view. * - * Views may have WITH [LOCAL|CASCADED] - * CHECK OPTION. These are not part of the view definition - * returned by pg_get_viewdef() and so need to be retrieved - * separately. Materialized views may have - * arbitrary storage parameter reloptions. + * Views may have WITH [LOCAL|CASCADED] CHECK OPTION. These are + * not part of the view definition returned by pg_get_viewdef() + * and so need to be retrieved separately. Materialized views may + * have arbitrary storage parameter reloptions. */ printfPQExpBuffer(query, "/* %s */\n", _("Get view's definition and details")); - appendPQExpBuffer(query, - "SELECT nspname, relname, relkind, " - "pg_catalog.pg_get_viewdef(c.oid, true), " - "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " - "FROM pg_catalog.pg_class c " - "LEFT JOIN pg_catalog.pg_namespace n " - "ON c.relnamespace = n.oid WHERE c.oid = %u", - oid); + appendPQExpBuffer(query, + "SELECT nspname, relname, relkind, " + "pg_catalog.pg_get_viewdef(c.oid, true), " + "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " + "FROM pg_catalog.pg_class c " + "LEFT JOIN pg_catalog.pg_namespace n " + "ON c.relnamespace = n.oid WHERE c.oid = %u", + oid); break; } diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index ce99137c613..ac0c55e7aa5 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -387,19 +387,19 @@ describeFunctions(const char *functypes, const char *func_pattern, gettext_noop("stable"), gettext_noop("volatile"), gettext_noop("Volatility")); - appendPQExpBuffer(&buf, - ",\n CASE\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" - " END as \"%s\"", - gettext_noop("restricted"), - gettext_noop("safe"), - gettext_noop("unsafe"), - gettext_noop("Parallel")); + appendPQExpBuffer(&buf, + ",\n CASE\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" + " END as \"%s\"", + gettext_noop("restricted"), + gettext_noop("safe"), + gettext_noop("unsafe"), + gettext_noop("Parallel")); appendPQExpBuffer(&buf, ",\n pg_catalog.pg_get_userbyid(p.proowner) as \"%s\"" ",\n CASE WHEN prosecdef THEN '%s' ELSE '%s' END AS \"%s\"" @@ -599,8 +599,8 @@ describeFunctions(const char *functypes, const char *func_pattern, myopt.title = _("List of functions"); myopt.translate_header = true; - myopt.translate_columns = translate_columns; - myopt.n_translate_columns = lengthof(translate_columns); + myopt.translate_columns = translate_columns; + myopt.n_translate_columns = lengthof(translate_columns); printQuery(res, &myopt, pset.queryFout, false, pset.logfile); @@ -1086,38 +1086,38 @@ permissionsList(const char *pattern, bool showSystem) " ), E'\\n') AS \"%s\"", gettext_noop("Column privileges")); - appendPQExpBuffer(&buf, - ",\n pg_catalog.array_to_string(ARRAY(\n" - " SELECT polname\n" - " || CASE WHEN NOT polpermissive THEN\n" - " E' (RESTRICTIVE)'\n" - " ELSE '' END\n" - " || CASE WHEN polcmd != '*' THEN\n" - " E' (' || polcmd::pg_catalog.text || E'):'\n" - " ELSE E':'\n" - " END\n" - " || CASE WHEN polqual IS NOT NULL THEN\n" - " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" - " ELSE E''\n" - " END\n" - " || CASE WHEN polwithcheck IS NOT NULL THEN\n" - " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" - " ELSE E''\n" - " END" - " || CASE WHEN polroles <> '{0}' THEN\n" - " E'\\n to: ' || pg_catalog.array_to_string(\n" - " ARRAY(\n" - " SELECT rolname\n" - " FROM pg_catalog.pg_roles\n" - " WHERE oid = ANY (polroles)\n" - " ORDER BY 1\n" - " ), E', ')\n" - " ELSE E''\n" - " END\n" - " FROM pg_catalog.pg_policy pol\n" - " WHERE polrelid = c.oid), E'\\n')\n" - " AS \"%s\"", - gettext_noop("Policies")); + appendPQExpBuffer(&buf, + ",\n pg_catalog.array_to_string(ARRAY(\n" + " SELECT polname\n" + " || CASE WHEN NOT polpermissive THEN\n" + " E' (RESTRICTIVE)'\n" + " ELSE '' END\n" + " || CASE WHEN polcmd != '*' THEN\n" + " E' (' || polcmd::pg_catalog.text || E'):'\n" + " ELSE E':'\n" + " END\n" + " || CASE WHEN polqual IS NOT NULL THEN\n" + " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" + " ELSE E''\n" + " END\n" + " || CASE WHEN polwithcheck IS NOT NULL THEN\n" + " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" + " ELSE E''\n" + " END" + " || CASE WHEN polroles <> '{0}' THEN\n" + " E'\\n to: ' || pg_catalog.array_to_string(\n" + " ARRAY(\n" + " SELECT rolname\n" + " FROM pg_catalog.pg_roles\n" + " WHERE oid = ANY (polroles)\n" + " ORDER BY 1\n" + " ), E', ')\n" + " ELSE E''\n" + " END\n" + " FROM pg_catalog.pg_policy pol\n" + " WHERE polrelid = c.oid), E'\\n')\n" + " AS \"%s\"", + gettext_noop("Policies")); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_class c\n" " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n" @@ -1675,27 +1675,27 @@ describeOneTableDetails(const char *schemaname, char *footers[3] = {NULL, NULL, NULL}; printfPQExpBuffer(&buf, "/* %s */\n", _("Get sequence information")); - appendPQExpBuffer(&buf, - "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" - " seqstart AS \"%s\",\n" - " seqmin AS \"%s\",\n" - " seqmax AS \"%s\",\n" - " seqincrement AS \"%s\",\n" - " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" - " seqcache AS \"%s\"\n", - gettext_noop("Type"), - gettext_noop("Start"), - gettext_noop("Minimum"), - gettext_noop("Maximum"), - gettext_noop("Increment"), - gettext_noop("yes"), - gettext_noop("no"), - gettext_noop("Cycles?"), - gettext_noop("Cache")); - appendPQExpBuffer(&buf, - "FROM pg_catalog.pg_sequence\n" - "WHERE seqrelid = '%s';", - oid); + appendPQExpBuffer(&buf, + "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" + " seqstart AS \"%s\",\n" + " seqmin AS \"%s\",\n" + " seqmax AS \"%s\",\n" + " seqincrement AS \"%s\",\n" + " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" + " seqcache AS \"%s\"\n", + gettext_noop("Type"), + gettext_noop("Start"), + gettext_noop("Minimum"), + gettext_noop("Maximum"), + gettext_noop("Increment"), + gettext_noop("yes"), + gettext_noop("no"), + gettext_noop("Cycles?"), + gettext_noop("Cache")); + appendPQExpBuffer(&buf, + "FROM pg_catalog.pg_sequence\n" + "WHERE seqrelid = '%s';", + oid); res = PSQLexec(buf.data); if (!res) @@ -1913,7 +1913,7 @@ describeOneTableDetails(const char *schemaname, appendPQExpBufferStr(&buf, ",\n (SELECT c.collname FROM pg_catalog.pg_collation c, pg_catalog.pg_type t\n" " WHERE c.oid = a.attcollation AND t.oid = a.atttypid AND a.attcollation <> t.typcollation) AS attcollation"); attcoll_col = cols++; - appendPQExpBufferStr(&buf, ",\n a.attidentity"); + appendPQExpBufferStr(&buf, ",\n a.attidentity"); attidentity_col = cols++; if (pset.sversion >= 120000) appendPQExpBufferStr(&buf, ",\n a.attgenerated"); @@ -2326,7 +2326,7 @@ describeOneTableDetails(const char *schemaname, CppAsString2(CONSTRAINT_EXCLUSION) ") AND " "condeferred) AS condeferred,\n"); - appendPQExpBufferStr(&buf, "i.indisreplident,\n"); + appendPQExpBufferStr(&buf, "i.indisreplident,\n"); if (pset.sversion >= 150000) appendPQExpBufferStr(&buf, "i.indnullsnotdistinct,\n"); @@ -2431,7 +2431,7 @@ describeOneTableDetails(const char *schemaname, "pg_catalog.pg_get_indexdef(i.indexrelid, 0, true),\n " "pg_catalog.pg_get_constraintdef(con.oid, true), " "contype, condeferrable, condeferred"); - appendPQExpBufferStr(&buf, ", i.indisreplident"); + appendPQExpBufferStr(&buf, ", i.indisreplident"); appendPQExpBufferStr(&buf, ", c2.reltablespace"); if (pset.sversion >= 180000) appendPQExpBufferStr(&buf, ", con.conperiod"); @@ -2682,81 +2682,80 @@ describeOneTableDetails(const char *schemaname, PQclear(result); /* print any row-level policies */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get row-level policies for this table")); - appendPQExpBufferStr(&buf, "SELECT pol.polname,"); - appendPQExpBufferStr(&buf, - " pol.polpermissive,\n"); - appendPQExpBuffer(&buf, - " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" - " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" - " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" - " CASE pol.polcmd\n" - " WHEN 'r' THEN 'SELECT'\n" - " WHEN 'a' THEN 'INSERT'\n" - " WHEN 'w' THEN 'UPDATE'\n" - " WHEN 'd' THEN 'DELETE'\n" - " END AS cmd\n" - "FROM pg_catalog.pg_policy pol\n" - "WHERE pol.polrelid = '%s' ORDER BY 1;", - oid); + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get row-level policies for this table")); + appendPQExpBufferStr(&buf, "SELECT pol.polname,"); + appendPQExpBufferStr(&buf, + " pol.polpermissive,\n"); + appendPQExpBuffer(&buf, + " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" + " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" + " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" + " CASE pol.polcmd\n" + " WHEN 'r' THEN 'SELECT'\n" + " WHEN 'a' THEN 'INSERT'\n" + " WHEN 'w' THEN 'UPDATE'\n" + " WHEN 'd' THEN 'DELETE'\n" + " END AS cmd\n" + "FROM pg_catalog.pg_policy pol\n" + "WHERE pol.polrelid = '%s' ORDER BY 1;", + oid); - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - /* - * Handle cases where RLS is enabled and there are policies, or - * there aren't policies, or RLS isn't enabled but there are - * policies - */ - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies:")); + /* + * Handle cases where RLS is enabled and there are policies, or there + * aren't policies, or RLS isn't enabled but there are policies + */ + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies:")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled):")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled):")); - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); - if (!tableinfo.rowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (row security disabled):")); + if (!tableinfo.rowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (row security disabled):")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " POLICY \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " POLICY \"%s\"", + PQgetvalue(result, i, 0)); - if (*(PQgetvalue(result, i, 1)) == 'f') - appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); + if (*(PQgetvalue(result, i, 1)) == 'f') + appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); - if (!PQgetisnull(result, i, 5)) - appendPQExpBuffer(&buf, " FOR %s", - PQgetvalue(result, i, 5)); + if (!PQgetisnull(result, i, 5)) + appendPQExpBuffer(&buf, " FOR %s", + PQgetvalue(result, i, 5)); - if (!PQgetisnull(result, i, 2)) - { - appendPQExpBuffer(&buf, "\n TO %s", - PQgetvalue(result, i, 2)); - } + if (!PQgetisnull(result, i, 2)) + { + appendPQExpBuffer(&buf, "\n TO %s", + PQgetvalue(result, i, 2)); + } - if (!PQgetisnull(result, i, 3)) - appendPQExpBuffer(&buf, "\n USING (%s)", - PQgetvalue(result, i, 3)); + if (!PQgetisnull(result, i, 3)) + appendPQExpBuffer(&buf, "\n USING (%s)", + PQgetvalue(result, i, 3)); - if (!PQgetisnull(result, i, 4)) - appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", - PQgetvalue(result, i, 4)); + if (!PQgetisnull(result, i, 4)) + appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", + PQgetvalue(result, i, 4)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* print any extended statistics */ if (pset.sversion >= 140000) @@ -3025,115 +3024,115 @@ describeOneTableDetails(const char *schemaname, } /* print any publications */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get publications that publish this table")); - if (pset.sversion >= 150000) + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get publications that publish this table")); + if (pset.sversion >= 150000) + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" + " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" + "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" + "UNION\n" + "SELECT pubname\n" + " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" + " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" + " (SELECT pg_catalog.string_agg(attname, ', ')\n" + " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" + " pg_catalog.pg_attribute\n" + " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" + " ELSE NULL END) " + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" + "WHERE pr.prrelid = '%s'\n", + oid, oid, oid); + + if (pset.sversion >= 190000) { + /* + * Skip entries where this relation appears in the + * publication's EXCEPT list. + */ appendPQExpBuffer(&buf, + " AND NOT pr.prexcept\n" + "UNION\n" "SELECT pubname\n" " , NULL\n" " , NULL\n" "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" - " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" - "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" - "UNION\n" - "SELECT pubname\n" - " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" - " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" - " (SELECT pg_catalog.string_agg(attname, ', ')\n" - " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" - " pg_catalog.pg_attribute\n" - " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" - " ELSE NULL END) " - "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" - "WHERE pr.prrelid = '%s'\n", + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + " AND NOT EXISTS (\n" + " SELECT 1\n" + " FROM pg_catalog.pg_publication_rel pr\n" + " WHERE pr.prpubid = p.oid AND\n" + " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" + "ORDER BY 1;", oid, oid, oid); - - if (pset.sversion >= 190000) - { - /* - * Skip entries where this relation appears in the - * publication's EXCEPT list. - */ - appendPQExpBuffer(&buf, - " AND NOT pr.prexcept\n" - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - " AND NOT EXISTS (\n" - " SELECT 1\n" - " FROM pg_catalog.pg_publication_rel pr\n" - " WHERE pr.prpubid = p.oid AND\n" - " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" - "ORDER BY 1;", - oid, oid, oid); - } - else - { - appendPQExpBuffer(&buf, - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - "ORDER BY 1;", - oid); - } } else { appendPQExpBuffer(&buf, + "UNION\n" "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - "WHERE pr.prrelid = '%s'\n" - "UNION ALL\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" + " , NULL\n" + " , NULL\n" "FROM pg_catalog.pg_publication p\n" "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" "ORDER BY 1;", - oid, oid); + oid); } + } + else + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + "WHERE pr.prrelid = '%s'\n" + "UNION ALL\n" + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + "ORDER BY 1;", + oid, oid); + } - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - if (tuples > 0) - printTableAddFooter(&cont, _("Included in publications:")); + if (tuples > 0) + printTableAddFooter(&cont, _("Included in publications:")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " \"%s\"", + PQgetvalue(result, i, 0)); - /* column list (if any) */ - if (!PQgetisnull(result, i, 2)) - appendPQExpBuffer(&buf, " (%s)", - PQgetvalue(result, i, 2)); + /* column list (if any) */ + if (!PQgetisnull(result, i, 2)) + appendPQExpBuffer(&buf, " (%s)", + PQgetvalue(result, i, 2)); - /* row filter (if any) */ - if (!PQgetisnull(result, i, 1)) - appendPQExpBuffer(&buf, " WHERE %s", - PQgetvalue(result, i, 1)); + /* row filter (if any) */ + if (!PQgetisnull(result, i, 1)) + appendPQExpBuffer(&buf, " WHERE %s", + PQgetvalue(result, i, 1)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* Print publications where the table is in the EXCEPT clause */ if (pset.sversion >= 190000) @@ -3805,7 +3804,7 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) ncols++; } appendPQExpBufferStr(&buf, "\n, r.rolreplication"); - appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); + appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_roles r\n"); @@ -3860,8 +3859,8 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) if (strcmp(PQgetvalue(res, i, (verbose ? 9 : 8)), "t") == 0) add_role_attribute(&buf, _("Replication")); - if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) - add_role_attribute(&buf, _("Bypass RLS")); + if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) + add_role_attribute(&buf, _("Bypass RLS")); conns = atoi(PQgetvalue(res, i, 6)); if (conns >= 0) @@ -5155,14 +5154,14 @@ listCollations(const char *pattern, bool verbose, bool showSystem) gettext_noop("Schema"), gettext_noop("Name")); - appendPQExpBuffer(&buf, - " CASE c.collprovider " - "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " - "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " - "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " - "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " - "END AS \"%s\",\n", - gettext_noop("Provider")); + appendPQExpBuffer(&buf, + " CASE c.collprovider " + "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " + "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " + "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " + "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " + "END AS \"%s\",\n", + gettext_noop("Provider")); appendPQExpBuffer(&buf, " c.collcollate AS \"%s\",\n" -- 2.50.1 (Apple Git-155) --aHl3HfeiUuO3zeNC-- ^ permalink raw reply [nested|flat] 59+ messages in thread
* [PATCH v6 4/4] run pgindent and pgperltidy @ 2026-06-30 18:24 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 59+ messages in thread From: Nathan Bossart @ 2026-06-30 18:24 UTC (permalink / raw) --- src/bin/pg_dump/pg_dump.c | 464 ++++++++++----------- src/bin/pg_dump/pg_dumpall.c | 30 +- src/bin/pg_upgrade/check.c | 16 +- src/bin/pg_upgrade/controldata.c | 2 +- src/bin/pg_upgrade/exec.c | 8 +- src/bin/pg_upgrade/multixact_rewrite.c | 80 ++-- src/bin/pg_upgrade/pg_upgrade.c | 34 +- src/bin/pg_upgrade/relfilenumber.c | 54 +-- src/bin/pg_upgrade/t/006_transfer_modes.pl | 33 +- src/bin/psql/command.c | 29 +- src/bin/psql/describe.c | 461 ++++++++++---------- 11 files changed, 601 insertions(+), 610 deletions(-) diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 65bd15ebfd2..5673268b467 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -1491,8 +1491,8 @@ setup_connection(Archive *AH, const char *dumpencoding, * Disable timeouts if supported. */ ExecuteSqlStatement(AH, "SET statement_timeout = 0"); - ExecuteSqlStatement(AH, "SET lock_timeout = 0"); - ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); + ExecuteSqlStatement(AH, "SET lock_timeout = 0"); + ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); if (AH->remoteVersion >= 170000) ExecuteSqlStatement(AH, "SET transaction_timeout = 0"); @@ -1505,10 +1505,10 @@ setup_connection(Archive *AH, const char *dumpencoding, /* * Adjust row-security mode, if supported. */ - if (dopt->enable_row_security) - ExecuteSqlStatement(AH, "SET row_security = on"); - else - ExecuteSqlStatement(AH, "SET row_security = off"); + if (dopt->enable_row_security) + ExecuteSqlStatement(AH, "SET row_security = on"); + else + ExecuteSqlStatement(AH, "SET row_security = off"); /* * For security reasons, we restrict the expansion of non-system views and @@ -1933,10 +1933,9 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) addObjectDependency(dobj, ext->dobj.dumpId); /* - * Mark the member object to have any non-initial ACLs - * dumped. (Any initial ACLs will be removed later, using data from - * pg_init_privs, so that we'll dump only the delta from the extension's - * initial setup.) + * Mark the member object to have any non-initial ACLs dumped. (Any + * initial ACLs will be removed later, using data from pg_init_privs, so + * that we'll dump only the delta from the extension's initial setup.) * * In binary upgrades, we still dump all components of the members * individually, since the idea is to exactly reproduce the database @@ -1953,7 +1952,7 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) if (fout->dopt->binary_upgrade) dobj->dump = ext->dobj.dump; else - dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); + dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); return true; } @@ -1987,9 +1986,9 @@ selectDumpableNamespace(NamespaceInfo *nsinfo, Archive *fout) else if (strcmp(nsinfo->dobj.name, "pg_catalog") == 0) { /* - * We dump out any ACLs defined in pg_catalog, if - * they are interesting (and not the original ACLs which were set at - * initdb time, see pg_init_privs). + * We dump out any ACLs defined in pg_catalog, if they are interesting + * (and not the original ACLs which were set at initdb time, see + * pg_init_privs). */ nsinfo->dobj.dump_contains = nsinfo->dobj.dump = DUMP_COMPONENT_ACL; } @@ -3296,7 +3295,7 @@ dumpDatabase(Archive *fout) "datcollate, datctype, datfrozenxid, " "datacl, acldefault('d', datdba) AS acldefault, " "datistemplate, datconnlimit, "); - appendPQExpBufferStr(dbQry, "datminmxid, "); + appendPQExpBufferStr(dbQry, "datminmxid, "); if (fout->remoteVersion >= 170000) appendPQExpBufferStr(dbQry, "datlocprovider, datlocale, datcollversion, "); else if (fout->remoteVersion >= 150000) @@ -3638,11 +3637,11 @@ dumpDatabase(Archive *fout) ii_oid, ii_relminmxid; - appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" - "FROM pg_catalog.pg_class\n" - "WHERE oid IN (%u, %u, %u, %u);\n", - LargeObjectRelationId, LargeObjectLOidPNIndexId, - LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); + appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" + "FROM pg_catalog.pg_class\n" + "WHERE oid IN (%u, %u, %u, %u);\n", + LargeObjectRelationId, LargeObjectLOidPNIndexId, + LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); lo_res = ExecuteSqlQuery(fout, loFrozenQry->data, PGRES_TUPLES_OK); @@ -4274,7 +4273,7 @@ getPolicies(Archive *fout, TableInfo tblinfo[], int numTables) printfPQExpBuffer(query, "SELECT pol.oid, pol.tableoid, pol.polrelid, pol.polname, pol.polcmd, "); - appendPQExpBufferStr(query, "pol.polpermissive, "); + appendPQExpBufferStr(query, "pol.polpermissive, "); appendPQExpBuffer(query, "CASE WHEN pol.polroles = '{0}' THEN NULL ELSE " " pg_catalog.array_to_string(ARRAY(SELECT pg_catalog.quote_ident(rolname) from pg_catalog.pg_roles WHERE oid = ANY(pol.polroles)), ', ') END AS polroles, " @@ -6633,9 +6632,9 @@ getAccessMethods(Archive *fout) * Select all access methods from pg_am table. */ appendPQExpBufferStr(query, "SELECT tableoid, oid, amname, "); - appendPQExpBufferStr(query, - "amtype, " - "amhandler::pg_catalog.regproc AS amhandler "); + appendPQExpBufferStr(query, + "amtype, " + "amhandler::pg_catalog.regproc AS amhandler "); appendPQExpBufferStr(query, "FROM pg_am"); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6827,35 +6826,35 @@ getAggregates(Archive *fout) * Find all interesting aggregates. See comment in getFuncs() for the * rationale behind the filtering logic. */ - agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" - : "p.proisagg"); + agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" + : "p.proisagg"); - appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " - "p.proname AS aggname, " - "p.pronamespace AS aggnamespace, " - "p.pronargs, p.proargtypes, " - "p.proowner, " - "p.proacl AS aggacl, " - "acldefault('f', p.proowner) AS acldefault " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s AND (" - "p.pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog') OR " - "p.proacl IS DISTINCT FROM pip.initprivs", - agg_check); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - " OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); - appendPQExpBufferChar(query, ')'); + appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " + "p.proname AS aggname, " + "p.pronamespace AS aggnamespace, " + "p.pronargs, p.proargtypes, " + "p.proowner, " + "p.proacl AS aggacl, " + "acldefault('f', p.proowner) AS acldefault " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s AND (" + "p.pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog') OR " + "p.proacl IS DISTINCT FROM pip.initprivs", + agg_check); + if (dopt->binary_upgrade) + appendPQExpBufferStr(query, + " OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6957,53 +6956,53 @@ getFuncs(Archive *fout) * include them, since we want to dump extension members individually in * that mode. Also, if they are used by casts or transforms then we need * to gather the information about them, though they won't be dumped if - * they are built-in. Also, include functions in - * pg_catalog if they have an ACL different from what's shown in - * pg_init_privs (so we have to join to pg_init_privs; annoying). + * they are built-in. Also, include functions in pg_catalog if they have + * an ACL different from what's shown in pg_init_privs (so we have to join + * to pg_init_privs; annoying). */ - not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" - : "NOT p.proisagg"); + not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" + : "NOT p.proisagg"); - appendPQExpBuffer(query, - "SELECT p.tableoid, p.oid, p.proname, p.prolang, " - "p.pronargs, p.proargtypes, p.prorettype, " - "p.proacl, " - "acldefault('f', p.proowner) AS acldefault, " - "p.pronamespace, " - "p.proowner " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s" - "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " - "WHERE classid = 'pg_proc'::regclass AND " - "objid = p.oid AND deptype = 'i')" - "\n AND (" - "\n pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog')" - "\n OR EXISTS (SELECT 1 FROM pg_cast" - "\n WHERE pg_cast.oid > %u " - "\n AND p.oid = pg_cast.castfunc)" - "\n OR EXISTS (SELECT 1 FROM pg_transform" - "\n WHERE pg_transform.oid > %u AND " - "\n (p.oid = pg_transform.trffromsql" - "\n OR p.oid = pg_transform.trftosql))", - not_agg_check, - g_last_builtin_oid, - g_last_builtin_oid); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); + appendPQExpBuffer(query, + "SELECT p.tableoid, p.oid, p.proname, p.prolang, " + "p.pronargs, p.proargtypes, p.prorettype, " + "p.proacl, " + "acldefault('f', p.proowner) AS acldefault, " + "p.pronamespace, " + "p.proowner " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s" + "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " + "WHERE classid = 'pg_proc'::regclass AND " + "objid = p.oid AND deptype = 'i')" + "\n AND (" + "\n pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog')" + "\n OR EXISTS (SELECT 1 FROM pg_cast" + "\n WHERE pg_cast.oid > %u " + "\n AND p.oid = pg_cast.castfunc)" + "\n OR EXISTS (SELECT 1 FROM pg_transform" + "\n WHERE pg_transform.oid > %u AND " + "\n (p.oid = pg_transform.trffromsql" + "\n OR p.oid = pg_transform.trftosql))", + not_agg_check, + g_last_builtin_oid, + g_last_builtin_oid); + if (dopt->binary_upgrade) appendPQExpBufferStr(query, - "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); - appendPQExpBufferChar(query, ')'); + "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferStr(query, + "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -7252,31 +7251,31 @@ getTables(Archive *fout, int *numTables) appendPQExpBufferStr(query, "c.relhasoids, "); - appendPQExpBufferStr(query, - "c.relispopulated, "); + appendPQExpBufferStr(query, + "c.relispopulated, "); - appendPQExpBufferStr(query, - "c.relreplident, "); + appendPQExpBufferStr(query, + "c.relreplident, "); - appendPQExpBufferStr(query, - "c.relrowsecurity, c.relforcerowsecurity, "); + appendPQExpBufferStr(query, + "c.relrowsecurity, c.relforcerowsecurity, "); - appendPQExpBufferStr(query, - "c.relminmxid, tc.relminmxid AS tminmxid, "); + appendPQExpBufferStr(query, + "c.relminmxid, tc.relminmxid AS tminmxid, "); - appendPQExpBufferStr(query, - "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); + appendPQExpBufferStr(query, + "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); - appendPQExpBufferStr(query, - "am.amname, "); + appendPQExpBufferStr(query, + "am.amname, "); - appendPQExpBufferStr(query, - "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); + appendPQExpBufferStr(query, + "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); - appendPQExpBufferStr(query, - "c.relispartition AS ispartition "); + appendPQExpBufferStr(query, + "c.relispartition AS ispartition "); /* * Left join to pg_depend to pick up dependency info linking sequences to @@ -7296,8 +7295,8 @@ getTables(Archive *fout, int *numTables) /* * Left join to pg_am to pick up the amname. */ - appendPQExpBufferStr(query, - "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); + appendPQExpBufferStr(query, + "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); /* * We purposefully ignore toast OIDs for partitioned tables; the reason is @@ -7868,8 +7867,8 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables) "t.reloptions AS indreloptions, "); - appendPQExpBufferStr(query, - "i.indisreplident, "); + appendPQExpBufferStr(query, + "i.indisreplident, "); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -9313,8 +9312,8 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables) appendPQExpBufferStr(q, "'' AS attcompression,\n"); - appendPQExpBufferStr(q, - "a.attidentity,\n"); + appendPQExpBufferStr(q, + "a.attidentity,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(q, @@ -10717,73 +10716,73 @@ getAdditionalACLs(Archive *fout) PQclear(res); /* Fetch initial-privileges data */ - printfPQExpBuffer(query, - "SELECT objoid, classoid, objsubid, privtype, initprivs " - "FROM pg_init_privs"); + printfPQExpBuffer(query, + "SELECT objoid, classoid, objsubid, privtype, initprivs " + "FROM pg_init_privs"); - res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); + res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); - ntups = PQntuples(res); - for (i = 0; i < ntups; i++) - { - Oid objoid = atooid(PQgetvalue(res, i, 0)); - Oid classoid = atooid(PQgetvalue(res, i, 1)); - int objsubid = atoi(PQgetvalue(res, i, 2)); - char privtype = *(PQgetvalue(res, i, 3)); - char *initprivs = PQgetvalue(res, i, 4); - CatalogId objId; - DumpableObject *dobj; + ntups = PQntuples(res); + for (i = 0; i < ntups; i++) + { + Oid objoid = atooid(PQgetvalue(res, i, 0)); + Oid classoid = atooid(PQgetvalue(res, i, 1)); + int objsubid = atoi(PQgetvalue(res, i, 2)); + char privtype = *(PQgetvalue(res, i, 3)); + char *initprivs = PQgetvalue(res, i, 4); + CatalogId objId; + DumpableObject *dobj; - objId.tableoid = classoid; - objId.oid = objoid; - dobj = findObjectByCatalogId(objId); - /* OK to ignore entries we haven't got a DumpableObject for */ - if (dobj) + objId.tableoid = classoid; + objId.oid = objoid; + dobj = findObjectByCatalogId(objId); + /* OK to ignore entries we haven't got a DumpableObject for */ + if (dobj) + { + /* Cope with sub-object initprivs */ + if (objsubid != 0) { - /* Cope with sub-object initprivs */ - if (objsubid != 0) - { - if (dobj->objType == DO_TABLE) - { - /* For a column initprivs, set the table's ACL flags */ - dobj->components |= DUMP_COMPONENT_ACL; - ((TableInfo *) dobj)->hascolumnACLs = true; - } - else - pg_log_warning("unsupported pg_init_privs entry: %u %u %d", - classoid, objoid, objsubid); - continue; - } - - /* - * We ignore any pg_init_privs.initprivs entry for the public - * schema, as explained in getNamespaces(). - */ - if (dobj->objType == DO_NAMESPACE && - strcmp(dobj->name, "public") == 0) - continue; - - /* Else it had better be of a type we think has ACLs */ - if (dobj->objType == DO_NAMESPACE || - dobj->objType == DO_TYPE || - dobj->objType == DO_FUNC || - dobj->objType == DO_AGG || - dobj->objType == DO_TABLE || - dobj->objType == DO_PROCLANG || - dobj->objType == DO_FDW || - dobj->objType == DO_FOREIGN_SERVER) + if (dobj->objType == DO_TABLE) { - DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; - - daobj->dacl.privtype = privtype; - daobj->dacl.initprivs = pstrdup(initprivs); + /* For a column initprivs, set the table's ACL flags */ + dobj->components |= DUMP_COMPONENT_ACL; + ((TableInfo *) dobj)->hascolumnACLs = true; } else pg_log_warning("unsupported pg_init_privs entry: %u %u %d", classoid, objoid, objsubid); + continue; + } + + /* + * We ignore any pg_init_privs.initprivs entry for the public + * schema, as explained in getNamespaces(). + */ + if (dobj->objType == DO_NAMESPACE && + strcmp(dobj->name, "public") == 0) + continue; + + /* Else it had better be of a type we think has ACLs */ + if (dobj->objType == DO_NAMESPACE || + dobj->objType == DO_TYPE || + dobj->objType == DO_FUNC || + dobj->objType == DO_AGG || + dobj->objType == DO_TABLE || + dobj->objType == DO_PROCLANG || + dobj->objType == DO_FDW || + dobj->objType == DO_FOREIGN_SERVER) + { + DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; + + daobj->dacl.privtype = privtype; + daobj->dacl.initprivs = pstrdup(initprivs); } + else + pg_log_warning("unsupported pg_init_privs entry: %u %u %d", + classoid, objoid, objsubid); } - PQclear(res); + } + PQclear(res); destroyPQExpBuffer(query); } @@ -11128,8 +11127,8 @@ dumpRelationStats_dumper(Archive *fout, const void *userArg, const TocEntry *te) * The results must be in the order of the relations supplied in the * parameters to ensure we remain in sync as we walk through the TOC. * - * For versions before 19, the redundant filter clause on s.tablename = - * ANY(...) seems sufficient to convince the planner to use + * For versions before 19, the redundant filter clause on s.tablename + * = ANY(...) seems sufficient to convince the planner to use * pg_class_relname_nsp_index, which avoids a full scan of pg_stats. * In newer versions, pg_stats returns the table OIDs, eliminating the * need for that hack. @@ -13469,11 +13468,11 @@ dumpFunc(Archive *fout, const FuncInfo *finfo) "pg_catalog.pg_get_function_result(p.oid) AS funcresult,\n" "proleakproof,\n"); - appendPQExpBufferStr(query, - "array_to_string(protrftypes, ' ') AS protrftypes,\n"); + appendPQExpBufferStr(query, + "array_to_string(protrftypes, ' ') AS protrftypes,\n"); - appendPQExpBufferStr(query, - "proparallel,\n"); + appendPQExpBufferStr(query, + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -14963,9 +14962,9 @@ dumpCollation(Archive *fout, const CollInfo *collinfo) /* Get collation-specific details */ appendPQExpBufferStr(query, "SELECT "); - appendPQExpBufferStr(query, - "collprovider, " - "collversion, "); + appendPQExpBufferStr(query, + "collprovider, " + "collversion, "); if (fout->remoteVersion >= 120000) appendPQExpBufferStr(query, @@ -15372,23 +15371,23 @@ dumpAgg(Archive *fout, const AggInfo *agginfo) "pg_catalog.pg_get_function_arguments(p.oid) AS funcargs,\n" "pg_catalog.pg_get_function_identity_arguments(p.oid) AS funciargs,\n"); - appendPQExpBufferStr(query, - "aggkind,\n" - "aggmtransfn,\n" - "aggminvtransfn,\n" - "aggmfinalfn,\n" - "aggmtranstype::pg_catalog.regtype,\n" - "aggfinalextra,\n" - "aggmfinalextra,\n" - "aggtransspace,\n" - "aggmtransspace,\n" - "aggminitval,\n"); + appendPQExpBufferStr(query, + "aggkind,\n" + "aggmtransfn,\n" + "aggminvtransfn,\n" + "aggmfinalfn,\n" + "aggmtranstype::pg_catalog.regtype,\n" + "aggfinalextra,\n" + "aggmfinalextra,\n" + "aggtransspace,\n" + "aggmtransspace,\n" + "aggminitval,\n"); - appendPQExpBufferStr(query, - "aggcombinefn,\n" - "aggserialfn,\n" - "aggdeserialfn,\n" - "proparallel,\n"); + appendPQExpBufferStr(query, + "aggcombinefn,\n" + "aggserialfn,\n" + "aggdeserialfn,\n" + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -16848,30 +16847,30 @@ dumpTable(Archive *fout, const TableInfo *tbinfo) appendPQExpBufferStr(query, "PREPARE getColumnACLs(pg_catalog.oid) AS\n"); - /* - * In principle we should call acldefault('c', relowner) to - * get the default ACL for a column. However, we don't - * currently store the numeric OID of the relowner in - * TableInfo. We could convert the owner name using regrole, - * but that creates a risk of failure due to concurrent role - * renames. Given that the default ACL for columns is empty - * and is likely to stay that way, it's not worth extra cycles - * and risk to avoid hard-wiring that knowledge here. - */ - appendPQExpBufferStr(query, - "SELECT at.attname, " - "at.attacl, " - "'{}' AS acldefault, " - "pip.privtype, pip.initprivs " - "FROM pg_catalog.pg_attribute at " - "LEFT JOIN pg_catalog.pg_init_privs pip ON " - "(at.attrelid = pip.objoid " - "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " - "AND at.attnum = pip.objsubid) " - "WHERE at.attrelid = $1 AND " - "NOT at.attisdropped " - "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " - "ORDER BY at.attnum"); + /* + * In principle we should call acldefault('c', relowner) to get + * the default ACL for a column. However, we don't currently + * store the numeric OID of the relowner in TableInfo. We could + * convert the owner name using regrole, but that creates a risk + * of failure due to concurrent role renames. Given that the + * default ACL for columns is empty and is likely to stay that + * way, it's not worth extra cycles and risk to avoid hard-wiring + * that knowledge here. + */ + appendPQExpBufferStr(query, + "SELECT at.attname, " + "at.attacl, " + "'{}' AS acldefault, " + "pip.privtype, pip.initprivs " + "FROM pg_catalog.pg_attribute at " + "LEFT JOIN pg_catalog.pg_init_privs pip ON " + "(at.attrelid = pip.objoid " + "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " + "AND at.attnum = pip.objsubid) " + "WHERE at.attrelid = $1 AND " + "NOT at.attisdropped " + "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " + "ORDER BY at.attnum"); ExecuteSqlStatement(fout, query->data); @@ -19165,7 +19164,7 @@ collectSequences(Archive *fout) * pg_get_sequence_data(), but we only do so for non-schema-only dumps. */ if (fout->remoteVersion < 180000 || - (!fout->dopt->dumpData && !fout->dopt->sequence_data)) + (!fout->dopt->dumpData && !fout->dopt->sequence_data)) query = "SELECT seqrelid, format_type(seqtypid, NULL), " "seqstart, seqincrement, " "seqmax, seqmin, " @@ -19227,15 +19226,14 @@ dumpSequence(Archive *fout, const TableInfo *tbinfo) qseqname = pg_strdup(fmtId(tbinfo->dobj.name)); /* - * The sequence information is gathered in a sorted - * table before any calls to dumpSequence(). See collectSequences() for - * more information. + * The sequence information is gathered in a sorted table before any calls + * to dumpSequence(). See collectSequences() for more information. */ - Assert(sequences); + Assert(sequences); - key.oid = tbinfo->dobj.catId.oid; - seq = bsearch(&key, sequences, nsequences, - sizeof(SequenceItem), SequenceItemCmp); + key.oid = tbinfo->dobj.catId.oid; + seq = bsearch(&key, sequences, nsequences, + sizeof(SequenceItem), SequenceItemCmp); /* Calculate default limits for a sequence of this type */ is_ascending = (seq->incby >= 0); diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c index e68937c9934..afcd9a218d8 100644 --- a/src/bin/pg_dump/pg_dumpall.c +++ b/src/bin/pg_dump/pg_dumpall.c @@ -785,11 +785,11 @@ dropRoles(PGconn *conn) int i_rolname; int i; - printfPQExpBuffer(buf, - "SELECT rolname " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 1", role_catalog); + printfPQExpBuffer(buf, + "SELECT rolname " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 1", role_catalog); res = executeQuery(conn, buf->data); @@ -843,16 +843,16 @@ dumpRoles(PGconn *conn) * Notes: rolconfig is dumped later, and pg_authid must be used for * extracting rolcomment regardless of role_catalog. */ - printfPQExpBuffer(buf, - "SELECT oid, rolname, rolsuper, rolinherit, " - "rolcreaterole, rolcreatedb, " - "rolcanlogin, rolconnlimit, rolpassword, " - "rolvaliduntil, rolreplication, rolbypassrls, " - "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " - "rolname = current_user AS is_current_user " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 2", role_catalog); + printfPQExpBuffer(buf, + "SELECT oid, rolname, rolsuper, rolinherit, " + "rolcreaterole, rolcreatedb, " + "rolcanlogin, rolconnlimit, rolpassword, " + "rolvaliduntil, rolreplication, rolbypassrls, " + "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " + "rolname = current_user AS is_current_user " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 2", role_catalog); res = executeQuery(conn, buf->data); diff --git a/src/bin/pg_upgrade/check.c b/src/bin/pg_upgrade/check.c index 786c1474829..f725f5ee3e2 100644 --- a/src/bin/pg_upgrade/check.c +++ b/src/bin/pg_upgrade/check.c @@ -1475,15 +1475,15 @@ check_for_incompatible_polymorphics(ClusterInfo *cluster) ", 'array_cat(anyarray,anyarray)'" ", 'array_prepend(anyelement,anyarray)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_remove(anyarray,anyelement)'" - ", 'array_replace(anyarray,anyelement,anyelement)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_remove(anyarray,anyelement)'" + ", 'array_replace(anyarray,anyelement,anyelement)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_position(anyarray,anyelement)'" - ", 'array_position(anyarray,anyelement,integer)'" - ", 'array_positions(anyarray,anyelement)'" - ", 'width_bucket(anyelement,anyarray)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_position(anyarray,anyelement)'" + ", 'array_position(anyarray,anyelement,integer)'" + ", 'array_positions(anyarray,anyelement)'" + ", 'width_bucket(anyelement,anyarray)'"); /* * The query below hardcodes FirstNormalObjectId as 16384 rather than diff --git a/src/bin/pg_upgrade/controldata.c b/src/bin/pg_upgrade/controldata.c index 8f81c9e9582..02ea02df60f 100644 --- a/src/bin/pg_upgrade/controldata.c +++ b/src/bin/pg_upgrade/controldata.c @@ -228,7 +228,7 @@ get_control_data(ClusterInfo *cluster) p++; /* remove ':' char */ cluster->controldata.chkpnt_nxtepoch = str2uint(p); - p = strchr(p, ':'); + p = strchr(p, ':'); if (p == NULL || strlen(p) <= 1) pg_fatal("%d: controldata retrieval problem", __LINE__); diff --git a/src/bin/pg_upgrade/exec.c b/src/bin/pg_upgrade/exec.c index 44355feea30..a1bdbf373e3 100644 --- a/src/bin/pg_upgrade/exec.c +++ b/src/bin/pg_upgrade/exec.c @@ -55,7 +55,7 @@ get_bin_version(ClusterInfo *cluster) if (sscanf(cmd_output, "%*s %*s %d.%d", &v1, &v2) < 1) pg_fatal("could not get pg_ctl version output from %s", cmd); - cluster->bin_version = v1 * 10000; + cluster->bin_version = v1 * 10000; } @@ -344,8 +344,8 @@ check_data_dir(ClusterInfo *cluster) check_single_dir(pg_data, "pg_subtrans"); check_single_dir(pg_data, PG_TBLSPC_DIR); check_single_dir(pg_data, "pg_twophase"); - check_single_dir(pg_data, "pg_wal"); - check_single_dir(pg_data, "pg_xact"); + check_single_dir(pg_data, "pg_wal"); + check_single_dir(pg_data, "pg_xact"); } @@ -385,7 +385,7 @@ check_bin_dir(ClusterInfo *cluster, bool check_versions) */ get_bin_version(cluster); - check_exec(cluster->bindir, "pg_resetwal", check_versions); + check_exec(cluster->bindir, "pg_resetwal", check_versions); if (cluster == &new_cluster) { diff --git a/src/bin/pg_upgrade/multixact_rewrite.c b/src/bin/pg_upgrade/multixact_rewrite.c index c45b3183684..c7a1416494d 100644 --- a/src/bin/pg_upgrade/multixact_rewrite.c +++ b/src/bin/pg_upgrade/multixact_rewrite.c @@ -61,52 +61,52 @@ rewrite_multixacts(MultiXactId from_multi, MultiXactId to_multi) * Convert old multixids, if needed, by reading them one-by-one from the * old cluster. */ - old_reader = AllocOldMultiXactRead(old_cluster.pgdata, - old_cluster.controldata.chkpnt_nxtmulti, - old_cluster.controldata.chkpnt_nxtmxoff); + old_reader = AllocOldMultiXactRead(old_cluster.pgdata, + old_cluster.controldata.chkpnt_nxtmulti, + old_cluster.controldata.chkpnt_nxtmxoff); - for (MultiXactId multi = from_multi; multi != to_multi;) - { - MultiXactMember member; - bool multixid_valid; - - /* - * Read this multixid's members. - * - * Locking-only XIDs that may be part of multi-xids don't matter - * after upgrade, as there can be no transactions running across - * upgrade. So as a small optimization, we only read one member - * from each multixid: the one updating one, or if there was no - * update, arbitrarily the first locking xid. - */ - multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); + for (MultiXactId multi = from_multi; multi != to_multi;) + { + MultiXactMember member; + bool multixid_valid; - /* - * Write the new offset to pg_multixact/offsets. - * - * Even if this multixid is invalid, we still need to write its - * offset if the *previous* multixid was valid. That's because - * when reading a multixid, the number of members is calculated - * from the difference between the two offsets. - */ - RecordMultiXactOffset(offsets_writer, multi, - (multixid_valid || prev_multixid_valid) ? next_offset : 0); + /* + * Read this multixid's members. + * + * Locking-only XIDs that may be part of multi-xids don't matter after + * upgrade, as there can be no transactions running across upgrade. So + * as a small optimization, we only read one member from each + * multixid: the one updating one, or if there was no update, + * arbitrarily the first locking xid. + */ + multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); - /* Write the members */ - if (multixid_valid) - { - RecordMultiXactMembers(members_writer, next_offset, 1, &member); - next_offset += 1; - } + /* + * Write the new offset to pg_multixact/offsets. + * + * Even if this multixid is invalid, we still need to write its offset + * if the *previous* multixid was valid. That's because when reading + * a multixid, the number of members is calculated from the difference + * between the two offsets. + */ + RecordMultiXactOffset(offsets_writer, multi, + (multixid_valid || prev_multixid_valid) ? next_offset : 0); - /* Advance to next multixid, handling wraparound */ - multi++; - if (multi < FirstMultiXactId) - multi = FirstMultiXactId; - prev_multixid_valid = multixid_valid; + /* Write the members */ + if (multixid_valid) + { + RecordMultiXactMembers(members_writer, next_offset, 1, &member); + next_offset += 1; } - FreeOldMultiXactReader(old_reader); + /* Advance to next multixid, handling wraparound */ + multi++; + if (multi < FirstMultiXactId) + multi = FirstMultiXactId; + prev_multixid_valid = multixid_valid; + } + + FreeOldMultiXactReader(old_reader); /* Write the final 'next' offset to the last SLRU page */ RecordMultiXactOffset(offsets_writer, to_multi, diff --git a/src/bin/pg_upgrade/pg_upgrade.c b/src/bin/pg_upgrade/pg_upgrade.c index c6af9035665..7366fd4627c 100644 --- a/src/bin/pg_upgrade/pg_upgrade.c +++ b/src/bin/pg_upgrade/pg_upgrade.c @@ -833,7 +833,7 @@ copy_xact_xlog_xid(void) * Determine the range of multixacts to convert. */ nxtmulti = old_cluster.controldata.chkpnt_nxtmulti; - oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; + oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; /* handle wraparound */ if (nxtmulti < FirstMultiXactId) nxtmulti = FirstMultiXactId; @@ -898,15 +898,15 @@ set_frozenxids(void) int i_datname; int i_datallowconn; - prep_status("Setting frozenxid and minmxid counters in new cluster"); + prep_status("Setting frozenxid and minmxid counters in new cluster"); conn_template1 = connectToServer(&new_cluster, "template1"); - /* set pg_database.datfrozenxid */ - PQclear(executeQueryOrDie(conn_template1, - "UPDATE pg_catalog.pg_database " - "SET datfrozenxid = '%u'", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_database.datfrozenxid */ + PQclear(executeQueryOrDie(conn_template1, + "UPDATE pg_catalog.pg_database " + "SET datfrozenxid = '%u'", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_database.datminmxid */ PQclear(executeQueryOrDie(conn_template1, @@ -942,16 +942,16 @@ set_frozenxids(void) conn = connectToServer(&new_cluster, datname); - /* set pg_class.relfrozenxid */ - PQclear(executeQueryOrDie(conn, - "UPDATE pg_catalog.pg_class " - "SET relfrozenxid = '%u' " - /* only heap, materialized view, and TOAST are vacuumed */ - "WHERE relkind IN (" - CppAsString2(RELKIND_RELATION) ", " - CppAsString2(RELKIND_MATVIEW) ", " - CppAsString2(RELKIND_TOASTVALUE) ")", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_class.relfrozenxid */ + PQclear(executeQueryOrDie(conn, + "UPDATE pg_catalog.pg_class " + "SET relfrozenxid = '%u' " + /* only heap, materialized view, and TOAST are vacuumed */ + "WHERE relkind IN (" + CppAsString2(RELKIND_RELATION) ", " + CppAsString2(RELKIND_MATVIEW) ", " + CppAsString2(RELKIND_TOASTVALUE) ")", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_class.relminmxid */ PQclear(executeQueryOrDie(conn, diff --git a/src/bin/pg_upgrade/relfilenumber.c b/src/bin/pg_upgrade/relfilenumber.c index ec2ff7acb21..6c467bdc8a5 100644 --- a/src/bin/pg_upgrade/relfilenumber.c +++ b/src/bin/pg_upgrade/relfilenumber.c @@ -587,32 +587,32 @@ transfer_relfile(FileNameMap *map, const char *type_suffix) /* Copying files might take some time, so give feedback. */ pg_log(PG_STATUS, "%s", old_file); - switch (user_opts.transfer_mode) - { - case TRANSFER_MODE_CLONE: - pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", - old_file, new_file); - cloneFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", - old_file, new_file); - copyFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY_FILE_RANGE: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", - old_file, new_file); - copyFileByRange(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_LINK: - pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", - old_file, new_file); - linkFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_SWAP: - /* swap mode is handled in its own code path */ - pg_fatal("should never happen"); - break; - } + switch (user_opts.transfer_mode) + { + case TRANSFER_MODE_CLONE: + pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", + old_file, new_file); + cloneFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", + old_file, new_file); + copyFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY_FILE_RANGE: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", + old_file, new_file); + copyFileByRange(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_LINK: + pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", + old_file, new_file); + linkFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_SWAP: + /* swap mode is handled in its own code path */ + pg_fatal("should never happen"); + break; + } } } diff --git a/src/bin/pg_upgrade/t/006_transfer_modes.pl b/src/bin/pg_upgrade/t/006_transfer_modes.pl index 9efa5dc863c..360d05c4b68 100644 --- a/src/bin/pg_upgrade/t/006_transfer_modes.pl +++ b/src/bin/pg_upgrade/t/006_transfer_modes.pl @@ -29,10 +29,8 @@ sub test_mode } $new->init(); - $new->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); - $old->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); + $new->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); + $old->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); # We can only test security labels if both the old and new installations # have dummy_seclabel. @@ -76,15 +74,14 @@ sub test_mode "CREATE TABLE test4 AS SELECT generate_series(400, 502)"); } - $old->safe_psql('postgres', - "CREATE TABLESPACE inplc_tblspc LOCATION ''"); - $old->safe_psql('postgres', - "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); - $old->safe_psql('postgres', - "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" - ); - $old->safe_psql('testdb3', - "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); + $old->safe_psql('postgres', "CREATE TABLESPACE inplc_tblspc LOCATION ''"); + $old->safe_psql('postgres', + "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); + $old->safe_psql('postgres', + "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" + ); + $old->safe_psql('testdb3', + "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); # While we are here, test handling of large objects. $old->safe_psql( @@ -152,12 +149,10 @@ sub test_mode } # Tests for in-place tablespaces. - $result = - $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); - is($result, '104', "test5 data after pg_upgrade $mode"); - $result = - $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); - is($result, '105', "test6 data after pg_upgrade $mode"); + $result = $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); + is($result, '104', "test5 data after pg_upgrade $mode"); + $result = $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); + is($result, '105', "test6 data after pg_upgrade $mode"); # Tests for large objects $result = $new->safe_psql('postgres', "SELECT lo_get(4532)"); diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index 44ef11d980e..c90bf8bbde2 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -6278,23 +6278,22 @@ get_create_object_cmd(EditableObjectType obj_type, Oid oid, * ensure the right view gets replaced. Also, check relation kind * to be sure it's a view. * - * Views may have WITH [LOCAL|CASCADED] - * CHECK OPTION. These are not part of the view definition - * returned by pg_get_viewdef() and so need to be retrieved - * separately. Materialized views may have - * arbitrary storage parameter reloptions. + * Views may have WITH [LOCAL|CASCADED] CHECK OPTION. These are + * not part of the view definition returned by pg_get_viewdef() + * and so need to be retrieved separately. Materialized views may + * have arbitrary storage parameter reloptions. */ printfPQExpBuffer(query, "/* %s */\n", _("Get view's definition and details")); - appendPQExpBuffer(query, - "SELECT nspname, relname, relkind, " - "pg_catalog.pg_get_viewdef(c.oid, true), " - "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " - "FROM pg_catalog.pg_class c " - "LEFT JOIN pg_catalog.pg_namespace n " - "ON c.relnamespace = n.oid WHERE c.oid = %u", - oid); + appendPQExpBuffer(query, + "SELECT nspname, relname, relkind, " + "pg_catalog.pg_get_viewdef(c.oid, true), " + "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " + "FROM pg_catalog.pg_class c " + "LEFT JOIN pg_catalog.pg_namespace n " + "ON c.relnamespace = n.oid WHERE c.oid = %u", + oid); break; } diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index ce99137c613..ac0c55e7aa5 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -387,19 +387,19 @@ describeFunctions(const char *functypes, const char *func_pattern, gettext_noop("stable"), gettext_noop("volatile"), gettext_noop("Volatility")); - appendPQExpBuffer(&buf, - ",\n CASE\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" - " END as \"%s\"", - gettext_noop("restricted"), - gettext_noop("safe"), - gettext_noop("unsafe"), - gettext_noop("Parallel")); + appendPQExpBuffer(&buf, + ",\n CASE\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" + " END as \"%s\"", + gettext_noop("restricted"), + gettext_noop("safe"), + gettext_noop("unsafe"), + gettext_noop("Parallel")); appendPQExpBuffer(&buf, ",\n pg_catalog.pg_get_userbyid(p.proowner) as \"%s\"" ",\n CASE WHEN prosecdef THEN '%s' ELSE '%s' END AS \"%s\"" @@ -599,8 +599,8 @@ describeFunctions(const char *functypes, const char *func_pattern, myopt.title = _("List of functions"); myopt.translate_header = true; - myopt.translate_columns = translate_columns; - myopt.n_translate_columns = lengthof(translate_columns); + myopt.translate_columns = translate_columns; + myopt.n_translate_columns = lengthof(translate_columns); printQuery(res, &myopt, pset.queryFout, false, pset.logfile); @@ -1086,38 +1086,38 @@ permissionsList(const char *pattern, bool showSystem) " ), E'\\n') AS \"%s\"", gettext_noop("Column privileges")); - appendPQExpBuffer(&buf, - ",\n pg_catalog.array_to_string(ARRAY(\n" - " SELECT polname\n" - " || CASE WHEN NOT polpermissive THEN\n" - " E' (RESTRICTIVE)'\n" - " ELSE '' END\n" - " || CASE WHEN polcmd != '*' THEN\n" - " E' (' || polcmd::pg_catalog.text || E'):'\n" - " ELSE E':'\n" - " END\n" - " || CASE WHEN polqual IS NOT NULL THEN\n" - " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" - " ELSE E''\n" - " END\n" - " || CASE WHEN polwithcheck IS NOT NULL THEN\n" - " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" - " ELSE E''\n" - " END" - " || CASE WHEN polroles <> '{0}' THEN\n" - " E'\\n to: ' || pg_catalog.array_to_string(\n" - " ARRAY(\n" - " SELECT rolname\n" - " FROM pg_catalog.pg_roles\n" - " WHERE oid = ANY (polroles)\n" - " ORDER BY 1\n" - " ), E', ')\n" - " ELSE E''\n" - " END\n" - " FROM pg_catalog.pg_policy pol\n" - " WHERE polrelid = c.oid), E'\\n')\n" - " AS \"%s\"", - gettext_noop("Policies")); + appendPQExpBuffer(&buf, + ",\n pg_catalog.array_to_string(ARRAY(\n" + " SELECT polname\n" + " || CASE WHEN NOT polpermissive THEN\n" + " E' (RESTRICTIVE)'\n" + " ELSE '' END\n" + " || CASE WHEN polcmd != '*' THEN\n" + " E' (' || polcmd::pg_catalog.text || E'):'\n" + " ELSE E':'\n" + " END\n" + " || CASE WHEN polqual IS NOT NULL THEN\n" + " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" + " ELSE E''\n" + " END\n" + " || CASE WHEN polwithcheck IS NOT NULL THEN\n" + " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" + " ELSE E''\n" + " END" + " || CASE WHEN polroles <> '{0}' THEN\n" + " E'\\n to: ' || pg_catalog.array_to_string(\n" + " ARRAY(\n" + " SELECT rolname\n" + " FROM pg_catalog.pg_roles\n" + " WHERE oid = ANY (polroles)\n" + " ORDER BY 1\n" + " ), E', ')\n" + " ELSE E''\n" + " END\n" + " FROM pg_catalog.pg_policy pol\n" + " WHERE polrelid = c.oid), E'\\n')\n" + " AS \"%s\"", + gettext_noop("Policies")); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_class c\n" " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n" @@ -1675,27 +1675,27 @@ describeOneTableDetails(const char *schemaname, char *footers[3] = {NULL, NULL, NULL}; printfPQExpBuffer(&buf, "/* %s */\n", _("Get sequence information")); - appendPQExpBuffer(&buf, - "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" - " seqstart AS \"%s\",\n" - " seqmin AS \"%s\",\n" - " seqmax AS \"%s\",\n" - " seqincrement AS \"%s\",\n" - " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" - " seqcache AS \"%s\"\n", - gettext_noop("Type"), - gettext_noop("Start"), - gettext_noop("Minimum"), - gettext_noop("Maximum"), - gettext_noop("Increment"), - gettext_noop("yes"), - gettext_noop("no"), - gettext_noop("Cycles?"), - gettext_noop("Cache")); - appendPQExpBuffer(&buf, - "FROM pg_catalog.pg_sequence\n" - "WHERE seqrelid = '%s';", - oid); + appendPQExpBuffer(&buf, + "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" + " seqstart AS \"%s\",\n" + " seqmin AS \"%s\",\n" + " seqmax AS \"%s\",\n" + " seqincrement AS \"%s\",\n" + " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" + " seqcache AS \"%s\"\n", + gettext_noop("Type"), + gettext_noop("Start"), + gettext_noop("Minimum"), + gettext_noop("Maximum"), + gettext_noop("Increment"), + gettext_noop("yes"), + gettext_noop("no"), + gettext_noop("Cycles?"), + gettext_noop("Cache")); + appendPQExpBuffer(&buf, + "FROM pg_catalog.pg_sequence\n" + "WHERE seqrelid = '%s';", + oid); res = PSQLexec(buf.data); if (!res) @@ -1913,7 +1913,7 @@ describeOneTableDetails(const char *schemaname, appendPQExpBufferStr(&buf, ",\n (SELECT c.collname FROM pg_catalog.pg_collation c, pg_catalog.pg_type t\n" " WHERE c.oid = a.attcollation AND t.oid = a.atttypid AND a.attcollation <> t.typcollation) AS attcollation"); attcoll_col = cols++; - appendPQExpBufferStr(&buf, ",\n a.attidentity"); + appendPQExpBufferStr(&buf, ",\n a.attidentity"); attidentity_col = cols++; if (pset.sversion >= 120000) appendPQExpBufferStr(&buf, ",\n a.attgenerated"); @@ -2326,7 +2326,7 @@ describeOneTableDetails(const char *schemaname, CppAsString2(CONSTRAINT_EXCLUSION) ") AND " "condeferred) AS condeferred,\n"); - appendPQExpBufferStr(&buf, "i.indisreplident,\n"); + appendPQExpBufferStr(&buf, "i.indisreplident,\n"); if (pset.sversion >= 150000) appendPQExpBufferStr(&buf, "i.indnullsnotdistinct,\n"); @@ -2431,7 +2431,7 @@ describeOneTableDetails(const char *schemaname, "pg_catalog.pg_get_indexdef(i.indexrelid, 0, true),\n " "pg_catalog.pg_get_constraintdef(con.oid, true), " "contype, condeferrable, condeferred"); - appendPQExpBufferStr(&buf, ", i.indisreplident"); + appendPQExpBufferStr(&buf, ", i.indisreplident"); appendPQExpBufferStr(&buf, ", c2.reltablespace"); if (pset.sversion >= 180000) appendPQExpBufferStr(&buf, ", con.conperiod"); @@ -2682,81 +2682,80 @@ describeOneTableDetails(const char *schemaname, PQclear(result); /* print any row-level policies */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get row-level policies for this table")); - appendPQExpBufferStr(&buf, "SELECT pol.polname,"); - appendPQExpBufferStr(&buf, - " pol.polpermissive,\n"); - appendPQExpBuffer(&buf, - " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" - " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" - " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" - " CASE pol.polcmd\n" - " WHEN 'r' THEN 'SELECT'\n" - " WHEN 'a' THEN 'INSERT'\n" - " WHEN 'w' THEN 'UPDATE'\n" - " WHEN 'd' THEN 'DELETE'\n" - " END AS cmd\n" - "FROM pg_catalog.pg_policy pol\n" - "WHERE pol.polrelid = '%s' ORDER BY 1;", - oid); + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get row-level policies for this table")); + appendPQExpBufferStr(&buf, "SELECT pol.polname,"); + appendPQExpBufferStr(&buf, + " pol.polpermissive,\n"); + appendPQExpBuffer(&buf, + " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" + " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" + " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" + " CASE pol.polcmd\n" + " WHEN 'r' THEN 'SELECT'\n" + " WHEN 'a' THEN 'INSERT'\n" + " WHEN 'w' THEN 'UPDATE'\n" + " WHEN 'd' THEN 'DELETE'\n" + " END AS cmd\n" + "FROM pg_catalog.pg_policy pol\n" + "WHERE pol.polrelid = '%s' ORDER BY 1;", + oid); - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - /* - * Handle cases where RLS is enabled and there are policies, or - * there aren't policies, or RLS isn't enabled but there are - * policies - */ - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies:")); + /* + * Handle cases where RLS is enabled and there are policies, or there + * aren't policies, or RLS isn't enabled but there are policies + */ + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies:")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled):")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled):")); - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); - if (!tableinfo.rowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (row security disabled):")); + if (!tableinfo.rowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (row security disabled):")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " POLICY \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " POLICY \"%s\"", + PQgetvalue(result, i, 0)); - if (*(PQgetvalue(result, i, 1)) == 'f') - appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); + if (*(PQgetvalue(result, i, 1)) == 'f') + appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); - if (!PQgetisnull(result, i, 5)) - appendPQExpBuffer(&buf, " FOR %s", - PQgetvalue(result, i, 5)); + if (!PQgetisnull(result, i, 5)) + appendPQExpBuffer(&buf, " FOR %s", + PQgetvalue(result, i, 5)); - if (!PQgetisnull(result, i, 2)) - { - appendPQExpBuffer(&buf, "\n TO %s", - PQgetvalue(result, i, 2)); - } + if (!PQgetisnull(result, i, 2)) + { + appendPQExpBuffer(&buf, "\n TO %s", + PQgetvalue(result, i, 2)); + } - if (!PQgetisnull(result, i, 3)) - appendPQExpBuffer(&buf, "\n USING (%s)", - PQgetvalue(result, i, 3)); + if (!PQgetisnull(result, i, 3)) + appendPQExpBuffer(&buf, "\n USING (%s)", + PQgetvalue(result, i, 3)); - if (!PQgetisnull(result, i, 4)) - appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", - PQgetvalue(result, i, 4)); + if (!PQgetisnull(result, i, 4)) + appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", + PQgetvalue(result, i, 4)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* print any extended statistics */ if (pset.sversion >= 140000) @@ -3025,115 +3024,115 @@ describeOneTableDetails(const char *schemaname, } /* print any publications */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get publications that publish this table")); - if (pset.sversion >= 150000) + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get publications that publish this table")); + if (pset.sversion >= 150000) + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" + " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" + "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" + "UNION\n" + "SELECT pubname\n" + " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" + " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" + " (SELECT pg_catalog.string_agg(attname, ', ')\n" + " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" + " pg_catalog.pg_attribute\n" + " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" + " ELSE NULL END) " + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" + "WHERE pr.prrelid = '%s'\n", + oid, oid, oid); + + if (pset.sversion >= 190000) { + /* + * Skip entries where this relation appears in the + * publication's EXCEPT list. + */ appendPQExpBuffer(&buf, + " AND NOT pr.prexcept\n" + "UNION\n" "SELECT pubname\n" " , NULL\n" " , NULL\n" "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" - " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" - "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" - "UNION\n" - "SELECT pubname\n" - " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" - " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" - " (SELECT pg_catalog.string_agg(attname, ', ')\n" - " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" - " pg_catalog.pg_attribute\n" - " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" - " ELSE NULL END) " - "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" - "WHERE pr.prrelid = '%s'\n", + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + " AND NOT EXISTS (\n" + " SELECT 1\n" + " FROM pg_catalog.pg_publication_rel pr\n" + " WHERE pr.prpubid = p.oid AND\n" + " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" + "ORDER BY 1;", oid, oid, oid); - - if (pset.sversion >= 190000) - { - /* - * Skip entries where this relation appears in the - * publication's EXCEPT list. - */ - appendPQExpBuffer(&buf, - " AND NOT pr.prexcept\n" - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - " AND NOT EXISTS (\n" - " SELECT 1\n" - " FROM pg_catalog.pg_publication_rel pr\n" - " WHERE pr.prpubid = p.oid AND\n" - " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" - "ORDER BY 1;", - oid, oid, oid); - } - else - { - appendPQExpBuffer(&buf, - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - "ORDER BY 1;", - oid); - } } else { appendPQExpBuffer(&buf, + "UNION\n" "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - "WHERE pr.prrelid = '%s'\n" - "UNION ALL\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" + " , NULL\n" + " , NULL\n" "FROM pg_catalog.pg_publication p\n" "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" "ORDER BY 1;", - oid, oid); + oid); } + } + else + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + "WHERE pr.prrelid = '%s'\n" + "UNION ALL\n" + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + "ORDER BY 1;", + oid, oid); + } - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - if (tuples > 0) - printTableAddFooter(&cont, _("Included in publications:")); + if (tuples > 0) + printTableAddFooter(&cont, _("Included in publications:")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " \"%s\"", + PQgetvalue(result, i, 0)); - /* column list (if any) */ - if (!PQgetisnull(result, i, 2)) - appendPQExpBuffer(&buf, " (%s)", - PQgetvalue(result, i, 2)); + /* column list (if any) */ + if (!PQgetisnull(result, i, 2)) + appendPQExpBuffer(&buf, " (%s)", + PQgetvalue(result, i, 2)); - /* row filter (if any) */ - if (!PQgetisnull(result, i, 1)) - appendPQExpBuffer(&buf, " WHERE %s", - PQgetvalue(result, i, 1)); + /* row filter (if any) */ + if (!PQgetisnull(result, i, 1)) + appendPQExpBuffer(&buf, " WHERE %s", + PQgetvalue(result, i, 1)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* Print publications where the table is in the EXCEPT clause */ if (pset.sversion >= 190000) @@ -3805,7 +3804,7 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) ncols++; } appendPQExpBufferStr(&buf, "\n, r.rolreplication"); - appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); + appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_roles r\n"); @@ -3860,8 +3859,8 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) if (strcmp(PQgetvalue(res, i, (verbose ? 9 : 8)), "t") == 0) add_role_attribute(&buf, _("Replication")); - if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) - add_role_attribute(&buf, _("Bypass RLS")); + if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) + add_role_attribute(&buf, _("Bypass RLS")); conns = atoi(PQgetvalue(res, i, 6)); if (conns >= 0) @@ -5155,14 +5154,14 @@ listCollations(const char *pattern, bool verbose, bool showSystem) gettext_noop("Schema"), gettext_noop("Name")); - appendPQExpBuffer(&buf, - " CASE c.collprovider " - "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " - "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " - "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " - "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " - "END AS \"%s\",\n", - gettext_noop("Provider")); + appendPQExpBuffer(&buf, + " CASE c.collprovider " + "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " + "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " + "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " + "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " + "END AS \"%s\",\n", + gettext_noop("Provider")); appendPQExpBuffer(&buf, " c.collcollate AS \"%s\",\n" -- 2.50.1 (Apple Git-155) --aHl3HfeiUuO3zeNC-- ^ permalink raw reply [nested|flat] 59+ messages in thread
* [PATCH v6 4/4] run pgindent and pgperltidy @ 2026-06-30 18:24 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 59+ messages in thread From: Nathan Bossart @ 2026-06-30 18:24 UTC (permalink / raw) --- src/bin/pg_dump/pg_dump.c | 464 ++++++++++----------- src/bin/pg_dump/pg_dumpall.c | 30 +- src/bin/pg_upgrade/check.c | 16 +- src/bin/pg_upgrade/controldata.c | 2 +- src/bin/pg_upgrade/exec.c | 8 +- src/bin/pg_upgrade/multixact_rewrite.c | 80 ++-- src/bin/pg_upgrade/pg_upgrade.c | 34 +- src/bin/pg_upgrade/relfilenumber.c | 54 +-- src/bin/pg_upgrade/t/006_transfer_modes.pl | 33 +- src/bin/psql/command.c | 29 +- src/bin/psql/describe.c | 461 ++++++++++---------- 11 files changed, 601 insertions(+), 610 deletions(-) diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 65bd15ebfd2..5673268b467 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -1491,8 +1491,8 @@ setup_connection(Archive *AH, const char *dumpencoding, * Disable timeouts if supported. */ ExecuteSqlStatement(AH, "SET statement_timeout = 0"); - ExecuteSqlStatement(AH, "SET lock_timeout = 0"); - ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); + ExecuteSqlStatement(AH, "SET lock_timeout = 0"); + ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); if (AH->remoteVersion >= 170000) ExecuteSqlStatement(AH, "SET transaction_timeout = 0"); @@ -1505,10 +1505,10 @@ setup_connection(Archive *AH, const char *dumpencoding, /* * Adjust row-security mode, if supported. */ - if (dopt->enable_row_security) - ExecuteSqlStatement(AH, "SET row_security = on"); - else - ExecuteSqlStatement(AH, "SET row_security = off"); + if (dopt->enable_row_security) + ExecuteSqlStatement(AH, "SET row_security = on"); + else + ExecuteSqlStatement(AH, "SET row_security = off"); /* * For security reasons, we restrict the expansion of non-system views and @@ -1933,10 +1933,9 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) addObjectDependency(dobj, ext->dobj.dumpId); /* - * Mark the member object to have any non-initial ACLs - * dumped. (Any initial ACLs will be removed later, using data from - * pg_init_privs, so that we'll dump only the delta from the extension's - * initial setup.) + * Mark the member object to have any non-initial ACLs dumped. (Any + * initial ACLs will be removed later, using data from pg_init_privs, so + * that we'll dump only the delta from the extension's initial setup.) * * In binary upgrades, we still dump all components of the members * individually, since the idea is to exactly reproduce the database @@ -1953,7 +1952,7 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) if (fout->dopt->binary_upgrade) dobj->dump = ext->dobj.dump; else - dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); + dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); return true; } @@ -1987,9 +1986,9 @@ selectDumpableNamespace(NamespaceInfo *nsinfo, Archive *fout) else if (strcmp(nsinfo->dobj.name, "pg_catalog") == 0) { /* - * We dump out any ACLs defined in pg_catalog, if - * they are interesting (and not the original ACLs which were set at - * initdb time, see pg_init_privs). + * We dump out any ACLs defined in pg_catalog, if they are interesting + * (and not the original ACLs which were set at initdb time, see + * pg_init_privs). */ nsinfo->dobj.dump_contains = nsinfo->dobj.dump = DUMP_COMPONENT_ACL; } @@ -3296,7 +3295,7 @@ dumpDatabase(Archive *fout) "datcollate, datctype, datfrozenxid, " "datacl, acldefault('d', datdba) AS acldefault, " "datistemplate, datconnlimit, "); - appendPQExpBufferStr(dbQry, "datminmxid, "); + appendPQExpBufferStr(dbQry, "datminmxid, "); if (fout->remoteVersion >= 170000) appendPQExpBufferStr(dbQry, "datlocprovider, datlocale, datcollversion, "); else if (fout->remoteVersion >= 150000) @@ -3638,11 +3637,11 @@ dumpDatabase(Archive *fout) ii_oid, ii_relminmxid; - appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" - "FROM pg_catalog.pg_class\n" - "WHERE oid IN (%u, %u, %u, %u);\n", - LargeObjectRelationId, LargeObjectLOidPNIndexId, - LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); + appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" + "FROM pg_catalog.pg_class\n" + "WHERE oid IN (%u, %u, %u, %u);\n", + LargeObjectRelationId, LargeObjectLOidPNIndexId, + LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); lo_res = ExecuteSqlQuery(fout, loFrozenQry->data, PGRES_TUPLES_OK); @@ -4274,7 +4273,7 @@ getPolicies(Archive *fout, TableInfo tblinfo[], int numTables) printfPQExpBuffer(query, "SELECT pol.oid, pol.tableoid, pol.polrelid, pol.polname, pol.polcmd, "); - appendPQExpBufferStr(query, "pol.polpermissive, "); + appendPQExpBufferStr(query, "pol.polpermissive, "); appendPQExpBuffer(query, "CASE WHEN pol.polroles = '{0}' THEN NULL ELSE " " pg_catalog.array_to_string(ARRAY(SELECT pg_catalog.quote_ident(rolname) from pg_catalog.pg_roles WHERE oid = ANY(pol.polroles)), ', ') END AS polroles, " @@ -6633,9 +6632,9 @@ getAccessMethods(Archive *fout) * Select all access methods from pg_am table. */ appendPQExpBufferStr(query, "SELECT tableoid, oid, amname, "); - appendPQExpBufferStr(query, - "amtype, " - "amhandler::pg_catalog.regproc AS amhandler "); + appendPQExpBufferStr(query, + "amtype, " + "amhandler::pg_catalog.regproc AS amhandler "); appendPQExpBufferStr(query, "FROM pg_am"); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6827,35 +6826,35 @@ getAggregates(Archive *fout) * Find all interesting aggregates. See comment in getFuncs() for the * rationale behind the filtering logic. */ - agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" - : "p.proisagg"); + agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" + : "p.proisagg"); - appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " - "p.proname AS aggname, " - "p.pronamespace AS aggnamespace, " - "p.pronargs, p.proargtypes, " - "p.proowner, " - "p.proacl AS aggacl, " - "acldefault('f', p.proowner) AS acldefault " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s AND (" - "p.pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog') OR " - "p.proacl IS DISTINCT FROM pip.initprivs", - agg_check); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - " OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); - appendPQExpBufferChar(query, ')'); + appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " + "p.proname AS aggname, " + "p.pronamespace AS aggnamespace, " + "p.pronargs, p.proargtypes, " + "p.proowner, " + "p.proacl AS aggacl, " + "acldefault('f', p.proowner) AS acldefault " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s AND (" + "p.pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog') OR " + "p.proacl IS DISTINCT FROM pip.initprivs", + agg_check); + if (dopt->binary_upgrade) + appendPQExpBufferStr(query, + " OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6957,53 +6956,53 @@ getFuncs(Archive *fout) * include them, since we want to dump extension members individually in * that mode. Also, if they are used by casts or transforms then we need * to gather the information about them, though they won't be dumped if - * they are built-in. Also, include functions in - * pg_catalog if they have an ACL different from what's shown in - * pg_init_privs (so we have to join to pg_init_privs; annoying). + * they are built-in. Also, include functions in pg_catalog if they have + * an ACL different from what's shown in pg_init_privs (so we have to join + * to pg_init_privs; annoying). */ - not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" - : "NOT p.proisagg"); + not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" + : "NOT p.proisagg"); - appendPQExpBuffer(query, - "SELECT p.tableoid, p.oid, p.proname, p.prolang, " - "p.pronargs, p.proargtypes, p.prorettype, " - "p.proacl, " - "acldefault('f', p.proowner) AS acldefault, " - "p.pronamespace, " - "p.proowner " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s" - "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " - "WHERE classid = 'pg_proc'::regclass AND " - "objid = p.oid AND deptype = 'i')" - "\n AND (" - "\n pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog')" - "\n OR EXISTS (SELECT 1 FROM pg_cast" - "\n WHERE pg_cast.oid > %u " - "\n AND p.oid = pg_cast.castfunc)" - "\n OR EXISTS (SELECT 1 FROM pg_transform" - "\n WHERE pg_transform.oid > %u AND " - "\n (p.oid = pg_transform.trffromsql" - "\n OR p.oid = pg_transform.trftosql))", - not_agg_check, - g_last_builtin_oid, - g_last_builtin_oid); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); + appendPQExpBuffer(query, + "SELECT p.tableoid, p.oid, p.proname, p.prolang, " + "p.pronargs, p.proargtypes, p.prorettype, " + "p.proacl, " + "acldefault('f', p.proowner) AS acldefault, " + "p.pronamespace, " + "p.proowner " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s" + "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " + "WHERE classid = 'pg_proc'::regclass AND " + "objid = p.oid AND deptype = 'i')" + "\n AND (" + "\n pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog')" + "\n OR EXISTS (SELECT 1 FROM pg_cast" + "\n WHERE pg_cast.oid > %u " + "\n AND p.oid = pg_cast.castfunc)" + "\n OR EXISTS (SELECT 1 FROM pg_transform" + "\n WHERE pg_transform.oid > %u AND " + "\n (p.oid = pg_transform.trffromsql" + "\n OR p.oid = pg_transform.trftosql))", + not_agg_check, + g_last_builtin_oid, + g_last_builtin_oid); + if (dopt->binary_upgrade) appendPQExpBufferStr(query, - "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); - appendPQExpBufferChar(query, ')'); + "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferStr(query, + "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -7252,31 +7251,31 @@ getTables(Archive *fout, int *numTables) appendPQExpBufferStr(query, "c.relhasoids, "); - appendPQExpBufferStr(query, - "c.relispopulated, "); + appendPQExpBufferStr(query, + "c.relispopulated, "); - appendPQExpBufferStr(query, - "c.relreplident, "); + appendPQExpBufferStr(query, + "c.relreplident, "); - appendPQExpBufferStr(query, - "c.relrowsecurity, c.relforcerowsecurity, "); + appendPQExpBufferStr(query, + "c.relrowsecurity, c.relforcerowsecurity, "); - appendPQExpBufferStr(query, - "c.relminmxid, tc.relminmxid AS tminmxid, "); + appendPQExpBufferStr(query, + "c.relminmxid, tc.relminmxid AS tminmxid, "); - appendPQExpBufferStr(query, - "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); + appendPQExpBufferStr(query, + "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); - appendPQExpBufferStr(query, - "am.amname, "); + appendPQExpBufferStr(query, + "am.amname, "); - appendPQExpBufferStr(query, - "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); + appendPQExpBufferStr(query, + "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); - appendPQExpBufferStr(query, - "c.relispartition AS ispartition "); + appendPQExpBufferStr(query, + "c.relispartition AS ispartition "); /* * Left join to pg_depend to pick up dependency info linking sequences to @@ -7296,8 +7295,8 @@ getTables(Archive *fout, int *numTables) /* * Left join to pg_am to pick up the amname. */ - appendPQExpBufferStr(query, - "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); + appendPQExpBufferStr(query, + "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); /* * We purposefully ignore toast OIDs for partitioned tables; the reason is @@ -7868,8 +7867,8 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables) "t.reloptions AS indreloptions, "); - appendPQExpBufferStr(query, - "i.indisreplident, "); + appendPQExpBufferStr(query, + "i.indisreplident, "); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -9313,8 +9312,8 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables) appendPQExpBufferStr(q, "'' AS attcompression,\n"); - appendPQExpBufferStr(q, - "a.attidentity,\n"); + appendPQExpBufferStr(q, + "a.attidentity,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(q, @@ -10717,73 +10716,73 @@ getAdditionalACLs(Archive *fout) PQclear(res); /* Fetch initial-privileges data */ - printfPQExpBuffer(query, - "SELECT objoid, classoid, objsubid, privtype, initprivs " - "FROM pg_init_privs"); + printfPQExpBuffer(query, + "SELECT objoid, classoid, objsubid, privtype, initprivs " + "FROM pg_init_privs"); - res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); + res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); - ntups = PQntuples(res); - for (i = 0; i < ntups; i++) - { - Oid objoid = atooid(PQgetvalue(res, i, 0)); - Oid classoid = atooid(PQgetvalue(res, i, 1)); - int objsubid = atoi(PQgetvalue(res, i, 2)); - char privtype = *(PQgetvalue(res, i, 3)); - char *initprivs = PQgetvalue(res, i, 4); - CatalogId objId; - DumpableObject *dobj; + ntups = PQntuples(res); + for (i = 0; i < ntups; i++) + { + Oid objoid = atooid(PQgetvalue(res, i, 0)); + Oid classoid = atooid(PQgetvalue(res, i, 1)); + int objsubid = atoi(PQgetvalue(res, i, 2)); + char privtype = *(PQgetvalue(res, i, 3)); + char *initprivs = PQgetvalue(res, i, 4); + CatalogId objId; + DumpableObject *dobj; - objId.tableoid = classoid; - objId.oid = objoid; - dobj = findObjectByCatalogId(objId); - /* OK to ignore entries we haven't got a DumpableObject for */ - if (dobj) + objId.tableoid = classoid; + objId.oid = objoid; + dobj = findObjectByCatalogId(objId); + /* OK to ignore entries we haven't got a DumpableObject for */ + if (dobj) + { + /* Cope with sub-object initprivs */ + if (objsubid != 0) { - /* Cope with sub-object initprivs */ - if (objsubid != 0) - { - if (dobj->objType == DO_TABLE) - { - /* For a column initprivs, set the table's ACL flags */ - dobj->components |= DUMP_COMPONENT_ACL; - ((TableInfo *) dobj)->hascolumnACLs = true; - } - else - pg_log_warning("unsupported pg_init_privs entry: %u %u %d", - classoid, objoid, objsubid); - continue; - } - - /* - * We ignore any pg_init_privs.initprivs entry for the public - * schema, as explained in getNamespaces(). - */ - if (dobj->objType == DO_NAMESPACE && - strcmp(dobj->name, "public") == 0) - continue; - - /* Else it had better be of a type we think has ACLs */ - if (dobj->objType == DO_NAMESPACE || - dobj->objType == DO_TYPE || - dobj->objType == DO_FUNC || - dobj->objType == DO_AGG || - dobj->objType == DO_TABLE || - dobj->objType == DO_PROCLANG || - dobj->objType == DO_FDW || - dobj->objType == DO_FOREIGN_SERVER) + if (dobj->objType == DO_TABLE) { - DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; - - daobj->dacl.privtype = privtype; - daobj->dacl.initprivs = pstrdup(initprivs); + /* For a column initprivs, set the table's ACL flags */ + dobj->components |= DUMP_COMPONENT_ACL; + ((TableInfo *) dobj)->hascolumnACLs = true; } else pg_log_warning("unsupported pg_init_privs entry: %u %u %d", classoid, objoid, objsubid); + continue; + } + + /* + * We ignore any pg_init_privs.initprivs entry for the public + * schema, as explained in getNamespaces(). + */ + if (dobj->objType == DO_NAMESPACE && + strcmp(dobj->name, "public") == 0) + continue; + + /* Else it had better be of a type we think has ACLs */ + if (dobj->objType == DO_NAMESPACE || + dobj->objType == DO_TYPE || + dobj->objType == DO_FUNC || + dobj->objType == DO_AGG || + dobj->objType == DO_TABLE || + dobj->objType == DO_PROCLANG || + dobj->objType == DO_FDW || + dobj->objType == DO_FOREIGN_SERVER) + { + DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; + + daobj->dacl.privtype = privtype; + daobj->dacl.initprivs = pstrdup(initprivs); } + else + pg_log_warning("unsupported pg_init_privs entry: %u %u %d", + classoid, objoid, objsubid); } - PQclear(res); + } + PQclear(res); destroyPQExpBuffer(query); } @@ -11128,8 +11127,8 @@ dumpRelationStats_dumper(Archive *fout, const void *userArg, const TocEntry *te) * The results must be in the order of the relations supplied in the * parameters to ensure we remain in sync as we walk through the TOC. * - * For versions before 19, the redundant filter clause on s.tablename = - * ANY(...) seems sufficient to convince the planner to use + * For versions before 19, the redundant filter clause on s.tablename + * = ANY(...) seems sufficient to convince the planner to use * pg_class_relname_nsp_index, which avoids a full scan of pg_stats. * In newer versions, pg_stats returns the table OIDs, eliminating the * need for that hack. @@ -13469,11 +13468,11 @@ dumpFunc(Archive *fout, const FuncInfo *finfo) "pg_catalog.pg_get_function_result(p.oid) AS funcresult,\n" "proleakproof,\n"); - appendPQExpBufferStr(query, - "array_to_string(protrftypes, ' ') AS protrftypes,\n"); + appendPQExpBufferStr(query, + "array_to_string(protrftypes, ' ') AS protrftypes,\n"); - appendPQExpBufferStr(query, - "proparallel,\n"); + appendPQExpBufferStr(query, + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -14963,9 +14962,9 @@ dumpCollation(Archive *fout, const CollInfo *collinfo) /* Get collation-specific details */ appendPQExpBufferStr(query, "SELECT "); - appendPQExpBufferStr(query, - "collprovider, " - "collversion, "); + appendPQExpBufferStr(query, + "collprovider, " + "collversion, "); if (fout->remoteVersion >= 120000) appendPQExpBufferStr(query, @@ -15372,23 +15371,23 @@ dumpAgg(Archive *fout, const AggInfo *agginfo) "pg_catalog.pg_get_function_arguments(p.oid) AS funcargs,\n" "pg_catalog.pg_get_function_identity_arguments(p.oid) AS funciargs,\n"); - appendPQExpBufferStr(query, - "aggkind,\n" - "aggmtransfn,\n" - "aggminvtransfn,\n" - "aggmfinalfn,\n" - "aggmtranstype::pg_catalog.regtype,\n" - "aggfinalextra,\n" - "aggmfinalextra,\n" - "aggtransspace,\n" - "aggmtransspace,\n" - "aggminitval,\n"); + appendPQExpBufferStr(query, + "aggkind,\n" + "aggmtransfn,\n" + "aggminvtransfn,\n" + "aggmfinalfn,\n" + "aggmtranstype::pg_catalog.regtype,\n" + "aggfinalextra,\n" + "aggmfinalextra,\n" + "aggtransspace,\n" + "aggmtransspace,\n" + "aggminitval,\n"); - appendPQExpBufferStr(query, - "aggcombinefn,\n" - "aggserialfn,\n" - "aggdeserialfn,\n" - "proparallel,\n"); + appendPQExpBufferStr(query, + "aggcombinefn,\n" + "aggserialfn,\n" + "aggdeserialfn,\n" + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -16848,30 +16847,30 @@ dumpTable(Archive *fout, const TableInfo *tbinfo) appendPQExpBufferStr(query, "PREPARE getColumnACLs(pg_catalog.oid) AS\n"); - /* - * In principle we should call acldefault('c', relowner) to - * get the default ACL for a column. However, we don't - * currently store the numeric OID of the relowner in - * TableInfo. We could convert the owner name using regrole, - * but that creates a risk of failure due to concurrent role - * renames. Given that the default ACL for columns is empty - * and is likely to stay that way, it's not worth extra cycles - * and risk to avoid hard-wiring that knowledge here. - */ - appendPQExpBufferStr(query, - "SELECT at.attname, " - "at.attacl, " - "'{}' AS acldefault, " - "pip.privtype, pip.initprivs " - "FROM pg_catalog.pg_attribute at " - "LEFT JOIN pg_catalog.pg_init_privs pip ON " - "(at.attrelid = pip.objoid " - "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " - "AND at.attnum = pip.objsubid) " - "WHERE at.attrelid = $1 AND " - "NOT at.attisdropped " - "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " - "ORDER BY at.attnum"); + /* + * In principle we should call acldefault('c', relowner) to get + * the default ACL for a column. However, we don't currently + * store the numeric OID of the relowner in TableInfo. We could + * convert the owner name using regrole, but that creates a risk + * of failure due to concurrent role renames. Given that the + * default ACL for columns is empty and is likely to stay that + * way, it's not worth extra cycles and risk to avoid hard-wiring + * that knowledge here. + */ + appendPQExpBufferStr(query, + "SELECT at.attname, " + "at.attacl, " + "'{}' AS acldefault, " + "pip.privtype, pip.initprivs " + "FROM pg_catalog.pg_attribute at " + "LEFT JOIN pg_catalog.pg_init_privs pip ON " + "(at.attrelid = pip.objoid " + "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " + "AND at.attnum = pip.objsubid) " + "WHERE at.attrelid = $1 AND " + "NOT at.attisdropped " + "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " + "ORDER BY at.attnum"); ExecuteSqlStatement(fout, query->data); @@ -19165,7 +19164,7 @@ collectSequences(Archive *fout) * pg_get_sequence_data(), but we only do so for non-schema-only dumps. */ if (fout->remoteVersion < 180000 || - (!fout->dopt->dumpData && !fout->dopt->sequence_data)) + (!fout->dopt->dumpData && !fout->dopt->sequence_data)) query = "SELECT seqrelid, format_type(seqtypid, NULL), " "seqstart, seqincrement, " "seqmax, seqmin, " @@ -19227,15 +19226,14 @@ dumpSequence(Archive *fout, const TableInfo *tbinfo) qseqname = pg_strdup(fmtId(tbinfo->dobj.name)); /* - * The sequence information is gathered in a sorted - * table before any calls to dumpSequence(). See collectSequences() for - * more information. + * The sequence information is gathered in a sorted table before any calls + * to dumpSequence(). See collectSequences() for more information. */ - Assert(sequences); + Assert(sequences); - key.oid = tbinfo->dobj.catId.oid; - seq = bsearch(&key, sequences, nsequences, - sizeof(SequenceItem), SequenceItemCmp); + key.oid = tbinfo->dobj.catId.oid; + seq = bsearch(&key, sequences, nsequences, + sizeof(SequenceItem), SequenceItemCmp); /* Calculate default limits for a sequence of this type */ is_ascending = (seq->incby >= 0); diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c index e68937c9934..afcd9a218d8 100644 --- a/src/bin/pg_dump/pg_dumpall.c +++ b/src/bin/pg_dump/pg_dumpall.c @@ -785,11 +785,11 @@ dropRoles(PGconn *conn) int i_rolname; int i; - printfPQExpBuffer(buf, - "SELECT rolname " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 1", role_catalog); + printfPQExpBuffer(buf, + "SELECT rolname " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 1", role_catalog); res = executeQuery(conn, buf->data); @@ -843,16 +843,16 @@ dumpRoles(PGconn *conn) * Notes: rolconfig is dumped later, and pg_authid must be used for * extracting rolcomment regardless of role_catalog. */ - printfPQExpBuffer(buf, - "SELECT oid, rolname, rolsuper, rolinherit, " - "rolcreaterole, rolcreatedb, " - "rolcanlogin, rolconnlimit, rolpassword, " - "rolvaliduntil, rolreplication, rolbypassrls, " - "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " - "rolname = current_user AS is_current_user " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 2", role_catalog); + printfPQExpBuffer(buf, + "SELECT oid, rolname, rolsuper, rolinherit, " + "rolcreaterole, rolcreatedb, " + "rolcanlogin, rolconnlimit, rolpassword, " + "rolvaliduntil, rolreplication, rolbypassrls, " + "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " + "rolname = current_user AS is_current_user " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 2", role_catalog); res = executeQuery(conn, buf->data); diff --git a/src/bin/pg_upgrade/check.c b/src/bin/pg_upgrade/check.c index 786c1474829..f725f5ee3e2 100644 --- a/src/bin/pg_upgrade/check.c +++ b/src/bin/pg_upgrade/check.c @@ -1475,15 +1475,15 @@ check_for_incompatible_polymorphics(ClusterInfo *cluster) ", 'array_cat(anyarray,anyarray)'" ", 'array_prepend(anyelement,anyarray)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_remove(anyarray,anyelement)'" - ", 'array_replace(anyarray,anyelement,anyelement)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_remove(anyarray,anyelement)'" + ", 'array_replace(anyarray,anyelement,anyelement)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_position(anyarray,anyelement)'" - ", 'array_position(anyarray,anyelement,integer)'" - ", 'array_positions(anyarray,anyelement)'" - ", 'width_bucket(anyelement,anyarray)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_position(anyarray,anyelement)'" + ", 'array_position(anyarray,anyelement,integer)'" + ", 'array_positions(anyarray,anyelement)'" + ", 'width_bucket(anyelement,anyarray)'"); /* * The query below hardcodes FirstNormalObjectId as 16384 rather than diff --git a/src/bin/pg_upgrade/controldata.c b/src/bin/pg_upgrade/controldata.c index 8f81c9e9582..02ea02df60f 100644 --- a/src/bin/pg_upgrade/controldata.c +++ b/src/bin/pg_upgrade/controldata.c @@ -228,7 +228,7 @@ get_control_data(ClusterInfo *cluster) p++; /* remove ':' char */ cluster->controldata.chkpnt_nxtepoch = str2uint(p); - p = strchr(p, ':'); + p = strchr(p, ':'); if (p == NULL || strlen(p) <= 1) pg_fatal("%d: controldata retrieval problem", __LINE__); diff --git a/src/bin/pg_upgrade/exec.c b/src/bin/pg_upgrade/exec.c index 44355feea30..a1bdbf373e3 100644 --- a/src/bin/pg_upgrade/exec.c +++ b/src/bin/pg_upgrade/exec.c @@ -55,7 +55,7 @@ get_bin_version(ClusterInfo *cluster) if (sscanf(cmd_output, "%*s %*s %d.%d", &v1, &v2) < 1) pg_fatal("could not get pg_ctl version output from %s", cmd); - cluster->bin_version = v1 * 10000; + cluster->bin_version = v1 * 10000; } @@ -344,8 +344,8 @@ check_data_dir(ClusterInfo *cluster) check_single_dir(pg_data, "pg_subtrans"); check_single_dir(pg_data, PG_TBLSPC_DIR); check_single_dir(pg_data, "pg_twophase"); - check_single_dir(pg_data, "pg_wal"); - check_single_dir(pg_data, "pg_xact"); + check_single_dir(pg_data, "pg_wal"); + check_single_dir(pg_data, "pg_xact"); } @@ -385,7 +385,7 @@ check_bin_dir(ClusterInfo *cluster, bool check_versions) */ get_bin_version(cluster); - check_exec(cluster->bindir, "pg_resetwal", check_versions); + check_exec(cluster->bindir, "pg_resetwal", check_versions); if (cluster == &new_cluster) { diff --git a/src/bin/pg_upgrade/multixact_rewrite.c b/src/bin/pg_upgrade/multixact_rewrite.c index c45b3183684..c7a1416494d 100644 --- a/src/bin/pg_upgrade/multixact_rewrite.c +++ b/src/bin/pg_upgrade/multixact_rewrite.c @@ -61,52 +61,52 @@ rewrite_multixacts(MultiXactId from_multi, MultiXactId to_multi) * Convert old multixids, if needed, by reading them one-by-one from the * old cluster. */ - old_reader = AllocOldMultiXactRead(old_cluster.pgdata, - old_cluster.controldata.chkpnt_nxtmulti, - old_cluster.controldata.chkpnt_nxtmxoff); + old_reader = AllocOldMultiXactRead(old_cluster.pgdata, + old_cluster.controldata.chkpnt_nxtmulti, + old_cluster.controldata.chkpnt_nxtmxoff); - for (MultiXactId multi = from_multi; multi != to_multi;) - { - MultiXactMember member; - bool multixid_valid; - - /* - * Read this multixid's members. - * - * Locking-only XIDs that may be part of multi-xids don't matter - * after upgrade, as there can be no transactions running across - * upgrade. So as a small optimization, we only read one member - * from each multixid: the one updating one, or if there was no - * update, arbitrarily the first locking xid. - */ - multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); + for (MultiXactId multi = from_multi; multi != to_multi;) + { + MultiXactMember member; + bool multixid_valid; - /* - * Write the new offset to pg_multixact/offsets. - * - * Even if this multixid is invalid, we still need to write its - * offset if the *previous* multixid was valid. That's because - * when reading a multixid, the number of members is calculated - * from the difference between the two offsets. - */ - RecordMultiXactOffset(offsets_writer, multi, - (multixid_valid || prev_multixid_valid) ? next_offset : 0); + /* + * Read this multixid's members. + * + * Locking-only XIDs that may be part of multi-xids don't matter after + * upgrade, as there can be no transactions running across upgrade. So + * as a small optimization, we only read one member from each + * multixid: the one updating one, or if there was no update, + * arbitrarily the first locking xid. + */ + multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); - /* Write the members */ - if (multixid_valid) - { - RecordMultiXactMembers(members_writer, next_offset, 1, &member); - next_offset += 1; - } + /* + * Write the new offset to pg_multixact/offsets. + * + * Even if this multixid is invalid, we still need to write its offset + * if the *previous* multixid was valid. That's because when reading + * a multixid, the number of members is calculated from the difference + * between the two offsets. + */ + RecordMultiXactOffset(offsets_writer, multi, + (multixid_valid || prev_multixid_valid) ? next_offset : 0); - /* Advance to next multixid, handling wraparound */ - multi++; - if (multi < FirstMultiXactId) - multi = FirstMultiXactId; - prev_multixid_valid = multixid_valid; + /* Write the members */ + if (multixid_valid) + { + RecordMultiXactMembers(members_writer, next_offset, 1, &member); + next_offset += 1; } - FreeOldMultiXactReader(old_reader); + /* Advance to next multixid, handling wraparound */ + multi++; + if (multi < FirstMultiXactId) + multi = FirstMultiXactId; + prev_multixid_valid = multixid_valid; + } + + FreeOldMultiXactReader(old_reader); /* Write the final 'next' offset to the last SLRU page */ RecordMultiXactOffset(offsets_writer, to_multi, diff --git a/src/bin/pg_upgrade/pg_upgrade.c b/src/bin/pg_upgrade/pg_upgrade.c index c6af9035665..7366fd4627c 100644 --- a/src/bin/pg_upgrade/pg_upgrade.c +++ b/src/bin/pg_upgrade/pg_upgrade.c @@ -833,7 +833,7 @@ copy_xact_xlog_xid(void) * Determine the range of multixacts to convert. */ nxtmulti = old_cluster.controldata.chkpnt_nxtmulti; - oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; + oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; /* handle wraparound */ if (nxtmulti < FirstMultiXactId) nxtmulti = FirstMultiXactId; @@ -898,15 +898,15 @@ set_frozenxids(void) int i_datname; int i_datallowconn; - prep_status("Setting frozenxid and minmxid counters in new cluster"); + prep_status("Setting frozenxid and minmxid counters in new cluster"); conn_template1 = connectToServer(&new_cluster, "template1"); - /* set pg_database.datfrozenxid */ - PQclear(executeQueryOrDie(conn_template1, - "UPDATE pg_catalog.pg_database " - "SET datfrozenxid = '%u'", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_database.datfrozenxid */ + PQclear(executeQueryOrDie(conn_template1, + "UPDATE pg_catalog.pg_database " + "SET datfrozenxid = '%u'", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_database.datminmxid */ PQclear(executeQueryOrDie(conn_template1, @@ -942,16 +942,16 @@ set_frozenxids(void) conn = connectToServer(&new_cluster, datname); - /* set pg_class.relfrozenxid */ - PQclear(executeQueryOrDie(conn, - "UPDATE pg_catalog.pg_class " - "SET relfrozenxid = '%u' " - /* only heap, materialized view, and TOAST are vacuumed */ - "WHERE relkind IN (" - CppAsString2(RELKIND_RELATION) ", " - CppAsString2(RELKIND_MATVIEW) ", " - CppAsString2(RELKIND_TOASTVALUE) ")", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_class.relfrozenxid */ + PQclear(executeQueryOrDie(conn, + "UPDATE pg_catalog.pg_class " + "SET relfrozenxid = '%u' " + /* only heap, materialized view, and TOAST are vacuumed */ + "WHERE relkind IN (" + CppAsString2(RELKIND_RELATION) ", " + CppAsString2(RELKIND_MATVIEW) ", " + CppAsString2(RELKIND_TOASTVALUE) ")", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_class.relminmxid */ PQclear(executeQueryOrDie(conn, diff --git a/src/bin/pg_upgrade/relfilenumber.c b/src/bin/pg_upgrade/relfilenumber.c index ec2ff7acb21..6c467bdc8a5 100644 --- a/src/bin/pg_upgrade/relfilenumber.c +++ b/src/bin/pg_upgrade/relfilenumber.c @@ -587,32 +587,32 @@ transfer_relfile(FileNameMap *map, const char *type_suffix) /* Copying files might take some time, so give feedback. */ pg_log(PG_STATUS, "%s", old_file); - switch (user_opts.transfer_mode) - { - case TRANSFER_MODE_CLONE: - pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", - old_file, new_file); - cloneFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", - old_file, new_file); - copyFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY_FILE_RANGE: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", - old_file, new_file); - copyFileByRange(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_LINK: - pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", - old_file, new_file); - linkFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_SWAP: - /* swap mode is handled in its own code path */ - pg_fatal("should never happen"); - break; - } + switch (user_opts.transfer_mode) + { + case TRANSFER_MODE_CLONE: + pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", + old_file, new_file); + cloneFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", + old_file, new_file); + copyFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY_FILE_RANGE: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", + old_file, new_file); + copyFileByRange(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_LINK: + pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", + old_file, new_file); + linkFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_SWAP: + /* swap mode is handled in its own code path */ + pg_fatal("should never happen"); + break; + } } } diff --git a/src/bin/pg_upgrade/t/006_transfer_modes.pl b/src/bin/pg_upgrade/t/006_transfer_modes.pl index 9efa5dc863c..360d05c4b68 100644 --- a/src/bin/pg_upgrade/t/006_transfer_modes.pl +++ b/src/bin/pg_upgrade/t/006_transfer_modes.pl @@ -29,10 +29,8 @@ sub test_mode } $new->init(); - $new->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); - $old->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); + $new->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); + $old->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); # We can only test security labels if both the old and new installations # have dummy_seclabel. @@ -76,15 +74,14 @@ sub test_mode "CREATE TABLE test4 AS SELECT generate_series(400, 502)"); } - $old->safe_psql('postgres', - "CREATE TABLESPACE inplc_tblspc LOCATION ''"); - $old->safe_psql('postgres', - "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); - $old->safe_psql('postgres', - "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" - ); - $old->safe_psql('testdb3', - "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); + $old->safe_psql('postgres', "CREATE TABLESPACE inplc_tblspc LOCATION ''"); + $old->safe_psql('postgres', + "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); + $old->safe_psql('postgres', + "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" + ); + $old->safe_psql('testdb3', + "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); # While we are here, test handling of large objects. $old->safe_psql( @@ -152,12 +149,10 @@ sub test_mode } # Tests for in-place tablespaces. - $result = - $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); - is($result, '104', "test5 data after pg_upgrade $mode"); - $result = - $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); - is($result, '105', "test6 data after pg_upgrade $mode"); + $result = $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); + is($result, '104', "test5 data after pg_upgrade $mode"); + $result = $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); + is($result, '105', "test6 data after pg_upgrade $mode"); # Tests for large objects $result = $new->safe_psql('postgres', "SELECT lo_get(4532)"); diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index 44ef11d980e..c90bf8bbde2 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -6278,23 +6278,22 @@ get_create_object_cmd(EditableObjectType obj_type, Oid oid, * ensure the right view gets replaced. Also, check relation kind * to be sure it's a view. * - * Views may have WITH [LOCAL|CASCADED] - * CHECK OPTION. These are not part of the view definition - * returned by pg_get_viewdef() and so need to be retrieved - * separately. Materialized views may have - * arbitrary storage parameter reloptions. + * Views may have WITH [LOCAL|CASCADED] CHECK OPTION. These are + * not part of the view definition returned by pg_get_viewdef() + * and so need to be retrieved separately. Materialized views may + * have arbitrary storage parameter reloptions. */ printfPQExpBuffer(query, "/* %s */\n", _("Get view's definition and details")); - appendPQExpBuffer(query, - "SELECT nspname, relname, relkind, " - "pg_catalog.pg_get_viewdef(c.oid, true), " - "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " - "FROM pg_catalog.pg_class c " - "LEFT JOIN pg_catalog.pg_namespace n " - "ON c.relnamespace = n.oid WHERE c.oid = %u", - oid); + appendPQExpBuffer(query, + "SELECT nspname, relname, relkind, " + "pg_catalog.pg_get_viewdef(c.oid, true), " + "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " + "FROM pg_catalog.pg_class c " + "LEFT JOIN pg_catalog.pg_namespace n " + "ON c.relnamespace = n.oid WHERE c.oid = %u", + oid); break; } diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index ce99137c613..ac0c55e7aa5 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -387,19 +387,19 @@ describeFunctions(const char *functypes, const char *func_pattern, gettext_noop("stable"), gettext_noop("volatile"), gettext_noop("Volatility")); - appendPQExpBuffer(&buf, - ",\n CASE\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" - " END as \"%s\"", - gettext_noop("restricted"), - gettext_noop("safe"), - gettext_noop("unsafe"), - gettext_noop("Parallel")); + appendPQExpBuffer(&buf, + ",\n CASE\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" + " END as \"%s\"", + gettext_noop("restricted"), + gettext_noop("safe"), + gettext_noop("unsafe"), + gettext_noop("Parallel")); appendPQExpBuffer(&buf, ",\n pg_catalog.pg_get_userbyid(p.proowner) as \"%s\"" ",\n CASE WHEN prosecdef THEN '%s' ELSE '%s' END AS \"%s\"" @@ -599,8 +599,8 @@ describeFunctions(const char *functypes, const char *func_pattern, myopt.title = _("List of functions"); myopt.translate_header = true; - myopt.translate_columns = translate_columns; - myopt.n_translate_columns = lengthof(translate_columns); + myopt.translate_columns = translate_columns; + myopt.n_translate_columns = lengthof(translate_columns); printQuery(res, &myopt, pset.queryFout, false, pset.logfile); @@ -1086,38 +1086,38 @@ permissionsList(const char *pattern, bool showSystem) " ), E'\\n') AS \"%s\"", gettext_noop("Column privileges")); - appendPQExpBuffer(&buf, - ",\n pg_catalog.array_to_string(ARRAY(\n" - " SELECT polname\n" - " || CASE WHEN NOT polpermissive THEN\n" - " E' (RESTRICTIVE)'\n" - " ELSE '' END\n" - " || CASE WHEN polcmd != '*' THEN\n" - " E' (' || polcmd::pg_catalog.text || E'):'\n" - " ELSE E':'\n" - " END\n" - " || CASE WHEN polqual IS NOT NULL THEN\n" - " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" - " ELSE E''\n" - " END\n" - " || CASE WHEN polwithcheck IS NOT NULL THEN\n" - " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" - " ELSE E''\n" - " END" - " || CASE WHEN polroles <> '{0}' THEN\n" - " E'\\n to: ' || pg_catalog.array_to_string(\n" - " ARRAY(\n" - " SELECT rolname\n" - " FROM pg_catalog.pg_roles\n" - " WHERE oid = ANY (polroles)\n" - " ORDER BY 1\n" - " ), E', ')\n" - " ELSE E''\n" - " END\n" - " FROM pg_catalog.pg_policy pol\n" - " WHERE polrelid = c.oid), E'\\n')\n" - " AS \"%s\"", - gettext_noop("Policies")); + appendPQExpBuffer(&buf, + ",\n pg_catalog.array_to_string(ARRAY(\n" + " SELECT polname\n" + " || CASE WHEN NOT polpermissive THEN\n" + " E' (RESTRICTIVE)'\n" + " ELSE '' END\n" + " || CASE WHEN polcmd != '*' THEN\n" + " E' (' || polcmd::pg_catalog.text || E'):'\n" + " ELSE E':'\n" + " END\n" + " || CASE WHEN polqual IS NOT NULL THEN\n" + " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" + " ELSE E''\n" + " END\n" + " || CASE WHEN polwithcheck IS NOT NULL THEN\n" + " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" + " ELSE E''\n" + " END" + " || CASE WHEN polroles <> '{0}' THEN\n" + " E'\\n to: ' || pg_catalog.array_to_string(\n" + " ARRAY(\n" + " SELECT rolname\n" + " FROM pg_catalog.pg_roles\n" + " WHERE oid = ANY (polroles)\n" + " ORDER BY 1\n" + " ), E', ')\n" + " ELSE E''\n" + " END\n" + " FROM pg_catalog.pg_policy pol\n" + " WHERE polrelid = c.oid), E'\\n')\n" + " AS \"%s\"", + gettext_noop("Policies")); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_class c\n" " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n" @@ -1675,27 +1675,27 @@ describeOneTableDetails(const char *schemaname, char *footers[3] = {NULL, NULL, NULL}; printfPQExpBuffer(&buf, "/* %s */\n", _("Get sequence information")); - appendPQExpBuffer(&buf, - "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" - " seqstart AS \"%s\",\n" - " seqmin AS \"%s\",\n" - " seqmax AS \"%s\",\n" - " seqincrement AS \"%s\",\n" - " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" - " seqcache AS \"%s\"\n", - gettext_noop("Type"), - gettext_noop("Start"), - gettext_noop("Minimum"), - gettext_noop("Maximum"), - gettext_noop("Increment"), - gettext_noop("yes"), - gettext_noop("no"), - gettext_noop("Cycles?"), - gettext_noop("Cache")); - appendPQExpBuffer(&buf, - "FROM pg_catalog.pg_sequence\n" - "WHERE seqrelid = '%s';", - oid); + appendPQExpBuffer(&buf, + "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" + " seqstart AS \"%s\",\n" + " seqmin AS \"%s\",\n" + " seqmax AS \"%s\",\n" + " seqincrement AS \"%s\",\n" + " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" + " seqcache AS \"%s\"\n", + gettext_noop("Type"), + gettext_noop("Start"), + gettext_noop("Minimum"), + gettext_noop("Maximum"), + gettext_noop("Increment"), + gettext_noop("yes"), + gettext_noop("no"), + gettext_noop("Cycles?"), + gettext_noop("Cache")); + appendPQExpBuffer(&buf, + "FROM pg_catalog.pg_sequence\n" + "WHERE seqrelid = '%s';", + oid); res = PSQLexec(buf.data); if (!res) @@ -1913,7 +1913,7 @@ describeOneTableDetails(const char *schemaname, appendPQExpBufferStr(&buf, ",\n (SELECT c.collname FROM pg_catalog.pg_collation c, pg_catalog.pg_type t\n" " WHERE c.oid = a.attcollation AND t.oid = a.atttypid AND a.attcollation <> t.typcollation) AS attcollation"); attcoll_col = cols++; - appendPQExpBufferStr(&buf, ",\n a.attidentity"); + appendPQExpBufferStr(&buf, ",\n a.attidentity"); attidentity_col = cols++; if (pset.sversion >= 120000) appendPQExpBufferStr(&buf, ",\n a.attgenerated"); @@ -2326,7 +2326,7 @@ describeOneTableDetails(const char *schemaname, CppAsString2(CONSTRAINT_EXCLUSION) ") AND " "condeferred) AS condeferred,\n"); - appendPQExpBufferStr(&buf, "i.indisreplident,\n"); + appendPQExpBufferStr(&buf, "i.indisreplident,\n"); if (pset.sversion >= 150000) appendPQExpBufferStr(&buf, "i.indnullsnotdistinct,\n"); @@ -2431,7 +2431,7 @@ describeOneTableDetails(const char *schemaname, "pg_catalog.pg_get_indexdef(i.indexrelid, 0, true),\n " "pg_catalog.pg_get_constraintdef(con.oid, true), " "contype, condeferrable, condeferred"); - appendPQExpBufferStr(&buf, ", i.indisreplident"); + appendPQExpBufferStr(&buf, ", i.indisreplident"); appendPQExpBufferStr(&buf, ", c2.reltablespace"); if (pset.sversion >= 180000) appendPQExpBufferStr(&buf, ", con.conperiod"); @@ -2682,81 +2682,80 @@ describeOneTableDetails(const char *schemaname, PQclear(result); /* print any row-level policies */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get row-level policies for this table")); - appendPQExpBufferStr(&buf, "SELECT pol.polname,"); - appendPQExpBufferStr(&buf, - " pol.polpermissive,\n"); - appendPQExpBuffer(&buf, - " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" - " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" - " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" - " CASE pol.polcmd\n" - " WHEN 'r' THEN 'SELECT'\n" - " WHEN 'a' THEN 'INSERT'\n" - " WHEN 'w' THEN 'UPDATE'\n" - " WHEN 'd' THEN 'DELETE'\n" - " END AS cmd\n" - "FROM pg_catalog.pg_policy pol\n" - "WHERE pol.polrelid = '%s' ORDER BY 1;", - oid); + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get row-level policies for this table")); + appendPQExpBufferStr(&buf, "SELECT pol.polname,"); + appendPQExpBufferStr(&buf, + " pol.polpermissive,\n"); + appendPQExpBuffer(&buf, + " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" + " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" + " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" + " CASE pol.polcmd\n" + " WHEN 'r' THEN 'SELECT'\n" + " WHEN 'a' THEN 'INSERT'\n" + " WHEN 'w' THEN 'UPDATE'\n" + " WHEN 'd' THEN 'DELETE'\n" + " END AS cmd\n" + "FROM pg_catalog.pg_policy pol\n" + "WHERE pol.polrelid = '%s' ORDER BY 1;", + oid); - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - /* - * Handle cases where RLS is enabled and there are policies, or - * there aren't policies, or RLS isn't enabled but there are - * policies - */ - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies:")); + /* + * Handle cases where RLS is enabled and there are policies, or there + * aren't policies, or RLS isn't enabled but there are policies + */ + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies:")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled):")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled):")); - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); - if (!tableinfo.rowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (row security disabled):")); + if (!tableinfo.rowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (row security disabled):")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " POLICY \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " POLICY \"%s\"", + PQgetvalue(result, i, 0)); - if (*(PQgetvalue(result, i, 1)) == 'f') - appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); + if (*(PQgetvalue(result, i, 1)) == 'f') + appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); - if (!PQgetisnull(result, i, 5)) - appendPQExpBuffer(&buf, " FOR %s", - PQgetvalue(result, i, 5)); + if (!PQgetisnull(result, i, 5)) + appendPQExpBuffer(&buf, " FOR %s", + PQgetvalue(result, i, 5)); - if (!PQgetisnull(result, i, 2)) - { - appendPQExpBuffer(&buf, "\n TO %s", - PQgetvalue(result, i, 2)); - } + if (!PQgetisnull(result, i, 2)) + { + appendPQExpBuffer(&buf, "\n TO %s", + PQgetvalue(result, i, 2)); + } - if (!PQgetisnull(result, i, 3)) - appendPQExpBuffer(&buf, "\n USING (%s)", - PQgetvalue(result, i, 3)); + if (!PQgetisnull(result, i, 3)) + appendPQExpBuffer(&buf, "\n USING (%s)", + PQgetvalue(result, i, 3)); - if (!PQgetisnull(result, i, 4)) - appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", - PQgetvalue(result, i, 4)); + if (!PQgetisnull(result, i, 4)) + appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", + PQgetvalue(result, i, 4)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* print any extended statistics */ if (pset.sversion >= 140000) @@ -3025,115 +3024,115 @@ describeOneTableDetails(const char *schemaname, } /* print any publications */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get publications that publish this table")); - if (pset.sversion >= 150000) + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get publications that publish this table")); + if (pset.sversion >= 150000) + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" + " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" + "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" + "UNION\n" + "SELECT pubname\n" + " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" + " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" + " (SELECT pg_catalog.string_agg(attname, ', ')\n" + " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" + " pg_catalog.pg_attribute\n" + " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" + " ELSE NULL END) " + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" + "WHERE pr.prrelid = '%s'\n", + oid, oid, oid); + + if (pset.sversion >= 190000) { + /* + * Skip entries where this relation appears in the + * publication's EXCEPT list. + */ appendPQExpBuffer(&buf, + " AND NOT pr.prexcept\n" + "UNION\n" "SELECT pubname\n" " , NULL\n" " , NULL\n" "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" - " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" - "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" - "UNION\n" - "SELECT pubname\n" - " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" - " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" - " (SELECT pg_catalog.string_agg(attname, ', ')\n" - " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" - " pg_catalog.pg_attribute\n" - " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" - " ELSE NULL END) " - "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" - "WHERE pr.prrelid = '%s'\n", + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + " AND NOT EXISTS (\n" + " SELECT 1\n" + " FROM pg_catalog.pg_publication_rel pr\n" + " WHERE pr.prpubid = p.oid AND\n" + " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" + "ORDER BY 1;", oid, oid, oid); - - if (pset.sversion >= 190000) - { - /* - * Skip entries where this relation appears in the - * publication's EXCEPT list. - */ - appendPQExpBuffer(&buf, - " AND NOT pr.prexcept\n" - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - " AND NOT EXISTS (\n" - " SELECT 1\n" - " FROM pg_catalog.pg_publication_rel pr\n" - " WHERE pr.prpubid = p.oid AND\n" - " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" - "ORDER BY 1;", - oid, oid, oid); - } - else - { - appendPQExpBuffer(&buf, - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - "ORDER BY 1;", - oid); - } } else { appendPQExpBuffer(&buf, + "UNION\n" "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - "WHERE pr.prrelid = '%s'\n" - "UNION ALL\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" + " , NULL\n" + " , NULL\n" "FROM pg_catalog.pg_publication p\n" "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" "ORDER BY 1;", - oid, oid); + oid); } + } + else + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + "WHERE pr.prrelid = '%s'\n" + "UNION ALL\n" + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + "ORDER BY 1;", + oid, oid); + } - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - if (tuples > 0) - printTableAddFooter(&cont, _("Included in publications:")); + if (tuples > 0) + printTableAddFooter(&cont, _("Included in publications:")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " \"%s\"", + PQgetvalue(result, i, 0)); - /* column list (if any) */ - if (!PQgetisnull(result, i, 2)) - appendPQExpBuffer(&buf, " (%s)", - PQgetvalue(result, i, 2)); + /* column list (if any) */ + if (!PQgetisnull(result, i, 2)) + appendPQExpBuffer(&buf, " (%s)", + PQgetvalue(result, i, 2)); - /* row filter (if any) */ - if (!PQgetisnull(result, i, 1)) - appendPQExpBuffer(&buf, " WHERE %s", - PQgetvalue(result, i, 1)); + /* row filter (if any) */ + if (!PQgetisnull(result, i, 1)) + appendPQExpBuffer(&buf, " WHERE %s", + PQgetvalue(result, i, 1)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* Print publications where the table is in the EXCEPT clause */ if (pset.sversion >= 190000) @@ -3805,7 +3804,7 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) ncols++; } appendPQExpBufferStr(&buf, "\n, r.rolreplication"); - appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); + appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_roles r\n"); @@ -3860,8 +3859,8 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) if (strcmp(PQgetvalue(res, i, (verbose ? 9 : 8)), "t") == 0) add_role_attribute(&buf, _("Replication")); - if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) - add_role_attribute(&buf, _("Bypass RLS")); + if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) + add_role_attribute(&buf, _("Bypass RLS")); conns = atoi(PQgetvalue(res, i, 6)); if (conns >= 0) @@ -5155,14 +5154,14 @@ listCollations(const char *pattern, bool verbose, bool showSystem) gettext_noop("Schema"), gettext_noop("Name")); - appendPQExpBuffer(&buf, - " CASE c.collprovider " - "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " - "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " - "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " - "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " - "END AS \"%s\",\n", - gettext_noop("Provider")); + appendPQExpBuffer(&buf, + " CASE c.collprovider " + "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " + "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " + "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " + "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " + "END AS \"%s\",\n", + gettext_noop("Provider")); appendPQExpBuffer(&buf, " c.collcollate AS \"%s\",\n" -- 2.50.1 (Apple Git-155) --aHl3HfeiUuO3zeNC-- ^ permalink raw reply [nested|flat] 59+ messages in thread
* [PATCH v6 4/4] run pgindent and pgperltidy @ 2026-06-30 18:24 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 59+ messages in thread From: Nathan Bossart @ 2026-06-30 18:24 UTC (permalink / raw) --- src/bin/pg_dump/pg_dump.c | 464 ++++++++++----------- src/bin/pg_dump/pg_dumpall.c | 30 +- src/bin/pg_upgrade/check.c | 16 +- src/bin/pg_upgrade/controldata.c | 2 +- src/bin/pg_upgrade/exec.c | 8 +- src/bin/pg_upgrade/multixact_rewrite.c | 80 ++-- src/bin/pg_upgrade/pg_upgrade.c | 34 +- src/bin/pg_upgrade/relfilenumber.c | 54 +-- src/bin/pg_upgrade/t/006_transfer_modes.pl | 33 +- src/bin/psql/command.c | 29 +- src/bin/psql/describe.c | 461 ++++++++++---------- 11 files changed, 601 insertions(+), 610 deletions(-) diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 65bd15ebfd2..5673268b467 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -1491,8 +1491,8 @@ setup_connection(Archive *AH, const char *dumpencoding, * Disable timeouts if supported. */ ExecuteSqlStatement(AH, "SET statement_timeout = 0"); - ExecuteSqlStatement(AH, "SET lock_timeout = 0"); - ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); + ExecuteSqlStatement(AH, "SET lock_timeout = 0"); + ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); if (AH->remoteVersion >= 170000) ExecuteSqlStatement(AH, "SET transaction_timeout = 0"); @@ -1505,10 +1505,10 @@ setup_connection(Archive *AH, const char *dumpencoding, /* * Adjust row-security mode, if supported. */ - if (dopt->enable_row_security) - ExecuteSqlStatement(AH, "SET row_security = on"); - else - ExecuteSqlStatement(AH, "SET row_security = off"); + if (dopt->enable_row_security) + ExecuteSqlStatement(AH, "SET row_security = on"); + else + ExecuteSqlStatement(AH, "SET row_security = off"); /* * For security reasons, we restrict the expansion of non-system views and @@ -1933,10 +1933,9 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) addObjectDependency(dobj, ext->dobj.dumpId); /* - * Mark the member object to have any non-initial ACLs - * dumped. (Any initial ACLs will be removed later, using data from - * pg_init_privs, so that we'll dump only the delta from the extension's - * initial setup.) + * Mark the member object to have any non-initial ACLs dumped. (Any + * initial ACLs will be removed later, using data from pg_init_privs, so + * that we'll dump only the delta from the extension's initial setup.) * * In binary upgrades, we still dump all components of the members * individually, since the idea is to exactly reproduce the database @@ -1953,7 +1952,7 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) if (fout->dopt->binary_upgrade) dobj->dump = ext->dobj.dump; else - dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); + dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); return true; } @@ -1987,9 +1986,9 @@ selectDumpableNamespace(NamespaceInfo *nsinfo, Archive *fout) else if (strcmp(nsinfo->dobj.name, "pg_catalog") == 0) { /* - * We dump out any ACLs defined in pg_catalog, if - * they are interesting (and not the original ACLs which were set at - * initdb time, see pg_init_privs). + * We dump out any ACLs defined in pg_catalog, if they are interesting + * (and not the original ACLs which were set at initdb time, see + * pg_init_privs). */ nsinfo->dobj.dump_contains = nsinfo->dobj.dump = DUMP_COMPONENT_ACL; } @@ -3296,7 +3295,7 @@ dumpDatabase(Archive *fout) "datcollate, datctype, datfrozenxid, " "datacl, acldefault('d', datdba) AS acldefault, " "datistemplate, datconnlimit, "); - appendPQExpBufferStr(dbQry, "datminmxid, "); + appendPQExpBufferStr(dbQry, "datminmxid, "); if (fout->remoteVersion >= 170000) appendPQExpBufferStr(dbQry, "datlocprovider, datlocale, datcollversion, "); else if (fout->remoteVersion >= 150000) @@ -3638,11 +3637,11 @@ dumpDatabase(Archive *fout) ii_oid, ii_relminmxid; - appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" - "FROM pg_catalog.pg_class\n" - "WHERE oid IN (%u, %u, %u, %u);\n", - LargeObjectRelationId, LargeObjectLOidPNIndexId, - LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); + appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" + "FROM pg_catalog.pg_class\n" + "WHERE oid IN (%u, %u, %u, %u);\n", + LargeObjectRelationId, LargeObjectLOidPNIndexId, + LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); lo_res = ExecuteSqlQuery(fout, loFrozenQry->data, PGRES_TUPLES_OK); @@ -4274,7 +4273,7 @@ getPolicies(Archive *fout, TableInfo tblinfo[], int numTables) printfPQExpBuffer(query, "SELECT pol.oid, pol.tableoid, pol.polrelid, pol.polname, pol.polcmd, "); - appendPQExpBufferStr(query, "pol.polpermissive, "); + appendPQExpBufferStr(query, "pol.polpermissive, "); appendPQExpBuffer(query, "CASE WHEN pol.polroles = '{0}' THEN NULL ELSE " " pg_catalog.array_to_string(ARRAY(SELECT pg_catalog.quote_ident(rolname) from pg_catalog.pg_roles WHERE oid = ANY(pol.polroles)), ', ') END AS polroles, " @@ -6633,9 +6632,9 @@ getAccessMethods(Archive *fout) * Select all access methods from pg_am table. */ appendPQExpBufferStr(query, "SELECT tableoid, oid, amname, "); - appendPQExpBufferStr(query, - "amtype, " - "amhandler::pg_catalog.regproc AS amhandler "); + appendPQExpBufferStr(query, + "amtype, " + "amhandler::pg_catalog.regproc AS amhandler "); appendPQExpBufferStr(query, "FROM pg_am"); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6827,35 +6826,35 @@ getAggregates(Archive *fout) * Find all interesting aggregates. See comment in getFuncs() for the * rationale behind the filtering logic. */ - agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" - : "p.proisagg"); + agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" + : "p.proisagg"); - appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " - "p.proname AS aggname, " - "p.pronamespace AS aggnamespace, " - "p.pronargs, p.proargtypes, " - "p.proowner, " - "p.proacl AS aggacl, " - "acldefault('f', p.proowner) AS acldefault " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s AND (" - "p.pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog') OR " - "p.proacl IS DISTINCT FROM pip.initprivs", - agg_check); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - " OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); - appendPQExpBufferChar(query, ')'); + appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " + "p.proname AS aggname, " + "p.pronamespace AS aggnamespace, " + "p.pronargs, p.proargtypes, " + "p.proowner, " + "p.proacl AS aggacl, " + "acldefault('f', p.proowner) AS acldefault " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s AND (" + "p.pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog') OR " + "p.proacl IS DISTINCT FROM pip.initprivs", + agg_check); + if (dopt->binary_upgrade) + appendPQExpBufferStr(query, + " OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6957,53 +6956,53 @@ getFuncs(Archive *fout) * include them, since we want to dump extension members individually in * that mode. Also, if they are used by casts or transforms then we need * to gather the information about them, though they won't be dumped if - * they are built-in. Also, include functions in - * pg_catalog if they have an ACL different from what's shown in - * pg_init_privs (so we have to join to pg_init_privs; annoying). + * they are built-in. Also, include functions in pg_catalog if they have + * an ACL different from what's shown in pg_init_privs (so we have to join + * to pg_init_privs; annoying). */ - not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" - : "NOT p.proisagg"); + not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" + : "NOT p.proisagg"); - appendPQExpBuffer(query, - "SELECT p.tableoid, p.oid, p.proname, p.prolang, " - "p.pronargs, p.proargtypes, p.prorettype, " - "p.proacl, " - "acldefault('f', p.proowner) AS acldefault, " - "p.pronamespace, " - "p.proowner " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s" - "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " - "WHERE classid = 'pg_proc'::regclass AND " - "objid = p.oid AND deptype = 'i')" - "\n AND (" - "\n pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog')" - "\n OR EXISTS (SELECT 1 FROM pg_cast" - "\n WHERE pg_cast.oid > %u " - "\n AND p.oid = pg_cast.castfunc)" - "\n OR EXISTS (SELECT 1 FROM pg_transform" - "\n WHERE pg_transform.oid > %u AND " - "\n (p.oid = pg_transform.trffromsql" - "\n OR p.oid = pg_transform.trftosql))", - not_agg_check, - g_last_builtin_oid, - g_last_builtin_oid); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); + appendPQExpBuffer(query, + "SELECT p.tableoid, p.oid, p.proname, p.prolang, " + "p.pronargs, p.proargtypes, p.prorettype, " + "p.proacl, " + "acldefault('f', p.proowner) AS acldefault, " + "p.pronamespace, " + "p.proowner " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s" + "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " + "WHERE classid = 'pg_proc'::regclass AND " + "objid = p.oid AND deptype = 'i')" + "\n AND (" + "\n pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog')" + "\n OR EXISTS (SELECT 1 FROM pg_cast" + "\n WHERE pg_cast.oid > %u " + "\n AND p.oid = pg_cast.castfunc)" + "\n OR EXISTS (SELECT 1 FROM pg_transform" + "\n WHERE pg_transform.oid > %u AND " + "\n (p.oid = pg_transform.trffromsql" + "\n OR p.oid = pg_transform.trftosql))", + not_agg_check, + g_last_builtin_oid, + g_last_builtin_oid); + if (dopt->binary_upgrade) appendPQExpBufferStr(query, - "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); - appendPQExpBufferChar(query, ')'); + "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferStr(query, + "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -7252,31 +7251,31 @@ getTables(Archive *fout, int *numTables) appendPQExpBufferStr(query, "c.relhasoids, "); - appendPQExpBufferStr(query, - "c.relispopulated, "); + appendPQExpBufferStr(query, + "c.relispopulated, "); - appendPQExpBufferStr(query, - "c.relreplident, "); + appendPQExpBufferStr(query, + "c.relreplident, "); - appendPQExpBufferStr(query, - "c.relrowsecurity, c.relforcerowsecurity, "); + appendPQExpBufferStr(query, + "c.relrowsecurity, c.relforcerowsecurity, "); - appendPQExpBufferStr(query, - "c.relminmxid, tc.relminmxid AS tminmxid, "); + appendPQExpBufferStr(query, + "c.relminmxid, tc.relminmxid AS tminmxid, "); - appendPQExpBufferStr(query, - "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); + appendPQExpBufferStr(query, + "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); - appendPQExpBufferStr(query, - "am.amname, "); + appendPQExpBufferStr(query, + "am.amname, "); - appendPQExpBufferStr(query, - "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); + appendPQExpBufferStr(query, + "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); - appendPQExpBufferStr(query, - "c.relispartition AS ispartition "); + appendPQExpBufferStr(query, + "c.relispartition AS ispartition "); /* * Left join to pg_depend to pick up dependency info linking sequences to @@ -7296,8 +7295,8 @@ getTables(Archive *fout, int *numTables) /* * Left join to pg_am to pick up the amname. */ - appendPQExpBufferStr(query, - "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); + appendPQExpBufferStr(query, + "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); /* * We purposefully ignore toast OIDs for partitioned tables; the reason is @@ -7868,8 +7867,8 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables) "t.reloptions AS indreloptions, "); - appendPQExpBufferStr(query, - "i.indisreplident, "); + appendPQExpBufferStr(query, + "i.indisreplident, "); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -9313,8 +9312,8 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables) appendPQExpBufferStr(q, "'' AS attcompression,\n"); - appendPQExpBufferStr(q, - "a.attidentity,\n"); + appendPQExpBufferStr(q, + "a.attidentity,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(q, @@ -10717,73 +10716,73 @@ getAdditionalACLs(Archive *fout) PQclear(res); /* Fetch initial-privileges data */ - printfPQExpBuffer(query, - "SELECT objoid, classoid, objsubid, privtype, initprivs " - "FROM pg_init_privs"); + printfPQExpBuffer(query, + "SELECT objoid, classoid, objsubid, privtype, initprivs " + "FROM pg_init_privs"); - res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); + res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); - ntups = PQntuples(res); - for (i = 0; i < ntups; i++) - { - Oid objoid = atooid(PQgetvalue(res, i, 0)); - Oid classoid = atooid(PQgetvalue(res, i, 1)); - int objsubid = atoi(PQgetvalue(res, i, 2)); - char privtype = *(PQgetvalue(res, i, 3)); - char *initprivs = PQgetvalue(res, i, 4); - CatalogId objId; - DumpableObject *dobj; + ntups = PQntuples(res); + for (i = 0; i < ntups; i++) + { + Oid objoid = atooid(PQgetvalue(res, i, 0)); + Oid classoid = atooid(PQgetvalue(res, i, 1)); + int objsubid = atoi(PQgetvalue(res, i, 2)); + char privtype = *(PQgetvalue(res, i, 3)); + char *initprivs = PQgetvalue(res, i, 4); + CatalogId objId; + DumpableObject *dobj; - objId.tableoid = classoid; - objId.oid = objoid; - dobj = findObjectByCatalogId(objId); - /* OK to ignore entries we haven't got a DumpableObject for */ - if (dobj) + objId.tableoid = classoid; + objId.oid = objoid; + dobj = findObjectByCatalogId(objId); + /* OK to ignore entries we haven't got a DumpableObject for */ + if (dobj) + { + /* Cope with sub-object initprivs */ + if (objsubid != 0) { - /* Cope with sub-object initprivs */ - if (objsubid != 0) - { - if (dobj->objType == DO_TABLE) - { - /* For a column initprivs, set the table's ACL flags */ - dobj->components |= DUMP_COMPONENT_ACL; - ((TableInfo *) dobj)->hascolumnACLs = true; - } - else - pg_log_warning("unsupported pg_init_privs entry: %u %u %d", - classoid, objoid, objsubid); - continue; - } - - /* - * We ignore any pg_init_privs.initprivs entry for the public - * schema, as explained in getNamespaces(). - */ - if (dobj->objType == DO_NAMESPACE && - strcmp(dobj->name, "public") == 0) - continue; - - /* Else it had better be of a type we think has ACLs */ - if (dobj->objType == DO_NAMESPACE || - dobj->objType == DO_TYPE || - dobj->objType == DO_FUNC || - dobj->objType == DO_AGG || - dobj->objType == DO_TABLE || - dobj->objType == DO_PROCLANG || - dobj->objType == DO_FDW || - dobj->objType == DO_FOREIGN_SERVER) + if (dobj->objType == DO_TABLE) { - DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; - - daobj->dacl.privtype = privtype; - daobj->dacl.initprivs = pstrdup(initprivs); + /* For a column initprivs, set the table's ACL flags */ + dobj->components |= DUMP_COMPONENT_ACL; + ((TableInfo *) dobj)->hascolumnACLs = true; } else pg_log_warning("unsupported pg_init_privs entry: %u %u %d", classoid, objoid, objsubid); + continue; + } + + /* + * We ignore any pg_init_privs.initprivs entry for the public + * schema, as explained in getNamespaces(). + */ + if (dobj->objType == DO_NAMESPACE && + strcmp(dobj->name, "public") == 0) + continue; + + /* Else it had better be of a type we think has ACLs */ + if (dobj->objType == DO_NAMESPACE || + dobj->objType == DO_TYPE || + dobj->objType == DO_FUNC || + dobj->objType == DO_AGG || + dobj->objType == DO_TABLE || + dobj->objType == DO_PROCLANG || + dobj->objType == DO_FDW || + dobj->objType == DO_FOREIGN_SERVER) + { + DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; + + daobj->dacl.privtype = privtype; + daobj->dacl.initprivs = pstrdup(initprivs); } + else + pg_log_warning("unsupported pg_init_privs entry: %u %u %d", + classoid, objoid, objsubid); } - PQclear(res); + } + PQclear(res); destroyPQExpBuffer(query); } @@ -11128,8 +11127,8 @@ dumpRelationStats_dumper(Archive *fout, const void *userArg, const TocEntry *te) * The results must be in the order of the relations supplied in the * parameters to ensure we remain in sync as we walk through the TOC. * - * For versions before 19, the redundant filter clause on s.tablename = - * ANY(...) seems sufficient to convince the planner to use + * For versions before 19, the redundant filter clause on s.tablename + * = ANY(...) seems sufficient to convince the planner to use * pg_class_relname_nsp_index, which avoids a full scan of pg_stats. * In newer versions, pg_stats returns the table OIDs, eliminating the * need for that hack. @@ -13469,11 +13468,11 @@ dumpFunc(Archive *fout, const FuncInfo *finfo) "pg_catalog.pg_get_function_result(p.oid) AS funcresult,\n" "proleakproof,\n"); - appendPQExpBufferStr(query, - "array_to_string(protrftypes, ' ') AS protrftypes,\n"); + appendPQExpBufferStr(query, + "array_to_string(protrftypes, ' ') AS protrftypes,\n"); - appendPQExpBufferStr(query, - "proparallel,\n"); + appendPQExpBufferStr(query, + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -14963,9 +14962,9 @@ dumpCollation(Archive *fout, const CollInfo *collinfo) /* Get collation-specific details */ appendPQExpBufferStr(query, "SELECT "); - appendPQExpBufferStr(query, - "collprovider, " - "collversion, "); + appendPQExpBufferStr(query, + "collprovider, " + "collversion, "); if (fout->remoteVersion >= 120000) appendPQExpBufferStr(query, @@ -15372,23 +15371,23 @@ dumpAgg(Archive *fout, const AggInfo *agginfo) "pg_catalog.pg_get_function_arguments(p.oid) AS funcargs,\n" "pg_catalog.pg_get_function_identity_arguments(p.oid) AS funciargs,\n"); - appendPQExpBufferStr(query, - "aggkind,\n" - "aggmtransfn,\n" - "aggminvtransfn,\n" - "aggmfinalfn,\n" - "aggmtranstype::pg_catalog.regtype,\n" - "aggfinalextra,\n" - "aggmfinalextra,\n" - "aggtransspace,\n" - "aggmtransspace,\n" - "aggminitval,\n"); + appendPQExpBufferStr(query, + "aggkind,\n" + "aggmtransfn,\n" + "aggminvtransfn,\n" + "aggmfinalfn,\n" + "aggmtranstype::pg_catalog.regtype,\n" + "aggfinalextra,\n" + "aggmfinalextra,\n" + "aggtransspace,\n" + "aggmtransspace,\n" + "aggminitval,\n"); - appendPQExpBufferStr(query, - "aggcombinefn,\n" - "aggserialfn,\n" - "aggdeserialfn,\n" - "proparallel,\n"); + appendPQExpBufferStr(query, + "aggcombinefn,\n" + "aggserialfn,\n" + "aggdeserialfn,\n" + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -16848,30 +16847,30 @@ dumpTable(Archive *fout, const TableInfo *tbinfo) appendPQExpBufferStr(query, "PREPARE getColumnACLs(pg_catalog.oid) AS\n"); - /* - * In principle we should call acldefault('c', relowner) to - * get the default ACL for a column. However, we don't - * currently store the numeric OID of the relowner in - * TableInfo. We could convert the owner name using regrole, - * but that creates a risk of failure due to concurrent role - * renames. Given that the default ACL for columns is empty - * and is likely to stay that way, it's not worth extra cycles - * and risk to avoid hard-wiring that knowledge here. - */ - appendPQExpBufferStr(query, - "SELECT at.attname, " - "at.attacl, " - "'{}' AS acldefault, " - "pip.privtype, pip.initprivs " - "FROM pg_catalog.pg_attribute at " - "LEFT JOIN pg_catalog.pg_init_privs pip ON " - "(at.attrelid = pip.objoid " - "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " - "AND at.attnum = pip.objsubid) " - "WHERE at.attrelid = $1 AND " - "NOT at.attisdropped " - "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " - "ORDER BY at.attnum"); + /* + * In principle we should call acldefault('c', relowner) to get + * the default ACL for a column. However, we don't currently + * store the numeric OID of the relowner in TableInfo. We could + * convert the owner name using regrole, but that creates a risk + * of failure due to concurrent role renames. Given that the + * default ACL for columns is empty and is likely to stay that + * way, it's not worth extra cycles and risk to avoid hard-wiring + * that knowledge here. + */ + appendPQExpBufferStr(query, + "SELECT at.attname, " + "at.attacl, " + "'{}' AS acldefault, " + "pip.privtype, pip.initprivs " + "FROM pg_catalog.pg_attribute at " + "LEFT JOIN pg_catalog.pg_init_privs pip ON " + "(at.attrelid = pip.objoid " + "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " + "AND at.attnum = pip.objsubid) " + "WHERE at.attrelid = $1 AND " + "NOT at.attisdropped " + "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " + "ORDER BY at.attnum"); ExecuteSqlStatement(fout, query->data); @@ -19165,7 +19164,7 @@ collectSequences(Archive *fout) * pg_get_sequence_data(), but we only do so for non-schema-only dumps. */ if (fout->remoteVersion < 180000 || - (!fout->dopt->dumpData && !fout->dopt->sequence_data)) + (!fout->dopt->dumpData && !fout->dopt->sequence_data)) query = "SELECT seqrelid, format_type(seqtypid, NULL), " "seqstart, seqincrement, " "seqmax, seqmin, " @@ -19227,15 +19226,14 @@ dumpSequence(Archive *fout, const TableInfo *tbinfo) qseqname = pg_strdup(fmtId(tbinfo->dobj.name)); /* - * The sequence information is gathered in a sorted - * table before any calls to dumpSequence(). See collectSequences() for - * more information. + * The sequence information is gathered in a sorted table before any calls + * to dumpSequence(). See collectSequences() for more information. */ - Assert(sequences); + Assert(sequences); - key.oid = tbinfo->dobj.catId.oid; - seq = bsearch(&key, sequences, nsequences, - sizeof(SequenceItem), SequenceItemCmp); + key.oid = tbinfo->dobj.catId.oid; + seq = bsearch(&key, sequences, nsequences, + sizeof(SequenceItem), SequenceItemCmp); /* Calculate default limits for a sequence of this type */ is_ascending = (seq->incby >= 0); diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c index e68937c9934..afcd9a218d8 100644 --- a/src/bin/pg_dump/pg_dumpall.c +++ b/src/bin/pg_dump/pg_dumpall.c @@ -785,11 +785,11 @@ dropRoles(PGconn *conn) int i_rolname; int i; - printfPQExpBuffer(buf, - "SELECT rolname " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 1", role_catalog); + printfPQExpBuffer(buf, + "SELECT rolname " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 1", role_catalog); res = executeQuery(conn, buf->data); @@ -843,16 +843,16 @@ dumpRoles(PGconn *conn) * Notes: rolconfig is dumped later, and pg_authid must be used for * extracting rolcomment regardless of role_catalog. */ - printfPQExpBuffer(buf, - "SELECT oid, rolname, rolsuper, rolinherit, " - "rolcreaterole, rolcreatedb, " - "rolcanlogin, rolconnlimit, rolpassword, " - "rolvaliduntil, rolreplication, rolbypassrls, " - "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " - "rolname = current_user AS is_current_user " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 2", role_catalog); + printfPQExpBuffer(buf, + "SELECT oid, rolname, rolsuper, rolinherit, " + "rolcreaterole, rolcreatedb, " + "rolcanlogin, rolconnlimit, rolpassword, " + "rolvaliduntil, rolreplication, rolbypassrls, " + "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " + "rolname = current_user AS is_current_user " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 2", role_catalog); res = executeQuery(conn, buf->data); diff --git a/src/bin/pg_upgrade/check.c b/src/bin/pg_upgrade/check.c index 786c1474829..f725f5ee3e2 100644 --- a/src/bin/pg_upgrade/check.c +++ b/src/bin/pg_upgrade/check.c @@ -1475,15 +1475,15 @@ check_for_incompatible_polymorphics(ClusterInfo *cluster) ", 'array_cat(anyarray,anyarray)'" ", 'array_prepend(anyelement,anyarray)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_remove(anyarray,anyelement)'" - ", 'array_replace(anyarray,anyelement,anyelement)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_remove(anyarray,anyelement)'" + ", 'array_replace(anyarray,anyelement,anyelement)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_position(anyarray,anyelement)'" - ", 'array_position(anyarray,anyelement,integer)'" - ", 'array_positions(anyarray,anyelement)'" - ", 'width_bucket(anyelement,anyarray)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_position(anyarray,anyelement)'" + ", 'array_position(anyarray,anyelement,integer)'" + ", 'array_positions(anyarray,anyelement)'" + ", 'width_bucket(anyelement,anyarray)'"); /* * The query below hardcodes FirstNormalObjectId as 16384 rather than diff --git a/src/bin/pg_upgrade/controldata.c b/src/bin/pg_upgrade/controldata.c index 8f81c9e9582..02ea02df60f 100644 --- a/src/bin/pg_upgrade/controldata.c +++ b/src/bin/pg_upgrade/controldata.c @@ -228,7 +228,7 @@ get_control_data(ClusterInfo *cluster) p++; /* remove ':' char */ cluster->controldata.chkpnt_nxtepoch = str2uint(p); - p = strchr(p, ':'); + p = strchr(p, ':'); if (p == NULL || strlen(p) <= 1) pg_fatal("%d: controldata retrieval problem", __LINE__); diff --git a/src/bin/pg_upgrade/exec.c b/src/bin/pg_upgrade/exec.c index 44355feea30..a1bdbf373e3 100644 --- a/src/bin/pg_upgrade/exec.c +++ b/src/bin/pg_upgrade/exec.c @@ -55,7 +55,7 @@ get_bin_version(ClusterInfo *cluster) if (sscanf(cmd_output, "%*s %*s %d.%d", &v1, &v2) < 1) pg_fatal("could not get pg_ctl version output from %s", cmd); - cluster->bin_version = v1 * 10000; + cluster->bin_version = v1 * 10000; } @@ -344,8 +344,8 @@ check_data_dir(ClusterInfo *cluster) check_single_dir(pg_data, "pg_subtrans"); check_single_dir(pg_data, PG_TBLSPC_DIR); check_single_dir(pg_data, "pg_twophase"); - check_single_dir(pg_data, "pg_wal"); - check_single_dir(pg_data, "pg_xact"); + check_single_dir(pg_data, "pg_wal"); + check_single_dir(pg_data, "pg_xact"); } @@ -385,7 +385,7 @@ check_bin_dir(ClusterInfo *cluster, bool check_versions) */ get_bin_version(cluster); - check_exec(cluster->bindir, "pg_resetwal", check_versions); + check_exec(cluster->bindir, "pg_resetwal", check_versions); if (cluster == &new_cluster) { diff --git a/src/bin/pg_upgrade/multixact_rewrite.c b/src/bin/pg_upgrade/multixact_rewrite.c index c45b3183684..c7a1416494d 100644 --- a/src/bin/pg_upgrade/multixact_rewrite.c +++ b/src/bin/pg_upgrade/multixact_rewrite.c @@ -61,52 +61,52 @@ rewrite_multixacts(MultiXactId from_multi, MultiXactId to_multi) * Convert old multixids, if needed, by reading them one-by-one from the * old cluster. */ - old_reader = AllocOldMultiXactRead(old_cluster.pgdata, - old_cluster.controldata.chkpnt_nxtmulti, - old_cluster.controldata.chkpnt_nxtmxoff); + old_reader = AllocOldMultiXactRead(old_cluster.pgdata, + old_cluster.controldata.chkpnt_nxtmulti, + old_cluster.controldata.chkpnt_nxtmxoff); - for (MultiXactId multi = from_multi; multi != to_multi;) - { - MultiXactMember member; - bool multixid_valid; - - /* - * Read this multixid's members. - * - * Locking-only XIDs that may be part of multi-xids don't matter - * after upgrade, as there can be no transactions running across - * upgrade. So as a small optimization, we only read one member - * from each multixid: the one updating one, or if there was no - * update, arbitrarily the first locking xid. - */ - multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); + for (MultiXactId multi = from_multi; multi != to_multi;) + { + MultiXactMember member; + bool multixid_valid; - /* - * Write the new offset to pg_multixact/offsets. - * - * Even if this multixid is invalid, we still need to write its - * offset if the *previous* multixid was valid. That's because - * when reading a multixid, the number of members is calculated - * from the difference between the two offsets. - */ - RecordMultiXactOffset(offsets_writer, multi, - (multixid_valid || prev_multixid_valid) ? next_offset : 0); + /* + * Read this multixid's members. + * + * Locking-only XIDs that may be part of multi-xids don't matter after + * upgrade, as there can be no transactions running across upgrade. So + * as a small optimization, we only read one member from each + * multixid: the one updating one, or if there was no update, + * arbitrarily the first locking xid. + */ + multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); - /* Write the members */ - if (multixid_valid) - { - RecordMultiXactMembers(members_writer, next_offset, 1, &member); - next_offset += 1; - } + /* + * Write the new offset to pg_multixact/offsets. + * + * Even if this multixid is invalid, we still need to write its offset + * if the *previous* multixid was valid. That's because when reading + * a multixid, the number of members is calculated from the difference + * between the two offsets. + */ + RecordMultiXactOffset(offsets_writer, multi, + (multixid_valid || prev_multixid_valid) ? next_offset : 0); - /* Advance to next multixid, handling wraparound */ - multi++; - if (multi < FirstMultiXactId) - multi = FirstMultiXactId; - prev_multixid_valid = multixid_valid; + /* Write the members */ + if (multixid_valid) + { + RecordMultiXactMembers(members_writer, next_offset, 1, &member); + next_offset += 1; } - FreeOldMultiXactReader(old_reader); + /* Advance to next multixid, handling wraparound */ + multi++; + if (multi < FirstMultiXactId) + multi = FirstMultiXactId; + prev_multixid_valid = multixid_valid; + } + + FreeOldMultiXactReader(old_reader); /* Write the final 'next' offset to the last SLRU page */ RecordMultiXactOffset(offsets_writer, to_multi, diff --git a/src/bin/pg_upgrade/pg_upgrade.c b/src/bin/pg_upgrade/pg_upgrade.c index c6af9035665..7366fd4627c 100644 --- a/src/bin/pg_upgrade/pg_upgrade.c +++ b/src/bin/pg_upgrade/pg_upgrade.c @@ -833,7 +833,7 @@ copy_xact_xlog_xid(void) * Determine the range of multixacts to convert. */ nxtmulti = old_cluster.controldata.chkpnt_nxtmulti; - oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; + oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; /* handle wraparound */ if (nxtmulti < FirstMultiXactId) nxtmulti = FirstMultiXactId; @@ -898,15 +898,15 @@ set_frozenxids(void) int i_datname; int i_datallowconn; - prep_status("Setting frozenxid and minmxid counters in new cluster"); + prep_status("Setting frozenxid and minmxid counters in new cluster"); conn_template1 = connectToServer(&new_cluster, "template1"); - /* set pg_database.datfrozenxid */ - PQclear(executeQueryOrDie(conn_template1, - "UPDATE pg_catalog.pg_database " - "SET datfrozenxid = '%u'", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_database.datfrozenxid */ + PQclear(executeQueryOrDie(conn_template1, + "UPDATE pg_catalog.pg_database " + "SET datfrozenxid = '%u'", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_database.datminmxid */ PQclear(executeQueryOrDie(conn_template1, @@ -942,16 +942,16 @@ set_frozenxids(void) conn = connectToServer(&new_cluster, datname); - /* set pg_class.relfrozenxid */ - PQclear(executeQueryOrDie(conn, - "UPDATE pg_catalog.pg_class " - "SET relfrozenxid = '%u' " - /* only heap, materialized view, and TOAST are vacuumed */ - "WHERE relkind IN (" - CppAsString2(RELKIND_RELATION) ", " - CppAsString2(RELKIND_MATVIEW) ", " - CppAsString2(RELKIND_TOASTVALUE) ")", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_class.relfrozenxid */ + PQclear(executeQueryOrDie(conn, + "UPDATE pg_catalog.pg_class " + "SET relfrozenxid = '%u' " + /* only heap, materialized view, and TOAST are vacuumed */ + "WHERE relkind IN (" + CppAsString2(RELKIND_RELATION) ", " + CppAsString2(RELKIND_MATVIEW) ", " + CppAsString2(RELKIND_TOASTVALUE) ")", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_class.relminmxid */ PQclear(executeQueryOrDie(conn, diff --git a/src/bin/pg_upgrade/relfilenumber.c b/src/bin/pg_upgrade/relfilenumber.c index ec2ff7acb21..6c467bdc8a5 100644 --- a/src/bin/pg_upgrade/relfilenumber.c +++ b/src/bin/pg_upgrade/relfilenumber.c @@ -587,32 +587,32 @@ transfer_relfile(FileNameMap *map, const char *type_suffix) /* Copying files might take some time, so give feedback. */ pg_log(PG_STATUS, "%s", old_file); - switch (user_opts.transfer_mode) - { - case TRANSFER_MODE_CLONE: - pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", - old_file, new_file); - cloneFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", - old_file, new_file); - copyFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY_FILE_RANGE: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", - old_file, new_file); - copyFileByRange(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_LINK: - pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", - old_file, new_file); - linkFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_SWAP: - /* swap mode is handled in its own code path */ - pg_fatal("should never happen"); - break; - } + switch (user_opts.transfer_mode) + { + case TRANSFER_MODE_CLONE: + pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", + old_file, new_file); + cloneFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", + old_file, new_file); + copyFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY_FILE_RANGE: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", + old_file, new_file); + copyFileByRange(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_LINK: + pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", + old_file, new_file); + linkFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_SWAP: + /* swap mode is handled in its own code path */ + pg_fatal("should never happen"); + break; + } } } diff --git a/src/bin/pg_upgrade/t/006_transfer_modes.pl b/src/bin/pg_upgrade/t/006_transfer_modes.pl index 9efa5dc863c..360d05c4b68 100644 --- a/src/bin/pg_upgrade/t/006_transfer_modes.pl +++ b/src/bin/pg_upgrade/t/006_transfer_modes.pl @@ -29,10 +29,8 @@ sub test_mode } $new->init(); - $new->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); - $old->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); + $new->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); + $old->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); # We can only test security labels if both the old and new installations # have dummy_seclabel. @@ -76,15 +74,14 @@ sub test_mode "CREATE TABLE test4 AS SELECT generate_series(400, 502)"); } - $old->safe_psql('postgres', - "CREATE TABLESPACE inplc_tblspc LOCATION ''"); - $old->safe_psql('postgres', - "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); - $old->safe_psql('postgres', - "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" - ); - $old->safe_psql('testdb3', - "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); + $old->safe_psql('postgres', "CREATE TABLESPACE inplc_tblspc LOCATION ''"); + $old->safe_psql('postgres', + "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); + $old->safe_psql('postgres', + "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" + ); + $old->safe_psql('testdb3', + "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); # While we are here, test handling of large objects. $old->safe_psql( @@ -152,12 +149,10 @@ sub test_mode } # Tests for in-place tablespaces. - $result = - $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); - is($result, '104', "test5 data after pg_upgrade $mode"); - $result = - $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); - is($result, '105', "test6 data after pg_upgrade $mode"); + $result = $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); + is($result, '104', "test5 data after pg_upgrade $mode"); + $result = $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); + is($result, '105', "test6 data after pg_upgrade $mode"); # Tests for large objects $result = $new->safe_psql('postgres', "SELECT lo_get(4532)"); diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index 44ef11d980e..c90bf8bbde2 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -6278,23 +6278,22 @@ get_create_object_cmd(EditableObjectType obj_type, Oid oid, * ensure the right view gets replaced. Also, check relation kind * to be sure it's a view. * - * Views may have WITH [LOCAL|CASCADED] - * CHECK OPTION. These are not part of the view definition - * returned by pg_get_viewdef() and so need to be retrieved - * separately. Materialized views may have - * arbitrary storage parameter reloptions. + * Views may have WITH [LOCAL|CASCADED] CHECK OPTION. These are + * not part of the view definition returned by pg_get_viewdef() + * and so need to be retrieved separately. Materialized views may + * have arbitrary storage parameter reloptions. */ printfPQExpBuffer(query, "/* %s */\n", _("Get view's definition and details")); - appendPQExpBuffer(query, - "SELECT nspname, relname, relkind, " - "pg_catalog.pg_get_viewdef(c.oid, true), " - "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " - "FROM pg_catalog.pg_class c " - "LEFT JOIN pg_catalog.pg_namespace n " - "ON c.relnamespace = n.oid WHERE c.oid = %u", - oid); + appendPQExpBuffer(query, + "SELECT nspname, relname, relkind, " + "pg_catalog.pg_get_viewdef(c.oid, true), " + "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " + "FROM pg_catalog.pg_class c " + "LEFT JOIN pg_catalog.pg_namespace n " + "ON c.relnamespace = n.oid WHERE c.oid = %u", + oid); break; } diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index ce99137c613..ac0c55e7aa5 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -387,19 +387,19 @@ describeFunctions(const char *functypes, const char *func_pattern, gettext_noop("stable"), gettext_noop("volatile"), gettext_noop("Volatility")); - appendPQExpBuffer(&buf, - ",\n CASE\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" - " END as \"%s\"", - gettext_noop("restricted"), - gettext_noop("safe"), - gettext_noop("unsafe"), - gettext_noop("Parallel")); + appendPQExpBuffer(&buf, + ",\n CASE\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" + " END as \"%s\"", + gettext_noop("restricted"), + gettext_noop("safe"), + gettext_noop("unsafe"), + gettext_noop("Parallel")); appendPQExpBuffer(&buf, ",\n pg_catalog.pg_get_userbyid(p.proowner) as \"%s\"" ",\n CASE WHEN prosecdef THEN '%s' ELSE '%s' END AS \"%s\"" @@ -599,8 +599,8 @@ describeFunctions(const char *functypes, const char *func_pattern, myopt.title = _("List of functions"); myopt.translate_header = true; - myopt.translate_columns = translate_columns; - myopt.n_translate_columns = lengthof(translate_columns); + myopt.translate_columns = translate_columns; + myopt.n_translate_columns = lengthof(translate_columns); printQuery(res, &myopt, pset.queryFout, false, pset.logfile); @@ -1086,38 +1086,38 @@ permissionsList(const char *pattern, bool showSystem) " ), E'\\n') AS \"%s\"", gettext_noop("Column privileges")); - appendPQExpBuffer(&buf, - ",\n pg_catalog.array_to_string(ARRAY(\n" - " SELECT polname\n" - " || CASE WHEN NOT polpermissive THEN\n" - " E' (RESTRICTIVE)'\n" - " ELSE '' END\n" - " || CASE WHEN polcmd != '*' THEN\n" - " E' (' || polcmd::pg_catalog.text || E'):'\n" - " ELSE E':'\n" - " END\n" - " || CASE WHEN polqual IS NOT NULL THEN\n" - " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" - " ELSE E''\n" - " END\n" - " || CASE WHEN polwithcheck IS NOT NULL THEN\n" - " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" - " ELSE E''\n" - " END" - " || CASE WHEN polroles <> '{0}' THEN\n" - " E'\\n to: ' || pg_catalog.array_to_string(\n" - " ARRAY(\n" - " SELECT rolname\n" - " FROM pg_catalog.pg_roles\n" - " WHERE oid = ANY (polroles)\n" - " ORDER BY 1\n" - " ), E', ')\n" - " ELSE E''\n" - " END\n" - " FROM pg_catalog.pg_policy pol\n" - " WHERE polrelid = c.oid), E'\\n')\n" - " AS \"%s\"", - gettext_noop("Policies")); + appendPQExpBuffer(&buf, + ",\n pg_catalog.array_to_string(ARRAY(\n" + " SELECT polname\n" + " || CASE WHEN NOT polpermissive THEN\n" + " E' (RESTRICTIVE)'\n" + " ELSE '' END\n" + " || CASE WHEN polcmd != '*' THEN\n" + " E' (' || polcmd::pg_catalog.text || E'):'\n" + " ELSE E':'\n" + " END\n" + " || CASE WHEN polqual IS NOT NULL THEN\n" + " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" + " ELSE E''\n" + " END\n" + " || CASE WHEN polwithcheck IS NOT NULL THEN\n" + " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" + " ELSE E''\n" + " END" + " || CASE WHEN polroles <> '{0}' THEN\n" + " E'\\n to: ' || pg_catalog.array_to_string(\n" + " ARRAY(\n" + " SELECT rolname\n" + " FROM pg_catalog.pg_roles\n" + " WHERE oid = ANY (polroles)\n" + " ORDER BY 1\n" + " ), E', ')\n" + " ELSE E''\n" + " END\n" + " FROM pg_catalog.pg_policy pol\n" + " WHERE polrelid = c.oid), E'\\n')\n" + " AS \"%s\"", + gettext_noop("Policies")); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_class c\n" " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n" @@ -1675,27 +1675,27 @@ describeOneTableDetails(const char *schemaname, char *footers[3] = {NULL, NULL, NULL}; printfPQExpBuffer(&buf, "/* %s */\n", _("Get sequence information")); - appendPQExpBuffer(&buf, - "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" - " seqstart AS \"%s\",\n" - " seqmin AS \"%s\",\n" - " seqmax AS \"%s\",\n" - " seqincrement AS \"%s\",\n" - " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" - " seqcache AS \"%s\"\n", - gettext_noop("Type"), - gettext_noop("Start"), - gettext_noop("Minimum"), - gettext_noop("Maximum"), - gettext_noop("Increment"), - gettext_noop("yes"), - gettext_noop("no"), - gettext_noop("Cycles?"), - gettext_noop("Cache")); - appendPQExpBuffer(&buf, - "FROM pg_catalog.pg_sequence\n" - "WHERE seqrelid = '%s';", - oid); + appendPQExpBuffer(&buf, + "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" + " seqstart AS \"%s\",\n" + " seqmin AS \"%s\",\n" + " seqmax AS \"%s\",\n" + " seqincrement AS \"%s\",\n" + " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" + " seqcache AS \"%s\"\n", + gettext_noop("Type"), + gettext_noop("Start"), + gettext_noop("Minimum"), + gettext_noop("Maximum"), + gettext_noop("Increment"), + gettext_noop("yes"), + gettext_noop("no"), + gettext_noop("Cycles?"), + gettext_noop("Cache")); + appendPQExpBuffer(&buf, + "FROM pg_catalog.pg_sequence\n" + "WHERE seqrelid = '%s';", + oid); res = PSQLexec(buf.data); if (!res) @@ -1913,7 +1913,7 @@ describeOneTableDetails(const char *schemaname, appendPQExpBufferStr(&buf, ",\n (SELECT c.collname FROM pg_catalog.pg_collation c, pg_catalog.pg_type t\n" " WHERE c.oid = a.attcollation AND t.oid = a.atttypid AND a.attcollation <> t.typcollation) AS attcollation"); attcoll_col = cols++; - appendPQExpBufferStr(&buf, ",\n a.attidentity"); + appendPQExpBufferStr(&buf, ",\n a.attidentity"); attidentity_col = cols++; if (pset.sversion >= 120000) appendPQExpBufferStr(&buf, ",\n a.attgenerated"); @@ -2326,7 +2326,7 @@ describeOneTableDetails(const char *schemaname, CppAsString2(CONSTRAINT_EXCLUSION) ") AND " "condeferred) AS condeferred,\n"); - appendPQExpBufferStr(&buf, "i.indisreplident,\n"); + appendPQExpBufferStr(&buf, "i.indisreplident,\n"); if (pset.sversion >= 150000) appendPQExpBufferStr(&buf, "i.indnullsnotdistinct,\n"); @@ -2431,7 +2431,7 @@ describeOneTableDetails(const char *schemaname, "pg_catalog.pg_get_indexdef(i.indexrelid, 0, true),\n " "pg_catalog.pg_get_constraintdef(con.oid, true), " "contype, condeferrable, condeferred"); - appendPQExpBufferStr(&buf, ", i.indisreplident"); + appendPQExpBufferStr(&buf, ", i.indisreplident"); appendPQExpBufferStr(&buf, ", c2.reltablespace"); if (pset.sversion >= 180000) appendPQExpBufferStr(&buf, ", con.conperiod"); @@ -2682,81 +2682,80 @@ describeOneTableDetails(const char *schemaname, PQclear(result); /* print any row-level policies */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get row-level policies for this table")); - appendPQExpBufferStr(&buf, "SELECT pol.polname,"); - appendPQExpBufferStr(&buf, - " pol.polpermissive,\n"); - appendPQExpBuffer(&buf, - " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" - " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" - " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" - " CASE pol.polcmd\n" - " WHEN 'r' THEN 'SELECT'\n" - " WHEN 'a' THEN 'INSERT'\n" - " WHEN 'w' THEN 'UPDATE'\n" - " WHEN 'd' THEN 'DELETE'\n" - " END AS cmd\n" - "FROM pg_catalog.pg_policy pol\n" - "WHERE pol.polrelid = '%s' ORDER BY 1;", - oid); + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get row-level policies for this table")); + appendPQExpBufferStr(&buf, "SELECT pol.polname,"); + appendPQExpBufferStr(&buf, + " pol.polpermissive,\n"); + appendPQExpBuffer(&buf, + " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" + " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" + " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" + " CASE pol.polcmd\n" + " WHEN 'r' THEN 'SELECT'\n" + " WHEN 'a' THEN 'INSERT'\n" + " WHEN 'w' THEN 'UPDATE'\n" + " WHEN 'd' THEN 'DELETE'\n" + " END AS cmd\n" + "FROM pg_catalog.pg_policy pol\n" + "WHERE pol.polrelid = '%s' ORDER BY 1;", + oid); - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - /* - * Handle cases where RLS is enabled and there are policies, or - * there aren't policies, or RLS isn't enabled but there are - * policies - */ - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies:")); + /* + * Handle cases where RLS is enabled and there are policies, or there + * aren't policies, or RLS isn't enabled but there are policies + */ + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies:")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled):")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled):")); - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); - if (!tableinfo.rowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (row security disabled):")); + if (!tableinfo.rowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (row security disabled):")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " POLICY \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " POLICY \"%s\"", + PQgetvalue(result, i, 0)); - if (*(PQgetvalue(result, i, 1)) == 'f') - appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); + if (*(PQgetvalue(result, i, 1)) == 'f') + appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); - if (!PQgetisnull(result, i, 5)) - appendPQExpBuffer(&buf, " FOR %s", - PQgetvalue(result, i, 5)); + if (!PQgetisnull(result, i, 5)) + appendPQExpBuffer(&buf, " FOR %s", + PQgetvalue(result, i, 5)); - if (!PQgetisnull(result, i, 2)) - { - appendPQExpBuffer(&buf, "\n TO %s", - PQgetvalue(result, i, 2)); - } + if (!PQgetisnull(result, i, 2)) + { + appendPQExpBuffer(&buf, "\n TO %s", + PQgetvalue(result, i, 2)); + } - if (!PQgetisnull(result, i, 3)) - appendPQExpBuffer(&buf, "\n USING (%s)", - PQgetvalue(result, i, 3)); + if (!PQgetisnull(result, i, 3)) + appendPQExpBuffer(&buf, "\n USING (%s)", + PQgetvalue(result, i, 3)); - if (!PQgetisnull(result, i, 4)) - appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", - PQgetvalue(result, i, 4)); + if (!PQgetisnull(result, i, 4)) + appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", + PQgetvalue(result, i, 4)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* print any extended statistics */ if (pset.sversion >= 140000) @@ -3025,115 +3024,115 @@ describeOneTableDetails(const char *schemaname, } /* print any publications */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get publications that publish this table")); - if (pset.sversion >= 150000) + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get publications that publish this table")); + if (pset.sversion >= 150000) + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" + " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" + "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" + "UNION\n" + "SELECT pubname\n" + " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" + " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" + " (SELECT pg_catalog.string_agg(attname, ', ')\n" + " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" + " pg_catalog.pg_attribute\n" + " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" + " ELSE NULL END) " + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" + "WHERE pr.prrelid = '%s'\n", + oid, oid, oid); + + if (pset.sversion >= 190000) { + /* + * Skip entries where this relation appears in the + * publication's EXCEPT list. + */ appendPQExpBuffer(&buf, + " AND NOT pr.prexcept\n" + "UNION\n" "SELECT pubname\n" " , NULL\n" " , NULL\n" "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" - " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" - "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" - "UNION\n" - "SELECT pubname\n" - " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" - " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" - " (SELECT pg_catalog.string_agg(attname, ', ')\n" - " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" - " pg_catalog.pg_attribute\n" - " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" - " ELSE NULL END) " - "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" - "WHERE pr.prrelid = '%s'\n", + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + " AND NOT EXISTS (\n" + " SELECT 1\n" + " FROM pg_catalog.pg_publication_rel pr\n" + " WHERE pr.prpubid = p.oid AND\n" + " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" + "ORDER BY 1;", oid, oid, oid); - - if (pset.sversion >= 190000) - { - /* - * Skip entries where this relation appears in the - * publication's EXCEPT list. - */ - appendPQExpBuffer(&buf, - " AND NOT pr.prexcept\n" - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - " AND NOT EXISTS (\n" - " SELECT 1\n" - " FROM pg_catalog.pg_publication_rel pr\n" - " WHERE pr.prpubid = p.oid AND\n" - " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" - "ORDER BY 1;", - oid, oid, oid); - } - else - { - appendPQExpBuffer(&buf, - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - "ORDER BY 1;", - oid); - } } else { appendPQExpBuffer(&buf, + "UNION\n" "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - "WHERE pr.prrelid = '%s'\n" - "UNION ALL\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" + " , NULL\n" + " , NULL\n" "FROM pg_catalog.pg_publication p\n" "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" "ORDER BY 1;", - oid, oid); + oid); } + } + else + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + "WHERE pr.prrelid = '%s'\n" + "UNION ALL\n" + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + "ORDER BY 1;", + oid, oid); + } - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - if (tuples > 0) - printTableAddFooter(&cont, _("Included in publications:")); + if (tuples > 0) + printTableAddFooter(&cont, _("Included in publications:")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " \"%s\"", + PQgetvalue(result, i, 0)); - /* column list (if any) */ - if (!PQgetisnull(result, i, 2)) - appendPQExpBuffer(&buf, " (%s)", - PQgetvalue(result, i, 2)); + /* column list (if any) */ + if (!PQgetisnull(result, i, 2)) + appendPQExpBuffer(&buf, " (%s)", + PQgetvalue(result, i, 2)); - /* row filter (if any) */ - if (!PQgetisnull(result, i, 1)) - appendPQExpBuffer(&buf, " WHERE %s", - PQgetvalue(result, i, 1)); + /* row filter (if any) */ + if (!PQgetisnull(result, i, 1)) + appendPQExpBuffer(&buf, " WHERE %s", + PQgetvalue(result, i, 1)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* Print publications where the table is in the EXCEPT clause */ if (pset.sversion >= 190000) @@ -3805,7 +3804,7 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) ncols++; } appendPQExpBufferStr(&buf, "\n, r.rolreplication"); - appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); + appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_roles r\n"); @@ -3860,8 +3859,8 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) if (strcmp(PQgetvalue(res, i, (verbose ? 9 : 8)), "t") == 0) add_role_attribute(&buf, _("Replication")); - if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) - add_role_attribute(&buf, _("Bypass RLS")); + if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) + add_role_attribute(&buf, _("Bypass RLS")); conns = atoi(PQgetvalue(res, i, 6)); if (conns >= 0) @@ -5155,14 +5154,14 @@ listCollations(const char *pattern, bool verbose, bool showSystem) gettext_noop("Schema"), gettext_noop("Name")); - appendPQExpBuffer(&buf, - " CASE c.collprovider " - "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " - "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " - "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " - "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " - "END AS \"%s\",\n", - gettext_noop("Provider")); + appendPQExpBuffer(&buf, + " CASE c.collprovider " + "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " + "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " + "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " + "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " + "END AS \"%s\",\n", + gettext_noop("Provider")); appendPQExpBuffer(&buf, " c.collcollate AS \"%s\",\n" -- 2.50.1 (Apple Git-155) --aHl3HfeiUuO3zeNC-- ^ permalink raw reply [nested|flat] 59+ messages in thread
* [PATCH v6 4/4] run pgindent and pgperltidy @ 2026-06-30 18:24 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 59+ messages in thread From: Nathan Bossart @ 2026-06-30 18:24 UTC (permalink / raw) --- src/bin/pg_dump/pg_dump.c | 464 ++++++++++----------- src/bin/pg_dump/pg_dumpall.c | 30 +- src/bin/pg_upgrade/check.c | 16 +- src/bin/pg_upgrade/controldata.c | 2 +- src/bin/pg_upgrade/exec.c | 8 +- src/bin/pg_upgrade/multixact_rewrite.c | 80 ++-- src/bin/pg_upgrade/pg_upgrade.c | 34 +- src/bin/pg_upgrade/relfilenumber.c | 54 +-- src/bin/pg_upgrade/t/006_transfer_modes.pl | 33 +- src/bin/psql/command.c | 29 +- src/bin/psql/describe.c | 461 ++++++++++---------- 11 files changed, 601 insertions(+), 610 deletions(-) diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 65bd15ebfd2..5673268b467 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -1491,8 +1491,8 @@ setup_connection(Archive *AH, const char *dumpencoding, * Disable timeouts if supported. */ ExecuteSqlStatement(AH, "SET statement_timeout = 0"); - ExecuteSqlStatement(AH, "SET lock_timeout = 0"); - ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); + ExecuteSqlStatement(AH, "SET lock_timeout = 0"); + ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); if (AH->remoteVersion >= 170000) ExecuteSqlStatement(AH, "SET transaction_timeout = 0"); @@ -1505,10 +1505,10 @@ setup_connection(Archive *AH, const char *dumpencoding, /* * Adjust row-security mode, if supported. */ - if (dopt->enable_row_security) - ExecuteSqlStatement(AH, "SET row_security = on"); - else - ExecuteSqlStatement(AH, "SET row_security = off"); + if (dopt->enable_row_security) + ExecuteSqlStatement(AH, "SET row_security = on"); + else + ExecuteSqlStatement(AH, "SET row_security = off"); /* * For security reasons, we restrict the expansion of non-system views and @@ -1933,10 +1933,9 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) addObjectDependency(dobj, ext->dobj.dumpId); /* - * Mark the member object to have any non-initial ACLs - * dumped. (Any initial ACLs will be removed later, using data from - * pg_init_privs, so that we'll dump only the delta from the extension's - * initial setup.) + * Mark the member object to have any non-initial ACLs dumped. (Any + * initial ACLs will be removed later, using data from pg_init_privs, so + * that we'll dump only the delta from the extension's initial setup.) * * In binary upgrades, we still dump all components of the members * individually, since the idea is to exactly reproduce the database @@ -1953,7 +1952,7 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) if (fout->dopt->binary_upgrade) dobj->dump = ext->dobj.dump; else - dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); + dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); return true; } @@ -1987,9 +1986,9 @@ selectDumpableNamespace(NamespaceInfo *nsinfo, Archive *fout) else if (strcmp(nsinfo->dobj.name, "pg_catalog") == 0) { /* - * We dump out any ACLs defined in pg_catalog, if - * they are interesting (and not the original ACLs which were set at - * initdb time, see pg_init_privs). + * We dump out any ACLs defined in pg_catalog, if they are interesting + * (and not the original ACLs which were set at initdb time, see + * pg_init_privs). */ nsinfo->dobj.dump_contains = nsinfo->dobj.dump = DUMP_COMPONENT_ACL; } @@ -3296,7 +3295,7 @@ dumpDatabase(Archive *fout) "datcollate, datctype, datfrozenxid, " "datacl, acldefault('d', datdba) AS acldefault, " "datistemplate, datconnlimit, "); - appendPQExpBufferStr(dbQry, "datminmxid, "); + appendPQExpBufferStr(dbQry, "datminmxid, "); if (fout->remoteVersion >= 170000) appendPQExpBufferStr(dbQry, "datlocprovider, datlocale, datcollversion, "); else if (fout->remoteVersion >= 150000) @@ -3638,11 +3637,11 @@ dumpDatabase(Archive *fout) ii_oid, ii_relminmxid; - appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" - "FROM pg_catalog.pg_class\n" - "WHERE oid IN (%u, %u, %u, %u);\n", - LargeObjectRelationId, LargeObjectLOidPNIndexId, - LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); + appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" + "FROM pg_catalog.pg_class\n" + "WHERE oid IN (%u, %u, %u, %u);\n", + LargeObjectRelationId, LargeObjectLOidPNIndexId, + LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); lo_res = ExecuteSqlQuery(fout, loFrozenQry->data, PGRES_TUPLES_OK); @@ -4274,7 +4273,7 @@ getPolicies(Archive *fout, TableInfo tblinfo[], int numTables) printfPQExpBuffer(query, "SELECT pol.oid, pol.tableoid, pol.polrelid, pol.polname, pol.polcmd, "); - appendPQExpBufferStr(query, "pol.polpermissive, "); + appendPQExpBufferStr(query, "pol.polpermissive, "); appendPQExpBuffer(query, "CASE WHEN pol.polroles = '{0}' THEN NULL ELSE " " pg_catalog.array_to_string(ARRAY(SELECT pg_catalog.quote_ident(rolname) from pg_catalog.pg_roles WHERE oid = ANY(pol.polroles)), ', ') END AS polroles, " @@ -6633,9 +6632,9 @@ getAccessMethods(Archive *fout) * Select all access methods from pg_am table. */ appendPQExpBufferStr(query, "SELECT tableoid, oid, amname, "); - appendPQExpBufferStr(query, - "amtype, " - "amhandler::pg_catalog.regproc AS amhandler "); + appendPQExpBufferStr(query, + "amtype, " + "amhandler::pg_catalog.regproc AS amhandler "); appendPQExpBufferStr(query, "FROM pg_am"); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6827,35 +6826,35 @@ getAggregates(Archive *fout) * Find all interesting aggregates. See comment in getFuncs() for the * rationale behind the filtering logic. */ - agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" - : "p.proisagg"); + agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" + : "p.proisagg"); - appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " - "p.proname AS aggname, " - "p.pronamespace AS aggnamespace, " - "p.pronargs, p.proargtypes, " - "p.proowner, " - "p.proacl AS aggacl, " - "acldefault('f', p.proowner) AS acldefault " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s AND (" - "p.pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog') OR " - "p.proacl IS DISTINCT FROM pip.initprivs", - agg_check); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - " OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); - appendPQExpBufferChar(query, ')'); + appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " + "p.proname AS aggname, " + "p.pronamespace AS aggnamespace, " + "p.pronargs, p.proargtypes, " + "p.proowner, " + "p.proacl AS aggacl, " + "acldefault('f', p.proowner) AS acldefault " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s AND (" + "p.pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog') OR " + "p.proacl IS DISTINCT FROM pip.initprivs", + agg_check); + if (dopt->binary_upgrade) + appendPQExpBufferStr(query, + " OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6957,53 +6956,53 @@ getFuncs(Archive *fout) * include them, since we want to dump extension members individually in * that mode. Also, if they are used by casts or transforms then we need * to gather the information about them, though they won't be dumped if - * they are built-in. Also, include functions in - * pg_catalog if they have an ACL different from what's shown in - * pg_init_privs (so we have to join to pg_init_privs; annoying). + * they are built-in. Also, include functions in pg_catalog if they have + * an ACL different from what's shown in pg_init_privs (so we have to join + * to pg_init_privs; annoying). */ - not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" - : "NOT p.proisagg"); + not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" + : "NOT p.proisagg"); - appendPQExpBuffer(query, - "SELECT p.tableoid, p.oid, p.proname, p.prolang, " - "p.pronargs, p.proargtypes, p.prorettype, " - "p.proacl, " - "acldefault('f', p.proowner) AS acldefault, " - "p.pronamespace, " - "p.proowner " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s" - "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " - "WHERE classid = 'pg_proc'::regclass AND " - "objid = p.oid AND deptype = 'i')" - "\n AND (" - "\n pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog')" - "\n OR EXISTS (SELECT 1 FROM pg_cast" - "\n WHERE pg_cast.oid > %u " - "\n AND p.oid = pg_cast.castfunc)" - "\n OR EXISTS (SELECT 1 FROM pg_transform" - "\n WHERE pg_transform.oid > %u AND " - "\n (p.oid = pg_transform.trffromsql" - "\n OR p.oid = pg_transform.trftosql))", - not_agg_check, - g_last_builtin_oid, - g_last_builtin_oid); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); + appendPQExpBuffer(query, + "SELECT p.tableoid, p.oid, p.proname, p.prolang, " + "p.pronargs, p.proargtypes, p.prorettype, " + "p.proacl, " + "acldefault('f', p.proowner) AS acldefault, " + "p.pronamespace, " + "p.proowner " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s" + "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " + "WHERE classid = 'pg_proc'::regclass AND " + "objid = p.oid AND deptype = 'i')" + "\n AND (" + "\n pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog')" + "\n OR EXISTS (SELECT 1 FROM pg_cast" + "\n WHERE pg_cast.oid > %u " + "\n AND p.oid = pg_cast.castfunc)" + "\n OR EXISTS (SELECT 1 FROM pg_transform" + "\n WHERE pg_transform.oid > %u AND " + "\n (p.oid = pg_transform.trffromsql" + "\n OR p.oid = pg_transform.trftosql))", + not_agg_check, + g_last_builtin_oid, + g_last_builtin_oid); + if (dopt->binary_upgrade) appendPQExpBufferStr(query, - "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); - appendPQExpBufferChar(query, ')'); + "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferStr(query, + "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -7252,31 +7251,31 @@ getTables(Archive *fout, int *numTables) appendPQExpBufferStr(query, "c.relhasoids, "); - appendPQExpBufferStr(query, - "c.relispopulated, "); + appendPQExpBufferStr(query, + "c.relispopulated, "); - appendPQExpBufferStr(query, - "c.relreplident, "); + appendPQExpBufferStr(query, + "c.relreplident, "); - appendPQExpBufferStr(query, - "c.relrowsecurity, c.relforcerowsecurity, "); + appendPQExpBufferStr(query, + "c.relrowsecurity, c.relforcerowsecurity, "); - appendPQExpBufferStr(query, - "c.relminmxid, tc.relminmxid AS tminmxid, "); + appendPQExpBufferStr(query, + "c.relminmxid, tc.relminmxid AS tminmxid, "); - appendPQExpBufferStr(query, - "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); + appendPQExpBufferStr(query, + "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); - appendPQExpBufferStr(query, - "am.amname, "); + appendPQExpBufferStr(query, + "am.amname, "); - appendPQExpBufferStr(query, - "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); + appendPQExpBufferStr(query, + "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); - appendPQExpBufferStr(query, - "c.relispartition AS ispartition "); + appendPQExpBufferStr(query, + "c.relispartition AS ispartition "); /* * Left join to pg_depend to pick up dependency info linking sequences to @@ -7296,8 +7295,8 @@ getTables(Archive *fout, int *numTables) /* * Left join to pg_am to pick up the amname. */ - appendPQExpBufferStr(query, - "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); + appendPQExpBufferStr(query, + "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); /* * We purposefully ignore toast OIDs for partitioned tables; the reason is @@ -7868,8 +7867,8 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables) "t.reloptions AS indreloptions, "); - appendPQExpBufferStr(query, - "i.indisreplident, "); + appendPQExpBufferStr(query, + "i.indisreplident, "); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -9313,8 +9312,8 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables) appendPQExpBufferStr(q, "'' AS attcompression,\n"); - appendPQExpBufferStr(q, - "a.attidentity,\n"); + appendPQExpBufferStr(q, + "a.attidentity,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(q, @@ -10717,73 +10716,73 @@ getAdditionalACLs(Archive *fout) PQclear(res); /* Fetch initial-privileges data */ - printfPQExpBuffer(query, - "SELECT objoid, classoid, objsubid, privtype, initprivs " - "FROM pg_init_privs"); + printfPQExpBuffer(query, + "SELECT objoid, classoid, objsubid, privtype, initprivs " + "FROM pg_init_privs"); - res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); + res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); - ntups = PQntuples(res); - for (i = 0; i < ntups; i++) - { - Oid objoid = atooid(PQgetvalue(res, i, 0)); - Oid classoid = atooid(PQgetvalue(res, i, 1)); - int objsubid = atoi(PQgetvalue(res, i, 2)); - char privtype = *(PQgetvalue(res, i, 3)); - char *initprivs = PQgetvalue(res, i, 4); - CatalogId objId; - DumpableObject *dobj; + ntups = PQntuples(res); + for (i = 0; i < ntups; i++) + { + Oid objoid = atooid(PQgetvalue(res, i, 0)); + Oid classoid = atooid(PQgetvalue(res, i, 1)); + int objsubid = atoi(PQgetvalue(res, i, 2)); + char privtype = *(PQgetvalue(res, i, 3)); + char *initprivs = PQgetvalue(res, i, 4); + CatalogId objId; + DumpableObject *dobj; - objId.tableoid = classoid; - objId.oid = objoid; - dobj = findObjectByCatalogId(objId); - /* OK to ignore entries we haven't got a DumpableObject for */ - if (dobj) + objId.tableoid = classoid; + objId.oid = objoid; + dobj = findObjectByCatalogId(objId); + /* OK to ignore entries we haven't got a DumpableObject for */ + if (dobj) + { + /* Cope with sub-object initprivs */ + if (objsubid != 0) { - /* Cope with sub-object initprivs */ - if (objsubid != 0) - { - if (dobj->objType == DO_TABLE) - { - /* For a column initprivs, set the table's ACL flags */ - dobj->components |= DUMP_COMPONENT_ACL; - ((TableInfo *) dobj)->hascolumnACLs = true; - } - else - pg_log_warning("unsupported pg_init_privs entry: %u %u %d", - classoid, objoid, objsubid); - continue; - } - - /* - * We ignore any pg_init_privs.initprivs entry for the public - * schema, as explained in getNamespaces(). - */ - if (dobj->objType == DO_NAMESPACE && - strcmp(dobj->name, "public") == 0) - continue; - - /* Else it had better be of a type we think has ACLs */ - if (dobj->objType == DO_NAMESPACE || - dobj->objType == DO_TYPE || - dobj->objType == DO_FUNC || - dobj->objType == DO_AGG || - dobj->objType == DO_TABLE || - dobj->objType == DO_PROCLANG || - dobj->objType == DO_FDW || - dobj->objType == DO_FOREIGN_SERVER) + if (dobj->objType == DO_TABLE) { - DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; - - daobj->dacl.privtype = privtype; - daobj->dacl.initprivs = pstrdup(initprivs); + /* For a column initprivs, set the table's ACL flags */ + dobj->components |= DUMP_COMPONENT_ACL; + ((TableInfo *) dobj)->hascolumnACLs = true; } else pg_log_warning("unsupported pg_init_privs entry: %u %u %d", classoid, objoid, objsubid); + continue; + } + + /* + * We ignore any pg_init_privs.initprivs entry for the public + * schema, as explained in getNamespaces(). + */ + if (dobj->objType == DO_NAMESPACE && + strcmp(dobj->name, "public") == 0) + continue; + + /* Else it had better be of a type we think has ACLs */ + if (dobj->objType == DO_NAMESPACE || + dobj->objType == DO_TYPE || + dobj->objType == DO_FUNC || + dobj->objType == DO_AGG || + dobj->objType == DO_TABLE || + dobj->objType == DO_PROCLANG || + dobj->objType == DO_FDW || + dobj->objType == DO_FOREIGN_SERVER) + { + DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; + + daobj->dacl.privtype = privtype; + daobj->dacl.initprivs = pstrdup(initprivs); } + else + pg_log_warning("unsupported pg_init_privs entry: %u %u %d", + classoid, objoid, objsubid); } - PQclear(res); + } + PQclear(res); destroyPQExpBuffer(query); } @@ -11128,8 +11127,8 @@ dumpRelationStats_dumper(Archive *fout, const void *userArg, const TocEntry *te) * The results must be in the order of the relations supplied in the * parameters to ensure we remain in sync as we walk through the TOC. * - * For versions before 19, the redundant filter clause on s.tablename = - * ANY(...) seems sufficient to convince the planner to use + * For versions before 19, the redundant filter clause on s.tablename + * = ANY(...) seems sufficient to convince the planner to use * pg_class_relname_nsp_index, which avoids a full scan of pg_stats. * In newer versions, pg_stats returns the table OIDs, eliminating the * need for that hack. @@ -13469,11 +13468,11 @@ dumpFunc(Archive *fout, const FuncInfo *finfo) "pg_catalog.pg_get_function_result(p.oid) AS funcresult,\n" "proleakproof,\n"); - appendPQExpBufferStr(query, - "array_to_string(protrftypes, ' ') AS protrftypes,\n"); + appendPQExpBufferStr(query, + "array_to_string(protrftypes, ' ') AS protrftypes,\n"); - appendPQExpBufferStr(query, - "proparallel,\n"); + appendPQExpBufferStr(query, + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -14963,9 +14962,9 @@ dumpCollation(Archive *fout, const CollInfo *collinfo) /* Get collation-specific details */ appendPQExpBufferStr(query, "SELECT "); - appendPQExpBufferStr(query, - "collprovider, " - "collversion, "); + appendPQExpBufferStr(query, + "collprovider, " + "collversion, "); if (fout->remoteVersion >= 120000) appendPQExpBufferStr(query, @@ -15372,23 +15371,23 @@ dumpAgg(Archive *fout, const AggInfo *agginfo) "pg_catalog.pg_get_function_arguments(p.oid) AS funcargs,\n" "pg_catalog.pg_get_function_identity_arguments(p.oid) AS funciargs,\n"); - appendPQExpBufferStr(query, - "aggkind,\n" - "aggmtransfn,\n" - "aggminvtransfn,\n" - "aggmfinalfn,\n" - "aggmtranstype::pg_catalog.regtype,\n" - "aggfinalextra,\n" - "aggmfinalextra,\n" - "aggtransspace,\n" - "aggmtransspace,\n" - "aggminitval,\n"); + appendPQExpBufferStr(query, + "aggkind,\n" + "aggmtransfn,\n" + "aggminvtransfn,\n" + "aggmfinalfn,\n" + "aggmtranstype::pg_catalog.regtype,\n" + "aggfinalextra,\n" + "aggmfinalextra,\n" + "aggtransspace,\n" + "aggmtransspace,\n" + "aggminitval,\n"); - appendPQExpBufferStr(query, - "aggcombinefn,\n" - "aggserialfn,\n" - "aggdeserialfn,\n" - "proparallel,\n"); + appendPQExpBufferStr(query, + "aggcombinefn,\n" + "aggserialfn,\n" + "aggdeserialfn,\n" + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -16848,30 +16847,30 @@ dumpTable(Archive *fout, const TableInfo *tbinfo) appendPQExpBufferStr(query, "PREPARE getColumnACLs(pg_catalog.oid) AS\n"); - /* - * In principle we should call acldefault('c', relowner) to - * get the default ACL for a column. However, we don't - * currently store the numeric OID of the relowner in - * TableInfo. We could convert the owner name using regrole, - * but that creates a risk of failure due to concurrent role - * renames. Given that the default ACL for columns is empty - * and is likely to stay that way, it's not worth extra cycles - * and risk to avoid hard-wiring that knowledge here. - */ - appendPQExpBufferStr(query, - "SELECT at.attname, " - "at.attacl, " - "'{}' AS acldefault, " - "pip.privtype, pip.initprivs " - "FROM pg_catalog.pg_attribute at " - "LEFT JOIN pg_catalog.pg_init_privs pip ON " - "(at.attrelid = pip.objoid " - "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " - "AND at.attnum = pip.objsubid) " - "WHERE at.attrelid = $1 AND " - "NOT at.attisdropped " - "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " - "ORDER BY at.attnum"); + /* + * In principle we should call acldefault('c', relowner) to get + * the default ACL for a column. However, we don't currently + * store the numeric OID of the relowner in TableInfo. We could + * convert the owner name using regrole, but that creates a risk + * of failure due to concurrent role renames. Given that the + * default ACL for columns is empty and is likely to stay that + * way, it's not worth extra cycles and risk to avoid hard-wiring + * that knowledge here. + */ + appendPQExpBufferStr(query, + "SELECT at.attname, " + "at.attacl, " + "'{}' AS acldefault, " + "pip.privtype, pip.initprivs " + "FROM pg_catalog.pg_attribute at " + "LEFT JOIN pg_catalog.pg_init_privs pip ON " + "(at.attrelid = pip.objoid " + "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " + "AND at.attnum = pip.objsubid) " + "WHERE at.attrelid = $1 AND " + "NOT at.attisdropped " + "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " + "ORDER BY at.attnum"); ExecuteSqlStatement(fout, query->data); @@ -19165,7 +19164,7 @@ collectSequences(Archive *fout) * pg_get_sequence_data(), but we only do so for non-schema-only dumps. */ if (fout->remoteVersion < 180000 || - (!fout->dopt->dumpData && !fout->dopt->sequence_data)) + (!fout->dopt->dumpData && !fout->dopt->sequence_data)) query = "SELECT seqrelid, format_type(seqtypid, NULL), " "seqstart, seqincrement, " "seqmax, seqmin, " @@ -19227,15 +19226,14 @@ dumpSequence(Archive *fout, const TableInfo *tbinfo) qseqname = pg_strdup(fmtId(tbinfo->dobj.name)); /* - * The sequence information is gathered in a sorted - * table before any calls to dumpSequence(). See collectSequences() for - * more information. + * The sequence information is gathered in a sorted table before any calls + * to dumpSequence(). See collectSequences() for more information. */ - Assert(sequences); + Assert(sequences); - key.oid = tbinfo->dobj.catId.oid; - seq = bsearch(&key, sequences, nsequences, - sizeof(SequenceItem), SequenceItemCmp); + key.oid = tbinfo->dobj.catId.oid; + seq = bsearch(&key, sequences, nsequences, + sizeof(SequenceItem), SequenceItemCmp); /* Calculate default limits for a sequence of this type */ is_ascending = (seq->incby >= 0); diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c index e68937c9934..afcd9a218d8 100644 --- a/src/bin/pg_dump/pg_dumpall.c +++ b/src/bin/pg_dump/pg_dumpall.c @@ -785,11 +785,11 @@ dropRoles(PGconn *conn) int i_rolname; int i; - printfPQExpBuffer(buf, - "SELECT rolname " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 1", role_catalog); + printfPQExpBuffer(buf, + "SELECT rolname " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 1", role_catalog); res = executeQuery(conn, buf->data); @@ -843,16 +843,16 @@ dumpRoles(PGconn *conn) * Notes: rolconfig is dumped later, and pg_authid must be used for * extracting rolcomment regardless of role_catalog. */ - printfPQExpBuffer(buf, - "SELECT oid, rolname, rolsuper, rolinherit, " - "rolcreaterole, rolcreatedb, " - "rolcanlogin, rolconnlimit, rolpassword, " - "rolvaliduntil, rolreplication, rolbypassrls, " - "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " - "rolname = current_user AS is_current_user " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 2", role_catalog); + printfPQExpBuffer(buf, + "SELECT oid, rolname, rolsuper, rolinherit, " + "rolcreaterole, rolcreatedb, " + "rolcanlogin, rolconnlimit, rolpassword, " + "rolvaliduntil, rolreplication, rolbypassrls, " + "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " + "rolname = current_user AS is_current_user " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 2", role_catalog); res = executeQuery(conn, buf->data); diff --git a/src/bin/pg_upgrade/check.c b/src/bin/pg_upgrade/check.c index 786c1474829..f725f5ee3e2 100644 --- a/src/bin/pg_upgrade/check.c +++ b/src/bin/pg_upgrade/check.c @@ -1475,15 +1475,15 @@ check_for_incompatible_polymorphics(ClusterInfo *cluster) ", 'array_cat(anyarray,anyarray)'" ", 'array_prepend(anyelement,anyarray)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_remove(anyarray,anyelement)'" - ", 'array_replace(anyarray,anyelement,anyelement)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_remove(anyarray,anyelement)'" + ", 'array_replace(anyarray,anyelement,anyelement)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_position(anyarray,anyelement)'" - ", 'array_position(anyarray,anyelement,integer)'" - ", 'array_positions(anyarray,anyelement)'" - ", 'width_bucket(anyelement,anyarray)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_position(anyarray,anyelement)'" + ", 'array_position(anyarray,anyelement,integer)'" + ", 'array_positions(anyarray,anyelement)'" + ", 'width_bucket(anyelement,anyarray)'"); /* * The query below hardcodes FirstNormalObjectId as 16384 rather than diff --git a/src/bin/pg_upgrade/controldata.c b/src/bin/pg_upgrade/controldata.c index 8f81c9e9582..02ea02df60f 100644 --- a/src/bin/pg_upgrade/controldata.c +++ b/src/bin/pg_upgrade/controldata.c @@ -228,7 +228,7 @@ get_control_data(ClusterInfo *cluster) p++; /* remove ':' char */ cluster->controldata.chkpnt_nxtepoch = str2uint(p); - p = strchr(p, ':'); + p = strchr(p, ':'); if (p == NULL || strlen(p) <= 1) pg_fatal("%d: controldata retrieval problem", __LINE__); diff --git a/src/bin/pg_upgrade/exec.c b/src/bin/pg_upgrade/exec.c index 44355feea30..a1bdbf373e3 100644 --- a/src/bin/pg_upgrade/exec.c +++ b/src/bin/pg_upgrade/exec.c @@ -55,7 +55,7 @@ get_bin_version(ClusterInfo *cluster) if (sscanf(cmd_output, "%*s %*s %d.%d", &v1, &v2) < 1) pg_fatal("could not get pg_ctl version output from %s", cmd); - cluster->bin_version = v1 * 10000; + cluster->bin_version = v1 * 10000; } @@ -344,8 +344,8 @@ check_data_dir(ClusterInfo *cluster) check_single_dir(pg_data, "pg_subtrans"); check_single_dir(pg_data, PG_TBLSPC_DIR); check_single_dir(pg_data, "pg_twophase"); - check_single_dir(pg_data, "pg_wal"); - check_single_dir(pg_data, "pg_xact"); + check_single_dir(pg_data, "pg_wal"); + check_single_dir(pg_data, "pg_xact"); } @@ -385,7 +385,7 @@ check_bin_dir(ClusterInfo *cluster, bool check_versions) */ get_bin_version(cluster); - check_exec(cluster->bindir, "pg_resetwal", check_versions); + check_exec(cluster->bindir, "pg_resetwal", check_versions); if (cluster == &new_cluster) { diff --git a/src/bin/pg_upgrade/multixact_rewrite.c b/src/bin/pg_upgrade/multixact_rewrite.c index c45b3183684..c7a1416494d 100644 --- a/src/bin/pg_upgrade/multixact_rewrite.c +++ b/src/bin/pg_upgrade/multixact_rewrite.c @@ -61,52 +61,52 @@ rewrite_multixacts(MultiXactId from_multi, MultiXactId to_multi) * Convert old multixids, if needed, by reading them one-by-one from the * old cluster. */ - old_reader = AllocOldMultiXactRead(old_cluster.pgdata, - old_cluster.controldata.chkpnt_nxtmulti, - old_cluster.controldata.chkpnt_nxtmxoff); + old_reader = AllocOldMultiXactRead(old_cluster.pgdata, + old_cluster.controldata.chkpnt_nxtmulti, + old_cluster.controldata.chkpnt_nxtmxoff); - for (MultiXactId multi = from_multi; multi != to_multi;) - { - MultiXactMember member; - bool multixid_valid; - - /* - * Read this multixid's members. - * - * Locking-only XIDs that may be part of multi-xids don't matter - * after upgrade, as there can be no transactions running across - * upgrade. So as a small optimization, we only read one member - * from each multixid: the one updating one, or if there was no - * update, arbitrarily the first locking xid. - */ - multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); + for (MultiXactId multi = from_multi; multi != to_multi;) + { + MultiXactMember member; + bool multixid_valid; - /* - * Write the new offset to pg_multixact/offsets. - * - * Even if this multixid is invalid, we still need to write its - * offset if the *previous* multixid was valid. That's because - * when reading a multixid, the number of members is calculated - * from the difference between the two offsets. - */ - RecordMultiXactOffset(offsets_writer, multi, - (multixid_valid || prev_multixid_valid) ? next_offset : 0); + /* + * Read this multixid's members. + * + * Locking-only XIDs that may be part of multi-xids don't matter after + * upgrade, as there can be no transactions running across upgrade. So + * as a small optimization, we only read one member from each + * multixid: the one updating one, or if there was no update, + * arbitrarily the first locking xid. + */ + multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); - /* Write the members */ - if (multixid_valid) - { - RecordMultiXactMembers(members_writer, next_offset, 1, &member); - next_offset += 1; - } + /* + * Write the new offset to pg_multixact/offsets. + * + * Even if this multixid is invalid, we still need to write its offset + * if the *previous* multixid was valid. That's because when reading + * a multixid, the number of members is calculated from the difference + * between the two offsets. + */ + RecordMultiXactOffset(offsets_writer, multi, + (multixid_valid || prev_multixid_valid) ? next_offset : 0); - /* Advance to next multixid, handling wraparound */ - multi++; - if (multi < FirstMultiXactId) - multi = FirstMultiXactId; - prev_multixid_valid = multixid_valid; + /* Write the members */ + if (multixid_valid) + { + RecordMultiXactMembers(members_writer, next_offset, 1, &member); + next_offset += 1; } - FreeOldMultiXactReader(old_reader); + /* Advance to next multixid, handling wraparound */ + multi++; + if (multi < FirstMultiXactId) + multi = FirstMultiXactId; + prev_multixid_valid = multixid_valid; + } + + FreeOldMultiXactReader(old_reader); /* Write the final 'next' offset to the last SLRU page */ RecordMultiXactOffset(offsets_writer, to_multi, diff --git a/src/bin/pg_upgrade/pg_upgrade.c b/src/bin/pg_upgrade/pg_upgrade.c index c6af9035665..7366fd4627c 100644 --- a/src/bin/pg_upgrade/pg_upgrade.c +++ b/src/bin/pg_upgrade/pg_upgrade.c @@ -833,7 +833,7 @@ copy_xact_xlog_xid(void) * Determine the range of multixacts to convert. */ nxtmulti = old_cluster.controldata.chkpnt_nxtmulti; - oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; + oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; /* handle wraparound */ if (nxtmulti < FirstMultiXactId) nxtmulti = FirstMultiXactId; @@ -898,15 +898,15 @@ set_frozenxids(void) int i_datname; int i_datallowconn; - prep_status("Setting frozenxid and minmxid counters in new cluster"); + prep_status("Setting frozenxid and minmxid counters in new cluster"); conn_template1 = connectToServer(&new_cluster, "template1"); - /* set pg_database.datfrozenxid */ - PQclear(executeQueryOrDie(conn_template1, - "UPDATE pg_catalog.pg_database " - "SET datfrozenxid = '%u'", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_database.datfrozenxid */ + PQclear(executeQueryOrDie(conn_template1, + "UPDATE pg_catalog.pg_database " + "SET datfrozenxid = '%u'", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_database.datminmxid */ PQclear(executeQueryOrDie(conn_template1, @@ -942,16 +942,16 @@ set_frozenxids(void) conn = connectToServer(&new_cluster, datname); - /* set pg_class.relfrozenxid */ - PQclear(executeQueryOrDie(conn, - "UPDATE pg_catalog.pg_class " - "SET relfrozenxid = '%u' " - /* only heap, materialized view, and TOAST are vacuumed */ - "WHERE relkind IN (" - CppAsString2(RELKIND_RELATION) ", " - CppAsString2(RELKIND_MATVIEW) ", " - CppAsString2(RELKIND_TOASTVALUE) ")", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_class.relfrozenxid */ + PQclear(executeQueryOrDie(conn, + "UPDATE pg_catalog.pg_class " + "SET relfrozenxid = '%u' " + /* only heap, materialized view, and TOAST are vacuumed */ + "WHERE relkind IN (" + CppAsString2(RELKIND_RELATION) ", " + CppAsString2(RELKIND_MATVIEW) ", " + CppAsString2(RELKIND_TOASTVALUE) ")", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_class.relminmxid */ PQclear(executeQueryOrDie(conn, diff --git a/src/bin/pg_upgrade/relfilenumber.c b/src/bin/pg_upgrade/relfilenumber.c index ec2ff7acb21..6c467bdc8a5 100644 --- a/src/bin/pg_upgrade/relfilenumber.c +++ b/src/bin/pg_upgrade/relfilenumber.c @@ -587,32 +587,32 @@ transfer_relfile(FileNameMap *map, const char *type_suffix) /* Copying files might take some time, so give feedback. */ pg_log(PG_STATUS, "%s", old_file); - switch (user_opts.transfer_mode) - { - case TRANSFER_MODE_CLONE: - pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", - old_file, new_file); - cloneFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", - old_file, new_file); - copyFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY_FILE_RANGE: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", - old_file, new_file); - copyFileByRange(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_LINK: - pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", - old_file, new_file); - linkFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_SWAP: - /* swap mode is handled in its own code path */ - pg_fatal("should never happen"); - break; - } + switch (user_opts.transfer_mode) + { + case TRANSFER_MODE_CLONE: + pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", + old_file, new_file); + cloneFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", + old_file, new_file); + copyFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY_FILE_RANGE: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", + old_file, new_file); + copyFileByRange(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_LINK: + pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", + old_file, new_file); + linkFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_SWAP: + /* swap mode is handled in its own code path */ + pg_fatal("should never happen"); + break; + } } } diff --git a/src/bin/pg_upgrade/t/006_transfer_modes.pl b/src/bin/pg_upgrade/t/006_transfer_modes.pl index 9efa5dc863c..360d05c4b68 100644 --- a/src/bin/pg_upgrade/t/006_transfer_modes.pl +++ b/src/bin/pg_upgrade/t/006_transfer_modes.pl @@ -29,10 +29,8 @@ sub test_mode } $new->init(); - $new->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); - $old->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); + $new->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); + $old->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); # We can only test security labels if both the old and new installations # have dummy_seclabel. @@ -76,15 +74,14 @@ sub test_mode "CREATE TABLE test4 AS SELECT generate_series(400, 502)"); } - $old->safe_psql('postgres', - "CREATE TABLESPACE inplc_tblspc LOCATION ''"); - $old->safe_psql('postgres', - "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); - $old->safe_psql('postgres', - "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" - ); - $old->safe_psql('testdb3', - "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); + $old->safe_psql('postgres', "CREATE TABLESPACE inplc_tblspc LOCATION ''"); + $old->safe_psql('postgres', + "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); + $old->safe_psql('postgres', + "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" + ); + $old->safe_psql('testdb3', + "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); # While we are here, test handling of large objects. $old->safe_psql( @@ -152,12 +149,10 @@ sub test_mode } # Tests for in-place tablespaces. - $result = - $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); - is($result, '104', "test5 data after pg_upgrade $mode"); - $result = - $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); - is($result, '105', "test6 data after pg_upgrade $mode"); + $result = $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); + is($result, '104', "test5 data after pg_upgrade $mode"); + $result = $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); + is($result, '105', "test6 data after pg_upgrade $mode"); # Tests for large objects $result = $new->safe_psql('postgres', "SELECT lo_get(4532)"); diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index 44ef11d980e..c90bf8bbde2 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -6278,23 +6278,22 @@ get_create_object_cmd(EditableObjectType obj_type, Oid oid, * ensure the right view gets replaced. Also, check relation kind * to be sure it's a view. * - * Views may have WITH [LOCAL|CASCADED] - * CHECK OPTION. These are not part of the view definition - * returned by pg_get_viewdef() and so need to be retrieved - * separately. Materialized views may have - * arbitrary storage parameter reloptions. + * Views may have WITH [LOCAL|CASCADED] CHECK OPTION. These are + * not part of the view definition returned by pg_get_viewdef() + * and so need to be retrieved separately. Materialized views may + * have arbitrary storage parameter reloptions. */ printfPQExpBuffer(query, "/* %s */\n", _("Get view's definition and details")); - appendPQExpBuffer(query, - "SELECT nspname, relname, relkind, " - "pg_catalog.pg_get_viewdef(c.oid, true), " - "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " - "FROM pg_catalog.pg_class c " - "LEFT JOIN pg_catalog.pg_namespace n " - "ON c.relnamespace = n.oid WHERE c.oid = %u", - oid); + appendPQExpBuffer(query, + "SELECT nspname, relname, relkind, " + "pg_catalog.pg_get_viewdef(c.oid, true), " + "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " + "FROM pg_catalog.pg_class c " + "LEFT JOIN pg_catalog.pg_namespace n " + "ON c.relnamespace = n.oid WHERE c.oid = %u", + oid); break; } diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index ce99137c613..ac0c55e7aa5 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -387,19 +387,19 @@ describeFunctions(const char *functypes, const char *func_pattern, gettext_noop("stable"), gettext_noop("volatile"), gettext_noop("Volatility")); - appendPQExpBuffer(&buf, - ",\n CASE\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" - " END as \"%s\"", - gettext_noop("restricted"), - gettext_noop("safe"), - gettext_noop("unsafe"), - gettext_noop("Parallel")); + appendPQExpBuffer(&buf, + ",\n CASE\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" + " END as \"%s\"", + gettext_noop("restricted"), + gettext_noop("safe"), + gettext_noop("unsafe"), + gettext_noop("Parallel")); appendPQExpBuffer(&buf, ",\n pg_catalog.pg_get_userbyid(p.proowner) as \"%s\"" ",\n CASE WHEN prosecdef THEN '%s' ELSE '%s' END AS \"%s\"" @@ -599,8 +599,8 @@ describeFunctions(const char *functypes, const char *func_pattern, myopt.title = _("List of functions"); myopt.translate_header = true; - myopt.translate_columns = translate_columns; - myopt.n_translate_columns = lengthof(translate_columns); + myopt.translate_columns = translate_columns; + myopt.n_translate_columns = lengthof(translate_columns); printQuery(res, &myopt, pset.queryFout, false, pset.logfile); @@ -1086,38 +1086,38 @@ permissionsList(const char *pattern, bool showSystem) " ), E'\\n') AS \"%s\"", gettext_noop("Column privileges")); - appendPQExpBuffer(&buf, - ",\n pg_catalog.array_to_string(ARRAY(\n" - " SELECT polname\n" - " || CASE WHEN NOT polpermissive THEN\n" - " E' (RESTRICTIVE)'\n" - " ELSE '' END\n" - " || CASE WHEN polcmd != '*' THEN\n" - " E' (' || polcmd::pg_catalog.text || E'):'\n" - " ELSE E':'\n" - " END\n" - " || CASE WHEN polqual IS NOT NULL THEN\n" - " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" - " ELSE E''\n" - " END\n" - " || CASE WHEN polwithcheck IS NOT NULL THEN\n" - " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" - " ELSE E''\n" - " END" - " || CASE WHEN polroles <> '{0}' THEN\n" - " E'\\n to: ' || pg_catalog.array_to_string(\n" - " ARRAY(\n" - " SELECT rolname\n" - " FROM pg_catalog.pg_roles\n" - " WHERE oid = ANY (polroles)\n" - " ORDER BY 1\n" - " ), E', ')\n" - " ELSE E''\n" - " END\n" - " FROM pg_catalog.pg_policy pol\n" - " WHERE polrelid = c.oid), E'\\n')\n" - " AS \"%s\"", - gettext_noop("Policies")); + appendPQExpBuffer(&buf, + ",\n pg_catalog.array_to_string(ARRAY(\n" + " SELECT polname\n" + " || CASE WHEN NOT polpermissive THEN\n" + " E' (RESTRICTIVE)'\n" + " ELSE '' END\n" + " || CASE WHEN polcmd != '*' THEN\n" + " E' (' || polcmd::pg_catalog.text || E'):'\n" + " ELSE E':'\n" + " END\n" + " || CASE WHEN polqual IS NOT NULL THEN\n" + " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" + " ELSE E''\n" + " END\n" + " || CASE WHEN polwithcheck IS NOT NULL THEN\n" + " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" + " ELSE E''\n" + " END" + " || CASE WHEN polroles <> '{0}' THEN\n" + " E'\\n to: ' || pg_catalog.array_to_string(\n" + " ARRAY(\n" + " SELECT rolname\n" + " FROM pg_catalog.pg_roles\n" + " WHERE oid = ANY (polroles)\n" + " ORDER BY 1\n" + " ), E', ')\n" + " ELSE E''\n" + " END\n" + " FROM pg_catalog.pg_policy pol\n" + " WHERE polrelid = c.oid), E'\\n')\n" + " AS \"%s\"", + gettext_noop("Policies")); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_class c\n" " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n" @@ -1675,27 +1675,27 @@ describeOneTableDetails(const char *schemaname, char *footers[3] = {NULL, NULL, NULL}; printfPQExpBuffer(&buf, "/* %s */\n", _("Get sequence information")); - appendPQExpBuffer(&buf, - "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" - " seqstart AS \"%s\",\n" - " seqmin AS \"%s\",\n" - " seqmax AS \"%s\",\n" - " seqincrement AS \"%s\",\n" - " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" - " seqcache AS \"%s\"\n", - gettext_noop("Type"), - gettext_noop("Start"), - gettext_noop("Minimum"), - gettext_noop("Maximum"), - gettext_noop("Increment"), - gettext_noop("yes"), - gettext_noop("no"), - gettext_noop("Cycles?"), - gettext_noop("Cache")); - appendPQExpBuffer(&buf, - "FROM pg_catalog.pg_sequence\n" - "WHERE seqrelid = '%s';", - oid); + appendPQExpBuffer(&buf, + "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" + " seqstart AS \"%s\",\n" + " seqmin AS \"%s\",\n" + " seqmax AS \"%s\",\n" + " seqincrement AS \"%s\",\n" + " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" + " seqcache AS \"%s\"\n", + gettext_noop("Type"), + gettext_noop("Start"), + gettext_noop("Minimum"), + gettext_noop("Maximum"), + gettext_noop("Increment"), + gettext_noop("yes"), + gettext_noop("no"), + gettext_noop("Cycles?"), + gettext_noop("Cache")); + appendPQExpBuffer(&buf, + "FROM pg_catalog.pg_sequence\n" + "WHERE seqrelid = '%s';", + oid); res = PSQLexec(buf.data); if (!res) @@ -1913,7 +1913,7 @@ describeOneTableDetails(const char *schemaname, appendPQExpBufferStr(&buf, ",\n (SELECT c.collname FROM pg_catalog.pg_collation c, pg_catalog.pg_type t\n" " WHERE c.oid = a.attcollation AND t.oid = a.atttypid AND a.attcollation <> t.typcollation) AS attcollation"); attcoll_col = cols++; - appendPQExpBufferStr(&buf, ",\n a.attidentity"); + appendPQExpBufferStr(&buf, ",\n a.attidentity"); attidentity_col = cols++; if (pset.sversion >= 120000) appendPQExpBufferStr(&buf, ",\n a.attgenerated"); @@ -2326,7 +2326,7 @@ describeOneTableDetails(const char *schemaname, CppAsString2(CONSTRAINT_EXCLUSION) ") AND " "condeferred) AS condeferred,\n"); - appendPQExpBufferStr(&buf, "i.indisreplident,\n"); + appendPQExpBufferStr(&buf, "i.indisreplident,\n"); if (pset.sversion >= 150000) appendPQExpBufferStr(&buf, "i.indnullsnotdistinct,\n"); @@ -2431,7 +2431,7 @@ describeOneTableDetails(const char *schemaname, "pg_catalog.pg_get_indexdef(i.indexrelid, 0, true),\n " "pg_catalog.pg_get_constraintdef(con.oid, true), " "contype, condeferrable, condeferred"); - appendPQExpBufferStr(&buf, ", i.indisreplident"); + appendPQExpBufferStr(&buf, ", i.indisreplident"); appendPQExpBufferStr(&buf, ", c2.reltablespace"); if (pset.sversion >= 180000) appendPQExpBufferStr(&buf, ", con.conperiod"); @@ -2682,81 +2682,80 @@ describeOneTableDetails(const char *schemaname, PQclear(result); /* print any row-level policies */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get row-level policies for this table")); - appendPQExpBufferStr(&buf, "SELECT pol.polname,"); - appendPQExpBufferStr(&buf, - " pol.polpermissive,\n"); - appendPQExpBuffer(&buf, - " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" - " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" - " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" - " CASE pol.polcmd\n" - " WHEN 'r' THEN 'SELECT'\n" - " WHEN 'a' THEN 'INSERT'\n" - " WHEN 'w' THEN 'UPDATE'\n" - " WHEN 'd' THEN 'DELETE'\n" - " END AS cmd\n" - "FROM pg_catalog.pg_policy pol\n" - "WHERE pol.polrelid = '%s' ORDER BY 1;", - oid); + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get row-level policies for this table")); + appendPQExpBufferStr(&buf, "SELECT pol.polname,"); + appendPQExpBufferStr(&buf, + " pol.polpermissive,\n"); + appendPQExpBuffer(&buf, + " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" + " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" + " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" + " CASE pol.polcmd\n" + " WHEN 'r' THEN 'SELECT'\n" + " WHEN 'a' THEN 'INSERT'\n" + " WHEN 'w' THEN 'UPDATE'\n" + " WHEN 'd' THEN 'DELETE'\n" + " END AS cmd\n" + "FROM pg_catalog.pg_policy pol\n" + "WHERE pol.polrelid = '%s' ORDER BY 1;", + oid); - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - /* - * Handle cases where RLS is enabled and there are policies, or - * there aren't policies, or RLS isn't enabled but there are - * policies - */ - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies:")); + /* + * Handle cases where RLS is enabled and there are policies, or there + * aren't policies, or RLS isn't enabled but there are policies + */ + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies:")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled):")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled):")); - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); - if (!tableinfo.rowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (row security disabled):")); + if (!tableinfo.rowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (row security disabled):")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " POLICY \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " POLICY \"%s\"", + PQgetvalue(result, i, 0)); - if (*(PQgetvalue(result, i, 1)) == 'f') - appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); + if (*(PQgetvalue(result, i, 1)) == 'f') + appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); - if (!PQgetisnull(result, i, 5)) - appendPQExpBuffer(&buf, " FOR %s", - PQgetvalue(result, i, 5)); + if (!PQgetisnull(result, i, 5)) + appendPQExpBuffer(&buf, " FOR %s", + PQgetvalue(result, i, 5)); - if (!PQgetisnull(result, i, 2)) - { - appendPQExpBuffer(&buf, "\n TO %s", - PQgetvalue(result, i, 2)); - } + if (!PQgetisnull(result, i, 2)) + { + appendPQExpBuffer(&buf, "\n TO %s", + PQgetvalue(result, i, 2)); + } - if (!PQgetisnull(result, i, 3)) - appendPQExpBuffer(&buf, "\n USING (%s)", - PQgetvalue(result, i, 3)); + if (!PQgetisnull(result, i, 3)) + appendPQExpBuffer(&buf, "\n USING (%s)", + PQgetvalue(result, i, 3)); - if (!PQgetisnull(result, i, 4)) - appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", - PQgetvalue(result, i, 4)); + if (!PQgetisnull(result, i, 4)) + appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", + PQgetvalue(result, i, 4)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* print any extended statistics */ if (pset.sversion >= 140000) @@ -3025,115 +3024,115 @@ describeOneTableDetails(const char *schemaname, } /* print any publications */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get publications that publish this table")); - if (pset.sversion >= 150000) + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get publications that publish this table")); + if (pset.sversion >= 150000) + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" + " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" + "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" + "UNION\n" + "SELECT pubname\n" + " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" + " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" + " (SELECT pg_catalog.string_agg(attname, ', ')\n" + " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" + " pg_catalog.pg_attribute\n" + " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" + " ELSE NULL END) " + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" + "WHERE pr.prrelid = '%s'\n", + oid, oid, oid); + + if (pset.sversion >= 190000) { + /* + * Skip entries where this relation appears in the + * publication's EXCEPT list. + */ appendPQExpBuffer(&buf, + " AND NOT pr.prexcept\n" + "UNION\n" "SELECT pubname\n" " , NULL\n" " , NULL\n" "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" - " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" - "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" - "UNION\n" - "SELECT pubname\n" - " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" - " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" - " (SELECT pg_catalog.string_agg(attname, ', ')\n" - " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" - " pg_catalog.pg_attribute\n" - " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" - " ELSE NULL END) " - "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" - "WHERE pr.prrelid = '%s'\n", + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + " AND NOT EXISTS (\n" + " SELECT 1\n" + " FROM pg_catalog.pg_publication_rel pr\n" + " WHERE pr.prpubid = p.oid AND\n" + " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" + "ORDER BY 1;", oid, oid, oid); - - if (pset.sversion >= 190000) - { - /* - * Skip entries where this relation appears in the - * publication's EXCEPT list. - */ - appendPQExpBuffer(&buf, - " AND NOT pr.prexcept\n" - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - " AND NOT EXISTS (\n" - " SELECT 1\n" - " FROM pg_catalog.pg_publication_rel pr\n" - " WHERE pr.prpubid = p.oid AND\n" - " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" - "ORDER BY 1;", - oid, oid, oid); - } - else - { - appendPQExpBuffer(&buf, - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - "ORDER BY 1;", - oid); - } } else { appendPQExpBuffer(&buf, + "UNION\n" "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - "WHERE pr.prrelid = '%s'\n" - "UNION ALL\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" + " , NULL\n" + " , NULL\n" "FROM pg_catalog.pg_publication p\n" "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" "ORDER BY 1;", - oid, oid); + oid); } + } + else + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + "WHERE pr.prrelid = '%s'\n" + "UNION ALL\n" + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + "ORDER BY 1;", + oid, oid); + } - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - if (tuples > 0) - printTableAddFooter(&cont, _("Included in publications:")); + if (tuples > 0) + printTableAddFooter(&cont, _("Included in publications:")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " \"%s\"", + PQgetvalue(result, i, 0)); - /* column list (if any) */ - if (!PQgetisnull(result, i, 2)) - appendPQExpBuffer(&buf, " (%s)", - PQgetvalue(result, i, 2)); + /* column list (if any) */ + if (!PQgetisnull(result, i, 2)) + appendPQExpBuffer(&buf, " (%s)", + PQgetvalue(result, i, 2)); - /* row filter (if any) */ - if (!PQgetisnull(result, i, 1)) - appendPQExpBuffer(&buf, " WHERE %s", - PQgetvalue(result, i, 1)); + /* row filter (if any) */ + if (!PQgetisnull(result, i, 1)) + appendPQExpBuffer(&buf, " WHERE %s", + PQgetvalue(result, i, 1)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* Print publications where the table is in the EXCEPT clause */ if (pset.sversion >= 190000) @@ -3805,7 +3804,7 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) ncols++; } appendPQExpBufferStr(&buf, "\n, r.rolreplication"); - appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); + appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_roles r\n"); @@ -3860,8 +3859,8 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) if (strcmp(PQgetvalue(res, i, (verbose ? 9 : 8)), "t") == 0) add_role_attribute(&buf, _("Replication")); - if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) - add_role_attribute(&buf, _("Bypass RLS")); + if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) + add_role_attribute(&buf, _("Bypass RLS")); conns = atoi(PQgetvalue(res, i, 6)); if (conns >= 0) @@ -5155,14 +5154,14 @@ listCollations(const char *pattern, bool verbose, bool showSystem) gettext_noop("Schema"), gettext_noop("Name")); - appendPQExpBuffer(&buf, - " CASE c.collprovider " - "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " - "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " - "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " - "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " - "END AS \"%s\",\n", - gettext_noop("Provider")); + appendPQExpBuffer(&buf, + " CASE c.collprovider " + "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " + "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " + "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " + "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " + "END AS \"%s\",\n", + gettext_noop("Provider")); appendPQExpBuffer(&buf, " c.collcollate AS \"%s\",\n" -- 2.50.1 (Apple Git-155) --aHl3HfeiUuO3zeNC-- ^ permalink raw reply [nested|flat] 59+ messages in thread
* [PATCH v6 4/4] run pgindent and pgperltidy @ 2026-06-30 18:24 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 59+ messages in thread From: Nathan Bossart @ 2026-06-30 18:24 UTC (permalink / raw) --- src/bin/pg_dump/pg_dump.c | 464 ++++++++++----------- src/bin/pg_dump/pg_dumpall.c | 30 +- src/bin/pg_upgrade/check.c | 16 +- src/bin/pg_upgrade/controldata.c | 2 +- src/bin/pg_upgrade/exec.c | 8 +- src/bin/pg_upgrade/multixact_rewrite.c | 80 ++-- src/bin/pg_upgrade/pg_upgrade.c | 34 +- src/bin/pg_upgrade/relfilenumber.c | 54 +-- src/bin/pg_upgrade/t/006_transfer_modes.pl | 33 +- src/bin/psql/command.c | 29 +- src/bin/psql/describe.c | 461 ++++++++++---------- 11 files changed, 601 insertions(+), 610 deletions(-) diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 65bd15ebfd2..5673268b467 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -1491,8 +1491,8 @@ setup_connection(Archive *AH, const char *dumpencoding, * Disable timeouts if supported. */ ExecuteSqlStatement(AH, "SET statement_timeout = 0"); - ExecuteSqlStatement(AH, "SET lock_timeout = 0"); - ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); + ExecuteSqlStatement(AH, "SET lock_timeout = 0"); + ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); if (AH->remoteVersion >= 170000) ExecuteSqlStatement(AH, "SET transaction_timeout = 0"); @@ -1505,10 +1505,10 @@ setup_connection(Archive *AH, const char *dumpencoding, /* * Adjust row-security mode, if supported. */ - if (dopt->enable_row_security) - ExecuteSqlStatement(AH, "SET row_security = on"); - else - ExecuteSqlStatement(AH, "SET row_security = off"); + if (dopt->enable_row_security) + ExecuteSqlStatement(AH, "SET row_security = on"); + else + ExecuteSqlStatement(AH, "SET row_security = off"); /* * For security reasons, we restrict the expansion of non-system views and @@ -1933,10 +1933,9 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) addObjectDependency(dobj, ext->dobj.dumpId); /* - * Mark the member object to have any non-initial ACLs - * dumped. (Any initial ACLs will be removed later, using data from - * pg_init_privs, so that we'll dump only the delta from the extension's - * initial setup.) + * Mark the member object to have any non-initial ACLs dumped. (Any + * initial ACLs will be removed later, using data from pg_init_privs, so + * that we'll dump only the delta from the extension's initial setup.) * * In binary upgrades, we still dump all components of the members * individually, since the idea is to exactly reproduce the database @@ -1953,7 +1952,7 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) if (fout->dopt->binary_upgrade) dobj->dump = ext->dobj.dump; else - dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); + dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); return true; } @@ -1987,9 +1986,9 @@ selectDumpableNamespace(NamespaceInfo *nsinfo, Archive *fout) else if (strcmp(nsinfo->dobj.name, "pg_catalog") == 0) { /* - * We dump out any ACLs defined in pg_catalog, if - * they are interesting (and not the original ACLs which were set at - * initdb time, see pg_init_privs). + * We dump out any ACLs defined in pg_catalog, if they are interesting + * (and not the original ACLs which were set at initdb time, see + * pg_init_privs). */ nsinfo->dobj.dump_contains = nsinfo->dobj.dump = DUMP_COMPONENT_ACL; } @@ -3296,7 +3295,7 @@ dumpDatabase(Archive *fout) "datcollate, datctype, datfrozenxid, " "datacl, acldefault('d', datdba) AS acldefault, " "datistemplate, datconnlimit, "); - appendPQExpBufferStr(dbQry, "datminmxid, "); + appendPQExpBufferStr(dbQry, "datminmxid, "); if (fout->remoteVersion >= 170000) appendPQExpBufferStr(dbQry, "datlocprovider, datlocale, datcollversion, "); else if (fout->remoteVersion >= 150000) @@ -3638,11 +3637,11 @@ dumpDatabase(Archive *fout) ii_oid, ii_relminmxid; - appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" - "FROM pg_catalog.pg_class\n" - "WHERE oid IN (%u, %u, %u, %u);\n", - LargeObjectRelationId, LargeObjectLOidPNIndexId, - LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); + appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" + "FROM pg_catalog.pg_class\n" + "WHERE oid IN (%u, %u, %u, %u);\n", + LargeObjectRelationId, LargeObjectLOidPNIndexId, + LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); lo_res = ExecuteSqlQuery(fout, loFrozenQry->data, PGRES_TUPLES_OK); @@ -4274,7 +4273,7 @@ getPolicies(Archive *fout, TableInfo tblinfo[], int numTables) printfPQExpBuffer(query, "SELECT pol.oid, pol.tableoid, pol.polrelid, pol.polname, pol.polcmd, "); - appendPQExpBufferStr(query, "pol.polpermissive, "); + appendPQExpBufferStr(query, "pol.polpermissive, "); appendPQExpBuffer(query, "CASE WHEN pol.polroles = '{0}' THEN NULL ELSE " " pg_catalog.array_to_string(ARRAY(SELECT pg_catalog.quote_ident(rolname) from pg_catalog.pg_roles WHERE oid = ANY(pol.polroles)), ', ') END AS polroles, " @@ -6633,9 +6632,9 @@ getAccessMethods(Archive *fout) * Select all access methods from pg_am table. */ appendPQExpBufferStr(query, "SELECT tableoid, oid, amname, "); - appendPQExpBufferStr(query, - "amtype, " - "amhandler::pg_catalog.regproc AS amhandler "); + appendPQExpBufferStr(query, + "amtype, " + "amhandler::pg_catalog.regproc AS amhandler "); appendPQExpBufferStr(query, "FROM pg_am"); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6827,35 +6826,35 @@ getAggregates(Archive *fout) * Find all interesting aggregates. See comment in getFuncs() for the * rationale behind the filtering logic. */ - agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" - : "p.proisagg"); + agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" + : "p.proisagg"); - appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " - "p.proname AS aggname, " - "p.pronamespace AS aggnamespace, " - "p.pronargs, p.proargtypes, " - "p.proowner, " - "p.proacl AS aggacl, " - "acldefault('f', p.proowner) AS acldefault " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s AND (" - "p.pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog') OR " - "p.proacl IS DISTINCT FROM pip.initprivs", - agg_check); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - " OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); - appendPQExpBufferChar(query, ')'); + appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " + "p.proname AS aggname, " + "p.pronamespace AS aggnamespace, " + "p.pronargs, p.proargtypes, " + "p.proowner, " + "p.proacl AS aggacl, " + "acldefault('f', p.proowner) AS acldefault " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s AND (" + "p.pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog') OR " + "p.proacl IS DISTINCT FROM pip.initprivs", + agg_check); + if (dopt->binary_upgrade) + appendPQExpBufferStr(query, + " OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6957,53 +6956,53 @@ getFuncs(Archive *fout) * include them, since we want to dump extension members individually in * that mode. Also, if they are used by casts or transforms then we need * to gather the information about them, though they won't be dumped if - * they are built-in. Also, include functions in - * pg_catalog if they have an ACL different from what's shown in - * pg_init_privs (so we have to join to pg_init_privs; annoying). + * they are built-in. Also, include functions in pg_catalog if they have + * an ACL different from what's shown in pg_init_privs (so we have to join + * to pg_init_privs; annoying). */ - not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" - : "NOT p.proisagg"); + not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" + : "NOT p.proisagg"); - appendPQExpBuffer(query, - "SELECT p.tableoid, p.oid, p.proname, p.prolang, " - "p.pronargs, p.proargtypes, p.prorettype, " - "p.proacl, " - "acldefault('f', p.proowner) AS acldefault, " - "p.pronamespace, " - "p.proowner " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s" - "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " - "WHERE classid = 'pg_proc'::regclass AND " - "objid = p.oid AND deptype = 'i')" - "\n AND (" - "\n pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog')" - "\n OR EXISTS (SELECT 1 FROM pg_cast" - "\n WHERE pg_cast.oid > %u " - "\n AND p.oid = pg_cast.castfunc)" - "\n OR EXISTS (SELECT 1 FROM pg_transform" - "\n WHERE pg_transform.oid > %u AND " - "\n (p.oid = pg_transform.trffromsql" - "\n OR p.oid = pg_transform.trftosql))", - not_agg_check, - g_last_builtin_oid, - g_last_builtin_oid); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); + appendPQExpBuffer(query, + "SELECT p.tableoid, p.oid, p.proname, p.prolang, " + "p.pronargs, p.proargtypes, p.prorettype, " + "p.proacl, " + "acldefault('f', p.proowner) AS acldefault, " + "p.pronamespace, " + "p.proowner " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s" + "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " + "WHERE classid = 'pg_proc'::regclass AND " + "objid = p.oid AND deptype = 'i')" + "\n AND (" + "\n pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog')" + "\n OR EXISTS (SELECT 1 FROM pg_cast" + "\n WHERE pg_cast.oid > %u " + "\n AND p.oid = pg_cast.castfunc)" + "\n OR EXISTS (SELECT 1 FROM pg_transform" + "\n WHERE pg_transform.oid > %u AND " + "\n (p.oid = pg_transform.trffromsql" + "\n OR p.oid = pg_transform.trftosql))", + not_agg_check, + g_last_builtin_oid, + g_last_builtin_oid); + if (dopt->binary_upgrade) appendPQExpBufferStr(query, - "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); - appendPQExpBufferChar(query, ')'); + "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferStr(query, + "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -7252,31 +7251,31 @@ getTables(Archive *fout, int *numTables) appendPQExpBufferStr(query, "c.relhasoids, "); - appendPQExpBufferStr(query, - "c.relispopulated, "); + appendPQExpBufferStr(query, + "c.relispopulated, "); - appendPQExpBufferStr(query, - "c.relreplident, "); + appendPQExpBufferStr(query, + "c.relreplident, "); - appendPQExpBufferStr(query, - "c.relrowsecurity, c.relforcerowsecurity, "); + appendPQExpBufferStr(query, + "c.relrowsecurity, c.relforcerowsecurity, "); - appendPQExpBufferStr(query, - "c.relminmxid, tc.relminmxid AS tminmxid, "); + appendPQExpBufferStr(query, + "c.relminmxid, tc.relminmxid AS tminmxid, "); - appendPQExpBufferStr(query, - "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); + appendPQExpBufferStr(query, + "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); - appendPQExpBufferStr(query, - "am.amname, "); + appendPQExpBufferStr(query, + "am.amname, "); - appendPQExpBufferStr(query, - "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); + appendPQExpBufferStr(query, + "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); - appendPQExpBufferStr(query, - "c.relispartition AS ispartition "); + appendPQExpBufferStr(query, + "c.relispartition AS ispartition "); /* * Left join to pg_depend to pick up dependency info linking sequences to @@ -7296,8 +7295,8 @@ getTables(Archive *fout, int *numTables) /* * Left join to pg_am to pick up the amname. */ - appendPQExpBufferStr(query, - "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); + appendPQExpBufferStr(query, + "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); /* * We purposefully ignore toast OIDs for partitioned tables; the reason is @@ -7868,8 +7867,8 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables) "t.reloptions AS indreloptions, "); - appendPQExpBufferStr(query, - "i.indisreplident, "); + appendPQExpBufferStr(query, + "i.indisreplident, "); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -9313,8 +9312,8 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables) appendPQExpBufferStr(q, "'' AS attcompression,\n"); - appendPQExpBufferStr(q, - "a.attidentity,\n"); + appendPQExpBufferStr(q, + "a.attidentity,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(q, @@ -10717,73 +10716,73 @@ getAdditionalACLs(Archive *fout) PQclear(res); /* Fetch initial-privileges data */ - printfPQExpBuffer(query, - "SELECT objoid, classoid, objsubid, privtype, initprivs " - "FROM pg_init_privs"); + printfPQExpBuffer(query, + "SELECT objoid, classoid, objsubid, privtype, initprivs " + "FROM pg_init_privs"); - res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); + res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); - ntups = PQntuples(res); - for (i = 0; i < ntups; i++) - { - Oid objoid = atooid(PQgetvalue(res, i, 0)); - Oid classoid = atooid(PQgetvalue(res, i, 1)); - int objsubid = atoi(PQgetvalue(res, i, 2)); - char privtype = *(PQgetvalue(res, i, 3)); - char *initprivs = PQgetvalue(res, i, 4); - CatalogId objId; - DumpableObject *dobj; + ntups = PQntuples(res); + for (i = 0; i < ntups; i++) + { + Oid objoid = atooid(PQgetvalue(res, i, 0)); + Oid classoid = atooid(PQgetvalue(res, i, 1)); + int objsubid = atoi(PQgetvalue(res, i, 2)); + char privtype = *(PQgetvalue(res, i, 3)); + char *initprivs = PQgetvalue(res, i, 4); + CatalogId objId; + DumpableObject *dobj; - objId.tableoid = classoid; - objId.oid = objoid; - dobj = findObjectByCatalogId(objId); - /* OK to ignore entries we haven't got a DumpableObject for */ - if (dobj) + objId.tableoid = classoid; + objId.oid = objoid; + dobj = findObjectByCatalogId(objId); + /* OK to ignore entries we haven't got a DumpableObject for */ + if (dobj) + { + /* Cope with sub-object initprivs */ + if (objsubid != 0) { - /* Cope with sub-object initprivs */ - if (objsubid != 0) - { - if (dobj->objType == DO_TABLE) - { - /* For a column initprivs, set the table's ACL flags */ - dobj->components |= DUMP_COMPONENT_ACL; - ((TableInfo *) dobj)->hascolumnACLs = true; - } - else - pg_log_warning("unsupported pg_init_privs entry: %u %u %d", - classoid, objoid, objsubid); - continue; - } - - /* - * We ignore any pg_init_privs.initprivs entry for the public - * schema, as explained in getNamespaces(). - */ - if (dobj->objType == DO_NAMESPACE && - strcmp(dobj->name, "public") == 0) - continue; - - /* Else it had better be of a type we think has ACLs */ - if (dobj->objType == DO_NAMESPACE || - dobj->objType == DO_TYPE || - dobj->objType == DO_FUNC || - dobj->objType == DO_AGG || - dobj->objType == DO_TABLE || - dobj->objType == DO_PROCLANG || - dobj->objType == DO_FDW || - dobj->objType == DO_FOREIGN_SERVER) + if (dobj->objType == DO_TABLE) { - DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; - - daobj->dacl.privtype = privtype; - daobj->dacl.initprivs = pstrdup(initprivs); + /* For a column initprivs, set the table's ACL flags */ + dobj->components |= DUMP_COMPONENT_ACL; + ((TableInfo *) dobj)->hascolumnACLs = true; } else pg_log_warning("unsupported pg_init_privs entry: %u %u %d", classoid, objoid, objsubid); + continue; + } + + /* + * We ignore any pg_init_privs.initprivs entry for the public + * schema, as explained in getNamespaces(). + */ + if (dobj->objType == DO_NAMESPACE && + strcmp(dobj->name, "public") == 0) + continue; + + /* Else it had better be of a type we think has ACLs */ + if (dobj->objType == DO_NAMESPACE || + dobj->objType == DO_TYPE || + dobj->objType == DO_FUNC || + dobj->objType == DO_AGG || + dobj->objType == DO_TABLE || + dobj->objType == DO_PROCLANG || + dobj->objType == DO_FDW || + dobj->objType == DO_FOREIGN_SERVER) + { + DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; + + daobj->dacl.privtype = privtype; + daobj->dacl.initprivs = pstrdup(initprivs); } + else + pg_log_warning("unsupported pg_init_privs entry: %u %u %d", + classoid, objoid, objsubid); } - PQclear(res); + } + PQclear(res); destroyPQExpBuffer(query); } @@ -11128,8 +11127,8 @@ dumpRelationStats_dumper(Archive *fout, const void *userArg, const TocEntry *te) * The results must be in the order of the relations supplied in the * parameters to ensure we remain in sync as we walk through the TOC. * - * For versions before 19, the redundant filter clause on s.tablename = - * ANY(...) seems sufficient to convince the planner to use + * For versions before 19, the redundant filter clause on s.tablename + * = ANY(...) seems sufficient to convince the planner to use * pg_class_relname_nsp_index, which avoids a full scan of pg_stats. * In newer versions, pg_stats returns the table OIDs, eliminating the * need for that hack. @@ -13469,11 +13468,11 @@ dumpFunc(Archive *fout, const FuncInfo *finfo) "pg_catalog.pg_get_function_result(p.oid) AS funcresult,\n" "proleakproof,\n"); - appendPQExpBufferStr(query, - "array_to_string(protrftypes, ' ') AS protrftypes,\n"); + appendPQExpBufferStr(query, + "array_to_string(protrftypes, ' ') AS protrftypes,\n"); - appendPQExpBufferStr(query, - "proparallel,\n"); + appendPQExpBufferStr(query, + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -14963,9 +14962,9 @@ dumpCollation(Archive *fout, const CollInfo *collinfo) /* Get collation-specific details */ appendPQExpBufferStr(query, "SELECT "); - appendPQExpBufferStr(query, - "collprovider, " - "collversion, "); + appendPQExpBufferStr(query, + "collprovider, " + "collversion, "); if (fout->remoteVersion >= 120000) appendPQExpBufferStr(query, @@ -15372,23 +15371,23 @@ dumpAgg(Archive *fout, const AggInfo *agginfo) "pg_catalog.pg_get_function_arguments(p.oid) AS funcargs,\n" "pg_catalog.pg_get_function_identity_arguments(p.oid) AS funciargs,\n"); - appendPQExpBufferStr(query, - "aggkind,\n" - "aggmtransfn,\n" - "aggminvtransfn,\n" - "aggmfinalfn,\n" - "aggmtranstype::pg_catalog.regtype,\n" - "aggfinalextra,\n" - "aggmfinalextra,\n" - "aggtransspace,\n" - "aggmtransspace,\n" - "aggminitval,\n"); + appendPQExpBufferStr(query, + "aggkind,\n" + "aggmtransfn,\n" + "aggminvtransfn,\n" + "aggmfinalfn,\n" + "aggmtranstype::pg_catalog.regtype,\n" + "aggfinalextra,\n" + "aggmfinalextra,\n" + "aggtransspace,\n" + "aggmtransspace,\n" + "aggminitval,\n"); - appendPQExpBufferStr(query, - "aggcombinefn,\n" - "aggserialfn,\n" - "aggdeserialfn,\n" - "proparallel,\n"); + appendPQExpBufferStr(query, + "aggcombinefn,\n" + "aggserialfn,\n" + "aggdeserialfn,\n" + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -16848,30 +16847,30 @@ dumpTable(Archive *fout, const TableInfo *tbinfo) appendPQExpBufferStr(query, "PREPARE getColumnACLs(pg_catalog.oid) AS\n"); - /* - * In principle we should call acldefault('c', relowner) to - * get the default ACL for a column. However, we don't - * currently store the numeric OID of the relowner in - * TableInfo. We could convert the owner name using regrole, - * but that creates a risk of failure due to concurrent role - * renames. Given that the default ACL for columns is empty - * and is likely to stay that way, it's not worth extra cycles - * and risk to avoid hard-wiring that knowledge here. - */ - appendPQExpBufferStr(query, - "SELECT at.attname, " - "at.attacl, " - "'{}' AS acldefault, " - "pip.privtype, pip.initprivs " - "FROM pg_catalog.pg_attribute at " - "LEFT JOIN pg_catalog.pg_init_privs pip ON " - "(at.attrelid = pip.objoid " - "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " - "AND at.attnum = pip.objsubid) " - "WHERE at.attrelid = $1 AND " - "NOT at.attisdropped " - "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " - "ORDER BY at.attnum"); + /* + * In principle we should call acldefault('c', relowner) to get + * the default ACL for a column. However, we don't currently + * store the numeric OID of the relowner in TableInfo. We could + * convert the owner name using regrole, but that creates a risk + * of failure due to concurrent role renames. Given that the + * default ACL for columns is empty and is likely to stay that + * way, it's not worth extra cycles and risk to avoid hard-wiring + * that knowledge here. + */ + appendPQExpBufferStr(query, + "SELECT at.attname, " + "at.attacl, " + "'{}' AS acldefault, " + "pip.privtype, pip.initprivs " + "FROM pg_catalog.pg_attribute at " + "LEFT JOIN pg_catalog.pg_init_privs pip ON " + "(at.attrelid = pip.objoid " + "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " + "AND at.attnum = pip.objsubid) " + "WHERE at.attrelid = $1 AND " + "NOT at.attisdropped " + "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " + "ORDER BY at.attnum"); ExecuteSqlStatement(fout, query->data); @@ -19165,7 +19164,7 @@ collectSequences(Archive *fout) * pg_get_sequence_data(), but we only do so for non-schema-only dumps. */ if (fout->remoteVersion < 180000 || - (!fout->dopt->dumpData && !fout->dopt->sequence_data)) + (!fout->dopt->dumpData && !fout->dopt->sequence_data)) query = "SELECT seqrelid, format_type(seqtypid, NULL), " "seqstart, seqincrement, " "seqmax, seqmin, " @@ -19227,15 +19226,14 @@ dumpSequence(Archive *fout, const TableInfo *tbinfo) qseqname = pg_strdup(fmtId(tbinfo->dobj.name)); /* - * The sequence information is gathered in a sorted - * table before any calls to dumpSequence(). See collectSequences() for - * more information. + * The sequence information is gathered in a sorted table before any calls + * to dumpSequence(). See collectSequences() for more information. */ - Assert(sequences); + Assert(sequences); - key.oid = tbinfo->dobj.catId.oid; - seq = bsearch(&key, sequences, nsequences, - sizeof(SequenceItem), SequenceItemCmp); + key.oid = tbinfo->dobj.catId.oid; + seq = bsearch(&key, sequences, nsequences, + sizeof(SequenceItem), SequenceItemCmp); /* Calculate default limits for a sequence of this type */ is_ascending = (seq->incby >= 0); diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c index e68937c9934..afcd9a218d8 100644 --- a/src/bin/pg_dump/pg_dumpall.c +++ b/src/bin/pg_dump/pg_dumpall.c @@ -785,11 +785,11 @@ dropRoles(PGconn *conn) int i_rolname; int i; - printfPQExpBuffer(buf, - "SELECT rolname " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 1", role_catalog); + printfPQExpBuffer(buf, + "SELECT rolname " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 1", role_catalog); res = executeQuery(conn, buf->data); @@ -843,16 +843,16 @@ dumpRoles(PGconn *conn) * Notes: rolconfig is dumped later, and pg_authid must be used for * extracting rolcomment regardless of role_catalog. */ - printfPQExpBuffer(buf, - "SELECT oid, rolname, rolsuper, rolinherit, " - "rolcreaterole, rolcreatedb, " - "rolcanlogin, rolconnlimit, rolpassword, " - "rolvaliduntil, rolreplication, rolbypassrls, " - "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " - "rolname = current_user AS is_current_user " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 2", role_catalog); + printfPQExpBuffer(buf, + "SELECT oid, rolname, rolsuper, rolinherit, " + "rolcreaterole, rolcreatedb, " + "rolcanlogin, rolconnlimit, rolpassword, " + "rolvaliduntil, rolreplication, rolbypassrls, " + "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " + "rolname = current_user AS is_current_user " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 2", role_catalog); res = executeQuery(conn, buf->data); diff --git a/src/bin/pg_upgrade/check.c b/src/bin/pg_upgrade/check.c index 786c1474829..f725f5ee3e2 100644 --- a/src/bin/pg_upgrade/check.c +++ b/src/bin/pg_upgrade/check.c @@ -1475,15 +1475,15 @@ check_for_incompatible_polymorphics(ClusterInfo *cluster) ", 'array_cat(anyarray,anyarray)'" ", 'array_prepend(anyelement,anyarray)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_remove(anyarray,anyelement)'" - ", 'array_replace(anyarray,anyelement,anyelement)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_remove(anyarray,anyelement)'" + ", 'array_replace(anyarray,anyelement,anyelement)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_position(anyarray,anyelement)'" - ", 'array_position(anyarray,anyelement,integer)'" - ", 'array_positions(anyarray,anyelement)'" - ", 'width_bucket(anyelement,anyarray)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_position(anyarray,anyelement)'" + ", 'array_position(anyarray,anyelement,integer)'" + ", 'array_positions(anyarray,anyelement)'" + ", 'width_bucket(anyelement,anyarray)'"); /* * The query below hardcodes FirstNormalObjectId as 16384 rather than diff --git a/src/bin/pg_upgrade/controldata.c b/src/bin/pg_upgrade/controldata.c index 8f81c9e9582..02ea02df60f 100644 --- a/src/bin/pg_upgrade/controldata.c +++ b/src/bin/pg_upgrade/controldata.c @@ -228,7 +228,7 @@ get_control_data(ClusterInfo *cluster) p++; /* remove ':' char */ cluster->controldata.chkpnt_nxtepoch = str2uint(p); - p = strchr(p, ':'); + p = strchr(p, ':'); if (p == NULL || strlen(p) <= 1) pg_fatal("%d: controldata retrieval problem", __LINE__); diff --git a/src/bin/pg_upgrade/exec.c b/src/bin/pg_upgrade/exec.c index 44355feea30..a1bdbf373e3 100644 --- a/src/bin/pg_upgrade/exec.c +++ b/src/bin/pg_upgrade/exec.c @@ -55,7 +55,7 @@ get_bin_version(ClusterInfo *cluster) if (sscanf(cmd_output, "%*s %*s %d.%d", &v1, &v2) < 1) pg_fatal("could not get pg_ctl version output from %s", cmd); - cluster->bin_version = v1 * 10000; + cluster->bin_version = v1 * 10000; } @@ -344,8 +344,8 @@ check_data_dir(ClusterInfo *cluster) check_single_dir(pg_data, "pg_subtrans"); check_single_dir(pg_data, PG_TBLSPC_DIR); check_single_dir(pg_data, "pg_twophase"); - check_single_dir(pg_data, "pg_wal"); - check_single_dir(pg_data, "pg_xact"); + check_single_dir(pg_data, "pg_wal"); + check_single_dir(pg_data, "pg_xact"); } @@ -385,7 +385,7 @@ check_bin_dir(ClusterInfo *cluster, bool check_versions) */ get_bin_version(cluster); - check_exec(cluster->bindir, "pg_resetwal", check_versions); + check_exec(cluster->bindir, "pg_resetwal", check_versions); if (cluster == &new_cluster) { diff --git a/src/bin/pg_upgrade/multixact_rewrite.c b/src/bin/pg_upgrade/multixact_rewrite.c index c45b3183684..c7a1416494d 100644 --- a/src/bin/pg_upgrade/multixact_rewrite.c +++ b/src/bin/pg_upgrade/multixact_rewrite.c @@ -61,52 +61,52 @@ rewrite_multixacts(MultiXactId from_multi, MultiXactId to_multi) * Convert old multixids, if needed, by reading them one-by-one from the * old cluster. */ - old_reader = AllocOldMultiXactRead(old_cluster.pgdata, - old_cluster.controldata.chkpnt_nxtmulti, - old_cluster.controldata.chkpnt_nxtmxoff); + old_reader = AllocOldMultiXactRead(old_cluster.pgdata, + old_cluster.controldata.chkpnt_nxtmulti, + old_cluster.controldata.chkpnt_nxtmxoff); - for (MultiXactId multi = from_multi; multi != to_multi;) - { - MultiXactMember member; - bool multixid_valid; - - /* - * Read this multixid's members. - * - * Locking-only XIDs that may be part of multi-xids don't matter - * after upgrade, as there can be no transactions running across - * upgrade. So as a small optimization, we only read one member - * from each multixid: the one updating one, or if there was no - * update, arbitrarily the first locking xid. - */ - multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); + for (MultiXactId multi = from_multi; multi != to_multi;) + { + MultiXactMember member; + bool multixid_valid; - /* - * Write the new offset to pg_multixact/offsets. - * - * Even if this multixid is invalid, we still need to write its - * offset if the *previous* multixid was valid. That's because - * when reading a multixid, the number of members is calculated - * from the difference between the two offsets. - */ - RecordMultiXactOffset(offsets_writer, multi, - (multixid_valid || prev_multixid_valid) ? next_offset : 0); + /* + * Read this multixid's members. + * + * Locking-only XIDs that may be part of multi-xids don't matter after + * upgrade, as there can be no transactions running across upgrade. So + * as a small optimization, we only read one member from each + * multixid: the one updating one, or if there was no update, + * arbitrarily the first locking xid. + */ + multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); - /* Write the members */ - if (multixid_valid) - { - RecordMultiXactMembers(members_writer, next_offset, 1, &member); - next_offset += 1; - } + /* + * Write the new offset to pg_multixact/offsets. + * + * Even if this multixid is invalid, we still need to write its offset + * if the *previous* multixid was valid. That's because when reading + * a multixid, the number of members is calculated from the difference + * between the two offsets. + */ + RecordMultiXactOffset(offsets_writer, multi, + (multixid_valid || prev_multixid_valid) ? next_offset : 0); - /* Advance to next multixid, handling wraparound */ - multi++; - if (multi < FirstMultiXactId) - multi = FirstMultiXactId; - prev_multixid_valid = multixid_valid; + /* Write the members */ + if (multixid_valid) + { + RecordMultiXactMembers(members_writer, next_offset, 1, &member); + next_offset += 1; } - FreeOldMultiXactReader(old_reader); + /* Advance to next multixid, handling wraparound */ + multi++; + if (multi < FirstMultiXactId) + multi = FirstMultiXactId; + prev_multixid_valid = multixid_valid; + } + + FreeOldMultiXactReader(old_reader); /* Write the final 'next' offset to the last SLRU page */ RecordMultiXactOffset(offsets_writer, to_multi, diff --git a/src/bin/pg_upgrade/pg_upgrade.c b/src/bin/pg_upgrade/pg_upgrade.c index c6af9035665..7366fd4627c 100644 --- a/src/bin/pg_upgrade/pg_upgrade.c +++ b/src/bin/pg_upgrade/pg_upgrade.c @@ -833,7 +833,7 @@ copy_xact_xlog_xid(void) * Determine the range of multixacts to convert. */ nxtmulti = old_cluster.controldata.chkpnt_nxtmulti; - oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; + oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; /* handle wraparound */ if (nxtmulti < FirstMultiXactId) nxtmulti = FirstMultiXactId; @@ -898,15 +898,15 @@ set_frozenxids(void) int i_datname; int i_datallowconn; - prep_status("Setting frozenxid and minmxid counters in new cluster"); + prep_status("Setting frozenxid and minmxid counters in new cluster"); conn_template1 = connectToServer(&new_cluster, "template1"); - /* set pg_database.datfrozenxid */ - PQclear(executeQueryOrDie(conn_template1, - "UPDATE pg_catalog.pg_database " - "SET datfrozenxid = '%u'", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_database.datfrozenxid */ + PQclear(executeQueryOrDie(conn_template1, + "UPDATE pg_catalog.pg_database " + "SET datfrozenxid = '%u'", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_database.datminmxid */ PQclear(executeQueryOrDie(conn_template1, @@ -942,16 +942,16 @@ set_frozenxids(void) conn = connectToServer(&new_cluster, datname); - /* set pg_class.relfrozenxid */ - PQclear(executeQueryOrDie(conn, - "UPDATE pg_catalog.pg_class " - "SET relfrozenxid = '%u' " - /* only heap, materialized view, and TOAST are vacuumed */ - "WHERE relkind IN (" - CppAsString2(RELKIND_RELATION) ", " - CppAsString2(RELKIND_MATVIEW) ", " - CppAsString2(RELKIND_TOASTVALUE) ")", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_class.relfrozenxid */ + PQclear(executeQueryOrDie(conn, + "UPDATE pg_catalog.pg_class " + "SET relfrozenxid = '%u' " + /* only heap, materialized view, and TOAST are vacuumed */ + "WHERE relkind IN (" + CppAsString2(RELKIND_RELATION) ", " + CppAsString2(RELKIND_MATVIEW) ", " + CppAsString2(RELKIND_TOASTVALUE) ")", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_class.relminmxid */ PQclear(executeQueryOrDie(conn, diff --git a/src/bin/pg_upgrade/relfilenumber.c b/src/bin/pg_upgrade/relfilenumber.c index ec2ff7acb21..6c467bdc8a5 100644 --- a/src/bin/pg_upgrade/relfilenumber.c +++ b/src/bin/pg_upgrade/relfilenumber.c @@ -587,32 +587,32 @@ transfer_relfile(FileNameMap *map, const char *type_suffix) /* Copying files might take some time, so give feedback. */ pg_log(PG_STATUS, "%s", old_file); - switch (user_opts.transfer_mode) - { - case TRANSFER_MODE_CLONE: - pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", - old_file, new_file); - cloneFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", - old_file, new_file); - copyFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY_FILE_RANGE: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", - old_file, new_file); - copyFileByRange(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_LINK: - pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", - old_file, new_file); - linkFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_SWAP: - /* swap mode is handled in its own code path */ - pg_fatal("should never happen"); - break; - } + switch (user_opts.transfer_mode) + { + case TRANSFER_MODE_CLONE: + pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", + old_file, new_file); + cloneFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", + old_file, new_file); + copyFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY_FILE_RANGE: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", + old_file, new_file); + copyFileByRange(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_LINK: + pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", + old_file, new_file); + linkFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_SWAP: + /* swap mode is handled in its own code path */ + pg_fatal("should never happen"); + break; + } } } diff --git a/src/bin/pg_upgrade/t/006_transfer_modes.pl b/src/bin/pg_upgrade/t/006_transfer_modes.pl index 9efa5dc863c..360d05c4b68 100644 --- a/src/bin/pg_upgrade/t/006_transfer_modes.pl +++ b/src/bin/pg_upgrade/t/006_transfer_modes.pl @@ -29,10 +29,8 @@ sub test_mode } $new->init(); - $new->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); - $old->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); + $new->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); + $old->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); # We can only test security labels if both the old and new installations # have dummy_seclabel. @@ -76,15 +74,14 @@ sub test_mode "CREATE TABLE test4 AS SELECT generate_series(400, 502)"); } - $old->safe_psql('postgres', - "CREATE TABLESPACE inplc_tblspc LOCATION ''"); - $old->safe_psql('postgres', - "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); - $old->safe_psql('postgres', - "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" - ); - $old->safe_psql('testdb3', - "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); + $old->safe_psql('postgres', "CREATE TABLESPACE inplc_tblspc LOCATION ''"); + $old->safe_psql('postgres', + "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); + $old->safe_psql('postgres', + "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" + ); + $old->safe_psql('testdb3', + "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); # While we are here, test handling of large objects. $old->safe_psql( @@ -152,12 +149,10 @@ sub test_mode } # Tests for in-place tablespaces. - $result = - $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); - is($result, '104', "test5 data after pg_upgrade $mode"); - $result = - $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); - is($result, '105', "test6 data after pg_upgrade $mode"); + $result = $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); + is($result, '104', "test5 data after pg_upgrade $mode"); + $result = $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); + is($result, '105', "test6 data after pg_upgrade $mode"); # Tests for large objects $result = $new->safe_psql('postgres', "SELECT lo_get(4532)"); diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index 44ef11d980e..c90bf8bbde2 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -6278,23 +6278,22 @@ get_create_object_cmd(EditableObjectType obj_type, Oid oid, * ensure the right view gets replaced. Also, check relation kind * to be sure it's a view. * - * Views may have WITH [LOCAL|CASCADED] - * CHECK OPTION. These are not part of the view definition - * returned by pg_get_viewdef() and so need to be retrieved - * separately. Materialized views may have - * arbitrary storage parameter reloptions. + * Views may have WITH [LOCAL|CASCADED] CHECK OPTION. These are + * not part of the view definition returned by pg_get_viewdef() + * and so need to be retrieved separately. Materialized views may + * have arbitrary storage parameter reloptions. */ printfPQExpBuffer(query, "/* %s */\n", _("Get view's definition and details")); - appendPQExpBuffer(query, - "SELECT nspname, relname, relkind, " - "pg_catalog.pg_get_viewdef(c.oid, true), " - "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " - "FROM pg_catalog.pg_class c " - "LEFT JOIN pg_catalog.pg_namespace n " - "ON c.relnamespace = n.oid WHERE c.oid = %u", - oid); + appendPQExpBuffer(query, + "SELECT nspname, relname, relkind, " + "pg_catalog.pg_get_viewdef(c.oid, true), " + "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " + "FROM pg_catalog.pg_class c " + "LEFT JOIN pg_catalog.pg_namespace n " + "ON c.relnamespace = n.oid WHERE c.oid = %u", + oid); break; } diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index ce99137c613..ac0c55e7aa5 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -387,19 +387,19 @@ describeFunctions(const char *functypes, const char *func_pattern, gettext_noop("stable"), gettext_noop("volatile"), gettext_noop("Volatility")); - appendPQExpBuffer(&buf, - ",\n CASE\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" - " END as \"%s\"", - gettext_noop("restricted"), - gettext_noop("safe"), - gettext_noop("unsafe"), - gettext_noop("Parallel")); + appendPQExpBuffer(&buf, + ",\n CASE\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" + " END as \"%s\"", + gettext_noop("restricted"), + gettext_noop("safe"), + gettext_noop("unsafe"), + gettext_noop("Parallel")); appendPQExpBuffer(&buf, ",\n pg_catalog.pg_get_userbyid(p.proowner) as \"%s\"" ",\n CASE WHEN prosecdef THEN '%s' ELSE '%s' END AS \"%s\"" @@ -599,8 +599,8 @@ describeFunctions(const char *functypes, const char *func_pattern, myopt.title = _("List of functions"); myopt.translate_header = true; - myopt.translate_columns = translate_columns; - myopt.n_translate_columns = lengthof(translate_columns); + myopt.translate_columns = translate_columns; + myopt.n_translate_columns = lengthof(translate_columns); printQuery(res, &myopt, pset.queryFout, false, pset.logfile); @@ -1086,38 +1086,38 @@ permissionsList(const char *pattern, bool showSystem) " ), E'\\n') AS \"%s\"", gettext_noop("Column privileges")); - appendPQExpBuffer(&buf, - ",\n pg_catalog.array_to_string(ARRAY(\n" - " SELECT polname\n" - " || CASE WHEN NOT polpermissive THEN\n" - " E' (RESTRICTIVE)'\n" - " ELSE '' END\n" - " || CASE WHEN polcmd != '*' THEN\n" - " E' (' || polcmd::pg_catalog.text || E'):'\n" - " ELSE E':'\n" - " END\n" - " || CASE WHEN polqual IS NOT NULL THEN\n" - " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" - " ELSE E''\n" - " END\n" - " || CASE WHEN polwithcheck IS NOT NULL THEN\n" - " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" - " ELSE E''\n" - " END" - " || CASE WHEN polroles <> '{0}' THEN\n" - " E'\\n to: ' || pg_catalog.array_to_string(\n" - " ARRAY(\n" - " SELECT rolname\n" - " FROM pg_catalog.pg_roles\n" - " WHERE oid = ANY (polroles)\n" - " ORDER BY 1\n" - " ), E', ')\n" - " ELSE E''\n" - " END\n" - " FROM pg_catalog.pg_policy pol\n" - " WHERE polrelid = c.oid), E'\\n')\n" - " AS \"%s\"", - gettext_noop("Policies")); + appendPQExpBuffer(&buf, + ",\n pg_catalog.array_to_string(ARRAY(\n" + " SELECT polname\n" + " || CASE WHEN NOT polpermissive THEN\n" + " E' (RESTRICTIVE)'\n" + " ELSE '' END\n" + " || CASE WHEN polcmd != '*' THEN\n" + " E' (' || polcmd::pg_catalog.text || E'):'\n" + " ELSE E':'\n" + " END\n" + " || CASE WHEN polqual IS NOT NULL THEN\n" + " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" + " ELSE E''\n" + " END\n" + " || CASE WHEN polwithcheck IS NOT NULL THEN\n" + " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" + " ELSE E''\n" + " END" + " || CASE WHEN polroles <> '{0}' THEN\n" + " E'\\n to: ' || pg_catalog.array_to_string(\n" + " ARRAY(\n" + " SELECT rolname\n" + " FROM pg_catalog.pg_roles\n" + " WHERE oid = ANY (polroles)\n" + " ORDER BY 1\n" + " ), E', ')\n" + " ELSE E''\n" + " END\n" + " FROM pg_catalog.pg_policy pol\n" + " WHERE polrelid = c.oid), E'\\n')\n" + " AS \"%s\"", + gettext_noop("Policies")); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_class c\n" " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n" @@ -1675,27 +1675,27 @@ describeOneTableDetails(const char *schemaname, char *footers[3] = {NULL, NULL, NULL}; printfPQExpBuffer(&buf, "/* %s */\n", _("Get sequence information")); - appendPQExpBuffer(&buf, - "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" - " seqstart AS \"%s\",\n" - " seqmin AS \"%s\",\n" - " seqmax AS \"%s\",\n" - " seqincrement AS \"%s\",\n" - " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" - " seqcache AS \"%s\"\n", - gettext_noop("Type"), - gettext_noop("Start"), - gettext_noop("Minimum"), - gettext_noop("Maximum"), - gettext_noop("Increment"), - gettext_noop("yes"), - gettext_noop("no"), - gettext_noop("Cycles?"), - gettext_noop("Cache")); - appendPQExpBuffer(&buf, - "FROM pg_catalog.pg_sequence\n" - "WHERE seqrelid = '%s';", - oid); + appendPQExpBuffer(&buf, + "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" + " seqstart AS \"%s\",\n" + " seqmin AS \"%s\",\n" + " seqmax AS \"%s\",\n" + " seqincrement AS \"%s\",\n" + " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" + " seqcache AS \"%s\"\n", + gettext_noop("Type"), + gettext_noop("Start"), + gettext_noop("Minimum"), + gettext_noop("Maximum"), + gettext_noop("Increment"), + gettext_noop("yes"), + gettext_noop("no"), + gettext_noop("Cycles?"), + gettext_noop("Cache")); + appendPQExpBuffer(&buf, + "FROM pg_catalog.pg_sequence\n" + "WHERE seqrelid = '%s';", + oid); res = PSQLexec(buf.data); if (!res) @@ -1913,7 +1913,7 @@ describeOneTableDetails(const char *schemaname, appendPQExpBufferStr(&buf, ",\n (SELECT c.collname FROM pg_catalog.pg_collation c, pg_catalog.pg_type t\n" " WHERE c.oid = a.attcollation AND t.oid = a.atttypid AND a.attcollation <> t.typcollation) AS attcollation"); attcoll_col = cols++; - appendPQExpBufferStr(&buf, ",\n a.attidentity"); + appendPQExpBufferStr(&buf, ",\n a.attidentity"); attidentity_col = cols++; if (pset.sversion >= 120000) appendPQExpBufferStr(&buf, ",\n a.attgenerated"); @@ -2326,7 +2326,7 @@ describeOneTableDetails(const char *schemaname, CppAsString2(CONSTRAINT_EXCLUSION) ") AND " "condeferred) AS condeferred,\n"); - appendPQExpBufferStr(&buf, "i.indisreplident,\n"); + appendPQExpBufferStr(&buf, "i.indisreplident,\n"); if (pset.sversion >= 150000) appendPQExpBufferStr(&buf, "i.indnullsnotdistinct,\n"); @@ -2431,7 +2431,7 @@ describeOneTableDetails(const char *schemaname, "pg_catalog.pg_get_indexdef(i.indexrelid, 0, true),\n " "pg_catalog.pg_get_constraintdef(con.oid, true), " "contype, condeferrable, condeferred"); - appendPQExpBufferStr(&buf, ", i.indisreplident"); + appendPQExpBufferStr(&buf, ", i.indisreplident"); appendPQExpBufferStr(&buf, ", c2.reltablespace"); if (pset.sversion >= 180000) appendPQExpBufferStr(&buf, ", con.conperiod"); @@ -2682,81 +2682,80 @@ describeOneTableDetails(const char *schemaname, PQclear(result); /* print any row-level policies */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get row-level policies for this table")); - appendPQExpBufferStr(&buf, "SELECT pol.polname,"); - appendPQExpBufferStr(&buf, - " pol.polpermissive,\n"); - appendPQExpBuffer(&buf, - " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" - " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" - " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" - " CASE pol.polcmd\n" - " WHEN 'r' THEN 'SELECT'\n" - " WHEN 'a' THEN 'INSERT'\n" - " WHEN 'w' THEN 'UPDATE'\n" - " WHEN 'd' THEN 'DELETE'\n" - " END AS cmd\n" - "FROM pg_catalog.pg_policy pol\n" - "WHERE pol.polrelid = '%s' ORDER BY 1;", - oid); + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get row-level policies for this table")); + appendPQExpBufferStr(&buf, "SELECT pol.polname,"); + appendPQExpBufferStr(&buf, + " pol.polpermissive,\n"); + appendPQExpBuffer(&buf, + " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" + " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" + " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" + " CASE pol.polcmd\n" + " WHEN 'r' THEN 'SELECT'\n" + " WHEN 'a' THEN 'INSERT'\n" + " WHEN 'w' THEN 'UPDATE'\n" + " WHEN 'd' THEN 'DELETE'\n" + " END AS cmd\n" + "FROM pg_catalog.pg_policy pol\n" + "WHERE pol.polrelid = '%s' ORDER BY 1;", + oid); - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - /* - * Handle cases where RLS is enabled and there are policies, or - * there aren't policies, or RLS isn't enabled but there are - * policies - */ - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies:")); + /* + * Handle cases where RLS is enabled and there are policies, or there + * aren't policies, or RLS isn't enabled but there are policies + */ + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies:")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled):")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled):")); - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); - if (!tableinfo.rowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (row security disabled):")); + if (!tableinfo.rowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (row security disabled):")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " POLICY \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " POLICY \"%s\"", + PQgetvalue(result, i, 0)); - if (*(PQgetvalue(result, i, 1)) == 'f') - appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); + if (*(PQgetvalue(result, i, 1)) == 'f') + appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); - if (!PQgetisnull(result, i, 5)) - appendPQExpBuffer(&buf, " FOR %s", - PQgetvalue(result, i, 5)); + if (!PQgetisnull(result, i, 5)) + appendPQExpBuffer(&buf, " FOR %s", + PQgetvalue(result, i, 5)); - if (!PQgetisnull(result, i, 2)) - { - appendPQExpBuffer(&buf, "\n TO %s", - PQgetvalue(result, i, 2)); - } + if (!PQgetisnull(result, i, 2)) + { + appendPQExpBuffer(&buf, "\n TO %s", + PQgetvalue(result, i, 2)); + } - if (!PQgetisnull(result, i, 3)) - appendPQExpBuffer(&buf, "\n USING (%s)", - PQgetvalue(result, i, 3)); + if (!PQgetisnull(result, i, 3)) + appendPQExpBuffer(&buf, "\n USING (%s)", + PQgetvalue(result, i, 3)); - if (!PQgetisnull(result, i, 4)) - appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", - PQgetvalue(result, i, 4)); + if (!PQgetisnull(result, i, 4)) + appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", + PQgetvalue(result, i, 4)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* print any extended statistics */ if (pset.sversion >= 140000) @@ -3025,115 +3024,115 @@ describeOneTableDetails(const char *schemaname, } /* print any publications */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get publications that publish this table")); - if (pset.sversion >= 150000) + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get publications that publish this table")); + if (pset.sversion >= 150000) + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" + " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" + "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" + "UNION\n" + "SELECT pubname\n" + " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" + " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" + " (SELECT pg_catalog.string_agg(attname, ', ')\n" + " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" + " pg_catalog.pg_attribute\n" + " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" + " ELSE NULL END) " + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" + "WHERE pr.prrelid = '%s'\n", + oid, oid, oid); + + if (pset.sversion >= 190000) { + /* + * Skip entries where this relation appears in the + * publication's EXCEPT list. + */ appendPQExpBuffer(&buf, + " AND NOT pr.prexcept\n" + "UNION\n" "SELECT pubname\n" " , NULL\n" " , NULL\n" "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" - " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" - "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" - "UNION\n" - "SELECT pubname\n" - " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" - " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" - " (SELECT pg_catalog.string_agg(attname, ', ')\n" - " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" - " pg_catalog.pg_attribute\n" - " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" - " ELSE NULL END) " - "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" - "WHERE pr.prrelid = '%s'\n", + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + " AND NOT EXISTS (\n" + " SELECT 1\n" + " FROM pg_catalog.pg_publication_rel pr\n" + " WHERE pr.prpubid = p.oid AND\n" + " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" + "ORDER BY 1;", oid, oid, oid); - - if (pset.sversion >= 190000) - { - /* - * Skip entries where this relation appears in the - * publication's EXCEPT list. - */ - appendPQExpBuffer(&buf, - " AND NOT pr.prexcept\n" - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - " AND NOT EXISTS (\n" - " SELECT 1\n" - " FROM pg_catalog.pg_publication_rel pr\n" - " WHERE pr.prpubid = p.oid AND\n" - " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" - "ORDER BY 1;", - oid, oid, oid); - } - else - { - appendPQExpBuffer(&buf, - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - "ORDER BY 1;", - oid); - } } else { appendPQExpBuffer(&buf, + "UNION\n" "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - "WHERE pr.prrelid = '%s'\n" - "UNION ALL\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" + " , NULL\n" + " , NULL\n" "FROM pg_catalog.pg_publication p\n" "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" "ORDER BY 1;", - oid, oid); + oid); } + } + else + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + "WHERE pr.prrelid = '%s'\n" + "UNION ALL\n" + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + "ORDER BY 1;", + oid, oid); + } - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - if (tuples > 0) - printTableAddFooter(&cont, _("Included in publications:")); + if (tuples > 0) + printTableAddFooter(&cont, _("Included in publications:")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " \"%s\"", + PQgetvalue(result, i, 0)); - /* column list (if any) */ - if (!PQgetisnull(result, i, 2)) - appendPQExpBuffer(&buf, " (%s)", - PQgetvalue(result, i, 2)); + /* column list (if any) */ + if (!PQgetisnull(result, i, 2)) + appendPQExpBuffer(&buf, " (%s)", + PQgetvalue(result, i, 2)); - /* row filter (if any) */ - if (!PQgetisnull(result, i, 1)) - appendPQExpBuffer(&buf, " WHERE %s", - PQgetvalue(result, i, 1)); + /* row filter (if any) */ + if (!PQgetisnull(result, i, 1)) + appendPQExpBuffer(&buf, " WHERE %s", + PQgetvalue(result, i, 1)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* Print publications where the table is in the EXCEPT clause */ if (pset.sversion >= 190000) @@ -3805,7 +3804,7 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) ncols++; } appendPQExpBufferStr(&buf, "\n, r.rolreplication"); - appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); + appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_roles r\n"); @@ -3860,8 +3859,8 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) if (strcmp(PQgetvalue(res, i, (verbose ? 9 : 8)), "t") == 0) add_role_attribute(&buf, _("Replication")); - if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) - add_role_attribute(&buf, _("Bypass RLS")); + if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) + add_role_attribute(&buf, _("Bypass RLS")); conns = atoi(PQgetvalue(res, i, 6)); if (conns >= 0) @@ -5155,14 +5154,14 @@ listCollations(const char *pattern, bool verbose, bool showSystem) gettext_noop("Schema"), gettext_noop("Name")); - appendPQExpBuffer(&buf, - " CASE c.collprovider " - "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " - "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " - "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " - "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " - "END AS \"%s\",\n", - gettext_noop("Provider")); + appendPQExpBuffer(&buf, + " CASE c.collprovider " + "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " + "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " + "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " + "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " + "END AS \"%s\",\n", + gettext_noop("Provider")); appendPQExpBuffer(&buf, " c.collcollate AS \"%s\",\n" -- 2.50.1 (Apple Git-155) --aHl3HfeiUuO3zeNC-- ^ permalink raw reply [nested|flat] 59+ messages in thread
* [PATCH v6 4/4] run pgindent and pgperltidy @ 2026-06-30 18:24 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 59+ messages in thread From: Nathan Bossart @ 2026-06-30 18:24 UTC (permalink / raw) --- src/bin/pg_dump/pg_dump.c | 464 ++++++++++----------- src/bin/pg_dump/pg_dumpall.c | 30 +- src/bin/pg_upgrade/check.c | 16 +- src/bin/pg_upgrade/controldata.c | 2 +- src/bin/pg_upgrade/exec.c | 8 +- src/bin/pg_upgrade/multixact_rewrite.c | 80 ++-- src/bin/pg_upgrade/pg_upgrade.c | 34 +- src/bin/pg_upgrade/relfilenumber.c | 54 +-- src/bin/pg_upgrade/t/006_transfer_modes.pl | 33 +- src/bin/psql/command.c | 29 +- src/bin/psql/describe.c | 461 ++++++++++---------- 11 files changed, 601 insertions(+), 610 deletions(-) diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 65bd15ebfd2..5673268b467 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -1491,8 +1491,8 @@ setup_connection(Archive *AH, const char *dumpencoding, * Disable timeouts if supported. */ ExecuteSqlStatement(AH, "SET statement_timeout = 0"); - ExecuteSqlStatement(AH, "SET lock_timeout = 0"); - ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); + ExecuteSqlStatement(AH, "SET lock_timeout = 0"); + ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); if (AH->remoteVersion >= 170000) ExecuteSqlStatement(AH, "SET transaction_timeout = 0"); @@ -1505,10 +1505,10 @@ setup_connection(Archive *AH, const char *dumpencoding, /* * Adjust row-security mode, if supported. */ - if (dopt->enable_row_security) - ExecuteSqlStatement(AH, "SET row_security = on"); - else - ExecuteSqlStatement(AH, "SET row_security = off"); + if (dopt->enable_row_security) + ExecuteSqlStatement(AH, "SET row_security = on"); + else + ExecuteSqlStatement(AH, "SET row_security = off"); /* * For security reasons, we restrict the expansion of non-system views and @@ -1933,10 +1933,9 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) addObjectDependency(dobj, ext->dobj.dumpId); /* - * Mark the member object to have any non-initial ACLs - * dumped. (Any initial ACLs will be removed later, using data from - * pg_init_privs, so that we'll dump only the delta from the extension's - * initial setup.) + * Mark the member object to have any non-initial ACLs dumped. (Any + * initial ACLs will be removed later, using data from pg_init_privs, so + * that we'll dump only the delta from the extension's initial setup.) * * In binary upgrades, we still dump all components of the members * individually, since the idea is to exactly reproduce the database @@ -1953,7 +1952,7 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) if (fout->dopt->binary_upgrade) dobj->dump = ext->dobj.dump; else - dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); + dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); return true; } @@ -1987,9 +1986,9 @@ selectDumpableNamespace(NamespaceInfo *nsinfo, Archive *fout) else if (strcmp(nsinfo->dobj.name, "pg_catalog") == 0) { /* - * We dump out any ACLs defined in pg_catalog, if - * they are interesting (and not the original ACLs which were set at - * initdb time, see pg_init_privs). + * We dump out any ACLs defined in pg_catalog, if they are interesting + * (and not the original ACLs which were set at initdb time, see + * pg_init_privs). */ nsinfo->dobj.dump_contains = nsinfo->dobj.dump = DUMP_COMPONENT_ACL; } @@ -3296,7 +3295,7 @@ dumpDatabase(Archive *fout) "datcollate, datctype, datfrozenxid, " "datacl, acldefault('d', datdba) AS acldefault, " "datistemplate, datconnlimit, "); - appendPQExpBufferStr(dbQry, "datminmxid, "); + appendPQExpBufferStr(dbQry, "datminmxid, "); if (fout->remoteVersion >= 170000) appendPQExpBufferStr(dbQry, "datlocprovider, datlocale, datcollversion, "); else if (fout->remoteVersion >= 150000) @@ -3638,11 +3637,11 @@ dumpDatabase(Archive *fout) ii_oid, ii_relminmxid; - appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" - "FROM pg_catalog.pg_class\n" - "WHERE oid IN (%u, %u, %u, %u);\n", - LargeObjectRelationId, LargeObjectLOidPNIndexId, - LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); + appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" + "FROM pg_catalog.pg_class\n" + "WHERE oid IN (%u, %u, %u, %u);\n", + LargeObjectRelationId, LargeObjectLOidPNIndexId, + LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); lo_res = ExecuteSqlQuery(fout, loFrozenQry->data, PGRES_TUPLES_OK); @@ -4274,7 +4273,7 @@ getPolicies(Archive *fout, TableInfo tblinfo[], int numTables) printfPQExpBuffer(query, "SELECT pol.oid, pol.tableoid, pol.polrelid, pol.polname, pol.polcmd, "); - appendPQExpBufferStr(query, "pol.polpermissive, "); + appendPQExpBufferStr(query, "pol.polpermissive, "); appendPQExpBuffer(query, "CASE WHEN pol.polroles = '{0}' THEN NULL ELSE " " pg_catalog.array_to_string(ARRAY(SELECT pg_catalog.quote_ident(rolname) from pg_catalog.pg_roles WHERE oid = ANY(pol.polroles)), ', ') END AS polroles, " @@ -6633,9 +6632,9 @@ getAccessMethods(Archive *fout) * Select all access methods from pg_am table. */ appendPQExpBufferStr(query, "SELECT tableoid, oid, amname, "); - appendPQExpBufferStr(query, - "amtype, " - "amhandler::pg_catalog.regproc AS amhandler "); + appendPQExpBufferStr(query, + "amtype, " + "amhandler::pg_catalog.regproc AS amhandler "); appendPQExpBufferStr(query, "FROM pg_am"); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6827,35 +6826,35 @@ getAggregates(Archive *fout) * Find all interesting aggregates. See comment in getFuncs() for the * rationale behind the filtering logic. */ - agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" - : "p.proisagg"); + agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" + : "p.proisagg"); - appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " - "p.proname AS aggname, " - "p.pronamespace AS aggnamespace, " - "p.pronargs, p.proargtypes, " - "p.proowner, " - "p.proacl AS aggacl, " - "acldefault('f', p.proowner) AS acldefault " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s AND (" - "p.pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog') OR " - "p.proacl IS DISTINCT FROM pip.initprivs", - agg_check); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - " OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); - appendPQExpBufferChar(query, ')'); + appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " + "p.proname AS aggname, " + "p.pronamespace AS aggnamespace, " + "p.pronargs, p.proargtypes, " + "p.proowner, " + "p.proacl AS aggacl, " + "acldefault('f', p.proowner) AS acldefault " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s AND (" + "p.pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog') OR " + "p.proacl IS DISTINCT FROM pip.initprivs", + agg_check); + if (dopt->binary_upgrade) + appendPQExpBufferStr(query, + " OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6957,53 +6956,53 @@ getFuncs(Archive *fout) * include them, since we want to dump extension members individually in * that mode. Also, if they are used by casts or transforms then we need * to gather the information about them, though they won't be dumped if - * they are built-in. Also, include functions in - * pg_catalog if they have an ACL different from what's shown in - * pg_init_privs (so we have to join to pg_init_privs; annoying). + * they are built-in. Also, include functions in pg_catalog if they have + * an ACL different from what's shown in pg_init_privs (so we have to join + * to pg_init_privs; annoying). */ - not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" - : "NOT p.proisagg"); + not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" + : "NOT p.proisagg"); - appendPQExpBuffer(query, - "SELECT p.tableoid, p.oid, p.proname, p.prolang, " - "p.pronargs, p.proargtypes, p.prorettype, " - "p.proacl, " - "acldefault('f', p.proowner) AS acldefault, " - "p.pronamespace, " - "p.proowner " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s" - "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " - "WHERE classid = 'pg_proc'::regclass AND " - "objid = p.oid AND deptype = 'i')" - "\n AND (" - "\n pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog')" - "\n OR EXISTS (SELECT 1 FROM pg_cast" - "\n WHERE pg_cast.oid > %u " - "\n AND p.oid = pg_cast.castfunc)" - "\n OR EXISTS (SELECT 1 FROM pg_transform" - "\n WHERE pg_transform.oid > %u AND " - "\n (p.oid = pg_transform.trffromsql" - "\n OR p.oid = pg_transform.trftosql))", - not_agg_check, - g_last_builtin_oid, - g_last_builtin_oid); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); + appendPQExpBuffer(query, + "SELECT p.tableoid, p.oid, p.proname, p.prolang, " + "p.pronargs, p.proargtypes, p.prorettype, " + "p.proacl, " + "acldefault('f', p.proowner) AS acldefault, " + "p.pronamespace, " + "p.proowner " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s" + "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " + "WHERE classid = 'pg_proc'::regclass AND " + "objid = p.oid AND deptype = 'i')" + "\n AND (" + "\n pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog')" + "\n OR EXISTS (SELECT 1 FROM pg_cast" + "\n WHERE pg_cast.oid > %u " + "\n AND p.oid = pg_cast.castfunc)" + "\n OR EXISTS (SELECT 1 FROM pg_transform" + "\n WHERE pg_transform.oid > %u AND " + "\n (p.oid = pg_transform.trffromsql" + "\n OR p.oid = pg_transform.trftosql))", + not_agg_check, + g_last_builtin_oid, + g_last_builtin_oid); + if (dopt->binary_upgrade) appendPQExpBufferStr(query, - "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); - appendPQExpBufferChar(query, ')'); + "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferStr(query, + "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -7252,31 +7251,31 @@ getTables(Archive *fout, int *numTables) appendPQExpBufferStr(query, "c.relhasoids, "); - appendPQExpBufferStr(query, - "c.relispopulated, "); + appendPQExpBufferStr(query, + "c.relispopulated, "); - appendPQExpBufferStr(query, - "c.relreplident, "); + appendPQExpBufferStr(query, + "c.relreplident, "); - appendPQExpBufferStr(query, - "c.relrowsecurity, c.relforcerowsecurity, "); + appendPQExpBufferStr(query, + "c.relrowsecurity, c.relforcerowsecurity, "); - appendPQExpBufferStr(query, - "c.relminmxid, tc.relminmxid AS tminmxid, "); + appendPQExpBufferStr(query, + "c.relminmxid, tc.relminmxid AS tminmxid, "); - appendPQExpBufferStr(query, - "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); + appendPQExpBufferStr(query, + "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); - appendPQExpBufferStr(query, - "am.amname, "); + appendPQExpBufferStr(query, + "am.amname, "); - appendPQExpBufferStr(query, - "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); + appendPQExpBufferStr(query, + "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); - appendPQExpBufferStr(query, - "c.relispartition AS ispartition "); + appendPQExpBufferStr(query, + "c.relispartition AS ispartition "); /* * Left join to pg_depend to pick up dependency info linking sequences to @@ -7296,8 +7295,8 @@ getTables(Archive *fout, int *numTables) /* * Left join to pg_am to pick up the amname. */ - appendPQExpBufferStr(query, - "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); + appendPQExpBufferStr(query, + "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); /* * We purposefully ignore toast OIDs for partitioned tables; the reason is @@ -7868,8 +7867,8 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables) "t.reloptions AS indreloptions, "); - appendPQExpBufferStr(query, - "i.indisreplident, "); + appendPQExpBufferStr(query, + "i.indisreplident, "); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -9313,8 +9312,8 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables) appendPQExpBufferStr(q, "'' AS attcompression,\n"); - appendPQExpBufferStr(q, - "a.attidentity,\n"); + appendPQExpBufferStr(q, + "a.attidentity,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(q, @@ -10717,73 +10716,73 @@ getAdditionalACLs(Archive *fout) PQclear(res); /* Fetch initial-privileges data */ - printfPQExpBuffer(query, - "SELECT objoid, classoid, objsubid, privtype, initprivs " - "FROM pg_init_privs"); + printfPQExpBuffer(query, + "SELECT objoid, classoid, objsubid, privtype, initprivs " + "FROM pg_init_privs"); - res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); + res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); - ntups = PQntuples(res); - for (i = 0; i < ntups; i++) - { - Oid objoid = atooid(PQgetvalue(res, i, 0)); - Oid classoid = atooid(PQgetvalue(res, i, 1)); - int objsubid = atoi(PQgetvalue(res, i, 2)); - char privtype = *(PQgetvalue(res, i, 3)); - char *initprivs = PQgetvalue(res, i, 4); - CatalogId objId; - DumpableObject *dobj; + ntups = PQntuples(res); + for (i = 0; i < ntups; i++) + { + Oid objoid = atooid(PQgetvalue(res, i, 0)); + Oid classoid = atooid(PQgetvalue(res, i, 1)); + int objsubid = atoi(PQgetvalue(res, i, 2)); + char privtype = *(PQgetvalue(res, i, 3)); + char *initprivs = PQgetvalue(res, i, 4); + CatalogId objId; + DumpableObject *dobj; - objId.tableoid = classoid; - objId.oid = objoid; - dobj = findObjectByCatalogId(objId); - /* OK to ignore entries we haven't got a DumpableObject for */ - if (dobj) + objId.tableoid = classoid; + objId.oid = objoid; + dobj = findObjectByCatalogId(objId); + /* OK to ignore entries we haven't got a DumpableObject for */ + if (dobj) + { + /* Cope with sub-object initprivs */ + if (objsubid != 0) { - /* Cope with sub-object initprivs */ - if (objsubid != 0) - { - if (dobj->objType == DO_TABLE) - { - /* For a column initprivs, set the table's ACL flags */ - dobj->components |= DUMP_COMPONENT_ACL; - ((TableInfo *) dobj)->hascolumnACLs = true; - } - else - pg_log_warning("unsupported pg_init_privs entry: %u %u %d", - classoid, objoid, objsubid); - continue; - } - - /* - * We ignore any pg_init_privs.initprivs entry for the public - * schema, as explained in getNamespaces(). - */ - if (dobj->objType == DO_NAMESPACE && - strcmp(dobj->name, "public") == 0) - continue; - - /* Else it had better be of a type we think has ACLs */ - if (dobj->objType == DO_NAMESPACE || - dobj->objType == DO_TYPE || - dobj->objType == DO_FUNC || - dobj->objType == DO_AGG || - dobj->objType == DO_TABLE || - dobj->objType == DO_PROCLANG || - dobj->objType == DO_FDW || - dobj->objType == DO_FOREIGN_SERVER) + if (dobj->objType == DO_TABLE) { - DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; - - daobj->dacl.privtype = privtype; - daobj->dacl.initprivs = pstrdup(initprivs); + /* For a column initprivs, set the table's ACL flags */ + dobj->components |= DUMP_COMPONENT_ACL; + ((TableInfo *) dobj)->hascolumnACLs = true; } else pg_log_warning("unsupported pg_init_privs entry: %u %u %d", classoid, objoid, objsubid); + continue; + } + + /* + * We ignore any pg_init_privs.initprivs entry for the public + * schema, as explained in getNamespaces(). + */ + if (dobj->objType == DO_NAMESPACE && + strcmp(dobj->name, "public") == 0) + continue; + + /* Else it had better be of a type we think has ACLs */ + if (dobj->objType == DO_NAMESPACE || + dobj->objType == DO_TYPE || + dobj->objType == DO_FUNC || + dobj->objType == DO_AGG || + dobj->objType == DO_TABLE || + dobj->objType == DO_PROCLANG || + dobj->objType == DO_FDW || + dobj->objType == DO_FOREIGN_SERVER) + { + DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; + + daobj->dacl.privtype = privtype; + daobj->dacl.initprivs = pstrdup(initprivs); } + else + pg_log_warning("unsupported pg_init_privs entry: %u %u %d", + classoid, objoid, objsubid); } - PQclear(res); + } + PQclear(res); destroyPQExpBuffer(query); } @@ -11128,8 +11127,8 @@ dumpRelationStats_dumper(Archive *fout, const void *userArg, const TocEntry *te) * The results must be in the order of the relations supplied in the * parameters to ensure we remain in sync as we walk through the TOC. * - * For versions before 19, the redundant filter clause on s.tablename = - * ANY(...) seems sufficient to convince the planner to use + * For versions before 19, the redundant filter clause on s.tablename + * = ANY(...) seems sufficient to convince the planner to use * pg_class_relname_nsp_index, which avoids a full scan of pg_stats. * In newer versions, pg_stats returns the table OIDs, eliminating the * need for that hack. @@ -13469,11 +13468,11 @@ dumpFunc(Archive *fout, const FuncInfo *finfo) "pg_catalog.pg_get_function_result(p.oid) AS funcresult,\n" "proleakproof,\n"); - appendPQExpBufferStr(query, - "array_to_string(protrftypes, ' ') AS protrftypes,\n"); + appendPQExpBufferStr(query, + "array_to_string(protrftypes, ' ') AS protrftypes,\n"); - appendPQExpBufferStr(query, - "proparallel,\n"); + appendPQExpBufferStr(query, + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -14963,9 +14962,9 @@ dumpCollation(Archive *fout, const CollInfo *collinfo) /* Get collation-specific details */ appendPQExpBufferStr(query, "SELECT "); - appendPQExpBufferStr(query, - "collprovider, " - "collversion, "); + appendPQExpBufferStr(query, + "collprovider, " + "collversion, "); if (fout->remoteVersion >= 120000) appendPQExpBufferStr(query, @@ -15372,23 +15371,23 @@ dumpAgg(Archive *fout, const AggInfo *agginfo) "pg_catalog.pg_get_function_arguments(p.oid) AS funcargs,\n" "pg_catalog.pg_get_function_identity_arguments(p.oid) AS funciargs,\n"); - appendPQExpBufferStr(query, - "aggkind,\n" - "aggmtransfn,\n" - "aggminvtransfn,\n" - "aggmfinalfn,\n" - "aggmtranstype::pg_catalog.regtype,\n" - "aggfinalextra,\n" - "aggmfinalextra,\n" - "aggtransspace,\n" - "aggmtransspace,\n" - "aggminitval,\n"); + appendPQExpBufferStr(query, + "aggkind,\n" + "aggmtransfn,\n" + "aggminvtransfn,\n" + "aggmfinalfn,\n" + "aggmtranstype::pg_catalog.regtype,\n" + "aggfinalextra,\n" + "aggmfinalextra,\n" + "aggtransspace,\n" + "aggmtransspace,\n" + "aggminitval,\n"); - appendPQExpBufferStr(query, - "aggcombinefn,\n" - "aggserialfn,\n" - "aggdeserialfn,\n" - "proparallel,\n"); + appendPQExpBufferStr(query, + "aggcombinefn,\n" + "aggserialfn,\n" + "aggdeserialfn,\n" + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -16848,30 +16847,30 @@ dumpTable(Archive *fout, const TableInfo *tbinfo) appendPQExpBufferStr(query, "PREPARE getColumnACLs(pg_catalog.oid) AS\n"); - /* - * In principle we should call acldefault('c', relowner) to - * get the default ACL for a column. However, we don't - * currently store the numeric OID of the relowner in - * TableInfo. We could convert the owner name using regrole, - * but that creates a risk of failure due to concurrent role - * renames. Given that the default ACL for columns is empty - * and is likely to stay that way, it's not worth extra cycles - * and risk to avoid hard-wiring that knowledge here. - */ - appendPQExpBufferStr(query, - "SELECT at.attname, " - "at.attacl, " - "'{}' AS acldefault, " - "pip.privtype, pip.initprivs " - "FROM pg_catalog.pg_attribute at " - "LEFT JOIN pg_catalog.pg_init_privs pip ON " - "(at.attrelid = pip.objoid " - "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " - "AND at.attnum = pip.objsubid) " - "WHERE at.attrelid = $1 AND " - "NOT at.attisdropped " - "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " - "ORDER BY at.attnum"); + /* + * In principle we should call acldefault('c', relowner) to get + * the default ACL for a column. However, we don't currently + * store the numeric OID of the relowner in TableInfo. We could + * convert the owner name using regrole, but that creates a risk + * of failure due to concurrent role renames. Given that the + * default ACL for columns is empty and is likely to stay that + * way, it's not worth extra cycles and risk to avoid hard-wiring + * that knowledge here. + */ + appendPQExpBufferStr(query, + "SELECT at.attname, " + "at.attacl, " + "'{}' AS acldefault, " + "pip.privtype, pip.initprivs " + "FROM pg_catalog.pg_attribute at " + "LEFT JOIN pg_catalog.pg_init_privs pip ON " + "(at.attrelid = pip.objoid " + "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " + "AND at.attnum = pip.objsubid) " + "WHERE at.attrelid = $1 AND " + "NOT at.attisdropped " + "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " + "ORDER BY at.attnum"); ExecuteSqlStatement(fout, query->data); @@ -19165,7 +19164,7 @@ collectSequences(Archive *fout) * pg_get_sequence_data(), but we only do so for non-schema-only dumps. */ if (fout->remoteVersion < 180000 || - (!fout->dopt->dumpData && !fout->dopt->sequence_data)) + (!fout->dopt->dumpData && !fout->dopt->sequence_data)) query = "SELECT seqrelid, format_type(seqtypid, NULL), " "seqstart, seqincrement, " "seqmax, seqmin, " @@ -19227,15 +19226,14 @@ dumpSequence(Archive *fout, const TableInfo *tbinfo) qseqname = pg_strdup(fmtId(tbinfo->dobj.name)); /* - * The sequence information is gathered in a sorted - * table before any calls to dumpSequence(). See collectSequences() for - * more information. + * The sequence information is gathered in a sorted table before any calls + * to dumpSequence(). See collectSequences() for more information. */ - Assert(sequences); + Assert(sequences); - key.oid = tbinfo->dobj.catId.oid; - seq = bsearch(&key, sequences, nsequences, - sizeof(SequenceItem), SequenceItemCmp); + key.oid = tbinfo->dobj.catId.oid; + seq = bsearch(&key, sequences, nsequences, + sizeof(SequenceItem), SequenceItemCmp); /* Calculate default limits for a sequence of this type */ is_ascending = (seq->incby >= 0); diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c index e68937c9934..afcd9a218d8 100644 --- a/src/bin/pg_dump/pg_dumpall.c +++ b/src/bin/pg_dump/pg_dumpall.c @@ -785,11 +785,11 @@ dropRoles(PGconn *conn) int i_rolname; int i; - printfPQExpBuffer(buf, - "SELECT rolname " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 1", role_catalog); + printfPQExpBuffer(buf, + "SELECT rolname " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 1", role_catalog); res = executeQuery(conn, buf->data); @@ -843,16 +843,16 @@ dumpRoles(PGconn *conn) * Notes: rolconfig is dumped later, and pg_authid must be used for * extracting rolcomment regardless of role_catalog. */ - printfPQExpBuffer(buf, - "SELECT oid, rolname, rolsuper, rolinherit, " - "rolcreaterole, rolcreatedb, " - "rolcanlogin, rolconnlimit, rolpassword, " - "rolvaliduntil, rolreplication, rolbypassrls, " - "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " - "rolname = current_user AS is_current_user " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 2", role_catalog); + printfPQExpBuffer(buf, + "SELECT oid, rolname, rolsuper, rolinherit, " + "rolcreaterole, rolcreatedb, " + "rolcanlogin, rolconnlimit, rolpassword, " + "rolvaliduntil, rolreplication, rolbypassrls, " + "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " + "rolname = current_user AS is_current_user " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 2", role_catalog); res = executeQuery(conn, buf->data); diff --git a/src/bin/pg_upgrade/check.c b/src/bin/pg_upgrade/check.c index 786c1474829..f725f5ee3e2 100644 --- a/src/bin/pg_upgrade/check.c +++ b/src/bin/pg_upgrade/check.c @@ -1475,15 +1475,15 @@ check_for_incompatible_polymorphics(ClusterInfo *cluster) ", 'array_cat(anyarray,anyarray)'" ", 'array_prepend(anyelement,anyarray)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_remove(anyarray,anyelement)'" - ", 'array_replace(anyarray,anyelement,anyelement)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_remove(anyarray,anyelement)'" + ", 'array_replace(anyarray,anyelement,anyelement)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_position(anyarray,anyelement)'" - ", 'array_position(anyarray,anyelement,integer)'" - ", 'array_positions(anyarray,anyelement)'" - ", 'width_bucket(anyelement,anyarray)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_position(anyarray,anyelement)'" + ", 'array_position(anyarray,anyelement,integer)'" + ", 'array_positions(anyarray,anyelement)'" + ", 'width_bucket(anyelement,anyarray)'"); /* * The query below hardcodes FirstNormalObjectId as 16384 rather than diff --git a/src/bin/pg_upgrade/controldata.c b/src/bin/pg_upgrade/controldata.c index 8f81c9e9582..02ea02df60f 100644 --- a/src/bin/pg_upgrade/controldata.c +++ b/src/bin/pg_upgrade/controldata.c @@ -228,7 +228,7 @@ get_control_data(ClusterInfo *cluster) p++; /* remove ':' char */ cluster->controldata.chkpnt_nxtepoch = str2uint(p); - p = strchr(p, ':'); + p = strchr(p, ':'); if (p == NULL || strlen(p) <= 1) pg_fatal("%d: controldata retrieval problem", __LINE__); diff --git a/src/bin/pg_upgrade/exec.c b/src/bin/pg_upgrade/exec.c index 44355feea30..a1bdbf373e3 100644 --- a/src/bin/pg_upgrade/exec.c +++ b/src/bin/pg_upgrade/exec.c @@ -55,7 +55,7 @@ get_bin_version(ClusterInfo *cluster) if (sscanf(cmd_output, "%*s %*s %d.%d", &v1, &v2) < 1) pg_fatal("could not get pg_ctl version output from %s", cmd); - cluster->bin_version = v1 * 10000; + cluster->bin_version = v1 * 10000; } @@ -344,8 +344,8 @@ check_data_dir(ClusterInfo *cluster) check_single_dir(pg_data, "pg_subtrans"); check_single_dir(pg_data, PG_TBLSPC_DIR); check_single_dir(pg_data, "pg_twophase"); - check_single_dir(pg_data, "pg_wal"); - check_single_dir(pg_data, "pg_xact"); + check_single_dir(pg_data, "pg_wal"); + check_single_dir(pg_data, "pg_xact"); } @@ -385,7 +385,7 @@ check_bin_dir(ClusterInfo *cluster, bool check_versions) */ get_bin_version(cluster); - check_exec(cluster->bindir, "pg_resetwal", check_versions); + check_exec(cluster->bindir, "pg_resetwal", check_versions); if (cluster == &new_cluster) { diff --git a/src/bin/pg_upgrade/multixact_rewrite.c b/src/bin/pg_upgrade/multixact_rewrite.c index c45b3183684..c7a1416494d 100644 --- a/src/bin/pg_upgrade/multixact_rewrite.c +++ b/src/bin/pg_upgrade/multixact_rewrite.c @@ -61,52 +61,52 @@ rewrite_multixacts(MultiXactId from_multi, MultiXactId to_multi) * Convert old multixids, if needed, by reading them one-by-one from the * old cluster. */ - old_reader = AllocOldMultiXactRead(old_cluster.pgdata, - old_cluster.controldata.chkpnt_nxtmulti, - old_cluster.controldata.chkpnt_nxtmxoff); + old_reader = AllocOldMultiXactRead(old_cluster.pgdata, + old_cluster.controldata.chkpnt_nxtmulti, + old_cluster.controldata.chkpnt_nxtmxoff); - for (MultiXactId multi = from_multi; multi != to_multi;) - { - MultiXactMember member; - bool multixid_valid; - - /* - * Read this multixid's members. - * - * Locking-only XIDs that may be part of multi-xids don't matter - * after upgrade, as there can be no transactions running across - * upgrade. So as a small optimization, we only read one member - * from each multixid: the one updating one, or if there was no - * update, arbitrarily the first locking xid. - */ - multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); + for (MultiXactId multi = from_multi; multi != to_multi;) + { + MultiXactMember member; + bool multixid_valid; - /* - * Write the new offset to pg_multixact/offsets. - * - * Even if this multixid is invalid, we still need to write its - * offset if the *previous* multixid was valid. That's because - * when reading a multixid, the number of members is calculated - * from the difference between the two offsets. - */ - RecordMultiXactOffset(offsets_writer, multi, - (multixid_valid || prev_multixid_valid) ? next_offset : 0); + /* + * Read this multixid's members. + * + * Locking-only XIDs that may be part of multi-xids don't matter after + * upgrade, as there can be no transactions running across upgrade. So + * as a small optimization, we only read one member from each + * multixid: the one updating one, or if there was no update, + * arbitrarily the first locking xid. + */ + multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); - /* Write the members */ - if (multixid_valid) - { - RecordMultiXactMembers(members_writer, next_offset, 1, &member); - next_offset += 1; - } + /* + * Write the new offset to pg_multixact/offsets. + * + * Even if this multixid is invalid, we still need to write its offset + * if the *previous* multixid was valid. That's because when reading + * a multixid, the number of members is calculated from the difference + * between the two offsets. + */ + RecordMultiXactOffset(offsets_writer, multi, + (multixid_valid || prev_multixid_valid) ? next_offset : 0); - /* Advance to next multixid, handling wraparound */ - multi++; - if (multi < FirstMultiXactId) - multi = FirstMultiXactId; - prev_multixid_valid = multixid_valid; + /* Write the members */ + if (multixid_valid) + { + RecordMultiXactMembers(members_writer, next_offset, 1, &member); + next_offset += 1; } - FreeOldMultiXactReader(old_reader); + /* Advance to next multixid, handling wraparound */ + multi++; + if (multi < FirstMultiXactId) + multi = FirstMultiXactId; + prev_multixid_valid = multixid_valid; + } + + FreeOldMultiXactReader(old_reader); /* Write the final 'next' offset to the last SLRU page */ RecordMultiXactOffset(offsets_writer, to_multi, diff --git a/src/bin/pg_upgrade/pg_upgrade.c b/src/bin/pg_upgrade/pg_upgrade.c index c6af9035665..7366fd4627c 100644 --- a/src/bin/pg_upgrade/pg_upgrade.c +++ b/src/bin/pg_upgrade/pg_upgrade.c @@ -833,7 +833,7 @@ copy_xact_xlog_xid(void) * Determine the range of multixacts to convert. */ nxtmulti = old_cluster.controldata.chkpnt_nxtmulti; - oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; + oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; /* handle wraparound */ if (nxtmulti < FirstMultiXactId) nxtmulti = FirstMultiXactId; @@ -898,15 +898,15 @@ set_frozenxids(void) int i_datname; int i_datallowconn; - prep_status("Setting frozenxid and minmxid counters in new cluster"); + prep_status("Setting frozenxid and minmxid counters in new cluster"); conn_template1 = connectToServer(&new_cluster, "template1"); - /* set pg_database.datfrozenxid */ - PQclear(executeQueryOrDie(conn_template1, - "UPDATE pg_catalog.pg_database " - "SET datfrozenxid = '%u'", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_database.datfrozenxid */ + PQclear(executeQueryOrDie(conn_template1, + "UPDATE pg_catalog.pg_database " + "SET datfrozenxid = '%u'", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_database.datminmxid */ PQclear(executeQueryOrDie(conn_template1, @@ -942,16 +942,16 @@ set_frozenxids(void) conn = connectToServer(&new_cluster, datname); - /* set pg_class.relfrozenxid */ - PQclear(executeQueryOrDie(conn, - "UPDATE pg_catalog.pg_class " - "SET relfrozenxid = '%u' " - /* only heap, materialized view, and TOAST are vacuumed */ - "WHERE relkind IN (" - CppAsString2(RELKIND_RELATION) ", " - CppAsString2(RELKIND_MATVIEW) ", " - CppAsString2(RELKIND_TOASTVALUE) ")", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_class.relfrozenxid */ + PQclear(executeQueryOrDie(conn, + "UPDATE pg_catalog.pg_class " + "SET relfrozenxid = '%u' " + /* only heap, materialized view, and TOAST are vacuumed */ + "WHERE relkind IN (" + CppAsString2(RELKIND_RELATION) ", " + CppAsString2(RELKIND_MATVIEW) ", " + CppAsString2(RELKIND_TOASTVALUE) ")", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_class.relminmxid */ PQclear(executeQueryOrDie(conn, diff --git a/src/bin/pg_upgrade/relfilenumber.c b/src/bin/pg_upgrade/relfilenumber.c index ec2ff7acb21..6c467bdc8a5 100644 --- a/src/bin/pg_upgrade/relfilenumber.c +++ b/src/bin/pg_upgrade/relfilenumber.c @@ -587,32 +587,32 @@ transfer_relfile(FileNameMap *map, const char *type_suffix) /* Copying files might take some time, so give feedback. */ pg_log(PG_STATUS, "%s", old_file); - switch (user_opts.transfer_mode) - { - case TRANSFER_MODE_CLONE: - pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", - old_file, new_file); - cloneFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", - old_file, new_file); - copyFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY_FILE_RANGE: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", - old_file, new_file); - copyFileByRange(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_LINK: - pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", - old_file, new_file); - linkFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_SWAP: - /* swap mode is handled in its own code path */ - pg_fatal("should never happen"); - break; - } + switch (user_opts.transfer_mode) + { + case TRANSFER_MODE_CLONE: + pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", + old_file, new_file); + cloneFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", + old_file, new_file); + copyFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY_FILE_RANGE: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", + old_file, new_file); + copyFileByRange(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_LINK: + pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", + old_file, new_file); + linkFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_SWAP: + /* swap mode is handled in its own code path */ + pg_fatal("should never happen"); + break; + } } } diff --git a/src/bin/pg_upgrade/t/006_transfer_modes.pl b/src/bin/pg_upgrade/t/006_transfer_modes.pl index 9efa5dc863c..360d05c4b68 100644 --- a/src/bin/pg_upgrade/t/006_transfer_modes.pl +++ b/src/bin/pg_upgrade/t/006_transfer_modes.pl @@ -29,10 +29,8 @@ sub test_mode } $new->init(); - $new->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); - $old->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); + $new->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); + $old->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); # We can only test security labels if both the old and new installations # have dummy_seclabel. @@ -76,15 +74,14 @@ sub test_mode "CREATE TABLE test4 AS SELECT generate_series(400, 502)"); } - $old->safe_psql('postgres', - "CREATE TABLESPACE inplc_tblspc LOCATION ''"); - $old->safe_psql('postgres', - "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); - $old->safe_psql('postgres', - "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" - ); - $old->safe_psql('testdb3', - "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); + $old->safe_psql('postgres', "CREATE TABLESPACE inplc_tblspc LOCATION ''"); + $old->safe_psql('postgres', + "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); + $old->safe_psql('postgres', + "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" + ); + $old->safe_psql('testdb3', + "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); # While we are here, test handling of large objects. $old->safe_psql( @@ -152,12 +149,10 @@ sub test_mode } # Tests for in-place tablespaces. - $result = - $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); - is($result, '104', "test5 data after pg_upgrade $mode"); - $result = - $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); - is($result, '105', "test6 data after pg_upgrade $mode"); + $result = $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); + is($result, '104', "test5 data after pg_upgrade $mode"); + $result = $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); + is($result, '105', "test6 data after pg_upgrade $mode"); # Tests for large objects $result = $new->safe_psql('postgres', "SELECT lo_get(4532)"); diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index 44ef11d980e..c90bf8bbde2 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -6278,23 +6278,22 @@ get_create_object_cmd(EditableObjectType obj_type, Oid oid, * ensure the right view gets replaced. Also, check relation kind * to be sure it's a view. * - * Views may have WITH [LOCAL|CASCADED] - * CHECK OPTION. These are not part of the view definition - * returned by pg_get_viewdef() and so need to be retrieved - * separately. Materialized views may have - * arbitrary storage parameter reloptions. + * Views may have WITH [LOCAL|CASCADED] CHECK OPTION. These are + * not part of the view definition returned by pg_get_viewdef() + * and so need to be retrieved separately. Materialized views may + * have arbitrary storage parameter reloptions. */ printfPQExpBuffer(query, "/* %s */\n", _("Get view's definition and details")); - appendPQExpBuffer(query, - "SELECT nspname, relname, relkind, " - "pg_catalog.pg_get_viewdef(c.oid, true), " - "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " - "FROM pg_catalog.pg_class c " - "LEFT JOIN pg_catalog.pg_namespace n " - "ON c.relnamespace = n.oid WHERE c.oid = %u", - oid); + appendPQExpBuffer(query, + "SELECT nspname, relname, relkind, " + "pg_catalog.pg_get_viewdef(c.oid, true), " + "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " + "FROM pg_catalog.pg_class c " + "LEFT JOIN pg_catalog.pg_namespace n " + "ON c.relnamespace = n.oid WHERE c.oid = %u", + oid); break; } diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index ce99137c613..ac0c55e7aa5 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -387,19 +387,19 @@ describeFunctions(const char *functypes, const char *func_pattern, gettext_noop("stable"), gettext_noop("volatile"), gettext_noop("Volatility")); - appendPQExpBuffer(&buf, - ",\n CASE\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" - " END as \"%s\"", - gettext_noop("restricted"), - gettext_noop("safe"), - gettext_noop("unsafe"), - gettext_noop("Parallel")); + appendPQExpBuffer(&buf, + ",\n CASE\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" + " END as \"%s\"", + gettext_noop("restricted"), + gettext_noop("safe"), + gettext_noop("unsafe"), + gettext_noop("Parallel")); appendPQExpBuffer(&buf, ",\n pg_catalog.pg_get_userbyid(p.proowner) as \"%s\"" ",\n CASE WHEN prosecdef THEN '%s' ELSE '%s' END AS \"%s\"" @@ -599,8 +599,8 @@ describeFunctions(const char *functypes, const char *func_pattern, myopt.title = _("List of functions"); myopt.translate_header = true; - myopt.translate_columns = translate_columns; - myopt.n_translate_columns = lengthof(translate_columns); + myopt.translate_columns = translate_columns; + myopt.n_translate_columns = lengthof(translate_columns); printQuery(res, &myopt, pset.queryFout, false, pset.logfile); @@ -1086,38 +1086,38 @@ permissionsList(const char *pattern, bool showSystem) " ), E'\\n') AS \"%s\"", gettext_noop("Column privileges")); - appendPQExpBuffer(&buf, - ",\n pg_catalog.array_to_string(ARRAY(\n" - " SELECT polname\n" - " || CASE WHEN NOT polpermissive THEN\n" - " E' (RESTRICTIVE)'\n" - " ELSE '' END\n" - " || CASE WHEN polcmd != '*' THEN\n" - " E' (' || polcmd::pg_catalog.text || E'):'\n" - " ELSE E':'\n" - " END\n" - " || CASE WHEN polqual IS NOT NULL THEN\n" - " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" - " ELSE E''\n" - " END\n" - " || CASE WHEN polwithcheck IS NOT NULL THEN\n" - " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" - " ELSE E''\n" - " END" - " || CASE WHEN polroles <> '{0}' THEN\n" - " E'\\n to: ' || pg_catalog.array_to_string(\n" - " ARRAY(\n" - " SELECT rolname\n" - " FROM pg_catalog.pg_roles\n" - " WHERE oid = ANY (polroles)\n" - " ORDER BY 1\n" - " ), E', ')\n" - " ELSE E''\n" - " END\n" - " FROM pg_catalog.pg_policy pol\n" - " WHERE polrelid = c.oid), E'\\n')\n" - " AS \"%s\"", - gettext_noop("Policies")); + appendPQExpBuffer(&buf, + ",\n pg_catalog.array_to_string(ARRAY(\n" + " SELECT polname\n" + " || CASE WHEN NOT polpermissive THEN\n" + " E' (RESTRICTIVE)'\n" + " ELSE '' END\n" + " || CASE WHEN polcmd != '*' THEN\n" + " E' (' || polcmd::pg_catalog.text || E'):'\n" + " ELSE E':'\n" + " END\n" + " || CASE WHEN polqual IS NOT NULL THEN\n" + " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" + " ELSE E''\n" + " END\n" + " || CASE WHEN polwithcheck IS NOT NULL THEN\n" + " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" + " ELSE E''\n" + " END" + " || CASE WHEN polroles <> '{0}' THEN\n" + " E'\\n to: ' || pg_catalog.array_to_string(\n" + " ARRAY(\n" + " SELECT rolname\n" + " FROM pg_catalog.pg_roles\n" + " WHERE oid = ANY (polroles)\n" + " ORDER BY 1\n" + " ), E', ')\n" + " ELSE E''\n" + " END\n" + " FROM pg_catalog.pg_policy pol\n" + " WHERE polrelid = c.oid), E'\\n')\n" + " AS \"%s\"", + gettext_noop("Policies")); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_class c\n" " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n" @@ -1675,27 +1675,27 @@ describeOneTableDetails(const char *schemaname, char *footers[3] = {NULL, NULL, NULL}; printfPQExpBuffer(&buf, "/* %s */\n", _("Get sequence information")); - appendPQExpBuffer(&buf, - "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" - " seqstart AS \"%s\",\n" - " seqmin AS \"%s\",\n" - " seqmax AS \"%s\",\n" - " seqincrement AS \"%s\",\n" - " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" - " seqcache AS \"%s\"\n", - gettext_noop("Type"), - gettext_noop("Start"), - gettext_noop("Minimum"), - gettext_noop("Maximum"), - gettext_noop("Increment"), - gettext_noop("yes"), - gettext_noop("no"), - gettext_noop("Cycles?"), - gettext_noop("Cache")); - appendPQExpBuffer(&buf, - "FROM pg_catalog.pg_sequence\n" - "WHERE seqrelid = '%s';", - oid); + appendPQExpBuffer(&buf, + "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" + " seqstart AS \"%s\",\n" + " seqmin AS \"%s\",\n" + " seqmax AS \"%s\",\n" + " seqincrement AS \"%s\",\n" + " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" + " seqcache AS \"%s\"\n", + gettext_noop("Type"), + gettext_noop("Start"), + gettext_noop("Minimum"), + gettext_noop("Maximum"), + gettext_noop("Increment"), + gettext_noop("yes"), + gettext_noop("no"), + gettext_noop("Cycles?"), + gettext_noop("Cache")); + appendPQExpBuffer(&buf, + "FROM pg_catalog.pg_sequence\n" + "WHERE seqrelid = '%s';", + oid); res = PSQLexec(buf.data); if (!res) @@ -1913,7 +1913,7 @@ describeOneTableDetails(const char *schemaname, appendPQExpBufferStr(&buf, ",\n (SELECT c.collname FROM pg_catalog.pg_collation c, pg_catalog.pg_type t\n" " WHERE c.oid = a.attcollation AND t.oid = a.atttypid AND a.attcollation <> t.typcollation) AS attcollation"); attcoll_col = cols++; - appendPQExpBufferStr(&buf, ",\n a.attidentity"); + appendPQExpBufferStr(&buf, ",\n a.attidentity"); attidentity_col = cols++; if (pset.sversion >= 120000) appendPQExpBufferStr(&buf, ",\n a.attgenerated"); @@ -2326,7 +2326,7 @@ describeOneTableDetails(const char *schemaname, CppAsString2(CONSTRAINT_EXCLUSION) ") AND " "condeferred) AS condeferred,\n"); - appendPQExpBufferStr(&buf, "i.indisreplident,\n"); + appendPQExpBufferStr(&buf, "i.indisreplident,\n"); if (pset.sversion >= 150000) appendPQExpBufferStr(&buf, "i.indnullsnotdistinct,\n"); @@ -2431,7 +2431,7 @@ describeOneTableDetails(const char *schemaname, "pg_catalog.pg_get_indexdef(i.indexrelid, 0, true),\n " "pg_catalog.pg_get_constraintdef(con.oid, true), " "contype, condeferrable, condeferred"); - appendPQExpBufferStr(&buf, ", i.indisreplident"); + appendPQExpBufferStr(&buf, ", i.indisreplident"); appendPQExpBufferStr(&buf, ", c2.reltablespace"); if (pset.sversion >= 180000) appendPQExpBufferStr(&buf, ", con.conperiod"); @@ -2682,81 +2682,80 @@ describeOneTableDetails(const char *schemaname, PQclear(result); /* print any row-level policies */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get row-level policies for this table")); - appendPQExpBufferStr(&buf, "SELECT pol.polname,"); - appendPQExpBufferStr(&buf, - " pol.polpermissive,\n"); - appendPQExpBuffer(&buf, - " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" - " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" - " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" - " CASE pol.polcmd\n" - " WHEN 'r' THEN 'SELECT'\n" - " WHEN 'a' THEN 'INSERT'\n" - " WHEN 'w' THEN 'UPDATE'\n" - " WHEN 'd' THEN 'DELETE'\n" - " END AS cmd\n" - "FROM pg_catalog.pg_policy pol\n" - "WHERE pol.polrelid = '%s' ORDER BY 1;", - oid); + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get row-level policies for this table")); + appendPQExpBufferStr(&buf, "SELECT pol.polname,"); + appendPQExpBufferStr(&buf, + " pol.polpermissive,\n"); + appendPQExpBuffer(&buf, + " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" + " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" + " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" + " CASE pol.polcmd\n" + " WHEN 'r' THEN 'SELECT'\n" + " WHEN 'a' THEN 'INSERT'\n" + " WHEN 'w' THEN 'UPDATE'\n" + " WHEN 'd' THEN 'DELETE'\n" + " END AS cmd\n" + "FROM pg_catalog.pg_policy pol\n" + "WHERE pol.polrelid = '%s' ORDER BY 1;", + oid); - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - /* - * Handle cases where RLS is enabled and there are policies, or - * there aren't policies, or RLS isn't enabled but there are - * policies - */ - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies:")); + /* + * Handle cases where RLS is enabled and there are policies, or there + * aren't policies, or RLS isn't enabled but there are policies + */ + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies:")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled):")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled):")); - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); - if (!tableinfo.rowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (row security disabled):")); + if (!tableinfo.rowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (row security disabled):")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " POLICY \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " POLICY \"%s\"", + PQgetvalue(result, i, 0)); - if (*(PQgetvalue(result, i, 1)) == 'f') - appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); + if (*(PQgetvalue(result, i, 1)) == 'f') + appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); - if (!PQgetisnull(result, i, 5)) - appendPQExpBuffer(&buf, " FOR %s", - PQgetvalue(result, i, 5)); + if (!PQgetisnull(result, i, 5)) + appendPQExpBuffer(&buf, " FOR %s", + PQgetvalue(result, i, 5)); - if (!PQgetisnull(result, i, 2)) - { - appendPQExpBuffer(&buf, "\n TO %s", - PQgetvalue(result, i, 2)); - } + if (!PQgetisnull(result, i, 2)) + { + appendPQExpBuffer(&buf, "\n TO %s", + PQgetvalue(result, i, 2)); + } - if (!PQgetisnull(result, i, 3)) - appendPQExpBuffer(&buf, "\n USING (%s)", - PQgetvalue(result, i, 3)); + if (!PQgetisnull(result, i, 3)) + appendPQExpBuffer(&buf, "\n USING (%s)", + PQgetvalue(result, i, 3)); - if (!PQgetisnull(result, i, 4)) - appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", - PQgetvalue(result, i, 4)); + if (!PQgetisnull(result, i, 4)) + appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", + PQgetvalue(result, i, 4)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* print any extended statistics */ if (pset.sversion >= 140000) @@ -3025,115 +3024,115 @@ describeOneTableDetails(const char *schemaname, } /* print any publications */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get publications that publish this table")); - if (pset.sversion >= 150000) + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get publications that publish this table")); + if (pset.sversion >= 150000) + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" + " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" + "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" + "UNION\n" + "SELECT pubname\n" + " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" + " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" + " (SELECT pg_catalog.string_agg(attname, ', ')\n" + " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" + " pg_catalog.pg_attribute\n" + " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" + " ELSE NULL END) " + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" + "WHERE pr.prrelid = '%s'\n", + oid, oid, oid); + + if (pset.sversion >= 190000) { + /* + * Skip entries where this relation appears in the + * publication's EXCEPT list. + */ appendPQExpBuffer(&buf, + " AND NOT pr.prexcept\n" + "UNION\n" "SELECT pubname\n" " , NULL\n" " , NULL\n" "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" - " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" - "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" - "UNION\n" - "SELECT pubname\n" - " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" - " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" - " (SELECT pg_catalog.string_agg(attname, ', ')\n" - " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" - " pg_catalog.pg_attribute\n" - " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" - " ELSE NULL END) " - "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" - "WHERE pr.prrelid = '%s'\n", + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + " AND NOT EXISTS (\n" + " SELECT 1\n" + " FROM pg_catalog.pg_publication_rel pr\n" + " WHERE pr.prpubid = p.oid AND\n" + " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" + "ORDER BY 1;", oid, oid, oid); - - if (pset.sversion >= 190000) - { - /* - * Skip entries where this relation appears in the - * publication's EXCEPT list. - */ - appendPQExpBuffer(&buf, - " AND NOT pr.prexcept\n" - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - " AND NOT EXISTS (\n" - " SELECT 1\n" - " FROM pg_catalog.pg_publication_rel pr\n" - " WHERE pr.prpubid = p.oid AND\n" - " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" - "ORDER BY 1;", - oid, oid, oid); - } - else - { - appendPQExpBuffer(&buf, - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - "ORDER BY 1;", - oid); - } } else { appendPQExpBuffer(&buf, + "UNION\n" "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - "WHERE pr.prrelid = '%s'\n" - "UNION ALL\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" + " , NULL\n" + " , NULL\n" "FROM pg_catalog.pg_publication p\n" "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" "ORDER BY 1;", - oid, oid); + oid); } + } + else + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + "WHERE pr.prrelid = '%s'\n" + "UNION ALL\n" + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + "ORDER BY 1;", + oid, oid); + } - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - if (tuples > 0) - printTableAddFooter(&cont, _("Included in publications:")); + if (tuples > 0) + printTableAddFooter(&cont, _("Included in publications:")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " \"%s\"", + PQgetvalue(result, i, 0)); - /* column list (if any) */ - if (!PQgetisnull(result, i, 2)) - appendPQExpBuffer(&buf, " (%s)", - PQgetvalue(result, i, 2)); + /* column list (if any) */ + if (!PQgetisnull(result, i, 2)) + appendPQExpBuffer(&buf, " (%s)", + PQgetvalue(result, i, 2)); - /* row filter (if any) */ - if (!PQgetisnull(result, i, 1)) - appendPQExpBuffer(&buf, " WHERE %s", - PQgetvalue(result, i, 1)); + /* row filter (if any) */ + if (!PQgetisnull(result, i, 1)) + appendPQExpBuffer(&buf, " WHERE %s", + PQgetvalue(result, i, 1)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* Print publications where the table is in the EXCEPT clause */ if (pset.sversion >= 190000) @@ -3805,7 +3804,7 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) ncols++; } appendPQExpBufferStr(&buf, "\n, r.rolreplication"); - appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); + appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_roles r\n"); @@ -3860,8 +3859,8 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) if (strcmp(PQgetvalue(res, i, (verbose ? 9 : 8)), "t") == 0) add_role_attribute(&buf, _("Replication")); - if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) - add_role_attribute(&buf, _("Bypass RLS")); + if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) + add_role_attribute(&buf, _("Bypass RLS")); conns = atoi(PQgetvalue(res, i, 6)); if (conns >= 0) @@ -5155,14 +5154,14 @@ listCollations(const char *pattern, bool verbose, bool showSystem) gettext_noop("Schema"), gettext_noop("Name")); - appendPQExpBuffer(&buf, - " CASE c.collprovider " - "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " - "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " - "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " - "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " - "END AS \"%s\",\n", - gettext_noop("Provider")); + appendPQExpBuffer(&buf, + " CASE c.collprovider " + "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " + "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " + "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " + "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " + "END AS \"%s\",\n", + gettext_noop("Provider")); appendPQExpBuffer(&buf, " c.collcollate AS \"%s\",\n" -- 2.50.1 (Apple Git-155) --aHl3HfeiUuO3zeNC-- ^ permalink raw reply [nested|flat] 59+ messages in thread
* [PATCH v6 4/4] run pgindent and pgperltidy @ 2026-06-30 18:24 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 59+ messages in thread From: Nathan Bossart @ 2026-06-30 18:24 UTC (permalink / raw) --- src/bin/pg_dump/pg_dump.c | 464 ++++++++++----------- src/bin/pg_dump/pg_dumpall.c | 30 +- src/bin/pg_upgrade/check.c | 16 +- src/bin/pg_upgrade/controldata.c | 2 +- src/bin/pg_upgrade/exec.c | 8 +- src/bin/pg_upgrade/multixact_rewrite.c | 80 ++-- src/bin/pg_upgrade/pg_upgrade.c | 34 +- src/bin/pg_upgrade/relfilenumber.c | 54 +-- src/bin/pg_upgrade/t/006_transfer_modes.pl | 33 +- src/bin/psql/command.c | 29 +- src/bin/psql/describe.c | 461 ++++++++++---------- 11 files changed, 601 insertions(+), 610 deletions(-) diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 65bd15ebfd2..5673268b467 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -1491,8 +1491,8 @@ setup_connection(Archive *AH, const char *dumpencoding, * Disable timeouts if supported. */ ExecuteSqlStatement(AH, "SET statement_timeout = 0"); - ExecuteSqlStatement(AH, "SET lock_timeout = 0"); - ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); + ExecuteSqlStatement(AH, "SET lock_timeout = 0"); + ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); if (AH->remoteVersion >= 170000) ExecuteSqlStatement(AH, "SET transaction_timeout = 0"); @@ -1505,10 +1505,10 @@ setup_connection(Archive *AH, const char *dumpencoding, /* * Adjust row-security mode, if supported. */ - if (dopt->enable_row_security) - ExecuteSqlStatement(AH, "SET row_security = on"); - else - ExecuteSqlStatement(AH, "SET row_security = off"); + if (dopt->enable_row_security) + ExecuteSqlStatement(AH, "SET row_security = on"); + else + ExecuteSqlStatement(AH, "SET row_security = off"); /* * For security reasons, we restrict the expansion of non-system views and @@ -1933,10 +1933,9 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) addObjectDependency(dobj, ext->dobj.dumpId); /* - * Mark the member object to have any non-initial ACLs - * dumped. (Any initial ACLs will be removed later, using data from - * pg_init_privs, so that we'll dump only the delta from the extension's - * initial setup.) + * Mark the member object to have any non-initial ACLs dumped. (Any + * initial ACLs will be removed later, using data from pg_init_privs, so + * that we'll dump only the delta from the extension's initial setup.) * * In binary upgrades, we still dump all components of the members * individually, since the idea is to exactly reproduce the database @@ -1953,7 +1952,7 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) if (fout->dopt->binary_upgrade) dobj->dump = ext->dobj.dump; else - dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); + dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); return true; } @@ -1987,9 +1986,9 @@ selectDumpableNamespace(NamespaceInfo *nsinfo, Archive *fout) else if (strcmp(nsinfo->dobj.name, "pg_catalog") == 0) { /* - * We dump out any ACLs defined in pg_catalog, if - * they are interesting (and not the original ACLs which were set at - * initdb time, see pg_init_privs). + * We dump out any ACLs defined in pg_catalog, if they are interesting + * (and not the original ACLs which were set at initdb time, see + * pg_init_privs). */ nsinfo->dobj.dump_contains = nsinfo->dobj.dump = DUMP_COMPONENT_ACL; } @@ -3296,7 +3295,7 @@ dumpDatabase(Archive *fout) "datcollate, datctype, datfrozenxid, " "datacl, acldefault('d', datdba) AS acldefault, " "datistemplate, datconnlimit, "); - appendPQExpBufferStr(dbQry, "datminmxid, "); + appendPQExpBufferStr(dbQry, "datminmxid, "); if (fout->remoteVersion >= 170000) appendPQExpBufferStr(dbQry, "datlocprovider, datlocale, datcollversion, "); else if (fout->remoteVersion >= 150000) @@ -3638,11 +3637,11 @@ dumpDatabase(Archive *fout) ii_oid, ii_relminmxid; - appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" - "FROM pg_catalog.pg_class\n" - "WHERE oid IN (%u, %u, %u, %u);\n", - LargeObjectRelationId, LargeObjectLOidPNIndexId, - LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); + appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" + "FROM pg_catalog.pg_class\n" + "WHERE oid IN (%u, %u, %u, %u);\n", + LargeObjectRelationId, LargeObjectLOidPNIndexId, + LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); lo_res = ExecuteSqlQuery(fout, loFrozenQry->data, PGRES_TUPLES_OK); @@ -4274,7 +4273,7 @@ getPolicies(Archive *fout, TableInfo tblinfo[], int numTables) printfPQExpBuffer(query, "SELECT pol.oid, pol.tableoid, pol.polrelid, pol.polname, pol.polcmd, "); - appendPQExpBufferStr(query, "pol.polpermissive, "); + appendPQExpBufferStr(query, "pol.polpermissive, "); appendPQExpBuffer(query, "CASE WHEN pol.polroles = '{0}' THEN NULL ELSE " " pg_catalog.array_to_string(ARRAY(SELECT pg_catalog.quote_ident(rolname) from pg_catalog.pg_roles WHERE oid = ANY(pol.polroles)), ', ') END AS polroles, " @@ -6633,9 +6632,9 @@ getAccessMethods(Archive *fout) * Select all access methods from pg_am table. */ appendPQExpBufferStr(query, "SELECT tableoid, oid, amname, "); - appendPQExpBufferStr(query, - "amtype, " - "amhandler::pg_catalog.regproc AS amhandler "); + appendPQExpBufferStr(query, + "amtype, " + "amhandler::pg_catalog.regproc AS amhandler "); appendPQExpBufferStr(query, "FROM pg_am"); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6827,35 +6826,35 @@ getAggregates(Archive *fout) * Find all interesting aggregates. See comment in getFuncs() for the * rationale behind the filtering logic. */ - agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" - : "p.proisagg"); + agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" + : "p.proisagg"); - appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " - "p.proname AS aggname, " - "p.pronamespace AS aggnamespace, " - "p.pronargs, p.proargtypes, " - "p.proowner, " - "p.proacl AS aggacl, " - "acldefault('f', p.proowner) AS acldefault " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s AND (" - "p.pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog') OR " - "p.proacl IS DISTINCT FROM pip.initprivs", - agg_check); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - " OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); - appendPQExpBufferChar(query, ')'); + appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " + "p.proname AS aggname, " + "p.pronamespace AS aggnamespace, " + "p.pronargs, p.proargtypes, " + "p.proowner, " + "p.proacl AS aggacl, " + "acldefault('f', p.proowner) AS acldefault " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s AND (" + "p.pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog') OR " + "p.proacl IS DISTINCT FROM pip.initprivs", + agg_check); + if (dopt->binary_upgrade) + appendPQExpBufferStr(query, + " OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6957,53 +6956,53 @@ getFuncs(Archive *fout) * include them, since we want to dump extension members individually in * that mode. Also, if they are used by casts or transforms then we need * to gather the information about them, though they won't be dumped if - * they are built-in. Also, include functions in - * pg_catalog if they have an ACL different from what's shown in - * pg_init_privs (so we have to join to pg_init_privs; annoying). + * they are built-in. Also, include functions in pg_catalog if they have + * an ACL different from what's shown in pg_init_privs (so we have to join + * to pg_init_privs; annoying). */ - not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" - : "NOT p.proisagg"); + not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" + : "NOT p.proisagg"); - appendPQExpBuffer(query, - "SELECT p.tableoid, p.oid, p.proname, p.prolang, " - "p.pronargs, p.proargtypes, p.prorettype, " - "p.proacl, " - "acldefault('f', p.proowner) AS acldefault, " - "p.pronamespace, " - "p.proowner " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s" - "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " - "WHERE classid = 'pg_proc'::regclass AND " - "objid = p.oid AND deptype = 'i')" - "\n AND (" - "\n pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog')" - "\n OR EXISTS (SELECT 1 FROM pg_cast" - "\n WHERE pg_cast.oid > %u " - "\n AND p.oid = pg_cast.castfunc)" - "\n OR EXISTS (SELECT 1 FROM pg_transform" - "\n WHERE pg_transform.oid > %u AND " - "\n (p.oid = pg_transform.trffromsql" - "\n OR p.oid = pg_transform.trftosql))", - not_agg_check, - g_last_builtin_oid, - g_last_builtin_oid); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); + appendPQExpBuffer(query, + "SELECT p.tableoid, p.oid, p.proname, p.prolang, " + "p.pronargs, p.proargtypes, p.prorettype, " + "p.proacl, " + "acldefault('f', p.proowner) AS acldefault, " + "p.pronamespace, " + "p.proowner " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s" + "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " + "WHERE classid = 'pg_proc'::regclass AND " + "objid = p.oid AND deptype = 'i')" + "\n AND (" + "\n pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog')" + "\n OR EXISTS (SELECT 1 FROM pg_cast" + "\n WHERE pg_cast.oid > %u " + "\n AND p.oid = pg_cast.castfunc)" + "\n OR EXISTS (SELECT 1 FROM pg_transform" + "\n WHERE pg_transform.oid > %u AND " + "\n (p.oid = pg_transform.trffromsql" + "\n OR p.oid = pg_transform.trftosql))", + not_agg_check, + g_last_builtin_oid, + g_last_builtin_oid); + if (dopt->binary_upgrade) appendPQExpBufferStr(query, - "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); - appendPQExpBufferChar(query, ')'); + "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferStr(query, + "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -7252,31 +7251,31 @@ getTables(Archive *fout, int *numTables) appendPQExpBufferStr(query, "c.relhasoids, "); - appendPQExpBufferStr(query, - "c.relispopulated, "); + appendPQExpBufferStr(query, + "c.relispopulated, "); - appendPQExpBufferStr(query, - "c.relreplident, "); + appendPQExpBufferStr(query, + "c.relreplident, "); - appendPQExpBufferStr(query, - "c.relrowsecurity, c.relforcerowsecurity, "); + appendPQExpBufferStr(query, + "c.relrowsecurity, c.relforcerowsecurity, "); - appendPQExpBufferStr(query, - "c.relminmxid, tc.relminmxid AS tminmxid, "); + appendPQExpBufferStr(query, + "c.relminmxid, tc.relminmxid AS tminmxid, "); - appendPQExpBufferStr(query, - "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); + appendPQExpBufferStr(query, + "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); - appendPQExpBufferStr(query, - "am.amname, "); + appendPQExpBufferStr(query, + "am.amname, "); - appendPQExpBufferStr(query, - "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); + appendPQExpBufferStr(query, + "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); - appendPQExpBufferStr(query, - "c.relispartition AS ispartition "); + appendPQExpBufferStr(query, + "c.relispartition AS ispartition "); /* * Left join to pg_depend to pick up dependency info linking sequences to @@ -7296,8 +7295,8 @@ getTables(Archive *fout, int *numTables) /* * Left join to pg_am to pick up the amname. */ - appendPQExpBufferStr(query, - "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); + appendPQExpBufferStr(query, + "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); /* * We purposefully ignore toast OIDs for partitioned tables; the reason is @@ -7868,8 +7867,8 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables) "t.reloptions AS indreloptions, "); - appendPQExpBufferStr(query, - "i.indisreplident, "); + appendPQExpBufferStr(query, + "i.indisreplident, "); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -9313,8 +9312,8 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables) appendPQExpBufferStr(q, "'' AS attcompression,\n"); - appendPQExpBufferStr(q, - "a.attidentity,\n"); + appendPQExpBufferStr(q, + "a.attidentity,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(q, @@ -10717,73 +10716,73 @@ getAdditionalACLs(Archive *fout) PQclear(res); /* Fetch initial-privileges data */ - printfPQExpBuffer(query, - "SELECT objoid, classoid, objsubid, privtype, initprivs " - "FROM pg_init_privs"); + printfPQExpBuffer(query, + "SELECT objoid, classoid, objsubid, privtype, initprivs " + "FROM pg_init_privs"); - res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); + res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); - ntups = PQntuples(res); - for (i = 0; i < ntups; i++) - { - Oid objoid = atooid(PQgetvalue(res, i, 0)); - Oid classoid = atooid(PQgetvalue(res, i, 1)); - int objsubid = atoi(PQgetvalue(res, i, 2)); - char privtype = *(PQgetvalue(res, i, 3)); - char *initprivs = PQgetvalue(res, i, 4); - CatalogId objId; - DumpableObject *dobj; + ntups = PQntuples(res); + for (i = 0; i < ntups; i++) + { + Oid objoid = atooid(PQgetvalue(res, i, 0)); + Oid classoid = atooid(PQgetvalue(res, i, 1)); + int objsubid = atoi(PQgetvalue(res, i, 2)); + char privtype = *(PQgetvalue(res, i, 3)); + char *initprivs = PQgetvalue(res, i, 4); + CatalogId objId; + DumpableObject *dobj; - objId.tableoid = classoid; - objId.oid = objoid; - dobj = findObjectByCatalogId(objId); - /* OK to ignore entries we haven't got a DumpableObject for */ - if (dobj) + objId.tableoid = classoid; + objId.oid = objoid; + dobj = findObjectByCatalogId(objId); + /* OK to ignore entries we haven't got a DumpableObject for */ + if (dobj) + { + /* Cope with sub-object initprivs */ + if (objsubid != 0) { - /* Cope with sub-object initprivs */ - if (objsubid != 0) - { - if (dobj->objType == DO_TABLE) - { - /* For a column initprivs, set the table's ACL flags */ - dobj->components |= DUMP_COMPONENT_ACL; - ((TableInfo *) dobj)->hascolumnACLs = true; - } - else - pg_log_warning("unsupported pg_init_privs entry: %u %u %d", - classoid, objoid, objsubid); - continue; - } - - /* - * We ignore any pg_init_privs.initprivs entry for the public - * schema, as explained in getNamespaces(). - */ - if (dobj->objType == DO_NAMESPACE && - strcmp(dobj->name, "public") == 0) - continue; - - /* Else it had better be of a type we think has ACLs */ - if (dobj->objType == DO_NAMESPACE || - dobj->objType == DO_TYPE || - dobj->objType == DO_FUNC || - dobj->objType == DO_AGG || - dobj->objType == DO_TABLE || - dobj->objType == DO_PROCLANG || - dobj->objType == DO_FDW || - dobj->objType == DO_FOREIGN_SERVER) + if (dobj->objType == DO_TABLE) { - DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; - - daobj->dacl.privtype = privtype; - daobj->dacl.initprivs = pstrdup(initprivs); + /* For a column initprivs, set the table's ACL flags */ + dobj->components |= DUMP_COMPONENT_ACL; + ((TableInfo *) dobj)->hascolumnACLs = true; } else pg_log_warning("unsupported pg_init_privs entry: %u %u %d", classoid, objoid, objsubid); + continue; + } + + /* + * We ignore any pg_init_privs.initprivs entry for the public + * schema, as explained in getNamespaces(). + */ + if (dobj->objType == DO_NAMESPACE && + strcmp(dobj->name, "public") == 0) + continue; + + /* Else it had better be of a type we think has ACLs */ + if (dobj->objType == DO_NAMESPACE || + dobj->objType == DO_TYPE || + dobj->objType == DO_FUNC || + dobj->objType == DO_AGG || + dobj->objType == DO_TABLE || + dobj->objType == DO_PROCLANG || + dobj->objType == DO_FDW || + dobj->objType == DO_FOREIGN_SERVER) + { + DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; + + daobj->dacl.privtype = privtype; + daobj->dacl.initprivs = pstrdup(initprivs); } + else + pg_log_warning("unsupported pg_init_privs entry: %u %u %d", + classoid, objoid, objsubid); } - PQclear(res); + } + PQclear(res); destroyPQExpBuffer(query); } @@ -11128,8 +11127,8 @@ dumpRelationStats_dumper(Archive *fout, const void *userArg, const TocEntry *te) * The results must be in the order of the relations supplied in the * parameters to ensure we remain in sync as we walk through the TOC. * - * For versions before 19, the redundant filter clause on s.tablename = - * ANY(...) seems sufficient to convince the planner to use + * For versions before 19, the redundant filter clause on s.tablename + * = ANY(...) seems sufficient to convince the planner to use * pg_class_relname_nsp_index, which avoids a full scan of pg_stats. * In newer versions, pg_stats returns the table OIDs, eliminating the * need for that hack. @@ -13469,11 +13468,11 @@ dumpFunc(Archive *fout, const FuncInfo *finfo) "pg_catalog.pg_get_function_result(p.oid) AS funcresult,\n" "proleakproof,\n"); - appendPQExpBufferStr(query, - "array_to_string(protrftypes, ' ') AS protrftypes,\n"); + appendPQExpBufferStr(query, + "array_to_string(protrftypes, ' ') AS protrftypes,\n"); - appendPQExpBufferStr(query, - "proparallel,\n"); + appendPQExpBufferStr(query, + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -14963,9 +14962,9 @@ dumpCollation(Archive *fout, const CollInfo *collinfo) /* Get collation-specific details */ appendPQExpBufferStr(query, "SELECT "); - appendPQExpBufferStr(query, - "collprovider, " - "collversion, "); + appendPQExpBufferStr(query, + "collprovider, " + "collversion, "); if (fout->remoteVersion >= 120000) appendPQExpBufferStr(query, @@ -15372,23 +15371,23 @@ dumpAgg(Archive *fout, const AggInfo *agginfo) "pg_catalog.pg_get_function_arguments(p.oid) AS funcargs,\n" "pg_catalog.pg_get_function_identity_arguments(p.oid) AS funciargs,\n"); - appendPQExpBufferStr(query, - "aggkind,\n" - "aggmtransfn,\n" - "aggminvtransfn,\n" - "aggmfinalfn,\n" - "aggmtranstype::pg_catalog.regtype,\n" - "aggfinalextra,\n" - "aggmfinalextra,\n" - "aggtransspace,\n" - "aggmtransspace,\n" - "aggminitval,\n"); + appendPQExpBufferStr(query, + "aggkind,\n" + "aggmtransfn,\n" + "aggminvtransfn,\n" + "aggmfinalfn,\n" + "aggmtranstype::pg_catalog.regtype,\n" + "aggfinalextra,\n" + "aggmfinalextra,\n" + "aggtransspace,\n" + "aggmtransspace,\n" + "aggminitval,\n"); - appendPQExpBufferStr(query, - "aggcombinefn,\n" - "aggserialfn,\n" - "aggdeserialfn,\n" - "proparallel,\n"); + appendPQExpBufferStr(query, + "aggcombinefn,\n" + "aggserialfn,\n" + "aggdeserialfn,\n" + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -16848,30 +16847,30 @@ dumpTable(Archive *fout, const TableInfo *tbinfo) appendPQExpBufferStr(query, "PREPARE getColumnACLs(pg_catalog.oid) AS\n"); - /* - * In principle we should call acldefault('c', relowner) to - * get the default ACL for a column. However, we don't - * currently store the numeric OID of the relowner in - * TableInfo. We could convert the owner name using regrole, - * but that creates a risk of failure due to concurrent role - * renames. Given that the default ACL for columns is empty - * and is likely to stay that way, it's not worth extra cycles - * and risk to avoid hard-wiring that knowledge here. - */ - appendPQExpBufferStr(query, - "SELECT at.attname, " - "at.attacl, " - "'{}' AS acldefault, " - "pip.privtype, pip.initprivs " - "FROM pg_catalog.pg_attribute at " - "LEFT JOIN pg_catalog.pg_init_privs pip ON " - "(at.attrelid = pip.objoid " - "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " - "AND at.attnum = pip.objsubid) " - "WHERE at.attrelid = $1 AND " - "NOT at.attisdropped " - "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " - "ORDER BY at.attnum"); + /* + * In principle we should call acldefault('c', relowner) to get + * the default ACL for a column. However, we don't currently + * store the numeric OID of the relowner in TableInfo. We could + * convert the owner name using regrole, but that creates a risk + * of failure due to concurrent role renames. Given that the + * default ACL for columns is empty and is likely to stay that + * way, it's not worth extra cycles and risk to avoid hard-wiring + * that knowledge here. + */ + appendPQExpBufferStr(query, + "SELECT at.attname, " + "at.attacl, " + "'{}' AS acldefault, " + "pip.privtype, pip.initprivs " + "FROM pg_catalog.pg_attribute at " + "LEFT JOIN pg_catalog.pg_init_privs pip ON " + "(at.attrelid = pip.objoid " + "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " + "AND at.attnum = pip.objsubid) " + "WHERE at.attrelid = $1 AND " + "NOT at.attisdropped " + "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " + "ORDER BY at.attnum"); ExecuteSqlStatement(fout, query->data); @@ -19165,7 +19164,7 @@ collectSequences(Archive *fout) * pg_get_sequence_data(), but we only do so for non-schema-only dumps. */ if (fout->remoteVersion < 180000 || - (!fout->dopt->dumpData && !fout->dopt->sequence_data)) + (!fout->dopt->dumpData && !fout->dopt->sequence_data)) query = "SELECT seqrelid, format_type(seqtypid, NULL), " "seqstart, seqincrement, " "seqmax, seqmin, " @@ -19227,15 +19226,14 @@ dumpSequence(Archive *fout, const TableInfo *tbinfo) qseqname = pg_strdup(fmtId(tbinfo->dobj.name)); /* - * The sequence information is gathered in a sorted - * table before any calls to dumpSequence(). See collectSequences() for - * more information. + * The sequence information is gathered in a sorted table before any calls + * to dumpSequence(). See collectSequences() for more information. */ - Assert(sequences); + Assert(sequences); - key.oid = tbinfo->dobj.catId.oid; - seq = bsearch(&key, sequences, nsequences, - sizeof(SequenceItem), SequenceItemCmp); + key.oid = tbinfo->dobj.catId.oid; + seq = bsearch(&key, sequences, nsequences, + sizeof(SequenceItem), SequenceItemCmp); /* Calculate default limits for a sequence of this type */ is_ascending = (seq->incby >= 0); diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c index e68937c9934..afcd9a218d8 100644 --- a/src/bin/pg_dump/pg_dumpall.c +++ b/src/bin/pg_dump/pg_dumpall.c @@ -785,11 +785,11 @@ dropRoles(PGconn *conn) int i_rolname; int i; - printfPQExpBuffer(buf, - "SELECT rolname " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 1", role_catalog); + printfPQExpBuffer(buf, + "SELECT rolname " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 1", role_catalog); res = executeQuery(conn, buf->data); @@ -843,16 +843,16 @@ dumpRoles(PGconn *conn) * Notes: rolconfig is dumped later, and pg_authid must be used for * extracting rolcomment regardless of role_catalog. */ - printfPQExpBuffer(buf, - "SELECT oid, rolname, rolsuper, rolinherit, " - "rolcreaterole, rolcreatedb, " - "rolcanlogin, rolconnlimit, rolpassword, " - "rolvaliduntil, rolreplication, rolbypassrls, " - "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " - "rolname = current_user AS is_current_user " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 2", role_catalog); + printfPQExpBuffer(buf, + "SELECT oid, rolname, rolsuper, rolinherit, " + "rolcreaterole, rolcreatedb, " + "rolcanlogin, rolconnlimit, rolpassword, " + "rolvaliduntil, rolreplication, rolbypassrls, " + "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " + "rolname = current_user AS is_current_user " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 2", role_catalog); res = executeQuery(conn, buf->data); diff --git a/src/bin/pg_upgrade/check.c b/src/bin/pg_upgrade/check.c index 786c1474829..f725f5ee3e2 100644 --- a/src/bin/pg_upgrade/check.c +++ b/src/bin/pg_upgrade/check.c @@ -1475,15 +1475,15 @@ check_for_incompatible_polymorphics(ClusterInfo *cluster) ", 'array_cat(anyarray,anyarray)'" ", 'array_prepend(anyelement,anyarray)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_remove(anyarray,anyelement)'" - ", 'array_replace(anyarray,anyelement,anyelement)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_remove(anyarray,anyelement)'" + ", 'array_replace(anyarray,anyelement,anyelement)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_position(anyarray,anyelement)'" - ", 'array_position(anyarray,anyelement,integer)'" - ", 'array_positions(anyarray,anyelement)'" - ", 'width_bucket(anyelement,anyarray)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_position(anyarray,anyelement)'" + ", 'array_position(anyarray,anyelement,integer)'" + ", 'array_positions(anyarray,anyelement)'" + ", 'width_bucket(anyelement,anyarray)'"); /* * The query below hardcodes FirstNormalObjectId as 16384 rather than diff --git a/src/bin/pg_upgrade/controldata.c b/src/bin/pg_upgrade/controldata.c index 8f81c9e9582..02ea02df60f 100644 --- a/src/bin/pg_upgrade/controldata.c +++ b/src/bin/pg_upgrade/controldata.c @@ -228,7 +228,7 @@ get_control_data(ClusterInfo *cluster) p++; /* remove ':' char */ cluster->controldata.chkpnt_nxtepoch = str2uint(p); - p = strchr(p, ':'); + p = strchr(p, ':'); if (p == NULL || strlen(p) <= 1) pg_fatal("%d: controldata retrieval problem", __LINE__); diff --git a/src/bin/pg_upgrade/exec.c b/src/bin/pg_upgrade/exec.c index 44355feea30..a1bdbf373e3 100644 --- a/src/bin/pg_upgrade/exec.c +++ b/src/bin/pg_upgrade/exec.c @@ -55,7 +55,7 @@ get_bin_version(ClusterInfo *cluster) if (sscanf(cmd_output, "%*s %*s %d.%d", &v1, &v2) < 1) pg_fatal("could not get pg_ctl version output from %s", cmd); - cluster->bin_version = v1 * 10000; + cluster->bin_version = v1 * 10000; } @@ -344,8 +344,8 @@ check_data_dir(ClusterInfo *cluster) check_single_dir(pg_data, "pg_subtrans"); check_single_dir(pg_data, PG_TBLSPC_DIR); check_single_dir(pg_data, "pg_twophase"); - check_single_dir(pg_data, "pg_wal"); - check_single_dir(pg_data, "pg_xact"); + check_single_dir(pg_data, "pg_wal"); + check_single_dir(pg_data, "pg_xact"); } @@ -385,7 +385,7 @@ check_bin_dir(ClusterInfo *cluster, bool check_versions) */ get_bin_version(cluster); - check_exec(cluster->bindir, "pg_resetwal", check_versions); + check_exec(cluster->bindir, "pg_resetwal", check_versions); if (cluster == &new_cluster) { diff --git a/src/bin/pg_upgrade/multixact_rewrite.c b/src/bin/pg_upgrade/multixact_rewrite.c index c45b3183684..c7a1416494d 100644 --- a/src/bin/pg_upgrade/multixact_rewrite.c +++ b/src/bin/pg_upgrade/multixact_rewrite.c @@ -61,52 +61,52 @@ rewrite_multixacts(MultiXactId from_multi, MultiXactId to_multi) * Convert old multixids, if needed, by reading them one-by-one from the * old cluster. */ - old_reader = AllocOldMultiXactRead(old_cluster.pgdata, - old_cluster.controldata.chkpnt_nxtmulti, - old_cluster.controldata.chkpnt_nxtmxoff); + old_reader = AllocOldMultiXactRead(old_cluster.pgdata, + old_cluster.controldata.chkpnt_nxtmulti, + old_cluster.controldata.chkpnt_nxtmxoff); - for (MultiXactId multi = from_multi; multi != to_multi;) - { - MultiXactMember member; - bool multixid_valid; - - /* - * Read this multixid's members. - * - * Locking-only XIDs that may be part of multi-xids don't matter - * after upgrade, as there can be no transactions running across - * upgrade. So as a small optimization, we only read one member - * from each multixid: the one updating one, or if there was no - * update, arbitrarily the first locking xid. - */ - multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); + for (MultiXactId multi = from_multi; multi != to_multi;) + { + MultiXactMember member; + bool multixid_valid; - /* - * Write the new offset to pg_multixact/offsets. - * - * Even if this multixid is invalid, we still need to write its - * offset if the *previous* multixid was valid. That's because - * when reading a multixid, the number of members is calculated - * from the difference between the two offsets. - */ - RecordMultiXactOffset(offsets_writer, multi, - (multixid_valid || prev_multixid_valid) ? next_offset : 0); + /* + * Read this multixid's members. + * + * Locking-only XIDs that may be part of multi-xids don't matter after + * upgrade, as there can be no transactions running across upgrade. So + * as a small optimization, we only read one member from each + * multixid: the one updating one, or if there was no update, + * arbitrarily the first locking xid. + */ + multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); - /* Write the members */ - if (multixid_valid) - { - RecordMultiXactMembers(members_writer, next_offset, 1, &member); - next_offset += 1; - } + /* + * Write the new offset to pg_multixact/offsets. + * + * Even if this multixid is invalid, we still need to write its offset + * if the *previous* multixid was valid. That's because when reading + * a multixid, the number of members is calculated from the difference + * between the two offsets. + */ + RecordMultiXactOffset(offsets_writer, multi, + (multixid_valid || prev_multixid_valid) ? next_offset : 0); - /* Advance to next multixid, handling wraparound */ - multi++; - if (multi < FirstMultiXactId) - multi = FirstMultiXactId; - prev_multixid_valid = multixid_valid; + /* Write the members */ + if (multixid_valid) + { + RecordMultiXactMembers(members_writer, next_offset, 1, &member); + next_offset += 1; } - FreeOldMultiXactReader(old_reader); + /* Advance to next multixid, handling wraparound */ + multi++; + if (multi < FirstMultiXactId) + multi = FirstMultiXactId; + prev_multixid_valid = multixid_valid; + } + + FreeOldMultiXactReader(old_reader); /* Write the final 'next' offset to the last SLRU page */ RecordMultiXactOffset(offsets_writer, to_multi, diff --git a/src/bin/pg_upgrade/pg_upgrade.c b/src/bin/pg_upgrade/pg_upgrade.c index c6af9035665..7366fd4627c 100644 --- a/src/bin/pg_upgrade/pg_upgrade.c +++ b/src/bin/pg_upgrade/pg_upgrade.c @@ -833,7 +833,7 @@ copy_xact_xlog_xid(void) * Determine the range of multixacts to convert. */ nxtmulti = old_cluster.controldata.chkpnt_nxtmulti; - oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; + oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; /* handle wraparound */ if (nxtmulti < FirstMultiXactId) nxtmulti = FirstMultiXactId; @@ -898,15 +898,15 @@ set_frozenxids(void) int i_datname; int i_datallowconn; - prep_status("Setting frozenxid and minmxid counters in new cluster"); + prep_status("Setting frozenxid and minmxid counters in new cluster"); conn_template1 = connectToServer(&new_cluster, "template1"); - /* set pg_database.datfrozenxid */ - PQclear(executeQueryOrDie(conn_template1, - "UPDATE pg_catalog.pg_database " - "SET datfrozenxid = '%u'", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_database.datfrozenxid */ + PQclear(executeQueryOrDie(conn_template1, + "UPDATE pg_catalog.pg_database " + "SET datfrozenxid = '%u'", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_database.datminmxid */ PQclear(executeQueryOrDie(conn_template1, @@ -942,16 +942,16 @@ set_frozenxids(void) conn = connectToServer(&new_cluster, datname); - /* set pg_class.relfrozenxid */ - PQclear(executeQueryOrDie(conn, - "UPDATE pg_catalog.pg_class " - "SET relfrozenxid = '%u' " - /* only heap, materialized view, and TOAST are vacuumed */ - "WHERE relkind IN (" - CppAsString2(RELKIND_RELATION) ", " - CppAsString2(RELKIND_MATVIEW) ", " - CppAsString2(RELKIND_TOASTVALUE) ")", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_class.relfrozenxid */ + PQclear(executeQueryOrDie(conn, + "UPDATE pg_catalog.pg_class " + "SET relfrozenxid = '%u' " + /* only heap, materialized view, and TOAST are vacuumed */ + "WHERE relkind IN (" + CppAsString2(RELKIND_RELATION) ", " + CppAsString2(RELKIND_MATVIEW) ", " + CppAsString2(RELKIND_TOASTVALUE) ")", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_class.relminmxid */ PQclear(executeQueryOrDie(conn, diff --git a/src/bin/pg_upgrade/relfilenumber.c b/src/bin/pg_upgrade/relfilenumber.c index ec2ff7acb21..6c467bdc8a5 100644 --- a/src/bin/pg_upgrade/relfilenumber.c +++ b/src/bin/pg_upgrade/relfilenumber.c @@ -587,32 +587,32 @@ transfer_relfile(FileNameMap *map, const char *type_suffix) /* Copying files might take some time, so give feedback. */ pg_log(PG_STATUS, "%s", old_file); - switch (user_opts.transfer_mode) - { - case TRANSFER_MODE_CLONE: - pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", - old_file, new_file); - cloneFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", - old_file, new_file); - copyFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY_FILE_RANGE: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", - old_file, new_file); - copyFileByRange(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_LINK: - pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", - old_file, new_file); - linkFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_SWAP: - /* swap mode is handled in its own code path */ - pg_fatal("should never happen"); - break; - } + switch (user_opts.transfer_mode) + { + case TRANSFER_MODE_CLONE: + pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", + old_file, new_file); + cloneFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", + old_file, new_file); + copyFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY_FILE_RANGE: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", + old_file, new_file); + copyFileByRange(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_LINK: + pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", + old_file, new_file); + linkFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_SWAP: + /* swap mode is handled in its own code path */ + pg_fatal("should never happen"); + break; + } } } diff --git a/src/bin/pg_upgrade/t/006_transfer_modes.pl b/src/bin/pg_upgrade/t/006_transfer_modes.pl index 9efa5dc863c..360d05c4b68 100644 --- a/src/bin/pg_upgrade/t/006_transfer_modes.pl +++ b/src/bin/pg_upgrade/t/006_transfer_modes.pl @@ -29,10 +29,8 @@ sub test_mode } $new->init(); - $new->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); - $old->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); + $new->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); + $old->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); # We can only test security labels if both the old and new installations # have dummy_seclabel. @@ -76,15 +74,14 @@ sub test_mode "CREATE TABLE test4 AS SELECT generate_series(400, 502)"); } - $old->safe_psql('postgres', - "CREATE TABLESPACE inplc_tblspc LOCATION ''"); - $old->safe_psql('postgres', - "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); - $old->safe_psql('postgres', - "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" - ); - $old->safe_psql('testdb3', - "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); + $old->safe_psql('postgres', "CREATE TABLESPACE inplc_tblspc LOCATION ''"); + $old->safe_psql('postgres', + "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); + $old->safe_psql('postgres', + "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" + ); + $old->safe_psql('testdb3', + "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); # While we are here, test handling of large objects. $old->safe_psql( @@ -152,12 +149,10 @@ sub test_mode } # Tests for in-place tablespaces. - $result = - $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); - is($result, '104', "test5 data after pg_upgrade $mode"); - $result = - $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); - is($result, '105', "test6 data after pg_upgrade $mode"); + $result = $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); + is($result, '104', "test5 data after pg_upgrade $mode"); + $result = $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); + is($result, '105', "test6 data after pg_upgrade $mode"); # Tests for large objects $result = $new->safe_psql('postgres', "SELECT lo_get(4532)"); diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index 44ef11d980e..c90bf8bbde2 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -6278,23 +6278,22 @@ get_create_object_cmd(EditableObjectType obj_type, Oid oid, * ensure the right view gets replaced. Also, check relation kind * to be sure it's a view. * - * Views may have WITH [LOCAL|CASCADED] - * CHECK OPTION. These are not part of the view definition - * returned by pg_get_viewdef() and so need to be retrieved - * separately. Materialized views may have - * arbitrary storage parameter reloptions. + * Views may have WITH [LOCAL|CASCADED] CHECK OPTION. These are + * not part of the view definition returned by pg_get_viewdef() + * and so need to be retrieved separately. Materialized views may + * have arbitrary storage parameter reloptions. */ printfPQExpBuffer(query, "/* %s */\n", _("Get view's definition and details")); - appendPQExpBuffer(query, - "SELECT nspname, relname, relkind, " - "pg_catalog.pg_get_viewdef(c.oid, true), " - "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " - "FROM pg_catalog.pg_class c " - "LEFT JOIN pg_catalog.pg_namespace n " - "ON c.relnamespace = n.oid WHERE c.oid = %u", - oid); + appendPQExpBuffer(query, + "SELECT nspname, relname, relkind, " + "pg_catalog.pg_get_viewdef(c.oid, true), " + "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " + "FROM pg_catalog.pg_class c " + "LEFT JOIN pg_catalog.pg_namespace n " + "ON c.relnamespace = n.oid WHERE c.oid = %u", + oid); break; } diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index ce99137c613..ac0c55e7aa5 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -387,19 +387,19 @@ describeFunctions(const char *functypes, const char *func_pattern, gettext_noop("stable"), gettext_noop("volatile"), gettext_noop("Volatility")); - appendPQExpBuffer(&buf, - ",\n CASE\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" - " END as \"%s\"", - gettext_noop("restricted"), - gettext_noop("safe"), - gettext_noop("unsafe"), - gettext_noop("Parallel")); + appendPQExpBuffer(&buf, + ",\n CASE\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" + " END as \"%s\"", + gettext_noop("restricted"), + gettext_noop("safe"), + gettext_noop("unsafe"), + gettext_noop("Parallel")); appendPQExpBuffer(&buf, ",\n pg_catalog.pg_get_userbyid(p.proowner) as \"%s\"" ",\n CASE WHEN prosecdef THEN '%s' ELSE '%s' END AS \"%s\"" @@ -599,8 +599,8 @@ describeFunctions(const char *functypes, const char *func_pattern, myopt.title = _("List of functions"); myopt.translate_header = true; - myopt.translate_columns = translate_columns; - myopt.n_translate_columns = lengthof(translate_columns); + myopt.translate_columns = translate_columns; + myopt.n_translate_columns = lengthof(translate_columns); printQuery(res, &myopt, pset.queryFout, false, pset.logfile); @@ -1086,38 +1086,38 @@ permissionsList(const char *pattern, bool showSystem) " ), E'\\n') AS \"%s\"", gettext_noop("Column privileges")); - appendPQExpBuffer(&buf, - ",\n pg_catalog.array_to_string(ARRAY(\n" - " SELECT polname\n" - " || CASE WHEN NOT polpermissive THEN\n" - " E' (RESTRICTIVE)'\n" - " ELSE '' END\n" - " || CASE WHEN polcmd != '*' THEN\n" - " E' (' || polcmd::pg_catalog.text || E'):'\n" - " ELSE E':'\n" - " END\n" - " || CASE WHEN polqual IS NOT NULL THEN\n" - " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" - " ELSE E''\n" - " END\n" - " || CASE WHEN polwithcheck IS NOT NULL THEN\n" - " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" - " ELSE E''\n" - " END" - " || CASE WHEN polroles <> '{0}' THEN\n" - " E'\\n to: ' || pg_catalog.array_to_string(\n" - " ARRAY(\n" - " SELECT rolname\n" - " FROM pg_catalog.pg_roles\n" - " WHERE oid = ANY (polroles)\n" - " ORDER BY 1\n" - " ), E', ')\n" - " ELSE E''\n" - " END\n" - " FROM pg_catalog.pg_policy pol\n" - " WHERE polrelid = c.oid), E'\\n')\n" - " AS \"%s\"", - gettext_noop("Policies")); + appendPQExpBuffer(&buf, + ",\n pg_catalog.array_to_string(ARRAY(\n" + " SELECT polname\n" + " || CASE WHEN NOT polpermissive THEN\n" + " E' (RESTRICTIVE)'\n" + " ELSE '' END\n" + " || CASE WHEN polcmd != '*' THEN\n" + " E' (' || polcmd::pg_catalog.text || E'):'\n" + " ELSE E':'\n" + " END\n" + " || CASE WHEN polqual IS NOT NULL THEN\n" + " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" + " ELSE E''\n" + " END\n" + " || CASE WHEN polwithcheck IS NOT NULL THEN\n" + " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" + " ELSE E''\n" + " END" + " || CASE WHEN polroles <> '{0}' THEN\n" + " E'\\n to: ' || pg_catalog.array_to_string(\n" + " ARRAY(\n" + " SELECT rolname\n" + " FROM pg_catalog.pg_roles\n" + " WHERE oid = ANY (polroles)\n" + " ORDER BY 1\n" + " ), E', ')\n" + " ELSE E''\n" + " END\n" + " FROM pg_catalog.pg_policy pol\n" + " WHERE polrelid = c.oid), E'\\n')\n" + " AS \"%s\"", + gettext_noop("Policies")); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_class c\n" " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n" @@ -1675,27 +1675,27 @@ describeOneTableDetails(const char *schemaname, char *footers[3] = {NULL, NULL, NULL}; printfPQExpBuffer(&buf, "/* %s */\n", _("Get sequence information")); - appendPQExpBuffer(&buf, - "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" - " seqstart AS \"%s\",\n" - " seqmin AS \"%s\",\n" - " seqmax AS \"%s\",\n" - " seqincrement AS \"%s\",\n" - " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" - " seqcache AS \"%s\"\n", - gettext_noop("Type"), - gettext_noop("Start"), - gettext_noop("Minimum"), - gettext_noop("Maximum"), - gettext_noop("Increment"), - gettext_noop("yes"), - gettext_noop("no"), - gettext_noop("Cycles?"), - gettext_noop("Cache")); - appendPQExpBuffer(&buf, - "FROM pg_catalog.pg_sequence\n" - "WHERE seqrelid = '%s';", - oid); + appendPQExpBuffer(&buf, + "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" + " seqstart AS \"%s\",\n" + " seqmin AS \"%s\",\n" + " seqmax AS \"%s\",\n" + " seqincrement AS \"%s\",\n" + " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" + " seqcache AS \"%s\"\n", + gettext_noop("Type"), + gettext_noop("Start"), + gettext_noop("Minimum"), + gettext_noop("Maximum"), + gettext_noop("Increment"), + gettext_noop("yes"), + gettext_noop("no"), + gettext_noop("Cycles?"), + gettext_noop("Cache")); + appendPQExpBuffer(&buf, + "FROM pg_catalog.pg_sequence\n" + "WHERE seqrelid = '%s';", + oid); res = PSQLexec(buf.data); if (!res) @@ -1913,7 +1913,7 @@ describeOneTableDetails(const char *schemaname, appendPQExpBufferStr(&buf, ",\n (SELECT c.collname FROM pg_catalog.pg_collation c, pg_catalog.pg_type t\n" " WHERE c.oid = a.attcollation AND t.oid = a.atttypid AND a.attcollation <> t.typcollation) AS attcollation"); attcoll_col = cols++; - appendPQExpBufferStr(&buf, ",\n a.attidentity"); + appendPQExpBufferStr(&buf, ",\n a.attidentity"); attidentity_col = cols++; if (pset.sversion >= 120000) appendPQExpBufferStr(&buf, ",\n a.attgenerated"); @@ -2326,7 +2326,7 @@ describeOneTableDetails(const char *schemaname, CppAsString2(CONSTRAINT_EXCLUSION) ") AND " "condeferred) AS condeferred,\n"); - appendPQExpBufferStr(&buf, "i.indisreplident,\n"); + appendPQExpBufferStr(&buf, "i.indisreplident,\n"); if (pset.sversion >= 150000) appendPQExpBufferStr(&buf, "i.indnullsnotdistinct,\n"); @@ -2431,7 +2431,7 @@ describeOneTableDetails(const char *schemaname, "pg_catalog.pg_get_indexdef(i.indexrelid, 0, true),\n " "pg_catalog.pg_get_constraintdef(con.oid, true), " "contype, condeferrable, condeferred"); - appendPQExpBufferStr(&buf, ", i.indisreplident"); + appendPQExpBufferStr(&buf, ", i.indisreplident"); appendPQExpBufferStr(&buf, ", c2.reltablespace"); if (pset.sversion >= 180000) appendPQExpBufferStr(&buf, ", con.conperiod"); @@ -2682,81 +2682,80 @@ describeOneTableDetails(const char *schemaname, PQclear(result); /* print any row-level policies */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get row-level policies for this table")); - appendPQExpBufferStr(&buf, "SELECT pol.polname,"); - appendPQExpBufferStr(&buf, - " pol.polpermissive,\n"); - appendPQExpBuffer(&buf, - " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" - " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" - " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" - " CASE pol.polcmd\n" - " WHEN 'r' THEN 'SELECT'\n" - " WHEN 'a' THEN 'INSERT'\n" - " WHEN 'w' THEN 'UPDATE'\n" - " WHEN 'd' THEN 'DELETE'\n" - " END AS cmd\n" - "FROM pg_catalog.pg_policy pol\n" - "WHERE pol.polrelid = '%s' ORDER BY 1;", - oid); + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get row-level policies for this table")); + appendPQExpBufferStr(&buf, "SELECT pol.polname,"); + appendPQExpBufferStr(&buf, + " pol.polpermissive,\n"); + appendPQExpBuffer(&buf, + " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" + " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" + " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" + " CASE pol.polcmd\n" + " WHEN 'r' THEN 'SELECT'\n" + " WHEN 'a' THEN 'INSERT'\n" + " WHEN 'w' THEN 'UPDATE'\n" + " WHEN 'd' THEN 'DELETE'\n" + " END AS cmd\n" + "FROM pg_catalog.pg_policy pol\n" + "WHERE pol.polrelid = '%s' ORDER BY 1;", + oid); - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - /* - * Handle cases where RLS is enabled and there are policies, or - * there aren't policies, or RLS isn't enabled but there are - * policies - */ - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies:")); + /* + * Handle cases where RLS is enabled and there are policies, or there + * aren't policies, or RLS isn't enabled but there are policies + */ + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies:")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled):")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled):")); - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); - if (!tableinfo.rowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (row security disabled):")); + if (!tableinfo.rowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (row security disabled):")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " POLICY \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " POLICY \"%s\"", + PQgetvalue(result, i, 0)); - if (*(PQgetvalue(result, i, 1)) == 'f') - appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); + if (*(PQgetvalue(result, i, 1)) == 'f') + appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); - if (!PQgetisnull(result, i, 5)) - appendPQExpBuffer(&buf, " FOR %s", - PQgetvalue(result, i, 5)); + if (!PQgetisnull(result, i, 5)) + appendPQExpBuffer(&buf, " FOR %s", + PQgetvalue(result, i, 5)); - if (!PQgetisnull(result, i, 2)) - { - appendPQExpBuffer(&buf, "\n TO %s", - PQgetvalue(result, i, 2)); - } + if (!PQgetisnull(result, i, 2)) + { + appendPQExpBuffer(&buf, "\n TO %s", + PQgetvalue(result, i, 2)); + } - if (!PQgetisnull(result, i, 3)) - appendPQExpBuffer(&buf, "\n USING (%s)", - PQgetvalue(result, i, 3)); + if (!PQgetisnull(result, i, 3)) + appendPQExpBuffer(&buf, "\n USING (%s)", + PQgetvalue(result, i, 3)); - if (!PQgetisnull(result, i, 4)) - appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", - PQgetvalue(result, i, 4)); + if (!PQgetisnull(result, i, 4)) + appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", + PQgetvalue(result, i, 4)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* print any extended statistics */ if (pset.sversion >= 140000) @@ -3025,115 +3024,115 @@ describeOneTableDetails(const char *schemaname, } /* print any publications */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get publications that publish this table")); - if (pset.sversion >= 150000) + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get publications that publish this table")); + if (pset.sversion >= 150000) + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" + " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" + "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" + "UNION\n" + "SELECT pubname\n" + " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" + " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" + " (SELECT pg_catalog.string_agg(attname, ', ')\n" + " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" + " pg_catalog.pg_attribute\n" + " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" + " ELSE NULL END) " + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" + "WHERE pr.prrelid = '%s'\n", + oid, oid, oid); + + if (pset.sversion >= 190000) { + /* + * Skip entries where this relation appears in the + * publication's EXCEPT list. + */ appendPQExpBuffer(&buf, + " AND NOT pr.prexcept\n" + "UNION\n" "SELECT pubname\n" " , NULL\n" " , NULL\n" "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" - " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" - "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" - "UNION\n" - "SELECT pubname\n" - " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" - " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" - " (SELECT pg_catalog.string_agg(attname, ', ')\n" - " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" - " pg_catalog.pg_attribute\n" - " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" - " ELSE NULL END) " - "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" - "WHERE pr.prrelid = '%s'\n", + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + " AND NOT EXISTS (\n" + " SELECT 1\n" + " FROM pg_catalog.pg_publication_rel pr\n" + " WHERE pr.prpubid = p.oid AND\n" + " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" + "ORDER BY 1;", oid, oid, oid); - - if (pset.sversion >= 190000) - { - /* - * Skip entries where this relation appears in the - * publication's EXCEPT list. - */ - appendPQExpBuffer(&buf, - " AND NOT pr.prexcept\n" - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - " AND NOT EXISTS (\n" - " SELECT 1\n" - " FROM pg_catalog.pg_publication_rel pr\n" - " WHERE pr.prpubid = p.oid AND\n" - " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" - "ORDER BY 1;", - oid, oid, oid); - } - else - { - appendPQExpBuffer(&buf, - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - "ORDER BY 1;", - oid); - } } else { appendPQExpBuffer(&buf, + "UNION\n" "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - "WHERE pr.prrelid = '%s'\n" - "UNION ALL\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" + " , NULL\n" + " , NULL\n" "FROM pg_catalog.pg_publication p\n" "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" "ORDER BY 1;", - oid, oid); + oid); } + } + else + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + "WHERE pr.prrelid = '%s'\n" + "UNION ALL\n" + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + "ORDER BY 1;", + oid, oid); + } - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - if (tuples > 0) - printTableAddFooter(&cont, _("Included in publications:")); + if (tuples > 0) + printTableAddFooter(&cont, _("Included in publications:")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " \"%s\"", + PQgetvalue(result, i, 0)); - /* column list (if any) */ - if (!PQgetisnull(result, i, 2)) - appendPQExpBuffer(&buf, " (%s)", - PQgetvalue(result, i, 2)); + /* column list (if any) */ + if (!PQgetisnull(result, i, 2)) + appendPQExpBuffer(&buf, " (%s)", + PQgetvalue(result, i, 2)); - /* row filter (if any) */ - if (!PQgetisnull(result, i, 1)) - appendPQExpBuffer(&buf, " WHERE %s", - PQgetvalue(result, i, 1)); + /* row filter (if any) */ + if (!PQgetisnull(result, i, 1)) + appendPQExpBuffer(&buf, " WHERE %s", + PQgetvalue(result, i, 1)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* Print publications where the table is in the EXCEPT clause */ if (pset.sversion >= 190000) @@ -3805,7 +3804,7 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) ncols++; } appendPQExpBufferStr(&buf, "\n, r.rolreplication"); - appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); + appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_roles r\n"); @@ -3860,8 +3859,8 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) if (strcmp(PQgetvalue(res, i, (verbose ? 9 : 8)), "t") == 0) add_role_attribute(&buf, _("Replication")); - if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) - add_role_attribute(&buf, _("Bypass RLS")); + if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) + add_role_attribute(&buf, _("Bypass RLS")); conns = atoi(PQgetvalue(res, i, 6)); if (conns >= 0) @@ -5155,14 +5154,14 @@ listCollations(const char *pattern, bool verbose, bool showSystem) gettext_noop("Schema"), gettext_noop("Name")); - appendPQExpBuffer(&buf, - " CASE c.collprovider " - "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " - "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " - "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " - "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " - "END AS \"%s\",\n", - gettext_noop("Provider")); + appendPQExpBuffer(&buf, + " CASE c.collprovider " + "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " + "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " + "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " + "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " + "END AS \"%s\",\n", + gettext_noop("Provider")); appendPQExpBuffer(&buf, " c.collcollate AS \"%s\",\n" -- 2.50.1 (Apple Git-155) --aHl3HfeiUuO3zeNC-- ^ permalink raw reply [nested|flat] 59+ messages in thread
* [PATCH v6 4/4] run pgindent and pgperltidy @ 2026-06-30 18:24 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 59+ messages in thread From: Nathan Bossart @ 2026-06-30 18:24 UTC (permalink / raw) --- src/bin/pg_dump/pg_dump.c | 464 ++++++++++----------- src/bin/pg_dump/pg_dumpall.c | 30 +- src/bin/pg_upgrade/check.c | 16 +- src/bin/pg_upgrade/controldata.c | 2 +- src/bin/pg_upgrade/exec.c | 8 +- src/bin/pg_upgrade/multixact_rewrite.c | 80 ++-- src/bin/pg_upgrade/pg_upgrade.c | 34 +- src/bin/pg_upgrade/relfilenumber.c | 54 +-- src/bin/pg_upgrade/t/006_transfer_modes.pl | 33 +- src/bin/psql/command.c | 29 +- src/bin/psql/describe.c | 461 ++++++++++---------- 11 files changed, 601 insertions(+), 610 deletions(-) diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 65bd15ebfd2..5673268b467 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -1491,8 +1491,8 @@ setup_connection(Archive *AH, const char *dumpencoding, * Disable timeouts if supported. */ ExecuteSqlStatement(AH, "SET statement_timeout = 0"); - ExecuteSqlStatement(AH, "SET lock_timeout = 0"); - ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); + ExecuteSqlStatement(AH, "SET lock_timeout = 0"); + ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); if (AH->remoteVersion >= 170000) ExecuteSqlStatement(AH, "SET transaction_timeout = 0"); @@ -1505,10 +1505,10 @@ setup_connection(Archive *AH, const char *dumpencoding, /* * Adjust row-security mode, if supported. */ - if (dopt->enable_row_security) - ExecuteSqlStatement(AH, "SET row_security = on"); - else - ExecuteSqlStatement(AH, "SET row_security = off"); + if (dopt->enable_row_security) + ExecuteSqlStatement(AH, "SET row_security = on"); + else + ExecuteSqlStatement(AH, "SET row_security = off"); /* * For security reasons, we restrict the expansion of non-system views and @@ -1933,10 +1933,9 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) addObjectDependency(dobj, ext->dobj.dumpId); /* - * Mark the member object to have any non-initial ACLs - * dumped. (Any initial ACLs will be removed later, using data from - * pg_init_privs, so that we'll dump only the delta from the extension's - * initial setup.) + * Mark the member object to have any non-initial ACLs dumped. (Any + * initial ACLs will be removed later, using data from pg_init_privs, so + * that we'll dump only the delta from the extension's initial setup.) * * In binary upgrades, we still dump all components of the members * individually, since the idea is to exactly reproduce the database @@ -1953,7 +1952,7 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) if (fout->dopt->binary_upgrade) dobj->dump = ext->dobj.dump; else - dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); + dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); return true; } @@ -1987,9 +1986,9 @@ selectDumpableNamespace(NamespaceInfo *nsinfo, Archive *fout) else if (strcmp(nsinfo->dobj.name, "pg_catalog") == 0) { /* - * We dump out any ACLs defined in pg_catalog, if - * they are interesting (and not the original ACLs which were set at - * initdb time, see pg_init_privs). + * We dump out any ACLs defined in pg_catalog, if they are interesting + * (and not the original ACLs which were set at initdb time, see + * pg_init_privs). */ nsinfo->dobj.dump_contains = nsinfo->dobj.dump = DUMP_COMPONENT_ACL; } @@ -3296,7 +3295,7 @@ dumpDatabase(Archive *fout) "datcollate, datctype, datfrozenxid, " "datacl, acldefault('d', datdba) AS acldefault, " "datistemplate, datconnlimit, "); - appendPQExpBufferStr(dbQry, "datminmxid, "); + appendPQExpBufferStr(dbQry, "datminmxid, "); if (fout->remoteVersion >= 170000) appendPQExpBufferStr(dbQry, "datlocprovider, datlocale, datcollversion, "); else if (fout->remoteVersion >= 150000) @@ -3638,11 +3637,11 @@ dumpDatabase(Archive *fout) ii_oid, ii_relminmxid; - appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" - "FROM pg_catalog.pg_class\n" - "WHERE oid IN (%u, %u, %u, %u);\n", - LargeObjectRelationId, LargeObjectLOidPNIndexId, - LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); + appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" + "FROM pg_catalog.pg_class\n" + "WHERE oid IN (%u, %u, %u, %u);\n", + LargeObjectRelationId, LargeObjectLOidPNIndexId, + LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); lo_res = ExecuteSqlQuery(fout, loFrozenQry->data, PGRES_TUPLES_OK); @@ -4274,7 +4273,7 @@ getPolicies(Archive *fout, TableInfo tblinfo[], int numTables) printfPQExpBuffer(query, "SELECT pol.oid, pol.tableoid, pol.polrelid, pol.polname, pol.polcmd, "); - appendPQExpBufferStr(query, "pol.polpermissive, "); + appendPQExpBufferStr(query, "pol.polpermissive, "); appendPQExpBuffer(query, "CASE WHEN pol.polroles = '{0}' THEN NULL ELSE " " pg_catalog.array_to_string(ARRAY(SELECT pg_catalog.quote_ident(rolname) from pg_catalog.pg_roles WHERE oid = ANY(pol.polroles)), ', ') END AS polroles, " @@ -6633,9 +6632,9 @@ getAccessMethods(Archive *fout) * Select all access methods from pg_am table. */ appendPQExpBufferStr(query, "SELECT tableoid, oid, amname, "); - appendPQExpBufferStr(query, - "amtype, " - "amhandler::pg_catalog.regproc AS amhandler "); + appendPQExpBufferStr(query, + "amtype, " + "amhandler::pg_catalog.regproc AS amhandler "); appendPQExpBufferStr(query, "FROM pg_am"); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6827,35 +6826,35 @@ getAggregates(Archive *fout) * Find all interesting aggregates. See comment in getFuncs() for the * rationale behind the filtering logic. */ - agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" - : "p.proisagg"); + agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" + : "p.proisagg"); - appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " - "p.proname AS aggname, " - "p.pronamespace AS aggnamespace, " - "p.pronargs, p.proargtypes, " - "p.proowner, " - "p.proacl AS aggacl, " - "acldefault('f', p.proowner) AS acldefault " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s AND (" - "p.pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog') OR " - "p.proacl IS DISTINCT FROM pip.initprivs", - agg_check); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - " OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); - appendPQExpBufferChar(query, ')'); + appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " + "p.proname AS aggname, " + "p.pronamespace AS aggnamespace, " + "p.pronargs, p.proargtypes, " + "p.proowner, " + "p.proacl AS aggacl, " + "acldefault('f', p.proowner) AS acldefault " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s AND (" + "p.pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog') OR " + "p.proacl IS DISTINCT FROM pip.initprivs", + agg_check); + if (dopt->binary_upgrade) + appendPQExpBufferStr(query, + " OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6957,53 +6956,53 @@ getFuncs(Archive *fout) * include them, since we want to dump extension members individually in * that mode. Also, if they are used by casts or transforms then we need * to gather the information about them, though they won't be dumped if - * they are built-in. Also, include functions in - * pg_catalog if they have an ACL different from what's shown in - * pg_init_privs (so we have to join to pg_init_privs; annoying). + * they are built-in. Also, include functions in pg_catalog if they have + * an ACL different from what's shown in pg_init_privs (so we have to join + * to pg_init_privs; annoying). */ - not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" - : "NOT p.proisagg"); + not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" + : "NOT p.proisagg"); - appendPQExpBuffer(query, - "SELECT p.tableoid, p.oid, p.proname, p.prolang, " - "p.pronargs, p.proargtypes, p.prorettype, " - "p.proacl, " - "acldefault('f', p.proowner) AS acldefault, " - "p.pronamespace, " - "p.proowner " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s" - "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " - "WHERE classid = 'pg_proc'::regclass AND " - "objid = p.oid AND deptype = 'i')" - "\n AND (" - "\n pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog')" - "\n OR EXISTS (SELECT 1 FROM pg_cast" - "\n WHERE pg_cast.oid > %u " - "\n AND p.oid = pg_cast.castfunc)" - "\n OR EXISTS (SELECT 1 FROM pg_transform" - "\n WHERE pg_transform.oid > %u AND " - "\n (p.oid = pg_transform.trffromsql" - "\n OR p.oid = pg_transform.trftosql))", - not_agg_check, - g_last_builtin_oid, - g_last_builtin_oid); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); + appendPQExpBuffer(query, + "SELECT p.tableoid, p.oid, p.proname, p.prolang, " + "p.pronargs, p.proargtypes, p.prorettype, " + "p.proacl, " + "acldefault('f', p.proowner) AS acldefault, " + "p.pronamespace, " + "p.proowner " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s" + "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " + "WHERE classid = 'pg_proc'::regclass AND " + "objid = p.oid AND deptype = 'i')" + "\n AND (" + "\n pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog')" + "\n OR EXISTS (SELECT 1 FROM pg_cast" + "\n WHERE pg_cast.oid > %u " + "\n AND p.oid = pg_cast.castfunc)" + "\n OR EXISTS (SELECT 1 FROM pg_transform" + "\n WHERE pg_transform.oid > %u AND " + "\n (p.oid = pg_transform.trffromsql" + "\n OR p.oid = pg_transform.trftosql))", + not_agg_check, + g_last_builtin_oid, + g_last_builtin_oid); + if (dopt->binary_upgrade) appendPQExpBufferStr(query, - "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); - appendPQExpBufferChar(query, ')'); + "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferStr(query, + "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -7252,31 +7251,31 @@ getTables(Archive *fout, int *numTables) appendPQExpBufferStr(query, "c.relhasoids, "); - appendPQExpBufferStr(query, - "c.relispopulated, "); + appendPQExpBufferStr(query, + "c.relispopulated, "); - appendPQExpBufferStr(query, - "c.relreplident, "); + appendPQExpBufferStr(query, + "c.relreplident, "); - appendPQExpBufferStr(query, - "c.relrowsecurity, c.relforcerowsecurity, "); + appendPQExpBufferStr(query, + "c.relrowsecurity, c.relforcerowsecurity, "); - appendPQExpBufferStr(query, - "c.relminmxid, tc.relminmxid AS tminmxid, "); + appendPQExpBufferStr(query, + "c.relminmxid, tc.relminmxid AS tminmxid, "); - appendPQExpBufferStr(query, - "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); + appendPQExpBufferStr(query, + "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); - appendPQExpBufferStr(query, - "am.amname, "); + appendPQExpBufferStr(query, + "am.amname, "); - appendPQExpBufferStr(query, - "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); + appendPQExpBufferStr(query, + "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); - appendPQExpBufferStr(query, - "c.relispartition AS ispartition "); + appendPQExpBufferStr(query, + "c.relispartition AS ispartition "); /* * Left join to pg_depend to pick up dependency info linking sequences to @@ -7296,8 +7295,8 @@ getTables(Archive *fout, int *numTables) /* * Left join to pg_am to pick up the amname. */ - appendPQExpBufferStr(query, - "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); + appendPQExpBufferStr(query, + "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); /* * We purposefully ignore toast OIDs for partitioned tables; the reason is @@ -7868,8 +7867,8 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables) "t.reloptions AS indreloptions, "); - appendPQExpBufferStr(query, - "i.indisreplident, "); + appendPQExpBufferStr(query, + "i.indisreplident, "); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -9313,8 +9312,8 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables) appendPQExpBufferStr(q, "'' AS attcompression,\n"); - appendPQExpBufferStr(q, - "a.attidentity,\n"); + appendPQExpBufferStr(q, + "a.attidentity,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(q, @@ -10717,73 +10716,73 @@ getAdditionalACLs(Archive *fout) PQclear(res); /* Fetch initial-privileges data */ - printfPQExpBuffer(query, - "SELECT objoid, classoid, objsubid, privtype, initprivs " - "FROM pg_init_privs"); + printfPQExpBuffer(query, + "SELECT objoid, classoid, objsubid, privtype, initprivs " + "FROM pg_init_privs"); - res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); + res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); - ntups = PQntuples(res); - for (i = 0; i < ntups; i++) - { - Oid objoid = atooid(PQgetvalue(res, i, 0)); - Oid classoid = atooid(PQgetvalue(res, i, 1)); - int objsubid = atoi(PQgetvalue(res, i, 2)); - char privtype = *(PQgetvalue(res, i, 3)); - char *initprivs = PQgetvalue(res, i, 4); - CatalogId objId; - DumpableObject *dobj; + ntups = PQntuples(res); + for (i = 0; i < ntups; i++) + { + Oid objoid = atooid(PQgetvalue(res, i, 0)); + Oid classoid = atooid(PQgetvalue(res, i, 1)); + int objsubid = atoi(PQgetvalue(res, i, 2)); + char privtype = *(PQgetvalue(res, i, 3)); + char *initprivs = PQgetvalue(res, i, 4); + CatalogId objId; + DumpableObject *dobj; - objId.tableoid = classoid; - objId.oid = objoid; - dobj = findObjectByCatalogId(objId); - /* OK to ignore entries we haven't got a DumpableObject for */ - if (dobj) + objId.tableoid = classoid; + objId.oid = objoid; + dobj = findObjectByCatalogId(objId); + /* OK to ignore entries we haven't got a DumpableObject for */ + if (dobj) + { + /* Cope with sub-object initprivs */ + if (objsubid != 0) { - /* Cope with sub-object initprivs */ - if (objsubid != 0) - { - if (dobj->objType == DO_TABLE) - { - /* For a column initprivs, set the table's ACL flags */ - dobj->components |= DUMP_COMPONENT_ACL; - ((TableInfo *) dobj)->hascolumnACLs = true; - } - else - pg_log_warning("unsupported pg_init_privs entry: %u %u %d", - classoid, objoid, objsubid); - continue; - } - - /* - * We ignore any pg_init_privs.initprivs entry for the public - * schema, as explained in getNamespaces(). - */ - if (dobj->objType == DO_NAMESPACE && - strcmp(dobj->name, "public") == 0) - continue; - - /* Else it had better be of a type we think has ACLs */ - if (dobj->objType == DO_NAMESPACE || - dobj->objType == DO_TYPE || - dobj->objType == DO_FUNC || - dobj->objType == DO_AGG || - dobj->objType == DO_TABLE || - dobj->objType == DO_PROCLANG || - dobj->objType == DO_FDW || - dobj->objType == DO_FOREIGN_SERVER) + if (dobj->objType == DO_TABLE) { - DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; - - daobj->dacl.privtype = privtype; - daobj->dacl.initprivs = pstrdup(initprivs); + /* For a column initprivs, set the table's ACL flags */ + dobj->components |= DUMP_COMPONENT_ACL; + ((TableInfo *) dobj)->hascolumnACLs = true; } else pg_log_warning("unsupported pg_init_privs entry: %u %u %d", classoid, objoid, objsubid); + continue; + } + + /* + * We ignore any pg_init_privs.initprivs entry for the public + * schema, as explained in getNamespaces(). + */ + if (dobj->objType == DO_NAMESPACE && + strcmp(dobj->name, "public") == 0) + continue; + + /* Else it had better be of a type we think has ACLs */ + if (dobj->objType == DO_NAMESPACE || + dobj->objType == DO_TYPE || + dobj->objType == DO_FUNC || + dobj->objType == DO_AGG || + dobj->objType == DO_TABLE || + dobj->objType == DO_PROCLANG || + dobj->objType == DO_FDW || + dobj->objType == DO_FOREIGN_SERVER) + { + DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; + + daobj->dacl.privtype = privtype; + daobj->dacl.initprivs = pstrdup(initprivs); } + else + pg_log_warning("unsupported pg_init_privs entry: %u %u %d", + classoid, objoid, objsubid); } - PQclear(res); + } + PQclear(res); destroyPQExpBuffer(query); } @@ -11128,8 +11127,8 @@ dumpRelationStats_dumper(Archive *fout, const void *userArg, const TocEntry *te) * The results must be in the order of the relations supplied in the * parameters to ensure we remain in sync as we walk through the TOC. * - * For versions before 19, the redundant filter clause on s.tablename = - * ANY(...) seems sufficient to convince the planner to use + * For versions before 19, the redundant filter clause on s.tablename + * = ANY(...) seems sufficient to convince the planner to use * pg_class_relname_nsp_index, which avoids a full scan of pg_stats. * In newer versions, pg_stats returns the table OIDs, eliminating the * need for that hack. @@ -13469,11 +13468,11 @@ dumpFunc(Archive *fout, const FuncInfo *finfo) "pg_catalog.pg_get_function_result(p.oid) AS funcresult,\n" "proleakproof,\n"); - appendPQExpBufferStr(query, - "array_to_string(protrftypes, ' ') AS protrftypes,\n"); + appendPQExpBufferStr(query, + "array_to_string(protrftypes, ' ') AS protrftypes,\n"); - appendPQExpBufferStr(query, - "proparallel,\n"); + appendPQExpBufferStr(query, + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -14963,9 +14962,9 @@ dumpCollation(Archive *fout, const CollInfo *collinfo) /* Get collation-specific details */ appendPQExpBufferStr(query, "SELECT "); - appendPQExpBufferStr(query, - "collprovider, " - "collversion, "); + appendPQExpBufferStr(query, + "collprovider, " + "collversion, "); if (fout->remoteVersion >= 120000) appendPQExpBufferStr(query, @@ -15372,23 +15371,23 @@ dumpAgg(Archive *fout, const AggInfo *agginfo) "pg_catalog.pg_get_function_arguments(p.oid) AS funcargs,\n" "pg_catalog.pg_get_function_identity_arguments(p.oid) AS funciargs,\n"); - appendPQExpBufferStr(query, - "aggkind,\n" - "aggmtransfn,\n" - "aggminvtransfn,\n" - "aggmfinalfn,\n" - "aggmtranstype::pg_catalog.regtype,\n" - "aggfinalextra,\n" - "aggmfinalextra,\n" - "aggtransspace,\n" - "aggmtransspace,\n" - "aggminitval,\n"); + appendPQExpBufferStr(query, + "aggkind,\n" + "aggmtransfn,\n" + "aggminvtransfn,\n" + "aggmfinalfn,\n" + "aggmtranstype::pg_catalog.regtype,\n" + "aggfinalextra,\n" + "aggmfinalextra,\n" + "aggtransspace,\n" + "aggmtransspace,\n" + "aggminitval,\n"); - appendPQExpBufferStr(query, - "aggcombinefn,\n" - "aggserialfn,\n" - "aggdeserialfn,\n" - "proparallel,\n"); + appendPQExpBufferStr(query, + "aggcombinefn,\n" + "aggserialfn,\n" + "aggdeserialfn,\n" + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -16848,30 +16847,30 @@ dumpTable(Archive *fout, const TableInfo *tbinfo) appendPQExpBufferStr(query, "PREPARE getColumnACLs(pg_catalog.oid) AS\n"); - /* - * In principle we should call acldefault('c', relowner) to - * get the default ACL for a column. However, we don't - * currently store the numeric OID of the relowner in - * TableInfo. We could convert the owner name using regrole, - * but that creates a risk of failure due to concurrent role - * renames. Given that the default ACL for columns is empty - * and is likely to stay that way, it's not worth extra cycles - * and risk to avoid hard-wiring that knowledge here. - */ - appendPQExpBufferStr(query, - "SELECT at.attname, " - "at.attacl, " - "'{}' AS acldefault, " - "pip.privtype, pip.initprivs " - "FROM pg_catalog.pg_attribute at " - "LEFT JOIN pg_catalog.pg_init_privs pip ON " - "(at.attrelid = pip.objoid " - "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " - "AND at.attnum = pip.objsubid) " - "WHERE at.attrelid = $1 AND " - "NOT at.attisdropped " - "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " - "ORDER BY at.attnum"); + /* + * In principle we should call acldefault('c', relowner) to get + * the default ACL for a column. However, we don't currently + * store the numeric OID of the relowner in TableInfo. We could + * convert the owner name using regrole, but that creates a risk + * of failure due to concurrent role renames. Given that the + * default ACL for columns is empty and is likely to stay that + * way, it's not worth extra cycles and risk to avoid hard-wiring + * that knowledge here. + */ + appendPQExpBufferStr(query, + "SELECT at.attname, " + "at.attacl, " + "'{}' AS acldefault, " + "pip.privtype, pip.initprivs " + "FROM pg_catalog.pg_attribute at " + "LEFT JOIN pg_catalog.pg_init_privs pip ON " + "(at.attrelid = pip.objoid " + "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " + "AND at.attnum = pip.objsubid) " + "WHERE at.attrelid = $1 AND " + "NOT at.attisdropped " + "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " + "ORDER BY at.attnum"); ExecuteSqlStatement(fout, query->data); @@ -19165,7 +19164,7 @@ collectSequences(Archive *fout) * pg_get_sequence_data(), but we only do so for non-schema-only dumps. */ if (fout->remoteVersion < 180000 || - (!fout->dopt->dumpData && !fout->dopt->sequence_data)) + (!fout->dopt->dumpData && !fout->dopt->sequence_data)) query = "SELECT seqrelid, format_type(seqtypid, NULL), " "seqstart, seqincrement, " "seqmax, seqmin, " @@ -19227,15 +19226,14 @@ dumpSequence(Archive *fout, const TableInfo *tbinfo) qseqname = pg_strdup(fmtId(tbinfo->dobj.name)); /* - * The sequence information is gathered in a sorted - * table before any calls to dumpSequence(). See collectSequences() for - * more information. + * The sequence information is gathered in a sorted table before any calls + * to dumpSequence(). See collectSequences() for more information. */ - Assert(sequences); + Assert(sequences); - key.oid = tbinfo->dobj.catId.oid; - seq = bsearch(&key, sequences, nsequences, - sizeof(SequenceItem), SequenceItemCmp); + key.oid = tbinfo->dobj.catId.oid; + seq = bsearch(&key, sequences, nsequences, + sizeof(SequenceItem), SequenceItemCmp); /* Calculate default limits for a sequence of this type */ is_ascending = (seq->incby >= 0); diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c index e68937c9934..afcd9a218d8 100644 --- a/src/bin/pg_dump/pg_dumpall.c +++ b/src/bin/pg_dump/pg_dumpall.c @@ -785,11 +785,11 @@ dropRoles(PGconn *conn) int i_rolname; int i; - printfPQExpBuffer(buf, - "SELECT rolname " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 1", role_catalog); + printfPQExpBuffer(buf, + "SELECT rolname " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 1", role_catalog); res = executeQuery(conn, buf->data); @@ -843,16 +843,16 @@ dumpRoles(PGconn *conn) * Notes: rolconfig is dumped later, and pg_authid must be used for * extracting rolcomment regardless of role_catalog. */ - printfPQExpBuffer(buf, - "SELECT oid, rolname, rolsuper, rolinherit, " - "rolcreaterole, rolcreatedb, " - "rolcanlogin, rolconnlimit, rolpassword, " - "rolvaliduntil, rolreplication, rolbypassrls, " - "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " - "rolname = current_user AS is_current_user " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 2", role_catalog); + printfPQExpBuffer(buf, + "SELECT oid, rolname, rolsuper, rolinherit, " + "rolcreaterole, rolcreatedb, " + "rolcanlogin, rolconnlimit, rolpassword, " + "rolvaliduntil, rolreplication, rolbypassrls, " + "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " + "rolname = current_user AS is_current_user " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 2", role_catalog); res = executeQuery(conn, buf->data); diff --git a/src/bin/pg_upgrade/check.c b/src/bin/pg_upgrade/check.c index 786c1474829..f725f5ee3e2 100644 --- a/src/bin/pg_upgrade/check.c +++ b/src/bin/pg_upgrade/check.c @@ -1475,15 +1475,15 @@ check_for_incompatible_polymorphics(ClusterInfo *cluster) ", 'array_cat(anyarray,anyarray)'" ", 'array_prepend(anyelement,anyarray)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_remove(anyarray,anyelement)'" - ", 'array_replace(anyarray,anyelement,anyelement)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_remove(anyarray,anyelement)'" + ", 'array_replace(anyarray,anyelement,anyelement)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_position(anyarray,anyelement)'" - ", 'array_position(anyarray,anyelement,integer)'" - ", 'array_positions(anyarray,anyelement)'" - ", 'width_bucket(anyelement,anyarray)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_position(anyarray,anyelement)'" + ", 'array_position(anyarray,anyelement,integer)'" + ", 'array_positions(anyarray,anyelement)'" + ", 'width_bucket(anyelement,anyarray)'"); /* * The query below hardcodes FirstNormalObjectId as 16384 rather than diff --git a/src/bin/pg_upgrade/controldata.c b/src/bin/pg_upgrade/controldata.c index 8f81c9e9582..02ea02df60f 100644 --- a/src/bin/pg_upgrade/controldata.c +++ b/src/bin/pg_upgrade/controldata.c @@ -228,7 +228,7 @@ get_control_data(ClusterInfo *cluster) p++; /* remove ':' char */ cluster->controldata.chkpnt_nxtepoch = str2uint(p); - p = strchr(p, ':'); + p = strchr(p, ':'); if (p == NULL || strlen(p) <= 1) pg_fatal("%d: controldata retrieval problem", __LINE__); diff --git a/src/bin/pg_upgrade/exec.c b/src/bin/pg_upgrade/exec.c index 44355feea30..a1bdbf373e3 100644 --- a/src/bin/pg_upgrade/exec.c +++ b/src/bin/pg_upgrade/exec.c @@ -55,7 +55,7 @@ get_bin_version(ClusterInfo *cluster) if (sscanf(cmd_output, "%*s %*s %d.%d", &v1, &v2) < 1) pg_fatal("could not get pg_ctl version output from %s", cmd); - cluster->bin_version = v1 * 10000; + cluster->bin_version = v1 * 10000; } @@ -344,8 +344,8 @@ check_data_dir(ClusterInfo *cluster) check_single_dir(pg_data, "pg_subtrans"); check_single_dir(pg_data, PG_TBLSPC_DIR); check_single_dir(pg_data, "pg_twophase"); - check_single_dir(pg_data, "pg_wal"); - check_single_dir(pg_data, "pg_xact"); + check_single_dir(pg_data, "pg_wal"); + check_single_dir(pg_data, "pg_xact"); } @@ -385,7 +385,7 @@ check_bin_dir(ClusterInfo *cluster, bool check_versions) */ get_bin_version(cluster); - check_exec(cluster->bindir, "pg_resetwal", check_versions); + check_exec(cluster->bindir, "pg_resetwal", check_versions); if (cluster == &new_cluster) { diff --git a/src/bin/pg_upgrade/multixact_rewrite.c b/src/bin/pg_upgrade/multixact_rewrite.c index c45b3183684..c7a1416494d 100644 --- a/src/bin/pg_upgrade/multixact_rewrite.c +++ b/src/bin/pg_upgrade/multixact_rewrite.c @@ -61,52 +61,52 @@ rewrite_multixacts(MultiXactId from_multi, MultiXactId to_multi) * Convert old multixids, if needed, by reading them one-by-one from the * old cluster. */ - old_reader = AllocOldMultiXactRead(old_cluster.pgdata, - old_cluster.controldata.chkpnt_nxtmulti, - old_cluster.controldata.chkpnt_nxtmxoff); + old_reader = AllocOldMultiXactRead(old_cluster.pgdata, + old_cluster.controldata.chkpnt_nxtmulti, + old_cluster.controldata.chkpnt_nxtmxoff); - for (MultiXactId multi = from_multi; multi != to_multi;) - { - MultiXactMember member; - bool multixid_valid; - - /* - * Read this multixid's members. - * - * Locking-only XIDs that may be part of multi-xids don't matter - * after upgrade, as there can be no transactions running across - * upgrade. So as a small optimization, we only read one member - * from each multixid: the one updating one, or if there was no - * update, arbitrarily the first locking xid. - */ - multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); + for (MultiXactId multi = from_multi; multi != to_multi;) + { + MultiXactMember member; + bool multixid_valid; - /* - * Write the new offset to pg_multixact/offsets. - * - * Even if this multixid is invalid, we still need to write its - * offset if the *previous* multixid was valid. That's because - * when reading a multixid, the number of members is calculated - * from the difference between the two offsets. - */ - RecordMultiXactOffset(offsets_writer, multi, - (multixid_valid || prev_multixid_valid) ? next_offset : 0); + /* + * Read this multixid's members. + * + * Locking-only XIDs that may be part of multi-xids don't matter after + * upgrade, as there can be no transactions running across upgrade. So + * as a small optimization, we only read one member from each + * multixid: the one updating one, or if there was no update, + * arbitrarily the first locking xid. + */ + multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); - /* Write the members */ - if (multixid_valid) - { - RecordMultiXactMembers(members_writer, next_offset, 1, &member); - next_offset += 1; - } + /* + * Write the new offset to pg_multixact/offsets. + * + * Even if this multixid is invalid, we still need to write its offset + * if the *previous* multixid was valid. That's because when reading + * a multixid, the number of members is calculated from the difference + * between the two offsets. + */ + RecordMultiXactOffset(offsets_writer, multi, + (multixid_valid || prev_multixid_valid) ? next_offset : 0); - /* Advance to next multixid, handling wraparound */ - multi++; - if (multi < FirstMultiXactId) - multi = FirstMultiXactId; - prev_multixid_valid = multixid_valid; + /* Write the members */ + if (multixid_valid) + { + RecordMultiXactMembers(members_writer, next_offset, 1, &member); + next_offset += 1; } - FreeOldMultiXactReader(old_reader); + /* Advance to next multixid, handling wraparound */ + multi++; + if (multi < FirstMultiXactId) + multi = FirstMultiXactId; + prev_multixid_valid = multixid_valid; + } + + FreeOldMultiXactReader(old_reader); /* Write the final 'next' offset to the last SLRU page */ RecordMultiXactOffset(offsets_writer, to_multi, diff --git a/src/bin/pg_upgrade/pg_upgrade.c b/src/bin/pg_upgrade/pg_upgrade.c index c6af9035665..7366fd4627c 100644 --- a/src/bin/pg_upgrade/pg_upgrade.c +++ b/src/bin/pg_upgrade/pg_upgrade.c @@ -833,7 +833,7 @@ copy_xact_xlog_xid(void) * Determine the range of multixacts to convert. */ nxtmulti = old_cluster.controldata.chkpnt_nxtmulti; - oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; + oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; /* handle wraparound */ if (nxtmulti < FirstMultiXactId) nxtmulti = FirstMultiXactId; @@ -898,15 +898,15 @@ set_frozenxids(void) int i_datname; int i_datallowconn; - prep_status("Setting frozenxid and minmxid counters in new cluster"); + prep_status("Setting frozenxid and minmxid counters in new cluster"); conn_template1 = connectToServer(&new_cluster, "template1"); - /* set pg_database.datfrozenxid */ - PQclear(executeQueryOrDie(conn_template1, - "UPDATE pg_catalog.pg_database " - "SET datfrozenxid = '%u'", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_database.datfrozenxid */ + PQclear(executeQueryOrDie(conn_template1, + "UPDATE pg_catalog.pg_database " + "SET datfrozenxid = '%u'", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_database.datminmxid */ PQclear(executeQueryOrDie(conn_template1, @@ -942,16 +942,16 @@ set_frozenxids(void) conn = connectToServer(&new_cluster, datname); - /* set pg_class.relfrozenxid */ - PQclear(executeQueryOrDie(conn, - "UPDATE pg_catalog.pg_class " - "SET relfrozenxid = '%u' " - /* only heap, materialized view, and TOAST are vacuumed */ - "WHERE relkind IN (" - CppAsString2(RELKIND_RELATION) ", " - CppAsString2(RELKIND_MATVIEW) ", " - CppAsString2(RELKIND_TOASTVALUE) ")", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_class.relfrozenxid */ + PQclear(executeQueryOrDie(conn, + "UPDATE pg_catalog.pg_class " + "SET relfrozenxid = '%u' " + /* only heap, materialized view, and TOAST are vacuumed */ + "WHERE relkind IN (" + CppAsString2(RELKIND_RELATION) ", " + CppAsString2(RELKIND_MATVIEW) ", " + CppAsString2(RELKIND_TOASTVALUE) ")", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_class.relminmxid */ PQclear(executeQueryOrDie(conn, diff --git a/src/bin/pg_upgrade/relfilenumber.c b/src/bin/pg_upgrade/relfilenumber.c index ec2ff7acb21..6c467bdc8a5 100644 --- a/src/bin/pg_upgrade/relfilenumber.c +++ b/src/bin/pg_upgrade/relfilenumber.c @@ -587,32 +587,32 @@ transfer_relfile(FileNameMap *map, const char *type_suffix) /* Copying files might take some time, so give feedback. */ pg_log(PG_STATUS, "%s", old_file); - switch (user_opts.transfer_mode) - { - case TRANSFER_MODE_CLONE: - pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", - old_file, new_file); - cloneFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", - old_file, new_file); - copyFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY_FILE_RANGE: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", - old_file, new_file); - copyFileByRange(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_LINK: - pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", - old_file, new_file); - linkFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_SWAP: - /* swap mode is handled in its own code path */ - pg_fatal("should never happen"); - break; - } + switch (user_opts.transfer_mode) + { + case TRANSFER_MODE_CLONE: + pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", + old_file, new_file); + cloneFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", + old_file, new_file); + copyFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY_FILE_RANGE: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", + old_file, new_file); + copyFileByRange(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_LINK: + pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", + old_file, new_file); + linkFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_SWAP: + /* swap mode is handled in its own code path */ + pg_fatal("should never happen"); + break; + } } } diff --git a/src/bin/pg_upgrade/t/006_transfer_modes.pl b/src/bin/pg_upgrade/t/006_transfer_modes.pl index 9efa5dc863c..360d05c4b68 100644 --- a/src/bin/pg_upgrade/t/006_transfer_modes.pl +++ b/src/bin/pg_upgrade/t/006_transfer_modes.pl @@ -29,10 +29,8 @@ sub test_mode } $new->init(); - $new->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); - $old->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); + $new->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); + $old->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); # We can only test security labels if both the old and new installations # have dummy_seclabel. @@ -76,15 +74,14 @@ sub test_mode "CREATE TABLE test4 AS SELECT generate_series(400, 502)"); } - $old->safe_psql('postgres', - "CREATE TABLESPACE inplc_tblspc LOCATION ''"); - $old->safe_psql('postgres', - "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); - $old->safe_psql('postgres', - "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" - ); - $old->safe_psql('testdb3', - "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); + $old->safe_psql('postgres', "CREATE TABLESPACE inplc_tblspc LOCATION ''"); + $old->safe_psql('postgres', + "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); + $old->safe_psql('postgres', + "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" + ); + $old->safe_psql('testdb3', + "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); # While we are here, test handling of large objects. $old->safe_psql( @@ -152,12 +149,10 @@ sub test_mode } # Tests for in-place tablespaces. - $result = - $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); - is($result, '104', "test5 data after pg_upgrade $mode"); - $result = - $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); - is($result, '105', "test6 data after pg_upgrade $mode"); + $result = $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); + is($result, '104', "test5 data after pg_upgrade $mode"); + $result = $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); + is($result, '105', "test6 data after pg_upgrade $mode"); # Tests for large objects $result = $new->safe_psql('postgres', "SELECT lo_get(4532)"); diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index 44ef11d980e..c90bf8bbde2 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -6278,23 +6278,22 @@ get_create_object_cmd(EditableObjectType obj_type, Oid oid, * ensure the right view gets replaced. Also, check relation kind * to be sure it's a view. * - * Views may have WITH [LOCAL|CASCADED] - * CHECK OPTION. These are not part of the view definition - * returned by pg_get_viewdef() and so need to be retrieved - * separately. Materialized views may have - * arbitrary storage parameter reloptions. + * Views may have WITH [LOCAL|CASCADED] CHECK OPTION. These are + * not part of the view definition returned by pg_get_viewdef() + * and so need to be retrieved separately. Materialized views may + * have arbitrary storage parameter reloptions. */ printfPQExpBuffer(query, "/* %s */\n", _("Get view's definition and details")); - appendPQExpBuffer(query, - "SELECT nspname, relname, relkind, " - "pg_catalog.pg_get_viewdef(c.oid, true), " - "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " - "FROM pg_catalog.pg_class c " - "LEFT JOIN pg_catalog.pg_namespace n " - "ON c.relnamespace = n.oid WHERE c.oid = %u", - oid); + appendPQExpBuffer(query, + "SELECT nspname, relname, relkind, " + "pg_catalog.pg_get_viewdef(c.oid, true), " + "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " + "FROM pg_catalog.pg_class c " + "LEFT JOIN pg_catalog.pg_namespace n " + "ON c.relnamespace = n.oid WHERE c.oid = %u", + oid); break; } diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index ce99137c613..ac0c55e7aa5 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -387,19 +387,19 @@ describeFunctions(const char *functypes, const char *func_pattern, gettext_noop("stable"), gettext_noop("volatile"), gettext_noop("Volatility")); - appendPQExpBuffer(&buf, - ",\n CASE\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" - " END as \"%s\"", - gettext_noop("restricted"), - gettext_noop("safe"), - gettext_noop("unsafe"), - gettext_noop("Parallel")); + appendPQExpBuffer(&buf, + ",\n CASE\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" + " END as \"%s\"", + gettext_noop("restricted"), + gettext_noop("safe"), + gettext_noop("unsafe"), + gettext_noop("Parallel")); appendPQExpBuffer(&buf, ",\n pg_catalog.pg_get_userbyid(p.proowner) as \"%s\"" ",\n CASE WHEN prosecdef THEN '%s' ELSE '%s' END AS \"%s\"" @@ -599,8 +599,8 @@ describeFunctions(const char *functypes, const char *func_pattern, myopt.title = _("List of functions"); myopt.translate_header = true; - myopt.translate_columns = translate_columns; - myopt.n_translate_columns = lengthof(translate_columns); + myopt.translate_columns = translate_columns; + myopt.n_translate_columns = lengthof(translate_columns); printQuery(res, &myopt, pset.queryFout, false, pset.logfile); @@ -1086,38 +1086,38 @@ permissionsList(const char *pattern, bool showSystem) " ), E'\\n') AS \"%s\"", gettext_noop("Column privileges")); - appendPQExpBuffer(&buf, - ",\n pg_catalog.array_to_string(ARRAY(\n" - " SELECT polname\n" - " || CASE WHEN NOT polpermissive THEN\n" - " E' (RESTRICTIVE)'\n" - " ELSE '' END\n" - " || CASE WHEN polcmd != '*' THEN\n" - " E' (' || polcmd::pg_catalog.text || E'):'\n" - " ELSE E':'\n" - " END\n" - " || CASE WHEN polqual IS NOT NULL THEN\n" - " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" - " ELSE E''\n" - " END\n" - " || CASE WHEN polwithcheck IS NOT NULL THEN\n" - " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" - " ELSE E''\n" - " END" - " || CASE WHEN polroles <> '{0}' THEN\n" - " E'\\n to: ' || pg_catalog.array_to_string(\n" - " ARRAY(\n" - " SELECT rolname\n" - " FROM pg_catalog.pg_roles\n" - " WHERE oid = ANY (polroles)\n" - " ORDER BY 1\n" - " ), E', ')\n" - " ELSE E''\n" - " END\n" - " FROM pg_catalog.pg_policy pol\n" - " WHERE polrelid = c.oid), E'\\n')\n" - " AS \"%s\"", - gettext_noop("Policies")); + appendPQExpBuffer(&buf, + ",\n pg_catalog.array_to_string(ARRAY(\n" + " SELECT polname\n" + " || CASE WHEN NOT polpermissive THEN\n" + " E' (RESTRICTIVE)'\n" + " ELSE '' END\n" + " || CASE WHEN polcmd != '*' THEN\n" + " E' (' || polcmd::pg_catalog.text || E'):'\n" + " ELSE E':'\n" + " END\n" + " || CASE WHEN polqual IS NOT NULL THEN\n" + " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" + " ELSE E''\n" + " END\n" + " || CASE WHEN polwithcheck IS NOT NULL THEN\n" + " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" + " ELSE E''\n" + " END" + " || CASE WHEN polroles <> '{0}' THEN\n" + " E'\\n to: ' || pg_catalog.array_to_string(\n" + " ARRAY(\n" + " SELECT rolname\n" + " FROM pg_catalog.pg_roles\n" + " WHERE oid = ANY (polroles)\n" + " ORDER BY 1\n" + " ), E', ')\n" + " ELSE E''\n" + " END\n" + " FROM pg_catalog.pg_policy pol\n" + " WHERE polrelid = c.oid), E'\\n')\n" + " AS \"%s\"", + gettext_noop("Policies")); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_class c\n" " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n" @@ -1675,27 +1675,27 @@ describeOneTableDetails(const char *schemaname, char *footers[3] = {NULL, NULL, NULL}; printfPQExpBuffer(&buf, "/* %s */\n", _("Get sequence information")); - appendPQExpBuffer(&buf, - "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" - " seqstart AS \"%s\",\n" - " seqmin AS \"%s\",\n" - " seqmax AS \"%s\",\n" - " seqincrement AS \"%s\",\n" - " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" - " seqcache AS \"%s\"\n", - gettext_noop("Type"), - gettext_noop("Start"), - gettext_noop("Minimum"), - gettext_noop("Maximum"), - gettext_noop("Increment"), - gettext_noop("yes"), - gettext_noop("no"), - gettext_noop("Cycles?"), - gettext_noop("Cache")); - appendPQExpBuffer(&buf, - "FROM pg_catalog.pg_sequence\n" - "WHERE seqrelid = '%s';", - oid); + appendPQExpBuffer(&buf, + "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" + " seqstart AS \"%s\",\n" + " seqmin AS \"%s\",\n" + " seqmax AS \"%s\",\n" + " seqincrement AS \"%s\",\n" + " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" + " seqcache AS \"%s\"\n", + gettext_noop("Type"), + gettext_noop("Start"), + gettext_noop("Minimum"), + gettext_noop("Maximum"), + gettext_noop("Increment"), + gettext_noop("yes"), + gettext_noop("no"), + gettext_noop("Cycles?"), + gettext_noop("Cache")); + appendPQExpBuffer(&buf, + "FROM pg_catalog.pg_sequence\n" + "WHERE seqrelid = '%s';", + oid); res = PSQLexec(buf.data); if (!res) @@ -1913,7 +1913,7 @@ describeOneTableDetails(const char *schemaname, appendPQExpBufferStr(&buf, ",\n (SELECT c.collname FROM pg_catalog.pg_collation c, pg_catalog.pg_type t\n" " WHERE c.oid = a.attcollation AND t.oid = a.atttypid AND a.attcollation <> t.typcollation) AS attcollation"); attcoll_col = cols++; - appendPQExpBufferStr(&buf, ",\n a.attidentity"); + appendPQExpBufferStr(&buf, ",\n a.attidentity"); attidentity_col = cols++; if (pset.sversion >= 120000) appendPQExpBufferStr(&buf, ",\n a.attgenerated"); @@ -2326,7 +2326,7 @@ describeOneTableDetails(const char *schemaname, CppAsString2(CONSTRAINT_EXCLUSION) ") AND " "condeferred) AS condeferred,\n"); - appendPQExpBufferStr(&buf, "i.indisreplident,\n"); + appendPQExpBufferStr(&buf, "i.indisreplident,\n"); if (pset.sversion >= 150000) appendPQExpBufferStr(&buf, "i.indnullsnotdistinct,\n"); @@ -2431,7 +2431,7 @@ describeOneTableDetails(const char *schemaname, "pg_catalog.pg_get_indexdef(i.indexrelid, 0, true),\n " "pg_catalog.pg_get_constraintdef(con.oid, true), " "contype, condeferrable, condeferred"); - appendPQExpBufferStr(&buf, ", i.indisreplident"); + appendPQExpBufferStr(&buf, ", i.indisreplident"); appendPQExpBufferStr(&buf, ", c2.reltablespace"); if (pset.sversion >= 180000) appendPQExpBufferStr(&buf, ", con.conperiod"); @@ -2682,81 +2682,80 @@ describeOneTableDetails(const char *schemaname, PQclear(result); /* print any row-level policies */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get row-level policies for this table")); - appendPQExpBufferStr(&buf, "SELECT pol.polname,"); - appendPQExpBufferStr(&buf, - " pol.polpermissive,\n"); - appendPQExpBuffer(&buf, - " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" - " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" - " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" - " CASE pol.polcmd\n" - " WHEN 'r' THEN 'SELECT'\n" - " WHEN 'a' THEN 'INSERT'\n" - " WHEN 'w' THEN 'UPDATE'\n" - " WHEN 'd' THEN 'DELETE'\n" - " END AS cmd\n" - "FROM pg_catalog.pg_policy pol\n" - "WHERE pol.polrelid = '%s' ORDER BY 1;", - oid); + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get row-level policies for this table")); + appendPQExpBufferStr(&buf, "SELECT pol.polname,"); + appendPQExpBufferStr(&buf, + " pol.polpermissive,\n"); + appendPQExpBuffer(&buf, + " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" + " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" + " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" + " CASE pol.polcmd\n" + " WHEN 'r' THEN 'SELECT'\n" + " WHEN 'a' THEN 'INSERT'\n" + " WHEN 'w' THEN 'UPDATE'\n" + " WHEN 'd' THEN 'DELETE'\n" + " END AS cmd\n" + "FROM pg_catalog.pg_policy pol\n" + "WHERE pol.polrelid = '%s' ORDER BY 1;", + oid); - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - /* - * Handle cases where RLS is enabled and there are policies, or - * there aren't policies, or RLS isn't enabled but there are - * policies - */ - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies:")); + /* + * Handle cases where RLS is enabled and there are policies, or there + * aren't policies, or RLS isn't enabled but there are policies + */ + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies:")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled):")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled):")); - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); - if (!tableinfo.rowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (row security disabled):")); + if (!tableinfo.rowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (row security disabled):")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " POLICY \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " POLICY \"%s\"", + PQgetvalue(result, i, 0)); - if (*(PQgetvalue(result, i, 1)) == 'f') - appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); + if (*(PQgetvalue(result, i, 1)) == 'f') + appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); - if (!PQgetisnull(result, i, 5)) - appendPQExpBuffer(&buf, " FOR %s", - PQgetvalue(result, i, 5)); + if (!PQgetisnull(result, i, 5)) + appendPQExpBuffer(&buf, " FOR %s", + PQgetvalue(result, i, 5)); - if (!PQgetisnull(result, i, 2)) - { - appendPQExpBuffer(&buf, "\n TO %s", - PQgetvalue(result, i, 2)); - } + if (!PQgetisnull(result, i, 2)) + { + appendPQExpBuffer(&buf, "\n TO %s", + PQgetvalue(result, i, 2)); + } - if (!PQgetisnull(result, i, 3)) - appendPQExpBuffer(&buf, "\n USING (%s)", - PQgetvalue(result, i, 3)); + if (!PQgetisnull(result, i, 3)) + appendPQExpBuffer(&buf, "\n USING (%s)", + PQgetvalue(result, i, 3)); - if (!PQgetisnull(result, i, 4)) - appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", - PQgetvalue(result, i, 4)); + if (!PQgetisnull(result, i, 4)) + appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", + PQgetvalue(result, i, 4)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* print any extended statistics */ if (pset.sversion >= 140000) @@ -3025,115 +3024,115 @@ describeOneTableDetails(const char *schemaname, } /* print any publications */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get publications that publish this table")); - if (pset.sversion >= 150000) + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get publications that publish this table")); + if (pset.sversion >= 150000) + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" + " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" + "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" + "UNION\n" + "SELECT pubname\n" + " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" + " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" + " (SELECT pg_catalog.string_agg(attname, ', ')\n" + " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" + " pg_catalog.pg_attribute\n" + " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" + " ELSE NULL END) " + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" + "WHERE pr.prrelid = '%s'\n", + oid, oid, oid); + + if (pset.sversion >= 190000) { + /* + * Skip entries where this relation appears in the + * publication's EXCEPT list. + */ appendPQExpBuffer(&buf, + " AND NOT pr.prexcept\n" + "UNION\n" "SELECT pubname\n" " , NULL\n" " , NULL\n" "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" - " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" - "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" - "UNION\n" - "SELECT pubname\n" - " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" - " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" - " (SELECT pg_catalog.string_agg(attname, ', ')\n" - " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" - " pg_catalog.pg_attribute\n" - " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" - " ELSE NULL END) " - "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" - "WHERE pr.prrelid = '%s'\n", + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + " AND NOT EXISTS (\n" + " SELECT 1\n" + " FROM pg_catalog.pg_publication_rel pr\n" + " WHERE pr.prpubid = p.oid AND\n" + " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" + "ORDER BY 1;", oid, oid, oid); - - if (pset.sversion >= 190000) - { - /* - * Skip entries where this relation appears in the - * publication's EXCEPT list. - */ - appendPQExpBuffer(&buf, - " AND NOT pr.prexcept\n" - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - " AND NOT EXISTS (\n" - " SELECT 1\n" - " FROM pg_catalog.pg_publication_rel pr\n" - " WHERE pr.prpubid = p.oid AND\n" - " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" - "ORDER BY 1;", - oid, oid, oid); - } - else - { - appendPQExpBuffer(&buf, - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - "ORDER BY 1;", - oid); - } } else { appendPQExpBuffer(&buf, + "UNION\n" "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - "WHERE pr.prrelid = '%s'\n" - "UNION ALL\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" + " , NULL\n" + " , NULL\n" "FROM pg_catalog.pg_publication p\n" "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" "ORDER BY 1;", - oid, oid); + oid); } + } + else + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + "WHERE pr.prrelid = '%s'\n" + "UNION ALL\n" + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + "ORDER BY 1;", + oid, oid); + } - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - if (tuples > 0) - printTableAddFooter(&cont, _("Included in publications:")); + if (tuples > 0) + printTableAddFooter(&cont, _("Included in publications:")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " \"%s\"", + PQgetvalue(result, i, 0)); - /* column list (if any) */ - if (!PQgetisnull(result, i, 2)) - appendPQExpBuffer(&buf, " (%s)", - PQgetvalue(result, i, 2)); + /* column list (if any) */ + if (!PQgetisnull(result, i, 2)) + appendPQExpBuffer(&buf, " (%s)", + PQgetvalue(result, i, 2)); - /* row filter (if any) */ - if (!PQgetisnull(result, i, 1)) - appendPQExpBuffer(&buf, " WHERE %s", - PQgetvalue(result, i, 1)); + /* row filter (if any) */ + if (!PQgetisnull(result, i, 1)) + appendPQExpBuffer(&buf, " WHERE %s", + PQgetvalue(result, i, 1)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* Print publications where the table is in the EXCEPT clause */ if (pset.sversion >= 190000) @@ -3805,7 +3804,7 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) ncols++; } appendPQExpBufferStr(&buf, "\n, r.rolreplication"); - appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); + appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_roles r\n"); @@ -3860,8 +3859,8 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) if (strcmp(PQgetvalue(res, i, (verbose ? 9 : 8)), "t") == 0) add_role_attribute(&buf, _("Replication")); - if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) - add_role_attribute(&buf, _("Bypass RLS")); + if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) + add_role_attribute(&buf, _("Bypass RLS")); conns = atoi(PQgetvalue(res, i, 6)); if (conns >= 0) @@ -5155,14 +5154,14 @@ listCollations(const char *pattern, bool verbose, bool showSystem) gettext_noop("Schema"), gettext_noop("Name")); - appendPQExpBuffer(&buf, - " CASE c.collprovider " - "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " - "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " - "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " - "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " - "END AS \"%s\",\n", - gettext_noop("Provider")); + appendPQExpBuffer(&buf, + " CASE c.collprovider " + "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " + "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " + "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " + "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " + "END AS \"%s\",\n", + gettext_noop("Provider")); appendPQExpBuffer(&buf, " c.collcollate AS \"%s\",\n" -- 2.50.1 (Apple Git-155) --aHl3HfeiUuO3zeNC-- ^ permalink raw reply [nested|flat] 59+ messages in thread
* [PATCH v6 4/4] run pgindent and pgperltidy @ 2026-06-30 18:24 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 59+ messages in thread From: Nathan Bossart @ 2026-06-30 18:24 UTC (permalink / raw) --- src/bin/pg_dump/pg_dump.c | 464 ++++++++++----------- src/bin/pg_dump/pg_dumpall.c | 30 +- src/bin/pg_upgrade/check.c | 16 +- src/bin/pg_upgrade/controldata.c | 2 +- src/bin/pg_upgrade/exec.c | 8 +- src/bin/pg_upgrade/multixact_rewrite.c | 80 ++-- src/bin/pg_upgrade/pg_upgrade.c | 34 +- src/bin/pg_upgrade/relfilenumber.c | 54 +-- src/bin/pg_upgrade/t/006_transfer_modes.pl | 33 +- src/bin/psql/command.c | 29 +- src/bin/psql/describe.c | 461 ++++++++++---------- 11 files changed, 601 insertions(+), 610 deletions(-) diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 65bd15ebfd2..5673268b467 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -1491,8 +1491,8 @@ setup_connection(Archive *AH, const char *dumpencoding, * Disable timeouts if supported. */ ExecuteSqlStatement(AH, "SET statement_timeout = 0"); - ExecuteSqlStatement(AH, "SET lock_timeout = 0"); - ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); + ExecuteSqlStatement(AH, "SET lock_timeout = 0"); + ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); if (AH->remoteVersion >= 170000) ExecuteSqlStatement(AH, "SET transaction_timeout = 0"); @@ -1505,10 +1505,10 @@ setup_connection(Archive *AH, const char *dumpencoding, /* * Adjust row-security mode, if supported. */ - if (dopt->enable_row_security) - ExecuteSqlStatement(AH, "SET row_security = on"); - else - ExecuteSqlStatement(AH, "SET row_security = off"); + if (dopt->enable_row_security) + ExecuteSqlStatement(AH, "SET row_security = on"); + else + ExecuteSqlStatement(AH, "SET row_security = off"); /* * For security reasons, we restrict the expansion of non-system views and @@ -1933,10 +1933,9 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) addObjectDependency(dobj, ext->dobj.dumpId); /* - * Mark the member object to have any non-initial ACLs - * dumped. (Any initial ACLs will be removed later, using data from - * pg_init_privs, so that we'll dump only the delta from the extension's - * initial setup.) + * Mark the member object to have any non-initial ACLs dumped. (Any + * initial ACLs will be removed later, using data from pg_init_privs, so + * that we'll dump only the delta from the extension's initial setup.) * * In binary upgrades, we still dump all components of the members * individually, since the idea is to exactly reproduce the database @@ -1953,7 +1952,7 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) if (fout->dopt->binary_upgrade) dobj->dump = ext->dobj.dump; else - dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); + dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); return true; } @@ -1987,9 +1986,9 @@ selectDumpableNamespace(NamespaceInfo *nsinfo, Archive *fout) else if (strcmp(nsinfo->dobj.name, "pg_catalog") == 0) { /* - * We dump out any ACLs defined in pg_catalog, if - * they are interesting (and not the original ACLs which were set at - * initdb time, see pg_init_privs). + * We dump out any ACLs defined in pg_catalog, if they are interesting + * (and not the original ACLs which were set at initdb time, see + * pg_init_privs). */ nsinfo->dobj.dump_contains = nsinfo->dobj.dump = DUMP_COMPONENT_ACL; } @@ -3296,7 +3295,7 @@ dumpDatabase(Archive *fout) "datcollate, datctype, datfrozenxid, " "datacl, acldefault('d', datdba) AS acldefault, " "datistemplate, datconnlimit, "); - appendPQExpBufferStr(dbQry, "datminmxid, "); + appendPQExpBufferStr(dbQry, "datminmxid, "); if (fout->remoteVersion >= 170000) appendPQExpBufferStr(dbQry, "datlocprovider, datlocale, datcollversion, "); else if (fout->remoteVersion >= 150000) @@ -3638,11 +3637,11 @@ dumpDatabase(Archive *fout) ii_oid, ii_relminmxid; - appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" - "FROM pg_catalog.pg_class\n" - "WHERE oid IN (%u, %u, %u, %u);\n", - LargeObjectRelationId, LargeObjectLOidPNIndexId, - LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); + appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" + "FROM pg_catalog.pg_class\n" + "WHERE oid IN (%u, %u, %u, %u);\n", + LargeObjectRelationId, LargeObjectLOidPNIndexId, + LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); lo_res = ExecuteSqlQuery(fout, loFrozenQry->data, PGRES_TUPLES_OK); @@ -4274,7 +4273,7 @@ getPolicies(Archive *fout, TableInfo tblinfo[], int numTables) printfPQExpBuffer(query, "SELECT pol.oid, pol.tableoid, pol.polrelid, pol.polname, pol.polcmd, "); - appendPQExpBufferStr(query, "pol.polpermissive, "); + appendPQExpBufferStr(query, "pol.polpermissive, "); appendPQExpBuffer(query, "CASE WHEN pol.polroles = '{0}' THEN NULL ELSE " " pg_catalog.array_to_string(ARRAY(SELECT pg_catalog.quote_ident(rolname) from pg_catalog.pg_roles WHERE oid = ANY(pol.polroles)), ', ') END AS polroles, " @@ -6633,9 +6632,9 @@ getAccessMethods(Archive *fout) * Select all access methods from pg_am table. */ appendPQExpBufferStr(query, "SELECT tableoid, oid, amname, "); - appendPQExpBufferStr(query, - "amtype, " - "amhandler::pg_catalog.regproc AS amhandler "); + appendPQExpBufferStr(query, + "amtype, " + "amhandler::pg_catalog.regproc AS amhandler "); appendPQExpBufferStr(query, "FROM pg_am"); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6827,35 +6826,35 @@ getAggregates(Archive *fout) * Find all interesting aggregates. See comment in getFuncs() for the * rationale behind the filtering logic. */ - agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" - : "p.proisagg"); + agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" + : "p.proisagg"); - appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " - "p.proname AS aggname, " - "p.pronamespace AS aggnamespace, " - "p.pronargs, p.proargtypes, " - "p.proowner, " - "p.proacl AS aggacl, " - "acldefault('f', p.proowner) AS acldefault " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s AND (" - "p.pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog') OR " - "p.proacl IS DISTINCT FROM pip.initprivs", - agg_check); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - " OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); - appendPQExpBufferChar(query, ')'); + appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " + "p.proname AS aggname, " + "p.pronamespace AS aggnamespace, " + "p.pronargs, p.proargtypes, " + "p.proowner, " + "p.proacl AS aggacl, " + "acldefault('f', p.proowner) AS acldefault " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s AND (" + "p.pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog') OR " + "p.proacl IS DISTINCT FROM pip.initprivs", + agg_check); + if (dopt->binary_upgrade) + appendPQExpBufferStr(query, + " OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6957,53 +6956,53 @@ getFuncs(Archive *fout) * include them, since we want to dump extension members individually in * that mode. Also, if they are used by casts or transforms then we need * to gather the information about them, though they won't be dumped if - * they are built-in. Also, include functions in - * pg_catalog if they have an ACL different from what's shown in - * pg_init_privs (so we have to join to pg_init_privs; annoying). + * they are built-in. Also, include functions in pg_catalog if they have + * an ACL different from what's shown in pg_init_privs (so we have to join + * to pg_init_privs; annoying). */ - not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" - : "NOT p.proisagg"); + not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" + : "NOT p.proisagg"); - appendPQExpBuffer(query, - "SELECT p.tableoid, p.oid, p.proname, p.prolang, " - "p.pronargs, p.proargtypes, p.prorettype, " - "p.proacl, " - "acldefault('f', p.proowner) AS acldefault, " - "p.pronamespace, " - "p.proowner " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s" - "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " - "WHERE classid = 'pg_proc'::regclass AND " - "objid = p.oid AND deptype = 'i')" - "\n AND (" - "\n pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog')" - "\n OR EXISTS (SELECT 1 FROM pg_cast" - "\n WHERE pg_cast.oid > %u " - "\n AND p.oid = pg_cast.castfunc)" - "\n OR EXISTS (SELECT 1 FROM pg_transform" - "\n WHERE pg_transform.oid > %u AND " - "\n (p.oid = pg_transform.trffromsql" - "\n OR p.oid = pg_transform.trftosql))", - not_agg_check, - g_last_builtin_oid, - g_last_builtin_oid); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); + appendPQExpBuffer(query, + "SELECT p.tableoid, p.oid, p.proname, p.prolang, " + "p.pronargs, p.proargtypes, p.prorettype, " + "p.proacl, " + "acldefault('f', p.proowner) AS acldefault, " + "p.pronamespace, " + "p.proowner " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s" + "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " + "WHERE classid = 'pg_proc'::regclass AND " + "objid = p.oid AND deptype = 'i')" + "\n AND (" + "\n pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog')" + "\n OR EXISTS (SELECT 1 FROM pg_cast" + "\n WHERE pg_cast.oid > %u " + "\n AND p.oid = pg_cast.castfunc)" + "\n OR EXISTS (SELECT 1 FROM pg_transform" + "\n WHERE pg_transform.oid > %u AND " + "\n (p.oid = pg_transform.trffromsql" + "\n OR p.oid = pg_transform.trftosql))", + not_agg_check, + g_last_builtin_oid, + g_last_builtin_oid); + if (dopt->binary_upgrade) appendPQExpBufferStr(query, - "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); - appendPQExpBufferChar(query, ')'); + "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferStr(query, + "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -7252,31 +7251,31 @@ getTables(Archive *fout, int *numTables) appendPQExpBufferStr(query, "c.relhasoids, "); - appendPQExpBufferStr(query, - "c.relispopulated, "); + appendPQExpBufferStr(query, + "c.relispopulated, "); - appendPQExpBufferStr(query, - "c.relreplident, "); + appendPQExpBufferStr(query, + "c.relreplident, "); - appendPQExpBufferStr(query, - "c.relrowsecurity, c.relforcerowsecurity, "); + appendPQExpBufferStr(query, + "c.relrowsecurity, c.relforcerowsecurity, "); - appendPQExpBufferStr(query, - "c.relminmxid, tc.relminmxid AS tminmxid, "); + appendPQExpBufferStr(query, + "c.relminmxid, tc.relminmxid AS tminmxid, "); - appendPQExpBufferStr(query, - "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); + appendPQExpBufferStr(query, + "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); - appendPQExpBufferStr(query, - "am.amname, "); + appendPQExpBufferStr(query, + "am.amname, "); - appendPQExpBufferStr(query, - "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); + appendPQExpBufferStr(query, + "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); - appendPQExpBufferStr(query, - "c.relispartition AS ispartition "); + appendPQExpBufferStr(query, + "c.relispartition AS ispartition "); /* * Left join to pg_depend to pick up dependency info linking sequences to @@ -7296,8 +7295,8 @@ getTables(Archive *fout, int *numTables) /* * Left join to pg_am to pick up the amname. */ - appendPQExpBufferStr(query, - "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); + appendPQExpBufferStr(query, + "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); /* * We purposefully ignore toast OIDs for partitioned tables; the reason is @@ -7868,8 +7867,8 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables) "t.reloptions AS indreloptions, "); - appendPQExpBufferStr(query, - "i.indisreplident, "); + appendPQExpBufferStr(query, + "i.indisreplident, "); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -9313,8 +9312,8 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables) appendPQExpBufferStr(q, "'' AS attcompression,\n"); - appendPQExpBufferStr(q, - "a.attidentity,\n"); + appendPQExpBufferStr(q, + "a.attidentity,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(q, @@ -10717,73 +10716,73 @@ getAdditionalACLs(Archive *fout) PQclear(res); /* Fetch initial-privileges data */ - printfPQExpBuffer(query, - "SELECT objoid, classoid, objsubid, privtype, initprivs " - "FROM pg_init_privs"); + printfPQExpBuffer(query, + "SELECT objoid, classoid, objsubid, privtype, initprivs " + "FROM pg_init_privs"); - res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); + res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); - ntups = PQntuples(res); - for (i = 0; i < ntups; i++) - { - Oid objoid = atooid(PQgetvalue(res, i, 0)); - Oid classoid = atooid(PQgetvalue(res, i, 1)); - int objsubid = atoi(PQgetvalue(res, i, 2)); - char privtype = *(PQgetvalue(res, i, 3)); - char *initprivs = PQgetvalue(res, i, 4); - CatalogId objId; - DumpableObject *dobj; + ntups = PQntuples(res); + for (i = 0; i < ntups; i++) + { + Oid objoid = atooid(PQgetvalue(res, i, 0)); + Oid classoid = atooid(PQgetvalue(res, i, 1)); + int objsubid = atoi(PQgetvalue(res, i, 2)); + char privtype = *(PQgetvalue(res, i, 3)); + char *initprivs = PQgetvalue(res, i, 4); + CatalogId objId; + DumpableObject *dobj; - objId.tableoid = classoid; - objId.oid = objoid; - dobj = findObjectByCatalogId(objId); - /* OK to ignore entries we haven't got a DumpableObject for */ - if (dobj) + objId.tableoid = classoid; + objId.oid = objoid; + dobj = findObjectByCatalogId(objId); + /* OK to ignore entries we haven't got a DumpableObject for */ + if (dobj) + { + /* Cope with sub-object initprivs */ + if (objsubid != 0) { - /* Cope with sub-object initprivs */ - if (objsubid != 0) - { - if (dobj->objType == DO_TABLE) - { - /* For a column initprivs, set the table's ACL flags */ - dobj->components |= DUMP_COMPONENT_ACL; - ((TableInfo *) dobj)->hascolumnACLs = true; - } - else - pg_log_warning("unsupported pg_init_privs entry: %u %u %d", - classoid, objoid, objsubid); - continue; - } - - /* - * We ignore any pg_init_privs.initprivs entry for the public - * schema, as explained in getNamespaces(). - */ - if (dobj->objType == DO_NAMESPACE && - strcmp(dobj->name, "public") == 0) - continue; - - /* Else it had better be of a type we think has ACLs */ - if (dobj->objType == DO_NAMESPACE || - dobj->objType == DO_TYPE || - dobj->objType == DO_FUNC || - dobj->objType == DO_AGG || - dobj->objType == DO_TABLE || - dobj->objType == DO_PROCLANG || - dobj->objType == DO_FDW || - dobj->objType == DO_FOREIGN_SERVER) + if (dobj->objType == DO_TABLE) { - DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; - - daobj->dacl.privtype = privtype; - daobj->dacl.initprivs = pstrdup(initprivs); + /* For a column initprivs, set the table's ACL flags */ + dobj->components |= DUMP_COMPONENT_ACL; + ((TableInfo *) dobj)->hascolumnACLs = true; } else pg_log_warning("unsupported pg_init_privs entry: %u %u %d", classoid, objoid, objsubid); + continue; + } + + /* + * We ignore any pg_init_privs.initprivs entry for the public + * schema, as explained in getNamespaces(). + */ + if (dobj->objType == DO_NAMESPACE && + strcmp(dobj->name, "public") == 0) + continue; + + /* Else it had better be of a type we think has ACLs */ + if (dobj->objType == DO_NAMESPACE || + dobj->objType == DO_TYPE || + dobj->objType == DO_FUNC || + dobj->objType == DO_AGG || + dobj->objType == DO_TABLE || + dobj->objType == DO_PROCLANG || + dobj->objType == DO_FDW || + dobj->objType == DO_FOREIGN_SERVER) + { + DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; + + daobj->dacl.privtype = privtype; + daobj->dacl.initprivs = pstrdup(initprivs); } + else + pg_log_warning("unsupported pg_init_privs entry: %u %u %d", + classoid, objoid, objsubid); } - PQclear(res); + } + PQclear(res); destroyPQExpBuffer(query); } @@ -11128,8 +11127,8 @@ dumpRelationStats_dumper(Archive *fout, const void *userArg, const TocEntry *te) * The results must be in the order of the relations supplied in the * parameters to ensure we remain in sync as we walk through the TOC. * - * For versions before 19, the redundant filter clause on s.tablename = - * ANY(...) seems sufficient to convince the planner to use + * For versions before 19, the redundant filter clause on s.tablename + * = ANY(...) seems sufficient to convince the planner to use * pg_class_relname_nsp_index, which avoids a full scan of pg_stats. * In newer versions, pg_stats returns the table OIDs, eliminating the * need for that hack. @@ -13469,11 +13468,11 @@ dumpFunc(Archive *fout, const FuncInfo *finfo) "pg_catalog.pg_get_function_result(p.oid) AS funcresult,\n" "proleakproof,\n"); - appendPQExpBufferStr(query, - "array_to_string(protrftypes, ' ') AS protrftypes,\n"); + appendPQExpBufferStr(query, + "array_to_string(protrftypes, ' ') AS protrftypes,\n"); - appendPQExpBufferStr(query, - "proparallel,\n"); + appendPQExpBufferStr(query, + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -14963,9 +14962,9 @@ dumpCollation(Archive *fout, const CollInfo *collinfo) /* Get collation-specific details */ appendPQExpBufferStr(query, "SELECT "); - appendPQExpBufferStr(query, - "collprovider, " - "collversion, "); + appendPQExpBufferStr(query, + "collprovider, " + "collversion, "); if (fout->remoteVersion >= 120000) appendPQExpBufferStr(query, @@ -15372,23 +15371,23 @@ dumpAgg(Archive *fout, const AggInfo *agginfo) "pg_catalog.pg_get_function_arguments(p.oid) AS funcargs,\n" "pg_catalog.pg_get_function_identity_arguments(p.oid) AS funciargs,\n"); - appendPQExpBufferStr(query, - "aggkind,\n" - "aggmtransfn,\n" - "aggminvtransfn,\n" - "aggmfinalfn,\n" - "aggmtranstype::pg_catalog.regtype,\n" - "aggfinalextra,\n" - "aggmfinalextra,\n" - "aggtransspace,\n" - "aggmtransspace,\n" - "aggminitval,\n"); + appendPQExpBufferStr(query, + "aggkind,\n" + "aggmtransfn,\n" + "aggminvtransfn,\n" + "aggmfinalfn,\n" + "aggmtranstype::pg_catalog.regtype,\n" + "aggfinalextra,\n" + "aggmfinalextra,\n" + "aggtransspace,\n" + "aggmtransspace,\n" + "aggminitval,\n"); - appendPQExpBufferStr(query, - "aggcombinefn,\n" - "aggserialfn,\n" - "aggdeserialfn,\n" - "proparallel,\n"); + appendPQExpBufferStr(query, + "aggcombinefn,\n" + "aggserialfn,\n" + "aggdeserialfn,\n" + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -16848,30 +16847,30 @@ dumpTable(Archive *fout, const TableInfo *tbinfo) appendPQExpBufferStr(query, "PREPARE getColumnACLs(pg_catalog.oid) AS\n"); - /* - * In principle we should call acldefault('c', relowner) to - * get the default ACL for a column. However, we don't - * currently store the numeric OID of the relowner in - * TableInfo. We could convert the owner name using regrole, - * but that creates a risk of failure due to concurrent role - * renames. Given that the default ACL for columns is empty - * and is likely to stay that way, it's not worth extra cycles - * and risk to avoid hard-wiring that knowledge here. - */ - appendPQExpBufferStr(query, - "SELECT at.attname, " - "at.attacl, " - "'{}' AS acldefault, " - "pip.privtype, pip.initprivs " - "FROM pg_catalog.pg_attribute at " - "LEFT JOIN pg_catalog.pg_init_privs pip ON " - "(at.attrelid = pip.objoid " - "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " - "AND at.attnum = pip.objsubid) " - "WHERE at.attrelid = $1 AND " - "NOT at.attisdropped " - "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " - "ORDER BY at.attnum"); + /* + * In principle we should call acldefault('c', relowner) to get + * the default ACL for a column. However, we don't currently + * store the numeric OID of the relowner in TableInfo. We could + * convert the owner name using regrole, but that creates a risk + * of failure due to concurrent role renames. Given that the + * default ACL for columns is empty and is likely to stay that + * way, it's not worth extra cycles and risk to avoid hard-wiring + * that knowledge here. + */ + appendPQExpBufferStr(query, + "SELECT at.attname, " + "at.attacl, " + "'{}' AS acldefault, " + "pip.privtype, pip.initprivs " + "FROM pg_catalog.pg_attribute at " + "LEFT JOIN pg_catalog.pg_init_privs pip ON " + "(at.attrelid = pip.objoid " + "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " + "AND at.attnum = pip.objsubid) " + "WHERE at.attrelid = $1 AND " + "NOT at.attisdropped " + "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " + "ORDER BY at.attnum"); ExecuteSqlStatement(fout, query->data); @@ -19165,7 +19164,7 @@ collectSequences(Archive *fout) * pg_get_sequence_data(), but we only do so for non-schema-only dumps. */ if (fout->remoteVersion < 180000 || - (!fout->dopt->dumpData && !fout->dopt->sequence_data)) + (!fout->dopt->dumpData && !fout->dopt->sequence_data)) query = "SELECT seqrelid, format_type(seqtypid, NULL), " "seqstart, seqincrement, " "seqmax, seqmin, " @@ -19227,15 +19226,14 @@ dumpSequence(Archive *fout, const TableInfo *tbinfo) qseqname = pg_strdup(fmtId(tbinfo->dobj.name)); /* - * The sequence information is gathered in a sorted - * table before any calls to dumpSequence(). See collectSequences() for - * more information. + * The sequence information is gathered in a sorted table before any calls + * to dumpSequence(). See collectSequences() for more information. */ - Assert(sequences); + Assert(sequences); - key.oid = tbinfo->dobj.catId.oid; - seq = bsearch(&key, sequences, nsequences, - sizeof(SequenceItem), SequenceItemCmp); + key.oid = tbinfo->dobj.catId.oid; + seq = bsearch(&key, sequences, nsequences, + sizeof(SequenceItem), SequenceItemCmp); /* Calculate default limits for a sequence of this type */ is_ascending = (seq->incby >= 0); diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c index e68937c9934..afcd9a218d8 100644 --- a/src/bin/pg_dump/pg_dumpall.c +++ b/src/bin/pg_dump/pg_dumpall.c @@ -785,11 +785,11 @@ dropRoles(PGconn *conn) int i_rolname; int i; - printfPQExpBuffer(buf, - "SELECT rolname " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 1", role_catalog); + printfPQExpBuffer(buf, + "SELECT rolname " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 1", role_catalog); res = executeQuery(conn, buf->data); @@ -843,16 +843,16 @@ dumpRoles(PGconn *conn) * Notes: rolconfig is dumped later, and pg_authid must be used for * extracting rolcomment regardless of role_catalog. */ - printfPQExpBuffer(buf, - "SELECT oid, rolname, rolsuper, rolinherit, " - "rolcreaterole, rolcreatedb, " - "rolcanlogin, rolconnlimit, rolpassword, " - "rolvaliduntil, rolreplication, rolbypassrls, " - "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " - "rolname = current_user AS is_current_user " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 2", role_catalog); + printfPQExpBuffer(buf, + "SELECT oid, rolname, rolsuper, rolinherit, " + "rolcreaterole, rolcreatedb, " + "rolcanlogin, rolconnlimit, rolpassword, " + "rolvaliduntil, rolreplication, rolbypassrls, " + "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " + "rolname = current_user AS is_current_user " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 2", role_catalog); res = executeQuery(conn, buf->data); diff --git a/src/bin/pg_upgrade/check.c b/src/bin/pg_upgrade/check.c index 786c1474829..f725f5ee3e2 100644 --- a/src/bin/pg_upgrade/check.c +++ b/src/bin/pg_upgrade/check.c @@ -1475,15 +1475,15 @@ check_for_incompatible_polymorphics(ClusterInfo *cluster) ", 'array_cat(anyarray,anyarray)'" ", 'array_prepend(anyelement,anyarray)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_remove(anyarray,anyelement)'" - ", 'array_replace(anyarray,anyelement,anyelement)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_remove(anyarray,anyelement)'" + ", 'array_replace(anyarray,anyelement,anyelement)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_position(anyarray,anyelement)'" - ", 'array_position(anyarray,anyelement,integer)'" - ", 'array_positions(anyarray,anyelement)'" - ", 'width_bucket(anyelement,anyarray)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_position(anyarray,anyelement)'" + ", 'array_position(anyarray,anyelement,integer)'" + ", 'array_positions(anyarray,anyelement)'" + ", 'width_bucket(anyelement,anyarray)'"); /* * The query below hardcodes FirstNormalObjectId as 16384 rather than diff --git a/src/bin/pg_upgrade/controldata.c b/src/bin/pg_upgrade/controldata.c index 8f81c9e9582..02ea02df60f 100644 --- a/src/bin/pg_upgrade/controldata.c +++ b/src/bin/pg_upgrade/controldata.c @@ -228,7 +228,7 @@ get_control_data(ClusterInfo *cluster) p++; /* remove ':' char */ cluster->controldata.chkpnt_nxtepoch = str2uint(p); - p = strchr(p, ':'); + p = strchr(p, ':'); if (p == NULL || strlen(p) <= 1) pg_fatal("%d: controldata retrieval problem", __LINE__); diff --git a/src/bin/pg_upgrade/exec.c b/src/bin/pg_upgrade/exec.c index 44355feea30..a1bdbf373e3 100644 --- a/src/bin/pg_upgrade/exec.c +++ b/src/bin/pg_upgrade/exec.c @@ -55,7 +55,7 @@ get_bin_version(ClusterInfo *cluster) if (sscanf(cmd_output, "%*s %*s %d.%d", &v1, &v2) < 1) pg_fatal("could not get pg_ctl version output from %s", cmd); - cluster->bin_version = v1 * 10000; + cluster->bin_version = v1 * 10000; } @@ -344,8 +344,8 @@ check_data_dir(ClusterInfo *cluster) check_single_dir(pg_data, "pg_subtrans"); check_single_dir(pg_data, PG_TBLSPC_DIR); check_single_dir(pg_data, "pg_twophase"); - check_single_dir(pg_data, "pg_wal"); - check_single_dir(pg_data, "pg_xact"); + check_single_dir(pg_data, "pg_wal"); + check_single_dir(pg_data, "pg_xact"); } @@ -385,7 +385,7 @@ check_bin_dir(ClusterInfo *cluster, bool check_versions) */ get_bin_version(cluster); - check_exec(cluster->bindir, "pg_resetwal", check_versions); + check_exec(cluster->bindir, "pg_resetwal", check_versions); if (cluster == &new_cluster) { diff --git a/src/bin/pg_upgrade/multixact_rewrite.c b/src/bin/pg_upgrade/multixact_rewrite.c index c45b3183684..c7a1416494d 100644 --- a/src/bin/pg_upgrade/multixact_rewrite.c +++ b/src/bin/pg_upgrade/multixact_rewrite.c @@ -61,52 +61,52 @@ rewrite_multixacts(MultiXactId from_multi, MultiXactId to_multi) * Convert old multixids, if needed, by reading them one-by-one from the * old cluster. */ - old_reader = AllocOldMultiXactRead(old_cluster.pgdata, - old_cluster.controldata.chkpnt_nxtmulti, - old_cluster.controldata.chkpnt_nxtmxoff); + old_reader = AllocOldMultiXactRead(old_cluster.pgdata, + old_cluster.controldata.chkpnt_nxtmulti, + old_cluster.controldata.chkpnt_nxtmxoff); - for (MultiXactId multi = from_multi; multi != to_multi;) - { - MultiXactMember member; - bool multixid_valid; - - /* - * Read this multixid's members. - * - * Locking-only XIDs that may be part of multi-xids don't matter - * after upgrade, as there can be no transactions running across - * upgrade. So as a small optimization, we only read one member - * from each multixid: the one updating one, or if there was no - * update, arbitrarily the first locking xid. - */ - multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); + for (MultiXactId multi = from_multi; multi != to_multi;) + { + MultiXactMember member; + bool multixid_valid; - /* - * Write the new offset to pg_multixact/offsets. - * - * Even if this multixid is invalid, we still need to write its - * offset if the *previous* multixid was valid. That's because - * when reading a multixid, the number of members is calculated - * from the difference between the two offsets. - */ - RecordMultiXactOffset(offsets_writer, multi, - (multixid_valid || prev_multixid_valid) ? next_offset : 0); + /* + * Read this multixid's members. + * + * Locking-only XIDs that may be part of multi-xids don't matter after + * upgrade, as there can be no transactions running across upgrade. So + * as a small optimization, we only read one member from each + * multixid: the one updating one, or if there was no update, + * arbitrarily the first locking xid. + */ + multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); - /* Write the members */ - if (multixid_valid) - { - RecordMultiXactMembers(members_writer, next_offset, 1, &member); - next_offset += 1; - } + /* + * Write the new offset to pg_multixact/offsets. + * + * Even if this multixid is invalid, we still need to write its offset + * if the *previous* multixid was valid. That's because when reading + * a multixid, the number of members is calculated from the difference + * between the two offsets. + */ + RecordMultiXactOffset(offsets_writer, multi, + (multixid_valid || prev_multixid_valid) ? next_offset : 0); - /* Advance to next multixid, handling wraparound */ - multi++; - if (multi < FirstMultiXactId) - multi = FirstMultiXactId; - prev_multixid_valid = multixid_valid; + /* Write the members */ + if (multixid_valid) + { + RecordMultiXactMembers(members_writer, next_offset, 1, &member); + next_offset += 1; } - FreeOldMultiXactReader(old_reader); + /* Advance to next multixid, handling wraparound */ + multi++; + if (multi < FirstMultiXactId) + multi = FirstMultiXactId; + prev_multixid_valid = multixid_valid; + } + + FreeOldMultiXactReader(old_reader); /* Write the final 'next' offset to the last SLRU page */ RecordMultiXactOffset(offsets_writer, to_multi, diff --git a/src/bin/pg_upgrade/pg_upgrade.c b/src/bin/pg_upgrade/pg_upgrade.c index c6af9035665..7366fd4627c 100644 --- a/src/bin/pg_upgrade/pg_upgrade.c +++ b/src/bin/pg_upgrade/pg_upgrade.c @@ -833,7 +833,7 @@ copy_xact_xlog_xid(void) * Determine the range of multixacts to convert. */ nxtmulti = old_cluster.controldata.chkpnt_nxtmulti; - oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; + oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; /* handle wraparound */ if (nxtmulti < FirstMultiXactId) nxtmulti = FirstMultiXactId; @@ -898,15 +898,15 @@ set_frozenxids(void) int i_datname; int i_datallowconn; - prep_status("Setting frozenxid and minmxid counters in new cluster"); + prep_status("Setting frozenxid and minmxid counters in new cluster"); conn_template1 = connectToServer(&new_cluster, "template1"); - /* set pg_database.datfrozenxid */ - PQclear(executeQueryOrDie(conn_template1, - "UPDATE pg_catalog.pg_database " - "SET datfrozenxid = '%u'", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_database.datfrozenxid */ + PQclear(executeQueryOrDie(conn_template1, + "UPDATE pg_catalog.pg_database " + "SET datfrozenxid = '%u'", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_database.datminmxid */ PQclear(executeQueryOrDie(conn_template1, @@ -942,16 +942,16 @@ set_frozenxids(void) conn = connectToServer(&new_cluster, datname); - /* set pg_class.relfrozenxid */ - PQclear(executeQueryOrDie(conn, - "UPDATE pg_catalog.pg_class " - "SET relfrozenxid = '%u' " - /* only heap, materialized view, and TOAST are vacuumed */ - "WHERE relkind IN (" - CppAsString2(RELKIND_RELATION) ", " - CppAsString2(RELKIND_MATVIEW) ", " - CppAsString2(RELKIND_TOASTVALUE) ")", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_class.relfrozenxid */ + PQclear(executeQueryOrDie(conn, + "UPDATE pg_catalog.pg_class " + "SET relfrozenxid = '%u' " + /* only heap, materialized view, and TOAST are vacuumed */ + "WHERE relkind IN (" + CppAsString2(RELKIND_RELATION) ", " + CppAsString2(RELKIND_MATVIEW) ", " + CppAsString2(RELKIND_TOASTVALUE) ")", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_class.relminmxid */ PQclear(executeQueryOrDie(conn, diff --git a/src/bin/pg_upgrade/relfilenumber.c b/src/bin/pg_upgrade/relfilenumber.c index ec2ff7acb21..6c467bdc8a5 100644 --- a/src/bin/pg_upgrade/relfilenumber.c +++ b/src/bin/pg_upgrade/relfilenumber.c @@ -587,32 +587,32 @@ transfer_relfile(FileNameMap *map, const char *type_suffix) /* Copying files might take some time, so give feedback. */ pg_log(PG_STATUS, "%s", old_file); - switch (user_opts.transfer_mode) - { - case TRANSFER_MODE_CLONE: - pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", - old_file, new_file); - cloneFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", - old_file, new_file); - copyFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY_FILE_RANGE: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", - old_file, new_file); - copyFileByRange(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_LINK: - pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", - old_file, new_file); - linkFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_SWAP: - /* swap mode is handled in its own code path */ - pg_fatal("should never happen"); - break; - } + switch (user_opts.transfer_mode) + { + case TRANSFER_MODE_CLONE: + pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", + old_file, new_file); + cloneFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", + old_file, new_file); + copyFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY_FILE_RANGE: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", + old_file, new_file); + copyFileByRange(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_LINK: + pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", + old_file, new_file); + linkFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_SWAP: + /* swap mode is handled in its own code path */ + pg_fatal("should never happen"); + break; + } } } diff --git a/src/bin/pg_upgrade/t/006_transfer_modes.pl b/src/bin/pg_upgrade/t/006_transfer_modes.pl index 9efa5dc863c..360d05c4b68 100644 --- a/src/bin/pg_upgrade/t/006_transfer_modes.pl +++ b/src/bin/pg_upgrade/t/006_transfer_modes.pl @@ -29,10 +29,8 @@ sub test_mode } $new->init(); - $new->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); - $old->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); + $new->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); + $old->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); # We can only test security labels if both the old and new installations # have dummy_seclabel. @@ -76,15 +74,14 @@ sub test_mode "CREATE TABLE test4 AS SELECT generate_series(400, 502)"); } - $old->safe_psql('postgres', - "CREATE TABLESPACE inplc_tblspc LOCATION ''"); - $old->safe_psql('postgres', - "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); - $old->safe_psql('postgres', - "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" - ); - $old->safe_psql('testdb3', - "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); + $old->safe_psql('postgres', "CREATE TABLESPACE inplc_tblspc LOCATION ''"); + $old->safe_psql('postgres', + "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); + $old->safe_psql('postgres', + "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" + ); + $old->safe_psql('testdb3', + "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); # While we are here, test handling of large objects. $old->safe_psql( @@ -152,12 +149,10 @@ sub test_mode } # Tests for in-place tablespaces. - $result = - $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); - is($result, '104', "test5 data after pg_upgrade $mode"); - $result = - $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); - is($result, '105', "test6 data after pg_upgrade $mode"); + $result = $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); + is($result, '104', "test5 data after pg_upgrade $mode"); + $result = $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); + is($result, '105', "test6 data after pg_upgrade $mode"); # Tests for large objects $result = $new->safe_psql('postgres', "SELECT lo_get(4532)"); diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index 44ef11d980e..c90bf8bbde2 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -6278,23 +6278,22 @@ get_create_object_cmd(EditableObjectType obj_type, Oid oid, * ensure the right view gets replaced. Also, check relation kind * to be sure it's a view. * - * Views may have WITH [LOCAL|CASCADED] - * CHECK OPTION. These are not part of the view definition - * returned by pg_get_viewdef() and so need to be retrieved - * separately. Materialized views may have - * arbitrary storage parameter reloptions. + * Views may have WITH [LOCAL|CASCADED] CHECK OPTION. These are + * not part of the view definition returned by pg_get_viewdef() + * and so need to be retrieved separately. Materialized views may + * have arbitrary storage parameter reloptions. */ printfPQExpBuffer(query, "/* %s */\n", _("Get view's definition and details")); - appendPQExpBuffer(query, - "SELECT nspname, relname, relkind, " - "pg_catalog.pg_get_viewdef(c.oid, true), " - "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " - "FROM pg_catalog.pg_class c " - "LEFT JOIN pg_catalog.pg_namespace n " - "ON c.relnamespace = n.oid WHERE c.oid = %u", - oid); + appendPQExpBuffer(query, + "SELECT nspname, relname, relkind, " + "pg_catalog.pg_get_viewdef(c.oid, true), " + "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " + "FROM pg_catalog.pg_class c " + "LEFT JOIN pg_catalog.pg_namespace n " + "ON c.relnamespace = n.oid WHERE c.oid = %u", + oid); break; } diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index ce99137c613..ac0c55e7aa5 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -387,19 +387,19 @@ describeFunctions(const char *functypes, const char *func_pattern, gettext_noop("stable"), gettext_noop("volatile"), gettext_noop("Volatility")); - appendPQExpBuffer(&buf, - ",\n CASE\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" - " END as \"%s\"", - gettext_noop("restricted"), - gettext_noop("safe"), - gettext_noop("unsafe"), - gettext_noop("Parallel")); + appendPQExpBuffer(&buf, + ",\n CASE\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" + " END as \"%s\"", + gettext_noop("restricted"), + gettext_noop("safe"), + gettext_noop("unsafe"), + gettext_noop("Parallel")); appendPQExpBuffer(&buf, ",\n pg_catalog.pg_get_userbyid(p.proowner) as \"%s\"" ",\n CASE WHEN prosecdef THEN '%s' ELSE '%s' END AS \"%s\"" @@ -599,8 +599,8 @@ describeFunctions(const char *functypes, const char *func_pattern, myopt.title = _("List of functions"); myopt.translate_header = true; - myopt.translate_columns = translate_columns; - myopt.n_translate_columns = lengthof(translate_columns); + myopt.translate_columns = translate_columns; + myopt.n_translate_columns = lengthof(translate_columns); printQuery(res, &myopt, pset.queryFout, false, pset.logfile); @@ -1086,38 +1086,38 @@ permissionsList(const char *pattern, bool showSystem) " ), E'\\n') AS \"%s\"", gettext_noop("Column privileges")); - appendPQExpBuffer(&buf, - ",\n pg_catalog.array_to_string(ARRAY(\n" - " SELECT polname\n" - " || CASE WHEN NOT polpermissive THEN\n" - " E' (RESTRICTIVE)'\n" - " ELSE '' END\n" - " || CASE WHEN polcmd != '*' THEN\n" - " E' (' || polcmd::pg_catalog.text || E'):'\n" - " ELSE E':'\n" - " END\n" - " || CASE WHEN polqual IS NOT NULL THEN\n" - " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" - " ELSE E''\n" - " END\n" - " || CASE WHEN polwithcheck IS NOT NULL THEN\n" - " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" - " ELSE E''\n" - " END" - " || CASE WHEN polroles <> '{0}' THEN\n" - " E'\\n to: ' || pg_catalog.array_to_string(\n" - " ARRAY(\n" - " SELECT rolname\n" - " FROM pg_catalog.pg_roles\n" - " WHERE oid = ANY (polroles)\n" - " ORDER BY 1\n" - " ), E', ')\n" - " ELSE E''\n" - " END\n" - " FROM pg_catalog.pg_policy pol\n" - " WHERE polrelid = c.oid), E'\\n')\n" - " AS \"%s\"", - gettext_noop("Policies")); + appendPQExpBuffer(&buf, + ",\n pg_catalog.array_to_string(ARRAY(\n" + " SELECT polname\n" + " || CASE WHEN NOT polpermissive THEN\n" + " E' (RESTRICTIVE)'\n" + " ELSE '' END\n" + " || CASE WHEN polcmd != '*' THEN\n" + " E' (' || polcmd::pg_catalog.text || E'):'\n" + " ELSE E':'\n" + " END\n" + " || CASE WHEN polqual IS NOT NULL THEN\n" + " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" + " ELSE E''\n" + " END\n" + " || CASE WHEN polwithcheck IS NOT NULL THEN\n" + " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" + " ELSE E''\n" + " END" + " || CASE WHEN polroles <> '{0}' THEN\n" + " E'\\n to: ' || pg_catalog.array_to_string(\n" + " ARRAY(\n" + " SELECT rolname\n" + " FROM pg_catalog.pg_roles\n" + " WHERE oid = ANY (polroles)\n" + " ORDER BY 1\n" + " ), E', ')\n" + " ELSE E''\n" + " END\n" + " FROM pg_catalog.pg_policy pol\n" + " WHERE polrelid = c.oid), E'\\n')\n" + " AS \"%s\"", + gettext_noop("Policies")); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_class c\n" " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n" @@ -1675,27 +1675,27 @@ describeOneTableDetails(const char *schemaname, char *footers[3] = {NULL, NULL, NULL}; printfPQExpBuffer(&buf, "/* %s */\n", _("Get sequence information")); - appendPQExpBuffer(&buf, - "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" - " seqstart AS \"%s\",\n" - " seqmin AS \"%s\",\n" - " seqmax AS \"%s\",\n" - " seqincrement AS \"%s\",\n" - " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" - " seqcache AS \"%s\"\n", - gettext_noop("Type"), - gettext_noop("Start"), - gettext_noop("Minimum"), - gettext_noop("Maximum"), - gettext_noop("Increment"), - gettext_noop("yes"), - gettext_noop("no"), - gettext_noop("Cycles?"), - gettext_noop("Cache")); - appendPQExpBuffer(&buf, - "FROM pg_catalog.pg_sequence\n" - "WHERE seqrelid = '%s';", - oid); + appendPQExpBuffer(&buf, + "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" + " seqstart AS \"%s\",\n" + " seqmin AS \"%s\",\n" + " seqmax AS \"%s\",\n" + " seqincrement AS \"%s\",\n" + " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" + " seqcache AS \"%s\"\n", + gettext_noop("Type"), + gettext_noop("Start"), + gettext_noop("Minimum"), + gettext_noop("Maximum"), + gettext_noop("Increment"), + gettext_noop("yes"), + gettext_noop("no"), + gettext_noop("Cycles?"), + gettext_noop("Cache")); + appendPQExpBuffer(&buf, + "FROM pg_catalog.pg_sequence\n" + "WHERE seqrelid = '%s';", + oid); res = PSQLexec(buf.data); if (!res) @@ -1913,7 +1913,7 @@ describeOneTableDetails(const char *schemaname, appendPQExpBufferStr(&buf, ",\n (SELECT c.collname FROM pg_catalog.pg_collation c, pg_catalog.pg_type t\n" " WHERE c.oid = a.attcollation AND t.oid = a.atttypid AND a.attcollation <> t.typcollation) AS attcollation"); attcoll_col = cols++; - appendPQExpBufferStr(&buf, ",\n a.attidentity"); + appendPQExpBufferStr(&buf, ",\n a.attidentity"); attidentity_col = cols++; if (pset.sversion >= 120000) appendPQExpBufferStr(&buf, ",\n a.attgenerated"); @@ -2326,7 +2326,7 @@ describeOneTableDetails(const char *schemaname, CppAsString2(CONSTRAINT_EXCLUSION) ") AND " "condeferred) AS condeferred,\n"); - appendPQExpBufferStr(&buf, "i.indisreplident,\n"); + appendPQExpBufferStr(&buf, "i.indisreplident,\n"); if (pset.sversion >= 150000) appendPQExpBufferStr(&buf, "i.indnullsnotdistinct,\n"); @@ -2431,7 +2431,7 @@ describeOneTableDetails(const char *schemaname, "pg_catalog.pg_get_indexdef(i.indexrelid, 0, true),\n " "pg_catalog.pg_get_constraintdef(con.oid, true), " "contype, condeferrable, condeferred"); - appendPQExpBufferStr(&buf, ", i.indisreplident"); + appendPQExpBufferStr(&buf, ", i.indisreplident"); appendPQExpBufferStr(&buf, ", c2.reltablespace"); if (pset.sversion >= 180000) appendPQExpBufferStr(&buf, ", con.conperiod"); @@ -2682,81 +2682,80 @@ describeOneTableDetails(const char *schemaname, PQclear(result); /* print any row-level policies */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get row-level policies for this table")); - appendPQExpBufferStr(&buf, "SELECT pol.polname,"); - appendPQExpBufferStr(&buf, - " pol.polpermissive,\n"); - appendPQExpBuffer(&buf, - " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" - " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" - " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" - " CASE pol.polcmd\n" - " WHEN 'r' THEN 'SELECT'\n" - " WHEN 'a' THEN 'INSERT'\n" - " WHEN 'w' THEN 'UPDATE'\n" - " WHEN 'd' THEN 'DELETE'\n" - " END AS cmd\n" - "FROM pg_catalog.pg_policy pol\n" - "WHERE pol.polrelid = '%s' ORDER BY 1;", - oid); + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get row-level policies for this table")); + appendPQExpBufferStr(&buf, "SELECT pol.polname,"); + appendPQExpBufferStr(&buf, + " pol.polpermissive,\n"); + appendPQExpBuffer(&buf, + " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" + " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" + " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" + " CASE pol.polcmd\n" + " WHEN 'r' THEN 'SELECT'\n" + " WHEN 'a' THEN 'INSERT'\n" + " WHEN 'w' THEN 'UPDATE'\n" + " WHEN 'd' THEN 'DELETE'\n" + " END AS cmd\n" + "FROM pg_catalog.pg_policy pol\n" + "WHERE pol.polrelid = '%s' ORDER BY 1;", + oid); - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - /* - * Handle cases where RLS is enabled and there are policies, or - * there aren't policies, or RLS isn't enabled but there are - * policies - */ - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies:")); + /* + * Handle cases where RLS is enabled and there are policies, or there + * aren't policies, or RLS isn't enabled but there are policies + */ + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies:")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled):")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled):")); - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); - if (!tableinfo.rowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (row security disabled):")); + if (!tableinfo.rowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (row security disabled):")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " POLICY \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " POLICY \"%s\"", + PQgetvalue(result, i, 0)); - if (*(PQgetvalue(result, i, 1)) == 'f') - appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); + if (*(PQgetvalue(result, i, 1)) == 'f') + appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); - if (!PQgetisnull(result, i, 5)) - appendPQExpBuffer(&buf, " FOR %s", - PQgetvalue(result, i, 5)); + if (!PQgetisnull(result, i, 5)) + appendPQExpBuffer(&buf, " FOR %s", + PQgetvalue(result, i, 5)); - if (!PQgetisnull(result, i, 2)) - { - appendPQExpBuffer(&buf, "\n TO %s", - PQgetvalue(result, i, 2)); - } + if (!PQgetisnull(result, i, 2)) + { + appendPQExpBuffer(&buf, "\n TO %s", + PQgetvalue(result, i, 2)); + } - if (!PQgetisnull(result, i, 3)) - appendPQExpBuffer(&buf, "\n USING (%s)", - PQgetvalue(result, i, 3)); + if (!PQgetisnull(result, i, 3)) + appendPQExpBuffer(&buf, "\n USING (%s)", + PQgetvalue(result, i, 3)); - if (!PQgetisnull(result, i, 4)) - appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", - PQgetvalue(result, i, 4)); + if (!PQgetisnull(result, i, 4)) + appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", + PQgetvalue(result, i, 4)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* print any extended statistics */ if (pset.sversion >= 140000) @@ -3025,115 +3024,115 @@ describeOneTableDetails(const char *schemaname, } /* print any publications */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get publications that publish this table")); - if (pset.sversion >= 150000) + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get publications that publish this table")); + if (pset.sversion >= 150000) + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" + " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" + "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" + "UNION\n" + "SELECT pubname\n" + " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" + " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" + " (SELECT pg_catalog.string_agg(attname, ', ')\n" + " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" + " pg_catalog.pg_attribute\n" + " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" + " ELSE NULL END) " + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" + "WHERE pr.prrelid = '%s'\n", + oid, oid, oid); + + if (pset.sversion >= 190000) { + /* + * Skip entries where this relation appears in the + * publication's EXCEPT list. + */ appendPQExpBuffer(&buf, + " AND NOT pr.prexcept\n" + "UNION\n" "SELECT pubname\n" " , NULL\n" " , NULL\n" "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" - " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" - "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" - "UNION\n" - "SELECT pubname\n" - " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" - " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" - " (SELECT pg_catalog.string_agg(attname, ', ')\n" - " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" - " pg_catalog.pg_attribute\n" - " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" - " ELSE NULL END) " - "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" - "WHERE pr.prrelid = '%s'\n", + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + " AND NOT EXISTS (\n" + " SELECT 1\n" + " FROM pg_catalog.pg_publication_rel pr\n" + " WHERE pr.prpubid = p.oid AND\n" + " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" + "ORDER BY 1;", oid, oid, oid); - - if (pset.sversion >= 190000) - { - /* - * Skip entries where this relation appears in the - * publication's EXCEPT list. - */ - appendPQExpBuffer(&buf, - " AND NOT pr.prexcept\n" - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - " AND NOT EXISTS (\n" - " SELECT 1\n" - " FROM pg_catalog.pg_publication_rel pr\n" - " WHERE pr.prpubid = p.oid AND\n" - " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" - "ORDER BY 1;", - oid, oid, oid); - } - else - { - appendPQExpBuffer(&buf, - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - "ORDER BY 1;", - oid); - } } else { appendPQExpBuffer(&buf, + "UNION\n" "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - "WHERE pr.prrelid = '%s'\n" - "UNION ALL\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" + " , NULL\n" + " , NULL\n" "FROM pg_catalog.pg_publication p\n" "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" "ORDER BY 1;", - oid, oid); + oid); } + } + else + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + "WHERE pr.prrelid = '%s'\n" + "UNION ALL\n" + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + "ORDER BY 1;", + oid, oid); + } - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - if (tuples > 0) - printTableAddFooter(&cont, _("Included in publications:")); + if (tuples > 0) + printTableAddFooter(&cont, _("Included in publications:")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " \"%s\"", + PQgetvalue(result, i, 0)); - /* column list (if any) */ - if (!PQgetisnull(result, i, 2)) - appendPQExpBuffer(&buf, " (%s)", - PQgetvalue(result, i, 2)); + /* column list (if any) */ + if (!PQgetisnull(result, i, 2)) + appendPQExpBuffer(&buf, " (%s)", + PQgetvalue(result, i, 2)); - /* row filter (if any) */ - if (!PQgetisnull(result, i, 1)) - appendPQExpBuffer(&buf, " WHERE %s", - PQgetvalue(result, i, 1)); + /* row filter (if any) */ + if (!PQgetisnull(result, i, 1)) + appendPQExpBuffer(&buf, " WHERE %s", + PQgetvalue(result, i, 1)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* Print publications where the table is in the EXCEPT clause */ if (pset.sversion >= 190000) @@ -3805,7 +3804,7 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) ncols++; } appendPQExpBufferStr(&buf, "\n, r.rolreplication"); - appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); + appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_roles r\n"); @@ -3860,8 +3859,8 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) if (strcmp(PQgetvalue(res, i, (verbose ? 9 : 8)), "t") == 0) add_role_attribute(&buf, _("Replication")); - if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) - add_role_attribute(&buf, _("Bypass RLS")); + if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) + add_role_attribute(&buf, _("Bypass RLS")); conns = atoi(PQgetvalue(res, i, 6)); if (conns >= 0) @@ -5155,14 +5154,14 @@ listCollations(const char *pattern, bool verbose, bool showSystem) gettext_noop("Schema"), gettext_noop("Name")); - appendPQExpBuffer(&buf, - " CASE c.collprovider " - "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " - "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " - "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " - "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " - "END AS \"%s\",\n", - gettext_noop("Provider")); + appendPQExpBuffer(&buf, + " CASE c.collprovider " + "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " + "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " + "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " + "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " + "END AS \"%s\",\n", + gettext_noop("Provider")); appendPQExpBuffer(&buf, " c.collcollate AS \"%s\",\n" -- 2.50.1 (Apple Git-155) --aHl3HfeiUuO3zeNC-- ^ permalink raw reply [nested|flat] 59+ messages in thread
* [PATCH v6 4/4] run pgindent and pgperltidy @ 2026-06-30 18:24 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 59+ messages in thread From: Nathan Bossart @ 2026-06-30 18:24 UTC (permalink / raw) --- src/bin/pg_dump/pg_dump.c | 464 ++++++++++----------- src/bin/pg_dump/pg_dumpall.c | 30 +- src/bin/pg_upgrade/check.c | 16 +- src/bin/pg_upgrade/controldata.c | 2 +- src/bin/pg_upgrade/exec.c | 8 +- src/bin/pg_upgrade/multixact_rewrite.c | 80 ++-- src/bin/pg_upgrade/pg_upgrade.c | 34 +- src/bin/pg_upgrade/relfilenumber.c | 54 +-- src/bin/pg_upgrade/t/006_transfer_modes.pl | 33 +- src/bin/psql/command.c | 29 +- src/bin/psql/describe.c | 461 ++++++++++---------- 11 files changed, 601 insertions(+), 610 deletions(-) diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 65bd15ebfd2..5673268b467 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -1491,8 +1491,8 @@ setup_connection(Archive *AH, const char *dumpencoding, * Disable timeouts if supported. */ ExecuteSqlStatement(AH, "SET statement_timeout = 0"); - ExecuteSqlStatement(AH, "SET lock_timeout = 0"); - ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); + ExecuteSqlStatement(AH, "SET lock_timeout = 0"); + ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); if (AH->remoteVersion >= 170000) ExecuteSqlStatement(AH, "SET transaction_timeout = 0"); @@ -1505,10 +1505,10 @@ setup_connection(Archive *AH, const char *dumpencoding, /* * Adjust row-security mode, if supported. */ - if (dopt->enable_row_security) - ExecuteSqlStatement(AH, "SET row_security = on"); - else - ExecuteSqlStatement(AH, "SET row_security = off"); + if (dopt->enable_row_security) + ExecuteSqlStatement(AH, "SET row_security = on"); + else + ExecuteSqlStatement(AH, "SET row_security = off"); /* * For security reasons, we restrict the expansion of non-system views and @@ -1933,10 +1933,9 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) addObjectDependency(dobj, ext->dobj.dumpId); /* - * Mark the member object to have any non-initial ACLs - * dumped. (Any initial ACLs will be removed later, using data from - * pg_init_privs, so that we'll dump only the delta from the extension's - * initial setup.) + * Mark the member object to have any non-initial ACLs dumped. (Any + * initial ACLs will be removed later, using data from pg_init_privs, so + * that we'll dump only the delta from the extension's initial setup.) * * In binary upgrades, we still dump all components of the members * individually, since the idea is to exactly reproduce the database @@ -1953,7 +1952,7 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) if (fout->dopt->binary_upgrade) dobj->dump = ext->dobj.dump; else - dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); + dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); return true; } @@ -1987,9 +1986,9 @@ selectDumpableNamespace(NamespaceInfo *nsinfo, Archive *fout) else if (strcmp(nsinfo->dobj.name, "pg_catalog") == 0) { /* - * We dump out any ACLs defined in pg_catalog, if - * they are interesting (and not the original ACLs which were set at - * initdb time, see pg_init_privs). + * We dump out any ACLs defined in pg_catalog, if they are interesting + * (and not the original ACLs which were set at initdb time, see + * pg_init_privs). */ nsinfo->dobj.dump_contains = nsinfo->dobj.dump = DUMP_COMPONENT_ACL; } @@ -3296,7 +3295,7 @@ dumpDatabase(Archive *fout) "datcollate, datctype, datfrozenxid, " "datacl, acldefault('d', datdba) AS acldefault, " "datistemplate, datconnlimit, "); - appendPQExpBufferStr(dbQry, "datminmxid, "); + appendPQExpBufferStr(dbQry, "datminmxid, "); if (fout->remoteVersion >= 170000) appendPQExpBufferStr(dbQry, "datlocprovider, datlocale, datcollversion, "); else if (fout->remoteVersion >= 150000) @@ -3638,11 +3637,11 @@ dumpDatabase(Archive *fout) ii_oid, ii_relminmxid; - appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" - "FROM pg_catalog.pg_class\n" - "WHERE oid IN (%u, %u, %u, %u);\n", - LargeObjectRelationId, LargeObjectLOidPNIndexId, - LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); + appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" + "FROM pg_catalog.pg_class\n" + "WHERE oid IN (%u, %u, %u, %u);\n", + LargeObjectRelationId, LargeObjectLOidPNIndexId, + LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); lo_res = ExecuteSqlQuery(fout, loFrozenQry->data, PGRES_TUPLES_OK); @@ -4274,7 +4273,7 @@ getPolicies(Archive *fout, TableInfo tblinfo[], int numTables) printfPQExpBuffer(query, "SELECT pol.oid, pol.tableoid, pol.polrelid, pol.polname, pol.polcmd, "); - appendPQExpBufferStr(query, "pol.polpermissive, "); + appendPQExpBufferStr(query, "pol.polpermissive, "); appendPQExpBuffer(query, "CASE WHEN pol.polroles = '{0}' THEN NULL ELSE " " pg_catalog.array_to_string(ARRAY(SELECT pg_catalog.quote_ident(rolname) from pg_catalog.pg_roles WHERE oid = ANY(pol.polroles)), ', ') END AS polroles, " @@ -6633,9 +6632,9 @@ getAccessMethods(Archive *fout) * Select all access methods from pg_am table. */ appendPQExpBufferStr(query, "SELECT tableoid, oid, amname, "); - appendPQExpBufferStr(query, - "amtype, " - "amhandler::pg_catalog.regproc AS amhandler "); + appendPQExpBufferStr(query, + "amtype, " + "amhandler::pg_catalog.regproc AS amhandler "); appendPQExpBufferStr(query, "FROM pg_am"); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6827,35 +6826,35 @@ getAggregates(Archive *fout) * Find all interesting aggregates. See comment in getFuncs() for the * rationale behind the filtering logic. */ - agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" - : "p.proisagg"); + agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" + : "p.proisagg"); - appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " - "p.proname AS aggname, " - "p.pronamespace AS aggnamespace, " - "p.pronargs, p.proargtypes, " - "p.proowner, " - "p.proacl AS aggacl, " - "acldefault('f', p.proowner) AS acldefault " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s AND (" - "p.pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog') OR " - "p.proacl IS DISTINCT FROM pip.initprivs", - agg_check); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - " OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); - appendPQExpBufferChar(query, ')'); + appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " + "p.proname AS aggname, " + "p.pronamespace AS aggnamespace, " + "p.pronargs, p.proargtypes, " + "p.proowner, " + "p.proacl AS aggacl, " + "acldefault('f', p.proowner) AS acldefault " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s AND (" + "p.pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog') OR " + "p.proacl IS DISTINCT FROM pip.initprivs", + agg_check); + if (dopt->binary_upgrade) + appendPQExpBufferStr(query, + " OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6957,53 +6956,53 @@ getFuncs(Archive *fout) * include them, since we want to dump extension members individually in * that mode. Also, if they are used by casts or transforms then we need * to gather the information about them, though they won't be dumped if - * they are built-in. Also, include functions in - * pg_catalog if they have an ACL different from what's shown in - * pg_init_privs (so we have to join to pg_init_privs; annoying). + * they are built-in. Also, include functions in pg_catalog if they have + * an ACL different from what's shown in pg_init_privs (so we have to join + * to pg_init_privs; annoying). */ - not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" - : "NOT p.proisagg"); + not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" + : "NOT p.proisagg"); - appendPQExpBuffer(query, - "SELECT p.tableoid, p.oid, p.proname, p.prolang, " - "p.pronargs, p.proargtypes, p.prorettype, " - "p.proacl, " - "acldefault('f', p.proowner) AS acldefault, " - "p.pronamespace, " - "p.proowner " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s" - "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " - "WHERE classid = 'pg_proc'::regclass AND " - "objid = p.oid AND deptype = 'i')" - "\n AND (" - "\n pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog')" - "\n OR EXISTS (SELECT 1 FROM pg_cast" - "\n WHERE pg_cast.oid > %u " - "\n AND p.oid = pg_cast.castfunc)" - "\n OR EXISTS (SELECT 1 FROM pg_transform" - "\n WHERE pg_transform.oid > %u AND " - "\n (p.oid = pg_transform.trffromsql" - "\n OR p.oid = pg_transform.trftosql))", - not_agg_check, - g_last_builtin_oid, - g_last_builtin_oid); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); + appendPQExpBuffer(query, + "SELECT p.tableoid, p.oid, p.proname, p.prolang, " + "p.pronargs, p.proargtypes, p.prorettype, " + "p.proacl, " + "acldefault('f', p.proowner) AS acldefault, " + "p.pronamespace, " + "p.proowner " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s" + "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " + "WHERE classid = 'pg_proc'::regclass AND " + "objid = p.oid AND deptype = 'i')" + "\n AND (" + "\n pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog')" + "\n OR EXISTS (SELECT 1 FROM pg_cast" + "\n WHERE pg_cast.oid > %u " + "\n AND p.oid = pg_cast.castfunc)" + "\n OR EXISTS (SELECT 1 FROM pg_transform" + "\n WHERE pg_transform.oid > %u AND " + "\n (p.oid = pg_transform.trffromsql" + "\n OR p.oid = pg_transform.trftosql))", + not_agg_check, + g_last_builtin_oid, + g_last_builtin_oid); + if (dopt->binary_upgrade) appendPQExpBufferStr(query, - "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); - appendPQExpBufferChar(query, ')'); + "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferStr(query, + "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -7252,31 +7251,31 @@ getTables(Archive *fout, int *numTables) appendPQExpBufferStr(query, "c.relhasoids, "); - appendPQExpBufferStr(query, - "c.relispopulated, "); + appendPQExpBufferStr(query, + "c.relispopulated, "); - appendPQExpBufferStr(query, - "c.relreplident, "); + appendPQExpBufferStr(query, + "c.relreplident, "); - appendPQExpBufferStr(query, - "c.relrowsecurity, c.relforcerowsecurity, "); + appendPQExpBufferStr(query, + "c.relrowsecurity, c.relforcerowsecurity, "); - appendPQExpBufferStr(query, - "c.relminmxid, tc.relminmxid AS tminmxid, "); + appendPQExpBufferStr(query, + "c.relminmxid, tc.relminmxid AS tminmxid, "); - appendPQExpBufferStr(query, - "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); + appendPQExpBufferStr(query, + "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); - appendPQExpBufferStr(query, - "am.amname, "); + appendPQExpBufferStr(query, + "am.amname, "); - appendPQExpBufferStr(query, - "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); + appendPQExpBufferStr(query, + "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); - appendPQExpBufferStr(query, - "c.relispartition AS ispartition "); + appendPQExpBufferStr(query, + "c.relispartition AS ispartition "); /* * Left join to pg_depend to pick up dependency info linking sequences to @@ -7296,8 +7295,8 @@ getTables(Archive *fout, int *numTables) /* * Left join to pg_am to pick up the amname. */ - appendPQExpBufferStr(query, - "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); + appendPQExpBufferStr(query, + "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); /* * We purposefully ignore toast OIDs for partitioned tables; the reason is @@ -7868,8 +7867,8 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables) "t.reloptions AS indreloptions, "); - appendPQExpBufferStr(query, - "i.indisreplident, "); + appendPQExpBufferStr(query, + "i.indisreplident, "); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -9313,8 +9312,8 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables) appendPQExpBufferStr(q, "'' AS attcompression,\n"); - appendPQExpBufferStr(q, - "a.attidentity,\n"); + appendPQExpBufferStr(q, + "a.attidentity,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(q, @@ -10717,73 +10716,73 @@ getAdditionalACLs(Archive *fout) PQclear(res); /* Fetch initial-privileges data */ - printfPQExpBuffer(query, - "SELECT objoid, classoid, objsubid, privtype, initprivs " - "FROM pg_init_privs"); + printfPQExpBuffer(query, + "SELECT objoid, classoid, objsubid, privtype, initprivs " + "FROM pg_init_privs"); - res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); + res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); - ntups = PQntuples(res); - for (i = 0; i < ntups; i++) - { - Oid objoid = atooid(PQgetvalue(res, i, 0)); - Oid classoid = atooid(PQgetvalue(res, i, 1)); - int objsubid = atoi(PQgetvalue(res, i, 2)); - char privtype = *(PQgetvalue(res, i, 3)); - char *initprivs = PQgetvalue(res, i, 4); - CatalogId objId; - DumpableObject *dobj; + ntups = PQntuples(res); + for (i = 0; i < ntups; i++) + { + Oid objoid = atooid(PQgetvalue(res, i, 0)); + Oid classoid = atooid(PQgetvalue(res, i, 1)); + int objsubid = atoi(PQgetvalue(res, i, 2)); + char privtype = *(PQgetvalue(res, i, 3)); + char *initprivs = PQgetvalue(res, i, 4); + CatalogId objId; + DumpableObject *dobj; - objId.tableoid = classoid; - objId.oid = objoid; - dobj = findObjectByCatalogId(objId); - /* OK to ignore entries we haven't got a DumpableObject for */ - if (dobj) + objId.tableoid = classoid; + objId.oid = objoid; + dobj = findObjectByCatalogId(objId); + /* OK to ignore entries we haven't got a DumpableObject for */ + if (dobj) + { + /* Cope with sub-object initprivs */ + if (objsubid != 0) { - /* Cope with sub-object initprivs */ - if (objsubid != 0) - { - if (dobj->objType == DO_TABLE) - { - /* For a column initprivs, set the table's ACL flags */ - dobj->components |= DUMP_COMPONENT_ACL; - ((TableInfo *) dobj)->hascolumnACLs = true; - } - else - pg_log_warning("unsupported pg_init_privs entry: %u %u %d", - classoid, objoid, objsubid); - continue; - } - - /* - * We ignore any pg_init_privs.initprivs entry for the public - * schema, as explained in getNamespaces(). - */ - if (dobj->objType == DO_NAMESPACE && - strcmp(dobj->name, "public") == 0) - continue; - - /* Else it had better be of a type we think has ACLs */ - if (dobj->objType == DO_NAMESPACE || - dobj->objType == DO_TYPE || - dobj->objType == DO_FUNC || - dobj->objType == DO_AGG || - dobj->objType == DO_TABLE || - dobj->objType == DO_PROCLANG || - dobj->objType == DO_FDW || - dobj->objType == DO_FOREIGN_SERVER) + if (dobj->objType == DO_TABLE) { - DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; - - daobj->dacl.privtype = privtype; - daobj->dacl.initprivs = pstrdup(initprivs); + /* For a column initprivs, set the table's ACL flags */ + dobj->components |= DUMP_COMPONENT_ACL; + ((TableInfo *) dobj)->hascolumnACLs = true; } else pg_log_warning("unsupported pg_init_privs entry: %u %u %d", classoid, objoid, objsubid); + continue; + } + + /* + * We ignore any pg_init_privs.initprivs entry for the public + * schema, as explained in getNamespaces(). + */ + if (dobj->objType == DO_NAMESPACE && + strcmp(dobj->name, "public") == 0) + continue; + + /* Else it had better be of a type we think has ACLs */ + if (dobj->objType == DO_NAMESPACE || + dobj->objType == DO_TYPE || + dobj->objType == DO_FUNC || + dobj->objType == DO_AGG || + dobj->objType == DO_TABLE || + dobj->objType == DO_PROCLANG || + dobj->objType == DO_FDW || + dobj->objType == DO_FOREIGN_SERVER) + { + DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; + + daobj->dacl.privtype = privtype; + daobj->dacl.initprivs = pstrdup(initprivs); } + else + pg_log_warning("unsupported pg_init_privs entry: %u %u %d", + classoid, objoid, objsubid); } - PQclear(res); + } + PQclear(res); destroyPQExpBuffer(query); } @@ -11128,8 +11127,8 @@ dumpRelationStats_dumper(Archive *fout, const void *userArg, const TocEntry *te) * The results must be in the order of the relations supplied in the * parameters to ensure we remain in sync as we walk through the TOC. * - * For versions before 19, the redundant filter clause on s.tablename = - * ANY(...) seems sufficient to convince the planner to use + * For versions before 19, the redundant filter clause on s.tablename + * = ANY(...) seems sufficient to convince the planner to use * pg_class_relname_nsp_index, which avoids a full scan of pg_stats. * In newer versions, pg_stats returns the table OIDs, eliminating the * need for that hack. @@ -13469,11 +13468,11 @@ dumpFunc(Archive *fout, const FuncInfo *finfo) "pg_catalog.pg_get_function_result(p.oid) AS funcresult,\n" "proleakproof,\n"); - appendPQExpBufferStr(query, - "array_to_string(protrftypes, ' ') AS protrftypes,\n"); + appendPQExpBufferStr(query, + "array_to_string(protrftypes, ' ') AS protrftypes,\n"); - appendPQExpBufferStr(query, - "proparallel,\n"); + appendPQExpBufferStr(query, + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -14963,9 +14962,9 @@ dumpCollation(Archive *fout, const CollInfo *collinfo) /* Get collation-specific details */ appendPQExpBufferStr(query, "SELECT "); - appendPQExpBufferStr(query, - "collprovider, " - "collversion, "); + appendPQExpBufferStr(query, + "collprovider, " + "collversion, "); if (fout->remoteVersion >= 120000) appendPQExpBufferStr(query, @@ -15372,23 +15371,23 @@ dumpAgg(Archive *fout, const AggInfo *agginfo) "pg_catalog.pg_get_function_arguments(p.oid) AS funcargs,\n" "pg_catalog.pg_get_function_identity_arguments(p.oid) AS funciargs,\n"); - appendPQExpBufferStr(query, - "aggkind,\n" - "aggmtransfn,\n" - "aggminvtransfn,\n" - "aggmfinalfn,\n" - "aggmtranstype::pg_catalog.regtype,\n" - "aggfinalextra,\n" - "aggmfinalextra,\n" - "aggtransspace,\n" - "aggmtransspace,\n" - "aggminitval,\n"); + appendPQExpBufferStr(query, + "aggkind,\n" + "aggmtransfn,\n" + "aggminvtransfn,\n" + "aggmfinalfn,\n" + "aggmtranstype::pg_catalog.regtype,\n" + "aggfinalextra,\n" + "aggmfinalextra,\n" + "aggtransspace,\n" + "aggmtransspace,\n" + "aggminitval,\n"); - appendPQExpBufferStr(query, - "aggcombinefn,\n" - "aggserialfn,\n" - "aggdeserialfn,\n" - "proparallel,\n"); + appendPQExpBufferStr(query, + "aggcombinefn,\n" + "aggserialfn,\n" + "aggdeserialfn,\n" + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -16848,30 +16847,30 @@ dumpTable(Archive *fout, const TableInfo *tbinfo) appendPQExpBufferStr(query, "PREPARE getColumnACLs(pg_catalog.oid) AS\n"); - /* - * In principle we should call acldefault('c', relowner) to - * get the default ACL for a column. However, we don't - * currently store the numeric OID of the relowner in - * TableInfo. We could convert the owner name using regrole, - * but that creates a risk of failure due to concurrent role - * renames. Given that the default ACL for columns is empty - * and is likely to stay that way, it's not worth extra cycles - * and risk to avoid hard-wiring that knowledge here. - */ - appendPQExpBufferStr(query, - "SELECT at.attname, " - "at.attacl, " - "'{}' AS acldefault, " - "pip.privtype, pip.initprivs " - "FROM pg_catalog.pg_attribute at " - "LEFT JOIN pg_catalog.pg_init_privs pip ON " - "(at.attrelid = pip.objoid " - "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " - "AND at.attnum = pip.objsubid) " - "WHERE at.attrelid = $1 AND " - "NOT at.attisdropped " - "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " - "ORDER BY at.attnum"); + /* + * In principle we should call acldefault('c', relowner) to get + * the default ACL for a column. However, we don't currently + * store the numeric OID of the relowner in TableInfo. We could + * convert the owner name using regrole, but that creates a risk + * of failure due to concurrent role renames. Given that the + * default ACL for columns is empty and is likely to stay that + * way, it's not worth extra cycles and risk to avoid hard-wiring + * that knowledge here. + */ + appendPQExpBufferStr(query, + "SELECT at.attname, " + "at.attacl, " + "'{}' AS acldefault, " + "pip.privtype, pip.initprivs " + "FROM pg_catalog.pg_attribute at " + "LEFT JOIN pg_catalog.pg_init_privs pip ON " + "(at.attrelid = pip.objoid " + "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " + "AND at.attnum = pip.objsubid) " + "WHERE at.attrelid = $1 AND " + "NOT at.attisdropped " + "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " + "ORDER BY at.attnum"); ExecuteSqlStatement(fout, query->data); @@ -19165,7 +19164,7 @@ collectSequences(Archive *fout) * pg_get_sequence_data(), but we only do so for non-schema-only dumps. */ if (fout->remoteVersion < 180000 || - (!fout->dopt->dumpData && !fout->dopt->sequence_data)) + (!fout->dopt->dumpData && !fout->dopt->sequence_data)) query = "SELECT seqrelid, format_type(seqtypid, NULL), " "seqstart, seqincrement, " "seqmax, seqmin, " @@ -19227,15 +19226,14 @@ dumpSequence(Archive *fout, const TableInfo *tbinfo) qseqname = pg_strdup(fmtId(tbinfo->dobj.name)); /* - * The sequence information is gathered in a sorted - * table before any calls to dumpSequence(). See collectSequences() for - * more information. + * The sequence information is gathered in a sorted table before any calls + * to dumpSequence(). See collectSequences() for more information. */ - Assert(sequences); + Assert(sequences); - key.oid = tbinfo->dobj.catId.oid; - seq = bsearch(&key, sequences, nsequences, - sizeof(SequenceItem), SequenceItemCmp); + key.oid = tbinfo->dobj.catId.oid; + seq = bsearch(&key, sequences, nsequences, + sizeof(SequenceItem), SequenceItemCmp); /* Calculate default limits for a sequence of this type */ is_ascending = (seq->incby >= 0); diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c index e68937c9934..afcd9a218d8 100644 --- a/src/bin/pg_dump/pg_dumpall.c +++ b/src/bin/pg_dump/pg_dumpall.c @@ -785,11 +785,11 @@ dropRoles(PGconn *conn) int i_rolname; int i; - printfPQExpBuffer(buf, - "SELECT rolname " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 1", role_catalog); + printfPQExpBuffer(buf, + "SELECT rolname " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 1", role_catalog); res = executeQuery(conn, buf->data); @@ -843,16 +843,16 @@ dumpRoles(PGconn *conn) * Notes: rolconfig is dumped later, and pg_authid must be used for * extracting rolcomment regardless of role_catalog. */ - printfPQExpBuffer(buf, - "SELECT oid, rolname, rolsuper, rolinherit, " - "rolcreaterole, rolcreatedb, " - "rolcanlogin, rolconnlimit, rolpassword, " - "rolvaliduntil, rolreplication, rolbypassrls, " - "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " - "rolname = current_user AS is_current_user " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 2", role_catalog); + printfPQExpBuffer(buf, + "SELECT oid, rolname, rolsuper, rolinherit, " + "rolcreaterole, rolcreatedb, " + "rolcanlogin, rolconnlimit, rolpassword, " + "rolvaliduntil, rolreplication, rolbypassrls, " + "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " + "rolname = current_user AS is_current_user " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 2", role_catalog); res = executeQuery(conn, buf->data); diff --git a/src/bin/pg_upgrade/check.c b/src/bin/pg_upgrade/check.c index 786c1474829..f725f5ee3e2 100644 --- a/src/bin/pg_upgrade/check.c +++ b/src/bin/pg_upgrade/check.c @@ -1475,15 +1475,15 @@ check_for_incompatible_polymorphics(ClusterInfo *cluster) ", 'array_cat(anyarray,anyarray)'" ", 'array_prepend(anyelement,anyarray)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_remove(anyarray,anyelement)'" - ", 'array_replace(anyarray,anyelement,anyelement)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_remove(anyarray,anyelement)'" + ", 'array_replace(anyarray,anyelement,anyelement)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_position(anyarray,anyelement)'" - ", 'array_position(anyarray,anyelement,integer)'" - ", 'array_positions(anyarray,anyelement)'" - ", 'width_bucket(anyelement,anyarray)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_position(anyarray,anyelement)'" + ", 'array_position(anyarray,anyelement,integer)'" + ", 'array_positions(anyarray,anyelement)'" + ", 'width_bucket(anyelement,anyarray)'"); /* * The query below hardcodes FirstNormalObjectId as 16384 rather than diff --git a/src/bin/pg_upgrade/controldata.c b/src/bin/pg_upgrade/controldata.c index 8f81c9e9582..02ea02df60f 100644 --- a/src/bin/pg_upgrade/controldata.c +++ b/src/bin/pg_upgrade/controldata.c @@ -228,7 +228,7 @@ get_control_data(ClusterInfo *cluster) p++; /* remove ':' char */ cluster->controldata.chkpnt_nxtepoch = str2uint(p); - p = strchr(p, ':'); + p = strchr(p, ':'); if (p == NULL || strlen(p) <= 1) pg_fatal("%d: controldata retrieval problem", __LINE__); diff --git a/src/bin/pg_upgrade/exec.c b/src/bin/pg_upgrade/exec.c index 44355feea30..a1bdbf373e3 100644 --- a/src/bin/pg_upgrade/exec.c +++ b/src/bin/pg_upgrade/exec.c @@ -55,7 +55,7 @@ get_bin_version(ClusterInfo *cluster) if (sscanf(cmd_output, "%*s %*s %d.%d", &v1, &v2) < 1) pg_fatal("could not get pg_ctl version output from %s", cmd); - cluster->bin_version = v1 * 10000; + cluster->bin_version = v1 * 10000; } @@ -344,8 +344,8 @@ check_data_dir(ClusterInfo *cluster) check_single_dir(pg_data, "pg_subtrans"); check_single_dir(pg_data, PG_TBLSPC_DIR); check_single_dir(pg_data, "pg_twophase"); - check_single_dir(pg_data, "pg_wal"); - check_single_dir(pg_data, "pg_xact"); + check_single_dir(pg_data, "pg_wal"); + check_single_dir(pg_data, "pg_xact"); } @@ -385,7 +385,7 @@ check_bin_dir(ClusterInfo *cluster, bool check_versions) */ get_bin_version(cluster); - check_exec(cluster->bindir, "pg_resetwal", check_versions); + check_exec(cluster->bindir, "pg_resetwal", check_versions); if (cluster == &new_cluster) { diff --git a/src/bin/pg_upgrade/multixact_rewrite.c b/src/bin/pg_upgrade/multixact_rewrite.c index c45b3183684..c7a1416494d 100644 --- a/src/bin/pg_upgrade/multixact_rewrite.c +++ b/src/bin/pg_upgrade/multixact_rewrite.c @@ -61,52 +61,52 @@ rewrite_multixacts(MultiXactId from_multi, MultiXactId to_multi) * Convert old multixids, if needed, by reading them one-by-one from the * old cluster. */ - old_reader = AllocOldMultiXactRead(old_cluster.pgdata, - old_cluster.controldata.chkpnt_nxtmulti, - old_cluster.controldata.chkpnt_nxtmxoff); + old_reader = AllocOldMultiXactRead(old_cluster.pgdata, + old_cluster.controldata.chkpnt_nxtmulti, + old_cluster.controldata.chkpnt_nxtmxoff); - for (MultiXactId multi = from_multi; multi != to_multi;) - { - MultiXactMember member; - bool multixid_valid; - - /* - * Read this multixid's members. - * - * Locking-only XIDs that may be part of multi-xids don't matter - * after upgrade, as there can be no transactions running across - * upgrade. So as a small optimization, we only read one member - * from each multixid: the one updating one, or if there was no - * update, arbitrarily the first locking xid. - */ - multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); + for (MultiXactId multi = from_multi; multi != to_multi;) + { + MultiXactMember member; + bool multixid_valid; - /* - * Write the new offset to pg_multixact/offsets. - * - * Even if this multixid is invalid, we still need to write its - * offset if the *previous* multixid was valid. That's because - * when reading a multixid, the number of members is calculated - * from the difference between the two offsets. - */ - RecordMultiXactOffset(offsets_writer, multi, - (multixid_valid || prev_multixid_valid) ? next_offset : 0); + /* + * Read this multixid's members. + * + * Locking-only XIDs that may be part of multi-xids don't matter after + * upgrade, as there can be no transactions running across upgrade. So + * as a small optimization, we only read one member from each + * multixid: the one updating one, or if there was no update, + * arbitrarily the first locking xid. + */ + multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); - /* Write the members */ - if (multixid_valid) - { - RecordMultiXactMembers(members_writer, next_offset, 1, &member); - next_offset += 1; - } + /* + * Write the new offset to pg_multixact/offsets. + * + * Even if this multixid is invalid, we still need to write its offset + * if the *previous* multixid was valid. That's because when reading + * a multixid, the number of members is calculated from the difference + * between the two offsets. + */ + RecordMultiXactOffset(offsets_writer, multi, + (multixid_valid || prev_multixid_valid) ? next_offset : 0); - /* Advance to next multixid, handling wraparound */ - multi++; - if (multi < FirstMultiXactId) - multi = FirstMultiXactId; - prev_multixid_valid = multixid_valid; + /* Write the members */ + if (multixid_valid) + { + RecordMultiXactMembers(members_writer, next_offset, 1, &member); + next_offset += 1; } - FreeOldMultiXactReader(old_reader); + /* Advance to next multixid, handling wraparound */ + multi++; + if (multi < FirstMultiXactId) + multi = FirstMultiXactId; + prev_multixid_valid = multixid_valid; + } + + FreeOldMultiXactReader(old_reader); /* Write the final 'next' offset to the last SLRU page */ RecordMultiXactOffset(offsets_writer, to_multi, diff --git a/src/bin/pg_upgrade/pg_upgrade.c b/src/bin/pg_upgrade/pg_upgrade.c index c6af9035665..7366fd4627c 100644 --- a/src/bin/pg_upgrade/pg_upgrade.c +++ b/src/bin/pg_upgrade/pg_upgrade.c @@ -833,7 +833,7 @@ copy_xact_xlog_xid(void) * Determine the range of multixacts to convert. */ nxtmulti = old_cluster.controldata.chkpnt_nxtmulti; - oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; + oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; /* handle wraparound */ if (nxtmulti < FirstMultiXactId) nxtmulti = FirstMultiXactId; @@ -898,15 +898,15 @@ set_frozenxids(void) int i_datname; int i_datallowconn; - prep_status("Setting frozenxid and minmxid counters in new cluster"); + prep_status("Setting frozenxid and minmxid counters in new cluster"); conn_template1 = connectToServer(&new_cluster, "template1"); - /* set pg_database.datfrozenxid */ - PQclear(executeQueryOrDie(conn_template1, - "UPDATE pg_catalog.pg_database " - "SET datfrozenxid = '%u'", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_database.datfrozenxid */ + PQclear(executeQueryOrDie(conn_template1, + "UPDATE pg_catalog.pg_database " + "SET datfrozenxid = '%u'", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_database.datminmxid */ PQclear(executeQueryOrDie(conn_template1, @@ -942,16 +942,16 @@ set_frozenxids(void) conn = connectToServer(&new_cluster, datname); - /* set pg_class.relfrozenxid */ - PQclear(executeQueryOrDie(conn, - "UPDATE pg_catalog.pg_class " - "SET relfrozenxid = '%u' " - /* only heap, materialized view, and TOAST are vacuumed */ - "WHERE relkind IN (" - CppAsString2(RELKIND_RELATION) ", " - CppAsString2(RELKIND_MATVIEW) ", " - CppAsString2(RELKIND_TOASTVALUE) ")", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_class.relfrozenxid */ + PQclear(executeQueryOrDie(conn, + "UPDATE pg_catalog.pg_class " + "SET relfrozenxid = '%u' " + /* only heap, materialized view, and TOAST are vacuumed */ + "WHERE relkind IN (" + CppAsString2(RELKIND_RELATION) ", " + CppAsString2(RELKIND_MATVIEW) ", " + CppAsString2(RELKIND_TOASTVALUE) ")", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_class.relminmxid */ PQclear(executeQueryOrDie(conn, diff --git a/src/bin/pg_upgrade/relfilenumber.c b/src/bin/pg_upgrade/relfilenumber.c index ec2ff7acb21..6c467bdc8a5 100644 --- a/src/bin/pg_upgrade/relfilenumber.c +++ b/src/bin/pg_upgrade/relfilenumber.c @@ -587,32 +587,32 @@ transfer_relfile(FileNameMap *map, const char *type_suffix) /* Copying files might take some time, so give feedback. */ pg_log(PG_STATUS, "%s", old_file); - switch (user_opts.transfer_mode) - { - case TRANSFER_MODE_CLONE: - pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", - old_file, new_file); - cloneFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", - old_file, new_file); - copyFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY_FILE_RANGE: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", - old_file, new_file); - copyFileByRange(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_LINK: - pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", - old_file, new_file); - linkFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_SWAP: - /* swap mode is handled in its own code path */ - pg_fatal("should never happen"); - break; - } + switch (user_opts.transfer_mode) + { + case TRANSFER_MODE_CLONE: + pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", + old_file, new_file); + cloneFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", + old_file, new_file); + copyFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY_FILE_RANGE: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", + old_file, new_file); + copyFileByRange(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_LINK: + pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", + old_file, new_file); + linkFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_SWAP: + /* swap mode is handled in its own code path */ + pg_fatal("should never happen"); + break; + } } } diff --git a/src/bin/pg_upgrade/t/006_transfer_modes.pl b/src/bin/pg_upgrade/t/006_transfer_modes.pl index 9efa5dc863c..360d05c4b68 100644 --- a/src/bin/pg_upgrade/t/006_transfer_modes.pl +++ b/src/bin/pg_upgrade/t/006_transfer_modes.pl @@ -29,10 +29,8 @@ sub test_mode } $new->init(); - $new->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); - $old->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); + $new->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); + $old->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); # We can only test security labels if both the old and new installations # have dummy_seclabel. @@ -76,15 +74,14 @@ sub test_mode "CREATE TABLE test4 AS SELECT generate_series(400, 502)"); } - $old->safe_psql('postgres', - "CREATE TABLESPACE inplc_tblspc LOCATION ''"); - $old->safe_psql('postgres', - "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); - $old->safe_psql('postgres', - "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" - ); - $old->safe_psql('testdb3', - "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); + $old->safe_psql('postgres', "CREATE TABLESPACE inplc_tblspc LOCATION ''"); + $old->safe_psql('postgres', + "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); + $old->safe_psql('postgres', + "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" + ); + $old->safe_psql('testdb3', + "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); # While we are here, test handling of large objects. $old->safe_psql( @@ -152,12 +149,10 @@ sub test_mode } # Tests for in-place tablespaces. - $result = - $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); - is($result, '104', "test5 data after pg_upgrade $mode"); - $result = - $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); - is($result, '105', "test6 data after pg_upgrade $mode"); + $result = $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); + is($result, '104', "test5 data after pg_upgrade $mode"); + $result = $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); + is($result, '105', "test6 data after pg_upgrade $mode"); # Tests for large objects $result = $new->safe_psql('postgres', "SELECT lo_get(4532)"); diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index 44ef11d980e..c90bf8bbde2 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -6278,23 +6278,22 @@ get_create_object_cmd(EditableObjectType obj_type, Oid oid, * ensure the right view gets replaced. Also, check relation kind * to be sure it's a view. * - * Views may have WITH [LOCAL|CASCADED] - * CHECK OPTION. These are not part of the view definition - * returned by pg_get_viewdef() and so need to be retrieved - * separately. Materialized views may have - * arbitrary storage parameter reloptions. + * Views may have WITH [LOCAL|CASCADED] CHECK OPTION. These are + * not part of the view definition returned by pg_get_viewdef() + * and so need to be retrieved separately. Materialized views may + * have arbitrary storage parameter reloptions. */ printfPQExpBuffer(query, "/* %s */\n", _("Get view's definition and details")); - appendPQExpBuffer(query, - "SELECT nspname, relname, relkind, " - "pg_catalog.pg_get_viewdef(c.oid, true), " - "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " - "FROM pg_catalog.pg_class c " - "LEFT JOIN pg_catalog.pg_namespace n " - "ON c.relnamespace = n.oid WHERE c.oid = %u", - oid); + appendPQExpBuffer(query, + "SELECT nspname, relname, relkind, " + "pg_catalog.pg_get_viewdef(c.oid, true), " + "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " + "FROM pg_catalog.pg_class c " + "LEFT JOIN pg_catalog.pg_namespace n " + "ON c.relnamespace = n.oid WHERE c.oid = %u", + oid); break; } diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index ce99137c613..ac0c55e7aa5 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -387,19 +387,19 @@ describeFunctions(const char *functypes, const char *func_pattern, gettext_noop("stable"), gettext_noop("volatile"), gettext_noop("Volatility")); - appendPQExpBuffer(&buf, - ",\n CASE\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" - " END as \"%s\"", - gettext_noop("restricted"), - gettext_noop("safe"), - gettext_noop("unsafe"), - gettext_noop("Parallel")); + appendPQExpBuffer(&buf, + ",\n CASE\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" + " END as \"%s\"", + gettext_noop("restricted"), + gettext_noop("safe"), + gettext_noop("unsafe"), + gettext_noop("Parallel")); appendPQExpBuffer(&buf, ",\n pg_catalog.pg_get_userbyid(p.proowner) as \"%s\"" ",\n CASE WHEN prosecdef THEN '%s' ELSE '%s' END AS \"%s\"" @@ -599,8 +599,8 @@ describeFunctions(const char *functypes, const char *func_pattern, myopt.title = _("List of functions"); myopt.translate_header = true; - myopt.translate_columns = translate_columns; - myopt.n_translate_columns = lengthof(translate_columns); + myopt.translate_columns = translate_columns; + myopt.n_translate_columns = lengthof(translate_columns); printQuery(res, &myopt, pset.queryFout, false, pset.logfile); @@ -1086,38 +1086,38 @@ permissionsList(const char *pattern, bool showSystem) " ), E'\\n') AS \"%s\"", gettext_noop("Column privileges")); - appendPQExpBuffer(&buf, - ",\n pg_catalog.array_to_string(ARRAY(\n" - " SELECT polname\n" - " || CASE WHEN NOT polpermissive THEN\n" - " E' (RESTRICTIVE)'\n" - " ELSE '' END\n" - " || CASE WHEN polcmd != '*' THEN\n" - " E' (' || polcmd::pg_catalog.text || E'):'\n" - " ELSE E':'\n" - " END\n" - " || CASE WHEN polqual IS NOT NULL THEN\n" - " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" - " ELSE E''\n" - " END\n" - " || CASE WHEN polwithcheck IS NOT NULL THEN\n" - " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" - " ELSE E''\n" - " END" - " || CASE WHEN polroles <> '{0}' THEN\n" - " E'\\n to: ' || pg_catalog.array_to_string(\n" - " ARRAY(\n" - " SELECT rolname\n" - " FROM pg_catalog.pg_roles\n" - " WHERE oid = ANY (polroles)\n" - " ORDER BY 1\n" - " ), E', ')\n" - " ELSE E''\n" - " END\n" - " FROM pg_catalog.pg_policy pol\n" - " WHERE polrelid = c.oid), E'\\n')\n" - " AS \"%s\"", - gettext_noop("Policies")); + appendPQExpBuffer(&buf, + ",\n pg_catalog.array_to_string(ARRAY(\n" + " SELECT polname\n" + " || CASE WHEN NOT polpermissive THEN\n" + " E' (RESTRICTIVE)'\n" + " ELSE '' END\n" + " || CASE WHEN polcmd != '*' THEN\n" + " E' (' || polcmd::pg_catalog.text || E'):'\n" + " ELSE E':'\n" + " END\n" + " || CASE WHEN polqual IS NOT NULL THEN\n" + " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" + " ELSE E''\n" + " END\n" + " || CASE WHEN polwithcheck IS NOT NULL THEN\n" + " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" + " ELSE E''\n" + " END" + " || CASE WHEN polroles <> '{0}' THEN\n" + " E'\\n to: ' || pg_catalog.array_to_string(\n" + " ARRAY(\n" + " SELECT rolname\n" + " FROM pg_catalog.pg_roles\n" + " WHERE oid = ANY (polroles)\n" + " ORDER BY 1\n" + " ), E', ')\n" + " ELSE E''\n" + " END\n" + " FROM pg_catalog.pg_policy pol\n" + " WHERE polrelid = c.oid), E'\\n')\n" + " AS \"%s\"", + gettext_noop("Policies")); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_class c\n" " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n" @@ -1675,27 +1675,27 @@ describeOneTableDetails(const char *schemaname, char *footers[3] = {NULL, NULL, NULL}; printfPQExpBuffer(&buf, "/* %s */\n", _("Get sequence information")); - appendPQExpBuffer(&buf, - "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" - " seqstart AS \"%s\",\n" - " seqmin AS \"%s\",\n" - " seqmax AS \"%s\",\n" - " seqincrement AS \"%s\",\n" - " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" - " seqcache AS \"%s\"\n", - gettext_noop("Type"), - gettext_noop("Start"), - gettext_noop("Minimum"), - gettext_noop("Maximum"), - gettext_noop("Increment"), - gettext_noop("yes"), - gettext_noop("no"), - gettext_noop("Cycles?"), - gettext_noop("Cache")); - appendPQExpBuffer(&buf, - "FROM pg_catalog.pg_sequence\n" - "WHERE seqrelid = '%s';", - oid); + appendPQExpBuffer(&buf, + "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" + " seqstart AS \"%s\",\n" + " seqmin AS \"%s\",\n" + " seqmax AS \"%s\",\n" + " seqincrement AS \"%s\",\n" + " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" + " seqcache AS \"%s\"\n", + gettext_noop("Type"), + gettext_noop("Start"), + gettext_noop("Minimum"), + gettext_noop("Maximum"), + gettext_noop("Increment"), + gettext_noop("yes"), + gettext_noop("no"), + gettext_noop("Cycles?"), + gettext_noop("Cache")); + appendPQExpBuffer(&buf, + "FROM pg_catalog.pg_sequence\n" + "WHERE seqrelid = '%s';", + oid); res = PSQLexec(buf.data); if (!res) @@ -1913,7 +1913,7 @@ describeOneTableDetails(const char *schemaname, appendPQExpBufferStr(&buf, ",\n (SELECT c.collname FROM pg_catalog.pg_collation c, pg_catalog.pg_type t\n" " WHERE c.oid = a.attcollation AND t.oid = a.atttypid AND a.attcollation <> t.typcollation) AS attcollation"); attcoll_col = cols++; - appendPQExpBufferStr(&buf, ",\n a.attidentity"); + appendPQExpBufferStr(&buf, ",\n a.attidentity"); attidentity_col = cols++; if (pset.sversion >= 120000) appendPQExpBufferStr(&buf, ",\n a.attgenerated"); @@ -2326,7 +2326,7 @@ describeOneTableDetails(const char *schemaname, CppAsString2(CONSTRAINT_EXCLUSION) ") AND " "condeferred) AS condeferred,\n"); - appendPQExpBufferStr(&buf, "i.indisreplident,\n"); + appendPQExpBufferStr(&buf, "i.indisreplident,\n"); if (pset.sversion >= 150000) appendPQExpBufferStr(&buf, "i.indnullsnotdistinct,\n"); @@ -2431,7 +2431,7 @@ describeOneTableDetails(const char *schemaname, "pg_catalog.pg_get_indexdef(i.indexrelid, 0, true),\n " "pg_catalog.pg_get_constraintdef(con.oid, true), " "contype, condeferrable, condeferred"); - appendPQExpBufferStr(&buf, ", i.indisreplident"); + appendPQExpBufferStr(&buf, ", i.indisreplident"); appendPQExpBufferStr(&buf, ", c2.reltablespace"); if (pset.sversion >= 180000) appendPQExpBufferStr(&buf, ", con.conperiod"); @@ -2682,81 +2682,80 @@ describeOneTableDetails(const char *schemaname, PQclear(result); /* print any row-level policies */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get row-level policies for this table")); - appendPQExpBufferStr(&buf, "SELECT pol.polname,"); - appendPQExpBufferStr(&buf, - " pol.polpermissive,\n"); - appendPQExpBuffer(&buf, - " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" - " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" - " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" - " CASE pol.polcmd\n" - " WHEN 'r' THEN 'SELECT'\n" - " WHEN 'a' THEN 'INSERT'\n" - " WHEN 'w' THEN 'UPDATE'\n" - " WHEN 'd' THEN 'DELETE'\n" - " END AS cmd\n" - "FROM pg_catalog.pg_policy pol\n" - "WHERE pol.polrelid = '%s' ORDER BY 1;", - oid); + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get row-level policies for this table")); + appendPQExpBufferStr(&buf, "SELECT pol.polname,"); + appendPQExpBufferStr(&buf, + " pol.polpermissive,\n"); + appendPQExpBuffer(&buf, + " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" + " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" + " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" + " CASE pol.polcmd\n" + " WHEN 'r' THEN 'SELECT'\n" + " WHEN 'a' THEN 'INSERT'\n" + " WHEN 'w' THEN 'UPDATE'\n" + " WHEN 'd' THEN 'DELETE'\n" + " END AS cmd\n" + "FROM pg_catalog.pg_policy pol\n" + "WHERE pol.polrelid = '%s' ORDER BY 1;", + oid); - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - /* - * Handle cases where RLS is enabled and there are policies, or - * there aren't policies, or RLS isn't enabled but there are - * policies - */ - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies:")); + /* + * Handle cases where RLS is enabled and there are policies, or there + * aren't policies, or RLS isn't enabled but there are policies + */ + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies:")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled):")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled):")); - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); - if (!tableinfo.rowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (row security disabled):")); + if (!tableinfo.rowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (row security disabled):")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " POLICY \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " POLICY \"%s\"", + PQgetvalue(result, i, 0)); - if (*(PQgetvalue(result, i, 1)) == 'f') - appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); + if (*(PQgetvalue(result, i, 1)) == 'f') + appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); - if (!PQgetisnull(result, i, 5)) - appendPQExpBuffer(&buf, " FOR %s", - PQgetvalue(result, i, 5)); + if (!PQgetisnull(result, i, 5)) + appendPQExpBuffer(&buf, " FOR %s", + PQgetvalue(result, i, 5)); - if (!PQgetisnull(result, i, 2)) - { - appendPQExpBuffer(&buf, "\n TO %s", - PQgetvalue(result, i, 2)); - } + if (!PQgetisnull(result, i, 2)) + { + appendPQExpBuffer(&buf, "\n TO %s", + PQgetvalue(result, i, 2)); + } - if (!PQgetisnull(result, i, 3)) - appendPQExpBuffer(&buf, "\n USING (%s)", - PQgetvalue(result, i, 3)); + if (!PQgetisnull(result, i, 3)) + appendPQExpBuffer(&buf, "\n USING (%s)", + PQgetvalue(result, i, 3)); - if (!PQgetisnull(result, i, 4)) - appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", - PQgetvalue(result, i, 4)); + if (!PQgetisnull(result, i, 4)) + appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", + PQgetvalue(result, i, 4)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* print any extended statistics */ if (pset.sversion >= 140000) @@ -3025,115 +3024,115 @@ describeOneTableDetails(const char *schemaname, } /* print any publications */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get publications that publish this table")); - if (pset.sversion >= 150000) + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get publications that publish this table")); + if (pset.sversion >= 150000) + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" + " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" + "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" + "UNION\n" + "SELECT pubname\n" + " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" + " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" + " (SELECT pg_catalog.string_agg(attname, ', ')\n" + " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" + " pg_catalog.pg_attribute\n" + " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" + " ELSE NULL END) " + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" + "WHERE pr.prrelid = '%s'\n", + oid, oid, oid); + + if (pset.sversion >= 190000) { + /* + * Skip entries where this relation appears in the + * publication's EXCEPT list. + */ appendPQExpBuffer(&buf, + " AND NOT pr.prexcept\n" + "UNION\n" "SELECT pubname\n" " , NULL\n" " , NULL\n" "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" - " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" - "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" - "UNION\n" - "SELECT pubname\n" - " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" - " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" - " (SELECT pg_catalog.string_agg(attname, ', ')\n" - " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" - " pg_catalog.pg_attribute\n" - " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" - " ELSE NULL END) " - "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" - "WHERE pr.prrelid = '%s'\n", + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + " AND NOT EXISTS (\n" + " SELECT 1\n" + " FROM pg_catalog.pg_publication_rel pr\n" + " WHERE pr.prpubid = p.oid AND\n" + " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" + "ORDER BY 1;", oid, oid, oid); - - if (pset.sversion >= 190000) - { - /* - * Skip entries where this relation appears in the - * publication's EXCEPT list. - */ - appendPQExpBuffer(&buf, - " AND NOT pr.prexcept\n" - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - " AND NOT EXISTS (\n" - " SELECT 1\n" - " FROM pg_catalog.pg_publication_rel pr\n" - " WHERE pr.prpubid = p.oid AND\n" - " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" - "ORDER BY 1;", - oid, oid, oid); - } - else - { - appendPQExpBuffer(&buf, - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - "ORDER BY 1;", - oid); - } } else { appendPQExpBuffer(&buf, + "UNION\n" "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - "WHERE pr.prrelid = '%s'\n" - "UNION ALL\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" + " , NULL\n" + " , NULL\n" "FROM pg_catalog.pg_publication p\n" "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" "ORDER BY 1;", - oid, oid); + oid); } + } + else + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + "WHERE pr.prrelid = '%s'\n" + "UNION ALL\n" + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + "ORDER BY 1;", + oid, oid); + } - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - if (tuples > 0) - printTableAddFooter(&cont, _("Included in publications:")); + if (tuples > 0) + printTableAddFooter(&cont, _("Included in publications:")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " \"%s\"", + PQgetvalue(result, i, 0)); - /* column list (if any) */ - if (!PQgetisnull(result, i, 2)) - appendPQExpBuffer(&buf, " (%s)", - PQgetvalue(result, i, 2)); + /* column list (if any) */ + if (!PQgetisnull(result, i, 2)) + appendPQExpBuffer(&buf, " (%s)", + PQgetvalue(result, i, 2)); - /* row filter (if any) */ - if (!PQgetisnull(result, i, 1)) - appendPQExpBuffer(&buf, " WHERE %s", - PQgetvalue(result, i, 1)); + /* row filter (if any) */ + if (!PQgetisnull(result, i, 1)) + appendPQExpBuffer(&buf, " WHERE %s", + PQgetvalue(result, i, 1)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* Print publications where the table is in the EXCEPT clause */ if (pset.sversion >= 190000) @@ -3805,7 +3804,7 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) ncols++; } appendPQExpBufferStr(&buf, "\n, r.rolreplication"); - appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); + appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_roles r\n"); @@ -3860,8 +3859,8 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) if (strcmp(PQgetvalue(res, i, (verbose ? 9 : 8)), "t") == 0) add_role_attribute(&buf, _("Replication")); - if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) - add_role_attribute(&buf, _("Bypass RLS")); + if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) + add_role_attribute(&buf, _("Bypass RLS")); conns = atoi(PQgetvalue(res, i, 6)); if (conns >= 0) @@ -5155,14 +5154,14 @@ listCollations(const char *pattern, bool verbose, bool showSystem) gettext_noop("Schema"), gettext_noop("Name")); - appendPQExpBuffer(&buf, - " CASE c.collprovider " - "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " - "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " - "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " - "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " - "END AS \"%s\",\n", - gettext_noop("Provider")); + appendPQExpBuffer(&buf, + " CASE c.collprovider " + "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " + "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " + "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " + "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " + "END AS \"%s\",\n", + gettext_noop("Provider")); appendPQExpBuffer(&buf, " c.collcollate AS \"%s\",\n" -- 2.50.1 (Apple Git-155) --aHl3HfeiUuO3zeNC-- ^ permalink raw reply [nested|flat] 59+ messages in thread
* [PATCH v6 4/4] run pgindent and pgperltidy @ 2026-06-30 18:24 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 59+ messages in thread From: Nathan Bossart @ 2026-06-30 18:24 UTC (permalink / raw) --- src/bin/pg_dump/pg_dump.c | 464 ++++++++++----------- src/bin/pg_dump/pg_dumpall.c | 30 +- src/bin/pg_upgrade/check.c | 16 +- src/bin/pg_upgrade/controldata.c | 2 +- src/bin/pg_upgrade/exec.c | 8 +- src/bin/pg_upgrade/multixact_rewrite.c | 80 ++-- src/bin/pg_upgrade/pg_upgrade.c | 34 +- src/bin/pg_upgrade/relfilenumber.c | 54 +-- src/bin/pg_upgrade/t/006_transfer_modes.pl | 33 +- src/bin/psql/command.c | 29 +- src/bin/psql/describe.c | 461 ++++++++++---------- 11 files changed, 601 insertions(+), 610 deletions(-) diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 65bd15ebfd2..5673268b467 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -1491,8 +1491,8 @@ setup_connection(Archive *AH, const char *dumpencoding, * Disable timeouts if supported. */ ExecuteSqlStatement(AH, "SET statement_timeout = 0"); - ExecuteSqlStatement(AH, "SET lock_timeout = 0"); - ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); + ExecuteSqlStatement(AH, "SET lock_timeout = 0"); + ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); if (AH->remoteVersion >= 170000) ExecuteSqlStatement(AH, "SET transaction_timeout = 0"); @@ -1505,10 +1505,10 @@ setup_connection(Archive *AH, const char *dumpencoding, /* * Adjust row-security mode, if supported. */ - if (dopt->enable_row_security) - ExecuteSqlStatement(AH, "SET row_security = on"); - else - ExecuteSqlStatement(AH, "SET row_security = off"); + if (dopt->enable_row_security) + ExecuteSqlStatement(AH, "SET row_security = on"); + else + ExecuteSqlStatement(AH, "SET row_security = off"); /* * For security reasons, we restrict the expansion of non-system views and @@ -1933,10 +1933,9 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) addObjectDependency(dobj, ext->dobj.dumpId); /* - * Mark the member object to have any non-initial ACLs - * dumped. (Any initial ACLs will be removed later, using data from - * pg_init_privs, so that we'll dump only the delta from the extension's - * initial setup.) + * Mark the member object to have any non-initial ACLs dumped. (Any + * initial ACLs will be removed later, using data from pg_init_privs, so + * that we'll dump only the delta from the extension's initial setup.) * * In binary upgrades, we still dump all components of the members * individually, since the idea is to exactly reproduce the database @@ -1953,7 +1952,7 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) if (fout->dopt->binary_upgrade) dobj->dump = ext->dobj.dump; else - dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); + dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); return true; } @@ -1987,9 +1986,9 @@ selectDumpableNamespace(NamespaceInfo *nsinfo, Archive *fout) else if (strcmp(nsinfo->dobj.name, "pg_catalog") == 0) { /* - * We dump out any ACLs defined in pg_catalog, if - * they are interesting (and not the original ACLs which were set at - * initdb time, see pg_init_privs). + * We dump out any ACLs defined in pg_catalog, if they are interesting + * (and not the original ACLs which were set at initdb time, see + * pg_init_privs). */ nsinfo->dobj.dump_contains = nsinfo->dobj.dump = DUMP_COMPONENT_ACL; } @@ -3296,7 +3295,7 @@ dumpDatabase(Archive *fout) "datcollate, datctype, datfrozenxid, " "datacl, acldefault('d', datdba) AS acldefault, " "datistemplate, datconnlimit, "); - appendPQExpBufferStr(dbQry, "datminmxid, "); + appendPQExpBufferStr(dbQry, "datminmxid, "); if (fout->remoteVersion >= 170000) appendPQExpBufferStr(dbQry, "datlocprovider, datlocale, datcollversion, "); else if (fout->remoteVersion >= 150000) @@ -3638,11 +3637,11 @@ dumpDatabase(Archive *fout) ii_oid, ii_relminmxid; - appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" - "FROM pg_catalog.pg_class\n" - "WHERE oid IN (%u, %u, %u, %u);\n", - LargeObjectRelationId, LargeObjectLOidPNIndexId, - LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); + appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" + "FROM pg_catalog.pg_class\n" + "WHERE oid IN (%u, %u, %u, %u);\n", + LargeObjectRelationId, LargeObjectLOidPNIndexId, + LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); lo_res = ExecuteSqlQuery(fout, loFrozenQry->data, PGRES_TUPLES_OK); @@ -4274,7 +4273,7 @@ getPolicies(Archive *fout, TableInfo tblinfo[], int numTables) printfPQExpBuffer(query, "SELECT pol.oid, pol.tableoid, pol.polrelid, pol.polname, pol.polcmd, "); - appendPQExpBufferStr(query, "pol.polpermissive, "); + appendPQExpBufferStr(query, "pol.polpermissive, "); appendPQExpBuffer(query, "CASE WHEN pol.polroles = '{0}' THEN NULL ELSE " " pg_catalog.array_to_string(ARRAY(SELECT pg_catalog.quote_ident(rolname) from pg_catalog.pg_roles WHERE oid = ANY(pol.polroles)), ', ') END AS polroles, " @@ -6633,9 +6632,9 @@ getAccessMethods(Archive *fout) * Select all access methods from pg_am table. */ appendPQExpBufferStr(query, "SELECT tableoid, oid, amname, "); - appendPQExpBufferStr(query, - "amtype, " - "amhandler::pg_catalog.regproc AS amhandler "); + appendPQExpBufferStr(query, + "amtype, " + "amhandler::pg_catalog.regproc AS amhandler "); appendPQExpBufferStr(query, "FROM pg_am"); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6827,35 +6826,35 @@ getAggregates(Archive *fout) * Find all interesting aggregates. See comment in getFuncs() for the * rationale behind the filtering logic. */ - agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" - : "p.proisagg"); + agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" + : "p.proisagg"); - appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " - "p.proname AS aggname, " - "p.pronamespace AS aggnamespace, " - "p.pronargs, p.proargtypes, " - "p.proowner, " - "p.proacl AS aggacl, " - "acldefault('f', p.proowner) AS acldefault " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s AND (" - "p.pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog') OR " - "p.proacl IS DISTINCT FROM pip.initprivs", - agg_check); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - " OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); - appendPQExpBufferChar(query, ')'); + appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " + "p.proname AS aggname, " + "p.pronamespace AS aggnamespace, " + "p.pronargs, p.proargtypes, " + "p.proowner, " + "p.proacl AS aggacl, " + "acldefault('f', p.proowner) AS acldefault " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s AND (" + "p.pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog') OR " + "p.proacl IS DISTINCT FROM pip.initprivs", + agg_check); + if (dopt->binary_upgrade) + appendPQExpBufferStr(query, + " OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6957,53 +6956,53 @@ getFuncs(Archive *fout) * include them, since we want to dump extension members individually in * that mode. Also, if they are used by casts or transforms then we need * to gather the information about them, though they won't be dumped if - * they are built-in. Also, include functions in - * pg_catalog if they have an ACL different from what's shown in - * pg_init_privs (so we have to join to pg_init_privs; annoying). + * they are built-in. Also, include functions in pg_catalog if they have + * an ACL different from what's shown in pg_init_privs (so we have to join + * to pg_init_privs; annoying). */ - not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" - : "NOT p.proisagg"); + not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" + : "NOT p.proisagg"); - appendPQExpBuffer(query, - "SELECT p.tableoid, p.oid, p.proname, p.prolang, " - "p.pronargs, p.proargtypes, p.prorettype, " - "p.proacl, " - "acldefault('f', p.proowner) AS acldefault, " - "p.pronamespace, " - "p.proowner " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s" - "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " - "WHERE classid = 'pg_proc'::regclass AND " - "objid = p.oid AND deptype = 'i')" - "\n AND (" - "\n pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog')" - "\n OR EXISTS (SELECT 1 FROM pg_cast" - "\n WHERE pg_cast.oid > %u " - "\n AND p.oid = pg_cast.castfunc)" - "\n OR EXISTS (SELECT 1 FROM pg_transform" - "\n WHERE pg_transform.oid > %u AND " - "\n (p.oid = pg_transform.trffromsql" - "\n OR p.oid = pg_transform.trftosql))", - not_agg_check, - g_last_builtin_oid, - g_last_builtin_oid); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); + appendPQExpBuffer(query, + "SELECT p.tableoid, p.oid, p.proname, p.prolang, " + "p.pronargs, p.proargtypes, p.prorettype, " + "p.proacl, " + "acldefault('f', p.proowner) AS acldefault, " + "p.pronamespace, " + "p.proowner " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s" + "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " + "WHERE classid = 'pg_proc'::regclass AND " + "objid = p.oid AND deptype = 'i')" + "\n AND (" + "\n pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog')" + "\n OR EXISTS (SELECT 1 FROM pg_cast" + "\n WHERE pg_cast.oid > %u " + "\n AND p.oid = pg_cast.castfunc)" + "\n OR EXISTS (SELECT 1 FROM pg_transform" + "\n WHERE pg_transform.oid > %u AND " + "\n (p.oid = pg_transform.trffromsql" + "\n OR p.oid = pg_transform.trftosql))", + not_agg_check, + g_last_builtin_oid, + g_last_builtin_oid); + if (dopt->binary_upgrade) appendPQExpBufferStr(query, - "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); - appendPQExpBufferChar(query, ')'); + "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferStr(query, + "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -7252,31 +7251,31 @@ getTables(Archive *fout, int *numTables) appendPQExpBufferStr(query, "c.relhasoids, "); - appendPQExpBufferStr(query, - "c.relispopulated, "); + appendPQExpBufferStr(query, + "c.relispopulated, "); - appendPQExpBufferStr(query, - "c.relreplident, "); + appendPQExpBufferStr(query, + "c.relreplident, "); - appendPQExpBufferStr(query, - "c.relrowsecurity, c.relforcerowsecurity, "); + appendPQExpBufferStr(query, + "c.relrowsecurity, c.relforcerowsecurity, "); - appendPQExpBufferStr(query, - "c.relminmxid, tc.relminmxid AS tminmxid, "); + appendPQExpBufferStr(query, + "c.relminmxid, tc.relminmxid AS tminmxid, "); - appendPQExpBufferStr(query, - "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); + appendPQExpBufferStr(query, + "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); - appendPQExpBufferStr(query, - "am.amname, "); + appendPQExpBufferStr(query, + "am.amname, "); - appendPQExpBufferStr(query, - "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); + appendPQExpBufferStr(query, + "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); - appendPQExpBufferStr(query, - "c.relispartition AS ispartition "); + appendPQExpBufferStr(query, + "c.relispartition AS ispartition "); /* * Left join to pg_depend to pick up dependency info linking sequences to @@ -7296,8 +7295,8 @@ getTables(Archive *fout, int *numTables) /* * Left join to pg_am to pick up the amname. */ - appendPQExpBufferStr(query, - "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); + appendPQExpBufferStr(query, + "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); /* * We purposefully ignore toast OIDs for partitioned tables; the reason is @@ -7868,8 +7867,8 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables) "t.reloptions AS indreloptions, "); - appendPQExpBufferStr(query, - "i.indisreplident, "); + appendPQExpBufferStr(query, + "i.indisreplident, "); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -9313,8 +9312,8 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables) appendPQExpBufferStr(q, "'' AS attcompression,\n"); - appendPQExpBufferStr(q, - "a.attidentity,\n"); + appendPQExpBufferStr(q, + "a.attidentity,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(q, @@ -10717,73 +10716,73 @@ getAdditionalACLs(Archive *fout) PQclear(res); /* Fetch initial-privileges data */ - printfPQExpBuffer(query, - "SELECT objoid, classoid, objsubid, privtype, initprivs " - "FROM pg_init_privs"); + printfPQExpBuffer(query, + "SELECT objoid, classoid, objsubid, privtype, initprivs " + "FROM pg_init_privs"); - res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); + res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); - ntups = PQntuples(res); - for (i = 0; i < ntups; i++) - { - Oid objoid = atooid(PQgetvalue(res, i, 0)); - Oid classoid = atooid(PQgetvalue(res, i, 1)); - int objsubid = atoi(PQgetvalue(res, i, 2)); - char privtype = *(PQgetvalue(res, i, 3)); - char *initprivs = PQgetvalue(res, i, 4); - CatalogId objId; - DumpableObject *dobj; + ntups = PQntuples(res); + for (i = 0; i < ntups; i++) + { + Oid objoid = atooid(PQgetvalue(res, i, 0)); + Oid classoid = atooid(PQgetvalue(res, i, 1)); + int objsubid = atoi(PQgetvalue(res, i, 2)); + char privtype = *(PQgetvalue(res, i, 3)); + char *initprivs = PQgetvalue(res, i, 4); + CatalogId objId; + DumpableObject *dobj; - objId.tableoid = classoid; - objId.oid = objoid; - dobj = findObjectByCatalogId(objId); - /* OK to ignore entries we haven't got a DumpableObject for */ - if (dobj) + objId.tableoid = classoid; + objId.oid = objoid; + dobj = findObjectByCatalogId(objId); + /* OK to ignore entries we haven't got a DumpableObject for */ + if (dobj) + { + /* Cope with sub-object initprivs */ + if (objsubid != 0) { - /* Cope with sub-object initprivs */ - if (objsubid != 0) - { - if (dobj->objType == DO_TABLE) - { - /* For a column initprivs, set the table's ACL flags */ - dobj->components |= DUMP_COMPONENT_ACL; - ((TableInfo *) dobj)->hascolumnACLs = true; - } - else - pg_log_warning("unsupported pg_init_privs entry: %u %u %d", - classoid, objoid, objsubid); - continue; - } - - /* - * We ignore any pg_init_privs.initprivs entry for the public - * schema, as explained in getNamespaces(). - */ - if (dobj->objType == DO_NAMESPACE && - strcmp(dobj->name, "public") == 0) - continue; - - /* Else it had better be of a type we think has ACLs */ - if (dobj->objType == DO_NAMESPACE || - dobj->objType == DO_TYPE || - dobj->objType == DO_FUNC || - dobj->objType == DO_AGG || - dobj->objType == DO_TABLE || - dobj->objType == DO_PROCLANG || - dobj->objType == DO_FDW || - dobj->objType == DO_FOREIGN_SERVER) + if (dobj->objType == DO_TABLE) { - DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; - - daobj->dacl.privtype = privtype; - daobj->dacl.initprivs = pstrdup(initprivs); + /* For a column initprivs, set the table's ACL flags */ + dobj->components |= DUMP_COMPONENT_ACL; + ((TableInfo *) dobj)->hascolumnACLs = true; } else pg_log_warning("unsupported pg_init_privs entry: %u %u %d", classoid, objoid, objsubid); + continue; + } + + /* + * We ignore any pg_init_privs.initprivs entry for the public + * schema, as explained in getNamespaces(). + */ + if (dobj->objType == DO_NAMESPACE && + strcmp(dobj->name, "public") == 0) + continue; + + /* Else it had better be of a type we think has ACLs */ + if (dobj->objType == DO_NAMESPACE || + dobj->objType == DO_TYPE || + dobj->objType == DO_FUNC || + dobj->objType == DO_AGG || + dobj->objType == DO_TABLE || + dobj->objType == DO_PROCLANG || + dobj->objType == DO_FDW || + dobj->objType == DO_FOREIGN_SERVER) + { + DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; + + daobj->dacl.privtype = privtype; + daobj->dacl.initprivs = pstrdup(initprivs); } + else + pg_log_warning("unsupported pg_init_privs entry: %u %u %d", + classoid, objoid, objsubid); } - PQclear(res); + } + PQclear(res); destroyPQExpBuffer(query); } @@ -11128,8 +11127,8 @@ dumpRelationStats_dumper(Archive *fout, const void *userArg, const TocEntry *te) * The results must be in the order of the relations supplied in the * parameters to ensure we remain in sync as we walk through the TOC. * - * For versions before 19, the redundant filter clause on s.tablename = - * ANY(...) seems sufficient to convince the planner to use + * For versions before 19, the redundant filter clause on s.tablename + * = ANY(...) seems sufficient to convince the planner to use * pg_class_relname_nsp_index, which avoids a full scan of pg_stats. * In newer versions, pg_stats returns the table OIDs, eliminating the * need for that hack. @@ -13469,11 +13468,11 @@ dumpFunc(Archive *fout, const FuncInfo *finfo) "pg_catalog.pg_get_function_result(p.oid) AS funcresult,\n" "proleakproof,\n"); - appendPQExpBufferStr(query, - "array_to_string(protrftypes, ' ') AS protrftypes,\n"); + appendPQExpBufferStr(query, + "array_to_string(protrftypes, ' ') AS protrftypes,\n"); - appendPQExpBufferStr(query, - "proparallel,\n"); + appendPQExpBufferStr(query, + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -14963,9 +14962,9 @@ dumpCollation(Archive *fout, const CollInfo *collinfo) /* Get collation-specific details */ appendPQExpBufferStr(query, "SELECT "); - appendPQExpBufferStr(query, - "collprovider, " - "collversion, "); + appendPQExpBufferStr(query, + "collprovider, " + "collversion, "); if (fout->remoteVersion >= 120000) appendPQExpBufferStr(query, @@ -15372,23 +15371,23 @@ dumpAgg(Archive *fout, const AggInfo *agginfo) "pg_catalog.pg_get_function_arguments(p.oid) AS funcargs,\n" "pg_catalog.pg_get_function_identity_arguments(p.oid) AS funciargs,\n"); - appendPQExpBufferStr(query, - "aggkind,\n" - "aggmtransfn,\n" - "aggminvtransfn,\n" - "aggmfinalfn,\n" - "aggmtranstype::pg_catalog.regtype,\n" - "aggfinalextra,\n" - "aggmfinalextra,\n" - "aggtransspace,\n" - "aggmtransspace,\n" - "aggminitval,\n"); + appendPQExpBufferStr(query, + "aggkind,\n" + "aggmtransfn,\n" + "aggminvtransfn,\n" + "aggmfinalfn,\n" + "aggmtranstype::pg_catalog.regtype,\n" + "aggfinalextra,\n" + "aggmfinalextra,\n" + "aggtransspace,\n" + "aggmtransspace,\n" + "aggminitval,\n"); - appendPQExpBufferStr(query, - "aggcombinefn,\n" - "aggserialfn,\n" - "aggdeserialfn,\n" - "proparallel,\n"); + appendPQExpBufferStr(query, + "aggcombinefn,\n" + "aggserialfn,\n" + "aggdeserialfn,\n" + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -16848,30 +16847,30 @@ dumpTable(Archive *fout, const TableInfo *tbinfo) appendPQExpBufferStr(query, "PREPARE getColumnACLs(pg_catalog.oid) AS\n"); - /* - * In principle we should call acldefault('c', relowner) to - * get the default ACL for a column. However, we don't - * currently store the numeric OID of the relowner in - * TableInfo. We could convert the owner name using regrole, - * but that creates a risk of failure due to concurrent role - * renames. Given that the default ACL for columns is empty - * and is likely to stay that way, it's not worth extra cycles - * and risk to avoid hard-wiring that knowledge here. - */ - appendPQExpBufferStr(query, - "SELECT at.attname, " - "at.attacl, " - "'{}' AS acldefault, " - "pip.privtype, pip.initprivs " - "FROM pg_catalog.pg_attribute at " - "LEFT JOIN pg_catalog.pg_init_privs pip ON " - "(at.attrelid = pip.objoid " - "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " - "AND at.attnum = pip.objsubid) " - "WHERE at.attrelid = $1 AND " - "NOT at.attisdropped " - "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " - "ORDER BY at.attnum"); + /* + * In principle we should call acldefault('c', relowner) to get + * the default ACL for a column. However, we don't currently + * store the numeric OID of the relowner in TableInfo. We could + * convert the owner name using regrole, but that creates a risk + * of failure due to concurrent role renames. Given that the + * default ACL for columns is empty and is likely to stay that + * way, it's not worth extra cycles and risk to avoid hard-wiring + * that knowledge here. + */ + appendPQExpBufferStr(query, + "SELECT at.attname, " + "at.attacl, " + "'{}' AS acldefault, " + "pip.privtype, pip.initprivs " + "FROM pg_catalog.pg_attribute at " + "LEFT JOIN pg_catalog.pg_init_privs pip ON " + "(at.attrelid = pip.objoid " + "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " + "AND at.attnum = pip.objsubid) " + "WHERE at.attrelid = $1 AND " + "NOT at.attisdropped " + "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " + "ORDER BY at.attnum"); ExecuteSqlStatement(fout, query->data); @@ -19165,7 +19164,7 @@ collectSequences(Archive *fout) * pg_get_sequence_data(), but we only do so for non-schema-only dumps. */ if (fout->remoteVersion < 180000 || - (!fout->dopt->dumpData && !fout->dopt->sequence_data)) + (!fout->dopt->dumpData && !fout->dopt->sequence_data)) query = "SELECT seqrelid, format_type(seqtypid, NULL), " "seqstart, seqincrement, " "seqmax, seqmin, " @@ -19227,15 +19226,14 @@ dumpSequence(Archive *fout, const TableInfo *tbinfo) qseqname = pg_strdup(fmtId(tbinfo->dobj.name)); /* - * The sequence information is gathered in a sorted - * table before any calls to dumpSequence(). See collectSequences() for - * more information. + * The sequence information is gathered in a sorted table before any calls + * to dumpSequence(). See collectSequences() for more information. */ - Assert(sequences); + Assert(sequences); - key.oid = tbinfo->dobj.catId.oid; - seq = bsearch(&key, sequences, nsequences, - sizeof(SequenceItem), SequenceItemCmp); + key.oid = tbinfo->dobj.catId.oid; + seq = bsearch(&key, sequences, nsequences, + sizeof(SequenceItem), SequenceItemCmp); /* Calculate default limits for a sequence of this type */ is_ascending = (seq->incby >= 0); diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c index e68937c9934..afcd9a218d8 100644 --- a/src/bin/pg_dump/pg_dumpall.c +++ b/src/bin/pg_dump/pg_dumpall.c @@ -785,11 +785,11 @@ dropRoles(PGconn *conn) int i_rolname; int i; - printfPQExpBuffer(buf, - "SELECT rolname " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 1", role_catalog); + printfPQExpBuffer(buf, + "SELECT rolname " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 1", role_catalog); res = executeQuery(conn, buf->data); @@ -843,16 +843,16 @@ dumpRoles(PGconn *conn) * Notes: rolconfig is dumped later, and pg_authid must be used for * extracting rolcomment regardless of role_catalog. */ - printfPQExpBuffer(buf, - "SELECT oid, rolname, rolsuper, rolinherit, " - "rolcreaterole, rolcreatedb, " - "rolcanlogin, rolconnlimit, rolpassword, " - "rolvaliduntil, rolreplication, rolbypassrls, " - "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " - "rolname = current_user AS is_current_user " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 2", role_catalog); + printfPQExpBuffer(buf, + "SELECT oid, rolname, rolsuper, rolinherit, " + "rolcreaterole, rolcreatedb, " + "rolcanlogin, rolconnlimit, rolpassword, " + "rolvaliduntil, rolreplication, rolbypassrls, " + "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " + "rolname = current_user AS is_current_user " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 2", role_catalog); res = executeQuery(conn, buf->data); diff --git a/src/bin/pg_upgrade/check.c b/src/bin/pg_upgrade/check.c index 786c1474829..f725f5ee3e2 100644 --- a/src/bin/pg_upgrade/check.c +++ b/src/bin/pg_upgrade/check.c @@ -1475,15 +1475,15 @@ check_for_incompatible_polymorphics(ClusterInfo *cluster) ", 'array_cat(anyarray,anyarray)'" ", 'array_prepend(anyelement,anyarray)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_remove(anyarray,anyelement)'" - ", 'array_replace(anyarray,anyelement,anyelement)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_remove(anyarray,anyelement)'" + ", 'array_replace(anyarray,anyelement,anyelement)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_position(anyarray,anyelement)'" - ", 'array_position(anyarray,anyelement,integer)'" - ", 'array_positions(anyarray,anyelement)'" - ", 'width_bucket(anyelement,anyarray)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_position(anyarray,anyelement)'" + ", 'array_position(anyarray,anyelement,integer)'" + ", 'array_positions(anyarray,anyelement)'" + ", 'width_bucket(anyelement,anyarray)'"); /* * The query below hardcodes FirstNormalObjectId as 16384 rather than diff --git a/src/bin/pg_upgrade/controldata.c b/src/bin/pg_upgrade/controldata.c index 8f81c9e9582..02ea02df60f 100644 --- a/src/bin/pg_upgrade/controldata.c +++ b/src/bin/pg_upgrade/controldata.c @@ -228,7 +228,7 @@ get_control_data(ClusterInfo *cluster) p++; /* remove ':' char */ cluster->controldata.chkpnt_nxtepoch = str2uint(p); - p = strchr(p, ':'); + p = strchr(p, ':'); if (p == NULL || strlen(p) <= 1) pg_fatal("%d: controldata retrieval problem", __LINE__); diff --git a/src/bin/pg_upgrade/exec.c b/src/bin/pg_upgrade/exec.c index 44355feea30..a1bdbf373e3 100644 --- a/src/bin/pg_upgrade/exec.c +++ b/src/bin/pg_upgrade/exec.c @@ -55,7 +55,7 @@ get_bin_version(ClusterInfo *cluster) if (sscanf(cmd_output, "%*s %*s %d.%d", &v1, &v2) < 1) pg_fatal("could not get pg_ctl version output from %s", cmd); - cluster->bin_version = v1 * 10000; + cluster->bin_version = v1 * 10000; } @@ -344,8 +344,8 @@ check_data_dir(ClusterInfo *cluster) check_single_dir(pg_data, "pg_subtrans"); check_single_dir(pg_data, PG_TBLSPC_DIR); check_single_dir(pg_data, "pg_twophase"); - check_single_dir(pg_data, "pg_wal"); - check_single_dir(pg_data, "pg_xact"); + check_single_dir(pg_data, "pg_wal"); + check_single_dir(pg_data, "pg_xact"); } @@ -385,7 +385,7 @@ check_bin_dir(ClusterInfo *cluster, bool check_versions) */ get_bin_version(cluster); - check_exec(cluster->bindir, "pg_resetwal", check_versions); + check_exec(cluster->bindir, "pg_resetwal", check_versions); if (cluster == &new_cluster) { diff --git a/src/bin/pg_upgrade/multixact_rewrite.c b/src/bin/pg_upgrade/multixact_rewrite.c index c45b3183684..c7a1416494d 100644 --- a/src/bin/pg_upgrade/multixact_rewrite.c +++ b/src/bin/pg_upgrade/multixact_rewrite.c @@ -61,52 +61,52 @@ rewrite_multixacts(MultiXactId from_multi, MultiXactId to_multi) * Convert old multixids, if needed, by reading them one-by-one from the * old cluster. */ - old_reader = AllocOldMultiXactRead(old_cluster.pgdata, - old_cluster.controldata.chkpnt_nxtmulti, - old_cluster.controldata.chkpnt_nxtmxoff); + old_reader = AllocOldMultiXactRead(old_cluster.pgdata, + old_cluster.controldata.chkpnt_nxtmulti, + old_cluster.controldata.chkpnt_nxtmxoff); - for (MultiXactId multi = from_multi; multi != to_multi;) - { - MultiXactMember member; - bool multixid_valid; - - /* - * Read this multixid's members. - * - * Locking-only XIDs that may be part of multi-xids don't matter - * after upgrade, as there can be no transactions running across - * upgrade. So as a small optimization, we only read one member - * from each multixid: the one updating one, or if there was no - * update, arbitrarily the first locking xid. - */ - multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); + for (MultiXactId multi = from_multi; multi != to_multi;) + { + MultiXactMember member; + bool multixid_valid; - /* - * Write the new offset to pg_multixact/offsets. - * - * Even if this multixid is invalid, we still need to write its - * offset if the *previous* multixid was valid. That's because - * when reading a multixid, the number of members is calculated - * from the difference between the two offsets. - */ - RecordMultiXactOffset(offsets_writer, multi, - (multixid_valid || prev_multixid_valid) ? next_offset : 0); + /* + * Read this multixid's members. + * + * Locking-only XIDs that may be part of multi-xids don't matter after + * upgrade, as there can be no transactions running across upgrade. So + * as a small optimization, we only read one member from each + * multixid: the one updating one, or if there was no update, + * arbitrarily the first locking xid. + */ + multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); - /* Write the members */ - if (multixid_valid) - { - RecordMultiXactMembers(members_writer, next_offset, 1, &member); - next_offset += 1; - } + /* + * Write the new offset to pg_multixact/offsets. + * + * Even if this multixid is invalid, we still need to write its offset + * if the *previous* multixid was valid. That's because when reading + * a multixid, the number of members is calculated from the difference + * between the two offsets. + */ + RecordMultiXactOffset(offsets_writer, multi, + (multixid_valid || prev_multixid_valid) ? next_offset : 0); - /* Advance to next multixid, handling wraparound */ - multi++; - if (multi < FirstMultiXactId) - multi = FirstMultiXactId; - prev_multixid_valid = multixid_valid; + /* Write the members */ + if (multixid_valid) + { + RecordMultiXactMembers(members_writer, next_offset, 1, &member); + next_offset += 1; } - FreeOldMultiXactReader(old_reader); + /* Advance to next multixid, handling wraparound */ + multi++; + if (multi < FirstMultiXactId) + multi = FirstMultiXactId; + prev_multixid_valid = multixid_valid; + } + + FreeOldMultiXactReader(old_reader); /* Write the final 'next' offset to the last SLRU page */ RecordMultiXactOffset(offsets_writer, to_multi, diff --git a/src/bin/pg_upgrade/pg_upgrade.c b/src/bin/pg_upgrade/pg_upgrade.c index c6af9035665..7366fd4627c 100644 --- a/src/bin/pg_upgrade/pg_upgrade.c +++ b/src/bin/pg_upgrade/pg_upgrade.c @@ -833,7 +833,7 @@ copy_xact_xlog_xid(void) * Determine the range of multixacts to convert. */ nxtmulti = old_cluster.controldata.chkpnt_nxtmulti; - oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; + oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; /* handle wraparound */ if (nxtmulti < FirstMultiXactId) nxtmulti = FirstMultiXactId; @@ -898,15 +898,15 @@ set_frozenxids(void) int i_datname; int i_datallowconn; - prep_status("Setting frozenxid and minmxid counters in new cluster"); + prep_status("Setting frozenxid and minmxid counters in new cluster"); conn_template1 = connectToServer(&new_cluster, "template1"); - /* set pg_database.datfrozenxid */ - PQclear(executeQueryOrDie(conn_template1, - "UPDATE pg_catalog.pg_database " - "SET datfrozenxid = '%u'", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_database.datfrozenxid */ + PQclear(executeQueryOrDie(conn_template1, + "UPDATE pg_catalog.pg_database " + "SET datfrozenxid = '%u'", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_database.datminmxid */ PQclear(executeQueryOrDie(conn_template1, @@ -942,16 +942,16 @@ set_frozenxids(void) conn = connectToServer(&new_cluster, datname); - /* set pg_class.relfrozenxid */ - PQclear(executeQueryOrDie(conn, - "UPDATE pg_catalog.pg_class " - "SET relfrozenxid = '%u' " - /* only heap, materialized view, and TOAST are vacuumed */ - "WHERE relkind IN (" - CppAsString2(RELKIND_RELATION) ", " - CppAsString2(RELKIND_MATVIEW) ", " - CppAsString2(RELKIND_TOASTVALUE) ")", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_class.relfrozenxid */ + PQclear(executeQueryOrDie(conn, + "UPDATE pg_catalog.pg_class " + "SET relfrozenxid = '%u' " + /* only heap, materialized view, and TOAST are vacuumed */ + "WHERE relkind IN (" + CppAsString2(RELKIND_RELATION) ", " + CppAsString2(RELKIND_MATVIEW) ", " + CppAsString2(RELKIND_TOASTVALUE) ")", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_class.relminmxid */ PQclear(executeQueryOrDie(conn, diff --git a/src/bin/pg_upgrade/relfilenumber.c b/src/bin/pg_upgrade/relfilenumber.c index ec2ff7acb21..6c467bdc8a5 100644 --- a/src/bin/pg_upgrade/relfilenumber.c +++ b/src/bin/pg_upgrade/relfilenumber.c @@ -587,32 +587,32 @@ transfer_relfile(FileNameMap *map, const char *type_suffix) /* Copying files might take some time, so give feedback. */ pg_log(PG_STATUS, "%s", old_file); - switch (user_opts.transfer_mode) - { - case TRANSFER_MODE_CLONE: - pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", - old_file, new_file); - cloneFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", - old_file, new_file); - copyFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY_FILE_RANGE: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", - old_file, new_file); - copyFileByRange(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_LINK: - pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", - old_file, new_file); - linkFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_SWAP: - /* swap mode is handled in its own code path */ - pg_fatal("should never happen"); - break; - } + switch (user_opts.transfer_mode) + { + case TRANSFER_MODE_CLONE: + pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", + old_file, new_file); + cloneFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", + old_file, new_file); + copyFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY_FILE_RANGE: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", + old_file, new_file); + copyFileByRange(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_LINK: + pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", + old_file, new_file); + linkFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_SWAP: + /* swap mode is handled in its own code path */ + pg_fatal("should never happen"); + break; + } } } diff --git a/src/bin/pg_upgrade/t/006_transfer_modes.pl b/src/bin/pg_upgrade/t/006_transfer_modes.pl index 9efa5dc863c..360d05c4b68 100644 --- a/src/bin/pg_upgrade/t/006_transfer_modes.pl +++ b/src/bin/pg_upgrade/t/006_transfer_modes.pl @@ -29,10 +29,8 @@ sub test_mode } $new->init(); - $new->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); - $old->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); + $new->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); + $old->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); # We can only test security labels if both the old and new installations # have dummy_seclabel. @@ -76,15 +74,14 @@ sub test_mode "CREATE TABLE test4 AS SELECT generate_series(400, 502)"); } - $old->safe_psql('postgres', - "CREATE TABLESPACE inplc_tblspc LOCATION ''"); - $old->safe_psql('postgres', - "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); - $old->safe_psql('postgres', - "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" - ); - $old->safe_psql('testdb3', - "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); + $old->safe_psql('postgres', "CREATE TABLESPACE inplc_tblspc LOCATION ''"); + $old->safe_psql('postgres', + "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); + $old->safe_psql('postgres', + "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" + ); + $old->safe_psql('testdb3', + "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); # While we are here, test handling of large objects. $old->safe_psql( @@ -152,12 +149,10 @@ sub test_mode } # Tests for in-place tablespaces. - $result = - $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); - is($result, '104', "test5 data after pg_upgrade $mode"); - $result = - $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); - is($result, '105', "test6 data after pg_upgrade $mode"); + $result = $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); + is($result, '104', "test5 data after pg_upgrade $mode"); + $result = $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); + is($result, '105', "test6 data after pg_upgrade $mode"); # Tests for large objects $result = $new->safe_psql('postgres', "SELECT lo_get(4532)"); diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index 44ef11d980e..c90bf8bbde2 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -6278,23 +6278,22 @@ get_create_object_cmd(EditableObjectType obj_type, Oid oid, * ensure the right view gets replaced. Also, check relation kind * to be sure it's a view. * - * Views may have WITH [LOCAL|CASCADED] - * CHECK OPTION. These are not part of the view definition - * returned by pg_get_viewdef() and so need to be retrieved - * separately. Materialized views may have - * arbitrary storage parameter reloptions. + * Views may have WITH [LOCAL|CASCADED] CHECK OPTION. These are + * not part of the view definition returned by pg_get_viewdef() + * and so need to be retrieved separately. Materialized views may + * have arbitrary storage parameter reloptions. */ printfPQExpBuffer(query, "/* %s */\n", _("Get view's definition and details")); - appendPQExpBuffer(query, - "SELECT nspname, relname, relkind, " - "pg_catalog.pg_get_viewdef(c.oid, true), " - "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " - "FROM pg_catalog.pg_class c " - "LEFT JOIN pg_catalog.pg_namespace n " - "ON c.relnamespace = n.oid WHERE c.oid = %u", - oid); + appendPQExpBuffer(query, + "SELECT nspname, relname, relkind, " + "pg_catalog.pg_get_viewdef(c.oid, true), " + "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " + "FROM pg_catalog.pg_class c " + "LEFT JOIN pg_catalog.pg_namespace n " + "ON c.relnamespace = n.oid WHERE c.oid = %u", + oid); break; } diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index ce99137c613..ac0c55e7aa5 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -387,19 +387,19 @@ describeFunctions(const char *functypes, const char *func_pattern, gettext_noop("stable"), gettext_noop("volatile"), gettext_noop("Volatility")); - appendPQExpBuffer(&buf, - ",\n CASE\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" - " END as \"%s\"", - gettext_noop("restricted"), - gettext_noop("safe"), - gettext_noop("unsafe"), - gettext_noop("Parallel")); + appendPQExpBuffer(&buf, + ",\n CASE\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" + " END as \"%s\"", + gettext_noop("restricted"), + gettext_noop("safe"), + gettext_noop("unsafe"), + gettext_noop("Parallel")); appendPQExpBuffer(&buf, ",\n pg_catalog.pg_get_userbyid(p.proowner) as \"%s\"" ",\n CASE WHEN prosecdef THEN '%s' ELSE '%s' END AS \"%s\"" @@ -599,8 +599,8 @@ describeFunctions(const char *functypes, const char *func_pattern, myopt.title = _("List of functions"); myopt.translate_header = true; - myopt.translate_columns = translate_columns; - myopt.n_translate_columns = lengthof(translate_columns); + myopt.translate_columns = translate_columns; + myopt.n_translate_columns = lengthof(translate_columns); printQuery(res, &myopt, pset.queryFout, false, pset.logfile); @@ -1086,38 +1086,38 @@ permissionsList(const char *pattern, bool showSystem) " ), E'\\n') AS \"%s\"", gettext_noop("Column privileges")); - appendPQExpBuffer(&buf, - ",\n pg_catalog.array_to_string(ARRAY(\n" - " SELECT polname\n" - " || CASE WHEN NOT polpermissive THEN\n" - " E' (RESTRICTIVE)'\n" - " ELSE '' END\n" - " || CASE WHEN polcmd != '*' THEN\n" - " E' (' || polcmd::pg_catalog.text || E'):'\n" - " ELSE E':'\n" - " END\n" - " || CASE WHEN polqual IS NOT NULL THEN\n" - " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" - " ELSE E''\n" - " END\n" - " || CASE WHEN polwithcheck IS NOT NULL THEN\n" - " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" - " ELSE E''\n" - " END" - " || CASE WHEN polroles <> '{0}' THEN\n" - " E'\\n to: ' || pg_catalog.array_to_string(\n" - " ARRAY(\n" - " SELECT rolname\n" - " FROM pg_catalog.pg_roles\n" - " WHERE oid = ANY (polroles)\n" - " ORDER BY 1\n" - " ), E', ')\n" - " ELSE E''\n" - " END\n" - " FROM pg_catalog.pg_policy pol\n" - " WHERE polrelid = c.oid), E'\\n')\n" - " AS \"%s\"", - gettext_noop("Policies")); + appendPQExpBuffer(&buf, + ",\n pg_catalog.array_to_string(ARRAY(\n" + " SELECT polname\n" + " || CASE WHEN NOT polpermissive THEN\n" + " E' (RESTRICTIVE)'\n" + " ELSE '' END\n" + " || CASE WHEN polcmd != '*' THEN\n" + " E' (' || polcmd::pg_catalog.text || E'):'\n" + " ELSE E':'\n" + " END\n" + " || CASE WHEN polqual IS NOT NULL THEN\n" + " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" + " ELSE E''\n" + " END\n" + " || CASE WHEN polwithcheck IS NOT NULL THEN\n" + " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" + " ELSE E''\n" + " END" + " || CASE WHEN polroles <> '{0}' THEN\n" + " E'\\n to: ' || pg_catalog.array_to_string(\n" + " ARRAY(\n" + " SELECT rolname\n" + " FROM pg_catalog.pg_roles\n" + " WHERE oid = ANY (polroles)\n" + " ORDER BY 1\n" + " ), E', ')\n" + " ELSE E''\n" + " END\n" + " FROM pg_catalog.pg_policy pol\n" + " WHERE polrelid = c.oid), E'\\n')\n" + " AS \"%s\"", + gettext_noop("Policies")); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_class c\n" " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n" @@ -1675,27 +1675,27 @@ describeOneTableDetails(const char *schemaname, char *footers[3] = {NULL, NULL, NULL}; printfPQExpBuffer(&buf, "/* %s */\n", _("Get sequence information")); - appendPQExpBuffer(&buf, - "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" - " seqstart AS \"%s\",\n" - " seqmin AS \"%s\",\n" - " seqmax AS \"%s\",\n" - " seqincrement AS \"%s\",\n" - " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" - " seqcache AS \"%s\"\n", - gettext_noop("Type"), - gettext_noop("Start"), - gettext_noop("Minimum"), - gettext_noop("Maximum"), - gettext_noop("Increment"), - gettext_noop("yes"), - gettext_noop("no"), - gettext_noop("Cycles?"), - gettext_noop("Cache")); - appendPQExpBuffer(&buf, - "FROM pg_catalog.pg_sequence\n" - "WHERE seqrelid = '%s';", - oid); + appendPQExpBuffer(&buf, + "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" + " seqstart AS \"%s\",\n" + " seqmin AS \"%s\",\n" + " seqmax AS \"%s\",\n" + " seqincrement AS \"%s\",\n" + " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" + " seqcache AS \"%s\"\n", + gettext_noop("Type"), + gettext_noop("Start"), + gettext_noop("Minimum"), + gettext_noop("Maximum"), + gettext_noop("Increment"), + gettext_noop("yes"), + gettext_noop("no"), + gettext_noop("Cycles?"), + gettext_noop("Cache")); + appendPQExpBuffer(&buf, + "FROM pg_catalog.pg_sequence\n" + "WHERE seqrelid = '%s';", + oid); res = PSQLexec(buf.data); if (!res) @@ -1913,7 +1913,7 @@ describeOneTableDetails(const char *schemaname, appendPQExpBufferStr(&buf, ",\n (SELECT c.collname FROM pg_catalog.pg_collation c, pg_catalog.pg_type t\n" " WHERE c.oid = a.attcollation AND t.oid = a.atttypid AND a.attcollation <> t.typcollation) AS attcollation"); attcoll_col = cols++; - appendPQExpBufferStr(&buf, ",\n a.attidentity"); + appendPQExpBufferStr(&buf, ",\n a.attidentity"); attidentity_col = cols++; if (pset.sversion >= 120000) appendPQExpBufferStr(&buf, ",\n a.attgenerated"); @@ -2326,7 +2326,7 @@ describeOneTableDetails(const char *schemaname, CppAsString2(CONSTRAINT_EXCLUSION) ") AND " "condeferred) AS condeferred,\n"); - appendPQExpBufferStr(&buf, "i.indisreplident,\n"); + appendPQExpBufferStr(&buf, "i.indisreplident,\n"); if (pset.sversion >= 150000) appendPQExpBufferStr(&buf, "i.indnullsnotdistinct,\n"); @@ -2431,7 +2431,7 @@ describeOneTableDetails(const char *schemaname, "pg_catalog.pg_get_indexdef(i.indexrelid, 0, true),\n " "pg_catalog.pg_get_constraintdef(con.oid, true), " "contype, condeferrable, condeferred"); - appendPQExpBufferStr(&buf, ", i.indisreplident"); + appendPQExpBufferStr(&buf, ", i.indisreplident"); appendPQExpBufferStr(&buf, ", c2.reltablespace"); if (pset.sversion >= 180000) appendPQExpBufferStr(&buf, ", con.conperiod"); @@ -2682,81 +2682,80 @@ describeOneTableDetails(const char *schemaname, PQclear(result); /* print any row-level policies */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get row-level policies for this table")); - appendPQExpBufferStr(&buf, "SELECT pol.polname,"); - appendPQExpBufferStr(&buf, - " pol.polpermissive,\n"); - appendPQExpBuffer(&buf, - " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" - " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" - " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" - " CASE pol.polcmd\n" - " WHEN 'r' THEN 'SELECT'\n" - " WHEN 'a' THEN 'INSERT'\n" - " WHEN 'w' THEN 'UPDATE'\n" - " WHEN 'd' THEN 'DELETE'\n" - " END AS cmd\n" - "FROM pg_catalog.pg_policy pol\n" - "WHERE pol.polrelid = '%s' ORDER BY 1;", - oid); + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get row-level policies for this table")); + appendPQExpBufferStr(&buf, "SELECT pol.polname,"); + appendPQExpBufferStr(&buf, + " pol.polpermissive,\n"); + appendPQExpBuffer(&buf, + " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" + " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" + " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" + " CASE pol.polcmd\n" + " WHEN 'r' THEN 'SELECT'\n" + " WHEN 'a' THEN 'INSERT'\n" + " WHEN 'w' THEN 'UPDATE'\n" + " WHEN 'd' THEN 'DELETE'\n" + " END AS cmd\n" + "FROM pg_catalog.pg_policy pol\n" + "WHERE pol.polrelid = '%s' ORDER BY 1;", + oid); - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - /* - * Handle cases where RLS is enabled and there are policies, or - * there aren't policies, or RLS isn't enabled but there are - * policies - */ - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies:")); + /* + * Handle cases where RLS is enabled and there are policies, or there + * aren't policies, or RLS isn't enabled but there are policies + */ + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies:")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled):")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled):")); - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); - if (!tableinfo.rowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (row security disabled):")); + if (!tableinfo.rowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (row security disabled):")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " POLICY \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " POLICY \"%s\"", + PQgetvalue(result, i, 0)); - if (*(PQgetvalue(result, i, 1)) == 'f') - appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); + if (*(PQgetvalue(result, i, 1)) == 'f') + appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); - if (!PQgetisnull(result, i, 5)) - appendPQExpBuffer(&buf, " FOR %s", - PQgetvalue(result, i, 5)); + if (!PQgetisnull(result, i, 5)) + appendPQExpBuffer(&buf, " FOR %s", + PQgetvalue(result, i, 5)); - if (!PQgetisnull(result, i, 2)) - { - appendPQExpBuffer(&buf, "\n TO %s", - PQgetvalue(result, i, 2)); - } + if (!PQgetisnull(result, i, 2)) + { + appendPQExpBuffer(&buf, "\n TO %s", + PQgetvalue(result, i, 2)); + } - if (!PQgetisnull(result, i, 3)) - appendPQExpBuffer(&buf, "\n USING (%s)", - PQgetvalue(result, i, 3)); + if (!PQgetisnull(result, i, 3)) + appendPQExpBuffer(&buf, "\n USING (%s)", + PQgetvalue(result, i, 3)); - if (!PQgetisnull(result, i, 4)) - appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", - PQgetvalue(result, i, 4)); + if (!PQgetisnull(result, i, 4)) + appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", + PQgetvalue(result, i, 4)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* print any extended statistics */ if (pset.sversion >= 140000) @@ -3025,115 +3024,115 @@ describeOneTableDetails(const char *schemaname, } /* print any publications */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get publications that publish this table")); - if (pset.sversion >= 150000) + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get publications that publish this table")); + if (pset.sversion >= 150000) + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" + " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" + "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" + "UNION\n" + "SELECT pubname\n" + " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" + " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" + " (SELECT pg_catalog.string_agg(attname, ', ')\n" + " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" + " pg_catalog.pg_attribute\n" + " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" + " ELSE NULL END) " + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" + "WHERE pr.prrelid = '%s'\n", + oid, oid, oid); + + if (pset.sversion >= 190000) { + /* + * Skip entries where this relation appears in the + * publication's EXCEPT list. + */ appendPQExpBuffer(&buf, + " AND NOT pr.prexcept\n" + "UNION\n" "SELECT pubname\n" " , NULL\n" " , NULL\n" "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" - " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" - "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" - "UNION\n" - "SELECT pubname\n" - " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" - " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" - " (SELECT pg_catalog.string_agg(attname, ', ')\n" - " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" - " pg_catalog.pg_attribute\n" - " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" - " ELSE NULL END) " - "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" - "WHERE pr.prrelid = '%s'\n", + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + " AND NOT EXISTS (\n" + " SELECT 1\n" + " FROM pg_catalog.pg_publication_rel pr\n" + " WHERE pr.prpubid = p.oid AND\n" + " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" + "ORDER BY 1;", oid, oid, oid); - - if (pset.sversion >= 190000) - { - /* - * Skip entries where this relation appears in the - * publication's EXCEPT list. - */ - appendPQExpBuffer(&buf, - " AND NOT pr.prexcept\n" - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - " AND NOT EXISTS (\n" - " SELECT 1\n" - " FROM pg_catalog.pg_publication_rel pr\n" - " WHERE pr.prpubid = p.oid AND\n" - " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" - "ORDER BY 1;", - oid, oid, oid); - } - else - { - appendPQExpBuffer(&buf, - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - "ORDER BY 1;", - oid); - } } else { appendPQExpBuffer(&buf, + "UNION\n" "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - "WHERE pr.prrelid = '%s'\n" - "UNION ALL\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" + " , NULL\n" + " , NULL\n" "FROM pg_catalog.pg_publication p\n" "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" "ORDER BY 1;", - oid, oid); + oid); } + } + else + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + "WHERE pr.prrelid = '%s'\n" + "UNION ALL\n" + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + "ORDER BY 1;", + oid, oid); + } - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - if (tuples > 0) - printTableAddFooter(&cont, _("Included in publications:")); + if (tuples > 0) + printTableAddFooter(&cont, _("Included in publications:")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " \"%s\"", + PQgetvalue(result, i, 0)); - /* column list (if any) */ - if (!PQgetisnull(result, i, 2)) - appendPQExpBuffer(&buf, " (%s)", - PQgetvalue(result, i, 2)); + /* column list (if any) */ + if (!PQgetisnull(result, i, 2)) + appendPQExpBuffer(&buf, " (%s)", + PQgetvalue(result, i, 2)); - /* row filter (if any) */ - if (!PQgetisnull(result, i, 1)) - appendPQExpBuffer(&buf, " WHERE %s", - PQgetvalue(result, i, 1)); + /* row filter (if any) */ + if (!PQgetisnull(result, i, 1)) + appendPQExpBuffer(&buf, " WHERE %s", + PQgetvalue(result, i, 1)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* Print publications where the table is in the EXCEPT clause */ if (pset.sversion >= 190000) @@ -3805,7 +3804,7 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) ncols++; } appendPQExpBufferStr(&buf, "\n, r.rolreplication"); - appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); + appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_roles r\n"); @@ -3860,8 +3859,8 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) if (strcmp(PQgetvalue(res, i, (verbose ? 9 : 8)), "t") == 0) add_role_attribute(&buf, _("Replication")); - if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) - add_role_attribute(&buf, _("Bypass RLS")); + if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) + add_role_attribute(&buf, _("Bypass RLS")); conns = atoi(PQgetvalue(res, i, 6)); if (conns >= 0) @@ -5155,14 +5154,14 @@ listCollations(const char *pattern, bool verbose, bool showSystem) gettext_noop("Schema"), gettext_noop("Name")); - appendPQExpBuffer(&buf, - " CASE c.collprovider " - "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " - "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " - "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " - "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " - "END AS \"%s\",\n", - gettext_noop("Provider")); + appendPQExpBuffer(&buf, + " CASE c.collprovider " + "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " + "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " + "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " + "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " + "END AS \"%s\",\n", + gettext_noop("Provider")); appendPQExpBuffer(&buf, " c.collcollate AS \"%s\",\n" -- 2.50.1 (Apple Git-155) --aHl3HfeiUuO3zeNC-- ^ permalink raw reply [nested|flat] 59+ messages in thread
* [PATCH v6 4/4] run pgindent and pgperltidy @ 2026-06-30 18:24 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 59+ messages in thread From: Nathan Bossart @ 2026-06-30 18:24 UTC (permalink / raw) --- src/bin/pg_dump/pg_dump.c | 464 ++++++++++----------- src/bin/pg_dump/pg_dumpall.c | 30 +- src/bin/pg_upgrade/check.c | 16 +- src/bin/pg_upgrade/controldata.c | 2 +- src/bin/pg_upgrade/exec.c | 8 +- src/bin/pg_upgrade/multixact_rewrite.c | 80 ++-- src/bin/pg_upgrade/pg_upgrade.c | 34 +- src/bin/pg_upgrade/relfilenumber.c | 54 +-- src/bin/pg_upgrade/t/006_transfer_modes.pl | 33 +- src/bin/psql/command.c | 29 +- src/bin/psql/describe.c | 461 ++++++++++---------- 11 files changed, 601 insertions(+), 610 deletions(-) diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 65bd15ebfd2..5673268b467 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -1491,8 +1491,8 @@ setup_connection(Archive *AH, const char *dumpencoding, * Disable timeouts if supported. */ ExecuteSqlStatement(AH, "SET statement_timeout = 0"); - ExecuteSqlStatement(AH, "SET lock_timeout = 0"); - ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); + ExecuteSqlStatement(AH, "SET lock_timeout = 0"); + ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); if (AH->remoteVersion >= 170000) ExecuteSqlStatement(AH, "SET transaction_timeout = 0"); @@ -1505,10 +1505,10 @@ setup_connection(Archive *AH, const char *dumpencoding, /* * Adjust row-security mode, if supported. */ - if (dopt->enable_row_security) - ExecuteSqlStatement(AH, "SET row_security = on"); - else - ExecuteSqlStatement(AH, "SET row_security = off"); + if (dopt->enable_row_security) + ExecuteSqlStatement(AH, "SET row_security = on"); + else + ExecuteSqlStatement(AH, "SET row_security = off"); /* * For security reasons, we restrict the expansion of non-system views and @@ -1933,10 +1933,9 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) addObjectDependency(dobj, ext->dobj.dumpId); /* - * Mark the member object to have any non-initial ACLs - * dumped. (Any initial ACLs will be removed later, using data from - * pg_init_privs, so that we'll dump only the delta from the extension's - * initial setup.) + * Mark the member object to have any non-initial ACLs dumped. (Any + * initial ACLs will be removed later, using data from pg_init_privs, so + * that we'll dump only the delta from the extension's initial setup.) * * In binary upgrades, we still dump all components of the members * individually, since the idea is to exactly reproduce the database @@ -1953,7 +1952,7 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) if (fout->dopt->binary_upgrade) dobj->dump = ext->dobj.dump; else - dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); + dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); return true; } @@ -1987,9 +1986,9 @@ selectDumpableNamespace(NamespaceInfo *nsinfo, Archive *fout) else if (strcmp(nsinfo->dobj.name, "pg_catalog") == 0) { /* - * We dump out any ACLs defined in pg_catalog, if - * they are interesting (and not the original ACLs which were set at - * initdb time, see pg_init_privs). + * We dump out any ACLs defined in pg_catalog, if they are interesting + * (and not the original ACLs which were set at initdb time, see + * pg_init_privs). */ nsinfo->dobj.dump_contains = nsinfo->dobj.dump = DUMP_COMPONENT_ACL; } @@ -3296,7 +3295,7 @@ dumpDatabase(Archive *fout) "datcollate, datctype, datfrozenxid, " "datacl, acldefault('d', datdba) AS acldefault, " "datistemplate, datconnlimit, "); - appendPQExpBufferStr(dbQry, "datminmxid, "); + appendPQExpBufferStr(dbQry, "datminmxid, "); if (fout->remoteVersion >= 170000) appendPQExpBufferStr(dbQry, "datlocprovider, datlocale, datcollversion, "); else if (fout->remoteVersion >= 150000) @@ -3638,11 +3637,11 @@ dumpDatabase(Archive *fout) ii_oid, ii_relminmxid; - appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" - "FROM pg_catalog.pg_class\n" - "WHERE oid IN (%u, %u, %u, %u);\n", - LargeObjectRelationId, LargeObjectLOidPNIndexId, - LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); + appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" + "FROM pg_catalog.pg_class\n" + "WHERE oid IN (%u, %u, %u, %u);\n", + LargeObjectRelationId, LargeObjectLOidPNIndexId, + LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); lo_res = ExecuteSqlQuery(fout, loFrozenQry->data, PGRES_TUPLES_OK); @@ -4274,7 +4273,7 @@ getPolicies(Archive *fout, TableInfo tblinfo[], int numTables) printfPQExpBuffer(query, "SELECT pol.oid, pol.tableoid, pol.polrelid, pol.polname, pol.polcmd, "); - appendPQExpBufferStr(query, "pol.polpermissive, "); + appendPQExpBufferStr(query, "pol.polpermissive, "); appendPQExpBuffer(query, "CASE WHEN pol.polroles = '{0}' THEN NULL ELSE " " pg_catalog.array_to_string(ARRAY(SELECT pg_catalog.quote_ident(rolname) from pg_catalog.pg_roles WHERE oid = ANY(pol.polroles)), ', ') END AS polroles, " @@ -6633,9 +6632,9 @@ getAccessMethods(Archive *fout) * Select all access methods from pg_am table. */ appendPQExpBufferStr(query, "SELECT tableoid, oid, amname, "); - appendPQExpBufferStr(query, - "amtype, " - "amhandler::pg_catalog.regproc AS amhandler "); + appendPQExpBufferStr(query, + "amtype, " + "amhandler::pg_catalog.regproc AS amhandler "); appendPQExpBufferStr(query, "FROM pg_am"); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6827,35 +6826,35 @@ getAggregates(Archive *fout) * Find all interesting aggregates. See comment in getFuncs() for the * rationale behind the filtering logic. */ - agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" - : "p.proisagg"); + agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" + : "p.proisagg"); - appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " - "p.proname AS aggname, " - "p.pronamespace AS aggnamespace, " - "p.pronargs, p.proargtypes, " - "p.proowner, " - "p.proacl AS aggacl, " - "acldefault('f', p.proowner) AS acldefault " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s AND (" - "p.pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog') OR " - "p.proacl IS DISTINCT FROM pip.initprivs", - agg_check); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - " OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); - appendPQExpBufferChar(query, ')'); + appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " + "p.proname AS aggname, " + "p.pronamespace AS aggnamespace, " + "p.pronargs, p.proargtypes, " + "p.proowner, " + "p.proacl AS aggacl, " + "acldefault('f', p.proowner) AS acldefault " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s AND (" + "p.pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog') OR " + "p.proacl IS DISTINCT FROM pip.initprivs", + agg_check); + if (dopt->binary_upgrade) + appendPQExpBufferStr(query, + " OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6957,53 +6956,53 @@ getFuncs(Archive *fout) * include them, since we want to dump extension members individually in * that mode. Also, if they are used by casts or transforms then we need * to gather the information about them, though they won't be dumped if - * they are built-in. Also, include functions in - * pg_catalog if they have an ACL different from what's shown in - * pg_init_privs (so we have to join to pg_init_privs; annoying). + * they are built-in. Also, include functions in pg_catalog if they have + * an ACL different from what's shown in pg_init_privs (so we have to join + * to pg_init_privs; annoying). */ - not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" - : "NOT p.proisagg"); + not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" + : "NOT p.proisagg"); - appendPQExpBuffer(query, - "SELECT p.tableoid, p.oid, p.proname, p.prolang, " - "p.pronargs, p.proargtypes, p.prorettype, " - "p.proacl, " - "acldefault('f', p.proowner) AS acldefault, " - "p.pronamespace, " - "p.proowner " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s" - "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " - "WHERE classid = 'pg_proc'::regclass AND " - "objid = p.oid AND deptype = 'i')" - "\n AND (" - "\n pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog')" - "\n OR EXISTS (SELECT 1 FROM pg_cast" - "\n WHERE pg_cast.oid > %u " - "\n AND p.oid = pg_cast.castfunc)" - "\n OR EXISTS (SELECT 1 FROM pg_transform" - "\n WHERE pg_transform.oid > %u AND " - "\n (p.oid = pg_transform.trffromsql" - "\n OR p.oid = pg_transform.trftosql))", - not_agg_check, - g_last_builtin_oid, - g_last_builtin_oid); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); + appendPQExpBuffer(query, + "SELECT p.tableoid, p.oid, p.proname, p.prolang, " + "p.pronargs, p.proargtypes, p.prorettype, " + "p.proacl, " + "acldefault('f', p.proowner) AS acldefault, " + "p.pronamespace, " + "p.proowner " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s" + "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " + "WHERE classid = 'pg_proc'::regclass AND " + "objid = p.oid AND deptype = 'i')" + "\n AND (" + "\n pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog')" + "\n OR EXISTS (SELECT 1 FROM pg_cast" + "\n WHERE pg_cast.oid > %u " + "\n AND p.oid = pg_cast.castfunc)" + "\n OR EXISTS (SELECT 1 FROM pg_transform" + "\n WHERE pg_transform.oid > %u AND " + "\n (p.oid = pg_transform.trffromsql" + "\n OR p.oid = pg_transform.trftosql))", + not_agg_check, + g_last_builtin_oid, + g_last_builtin_oid); + if (dopt->binary_upgrade) appendPQExpBufferStr(query, - "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); - appendPQExpBufferChar(query, ')'); + "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferStr(query, + "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -7252,31 +7251,31 @@ getTables(Archive *fout, int *numTables) appendPQExpBufferStr(query, "c.relhasoids, "); - appendPQExpBufferStr(query, - "c.relispopulated, "); + appendPQExpBufferStr(query, + "c.relispopulated, "); - appendPQExpBufferStr(query, - "c.relreplident, "); + appendPQExpBufferStr(query, + "c.relreplident, "); - appendPQExpBufferStr(query, - "c.relrowsecurity, c.relforcerowsecurity, "); + appendPQExpBufferStr(query, + "c.relrowsecurity, c.relforcerowsecurity, "); - appendPQExpBufferStr(query, - "c.relminmxid, tc.relminmxid AS tminmxid, "); + appendPQExpBufferStr(query, + "c.relminmxid, tc.relminmxid AS tminmxid, "); - appendPQExpBufferStr(query, - "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); + appendPQExpBufferStr(query, + "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); - appendPQExpBufferStr(query, - "am.amname, "); + appendPQExpBufferStr(query, + "am.amname, "); - appendPQExpBufferStr(query, - "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); + appendPQExpBufferStr(query, + "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); - appendPQExpBufferStr(query, - "c.relispartition AS ispartition "); + appendPQExpBufferStr(query, + "c.relispartition AS ispartition "); /* * Left join to pg_depend to pick up dependency info linking sequences to @@ -7296,8 +7295,8 @@ getTables(Archive *fout, int *numTables) /* * Left join to pg_am to pick up the amname. */ - appendPQExpBufferStr(query, - "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); + appendPQExpBufferStr(query, + "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); /* * We purposefully ignore toast OIDs for partitioned tables; the reason is @@ -7868,8 +7867,8 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables) "t.reloptions AS indreloptions, "); - appendPQExpBufferStr(query, - "i.indisreplident, "); + appendPQExpBufferStr(query, + "i.indisreplident, "); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -9313,8 +9312,8 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables) appendPQExpBufferStr(q, "'' AS attcompression,\n"); - appendPQExpBufferStr(q, - "a.attidentity,\n"); + appendPQExpBufferStr(q, + "a.attidentity,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(q, @@ -10717,73 +10716,73 @@ getAdditionalACLs(Archive *fout) PQclear(res); /* Fetch initial-privileges data */ - printfPQExpBuffer(query, - "SELECT objoid, classoid, objsubid, privtype, initprivs " - "FROM pg_init_privs"); + printfPQExpBuffer(query, + "SELECT objoid, classoid, objsubid, privtype, initprivs " + "FROM pg_init_privs"); - res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); + res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); - ntups = PQntuples(res); - for (i = 0; i < ntups; i++) - { - Oid objoid = atooid(PQgetvalue(res, i, 0)); - Oid classoid = atooid(PQgetvalue(res, i, 1)); - int objsubid = atoi(PQgetvalue(res, i, 2)); - char privtype = *(PQgetvalue(res, i, 3)); - char *initprivs = PQgetvalue(res, i, 4); - CatalogId objId; - DumpableObject *dobj; + ntups = PQntuples(res); + for (i = 0; i < ntups; i++) + { + Oid objoid = atooid(PQgetvalue(res, i, 0)); + Oid classoid = atooid(PQgetvalue(res, i, 1)); + int objsubid = atoi(PQgetvalue(res, i, 2)); + char privtype = *(PQgetvalue(res, i, 3)); + char *initprivs = PQgetvalue(res, i, 4); + CatalogId objId; + DumpableObject *dobj; - objId.tableoid = classoid; - objId.oid = objoid; - dobj = findObjectByCatalogId(objId); - /* OK to ignore entries we haven't got a DumpableObject for */ - if (dobj) + objId.tableoid = classoid; + objId.oid = objoid; + dobj = findObjectByCatalogId(objId); + /* OK to ignore entries we haven't got a DumpableObject for */ + if (dobj) + { + /* Cope with sub-object initprivs */ + if (objsubid != 0) { - /* Cope with sub-object initprivs */ - if (objsubid != 0) - { - if (dobj->objType == DO_TABLE) - { - /* For a column initprivs, set the table's ACL flags */ - dobj->components |= DUMP_COMPONENT_ACL; - ((TableInfo *) dobj)->hascolumnACLs = true; - } - else - pg_log_warning("unsupported pg_init_privs entry: %u %u %d", - classoid, objoid, objsubid); - continue; - } - - /* - * We ignore any pg_init_privs.initprivs entry for the public - * schema, as explained in getNamespaces(). - */ - if (dobj->objType == DO_NAMESPACE && - strcmp(dobj->name, "public") == 0) - continue; - - /* Else it had better be of a type we think has ACLs */ - if (dobj->objType == DO_NAMESPACE || - dobj->objType == DO_TYPE || - dobj->objType == DO_FUNC || - dobj->objType == DO_AGG || - dobj->objType == DO_TABLE || - dobj->objType == DO_PROCLANG || - dobj->objType == DO_FDW || - dobj->objType == DO_FOREIGN_SERVER) + if (dobj->objType == DO_TABLE) { - DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; - - daobj->dacl.privtype = privtype; - daobj->dacl.initprivs = pstrdup(initprivs); + /* For a column initprivs, set the table's ACL flags */ + dobj->components |= DUMP_COMPONENT_ACL; + ((TableInfo *) dobj)->hascolumnACLs = true; } else pg_log_warning("unsupported pg_init_privs entry: %u %u %d", classoid, objoid, objsubid); + continue; + } + + /* + * We ignore any pg_init_privs.initprivs entry for the public + * schema, as explained in getNamespaces(). + */ + if (dobj->objType == DO_NAMESPACE && + strcmp(dobj->name, "public") == 0) + continue; + + /* Else it had better be of a type we think has ACLs */ + if (dobj->objType == DO_NAMESPACE || + dobj->objType == DO_TYPE || + dobj->objType == DO_FUNC || + dobj->objType == DO_AGG || + dobj->objType == DO_TABLE || + dobj->objType == DO_PROCLANG || + dobj->objType == DO_FDW || + dobj->objType == DO_FOREIGN_SERVER) + { + DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; + + daobj->dacl.privtype = privtype; + daobj->dacl.initprivs = pstrdup(initprivs); } + else + pg_log_warning("unsupported pg_init_privs entry: %u %u %d", + classoid, objoid, objsubid); } - PQclear(res); + } + PQclear(res); destroyPQExpBuffer(query); } @@ -11128,8 +11127,8 @@ dumpRelationStats_dumper(Archive *fout, const void *userArg, const TocEntry *te) * The results must be in the order of the relations supplied in the * parameters to ensure we remain in sync as we walk through the TOC. * - * For versions before 19, the redundant filter clause on s.tablename = - * ANY(...) seems sufficient to convince the planner to use + * For versions before 19, the redundant filter clause on s.tablename + * = ANY(...) seems sufficient to convince the planner to use * pg_class_relname_nsp_index, which avoids a full scan of pg_stats. * In newer versions, pg_stats returns the table OIDs, eliminating the * need for that hack. @@ -13469,11 +13468,11 @@ dumpFunc(Archive *fout, const FuncInfo *finfo) "pg_catalog.pg_get_function_result(p.oid) AS funcresult,\n" "proleakproof,\n"); - appendPQExpBufferStr(query, - "array_to_string(protrftypes, ' ') AS protrftypes,\n"); + appendPQExpBufferStr(query, + "array_to_string(protrftypes, ' ') AS protrftypes,\n"); - appendPQExpBufferStr(query, - "proparallel,\n"); + appendPQExpBufferStr(query, + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -14963,9 +14962,9 @@ dumpCollation(Archive *fout, const CollInfo *collinfo) /* Get collation-specific details */ appendPQExpBufferStr(query, "SELECT "); - appendPQExpBufferStr(query, - "collprovider, " - "collversion, "); + appendPQExpBufferStr(query, + "collprovider, " + "collversion, "); if (fout->remoteVersion >= 120000) appendPQExpBufferStr(query, @@ -15372,23 +15371,23 @@ dumpAgg(Archive *fout, const AggInfo *agginfo) "pg_catalog.pg_get_function_arguments(p.oid) AS funcargs,\n" "pg_catalog.pg_get_function_identity_arguments(p.oid) AS funciargs,\n"); - appendPQExpBufferStr(query, - "aggkind,\n" - "aggmtransfn,\n" - "aggminvtransfn,\n" - "aggmfinalfn,\n" - "aggmtranstype::pg_catalog.regtype,\n" - "aggfinalextra,\n" - "aggmfinalextra,\n" - "aggtransspace,\n" - "aggmtransspace,\n" - "aggminitval,\n"); + appendPQExpBufferStr(query, + "aggkind,\n" + "aggmtransfn,\n" + "aggminvtransfn,\n" + "aggmfinalfn,\n" + "aggmtranstype::pg_catalog.regtype,\n" + "aggfinalextra,\n" + "aggmfinalextra,\n" + "aggtransspace,\n" + "aggmtransspace,\n" + "aggminitval,\n"); - appendPQExpBufferStr(query, - "aggcombinefn,\n" - "aggserialfn,\n" - "aggdeserialfn,\n" - "proparallel,\n"); + appendPQExpBufferStr(query, + "aggcombinefn,\n" + "aggserialfn,\n" + "aggdeserialfn,\n" + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -16848,30 +16847,30 @@ dumpTable(Archive *fout, const TableInfo *tbinfo) appendPQExpBufferStr(query, "PREPARE getColumnACLs(pg_catalog.oid) AS\n"); - /* - * In principle we should call acldefault('c', relowner) to - * get the default ACL for a column. However, we don't - * currently store the numeric OID of the relowner in - * TableInfo. We could convert the owner name using regrole, - * but that creates a risk of failure due to concurrent role - * renames. Given that the default ACL for columns is empty - * and is likely to stay that way, it's not worth extra cycles - * and risk to avoid hard-wiring that knowledge here. - */ - appendPQExpBufferStr(query, - "SELECT at.attname, " - "at.attacl, " - "'{}' AS acldefault, " - "pip.privtype, pip.initprivs " - "FROM pg_catalog.pg_attribute at " - "LEFT JOIN pg_catalog.pg_init_privs pip ON " - "(at.attrelid = pip.objoid " - "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " - "AND at.attnum = pip.objsubid) " - "WHERE at.attrelid = $1 AND " - "NOT at.attisdropped " - "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " - "ORDER BY at.attnum"); + /* + * In principle we should call acldefault('c', relowner) to get + * the default ACL for a column. However, we don't currently + * store the numeric OID of the relowner in TableInfo. We could + * convert the owner name using regrole, but that creates a risk + * of failure due to concurrent role renames. Given that the + * default ACL for columns is empty and is likely to stay that + * way, it's not worth extra cycles and risk to avoid hard-wiring + * that knowledge here. + */ + appendPQExpBufferStr(query, + "SELECT at.attname, " + "at.attacl, " + "'{}' AS acldefault, " + "pip.privtype, pip.initprivs " + "FROM pg_catalog.pg_attribute at " + "LEFT JOIN pg_catalog.pg_init_privs pip ON " + "(at.attrelid = pip.objoid " + "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " + "AND at.attnum = pip.objsubid) " + "WHERE at.attrelid = $1 AND " + "NOT at.attisdropped " + "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " + "ORDER BY at.attnum"); ExecuteSqlStatement(fout, query->data); @@ -19165,7 +19164,7 @@ collectSequences(Archive *fout) * pg_get_sequence_data(), but we only do so for non-schema-only dumps. */ if (fout->remoteVersion < 180000 || - (!fout->dopt->dumpData && !fout->dopt->sequence_data)) + (!fout->dopt->dumpData && !fout->dopt->sequence_data)) query = "SELECT seqrelid, format_type(seqtypid, NULL), " "seqstart, seqincrement, " "seqmax, seqmin, " @@ -19227,15 +19226,14 @@ dumpSequence(Archive *fout, const TableInfo *tbinfo) qseqname = pg_strdup(fmtId(tbinfo->dobj.name)); /* - * The sequence information is gathered in a sorted - * table before any calls to dumpSequence(). See collectSequences() for - * more information. + * The sequence information is gathered in a sorted table before any calls + * to dumpSequence(). See collectSequences() for more information. */ - Assert(sequences); + Assert(sequences); - key.oid = tbinfo->dobj.catId.oid; - seq = bsearch(&key, sequences, nsequences, - sizeof(SequenceItem), SequenceItemCmp); + key.oid = tbinfo->dobj.catId.oid; + seq = bsearch(&key, sequences, nsequences, + sizeof(SequenceItem), SequenceItemCmp); /* Calculate default limits for a sequence of this type */ is_ascending = (seq->incby >= 0); diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c index e68937c9934..afcd9a218d8 100644 --- a/src/bin/pg_dump/pg_dumpall.c +++ b/src/bin/pg_dump/pg_dumpall.c @@ -785,11 +785,11 @@ dropRoles(PGconn *conn) int i_rolname; int i; - printfPQExpBuffer(buf, - "SELECT rolname " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 1", role_catalog); + printfPQExpBuffer(buf, + "SELECT rolname " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 1", role_catalog); res = executeQuery(conn, buf->data); @@ -843,16 +843,16 @@ dumpRoles(PGconn *conn) * Notes: rolconfig is dumped later, and pg_authid must be used for * extracting rolcomment regardless of role_catalog. */ - printfPQExpBuffer(buf, - "SELECT oid, rolname, rolsuper, rolinherit, " - "rolcreaterole, rolcreatedb, " - "rolcanlogin, rolconnlimit, rolpassword, " - "rolvaliduntil, rolreplication, rolbypassrls, " - "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " - "rolname = current_user AS is_current_user " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 2", role_catalog); + printfPQExpBuffer(buf, + "SELECT oid, rolname, rolsuper, rolinherit, " + "rolcreaterole, rolcreatedb, " + "rolcanlogin, rolconnlimit, rolpassword, " + "rolvaliduntil, rolreplication, rolbypassrls, " + "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " + "rolname = current_user AS is_current_user " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 2", role_catalog); res = executeQuery(conn, buf->data); diff --git a/src/bin/pg_upgrade/check.c b/src/bin/pg_upgrade/check.c index 786c1474829..f725f5ee3e2 100644 --- a/src/bin/pg_upgrade/check.c +++ b/src/bin/pg_upgrade/check.c @@ -1475,15 +1475,15 @@ check_for_incompatible_polymorphics(ClusterInfo *cluster) ", 'array_cat(anyarray,anyarray)'" ", 'array_prepend(anyelement,anyarray)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_remove(anyarray,anyelement)'" - ", 'array_replace(anyarray,anyelement,anyelement)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_remove(anyarray,anyelement)'" + ", 'array_replace(anyarray,anyelement,anyelement)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_position(anyarray,anyelement)'" - ", 'array_position(anyarray,anyelement,integer)'" - ", 'array_positions(anyarray,anyelement)'" - ", 'width_bucket(anyelement,anyarray)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_position(anyarray,anyelement)'" + ", 'array_position(anyarray,anyelement,integer)'" + ", 'array_positions(anyarray,anyelement)'" + ", 'width_bucket(anyelement,anyarray)'"); /* * The query below hardcodes FirstNormalObjectId as 16384 rather than diff --git a/src/bin/pg_upgrade/controldata.c b/src/bin/pg_upgrade/controldata.c index 8f81c9e9582..02ea02df60f 100644 --- a/src/bin/pg_upgrade/controldata.c +++ b/src/bin/pg_upgrade/controldata.c @@ -228,7 +228,7 @@ get_control_data(ClusterInfo *cluster) p++; /* remove ':' char */ cluster->controldata.chkpnt_nxtepoch = str2uint(p); - p = strchr(p, ':'); + p = strchr(p, ':'); if (p == NULL || strlen(p) <= 1) pg_fatal("%d: controldata retrieval problem", __LINE__); diff --git a/src/bin/pg_upgrade/exec.c b/src/bin/pg_upgrade/exec.c index 44355feea30..a1bdbf373e3 100644 --- a/src/bin/pg_upgrade/exec.c +++ b/src/bin/pg_upgrade/exec.c @@ -55,7 +55,7 @@ get_bin_version(ClusterInfo *cluster) if (sscanf(cmd_output, "%*s %*s %d.%d", &v1, &v2) < 1) pg_fatal("could not get pg_ctl version output from %s", cmd); - cluster->bin_version = v1 * 10000; + cluster->bin_version = v1 * 10000; } @@ -344,8 +344,8 @@ check_data_dir(ClusterInfo *cluster) check_single_dir(pg_data, "pg_subtrans"); check_single_dir(pg_data, PG_TBLSPC_DIR); check_single_dir(pg_data, "pg_twophase"); - check_single_dir(pg_data, "pg_wal"); - check_single_dir(pg_data, "pg_xact"); + check_single_dir(pg_data, "pg_wal"); + check_single_dir(pg_data, "pg_xact"); } @@ -385,7 +385,7 @@ check_bin_dir(ClusterInfo *cluster, bool check_versions) */ get_bin_version(cluster); - check_exec(cluster->bindir, "pg_resetwal", check_versions); + check_exec(cluster->bindir, "pg_resetwal", check_versions); if (cluster == &new_cluster) { diff --git a/src/bin/pg_upgrade/multixact_rewrite.c b/src/bin/pg_upgrade/multixact_rewrite.c index c45b3183684..c7a1416494d 100644 --- a/src/bin/pg_upgrade/multixact_rewrite.c +++ b/src/bin/pg_upgrade/multixact_rewrite.c @@ -61,52 +61,52 @@ rewrite_multixacts(MultiXactId from_multi, MultiXactId to_multi) * Convert old multixids, if needed, by reading them one-by-one from the * old cluster. */ - old_reader = AllocOldMultiXactRead(old_cluster.pgdata, - old_cluster.controldata.chkpnt_nxtmulti, - old_cluster.controldata.chkpnt_nxtmxoff); + old_reader = AllocOldMultiXactRead(old_cluster.pgdata, + old_cluster.controldata.chkpnt_nxtmulti, + old_cluster.controldata.chkpnt_nxtmxoff); - for (MultiXactId multi = from_multi; multi != to_multi;) - { - MultiXactMember member; - bool multixid_valid; - - /* - * Read this multixid's members. - * - * Locking-only XIDs that may be part of multi-xids don't matter - * after upgrade, as there can be no transactions running across - * upgrade. So as a small optimization, we only read one member - * from each multixid: the one updating one, or if there was no - * update, arbitrarily the first locking xid. - */ - multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); + for (MultiXactId multi = from_multi; multi != to_multi;) + { + MultiXactMember member; + bool multixid_valid; - /* - * Write the new offset to pg_multixact/offsets. - * - * Even if this multixid is invalid, we still need to write its - * offset if the *previous* multixid was valid. That's because - * when reading a multixid, the number of members is calculated - * from the difference between the two offsets. - */ - RecordMultiXactOffset(offsets_writer, multi, - (multixid_valid || prev_multixid_valid) ? next_offset : 0); + /* + * Read this multixid's members. + * + * Locking-only XIDs that may be part of multi-xids don't matter after + * upgrade, as there can be no transactions running across upgrade. So + * as a small optimization, we only read one member from each + * multixid: the one updating one, or if there was no update, + * arbitrarily the first locking xid. + */ + multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); - /* Write the members */ - if (multixid_valid) - { - RecordMultiXactMembers(members_writer, next_offset, 1, &member); - next_offset += 1; - } + /* + * Write the new offset to pg_multixact/offsets. + * + * Even if this multixid is invalid, we still need to write its offset + * if the *previous* multixid was valid. That's because when reading + * a multixid, the number of members is calculated from the difference + * between the two offsets. + */ + RecordMultiXactOffset(offsets_writer, multi, + (multixid_valid || prev_multixid_valid) ? next_offset : 0); - /* Advance to next multixid, handling wraparound */ - multi++; - if (multi < FirstMultiXactId) - multi = FirstMultiXactId; - prev_multixid_valid = multixid_valid; + /* Write the members */ + if (multixid_valid) + { + RecordMultiXactMembers(members_writer, next_offset, 1, &member); + next_offset += 1; } - FreeOldMultiXactReader(old_reader); + /* Advance to next multixid, handling wraparound */ + multi++; + if (multi < FirstMultiXactId) + multi = FirstMultiXactId; + prev_multixid_valid = multixid_valid; + } + + FreeOldMultiXactReader(old_reader); /* Write the final 'next' offset to the last SLRU page */ RecordMultiXactOffset(offsets_writer, to_multi, diff --git a/src/bin/pg_upgrade/pg_upgrade.c b/src/bin/pg_upgrade/pg_upgrade.c index c6af9035665..7366fd4627c 100644 --- a/src/bin/pg_upgrade/pg_upgrade.c +++ b/src/bin/pg_upgrade/pg_upgrade.c @@ -833,7 +833,7 @@ copy_xact_xlog_xid(void) * Determine the range of multixacts to convert. */ nxtmulti = old_cluster.controldata.chkpnt_nxtmulti; - oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; + oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; /* handle wraparound */ if (nxtmulti < FirstMultiXactId) nxtmulti = FirstMultiXactId; @@ -898,15 +898,15 @@ set_frozenxids(void) int i_datname; int i_datallowconn; - prep_status("Setting frozenxid and minmxid counters in new cluster"); + prep_status("Setting frozenxid and minmxid counters in new cluster"); conn_template1 = connectToServer(&new_cluster, "template1"); - /* set pg_database.datfrozenxid */ - PQclear(executeQueryOrDie(conn_template1, - "UPDATE pg_catalog.pg_database " - "SET datfrozenxid = '%u'", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_database.datfrozenxid */ + PQclear(executeQueryOrDie(conn_template1, + "UPDATE pg_catalog.pg_database " + "SET datfrozenxid = '%u'", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_database.datminmxid */ PQclear(executeQueryOrDie(conn_template1, @@ -942,16 +942,16 @@ set_frozenxids(void) conn = connectToServer(&new_cluster, datname); - /* set pg_class.relfrozenxid */ - PQclear(executeQueryOrDie(conn, - "UPDATE pg_catalog.pg_class " - "SET relfrozenxid = '%u' " - /* only heap, materialized view, and TOAST are vacuumed */ - "WHERE relkind IN (" - CppAsString2(RELKIND_RELATION) ", " - CppAsString2(RELKIND_MATVIEW) ", " - CppAsString2(RELKIND_TOASTVALUE) ")", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_class.relfrozenxid */ + PQclear(executeQueryOrDie(conn, + "UPDATE pg_catalog.pg_class " + "SET relfrozenxid = '%u' " + /* only heap, materialized view, and TOAST are vacuumed */ + "WHERE relkind IN (" + CppAsString2(RELKIND_RELATION) ", " + CppAsString2(RELKIND_MATVIEW) ", " + CppAsString2(RELKIND_TOASTVALUE) ")", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_class.relminmxid */ PQclear(executeQueryOrDie(conn, diff --git a/src/bin/pg_upgrade/relfilenumber.c b/src/bin/pg_upgrade/relfilenumber.c index ec2ff7acb21..6c467bdc8a5 100644 --- a/src/bin/pg_upgrade/relfilenumber.c +++ b/src/bin/pg_upgrade/relfilenumber.c @@ -587,32 +587,32 @@ transfer_relfile(FileNameMap *map, const char *type_suffix) /* Copying files might take some time, so give feedback. */ pg_log(PG_STATUS, "%s", old_file); - switch (user_opts.transfer_mode) - { - case TRANSFER_MODE_CLONE: - pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", - old_file, new_file); - cloneFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", - old_file, new_file); - copyFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY_FILE_RANGE: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", - old_file, new_file); - copyFileByRange(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_LINK: - pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", - old_file, new_file); - linkFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_SWAP: - /* swap mode is handled in its own code path */ - pg_fatal("should never happen"); - break; - } + switch (user_opts.transfer_mode) + { + case TRANSFER_MODE_CLONE: + pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", + old_file, new_file); + cloneFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", + old_file, new_file); + copyFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY_FILE_RANGE: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", + old_file, new_file); + copyFileByRange(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_LINK: + pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", + old_file, new_file); + linkFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_SWAP: + /* swap mode is handled in its own code path */ + pg_fatal("should never happen"); + break; + } } } diff --git a/src/bin/pg_upgrade/t/006_transfer_modes.pl b/src/bin/pg_upgrade/t/006_transfer_modes.pl index 9efa5dc863c..360d05c4b68 100644 --- a/src/bin/pg_upgrade/t/006_transfer_modes.pl +++ b/src/bin/pg_upgrade/t/006_transfer_modes.pl @@ -29,10 +29,8 @@ sub test_mode } $new->init(); - $new->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); - $old->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); + $new->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); + $old->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); # We can only test security labels if both the old and new installations # have dummy_seclabel. @@ -76,15 +74,14 @@ sub test_mode "CREATE TABLE test4 AS SELECT generate_series(400, 502)"); } - $old->safe_psql('postgres', - "CREATE TABLESPACE inplc_tblspc LOCATION ''"); - $old->safe_psql('postgres', - "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); - $old->safe_psql('postgres', - "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" - ); - $old->safe_psql('testdb3', - "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); + $old->safe_psql('postgres', "CREATE TABLESPACE inplc_tblspc LOCATION ''"); + $old->safe_psql('postgres', + "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); + $old->safe_psql('postgres', + "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" + ); + $old->safe_psql('testdb3', + "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); # While we are here, test handling of large objects. $old->safe_psql( @@ -152,12 +149,10 @@ sub test_mode } # Tests for in-place tablespaces. - $result = - $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); - is($result, '104', "test5 data after pg_upgrade $mode"); - $result = - $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); - is($result, '105', "test6 data after pg_upgrade $mode"); + $result = $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); + is($result, '104', "test5 data after pg_upgrade $mode"); + $result = $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); + is($result, '105', "test6 data after pg_upgrade $mode"); # Tests for large objects $result = $new->safe_psql('postgres', "SELECT lo_get(4532)"); diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index 44ef11d980e..c90bf8bbde2 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -6278,23 +6278,22 @@ get_create_object_cmd(EditableObjectType obj_type, Oid oid, * ensure the right view gets replaced. Also, check relation kind * to be sure it's a view. * - * Views may have WITH [LOCAL|CASCADED] - * CHECK OPTION. These are not part of the view definition - * returned by pg_get_viewdef() and so need to be retrieved - * separately. Materialized views may have - * arbitrary storage parameter reloptions. + * Views may have WITH [LOCAL|CASCADED] CHECK OPTION. These are + * not part of the view definition returned by pg_get_viewdef() + * and so need to be retrieved separately. Materialized views may + * have arbitrary storage parameter reloptions. */ printfPQExpBuffer(query, "/* %s */\n", _("Get view's definition and details")); - appendPQExpBuffer(query, - "SELECT nspname, relname, relkind, " - "pg_catalog.pg_get_viewdef(c.oid, true), " - "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " - "FROM pg_catalog.pg_class c " - "LEFT JOIN pg_catalog.pg_namespace n " - "ON c.relnamespace = n.oid WHERE c.oid = %u", - oid); + appendPQExpBuffer(query, + "SELECT nspname, relname, relkind, " + "pg_catalog.pg_get_viewdef(c.oid, true), " + "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " + "FROM pg_catalog.pg_class c " + "LEFT JOIN pg_catalog.pg_namespace n " + "ON c.relnamespace = n.oid WHERE c.oid = %u", + oid); break; } diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index ce99137c613..ac0c55e7aa5 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -387,19 +387,19 @@ describeFunctions(const char *functypes, const char *func_pattern, gettext_noop("stable"), gettext_noop("volatile"), gettext_noop("Volatility")); - appendPQExpBuffer(&buf, - ",\n CASE\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" - " END as \"%s\"", - gettext_noop("restricted"), - gettext_noop("safe"), - gettext_noop("unsafe"), - gettext_noop("Parallel")); + appendPQExpBuffer(&buf, + ",\n CASE\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" + " END as \"%s\"", + gettext_noop("restricted"), + gettext_noop("safe"), + gettext_noop("unsafe"), + gettext_noop("Parallel")); appendPQExpBuffer(&buf, ",\n pg_catalog.pg_get_userbyid(p.proowner) as \"%s\"" ",\n CASE WHEN prosecdef THEN '%s' ELSE '%s' END AS \"%s\"" @@ -599,8 +599,8 @@ describeFunctions(const char *functypes, const char *func_pattern, myopt.title = _("List of functions"); myopt.translate_header = true; - myopt.translate_columns = translate_columns; - myopt.n_translate_columns = lengthof(translate_columns); + myopt.translate_columns = translate_columns; + myopt.n_translate_columns = lengthof(translate_columns); printQuery(res, &myopt, pset.queryFout, false, pset.logfile); @@ -1086,38 +1086,38 @@ permissionsList(const char *pattern, bool showSystem) " ), E'\\n') AS \"%s\"", gettext_noop("Column privileges")); - appendPQExpBuffer(&buf, - ",\n pg_catalog.array_to_string(ARRAY(\n" - " SELECT polname\n" - " || CASE WHEN NOT polpermissive THEN\n" - " E' (RESTRICTIVE)'\n" - " ELSE '' END\n" - " || CASE WHEN polcmd != '*' THEN\n" - " E' (' || polcmd::pg_catalog.text || E'):'\n" - " ELSE E':'\n" - " END\n" - " || CASE WHEN polqual IS NOT NULL THEN\n" - " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" - " ELSE E''\n" - " END\n" - " || CASE WHEN polwithcheck IS NOT NULL THEN\n" - " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" - " ELSE E''\n" - " END" - " || CASE WHEN polroles <> '{0}' THEN\n" - " E'\\n to: ' || pg_catalog.array_to_string(\n" - " ARRAY(\n" - " SELECT rolname\n" - " FROM pg_catalog.pg_roles\n" - " WHERE oid = ANY (polroles)\n" - " ORDER BY 1\n" - " ), E', ')\n" - " ELSE E''\n" - " END\n" - " FROM pg_catalog.pg_policy pol\n" - " WHERE polrelid = c.oid), E'\\n')\n" - " AS \"%s\"", - gettext_noop("Policies")); + appendPQExpBuffer(&buf, + ",\n pg_catalog.array_to_string(ARRAY(\n" + " SELECT polname\n" + " || CASE WHEN NOT polpermissive THEN\n" + " E' (RESTRICTIVE)'\n" + " ELSE '' END\n" + " || CASE WHEN polcmd != '*' THEN\n" + " E' (' || polcmd::pg_catalog.text || E'):'\n" + " ELSE E':'\n" + " END\n" + " || CASE WHEN polqual IS NOT NULL THEN\n" + " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" + " ELSE E''\n" + " END\n" + " || CASE WHEN polwithcheck IS NOT NULL THEN\n" + " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" + " ELSE E''\n" + " END" + " || CASE WHEN polroles <> '{0}' THEN\n" + " E'\\n to: ' || pg_catalog.array_to_string(\n" + " ARRAY(\n" + " SELECT rolname\n" + " FROM pg_catalog.pg_roles\n" + " WHERE oid = ANY (polroles)\n" + " ORDER BY 1\n" + " ), E', ')\n" + " ELSE E''\n" + " END\n" + " FROM pg_catalog.pg_policy pol\n" + " WHERE polrelid = c.oid), E'\\n')\n" + " AS \"%s\"", + gettext_noop("Policies")); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_class c\n" " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n" @@ -1675,27 +1675,27 @@ describeOneTableDetails(const char *schemaname, char *footers[3] = {NULL, NULL, NULL}; printfPQExpBuffer(&buf, "/* %s */\n", _("Get sequence information")); - appendPQExpBuffer(&buf, - "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" - " seqstart AS \"%s\",\n" - " seqmin AS \"%s\",\n" - " seqmax AS \"%s\",\n" - " seqincrement AS \"%s\",\n" - " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" - " seqcache AS \"%s\"\n", - gettext_noop("Type"), - gettext_noop("Start"), - gettext_noop("Minimum"), - gettext_noop("Maximum"), - gettext_noop("Increment"), - gettext_noop("yes"), - gettext_noop("no"), - gettext_noop("Cycles?"), - gettext_noop("Cache")); - appendPQExpBuffer(&buf, - "FROM pg_catalog.pg_sequence\n" - "WHERE seqrelid = '%s';", - oid); + appendPQExpBuffer(&buf, + "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" + " seqstart AS \"%s\",\n" + " seqmin AS \"%s\",\n" + " seqmax AS \"%s\",\n" + " seqincrement AS \"%s\",\n" + " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" + " seqcache AS \"%s\"\n", + gettext_noop("Type"), + gettext_noop("Start"), + gettext_noop("Minimum"), + gettext_noop("Maximum"), + gettext_noop("Increment"), + gettext_noop("yes"), + gettext_noop("no"), + gettext_noop("Cycles?"), + gettext_noop("Cache")); + appendPQExpBuffer(&buf, + "FROM pg_catalog.pg_sequence\n" + "WHERE seqrelid = '%s';", + oid); res = PSQLexec(buf.data); if (!res) @@ -1913,7 +1913,7 @@ describeOneTableDetails(const char *schemaname, appendPQExpBufferStr(&buf, ",\n (SELECT c.collname FROM pg_catalog.pg_collation c, pg_catalog.pg_type t\n" " WHERE c.oid = a.attcollation AND t.oid = a.atttypid AND a.attcollation <> t.typcollation) AS attcollation"); attcoll_col = cols++; - appendPQExpBufferStr(&buf, ",\n a.attidentity"); + appendPQExpBufferStr(&buf, ",\n a.attidentity"); attidentity_col = cols++; if (pset.sversion >= 120000) appendPQExpBufferStr(&buf, ",\n a.attgenerated"); @@ -2326,7 +2326,7 @@ describeOneTableDetails(const char *schemaname, CppAsString2(CONSTRAINT_EXCLUSION) ") AND " "condeferred) AS condeferred,\n"); - appendPQExpBufferStr(&buf, "i.indisreplident,\n"); + appendPQExpBufferStr(&buf, "i.indisreplident,\n"); if (pset.sversion >= 150000) appendPQExpBufferStr(&buf, "i.indnullsnotdistinct,\n"); @@ -2431,7 +2431,7 @@ describeOneTableDetails(const char *schemaname, "pg_catalog.pg_get_indexdef(i.indexrelid, 0, true),\n " "pg_catalog.pg_get_constraintdef(con.oid, true), " "contype, condeferrable, condeferred"); - appendPQExpBufferStr(&buf, ", i.indisreplident"); + appendPQExpBufferStr(&buf, ", i.indisreplident"); appendPQExpBufferStr(&buf, ", c2.reltablespace"); if (pset.sversion >= 180000) appendPQExpBufferStr(&buf, ", con.conperiod"); @@ -2682,81 +2682,80 @@ describeOneTableDetails(const char *schemaname, PQclear(result); /* print any row-level policies */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get row-level policies for this table")); - appendPQExpBufferStr(&buf, "SELECT pol.polname,"); - appendPQExpBufferStr(&buf, - " pol.polpermissive,\n"); - appendPQExpBuffer(&buf, - " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" - " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" - " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" - " CASE pol.polcmd\n" - " WHEN 'r' THEN 'SELECT'\n" - " WHEN 'a' THEN 'INSERT'\n" - " WHEN 'w' THEN 'UPDATE'\n" - " WHEN 'd' THEN 'DELETE'\n" - " END AS cmd\n" - "FROM pg_catalog.pg_policy pol\n" - "WHERE pol.polrelid = '%s' ORDER BY 1;", - oid); + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get row-level policies for this table")); + appendPQExpBufferStr(&buf, "SELECT pol.polname,"); + appendPQExpBufferStr(&buf, + " pol.polpermissive,\n"); + appendPQExpBuffer(&buf, + " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" + " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" + " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" + " CASE pol.polcmd\n" + " WHEN 'r' THEN 'SELECT'\n" + " WHEN 'a' THEN 'INSERT'\n" + " WHEN 'w' THEN 'UPDATE'\n" + " WHEN 'd' THEN 'DELETE'\n" + " END AS cmd\n" + "FROM pg_catalog.pg_policy pol\n" + "WHERE pol.polrelid = '%s' ORDER BY 1;", + oid); - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - /* - * Handle cases where RLS is enabled and there are policies, or - * there aren't policies, or RLS isn't enabled but there are - * policies - */ - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies:")); + /* + * Handle cases where RLS is enabled and there are policies, or there + * aren't policies, or RLS isn't enabled but there are policies + */ + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies:")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled):")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled):")); - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); - if (!tableinfo.rowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (row security disabled):")); + if (!tableinfo.rowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (row security disabled):")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " POLICY \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " POLICY \"%s\"", + PQgetvalue(result, i, 0)); - if (*(PQgetvalue(result, i, 1)) == 'f') - appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); + if (*(PQgetvalue(result, i, 1)) == 'f') + appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); - if (!PQgetisnull(result, i, 5)) - appendPQExpBuffer(&buf, " FOR %s", - PQgetvalue(result, i, 5)); + if (!PQgetisnull(result, i, 5)) + appendPQExpBuffer(&buf, " FOR %s", + PQgetvalue(result, i, 5)); - if (!PQgetisnull(result, i, 2)) - { - appendPQExpBuffer(&buf, "\n TO %s", - PQgetvalue(result, i, 2)); - } + if (!PQgetisnull(result, i, 2)) + { + appendPQExpBuffer(&buf, "\n TO %s", + PQgetvalue(result, i, 2)); + } - if (!PQgetisnull(result, i, 3)) - appendPQExpBuffer(&buf, "\n USING (%s)", - PQgetvalue(result, i, 3)); + if (!PQgetisnull(result, i, 3)) + appendPQExpBuffer(&buf, "\n USING (%s)", + PQgetvalue(result, i, 3)); - if (!PQgetisnull(result, i, 4)) - appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", - PQgetvalue(result, i, 4)); + if (!PQgetisnull(result, i, 4)) + appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", + PQgetvalue(result, i, 4)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* print any extended statistics */ if (pset.sversion >= 140000) @@ -3025,115 +3024,115 @@ describeOneTableDetails(const char *schemaname, } /* print any publications */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get publications that publish this table")); - if (pset.sversion >= 150000) + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get publications that publish this table")); + if (pset.sversion >= 150000) + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" + " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" + "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" + "UNION\n" + "SELECT pubname\n" + " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" + " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" + " (SELECT pg_catalog.string_agg(attname, ', ')\n" + " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" + " pg_catalog.pg_attribute\n" + " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" + " ELSE NULL END) " + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" + "WHERE pr.prrelid = '%s'\n", + oid, oid, oid); + + if (pset.sversion >= 190000) { + /* + * Skip entries where this relation appears in the + * publication's EXCEPT list. + */ appendPQExpBuffer(&buf, + " AND NOT pr.prexcept\n" + "UNION\n" "SELECT pubname\n" " , NULL\n" " , NULL\n" "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" - " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" - "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" - "UNION\n" - "SELECT pubname\n" - " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" - " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" - " (SELECT pg_catalog.string_agg(attname, ', ')\n" - " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" - " pg_catalog.pg_attribute\n" - " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" - " ELSE NULL END) " - "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" - "WHERE pr.prrelid = '%s'\n", + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + " AND NOT EXISTS (\n" + " SELECT 1\n" + " FROM pg_catalog.pg_publication_rel pr\n" + " WHERE pr.prpubid = p.oid AND\n" + " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" + "ORDER BY 1;", oid, oid, oid); - - if (pset.sversion >= 190000) - { - /* - * Skip entries where this relation appears in the - * publication's EXCEPT list. - */ - appendPQExpBuffer(&buf, - " AND NOT pr.prexcept\n" - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - " AND NOT EXISTS (\n" - " SELECT 1\n" - " FROM pg_catalog.pg_publication_rel pr\n" - " WHERE pr.prpubid = p.oid AND\n" - " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" - "ORDER BY 1;", - oid, oid, oid); - } - else - { - appendPQExpBuffer(&buf, - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - "ORDER BY 1;", - oid); - } } else { appendPQExpBuffer(&buf, + "UNION\n" "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - "WHERE pr.prrelid = '%s'\n" - "UNION ALL\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" + " , NULL\n" + " , NULL\n" "FROM pg_catalog.pg_publication p\n" "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" "ORDER BY 1;", - oid, oid); + oid); } + } + else + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + "WHERE pr.prrelid = '%s'\n" + "UNION ALL\n" + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + "ORDER BY 1;", + oid, oid); + } - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - if (tuples > 0) - printTableAddFooter(&cont, _("Included in publications:")); + if (tuples > 0) + printTableAddFooter(&cont, _("Included in publications:")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " \"%s\"", + PQgetvalue(result, i, 0)); - /* column list (if any) */ - if (!PQgetisnull(result, i, 2)) - appendPQExpBuffer(&buf, " (%s)", - PQgetvalue(result, i, 2)); + /* column list (if any) */ + if (!PQgetisnull(result, i, 2)) + appendPQExpBuffer(&buf, " (%s)", + PQgetvalue(result, i, 2)); - /* row filter (if any) */ - if (!PQgetisnull(result, i, 1)) - appendPQExpBuffer(&buf, " WHERE %s", - PQgetvalue(result, i, 1)); + /* row filter (if any) */ + if (!PQgetisnull(result, i, 1)) + appendPQExpBuffer(&buf, " WHERE %s", + PQgetvalue(result, i, 1)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* Print publications where the table is in the EXCEPT clause */ if (pset.sversion >= 190000) @@ -3805,7 +3804,7 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) ncols++; } appendPQExpBufferStr(&buf, "\n, r.rolreplication"); - appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); + appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_roles r\n"); @@ -3860,8 +3859,8 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) if (strcmp(PQgetvalue(res, i, (verbose ? 9 : 8)), "t") == 0) add_role_attribute(&buf, _("Replication")); - if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) - add_role_attribute(&buf, _("Bypass RLS")); + if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) + add_role_attribute(&buf, _("Bypass RLS")); conns = atoi(PQgetvalue(res, i, 6)); if (conns >= 0) @@ -5155,14 +5154,14 @@ listCollations(const char *pattern, bool verbose, bool showSystem) gettext_noop("Schema"), gettext_noop("Name")); - appendPQExpBuffer(&buf, - " CASE c.collprovider " - "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " - "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " - "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " - "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " - "END AS \"%s\",\n", - gettext_noop("Provider")); + appendPQExpBuffer(&buf, + " CASE c.collprovider " + "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " + "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " + "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " + "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " + "END AS \"%s\",\n", + gettext_noop("Provider")); appendPQExpBuffer(&buf, " c.collcollate AS \"%s\",\n" -- 2.50.1 (Apple Git-155) --aHl3HfeiUuO3zeNC-- ^ permalink raw reply [nested|flat] 59+ messages in thread
* [PATCH v6 4/4] run pgindent and pgperltidy @ 2026-06-30 18:24 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 59+ messages in thread From: Nathan Bossart @ 2026-06-30 18:24 UTC (permalink / raw) --- src/bin/pg_dump/pg_dump.c | 464 ++++++++++----------- src/bin/pg_dump/pg_dumpall.c | 30 +- src/bin/pg_upgrade/check.c | 16 +- src/bin/pg_upgrade/controldata.c | 2 +- src/bin/pg_upgrade/exec.c | 8 +- src/bin/pg_upgrade/multixact_rewrite.c | 80 ++-- src/bin/pg_upgrade/pg_upgrade.c | 34 +- src/bin/pg_upgrade/relfilenumber.c | 54 +-- src/bin/pg_upgrade/t/006_transfer_modes.pl | 33 +- src/bin/psql/command.c | 29 +- src/bin/psql/describe.c | 461 ++++++++++---------- 11 files changed, 601 insertions(+), 610 deletions(-) diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 65bd15ebfd2..5673268b467 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -1491,8 +1491,8 @@ setup_connection(Archive *AH, const char *dumpencoding, * Disable timeouts if supported. */ ExecuteSqlStatement(AH, "SET statement_timeout = 0"); - ExecuteSqlStatement(AH, "SET lock_timeout = 0"); - ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); + ExecuteSqlStatement(AH, "SET lock_timeout = 0"); + ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); if (AH->remoteVersion >= 170000) ExecuteSqlStatement(AH, "SET transaction_timeout = 0"); @@ -1505,10 +1505,10 @@ setup_connection(Archive *AH, const char *dumpencoding, /* * Adjust row-security mode, if supported. */ - if (dopt->enable_row_security) - ExecuteSqlStatement(AH, "SET row_security = on"); - else - ExecuteSqlStatement(AH, "SET row_security = off"); + if (dopt->enable_row_security) + ExecuteSqlStatement(AH, "SET row_security = on"); + else + ExecuteSqlStatement(AH, "SET row_security = off"); /* * For security reasons, we restrict the expansion of non-system views and @@ -1933,10 +1933,9 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) addObjectDependency(dobj, ext->dobj.dumpId); /* - * Mark the member object to have any non-initial ACLs - * dumped. (Any initial ACLs will be removed later, using data from - * pg_init_privs, so that we'll dump only the delta from the extension's - * initial setup.) + * Mark the member object to have any non-initial ACLs dumped. (Any + * initial ACLs will be removed later, using data from pg_init_privs, so + * that we'll dump only the delta from the extension's initial setup.) * * In binary upgrades, we still dump all components of the members * individually, since the idea is to exactly reproduce the database @@ -1953,7 +1952,7 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) if (fout->dopt->binary_upgrade) dobj->dump = ext->dobj.dump; else - dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); + dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); return true; } @@ -1987,9 +1986,9 @@ selectDumpableNamespace(NamespaceInfo *nsinfo, Archive *fout) else if (strcmp(nsinfo->dobj.name, "pg_catalog") == 0) { /* - * We dump out any ACLs defined in pg_catalog, if - * they are interesting (and not the original ACLs which were set at - * initdb time, see pg_init_privs). + * We dump out any ACLs defined in pg_catalog, if they are interesting + * (and not the original ACLs which were set at initdb time, see + * pg_init_privs). */ nsinfo->dobj.dump_contains = nsinfo->dobj.dump = DUMP_COMPONENT_ACL; } @@ -3296,7 +3295,7 @@ dumpDatabase(Archive *fout) "datcollate, datctype, datfrozenxid, " "datacl, acldefault('d', datdba) AS acldefault, " "datistemplate, datconnlimit, "); - appendPQExpBufferStr(dbQry, "datminmxid, "); + appendPQExpBufferStr(dbQry, "datminmxid, "); if (fout->remoteVersion >= 170000) appendPQExpBufferStr(dbQry, "datlocprovider, datlocale, datcollversion, "); else if (fout->remoteVersion >= 150000) @@ -3638,11 +3637,11 @@ dumpDatabase(Archive *fout) ii_oid, ii_relminmxid; - appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" - "FROM pg_catalog.pg_class\n" - "WHERE oid IN (%u, %u, %u, %u);\n", - LargeObjectRelationId, LargeObjectLOidPNIndexId, - LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); + appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" + "FROM pg_catalog.pg_class\n" + "WHERE oid IN (%u, %u, %u, %u);\n", + LargeObjectRelationId, LargeObjectLOidPNIndexId, + LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); lo_res = ExecuteSqlQuery(fout, loFrozenQry->data, PGRES_TUPLES_OK); @@ -4274,7 +4273,7 @@ getPolicies(Archive *fout, TableInfo tblinfo[], int numTables) printfPQExpBuffer(query, "SELECT pol.oid, pol.tableoid, pol.polrelid, pol.polname, pol.polcmd, "); - appendPQExpBufferStr(query, "pol.polpermissive, "); + appendPQExpBufferStr(query, "pol.polpermissive, "); appendPQExpBuffer(query, "CASE WHEN pol.polroles = '{0}' THEN NULL ELSE " " pg_catalog.array_to_string(ARRAY(SELECT pg_catalog.quote_ident(rolname) from pg_catalog.pg_roles WHERE oid = ANY(pol.polroles)), ', ') END AS polroles, " @@ -6633,9 +6632,9 @@ getAccessMethods(Archive *fout) * Select all access methods from pg_am table. */ appendPQExpBufferStr(query, "SELECT tableoid, oid, amname, "); - appendPQExpBufferStr(query, - "amtype, " - "amhandler::pg_catalog.regproc AS amhandler "); + appendPQExpBufferStr(query, + "amtype, " + "amhandler::pg_catalog.regproc AS amhandler "); appendPQExpBufferStr(query, "FROM pg_am"); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6827,35 +6826,35 @@ getAggregates(Archive *fout) * Find all interesting aggregates. See comment in getFuncs() for the * rationale behind the filtering logic. */ - agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" - : "p.proisagg"); + agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" + : "p.proisagg"); - appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " - "p.proname AS aggname, " - "p.pronamespace AS aggnamespace, " - "p.pronargs, p.proargtypes, " - "p.proowner, " - "p.proacl AS aggacl, " - "acldefault('f', p.proowner) AS acldefault " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s AND (" - "p.pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog') OR " - "p.proacl IS DISTINCT FROM pip.initprivs", - agg_check); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - " OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); - appendPQExpBufferChar(query, ')'); + appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " + "p.proname AS aggname, " + "p.pronamespace AS aggnamespace, " + "p.pronargs, p.proargtypes, " + "p.proowner, " + "p.proacl AS aggacl, " + "acldefault('f', p.proowner) AS acldefault " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s AND (" + "p.pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog') OR " + "p.proacl IS DISTINCT FROM pip.initprivs", + agg_check); + if (dopt->binary_upgrade) + appendPQExpBufferStr(query, + " OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6957,53 +6956,53 @@ getFuncs(Archive *fout) * include them, since we want to dump extension members individually in * that mode. Also, if they are used by casts or transforms then we need * to gather the information about them, though they won't be dumped if - * they are built-in. Also, include functions in - * pg_catalog if they have an ACL different from what's shown in - * pg_init_privs (so we have to join to pg_init_privs; annoying). + * they are built-in. Also, include functions in pg_catalog if they have + * an ACL different from what's shown in pg_init_privs (so we have to join + * to pg_init_privs; annoying). */ - not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" - : "NOT p.proisagg"); + not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" + : "NOT p.proisagg"); - appendPQExpBuffer(query, - "SELECT p.tableoid, p.oid, p.proname, p.prolang, " - "p.pronargs, p.proargtypes, p.prorettype, " - "p.proacl, " - "acldefault('f', p.proowner) AS acldefault, " - "p.pronamespace, " - "p.proowner " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s" - "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " - "WHERE classid = 'pg_proc'::regclass AND " - "objid = p.oid AND deptype = 'i')" - "\n AND (" - "\n pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog')" - "\n OR EXISTS (SELECT 1 FROM pg_cast" - "\n WHERE pg_cast.oid > %u " - "\n AND p.oid = pg_cast.castfunc)" - "\n OR EXISTS (SELECT 1 FROM pg_transform" - "\n WHERE pg_transform.oid > %u AND " - "\n (p.oid = pg_transform.trffromsql" - "\n OR p.oid = pg_transform.trftosql))", - not_agg_check, - g_last_builtin_oid, - g_last_builtin_oid); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); + appendPQExpBuffer(query, + "SELECT p.tableoid, p.oid, p.proname, p.prolang, " + "p.pronargs, p.proargtypes, p.prorettype, " + "p.proacl, " + "acldefault('f', p.proowner) AS acldefault, " + "p.pronamespace, " + "p.proowner " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s" + "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " + "WHERE classid = 'pg_proc'::regclass AND " + "objid = p.oid AND deptype = 'i')" + "\n AND (" + "\n pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog')" + "\n OR EXISTS (SELECT 1 FROM pg_cast" + "\n WHERE pg_cast.oid > %u " + "\n AND p.oid = pg_cast.castfunc)" + "\n OR EXISTS (SELECT 1 FROM pg_transform" + "\n WHERE pg_transform.oid > %u AND " + "\n (p.oid = pg_transform.trffromsql" + "\n OR p.oid = pg_transform.trftosql))", + not_agg_check, + g_last_builtin_oid, + g_last_builtin_oid); + if (dopt->binary_upgrade) appendPQExpBufferStr(query, - "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); - appendPQExpBufferChar(query, ')'); + "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferStr(query, + "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -7252,31 +7251,31 @@ getTables(Archive *fout, int *numTables) appendPQExpBufferStr(query, "c.relhasoids, "); - appendPQExpBufferStr(query, - "c.relispopulated, "); + appendPQExpBufferStr(query, + "c.relispopulated, "); - appendPQExpBufferStr(query, - "c.relreplident, "); + appendPQExpBufferStr(query, + "c.relreplident, "); - appendPQExpBufferStr(query, - "c.relrowsecurity, c.relforcerowsecurity, "); + appendPQExpBufferStr(query, + "c.relrowsecurity, c.relforcerowsecurity, "); - appendPQExpBufferStr(query, - "c.relminmxid, tc.relminmxid AS tminmxid, "); + appendPQExpBufferStr(query, + "c.relminmxid, tc.relminmxid AS tminmxid, "); - appendPQExpBufferStr(query, - "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); + appendPQExpBufferStr(query, + "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); - appendPQExpBufferStr(query, - "am.amname, "); + appendPQExpBufferStr(query, + "am.amname, "); - appendPQExpBufferStr(query, - "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); + appendPQExpBufferStr(query, + "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); - appendPQExpBufferStr(query, - "c.relispartition AS ispartition "); + appendPQExpBufferStr(query, + "c.relispartition AS ispartition "); /* * Left join to pg_depend to pick up dependency info linking sequences to @@ -7296,8 +7295,8 @@ getTables(Archive *fout, int *numTables) /* * Left join to pg_am to pick up the amname. */ - appendPQExpBufferStr(query, - "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); + appendPQExpBufferStr(query, + "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); /* * We purposefully ignore toast OIDs for partitioned tables; the reason is @@ -7868,8 +7867,8 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables) "t.reloptions AS indreloptions, "); - appendPQExpBufferStr(query, - "i.indisreplident, "); + appendPQExpBufferStr(query, + "i.indisreplident, "); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -9313,8 +9312,8 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables) appendPQExpBufferStr(q, "'' AS attcompression,\n"); - appendPQExpBufferStr(q, - "a.attidentity,\n"); + appendPQExpBufferStr(q, + "a.attidentity,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(q, @@ -10717,73 +10716,73 @@ getAdditionalACLs(Archive *fout) PQclear(res); /* Fetch initial-privileges data */ - printfPQExpBuffer(query, - "SELECT objoid, classoid, objsubid, privtype, initprivs " - "FROM pg_init_privs"); + printfPQExpBuffer(query, + "SELECT objoid, classoid, objsubid, privtype, initprivs " + "FROM pg_init_privs"); - res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); + res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); - ntups = PQntuples(res); - for (i = 0; i < ntups; i++) - { - Oid objoid = atooid(PQgetvalue(res, i, 0)); - Oid classoid = atooid(PQgetvalue(res, i, 1)); - int objsubid = atoi(PQgetvalue(res, i, 2)); - char privtype = *(PQgetvalue(res, i, 3)); - char *initprivs = PQgetvalue(res, i, 4); - CatalogId objId; - DumpableObject *dobj; + ntups = PQntuples(res); + for (i = 0; i < ntups; i++) + { + Oid objoid = atooid(PQgetvalue(res, i, 0)); + Oid classoid = atooid(PQgetvalue(res, i, 1)); + int objsubid = atoi(PQgetvalue(res, i, 2)); + char privtype = *(PQgetvalue(res, i, 3)); + char *initprivs = PQgetvalue(res, i, 4); + CatalogId objId; + DumpableObject *dobj; - objId.tableoid = classoid; - objId.oid = objoid; - dobj = findObjectByCatalogId(objId); - /* OK to ignore entries we haven't got a DumpableObject for */ - if (dobj) + objId.tableoid = classoid; + objId.oid = objoid; + dobj = findObjectByCatalogId(objId); + /* OK to ignore entries we haven't got a DumpableObject for */ + if (dobj) + { + /* Cope with sub-object initprivs */ + if (objsubid != 0) { - /* Cope with sub-object initprivs */ - if (objsubid != 0) - { - if (dobj->objType == DO_TABLE) - { - /* For a column initprivs, set the table's ACL flags */ - dobj->components |= DUMP_COMPONENT_ACL; - ((TableInfo *) dobj)->hascolumnACLs = true; - } - else - pg_log_warning("unsupported pg_init_privs entry: %u %u %d", - classoid, objoid, objsubid); - continue; - } - - /* - * We ignore any pg_init_privs.initprivs entry for the public - * schema, as explained in getNamespaces(). - */ - if (dobj->objType == DO_NAMESPACE && - strcmp(dobj->name, "public") == 0) - continue; - - /* Else it had better be of a type we think has ACLs */ - if (dobj->objType == DO_NAMESPACE || - dobj->objType == DO_TYPE || - dobj->objType == DO_FUNC || - dobj->objType == DO_AGG || - dobj->objType == DO_TABLE || - dobj->objType == DO_PROCLANG || - dobj->objType == DO_FDW || - dobj->objType == DO_FOREIGN_SERVER) + if (dobj->objType == DO_TABLE) { - DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; - - daobj->dacl.privtype = privtype; - daobj->dacl.initprivs = pstrdup(initprivs); + /* For a column initprivs, set the table's ACL flags */ + dobj->components |= DUMP_COMPONENT_ACL; + ((TableInfo *) dobj)->hascolumnACLs = true; } else pg_log_warning("unsupported pg_init_privs entry: %u %u %d", classoid, objoid, objsubid); + continue; + } + + /* + * We ignore any pg_init_privs.initprivs entry for the public + * schema, as explained in getNamespaces(). + */ + if (dobj->objType == DO_NAMESPACE && + strcmp(dobj->name, "public") == 0) + continue; + + /* Else it had better be of a type we think has ACLs */ + if (dobj->objType == DO_NAMESPACE || + dobj->objType == DO_TYPE || + dobj->objType == DO_FUNC || + dobj->objType == DO_AGG || + dobj->objType == DO_TABLE || + dobj->objType == DO_PROCLANG || + dobj->objType == DO_FDW || + dobj->objType == DO_FOREIGN_SERVER) + { + DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; + + daobj->dacl.privtype = privtype; + daobj->dacl.initprivs = pstrdup(initprivs); } + else + pg_log_warning("unsupported pg_init_privs entry: %u %u %d", + classoid, objoid, objsubid); } - PQclear(res); + } + PQclear(res); destroyPQExpBuffer(query); } @@ -11128,8 +11127,8 @@ dumpRelationStats_dumper(Archive *fout, const void *userArg, const TocEntry *te) * The results must be in the order of the relations supplied in the * parameters to ensure we remain in sync as we walk through the TOC. * - * For versions before 19, the redundant filter clause on s.tablename = - * ANY(...) seems sufficient to convince the planner to use + * For versions before 19, the redundant filter clause on s.tablename + * = ANY(...) seems sufficient to convince the planner to use * pg_class_relname_nsp_index, which avoids a full scan of pg_stats. * In newer versions, pg_stats returns the table OIDs, eliminating the * need for that hack. @@ -13469,11 +13468,11 @@ dumpFunc(Archive *fout, const FuncInfo *finfo) "pg_catalog.pg_get_function_result(p.oid) AS funcresult,\n" "proleakproof,\n"); - appendPQExpBufferStr(query, - "array_to_string(protrftypes, ' ') AS protrftypes,\n"); + appendPQExpBufferStr(query, + "array_to_string(protrftypes, ' ') AS protrftypes,\n"); - appendPQExpBufferStr(query, - "proparallel,\n"); + appendPQExpBufferStr(query, + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -14963,9 +14962,9 @@ dumpCollation(Archive *fout, const CollInfo *collinfo) /* Get collation-specific details */ appendPQExpBufferStr(query, "SELECT "); - appendPQExpBufferStr(query, - "collprovider, " - "collversion, "); + appendPQExpBufferStr(query, + "collprovider, " + "collversion, "); if (fout->remoteVersion >= 120000) appendPQExpBufferStr(query, @@ -15372,23 +15371,23 @@ dumpAgg(Archive *fout, const AggInfo *agginfo) "pg_catalog.pg_get_function_arguments(p.oid) AS funcargs,\n" "pg_catalog.pg_get_function_identity_arguments(p.oid) AS funciargs,\n"); - appendPQExpBufferStr(query, - "aggkind,\n" - "aggmtransfn,\n" - "aggminvtransfn,\n" - "aggmfinalfn,\n" - "aggmtranstype::pg_catalog.regtype,\n" - "aggfinalextra,\n" - "aggmfinalextra,\n" - "aggtransspace,\n" - "aggmtransspace,\n" - "aggminitval,\n"); + appendPQExpBufferStr(query, + "aggkind,\n" + "aggmtransfn,\n" + "aggminvtransfn,\n" + "aggmfinalfn,\n" + "aggmtranstype::pg_catalog.regtype,\n" + "aggfinalextra,\n" + "aggmfinalextra,\n" + "aggtransspace,\n" + "aggmtransspace,\n" + "aggminitval,\n"); - appendPQExpBufferStr(query, - "aggcombinefn,\n" - "aggserialfn,\n" - "aggdeserialfn,\n" - "proparallel,\n"); + appendPQExpBufferStr(query, + "aggcombinefn,\n" + "aggserialfn,\n" + "aggdeserialfn,\n" + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -16848,30 +16847,30 @@ dumpTable(Archive *fout, const TableInfo *tbinfo) appendPQExpBufferStr(query, "PREPARE getColumnACLs(pg_catalog.oid) AS\n"); - /* - * In principle we should call acldefault('c', relowner) to - * get the default ACL for a column. However, we don't - * currently store the numeric OID of the relowner in - * TableInfo. We could convert the owner name using regrole, - * but that creates a risk of failure due to concurrent role - * renames. Given that the default ACL for columns is empty - * and is likely to stay that way, it's not worth extra cycles - * and risk to avoid hard-wiring that knowledge here. - */ - appendPQExpBufferStr(query, - "SELECT at.attname, " - "at.attacl, " - "'{}' AS acldefault, " - "pip.privtype, pip.initprivs " - "FROM pg_catalog.pg_attribute at " - "LEFT JOIN pg_catalog.pg_init_privs pip ON " - "(at.attrelid = pip.objoid " - "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " - "AND at.attnum = pip.objsubid) " - "WHERE at.attrelid = $1 AND " - "NOT at.attisdropped " - "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " - "ORDER BY at.attnum"); + /* + * In principle we should call acldefault('c', relowner) to get + * the default ACL for a column. However, we don't currently + * store the numeric OID of the relowner in TableInfo. We could + * convert the owner name using regrole, but that creates a risk + * of failure due to concurrent role renames. Given that the + * default ACL for columns is empty and is likely to stay that + * way, it's not worth extra cycles and risk to avoid hard-wiring + * that knowledge here. + */ + appendPQExpBufferStr(query, + "SELECT at.attname, " + "at.attacl, " + "'{}' AS acldefault, " + "pip.privtype, pip.initprivs " + "FROM pg_catalog.pg_attribute at " + "LEFT JOIN pg_catalog.pg_init_privs pip ON " + "(at.attrelid = pip.objoid " + "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " + "AND at.attnum = pip.objsubid) " + "WHERE at.attrelid = $1 AND " + "NOT at.attisdropped " + "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " + "ORDER BY at.attnum"); ExecuteSqlStatement(fout, query->data); @@ -19165,7 +19164,7 @@ collectSequences(Archive *fout) * pg_get_sequence_data(), but we only do so for non-schema-only dumps. */ if (fout->remoteVersion < 180000 || - (!fout->dopt->dumpData && !fout->dopt->sequence_data)) + (!fout->dopt->dumpData && !fout->dopt->sequence_data)) query = "SELECT seqrelid, format_type(seqtypid, NULL), " "seqstart, seqincrement, " "seqmax, seqmin, " @@ -19227,15 +19226,14 @@ dumpSequence(Archive *fout, const TableInfo *tbinfo) qseqname = pg_strdup(fmtId(tbinfo->dobj.name)); /* - * The sequence information is gathered in a sorted - * table before any calls to dumpSequence(). See collectSequences() for - * more information. + * The sequence information is gathered in a sorted table before any calls + * to dumpSequence(). See collectSequences() for more information. */ - Assert(sequences); + Assert(sequences); - key.oid = tbinfo->dobj.catId.oid; - seq = bsearch(&key, sequences, nsequences, - sizeof(SequenceItem), SequenceItemCmp); + key.oid = tbinfo->dobj.catId.oid; + seq = bsearch(&key, sequences, nsequences, + sizeof(SequenceItem), SequenceItemCmp); /* Calculate default limits for a sequence of this type */ is_ascending = (seq->incby >= 0); diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c index e68937c9934..afcd9a218d8 100644 --- a/src/bin/pg_dump/pg_dumpall.c +++ b/src/bin/pg_dump/pg_dumpall.c @@ -785,11 +785,11 @@ dropRoles(PGconn *conn) int i_rolname; int i; - printfPQExpBuffer(buf, - "SELECT rolname " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 1", role_catalog); + printfPQExpBuffer(buf, + "SELECT rolname " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 1", role_catalog); res = executeQuery(conn, buf->data); @@ -843,16 +843,16 @@ dumpRoles(PGconn *conn) * Notes: rolconfig is dumped later, and pg_authid must be used for * extracting rolcomment regardless of role_catalog. */ - printfPQExpBuffer(buf, - "SELECT oid, rolname, rolsuper, rolinherit, " - "rolcreaterole, rolcreatedb, " - "rolcanlogin, rolconnlimit, rolpassword, " - "rolvaliduntil, rolreplication, rolbypassrls, " - "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " - "rolname = current_user AS is_current_user " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 2", role_catalog); + printfPQExpBuffer(buf, + "SELECT oid, rolname, rolsuper, rolinherit, " + "rolcreaterole, rolcreatedb, " + "rolcanlogin, rolconnlimit, rolpassword, " + "rolvaliduntil, rolreplication, rolbypassrls, " + "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " + "rolname = current_user AS is_current_user " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 2", role_catalog); res = executeQuery(conn, buf->data); diff --git a/src/bin/pg_upgrade/check.c b/src/bin/pg_upgrade/check.c index 786c1474829..f725f5ee3e2 100644 --- a/src/bin/pg_upgrade/check.c +++ b/src/bin/pg_upgrade/check.c @@ -1475,15 +1475,15 @@ check_for_incompatible_polymorphics(ClusterInfo *cluster) ", 'array_cat(anyarray,anyarray)'" ", 'array_prepend(anyelement,anyarray)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_remove(anyarray,anyelement)'" - ", 'array_replace(anyarray,anyelement,anyelement)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_remove(anyarray,anyelement)'" + ", 'array_replace(anyarray,anyelement,anyelement)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_position(anyarray,anyelement)'" - ", 'array_position(anyarray,anyelement,integer)'" - ", 'array_positions(anyarray,anyelement)'" - ", 'width_bucket(anyelement,anyarray)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_position(anyarray,anyelement)'" + ", 'array_position(anyarray,anyelement,integer)'" + ", 'array_positions(anyarray,anyelement)'" + ", 'width_bucket(anyelement,anyarray)'"); /* * The query below hardcodes FirstNormalObjectId as 16384 rather than diff --git a/src/bin/pg_upgrade/controldata.c b/src/bin/pg_upgrade/controldata.c index 8f81c9e9582..02ea02df60f 100644 --- a/src/bin/pg_upgrade/controldata.c +++ b/src/bin/pg_upgrade/controldata.c @@ -228,7 +228,7 @@ get_control_data(ClusterInfo *cluster) p++; /* remove ':' char */ cluster->controldata.chkpnt_nxtepoch = str2uint(p); - p = strchr(p, ':'); + p = strchr(p, ':'); if (p == NULL || strlen(p) <= 1) pg_fatal("%d: controldata retrieval problem", __LINE__); diff --git a/src/bin/pg_upgrade/exec.c b/src/bin/pg_upgrade/exec.c index 44355feea30..a1bdbf373e3 100644 --- a/src/bin/pg_upgrade/exec.c +++ b/src/bin/pg_upgrade/exec.c @@ -55,7 +55,7 @@ get_bin_version(ClusterInfo *cluster) if (sscanf(cmd_output, "%*s %*s %d.%d", &v1, &v2) < 1) pg_fatal("could not get pg_ctl version output from %s", cmd); - cluster->bin_version = v1 * 10000; + cluster->bin_version = v1 * 10000; } @@ -344,8 +344,8 @@ check_data_dir(ClusterInfo *cluster) check_single_dir(pg_data, "pg_subtrans"); check_single_dir(pg_data, PG_TBLSPC_DIR); check_single_dir(pg_data, "pg_twophase"); - check_single_dir(pg_data, "pg_wal"); - check_single_dir(pg_data, "pg_xact"); + check_single_dir(pg_data, "pg_wal"); + check_single_dir(pg_data, "pg_xact"); } @@ -385,7 +385,7 @@ check_bin_dir(ClusterInfo *cluster, bool check_versions) */ get_bin_version(cluster); - check_exec(cluster->bindir, "pg_resetwal", check_versions); + check_exec(cluster->bindir, "pg_resetwal", check_versions); if (cluster == &new_cluster) { diff --git a/src/bin/pg_upgrade/multixact_rewrite.c b/src/bin/pg_upgrade/multixact_rewrite.c index c45b3183684..c7a1416494d 100644 --- a/src/bin/pg_upgrade/multixact_rewrite.c +++ b/src/bin/pg_upgrade/multixact_rewrite.c @@ -61,52 +61,52 @@ rewrite_multixacts(MultiXactId from_multi, MultiXactId to_multi) * Convert old multixids, if needed, by reading them one-by-one from the * old cluster. */ - old_reader = AllocOldMultiXactRead(old_cluster.pgdata, - old_cluster.controldata.chkpnt_nxtmulti, - old_cluster.controldata.chkpnt_nxtmxoff); + old_reader = AllocOldMultiXactRead(old_cluster.pgdata, + old_cluster.controldata.chkpnt_nxtmulti, + old_cluster.controldata.chkpnt_nxtmxoff); - for (MultiXactId multi = from_multi; multi != to_multi;) - { - MultiXactMember member; - bool multixid_valid; - - /* - * Read this multixid's members. - * - * Locking-only XIDs that may be part of multi-xids don't matter - * after upgrade, as there can be no transactions running across - * upgrade. So as a small optimization, we only read one member - * from each multixid: the one updating one, or if there was no - * update, arbitrarily the first locking xid. - */ - multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); + for (MultiXactId multi = from_multi; multi != to_multi;) + { + MultiXactMember member; + bool multixid_valid; - /* - * Write the new offset to pg_multixact/offsets. - * - * Even if this multixid is invalid, we still need to write its - * offset if the *previous* multixid was valid. That's because - * when reading a multixid, the number of members is calculated - * from the difference between the two offsets. - */ - RecordMultiXactOffset(offsets_writer, multi, - (multixid_valid || prev_multixid_valid) ? next_offset : 0); + /* + * Read this multixid's members. + * + * Locking-only XIDs that may be part of multi-xids don't matter after + * upgrade, as there can be no transactions running across upgrade. So + * as a small optimization, we only read one member from each + * multixid: the one updating one, or if there was no update, + * arbitrarily the first locking xid. + */ + multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); - /* Write the members */ - if (multixid_valid) - { - RecordMultiXactMembers(members_writer, next_offset, 1, &member); - next_offset += 1; - } + /* + * Write the new offset to pg_multixact/offsets. + * + * Even if this multixid is invalid, we still need to write its offset + * if the *previous* multixid was valid. That's because when reading + * a multixid, the number of members is calculated from the difference + * between the two offsets. + */ + RecordMultiXactOffset(offsets_writer, multi, + (multixid_valid || prev_multixid_valid) ? next_offset : 0); - /* Advance to next multixid, handling wraparound */ - multi++; - if (multi < FirstMultiXactId) - multi = FirstMultiXactId; - prev_multixid_valid = multixid_valid; + /* Write the members */ + if (multixid_valid) + { + RecordMultiXactMembers(members_writer, next_offset, 1, &member); + next_offset += 1; } - FreeOldMultiXactReader(old_reader); + /* Advance to next multixid, handling wraparound */ + multi++; + if (multi < FirstMultiXactId) + multi = FirstMultiXactId; + prev_multixid_valid = multixid_valid; + } + + FreeOldMultiXactReader(old_reader); /* Write the final 'next' offset to the last SLRU page */ RecordMultiXactOffset(offsets_writer, to_multi, diff --git a/src/bin/pg_upgrade/pg_upgrade.c b/src/bin/pg_upgrade/pg_upgrade.c index c6af9035665..7366fd4627c 100644 --- a/src/bin/pg_upgrade/pg_upgrade.c +++ b/src/bin/pg_upgrade/pg_upgrade.c @@ -833,7 +833,7 @@ copy_xact_xlog_xid(void) * Determine the range of multixacts to convert. */ nxtmulti = old_cluster.controldata.chkpnt_nxtmulti; - oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; + oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; /* handle wraparound */ if (nxtmulti < FirstMultiXactId) nxtmulti = FirstMultiXactId; @@ -898,15 +898,15 @@ set_frozenxids(void) int i_datname; int i_datallowconn; - prep_status("Setting frozenxid and minmxid counters in new cluster"); + prep_status("Setting frozenxid and minmxid counters in new cluster"); conn_template1 = connectToServer(&new_cluster, "template1"); - /* set pg_database.datfrozenxid */ - PQclear(executeQueryOrDie(conn_template1, - "UPDATE pg_catalog.pg_database " - "SET datfrozenxid = '%u'", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_database.datfrozenxid */ + PQclear(executeQueryOrDie(conn_template1, + "UPDATE pg_catalog.pg_database " + "SET datfrozenxid = '%u'", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_database.datminmxid */ PQclear(executeQueryOrDie(conn_template1, @@ -942,16 +942,16 @@ set_frozenxids(void) conn = connectToServer(&new_cluster, datname); - /* set pg_class.relfrozenxid */ - PQclear(executeQueryOrDie(conn, - "UPDATE pg_catalog.pg_class " - "SET relfrozenxid = '%u' " - /* only heap, materialized view, and TOAST are vacuumed */ - "WHERE relkind IN (" - CppAsString2(RELKIND_RELATION) ", " - CppAsString2(RELKIND_MATVIEW) ", " - CppAsString2(RELKIND_TOASTVALUE) ")", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_class.relfrozenxid */ + PQclear(executeQueryOrDie(conn, + "UPDATE pg_catalog.pg_class " + "SET relfrozenxid = '%u' " + /* only heap, materialized view, and TOAST are vacuumed */ + "WHERE relkind IN (" + CppAsString2(RELKIND_RELATION) ", " + CppAsString2(RELKIND_MATVIEW) ", " + CppAsString2(RELKIND_TOASTVALUE) ")", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_class.relminmxid */ PQclear(executeQueryOrDie(conn, diff --git a/src/bin/pg_upgrade/relfilenumber.c b/src/bin/pg_upgrade/relfilenumber.c index ec2ff7acb21..6c467bdc8a5 100644 --- a/src/bin/pg_upgrade/relfilenumber.c +++ b/src/bin/pg_upgrade/relfilenumber.c @@ -587,32 +587,32 @@ transfer_relfile(FileNameMap *map, const char *type_suffix) /* Copying files might take some time, so give feedback. */ pg_log(PG_STATUS, "%s", old_file); - switch (user_opts.transfer_mode) - { - case TRANSFER_MODE_CLONE: - pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", - old_file, new_file); - cloneFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", - old_file, new_file); - copyFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY_FILE_RANGE: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", - old_file, new_file); - copyFileByRange(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_LINK: - pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", - old_file, new_file); - linkFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_SWAP: - /* swap mode is handled in its own code path */ - pg_fatal("should never happen"); - break; - } + switch (user_opts.transfer_mode) + { + case TRANSFER_MODE_CLONE: + pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", + old_file, new_file); + cloneFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", + old_file, new_file); + copyFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY_FILE_RANGE: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", + old_file, new_file); + copyFileByRange(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_LINK: + pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", + old_file, new_file); + linkFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_SWAP: + /* swap mode is handled in its own code path */ + pg_fatal("should never happen"); + break; + } } } diff --git a/src/bin/pg_upgrade/t/006_transfer_modes.pl b/src/bin/pg_upgrade/t/006_transfer_modes.pl index 9efa5dc863c..360d05c4b68 100644 --- a/src/bin/pg_upgrade/t/006_transfer_modes.pl +++ b/src/bin/pg_upgrade/t/006_transfer_modes.pl @@ -29,10 +29,8 @@ sub test_mode } $new->init(); - $new->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); - $old->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); + $new->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); + $old->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); # We can only test security labels if both the old and new installations # have dummy_seclabel. @@ -76,15 +74,14 @@ sub test_mode "CREATE TABLE test4 AS SELECT generate_series(400, 502)"); } - $old->safe_psql('postgres', - "CREATE TABLESPACE inplc_tblspc LOCATION ''"); - $old->safe_psql('postgres', - "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); - $old->safe_psql('postgres', - "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" - ); - $old->safe_psql('testdb3', - "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); + $old->safe_psql('postgres', "CREATE TABLESPACE inplc_tblspc LOCATION ''"); + $old->safe_psql('postgres', + "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); + $old->safe_psql('postgres', + "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" + ); + $old->safe_psql('testdb3', + "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); # While we are here, test handling of large objects. $old->safe_psql( @@ -152,12 +149,10 @@ sub test_mode } # Tests for in-place tablespaces. - $result = - $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); - is($result, '104', "test5 data after pg_upgrade $mode"); - $result = - $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); - is($result, '105', "test6 data after pg_upgrade $mode"); + $result = $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); + is($result, '104', "test5 data after pg_upgrade $mode"); + $result = $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); + is($result, '105', "test6 data after pg_upgrade $mode"); # Tests for large objects $result = $new->safe_psql('postgres', "SELECT lo_get(4532)"); diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index 44ef11d980e..c90bf8bbde2 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -6278,23 +6278,22 @@ get_create_object_cmd(EditableObjectType obj_type, Oid oid, * ensure the right view gets replaced. Also, check relation kind * to be sure it's a view. * - * Views may have WITH [LOCAL|CASCADED] - * CHECK OPTION. These are not part of the view definition - * returned by pg_get_viewdef() and so need to be retrieved - * separately. Materialized views may have - * arbitrary storage parameter reloptions. + * Views may have WITH [LOCAL|CASCADED] CHECK OPTION. These are + * not part of the view definition returned by pg_get_viewdef() + * and so need to be retrieved separately. Materialized views may + * have arbitrary storage parameter reloptions. */ printfPQExpBuffer(query, "/* %s */\n", _("Get view's definition and details")); - appendPQExpBuffer(query, - "SELECT nspname, relname, relkind, " - "pg_catalog.pg_get_viewdef(c.oid, true), " - "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " - "FROM pg_catalog.pg_class c " - "LEFT JOIN pg_catalog.pg_namespace n " - "ON c.relnamespace = n.oid WHERE c.oid = %u", - oid); + appendPQExpBuffer(query, + "SELECT nspname, relname, relkind, " + "pg_catalog.pg_get_viewdef(c.oid, true), " + "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " + "FROM pg_catalog.pg_class c " + "LEFT JOIN pg_catalog.pg_namespace n " + "ON c.relnamespace = n.oid WHERE c.oid = %u", + oid); break; } diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index ce99137c613..ac0c55e7aa5 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -387,19 +387,19 @@ describeFunctions(const char *functypes, const char *func_pattern, gettext_noop("stable"), gettext_noop("volatile"), gettext_noop("Volatility")); - appendPQExpBuffer(&buf, - ",\n CASE\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" - " END as \"%s\"", - gettext_noop("restricted"), - gettext_noop("safe"), - gettext_noop("unsafe"), - gettext_noop("Parallel")); + appendPQExpBuffer(&buf, + ",\n CASE\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" + " END as \"%s\"", + gettext_noop("restricted"), + gettext_noop("safe"), + gettext_noop("unsafe"), + gettext_noop("Parallel")); appendPQExpBuffer(&buf, ",\n pg_catalog.pg_get_userbyid(p.proowner) as \"%s\"" ",\n CASE WHEN prosecdef THEN '%s' ELSE '%s' END AS \"%s\"" @@ -599,8 +599,8 @@ describeFunctions(const char *functypes, const char *func_pattern, myopt.title = _("List of functions"); myopt.translate_header = true; - myopt.translate_columns = translate_columns; - myopt.n_translate_columns = lengthof(translate_columns); + myopt.translate_columns = translate_columns; + myopt.n_translate_columns = lengthof(translate_columns); printQuery(res, &myopt, pset.queryFout, false, pset.logfile); @@ -1086,38 +1086,38 @@ permissionsList(const char *pattern, bool showSystem) " ), E'\\n') AS \"%s\"", gettext_noop("Column privileges")); - appendPQExpBuffer(&buf, - ",\n pg_catalog.array_to_string(ARRAY(\n" - " SELECT polname\n" - " || CASE WHEN NOT polpermissive THEN\n" - " E' (RESTRICTIVE)'\n" - " ELSE '' END\n" - " || CASE WHEN polcmd != '*' THEN\n" - " E' (' || polcmd::pg_catalog.text || E'):'\n" - " ELSE E':'\n" - " END\n" - " || CASE WHEN polqual IS NOT NULL THEN\n" - " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" - " ELSE E''\n" - " END\n" - " || CASE WHEN polwithcheck IS NOT NULL THEN\n" - " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" - " ELSE E''\n" - " END" - " || CASE WHEN polroles <> '{0}' THEN\n" - " E'\\n to: ' || pg_catalog.array_to_string(\n" - " ARRAY(\n" - " SELECT rolname\n" - " FROM pg_catalog.pg_roles\n" - " WHERE oid = ANY (polroles)\n" - " ORDER BY 1\n" - " ), E', ')\n" - " ELSE E''\n" - " END\n" - " FROM pg_catalog.pg_policy pol\n" - " WHERE polrelid = c.oid), E'\\n')\n" - " AS \"%s\"", - gettext_noop("Policies")); + appendPQExpBuffer(&buf, + ",\n pg_catalog.array_to_string(ARRAY(\n" + " SELECT polname\n" + " || CASE WHEN NOT polpermissive THEN\n" + " E' (RESTRICTIVE)'\n" + " ELSE '' END\n" + " || CASE WHEN polcmd != '*' THEN\n" + " E' (' || polcmd::pg_catalog.text || E'):'\n" + " ELSE E':'\n" + " END\n" + " || CASE WHEN polqual IS NOT NULL THEN\n" + " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" + " ELSE E''\n" + " END\n" + " || CASE WHEN polwithcheck IS NOT NULL THEN\n" + " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" + " ELSE E''\n" + " END" + " || CASE WHEN polroles <> '{0}' THEN\n" + " E'\\n to: ' || pg_catalog.array_to_string(\n" + " ARRAY(\n" + " SELECT rolname\n" + " FROM pg_catalog.pg_roles\n" + " WHERE oid = ANY (polroles)\n" + " ORDER BY 1\n" + " ), E', ')\n" + " ELSE E''\n" + " END\n" + " FROM pg_catalog.pg_policy pol\n" + " WHERE polrelid = c.oid), E'\\n')\n" + " AS \"%s\"", + gettext_noop("Policies")); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_class c\n" " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n" @@ -1675,27 +1675,27 @@ describeOneTableDetails(const char *schemaname, char *footers[3] = {NULL, NULL, NULL}; printfPQExpBuffer(&buf, "/* %s */\n", _("Get sequence information")); - appendPQExpBuffer(&buf, - "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" - " seqstart AS \"%s\",\n" - " seqmin AS \"%s\",\n" - " seqmax AS \"%s\",\n" - " seqincrement AS \"%s\",\n" - " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" - " seqcache AS \"%s\"\n", - gettext_noop("Type"), - gettext_noop("Start"), - gettext_noop("Minimum"), - gettext_noop("Maximum"), - gettext_noop("Increment"), - gettext_noop("yes"), - gettext_noop("no"), - gettext_noop("Cycles?"), - gettext_noop("Cache")); - appendPQExpBuffer(&buf, - "FROM pg_catalog.pg_sequence\n" - "WHERE seqrelid = '%s';", - oid); + appendPQExpBuffer(&buf, + "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" + " seqstart AS \"%s\",\n" + " seqmin AS \"%s\",\n" + " seqmax AS \"%s\",\n" + " seqincrement AS \"%s\",\n" + " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" + " seqcache AS \"%s\"\n", + gettext_noop("Type"), + gettext_noop("Start"), + gettext_noop("Minimum"), + gettext_noop("Maximum"), + gettext_noop("Increment"), + gettext_noop("yes"), + gettext_noop("no"), + gettext_noop("Cycles?"), + gettext_noop("Cache")); + appendPQExpBuffer(&buf, + "FROM pg_catalog.pg_sequence\n" + "WHERE seqrelid = '%s';", + oid); res = PSQLexec(buf.data); if (!res) @@ -1913,7 +1913,7 @@ describeOneTableDetails(const char *schemaname, appendPQExpBufferStr(&buf, ",\n (SELECT c.collname FROM pg_catalog.pg_collation c, pg_catalog.pg_type t\n" " WHERE c.oid = a.attcollation AND t.oid = a.atttypid AND a.attcollation <> t.typcollation) AS attcollation"); attcoll_col = cols++; - appendPQExpBufferStr(&buf, ",\n a.attidentity"); + appendPQExpBufferStr(&buf, ",\n a.attidentity"); attidentity_col = cols++; if (pset.sversion >= 120000) appendPQExpBufferStr(&buf, ",\n a.attgenerated"); @@ -2326,7 +2326,7 @@ describeOneTableDetails(const char *schemaname, CppAsString2(CONSTRAINT_EXCLUSION) ") AND " "condeferred) AS condeferred,\n"); - appendPQExpBufferStr(&buf, "i.indisreplident,\n"); + appendPQExpBufferStr(&buf, "i.indisreplident,\n"); if (pset.sversion >= 150000) appendPQExpBufferStr(&buf, "i.indnullsnotdistinct,\n"); @@ -2431,7 +2431,7 @@ describeOneTableDetails(const char *schemaname, "pg_catalog.pg_get_indexdef(i.indexrelid, 0, true),\n " "pg_catalog.pg_get_constraintdef(con.oid, true), " "contype, condeferrable, condeferred"); - appendPQExpBufferStr(&buf, ", i.indisreplident"); + appendPQExpBufferStr(&buf, ", i.indisreplident"); appendPQExpBufferStr(&buf, ", c2.reltablespace"); if (pset.sversion >= 180000) appendPQExpBufferStr(&buf, ", con.conperiod"); @@ -2682,81 +2682,80 @@ describeOneTableDetails(const char *schemaname, PQclear(result); /* print any row-level policies */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get row-level policies for this table")); - appendPQExpBufferStr(&buf, "SELECT pol.polname,"); - appendPQExpBufferStr(&buf, - " pol.polpermissive,\n"); - appendPQExpBuffer(&buf, - " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" - " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" - " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" - " CASE pol.polcmd\n" - " WHEN 'r' THEN 'SELECT'\n" - " WHEN 'a' THEN 'INSERT'\n" - " WHEN 'w' THEN 'UPDATE'\n" - " WHEN 'd' THEN 'DELETE'\n" - " END AS cmd\n" - "FROM pg_catalog.pg_policy pol\n" - "WHERE pol.polrelid = '%s' ORDER BY 1;", - oid); + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get row-level policies for this table")); + appendPQExpBufferStr(&buf, "SELECT pol.polname,"); + appendPQExpBufferStr(&buf, + " pol.polpermissive,\n"); + appendPQExpBuffer(&buf, + " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" + " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" + " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" + " CASE pol.polcmd\n" + " WHEN 'r' THEN 'SELECT'\n" + " WHEN 'a' THEN 'INSERT'\n" + " WHEN 'w' THEN 'UPDATE'\n" + " WHEN 'd' THEN 'DELETE'\n" + " END AS cmd\n" + "FROM pg_catalog.pg_policy pol\n" + "WHERE pol.polrelid = '%s' ORDER BY 1;", + oid); - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - /* - * Handle cases where RLS is enabled and there are policies, or - * there aren't policies, or RLS isn't enabled but there are - * policies - */ - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies:")); + /* + * Handle cases where RLS is enabled and there are policies, or there + * aren't policies, or RLS isn't enabled but there are policies + */ + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies:")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled):")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled):")); - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); - if (!tableinfo.rowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (row security disabled):")); + if (!tableinfo.rowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (row security disabled):")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " POLICY \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " POLICY \"%s\"", + PQgetvalue(result, i, 0)); - if (*(PQgetvalue(result, i, 1)) == 'f') - appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); + if (*(PQgetvalue(result, i, 1)) == 'f') + appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); - if (!PQgetisnull(result, i, 5)) - appendPQExpBuffer(&buf, " FOR %s", - PQgetvalue(result, i, 5)); + if (!PQgetisnull(result, i, 5)) + appendPQExpBuffer(&buf, " FOR %s", + PQgetvalue(result, i, 5)); - if (!PQgetisnull(result, i, 2)) - { - appendPQExpBuffer(&buf, "\n TO %s", - PQgetvalue(result, i, 2)); - } + if (!PQgetisnull(result, i, 2)) + { + appendPQExpBuffer(&buf, "\n TO %s", + PQgetvalue(result, i, 2)); + } - if (!PQgetisnull(result, i, 3)) - appendPQExpBuffer(&buf, "\n USING (%s)", - PQgetvalue(result, i, 3)); + if (!PQgetisnull(result, i, 3)) + appendPQExpBuffer(&buf, "\n USING (%s)", + PQgetvalue(result, i, 3)); - if (!PQgetisnull(result, i, 4)) - appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", - PQgetvalue(result, i, 4)); + if (!PQgetisnull(result, i, 4)) + appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", + PQgetvalue(result, i, 4)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* print any extended statistics */ if (pset.sversion >= 140000) @@ -3025,115 +3024,115 @@ describeOneTableDetails(const char *schemaname, } /* print any publications */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get publications that publish this table")); - if (pset.sversion >= 150000) + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get publications that publish this table")); + if (pset.sversion >= 150000) + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" + " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" + "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" + "UNION\n" + "SELECT pubname\n" + " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" + " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" + " (SELECT pg_catalog.string_agg(attname, ', ')\n" + " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" + " pg_catalog.pg_attribute\n" + " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" + " ELSE NULL END) " + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" + "WHERE pr.prrelid = '%s'\n", + oid, oid, oid); + + if (pset.sversion >= 190000) { + /* + * Skip entries where this relation appears in the + * publication's EXCEPT list. + */ appendPQExpBuffer(&buf, + " AND NOT pr.prexcept\n" + "UNION\n" "SELECT pubname\n" " , NULL\n" " , NULL\n" "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" - " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" - "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" - "UNION\n" - "SELECT pubname\n" - " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" - " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" - " (SELECT pg_catalog.string_agg(attname, ', ')\n" - " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" - " pg_catalog.pg_attribute\n" - " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" - " ELSE NULL END) " - "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" - "WHERE pr.prrelid = '%s'\n", + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + " AND NOT EXISTS (\n" + " SELECT 1\n" + " FROM pg_catalog.pg_publication_rel pr\n" + " WHERE pr.prpubid = p.oid AND\n" + " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" + "ORDER BY 1;", oid, oid, oid); - - if (pset.sversion >= 190000) - { - /* - * Skip entries where this relation appears in the - * publication's EXCEPT list. - */ - appendPQExpBuffer(&buf, - " AND NOT pr.prexcept\n" - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - " AND NOT EXISTS (\n" - " SELECT 1\n" - " FROM pg_catalog.pg_publication_rel pr\n" - " WHERE pr.prpubid = p.oid AND\n" - " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" - "ORDER BY 1;", - oid, oid, oid); - } - else - { - appendPQExpBuffer(&buf, - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - "ORDER BY 1;", - oid); - } } else { appendPQExpBuffer(&buf, + "UNION\n" "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - "WHERE pr.prrelid = '%s'\n" - "UNION ALL\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" + " , NULL\n" + " , NULL\n" "FROM pg_catalog.pg_publication p\n" "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" "ORDER BY 1;", - oid, oid); + oid); } + } + else + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + "WHERE pr.prrelid = '%s'\n" + "UNION ALL\n" + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + "ORDER BY 1;", + oid, oid); + } - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - if (tuples > 0) - printTableAddFooter(&cont, _("Included in publications:")); + if (tuples > 0) + printTableAddFooter(&cont, _("Included in publications:")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " \"%s\"", + PQgetvalue(result, i, 0)); - /* column list (if any) */ - if (!PQgetisnull(result, i, 2)) - appendPQExpBuffer(&buf, " (%s)", - PQgetvalue(result, i, 2)); + /* column list (if any) */ + if (!PQgetisnull(result, i, 2)) + appendPQExpBuffer(&buf, " (%s)", + PQgetvalue(result, i, 2)); - /* row filter (if any) */ - if (!PQgetisnull(result, i, 1)) - appendPQExpBuffer(&buf, " WHERE %s", - PQgetvalue(result, i, 1)); + /* row filter (if any) */ + if (!PQgetisnull(result, i, 1)) + appendPQExpBuffer(&buf, " WHERE %s", + PQgetvalue(result, i, 1)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* Print publications where the table is in the EXCEPT clause */ if (pset.sversion >= 190000) @@ -3805,7 +3804,7 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) ncols++; } appendPQExpBufferStr(&buf, "\n, r.rolreplication"); - appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); + appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_roles r\n"); @@ -3860,8 +3859,8 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) if (strcmp(PQgetvalue(res, i, (verbose ? 9 : 8)), "t") == 0) add_role_attribute(&buf, _("Replication")); - if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) - add_role_attribute(&buf, _("Bypass RLS")); + if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) + add_role_attribute(&buf, _("Bypass RLS")); conns = atoi(PQgetvalue(res, i, 6)); if (conns >= 0) @@ -5155,14 +5154,14 @@ listCollations(const char *pattern, bool verbose, bool showSystem) gettext_noop("Schema"), gettext_noop("Name")); - appendPQExpBuffer(&buf, - " CASE c.collprovider " - "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " - "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " - "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " - "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " - "END AS \"%s\",\n", - gettext_noop("Provider")); + appendPQExpBuffer(&buf, + " CASE c.collprovider " + "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " + "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " + "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " + "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " + "END AS \"%s\",\n", + gettext_noop("Provider")); appendPQExpBuffer(&buf, " c.collcollate AS \"%s\",\n" -- 2.50.1 (Apple Git-155) --aHl3HfeiUuO3zeNC-- ^ permalink raw reply [nested|flat] 59+ messages in thread
* [PATCH v6 4/4] run pgindent and pgperltidy @ 2026-06-30 18:24 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 59+ messages in thread From: Nathan Bossart @ 2026-06-30 18:24 UTC (permalink / raw) --- src/bin/pg_dump/pg_dump.c | 464 ++++++++++----------- src/bin/pg_dump/pg_dumpall.c | 30 +- src/bin/pg_upgrade/check.c | 16 +- src/bin/pg_upgrade/controldata.c | 2 +- src/bin/pg_upgrade/exec.c | 8 +- src/bin/pg_upgrade/multixact_rewrite.c | 80 ++-- src/bin/pg_upgrade/pg_upgrade.c | 34 +- src/bin/pg_upgrade/relfilenumber.c | 54 +-- src/bin/pg_upgrade/t/006_transfer_modes.pl | 33 +- src/bin/psql/command.c | 29 +- src/bin/psql/describe.c | 461 ++++++++++---------- 11 files changed, 601 insertions(+), 610 deletions(-) diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 65bd15ebfd2..5673268b467 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -1491,8 +1491,8 @@ setup_connection(Archive *AH, const char *dumpencoding, * Disable timeouts if supported. */ ExecuteSqlStatement(AH, "SET statement_timeout = 0"); - ExecuteSqlStatement(AH, "SET lock_timeout = 0"); - ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); + ExecuteSqlStatement(AH, "SET lock_timeout = 0"); + ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); if (AH->remoteVersion >= 170000) ExecuteSqlStatement(AH, "SET transaction_timeout = 0"); @@ -1505,10 +1505,10 @@ setup_connection(Archive *AH, const char *dumpencoding, /* * Adjust row-security mode, if supported. */ - if (dopt->enable_row_security) - ExecuteSqlStatement(AH, "SET row_security = on"); - else - ExecuteSqlStatement(AH, "SET row_security = off"); + if (dopt->enable_row_security) + ExecuteSqlStatement(AH, "SET row_security = on"); + else + ExecuteSqlStatement(AH, "SET row_security = off"); /* * For security reasons, we restrict the expansion of non-system views and @@ -1933,10 +1933,9 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) addObjectDependency(dobj, ext->dobj.dumpId); /* - * Mark the member object to have any non-initial ACLs - * dumped. (Any initial ACLs will be removed later, using data from - * pg_init_privs, so that we'll dump only the delta from the extension's - * initial setup.) + * Mark the member object to have any non-initial ACLs dumped. (Any + * initial ACLs will be removed later, using data from pg_init_privs, so + * that we'll dump only the delta from the extension's initial setup.) * * In binary upgrades, we still dump all components of the members * individually, since the idea is to exactly reproduce the database @@ -1953,7 +1952,7 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) if (fout->dopt->binary_upgrade) dobj->dump = ext->dobj.dump; else - dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); + dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); return true; } @@ -1987,9 +1986,9 @@ selectDumpableNamespace(NamespaceInfo *nsinfo, Archive *fout) else if (strcmp(nsinfo->dobj.name, "pg_catalog") == 0) { /* - * We dump out any ACLs defined in pg_catalog, if - * they are interesting (and not the original ACLs which were set at - * initdb time, see pg_init_privs). + * We dump out any ACLs defined in pg_catalog, if they are interesting + * (and not the original ACLs which were set at initdb time, see + * pg_init_privs). */ nsinfo->dobj.dump_contains = nsinfo->dobj.dump = DUMP_COMPONENT_ACL; } @@ -3296,7 +3295,7 @@ dumpDatabase(Archive *fout) "datcollate, datctype, datfrozenxid, " "datacl, acldefault('d', datdba) AS acldefault, " "datistemplate, datconnlimit, "); - appendPQExpBufferStr(dbQry, "datminmxid, "); + appendPQExpBufferStr(dbQry, "datminmxid, "); if (fout->remoteVersion >= 170000) appendPQExpBufferStr(dbQry, "datlocprovider, datlocale, datcollversion, "); else if (fout->remoteVersion >= 150000) @@ -3638,11 +3637,11 @@ dumpDatabase(Archive *fout) ii_oid, ii_relminmxid; - appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" - "FROM pg_catalog.pg_class\n" - "WHERE oid IN (%u, %u, %u, %u);\n", - LargeObjectRelationId, LargeObjectLOidPNIndexId, - LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); + appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" + "FROM pg_catalog.pg_class\n" + "WHERE oid IN (%u, %u, %u, %u);\n", + LargeObjectRelationId, LargeObjectLOidPNIndexId, + LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); lo_res = ExecuteSqlQuery(fout, loFrozenQry->data, PGRES_TUPLES_OK); @@ -4274,7 +4273,7 @@ getPolicies(Archive *fout, TableInfo tblinfo[], int numTables) printfPQExpBuffer(query, "SELECT pol.oid, pol.tableoid, pol.polrelid, pol.polname, pol.polcmd, "); - appendPQExpBufferStr(query, "pol.polpermissive, "); + appendPQExpBufferStr(query, "pol.polpermissive, "); appendPQExpBuffer(query, "CASE WHEN pol.polroles = '{0}' THEN NULL ELSE " " pg_catalog.array_to_string(ARRAY(SELECT pg_catalog.quote_ident(rolname) from pg_catalog.pg_roles WHERE oid = ANY(pol.polroles)), ', ') END AS polroles, " @@ -6633,9 +6632,9 @@ getAccessMethods(Archive *fout) * Select all access methods from pg_am table. */ appendPQExpBufferStr(query, "SELECT tableoid, oid, amname, "); - appendPQExpBufferStr(query, - "amtype, " - "amhandler::pg_catalog.regproc AS amhandler "); + appendPQExpBufferStr(query, + "amtype, " + "amhandler::pg_catalog.regproc AS amhandler "); appendPQExpBufferStr(query, "FROM pg_am"); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6827,35 +6826,35 @@ getAggregates(Archive *fout) * Find all interesting aggregates. See comment in getFuncs() for the * rationale behind the filtering logic. */ - agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" - : "p.proisagg"); + agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" + : "p.proisagg"); - appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " - "p.proname AS aggname, " - "p.pronamespace AS aggnamespace, " - "p.pronargs, p.proargtypes, " - "p.proowner, " - "p.proacl AS aggacl, " - "acldefault('f', p.proowner) AS acldefault " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s AND (" - "p.pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog') OR " - "p.proacl IS DISTINCT FROM pip.initprivs", - agg_check); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - " OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); - appendPQExpBufferChar(query, ')'); + appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " + "p.proname AS aggname, " + "p.pronamespace AS aggnamespace, " + "p.pronargs, p.proargtypes, " + "p.proowner, " + "p.proacl AS aggacl, " + "acldefault('f', p.proowner) AS acldefault " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s AND (" + "p.pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog') OR " + "p.proacl IS DISTINCT FROM pip.initprivs", + agg_check); + if (dopt->binary_upgrade) + appendPQExpBufferStr(query, + " OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6957,53 +6956,53 @@ getFuncs(Archive *fout) * include them, since we want to dump extension members individually in * that mode. Also, if they are used by casts or transforms then we need * to gather the information about them, though they won't be dumped if - * they are built-in. Also, include functions in - * pg_catalog if they have an ACL different from what's shown in - * pg_init_privs (so we have to join to pg_init_privs; annoying). + * they are built-in. Also, include functions in pg_catalog if they have + * an ACL different from what's shown in pg_init_privs (so we have to join + * to pg_init_privs; annoying). */ - not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" - : "NOT p.proisagg"); + not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" + : "NOT p.proisagg"); - appendPQExpBuffer(query, - "SELECT p.tableoid, p.oid, p.proname, p.prolang, " - "p.pronargs, p.proargtypes, p.prorettype, " - "p.proacl, " - "acldefault('f', p.proowner) AS acldefault, " - "p.pronamespace, " - "p.proowner " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s" - "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " - "WHERE classid = 'pg_proc'::regclass AND " - "objid = p.oid AND deptype = 'i')" - "\n AND (" - "\n pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog')" - "\n OR EXISTS (SELECT 1 FROM pg_cast" - "\n WHERE pg_cast.oid > %u " - "\n AND p.oid = pg_cast.castfunc)" - "\n OR EXISTS (SELECT 1 FROM pg_transform" - "\n WHERE pg_transform.oid > %u AND " - "\n (p.oid = pg_transform.trffromsql" - "\n OR p.oid = pg_transform.trftosql))", - not_agg_check, - g_last_builtin_oid, - g_last_builtin_oid); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); + appendPQExpBuffer(query, + "SELECT p.tableoid, p.oid, p.proname, p.prolang, " + "p.pronargs, p.proargtypes, p.prorettype, " + "p.proacl, " + "acldefault('f', p.proowner) AS acldefault, " + "p.pronamespace, " + "p.proowner " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s" + "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " + "WHERE classid = 'pg_proc'::regclass AND " + "objid = p.oid AND deptype = 'i')" + "\n AND (" + "\n pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog')" + "\n OR EXISTS (SELECT 1 FROM pg_cast" + "\n WHERE pg_cast.oid > %u " + "\n AND p.oid = pg_cast.castfunc)" + "\n OR EXISTS (SELECT 1 FROM pg_transform" + "\n WHERE pg_transform.oid > %u AND " + "\n (p.oid = pg_transform.trffromsql" + "\n OR p.oid = pg_transform.trftosql))", + not_agg_check, + g_last_builtin_oid, + g_last_builtin_oid); + if (dopt->binary_upgrade) appendPQExpBufferStr(query, - "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); - appendPQExpBufferChar(query, ')'); + "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferStr(query, + "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -7252,31 +7251,31 @@ getTables(Archive *fout, int *numTables) appendPQExpBufferStr(query, "c.relhasoids, "); - appendPQExpBufferStr(query, - "c.relispopulated, "); + appendPQExpBufferStr(query, + "c.relispopulated, "); - appendPQExpBufferStr(query, - "c.relreplident, "); + appendPQExpBufferStr(query, + "c.relreplident, "); - appendPQExpBufferStr(query, - "c.relrowsecurity, c.relforcerowsecurity, "); + appendPQExpBufferStr(query, + "c.relrowsecurity, c.relforcerowsecurity, "); - appendPQExpBufferStr(query, - "c.relminmxid, tc.relminmxid AS tminmxid, "); + appendPQExpBufferStr(query, + "c.relminmxid, tc.relminmxid AS tminmxid, "); - appendPQExpBufferStr(query, - "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); + appendPQExpBufferStr(query, + "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); - appendPQExpBufferStr(query, - "am.amname, "); + appendPQExpBufferStr(query, + "am.amname, "); - appendPQExpBufferStr(query, - "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); + appendPQExpBufferStr(query, + "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); - appendPQExpBufferStr(query, - "c.relispartition AS ispartition "); + appendPQExpBufferStr(query, + "c.relispartition AS ispartition "); /* * Left join to pg_depend to pick up dependency info linking sequences to @@ -7296,8 +7295,8 @@ getTables(Archive *fout, int *numTables) /* * Left join to pg_am to pick up the amname. */ - appendPQExpBufferStr(query, - "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); + appendPQExpBufferStr(query, + "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); /* * We purposefully ignore toast OIDs for partitioned tables; the reason is @@ -7868,8 +7867,8 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables) "t.reloptions AS indreloptions, "); - appendPQExpBufferStr(query, - "i.indisreplident, "); + appendPQExpBufferStr(query, + "i.indisreplident, "); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -9313,8 +9312,8 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables) appendPQExpBufferStr(q, "'' AS attcompression,\n"); - appendPQExpBufferStr(q, - "a.attidentity,\n"); + appendPQExpBufferStr(q, + "a.attidentity,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(q, @@ -10717,73 +10716,73 @@ getAdditionalACLs(Archive *fout) PQclear(res); /* Fetch initial-privileges data */ - printfPQExpBuffer(query, - "SELECT objoid, classoid, objsubid, privtype, initprivs " - "FROM pg_init_privs"); + printfPQExpBuffer(query, + "SELECT objoid, classoid, objsubid, privtype, initprivs " + "FROM pg_init_privs"); - res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); + res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); - ntups = PQntuples(res); - for (i = 0; i < ntups; i++) - { - Oid objoid = atooid(PQgetvalue(res, i, 0)); - Oid classoid = atooid(PQgetvalue(res, i, 1)); - int objsubid = atoi(PQgetvalue(res, i, 2)); - char privtype = *(PQgetvalue(res, i, 3)); - char *initprivs = PQgetvalue(res, i, 4); - CatalogId objId; - DumpableObject *dobj; + ntups = PQntuples(res); + for (i = 0; i < ntups; i++) + { + Oid objoid = atooid(PQgetvalue(res, i, 0)); + Oid classoid = atooid(PQgetvalue(res, i, 1)); + int objsubid = atoi(PQgetvalue(res, i, 2)); + char privtype = *(PQgetvalue(res, i, 3)); + char *initprivs = PQgetvalue(res, i, 4); + CatalogId objId; + DumpableObject *dobj; - objId.tableoid = classoid; - objId.oid = objoid; - dobj = findObjectByCatalogId(objId); - /* OK to ignore entries we haven't got a DumpableObject for */ - if (dobj) + objId.tableoid = classoid; + objId.oid = objoid; + dobj = findObjectByCatalogId(objId); + /* OK to ignore entries we haven't got a DumpableObject for */ + if (dobj) + { + /* Cope with sub-object initprivs */ + if (objsubid != 0) { - /* Cope with sub-object initprivs */ - if (objsubid != 0) - { - if (dobj->objType == DO_TABLE) - { - /* For a column initprivs, set the table's ACL flags */ - dobj->components |= DUMP_COMPONENT_ACL; - ((TableInfo *) dobj)->hascolumnACLs = true; - } - else - pg_log_warning("unsupported pg_init_privs entry: %u %u %d", - classoid, objoid, objsubid); - continue; - } - - /* - * We ignore any pg_init_privs.initprivs entry for the public - * schema, as explained in getNamespaces(). - */ - if (dobj->objType == DO_NAMESPACE && - strcmp(dobj->name, "public") == 0) - continue; - - /* Else it had better be of a type we think has ACLs */ - if (dobj->objType == DO_NAMESPACE || - dobj->objType == DO_TYPE || - dobj->objType == DO_FUNC || - dobj->objType == DO_AGG || - dobj->objType == DO_TABLE || - dobj->objType == DO_PROCLANG || - dobj->objType == DO_FDW || - dobj->objType == DO_FOREIGN_SERVER) + if (dobj->objType == DO_TABLE) { - DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; - - daobj->dacl.privtype = privtype; - daobj->dacl.initprivs = pstrdup(initprivs); + /* For a column initprivs, set the table's ACL flags */ + dobj->components |= DUMP_COMPONENT_ACL; + ((TableInfo *) dobj)->hascolumnACLs = true; } else pg_log_warning("unsupported pg_init_privs entry: %u %u %d", classoid, objoid, objsubid); + continue; + } + + /* + * We ignore any pg_init_privs.initprivs entry for the public + * schema, as explained in getNamespaces(). + */ + if (dobj->objType == DO_NAMESPACE && + strcmp(dobj->name, "public") == 0) + continue; + + /* Else it had better be of a type we think has ACLs */ + if (dobj->objType == DO_NAMESPACE || + dobj->objType == DO_TYPE || + dobj->objType == DO_FUNC || + dobj->objType == DO_AGG || + dobj->objType == DO_TABLE || + dobj->objType == DO_PROCLANG || + dobj->objType == DO_FDW || + dobj->objType == DO_FOREIGN_SERVER) + { + DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; + + daobj->dacl.privtype = privtype; + daobj->dacl.initprivs = pstrdup(initprivs); } + else + pg_log_warning("unsupported pg_init_privs entry: %u %u %d", + classoid, objoid, objsubid); } - PQclear(res); + } + PQclear(res); destroyPQExpBuffer(query); } @@ -11128,8 +11127,8 @@ dumpRelationStats_dumper(Archive *fout, const void *userArg, const TocEntry *te) * The results must be in the order of the relations supplied in the * parameters to ensure we remain in sync as we walk through the TOC. * - * For versions before 19, the redundant filter clause on s.tablename = - * ANY(...) seems sufficient to convince the planner to use + * For versions before 19, the redundant filter clause on s.tablename + * = ANY(...) seems sufficient to convince the planner to use * pg_class_relname_nsp_index, which avoids a full scan of pg_stats. * In newer versions, pg_stats returns the table OIDs, eliminating the * need for that hack. @@ -13469,11 +13468,11 @@ dumpFunc(Archive *fout, const FuncInfo *finfo) "pg_catalog.pg_get_function_result(p.oid) AS funcresult,\n" "proleakproof,\n"); - appendPQExpBufferStr(query, - "array_to_string(protrftypes, ' ') AS protrftypes,\n"); + appendPQExpBufferStr(query, + "array_to_string(protrftypes, ' ') AS protrftypes,\n"); - appendPQExpBufferStr(query, - "proparallel,\n"); + appendPQExpBufferStr(query, + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -14963,9 +14962,9 @@ dumpCollation(Archive *fout, const CollInfo *collinfo) /* Get collation-specific details */ appendPQExpBufferStr(query, "SELECT "); - appendPQExpBufferStr(query, - "collprovider, " - "collversion, "); + appendPQExpBufferStr(query, + "collprovider, " + "collversion, "); if (fout->remoteVersion >= 120000) appendPQExpBufferStr(query, @@ -15372,23 +15371,23 @@ dumpAgg(Archive *fout, const AggInfo *agginfo) "pg_catalog.pg_get_function_arguments(p.oid) AS funcargs,\n" "pg_catalog.pg_get_function_identity_arguments(p.oid) AS funciargs,\n"); - appendPQExpBufferStr(query, - "aggkind,\n" - "aggmtransfn,\n" - "aggminvtransfn,\n" - "aggmfinalfn,\n" - "aggmtranstype::pg_catalog.regtype,\n" - "aggfinalextra,\n" - "aggmfinalextra,\n" - "aggtransspace,\n" - "aggmtransspace,\n" - "aggminitval,\n"); + appendPQExpBufferStr(query, + "aggkind,\n" + "aggmtransfn,\n" + "aggminvtransfn,\n" + "aggmfinalfn,\n" + "aggmtranstype::pg_catalog.regtype,\n" + "aggfinalextra,\n" + "aggmfinalextra,\n" + "aggtransspace,\n" + "aggmtransspace,\n" + "aggminitval,\n"); - appendPQExpBufferStr(query, - "aggcombinefn,\n" - "aggserialfn,\n" - "aggdeserialfn,\n" - "proparallel,\n"); + appendPQExpBufferStr(query, + "aggcombinefn,\n" + "aggserialfn,\n" + "aggdeserialfn,\n" + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -16848,30 +16847,30 @@ dumpTable(Archive *fout, const TableInfo *tbinfo) appendPQExpBufferStr(query, "PREPARE getColumnACLs(pg_catalog.oid) AS\n"); - /* - * In principle we should call acldefault('c', relowner) to - * get the default ACL for a column. However, we don't - * currently store the numeric OID of the relowner in - * TableInfo. We could convert the owner name using regrole, - * but that creates a risk of failure due to concurrent role - * renames. Given that the default ACL for columns is empty - * and is likely to stay that way, it's not worth extra cycles - * and risk to avoid hard-wiring that knowledge here. - */ - appendPQExpBufferStr(query, - "SELECT at.attname, " - "at.attacl, " - "'{}' AS acldefault, " - "pip.privtype, pip.initprivs " - "FROM pg_catalog.pg_attribute at " - "LEFT JOIN pg_catalog.pg_init_privs pip ON " - "(at.attrelid = pip.objoid " - "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " - "AND at.attnum = pip.objsubid) " - "WHERE at.attrelid = $1 AND " - "NOT at.attisdropped " - "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " - "ORDER BY at.attnum"); + /* + * In principle we should call acldefault('c', relowner) to get + * the default ACL for a column. However, we don't currently + * store the numeric OID of the relowner in TableInfo. We could + * convert the owner name using regrole, but that creates a risk + * of failure due to concurrent role renames. Given that the + * default ACL for columns is empty and is likely to stay that + * way, it's not worth extra cycles and risk to avoid hard-wiring + * that knowledge here. + */ + appendPQExpBufferStr(query, + "SELECT at.attname, " + "at.attacl, " + "'{}' AS acldefault, " + "pip.privtype, pip.initprivs " + "FROM pg_catalog.pg_attribute at " + "LEFT JOIN pg_catalog.pg_init_privs pip ON " + "(at.attrelid = pip.objoid " + "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " + "AND at.attnum = pip.objsubid) " + "WHERE at.attrelid = $1 AND " + "NOT at.attisdropped " + "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " + "ORDER BY at.attnum"); ExecuteSqlStatement(fout, query->data); @@ -19165,7 +19164,7 @@ collectSequences(Archive *fout) * pg_get_sequence_data(), but we only do so for non-schema-only dumps. */ if (fout->remoteVersion < 180000 || - (!fout->dopt->dumpData && !fout->dopt->sequence_data)) + (!fout->dopt->dumpData && !fout->dopt->sequence_data)) query = "SELECT seqrelid, format_type(seqtypid, NULL), " "seqstart, seqincrement, " "seqmax, seqmin, " @@ -19227,15 +19226,14 @@ dumpSequence(Archive *fout, const TableInfo *tbinfo) qseqname = pg_strdup(fmtId(tbinfo->dobj.name)); /* - * The sequence information is gathered in a sorted - * table before any calls to dumpSequence(). See collectSequences() for - * more information. + * The sequence information is gathered in a sorted table before any calls + * to dumpSequence(). See collectSequences() for more information. */ - Assert(sequences); + Assert(sequences); - key.oid = tbinfo->dobj.catId.oid; - seq = bsearch(&key, sequences, nsequences, - sizeof(SequenceItem), SequenceItemCmp); + key.oid = tbinfo->dobj.catId.oid; + seq = bsearch(&key, sequences, nsequences, + sizeof(SequenceItem), SequenceItemCmp); /* Calculate default limits for a sequence of this type */ is_ascending = (seq->incby >= 0); diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c index e68937c9934..afcd9a218d8 100644 --- a/src/bin/pg_dump/pg_dumpall.c +++ b/src/bin/pg_dump/pg_dumpall.c @@ -785,11 +785,11 @@ dropRoles(PGconn *conn) int i_rolname; int i; - printfPQExpBuffer(buf, - "SELECT rolname " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 1", role_catalog); + printfPQExpBuffer(buf, + "SELECT rolname " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 1", role_catalog); res = executeQuery(conn, buf->data); @@ -843,16 +843,16 @@ dumpRoles(PGconn *conn) * Notes: rolconfig is dumped later, and pg_authid must be used for * extracting rolcomment regardless of role_catalog. */ - printfPQExpBuffer(buf, - "SELECT oid, rolname, rolsuper, rolinherit, " - "rolcreaterole, rolcreatedb, " - "rolcanlogin, rolconnlimit, rolpassword, " - "rolvaliduntil, rolreplication, rolbypassrls, " - "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " - "rolname = current_user AS is_current_user " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 2", role_catalog); + printfPQExpBuffer(buf, + "SELECT oid, rolname, rolsuper, rolinherit, " + "rolcreaterole, rolcreatedb, " + "rolcanlogin, rolconnlimit, rolpassword, " + "rolvaliduntil, rolreplication, rolbypassrls, " + "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " + "rolname = current_user AS is_current_user " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 2", role_catalog); res = executeQuery(conn, buf->data); diff --git a/src/bin/pg_upgrade/check.c b/src/bin/pg_upgrade/check.c index 786c1474829..f725f5ee3e2 100644 --- a/src/bin/pg_upgrade/check.c +++ b/src/bin/pg_upgrade/check.c @@ -1475,15 +1475,15 @@ check_for_incompatible_polymorphics(ClusterInfo *cluster) ", 'array_cat(anyarray,anyarray)'" ", 'array_prepend(anyelement,anyarray)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_remove(anyarray,anyelement)'" - ", 'array_replace(anyarray,anyelement,anyelement)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_remove(anyarray,anyelement)'" + ", 'array_replace(anyarray,anyelement,anyelement)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_position(anyarray,anyelement)'" - ", 'array_position(anyarray,anyelement,integer)'" - ", 'array_positions(anyarray,anyelement)'" - ", 'width_bucket(anyelement,anyarray)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_position(anyarray,anyelement)'" + ", 'array_position(anyarray,anyelement,integer)'" + ", 'array_positions(anyarray,anyelement)'" + ", 'width_bucket(anyelement,anyarray)'"); /* * The query below hardcodes FirstNormalObjectId as 16384 rather than diff --git a/src/bin/pg_upgrade/controldata.c b/src/bin/pg_upgrade/controldata.c index 8f81c9e9582..02ea02df60f 100644 --- a/src/bin/pg_upgrade/controldata.c +++ b/src/bin/pg_upgrade/controldata.c @@ -228,7 +228,7 @@ get_control_data(ClusterInfo *cluster) p++; /* remove ':' char */ cluster->controldata.chkpnt_nxtepoch = str2uint(p); - p = strchr(p, ':'); + p = strchr(p, ':'); if (p == NULL || strlen(p) <= 1) pg_fatal("%d: controldata retrieval problem", __LINE__); diff --git a/src/bin/pg_upgrade/exec.c b/src/bin/pg_upgrade/exec.c index 44355feea30..a1bdbf373e3 100644 --- a/src/bin/pg_upgrade/exec.c +++ b/src/bin/pg_upgrade/exec.c @@ -55,7 +55,7 @@ get_bin_version(ClusterInfo *cluster) if (sscanf(cmd_output, "%*s %*s %d.%d", &v1, &v2) < 1) pg_fatal("could not get pg_ctl version output from %s", cmd); - cluster->bin_version = v1 * 10000; + cluster->bin_version = v1 * 10000; } @@ -344,8 +344,8 @@ check_data_dir(ClusterInfo *cluster) check_single_dir(pg_data, "pg_subtrans"); check_single_dir(pg_data, PG_TBLSPC_DIR); check_single_dir(pg_data, "pg_twophase"); - check_single_dir(pg_data, "pg_wal"); - check_single_dir(pg_data, "pg_xact"); + check_single_dir(pg_data, "pg_wal"); + check_single_dir(pg_data, "pg_xact"); } @@ -385,7 +385,7 @@ check_bin_dir(ClusterInfo *cluster, bool check_versions) */ get_bin_version(cluster); - check_exec(cluster->bindir, "pg_resetwal", check_versions); + check_exec(cluster->bindir, "pg_resetwal", check_versions); if (cluster == &new_cluster) { diff --git a/src/bin/pg_upgrade/multixact_rewrite.c b/src/bin/pg_upgrade/multixact_rewrite.c index c45b3183684..c7a1416494d 100644 --- a/src/bin/pg_upgrade/multixact_rewrite.c +++ b/src/bin/pg_upgrade/multixact_rewrite.c @@ -61,52 +61,52 @@ rewrite_multixacts(MultiXactId from_multi, MultiXactId to_multi) * Convert old multixids, if needed, by reading them one-by-one from the * old cluster. */ - old_reader = AllocOldMultiXactRead(old_cluster.pgdata, - old_cluster.controldata.chkpnt_nxtmulti, - old_cluster.controldata.chkpnt_nxtmxoff); + old_reader = AllocOldMultiXactRead(old_cluster.pgdata, + old_cluster.controldata.chkpnt_nxtmulti, + old_cluster.controldata.chkpnt_nxtmxoff); - for (MultiXactId multi = from_multi; multi != to_multi;) - { - MultiXactMember member; - bool multixid_valid; - - /* - * Read this multixid's members. - * - * Locking-only XIDs that may be part of multi-xids don't matter - * after upgrade, as there can be no transactions running across - * upgrade. So as a small optimization, we only read one member - * from each multixid: the one updating one, or if there was no - * update, arbitrarily the first locking xid. - */ - multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); + for (MultiXactId multi = from_multi; multi != to_multi;) + { + MultiXactMember member; + bool multixid_valid; - /* - * Write the new offset to pg_multixact/offsets. - * - * Even if this multixid is invalid, we still need to write its - * offset if the *previous* multixid was valid. That's because - * when reading a multixid, the number of members is calculated - * from the difference between the two offsets. - */ - RecordMultiXactOffset(offsets_writer, multi, - (multixid_valid || prev_multixid_valid) ? next_offset : 0); + /* + * Read this multixid's members. + * + * Locking-only XIDs that may be part of multi-xids don't matter after + * upgrade, as there can be no transactions running across upgrade. So + * as a small optimization, we only read one member from each + * multixid: the one updating one, or if there was no update, + * arbitrarily the first locking xid. + */ + multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); - /* Write the members */ - if (multixid_valid) - { - RecordMultiXactMembers(members_writer, next_offset, 1, &member); - next_offset += 1; - } + /* + * Write the new offset to pg_multixact/offsets. + * + * Even if this multixid is invalid, we still need to write its offset + * if the *previous* multixid was valid. That's because when reading + * a multixid, the number of members is calculated from the difference + * between the two offsets. + */ + RecordMultiXactOffset(offsets_writer, multi, + (multixid_valid || prev_multixid_valid) ? next_offset : 0); - /* Advance to next multixid, handling wraparound */ - multi++; - if (multi < FirstMultiXactId) - multi = FirstMultiXactId; - prev_multixid_valid = multixid_valid; + /* Write the members */ + if (multixid_valid) + { + RecordMultiXactMembers(members_writer, next_offset, 1, &member); + next_offset += 1; } - FreeOldMultiXactReader(old_reader); + /* Advance to next multixid, handling wraparound */ + multi++; + if (multi < FirstMultiXactId) + multi = FirstMultiXactId; + prev_multixid_valid = multixid_valid; + } + + FreeOldMultiXactReader(old_reader); /* Write the final 'next' offset to the last SLRU page */ RecordMultiXactOffset(offsets_writer, to_multi, diff --git a/src/bin/pg_upgrade/pg_upgrade.c b/src/bin/pg_upgrade/pg_upgrade.c index c6af9035665..7366fd4627c 100644 --- a/src/bin/pg_upgrade/pg_upgrade.c +++ b/src/bin/pg_upgrade/pg_upgrade.c @@ -833,7 +833,7 @@ copy_xact_xlog_xid(void) * Determine the range of multixacts to convert. */ nxtmulti = old_cluster.controldata.chkpnt_nxtmulti; - oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; + oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; /* handle wraparound */ if (nxtmulti < FirstMultiXactId) nxtmulti = FirstMultiXactId; @@ -898,15 +898,15 @@ set_frozenxids(void) int i_datname; int i_datallowconn; - prep_status("Setting frozenxid and minmxid counters in new cluster"); + prep_status("Setting frozenxid and minmxid counters in new cluster"); conn_template1 = connectToServer(&new_cluster, "template1"); - /* set pg_database.datfrozenxid */ - PQclear(executeQueryOrDie(conn_template1, - "UPDATE pg_catalog.pg_database " - "SET datfrozenxid = '%u'", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_database.datfrozenxid */ + PQclear(executeQueryOrDie(conn_template1, + "UPDATE pg_catalog.pg_database " + "SET datfrozenxid = '%u'", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_database.datminmxid */ PQclear(executeQueryOrDie(conn_template1, @@ -942,16 +942,16 @@ set_frozenxids(void) conn = connectToServer(&new_cluster, datname); - /* set pg_class.relfrozenxid */ - PQclear(executeQueryOrDie(conn, - "UPDATE pg_catalog.pg_class " - "SET relfrozenxid = '%u' " - /* only heap, materialized view, and TOAST are vacuumed */ - "WHERE relkind IN (" - CppAsString2(RELKIND_RELATION) ", " - CppAsString2(RELKIND_MATVIEW) ", " - CppAsString2(RELKIND_TOASTVALUE) ")", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_class.relfrozenxid */ + PQclear(executeQueryOrDie(conn, + "UPDATE pg_catalog.pg_class " + "SET relfrozenxid = '%u' " + /* only heap, materialized view, and TOAST are vacuumed */ + "WHERE relkind IN (" + CppAsString2(RELKIND_RELATION) ", " + CppAsString2(RELKIND_MATVIEW) ", " + CppAsString2(RELKIND_TOASTVALUE) ")", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_class.relminmxid */ PQclear(executeQueryOrDie(conn, diff --git a/src/bin/pg_upgrade/relfilenumber.c b/src/bin/pg_upgrade/relfilenumber.c index ec2ff7acb21..6c467bdc8a5 100644 --- a/src/bin/pg_upgrade/relfilenumber.c +++ b/src/bin/pg_upgrade/relfilenumber.c @@ -587,32 +587,32 @@ transfer_relfile(FileNameMap *map, const char *type_suffix) /* Copying files might take some time, so give feedback. */ pg_log(PG_STATUS, "%s", old_file); - switch (user_opts.transfer_mode) - { - case TRANSFER_MODE_CLONE: - pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", - old_file, new_file); - cloneFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", - old_file, new_file); - copyFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY_FILE_RANGE: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", - old_file, new_file); - copyFileByRange(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_LINK: - pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", - old_file, new_file); - linkFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_SWAP: - /* swap mode is handled in its own code path */ - pg_fatal("should never happen"); - break; - } + switch (user_opts.transfer_mode) + { + case TRANSFER_MODE_CLONE: + pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", + old_file, new_file); + cloneFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", + old_file, new_file); + copyFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY_FILE_RANGE: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", + old_file, new_file); + copyFileByRange(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_LINK: + pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", + old_file, new_file); + linkFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_SWAP: + /* swap mode is handled in its own code path */ + pg_fatal("should never happen"); + break; + } } } diff --git a/src/bin/pg_upgrade/t/006_transfer_modes.pl b/src/bin/pg_upgrade/t/006_transfer_modes.pl index 9efa5dc863c..360d05c4b68 100644 --- a/src/bin/pg_upgrade/t/006_transfer_modes.pl +++ b/src/bin/pg_upgrade/t/006_transfer_modes.pl @@ -29,10 +29,8 @@ sub test_mode } $new->init(); - $new->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); - $old->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); + $new->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); + $old->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); # We can only test security labels if both the old and new installations # have dummy_seclabel. @@ -76,15 +74,14 @@ sub test_mode "CREATE TABLE test4 AS SELECT generate_series(400, 502)"); } - $old->safe_psql('postgres', - "CREATE TABLESPACE inplc_tblspc LOCATION ''"); - $old->safe_psql('postgres', - "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); - $old->safe_psql('postgres', - "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" - ); - $old->safe_psql('testdb3', - "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); + $old->safe_psql('postgres', "CREATE TABLESPACE inplc_tblspc LOCATION ''"); + $old->safe_psql('postgres', + "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); + $old->safe_psql('postgres', + "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" + ); + $old->safe_psql('testdb3', + "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); # While we are here, test handling of large objects. $old->safe_psql( @@ -152,12 +149,10 @@ sub test_mode } # Tests for in-place tablespaces. - $result = - $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); - is($result, '104', "test5 data after pg_upgrade $mode"); - $result = - $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); - is($result, '105', "test6 data after pg_upgrade $mode"); + $result = $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); + is($result, '104', "test5 data after pg_upgrade $mode"); + $result = $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); + is($result, '105', "test6 data after pg_upgrade $mode"); # Tests for large objects $result = $new->safe_psql('postgres', "SELECT lo_get(4532)"); diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index 44ef11d980e..c90bf8bbde2 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -6278,23 +6278,22 @@ get_create_object_cmd(EditableObjectType obj_type, Oid oid, * ensure the right view gets replaced. Also, check relation kind * to be sure it's a view. * - * Views may have WITH [LOCAL|CASCADED] - * CHECK OPTION. These are not part of the view definition - * returned by pg_get_viewdef() and so need to be retrieved - * separately. Materialized views may have - * arbitrary storage parameter reloptions. + * Views may have WITH [LOCAL|CASCADED] CHECK OPTION. These are + * not part of the view definition returned by pg_get_viewdef() + * and so need to be retrieved separately. Materialized views may + * have arbitrary storage parameter reloptions. */ printfPQExpBuffer(query, "/* %s */\n", _("Get view's definition and details")); - appendPQExpBuffer(query, - "SELECT nspname, relname, relkind, " - "pg_catalog.pg_get_viewdef(c.oid, true), " - "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " - "FROM pg_catalog.pg_class c " - "LEFT JOIN pg_catalog.pg_namespace n " - "ON c.relnamespace = n.oid WHERE c.oid = %u", - oid); + appendPQExpBuffer(query, + "SELECT nspname, relname, relkind, " + "pg_catalog.pg_get_viewdef(c.oid, true), " + "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " + "FROM pg_catalog.pg_class c " + "LEFT JOIN pg_catalog.pg_namespace n " + "ON c.relnamespace = n.oid WHERE c.oid = %u", + oid); break; } diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index ce99137c613..ac0c55e7aa5 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -387,19 +387,19 @@ describeFunctions(const char *functypes, const char *func_pattern, gettext_noop("stable"), gettext_noop("volatile"), gettext_noop("Volatility")); - appendPQExpBuffer(&buf, - ",\n CASE\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" - " END as \"%s\"", - gettext_noop("restricted"), - gettext_noop("safe"), - gettext_noop("unsafe"), - gettext_noop("Parallel")); + appendPQExpBuffer(&buf, + ",\n CASE\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" + " END as \"%s\"", + gettext_noop("restricted"), + gettext_noop("safe"), + gettext_noop("unsafe"), + gettext_noop("Parallel")); appendPQExpBuffer(&buf, ",\n pg_catalog.pg_get_userbyid(p.proowner) as \"%s\"" ",\n CASE WHEN prosecdef THEN '%s' ELSE '%s' END AS \"%s\"" @@ -599,8 +599,8 @@ describeFunctions(const char *functypes, const char *func_pattern, myopt.title = _("List of functions"); myopt.translate_header = true; - myopt.translate_columns = translate_columns; - myopt.n_translate_columns = lengthof(translate_columns); + myopt.translate_columns = translate_columns; + myopt.n_translate_columns = lengthof(translate_columns); printQuery(res, &myopt, pset.queryFout, false, pset.logfile); @@ -1086,38 +1086,38 @@ permissionsList(const char *pattern, bool showSystem) " ), E'\\n') AS \"%s\"", gettext_noop("Column privileges")); - appendPQExpBuffer(&buf, - ",\n pg_catalog.array_to_string(ARRAY(\n" - " SELECT polname\n" - " || CASE WHEN NOT polpermissive THEN\n" - " E' (RESTRICTIVE)'\n" - " ELSE '' END\n" - " || CASE WHEN polcmd != '*' THEN\n" - " E' (' || polcmd::pg_catalog.text || E'):'\n" - " ELSE E':'\n" - " END\n" - " || CASE WHEN polqual IS NOT NULL THEN\n" - " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" - " ELSE E''\n" - " END\n" - " || CASE WHEN polwithcheck IS NOT NULL THEN\n" - " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" - " ELSE E''\n" - " END" - " || CASE WHEN polroles <> '{0}' THEN\n" - " E'\\n to: ' || pg_catalog.array_to_string(\n" - " ARRAY(\n" - " SELECT rolname\n" - " FROM pg_catalog.pg_roles\n" - " WHERE oid = ANY (polroles)\n" - " ORDER BY 1\n" - " ), E', ')\n" - " ELSE E''\n" - " END\n" - " FROM pg_catalog.pg_policy pol\n" - " WHERE polrelid = c.oid), E'\\n')\n" - " AS \"%s\"", - gettext_noop("Policies")); + appendPQExpBuffer(&buf, + ",\n pg_catalog.array_to_string(ARRAY(\n" + " SELECT polname\n" + " || CASE WHEN NOT polpermissive THEN\n" + " E' (RESTRICTIVE)'\n" + " ELSE '' END\n" + " || CASE WHEN polcmd != '*' THEN\n" + " E' (' || polcmd::pg_catalog.text || E'):'\n" + " ELSE E':'\n" + " END\n" + " || CASE WHEN polqual IS NOT NULL THEN\n" + " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" + " ELSE E''\n" + " END\n" + " || CASE WHEN polwithcheck IS NOT NULL THEN\n" + " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" + " ELSE E''\n" + " END" + " || CASE WHEN polroles <> '{0}' THEN\n" + " E'\\n to: ' || pg_catalog.array_to_string(\n" + " ARRAY(\n" + " SELECT rolname\n" + " FROM pg_catalog.pg_roles\n" + " WHERE oid = ANY (polroles)\n" + " ORDER BY 1\n" + " ), E', ')\n" + " ELSE E''\n" + " END\n" + " FROM pg_catalog.pg_policy pol\n" + " WHERE polrelid = c.oid), E'\\n')\n" + " AS \"%s\"", + gettext_noop("Policies")); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_class c\n" " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n" @@ -1675,27 +1675,27 @@ describeOneTableDetails(const char *schemaname, char *footers[3] = {NULL, NULL, NULL}; printfPQExpBuffer(&buf, "/* %s */\n", _("Get sequence information")); - appendPQExpBuffer(&buf, - "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" - " seqstart AS \"%s\",\n" - " seqmin AS \"%s\",\n" - " seqmax AS \"%s\",\n" - " seqincrement AS \"%s\",\n" - " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" - " seqcache AS \"%s\"\n", - gettext_noop("Type"), - gettext_noop("Start"), - gettext_noop("Minimum"), - gettext_noop("Maximum"), - gettext_noop("Increment"), - gettext_noop("yes"), - gettext_noop("no"), - gettext_noop("Cycles?"), - gettext_noop("Cache")); - appendPQExpBuffer(&buf, - "FROM pg_catalog.pg_sequence\n" - "WHERE seqrelid = '%s';", - oid); + appendPQExpBuffer(&buf, + "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" + " seqstart AS \"%s\",\n" + " seqmin AS \"%s\",\n" + " seqmax AS \"%s\",\n" + " seqincrement AS \"%s\",\n" + " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" + " seqcache AS \"%s\"\n", + gettext_noop("Type"), + gettext_noop("Start"), + gettext_noop("Minimum"), + gettext_noop("Maximum"), + gettext_noop("Increment"), + gettext_noop("yes"), + gettext_noop("no"), + gettext_noop("Cycles?"), + gettext_noop("Cache")); + appendPQExpBuffer(&buf, + "FROM pg_catalog.pg_sequence\n" + "WHERE seqrelid = '%s';", + oid); res = PSQLexec(buf.data); if (!res) @@ -1913,7 +1913,7 @@ describeOneTableDetails(const char *schemaname, appendPQExpBufferStr(&buf, ",\n (SELECT c.collname FROM pg_catalog.pg_collation c, pg_catalog.pg_type t\n" " WHERE c.oid = a.attcollation AND t.oid = a.atttypid AND a.attcollation <> t.typcollation) AS attcollation"); attcoll_col = cols++; - appendPQExpBufferStr(&buf, ",\n a.attidentity"); + appendPQExpBufferStr(&buf, ",\n a.attidentity"); attidentity_col = cols++; if (pset.sversion >= 120000) appendPQExpBufferStr(&buf, ",\n a.attgenerated"); @@ -2326,7 +2326,7 @@ describeOneTableDetails(const char *schemaname, CppAsString2(CONSTRAINT_EXCLUSION) ") AND " "condeferred) AS condeferred,\n"); - appendPQExpBufferStr(&buf, "i.indisreplident,\n"); + appendPQExpBufferStr(&buf, "i.indisreplident,\n"); if (pset.sversion >= 150000) appendPQExpBufferStr(&buf, "i.indnullsnotdistinct,\n"); @@ -2431,7 +2431,7 @@ describeOneTableDetails(const char *schemaname, "pg_catalog.pg_get_indexdef(i.indexrelid, 0, true),\n " "pg_catalog.pg_get_constraintdef(con.oid, true), " "contype, condeferrable, condeferred"); - appendPQExpBufferStr(&buf, ", i.indisreplident"); + appendPQExpBufferStr(&buf, ", i.indisreplident"); appendPQExpBufferStr(&buf, ", c2.reltablespace"); if (pset.sversion >= 180000) appendPQExpBufferStr(&buf, ", con.conperiod"); @@ -2682,81 +2682,80 @@ describeOneTableDetails(const char *schemaname, PQclear(result); /* print any row-level policies */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get row-level policies for this table")); - appendPQExpBufferStr(&buf, "SELECT pol.polname,"); - appendPQExpBufferStr(&buf, - " pol.polpermissive,\n"); - appendPQExpBuffer(&buf, - " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" - " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" - " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" - " CASE pol.polcmd\n" - " WHEN 'r' THEN 'SELECT'\n" - " WHEN 'a' THEN 'INSERT'\n" - " WHEN 'w' THEN 'UPDATE'\n" - " WHEN 'd' THEN 'DELETE'\n" - " END AS cmd\n" - "FROM pg_catalog.pg_policy pol\n" - "WHERE pol.polrelid = '%s' ORDER BY 1;", - oid); + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get row-level policies for this table")); + appendPQExpBufferStr(&buf, "SELECT pol.polname,"); + appendPQExpBufferStr(&buf, + " pol.polpermissive,\n"); + appendPQExpBuffer(&buf, + " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" + " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" + " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" + " CASE pol.polcmd\n" + " WHEN 'r' THEN 'SELECT'\n" + " WHEN 'a' THEN 'INSERT'\n" + " WHEN 'w' THEN 'UPDATE'\n" + " WHEN 'd' THEN 'DELETE'\n" + " END AS cmd\n" + "FROM pg_catalog.pg_policy pol\n" + "WHERE pol.polrelid = '%s' ORDER BY 1;", + oid); - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - /* - * Handle cases where RLS is enabled and there are policies, or - * there aren't policies, or RLS isn't enabled but there are - * policies - */ - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies:")); + /* + * Handle cases where RLS is enabled and there are policies, or there + * aren't policies, or RLS isn't enabled but there are policies + */ + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies:")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled):")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled):")); - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); - if (!tableinfo.rowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (row security disabled):")); + if (!tableinfo.rowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (row security disabled):")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " POLICY \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " POLICY \"%s\"", + PQgetvalue(result, i, 0)); - if (*(PQgetvalue(result, i, 1)) == 'f') - appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); + if (*(PQgetvalue(result, i, 1)) == 'f') + appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); - if (!PQgetisnull(result, i, 5)) - appendPQExpBuffer(&buf, " FOR %s", - PQgetvalue(result, i, 5)); + if (!PQgetisnull(result, i, 5)) + appendPQExpBuffer(&buf, " FOR %s", + PQgetvalue(result, i, 5)); - if (!PQgetisnull(result, i, 2)) - { - appendPQExpBuffer(&buf, "\n TO %s", - PQgetvalue(result, i, 2)); - } + if (!PQgetisnull(result, i, 2)) + { + appendPQExpBuffer(&buf, "\n TO %s", + PQgetvalue(result, i, 2)); + } - if (!PQgetisnull(result, i, 3)) - appendPQExpBuffer(&buf, "\n USING (%s)", - PQgetvalue(result, i, 3)); + if (!PQgetisnull(result, i, 3)) + appendPQExpBuffer(&buf, "\n USING (%s)", + PQgetvalue(result, i, 3)); - if (!PQgetisnull(result, i, 4)) - appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", - PQgetvalue(result, i, 4)); + if (!PQgetisnull(result, i, 4)) + appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", + PQgetvalue(result, i, 4)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* print any extended statistics */ if (pset.sversion >= 140000) @@ -3025,115 +3024,115 @@ describeOneTableDetails(const char *schemaname, } /* print any publications */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get publications that publish this table")); - if (pset.sversion >= 150000) + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get publications that publish this table")); + if (pset.sversion >= 150000) + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" + " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" + "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" + "UNION\n" + "SELECT pubname\n" + " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" + " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" + " (SELECT pg_catalog.string_agg(attname, ', ')\n" + " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" + " pg_catalog.pg_attribute\n" + " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" + " ELSE NULL END) " + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" + "WHERE pr.prrelid = '%s'\n", + oid, oid, oid); + + if (pset.sversion >= 190000) { + /* + * Skip entries where this relation appears in the + * publication's EXCEPT list. + */ appendPQExpBuffer(&buf, + " AND NOT pr.prexcept\n" + "UNION\n" "SELECT pubname\n" " , NULL\n" " , NULL\n" "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" - " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" - "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" - "UNION\n" - "SELECT pubname\n" - " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" - " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" - " (SELECT pg_catalog.string_agg(attname, ', ')\n" - " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" - " pg_catalog.pg_attribute\n" - " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" - " ELSE NULL END) " - "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" - "WHERE pr.prrelid = '%s'\n", + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + " AND NOT EXISTS (\n" + " SELECT 1\n" + " FROM pg_catalog.pg_publication_rel pr\n" + " WHERE pr.prpubid = p.oid AND\n" + " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" + "ORDER BY 1;", oid, oid, oid); - - if (pset.sversion >= 190000) - { - /* - * Skip entries where this relation appears in the - * publication's EXCEPT list. - */ - appendPQExpBuffer(&buf, - " AND NOT pr.prexcept\n" - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - " AND NOT EXISTS (\n" - " SELECT 1\n" - " FROM pg_catalog.pg_publication_rel pr\n" - " WHERE pr.prpubid = p.oid AND\n" - " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" - "ORDER BY 1;", - oid, oid, oid); - } - else - { - appendPQExpBuffer(&buf, - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - "ORDER BY 1;", - oid); - } } else { appendPQExpBuffer(&buf, + "UNION\n" "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - "WHERE pr.prrelid = '%s'\n" - "UNION ALL\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" + " , NULL\n" + " , NULL\n" "FROM pg_catalog.pg_publication p\n" "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" "ORDER BY 1;", - oid, oid); + oid); } + } + else + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + "WHERE pr.prrelid = '%s'\n" + "UNION ALL\n" + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + "ORDER BY 1;", + oid, oid); + } - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - if (tuples > 0) - printTableAddFooter(&cont, _("Included in publications:")); + if (tuples > 0) + printTableAddFooter(&cont, _("Included in publications:")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " \"%s\"", + PQgetvalue(result, i, 0)); - /* column list (if any) */ - if (!PQgetisnull(result, i, 2)) - appendPQExpBuffer(&buf, " (%s)", - PQgetvalue(result, i, 2)); + /* column list (if any) */ + if (!PQgetisnull(result, i, 2)) + appendPQExpBuffer(&buf, " (%s)", + PQgetvalue(result, i, 2)); - /* row filter (if any) */ - if (!PQgetisnull(result, i, 1)) - appendPQExpBuffer(&buf, " WHERE %s", - PQgetvalue(result, i, 1)); + /* row filter (if any) */ + if (!PQgetisnull(result, i, 1)) + appendPQExpBuffer(&buf, " WHERE %s", + PQgetvalue(result, i, 1)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* Print publications where the table is in the EXCEPT clause */ if (pset.sversion >= 190000) @@ -3805,7 +3804,7 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) ncols++; } appendPQExpBufferStr(&buf, "\n, r.rolreplication"); - appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); + appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_roles r\n"); @@ -3860,8 +3859,8 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) if (strcmp(PQgetvalue(res, i, (verbose ? 9 : 8)), "t") == 0) add_role_attribute(&buf, _("Replication")); - if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) - add_role_attribute(&buf, _("Bypass RLS")); + if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) + add_role_attribute(&buf, _("Bypass RLS")); conns = atoi(PQgetvalue(res, i, 6)); if (conns >= 0) @@ -5155,14 +5154,14 @@ listCollations(const char *pattern, bool verbose, bool showSystem) gettext_noop("Schema"), gettext_noop("Name")); - appendPQExpBuffer(&buf, - " CASE c.collprovider " - "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " - "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " - "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " - "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " - "END AS \"%s\",\n", - gettext_noop("Provider")); + appendPQExpBuffer(&buf, + " CASE c.collprovider " + "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " + "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " + "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " + "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " + "END AS \"%s\",\n", + gettext_noop("Provider")); appendPQExpBuffer(&buf, " c.collcollate AS \"%s\",\n" -- 2.50.1 (Apple Git-155) --aHl3HfeiUuO3zeNC-- ^ permalink raw reply [nested|flat] 59+ messages in thread
* [PATCH v6 4/4] run pgindent and pgperltidy @ 2026-06-30 18:24 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 59+ messages in thread From: Nathan Bossart @ 2026-06-30 18:24 UTC (permalink / raw) --- src/bin/pg_dump/pg_dump.c | 464 ++++++++++----------- src/bin/pg_dump/pg_dumpall.c | 30 +- src/bin/pg_upgrade/check.c | 16 +- src/bin/pg_upgrade/controldata.c | 2 +- src/bin/pg_upgrade/exec.c | 8 +- src/bin/pg_upgrade/multixact_rewrite.c | 80 ++-- src/bin/pg_upgrade/pg_upgrade.c | 34 +- src/bin/pg_upgrade/relfilenumber.c | 54 +-- src/bin/pg_upgrade/t/006_transfer_modes.pl | 33 +- src/bin/psql/command.c | 29 +- src/bin/psql/describe.c | 461 ++++++++++---------- 11 files changed, 601 insertions(+), 610 deletions(-) diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 65bd15ebfd2..5673268b467 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -1491,8 +1491,8 @@ setup_connection(Archive *AH, const char *dumpencoding, * Disable timeouts if supported. */ ExecuteSqlStatement(AH, "SET statement_timeout = 0"); - ExecuteSqlStatement(AH, "SET lock_timeout = 0"); - ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); + ExecuteSqlStatement(AH, "SET lock_timeout = 0"); + ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); if (AH->remoteVersion >= 170000) ExecuteSqlStatement(AH, "SET transaction_timeout = 0"); @@ -1505,10 +1505,10 @@ setup_connection(Archive *AH, const char *dumpencoding, /* * Adjust row-security mode, if supported. */ - if (dopt->enable_row_security) - ExecuteSqlStatement(AH, "SET row_security = on"); - else - ExecuteSqlStatement(AH, "SET row_security = off"); + if (dopt->enable_row_security) + ExecuteSqlStatement(AH, "SET row_security = on"); + else + ExecuteSqlStatement(AH, "SET row_security = off"); /* * For security reasons, we restrict the expansion of non-system views and @@ -1933,10 +1933,9 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) addObjectDependency(dobj, ext->dobj.dumpId); /* - * Mark the member object to have any non-initial ACLs - * dumped. (Any initial ACLs will be removed later, using data from - * pg_init_privs, so that we'll dump only the delta from the extension's - * initial setup.) + * Mark the member object to have any non-initial ACLs dumped. (Any + * initial ACLs will be removed later, using data from pg_init_privs, so + * that we'll dump only the delta from the extension's initial setup.) * * In binary upgrades, we still dump all components of the members * individually, since the idea is to exactly reproduce the database @@ -1953,7 +1952,7 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) if (fout->dopt->binary_upgrade) dobj->dump = ext->dobj.dump; else - dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); + dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); return true; } @@ -1987,9 +1986,9 @@ selectDumpableNamespace(NamespaceInfo *nsinfo, Archive *fout) else if (strcmp(nsinfo->dobj.name, "pg_catalog") == 0) { /* - * We dump out any ACLs defined in pg_catalog, if - * they are interesting (and not the original ACLs which were set at - * initdb time, see pg_init_privs). + * We dump out any ACLs defined in pg_catalog, if they are interesting + * (and not the original ACLs which were set at initdb time, see + * pg_init_privs). */ nsinfo->dobj.dump_contains = nsinfo->dobj.dump = DUMP_COMPONENT_ACL; } @@ -3296,7 +3295,7 @@ dumpDatabase(Archive *fout) "datcollate, datctype, datfrozenxid, " "datacl, acldefault('d', datdba) AS acldefault, " "datistemplate, datconnlimit, "); - appendPQExpBufferStr(dbQry, "datminmxid, "); + appendPQExpBufferStr(dbQry, "datminmxid, "); if (fout->remoteVersion >= 170000) appendPQExpBufferStr(dbQry, "datlocprovider, datlocale, datcollversion, "); else if (fout->remoteVersion >= 150000) @@ -3638,11 +3637,11 @@ dumpDatabase(Archive *fout) ii_oid, ii_relminmxid; - appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" - "FROM pg_catalog.pg_class\n" - "WHERE oid IN (%u, %u, %u, %u);\n", - LargeObjectRelationId, LargeObjectLOidPNIndexId, - LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); + appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" + "FROM pg_catalog.pg_class\n" + "WHERE oid IN (%u, %u, %u, %u);\n", + LargeObjectRelationId, LargeObjectLOidPNIndexId, + LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); lo_res = ExecuteSqlQuery(fout, loFrozenQry->data, PGRES_TUPLES_OK); @@ -4274,7 +4273,7 @@ getPolicies(Archive *fout, TableInfo tblinfo[], int numTables) printfPQExpBuffer(query, "SELECT pol.oid, pol.tableoid, pol.polrelid, pol.polname, pol.polcmd, "); - appendPQExpBufferStr(query, "pol.polpermissive, "); + appendPQExpBufferStr(query, "pol.polpermissive, "); appendPQExpBuffer(query, "CASE WHEN pol.polroles = '{0}' THEN NULL ELSE " " pg_catalog.array_to_string(ARRAY(SELECT pg_catalog.quote_ident(rolname) from pg_catalog.pg_roles WHERE oid = ANY(pol.polroles)), ', ') END AS polroles, " @@ -6633,9 +6632,9 @@ getAccessMethods(Archive *fout) * Select all access methods from pg_am table. */ appendPQExpBufferStr(query, "SELECT tableoid, oid, amname, "); - appendPQExpBufferStr(query, - "amtype, " - "amhandler::pg_catalog.regproc AS amhandler "); + appendPQExpBufferStr(query, + "amtype, " + "amhandler::pg_catalog.regproc AS amhandler "); appendPQExpBufferStr(query, "FROM pg_am"); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6827,35 +6826,35 @@ getAggregates(Archive *fout) * Find all interesting aggregates. See comment in getFuncs() for the * rationale behind the filtering logic. */ - agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" - : "p.proisagg"); + agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" + : "p.proisagg"); - appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " - "p.proname AS aggname, " - "p.pronamespace AS aggnamespace, " - "p.pronargs, p.proargtypes, " - "p.proowner, " - "p.proacl AS aggacl, " - "acldefault('f', p.proowner) AS acldefault " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s AND (" - "p.pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog') OR " - "p.proacl IS DISTINCT FROM pip.initprivs", - agg_check); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - " OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); - appendPQExpBufferChar(query, ')'); + appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " + "p.proname AS aggname, " + "p.pronamespace AS aggnamespace, " + "p.pronargs, p.proargtypes, " + "p.proowner, " + "p.proacl AS aggacl, " + "acldefault('f', p.proowner) AS acldefault " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s AND (" + "p.pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog') OR " + "p.proacl IS DISTINCT FROM pip.initprivs", + agg_check); + if (dopt->binary_upgrade) + appendPQExpBufferStr(query, + " OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6957,53 +6956,53 @@ getFuncs(Archive *fout) * include them, since we want to dump extension members individually in * that mode. Also, if they are used by casts or transforms then we need * to gather the information about them, though they won't be dumped if - * they are built-in. Also, include functions in - * pg_catalog if they have an ACL different from what's shown in - * pg_init_privs (so we have to join to pg_init_privs; annoying). + * they are built-in. Also, include functions in pg_catalog if they have + * an ACL different from what's shown in pg_init_privs (so we have to join + * to pg_init_privs; annoying). */ - not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" - : "NOT p.proisagg"); + not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" + : "NOT p.proisagg"); - appendPQExpBuffer(query, - "SELECT p.tableoid, p.oid, p.proname, p.prolang, " - "p.pronargs, p.proargtypes, p.prorettype, " - "p.proacl, " - "acldefault('f', p.proowner) AS acldefault, " - "p.pronamespace, " - "p.proowner " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s" - "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " - "WHERE classid = 'pg_proc'::regclass AND " - "objid = p.oid AND deptype = 'i')" - "\n AND (" - "\n pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog')" - "\n OR EXISTS (SELECT 1 FROM pg_cast" - "\n WHERE pg_cast.oid > %u " - "\n AND p.oid = pg_cast.castfunc)" - "\n OR EXISTS (SELECT 1 FROM pg_transform" - "\n WHERE pg_transform.oid > %u AND " - "\n (p.oid = pg_transform.trffromsql" - "\n OR p.oid = pg_transform.trftosql))", - not_agg_check, - g_last_builtin_oid, - g_last_builtin_oid); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); + appendPQExpBuffer(query, + "SELECT p.tableoid, p.oid, p.proname, p.prolang, " + "p.pronargs, p.proargtypes, p.prorettype, " + "p.proacl, " + "acldefault('f', p.proowner) AS acldefault, " + "p.pronamespace, " + "p.proowner " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s" + "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " + "WHERE classid = 'pg_proc'::regclass AND " + "objid = p.oid AND deptype = 'i')" + "\n AND (" + "\n pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog')" + "\n OR EXISTS (SELECT 1 FROM pg_cast" + "\n WHERE pg_cast.oid > %u " + "\n AND p.oid = pg_cast.castfunc)" + "\n OR EXISTS (SELECT 1 FROM pg_transform" + "\n WHERE pg_transform.oid > %u AND " + "\n (p.oid = pg_transform.trffromsql" + "\n OR p.oid = pg_transform.trftosql))", + not_agg_check, + g_last_builtin_oid, + g_last_builtin_oid); + if (dopt->binary_upgrade) appendPQExpBufferStr(query, - "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); - appendPQExpBufferChar(query, ')'); + "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferStr(query, + "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -7252,31 +7251,31 @@ getTables(Archive *fout, int *numTables) appendPQExpBufferStr(query, "c.relhasoids, "); - appendPQExpBufferStr(query, - "c.relispopulated, "); + appendPQExpBufferStr(query, + "c.relispopulated, "); - appendPQExpBufferStr(query, - "c.relreplident, "); + appendPQExpBufferStr(query, + "c.relreplident, "); - appendPQExpBufferStr(query, - "c.relrowsecurity, c.relforcerowsecurity, "); + appendPQExpBufferStr(query, + "c.relrowsecurity, c.relforcerowsecurity, "); - appendPQExpBufferStr(query, - "c.relminmxid, tc.relminmxid AS tminmxid, "); + appendPQExpBufferStr(query, + "c.relminmxid, tc.relminmxid AS tminmxid, "); - appendPQExpBufferStr(query, - "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); + appendPQExpBufferStr(query, + "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); - appendPQExpBufferStr(query, - "am.amname, "); + appendPQExpBufferStr(query, + "am.amname, "); - appendPQExpBufferStr(query, - "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); + appendPQExpBufferStr(query, + "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); - appendPQExpBufferStr(query, - "c.relispartition AS ispartition "); + appendPQExpBufferStr(query, + "c.relispartition AS ispartition "); /* * Left join to pg_depend to pick up dependency info linking sequences to @@ -7296,8 +7295,8 @@ getTables(Archive *fout, int *numTables) /* * Left join to pg_am to pick up the amname. */ - appendPQExpBufferStr(query, - "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); + appendPQExpBufferStr(query, + "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); /* * We purposefully ignore toast OIDs for partitioned tables; the reason is @@ -7868,8 +7867,8 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables) "t.reloptions AS indreloptions, "); - appendPQExpBufferStr(query, - "i.indisreplident, "); + appendPQExpBufferStr(query, + "i.indisreplident, "); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -9313,8 +9312,8 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables) appendPQExpBufferStr(q, "'' AS attcompression,\n"); - appendPQExpBufferStr(q, - "a.attidentity,\n"); + appendPQExpBufferStr(q, + "a.attidentity,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(q, @@ -10717,73 +10716,73 @@ getAdditionalACLs(Archive *fout) PQclear(res); /* Fetch initial-privileges data */ - printfPQExpBuffer(query, - "SELECT objoid, classoid, objsubid, privtype, initprivs " - "FROM pg_init_privs"); + printfPQExpBuffer(query, + "SELECT objoid, classoid, objsubid, privtype, initprivs " + "FROM pg_init_privs"); - res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); + res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); - ntups = PQntuples(res); - for (i = 0; i < ntups; i++) - { - Oid objoid = atooid(PQgetvalue(res, i, 0)); - Oid classoid = atooid(PQgetvalue(res, i, 1)); - int objsubid = atoi(PQgetvalue(res, i, 2)); - char privtype = *(PQgetvalue(res, i, 3)); - char *initprivs = PQgetvalue(res, i, 4); - CatalogId objId; - DumpableObject *dobj; + ntups = PQntuples(res); + for (i = 0; i < ntups; i++) + { + Oid objoid = atooid(PQgetvalue(res, i, 0)); + Oid classoid = atooid(PQgetvalue(res, i, 1)); + int objsubid = atoi(PQgetvalue(res, i, 2)); + char privtype = *(PQgetvalue(res, i, 3)); + char *initprivs = PQgetvalue(res, i, 4); + CatalogId objId; + DumpableObject *dobj; - objId.tableoid = classoid; - objId.oid = objoid; - dobj = findObjectByCatalogId(objId); - /* OK to ignore entries we haven't got a DumpableObject for */ - if (dobj) + objId.tableoid = classoid; + objId.oid = objoid; + dobj = findObjectByCatalogId(objId); + /* OK to ignore entries we haven't got a DumpableObject for */ + if (dobj) + { + /* Cope with sub-object initprivs */ + if (objsubid != 0) { - /* Cope with sub-object initprivs */ - if (objsubid != 0) - { - if (dobj->objType == DO_TABLE) - { - /* For a column initprivs, set the table's ACL flags */ - dobj->components |= DUMP_COMPONENT_ACL; - ((TableInfo *) dobj)->hascolumnACLs = true; - } - else - pg_log_warning("unsupported pg_init_privs entry: %u %u %d", - classoid, objoid, objsubid); - continue; - } - - /* - * We ignore any pg_init_privs.initprivs entry for the public - * schema, as explained in getNamespaces(). - */ - if (dobj->objType == DO_NAMESPACE && - strcmp(dobj->name, "public") == 0) - continue; - - /* Else it had better be of a type we think has ACLs */ - if (dobj->objType == DO_NAMESPACE || - dobj->objType == DO_TYPE || - dobj->objType == DO_FUNC || - dobj->objType == DO_AGG || - dobj->objType == DO_TABLE || - dobj->objType == DO_PROCLANG || - dobj->objType == DO_FDW || - dobj->objType == DO_FOREIGN_SERVER) + if (dobj->objType == DO_TABLE) { - DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; - - daobj->dacl.privtype = privtype; - daobj->dacl.initprivs = pstrdup(initprivs); + /* For a column initprivs, set the table's ACL flags */ + dobj->components |= DUMP_COMPONENT_ACL; + ((TableInfo *) dobj)->hascolumnACLs = true; } else pg_log_warning("unsupported pg_init_privs entry: %u %u %d", classoid, objoid, objsubid); + continue; + } + + /* + * We ignore any pg_init_privs.initprivs entry for the public + * schema, as explained in getNamespaces(). + */ + if (dobj->objType == DO_NAMESPACE && + strcmp(dobj->name, "public") == 0) + continue; + + /* Else it had better be of a type we think has ACLs */ + if (dobj->objType == DO_NAMESPACE || + dobj->objType == DO_TYPE || + dobj->objType == DO_FUNC || + dobj->objType == DO_AGG || + dobj->objType == DO_TABLE || + dobj->objType == DO_PROCLANG || + dobj->objType == DO_FDW || + dobj->objType == DO_FOREIGN_SERVER) + { + DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; + + daobj->dacl.privtype = privtype; + daobj->dacl.initprivs = pstrdup(initprivs); } + else + pg_log_warning("unsupported pg_init_privs entry: %u %u %d", + classoid, objoid, objsubid); } - PQclear(res); + } + PQclear(res); destroyPQExpBuffer(query); } @@ -11128,8 +11127,8 @@ dumpRelationStats_dumper(Archive *fout, const void *userArg, const TocEntry *te) * The results must be in the order of the relations supplied in the * parameters to ensure we remain in sync as we walk through the TOC. * - * For versions before 19, the redundant filter clause on s.tablename = - * ANY(...) seems sufficient to convince the planner to use + * For versions before 19, the redundant filter clause on s.tablename + * = ANY(...) seems sufficient to convince the planner to use * pg_class_relname_nsp_index, which avoids a full scan of pg_stats. * In newer versions, pg_stats returns the table OIDs, eliminating the * need for that hack. @@ -13469,11 +13468,11 @@ dumpFunc(Archive *fout, const FuncInfo *finfo) "pg_catalog.pg_get_function_result(p.oid) AS funcresult,\n" "proleakproof,\n"); - appendPQExpBufferStr(query, - "array_to_string(protrftypes, ' ') AS protrftypes,\n"); + appendPQExpBufferStr(query, + "array_to_string(protrftypes, ' ') AS protrftypes,\n"); - appendPQExpBufferStr(query, - "proparallel,\n"); + appendPQExpBufferStr(query, + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -14963,9 +14962,9 @@ dumpCollation(Archive *fout, const CollInfo *collinfo) /* Get collation-specific details */ appendPQExpBufferStr(query, "SELECT "); - appendPQExpBufferStr(query, - "collprovider, " - "collversion, "); + appendPQExpBufferStr(query, + "collprovider, " + "collversion, "); if (fout->remoteVersion >= 120000) appendPQExpBufferStr(query, @@ -15372,23 +15371,23 @@ dumpAgg(Archive *fout, const AggInfo *agginfo) "pg_catalog.pg_get_function_arguments(p.oid) AS funcargs,\n" "pg_catalog.pg_get_function_identity_arguments(p.oid) AS funciargs,\n"); - appendPQExpBufferStr(query, - "aggkind,\n" - "aggmtransfn,\n" - "aggminvtransfn,\n" - "aggmfinalfn,\n" - "aggmtranstype::pg_catalog.regtype,\n" - "aggfinalextra,\n" - "aggmfinalextra,\n" - "aggtransspace,\n" - "aggmtransspace,\n" - "aggminitval,\n"); + appendPQExpBufferStr(query, + "aggkind,\n" + "aggmtransfn,\n" + "aggminvtransfn,\n" + "aggmfinalfn,\n" + "aggmtranstype::pg_catalog.regtype,\n" + "aggfinalextra,\n" + "aggmfinalextra,\n" + "aggtransspace,\n" + "aggmtransspace,\n" + "aggminitval,\n"); - appendPQExpBufferStr(query, - "aggcombinefn,\n" - "aggserialfn,\n" - "aggdeserialfn,\n" - "proparallel,\n"); + appendPQExpBufferStr(query, + "aggcombinefn,\n" + "aggserialfn,\n" + "aggdeserialfn,\n" + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -16848,30 +16847,30 @@ dumpTable(Archive *fout, const TableInfo *tbinfo) appendPQExpBufferStr(query, "PREPARE getColumnACLs(pg_catalog.oid) AS\n"); - /* - * In principle we should call acldefault('c', relowner) to - * get the default ACL for a column. However, we don't - * currently store the numeric OID of the relowner in - * TableInfo. We could convert the owner name using regrole, - * but that creates a risk of failure due to concurrent role - * renames. Given that the default ACL for columns is empty - * and is likely to stay that way, it's not worth extra cycles - * and risk to avoid hard-wiring that knowledge here. - */ - appendPQExpBufferStr(query, - "SELECT at.attname, " - "at.attacl, " - "'{}' AS acldefault, " - "pip.privtype, pip.initprivs " - "FROM pg_catalog.pg_attribute at " - "LEFT JOIN pg_catalog.pg_init_privs pip ON " - "(at.attrelid = pip.objoid " - "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " - "AND at.attnum = pip.objsubid) " - "WHERE at.attrelid = $1 AND " - "NOT at.attisdropped " - "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " - "ORDER BY at.attnum"); + /* + * In principle we should call acldefault('c', relowner) to get + * the default ACL for a column. However, we don't currently + * store the numeric OID of the relowner in TableInfo. We could + * convert the owner name using regrole, but that creates a risk + * of failure due to concurrent role renames. Given that the + * default ACL for columns is empty and is likely to stay that + * way, it's not worth extra cycles and risk to avoid hard-wiring + * that knowledge here. + */ + appendPQExpBufferStr(query, + "SELECT at.attname, " + "at.attacl, " + "'{}' AS acldefault, " + "pip.privtype, pip.initprivs " + "FROM pg_catalog.pg_attribute at " + "LEFT JOIN pg_catalog.pg_init_privs pip ON " + "(at.attrelid = pip.objoid " + "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " + "AND at.attnum = pip.objsubid) " + "WHERE at.attrelid = $1 AND " + "NOT at.attisdropped " + "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " + "ORDER BY at.attnum"); ExecuteSqlStatement(fout, query->data); @@ -19165,7 +19164,7 @@ collectSequences(Archive *fout) * pg_get_sequence_data(), but we only do so for non-schema-only dumps. */ if (fout->remoteVersion < 180000 || - (!fout->dopt->dumpData && !fout->dopt->sequence_data)) + (!fout->dopt->dumpData && !fout->dopt->sequence_data)) query = "SELECT seqrelid, format_type(seqtypid, NULL), " "seqstart, seqincrement, " "seqmax, seqmin, " @@ -19227,15 +19226,14 @@ dumpSequence(Archive *fout, const TableInfo *tbinfo) qseqname = pg_strdup(fmtId(tbinfo->dobj.name)); /* - * The sequence information is gathered in a sorted - * table before any calls to dumpSequence(). See collectSequences() for - * more information. + * The sequence information is gathered in a sorted table before any calls + * to dumpSequence(). See collectSequences() for more information. */ - Assert(sequences); + Assert(sequences); - key.oid = tbinfo->dobj.catId.oid; - seq = bsearch(&key, sequences, nsequences, - sizeof(SequenceItem), SequenceItemCmp); + key.oid = tbinfo->dobj.catId.oid; + seq = bsearch(&key, sequences, nsequences, + sizeof(SequenceItem), SequenceItemCmp); /* Calculate default limits for a sequence of this type */ is_ascending = (seq->incby >= 0); diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c index e68937c9934..afcd9a218d8 100644 --- a/src/bin/pg_dump/pg_dumpall.c +++ b/src/bin/pg_dump/pg_dumpall.c @@ -785,11 +785,11 @@ dropRoles(PGconn *conn) int i_rolname; int i; - printfPQExpBuffer(buf, - "SELECT rolname " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 1", role_catalog); + printfPQExpBuffer(buf, + "SELECT rolname " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 1", role_catalog); res = executeQuery(conn, buf->data); @@ -843,16 +843,16 @@ dumpRoles(PGconn *conn) * Notes: rolconfig is dumped later, and pg_authid must be used for * extracting rolcomment regardless of role_catalog. */ - printfPQExpBuffer(buf, - "SELECT oid, rolname, rolsuper, rolinherit, " - "rolcreaterole, rolcreatedb, " - "rolcanlogin, rolconnlimit, rolpassword, " - "rolvaliduntil, rolreplication, rolbypassrls, " - "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " - "rolname = current_user AS is_current_user " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 2", role_catalog); + printfPQExpBuffer(buf, + "SELECT oid, rolname, rolsuper, rolinherit, " + "rolcreaterole, rolcreatedb, " + "rolcanlogin, rolconnlimit, rolpassword, " + "rolvaliduntil, rolreplication, rolbypassrls, " + "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " + "rolname = current_user AS is_current_user " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 2", role_catalog); res = executeQuery(conn, buf->data); diff --git a/src/bin/pg_upgrade/check.c b/src/bin/pg_upgrade/check.c index 786c1474829..f725f5ee3e2 100644 --- a/src/bin/pg_upgrade/check.c +++ b/src/bin/pg_upgrade/check.c @@ -1475,15 +1475,15 @@ check_for_incompatible_polymorphics(ClusterInfo *cluster) ", 'array_cat(anyarray,anyarray)'" ", 'array_prepend(anyelement,anyarray)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_remove(anyarray,anyelement)'" - ", 'array_replace(anyarray,anyelement,anyelement)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_remove(anyarray,anyelement)'" + ", 'array_replace(anyarray,anyelement,anyelement)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_position(anyarray,anyelement)'" - ", 'array_position(anyarray,anyelement,integer)'" - ", 'array_positions(anyarray,anyelement)'" - ", 'width_bucket(anyelement,anyarray)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_position(anyarray,anyelement)'" + ", 'array_position(anyarray,anyelement,integer)'" + ", 'array_positions(anyarray,anyelement)'" + ", 'width_bucket(anyelement,anyarray)'"); /* * The query below hardcodes FirstNormalObjectId as 16384 rather than diff --git a/src/bin/pg_upgrade/controldata.c b/src/bin/pg_upgrade/controldata.c index 8f81c9e9582..02ea02df60f 100644 --- a/src/bin/pg_upgrade/controldata.c +++ b/src/bin/pg_upgrade/controldata.c @@ -228,7 +228,7 @@ get_control_data(ClusterInfo *cluster) p++; /* remove ':' char */ cluster->controldata.chkpnt_nxtepoch = str2uint(p); - p = strchr(p, ':'); + p = strchr(p, ':'); if (p == NULL || strlen(p) <= 1) pg_fatal("%d: controldata retrieval problem", __LINE__); diff --git a/src/bin/pg_upgrade/exec.c b/src/bin/pg_upgrade/exec.c index 44355feea30..a1bdbf373e3 100644 --- a/src/bin/pg_upgrade/exec.c +++ b/src/bin/pg_upgrade/exec.c @@ -55,7 +55,7 @@ get_bin_version(ClusterInfo *cluster) if (sscanf(cmd_output, "%*s %*s %d.%d", &v1, &v2) < 1) pg_fatal("could not get pg_ctl version output from %s", cmd); - cluster->bin_version = v1 * 10000; + cluster->bin_version = v1 * 10000; } @@ -344,8 +344,8 @@ check_data_dir(ClusterInfo *cluster) check_single_dir(pg_data, "pg_subtrans"); check_single_dir(pg_data, PG_TBLSPC_DIR); check_single_dir(pg_data, "pg_twophase"); - check_single_dir(pg_data, "pg_wal"); - check_single_dir(pg_data, "pg_xact"); + check_single_dir(pg_data, "pg_wal"); + check_single_dir(pg_data, "pg_xact"); } @@ -385,7 +385,7 @@ check_bin_dir(ClusterInfo *cluster, bool check_versions) */ get_bin_version(cluster); - check_exec(cluster->bindir, "pg_resetwal", check_versions); + check_exec(cluster->bindir, "pg_resetwal", check_versions); if (cluster == &new_cluster) { diff --git a/src/bin/pg_upgrade/multixact_rewrite.c b/src/bin/pg_upgrade/multixact_rewrite.c index c45b3183684..c7a1416494d 100644 --- a/src/bin/pg_upgrade/multixact_rewrite.c +++ b/src/bin/pg_upgrade/multixact_rewrite.c @@ -61,52 +61,52 @@ rewrite_multixacts(MultiXactId from_multi, MultiXactId to_multi) * Convert old multixids, if needed, by reading them one-by-one from the * old cluster. */ - old_reader = AllocOldMultiXactRead(old_cluster.pgdata, - old_cluster.controldata.chkpnt_nxtmulti, - old_cluster.controldata.chkpnt_nxtmxoff); + old_reader = AllocOldMultiXactRead(old_cluster.pgdata, + old_cluster.controldata.chkpnt_nxtmulti, + old_cluster.controldata.chkpnt_nxtmxoff); - for (MultiXactId multi = from_multi; multi != to_multi;) - { - MultiXactMember member; - bool multixid_valid; - - /* - * Read this multixid's members. - * - * Locking-only XIDs that may be part of multi-xids don't matter - * after upgrade, as there can be no transactions running across - * upgrade. So as a small optimization, we only read one member - * from each multixid: the one updating one, or if there was no - * update, arbitrarily the first locking xid. - */ - multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); + for (MultiXactId multi = from_multi; multi != to_multi;) + { + MultiXactMember member; + bool multixid_valid; - /* - * Write the new offset to pg_multixact/offsets. - * - * Even if this multixid is invalid, we still need to write its - * offset if the *previous* multixid was valid. That's because - * when reading a multixid, the number of members is calculated - * from the difference between the two offsets. - */ - RecordMultiXactOffset(offsets_writer, multi, - (multixid_valid || prev_multixid_valid) ? next_offset : 0); + /* + * Read this multixid's members. + * + * Locking-only XIDs that may be part of multi-xids don't matter after + * upgrade, as there can be no transactions running across upgrade. So + * as a small optimization, we only read one member from each + * multixid: the one updating one, or if there was no update, + * arbitrarily the first locking xid. + */ + multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); - /* Write the members */ - if (multixid_valid) - { - RecordMultiXactMembers(members_writer, next_offset, 1, &member); - next_offset += 1; - } + /* + * Write the new offset to pg_multixact/offsets. + * + * Even if this multixid is invalid, we still need to write its offset + * if the *previous* multixid was valid. That's because when reading + * a multixid, the number of members is calculated from the difference + * between the two offsets. + */ + RecordMultiXactOffset(offsets_writer, multi, + (multixid_valid || prev_multixid_valid) ? next_offset : 0); - /* Advance to next multixid, handling wraparound */ - multi++; - if (multi < FirstMultiXactId) - multi = FirstMultiXactId; - prev_multixid_valid = multixid_valid; + /* Write the members */ + if (multixid_valid) + { + RecordMultiXactMembers(members_writer, next_offset, 1, &member); + next_offset += 1; } - FreeOldMultiXactReader(old_reader); + /* Advance to next multixid, handling wraparound */ + multi++; + if (multi < FirstMultiXactId) + multi = FirstMultiXactId; + prev_multixid_valid = multixid_valid; + } + + FreeOldMultiXactReader(old_reader); /* Write the final 'next' offset to the last SLRU page */ RecordMultiXactOffset(offsets_writer, to_multi, diff --git a/src/bin/pg_upgrade/pg_upgrade.c b/src/bin/pg_upgrade/pg_upgrade.c index c6af9035665..7366fd4627c 100644 --- a/src/bin/pg_upgrade/pg_upgrade.c +++ b/src/bin/pg_upgrade/pg_upgrade.c @@ -833,7 +833,7 @@ copy_xact_xlog_xid(void) * Determine the range of multixacts to convert. */ nxtmulti = old_cluster.controldata.chkpnt_nxtmulti; - oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; + oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; /* handle wraparound */ if (nxtmulti < FirstMultiXactId) nxtmulti = FirstMultiXactId; @@ -898,15 +898,15 @@ set_frozenxids(void) int i_datname; int i_datallowconn; - prep_status("Setting frozenxid and minmxid counters in new cluster"); + prep_status("Setting frozenxid and minmxid counters in new cluster"); conn_template1 = connectToServer(&new_cluster, "template1"); - /* set pg_database.datfrozenxid */ - PQclear(executeQueryOrDie(conn_template1, - "UPDATE pg_catalog.pg_database " - "SET datfrozenxid = '%u'", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_database.datfrozenxid */ + PQclear(executeQueryOrDie(conn_template1, + "UPDATE pg_catalog.pg_database " + "SET datfrozenxid = '%u'", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_database.datminmxid */ PQclear(executeQueryOrDie(conn_template1, @@ -942,16 +942,16 @@ set_frozenxids(void) conn = connectToServer(&new_cluster, datname); - /* set pg_class.relfrozenxid */ - PQclear(executeQueryOrDie(conn, - "UPDATE pg_catalog.pg_class " - "SET relfrozenxid = '%u' " - /* only heap, materialized view, and TOAST are vacuumed */ - "WHERE relkind IN (" - CppAsString2(RELKIND_RELATION) ", " - CppAsString2(RELKIND_MATVIEW) ", " - CppAsString2(RELKIND_TOASTVALUE) ")", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_class.relfrozenxid */ + PQclear(executeQueryOrDie(conn, + "UPDATE pg_catalog.pg_class " + "SET relfrozenxid = '%u' " + /* only heap, materialized view, and TOAST are vacuumed */ + "WHERE relkind IN (" + CppAsString2(RELKIND_RELATION) ", " + CppAsString2(RELKIND_MATVIEW) ", " + CppAsString2(RELKIND_TOASTVALUE) ")", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_class.relminmxid */ PQclear(executeQueryOrDie(conn, diff --git a/src/bin/pg_upgrade/relfilenumber.c b/src/bin/pg_upgrade/relfilenumber.c index ec2ff7acb21..6c467bdc8a5 100644 --- a/src/bin/pg_upgrade/relfilenumber.c +++ b/src/bin/pg_upgrade/relfilenumber.c @@ -587,32 +587,32 @@ transfer_relfile(FileNameMap *map, const char *type_suffix) /* Copying files might take some time, so give feedback. */ pg_log(PG_STATUS, "%s", old_file); - switch (user_opts.transfer_mode) - { - case TRANSFER_MODE_CLONE: - pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", - old_file, new_file); - cloneFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", - old_file, new_file); - copyFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY_FILE_RANGE: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", - old_file, new_file); - copyFileByRange(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_LINK: - pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", - old_file, new_file); - linkFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_SWAP: - /* swap mode is handled in its own code path */ - pg_fatal("should never happen"); - break; - } + switch (user_opts.transfer_mode) + { + case TRANSFER_MODE_CLONE: + pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", + old_file, new_file); + cloneFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", + old_file, new_file); + copyFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY_FILE_RANGE: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", + old_file, new_file); + copyFileByRange(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_LINK: + pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", + old_file, new_file); + linkFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_SWAP: + /* swap mode is handled in its own code path */ + pg_fatal("should never happen"); + break; + } } } diff --git a/src/bin/pg_upgrade/t/006_transfer_modes.pl b/src/bin/pg_upgrade/t/006_transfer_modes.pl index 9efa5dc863c..360d05c4b68 100644 --- a/src/bin/pg_upgrade/t/006_transfer_modes.pl +++ b/src/bin/pg_upgrade/t/006_transfer_modes.pl @@ -29,10 +29,8 @@ sub test_mode } $new->init(); - $new->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); - $old->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); + $new->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); + $old->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); # We can only test security labels if both the old and new installations # have dummy_seclabel. @@ -76,15 +74,14 @@ sub test_mode "CREATE TABLE test4 AS SELECT generate_series(400, 502)"); } - $old->safe_psql('postgres', - "CREATE TABLESPACE inplc_tblspc LOCATION ''"); - $old->safe_psql('postgres', - "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); - $old->safe_psql('postgres', - "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" - ); - $old->safe_psql('testdb3', - "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); + $old->safe_psql('postgres', "CREATE TABLESPACE inplc_tblspc LOCATION ''"); + $old->safe_psql('postgres', + "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); + $old->safe_psql('postgres', + "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" + ); + $old->safe_psql('testdb3', + "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); # While we are here, test handling of large objects. $old->safe_psql( @@ -152,12 +149,10 @@ sub test_mode } # Tests for in-place tablespaces. - $result = - $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); - is($result, '104', "test5 data after pg_upgrade $mode"); - $result = - $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); - is($result, '105', "test6 data after pg_upgrade $mode"); + $result = $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); + is($result, '104', "test5 data after pg_upgrade $mode"); + $result = $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); + is($result, '105', "test6 data after pg_upgrade $mode"); # Tests for large objects $result = $new->safe_psql('postgres', "SELECT lo_get(4532)"); diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index 44ef11d980e..c90bf8bbde2 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -6278,23 +6278,22 @@ get_create_object_cmd(EditableObjectType obj_type, Oid oid, * ensure the right view gets replaced. Also, check relation kind * to be sure it's a view. * - * Views may have WITH [LOCAL|CASCADED] - * CHECK OPTION. These are not part of the view definition - * returned by pg_get_viewdef() and so need to be retrieved - * separately. Materialized views may have - * arbitrary storage parameter reloptions. + * Views may have WITH [LOCAL|CASCADED] CHECK OPTION. These are + * not part of the view definition returned by pg_get_viewdef() + * and so need to be retrieved separately. Materialized views may + * have arbitrary storage parameter reloptions. */ printfPQExpBuffer(query, "/* %s */\n", _("Get view's definition and details")); - appendPQExpBuffer(query, - "SELECT nspname, relname, relkind, " - "pg_catalog.pg_get_viewdef(c.oid, true), " - "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " - "FROM pg_catalog.pg_class c " - "LEFT JOIN pg_catalog.pg_namespace n " - "ON c.relnamespace = n.oid WHERE c.oid = %u", - oid); + appendPQExpBuffer(query, + "SELECT nspname, relname, relkind, " + "pg_catalog.pg_get_viewdef(c.oid, true), " + "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " + "FROM pg_catalog.pg_class c " + "LEFT JOIN pg_catalog.pg_namespace n " + "ON c.relnamespace = n.oid WHERE c.oid = %u", + oid); break; } diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index ce99137c613..ac0c55e7aa5 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -387,19 +387,19 @@ describeFunctions(const char *functypes, const char *func_pattern, gettext_noop("stable"), gettext_noop("volatile"), gettext_noop("Volatility")); - appendPQExpBuffer(&buf, - ",\n CASE\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" - " END as \"%s\"", - gettext_noop("restricted"), - gettext_noop("safe"), - gettext_noop("unsafe"), - gettext_noop("Parallel")); + appendPQExpBuffer(&buf, + ",\n CASE\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" + " END as \"%s\"", + gettext_noop("restricted"), + gettext_noop("safe"), + gettext_noop("unsafe"), + gettext_noop("Parallel")); appendPQExpBuffer(&buf, ",\n pg_catalog.pg_get_userbyid(p.proowner) as \"%s\"" ",\n CASE WHEN prosecdef THEN '%s' ELSE '%s' END AS \"%s\"" @@ -599,8 +599,8 @@ describeFunctions(const char *functypes, const char *func_pattern, myopt.title = _("List of functions"); myopt.translate_header = true; - myopt.translate_columns = translate_columns; - myopt.n_translate_columns = lengthof(translate_columns); + myopt.translate_columns = translate_columns; + myopt.n_translate_columns = lengthof(translate_columns); printQuery(res, &myopt, pset.queryFout, false, pset.logfile); @@ -1086,38 +1086,38 @@ permissionsList(const char *pattern, bool showSystem) " ), E'\\n') AS \"%s\"", gettext_noop("Column privileges")); - appendPQExpBuffer(&buf, - ",\n pg_catalog.array_to_string(ARRAY(\n" - " SELECT polname\n" - " || CASE WHEN NOT polpermissive THEN\n" - " E' (RESTRICTIVE)'\n" - " ELSE '' END\n" - " || CASE WHEN polcmd != '*' THEN\n" - " E' (' || polcmd::pg_catalog.text || E'):'\n" - " ELSE E':'\n" - " END\n" - " || CASE WHEN polqual IS NOT NULL THEN\n" - " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" - " ELSE E''\n" - " END\n" - " || CASE WHEN polwithcheck IS NOT NULL THEN\n" - " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" - " ELSE E''\n" - " END" - " || CASE WHEN polroles <> '{0}' THEN\n" - " E'\\n to: ' || pg_catalog.array_to_string(\n" - " ARRAY(\n" - " SELECT rolname\n" - " FROM pg_catalog.pg_roles\n" - " WHERE oid = ANY (polroles)\n" - " ORDER BY 1\n" - " ), E', ')\n" - " ELSE E''\n" - " END\n" - " FROM pg_catalog.pg_policy pol\n" - " WHERE polrelid = c.oid), E'\\n')\n" - " AS \"%s\"", - gettext_noop("Policies")); + appendPQExpBuffer(&buf, + ",\n pg_catalog.array_to_string(ARRAY(\n" + " SELECT polname\n" + " || CASE WHEN NOT polpermissive THEN\n" + " E' (RESTRICTIVE)'\n" + " ELSE '' END\n" + " || CASE WHEN polcmd != '*' THEN\n" + " E' (' || polcmd::pg_catalog.text || E'):'\n" + " ELSE E':'\n" + " END\n" + " || CASE WHEN polqual IS NOT NULL THEN\n" + " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" + " ELSE E''\n" + " END\n" + " || CASE WHEN polwithcheck IS NOT NULL THEN\n" + " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" + " ELSE E''\n" + " END" + " || CASE WHEN polroles <> '{0}' THEN\n" + " E'\\n to: ' || pg_catalog.array_to_string(\n" + " ARRAY(\n" + " SELECT rolname\n" + " FROM pg_catalog.pg_roles\n" + " WHERE oid = ANY (polroles)\n" + " ORDER BY 1\n" + " ), E', ')\n" + " ELSE E''\n" + " END\n" + " FROM pg_catalog.pg_policy pol\n" + " WHERE polrelid = c.oid), E'\\n')\n" + " AS \"%s\"", + gettext_noop("Policies")); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_class c\n" " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n" @@ -1675,27 +1675,27 @@ describeOneTableDetails(const char *schemaname, char *footers[3] = {NULL, NULL, NULL}; printfPQExpBuffer(&buf, "/* %s */\n", _("Get sequence information")); - appendPQExpBuffer(&buf, - "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" - " seqstart AS \"%s\",\n" - " seqmin AS \"%s\",\n" - " seqmax AS \"%s\",\n" - " seqincrement AS \"%s\",\n" - " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" - " seqcache AS \"%s\"\n", - gettext_noop("Type"), - gettext_noop("Start"), - gettext_noop("Minimum"), - gettext_noop("Maximum"), - gettext_noop("Increment"), - gettext_noop("yes"), - gettext_noop("no"), - gettext_noop("Cycles?"), - gettext_noop("Cache")); - appendPQExpBuffer(&buf, - "FROM pg_catalog.pg_sequence\n" - "WHERE seqrelid = '%s';", - oid); + appendPQExpBuffer(&buf, + "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" + " seqstart AS \"%s\",\n" + " seqmin AS \"%s\",\n" + " seqmax AS \"%s\",\n" + " seqincrement AS \"%s\",\n" + " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" + " seqcache AS \"%s\"\n", + gettext_noop("Type"), + gettext_noop("Start"), + gettext_noop("Minimum"), + gettext_noop("Maximum"), + gettext_noop("Increment"), + gettext_noop("yes"), + gettext_noop("no"), + gettext_noop("Cycles?"), + gettext_noop("Cache")); + appendPQExpBuffer(&buf, + "FROM pg_catalog.pg_sequence\n" + "WHERE seqrelid = '%s';", + oid); res = PSQLexec(buf.data); if (!res) @@ -1913,7 +1913,7 @@ describeOneTableDetails(const char *schemaname, appendPQExpBufferStr(&buf, ",\n (SELECT c.collname FROM pg_catalog.pg_collation c, pg_catalog.pg_type t\n" " WHERE c.oid = a.attcollation AND t.oid = a.atttypid AND a.attcollation <> t.typcollation) AS attcollation"); attcoll_col = cols++; - appendPQExpBufferStr(&buf, ",\n a.attidentity"); + appendPQExpBufferStr(&buf, ",\n a.attidentity"); attidentity_col = cols++; if (pset.sversion >= 120000) appendPQExpBufferStr(&buf, ",\n a.attgenerated"); @@ -2326,7 +2326,7 @@ describeOneTableDetails(const char *schemaname, CppAsString2(CONSTRAINT_EXCLUSION) ") AND " "condeferred) AS condeferred,\n"); - appendPQExpBufferStr(&buf, "i.indisreplident,\n"); + appendPQExpBufferStr(&buf, "i.indisreplident,\n"); if (pset.sversion >= 150000) appendPQExpBufferStr(&buf, "i.indnullsnotdistinct,\n"); @@ -2431,7 +2431,7 @@ describeOneTableDetails(const char *schemaname, "pg_catalog.pg_get_indexdef(i.indexrelid, 0, true),\n " "pg_catalog.pg_get_constraintdef(con.oid, true), " "contype, condeferrable, condeferred"); - appendPQExpBufferStr(&buf, ", i.indisreplident"); + appendPQExpBufferStr(&buf, ", i.indisreplident"); appendPQExpBufferStr(&buf, ", c2.reltablespace"); if (pset.sversion >= 180000) appendPQExpBufferStr(&buf, ", con.conperiod"); @@ -2682,81 +2682,80 @@ describeOneTableDetails(const char *schemaname, PQclear(result); /* print any row-level policies */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get row-level policies for this table")); - appendPQExpBufferStr(&buf, "SELECT pol.polname,"); - appendPQExpBufferStr(&buf, - " pol.polpermissive,\n"); - appendPQExpBuffer(&buf, - " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" - " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" - " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" - " CASE pol.polcmd\n" - " WHEN 'r' THEN 'SELECT'\n" - " WHEN 'a' THEN 'INSERT'\n" - " WHEN 'w' THEN 'UPDATE'\n" - " WHEN 'd' THEN 'DELETE'\n" - " END AS cmd\n" - "FROM pg_catalog.pg_policy pol\n" - "WHERE pol.polrelid = '%s' ORDER BY 1;", - oid); + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get row-level policies for this table")); + appendPQExpBufferStr(&buf, "SELECT pol.polname,"); + appendPQExpBufferStr(&buf, + " pol.polpermissive,\n"); + appendPQExpBuffer(&buf, + " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" + " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" + " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" + " CASE pol.polcmd\n" + " WHEN 'r' THEN 'SELECT'\n" + " WHEN 'a' THEN 'INSERT'\n" + " WHEN 'w' THEN 'UPDATE'\n" + " WHEN 'd' THEN 'DELETE'\n" + " END AS cmd\n" + "FROM pg_catalog.pg_policy pol\n" + "WHERE pol.polrelid = '%s' ORDER BY 1;", + oid); - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - /* - * Handle cases where RLS is enabled and there are policies, or - * there aren't policies, or RLS isn't enabled but there are - * policies - */ - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies:")); + /* + * Handle cases where RLS is enabled and there are policies, or there + * aren't policies, or RLS isn't enabled but there are policies + */ + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies:")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled):")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled):")); - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); - if (!tableinfo.rowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (row security disabled):")); + if (!tableinfo.rowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (row security disabled):")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " POLICY \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " POLICY \"%s\"", + PQgetvalue(result, i, 0)); - if (*(PQgetvalue(result, i, 1)) == 'f') - appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); + if (*(PQgetvalue(result, i, 1)) == 'f') + appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); - if (!PQgetisnull(result, i, 5)) - appendPQExpBuffer(&buf, " FOR %s", - PQgetvalue(result, i, 5)); + if (!PQgetisnull(result, i, 5)) + appendPQExpBuffer(&buf, " FOR %s", + PQgetvalue(result, i, 5)); - if (!PQgetisnull(result, i, 2)) - { - appendPQExpBuffer(&buf, "\n TO %s", - PQgetvalue(result, i, 2)); - } + if (!PQgetisnull(result, i, 2)) + { + appendPQExpBuffer(&buf, "\n TO %s", + PQgetvalue(result, i, 2)); + } - if (!PQgetisnull(result, i, 3)) - appendPQExpBuffer(&buf, "\n USING (%s)", - PQgetvalue(result, i, 3)); + if (!PQgetisnull(result, i, 3)) + appendPQExpBuffer(&buf, "\n USING (%s)", + PQgetvalue(result, i, 3)); - if (!PQgetisnull(result, i, 4)) - appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", - PQgetvalue(result, i, 4)); + if (!PQgetisnull(result, i, 4)) + appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", + PQgetvalue(result, i, 4)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* print any extended statistics */ if (pset.sversion >= 140000) @@ -3025,115 +3024,115 @@ describeOneTableDetails(const char *schemaname, } /* print any publications */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get publications that publish this table")); - if (pset.sversion >= 150000) + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get publications that publish this table")); + if (pset.sversion >= 150000) + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" + " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" + "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" + "UNION\n" + "SELECT pubname\n" + " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" + " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" + " (SELECT pg_catalog.string_agg(attname, ', ')\n" + " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" + " pg_catalog.pg_attribute\n" + " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" + " ELSE NULL END) " + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" + "WHERE pr.prrelid = '%s'\n", + oid, oid, oid); + + if (pset.sversion >= 190000) { + /* + * Skip entries where this relation appears in the + * publication's EXCEPT list. + */ appendPQExpBuffer(&buf, + " AND NOT pr.prexcept\n" + "UNION\n" "SELECT pubname\n" " , NULL\n" " , NULL\n" "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" - " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" - "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" - "UNION\n" - "SELECT pubname\n" - " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" - " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" - " (SELECT pg_catalog.string_agg(attname, ', ')\n" - " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" - " pg_catalog.pg_attribute\n" - " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" - " ELSE NULL END) " - "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" - "WHERE pr.prrelid = '%s'\n", + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + " AND NOT EXISTS (\n" + " SELECT 1\n" + " FROM pg_catalog.pg_publication_rel pr\n" + " WHERE pr.prpubid = p.oid AND\n" + " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" + "ORDER BY 1;", oid, oid, oid); - - if (pset.sversion >= 190000) - { - /* - * Skip entries where this relation appears in the - * publication's EXCEPT list. - */ - appendPQExpBuffer(&buf, - " AND NOT pr.prexcept\n" - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - " AND NOT EXISTS (\n" - " SELECT 1\n" - " FROM pg_catalog.pg_publication_rel pr\n" - " WHERE pr.prpubid = p.oid AND\n" - " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" - "ORDER BY 1;", - oid, oid, oid); - } - else - { - appendPQExpBuffer(&buf, - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - "ORDER BY 1;", - oid); - } } else { appendPQExpBuffer(&buf, + "UNION\n" "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - "WHERE pr.prrelid = '%s'\n" - "UNION ALL\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" + " , NULL\n" + " , NULL\n" "FROM pg_catalog.pg_publication p\n" "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" "ORDER BY 1;", - oid, oid); + oid); } + } + else + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + "WHERE pr.prrelid = '%s'\n" + "UNION ALL\n" + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + "ORDER BY 1;", + oid, oid); + } - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - if (tuples > 0) - printTableAddFooter(&cont, _("Included in publications:")); + if (tuples > 0) + printTableAddFooter(&cont, _("Included in publications:")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " \"%s\"", + PQgetvalue(result, i, 0)); - /* column list (if any) */ - if (!PQgetisnull(result, i, 2)) - appendPQExpBuffer(&buf, " (%s)", - PQgetvalue(result, i, 2)); + /* column list (if any) */ + if (!PQgetisnull(result, i, 2)) + appendPQExpBuffer(&buf, " (%s)", + PQgetvalue(result, i, 2)); - /* row filter (if any) */ - if (!PQgetisnull(result, i, 1)) - appendPQExpBuffer(&buf, " WHERE %s", - PQgetvalue(result, i, 1)); + /* row filter (if any) */ + if (!PQgetisnull(result, i, 1)) + appendPQExpBuffer(&buf, " WHERE %s", + PQgetvalue(result, i, 1)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* Print publications where the table is in the EXCEPT clause */ if (pset.sversion >= 190000) @@ -3805,7 +3804,7 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) ncols++; } appendPQExpBufferStr(&buf, "\n, r.rolreplication"); - appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); + appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_roles r\n"); @@ -3860,8 +3859,8 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) if (strcmp(PQgetvalue(res, i, (verbose ? 9 : 8)), "t") == 0) add_role_attribute(&buf, _("Replication")); - if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) - add_role_attribute(&buf, _("Bypass RLS")); + if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) + add_role_attribute(&buf, _("Bypass RLS")); conns = atoi(PQgetvalue(res, i, 6)); if (conns >= 0) @@ -5155,14 +5154,14 @@ listCollations(const char *pattern, bool verbose, bool showSystem) gettext_noop("Schema"), gettext_noop("Name")); - appendPQExpBuffer(&buf, - " CASE c.collprovider " - "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " - "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " - "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " - "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " - "END AS \"%s\",\n", - gettext_noop("Provider")); + appendPQExpBuffer(&buf, + " CASE c.collprovider " + "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " + "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " + "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " + "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " + "END AS \"%s\",\n", + gettext_noop("Provider")); appendPQExpBuffer(&buf, " c.collcollate AS \"%s\",\n" -- 2.50.1 (Apple Git-155) --aHl3HfeiUuO3zeNC-- ^ permalink raw reply [nested|flat] 59+ messages in thread
* [PATCH v6 4/4] run pgindent and pgperltidy @ 2026-06-30 18:24 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 59+ messages in thread From: Nathan Bossart @ 2026-06-30 18:24 UTC (permalink / raw) --- src/bin/pg_dump/pg_dump.c | 464 ++++++++++----------- src/bin/pg_dump/pg_dumpall.c | 30 +- src/bin/pg_upgrade/check.c | 16 +- src/bin/pg_upgrade/controldata.c | 2 +- src/bin/pg_upgrade/exec.c | 8 +- src/bin/pg_upgrade/multixact_rewrite.c | 80 ++-- src/bin/pg_upgrade/pg_upgrade.c | 34 +- src/bin/pg_upgrade/relfilenumber.c | 54 +-- src/bin/pg_upgrade/t/006_transfer_modes.pl | 33 +- src/bin/psql/command.c | 29 +- src/bin/psql/describe.c | 461 ++++++++++---------- 11 files changed, 601 insertions(+), 610 deletions(-) diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 65bd15ebfd2..5673268b467 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -1491,8 +1491,8 @@ setup_connection(Archive *AH, const char *dumpencoding, * Disable timeouts if supported. */ ExecuteSqlStatement(AH, "SET statement_timeout = 0"); - ExecuteSqlStatement(AH, "SET lock_timeout = 0"); - ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); + ExecuteSqlStatement(AH, "SET lock_timeout = 0"); + ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); if (AH->remoteVersion >= 170000) ExecuteSqlStatement(AH, "SET transaction_timeout = 0"); @@ -1505,10 +1505,10 @@ setup_connection(Archive *AH, const char *dumpencoding, /* * Adjust row-security mode, if supported. */ - if (dopt->enable_row_security) - ExecuteSqlStatement(AH, "SET row_security = on"); - else - ExecuteSqlStatement(AH, "SET row_security = off"); + if (dopt->enable_row_security) + ExecuteSqlStatement(AH, "SET row_security = on"); + else + ExecuteSqlStatement(AH, "SET row_security = off"); /* * For security reasons, we restrict the expansion of non-system views and @@ -1933,10 +1933,9 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) addObjectDependency(dobj, ext->dobj.dumpId); /* - * Mark the member object to have any non-initial ACLs - * dumped. (Any initial ACLs will be removed later, using data from - * pg_init_privs, so that we'll dump only the delta from the extension's - * initial setup.) + * Mark the member object to have any non-initial ACLs dumped. (Any + * initial ACLs will be removed later, using data from pg_init_privs, so + * that we'll dump only the delta from the extension's initial setup.) * * In binary upgrades, we still dump all components of the members * individually, since the idea is to exactly reproduce the database @@ -1953,7 +1952,7 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) if (fout->dopt->binary_upgrade) dobj->dump = ext->dobj.dump; else - dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); + dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); return true; } @@ -1987,9 +1986,9 @@ selectDumpableNamespace(NamespaceInfo *nsinfo, Archive *fout) else if (strcmp(nsinfo->dobj.name, "pg_catalog") == 0) { /* - * We dump out any ACLs defined in pg_catalog, if - * they are interesting (and not the original ACLs which were set at - * initdb time, see pg_init_privs). + * We dump out any ACLs defined in pg_catalog, if they are interesting + * (and not the original ACLs which were set at initdb time, see + * pg_init_privs). */ nsinfo->dobj.dump_contains = nsinfo->dobj.dump = DUMP_COMPONENT_ACL; } @@ -3296,7 +3295,7 @@ dumpDatabase(Archive *fout) "datcollate, datctype, datfrozenxid, " "datacl, acldefault('d', datdba) AS acldefault, " "datistemplate, datconnlimit, "); - appendPQExpBufferStr(dbQry, "datminmxid, "); + appendPQExpBufferStr(dbQry, "datminmxid, "); if (fout->remoteVersion >= 170000) appendPQExpBufferStr(dbQry, "datlocprovider, datlocale, datcollversion, "); else if (fout->remoteVersion >= 150000) @@ -3638,11 +3637,11 @@ dumpDatabase(Archive *fout) ii_oid, ii_relminmxid; - appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" - "FROM pg_catalog.pg_class\n" - "WHERE oid IN (%u, %u, %u, %u);\n", - LargeObjectRelationId, LargeObjectLOidPNIndexId, - LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); + appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" + "FROM pg_catalog.pg_class\n" + "WHERE oid IN (%u, %u, %u, %u);\n", + LargeObjectRelationId, LargeObjectLOidPNIndexId, + LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); lo_res = ExecuteSqlQuery(fout, loFrozenQry->data, PGRES_TUPLES_OK); @@ -4274,7 +4273,7 @@ getPolicies(Archive *fout, TableInfo tblinfo[], int numTables) printfPQExpBuffer(query, "SELECT pol.oid, pol.tableoid, pol.polrelid, pol.polname, pol.polcmd, "); - appendPQExpBufferStr(query, "pol.polpermissive, "); + appendPQExpBufferStr(query, "pol.polpermissive, "); appendPQExpBuffer(query, "CASE WHEN pol.polroles = '{0}' THEN NULL ELSE " " pg_catalog.array_to_string(ARRAY(SELECT pg_catalog.quote_ident(rolname) from pg_catalog.pg_roles WHERE oid = ANY(pol.polroles)), ', ') END AS polroles, " @@ -6633,9 +6632,9 @@ getAccessMethods(Archive *fout) * Select all access methods from pg_am table. */ appendPQExpBufferStr(query, "SELECT tableoid, oid, amname, "); - appendPQExpBufferStr(query, - "amtype, " - "amhandler::pg_catalog.regproc AS amhandler "); + appendPQExpBufferStr(query, + "amtype, " + "amhandler::pg_catalog.regproc AS amhandler "); appendPQExpBufferStr(query, "FROM pg_am"); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6827,35 +6826,35 @@ getAggregates(Archive *fout) * Find all interesting aggregates. See comment in getFuncs() for the * rationale behind the filtering logic. */ - agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" - : "p.proisagg"); + agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" + : "p.proisagg"); - appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " - "p.proname AS aggname, " - "p.pronamespace AS aggnamespace, " - "p.pronargs, p.proargtypes, " - "p.proowner, " - "p.proacl AS aggacl, " - "acldefault('f', p.proowner) AS acldefault " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s AND (" - "p.pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog') OR " - "p.proacl IS DISTINCT FROM pip.initprivs", - agg_check); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - " OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); - appendPQExpBufferChar(query, ')'); + appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " + "p.proname AS aggname, " + "p.pronamespace AS aggnamespace, " + "p.pronargs, p.proargtypes, " + "p.proowner, " + "p.proacl AS aggacl, " + "acldefault('f', p.proowner) AS acldefault " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s AND (" + "p.pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog') OR " + "p.proacl IS DISTINCT FROM pip.initprivs", + agg_check); + if (dopt->binary_upgrade) + appendPQExpBufferStr(query, + " OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6957,53 +6956,53 @@ getFuncs(Archive *fout) * include them, since we want to dump extension members individually in * that mode. Also, if they are used by casts or transforms then we need * to gather the information about them, though they won't be dumped if - * they are built-in. Also, include functions in - * pg_catalog if they have an ACL different from what's shown in - * pg_init_privs (so we have to join to pg_init_privs; annoying). + * they are built-in. Also, include functions in pg_catalog if they have + * an ACL different from what's shown in pg_init_privs (so we have to join + * to pg_init_privs; annoying). */ - not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" - : "NOT p.proisagg"); + not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" + : "NOT p.proisagg"); - appendPQExpBuffer(query, - "SELECT p.tableoid, p.oid, p.proname, p.prolang, " - "p.pronargs, p.proargtypes, p.prorettype, " - "p.proacl, " - "acldefault('f', p.proowner) AS acldefault, " - "p.pronamespace, " - "p.proowner " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s" - "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " - "WHERE classid = 'pg_proc'::regclass AND " - "objid = p.oid AND deptype = 'i')" - "\n AND (" - "\n pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog')" - "\n OR EXISTS (SELECT 1 FROM pg_cast" - "\n WHERE pg_cast.oid > %u " - "\n AND p.oid = pg_cast.castfunc)" - "\n OR EXISTS (SELECT 1 FROM pg_transform" - "\n WHERE pg_transform.oid > %u AND " - "\n (p.oid = pg_transform.trffromsql" - "\n OR p.oid = pg_transform.trftosql))", - not_agg_check, - g_last_builtin_oid, - g_last_builtin_oid); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); + appendPQExpBuffer(query, + "SELECT p.tableoid, p.oid, p.proname, p.prolang, " + "p.pronargs, p.proargtypes, p.prorettype, " + "p.proacl, " + "acldefault('f', p.proowner) AS acldefault, " + "p.pronamespace, " + "p.proowner " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s" + "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " + "WHERE classid = 'pg_proc'::regclass AND " + "objid = p.oid AND deptype = 'i')" + "\n AND (" + "\n pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog')" + "\n OR EXISTS (SELECT 1 FROM pg_cast" + "\n WHERE pg_cast.oid > %u " + "\n AND p.oid = pg_cast.castfunc)" + "\n OR EXISTS (SELECT 1 FROM pg_transform" + "\n WHERE pg_transform.oid > %u AND " + "\n (p.oid = pg_transform.trffromsql" + "\n OR p.oid = pg_transform.trftosql))", + not_agg_check, + g_last_builtin_oid, + g_last_builtin_oid); + if (dopt->binary_upgrade) appendPQExpBufferStr(query, - "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); - appendPQExpBufferChar(query, ')'); + "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferStr(query, + "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -7252,31 +7251,31 @@ getTables(Archive *fout, int *numTables) appendPQExpBufferStr(query, "c.relhasoids, "); - appendPQExpBufferStr(query, - "c.relispopulated, "); + appendPQExpBufferStr(query, + "c.relispopulated, "); - appendPQExpBufferStr(query, - "c.relreplident, "); + appendPQExpBufferStr(query, + "c.relreplident, "); - appendPQExpBufferStr(query, - "c.relrowsecurity, c.relforcerowsecurity, "); + appendPQExpBufferStr(query, + "c.relrowsecurity, c.relforcerowsecurity, "); - appendPQExpBufferStr(query, - "c.relminmxid, tc.relminmxid AS tminmxid, "); + appendPQExpBufferStr(query, + "c.relminmxid, tc.relminmxid AS tminmxid, "); - appendPQExpBufferStr(query, - "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); + appendPQExpBufferStr(query, + "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); - appendPQExpBufferStr(query, - "am.amname, "); + appendPQExpBufferStr(query, + "am.amname, "); - appendPQExpBufferStr(query, - "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); + appendPQExpBufferStr(query, + "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); - appendPQExpBufferStr(query, - "c.relispartition AS ispartition "); + appendPQExpBufferStr(query, + "c.relispartition AS ispartition "); /* * Left join to pg_depend to pick up dependency info linking sequences to @@ -7296,8 +7295,8 @@ getTables(Archive *fout, int *numTables) /* * Left join to pg_am to pick up the amname. */ - appendPQExpBufferStr(query, - "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); + appendPQExpBufferStr(query, + "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); /* * We purposefully ignore toast OIDs for partitioned tables; the reason is @@ -7868,8 +7867,8 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables) "t.reloptions AS indreloptions, "); - appendPQExpBufferStr(query, - "i.indisreplident, "); + appendPQExpBufferStr(query, + "i.indisreplident, "); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -9313,8 +9312,8 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables) appendPQExpBufferStr(q, "'' AS attcompression,\n"); - appendPQExpBufferStr(q, - "a.attidentity,\n"); + appendPQExpBufferStr(q, + "a.attidentity,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(q, @@ -10717,73 +10716,73 @@ getAdditionalACLs(Archive *fout) PQclear(res); /* Fetch initial-privileges data */ - printfPQExpBuffer(query, - "SELECT objoid, classoid, objsubid, privtype, initprivs " - "FROM pg_init_privs"); + printfPQExpBuffer(query, + "SELECT objoid, classoid, objsubid, privtype, initprivs " + "FROM pg_init_privs"); - res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); + res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); - ntups = PQntuples(res); - for (i = 0; i < ntups; i++) - { - Oid objoid = atooid(PQgetvalue(res, i, 0)); - Oid classoid = atooid(PQgetvalue(res, i, 1)); - int objsubid = atoi(PQgetvalue(res, i, 2)); - char privtype = *(PQgetvalue(res, i, 3)); - char *initprivs = PQgetvalue(res, i, 4); - CatalogId objId; - DumpableObject *dobj; + ntups = PQntuples(res); + for (i = 0; i < ntups; i++) + { + Oid objoid = atooid(PQgetvalue(res, i, 0)); + Oid classoid = atooid(PQgetvalue(res, i, 1)); + int objsubid = atoi(PQgetvalue(res, i, 2)); + char privtype = *(PQgetvalue(res, i, 3)); + char *initprivs = PQgetvalue(res, i, 4); + CatalogId objId; + DumpableObject *dobj; - objId.tableoid = classoid; - objId.oid = objoid; - dobj = findObjectByCatalogId(objId); - /* OK to ignore entries we haven't got a DumpableObject for */ - if (dobj) + objId.tableoid = classoid; + objId.oid = objoid; + dobj = findObjectByCatalogId(objId); + /* OK to ignore entries we haven't got a DumpableObject for */ + if (dobj) + { + /* Cope with sub-object initprivs */ + if (objsubid != 0) { - /* Cope with sub-object initprivs */ - if (objsubid != 0) - { - if (dobj->objType == DO_TABLE) - { - /* For a column initprivs, set the table's ACL flags */ - dobj->components |= DUMP_COMPONENT_ACL; - ((TableInfo *) dobj)->hascolumnACLs = true; - } - else - pg_log_warning("unsupported pg_init_privs entry: %u %u %d", - classoid, objoid, objsubid); - continue; - } - - /* - * We ignore any pg_init_privs.initprivs entry for the public - * schema, as explained in getNamespaces(). - */ - if (dobj->objType == DO_NAMESPACE && - strcmp(dobj->name, "public") == 0) - continue; - - /* Else it had better be of a type we think has ACLs */ - if (dobj->objType == DO_NAMESPACE || - dobj->objType == DO_TYPE || - dobj->objType == DO_FUNC || - dobj->objType == DO_AGG || - dobj->objType == DO_TABLE || - dobj->objType == DO_PROCLANG || - dobj->objType == DO_FDW || - dobj->objType == DO_FOREIGN_SERVER) + if (dobj->objType == DO_TABLE) { - DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; - - daobj->dacl.privtype = privtype; - daobj->dacl.initprivs = pstrdup(initprivs); + /* For a column initprivs, set the table's ACL flags */ + dobj->components |= DUMP_COMPONENT_ACL; + ((TableInfo *) dobj)->hascolumnACLs = true; } else pg_log_warning("unsupported pg_init_privs entry: %u %u %d", classoid, objoid, objsubid); + continue; + } + + /* + * We ignore any pg_init_privs.initprivs entry for the public + * schema, as explained in getNamespaces(). + */ + if (dobj->objType == DO_NAMESPACE && + strcmp(dobj->name, "public") == 0) + continue; + + /* Else it had better be of a type we think has ACLs */ + if (dobj->objType == DO_NAMESPACE || + dobj->objType == DO_TYPE || + dobj->objType == DO_FUNC || + dobj->objType == DO_AGG || + dobj->objType == DO_TABLE || + dobj->objType == DO_PROCLANG || + dobj->objType == DO_FDW || + dobj->objType == DO_FOREIGN_SERVER) + { + DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; + + daobj->dacl.privtype = privtype; + daobj->dacl.initprivs = pstrdup(initprivs); } + else + pg_log_warning("unsupported pg_init_privs entry: %u %u %d", + classoid, objoid, objsubid); } - PQclear(res); + } + PQclear(res); destroyPQExpBuffer(query); } @@ -11128,8 +11127,8 @@ dumpRelationStats_dumper(Archive *fout, const void *userArg, const TocEntry *te) * The results must be in the order of the relations supplied in the * parameters to ensure we remain in sync as we walk through the TOC. * - * For versions before 19, the redundant filter clause on s.tablename = - * ANY(...) seems sufficient to convince the planner to use + * For versions before 19, the redundant filter clause on s.tablename + * = ANY(...) seems sufficient to convince the planner to use * pg_class_relname_nsp_index, which avoids a full scan of pg_stats. * In newer versions, pg_stats returns the table OIDs, eliminating the * need for that hack. @@ -13469,11 +13468,11 @@ dumpFunc(Archive *fout, const FuncInfo *finfo) "pg_catalog.pg_get_function_result(p.oid) AS funcresult,\n" "proleakproof,\n"); - appendPQExpBufferStr(query, - "array_to_string(protrftypes, ' ') AS protrftypes,\n"); + appendPQExpBufferStr(query, + "array_to_string(protrftypes, ' ') AS protrftypes,\n"); - appendPQExpBufferStr(query, - "proparallel,\n"); + appendPQExpBufferStr(query, + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -14963,9 +14962,9 @@ dumpCollation(Archive *fout, const CollInfo *collinfo) /* Get collation-specific details */ appendPQExpBufferStr(query, "SELECT "); - appendPQExpBufferStr(query, - "collprovider, " - "collversion, "); + appendPQExpBufferStr(query, + "collprovider, " + "collversion, "); if (fout->remoteVersion >= 120000) appendPQExpBufferStr(query, @@ -15372,23 +15371,23 @@ dumpAgg(Archive *fout, const AggInfo *agginfo) "pg_catalog.pg_get_function_arguments(p.oid) AS funcargs,\n" "pg_catalog.pg_get_function_identity_arguments(p.oid) AS funciargs,\n"); - appendPQExpBufferStr(query, - "aggkind,\n" - "aggmtransfn,\n" - "aggminvtransfn,\n" - "aggmfinalfn,\n" - "aggmtranstype::pg_catalog.regtype,\n" - "aggfinalextra,\n" - "aggmfinalextra,\n" - "aggtransspace,\n" - "aggmtransspace,\n" - "aggminitval,\n"); + appendPQExpBufferStr(query, + "aggkind,\n" + "aggmtransfn,\n" + "aggminvtransfn,\n" + "aggmfinalfn,\n" + "aggmtranstype::pg_catalog.regtype,\n" + "aggfinalextra,\n" + "aggmfinalextra,\n" + "aggtransspace,\n" + "aggmtransspace,\n" + "aggminitval,\n"); - appendPQExpBufferStr(query, - "aggcombinefn,\n" - "aggserialfn,\n" - "aggdeserialfn,\n" - "proparallel,\n"); + appendPQExpBufferStr(query, + "aggcombinefn,\n" + "aggserialfn,\n" + "aggdeserialfn,\n" + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -16848,30 +16847,30 @@ dumpTable(Archive *fout, const TableInfo *tbinfo) appendPQExpBufferStr(query, "PREPARE getColumnACLs(pg_catalog.oid) AS\n"); - /* - * In principle we should call acldefault('c', relowner) to - * get the default ACL for a column. However, we don't - * currently store the numeric OID of the relowner in - * TableInfo. We could convert the owner name using regrole, - * but that creates a risk of failure due to concurrent role - * renames. Given that the default ACL for columns is empty - * and is likely to stay that way, it's not worth extra cycles - * and risk to avoid hard-wiring that knowledge here. - */ - appendPQExpBufferStr(query, - "SELECT at.attname, " - "at.attacl, " - "'{}' AS acldefault, " - "pip.privtype, pip.initprivs " - "FROM pg_catalog.pg_attribute at " - "LEFT JOIN pg_catalog.pg_init_privs pip ON " - "(at.attrelid = pip.objoid " - "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " - "AND at.attnum = pip.objsubid) " - "WHERE at.attrelid = $1 AND " - "NOT at.attisdropped " - "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " - "ORDER BY at.attnum"); + /* + * In principle we should call acldefault('c', relowner) to get + * the default ACL for a column. However, we don't currently + * store the numeric OID of the relowner in TableInfo. We could + * convert the owner name using regrole, but that creates a risk + * of failure due to concurrent role renames. Given that the + * default ACL for columns is empty and is likely to stay that + * way, it's not worth extra cycles and risk to avoid hard-wiring + * that knowledge here. + */ + appendPQExpBufferStr(query, + "SELECT at.attname, " + "at.attacl, " + "'{}' AS acldefault, " + "pip.privtype, pip.initprivs " + "FROM pg_catalog.pg_attribute at " + "LEFT JOIN pg_catalog.pg_init_privs pip ON " + "(at.attrelid = pip.objoid " + "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " + "AND at.attnum = pip.objsubid) " + "WHERE at.attrelid = $1 AND " + "NOT at.attisdropped " + "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " + "ORDER BY at.attnum"); ExecuteSqlStatement(fout, query->data); @@ -19165,7 +19164,7 @@ collectSequences(Archive *fout) * pg_get_sequence_data(), but we only do so for non-schema-only dumps. */ if (fout->remoteVersion < 180000 || - (!fout->dopt->dumpData && !fout->dopt->sequence_data)) + (!fout->dopt->dumpData && !fout->dopt->sequence_data)) query = "SELECT seqrelid, format_type(seqtypid, NULL), " "seqstart, seqincrement, " "seqmax, seqmin, " @@ -19227,15 +19226,14 @@ dumpSequence(Archive *fout, const TableInfo *tbinfo) qseqname = pg_strdup(fmtId(tbinfo->dobj.name)); /* - * The sequence information is gathered in a sorted - * table before any calls to dumpSequence(). See collectSequences() for - * more information. + * The sequence information is gathered in a sorted table before any calls + * to dumpSequence(). See collectSequences() for more information. */ - Assert(sequences); + Assert(sequences); - key.oid = tbinfo->dobj.catId.oid; - seq = bsearch(&key, sequences, nsequences, - sizeof(SequenceItem), SequenceItemCmp); + key.oid = tbinfo->dobj.catId.oid; + seq = bsearch(&key, sequences, nsequences, + sizeof(SequenceItem), SequenceItemCmp); /* Calculate default limits for a sequence of this type */ is_ascending = (seq->incby >= 0); diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c index e68937c9934..afcd9a218d8 100644 --- a/src/bin/pg_dump/pg_dumpall.c +++ b/src/bin/pg_dump/pg_dumpall.c @@ -785,11 +785,11 @@ dropRoles(PGconn *conn) int i_rolname; int i; - printfPQExpBuffer(buf, - "SELECT rolname " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 1", role_catalog); + printfPQExpBuffer(buf, + "SELECT rolname " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 1", role_catalog); res = executeQuery(conn, buf->data); @@ -843,16 +843,16 @@ dumpRoles(PGconn *conn) * Notes: rolconfig is dumped later, and pg_authid must be used for * extracting rolcomment regardless of role_catalog. */ - printfPQExpBuffer(buf, - "SELECT oid, rolname, rolsuper, rolinherit, " - "rolcreaterole, rolcreatedb, " - "rolcanlogin, rolconnlimit, rolpassword, " - "rolvaliduntil, rolreplication, rolbypassrls, " - "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " - "rolname = current_user AS is_current_user " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 2", role_catalog); + printfPQExpBuffer(buf, + "SELECT oid, rolname, rolsuper, rolinherit, " + "rolcreaterole, rolcreatedb, " + "rolcanlogin, rolconnlimit, rolpassword, " + "rolvaliduntil, rolreplication, rolbypassrls, " + "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " + "rolname = current_user AS is_current_user " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 2", role_catalog); res = executeQuery(conn, buf->data); diff --git a/src/bin/pg_upgrade/check.c b/src/bin/pg_upgrade/check.c index 786c1474829..f725f5ee3e2 100644 --- a/src/bin/pg_upgrade/check.c +++ b/src/bin/pg_upgrade/check.c @@ -1475,15 +1475,15 @@ check_for_incompatible_polymorphics(ClusterInfo *cluster) ", 'array_cat(anyarray,anyarray)'" ", 'array_prepend(anyelement,anyarray)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_remove(anyarray,anyelement)'" - ", 'array_replace(anyarray,anyelement,anyelement)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_remove(anyarray,anyelement)'" + ", 'array_replace(anyarray,anyelement,anyelement)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_position(anyarray,anyelement)'" - ", 'array_position(anyarray,anyelement,integer)'" - ", 'array_positions(anyarray,anyelement)'" - ", 'width_bucket(anyelement,anyarray)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_position(anyarray,anyelement)'" + ", 'array_position(anyarray,anyelement,integer)'" + ", 'array_positions(anyarray,anyelement)'" + ", 'width_bucket(anyelement,anyarray)'"); /* * The query below hardcodes FirstNormalObjectId as 16384 rather than diff --git a/src/bin/pg_upgrade/controldata.c b/src/bin/pg_upgrade/controldata.c index 8f81c9e9582..02ea02df60f 100644 --- a/src/bin/pg_upgrade/controldata.c +++ b/src/bin/pg_upgrade/controldata.c @@ -228,7 +228,7 @@ get_control_data(ClusterInfo *cluster) p++; /* remove ':' char */ cluster->controldata.chkpnt_nxtepoch = str2uint(p); - p = strchr(p, ':'); + p = strchr(p, ':'); if (p == NULL || strlen(p) <= 1) pg_fatal("%d: controldata retrieval problem", __LINE__); diff --git a/src/bin/pg_upgrade/exec.c b/src/bin/pg_upgrade/exec.c index 44355feea30..a1bdbf373e3 100644 --- a/src/bin/pg_upgrade/exec.c +++ b/src/bin/pg_upgrade/exec.c @@ -55,7 +55,7 @@ get_bin_version(ClusterInfo *cluster) if (sscanf(cmd_output, "%*s %*s %d.%d", &v1, &v2) < 1) pg_fatal("could not get pg_ctl version output from %s", cmd); - cluster->bin_version = v1 * 10000; + cluster->bin_version = v1 * 10000; } @@ -344,8 +344,8 @@ check_data_dir(ClusterInfo *cluster) check_single_dir(pg_data, "pg_subtrans"); check_single_dir(pg_data, PG_TBLSPC_DIR); check_single_dir(pg_data, "pg_twophase"); - check_single_dir(pg_data, "pg_wal"); - check_single_dir(pg_data, "pg_xact"); + check_single_dir(pg_data, "pg_wal"); + check_single_dir(pg_data, "pg_xact"); } @@ -385,7 +385,7 @@ check_bin_dir(ClusterInfo *cluster, bool check_versions) */ get_bin_version(cluster); - check_exec(cluster->bindir, "pg_resetwal", check_versions); + check_exec(cluster->bindir, "pg_resetwal", check_versions); if (cluster == &new_cluster) { diff --git a/src/bin/pg_upgrade/multixact_rewrite.c b/src/bin/pg_upgrade/multixact_rewrite.c index c45b3183684..c7a1416494d 100644 --- a/src/bin/pg_upgrade/multixact_rewrite.c +++ b/src/bin/pg_upgrade/multixact_rewrite.c @@ -61,52 +61,52 @@ rewrite_multixacts(MultiXactId from_multi, MultiXactId to_multi) * Convert old multixids, if needed, by reading them one-by-one from the * old cluster. */ - old_reader = AllocOldMultiXactRead(old_cluster.pgdata, - old_cluster.controldata.chkpnt_nxtmulti, - old_cluster.controldata.chkpnt_nxtmxoff); + old_reader = AllocOldMultiXactRead(old_cluster.pgdata, + old_cluster.controldata.chkpnt_nxtmulti, + old_cluster.controldata.chkpnt_nxtmxoff); - for (MultiXactId multi = from_multi; multi != to_multi;) - { - MultiXactMember member; - bool multixid_valid; - - /* - * Read this multixid's members. - * - * Locking-only XIDs that may be part of multi-xids don't matter - * after upgrade, as there can be no transactions running across - * upgrade. So as a small optimization, we only read one member - * from each multixid: the one updating one, or if there was no - * update, arbitrarily the first locking xid. - */ - multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); + for (MultiXactId multi = from_multi; multi != to_multi;) + { + MultiXactMember member; + bool multixid_valid; - /* - * Write the new offset to pg_multixact/offsets. - * - * Even if this multixid is invalid, we still need to write its - * offset if the *previous* multixid was valid. That's because - * when reading a multixid, the number of members is calculated - * from the difference between the two offsets. - */ - RecordMultiXactOffset(offsets_writer, multi, - (multixid_valid || prev_multixid_valid) ? next_offset : 0); + /* + * Read this multixid's members. + * + * Locking-only XIDs that may be part of multi-xids don't matter after + * upgrade, as there can be no transactions running across upgrade. So + * as a small optimization, we only read one member from each + * multixid: the one updating one, or if there was no update, + * arbitrarily the first locking xid. + */ + multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); - /* Write the members */ - if (multixid_valid) - { - RecordMultiXactMembers(members_writer, next_offset, 1, &member); - next_offset += 1; - } + /* + * Write the new offset to pg_multixact/offsets. + * + * Even if this multixid is invalid, we still need to write its offset + * if the *previous* multixid was valid. That's because when reading + * a multixid, the number of members is calculated from the difference + * between the two offsets. + */ + RecordMultiXactOffset(offsets_writer, multi, + (multixid_valid || prev_multixid_valid) ? next_offset : 0); - /* Advance to next multixid, handling wraparound */ - multi++; - if (multi < FirstMultiXactId) - multi = FirstMultiXactId; - prev_multixid_valid = multixid_valid; + /* Write the members */ + if (multixid_valid) + { + RecordMultiXactMembers(members_writer, next_offset, 1, &member); + next_offset += 1; } - FreeOldMultiXactReader(old_reader); + /* Advance to next multixid, handling wraparound */ + multi++; + if (multi < FirstMultiXactId) + multi = FirstMultiXactId; + prev_multixid_valid = multixid_valid; + } + + FreeOldMultiXactReader(old_reader); /* Write the final 'next' offset to the last SLRU page */ RecordMultiXactOffset(offsets_writer, to_multi, diff --git a/src/bin/pg_upgrade/pg_upgrade.c b/src/bin/pg_upgrade/pg_upgrade.c index c6af9035665..7366fd4627c 100644 --- a/src/bin/pg_upgrade/pg_upgrade.c +++ b/src/bin/pg_upgrade/pg_upgrade.c @@ -833,7 +833,7 @@ copy_xact_xlog_xid(void) * Determine the range of multixacts to convert. */ nxtmulti = old_cluster.controldata.chkpnt_nxtmulti; - oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; + oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; /* handle wraparound */ if (nxtmulti < FirstMultiXactId) nxtmulti = FirstMultiXactId; @@ -898,15 +898,15 @@ set_frozenxids(void) int i_datname; int i_datallowconn; - prep_status("Setting frozenxid and minmxid counters in new cluster"); + prep_status("Setting frozenxid and minmxid counters in new cluster"); conn_template1 = connectToServer(&new_cluster, "template1"); - /* set pg_database.datfrozenxid */ - PQclear(executeQueryOrDie(conn_template1, - "UPDATE pg_catalog.pg_database " - "SET datfrozenxid = '%u'", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_database.datfrozenxid */ + PQclear(executeQueryOrDie(conn_template1, + "UPDATE pg_catalog.pg_database " + "SET datfrozenxid = '%u'", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_database.datminmxid */ PQclear(executeQueryOrDie(conn_template1, @@ -942,16 +942,16 @@ set_frozenxids(void) conn = connectToServer(&new_cluster, datname); - /* set pg_class.relfrozenxid */ - PQclear(executeQueryOrDie(conn, - "UPDATE pg_catalog.pg_class " - "SET relfrozenxid = '%u' " - /* only heap, materialized view, and TOAST are vacuumed */ - "WHERE relkind IN (" - CppAsString2(RELKIND_RELATION) ", " - CppAsString2(RELKIND_MATVIEW) ", " - CppAsString2(RELKIND_TOASTVALUE) ")", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_class.relfrozenxid */ + PQclear(executeQueryOrDie(conn, + "UPDATE pg_catalog.pg_class " + "SET relfrozenxid = '%u' " + /* only heap, materialized view, and TOAST are vacuumed */ + "WHERE relkind IN (" + CppAsString2(RELKIND_RELATION) ", " + CppAsString2(RELKIND_MATVIEW) ", " + CppAsString2(RELKIND_TOASTVALUE) ")", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_class.relminmxid */ PQclear(executeQueryOrDie(conn, diff --git a/src/bin/pg_upgrade/relfilenumber.c b/src/bin/pg_upgrade/relfilenumber.c index ec2ff7acb21..6c467bdc8a5 100644 --- a/src/bin/pg_upgrade/relfilenumber.c +++ b/src/bin/pg_upgrade/relfilenumber.c @@ -587,32 +587,32 @@ transfer_relfile(FileNameMap *map, const char *type_suffix) /* Copying files might take some time, so give feedback. */ pg_log(PG_STATUS, "%s", old_file); - switch (user_opts.transfer_mode) - { - case TRANSFER_MODE_CLONE: - pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", - old_file, new_file); - cloneFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", - old_file, new_file); - copyFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY_FILE_RANGE: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", - old_file, new_file); - copyFileByRange(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_LINK: - pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", - old_file, new_file); - linkFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_SWAP: - /* swap mode is handled in its own code path */ - pg_fatal("should never happen"); - break; - } + switch (user_opts.transfer_mode) + { + case TRANSFER_MODE_CLONE: + pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", + old_file, new_file); + cloneFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", + old_file, new_file); + copyFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY_FILE_RANGE: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", + old_file, new_file); + copyFileByRange(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_LINK: + pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", + old_file, new_file); + linkFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_SWAP: + /* swap mode is handled in its own code path */ + pg_fatal("should never happen"); + break; + } } } diff --git a/src/bin/pg_upgrade/t/006_transfer_modes.pl b/src/bin/pg_upgrade/t/006_transfer_modes.pl index 9efa5dc863c..360d05c4b68 100644 --- a/src/bin/pg_upgrade/t/006_transfer_modes.pl +++ b/src/bin/pg_upgrade/t/006_transfer_modes.pl @@ -29,10 +29,8 @@ sub test_mode } $new->init(); - $new->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); - $old->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); + $new->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); + $old->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); # We can only test security labels if both the old and new installations # have dummy_seclabel. @@ -76,15 +74,14 @@ sub test_mode "CREATE TABLE test4 AS SELECT generate_series(400, 502)"); } - $old->safe_psql('postgres', - "CREATE TABLESPACE inplc_tblspc LOCATION ''"); - $old->safe_psql('postgres', - "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); - $old->safe_psql('postgres', - "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" - ); - $old->safe_psql('testdb3', - "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); + $old->safe_psql('postgres', "CREATE TABLESPACE inplc_tblspc LOCATION ''"); + $old->safe_psql('postgres', + "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); + $old->safe_psql('postgres', + "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" + ); + $old->safe_psql('testdb3', + "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); # While we are here, test handling of large objects. $old->safe_psql( @@ -152,12 +149,10 @@ sub test_mode } # Tests for in-place tablespaces. - $result = - $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); - is($result, '104', "test5 data after pg_upgrade $mode"); - $result = - $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); - is($result, '105', "test6 data after pg_upgrade $mode"); + $result = $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); + is($result, '104', "test5 data after pg_upgrade $mode"); + $result = $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); + is($result, '105', "test6 data after pg_upgrade $mode"); # Tests for large objects $result = $new->safe_psql('postgres', "SELECT lo_get(4532)"); diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index 44ef11d980e..c90bf8bbde2 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -6278,23 +6278,22 @@ get_create_object_cmd(EditableObjectType obj_type, Oid oid, * ensure the right view gets replaced. Also, check relation kind * to be sure it's a view. * - * Views may have WITH [LOCAL|CASCADED] - * CHECK OPTION. These are not part of the view definition - * returned by pg_get_viewdef() and so need to be retrieved - * separately. Materialized views may have - * arbitrary storage parameter reloptions. + * Views may have WITH [LOCAL|CASCADED] CHECK OPTION. These are + * not part of the view definition returned by pg_get_viewdef() + * and so need to be retrieved separately. Materialized views may + * have arbitrary storage parameter reloptions. */ printfPQExpBuffer(query, "/* %s */\n", _("Get view's definition and details")); - appendPQExpBuffer(query, - "SELECT nspname, relname, relkind, " - "pg_catalog.pg_get_viewdef(c.oid, true), " - "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " - "FROM pg_catalog.pg_class c " - "LEFT JOIN pg_catalog.pg_namespace n " - "ON c.relnamespace = n.oid WHERE c.oid = %u", - oid); + appendPQExpBuffer(query, + "SELECT nspname, relname, relkind, " + "pg_catalog.pg_get_viewdef(c.oid, true), " + "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " + "FROM pg_catalog.pg_class c " + "LEFT JOIN pg_catalog.pg_namespace n " + "ON c.relnamespace = n.oid WHERE c.oid = %u", + oid); break; } diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index ce99137c613..ac0c55e7aa5 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -387,19 +387,19 @@ describeFunctions(const char *functypes, const char *func_pattern, gettext_noop("stable"), gettext_noop("volatile"), gettext_noop("Volatility")); - appendPQExpBuffer(&buf, - ",\n CASE\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" - " END as \"%s\"", - gettext_noop("restricted"), - gettext_noop("safe"), - gettext_noop("unsafe"), - gettext_noop("Parallel")); + appendPQExpBuffer(&buf, + ",\n CASE\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" + " END as \"%s\"", + gettext_noop("restricted"), + gettext_noop("safe"), + gettext_noop("unsafe"), + gettext_noop("Parallel")); appendPQExpBuffer(&buf, ",\n pg_catalog.pg_get_userbyid(p.proowner) as \"%s\"" ",\n CASE WHEN prosecdef THEN '%s' ELSE '%s' END AS \"%s\"" @@ -599,8 +599,8 @@ describeFunctions(const char *functypes, const char *func_pattern, myopt.title = _("List of functions"); myopt.translate_header = true; - myopt.translate_columns = translate_columns; - myopt.n_translate_columns = lengthof(translate_columns); + myopt.translate_columns = translate_columns; + myopt.n_translate_columns = lengthof(translate_columns); printQuery(res, &myopt, pset.queryFout, false, pset.logfile); @@ -1086,38 +1086,38 @@ permissionsList(const char *pattern, bool showSystem) " ), E'\\n') AS \"%s\"", gettext_noop("Column privileges")); - appendPQExpBuffer(&buf, - ",\n pg_catalog.array_to_string(ARRAY(\n" - " SELECT polname\n" - " || CASE WHEN NOT polpermissive THEN\n" - " E' (RESTRICTIVE)'\n" - " ELSE '' END\n" - " || CASE WHEN polcmd != '*' THEN\n" - " E' (' || polcmd::pg_catalog.text || E'):'\n" - " ELSE E':'\n" - " END\n" - " || CASE WHEN polqual IS NOT NULL THEN\n" - " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" - " ELSE E''\n" - " END\n" - " || CASE WHEN polwithcheck IS NOT NULL THEN\n" - " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" - " ELSE E''\n" - " END" - " || CASE WHEN polroles <> '{0}' THEN\n" - " E'\\n to: ' || pg_catalog.array_to_string(\n" - " ARRAY(\n" - " SELECT rolname\n" - " FROM pg_catalog.pg_roles\n" - " WHERE oid = ANY (polroles)\n" - " ORDER BY 1\n" - " ), E', ')\n" - " ELSE E''\n" - " END\n" - " FROM pg_catalog.pg_policy pol\n" - " WHERE polrelid = c.oid), E'\\n')\n" - " AS \"%s\"", - gettext_noop("Policies")); + appendPQExpBuffer(&buf, + ",\n pg_catalog.array_to_string(ARRAY(\n" + " SELECT polname\n" + " || CASE WHEN NOT polpermissive THEN\n" + " E' (RESTRICTIVE)'\n" + " ELSE '' END\n" + " || CASE WHEN polcmd != '*' THEN\n" + " E' (' || polcmd::pg_catalog.text || E'):'\n" + " ELSE E':'\n" + " END\n" + " || CASE WHEN polqual IS NOT NULL THEN\n" + " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" + " ELSE E''\n" + " END\n" + " || CASE WHEN polwithcheck IS NOT NULL THEN\n" + " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" + " ELSE E''\n" + " END" + " || CASE WHEN polroles <> '{0}' THEN\n" + " E'\\n to: ' || pg_catalog.array_to_string(\n" + " ARRAY(\n" + " SELECT rolname\n" + " FROM pg_catalog.pg_roles\n" + " WHERE oid = ANY (polroles)\n" + " ORDER BY 1\n" + " ), E', ')\n" + " ELSE E''\n" + " END\n" + " FROM pg_catalog.pg_policy pol\n" + " WHERE polrelid = c.oid), E'\\n')\n" + " AS \"%s\"", + gettext_noop("Policies")); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_class c\n" " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n" @@ -1675,27 +1675,27 @@ describeOneTableDetails(const char *schemaname, char *footers[3] = {NULL, NULL, NULL}; printfPQExpBuffer(&buf, "/* %s */\n", _("Get sequence information")); - appendPQExpBuffer(&buf, - "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" - " seqstart AS \"%s\",\n" - " seqmin AS \"%s\",\n" - " seqmax AS \"%s\",\n" - " seqincrement AS \"%s\",\n" - " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" - " seqcache AS \"%s\"\n", - gettext_noop("Type"), - gettext_noop("Start"), - gettext_noop("Minimum"), - gettext_noop("Maximum"), - gettext_noop("Increment"), - gettext_noop("yes"), - gettext_noop("no"), - gettext_noop("Cycles?"), - gettext_noop("Cache")); - appendPQExpBuffer(&buf, - "FROM pg_catalog.pg_sequence\n" - "WHERE seqrelid = '%s';", - oid); + appendPQExpBuffer(&buf, + "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" + " seqstart AS \"%s\",\n" + " seqmin AS \"%s\",\n" + " seqmax AS \"%s\",\n" + " seqincrement AS \"%s\",\n" + " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" + " seqcache AS \"%s\"\n", + gettext_noop("Type"), + gettext_noop("Start"), + gettext_noop("Minimum"), + gettext_noop("Maximum"), + gettext_noop("Increment"), + gettext_noop("yes"), + gettext_noop("no"), + gettext_noop("Cycles?"), + gettext_noop("Cache")); + appendPQExpBuffer(&buf, + "FROM pg_catalog.pg_sequence\n" + "WHERE seqrelid = '%s';", + oid); res = PSQLexec(buf.data); if (!res) @@ -1913,7 +1913,7 @@ describeOneTableDetails(const char *schemaname, appendPQExpBufferStr(&buf, ",\n (SELECT c.collname FROM pg_catalog.pg_collation c, pg_catalog.pg_type t\n" " WHERE c.oid = a.attcollation AND t.oid = a.atttypid AND a.attcollation <> t.typcollation) AS attcollation"); attcoll_col = cols++; - appendPQExpBufferStr(&buf, ",\n a.attidentity"); + appendPQExpBufferStr(&buf, ",\n a.attidentity"); attidentity_col = cols++; if (pset.sversion >= 120000) appendPQExpBufferStr(&buf, ",\n a.attgenerated"); @@ -2326,7 +2326,7 @@ describeOneTableDetails(const char *schemaname, CppAsString2(CONSTRAINT_EXCLUSION) ") AND " "condeferred) AS condeferred,\n"); - appendPQExpBufferStr(&buf, "i.indisreplident,\n"); + appendPQExpBufferStr(&buf, "i.indisreplident,\n"); if (pset.sversion >= 150000) appendPQExpBufferStr(&buf, "i.indnullsnotdistinct,\n"); @@ -2431,7 +2431,7 @@ describeOneTableDetails(const char *schemaname, "pg_catalog.pg_get_indexdef(i.indexrelid, 0, true),\n " "pg_catalog.pg_get_constraintdef(con.oid, true), " "contype, condeferrable, condeferred"); - appendPQExpBufferStr(&buf, ", i.indisreplident"); + appendPQExpBufferStr(&buf, ", i.indisreplident"); appendPQExpBufferStr(&buf, ", c2.reltablespace"); if (pset.sversion >= 180000) appendPQExpBufferStr(&buf, ", con.conperiod"); @@ -2682,81 +2682,80 @@ describeOneTableDetails(const char *schemaname, PQclear(result); /* print any row-level policies */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get row-level policies for this table")); - appendPQExpBufferStr(&buf, "SELECT pol.polname,"); - appendPQExpBufferStr(&buf, - " pol.polpermissive,\n"); - appendPQExpBuffer(&buf, - " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" - " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" - " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" - " CASE pol.polcmd\n" - " WHEN 'r' THEN 'SELECT'\n" - " WHEN 'a' THEN 'INSERT'\n" - " WHEN 'w' THEN 'UPDATE'\n" - " WHEN 'd' THEN 'DELETE'\n" - " END AS cmd\n" - "FROM pg_catalog.pg_policy pol\n" - "WHERE pol.polrelid = '%s' ORDER BY 1;", - oid); + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get row-level policies for this table")); + appendPQExpBufferStr(&buf, "SELECT pol.polname,"); + appendPQExpBufferStr(&buf, + " pol.polpermissive,\n"); + appendPQExpBuffer(&buf, + " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" + " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" + " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" + " CASE pol.polcmd\n" + " WHEN 'r' THEN 'SELECT'\n" + " WHEN 'a' THEN 'INSERT'\n" + " WHEN 'w' THEN 'UPDATE'\n" + " WHEN 'd' THEN 'DELETE'\n" + " END AS cmd\n" + "FROM pg_catalog.pg_policy pol\n" + "WHERE pol.polrelid = '%s' ORDER BY 1;", + oid); - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - /* - * Handle cases where RLS is enabled and there are policies, or - * there aren't policies, or RLS isn't enabled but there are - * policies - */ - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies:")); + /* + * Handle cases where RLS is enabled and there are policies, or there + * aren't policies, or RLS isn't enabled but there are policies + */ + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies:")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled):")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled):")); - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); - if (!tableinfo.rowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (row security disabled):")); + if (!tableinfo.rowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (row security disabled):")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " POLICY \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " POLICY \"%s\"", + PQgetvalue(result, i, 0)); - if (*(PQgetvalue(result, i, 1)) == 'f') - appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); + if (*(PQgetvalue(result, i, 1)) == 'f') + appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); - if (!PQgetisnull(result, i, 5)) - appendPQExpBuffer(&buf, " FOR %s", - PQgetvalue(result, i, 5)); + if (!PQgetisnull(result, i, 5)) + appendPQExpBuffer(&buf, " FOR %s", + PQgetvalue(result, i, 5)); - if (!PQgetisnull(result, i, 2)) - { - appendPQExpBuffer(&buf, "\n TO %s", - PQgetvalue(result, i, 2)); - } + if (!PQgetisnull(result, i, 2)) + { + appendPQExpBuffer(&buf, "\n TO %s", + PQgetvalue(result, i, 2)); + } - if (!PQgetisnull(result, i, 3)) - appendPQExpBuffer(&buf, "\n USING (%s)", - PQgetvalue(result, i, 3)); + if (!PQgetisnull(result, i, 3)) + appendPQExpBuffer(&buf, "\n USING (%s)", + PQgetvalue(result, i, 3)); - if (!PQgetisnull(result, i, 4)) - appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", - PQgetvalue(result, i, 4)); + if (!PQgetisnull(result, i, 4)) + appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", + PQgetvalue(result, i, 4)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* print any extended statistics */ if (pset.sversion >= 140000) @@ -3025,115 +3024,115 @@ describeOneTableDetails(const char *schemaname, } /* print any publications */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get publications that publish this table")); - if (pset.sversion >= 150000) + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get publications that publish this table")); + if (pset.sversion >= 150000) + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" + " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" + "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" + "UNION\n" + "SELECT pubname\n" + " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" + " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" + " (SELECT pg_catalog.string_agg(attname, ', ')\n" + " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" + " pg_catalog.pg_attribute\n" + " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" + " ELSE NULL END) " + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" + "WHERE pr.prrelid = '%s'\n", + oid, oid, oid); + + if (pset.sversion >= 190000) { + /* + * Skip entries where this relation appears in the + * publication's EXCEPT list. + */ appendPQExpBuffer(&buf, + " AND NOT pr.prexcept\n" + "UNION\n" "SELECT pubname\n" " , NULL\n" " , NULL\n" "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" - " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" - "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" - "UNION\n" - "SELECT pubname\n" - " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" - " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" - " (SELECT pg_catalog.string_agg(attname, ', ')\n" - " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" - " pg_catalog.pg_attribute\n" - " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" - " ELSE NULL END) " - "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" - "WHERE pr.prrelid = '%s'\n", + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + " AND NOT EXISTS (\n" + " SELECT 1\n" + " FROM pg_catalog.pg_publication_rel pr\n" + " WHERE pr.prpubid = p.oid AND\n" + " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" + "ORDER BY 1;", oid, oid, oid); - - if (pset.sversion >= 190000) - { - /* - * Skip entries where this relation appears in the - * publication's EXCEPT list. - */ - appendPQExpBuffer(&buf, - " AND NOT pr.prexcept\n" - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - " AND NOT EXISTS (\n" - " SELECT 1\n" - " FROM pg_catalog.pg_publication_rel pr\n" - " WHERE pr.prpubid = p.oid AND\n" - " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" - "ORDER BY 1;", - oid, oid, oid); - } - else - { - appendPQExpBuffer(&buf, - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - "ORDER BY 1;", - oid); - } } else { appendPQExpBuffer(&buf, + "UNION\n" "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - "WHERE pr.prrelid = '%s'\n" - "UNION ALL\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" + " , NULL\n" + " , NULL\n" "FROM pg_catalog.pg_publication p\n" "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" "ORDER BY 1;", - oid, oid); + oid); } + } + else + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + "WHERE pr.prrelid = '%s'\n" + "UNION ALL\n" + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + "ORDER BY 1;", + oid, oid); + } - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - if (tuples > 0) - printTableAddFooter(&cont, _("Included in publications:")); + if (tuples > 0) + printTableAddFooter(&cont, _("Included in publications:")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " \"%s\"", + PQgetvalue(result, i, 0)); - /* column list (if any) */ - if (!PQgetisnull(result, i, 2)) - appendPQExpBuffer(&buf, " (%s)", - PQgetvalue(result, i, 2)); + /* column list (if any) */ + if (!PQgetisnull(result, i, 2)) + appendPQExpBuffer(&buf, " (%s)", + PQgetvalue(result, i, 2)); - /* row filter (if any) */ - if (!PQgetisnull(result, i, 1)) - appendPQExpBuffer(&buf, " WHERE %s", - PQgetvalue(result, i, 1)); + /* row filter (if any) */ + if (!PQgetisnull(result, i, 1)) + appendPQExpBuffer(&buf, " WHERE %s", + PQgetvalue(result, i, 1)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* Print publications where the table is in the EXCEPT clause */ if (pset.sversion >= 190000) @@ -3805,7 +3804,7 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) ncols++; } appendPQExpBufferStr(&buf, "\n, r.rolreplication"); - appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); + appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_roles r\n"); @@ -3860,8 +3859,8 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) if (strcmp(PQgetvalue(res, i, (verbose ? 9 : 8)), "t") == 0) add_role_attribute(&buf, _("Replication")); - if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) - add_role_attribute(&buf, _("Bypass RLS")); + if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) + add_role_attribute(&buf, _("Bypass RLS")); conns = atoi(PQgetvalue(res, i, 6)); if (conns >= 0) @@ -5155,14 +5154,14 @@ listCollations(const char *pattern, bool verbose, bool showSystem) gettext_noop("Schema"), gettext_noop("Name")); - appendPQExpBuffer(&buf, - " CASE c.collprovider " - "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " - "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " - "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " - "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " - "END AS \"%s\",\n", - gettext_noop("Provider")); + appendPQExpBuffer(&buf, + " CASE c.collprovider " + "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " + "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " + "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " + "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " + "END AS \"%s\",\n", + gettext_noop("Provider")); appendPQExpBuffer(&buf, " c.collcollate AS \"%s\",\n" -- 2.50.1 (Apple Git-155) --aHl3HfeiUuO3zeNC-- ^ permalink raw reply [nested|flat] 59+ messages in thread
* [PATCH v6 4/4] run pgindent and pgperltidy @ 2026-06-30 18:24 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 59+ messages in thread From: Nathan Bossart @ 2026-06-30 18:24 UTC (permalink / raw) --- src/bin/pg_dump/pg_dump.c | 464 ++++++++++----------- src/bin/pg_dump/pg_dumpall.c | 30 +- src/bin/pg_upgrade/check.c | 16 +- src/bin/pg_upgrade/controldata.c | 2 +- src/bin/pg_upgrade/exec.c | 8 +- src/bin/pg_upgrade/multixact_rewrite.c | 80 ++-- src/bin/pg_upgrade/pg_upgrade.c | 34 +- src/bin/pg_upgrade/relfilenumber.c | 54 +-- src/bin/pg_upgrade/t/006_transfer_modes.pl | 33 +- src/bin/psql/command.c | 29 +- src/bin/psql/describe.c | 461 ++++++++++---------- 11 files changed, 601 insertions(+), 610 deletions(-) diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 65bd15ebfd2..5673268b467 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -1491,8 +1491,8 @@ setup_connection(Archive *AH, const char *dumpencoding, * Disable timeouts if supported. */ ExecuteSqlStatement(AH, "SET statement_timeout = 0"); - ExecuteSqlStatement(AH, "SET lock_timeout = 0"); - ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); + ExecuteSqlStatement(AH, "SET lock_timeout = 0"); + ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); if (AH->remoteVersion >= 170000) ExecuteSqlStatement(AH, "SET transaction_timeout = 0"); @@ -1505,10 +1505,10 @@ setup_connection(Archive *AH, const char *dumpencoding, /* * Adjust row-security mode, if supported. */ - if (dopt->enable_row_security) - ExecuteSqlStatement(AH, "SET row_security = on"); - else - ExecuteSqlStatement(AH, "SET row_security = off"); + if (dopt->enable_row_security) + ExecuteSqlStatement(AH, "SET row_security = on"); + else + ExecuteSqlStatement(AH, "SET row_security = off"); /* * For security reasons, we restrict the expansion of non-system views and @@ -1933,10 +1933,9 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) addObjectDependency(dobj, ext->dobj.dumpId); /* - * Mark the member object to have any non-initial ACLs - * dumped. (Any initial ACLs will be removed later, using data from - * pg_init_privs, so that we'll dump only the delta from the extension's - * initial setup.) + * Mark the member object to have any non-initial ACLs dumped. (Any + * initial ACLs will be removed later, using data from pg_init_privs, so + * that we'll dump only the delta from the extension's initial setup.) * * In binary upgrades, we still dump all components of the members * individually, since the idea is to exactly reproduce the database @@ -1953,7 +1952,7 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) if (fout->dopt->binary_upgrade) dobj->dump = ext->dobj.dump; else - dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); + dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); return true; } @@ -1987,9 +1986,9 @@ selectDumpableNamespace(NamespaceInfo *nsinfo, Archive *fout) else if (strcmp(nsinfo->dobj.name, "pg_catalog") == 0) { /* - * We dump out any ACLs defined in pg_catalog, if - * they are interesting (and not the original ACLs which were set at - * initdb time, see pg_init_privs). + * We dump out any ACLs defined in pg_catalog, if they are interesting + * (and not the original ACLs which were set at initdb time, see + * pg_init_privs). */ nsinfo->dobj.dump_contains = nsinfo->dobj.dump = DUMP_COMPONENT_ACL; } @@ -3296,7 +3295,7 @@ dumpDatabase(Archive *fout) "datcollate, datctype, datfrozenxid, " "datacl, acldefault('d', datdba) AS acldefault, " "datistemplate, datconnlimit, "); - appendPQExpBufferStr(dbQry, "datminmxid, "); + appendPQExpBufferStr(dbQry, "datminmxid, "); if (fout->remoteVersion >= 170000) appendPQExpBufferStr(dbQry, "datlocprovider, datlocale, datcollversion, "); else if (fout->remoteVersion >= 150000) @@ -3638,11 +3637,11 @@ dumpDatabase(Archive *fout) ii_oid, ii_relminmxid; - appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" - "FROM pg_catalog.pg_class\n" - "WHERE oid IN (%u, %u, %u, %u);\n", - LargeObjectRelationId, LargeObjectLOidPNIndexId, - LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); + appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" + "FROM pg_catalog.pg_class\n" + "WHERE oid IN (%u, %u, %u, %u);\n", + LargeObjectRelationId, LargeObjectLOidPNIndexId, + LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); lo_res = ExecuteSqlQuery(fout, loFrozenQry->data, PGRES_TUPLES_OK); @@ -4274,7 +4273,7 @@ getPolicies(Archive *fout, TableInfo tblinfo[], int numTables) printfPQExpBuffer(query, "SELECT pol.oid, pol.tableoid, pol.polrelid, pol.polname, pol.polcmd, "); - appendPQExpBufferStr(query, "pol.polpermissive, "); + appendPQExpBufferStr(query, "pol.polpermissive, "); appendPQExpBuffer(query, "CASE WHEN pol.polroles = '{0}' THEN NULL ELSE " " pg_catalog.array_to_string(ARRAY(SELECT pg_catalog.quote_ident(rolname) from pg_catalog.pg_roles WHERE oid = ANY(pol.polroles)), ', ') END AS polroles, " @@ -6633,9 +6632,9 @@ getAccessMethods(Archive *fout) * Select all access methods from pg_am table. */ appendPQExpBufferStr(query, "SELECT tableoid, oid, amname, "); - appendPQExpBufferStr(query, - "amtype, " - "amhandler::pg_catalog.regproc AS amhandler "); + appendPQExpBufferStr(query, + "amtype, " + "amhandler::pg_catalog.regproc AS amhandler "); appendPQExpBufferStr(query, "FROM pg_am"); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6827,35 +6826,35 @@ getAggregates(Archive *fout) * Find all interesting aggregates. See comment in getFuncs() for the * rationale behind the filtering logic. */ - agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" - : "p.proisagg"); + agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" + : "p.proisagg"); - appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " - "p.proname AS aggname, " - "p.pronamespace AS aggnamespace, " - "p.pronargs, p.proargtypes, " - "p.proowner, " - "p.proacl AS aggacl, " - "acldefault('f', p.proowner) AS acldefault " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s AND (" - "p.pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog') OR " - "p.proacl IS DISTINCT FROM pip.initprivs", - agg_check); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - " OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); - appendPQExpBufferChar(query, ')'); + appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " + "p.proname AS aggname, " + "p.pronamespace AS aggnamespace, " + "p.pronargs, p.proargtypes, " + "p.proowner, " + "p.proacl AS aggacl, " + "acldefault('f', p.proowner) AS acldefault " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s AND (" + "p.pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog') OR " + "p.proacl IS DISTINCT FROM pip.initprivs", + agg_check); + if (dopt->binary_upgrade) + appendPQExpBufferStr(query, + " OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6957,53 +6956,53 @@ getFuncs(Archive *fout) * include them, since we want to dump extension members individually in * that mode. Also, if they are used by casts or transforms then we need * to gather the information about them, though they won't be dumped if - * they are built-in. Also, include functions in - * pg_catalog if they have an ACL different from what's shown in - * pg_init_privs (so we have to join to pg_init_privs; annoying). + * they are built-in. Also, include functions in pg_catalog if they have + * an ACL different from what's shown in pg_init_privs (so we have to join + * to pg_init_privs; annoying). */ - not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" - : "NOT p.proisagg"); + not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" + : "NOT p.proisagg"); - appendPQExpBuffer(query, - "SELECT p.tableoid, p.oid, p.proname, p.prolang, " - "p.pronargs, p.proargtypes, p.prorettype, " - "p.proacl, " - "acldefault('f', p.proowner) AS acldefault, " - "p.pronamespace, " - "p.proowner " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s" - "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " - "WHERE classid = 'pg_proc'::regclass AND " - "objid = p.oid AND deptype = 'i')" - "\n AND (" - "\n pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog')" - "\n OR EXISTS (SELECT 1 FROM pg_cast" - "\n WHERE pg_cast.oid > %u " - "\n AND p.oid = pg_cast.castfunc)" - "\n OR EXISTS (SELECT 1 FROM pg_transform" - "\n WHERE pg_transform.oid > %u AND " - "\n (p.oid = pg_transform.trffromsql" - "\n OR p.oid = pg_transform.trftosql))", - not_agg_check, - g_last_builtin_oid, - g_last_builtin_oid); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); + appendPQExpBuffer(query, + "SELECT p.tableoid, p.oid, p.proname, p.prolang, " + "p.pronargs, p.proargtypes, p.prorettype, " + "p.proacl, " + "acldefault('f', p.proowner) AS acldefault, " + "p.pronamespace, " + "p.proowner " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s" + "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " + "WHERE classid = 'pg_proc'::regclass AND " + "objid = p.oid AND deptype = 'i')" + "\n AND (" + "\n pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog')" + "\n OR EXISTS (SELECT 1 FROM pg_cast" + "\n WHERE pg_cast.oid > %u " + "\n AND p.oid = pg_cast.castfunc)" + "\n OR EXISTS (SELECT 1 FROM pg_transform" + "\n WHERE pg_transform.oid > %u AND " + "\n (p.oid = pg_transform.trffromsql" + "\n OR p.oid = pg_transform.trftosql))", + not_agg_check, + g_last_builtin_oid, + g_last_builtin_oid); + if (dopt->binary_upgrade) appendPQExpBufferStr(query, - "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); - appendPQExpBufferChar(query, ')'); + "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferStr(query, + "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -7252,31 +7251,31 @@ getTables(Archive *fout, int *numTables) appendPQExpBufferStr(query, "c.relhasoids, "); - appendPQExpBufferStr(query, - "c.relispopulated, "); + appendPQExpBufferStr(query, + "c.relispopulated, "); - appendPQExpBufferStr(query, - "c.relreplident, "); + appendPQExpBufferStr(query, + "c.relreplident, "); - appendPQExpBufferStr(query, - "c.relrowsecurity, c.relforcerowsecurity, "); + appendPQExpBufferStr(query, + "c.relrowsecurity, c.relforcerowsecurity, "); - appendPQExpBufferStr(query, - "c.relminmxid, tc.relminmxid AS tminmxid, "); + appendPQExpBufferStr(query, + "c.relminmxid, tc.relminmxid AS tminmxid, "); - appendPQExpBufferStr(query, - "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); + appendPQExpBufferStr(query, + "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); - appendPQExpBufferStr(query, - "am.amname, "); + appendPQExpBufferStr(query, + "am.amname, "); - appendPQExpBufferStr(query, - "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); + appendPQExpBufferStr(query, + "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); - appendPQExpBufferStr(query, - "c.relispartition AS ispartition "); + appendPQExpBufferStr(query, + "c.relispartition AS ispartition "); /* * Left join to pg_depend to pick up dependency info linking sequences to @@ -7296,8 +7295,8 @@ getTables(Archive *fout, int *numTables) /* * Left join to pg_am to pick up the amname. */ - appendPQExpBufferStr(query, - "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); + appendPQExpBufferStr(query, + "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); /* * We purposefully ignore toast OIDs for partitioned tables; the reason is @@ -7868,8 +7867,8 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables) "t.reloptions AS indreloptions, "); - appendPQExpBufferStr(query, - "i.indisreplident, "); + appendPQExpBufferStr(query, + "i.indisreplident, "); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -9313,8 +9312,8 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables) appendPQExpBufferStr(q, "'' AS attcompression,\n"); - appendPQExpBufferStr(q, - "a.attidentity,\n"); + appendPQExpBufferStr(q, + "a.attidentity,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(q, @@ -10717,73 +10716,73 @@ getAdditionalACLs(Archive *fout) PQclear(res); /* Fetch initial-privileges data */ - printfPQExpBuffer(query, - "SELECT objoid, classoid, objsubid, privtype, initprivs " - "FROM pg_init_privs"); + printfPQExpBuffer(query, + "SELECT objoid, classoid, objsubid, privtype, initprivs " + "FROM pg_init_privs"); - res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); + res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); - ntups = PQntuples(res); - for (i = 0; i < ntups; i++) - { - Oid objoid = atooid(PQgetvalue(res, i, 0)); - Oid classoid = atooid(PQgetvalue(res, i, 1)); - int objsubid = atoi(PQgetvalue(res, i, 2)); - char privtype = *(PQgetvalue(res, i, 3)); - char *initprivs = PQgetvalue(res, i, 4); - CatalogId objId; - DumpableObject *dobj; + ntups = PQntuples(res); + for (i = 0; i < ntups; i++) + { + Oid objoid = atooid(PQgetvalue(res, i, 0)); + Oid classoid = atooid(PQgetvalue(res, i, 1)); + int objsubid = atoi(PQgetvalue(res, i, 2)); + char privtype = *(PQgetvalue(res, i, 3)); + char *initprivs = PQgetvalue(res, i, 4); + CatalogId objId; + DumpableObject *dobj; - objId.tableoid = classoid; - objId.oid = objoid; - dobj = findObjectByCatalogId(objId); - /* OK to ignore entries we haven't got a DumpableObject for */ - if (dobj) + objId.tableoid = classoid; + objId.oid = objoid; + dobj = findObjectByCatalogId(objId); + /* OK to ignore entries we haven't got a DumpableObject for */ + if (dobj) + { + /* Cope with sub-object initprivs */ + if (objsubid != 0) { - /* Cope with sub-object initprivs */ - if (objsubid != 0) - { - if (dobj->objType == DO_TABLE) - { - /* For a column initprivs, set the table's ACL flags */ - dobj->components |= DUMP_COMPONENT_ACL; - ((TableInfo *) dobj)->hascolumnACLs = true; - } - else - pg_log_warning("unsupported pg_init_privs entry: %u %u %d", - classoid, objoid, objsubid); - continue; - } - - /* - * We ignore any pg_init_privs.initprivs entry for the public - * schema, as explained in getNamespaces(). - */ - if (dobj->objType == DO_NAMESPACE && - strcmp(dobj->name, "public") == 0) - continue; - - /* Else it had better be of a type we think has ACLs */ - if (dobj->objType == DO_NAMESPACE || - dobj->objType == DO_TYPE || - dobj->objType == DO_FUNC || - dobj->objType == DO_AGG || - dobj->objType == DO_TABLE || - dobj->objType == DO_PROCLANG || - dobj->objType == DO_FDW || - dobj->objType == DO_FOREIGN_SERVER) + if (dobj->objType == DO_TABLE) { - DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; - - daobj->dacl.privtype = privtype; - daobj->dacl.initprivs = pstrdup(initprivs); + /* For a column initprivs, set the table's ACL flags */ + dobj->components |= DUMP_COMPONENT_ACL; + ((TableInfo *) dobj)->hascolumnACLs = true; } else pg_log_warning("unsupported pg_init_privs entry: %u %u %d", classoid, objoid, objsubid); + continue; + } + + /* + * We ignore any pg_init_privs.initprivs entry for the public + * schema, as explained in getNamespaces(). + */ + if (dobj->objType == DO_NAMESPACE && + strcmp(dobj->name, "public") == 0) + continue; + + /* Else it had better be of a type we think has ACLs */ + if (dobj->objType == DO_NAMESPACE || + dobj->objType == DO_TYPE || + dobj->objType == DO_FUNC || + dobj->objType == DO_AGG || + dobj->objType == DO_TABLE || + dobj->objType == DO_PROCLANG || + dobj->objType == DO_FDW || + dobj->objType == DO_FOREIGN_SERVER) + { + DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; + + daobj->dacl.privtype = privtype; + daobj->dacl.initprivs = pstrdup(initprivs); } + else + pg_log_warning("unsupported pg_init_privs entry: %u %u %d", + classoid, objoid, objsubid); } - PQclear(res); + } + PQclear(res); destroyPQExpBuffer(query); } @@ -11128,8 +11127,8 @@ dumpRelationStats_dumper(Archive *fout, const void *userArg, const TocEntry *te) * The results must be in the order of the relations supplied in the * parameters to ensure we remain in sync as we walk through the TOC. * - * For versions before 19, the redundant filter clause on s.tablename = - * ANY(...) seems sufficient to convince the planner to use + * For versions before 19, the redundant filter clause on s.tablename + * = ANY(...) seems sufficient to convince the planner to use * pg_class_relname_nsp_index, which avoids a full scan of pg_stats. * In newer versions, pg_stats returns the table OIDs, eliminating the * need for that hack. @@ -13469,11 +13468,11 @@ dumpFunc(Archive *fout, const FuncInfo *finfo) "pg_catalog.pg_get_function_result(p.oid) AS funcresult,\n" "proleakproof,\n"); - appendPQExpBufferStr(query, - "array_to_string(protrftypes, ' ') AS protrftypes,\n"); + appendPQExpBufferStr(query, + "array_to_string(protrftypes, ' ') AS protrftypes,\n"); - appendPQExpBufferStr(query, - "proparallel,\n"); + appendPQExpBufferStr(query, + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -14963,9 +14962,9 @@ dumpCollation(Archive *fout, const CollInfo *collinfo) /* Get collation-specific details */ appendPQExpBufferStr(query, "SELECT "); - appendPQExpBufferStr(query, - "collprovider, " - "collversion, "); + appendPQExpBufferStr(query, + "collprovider, " + "collversion, "); if (fout->remoteVersion >= 120000) appendPQExpBufferStr(query, @@ -15372,23 +15371,23 @@ dumpAgg(Archive *fout, const AggInfo *agginfo) "pg_catalog.pg_get_function_arguments(p.oid) AS funcargs,\n" "pg_catalog.pg_get_function_identity_arguments(p.oid) AS funciargs,\n"); - appendPQExpBufferStr(query, - "aggkind,\n" - "aggmtransfn,\n" - "aggminvtransfn,\n" - "aggmfinalfn,\n" - "aggmtranstype::pg_catalog.regtype,\n" - "aggfinalextra,\n" - "aggmfinalextra,\n" - "aggtransspace,\n" - "aggmtransspace,\n" - "aggminitval,\n"); + appendPQExpBufferStr(query, + "aggkind,\n" + "aggmtransfn,\n" + "aggminvtransfn,\n" + "aggmfinalfn,\n" + "aggmtranstype::pg_catalog.regtype,\n" + "aggfinalextra,\n" + "aggmfinalextra,\n" + "aggtransspace,\n" + "aggmtransspace,\n" + "aggminitval,\n"); - appendPQExpBufferStr(query, - "aggcombinefn,\n" - "aggserialfn,\n" - "aggdeserialfn,\n" - "proparallel,\n"); + appendPQExpBufferStr(query, + "aggcombinefn,\n" + "aggserialfn,\n" + "aggdeserialfn,\n" + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -16848,30 +16847,30 @@ dumpTable(Archive *fout, const TableInfo *tbinfo) appendPQExpBufferStr(query, "PREPARE getColumnACLs(pg_catalog.oid) AS\n"); - /* - * In principle we should call acldefault('c', relowner) to - * get the default ACL for a column. However, we don't - * currently store the numeric OID of the relowner in - * TableInfo. We could convert the owner name using regrole, - * but that creates a risk of failure due to concurrent role - * renames. Given that the default ACL for columns is empty - * and is likely to stay that way, it's not worth extra cycles - * and risk to avoid hard-wiring that knowledge here. - */ - appendPQExpBufferStr(query, - "SELECT at.attname, " - "at.attacl, " - "'{}' AS acldefault, " - "pip.privtype, pip.initprivs " - "FROM pg_catalog.pg_attribute at " - "LEFT JOIN pg_catalog.pg_init_privs pip ON " - "(at.attrelid = pip.objoid " - "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " - "AND at.attnum = pip.objsubid) " - "WHERE at.attrelid = $1 AND " - "NOT at.attisdropped " - "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " - "ORDER BY at.attnum"); + /* + * In principle we should call acldefault('c', relowner) to get + * the default ACL for a column. However, we don't currently + * store the numeric OID of the relowner in TableInfo. We could + * convert the owner name using regrole, but that creates a risk + * of failure due to concurrent role renames. Given that the + * default ACL for columns is empty and is likely to stay that + * way, it's not worth extra cycles and risk to avoid hard-wiring + * that knowledge here. + */ + appendPQExpBufferStr(query, + "SELECT at.attname, " + "at.attacl, " + "'{}' AS acldefault, " + "pip.privtype, pip.initprivs " + "FROM pg_catalog.pg_attribute at " + "LEFT JOIN pg_catalog.pg_init_privs pip ON " + "(at.attrelid = pip.objoid " + "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " + "AND at.attnum = pip.objsubid) " + "WHERE at.attrelid = $1 AND " + "NOT at.attisdropped " + "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " + "ORDER BY at.attnum"); ExecuteSqlStatement(fout, query->data); @@ -19165,7 +19164,7 @@ collectSequences(Archive *fout) * pg_get_sequence_data(), but we only do so for non-schema-only dumps. */ if (fout->remoteVersion < 180000 || - (!fout->dopt->dumpData && !fout->dopt->sequence_data)) + (!fout->dopt->dumpData && !fout->dopt->sequence_data)) query = "SELECT seqrelid, format_type(seqtypid, NULL), " "seqstart, seqincrement, " "seqmax, seqmin, " @@ -19227,15 +19226,14 @@ dumpSequence(Archive *fout, const TableInfo *tbinfo) qseqname = pg_strdup(fmtId(tbinfo->dobj.name)); /* - * The sequence information is gathered in a sorted - * table before any calls to dumpSequence(). See collectSequences() for - * more information. + * The sequence information is gathered in a sorted table before any calls + * to dumpSequence(). See collectSequences() for more information. */ - Assert(sequences); + Assert(sequences); - key.oid = tbinfo->dobj.catId.oid; - seq = bsearch(&key, sequences, nsequences, - sizeof(SequenceItem), SequenceItemCmp); + key.oid = tbinfo->dobj.catId.oid; + seq = bsearch(&key, sequences, nsequences, + sizeof(SequenceItem), SequenceItemCmp); /* Calculate default limits for a sequence of this type */ is_ascending = (seq->incby >= 0); diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c index e68937c9934..afcd9a218d8 100644 --- a/src/bin/pg_dump/pg_dumpall.c +++ b/src/bin/pg_dump/pg_dumpall.c @@ -785,11 +785,11 @@ dropRoles(PGconn *conn) int i_rolname; int i; - printfPQExpBuffer(buf, - "SELECT rolname " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 1", role_catalog); + printfPQExpBuffer(buf, + "SELECT rolname " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 1", role_catalog); res = executeQuery(conn, buf->data); @@ -843,16 +843,16 @@ dumpRoles(PGconn *conn) * Notes: rolconfig is dumped later, and pg_authid must be used for * extracting rolcomment regardless of role_catalog. */ - printfPQExpBuffer(buf, - "SELECT oid, rolname, rolsuper, rolinherit, " - "rolcreaterole, rolcreatedb, " - "rolcanlogin, rolconnlimit, rolpassword, " - "rolvaliduntil, rolreplication, rolbypassrls, " - "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " - "rolname = current_user AS is_current_user " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 2", role_catalog); + printfPQExpBuffer(buf, + "SELECT oid, rolname, rolsuper, rolinherit, " + "rolcreaterole, rolcreatedb, " + "rolcanlogin, rolconnlimit, rolpassword, " + "rolvaliduntil, rolreplication, rolbypassrls, " + "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " + "rolname = current_user AS is_current_user " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 2", role_catalog); res = executeQuery(conn, buf->data); diff --git a/src/bin/pg_upgrade/check.c b/src/bin/pg_upgrade/check.c index 786c1474829..f725f5ee3e2 100644 --- a/src/bin/pg_upgrade/check.c +++ b/src/bin/pg_upgrade/check.c @@ -1475,15 +1475,15 @@ check_for_incompatible_polymorphics(ClusterInfo *cluster) ", 'array_cat(anyarray,anyarray)'" ", 'array_prepend(anyelement,anyarray)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_remove(anyarray,anyelement)'" - ", 'array_replace(anyarray,anyelement,anyelement)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_remove(anyarray,anyelement)'" + ", 'array_replace(anyarray,anyelement,anyelement)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_position(anyarray,anyelement)'" - ", 'array_position(anyarray,anyelement,integer)'" - ", 'array_positions(anyarray,anyelement)'" - ", 'width_bucket(anyelement,anyarray)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_position(anyarray,anyelement)'" + ", 'array_position(anyarray,anyelement,integer)'" + ", 'array_positions(anyarray,anyelement)'" + ", 'width_bucket(anyelement,anyarray)'"); /* * The query below hardcodes FirstNormalObjectId as 16384 rather than diff --git a/src/bin/pg_upgrade/controldata.c b/src/bin/pg_upgrade/controldata.c index 8f81c9e9582..02ea02df60f 100644 --- a/src/bin/pg_upgrade/controldata.c +++ b/src/bin/pg_upgrade/controldata.c @@ -228,7 +228,7 @@ get_control_data(ClusterInfo *cluster) p++; /* remove ':' char */ cluster->controldata.chkpnt_nxtepoch = str2uint(p); - p = strchr(p, ':'); + p = strchr(p, ':'); if (p == NULL || strlen(p) <= 1) pg_fatal("%d: controldata retrieval problem", __LINE__); diff --git a/src/bin/pg_upgrade/exec.c b/src/bin/pg_upgrade/exec.c index 44355feea30..a1bdbf373e3 100644 --- a/src/bin/pg_upgrade/exec.c +++ b/src/bin/pg_upgrade/exec.c @@ -55,7 +55,7 @@ get_bin_version(ClusterInfo *cluster) if (sscanf(cmd_output, "%*s %*s %d.%d", &v1, &v2) < 1) pg_fatal("could not get pg_ctl version output from %s", cmd); - cluster->bin_version = v1 * 10000; + cluster->bin_version = v1 * 10000; } @@ -344,8 +344,8 @@ check_data_dir(ClusterInfo *cluster) check_single_dir(pg_data, "pg_subtrans"); check_single_dir(pg_data, PG_TBLSPC_DIR); check_single_dir(pg_data, "pg_twophase"); - check_single_dir(pg_data, "pg_wal"); - check_single_dir(pg_data, "pg_xact"); + check_single_dir(pg_data, "pg_wal"); + check_single_dir(pg_data, "pg_xact"); } @@ -385,7 +385,7 @@ check_bin_dir(ClusterInfo *cluster, bool check_versions) */ get_bin_version(cluster); - check_exec(cluster->bindir, "pg_resetwal", check_versions); + check_exec(cluster->bindir, "pg_resetwal", check_versions); if (cluster == &new_cluster) { diff --git a/src/bin/pg_upgrade/multixact_rewrite.c b/src/bin/pg_upgrade/multixact_rewrite.c index c45b3183684..c7a1416494d 100644 --- a/src/bin/pg_upgrade/multixact_rewrite.c +++ b/src/bin/pg_upgrade/multixact_rewrite.c @@ -61,52 +61,52 @@ rewrite_multixacts(MultiXactId from_multi, MultiXactId to_multi) * Convert old multixids, if needed, by reading them one-by-one from the * old cluster. */ - old_reader = AllocOldMultiXactRead(old_cluster.pgdata, - old_cluster.controldata.chkpnt_nxtmulti, - old_cluster.controldata.chkpnt_nxtmxoff); + old_reader = AllocOldMultiXactRead(old_cluster.pgdata, + old_cluster.controldata.chkpnt_nxtmulti, + old_cluster.controldata.chkpnt_nxtmxoff); - for (MultiXactId multi = from_multi; multi != to_multi;) - { - MultiXactMember member; - bool multixid_valid; - - /* - * Read this multixid's members. - * - * Locking-only XIDs that may be part of multi-xids don't matter - * after upgrade, as there can be no transactions running across - * upgrade. So as a small optimization, we only read one member - * from each multixid: the one updating one, or if there was no - * update, arbitrarily the first locking xid. - */ - multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); + for (MultiXactId multi = from_multi; multi != to_multi;) + { + MultiXactMember member; + bool multixid_valid; - /* - * Write the new offset to pg_multixact/offsets. - * - * Even if this multixid is invalid, we still need to write its - * offset if the *previous* multixid was valid. That's because - * when reading a multixid, the number of members is calculated - * from the difference between the two offsets. - */ - RecordMultiXactOffset(offsets_writer, multi, - (multixid_valid || prev_multixid_valid) ? next_offset : 0); + /* + * Read this multixid's members. + * + * Locking-only XIDs that may be part of multi-xids don't matter after + * upgrade, as there can be no transactions running across upgrade. So + * as a small optimization, we only read one member from each + * multixid: the one updating one, or if there was no update, + * arbitrarily the first locking xid. + */ + multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); - /* Write the members */ - if (multixid_valid) - { - RecordMultiXactMembers(members_writer, next_offset, 1, &member); - next_offset += 1; - } + /* + * Write the new offset to pg_multixact/offsets. + * + * Even if this multixid is invalid, we still need to write its offset + * if the *previous* multixid was valid. That's because when reading + * a multixid, the number of members is calculated from the difference + * between the two offsets. + */ + RecordMultiXactOffset(offsets_writer, multi, + (multixid_valid || prev_multixid_valid) ? next_offset : 0); - /* Advance to next multixid, handling wraparound */ - multi++; - if (multi < FirstMultiXactId) - multi = FirstMultiXactId; - prev_multixid_valid = multixid_valid; + /* Write the members */ + if (multixid_valid) + { + RecordMultiXactMembers(members_writer, next_offset, 1, &member); + next_offset += 1; } - FreeOldMultiXactReader(old_reader); + /* Advance to next multixid, handling wraparound */ + multi++; + if (multi < FirstMultiXactId) + multi = FirstMultiXactId; + prev_multixid_valid = multixid_valid; + } + + FreeOldMultiXactReader(old_reader); /* Write the final 'next' offset to the last SLRU page */ RecordMultiXactOffset(offsets_writer, to_multi, diff --git a/src/bin/pg_upgrade/pg_upgrade.c b/src/bin/pg_upgrade/pg_upgrade.c index c6af9035665..7366fd4627c 100644 --- a/src/bin/pg_upgrade/pg_upgrade.c +++ b/src/bin/pg_upgrade/pg_upgrade.c @@ -833,7 +833,7 @@ copy_xact_xlog_xid(void) * Determine the range of multixacts to convert. */ nxtmulti = old_cluster.controldata.chkpnt_nxtmulti; - oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; + oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; /* handle wraparound */ if (nxtmulti < FirstMultiXactId) nxtmulti = FirstMultiXactId; @@ -898,15 +898,15 @@ set_frozenxids(void) int i_datname; int i_datallowconn; - prep_status("Setting frozenxid and minmxid counters in new cluster"); + prep_status("Setting frozenxid and minmxid counters in new cluster"); conn_template1 = connectToServer(&new_cluster, "template1"); - /* set pg_database.datfrozenxid */ - PQclear(executeQueryOrDie(conn_template1, - "UPDATE pg_catalog.pg_database " - "SET datfrozenxid = '%u'", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_database.datfrozenxid */ + PQclear(executeQueryOrDie(conn_template1, + "UPDATE pg_catalog.pg_database " + "SET datfrozenxid = '%u'", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_database.datminmxid */ PQclear(executeQueryOrDie(conn_template1, @@ -942,16 +942,16 @@ set_frozenxids(void) conn = connectToServer(&new_cluster, datname); - /* set pg_class.relfrozenxid */ - PQclear(executeQueryOrDie(conn, - "UPDATE pg_catalog.pg_class " - "SET relfrozenxid = '%u' " - /* only heap, materialized view, and TOAST are vacuumed */ - "WHERE relkind IN (" - CppAsString2(RELKIND_RELATION) ", " - CppAsString2(RELKIND_MATVIEW) ", " - CppAsString2(RELKIND_TOASTVALUE) ")", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_class.relfrozenxid */ + PQclear(executeQueryOrDie(conn, + "UPDATE pg_catalog.pg_class " + "SET relfrozenxid = '%u' " + /* only heap, materialized view, and TOAST are vacuumed */ + "WHERE relkind IN (" + CppAsString2(RELKIND_RELATION) ", " + CppAsString2(RELKIND_MATVIEW) ", " + CppAsString2(RELKIND_TOASTVALUE) ")", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_class.relminmxid */ PQclear(executeQueryOrDie(conn, diff --git a/src/bin/pg_upgrade/relfilenumber.c b/src/bin/pg_upgrade/relfilenumber.c index ec2ff7acb21..6c467bdc8a5 100644 --- a/src/bin/pg_upgrade/relfilenumber.c +++ b/src/bin/pg_upgrade/relfilenumber.c @@ -587,32 +587,32 @@ transfer_relfile(FileNameMap *map, const char *type_suffix) /* Copying files might take some time, so give feedback. */ pg_log(PG_STATUS, "%s", old_file); - switch (user_opts.transfer_mode) - { - case TRANSFER_MODE_CLONE: - pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", - old_file, new_file); - cloneFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", - old_file, new_file); - copyFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY_FILE_RANGE: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", - old_file, new_file); - copyFileByRange(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_LINK: - pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", - old_file, new_file); - linkFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_SWAP: - /* swap mode is handled in its own code path */ - pg_fatal("should never happen"); - break; - } + switch (user_opts.transfer_mode) + { + case TRANSFER_MODE_CLONE: + pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", + old_file, new_file); + cloneFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", + old_file, new_file); + copyFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY_FILE_RANGE: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", + old_file, new_file); + copyFileByRange(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_LINK: + pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", + old_file, new_file); + linkFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_SWAP: + /* swap mode is handled in its own code path */ + pg_fatal("should never happen"); + break; + } } } diff --git a/src/bin/pg_upgrade/t/006_transfer_modes.pl b/src/bin/pg_upgrade/t/006_transfer_modes.pl index 9efa5dc863c..360d05c4b68 100644 --- a/src/bin/pg_upgrade/t/006_transfer_modes.pl +++ b/src/bin/pg_upgrade/t/006_transfer_modes.pl @@ -29,10 +29,8 @@ sub test_mode } $new->init(); - $new->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); - $old->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); + $new->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); + $old->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); # We can only test security labels if both the old and new installations # have dummy_seclabel. @@ -76,15 +74,14 @@ sub test_mode "CREATE TABLE test4 AS SELECT generate_series(400, 502)"); } - $old->safe_psql('postgres', - "CREATE TABLESPACE inplc_tblspc LOCATION ''"); - $old->safe_psql('postgres', - "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); - $old->safe_psql('postgres', - "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" - ); - $old->safe_psql('testdb3', - "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); + $old->safe_psql('postgres', "CREATE TABLESPACE inplc_tblspc LOCATION ''"); + $old->safe_psql('postgres', + "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); + $old->safe_psql('postgres', + "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" + ); + $old->safe_psql('testdb3', + "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); # While we are here, test handling of large objects. $old->safe_psql( @@ -152,12 +149,10 @@ sub test_mode } # Tests for in-place tablespaces. - $result = - $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); - is($result, '104', "test5 data after pg_upgrade $mode"); - $result = - $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); - is($result, '105', "test6 data after pg_upgrade $mode"); + $result = $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); + is($result, '104', "test5 data after pg_upgrade $mode"); + $result = $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); + is($result, '105', "test6 data after pg_upgrade $mode"); # Tests for large objects $result = $new->safe_psql('postgres', "SELECT lo_get(4532)"); diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index 44ef11d980e..c90bf8bbde2 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -6278,23 +6278,22 @@ get_create_object_cmd(EditableObjectType obj_type, Oid oid, * ensure the right view gets replaced. Also, check relation kind * to be sure it's a view. * - * Views may have WITH [LOCAL|CASCADED] - * CHECK OPTION. These are not part of the view definition - * returned by pg_get_viewdef() and so need to be retrieved - * separately. Materialized views may have - * arbitrary storage parameter reloptions. + * Views may have WITH [LOCAL|CASCADED] CHECK OPTION. These are + * not part of the view definition returned by pg_get_viewdef() + * and so need to be retrieved separately. Materialized views may + * have arbitrary storage parameter reloptions. */ printfPQExpBuffer(query, "/* %s */\n", _("Get view's definition and details")); - appendPQExpBuffer(query, - "SELECT nspname, relname, relkind, " - "pg_catalog.pg_get_viewdef(c.oid, true), " - "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " - "FROM pg_catalog.pg_class c " - "LEFT JOIN pg_catalog.pg_namespace n " - "ON c.relnamespace = n.oid WHERE c.oid = %u", - oid); + appendPQExpBuffer(query, + "SELECT nspname, relname, relkind, " + "pg_catalog.pg_get_viewdef(c.oid, true), " + "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " + "FROM pg_catalog.pg_class c " + "LEFT JOIN pg_catalog.pg_namespace n " + "ON c.relnamespace = n.oid WHERE c.oid = %u", + oid); break; } diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index ce99137c613..ac0c55e7aa5 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -387,19 +387,19 @@ describeFunctions(const char *functypes, const char *func_pattern, gettext_noop("stable"), gettext_noop("volatile"), gettext_noop("Volatility")); - appendPQExpBuffer(&buf, - ",\n CASE\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" - " END as \"%s\"", - gettext_noop("restricted"), - gettext_noop("safe"), - gettext_noop("unsafe"), - gettext_noop("Parallel")); + appendPQExpBuffer(&buf, + ",\n CASE\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" + " END as \"%s\"", + gettext_noop("restricted"), + gettext_noop("safe"), + gettext_noop("unsafe"), + gettext_noop("Parallel")); appendPQExpBuffer(&buf, ",\n pg_catalog.pg_get_userbyid(p.proowner) as \"%s\"" ",\n CASE WHEN prosecdef THEN '%s' ELSE '%s' END AS \"%s\"" @@ -599,8 +599,8 @@ describeFunctions(const char *functypes, const char *func_pattern, myopt.title = _("List of functions"); myopt.translate_header = true; - myopt.translate_columns = translate_columns; - myopt.n_translate_columns = lengthof(translate_columns); + myopt.translate_columns = translate_columns; + myopt.n_translate_columns = lengthof(translate_columns); printQuery(res, &myopt, pset.queryFout, false, pset.logfile); @@ -1086,38 +1086,38 @@ permissionsList(const char *pattern, bool showSystem) " ), E'\\n') AS \"%s\"", gettext_noop("Column privileges")); - appendPQExpBuffer(&buf, - ",\n pg_catalog.array_to_string(ARRAY(\n" - " SELECT polname\n" - " || CASE WHEN NOT polpermissive THEN\n" - " E' (RESTRICTIVE)'\n" - " ELSE '' END\n" - " || CASE WHEN polcmd != '*' THEN\n" - " E' (' || polcmd::pg_catalog.text || E'):'\n" - " ELSE E':'\n" - " END\n" - " || CASE WHEN polqual IS NOT NULL THEN\n" - " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" - " ELSE E''\n" - " END\n" - " || CASE WHEN polwithcheck IS NOT NULL THEN\n" - " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" - " ELSE E''\n" - " END" - " || CASE WHEN polroles <> '{0}' THEN\n" - " E'\\n to: ' || pg_catalog.array_to_string(\n" - " ARRAY(\n" - " SELECT rolname\n" - " FROM pg_catalog.pg_roles\n" - " WHERE oid = ANY (polroles)\n" - " ORDER BY 1\n" - " ), E', ')\n" - " ELSE E''\n" - " END\n" - " FROM pg_catalog.pg_policy pol\n" - " WHERE polrelid = c.oid), E'\\n')\n" - " AS \"%s\"", - gettext_noop("Policies")); + appendPQExpBuffer(&buf, + ",\n pg_catalog.array_to_string(ARRAY(\n" + " SELECT polname\n" + " || CASE WHEN NOT polpermissive THEN\n" + " E' (RESTRICTIVE)'\n" + " ELSE '' END\n" + " || CASE WHEN polcmd != '*' THEN\n" + " E' (' || polcmd::pg_catalog.text || E'):'\n" + " ELSE E':'\n" + " END\n" + " || CASE WHEN polqual IS NOT NULL THEN\n" + " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" + " ELSE E''\n" + " END\n" + " || CASE WHEN polwithcheck IS NOT NULL THEN\n" + " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" + " ELSE E''\n" + " END" + " || CASE WHEN polroles <> '{0}' THEN\n" + " E'\\n to: ' || pg_catalog.array_to_string(\n" + " ARRAY(\n" + " SELECT rolname\n" + " FROM pg_catalog.pg_roles\n" + " WHERE oid = ANY (polroles)\n" + " ORDER BY 1\n" + " ), E', ')\n" + " ELSE E''\n" + " END\n" + " FROM pg_catalog.pg_policy pol\n" + " WHERE polrelid = c.oid), E'\\n')\n" + " AS \"%s\"", + gettext_noop("Policies")); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_class c\n" " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n" @@ -1675,27 +1675,27 @@ describeOneTableDetails(const char *schemaname, char *footers[3] = {NULL, NULL, NULL}; printfPQExpBuffer(&buf, "/* %s */\n", _("Get sequence information")); - appendPQExpBuffer(&buf, - "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" - " seqstart AS \"%s\",\n" - " seqmin AS \"%s\",\n" - " seqmax AS \"%s\",\n" - " seqincrement AS \"%s\",\n" - " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" - " seqcache AS \"%s\"\n", - gettext_noop("Type"), - gettext_noop("Start"), - gettext_noop("Minimum"), - gettext_noop("Maximum"), - gettext_noop("Increment"), - gettext_noop("yes"), - gettext_noop("no"), - gettext_noop("Cycles?"), - gettext_noop("Cache")); - appendPQExpBuffer(&buf, - "FROM pg_catalog.pg_sequence\n" - "WHERE seqrelid = '%s';", - oid); + appendPQExpBuffer(&buf, + "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" + " seqstart AS \"%s\",\n" + " seqmin AS \"%s\",\n" + " seqmax AS \"%s\",\n" + " seqincrement AS \"%s\",\n" + " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" + " seqcache AS \"%s\"\n", + gettext_noop("Type"), + gettext_noop("Start"), + gettext_noop("Minimum"), + gettext_noop("Maximum"), + gettext_noop("Increment"), + gettext_noop("yes"), + gettext_noop("no"), + gettext_noop("Cycles?"), + gettext_noop("Cache")); + appendPQExpBuffer(&buf, + "FROM pg_catalog.pg_sequence\n" + "WHERE seqrelid = '%s';", + oid); res = PSQLexec(buf.data); if (!res) @@ -1913,7 +1913,7 @@ describeOneTableDetails(const char *schemaname, appendPQExpBufferStr(&buf, ",\n (SELECT c.collname FROM pg_catalog.pg_collation c, pg_catalog.pg_type t\n" " WHERE c.oid = a.attcollation AND t.oid = a.atttypid AND a.attcollation <> t.typcollation) AS attcollation"); attcoll_col = cols++; - appendPQExpBufferStr(&buf, ",\n a.attidentity"); + appendPQExpBufferStr(&buf, ",\n a.attidentity"); attidentity_col = cols++; if (pset.sversion >= 120000) appendPQExpBufferStr(&buf, ",\n a.attgenerated"); @@ -2326,7 +2326,7 @@ describeOneTableDetails(const char *schemaname, CppAsString2(CONSTRAINT_EXCLUSION) ") AND " "condeferred) AS condeferred,\n"); - appendPQExpBufferStr(&buf, "i.indisreplident,\n"); + appendPQExpBufferStr(&buf, "i.indisreplident,\n"); if (pset.sversion >= 150000) appendPQExpBufferStr(&buf, "i.indnullsnotdistinct,\n"); @@ -2431,7 +2431,7 @@ describeOneTableDetails(const char *schemaname, "pg_catalog.pg_get_indexdef(i.indexrelid, 0, true),\n " "pg_catalog.pg_get_constraintdef(con.oid, true), " "contype, condeferrable, condeferred"); - appendPQExpBufferStr(&buf, ", i.indisreplident"); + appendPQExpBufferStr(&buf, ", i.indisreplident"); appendPQExpBufferStr(&buf, ", c2.reltablespace"); if (pset.sversion >= 180000) appendPQExpBufferStr(&buf, ", con.conperiod"); @@ -2682,81 +2682,80 @@ describeOneTableDetails(const char *schemaname, PQclear(result); /* print any row-level policies */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get row-level policies for this table")); - appendPQExpBufferStr(&buf, "SELECT pol.polname,"); - appendPQExpBufferStr(&buf, - " pol.polpermissive,\n"); - appendPQExpBuffer(&buf, - " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" - " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" - " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" - " CASE pol.polcmd\n" - " WHEN 'r' THEN 'SELECT'\n" - " WHEN 'a' THEN 'INSERT'\n" - " WHEN 'w' THEN 'UPDATE'\n" - " WHEN 'd' THEN 'DELETE'\n" - " END AS cmd\n" - "FROM pg_catalog.pg_policy pol\n" - "WHERE pol.polrelid = '%s' ORDER BY 1;", - oid); + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get row-level policies for this table")); + appendPQExpBufferStr(&buf, "SELECT pol.polname,"); + appendPQExpBufferStr(&buf, + " pol.polpermissive,\n"); + appendPQExpBuffer(&buf, + " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" + " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" + " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" + " CASE pol.polcmd\n" + " WHEN 'r' THEN 'SELECT'\n" + " WHEN 'a' THEN 'INSERT'\n" + " WHEN 'w' THEN 'UPDATE'\n" + " WHEN 'd' THEN 'DELETE'\n" + " END AS cmd\n" + "FROM pg_catalog.pg_policy pol\n" + "WHERE pol.polrelid = '%s' ORDER BY 1;", + oid); - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - /* - * Handle cases where RLS is enabled and there are policies, or - * there aren't policies, or RLS isn't enabled but there are - * policies - */ - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies:")); + /* + * Handle cases where RLS is enabled and there are policies, or there + * aren't policies, or RLS isn't enabled but there are policies + */ + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies:")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled):")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled):")); - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); - if (!tableinfo.rowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (row security disabled):")); + if (!tableinfo.rowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (row security disabled):")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " POLICY \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " POLICY \"%s\"", + PQgetvalue(result, i, 0)); - if (*(PQgetvalue(result, i, 1)) == 'f') - appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); + if (*(PQgetvalue(result, i, 1)) == 'f') + appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); - if (!PQgetisnull(result, i, 5)) - appendPQExpBuffer(&buf, " FOR %s", - PQgetvalue(result, i, 5)); + if (!PQgetisnull(result, i, 5)) + appendPQExpBuffer(&buf, " FOR %s", + PQgetvalue(result, i, 5)); - if (!PQgetisnull(result, i, 2)) - { - appendPQExpBuffer(&buf, "\n TO %s", - PQgetvalue(result, i, 2)); - } + if (!PQgetisnull(result, i, 2)) + { + appendPQExpBuffer(&buf, "\n TO %s", + PQgetvalue(result, i, 2)); + } - if (!PQgetisnull(result, i, 3)) - appendPQExpBuffer(&buf, "\n USING (%s)", - PQgetvalue(result, i, 3)); + if (!PQgetisnull(result, i, 3)) + appendPQExpBuffer(&buf, "\n USING (%s)", + PQgetvalue(result, i, 3)); - if (!PQgetisnull(result, i, 4)) - appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", - PQgetvalue(result, i, 4)); + if (!PQgetisnull(result, i, 4)) + appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", + PQgetvalue(result, i, 4)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* print any extended statistics */ if (pset.sversion >= 140000) @@ -3025,115 +3024,115 @@ describeOneTableDetails(const char *schemaname, } /* print any publications */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get publications that publish this table")); - if (pset.sversion >= 150000) + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get publications that publish this table")); + if (pset.sversion >= 150000) + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" + " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" + "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" + "UNION\n" + "SELECT pubname\n" + " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" + " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" + " (SELECT pg_catalog.string_agg(attname, ', ')\n" + " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" + " pg_catalog.pg_attribute\n" + " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" + " ELSE NULL END) " + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" + "WHERE pr.prrelid = '%s'\n", + oid, oid, oid); + + if (pset.sversion >= 190000) { + /* + * Skip entries where this relation appears in the + * publication's EXCEPT list. + */ appendPQExpBuffer(&buf, + " AND NOT pr.prexcept\n" + "UNION\n" "SELECT pubname\n" " , NULL\n" " , NULL\n" "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" - " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" - "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" - "UNION\n" - "SELECT pubname\n" - " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" - " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" - " (SELECT pg_catalog.string_agg(attname, ', ')\n" - " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" - " pg_catalog.pg_attribute\n" - " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" - " ELSE NULL END) " - "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" - "WHERE pr.prrelid = '%s'\n", + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + " AND NOT EXISTS (\n" + " SELECT 1\n" + " FROM pg_catalog.pg_publication_rel pr\n" + " WHERE pr.prpubid = p.oid AND\n" + " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" + "ORDER BY 1;", oid, oid, oid); - - if (pset.sversion >= 190000) - { - /* - * Skip entries where this relation appears in the - * publication's EXCEPT list. - */ - appendPQExpBuffer(&buf, - " AND NOT pr.prexcept\n" - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - " AND NOT EXISTS (\n" - " SELECT 1\n" - " FROM pg_catalog.pg_publication_rel pr\n" - " WHERE pr.prpubid = p.oid AND\n" - " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" - "ORDER BY 1;", - oid, oid, oid); - } - else - { - appendPQExpBuffer(&buf, - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - "ORDER BY 1;", - oid); - } } else { appendPQExpBuffer(&buf, + "UNION\n" "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - "WHERE pr.prrelid = '%s'\n" - "UNION ALL\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" + " , NULL\n" + " , NULL\n" "FROM pg_catalog.pg_publication p\n" "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" "ORDER BY 1;", - oid, oid); + oid); } + } + else + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + "WHERE pr.prrelid = '%s'\n" + "UNION ALL\n" + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + "ORDER BY 1;", + oid, oid); + } - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - if (tuples > 0) - printTableAddFooter(&cont, _("Included in publications:")); + if (tuples > 0) + printTableAddFooter(&cont, _("Included in publications:")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " \"%s\"", + PQgetvalue(result, i, 0)); - /* column list (if any) */ - if (!PQgetisnull(result, i, 2)) - appendPQExpBuffer(&buf, " (%s)", - PQgetvalue(result, i, 2)); + /* column list (if any) */ + if (!PQgetisnull(result, i, 2)) + appendPQExpBuffer(&buf, " (%s)", + PQgetvalue(result, i, 2)); - /* row filter (if any) */ - if (!PQgetisnull(result, i, 1)) - appendPQExpBuffer(&buf, " WHERE %s", - PQgetvalue(result, i, 1)); + /* row filter (if any) */ + if (!PQgetisnull(result, i, 1)) + appendPQExpBuffer(&buf, " WHERE %s", + PQgetvalue(result, i, 1)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* Print publications where the table is in the EXCEPT clause */ if (pset.sversion >= 190000) @@ -3805,7 +3804,7 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) ncols++; } appendPQExpBufferStr(&buf, "\n, r.rolreplication"); - appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); + appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_roles r\n"); @@ -3860,8 +3859,8 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) if (strcmp(PQgetvalue(res, i, (verbose ? 9 : 8)), "t") == 0) add_role_attribute(&buf, _("Replication")); - if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) - add_role_attribute(&buf, _("Bypass RLS")); + if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) + add_role_attribute(&buf, _("Bypass RLS")); conns = atoi(PQgetvalue(res, i, 6)); if (conns >= 0) @@ -5155,14 +5154,14 @@ listCollations(const char *pattern, bool verbose, bool showSystem) gettext_noop("Schema"), gettext_noop("Name")); - appendPQExpBuffer(&buf, - " CASE c.collprovider " - "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " - "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " - "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " - "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " - "END AS \"%s\",\n", - gettext_noop("Provider")); + appendPQExpBuffer(&buf, + " CASE c.collprovider " + "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " + "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " + "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " + "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " + "END AS \"%s\",\n", + gettext_noop("Provider")); appendPQExpBuffer(&buf, " c.collcollate AS \"%s\",\n" -- 2.50.1 (Apple Git-155) --aHl3HfeiUuO3zeNC-- ^ permalink raw reply [nested|flat] 59+ messages in thread
* [PATCH v6 4/4] run pgindent and pgperltidy @ 2026-06-30 18:24 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 59+ messages in thread From: Nathan Bossart @ 2026-06-30 18:24 UTC (permalink / raw) --- src/bin/pg_dump/pg_dump.c | 464 ++++++++++----------- src/bin/pg_dump/pg_dumpall.c | 30 +- src/bin/pg_upgrade/check.c | 16 +- src/bin/pg_upgrade/controldata.c | 2 +- src/bin/pg_upgrade/exec.c | 8 +- src/bin/pg_upgrade/multixact_rewrite.c | 80 ++-- src/bin/pg_upgrade/pg_upgrade.c | 34 +- src/bin/pg_upgrade/relfilenumber.c | 54 +-- src/bin/pg_upgrade/t/006_transfer_modes.pl | 33 +- src/bin/psql/command.c | 29 +- src/bin/psql/describe.c | 461 ++++++++++---------- 11 files changed, 601 insertions(+), 610 deletions(-) diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 65bd15ebfd2..5673268b467 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -1491,8 +1491,8 @@ setup_connection(Archive *AH, const char *dumpencoding, * Disable timeouts if supported. */ ExecuteSqlStatement(AH, "SET statement_timeout = 0"); - ExecuteSqlStatement(AH, "SET lock_timeout = 0"); - ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); + ExecuteSqlStatement(AH, "SET lock_timeout = 0"); + ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); if (AH->remoteVersion >= 170000) ExecuteSqlStatement(AH, "SET transaction_timeout = 0"); @@ -1505,10 +1505,10 @@ setup_connection(Archive *AH, const char *dumpencoding, /* * Adjust row-security mode, if supported. */ - if (dopt->enable_row_security) - ExecuteSqlStatement(AH, "SET row_security = on"); - else - ExecuteSqlStatement(AH, "SET row_security = off"); + if (dopt->enable_row_security) + ExecuteSqlStatement(AH, "SET row_security = on"); + else + ExecuteSqlStatement(AH, "SET row_security = off"); /* * For security reasons, we restrict the expansion of non-system views and @@ -1933,10 +1933,9 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) addObjectDependency(dobj, ext->dobj.dumpId); /* - * Mark the member object to have any non-initial ACLs - * dumped. (Any initial ACLs will be removed later, using data from - * pg_init_privs, so that we'll dump only the delta from the extension's - * initial setup.) + * Mark the member object to have any non-initial ACLs dumped. (Any + * initial ACLs will be removed later, using data from pg_init_privs, so + * that we'll dump only the delta from the extension's initial setup.) * * In binary upgrades, we still dump all components of the members * individually, since the idea is to exactly reproduce the database @@ -1953,7 +1952,7 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) if (fout->dopt->binary_upgrade) dobj->dump = ext->dobj.dump; else - dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); + dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); return true; } @@ -1987,9 +1986,9 @@ selectDumpableNamespace(NamespaceInfo *nsinfo, Archive *fout) else if (strcmp(nsinfo->dobj.name, "pg_catalog") == 0) { /* - * We dump out any ACLs defined in pg_catalog, if - * they are interesting (and not the original ACLs which were set at - * initdb time, see pg_init_privs). + * We dump out any ACLs defined in pg_catalog, if they are interesting + * (and not the original ACLs which were set at initdb time, see + * pg_init_privs). */ nsinfo->dobj.dump_contains = nsinfo->dobj.dump = DUMP_COMPONENT_ACL; } @@ -3296,7 +3295,7 @@ dumpDatabase(Archive *fout) "datcollate, datctype, datfrozenxid, " "datacl, acldefault('d', datdba) AS acldefault, " "datistemplate, datconnlimit, "); - appendPQExpBufferStr(dbQry, "datminmxid, "); + appendPQExpBufferStr(dbQry, "datminmxid, "); if (fout->remoteVersion >= 170000) appendPQExpBufferStr(dbQry, "datlocprovider, datlocale, datcollversion, "); else if (fout->remoteVersion >= 150000) @@ -3638,11 +3637,11 @@ dumpDatabase(Archive *fout) ii_oid, ii_relminmxid; - appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" - "FROM pg_catalog.pg_class\n" - "WHERE oid IN (%u, %u, %u, %u);\n", - LargeObjectRelationId, LargeObjectLOidPNIndexId, - LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); + appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" + "FROM pg_catalog.pg_class\n" + "WHERE oid IN (%u, %u, %u, %u);\n", + LargeObjectRelationId, LargeObjectLOidPNIndexId, + LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); lo_res = ExecuteSqlQuery(fout, loFrozenQry->data, PGRES_TUPLES_OK); @@ -4274,7 +4273,7 @@ getPolicies(Archive *fout, TableInfo tblinfo[], int numTables) printfPQExpBuffer(query, "SELECT pol.oid, pol.tableoid, pol.polrelid, pol.polname, pol.polcmd, "); - appendPQExpBufferStr(query, "pol.polpermissive, "); + appendPQExpBufferStr(query, "pol.polpermissive, "); appendPQExpBuffer(query, "CASE WHEN pol.polroles = '{0}' THEN NULL ELSE " " pg_catalog.array_to_string(ARRAY(SELECT pg_catalog.quote_ident(rolname) from pg_catalog.pg_roles WHERE oid = ANY(pol.polroles)), ', ') END AS polroles, " @@ -6633,9 +6632,9 @@ getAccessMethods(Archive *fout) * Select all access methods from pg_am table. */ appendPQExpBufferStr(query, "SELECT tableoid, oid, amname, "); - appendPQExpBufferStr(query, - "amtype, " - "amhandler::pg_catalog.regproc AS amhandler "); + appendPQExpBufferStr(query, + "amtype, " + "amhandler::pg_catalog.regproc AS amhandler "); appendPQExpBufferStr(query, "FROM pg_am"); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6827,35 +6826,35 @@ getAggregates(Archive *fout) * Find all interesting aggregates. See comment in getFuncs() for the * rationale behind the filtering logic. */ - agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" - : "p.proisagg"); + agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" + : "p.proisagg"); - appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " - "p.proname AS aggname, " - "p.pronamespace AS aggnamespace, " - "p.pronargs, p.proargtypes, " - "p.proowner, " - "p.proacl AS aggacl, " - "acldefault('f', p.proowner) AS acldefault " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s AND (" - "p.pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog') OR " - "p.proacl IS DISTINCT FROM pip.initprivs", - agg_check); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - " OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); - appendPQExpBufferChar(query, ')'); + appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " + "p.proname AS aggname, " + "p.pronamespace AS aggnamespace, " + "p.pronargs, p.proargtypes, " + "p.proowner, " + "p.proacl AS aggacl, " + "acldefault('f', p.proowner) AS acldefault " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s AND (" + "p.pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog') OR " + "p.proacl IS DISTINCT FROM pip.initprivs", + agg_check); + if (dopt->binary_upgrade) + appendPQExpBufferStr(query, + " OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6957,53 +6956,53 @@ getFuncs(Archive *fout) * include them, since we want to dump extension members individually in * that mode. Also, if they are used by casts or transforms then we need * to gather the information about them, though they won't be dumped if - * they are built-in. Also, include functions in - * pg_catalog if they have an ACL different from what's shown in - * pg_init_privs (so we have to join to pg_init_privs; annoying). + * they are built-in. Also, include functions in pg_catalog if they have + * an ACL different from what's shown in pg_init_privs (so we have to join + * to pg_init_privs; annoying). */ - not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" - : "NOT p.proisagg"); + not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" + : "NOT p.proisagg"); - appendPQExpBuffer(query, - "SELECT p.tableoid, p.oid, p.proname, p.prolang, " - "p.pronargs, p.proargtypes, p.prorettype, " - "p.proacl, " - "acldefault('f', p.proowner) AS acldefault, " - "p.pronamespace, " - "p.proowner " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s" - "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " - "WHERE classid = 'pg_proc'::regclass AND " - "objid = p.oid AND deptype = 'i')" - "\n AND (" - "\n pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog')" - "\n OR EXISTS (SELECT 1 FROM pg_cast" - "\n WHERE pg_cast.oid > %u " - "\n AND p.oid = pg_cast.castfunc)" - "\n OR EXISTS (SELECT 1 FROM pg_transform" - "\n WHERE pg_transform.oid > %u AND " - "\n (p.oid = pg_transform.trffromsql" - "\n OR p.oid = pg_transform.trftosql))", - not_agg_check, - g_last_builtin_oid, - g_last_builtin_oid); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); + appendPQExpBuffer(query, + "SELECT p.tableoid, p.oid, p.proname, p.prolang, " + "p.pronargs, p.proargtypes, p.prorettype, " + "p.proacl, " + "acldefault('f', p.proowner) AS acldefault, " + "p.pronamespace, " + "p.proowner " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s" + "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " + "WHERE classid = 'pg_proc'::regclass AND " + "objid = p.oid AND deptype = 'i')" + "\n AND (" + "\n pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog')" + "\n OR EXISTS (SELECT 1 FROM pg_cast" + "\n WHERE pg_cast.oid > %u " + "\n AND p.oid = pg_cast.castfunc)" + "\n OR EXISTS (SELECT 1 FROM pg_transform" + "\n WHERE pg_transform.oid > %u AND " + "\n (p.oid = pg_transform.trffromsql" + "\n OR p.oid = pg_transform.trftosql))", + not_agg_check, + g_last_builtin_oid, + g_last_builtin_oid); + if (dopt->binary_upgrade) appendPQExpBufferStr(query, - "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); - appendPQExpBufferChar(query, ')'); + "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferStr(query, + "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -7252,31 +7251,31 @@ getTables(Archive *fout, int *numTables) appendPQExpBufferStr(query, "c.relhasoids, "); - appendPQExpBufferStr(query, - "c.relispopulated, "); + appendPQExpBufferStr(query, + "c.relispopulated, "); - appendPQExpBufferStr(query, - "c.relreplident, "); + appendPQExpBufferStr(query, + "c.relreplident, "); - appendPQExpBufferStr(query, - "c.relrowsecurity, c.relforcerowsecurity, "); + appendPQExpBufferStr(query, + "c.relrowsecurity, c.relforcerowsecurity, "); - appendPQExpBufferStr(query, - "c.relminmxid, tc.relminmxid AS tminmxid, "); + appendPQExpBufferStr(query, + "c.relminmxid, tc.relminmxid AS tminmxid, "); - appendPQExpBufferStr(query, - "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); + appendPQExpBufferStr(query, + "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); - appendPQExpBufferStr(query, - "am.amname, "); + appendPQExpBufferStr(query, + "am.amname, "); - appendPQExpBufferStr(query, - "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); + appendPQExpBufferStr(query, + "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); - appendPQExpBufferStr(query, - "c.relispartition AS ispartition "); + appendPQExpBufferStr(query, + "c.relispartition AS ispartition "); /* * Left join to pg_depend to pick up dependency info linking sequences to @@ -7296,8 +7295,8 @@ getTables(Archive *fout, int *numTables) /* * Left join to pg_am to pick up the amname. */ - appendPQExpBufferStr(query, - "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); + appendPQExpBufferStr(query, + "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); /* * We purposefully ignore toast OIDs for partitioned tables; the reason is @@ -7868,8 +7867,8 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables) "t.reloptions AS indreloptions, "); - appendPQExpBufferStr(query, - "i.indisreplident, "); + appendPQExpBufferStr(query, + "i.indisreplident, "); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -9313,8 +9312,8 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables) appendPQExpBufferStr(q, "'' AS attcompression,\n"); - appendPQExpBufferStr(q, - "a.attidentity,\n"); + appendPQExpBufferStr(q, + "a.attidentity,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(q, @@ -10717,73 +10716,73 @@ getAdditionalACLs(Archive *fout) PQclear(res); /* Fetch initial-privileges data */ - printfPQExpBuffer(query, - "SELECT objoid, classoid, objsubid, privtype, initprivs " - "FROM pg_init_privs"); + printfPQExpBuffer(query, + "SELECT objoid, classoid, objsubid, privtype, initprivs " + "FROM pg_init_privs"); - res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); + res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); - ntups = PQntuples(res); - for (i = 0; i < ntups; i++) - { - Oid objoid = atooid(PQgetvalue(res, i, 0)); - Oid classoid = atooid(PQgetvalue(res, i, 1)); - int objsubid = atoi(PQgetvalue(res, i, 2)); - char privtype = *(PQgetvalue(res, i, 3)); - char *initprivs = PQgetvalue(res, i, 4); - CatalogId objId; - DumpableObject *dobj; + ntups = PQntuples(res); + for (i = 0; i < ntups; i++) + { + Oid objoid = atooid(PQgetvalue(res, i, 0)); + Oid classoid = atooid(PQgetvalue(res, i, 1)); + int objsubid = atoi(PQgetvalue(res, i, 2)); + char privtype = *(PQgetvalue(res, i, 3)); + char *initprivs = PQgetvalue(res, i, 4); + CatalogId objId; + DumpableObject *dobj; - objId.tableoid = classoid; - objId.oid = objoid; - dobj = findObjectByCatalogId(objId); - /* OK to ignore entries we haven't got a DumpableObject for */ - if (dobj) + objId.tableoid = classoid; + objId.oid = objoid; + dobj = findObjectByCatalogId(objId); + /* OK to ignore entries we haven't got a DumpableObject for */ + if (dobj) + { + /* Cope with sub-object initprivs */ + if (objsubid != 0) { - /* Cope with sub-object initprivs */ - if (objsubid != 0) - { - if (dobj->objType == DO_TABLE) - { - /* For a column initprivs, set the table's ACL flags */ - dobj->components |= DUMP_COMPONENT_ACL; - ((TableInfo *) dobj)->hascolumnACLs = true; - } - else - pg_log_warning("unsupported pg_init_privs entry: %u %u %d", - classoid, objoid, objsubid); - continue; - } - - /* - * We ignore any pg_init_privs.initprivs entry for the public - * schema, as explained in getNamespaces(). - */ - if (dobj->objType == DO_NAMESPACE && - strcmp(dobj->name, "public") == 0) - continue; - - /* Else it had better be of a type we think has ACLs */ - if (dobj->objType == DO_NAMESPACE || - dobj->objType == DO_TYPE || - dobj->objType == DO_FUNC || - dobj->objType == DO_AGG || - dobj->objType == DO_TABLE || - dobj->objType == DO_PROCLANG || - dobj->objType == DO_FDW || - dobj->objType == DO_FOREIGN_SERVER) + if (dobj->objType == DO_TABLE) { - DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; - - daobj->dacl.privtype = privtype; - daobj->dacl.initprivs = pstrdup(initprivs); + /* For a column initprivs, set the table's ACL flags */ + dobj->components |= DUMP_COMPONENT_ACL; + ((TableInfo *) dobj)->hascolumnACLs = true; } else pg_log_warning("unsupported pg_init_privs entry: %u %u %d", classoid, objoid, objsubid); + continue; + } + + /* + * We ignore any pg_init_privs.initprivs entry for the public + * schema, as explained in getNamespaces(). + */ + if (dobj->objType == DO_NAMESPACE && + strcmp(dobj->name, "public") == 0) + continue; + + /* Else it had better be of a type we think has ACLs */ + if (dobj->objType == DO_NAMESPACE || + dobj->objType == DO_TYPE || + dobj->objType == DO_FUNC || + dobj->objType == DO_AGG || + dobj->objType == DO_TABLE || + dobj->objType == DO_PROCLANG || + dobj->objType == DO_FDW || + dobj->objType == DO_FOREIGN_SERVER) + { + DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; + + daobj->dacl.privtype = privtype; + daobj->dacl.initprivs = pstrdup(initprivs); } + else + pg_log_warning("unsupported pg_init_privs entry: %u %u %d", + classoid, objoid, objsubid); } - PQclear(res); + } + PQclear(res); destroyPQExpBuffer(query); } @@ -11128,8 +11127,8 @@ dumpRelationStats_dumper(Archive *fout, const void *userArg, const TocEntry *te) * The results must be in the order of the relations supplied in the * parameters to ensure we remain in sync as we walk through the TOC. * - * For versions before 19, the redundant filter clause on s.tablename = - * ANY(...) seems sufficient to convince the planner to use + * For versions before 19, the redundant filter clause on s.tablename + * = ANY(...) seems sufficient to convince the planner to use * pg_class_relname_nsp_index, which avoids a full scan of pg_stats. * In newer versions, pg_stats returns the table OIDs, eliminating the * need for that hack. @@ -13469,11 +13468,11 @@ dumpFunc(Archive *fout, const FuncInfo *finfo) "pg_catalog.pg_get_function_result(p.oid) AS funcresult,\n" "proleakproof,\n"); - appendPQExpBufferStr(query, - "array_to_string(protrftypes, ' ') AS protrftypes,\n"); + appendPQExpBufferStr(query, + "array_to_string(protrftypes, ' ') AS protrftypes,\n"); - appendPQExpBufferStr(query, - "proparallel,\n"); + appendPQExpBufferStr(query, + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -14963,9 +14962,9 @@ dumpCollation(Archive *fout, const CollInfo *collinfo) /* Get collation-specific details */ appendPQExpBufferStr(query, "SELECT "); - appendPQExpBufferStr(query, - "collprovider, " - "collversion, "); + appendPQExpBufferStr(query, + "collprovider, " + "collversion, "); if (fout->remoteVersion >= 120000) appendPQExpBufferStr(query, @@ -15372,23 +15371,23 @@ dumpAgg(Archive *fout, const AggInfo *agginfo) "pg_catalog.pg_get_function_arguments(p.oid) AS funcargs,\n" "pg_catalog.pg_get_function_identity_arguments(p.oid) AS funciargs,\n"); - appendPQExpBufferStr(query, - "aggkind,\n" - "aggmtransfn,\n" - "aggminvtransfn,\n" - "aggmfinalfn,\n" - "aggmtranstype::pg_catalog.regtype,\n" - "aggfinalextra,\n" - "aggmfinalextra,\n" - "aggtransspace,\n" - "aggmtransspace,\n" - "aggminitval,\n"); + appendPQExpBufferStr(query, + "aggkind,\n" + "aggmtransfn,\n" + "aggminvtransfn,\n" + "aggmfinalfn,\n" + "aggmtranstype::pg_catalog.regtype,\n" + "aggfinalextra,\n" + "aggmfinalextra,\n" + "aggtransspace,\n" + "aggmtransspace,\n" + "aggminitval,\n"); - appendPQExpBufferStr(query, - "aggcombinefn,\n" - "aggserialfn,\n" - "aggdeserialfn,\n" - "proparallel,\n"); + appendPQExpBufferStr(query, + "aggcombinefn,\n" + "aggserialfn,\n" + "aggdeserialfn,\n" + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -16848,30 +16847,30 @@ dumpTable(Archive *fout, const TableInfo *tbinfo) appendPQExpBufferStr(query, "PREPARE getColumnACLs(pg_catalog.oid) AS\n"); - /* - * In principle we should call acldefault('c', relowner) to - * get the default ACL for a column. However, we don't - * currently store the numeric OID of the relowner in - * TableInfo. We could convert the owner name using regrole, - * but that creates a risk of failure due to concurrent role - * renames. Given that the default ACL for columns is empty - * and is likely to stay that way, it's not worth extra cycles - * and risk to avoid hard-wiring that knowledge here. - */ - appendPQExpBufferStr(query, - "SELECT at.attname, " - "at.attacl, " - "'{}' AS acldefault, " - "pip.privtype, pip.initprivs " - "FROM pg_catalog.pg_attribute at " - "LEFT JOIN pg_catalog.pg_init_privs pip ON " - "(at.attrelid = pip.objoid " - "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " - "AND at.attnum = pip.objsubid) " - "WHERE at.attrelid = $1 AND " - "NOT at.attisdropped " - "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " - "ORDER BY at.attnum"); + /* + * In principle we should call acldefault('c', relowner) to get + * the default ACL for a column. However, we don't currently + * store the numeric OID of the relowner in TableInfo. We could + * convert the owner name using regrole, but that creates a risk + * of failure due to concurrent role renames. Given that the + * default ACL for columns is empty and is likely to stay that + * way, it's not worth extra cycles and risk to avoid hard-wiring + * that knowledge here. + */ + appendPQExpBufferStr(query, + "SELECT at.attname, " + "at.attacl, " + "'{}' AS acldefault, " + "pip.privtype, pip.initprivs " + "FROM pg_catalog.pg_attribute at " + "LEFT JOIN pg_catalog.pg_init_privs pip ON " + "(at.attrelid = pip.objoid " + "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " + "AND at.attnum = pip.objsubid) " + "WHERE at.attrelid = $1 AND " + "NOT at.attisdropped " + "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " + "ORDER BY at.attnum"); ExecuteSqlStatement(fout, query->data); @@ -19165,7 +19164,7 @@ collectSequences(Archive *fout) * pg_get_sequence_data(), but we only do so for non-schema-only dumps. */ if (fout->remoteVersion < 180000 || - (!fout->dopt->dumpData && !fout->dopt->sequence_data)) + (!fout->dopt->dumpData && !fout->dopt->sequence_data)) query = "SELECT seqrelid, format_type(seqtypid, NULL), " "seqstart, seqincrement, " "seqmax, seqmin, " @@ -19227,15 +19226,14 @@ dumpSequence(Archive *fout, const TableInfo *tbinfo) qseqname = pg_strdup(fmtId(tbinfo->dobj.name)); /* - * The sequence information is gathered in a sorted - * table before any calls to dumpSequence(). See collectSequences() for - * more information. + * The sequence information is gathered in a sorted table before any calls + * to dumpSequence(). See collectSequences() for more information. */ - Assert(sequences); + Assert(sequences); - key.oid = tbinfo->dobj.catId.oid; - seq = bsearch(&key, sequences, nsequences, - sizeof(SequenceItem), SequenceItemCmp); + key.oid = tbinfo->dobj.catId.oid; + seq = bsearch(&key, sequences, nsequences, + sizeof(SequenceItem), SequenceItemCmp); /* Calculate default limits for a sequence of this type */ is_ascending = (seq->incby >= 0); diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c index e68937c9934..afcd9a218d8 100644 --- a/src/bin/pg_dump/pg_dumpall.c +++ b/src/bin/pg_dump/pg_dumpall.c @@ -785,11 +785,11 @@ dropRoles(PGconn *conn) int i_rolname; int i; - printfPQExpBuffer(buf, - "SELECT rolname " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 1", role_catalog); + printfPQExpBuffer(buf, + "SELECT rolname " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 1", role_catalog); res = executeQuery(conn, buf->data); @@ -843,16 +843,16 @@ dumpRoles(PGconn *conn) * Notes: rolconfig is dumped later, and pg_authid must be used for * extracting rolcomment regardless of role_catalog. */ - printfPQExpBuffer(buf, - "SELECT oid, rolname, rolsuper, rolinherit, " - "rolcreaterole, rolcreatedb, " - "rolcanlogin, rolconnlimit, rolpassword, " - "rolvaliduntil, rolreplication, rolbypassrls, " - "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " - "rolname = current_user AS is_current_user " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 2", role_catalog); + printfPQExpBuffer(buf, + "SELECT oid, rolname, rolsuper, rolinherit, " + "rolcreaterole, rolcreatedb, " + "rolcanlogin, rolconnlimit, rolpassword, " + "rolvaliduntil, rolreplication, rolbypassrls, " + "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " + "rolname = current_user AS is_current_user " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 2", role_catalog); res = executeQuery(conn, buf->data); diff --git a/src/bin/pg_upgrade/check.c b/src/bin/pg_upgrade/check.c index 786c1474829..f725f5ee3e2 100644 --- a/src/bin/pg_upgrade/check.c +++ b/src/bin/pg_upgrade/check.c @@ -1475,15 +1475,15 @@ check_for_incompatible_polymorphics(ClusterInfo *cluster) ", 'array_cat(anyarray,anyarray)'" ", 'array_prepend(anyelement,anyarray)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_remove(anyarray,anyelement)'" - ", 'array_replace(anyarray,anyelement,anyelement)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_remove(anyarray,anyelement)'" + ", 'array_replace(anyarray,anyelement,anyelement)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_position(anyarray,anyelement)'" - ", 'array_position(anyarray,anyelement,integer)'" - ", 'array_positions(anyarray,anyelement)'" - ", 'width_bucket(anyelement,anyarray)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_position(anyarray,anyelement)'" + ", 'array_position(anyarray,anyelement,integer)'" + ", 'array_positions(anyarray,anyelement)'" + ", 'width_bucket(anyelement,anyarray)'"); /* * The query below hardcodes FirstNormalObjectId as 16384 rather than diff --git a/src/bin/pg_upgrade/controldata.c b/src/bin/pg_upgrade/controldata.c index 8f81c9e9582..02ea02df60f 100644 --- a/src/bin/pg_upgrade/controldata.c +++ b/src/bin/pg_upgrade/controldata.c @@ -228,7 +228,7 @@ get_control_data(ClusterInfo *cluster) p++; /* remove ':' char */ cluster->controldata.chkpnt_nxtepoch = str2uint(p); - p = strchr(p, ':'); + p = strchr(p, ':'); if (p == NULL || strlen(p) <= 1) pg_fatal("%d: controldata retrieval problem", __LINE__); diff --git a/src/bin/pg_upgrade/exec.c b/src/bin/pg_upgrade/exec.c index 44355feea30..a1bdbf373e3 100644 --- a/src/bin/pg_upgrade/exec.c +++ b/src/bin/pg_upgrade/exec.c @@ -55,7 +55,7 @@ get_bin_version(ClusterInfo *cluster) if (sscanf(cmd_output, "%*s %*s %d.%d", &v1, &v2) < 1) pg_fatal("could not get pg_ctl version output from %s", cmd); - cluster->bin_version = v1 * 10000; + cluster->bin_version = v1 * 10000; } @@ -344,8 +344,8 @@ check_data_dir(ClusterInfo *cluster) check_single_dir(pg_data, "pg_subtrans"); check_single_dir(pg_data, PG_TBLSPC_DIR); check_single_dir(pg_data, "pg_twophase"); - check_single_dir(pg_data, "pg_wal"); - check_single_dir(pg_data, "pg_xact"); + check_single_dir(pg_data, "pg_wal"); + check_single_dir(pg_data, "pg_xact"); } @@ -385,7 +385,7 @@ check_bin_dir(ClusterInfo *cluster, bool check_versions) */ get_bin_version(cluster); - check_exec(cluster->bindir, "pg_resetwal", check_versions); + check_exec(cluster->bindir, "pg_resetwal", check_versions); if (cluster == &new_cluster) { diff --git a/src/bin/pg_upgrade/multixact_rewrite.c b/src/bin/pg_upgrade/multixact_rewrite.c index c45b3183684..c7a1416494d 100644 --- a/src/bin/pg_upgrade/multixact_rewrite.c +++ b/src/bin/pg_upgrade/multixact_rewrite.c @@ -61,52 +61,52 @@ rewrite_multixacts(MultiXactId from_multi, MultiXactId to_multi) * Convert old multixids, if needed, by reading them one-by-one from the * old cluster. */ - old_reader = AllocOldMultiXactRead(old_cluster.pgdata, - old_cluster.controldata.chkpnt_nxtmulti, - old_cluster.controldata.chkpnt_nxtmxoff); + old_reader = AllocOldMultiXactRead(old_cluster.pgdata, + old_cluster.controldata.chkpnt_nxtmulti, + old_cluster.controldata.chkpnt_nxtmxoff); - for (MultiXactId multi = from_multi; multi != to_multi;) - { - MultiXactMember member; - bool multixid_valid; - - /* - * Read this multixid's members. - * - * Locking-only XIDs that may be part of multi-xids don't matter - * after upgrade, as there can be no transactions running across - * upgrade. So as a small optimization, we only read one member - * from each multixid: the one updating one, or if there was no - * update, arbitrarily the first locking xid. - */ - multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); + for (MultiXactId multi = from_multi; multi != to_multi;) + { + MultiXactMember member; + bool multixid_valid; - /* - * Write the new offset to pg_multixact/offsets. - * - * Even if this multixid is invalid, we still need to write its - * offset if the *previous* multixid was valid. That's because - * when reading a multixid, the number of members is calculated - * from the difference between the two offsets. - */ - RecordMultiXactOffset(offsets_writer, multi, - (multixid_valid || prev_multixid_valid) ? next_offset : 0); + /* + * Read this multixid's members. + * + * Locking-only XIDs that may be part of multi-xids don't matter after + * upgrade, as there can be no transactions running across upgrade. So + * as a small optimization, we only read one member from each + * multixid: the one updating one, or if there was no update, + * arbitrarily the first locking xid. + */ + multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); - /* Write the members */ - if (multixid_valid) - { - RecordMultiXactMembers(members_writer, next_offset, 1, &member); - next_offset += 1; - } + /* + * Write the new offset to pg_multixact/offsets. + * + * Even if this multixid is invalid, we still need to write its offset + * if the *previous* multixid was valid. That's because when reading + * a multixid, the number of members is calculated from the difference + * between the two offsets. + */ + RecordMultiXactOffset(offsets_writer, multi, + (multixid_valid || prev_multixid_valid) ? next_offset : 0); - /* Advance to next multixid, handling wraparound */ - multi++; - if (multi < FirstMultiXactId) - multi = FirstMultiXactId; - prev_multixid_valid = multixid_valid; + /* Write the members */ + if (multixid_valid) + { + RecordMultiXactMembers(members_writer, next_offset, 1, &member); + next_offset += 1; } - FreeOldMultiXactReader(old_reader); + /* Advance to next multixid, handling wraparound */ + multi++; + if (multi < FirstMultiXactId) + multi = FirstMultiXactId; + prev_multixid_valid = multixid_valid; + } + + FreeOldMultiXactReader(old_reader); /* Write the final 'next' offset to the last SLRU page */ RecordMultiXactOffset(offsets_writer, to_multi, diff --git a/src/bin/pg_upgrade/pg_upgrade.c b/src/bin/pg_upgrade/pg_upgrade.c index c6af9035665..7366fd4627c 100644 --- a/src/bin/pg_upgrade/pg_upgrade.c +++ b/src/bin/pg_upgrade/pg_upgrade.c @@ -833,7 +833,7 @@ copy_xact_xlog_xid(void) * Determine the range of multixacts to convert. */ nxtmulti = old_cluster.controldata.chkpnt_nxtmulti; - oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; + oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; /* handle wraparound */ if (nxtmulti < FirstMultiXactId) nxtmulti = FirstMultiXactId; @@ -898,15 +898,15 @@ set_frozenxids(void) int i_datname; int i_datallowconn; - prep_status("Setting frozenxid and minmxid counters in new cluster"); + prep_status("Setting frozenxid and minmxid counters in new cluster"); conn_template1 = connectToServer(&new_cluster, "template1"); - /* set pg_database.datfrozenxid */ - PQclear(executeQueryOrDie(conn_template1, - "UPDATE pg_catalog.pg_database " - "SET datfrozenxid = '%u'", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_database.datfrozenxid */ + PQclear(executeQueryOrDie(conn_template1, + "UPDATE pg_catalog.pg_database " + "SET datfrozenxid = '%u'", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_database.datminmxid */ PQclear(executeQueryOrDie(conn_template1, @@ -942,16 +942,16 @@ set_frozenxids(void) conn = connectToServer(&new_cluster, datname); - /* set pg_class.relfrozenxid */ - PQclear(executeQueryOrDie(conn, - "UPDATE pg_catalog.pg_class " - "SET relfrozenxid = '%u' " - /* only heap, materialized view, and TOAST are vacuumed */ - "WHERE relkind IN (" - CppAsString2(RELKIND_RELATION) ", " - CppAsString2(RELKIND_MATVIEW) ", " - CppAsString2(RELKIND_TOASTVALUE) ")", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_class.relfrozenxid */ + PQclear(executeQueryOrDie(conn, + "UPDATE pg_catalog.pg_class " + "SET relfrozenxid = '%u' " + /* only heap, materialized view, and TOAST are vacuumed */ + "WHERE relkind IN (" + CppAsString2(RELKIND_RELATION) ", " + CppAsString2(RELKIND_MATVIEW) ", " + CppAsString2(RELKIND_TOASTVALUE) ")", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_class.relminmxid */ PQclear(executeQueryOrDie(conn, diff --git a/src/bin/pg_upgrade/relfilenumber.c b/src/bin/pg_upgrade/relfilenumber.c index ec2ff7acb21..6c467bdc8a5 100644 --- a/src/bin/pg_upgrade/relfilenumber.c +++ b/src/bin/pg_upgrade/relfilenumber.c @@ -587,32 +587,32 @@ transfer_relfile(FileNameMap *map, const char *type_suffix) /* Copying files might take some time, so give feedback. */ pg_log(PG_STATUS, "%s", old_file); - switch (user_opts.transfer_mode) - { - case TRANSFER_MODE_CLONE: - pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", - old_file, new_file); - cloneFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", - old_file, new_file); - copyFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY_FILE_RANGE: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", - old_file, new_file); - copyFileByRange(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_LINK: - pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", - old_file, new_file); - linkFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_SWAP: - /* swap mode is handled in its own code path */ - pg_fatal("should never happen"); - break; - } + switch (user_opts.transfer_mode) + { + case TRANSFER_MODE_CLONE: + pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", + old_file, new_file); + cloneFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", + old_file, new_file); + copyFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY_FILE_RANGE: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", + old_file, new_file); + copyFileByRange(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_LINK: + pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", + old_file, new_file); + linkFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_SWAP: + /* swap mode is handled in its own code path */ + pg_fatal("should never happen"); + break; + } } } diff --git a/src/bin/pg_upgrade/t/006_transfer_modes.pl b/src/bin/pg_upgrade/t/006_transfer_modes.pl index 9efa5dc863c..360d05c4b68 100644 --- a/src/bin/pg_upgrade/t/006_transfer_modes.pl +++ b/src/bin/pg_upgrade/t/006_transfer_modes.pl @@ -29,10 +29,8 @@ sub test_mode } $new->init(); - $new->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); - $old->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); + $new->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); + $old->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); # We can only test security labels if both the old and new installations # have dummy_seclabel. @@ -76,15 +74,14 @@ sub test_mode "CREATE TABLE test4 AS SELECT generate_series(400, 502)"); } - $old->safe_psql('postgres', - "CREATE TABLESPACE inplc_tblspc LOCATION ''"); - $old->safe_psql('postgres', - "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); - $old->safe_psql('postgres', - "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" - ); - $old->safe_psql('testdb3', - "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); + $old->safe_psql('postgres', "CREATE TABLESPACE inplc_tblspc LOCATION ''"); + $old->safe_psql('postgres', + "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); + $old->safe_psql('postgres', + "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" + ); + $old->safe_psql('testdb3', + "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); # While we are here, test handling of large objects. $old->safe_psql( @@ -152,12 +149,10 @@ sub test_mode } # Tests for in-place tablespaces. - $result = - $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); - is($result, '104', "test5 data after pg_upgrade $mode"); - $result = - $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); - is($result, '105', "test6 data after pg_upgrade $mode"); + $result = $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); + is($result, '104', "test5 data after pg_upgrade $mode"); + $result = $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); + is($result, '105', "test6 data after pg_upgrade $mode"); # Tests for large objects $result = $new->safe_psql('postgres', "SELECT lo_get(4532)"); diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index 44ef11d980e..c90bf8bbde2 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -6278,23 +6278,22 @@ get_create_object_cmd(EditableObjectType obj_type, Oid oid, * ensure the right view gets replaced. Also, check relation kind * to be sure it's a view. * - * Views may have WITH [LOCAL|CASCADED] - * CHECK OPTION. These are not part of the view definition - * returned by pg_get_viewdef() and so need to be retrieved - * separately. Materialized views may have - * arbitrary storage parameter reloptions. + * Views may have WITH [LOCAL|CASCADED] CHECK OPTION. These are + * not part of the view definition returned by pg_get_viewdef() + * and so need to be retrieved separately. Materialized views may + * have arbitrary storage parameter reloptions. */ printfPQExpBuffer(query, "/* %s */\n", _("Get view's definition and details")); - appendPQExpBuffer(query, - "SELECT nspname, relname, relkind, " - "pg_catalog.pg_get_viewdef(c.oid, true), " - "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " - "FROM pg_catalog.pg_class c " - "LEFT JOIN pg_catalog.pg_namespace n " - "ON c.relnamespace = n.oid WHERE c.oid = %u", - oid); + appendPQExpBuffer(query, + "SELECT nspname, relname, relkind, " + "pg_catalog.pg_get_viewdef(c.oid, true), " + "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " + "FROM pg_catalog.pg_class c " + "LEFT JOIN pg_catalog.pg_namespace n " + "ON c.relnamespace = n.oid WHERE c.oid = %u", + oid); break; } diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index ce99137c613..ac0c55e7aa5 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -387,19 +387,19 @@ describeFunctions(const char *functypes, const char *func_pattern, gettext_noop("stable"), gettext_noop("volatile"), gettext_noop("Volatility")); - appendPQExpBuffer(&buf, - ",\n CASE\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" - " END as \"%s\"", - gettext_noop("restricted"), - gettext_noop("safe"), - gettext_noop("unsafe"), - gettext_noop("Parallel")); + appendPQExpBuffer(&buf, + ",\n CASE\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" + " END as \"%s\"", + gettext_noop("restricted"), + gettext_noop("safe"), + gettext_noop("unsafe"), + gettext_noop("Parallel")); appendPQExpBuffer(&buf, ",\n pg_catalog.pg_get_userbyid(p.proowner) as \"%s\"" ",\n CASE WHEN prosecdef THEN '%s' ELSE '%s' END AS \"%s\"" @@ -599,8 +599,8 @@ describeFunctions(const char *functypes, const char *func_pattern, myopt.title = _("List of functions"); myopt.translate_header = true; - myopt.translate_columns = translate_columns; - myopt.n_translate_columns = lengthof(translate_columns); + myopt.translate_columns = translate_columns; + myopt.n_translate_columns = lengthof(translate_columns); printQuery(res, &myopt, pset.queryFout, false, pset.logfile); @@ -1086,38 +1086,38 @@ permissionsList(const char *pattern, bool showSystem) " ), E'\\n') AS \"%s\"", gettext_noop("Column privileges")); - appendPQExpBuffer(&buf, - ",\n pg_catalog.array_to_string(ARRAY(\n" - " SELECT polname\n" - " || CASE WHEN NOT polpermissive THEN\n" - " E' (RESTRICTIVE)'\n" - " ELSE '' END\n" - " || CASE WHEN polcmd != '*' THEN\n" - " E' (' || polcmd::pg_catalog.text || E'):'\n" - " ELSE E':'\n" - " END\n" - " || CASE WHEN polqual IS NOT NULL THEN\n" - " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" - " ELSE E''\n" - " END\n" - " || CASE WHEN polwithcheck IS NOT NULL THEN\n" - " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" - " ELSE E''\n" - " END" - " || CASE WHEN polroles <> '{0}' THEN\n" - " E'\\n to: ' || pg_catalog.array_to_string(\n" - " ARRAY(\n" - " SELECT rolname\n" - " FROM pg_catalog.pg_roles\n" - " WHERE oid = ANY (polroles)\n" - " ORDER BY 1\n" - " ), E', ')\n" - " ELSE E''\n" - " END\n" - " FROM pg_catalog.pg_policy pol\n" - " WHERE polrelid = c.oid), E'\\n')\n" - " AS \"%s\"", - gettext_noop("Policies")); + appendPQExpBuffer(&buf, + ",\n pg_catalog.array_to_string(ARRAY(\n" + " SELECT polname\n" + " || CASE WHEN NOT polpermissive THEN\n" + " E' (RESTRICTIVE)'\n" + " ELSE '' END\n" + " || CASE WHEN polcmd != '*' THEN\n" + " E' (' || polcmd::pg_catalog.text || E'):'\n" + " ELSE E':'\n" + " END\n" + " || CASE WHEN polqual IS NOT NULL THEN\n" + " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" + " ELSE E''\n" + " END\n" + " || CASE WHEN polwithcheck IS NOT NULL THEN\n" + " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" + " ELSE E''\n" + " END" + " || CASE WHEN polroles <> '{0}' THEN\n" + " E'\\n to: ' || pg_catalog.array_to_string(\n" + " ARRAY(\n" + " SELECT rolname\n" + " FROM pg_catalog.pg_roles\n" + " WHERE oid = ANY (polroles)\n" + " ORDER BY 1\n" + " ), E', ')\n" + " ELSE E''\n" + " END\n" + " FROM pg_catalog.pg_policy pol\n" + " WHERE polrelid = c.oid), E'\\n')\n" + " AS \"%s\"", + gettext_noop("Policies")); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_class c\n" " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n" @@ -1675,27 +1675,27 @@ describeOneTableDetails(const char *schemaname, char *footers[3] = {NULL, NULL, NULL}; printfPQExpBuffer(&buf, "/* %s */\n", _("Get sequence information")); - appendPQExpBuffer(&buf, - "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" - " seqstart AS \"%s\",\n" - " seqmin AS \"%s\",\n" - " seqmax AS \"%s\",\n" - " seqincrement AS \"%s\",\n" - " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" - " seqcache AS \"%s\"\n", - gettext_noop("Type"), - gettext_noop("Start"), - gettext_noop("Minimum"), - gettext_noop("Maximum"), - gettext_noop("Increment"), - gettext_noop("yes"), - gettext_noop("no"), - gettext_noop("Cycles?"), - gettext_noop("Cache")); - appendPQExpBuffer(&buf, - "FROM pg_catalog.pg_sequence\n" - "WHERE seqrelid = '%s';", - oid); + appendPQExpBuffer(&buf, + "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" + " seqstart AS \"%s\",\n" + " seqmin AS \"%s\",\n" + " seqmax AS \"%s\",\n" + " seqincrement AS \"%s\",\n" + " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" + " seqcache AS \"%s\"\n", + gettext_noop("Type"), + gettext_noop("Start"), + gettext_noop("Minimum"), + gettext_noop("Maximum"), + gettext_noop("Increment"), + gettext_noop("yes"), + gettext_noop("no"), + gettext_noop("Cycles?"), + gettext_noop("Cache")); + appendPQExpBuffer(&buf, + "FROM pg_catalog.pg_sequence\n" + "WHERE seqrelid = '%s';", + oid); res = PSQLexec(buf.data); if (!res) @@ -1913,7 +1913,7 @@ describeOneTableDetails(const char *schemaname, appendPQExpBufferStr(&buf, ",\n (SELECT c.collname FROM pg_catalog.pg_collation c, pg_catalog.pg_type t\n" " WHERE c.oid = a.attcollation AND t.oid = a.atttypid AND a.attcollation <> t.typcollation) AS attcollation"); attcoll_col = cols++; - appendPQExpBufferStr(&buf, ",\n a.attidentity"); + appendPQExpBufferStr(&buf, ",\n a.attidentity"); attidentity_col = cols++; if (pset.sversion >= 120000) appendPQExpBufferStr(&buf, ",\n a.attgenerated"); @@ -2326,7 +2326,7 @@ describeOneTableDetails(const char *schemaname, CppAsString2(CONSTRAINT_EXCLUSION) ") AND " "condeferred) AS condeferred,\n"); - appendPQExpBufferStr(&buf, "i.indisreplident,\n"); + appendPQExpBufferStr(&buf, "i.indisreplident,\n"); if (pset.sversion >= 150000) appendPQExpBufferStr(&buf, "i.indnullsnotdistinct,\n"); @@ -2431,7 +2431,7 @@ describeOneTableDetails(const char *schemaname, "pg_catalog.pg_get_indexdef(i.indexrelid, 0, true),\n " "pg_catalog.pg_get_constraintdef(con.oid, true), " "contype, condeferrable, condeferred"); - appendPQExpBufferStr(&buf, ", i.indisreplident"); + appendPQExpBufferStr(&buf, ", i.indisreplident"); appendPQExpBufferStr(&buf, ", c2.reltablespace"); if (pset.sversion >= 180000) appendPQExpBufferStr(&buf, ", con.conperiod"); @@ -2682,81 +2682,80 @@ describeOneTableDetails(const char *schemaname, PQclear(result); /* print any row-level policies */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get row-level policies for this table")); - appendPQExpBufferStr(&buf, "SELECT pol.polname,"); - appendPQExpBufferStr(&buf, - " pol.polpermissive,\n"); - appendPQExpBuffer(&buf, - " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" - " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" - " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" - " CASE pol.polcmd\n" - " WHEN 'r' THEN 'SELECT'\n" - " WHEN 'a' THEN 'INSERT'\n" - " WHEN 'w' THEN 'UPDATE'\n" - " WHEN 'd' THEN 'DELETE'\n" - " END AS cmd\n" - "FROM pg_catalog.pg_policy pol\n" - "WHERE pol.polrelid = '%s' ORDER BY 1;", - oid); + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get row-level policies for this table")); + appendPQExpBufferStr(&buf, "SELECT pol.polname,"); + appendPQExpBufferStr(&buf, + " pol.polpermissive,\n"); + appendPQExpBuffer(&buf, + " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" + " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" + " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" + " CASE pol.polcmd\n" + " WHEN 'r' THEN 'SELECT'\n" + " WHEN 'a' THEN 'INSERT'\n" + " WHEN 'w' THEN 'UPDATE'\n" + " WHEN 'd' THEN 'DELETE'\n" + " END AS cmd\n" + "FROM pg_catalog.pg_policy pol\n" + "WHERE pol.polrelid = '%s' ORDER BY 1;", + oid); - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - /* - * Handle cases where RLS is enabled and there are policies, or - * there aren't policies, or RLS isn't enabled but there are - * policies - */ - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies:")); + /* + * Handle cases where RLS is enabled and there are policies, or there + * aren't policies, or RLS isn't enabled but there are policies + */ + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies:")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled):")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled):")); - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); - if (!tableinfo.rowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (row security disabled):")); + if (!tableinfo.rowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (row security disabled):")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " POLICY \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " POLICY \"%s\"", + PQgetvalue(result, i, 0)); - if (*(PQgetvalue(result, i, 1)) == 'f') - appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); + if (*(PQgetvalue(result, i, 1)) == 'f') + appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); - if (!PQgetisnull(result, i, 5)) - appendPQExpBuffer(&buf, " FOR %s", - PQgetvalue(result, i, 5)); + if (!PQgetisnull(result, i, 5)) + appendPQExpBuffer(&buf, " FOR %s", + PQgetvalue(result, i, 5)); - if (!PQgetisnull(result, i, 2)) - { - appendPQExpBuffer(&buf, "\n TO %s", - PQgetvalue(result, i, 2)); - } + if (!PQgetisnull(result, i, 2)) + { + appendPQExpBuffer(&buf, "\n TO %s", + PQgetvalue(result, i, 2)); + } - if (!PQgetisnull(result, i, 3)) - appendPQExpBuffer(&buf, "\n USING (%s)", - PQgetvalue(result, i, 3)); + if (!PQgetisnull(result, i, 3)) + appendPQExpBuffer(&buf, "\n USING (%s)", + PQgetvalue(result, i, 3)); - if (!PQgetisnull(result, i, 4)) - appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", - PQgetvalue(result, i, 4)); + if (!PQgetisnull(result, i, 4)) + appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", + PQgetvalue(result, i, 4)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* print any extended statistics */ if (pset.sversion >= 140000) @@ -3025,115 +3024,115 @@ describeOneTableDetails(const char *schemaname, } /* print any publications */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get publications that publish this table")); - if (pset.sversion >= 150000) + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get publications that publish this table")); + if (pset.sversion >= 150000) + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" + " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" + "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" + "UNION\n" + "SELECT pubname\n" + " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" + " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" + " (SELECT pg_catalog.string_agg(attname, ', ')\n" + " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" + " pg_catalog.pg_attribute\n" + " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" + " ELSE NULL END) " + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" + "WHERE pr.prrelid = '%s'\n", + oid, oid, oid); + + if (pset.sversion >= 190000) { + /* + * Skip entries where this relation appears in the + * publication's EXCEPT list. + */ appendPQExpBuffer(&buf, + " AND NOT pr.prexcept\n" + "UNION\n" "SELECT pubname\n" " , NULL\n" " , NULL\n" "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" - " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" - "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" - "UNION\n" - "SELECT pubname\n" - " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" - " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" - " (SELECT pg_catalog.string_agg(attname, ', ')\n" - " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" - " pg_catalog.pg_attribute\n" - " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" - " ELSE NULL END) " - "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" - "WHERE pr.prrelid = '%s'\n", + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + " AND NOT EXISTS (\n" + " SELECT 1\n" + " FROM pg_catalog.pg_publication_rel pr\n" + " WHERE pr.prpubid = p.oid AND\n" + " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" + "ORDER BY 1;", oid, oid, oid); - - if (pset.sversion >= 190000) - { - /* - * Skip entries where this relation appears in the - * publication's EXCEPT list. - */ - appendPQExpBuffer(&buf, - " AND NOT pr.prexcept\n" - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - " AND NOT EXISTS (\n" - " SELECT 1\n" - " FROM pg_catalog.pg_publication_rel pr\n" - " WHERE pr.prpubid = p.oid AND\n" - " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" - "ORDER BY 1;", - oid, oid, oid); - } - else - { - appendPQExpBuffer(&buf, - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - "ORDER BY 1;", - oid); - } } else { appendPQExpBuffer(&buf, + "UNION\n" "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - "WHERE pr.prrelid = '%s'\n" - "UNION ALL\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" + " , NULL\n" + " , NULL\n" "FROM pg_catalog.pg_publication p\n" "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" "ORDER BY 1;", - oid, oid); + oid); } + } + else + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + "WHERE pr.prrelid = '%s'\n" + "UNION ALL\n" + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + "ORDER BY 1;", + oid, oid); + } - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - if (tuples > 0) - printTableAddFooter(&cont, _("Included in publications:")); + if (tuples > 0) + printTableAddFooter(&cont, _("Included in publications:")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " \"%s\"", + PQgetvalue(result, i, 0)); - /* column list (if any) */ - if (!PQgetisnull(result, i, 2)) - appendPQExpBuffer(&buf, " (%s)", - PQgetvalue(result, i, 2)); + /* column list (if any) */ + if (!PQgetisnull(result, i, 2)) + appendPQExpBuffer(&buf, " (%s)", + PQgetvalue(result, i, 2)); - /* row filter (if any) */ - if (!PQgetisnull(result, i, 1)) - appendPQExpBuffer(&buf, " WHERE %s", - PQgetvalue(result, i, 1)); + /* row filter (if any) */ + if (!PQgetisnull(result, i, 1)) + appendPQExpBuffer(&buf, " WHERE %s", + PQgetvalue(result, i, 1)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* Print publications where the table is in the EXCEPT clause */ if (pset.sversion >= 190000) @@ -3805,7 +3804,7 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) ncols++; } appendPQExpBufferStr(&buf, "\n, r.rolreplication"); - appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); + appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_roles r\n"); @@ -3860,8 +3859,8 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) if (strcmp(PQgetvalue(res, i, (verbose ? 9 : 8)), "t") == 0) add_role_attribute(&buf, _("Replication")); - if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) - add_role_attribute(&buf, _("Bypass RLS")); + if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) + add_role_attribute(&buf, _("Bypass RLS")); conns = atoi(PQgetvalue(res, i, 6)); if (conns >= 0) @@ -5155,14 +5154,14 @@ listCollations(const char *pattern, bool verbose, bool showSystem) gettext_noop("Schema"), gettext_noop("Name")); - appendPQExpBuffer(&buf, - " CASE c.collprovider " - "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " - "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " - "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " - "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " - "END AS \"%s\",\n", - gettext_noop("Provider")); + appendPQExpBuffer(&buf, + " CASE c.collprovider " + "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " + "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " + "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " + "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " + "END AS \"%s\",\n", + gettext_noop("Provider")); appendPQExpBuffer(&buf, " c.collcollate AS \"%s\",\n" -- 2.50.1 (Apple Git-155) --aHl3HfeiUuO3zeNC-- ^ permalink raw reply [nested|flat] 59+ messages in thread
* [PATCH v6 4/4] run pgindent and pgperltidy @ 2026-06-30 18:24 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 59+ messages in thread From: Nathan Bossart @ 2026-06-30 18:24 UTC (permalink / raw) --- src/bin/pg_dump/pg_dump.c | 464 ++++++++++----------- src/bin/pg_dump/pg_dumpall.c | 30 +- src/bin/pg_upgrade/check.c | 16 +- src/bin/pg_upgrade/controldata.c | 2 +- src/bin/pg_upgrade/exec.c | 8 +- src/bin/pg_upgrade/multixact_rewrite.c | 80 ++-- src/bin/pg_upgrade/pg_upgrade.c | 34 +- src/bin/pg_upgrade/relfilenumber.c | 54 +-- src/bin/pg_upgrade/t/006_transfer_modes.pl | 33 +- src/bin/psql/command.c | 29 +- src/bin/psql/describe.c | 461 ++++++++++---------- 11 files changed, 601 insertions(+), 610 deletions(-) diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 65bd15ebfd2..5673268b467 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -1491,8 +1491,8 @@ setup_connection(Archive *AH, const char *dumpencoding, * Disable timeouts if supported. */ ExecuteSqlStatement(AH, "SET statement_timeout = 0"); - ExecuteSqlStatement(AH, "SET lock_timeout = 0"); - ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); + ExecuteSqlStatement(AH, "SET lock_timeout = 0"); + ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); if (AH->remoteVersion >= 170000) ExecuteSqlStatement(AH, "SET transaction_timeout = 0"); @@ -1505,10 +1505,10 @@ setup_connection(Archive *AH, const char *dumpencoding, /* * Adjust row-security mode, if supported. */ - if (dopt->enable_row_security) - ExecuteSqlStatement(AH, "SET row_security = on"); - else - ExecuteSqlStatement(AH, "SET row_security = off"); + if (dopt->enable_row_security) + ExecuteSqlStatement(AH, "SET row_security = on"); + else + ExecuteSqlStatement(AH, "SET row_security = off"); /* * For security reasons, we restrict the expansion of non-system views and @@ -1933,10 +1933,9 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) addObjectDependency(dobj, ext->dobj.dumpId); /* - * Mark the member object to have any non-initial ACLs - * dumped. (Any initial ACLs will be removed later, using data from - * pg_init_privs, so that we'll dump only the delta from the extension's - * initial setup.) + * Mark the member object to have any non-initial ACLs dumped. (Any + * initial ACLs will be removed later, using data from pg_init_privs, so + * that we'll dump only the delta from the extension's initial setup.) * * In binary upgrades, we still dump all components of the members * individually, since the idea is to exactly reproduce the database @@ -1953,7 +1952,7 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) if (fout->dopt->binary_upgrade) dobj->dump = ext->dobj.dump; else - dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); + dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); return true; } @@ -1987,9 +1986,9 @@ selectDumpableNamespace(NamespaceInfo *nsinfo, Archive *fout) else if (strcmp(nsinfo->dobj.name, "pg_catalog") == 0) { /* - * We dump out any ACLs defined in pg_catalog, if - * they are interesting (and not the original ACLs which were set at - * initdb time, see pg_init_privs). + * We dump out any ACLs defined in pg_catalog, if they are interesting + * (and not the original ACLs which were set at initdb time, see + * pg_init_privs). */ nsinfo->dobj.dump_contains = nsinfo->dobj.dump = DUMP_COMPONENT_ACL; } @@ -3296,7 +3295,7 @@ dumpDatabase(Archive *fout) "datcollate, datctype, datfrozenxid, " "datacl, acldefault('d', datdba) AS acldefault, " "datistemplate, datconnlimit, "); - appendPQExpBufferStr(dbQry, "datminmxid, "); + appendPQExpBufferStr(dbQry, "datminmxid, "); if (fout->remoteVersion >= 170000) appendPQExpBufferStr(dbQry, "datlocprovider, datlocale, datcollversion, "); else if (fout->remoteVersion >= 150000) @@ -3638,11 +3637,11 @@ dumpDatabase(Archive *fout) ii_oid, ii_relminmxid; - appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" - "FROM pg_catalog.pg_class\n" - "WHERE oid IN (%u, %u, %u, %u);\n", - LargeObjectRelationId, LargeObjectLOidPNIndexId, - LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); + appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" + "FROM pg_catalog.pg_class\n" + "WHERE oid IN (%u, %u, %u, %u);\n", + LargeObjectRelationId, LargeObjectLOidPNIndexId, + LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); lo_res = ExecuteSqlQuery(fout, loFrozenQry->data, PGRES_TUPLES_OK); @@ -4274,7 +4273,7 @@ getPolicies(Archive *fout, TableInfo tblinfo[], int numTables) printfPQExpBuffer(query, "SELECT pol.oid, pol.tableoid, pol.polrelid, pol.polname, pol.polcmd, "); - appendPQExpBufferStr(query, "pol.polpermissive, "); + appendPQExpBufferStr(query, "pol.polpermissive, "); appendPQExpBuffer(query, "CASE WHEN pol.polroles = '{0}' THEN NULL ELSE " " pg_catalog.array_to_string(ARRAY(SELECT pg_catalog.quote_ident(rolname) from pg_catalog.pg_roles WHERE oid = ANY(pol.polroles)), ', ') END AS polroles, " @@ -6633,9 +6632,9 @@ getAccessMethods(Archive *fout) * Select all access methods from pg_am table. */ appendPQExpBufferStr(query, "SELECT tableoid, oid, amname, "); - appendPQExpBufferStr(query, - "amtype, " - "amhandler::pg_catalog.regproc AS amhandler "); + appendPQExpBufferStr(query, + "amtype, " + "amhandler::pg_catalog.regproc AS amhandler "); appendPQExpBufferStr(query, "FROM pg_am"); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6827,35 +6826,35 @@ getAggregates(Archive *fout) * Find all interesting aggregates. See comment in getFuncs() for the * rationale behind the filtering logic. */ - agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" - : "p.proisagg"); + agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" + : "p.proisagg"); - appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " - "p.proname AS aggname, " - "p.pronamespace AS aggnamespace, " - "p.pronargs, p.proargtypes, " - "p.proowner, " - "p.proacl AS aggacl, " - "acldefault('f', p.proowner) AS acldefault " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s AND (" - "p.pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog') OR " - "p.proacl IS DISTINCT FROM pip.initprivs", - agg_check); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - " OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); - appendPQExpBufferChar(query, ')'); + appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " + "p.proname AS aggname, " + "p.pronamespace AS aggnamespace, " + "p.pronargs, p.proargtypes, " + "p.proowner, " + "p.proacl AS aggacl, " + "acldefault('f', p.proowner) AS acldefault " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s AND (" + "p.pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog') OR " + "p.proacl IS DISTINCT FROM pip.initprivs", + agg_check); + if (dopt->binary_upgrade) + appendPQExpBufferStr(query, + " OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6957,53 +6956,53 @@ getFuncs(Archive *fout) * include them, since we want to dump extension members individually in * that mode. Also, if they are used by casts or transforms then we need * to gather the information about them, though they won't be dumped if - * they are built-in. Also, include functions in - * pg_catalog if they have an ACL different from what's shown in - * pg_init_privs (so we have to join to pg_init_privs; annoying). + * they are built-in. Also, include functions in pg_catalog if they have + * an ACL different from what's shown in pg_init_privs (so we have to join + * to pg_init_privs; annoying). */ - not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" - : "NOT p.proisagg"); + not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" + : "NOT p.proisagg"); - appendPQExpBuffer(query, - "SELECT p.tableoid, p.oid, p.proname, p.prolang, " - "p.pronargs, p.proargtypes, p.prorettype, " - "p.proacl, " - "acldefault('f', p.proowner) AS acldefault, " - "p.pronamespace, " - "p.proowner " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s" - "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " - "WHERE classid = 'pg_proc'::regclass AND " - "objid = p.oid AND deptype = 'i')" - "\n AND (" - "\n pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog')" - "\n OR EXISTS (SELECT 1 FROM pg_cast" - "\n WHERE pg_cast.oid > %u " - "\n AND p.oid = pg_cast.castfunc)" - "\n OR EXISTS (SELECT 1 FROM pg_transform" - "\n WHERE pg_transform.oid > %u AND " - "\n (p.oid = pg_transform.trffromsql" - "\n OR p.oid = pg_transform.trftosql))", - not_agg_check, - g_last_builtin_oid, - g_last_builtin_oid); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); + appendPQExpBuffer(query, + "SELECT p.tableoid, p.oid, p.proname, p.prolang, " + "p.pronargs, p.proargtypes, p.prorettype, " + "p.proacl, " + "acldefault('f', p.proowner) AS acldefault, " + "p.pronamespace, " + "p.proowner " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s" + "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " + "WHERE classid = 'pg_proc'::regclass AND " + "objid = p.oid AND deptype = 'i')" + "\n AND (" + "\n pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog')" + "\n OR EXISTS (SELECT 1 FROM pg_cast" + "\n WHERE pg_cast.oid > %u " + "\n AND p.oid = pg_cast.castfunc)" + "\n OR EXISTS (SELECT 1 FROM pg_transform" + "\n WHERE pg_transform.oid > %u AND " + "\n (p.oid = pg_transform.trffromsql" + "\n OR p.oid = pg_transform.trftosql))", + not_agg_check, + g_last_builtin_oid, + g_last_builtin_oid); + if (dopt->binary_upgrade) appendPQExpBufferStr(query, - "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); - appendPQExpBufferChar(query, ')'); + "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferStr(query, + "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -7252,31 +7251,31 @@ getTables(Archive *fout, int *numTables) appendPQExpBufferStr(query, "c.relhasoids, "); - appendPQExpBufferStr(query, - "c.relispopulated, "); + appendPQExpBufferStr(query, + "c.relispopulated, "); - appendPQExpBufferStr(query, - "c.relreplident, "); + appendPQExpBufferStr(query, + "c.relreplident, "); - appendPQExpBufferStr(query, - "c.relrowsecurity, c.relforcerowsecurity, "); + appendPQExpBufferStr(query, + "c.relrowsecurity, c.relforcerowsecurity, "); - appendPQExpBufferStr(query, - "c.relminmxid, tc.relminmxid AS tminmxid, "); + appendPQExpBufferStr(query, + "c.relminmxid, tc.relminmxid AS tminmxid, "); - appendPQExpBufferStr(query, - "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); + appendPQExpBufferStr(query, + "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); - appendPQExpBufferStr(query, - "am.amname, "); + appendPQExpBufferStr(query, + "am.amname, "); - appendPQExpBufferStr(query, - "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); + appendPQExpBufferStr(query, + "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); - appendPQExpBufferStr(query, - "c.relispartition AS ispartition "); + appendPQExpBufferStr(query, + "c.relispartition AS ispartition "); /* * Left join to pg_depend to pick up dependency info linking sequences to @@ -7296,8 +7295,8 @@ getTables(Archive *fout, int *numTables) /* * Left join to pg_am to pick up the amname. */ - appendPQExpBufferStr(query, - "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); + appendPQExpBufferStr(query, + "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); /* * We purposefully ignore toast OIDs for partitioned tables; the reason is @@ -7868,8 +7867,8 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables) "t.reloptions AS indreloptions, "); - appendPQExpBufferStr(query, - "i.indisreplident, "); + appendPQExpBufferStr(query, + "i.indisreplident, "); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -9313,8 +9312,8 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables) appendPQExpBufferStr(q, "'' AS attcompression,\n"); - appendPQExpBufferStr(q, - "a.attidentity,\n"); + appendPQExpBufferStr(q, + "a.attidentity,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(q, @@ -10717,73 +10716,73 @@ getAdditionalACLs(Archive *fout) PQclear(res); /* Fetch initial-privileges data */ - printfPQExpBuffer(query, - "SELECT objoid, classoid, objsubid, privtype, initprivs " - "FROM pg_init_privs"); + printfPQExpBuffer(query, + "SELECT objoid, classoid, objsubid, privtype, initprivs " + "FROM pg_init_privs"); - res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); + res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); - ntups = PQntuples(res); - for (i = 0; i < ntups; i++) - { - Oid objoid = atooid(PQgetvalue(res, i, 0)); - Oid classoid = atooid(PQgetvalue(res, i, 1)); - int objsubid = atoi(PQgetvalue(res, i, 2)); - char privtype = *(PQgetvalue(res, i, 3)); - char *initprivs = PQgetvalue(res, i, 4); - CatalogId objId; - DumpableObject *dobj; + ntups = PQntuples(res); + for (i = 0; i < ntups; i++) + { + Oid objoid = atooid(PQgetvalue(res, i, 0)); + Oid classoid = atooid(PQgetvalue(res, i, 1)); + int objsubid = atoi(PQgetvalue(res, i, 2)); + char privtype = *(PQgetvalue(res, i, 3)); + char *initprivs = PQgetvalue(res, i, 4); + CatalogId objId; + DumpableObject *dobj; - objId.tableoid = classoid; - objId.oid = objoid; - dobj = findObjectByCatalogId(objId); - /* OK to ignore entries we haven't got a DumpableObject for */ - if (dobj) + objId.tableoid = classoid; + objId.oid = objoid; + dobj = findObjectByCatalogId(objId); + /* OK to ignore entries we haven't got a DumpableObject for */ + if (dobj) + { + /* Cope with sub-object initprivs */ + if (objsubid != 0) { - /* Cope with sub-object initprivs */ - if (objsubid != 0) - { - if (dobj->objType == DO_TABLE) - { - /* For a column initprivs, set the table's ACL flags */ - dobj->components |= DUMP_COMPONENT_ACL; - ((TableInfo *) dobj)->hascolumnACLs = true; - } - else - pg_log_warning("unsupported pg_init_privs entry: %u %u %d", - classoid, objoid, objsubid); - continue; - } - - /* - * We ignore any pg_init_privs.initprivs entry for the public - * schema, as explained in getNamespaces(). - */ - if (dobj->objType == DO_NAMESPACE && - strcmp(dobj->name, "public") == 0) - continue; - - /* Else it had better be of a type we think has ACLs */ - if (dobj->objType == DO_NAMESPACE || - dobj->objType == DO_TYPE || - dobj->objType == DO_FUNC || - dobj->objType == DO_AGG || - dobj->objType == DO_TABLE || - dobj->objType == DO_PROCLANG || - dobj->objType == DO_FDW || - dobj->objType == DO_FOREIGN_SERVER) + if (dobj->objType == DO_TABLE) { - DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; - - daobj->dacl.privtype = privtype; - daobj->dacl.initprivs = pstrdup(initprivs); + /* For a column initprivs, set the table's ACL flags */ + dobj->components |= DUMP_COMPONENT_ACL; + ((TableInfo *) dobj)->hascolumnACLs = true; } else pg_log_warning("unsupported pg_init_privs entry: %u %u %d", classoid, objoid, objsubid); + continue; + } + + /* + * We ignore any pg_init_privs.initprivs entry for the public + * schema, as explained in getNamespaces(). + */ + if (dobj->objType == DO_NAMESPACE && + strcmp(dobj->name, "public") == 0) + continue; + + /* Else it had better be of a type we think has ACLs */ + if (dobj->objType == DO_NAMESPACE || + dobj->objType == DO_TYPE || + dobj->objType == DO_FUNC || + dobj->objType == DO_AGG || + dobj->objType == DO_TABLE || + dobj->objType == DO_PROCLANG || + dobj->objType == DO_FDW || + dobj->objType == DO_FOREIGN_SERVER) + { + DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; + + daobj->dacl.privtype = privtype; + daobj->dacl.initprivs = pstrdup(initprivs); } + else + pg_log_warning("unsupported pg_init_privs entry: %u %u %d", + classoid, objoid, objsubid); } - PQclear(res); + } + PQclear(res); destroyPQExpBuffer(query); } @@ -11128,8 +11127,8 @@ dumpRelationStats_dumper(Archive *fout, const void *userArg, const TocEntry *te) * The results must be in the order of the relations supplied in the * parameters to ensure we remain in sync as we walk through the TOC. * - * For versions before 19, the redundant filter clause on s.tablename = - * ANY(...) seems sufficient to convince the planner to use + * For versions before 19, the redundant filter clause on s.tablename + * = ANY(...) seems sufficient to convince the planner to use * pg_class_relname_nsp_index, which avoids a full scan of pg_stats. * In newer versions, pg_stats returns the table OIDs, eliminating the * need for that hack. @@ -13469,11 +13468,11 @@ dumpFunc(Archive *fout, const FuncInfo *finfo) "pg_catalog.pg_get_function_result(p.oid) AS funcresult,\n" "proleakproof,\n"); - appendPQExpBufferStr(query, - "array_to_string(protrftypes, ' ') AS protrftypes,\n"); + appendPQExpBufferStr(query, + "array_to_string(protrftypes, ' ') AS protrftypes,\n"); - appendPQExpBufferStr(query, - "proparallel,\n"); + appendPQExpBufferStr(query, + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -14963,9 +14962,9 @@ dumpCollation(Archive *fout, const CollInfo *collinfo) /* Get collation-specific details */ appendPQExpBufferStr(query, "SELECT "); - appendPQExpBufferStr(query, - "collprovider, " - "collversion, "); + appendPQExpBufferStr(query, + "collprovider, " + "collversion, "); if (fout->remoteVersion >= 120000) appendPQExpBufferStr(query, @@ -15372,23 +15371,23 @@ dumpAgg(Archive *fout, const AggInfo *agginfo) "pg_catalog.pg_get_function_arguments(p.oid) AS funcargs,\n" "pg_catalog.pg_get_function_identity_arguments(p.oid) AS funciargs,\n"); - appendPQExpBufferStr(query, - "aggkind,\n" - "aggmtransfn,\n" - "aggminvtransfn,\n" - "aggmfinalfn,\n" - "aggmtranstype::pg_catalog.regtype,\n" - "aggfinalextra,\n" - "aggmfinalextra,\n" - "aggtransspace,\n" - "aggmtransspace,\n" - "aggminitval,\n"); + appendPQExpBufferStr(query, + "aggkind,\n" + "aggmtransfn,\n" + "aggminvtransfn,\n" + "aggmfinalfn,\n" + "aggmtranstype::pg_catalog.regtype,\n" + "aggfinalextra,\n" + "aggmfinalextra,\n" + "aggtransspace,\n" + "aggmtransspace,\n" + "aggminitval,\n"); - appendPQExpBufferStr(query, - "aggcombinefn,\n" - "aggserialfn,\n" - "aggdeserialfn,\n" - "proparallel,\n"); + appendPQExpBufferStr(query, + "aggcombinefn,\n" + "aggserialfn,\n" + "aggdeserialfn,\n" + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -16848,30 +16847,30 @@ dumpTable(Archive *fout, const TableInfo *tbinfo) appendPQExpBufferStr(query, "PREPARE getColumnACLs(pg_catalog.oid) AS\n"); - /* - * In principle we should call acldefault('c', relowner) to - * get the default ACL for a column. However, we don't - * currently store the numeric OID of the relowner in - * TableInfo. We could convert the owner name using regrole, - * but that creates a risk of failure due to concurrent role - * renames. Given that the default ACL for columns is empty - * and is likely to stay that way, it's not worth extra cycles - * and risk to avoid hard-wiring that knowledge here. - */ - appendPQExpBufferStr(query, - "SELECT at.attname, " - "at.attacl, " - "'{}' AS acldefault, " - "pip.privtype, pip.initprivs " - "FROM pg_catalog.pg_attribute at " - "LEFT JOIN pg_catalog.pg_init_privs pip ON " - "(at.attrelid = pip.objoid " - "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " - "AND at.attnum = pip.objsubid) " - "WHERE at.attrelid = $1 AND " - "NOT at.attisdropped " - "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " - "ORDER BY at.attnum"); + /* + * In principle we should call acldefault('c', relowner) to get + * the default ACL for a column. However, we don't currently + * store the numeric OID of the relowner in TableInfo. We could + * convert the owner name using regrole, but that creates a risk + * of failure due to concurrent role renames. Given that the + * default ACL for columns is empty and is likely to stay that + * way, it's not worth extra cycles and risk to avoid hard-wiring + * that knowledge here. + */ + appendPQExpBufferStr(query, + "SELECT at.attname, " + "at.attacl, " + "'{}' AS acldefault, " + "pip.privtype, pip.initprivs " + "FROM pg_catalog.pg_attribute at " + "LEFT JOIN pg_catalog.pg_init_privs pip ON " + "(at.attrelid = pip.objoid " + "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " + "AND at.attnum = pip.objsubid) " + "WHERE at.attrelid = $1 AND " + "NOT at.attisdropped " + "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " + "ORDER BY at.attnum"); ExecuteSqlStatement(fout, query->data); @@ -19165,7 +19164,7 @@ collectSequences(Archive *fout) * pg_get_sequence_data(), but we only do so for non-schema-only dumps. */ if (fout->remoteVersion < 180000 || - (!fout->dopt->dumpData && !fout->dopt->sequence_data)) + (!fout->dopt->dumpData && !fout->dopt->sequence_data)) query = "SELECT seqrelid, format_type(seqtypid, NULL), " "seqstart, seqincrement, " "seqmax, seqmin, " @@ -19227,15 +19226,14 @@ dumpSequence(Archive *fout, const TableInfo *tbinfo) qseqname = pg_strdup(fmtId(tbinfo->dobj.name)); /* - * The sequence information is gathered in a sorted - * table before any calls to dumpSequence(). See collectSequences() for - * more information. + * The sequence information is gathered in a sorted table before any calls + * to dumpSequence(). See collectSequences() for more information. */ - Assert(sequences); + Assert(sequences); - key.oid = tbinfo->dobj.catId.oid; - seq = bsearch(&key, sequences, nsequences, - sizeof(SequenceItem), SequenceItemCmp); + key.oid = tbinfo->dobj.catId.oid; + seq = bsearch(&key, sequences, nsequences, + sizeof(SequenceItem), SequenceItemCmp); /* Calculate default limits for a sequence of this type */ is_ascending = (seq->incby >= 0); diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c index e68937c9934..afcd9a218d8 100644 --- a/src/bin/pg_dump/pg_dumpall.c +++ b/src/bin/pg_dump/pg_dumpall.c @@ -785,11 +785,11 @@ dropRoles(PGconn *conn) int i_rolname; int i; - printfPQExpBuffer(buf, - "SELECT rolname " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 1", role_catalog); + printfPQExpBuffer(buf, + "SELECT rolname " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 1", role_catalog); res = executeQuery(conn, buf->data); @@ -843,16 +843,16 @@ dumpRoles(PGconn *conn) * Notes: rolconfig is dumped later, and pg_authid must be used for * extracting rolcomment regardless of role_catalog. */ - printfPQExpBuffer(buf, - "SELECT oid, rolname, rolsuper, rolinherit, " - "rolcreaterole, rolcreatedb, " - "rolcanlogin, rolconnlimit, rolpassword, " - "rolvaliduntil, rolreplication, rolbypassrls, " - "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " - "rolname = current_user AS is_current_user " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 2", role_catalog); + printfPQExpBuffer(buf, + "SELECT oid, rolname, rolsuper, rolinherit, " + "rolcreaterole, rolcreatedb, " + "rolcanlogin, rolconnlimit, rolpassword, " + "rolvaliduntil, rolreplication, rolbypassrls, " + "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " + "rolname = current_user AS is_current_user " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 2", role_catalog); res = executeQuery(conn, buf->data); diff --git a/src/bin/pg_upgrade/check.c b/src/bin/pg_upgrade/check.c index 786c1474829..f725f5ee3e2 100644 --- a/src/bin/pg_upgrade/check.c +++ b/src/bin/pg_upgrade/check.c @@ -1475,15 +1475,15 @@ check_for_incompatible_polymorphics(ClusterInfo *cluster) ", 'array_cat(anyarray,anyarray)'" ", 'array_prepend(anyelement,anyarray)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_remove(anyarray,anyelement)'" - ", 'array_replace(anyarray,anyelement,anyelement)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_remove(anyarray,anyelement)'" + ", 'array_replace(anyarray,anyelement,anyelement)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_position(anyarray,anyelement)'" - ", 'array_position(anyarray,anyelement,integer)'" - ", 'array_positions(anyarray,anyelement)'" - ", 'width_bucket(anyelement,anyarray)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_position(anyarray,anyelement)'" + ", 'array_position(anyarray,anyelement,integer)'" + ", 'array_positions(anyarray,anyelement)'" + ", 'width_bucket(anyelement,anyarray)'"); /* * The query below hardcodes FirstNormalObjectId as 16384 rather than diff --git a/src/bin/pg_upgrade/controldata.c b/src/bin/pg_upgrade/controldata.c index 8f81c9e9582..02ea02df60f 100644 --- a/src/bin/pg_upgrade/controldata.c +++ b/src/bin/pg_upgrade/controldata.c @@ -228,7 +228,7 @@ get_control_data(ClusterInfo *cluster) p++; /* remove ':' char */ cluster->controldata.chkpnt_nxtepoch = str2uint(p); - p = strchr(p, ':'); + p = strchr(p, ':'); if (p == NULL || strlen(p) <= 1) pg_fatal("%d: controldata retrieval problem", __LINE__); diff --git a/src/bin/pg_upgrade/exec.c b/src/bin/pg_upgrade/exec.c index 44355feea30..a1bdbf373e3 100644 --- a/src/bin/pg_upgrade/exec.c +++ b/src/bin/pg_upgrade/exec.c @@ -55,7 +55,7 @@ get_bin_version(ClusterInfo *cluster) if (sscanf(cmd_output, "%*s %*s %d.%d", &v1, &v2) < 1) pg_fatal("could not get pg_ctl version output from %s", cmd); - cluster->bin_version = v1 * 10000; + cluster->bin_version = v1 * 10000; } @@ -344,8 +344,8 @@ check_data_dir(ClusterInfo *cluster) check_single_dir(pg_data, "pg_subtrans"); check_single_dir(pg_data, PG_TBLSPC_DIR); check_single_dir(pg_data, "pg_twophase"); - check_single_dir(pg_data, "pg_wal"); - check_single_dir(pg_data, "pg_xact"); + check_single_dir(pg_data, "pg_wal"); + check_single_dir(pg_data, "pg_xact"); } @@ -385,7 +385,7 @@ check_bin_dir(ClusterInfo *cluster, bool check_versions) */ get_bin_version(cluster); - check_exec(cluster->bindir, "pg_resetwal", check_versions); + check_exec(cluster->bindir, "pg_resetwal", check_versions); if (cluster == &new_cluster) { diff --git a/src/bin/pg_upgrade/multixact_rewrite.c b/src/bin/pg_upgrade/multixact_rewrite.c index c45b3183684..c7a1416494d 100644 --- a/src/bin/pg_upgrade/multixact_rewrite.c +++ b/src/bin/pg_upgrade/multixact_rewrite.c @@ -61,52 +61,52 @@ rewrite_multixacts(MultiXactId from_multi, MultiXactId to_multi) * Convert old multixids, if needed, by reading them one-by-one from the * old cluster. */ - old_reader = AllocOldMultiXactRead(old_cluster.pgdata, - old_cluster.controldata.chkpnt_nxtmulti, - old_cluster.controldata.chkpnt_nxtmxoff); + old_reader = AllocOldMultiXactRead(old_cluster.pgdata, + old_cluster.controldata.chkpnt_nxtmulti, + old_cluster.controldata.chkpnt_nxtmxoff); - for (MultiXactId multi = from_multi; multi != to_multi;) - { - MultiXactMember member; - bool multixid_valid; - - /* - * Read this multixid's members. - * - * Locking-only XIDs that may be part of multi-xids don't matter - * after upgrade, as there can be no transactions running across - * upgrade. So as a small optimization, we only read one member - * from each multixid: the one updating one, or if there was no - * update, arbitrarily the first locking xid. - */ - multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); + for (MultiXactId multi = from_multi; multi != to_multi;) + { + MultiXactMember member; + bool multixid_valid; - /* - * Write the new offset to pg_multixact/offsets. - * - * Even if this multixid is invalid, we still need to write its - * offset if the *previous* multixid was valid. That's because - * when reading a multixid, the number of members is calculated - * from the difference between the two offsets. - */ - RecordMultiXactOffset(offsets_writer, multi, - (multixid_valid || prev_multixid_valid) ? next_offset : 0); + /* + * Read this multixid's members. + * + * Locking-only XIDs that may be part of multi-xids don't matter after + * upgrade, as there can be no transactions running across upgrade. So + * as a small optimization, we only read one member from each + * multixid: the one updating one, or if there was no update, + * arbitrarily the first locking xid. + */ + multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); - /* Write the members */ - if (multixid_valid) - { - RecordMultiXactMembers(members_writer, next_offset, 1, &member); - next_offset += 1; - } + /* + * Write the new offset to pg_multixact/offsets. + * + * Even if this multixid is invalid, we still need to write its offset + * if the *previous* multixid was valid. That's because when reading + * a multixid, the number of members is calculated from the difference + * between the two offsets. + */ + RecordMultiXactOffset(offsets_writer, multi, + (multixid_valid || prev_multixid_valid) ? next_offset : 0); - /* Advance to next multixid, handling wraparound */ - multi++; - if (multi < FirstMultiXactId) - multi = FirstMultiXactId; - prev_multixid_valid = multixid_valid; + /* Write the members */ + if (multixid_valid) + { + RecordMultiXactMembers(members_writer, next_offset, 1, &member); + next_offset += 1; } - FreeOldMultiXactReader(old_reader); + /* Advance to next multixid, handling wraparound */ + multi++; + if (multi < FirstMultiXactId) + multi = FirstMultiXactId; + prev_multixid_valid = multixid_valid; + } + + FreeOldMultiXactReader(old_reader); /* Write the final 'next' offset to the last SLRU page */ RecordMultiXactOffset(offsets_writer, to_multi, diff --git a/src/bin/pg_upgrade/pg_upgrade.c b/src/bin/pg_upgrade/pg_upgrade.c index c6af9035665..7366fd4627c 100644 --- a/src/bin/pg_upgrade/pg_upgrade.c +++ b/src/bin/pg_upgrade/pg_upgrade.c @@ -833,7 +833,7 @@ copy_xact_xlog_xid(void) * Determine the range of multixacts to convert. */ nxtmulti = old_cluster.controldata.chkpnt_nxtmulti; - oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; + oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; /* handle wraparound */ if (nxtmulti < FirstMultiXactId) nxtmulti = FirstMultiXactId; @@ -898,15 +898,15 @@ set_frozenxids(void) int i_datname; int i_datallowconn; - prep_status("Setting frozenxid and minmxid counters in new cluster"); + prep_status("Setting frozenxid and minmxid counters in new cluster"); conn_template1 = connectToServer(&new_cluster, "template1"); - /* set pg_database.datfrozenxid */ - PQclear(executeQueryOrDie(conn_template1, - "UPDATE pg_catalog.pg_database " - "SET datfrozenxid = '%u'", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_database.datfrozenxid */ + PQclear(executeQueryOrDie(conn_template1, + "UPDATE pg_catalog.pg_database " + "SET datfrozenxid = '%u'", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_database.datminmxid */ PQclear(executeQueryOrDie(conn_template1, @@ -942,16 +942,16 @@ set_frozenxids(void) conn = connectToServer(&new_cluster, datname); - /* set pg_class.relfrozenxid */ - PQclear(executeQueryOrDie(conn, - "UPDATE pg_catalog.pg_class " - "SET relfrozenxid = '%u' " - /* only heap, materialized view, and TOAST are vacuumed */ - "WHERE relkind IN (" - CppAsString2(RELKIND_RELATION) ", " - CppAsString2(RELKIND_MATVIEW) ", " - CppAsString2(RELKIND_TOASTVALUE) ")", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_class.relfrozenxid */ + PQclear(executeQueryOrDie(conn, + "UPDATE pg_catalog.pg_class " + "SET relfrozenxid = '%u' " + /* only heap, materialized view, and TOAST are vacuumed */ + "WHERE relkind IN (" + CppAsString2(RELKIND_RELATION) ", " + CppAsString2(RELKIND_MATVIEW) ", " + CppAsString2(RELKIND_TOASTVALUE) ")", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_class.relminmxid */ PQclear(executeQueryOrDie(conn, diff --git a/src/bin/pg_upgrade/relfilenumber.c b/src/bin/pg_upgrade/relfilenumber.c index ec2ff7acb21..6c467bdc8a5 100644 --- a/src/bin/pg_upgrade/relfilenumber.c +++ b/src/bin/pg_upgrade/relfilenumber.c @@ -587,32 +587,32 @@ transfer_relfile(FileNameMap *map, const char *type_suffix) /* Copying files might take some time, so give feedback. */ pg_log(PG_STATUS, "%s", old_file); - switch (user_opts.transfer_mode) - { - case TRANSFER_MODE_CLONE: - pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", - old_file, new_file); - cloneFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", - old_file, new_file); - copyFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY_FILE_RANGE: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", - old_file, new_file); - copyFileByRange(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_LINK: - pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", - old_file, new_file); - linkFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_SWAP: - /* swap mode is handled in its own code path */ - pg_fatal("should never happen"); - break; - } + switch (user_opts.transfer_mode) + { + case TRANSFER_MODE_CLONE: + pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", + old_file, new_file); + cloneFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", + old_file, new_file); + copyFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY_FILE_RANGE: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", + old_file, new_file); + copyFileByRange(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_LINK: + pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", + old_file, new_file); + linkFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_SWAP: + /* swap mode is handled in its own code path */ + pg_fatal("should never happen"); + break; + } } } diff --git a/src/bin/pg_upgrade/t/006_transfer_modes.pl b/src/bin/pg_upgrade/t/006_transfer_modes.pl index 9efa5dc863c..360d05c4b68 100644 --- a/src/bin/pg_upgrade/t/006_transfer_modes.pl +++ b/src/bin/pg_upgrade/t/006_transfer_modes.pl @@ -29,10 +29,8 @@ sub test_mode } $new->init(); - $new->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); - $old->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); + $new->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); + $old->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); # We can only test security labels if both the old and new installations # have dummy_seclabel. @@ -76,15 +74,14 @@ sub test_mode "CREATE TABLE test4 AS SELECT generate_series(400, 502)"); } - $old->safe_psql('postgres', - "CREATE TABLESPACE inplc_tblspc LOCATION ''"); - $old->safe_psql('postgres', - "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); - $old->safe_psql('postgres', - "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" - ); - $old->safe_psql('testdb3', - "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); + $old->safe_psql('postgres', "CREATE TABLESPACE inplc_tblspc LOCATION ''"); + $old->safe_psql('postgres', + "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); + $old->safe_psql('postgres', + "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" + ); + $old->safe_psql('testdb3', + "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); # While we are here, test handling of large objects. $old->safe_psql( @@ -152,12 +149,10 @@ sub test_mode } # Tests for in-place tablespaces. - $result = - $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); - is($result, '104', "test5 data after pg_upgrade $mode"); - $result = - $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); - is($result, '105', "test6 data after pg_upgrade $mode"); + $result = $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); + is($result, '104', "test5 data after pg_upgrade $mode"); + $result = $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); + is($result, '105', "test6 data after pg_upgrade $mode"); # Tests for large objects $result = $new->safe_psql('postgres', "SELECT lo_get(4532)"); diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index 44ef11d980e..c90bf8bbde2 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -6278,23 +6278,22 @@ get_create_object_cmd(EditableObjectType obj_type, Oid oid, * ensure the right view gets replaced. Also, check relation kind * to be sure it's a view. * - * Views may have WITH [LOCAL|CASCADED] - * CHECK OPTION. These are not part of the view definition - * returned by pg_get_viewdef() and so need to be retrieved - * separately. Materialized views may have - * arbitrary storage parameter reloptions. + * Views may have WITH [LOCAL|CASCADED] CHECK OPTION. These are + * not part of the view definition returned by pg_get_viewdef() + * and so need to be retrieved separately. Materialized views may + * have arbitrary storage parameter reloptions. */ printfPQExpBuffer(query, "/* %s */\n", _("Get view's definition and details")); - appendPQExpBuffer(query, - "SELECT nspname, relname, relkind, " - "pg_catalog.pg_get_viewdef(c.oid, true), " - "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " - "FROM pg_catalog.pg_class c " - "LEFT JOIN pg_catalog.pg_namespace n " - "ON c.relnamespace = n.oid WHERE c.oid = %u", - oid); + appendPQExpBuffer(query, + "SELECT nspname, relname, relkind, " + "pg_catalog.pg_get_viewdef(c.oid, true), " + "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " + "FROM pg_catalog.pg_class c " + "LEFT JOIN pg_catalog.pg_namespace n " + "ON c.relnamespace = n.oid WHERE c.oid = %u", + oid); break; } diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index ce99137c613..ac0c55e7aa5 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -387,19 +387,19 @@ describeFunctions(const char *functypes, const char *func_pattern, gettext_noop("stable"), gettext_noop("volatile"), gettext_noop("Volatility")); - appendPQExpBuffer(&buf, - ",\n CASE\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" - " END as \"%s\"", - gettext_noop("restricted"), - gettext_noop("safe"), - gettext_noop("unsafe"), - gettext_noop("Parallel")); + appendPQExpBuffer(&buf, + ",\n CASE\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" + " END as \"%s\"", + gettext_noop("restricted"), + gettext_noop("safe"), + gettext_noop("unsafe"), + gettext_noop("Parallel")); appendPQExpBuffer(&buf, ",\n pg_catalog.pg_get_userbyid(p.proowner) as \"%s\"" ",\n CASE WHEN prosecdef THEN '%s' ELSE '%s' END AS \"%s\"" @@ -599,8 +599,8 @@ describeFunctions(const char *functypes, const char *func_pattern, myopt.title = _("List of functions"); myopt.translate_header = true; - myopt.translate_columns = translate_columns; - myopt.n_translate_columns = lengthof(translate_columns); + myopt.translate_columns = translate_columns; + myopt.n_translate_columns = lengthof(translate_columns); printQuery(res, &myopt, pset.queryFout, false, pset.logfile); @@ -1086,38 +1086,38 @@ permissionsList(const char *pattern, bool showSystem) " ), E'\\n') AS \"%s\"", gettext_noop("Column privileges")); - appendPQExpBuffer(&buf, - ",\n pg_catalog.array_to_string(ARRAY(\n" - " SELECT polname\n" - " || CASE WHEN NOT polpermissive THEN\n" - " E' (RESTRICTIVE)'\n" - " ELSE '' END\n" - " || CASE WHEN polcmd != '*' THEN\n" - " E' (' || polcmd::pg_catalog.text || E'):'\n" - " ELSE E':'\n" - " END\n" - " || CASE WHEN polqual IS NOT NULL THEN\n" - " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" - " ELSE E''\n" - " END\n" - " || CASE WHEN polwithcheck IS NOT NULL THEN\n" - " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" - " ELSE E''\n" - " END" - " || CASE WHEN polroles <> '{0}' THEN\n" - " E'\\n to: ' || pg_catalog.array_to_string(\n" - " ARRAY(\n" - " SELECT rolname\n" - " FROM pg_catalog.pg_roles\n" - " WHERE oid = ANY (polroles)\n" - " ORDER BY 1\n" - " ), E', ')\n" - " ELSE E''\n" - " END\n" - " FROM pg_catalog.pg_policy pol\n" - " WHERE polrelid = c.oid), E'\\n')\n" - " AS \"%s\"", - gettext_noop("Policies")); + appendPQExpBuffer(&buf, + ",\n pg_catalog.array_to_string(ARRAY(\n" + " SELECT polname\n" + " || CASE WHEN NOT polpermissive THEN\n" + " E' (RESTRICTIVE)'\n" + " ELSE '' END\n" + " || CASE WHEN polcmd != '*' THEN\n" + " E' (' || polcmd::pg_catalog.text || E'):'\n" + " ELSE E':'\n" + " END\n" + " || CASE WHEN polqual IS NOT NULL THEN\n" + " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" + " ELSE E''\n" + " END\n" + " || CASE WHEN polwithcheck IS NOT NULL THEN\n" + " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" + " ELSE E''\n" + " END" + " || CASE WHEN polroles <> '{0}' THEN\n" + " E'\\n to: ' || pg_catalog.array_to_string(\n" + " ARRAY(\n" + " SELECT rolname\n" + " FROM pg_catalog.pg_roles\n" + " WHERE oid = ANY (polroles)\n" + " ORDER BY 1\n" + " ), E', ')\n" + " ELSE E''\n" + " END\n" + " FROM pg_catalog.pg_policy pol\n" + " WHERE polrelid = c.oid), E'\\n')\n" + " AS \"%s\"", + gettext_noop("Policies")); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_class c\n" " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n" @@ -1675,27 +1675,27 @@ describeOneTableDetails(const char *schemaname, char *footers[3] = {NULL, NULL, NULL}; printfPQExpBuffer(&buf, "/* %s */\n", _("Get sequence information")); - appendPQExpBuffer(&buf, - "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" - " seqstart AS \"%s\",\n" - " seqmin AS \"%s\",\n" - " seqmax AS \"%s\",\n" - " seqincrement AS \"%s\",\n" - " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" - " seqcache AS \"%s\"\n", - gettext_noop("Type"), - gettext_noop("Start"), - gettext_noop("Minimum"), - gettext_noop("Maximum"), - gettext_noop("Increment"), - gettext_noop("yes"), - gettext_noop("no"), - gettext_noop("Cycles?"), - gettext_noop("Cache")); - appendPQExpBuffer(&buf, - "FROM pg_catalog.pg_sequence\n" - "WHERE seqrelid = '%s';", - oid); + appendPQExpBuffer(&buf, + "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" + " seqstart AS \"%s\",\n" + " seqmin AS \"%s\",\n" + " seqmax AS \"%s\",\n" + " seqincrement AS \"%s\",\n" + " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" + " seqcache AS \"%s\"\n", + gettext_noop("Type"), + gettext_noop("Start"), + gettext_noop("Minimum"), + gettext_noop("Maximum"), + gettext_noop("Increment"), + gettext_noop("yes"), + gettext_noop("no"), + gettext_noop("Cycles?"), + gettext_noop("Cache")); + appendPQExpBuffer(&buf, + "FROM pg_catalog.pg_sequence\n" + "WHERE seqrelid = '%s';", + oid); res = PSQLexec(buf.data); if (!res) @@ -1913,7 +1913,7 @@ describeOneTableDetails(const char *schemaname, appendPQExpBufferStr(&buf, ",\n (SELECT c.collname FROM pg_catalog.pg_collation c, pg_catalog.pg_type t\n" " WHERE c.oid = a.attcollation AND t.oid = a.atttypid AND a.attcollation <> t.typcollation) AS attcollation"); attcoll_col = cols++; - appendPQExpBufferStr(&buf, ",\n a.attidentity"); + appendPQExpBufferStr(&buf, ",\n a.attidentity"); attidentity_col = cols++; if (pset.sversion >= 120000) appendPQExpBufferStr(&buf, ",\n a.attgenerated"); @@ -2326,7 +2326,7 @@ describeOneTableDetails(const char *schemaname, CppAsString2(CONSTRAINT_EXCLUSION) ") AND " "condeferred) AS condeferred,\n"); - appendPQExpBufferStr(&buf, "i.indisreplident,\n"); + appendPQExpBufferStr(&buf, "i.indisreplident,\n"); if (pset.sversion >= 150000) appendPQExpBufferStr(&buf, "i.indnullsnotdistinct,\n"); @@ -2431,7 +2431,7 @@ describeOneTableDetails(const char *schemaname, "pg_catalog.pg_get_indexdef(i.indexrelid, 0, true),\n " "pg_catalog.pg_get_constraintdef(con.oid, true), " "contype, condeferrable, condeferred"); - appendPQExpBufferStr(&buf, ", i.indisreplident"); + appendPQExpBufferStr(&buf, ", i.indisreplident"); appendPQExpBufferStr(&buf, ", c2.reltablespace"); if (pset.sversion >= 180000) appendPQExpBufferStr(&buf, ", con.conperiod"); @@ -2682,81 +2682,80 @@ describeOneTableDetails(const char *schemaname, PQclear(result); /* print any row-level policies */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get row-level policies for this table")); - appendPQExpBufferStr(&buf, "SELECT pol.polname,"); - appendPQExpBufferStr(&buf, - " pol.polpermissive,\n"); - appendPQExpBuffer(&buf, - " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" - " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" - " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" - " CASE pol.polcmd\n" - " WHEN 'r' THEN 'SELECT'\n" - " WHEN 'a' THEN 'INSERT'\n" - " WHEN 'w' THEN 'UPDATE'\n" - " WHEN 'd' THEN 'DELETE'\n" - " END AS cmd\n" - "FROM pg_catalog.pg_policy pol\n" - "WHERE pol.polrelid = '%s' ORDER BY 1;", - oid); + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get row-level policies for this table")); + appendPQExpBufferStr(&buf, "SELECT pol.polname,"); + appendPQExpBufferStr(&buf, + " pol.polpermissive,\n"); + appendPQExpBuffer(&buf, + " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" + " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" + " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" + " CASE pol.polcmd\n" + " WHEN 'r' THEN 'SELECT'\n" + " WHEN 'a' THEN 'INSERT'\n" + " WHEN 'w' THEN 'UPDATE'\n" + " WHEN 'd' THEN 'DELETE'\n" + " END AS cmd\n" + "FROM pg_catalog.pg_policy pol\n" + "WHERE pol.polrelid = '%s' ORDER BY 1;", + oid); - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - /* - * Handle cases where RLS is enabled and there are policies, or - * there aren't policies, or RLS isn't enabled but there are - * policies - */ - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies:")); + /* + * Handle cases where RLS is enabled and there are policies, or there + * aren't policies, or RLS isn't enabled but there are policies + */ + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies:")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled):")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled):")); - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); - if (!tableinfo.rowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (row security disabled):")); + if (!tableinfo.rowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (row security disabled):")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " POLICY \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " POLICY \"%s\"", + PQgetvalue(result, i, 0)); - if (*(PQgetvalue(result, i, 1)) == 'f') - appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); + if (*(PQgetvalue(result, i, 1)) == 'f') + appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); - if (!PQgetisnull(result, i, 5)) - appendPQExpBuffer(&buf, " FOR %s", - PQgetvalue(result, i, 5)); + if (!PQgetisnull(result, i, 5)) + appendPQExpBuffer(&buf, " FOR %s", + PQgetvalue(result, i, 5)); - if (!PQgetisnull(result, i, 2)) - { - appendPQExpBuffer(&buf, "\n TO %s", - PQgetvalue(result, i, 2)); - } + if (!PQgetisnull(result, i, 2)) + { + appendPQExpBuffer(&buf, "\n TO %s", + PQgetvalue(result, i, 2)); + } - if (!PQgetisnull(result, i, 3)) - appendPQExpBuffer(&buf, "\n USING (%s)", - PQgetvalue(result, i, 3)); + if (!PQgetisnull(result, i, 3)) + appendPQExpBuffer(&buf, "\n USING (%s)", + PQgetvalue(result, i, 3)); - if (!PQgetisnull(result, i, 4)) - appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", - PQgetvalue(result, i, 4)); + if (!PQgetisnull(result, i, 4)) + appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", + PQgetvalue(result, i, 4)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* print any extended statistics */ if (pset.sversion >= 140000) @@ -3025,115 +3024,115 @@ describeOneTableDetails(const char *schemaname, } /* print any publications */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get publications that publish this table")); - if (pset.sversion >= 150000) + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get publications that publish this table")); + if (pset.sversion >= 150000) + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" + " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" + "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" + "UNION\n" + "SELECT pubname\n" + " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" + " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" + " (SELECT pg_catalog.string_agg(attname, ', ')\n" + " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" + " pg_catalog.pg_attribute\n" + " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" + " ELSE NULL END) " + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" + "WHERE pr.prrelid = '%s'\n", + oid, oid, oid); + + if (pset.sversion >= 190000) { + /* + * Skip entries where this relation appears in the + * publication's EXCEPT list. + */ appendPQExpBuffer(&buf, + " AND NOT pr.prexcept\n" + "UNION\n" "SELECT pubname\n" " , NULL\n" " , NULL\n" "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" - " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" - "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" - "UNION\n" - "SELECT pubname\n" - " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" - " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" - " (SELECT pg_catalog.string_agg(attname, ', ')\n" - " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" - " pg_catalog.pg_attribute\n" - " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" - " ELSE NULL END) " - "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" - "WHERE pr.prrelid = '%s'\n", + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + " AND NOT EXISTS (\n" + " SELECT 1\n" + " FROM pg_catalog.pg_publication_rel pr\n" + " WHERE pr.prpubid = p.oid AND\n" + " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" + "ORDER BY 1;", oid, oid, oid); - - if (pset.sversion >= 190000) - { - /* - * Skip entries where this relation appears in the - * publication's EXCEPT list. - */ - appendPQExpBuffer(&buf, - " AND NOT pr.prexcept\n" - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - " AND NOT EXISTS (\n" - " SELECT 1\n" - " FROM pg_catalog.pg_publication_rel pr\n" - " WHERE pr.prpubid = p.oid AND\n" - " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" - "ORDER BY 1;", - oid, oid, oid); - } - else - { - appendPQExpBuffer(&buf, - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - "ORDER BY 1;", - oid); - } } else { appendPQExpBuffer(&buf, + "UNION\n" "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - "WHERE pr.prrelid = '%s'\n" - "UNION ALL\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" + " , NULL\n" + " , NULL\n" "FROM pg_catalog.pg_publication p\n" "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" "ORDER BY 1;", - oid, oid); + oid); } + } + else + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + "WHERE pr.prrelid = '%s'\n" + "UNION ALL\n" + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + "ORDER BY 1;", + oid, oid); + } - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - if (tuples > 0) - printTableAddFooter(&cont, _("Included in publications:")); + if (tuples > 0) + printTableAddFooter(&cont, _("Included in publications:")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " \"%s\"", + PQgetvalue(result, i, 0)); - /* column list (if any) */ - if (!PQgetisnull(result, i, 2)) - appendPQExpBuffer(&buf, " (%s)", - PQgetvalue(result, i, 2)); + /* column list (if any) */ + if (!PQgetisnull(result, i, 2)) + appendPQExpBuffer(&buf, " (%s)", + PQgetvalue(result, i, 2)); - /* row filter (if any) */ - if (!PQgetisnull(result, i, 1)) - appendPQExpBuffer(&buf, " WHERE %s", - PQgetvalue(result, i, 1)); + /* row filter (if any) */ + if (!PQgetisnull(result, i, 1)) + appendPQExpBuffer(&buf, " WHERE %s", + PQgetvalue(result, i, 1)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* Print publications where the table is in the EXCEPT clause */ if (pset.sversion >= 190000) @@ -3805,7 +3804,7 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) ncols++; } appendPQExpBufferStr(&buf, "\n, r.rolreplication"); - appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); + appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_roles r\n"); @@ -3860,8 +3859,8 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) if (strcmp(PQgetvalue(res, i, (verbose ? 9 : 8)), "t") == 0) add_role_attribute(&buf, _("Replication")); - if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) - add_role_attribute(&buf, _("Bypass RLS")); + if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) + add_role_attribute(&buf, _("Bypass RLS")); conns = atoi(PQgetvalue(res, i, 6)); if (conns >= 0) @@ -5155,14 +5154,14 @@ listCollations(const char *pattern, bool verbose, bool showSystem) gettext_noop("Schema"), gettext_noop("Name")); - appendPQExpBuffer(&buf, - " CASE c.collprovider " - "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " - "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " - "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " - "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " - "END AS \"%s\",\n", - gettext_noop("Provider")); + appendPQExpBuffer(&buf, + " CASE c.collprovider " + "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " + "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " + "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " + "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " + "END AS \"%s\",\n", + gettext_noop("Provider")); appendPQExpBuffer(&buf, " c.collcollate AS \"%s\",\n" -- 2.50.1 (Apple Git-155) --aHl3HfeiUuO3zeNC-- ^ permalink raw reply [nested|flat] 59+ messages in thread
* [PATCH v6 4/4] run pgindent and pgperltidy @ 2026-06-30 18:24 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 59+ messages in thread From: Nathan Bossart @ 2026-06-30 18:24 UTC (permalink / raw) --- src/bin/pg_dump/pg_dump.c | 464 ++++++++++----------- src/bin/pg_dump/pg_dumpall.c | 30 +- src/bin/pg_upgrade/check.c | 16 +- src/bin/pg_upgrade/controldata.c | 2 +- src/bin/pg_upgrade/exec.c | 8 +- src/bin/pg_upgrade/multixact_rewrite.c | 80 ++-- src/bin/pg_upgrade/pg_upgrade.c | 34 +- src/bin/pg_upgrade/relfilenumber.c | 54 +-- src/bin/pg_upgrade/t/006_transfer_modes.pl | 33 +- src/bin/psql/command.c | 29 +- src/bin/psql/describe.c | 461 ++++++++++---------- 11 files changed, 601 insertions(+), 610 deletions(-) diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 65bd15ebfd2..5673268b467 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -1491,8 +1491,8 @@ setup_connection(Archive *AH, const char *dumpencoding, * Disable timeouts if supported. */ ExecuteSqlStatement(AH, "SET statement_timeout = 0"); - ExecuteSqlStatement(AH, "SET lock_timeout = 0"); - ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); + ExecuteSqlStatement(AH, "SET lock_timeout = 0"); + ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); if (AH->remoteVersion >= 170000) ExecuteSqlStatement(AH, "SET transaction_timeout = 0"); @@ -1505,10 +1505,10 @@ setup_connection(Archive *AH, const char *dumpencoding, /* * Adjust row-security mode, if supported. */ - if (dopt->enable_row_security) - ExecuteSqlStatement(AH, "SET row_security = on"); - else - ExecuteSqlStatement(AH, "SET row_security = off"); + if (dopt->enable_row_security) + ExecuteSqlStatement(AH, "SET row_security = on"); + else + ExecuteSqlStatement(AH, "SET row_security = off"); /* * For security reasons, we restrict the expansion of non-system views and @@ -1933,10 +1933,9 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) addObjectDependency(dobj, ext->dobj.dumpId); /* - * Mark the member object to have any non-initial ACLs - * dumped. (Any initial ACLs will be removed later, using data from - * pg_init_privs, so that we'll dump only the delta from the extension's - * initial setup.) + * Mark the member object to have any non-initial ACLs dumped. (Any + * initial ACLs will be removed later, using data from pg_init_privs, so + * that we'll dump only the delta from the extension's initial setup.) * * In binary upgrades, we still dump all components of the members * individually, since the idea is to exactly reproduce the database @@ -1953,7 +1952,7 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) if (fout->dopt->binary_upgrade) dobj->dump = ext->dobj.dump; else - dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); + dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); return true; } @@ -1987,9 +1986,9 @@ selectDumpableNamespace(NamespaceInfo *nsinfo, Archive *fout) else if (strcmp(nsinfo->dobj.name, "pg_catalog") == 0) { /* - * We dump out any ACLs defined in pg_catalog, if - * they are interesting (and not the original ACLs which were set at - * initdb time, see pg_init_privs). + * We dump out any ACLs defined in pg_catalog, if they are interesting + * (and not the original ACLs which were set at initdb time, see + * pg_init_privs). */ nsinfo->dobj.dump_contains = nsinfo->dobj.dump = DUMP_COMPONENT_ACL; } @@ -3296,7 +3295,7 @@ dumpDatabase(Archive *fout) "datcollate, datctype, datfrozenxid, " "datacl, acldefault('d', datdba) AS acldefault, " "datistemplate, datconnlimit, "); - appendPQExpBufferStr(dbQry, "datminmxid, "); + appendPQExpBufferStr(dbQry, "datminmxid, "); if (fout->remoteVersion >= 170000) appendPQExpBufferStr(dbQry, "datlocprovider, datlocale, datcollversion, "); else if (fout->remoteVersion >= 150000) @@ -3638,11 +3637,11 @@ dumpDatabase(Archive *fout) ii_oid, ii_relminmxid; - appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" - "FROM pg_catalog.pg_class\n" - "WHERE oid IN (%u, %u, %u, %u);\n", - LargeObjectRelationId, LargeObjectLOidPNIndexId, - LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); + appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" + "FROM pg_catalog.pg_class\n" + "WHERE oid IN (%u, %u, %u, %u);\n", + LargeObjectRelationId, LargeObjectLOidPNIndexId, + LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); lo_res = ExecuteSqlQuery(fout, loFrozenQry->data, PGRES_TUPLES_OK); @@ -4274,7 +4273,7 @@ getPolicies(Archive *fout, TableInfo tblinfo[], int numTables) printfPQExpBuffer(query, "SELECT pol.oid, pol.tableoid, pol.polrelid, pol.polname, pol.polcmd, "); - appendPQExpBufferStr(query, "pol.polpermissive, "); + appendPQExpBufferStr(query, "pol.polpermissive, "); appendPQExpBuffer(query, "CASE WHEN pol.polroles = '{0}' THEN NULL ELSE " " pg_catalog.array_to_string(ARRAY(SELECT pg_catalog.quote_ident(rolname) from pg_catalog.pg_roles WHERE oid = ANY(pol.polroles)), ', ') END AS polroles, " @@ -6633,9 +6632,9 @@ getAccessMethods(Archive *fout) * Select all access methods from pg_am table. */ appendPQExpBufferStr(query, "SELECT tableoid, oid, amname, "); - appendPQExpBufferStr(query, - "amtype, " - "amhandler::pg_catalog.regproc AS amhandler "); + appendPQExpBufferStr(query, + "amtype, " + "amhandler::pg_catalog.regproc AS amhandler "); appendPQExpBufferStr(query, "FROM pg_am"); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6827,35 +6826,35 @@ getAggregates(Archive *fout) * Find all interesting aggregates. See comment in getFuncs() for the * rationale behind the filtering logic. */ - agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" - : "p.proisagg"); + agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" + : "p.proisagg"); - appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " - "p.proname AS aggname, " - "p.pronamespace AS aggnamespace, " - "p.pronargs, p.proargtypes, " - "p.proowner, " - "p.proacl AS aggacl, " - "acldefault('f', p.proowner) AS acldefault " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s AND (" - "p.pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog') OR " - "p.proacl IS DISTINCT FROM pip.initprivs", - agg_check); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - " OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); - appendPQExpBufferChar(query, ')'); + appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " + "p.proname AS aggname, " + "p.pronamespace AS aggnamespace, " + "p.pronargs, p.proargtypes, " + "p.proowner, " + "p.proacl AS aggacl, " + "acldefault('f', p.proowner) AS acldefault " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s AND (" + "p.pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog') OR " + "p.proacl IS DISTINCT FROM pip.initprivs", + agg_check); + if (dopt->binary_upgrade) + appendPQExpBufferStr(query, + " OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6957,53 +6956,53 @@ getFuncs(Archive *fout) * include them, since we want to dump extension members individually in * that mode. Also, if they are used by casts or transforms then we need * to gather the information about them, though they won't be dumped if - * they are built-in. Also, include functions in - * pg_catalog if they have an ACL different from what's shown in - * pg_init_privs (so we have to join to pg_init_privs; annoying). + * they are built-in. Also, include functions in pg_catalog if they have + * an ACL different from what's shown in pg_init_privs (so we have to join + * to pg_init_privs; annoying). */ - not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" - : "NOT p.proisagg"); + not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" + : "NOT p.proisagg"); - appendPQExpBuffer(query, - "SELECT p.tableoid, p.oid, p.proname, p.prolang, " - "p.pronargs, p.proargtypes, p.prorettype, " - "p.proacl, " - "acldefault('f', p.proowner) AS acldefault, " - "p.pronamespace, " - "p.proowner " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s" - "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " - "WHERE classid = 'pg_proc'::regclass AND " - "objid = p.oid AND deptype = 'i')" - "\n AND (" - "\n pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog')" - "\n OR EXISTS (SELECT 1 FROM pg_cast" - "\n WHERE pg_cast.oid > %u " - "\n AND p.oid = pg_cast.castfunc)" - "\n OR EXISTS (SELECT 1 FROM pg_transform" - "\n WHERE pg_transform.oid > %u AND " - "\n (p.oid = pg_transform.trffromsql" - "\n OR p.oid = pg_transform.trftosql))", - not_agg_check, - g_last_builtin_oid, - g_last_builtin_oid); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); + appendPQExpBuffer(query, + "SELECT p.tableoid, p.oid, p.proname, p.prolang, " + "p.pronargs, p.proargtypes, p.prorettype, " + "p.proacl, " + "acldefault('f', p.proowner) AS acldefault, " + "p.pronamespace, " + "p.proowner " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s" + "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " + "WHERE classid = 'pg_proc'::regclass AND " + "objid = p.oid AND deptype = 'i')" + "\n AND (" + "\n pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog')" + "\n OR EXISTS (SELECT 1 FROM pg_cast" + "\n WHERE pg_cast.oid > %u " + "\n AND p.oid = pg_cast.castfunc)" + "\n OR EXISTS (SELECT 1 FROM pg_transform" + "\n WHERE pg_transform.oid > %u AND " + "\n (p.oid = pg_transform.trffromsql" + "\n OR p.oid = pg_transform.trftosql))", + not_agg_check, + g_last_builtin_oid, + g_last_builtin_oid); + if (dopt->binary_upgrade) appendPQExpBufferStr(query, - "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); - appendPQExpBufferChar(query, ')'); + "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferStr(query, + "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -7252,31 +7251,31 @@ getTables(Archive *fout, int *numTables) appendPQExpBufferStr(query, "c.relhasoids, "); - appendPQExpBufferStr(query, - "c.relispopulated, "); + appendPQExpBufferStr(query, + "c.relispopulated, "); - appendPQExpBufferStr(query, - "c.relreplident, "); + appendPQExpBufferStr(query, + "c.relreplident, "); - appendPQExpBufferStr(query, - "c.relrowsecurity, c.relforcerowsecurity, "); + appendPQExpBufferStr(query, + "c.relrowsecurity, c.relforcerowsecurity, "); - appendPQExpBufferStr(query, - "c.relminmxid, tc.relminmxid AS tminmxid, "); + appendPQExpBufferStr(query, + "c.relminmxid, tc.relminmxid AS tminmxid, "); - appendPQExpBufferStr(query, - "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); + appendPQExpBufferStr(query, + "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); - appendPQExpBufferStr(query, - "am.amname, "); + appendPQExpBufferStr(query, + "am.amname, "); - appendPQExpBufferStr(query, - "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); + appendPQExpBufferStr(query, + "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); - appendPQExpBufferStr(query, - "c.relispartition AS ispartition "); + appendPQExpBufferStr(query, + "c.relispartition AS ispartition "); /* * Left join to pg_depend to pick up dependency info linking sequences to @@ -7296,8 +7295,8 @@ getTables(Archive *fout, int *numTables) /* * Left join to pg_am to pick up the amname. */ - appendPQExpBufferStr(query, - "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); + appendPQExpBufferStr(query, + "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); /* * We purposefully ignore toast OIDs for partitioned tables; the reason is @@ -7868,8 +7867,8 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables) "t.reloptions AS indreloptions, "); - appendPQExpBufferStr(query, - "i.indisreplident, "); + appendPQExpBufferStr(query, + "i.indisreplident, "); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -9313,8 +9312,8 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables) appendPQExpBufferStr(q, "'' AS attcompression,\n"); - appendPQExpBufferStr(q, - "a.attidentity,\n"); + appendPQExpBufferStr(q, + "a.attidentity,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(q, @@ -10717,73 +10716,73 @@ getAdditionalACLs(Archive *fout) PQclear(res); /* Fetch initial-privileges data */ - printfPQExpBuffer(query, - "SELECT objoid, classoid, objsubid, privtype, initprivs " - "FROM pg_init_privs"); + printfPQExpBuffer(query, + "SELECT objoid, classoid, objsubid, privtype, initprivs " + "FROM pg_init_privs"); - res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); + res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); - ntups = PQntuples(res); - for (i = 0; i < ntups; i++) - { - Oid objoid = atooid(PQgetvalue(res, i, 0)); - Oid classoid = atooid(PQgetvalue(res, i, 1)); - int objsubid = atoi(PQgetvalue(res, i, 2)); - char privtype = *(PQgetvalue(res, i, 3)); - char *initprivs = PQgetvalue(res, i, 4); - CatalogId objId; - DumpableObject *dobj; + ntups = PQntuples(res); + for (i = 0; i < ntups; i++) + { + Oid objoid = atooid(PQgetvalue(res, i, 0)); + Oid classoid = atooid(PQgetvalue(res, i, 1)); + int objsubid = atoi(PQgetvalue(res, i, 2)); + char privtype = *(PQgetvalue(res, i, 3)); + char *initprivs = PQgetvalue(res, i, 4); + CatalogId objId; + DumpableObject *dobj; - objId.tableoid = classoid; - objId.oid = objoid; - dobj = findObjectByCatalogId(objId); - /* OK to ignore entries we haven't got a DumpableObject for */ - if (dobj) + objId.tableoid = classoid; + objId.oid = objoid; + dobj = findObjectByCatalogId(objId); + /* OK to ignore entries we haven't got a DumpableObject for */ + if (dobj) + { + /* Cope with sub-object initprivs */ + if (objsubid != 0) { - /* Cope with sub-object initprivs */ - if (objsubid != 0) - { - if (dobj->objType == DO_TABLE) - { - /* For a column initprivs, set the table's ACL flags */ - dobj->components |= DUMP_COMPONENT_ACL; - ((TableInfo *) dobj)->hascolumnACLs = true; - } - else - pg_log_warning("unsupported pg_init_privs entry: %u %u %d", - classoid, objoid, objsubid); - continue; - } - - /* - * We ignore any pg_init_privs.initprivs entry for the public - * schema, as explained in getNamespaces(). - */ - if (dobj->objType == DO_NAMESPACE && - strcmp(dobj->name, "public") == 0) - continue; - - /* Else it had better be of a type we think has ACLs */ - if (dobj->objType == DO_NAMESPACE || - dobj->objType == DO_TYPE || - dobj->objType == DO_FUNC || - dobj->objType == DO_AGG || - dobj->objType == DO_TABLE || - dobj->objType == DO_PROCLANG || - dobj->objType == DO_FDW || - dobj->objType == DO_FOREIGN_SERVER) + if (dobj->objType == DO_TABLE) { - DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; - - daobj->dacl.privtype = privtype; - daobj->dacl.initprivs = pstrdup(initprivs); + /* For a column initprivs, set the table's ACL flags */ + dobj->components |= DUMP_COMPONENT_ACL; + ((TableInfo *) dobj)->hascolumnACLs = true; } else pg_log_warning("unsupported pg_init_privs entry: %u %u %d", classoid, objoid, objsubid); + continue; + } + + /* + * We ignore any pg_init_privs.initprivs entry for the public + * schema, as explained in getNamespaces(). + */ + if (dobj->objType == DO_NAMESPACE && + strcmp(dobj->name, "public") == 0) + continue; + + /* Else it had better be of a type we think has ACLs */ + if (dobj->objType == DO_NAMESPACE || + dobj->objType == DO_TYPE || + dobj->objType == DO_FUNC || + dobj->objType == DO_AGG || + dobj->objType == DO_TABLE || + dobj->objType == DO_PROCLANG || + dobj->objType == DO_FDW || + dobj->objType == DO_FOREIGN_SERVER) + { + DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; + + daobj->dacl.privtype = privtype; + daobj->dacl.initprivs = pstrdup(initprivs); } + else + pg_log_warning("unsupported pg_init_privs entry: %u %u %d", + classoid, objoid, objsubid); } - PQclear(res); + } + PQclear(res); destroyPQExpBuffer(query); } @@ -11128,8 +11127,8 @@ dumpRelationStats_dumper(Archive *fout, const void *userArg, const TocEntry *te) * The results must be in the order of the relations supplied in the * parameters to ensure we remain in sync as we walk through the TOC. * - * For versions before 19, the redundant filter clause on s.tablename = - * ANY(...) seems sufficient to convince the planner to use + * For versions before 19, the redundant filter clause on s.tablename + * = ANY(...) seems sufficient to convince the planner to use * pg_class_relname_nsp_index, which avoids a full scan of pg_stats. * In newer versions, pg_stats returns the table OIDs, eliminating the * need for that hack. @@ -13469,11 +13468,11 @@ dumpFunc(Archive *fout, const FuncInfo *finfo) "pg_catalog.pg_get_function_result(p.oid) AS funcresult,\n" "proleakproof,\n"); - appendPQExpBufferStr(query, - "array_to_string(protrftypes, ' ') AS protrftypes,\n"); + appendPQExpBufferStr(query, + "array_to_string(protrftypes, ' ') AS protrftypes,\n"); - appendPQExpBufferStr(query, - "proparallel,\n"); + appendPQExpBufferStr(query, + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -14963,9 +14962,9 @@ dumpCollation(Archive *fout, const CollInfo *collinfo) /* Get collation-specific details */ appendPQExpBufferStr(query, "SELECT "); - appendPQExpBufferStr(query, - "collprovider, " - "collversion, "); + appendPQExpBufferStr(query, + "collprovider, " + "collversion, "); if (fout->remoteVersion >= 120000) appendPQExpBufferStr(query, @@ -15372,23 +15371,23 @@ dumpAgg(Archive *fout, const AggInfo *agginfo) "pg_catalog.pg_get_function_arguments(p.oid) AS funcargs,\n" "pg_catalog.pg_get_function_identity_arguments(p.oid) AS funciargs,\n"); - appendPQExpBufferStr(query, - "aggkind,\n" - "aggmtransfn,\n" - "aggminvtransfn,\n" - "aggmfinalfn,\n" - "aggmtranstype::pg_catalog.regtype,\n" - "aggfinalextra,\n" - "aggmfinalextra,\n" - "aggtransspace,\n" - "aggmtransspace,\n" - "aggminitval,\n"); + appendPQExpBufferStr(query, + "aggkind,\n" + "aggmtransfn,\n" + "aggminvtransfn,\n" + "aggmfinalfn,\n" + "aggmtranstype::pg_catalog.regtype,\n" + "aggfinalextra,\n" + "aggmfinalextra,\n" + "aggtransspace,\n" + "aggmtransspace,\n" + "aggminitval,\n"); - appendPQExpBufferStr(query, - "aggcombinefn,\n" - "aggserialfn,\n" - "aggdeserialfn,\n" - "proparallel,\n"); + appendPQExpBufferStr(query, + "aggcombinefn,\n" + "aggserialfn,\n" + "aggdeserialfn,\n" + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -16848,30 +16847,30 @@ dumpTable(Archive *fout, const TableInfo *tbinfo) appendPQExpBufferStr(query, "PREPARE getColumnACLs(pg_catalog.oid) AS\n"); - /* - * In principle we should call acldefault('c', relowner) to - * get the default ACL for a column. However, we don't - * currently store the numeric OID of the relowner in - * TableInfo. We could convert the owner name using regrole, - * but that creates a risk of failure due to concurrent role - * renames. Given that the default ACL for columns is empty - * and is likely to stay that way, it's not worth extra cycles - * and risk to avoid hard-wiring that knowledge here. - */ - appendPQExpBufferStr(query, - "SELECT at.attname, " - "at.attacl, " - "'{}' AS acldefault, " - "pip.privtype, pip.initprivs " - "FROM pg_catalog.pg_attribute at " - "LEFT JOIN pg_catalog.pg_init_privs pip ON " - "(at.attrelid = pip.objoid " - "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " - "AND at.attnum = pip.objsubid) " - "WHERE at.attrelid = $1 AND " - "NOT at.attisdropped " - "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " - "ORDER BY at.attnum"); + /* + * In principle we should call acldefault('c', relowner) to get + * the default ACL for a column. However, we don't currently + * store the numeric OID of the relowner in TableInfo. We could + * convert the owner name using regrole, but that creates a risk + * of failure due to concurrent role renames. Given that the + * default ACL for columns is empty and is likely to stay that + * way, it's not worth extra cycles and risk to avoid hard-wiring + * that knowledge here. + */ + appendPQExpBufferStr(query, + "SELECT at.attname, " + "at.attacl, " + "'{}' AS acldefault, " + "pip.privtype, pip.initprivs " + "FROM pg_catalog.pg_attribute at " + "LEFT JOIN pg_catalog.pg_init_privs pip ON " + "(at.attrelid = pip.objoid " + "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " + "AND at.attnum = pip.objsubid) " + "WHERE at.attrelid = $1 AND " + "NOT at.attisdropped " + "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " + "ORDER BY at.attnum"); ExecuteSqlStatement(fout, query->data); @@ -19165,7 +19164,7 @@ collectSequences(Archive *fout) * pg_get_sequence_data(), but we only do so for non-schema-only dumps. */ if (fout->remoteVersion < 180000 || - (!fout->dopt->dumpData && !fout->dopt->sequence_data)) + (!fout->dopt->dumpData && !fout->dopt->sequence_data)) query = "SELECT seqrelid, format_type(seqtypid, NULL), " "seqstart, seqincrement, " "seqmax, seqmin, " @@ -19227,15 +19226,14 @@ dumpSequence(Archive *fout, const TableInfo *tbinfo) qseqname = pg_strdup(fmtId(tbinfo->dobj.name)); /* - * The sequence information is gathered in a sorted - * table before any calls to dumpSequence(). See collectSequences() for - * more information. + * The sequence information is gathered in a sorted table before any calls + * to dumpSequence(). See collectSequences() for more information. */ - Assert(sequences); + Assert(sequences); - key.oid = tbinfo->dobj.catId.oid; - seq = bsearch(&key, sequences, nsequences, - sizeof(SequenceItem), SequenceItemCmp); + key.oid = tbinfo->dobj.catId.oid; + seq = bsearch(&key, sequences, nsequences, + sizeof(SequenceItem), SequenceItemCmp); /* Calculate default limits for a sequence of this type */ is_ascending = (seq->incby >= 0); diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c index e68937c9934..afcd9a218d8 100644 --- a/src/bin/pg_dump/pg_dumpall.c +++ b/src/bin/pg_dump/pg_dumpall.c @@ -785,11 +785,11 @@ dropRoles(PGconn *conn) int i_rolname; int i; - printfPQExpBuffer(buf, - "SELECT rolname " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 1", role_catalog); + printfPQExpBuffer(buf, + "SELECT rolname " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 1", role_catalog); res = executeQuery(conn, buf->data); @@ -843,16 +843,16 @@ dumpRoles(PGconn *conn) * Notes: rolconfig is dumped later, and pg_authid must be used for * extracting rolcomment regardless of role_catalog. */ - printfPQExpBuffer(buf, - "SELECT oid, rolname, rolsuper, rolinherit, " - "rolcreaterole, rolcreatedb, " - "rolcanlogin, rolconnlimit, rolpassword, " - "rolvaliduntil, rolreplication, rolbypassrls, " - "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " - "rolname = current_user AS is_current_user " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 2", role_catalog); + printfPQExpBuffer(buf, + "SELECT oid, rolname, rolsuper, rolinherit, " + "rolcreaterole, rolcreatedb, " + "rolcanlogin, rolconnlimit, rolpassword, " + "rolvaliduntil, rolreplication, rolbypassrls, " + "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " + "rolname = current_user AS is_current_user " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 2", role_catalog); res = executeQuery(conn, buf->data); diff --git a/src/bin/pg_upgrade/check.c b/src/bin/pg_upgrade/check.c index 786c1474829..f725f5ee3e2 100644 --- a/src/bin/pg_upgrade/check.c +++ b/src/bin/pg_upgrade/check.c @@ -1475,15 +1475,15 @@ check_for_incompatible_polymorphics(ClusterInfo *cluster) ", 'array_cat(anyarray,anyarray)'" ", 'array_prepend(anyelement,anyarray)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_remove(anyarray,anyelement)'" - ", 'array_replace(anyarray,anyelement,anyelement)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_remove(anyarray,anyelement)'" + ", 'array_replace(anyarray,anyelement,anyelement)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_position(anyarray,anyelement)'" - ", 'array_position(anyarray,anyelement,integer)'" - ", 'array_positions(anyarray,anyelement)'" - ", 'width_bucket(anyelement,anyarray)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_position(anyarray,anyelement)'" + ", 'array_position(anyarray,anyelement,integer)'" + ", 'array_positions(anyarray,anyelement)'" + ", 'width_bucket(anyelement,anyarray)'"); /* * The query below hardcodes FirstNormalObjectId as 16384 rather than diff --git a/src/bin/pg_upgrade/controldata.c b/src/bin/pg_upgrade/controldata.c index 8f81c9e9582..02ea02df60f 100644 --- a/src/bin/pg_upgrade/controldata.c +++ b/src/bin/pg_upgrade/controldata.c @@ -228,7 +228,7 @@ get_control_data(ClusterInfo *cluster) p++; /* remove ':' char */ cluster->controldata.chkpnt_nxtepoch = str2uint(p); - p = strchr(p, ':'); + p = strchr(p, ':'); if (p == NULL || strlen(p) <= 1) pg_fatal("%d: controldata retrieval problem", __LINE__); diff --git a/src/bin/pg_upgrade/exec.c b/src/bin/pg_upgrade/exec.c index 44355feea30..a1bdbf373e3 100644 --- a/src/bin/pg_upgrade/exec.c +++ b/src/bin/pg_upgrade/exec.c @@ -55,7 +55,7 @@ get_bin_version(ClusterInfo *cluster) if (sscanf(cmd_output, "%*s %*s %d.%d", &v1, &v2) < 1) pg_fatal("could not get pg_ctl version output from %s", cmd); - cluster->bin_version = v1 * 10000; + cluster->bin_version = v1 * 10000; } @@ -344,8 +344,8 @@ check_data_dir(ClusterInfo *cluster) check_single_dir(pg_data, "pg_subtrans"); check_single_dir(pg_data, PG_TBLSPC_DIR); check_single_dir(pg_data, "pg_twophase"); - check_single_dir(pg_data, "pg_wal"); - check_single_dir(pg_data, "pg_xact"); + check_single_dir(pg_data, "pg_wal"); + check_single_dir(pg_data, "pg_xact"); } @@ -385,7 +385,7 @@ check_bin_dir(ClusterInfo *cluster, bool check_versions) */ get_bin_version(cluster); - check_exec(cluster->bindir, "pg_resetwal", check_versions); + check_exec(cluster->bindir, "pg_resetwal", check_versions); if (cluster == &new_cluster) { diff --git a/src/bin/pg_upgrade/multixact_rewrite.c b/src/bin/pg_upgrade/multixact_rewrite.c index c45b3183684..c7a1416494d 100644 --- a/src/bin/pg_upgrade/multixact_rewrite.c +++ b/src/bin/pg_upgrade/multixact_rewrite.c @@ -61,52 +61,52 @@ rewrite_multixacts(MultiXactId from_multi, MultiXactId to_multi) * Convert old multixids, if needed, by reading them one-by-one from the * old cluster. */ - old_reader = AllocOldMultiXactRead(old_cluster.pgdata, - old_cluster.controldata.chkpnt_nxtmulti, - old_cluster.controldata.chkpnt_nxtmxoff); + old_reader = AllocOldMultiXactRead(old_cluster.pgdata, + old_cluster.controldata.chkpnt_nxtmulti, + old_cluster.controldata.chkpnt_nxtmxoff); - for (MultiXactId multi = from_multi; multi != to_multi;) - { - MultiXactMember member; - bool multixid_valid; - - /* - * Read this multixid's members. - * - * Locking-only XIDs that may be part of multi-xids don't matter - * after upgrade, as there can be no transactions running across - * upgrade. So as a small optimization, we only read one member - * from each multixid: the one updating one, or if there was no - * update, arbitrarily the first locking xid. - */ - multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); + for (MultiXactId multi = from_multi; multi != to_multi;) + { + MultiXactMember member; + bool multixid_valid; - /* - * Write the new offset to pg_multixact/offsets. - * - * Even if this multixid is invalid, we still need to write its - * offset if the *previous* multixid was valid. That's because - * when reading a multixid, the number of members is calculated - * from the difference between the two offsets. - */ - RecordMultiXactOffset(offsets_writer, multi, - (multixid_valid || prev_multixid_valid) ? next_offset : 0); + /* + * Read this multixid's members. + * + * Locking-only XIDs that may be part of multi-xids don't matter after + * upgrade, as there can be no transactions running across upgrade. So + * as a small optimization, we only read one member from each + * multixid: the one updating one, or if there was no update, + * arbitrarily the first locking xid. + */ + multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); - /* Write the members */ - if (multixid_valid) - { - RecordMultiXactMembers(members_writer, next_offset, 1, &member); - next_offset += 1; - } + /* + * Write the new offset to pg_multixact/offsets. + * + * Even if this multixid is invalid, we still need to write its offset + * if the *previous* multixid was valid. That's because when reading + * a multixid, the number of members is calculated from the difference + * between the two offsets. + */ + RecordMultiXactOffset(offsets_writer, multi, + (multixid_valid || prev_multixid_valid) ? next_offset : 0); - /* Advance to next multixid, handling wraparound */ - multi++; - if (multi < FirstMultiXactId) - multi = FirstMultiXactId; - prev_multixid_valid = multixid_valid; + /* Write the members */ + if (multixid_valid) + { + RecordMultiXactMembers(members_writer, next_offset, 1, &member); + next_offset += 1; } - FreeOldMultiXactReader(old_reader); + /* Advance to next multixid, handling wraparound */ + multi++; + if (multi < FirstMultiXactId) + multi = FirstMultiXactId; + prev_multixid_valid = multixid_valid; + } + + FreeOldMultiXactReader(old_reader); /* Write the final 'next' offset to the last SLRU page */ RecordMultiXactOffset(offsets_writer, to_multi, diff --git a/src/bin/pg_upgrade/pg_upgrade.c b/src/bin/pg_upgrade/pg_upgrade.c index c6af9035665..7366fd4627c 100644 --- a/src/bin/pg_upgrade/pg_upgrade.c +++ b/src/bin/pg_upgrade/pg_upgrade.c @@ -833,7 +833,7 @@ copy_xact_xlog_xid(void) * Determine the range of multixacts to convert. */ nxtmulti = old_cluster.controldata.chkpnt_nxtmulti; - oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; + oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; /* handle wraparound */ if (nxtmulti < FirstMultiXactId) nxtmulti = FirstMultiXactId; @@ -898,15 +898,15 @@ set_frozenxids(void) int i_datname; int i_datallowconn; - prep_status("Setting frozenxid and minmxid counters in new cluster"); + prep_status("Setting frozenxid and minmxid counters in new cluster"); conn_template1 = connectToServer(&new_cluster, "template1"); - /* set pg_database.datfrozenxid */ - PQclear(executeQueryOrDie(conn_template1, - "UPDATE pg_catalog.pg_database " - "SET datfrozenxid = '%u'", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_database.datfrozenxid */ + PQclear(executeQueryOrDie(conn_template1, + "UPDATE pg_catalog.pg_database " + "SET datfrozenxid = '%u'", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_database.datminmxid */ PQclear(executeQueryOrDie(conn_template1, @@ -942,16 +942,16 @@ set_frozenxids(void) conn = connectToServer(&new_cluster, datname); - /* set pg_class.relfrozenxid */ - PQclear(executeQueryOrDie(conn, - "UPDATE pg_catalog.pg_class " - "SET relfrozenxid = '%u' " - /* only heap, materialized view, and TOAST are vacuumed */ - "WHERE relkind IN (" - CppAsString2(RELKIND_RELATION) ", " - CppAsString2(RELKIND_MATVIEW) ", " - CppAsString2(RELKIND_TOASTVALUE) ")", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_class.relfrozenxid */ + PQclear(executeQueryOrDie(conn, + "UPDATE pg_catalog.pg_class " + "SET relfrozenxid = '%u' " + /* only heap, materialized view, and TOAST are vacuumed */ + "WHERE relkind IN (" + CppAsString2(RELKIND_RELATION) ", " + CppAsString2(RELKIND_MATVIEW) ", " + CppAsString2(RELKIND_TOASTVALUE) ")", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_class.relminmxid */ PQclear(executeQueryOrDie(conn, diff --git a/src/bin/pg_upgrade/relfilenumber.c b/src/bin/pg_upgrade/relfilenumber.c index ec2ff7acb21..6c467bdc8a5 100644 --- a/src/bin/pg_upgrade/relfilenumber.c +++ b/src/bin/pg_upgrade/relfilenumber.c @@ -587,32 +587,32 @@ transfer_relfile(FileNameMap *map, const char *type_suffix) /* Copying files might take some time, so give feedback. */ pg_log(PG_STATUS, "%s", old_file); - switch (user_opts.transfer_mode) - { - case TRANSFER_MODE_CLONE: - pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", - old_file, new_file); - cloneFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", - old_file, new_file); - copyFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY_FILE_RANGE: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", - old_file, new_file); - copyFileByRange(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_LINK: - pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", - old_file, new_file); - linkFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_SWAP: - /* swap mode is handled in its own code path */ - pg_fatal("should never happen"); - break; - } + switch (user_opts.transfer_mode) + { + case TRANSFER_MODE_CLONE: + pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", + old_file, new_file); + cloneFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", + old_file, new_file); + copyFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY_FILE_RANGE: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", + old_file, new_file); + copyFileByRange(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_LINK: + pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", + old_file, new_file); + linkFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_SWAP: + /* swap mode is handled in its own code path */ + pg_fatal("should never happen"); + break; + } } } diff --git a/src/bin/pg_upgrade/t/006_transfer_modes.pl b/src/bin/pg_upgrade/t/006_transfer_modes.pl index 9efa5dc863c..360d05c4b68 100644 --- a/src/bin/pg_upgrade/t/006_transfer_modes.pl +++ b/src/bin/pg_upgrade/t/006_transfer_modes.pl @@ -29,10 +29,8 @@ sub test_mode } $new->init(); - $new->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); - $old->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); + $new->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); + $old->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); # We can only test security labels if both the old and new installations # have dummy_seclabel. @@ -76,15 +74,14 @@ sub test_mode "CREATE TABLE test4 AS SELECT generate_series(400, 502)"); } - $old->safe_psql('postgres', - "CREATE TABLESPACE inplc_tblspc LOCATION ''"); - $old->safe_psql('postgres', - "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); - $old->safe_psql('postgres', - "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" - ); - $old->safe_psql('testdb3', - "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); + $old->safe_psql('postgres', "CREATE TABLESPACE inplc_tblspc LOCATION ''"); + $old->safe_psql('postgres', + "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); + $old->safe_psql('postgres', + "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" + ); + $old->safe_psql('testdb3', + "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); # While we are here, test handling of large objects. $old->safe_psql( @@ -152,12 +149,10 @@ sub test_mode } # Tests for in-place tablespaces. - $result = - $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); - is($result, '104', "test5 data after pg_upgrade $mode"); - $result = - $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); - is($result, '105', "test6 data after pg_upgrade $mode"); + $result = $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); + is($result, '104', "test5 data after pg_upgrade $mode"); + $result = $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); + is($result, '105', "test6 data after pg_upgrade $mode"); # Tests for large objects $result = $new->safe_psql('postgres', "SELECT lo_get(4532)"); diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index 44ef11d980e..c90bf8bbde2 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -6278,23 +6278,22 @@ get_create_object_cmd(EditableObjectType obj_type, Oid oid, * ensure the right view gets replaced. Also, check relation kind * to be sure it's a view. * - * Views may have WITH [LOCAL|CASCADED] - * CHECK OPTION. These are not part of the view definition - * returned by pg_get_viewdef() and so need to be retrieved - * separately. Materialized views may have - * arbitrary storage parameter reloptions. + * Views may have WITH [LOCAL|CASCADED] CHECK OPTION. These are + * not part of the view definition returned by pg_get_viewdef() + * and so need to be retrieved separately. Materialized views may + * have arbitrary storage parameter reloptions. */ printfPQExpBuffer(query, "/* %s */\n", _("Get view's definition and details")); - appendPQExpBuffer(query, - "SELECT nspname, relname, relkind, " - "pg_catalog.pg_get_viewdef(c.oid, true), " - "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " - "FROM pg_catalog.pg_class c " - "LEFT JOIN pg_catalog.pg_namespace n " - "ON c.relnamespace = n.oid WHERE c.oid = %u", - oid); + appendPQExpBuffer(query, + "SELECT nspname, relname, relkind, " + "pg_catalog.pg_get_viewdef(c.oid, true), " + "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " + "FROM pg_catalog.pg_class c " + "LEFT JOIN pg_catalog.pg_namespace n " + "ON c.relnamespace = n.oid WHERE c.oid = %u", + oid); break; } diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index ce99137c613..ac0c55e7aa5 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -387,19 +387,19 @@ describeFunctions(const char *functypes, const char *func_pattern, gettext_noop("stable"), gettext_noop("volatile"), gettext_noop("Volatility")); - appendPQExpBuffer(&buf, - ",\n CASE\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" - " END as \"%s\"", - gettext_noop("restricted"), - gettext_noop("safe"), - gettext_noop("unsafe"), - gettext_noop("Parallel")); + appendPQExpBuffer(&buf, + ",\n CASE\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" + " END as \"%s\"", + gettext_noop("restricted"), + gettext_noop("safe"), + gettext_noop("unsafe"), + gettext_noop("Parallel")); appendPQExpBuffer(&buf, ",\n pg_catalog.pg_get_userbyid(p.proowner) as \"%s\"" ",\n CASE WHEN prosecdef THEN '%s' ELSE '%s' END AS \"%s\"" @@ -599,8 +599,8 @@ describeFunctions(const char *functypes, const char *func_pattern, myopt.title = _("List of functions"); myopt.translate_header = true; - myopt.translate_columns = translate_columns; - myopt.n_translate_columns = lengthof(translate_columns); + myopt.translate_columns = translate_columns; + myopt.n_translate_columns = lengthof(translate_columns); printQuery(res, &myopt, pset.queryFout, false, pset.logfile); @@ -1086,38 +1086,38 @@ permissionsList(const char *pattern, bool showSystem) " ), E'\\n') AS \"%s\"", gettext_noop("Column privileges")); - appendPQExpBuffer(&buf, - ",\n pg_catalog.array_to_string(ARRAY(\n" - " SELECT polname\n" - " || CASE WHEN NOT polpermissive THEN\n" - " E' (RESTRICTIVE)'\n" - " ELSE '' END\n" - " || CASE WHEN polcmd != '*' THEN\n" - " E' (' || polcmd::pg_catalog.text || E'):'\n" - " ELSE E':'\n" - " END\n" - " || CASE WHEN polqual IS NOT NULL THEN\n" - " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" - " ELSE E''\n" - " END\n" - " || CASE WHEN polwithcheck IS NOT NULL THEN\n" - " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" - " ELSE E''\n" - " END" - " || CASE WHEN polroles <> '{0}' THEN\n" - " E'\\n to: ' || pg_catalog.array_to_string(\n" - " ARRAY(\n" - " SELECT rolname\n" - " FROM pg_catalog.pg_roles\n" - " WHERE oid = ANY (polroles)\n" - " ORDER BY 1\n" - " ), E', ')\n" - " ELSE E''\n" - " END\n" - " FROM pg_catalog.pg_policy pol\n" - " WHERE polrelid = c.oid), E'\\n')\n" - " AS \"%s\"", - gettext_noop("Policies")); + appendPQExpBuffer(&buf, + ",\n pg_catalog.array_to_string(ARRAY(\n" + " SELECT polname\n" + " || CASE WHEN NOT polpermissive THEN\n" + " E' (RESTRICTIVE)'\n" + " ELSE '' END\n" + " || CASE WHEN polcmd != '*' THEN\n" + " E' (' || polcmd::pg_catalog.text || E'):'\n" + " ELSE E':'\n" + " END\n" + " || CASE WHEN polqual IS NOT NULL THEN\n" + " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" + " ELSE E''\n" + " END\n" + " || CASE WHEN polwithcheck IS NOT NULL THEN\n" + " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" + " ELSE E''\n" + " END" + " || CASE WHEN polroles <> '{0}' THEN\n" + " E'\\n to: ' || pg_catalog.array_to_string(\n" + " ARRAY(\n" + " SELECT rolname\n" + " FROM pg_catalog.pg_roles\n" + " WHERE oid = ANY (polroles)\n" + " ORDER BY 1\n" + " ), E', ')\n" + " ELSE E''\n" + " END\n" + " FROM pg_catalog.pg_policy pol\n" + " WHERE polrelid = c.oid), E'\\n')\n" + " AS \"%s\"", + gettext_noop("Policies")); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_class c\n" " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n" @@ -1675,27 +1675,27 @@ describeOneTableDetails(const char *schemaname, char *footers[3] = {NULL, NULL, NULL}; printfPQExpBuffer(&buf, "/* %s */\n", _("Get sequence information")); - appendPQExpBuffer(&buf, - "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" - " seqstart AS \"%s\",\n" - " seqmin AS \"%s\",\n" - " seqmax AS \"%s\",\n" - " seqincrement AS \"%s\",\n" - " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" - " seqcache AS \"%s\"\n", - gettext_noop("Type"), - gettext_noop("Start"), - gettext_noop("Minimum"), - gettext_noop("Maximum"), - gettext_noop("Increment"), - gettext_noop("yes"), - gettext_noop("no"), - gettext_noop("Cycles?"), - gettext_noop("Cache")); - appendPQExpBuffer(&buf, - "FROM pg_catalog.pg_sequence\n" - "WHERE seqrelid = '%s';", - oid); + appendPQExpBuffer(&buf, + "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" + " seqstart AS \"%s\",\n" + " seqmin AS \"%s\",\n" + " seqmax AS \"%s\",\n" + " seqincrement AS \"%s\",\n" + " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" + " seqcache AS \"%s\"\n", + gettext_noop("Type"), + gettext_noop("Start"), + gettext_noop("Minimum"), + gettext_noop("Maximum"), + gettext_noop("Increment"), + gettext_noop("yes"), + gettext_noop("no"), + gettext_noop("Cycles?"), + gettext_noop("Cache")); + appendPQExpBuffer(&buf, + "FROM pg_catalog.pg_sequence\n" + "WHERE seqrelid = '%s';", + oid); res = PSQLexec(buf.data); if (!res) @@ -1913,7 +1913,7 @@ describeOneTableDetails(const char *schemaname, appendPQExpBufferStr(&buf, ",\n (SELECT c.collname FROM pg_catalog.pg_collation c, pg_catalog.pg_type t\n" " WHERE c.oid = a.attcollation AND t.oid = a.atttypid AND a.attcollation <> t.typcollation) AS attcollation"); attcoll_col = cols++; - appendPQExpBufferStr(&buf, ",\n a.attidentity"); + appendPQExpBufferStr(&buf, ",\n a.attidentity"); attidentity_col = cols++; if (pset.sversion >= 120000) appendPQExpBufferStr(&buf, ",\n a.attgenerated"); @@ -2326,7 +2326,7 @@ describeOneTableDetails(const char *schemaname, CppAsString2(CONSTRAINT_EXCLUSION) ") AND " "condeferred) AS condeferred,\n"); - appendPQExpBufferStr(&buf, "i.indisreplident,\n"); + appendPQExpBufferStr(&buf, "i.indisreplident,\n"); if (pset.sversion >= 150000) appendPQExpBufferStr(&buf, "i.indnullsnotdistinct,\n"); @@ -2431,7 +2431,7 @@ describeOneTableDetails(const char *schemaname, "pg_catalog.pg_get_indexdef(i.indexrelid, 0, true),\n " "pg_catalog.pg_get_constraintdef(con.oid, true), " "contype, condeferrable, condeferred"); - appendPQExpBufferStr(&buf, ", i.indisreplident"); + appendPQExpBufferStr(&buf, ", i.indisreplident"); appendPQExpBufferStr(&buf, ", c2.reltablespace"); if (pset.sversion >= 180000) appendPQExpBufferStr(&buf, ", con.conperiod"); @@ -2682,81 +2682,80 @@ describeOneTableDetails(const char *schemaname, PQclear(result); /* print any row-level policies */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get row-level policies for this table")); - appendPQExpBufferStr(&buf, "SELECT pol.polname,"); - appendPQExpBufferStr(&buf, - " pol.polpermissive,\n"); - appendPQExpBuffer(&buf, - " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" - " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" - " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" - " CASE pol.polcmd\n" - " WHEN 'r' THEN 'SELECT'\n" - " WHEN 'a' THEN 'INSERT'\n" - " WHEN 'w' THEN 'UPDATE'\n" - " WHEN 'd' THEN 'DELETE'\n" - " END AS cmd\n" - "FROM pg_catalog.pg_policy pol\n" - "WHERE pol.polrelid = '%s' ORDER BY 1;", - oid); + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get row-level policies for this table")); + appendPQExpBufferStr(&buf, "SELECT pol.polname,"); + appendPQExpBufferStr(&buf, + " pol.polpermissive,\n"); + appendPQExpBuffer(&buf, + " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" + " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" + " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" + " CASE pol.polcmd\n" + " WHEN 'r' THEN 'SELECT'\n" + " WHEN 'a' THEN 'INSERT'\n" + " WHEN 'w' THEN 'UPDATE'\n" + " WHEN 'd' THEN 'DELETE'\n" + " END AS cmd\n" + "FROM pg_catalog.pg_policy pol\n" + "WHERE pol.polrelid = '%s' ORDER BY 1;", + oid); - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - /* - * Handle cases where RLS is enabled and there are policies, or - * there aren't policies, or RLS isn't enabled but there are - * policies - */ - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies:")); + /* + * Handle cases where RLS is enabled and there are policies, or there + * aren't policies, or RLS isn't enabled but there are policies + */ + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies:")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled):")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled):")); - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); - if (!tableinfo.rowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (row security disabled):")); + if (!tableinfo.rowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (row security disabled):")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " POLICY \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " POLICY \"%s\"", + PQgetvalue(result, i, 0)); - if (*(PQgetvalue(result, i, 1)) == 'f') - appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); + if (*(PQgetvalue(result, i, 1)) == 'f') + appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); - if (!PQgetisnull(result, i, 5)) - appendPQExpBuffer(&buf, " FOR %s", - PQgetvalue(result, i, 5)); + if (!PQgetisnull(result, i, 5)) + appendPQExpBuffer(&buf, " FOR %s", + PQgetvalue(result, i, 5)); - if (!PQgetisnull(result, i, 2)) - { - appendPQExpBuffer(&buf, "\n TO %s", - PQgetvalue(result, i, 2)); - } + if (!PQgetisnull(result, i, 2)) + { + appendPQExpBuffer(&buf, "\n TO %s", + PQgetvalue(result, i, 2)); + } - if (!PQgetisnull(result, i, 3)) - appendPQExpBuffer(&buf, "\n USING (%s)", - PQgetvalue(result, i, 3)); + if (!PQgetisnull(result, i, 3)) + appendPQExpBuffer(&buf, "\n USING (%s)", + PQgetvalue(result, i, 3)); - if (!PQgetisnull(result, i, 4)) - appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", - PQgetvalue(result, i, 4)); + if (!PQgetisnull(result, i, 4)) + appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", + PQgetvalue(result, i, 4)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* print any extended statistics */ if (pset.sversion >= 140000) @@ -3025,115 +3024,115 @@ describeOneTableDetails(const char *schemaname, } /* print any publications */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get publications that publish this table")); - if (pset.sversion >= 150000) + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get publications that publish this table")); + if (pset.sversion >= 150000) + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" + " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" + "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" + "UNION\n" + "SELECT pubname\n" + " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" + " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" + " (SELECT pg_catalog.string_agg(attname, ', ')\n" + " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" + " pg_catalog.pg_attribute\n" + " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" + " ELSE NULL END) " + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" + "WHERE pr.prrelid = '%s'\n", + oid, oid, oid); + + if (pset.sversion >= 190000) { + /* + * Skip entries where this relation appears in the + * publication's EXCEPT list. + */ appendPQExpBuffer(&buf, + " AND NOT pr.prexcept\n" + "UNION\n" "SELECT pubname\n" " , NULL\n" " , NULL\n" "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" - " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" - "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" - "UNION\n" - "SELECT pubname\n" - " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" - " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" - " (SELECT pg_catalog.string_agg(attname, ', ')\n" - " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" - " pg_catalog.pg_attribute\n" - " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" - " ELSE NULL END) " - "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" - "WHERE pr.prrelid = '%s'\n", + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + " AND NOT EXISTS (\n" + " SELECT 1\n" + " FROM pg_catalog.pg_publication_rel pr\n" + " WHERE pr.prpubid = p.oid AND\n" + " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" + "ORDER BY 1;", oid, oid, oid); - - if (pset.sversion >= 190000) - { - /* - * Skip entries where this relation appears in the - * publication's EXCEPT list. - */ - appendPQExpBuffer(&buf, - " AND NOT pr.prexcept\n" - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - " AND NOT EXISTS (\n" - " SELECT 1\n" - " FROM pg_catalog.pg_publication_rel pr\n" - " WHERE pr.prpubid = p.oid AND\n" - " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" - "ORDER BY 1;", - oid, oid, oid); - } - else - { - appendPQExpBuffer(&buf, - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - "ORDER BY 1;", - oid); - } } else { appendPQExpBuffer(&buf, + "UNION\n" "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - "WHERE pr.prrelid = '%s'\n" - "UNION ALL\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" + " , NULL\n" + " , NULL\n" "FROM pg_catalog.pg_publication p\n" "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" "ORDER BY 1;", - oid, oid); + oid); } + } + else + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + "WHERE pr.prrelid = '%s'\n" + "UNION ALL\n" + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + "ORDER BY 1;", + oid, oid); + } - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - if (tuples > 0) - printTableAddFooter(&cont, _("Included in publications:")); + if (tuples > 0) + printTableAddFooter(&cont, _("Included in publications:")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " \"%s\"", + PQgetvalue(result, i, 0)); - /* column list (if any) */ - if (!PQgetisnull(result, i, 2)) - appendPQExpBuffer(&buf, " (%s)", - PQgetvalue(result, i, 2)); + /* column list (if any) */ + if (!PQgetisnull(result, i, 2)) + appendPQExpBuffer(&buf, " (%s)", + PQgetvalue(result, i, 2)); - /* row filter (if any) */ - if (!PQgetisnull(result, i, 1)) - appendPQExpBuffer(&buf, " WHERE %s", - PQgetvalue(result, i, 1)); + /* row filter (if any) */ + if (!PQgetisnull(result, i, 1)) + appendPQExpBuffer(&buf, " WHERE %s", + PQgetvalue(result, i, 1)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* Print publications where the table is in the EXCEPT clause */ if (pset.sversion >= 190000) @@ -3805,7 +3804,7 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) ncols++; } appendPQExpBufferStr(&buf, "\n, r.rolreplication"); - appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); + appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_roles r\n"); @@ -3860,8 +3859,8 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) if (strcmp(PQgetvalue(res, i, (verbose ? 9 : 8)), "t") == 0) add_role_attribute(&buf, _("Replication")); - if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) - add_role_attribute(&buf, _("Bypass RLS")); + if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) + add_role_attribute(&buf, _("Bypass RLS")); conns = atoi(PQgetvalue(res, i, 6)); if (conns >= 0) @@ -5155,14 +5154,14 @@ listCollations(const char *pattern, bool verbose, bool showSystem) gettext_noop("Schema"), gettext_noop("Name")); - appendPQExpBuffer(&buf, - " CASE c.collprovider " - "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " - "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " - "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " - "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " - "END AS \"%s\",\n", - gettext_noop("Provider")); + appendPQExpBuffer(&buf, + " CASE c.collprovider " + "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " + "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " + "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " + "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " + "END AS \"%s\",\n", + gettext_noop("Provider")); appendPQExpBuffer(&buf, " c.collcollate AS \"%s\",\n" -- 2.50.1 (Apple Git-155) --aHl3HfeiUuO3zeNC-- ^ permalink raw reply [nested|flat] 59+ messages in thread
* [PATCH v6 4/4] run pgindent and pgperltidy @ 2026-06-30 18:24 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 59+ messages in thread From: Nathan Bossart @ 2026-06-30 18:24 UTC (permalink / raw) --- src/bin/pg_dump/pg_dump.c | 464 ++++++++++----------- src/bin/pg_dump/pg_dumpall.c | 30 +- src/bin/pg_upgrade/check.c | 16 +- src/bin/pg_upgrade/controldata.c | 2 +- src/bin/pg_upgrade/exec.c | 8 +- src/bin/pg_upgrade/multixact_rewrite.c | 80 ++-- src/bin/pg_upgrade/pg_upgrade.c | 34 +- src/bin/pg_upgrade/relfilenumber.c | 54 +-- src/bin/pg_upgrade/t/006_transfer_modes.pl | 33 +- src/bin/psql/command.c | 29 +- src/bin/psql/describe.c | 461 ++++++++++---------- 11 files changed, 601 insertions(+), 610 deletions(-) diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 65bd15ebfd2..5673268b467 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -1491,8 +1491,8 @@ setup_connection(Archive *AH, const char *dumpencoding, * Disable timeouts if supported. */ ExecuteSqlStatement(AH, "SET statement_timeout = 0"); - ExecuteSqlStatement(AH, "SET lock_timeout = 0"); - ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); + ExecuteSqlStatement(AH, "SET lock_timeout = 0"); + ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); if (AH->remoteVersion >= 170000) ExecuteSqlStatement(AH, "SET transaction_timeout = 0"); @@ -1505,10 +1505,10 @@ setup_connection(Archive *AH, const char *dumpencoding, /* * Adjust row-security mode, if supported. */ - if (dopt->enable_row_security) - ExecuteSqlStatement(AH, "SET row_security = on"); - else - ExecuteSqlStatement(AH, "SET row_security = off"); + if (dopt->enable_row_security) + ExecuteSqlStatement(AH, "SET row_security = on"); + else + ExecuteSqlStatement(AH, "SET row_security = off"); /* * For security reasons, we restrict the expansion of non-system views and @@ -1933,10 +1933,9 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) addObjectDependency(dobj, ext->dobj.dumpId); /* - * Mark the member object to have any non-initial ACLs - * dumped. (Any initial ACLs will be removed later, using data from - * pg_init_privs, so that we'll dump only the delta from the extension's - * initial setup.) + * Mark the member object to have any non-initial ACLs dumped. (Any + * initial ACLs will be removed later, using data from pg_init_privs, so + * that we'll dump only the delta from the extension's initial setup.) * * In binary upgrades, we still dump all components of the members * individually, since the idea is to exactly reproduce the database @@ -1953,7 +1952,7 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) if (fout->dopt->binary_upgrade) dobj->dump = ext->dobj.dump; else - dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); + dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); return true; } @@ -1987,9 +1986,9 @@ selectDumpableNamespace(NamespaceInfo *nsinfo, Archive *fout) else if (strcmp(nsinfo->dobj.name, "pg_catalog") == 0) { /* - * We dump out any ACLs defined in pg_catalog, if - * they are interesting (and not the original ACLs which were set at - * initdb time, see pg_init_privs). + * We dump out any ACLs defined in pg_catalog, if they are interesting + * (and not the original ACLs which were set at initdb time, see + * pg_init_privs). */ nsinfo->dobj.dump_contains = nsinfo->dobj.dump = DUMP_COMPONENT_ACL; } @@ -3296,7 +3295,7 @@ dumpDatabase(Archive *fout) "datcollate, datctype, datfrozenxid, " "datacl, acldefault('d', datdba) AS acldefault, " "datistemplate, datconnlimit, "); - appendPQExpBufferStr(dbQry, "datminmxid, "); + appendPQExpBufferStr(dbQry, "datminmxid, "); if (fout->remoteVersion >= 170000) appendPQExpBufferStr(dbQry, "datlocprovider, datlocale, datcollversion, "); else if (fout->remoteVersion >= 150000) @@ -3638,11 +3637,11 @@ dumpDatabase(Archive *fout) ii_oid, ii_relminmxid; - appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" - "FROM pg_catalog.pg_class\n" - "WHERE oid IN (%u, %u, %u, %u);\n", - LargeObjectRelationId, LargeObjectLOidPNIndexId, - LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); + appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" + "FROM pg_catalog.pg_class\n" + "WHERE oid IN (%u, %u, %u, %u);\n", + LargeObjectRelationId, LargeObjectLOidPNIndexId, + LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); lo_res = ExecuteSqlQuery(fout, loFrozenQry->data, PGRES_TUPLES_OK); @@ -4274,7 +4273,7 @@ getPolicies(Archive *fout, TableInfo tblinfo[], int numTables) printfPQExpBuffer(query, "SELECT pol.oid, pol.tableoid, pol.polrelid, pol.polname, pol.polcmd, "); - appendPQExpBufferStr(query, "pol.polpermissive, "); + appendPQExpBufferStr(query, "pol.polpermissive, "); appendPQExpBuffer(query, "CASE WHEN pol.polroles = '{0}' THEN NULL ELSE " " pg_catalog.array_to_string(ARRAY(SELECT pg_catalog.quote_ident(rolname) from pg_catalog.pg_roles WHERE oid = ANY(pol.polroles)), ', ') END AS polroles, " @@ -6633,9 +6632,9 @@ getAccessMethods(Archive *fout) * Select all access methods from pg_am table. */ appendPQExpBufferStr(query, "SELECT tableoid, oid, amname, "); - appendPQExpBufferStr(query, - "amtype, " - "amhandler::pg_catalog.regproc AS amhandler "); + appendPQExpBufferStr(query, + "amtype, " + "amhandler::pg_catalog.regproc AS amhandler "); appendPQExpBufferStr(query, "FROM pg_am"); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6827,35 +6826,35 @@ getAggregates(Archive *fout) * Find all interesting aggregates. See comment in getFuncs() for the * rationale behind the filtering logic. */ - agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" - : "p.proisagg"); + agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" + : "p.proisagg"); - appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " - "p.proname AS aggname, " - "p.pronamespace AS aggnamespace, " - "p.pronargs, p.proargtypes, " - "p.proowner, " - "p.proacl AS aggacl, " - "acldefault('f', p.proowner) AS acldefault " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s AND (" - "p.pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog') OR " - "p.proacl IS DISTINCT FROM pip.initprivs", - agg_check); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - " OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); - appendPQExpBufferChar(query, ')'); + appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " + "p.proname AS aggname, " + "p.pronamespace AS aggnamespace, " + "p.pronargs, p.proargtypes, " + "p.proowner, " + "p.proacl AS aggacl, " + "acldefault('f', p.proowner) AS acldefault " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s AND (" + "p.pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog') OR " + "p.proacl IS DISTINCT FROM pip.initprivs", + agg_check); + if (dopt->binary_upgrade) + appendPQExpBufferStr(query, + " OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6957,53 +6956,53 @@ getFuncs(Archive *fout) * include them, since we want to dump extension members individually in * that mode. Also, if they are used by casts or transforms then we need * to gather the information about them, though they won't be dumped if - * they are built-in. Also, include functions in - * pg_catalog if they have an ACL different from what's shown in - * pg_init_privs (so we have to join to pg_init_privs; annoying). + * they are built-in. Also, include functions in pg_catalog if they have + * an ACL different from what's shown in pg_init_privs (so we have to join + * to pg_init_privs; annoying). */ - not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" - : "NOT p.proisagg"); + not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" + : "NOT p.proisagg"); - appendPQExpBuffer(query, - "SELECT p.tableoid, p.oid, p.proname, p.prolang, " - "p.pronargs, p.proargtypes, p.prorettype, " - "p.proacl, " - "acldefault('f', p.proowner) AS acldefault, " - "p.pronamespace, " - "p.proowner " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s" - "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " - "WHERE classid = 'pg_proc'::regclass AND " - "objid = p.oid AND deptype = 'i')" - "\n AND (" - "\n pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog')" - "\n OR EXISTS (SELECT 1 FROM pg_cast" - "\n WHERE pg_cast.oid > %u " - "\n AND p.oid = pg_cast.castfunc)" - "\n OR EXISTS (SELECT 1 FROM pg_transform" - "\n WHERE pg_transform.oid > %u AND " - "\n (p.oid = pg_transform.trffromsql" - "\n OR p.oid = pg_transform.trftosql))", - not_agg_check, - g_last_builtin_oid, - g_last_builtin_oid); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); + appendPQExpBuffer(query, + "SELECT p.tableoid, p.oid, p.proname, p.prolang, " + "p.pronargs, p.proargtypes, p.prorettype, " + "p.proacl, " + "acldefault('f', p.proowner) AS acldefault, " + "p.pronamespace, " + "p.proowner " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s" + "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " + "WHERE classid = 'pg_proc'::regclass AND " + "objid = p.oid AND deptype = 'i')" + "\n AND (" + "\n pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog')" + "\n OR EXISTS (SELECT 1 FROM pg_cast" + "\n WHERE pg_cast.oid > %u " + "\n AND p.oid = pg_cast.castfunc)" + "\n OR EXISTS (SELECT 1 FROM pg_transform" + "\n WHERE pg_transform.oid > %u AND " + "\n (p.oid = pg_transform.trffromsql" + "\n OR p.oid = pg_transform.trftosql))", + not_agg_check, + g_last_builtin_oid, + g_last_builtin_oid); + if (dopt->binary_upgrade) appendPQExpBufferStr(query, - "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); - appendPQExpBufferChar(query, ')'); + "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferStr(query, + "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -7252,31 +7251,31 @@ getTables(Archive *fout, int *numTables) appendPQExpBufferStr(query, "c.relhasoids, "); - appendPQExpBufferStr(query, - "c.relispopulated, "); + appendPQExpBufferStr(query, + "c.relispopulated, "); - appendPQExpBufferStr(query, - "c.relreplident, "); + appendPQExpBufferStr(query, + "c.relreplident, "); - appendPQExpBufferStr(query, - "c.relrowsecurity, c.relforcerowsecurity, "); + appendPQExpBufferStr(query, + "c.relrowsecurity, c.relforcerowsecurity, "); - appendPQExpBufferStr(query, - "c.relminmxid, tc.relminmxid AS tminmxid, "); + appendPQExpBufferStr(query, + "c.relminmxid, tc.relminmxid AS tminmxid, "); - appendPQExpBufferStr(query, - "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); + appendPQExpBufferStr(query, + "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); - appendPQExpBufferStr(query, - "am.amname, "); + appendPQExpBufferStr(query, + "am.amname, "); - appendPQExpBufferStr(query, - "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); + appendPQExpBufferStr(query, + "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); - appendPQExpBufferStr(query, - "c.relispartition AS ispartition "); + appendPQExpBufferStr(query, + "c.relispartition AS ispartition "); /* * Left join to pg_depend to pick up dependency info linking sequences to @@ -7296,8 +7295,8 @@ getTables(Archive *fout, int *numTables) /* * Left join to pg_am to pick up the amname. */ - appendPQExpBufferStr(query, - "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); + appendPQExpBufferStr(query, + "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); /* * We purposefully ignore toast OIDs for partitioned tables; the reason is @@ -7868,8 +7867,8 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables) "t.reloptions AS indreloptions, "); - appendPQExpBufferStr(query, - "i.indisreplident, "); + appendPQExpBufferStr(query, + "i.indisreplident, "); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -9313,8 +9312,8 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables) appendPQExpBufferStr(q, "'' AS attcompression,\n"); - appendPQExpBufferStr(q, - "a.attidentity,\n"); + appendPQExpBufferStr(q, + "a.attidentity,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(q, @@ -10717,73 +10716,73 @@ getAdditionalACLs(Archive *fout) PQclear(res); /* Fetch initial-privileges data */ - printfPQExpBuffer(query, - "SELECT objoid, classoid, objsubid, privtype, initprivs " - "FROM pg_init_privs"); + printfPQExpBuffer(query, + "SELECT objoid, classoid, objsubid, privtype, initprivs " + "FROM pg_init_privs"); - res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); + res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); - ntups = PQntuples(res); - for (i = 0; i < ntups; i++) - { - Oid objoid = atooid(PQgetvalue(res, i, 0)); - Oid classoid = atooid(PQgetvalue(res, i, 1)); - int objsubid = atoi(PQgetvalue(res, i, 2)); - char privtype = *(PQgetvalue(res, i, 3)); - char *initprivs = PQgetvalue(res, i, 4); - CatalogId objId; - DumpableObject *dobj; + ntups = PQntuples(res); + for (i = 0; i < ntups; i++) + { + Oid objoid = atooid(PQgetvalue(res, i, 0)); + Oid classoid = atooid(PQgetvalue(res, i, 1)); + int objsubid = atoi(PQgetvalue(res, i, 2)); + char privtype = *(PQgetvalue(res, i, 3)); + char *initprivs = PQgetvalue(res, i, 4); + CatalogId objId; + DumpableObject *dobj; - objId.tableoid = classoid; - objId.oid = objoid; - dobj = findObjectByCatalogId(objId); - /* OK to ignore entries we haven't got a DumpableObject for */ - if (dobj) + objId.tableoid = classoid; + objId.oid = objoid; + dobj = findObjectByCatalogId(objId); + /* OK to ignore entries we haven't got a DumpableObject for */ + if (dobj) + { + /* Cope with sub-object initprivs */ + if (objsubid != 0) { - /* Cope with sub-object initprivs */ - if (objsubid != 0) - { - if (dobj->objType == DO_TABLE) - { - /* For a column initprivs, set the table's ACL flags */ - dobj->components |= DUMP_COMPONENT_ACL; - ((TableInfo *) dobj)->hascolumnACLs = true; - } - else - pg_log_warning("unsupported pg_init_privs entry: %u %u %d", - classoid, objoid, objsubid); - continue; - } - - /* - * We ignore any pg_init_privs.initprivs entry for the public - * schema, as explained in getNamespaces(). - */ - if (dobj->objType == DO_NAMESPACE && - strcmp(dobj->name, "public") == 0) - continue; - - /* Else it had better be of a type we think has ACLs */ - if (dobj->objType == DO_NAMESPACE || - dobj->objType == DO_TYPE || - dobj->objType == DO_FUNC || - dobj->objType == DO_AGG || - dobj->objType == DO_TABLE || - dobj->objType == DO_PROCLANG || - dobj->objType == DO_FDW || - dobj->objType == DO_FOREIGN_SERVER) + if (dobj->objType == DO_TABLE) { - DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; - - daobj->dacl.privtype = privtype; - daobj->dacl.initprivs = pstrdup(initprivs); + /* For a column initprivs, set the table's ACL flags */ + dobj->components |= DUMP_COMPONENT_ACL; + ((TableInfo *) dobj)->hascolumnACLs = true; } else pg_log_warning("unsupported pg_init_privs entry: %u %u %d", classoid, objoid, objsubid); + continue; + } + + /* + * We ignore any pg_init_privs.initprivs entry for the public + * schema, as explained in getNamespaces(). + */ + if (dobj->objType == DO_NAMESPACE && + strcmp(dobj->name, "public") == 0) + continue; + + /* Else it had better be of a type we think has ACLs */ + if (dobj->objType == DO_NAMESPACE || + dobj->objType == DO_TYPE || + dobj->objType == DO_FUNC || + dobj->objType == DO_AGG || + dobj->objType == DO_TABLE || + dobj->objType == DO_PROCLANG || + dobj->objType == DO_FDW || + dobj->objType == DO_FOREIGN_SERVER) + { + DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; + + daobj->dacl.privtype = privtype; + daobj->dacl.initprivs = pstrdup(initprivs); } + else + pg_log_warning("unsupported pg_init_privs entry: %u %u %d", + classoid, objoid, objsubid); } - PQclear(res); + } + PQclear(res); destroyPQExpBuffer(query); } @@ -11128,8 +11127,8 @@ dumpRelationStats_dumper(Archive *fout, const void *userArg, const TocEntry *te) * The results must be in the order of the relations supplied in the * parameters to ensure we remain in sync as we walk through the TOC. * - * For versions before 19, the redundant filter clause on s.tablename = - * ANY(...) seems sufficient to convince the planner to use + * For versions before 19, the redundant filter clause on s.tablename + * = ANY(...) seems sufficient to convince the planner to use * pg_class_relname_nsp_index, which avoids a full scan of pg_stats. * In newer versions, pg_stats returns the table OIDs, eliminating the * need for that hack. @@ -13469,11 +13468,11 @@ dumpFunc(Archive *fout, const FuncInfo *finfo) "pg_catalog.pg_get_function_result(p.oid) AS funcresult,\n" "proleakproof,\n"); - appendPQExpBufferStr(query, - "array_to_string(protrftypes, ' ') AS protrftypes,\n"); + appendPQExpBufferStr(query, + "array_to_string(protrftypes, ' ') AS protrftypes,\n"); - appendPQExpBufferStr(query, - "proparallel,\n"); + appendPQExpBufferStr(query, + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -14963,9 +14962,9 @@ dumpCollation(Archive *fout, const CollInfo *collinfo) /* Get collation-specific details */ appendPQExpBufferStr(query, "SELECT "); - appendPQExpBufferStr(query, - "collprovider, " - "collversion, "); + appendPQExpBufferStr(query, + "collprovider, " + "collversion, "); if (fout->remoteVersion >= 120000) appendPQExpBufferStr(query, @@ -15372,23 +15371,23 @@ dumpAgg(Archive *fout, const AggInfo *agginfo) "pg_catalog.pg_get_function_arguments(p.oid) AS funcargs,\n" "pg_catalog.pg_get_function_identity_arguments(p.oid) AS funciargs,\n"); - appendPQExpBufferStr(query, - "aggkind,\n" - "aggmtransfn,\n" - "aggminvtransfn,\n" - "aggmfinalfn,\n" - "aggmtranstype::pg_catalog.regtype,\n" - "aggfinalextra,\n" - "aggmfinalextra,\n" - "aggtransspace,\n" - "aggmtransspace,\n" - "aggminitval,\n"); + appendPQExpBufferStr(query, + "aggkind,\n" + "aggmtransfn,\n" + "aggminvtransfn,\n" + "aggmfinalfn,\n" + "aggmtranstype::pg_catalog.regtype,\n" + "aggfinalextra,\n" + "aggmfinalextra,\n" + "aggtransspace,\n" + "aggmtransspace,\n" + "aggminitval,\n"); - appendPQExpBufferStr(query, - "aggcombinefn,\n" - "aggserialfn,\n" - "aggdeserialfn,\n" - "proparallel,\n"); + appendPQExpBufferStr(query, + "aggcombinefn,\n" + "aggserialfn,\n" + "aggdeserialfn,\n" + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -16848,30 +16847,30 @@ dumpTable(Archive *fout, const TableInfo *tbinfo) appendPQExpBufferStr(query, "PREPARE getColumnACLs(pg_catalog.oid) AS\n"); - /* - * In principle we should call acldefault('c', relowner) to - * get the default ACL for a column. However, we don't - * currently store the numeric OID of the relowner in - * TableInfo. We could convert the owner name using regrole, - * but that creates a risk of failure due to concurrent role - * renames. Given that the default ACL for columns is empty - * and is likely to stay that way, it's not worth extra cycles - * and risk to avoid hard-wiring that knowledge here. - */ - appendPQExpBufferStr(query, - "SELECT at.attname, " - "at.attacl, " - "'{}' AS acldefault, " - "pip.privtype, pip.initprivs " - "FROM pg_catalog.pg_attribute at " - "LEFT JOIN pg_catalog.pg_init_privs pip ON " - "(at.attrelid = pip.objoid " - "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " - "AND at.attnum = pip.objsubid) " - "WHERE at.attrelid = $1 AND " - "NOT at.attisdropped " - "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " - "ORDER BY at.attnum"); + /* + * In principle we should call acldefault('c', relowner) to get + * the default ACL for a column. However, we don't currently + * store the numeric OID of the relowner in TableInfo. We could + * convert the owner name using regrole, but that creates a risk + * of failure due to concurrent role renames. Given that the + * default ACL for columns is empty and is likely to stay that + * way, it's not worth extra cycles and risk to avoid hard-wiring + * that knowledge here. + */ + appendPQExpBufferStr(query, + "SELECT at.attname, " + "at.attacl, " + "'{}' AS acldefault, " + "pip.privtype, pip.initprivs " + "FROM pg_catalog.pg_attribute at " + "LEFT JOIN pg_catalog.pg_init_privs pip ON " + "(at.attrelid = pip.objoid " + "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " + "AND at.attnum = pip.objsubid) " + "WHERE at.attrelid = $1 AND " + "NOT at.attisdropped " + "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " + "ORDER BY at.attnum"); ExecuteSqlStatement(fout, query->data); @@ -19165,7 +19164,7 @@ collectSequences(Archive *fout) * pg_get_sequence_data(), but we only do so for non-schema-only dumps. */ if (fout->remoteVersion < 180000 || - (!fout->dopt->dumpData && !fout->dopt->sequence_data)) + (!fout->dopt->dumpData && !fout->dopt->sequence_data)) query = "SELECT seqrelid, format_type(seqtypid, NULL), " "seqstart, seqincrement, " "seqmax, seqmin, " @@ -19227,15 +19226,14 @@ dumpSequence(Archive *fout, const TableInfo *tbinfo) qseqname = pg_strdup(fmtId(tbinfo->dobj.name)); /* - * The sequence information is gathered in a sorted - * table before any calls to dumpSequence(). See collectSequences() for - * more information. + * The sequence information is gathered in a sorted table before any calls + * to dumpSequence(). See collectSequences() for more information. */ - Assert(sequences); + Assert(sequences); - key.oid = tbinfo->dobj.catId.oid; - seq = bsearch(&key, sequences, nsequences, - sizeof(SequenceItem), SequenceItemCmp); + key.oid = tbinfo->dobj.catId.oid; + seq = bsearch(&key, sequences, nsequences, + sizeof(SequenceItem), SequenceItemCmp); /* Calculate default limits for a sequence of this type */ is_ascending = (seq->incby >= 0); diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c index e68937c9934..afcd9a218d8 100644 --- a/src/bin/pg_dump/pg_dumpall.c +++ b/src/bin/pg_dump/pg_dumpall.c @@ -785,11 +785,11 @@ dropRoles(PGconn *conn) int i_rolname; int i; - printfPQExpBuffer(buf, - "SELECT rolname " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 1", role_catalog); + printfPQExpBuffer(buf, + "SELECT rolname " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 1", role_catalog); res = executeQuery(conn, buf->data); @@ -843,16 +843,16 @@ dumpRoles(PGconn *conn) * Notes: rolconfig is dumped later, and pg_authid must be used for * extracting rolcomment regardless of role_catalog. */ - printfPQExpBuffer(buf, - "SELECT oid, rolname, rolsuper, rolinherit, " - "rolcreaterole, rolcreatedb, " - "rolcanlogin, rolconnlimit, rolpassword, " - "rolvaliduntil, rolreplication, rolbypassrls, " - "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " - "rolname = current_user AS is_current_user " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 2", role_catalog); + printfPQExpBuffer(buf, + "SELECT oid, rolname, rolsuper, rolinherit, " + "rolcreaterole, rolcreatedb, " + "rolcanlogin, rolconnlimit, rolpassword, " + "rolvaliduntil, rolreplication, rolbypassrls, " + "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " + "rolname = current_user AS is_current_user " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 2", role_catalog); res = executeQuery(conn, buf->data); diff --git a/src/bin/pg_upgrade/check.c b/src/bin/pg_upgrade/check.c index 786c1474829..f725f5ee3e2 100644 --- a/src/bin/pg_upgrade/check.c +++ b/src/bin/pg_upgrade/check.c @@ -1475,15 +1475,15 @@ check_for_incompatible_polymorphics(ClusterInfo *cluster) ", 'array_cat(anyarray,anyarray)'" ", 'array_prepend(anyelement,anyarray)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_remove(anyarray,anyelement)'" - ", 'array_replace(anyarray,anyelement,anyelement)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_remove(anyarray,anyelement)'" + ", 'array_replace(anyarray,anyelement,anyelement)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_position(anyarray,anyelement)'" - ", 'array_position(anyarray,anyelement,integer)'" - ", 'array_positions(anyarray,anyelement)'" - ", 'width_bucket(anyelement,anyarray)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_position(anyarray,anyelement)'" + ", 'array_position(anyarray,anyelement,integer)'" + ", 'array_positions(anyarray,anyelement)'" + ", 'width_bucket(anyelement,anyarray)'"); /* * The query below hardcodes FirstNormalObjectId as 16384 rather than diff --git a/src/bin/pg_upgrade/controldata.c b/src/bin/pg_upgrade/controldata.c index 8f81c9e9582..02ea02df60f 100644 --- a/src/bin/pg_upgrade/controldata.c +++ b/src/bin/pg_upgrade/controldata.c @@ -228,7 +228,7 @@ get_control_data(ClusterInfo *cluster) p++; /* remove ':' char */ cluster->controldata.chkpnt_nxtepoch = str2uint(p); - p = strchr(p, ':'); + p = strchr(p, ':'); if (p == NULL || strlen(p) <= 1) pg_fatal("%d: controldata retrieval problem", __LINE__); diff --git a/src/bin/pg_upgrade/exec.c b/src/bin/pg_upgrade/exec.c index 44355feea30..a1bdbf373e3 100644 --- a/src/bin/pg_upgrade/exec.c +++ b/src/bin/pg_upgrade/exec.c @@ -55,7 +55,7 @@ get_bin_version(ClusterInfo *cluster) if (sscanf(cmd_output, "%*s %*s %d.%d", &v1, &v2) < 1) pg_fatal("could not get pg_ctl version output from %s", cmd); - cluster->bin_version = v1 * 10000; + cluster->bin_version = v1 * 10000; } @@ -344,8 +344,8 @@ check_data_dir(ClusterInfo *cluster) check_single_dir(pg_data, "pg_subtrans"); check_single_dir(pg_data, PG_TBLSPC_DIR); check_single_dir(pg_data, "pg_twophase"); - check_single_dir(pg_data, "pg_wal"); - check_single_dir(pg_data, "pg_xact"); + check_single_dir(pg_data, "pg_wal"); + check_single_dir(pg_data, "pg_xact"); } @@ -385,7 +385,7 @@ check_bin_dir(ClusterInfo *cluster, bool check_versions) */ get_bin_version(cluster); - check_exec(cluster->bindir, "pg_resetwal", check_versions); + check_exec(cluster->bindir, "pg_resetwal", check_versions); if (cluster == &new_cluster) { diff --git a/src/bin/pg_upgrade/multixact_rewrite.c b/src/bin/pg_upgrade/multixact_rewrite.c index c45b3183684..c7a1416494d 100644 --- a/src/bin/pg_upgrade/multixact_rewrite.c +++ b/src/bin/pg_upgrade/multixact_rewrite.c @@ -61,52 +61,52 @@ rewrite_multixacts(MultiXactId from_multi, MultiXactId to_multi) * Convert old multixids, if needed, by reading them one-by-one from the * old cluster. */ - old_reader = AllocOldMultiXactRead(old_cluster.pgdata, - old_cluster.controldata.chkpnt_nxtmulti, - old_cluster.controldata.chkpnt_nxtmxoff); + old_reader = AllocOldMultiXactRead(old_cluster.pgdata, + old_cluster.controldata.chkpnt_nxtmulti, + old_cluster.controldata.chkpnt_nxtmxoff); - for (MultiXactId multi = from_multi; multi != to_multi;) - { - MultiXactMember member; - bool multixid_valid; - - /* - * Read this multixid's members. - * - * Locking-only XIDs that may be part of multi-xids don't matter - * after upgrade, as there can be no transactions running across - * upgrade. So as a small optimization, we only read one member - * from each multixid: the one updating one, or if there was no - * update, arbitrarily the first locking xid. - */ - multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); + for (MultiXactId multi = from_multi; multi != to_multi;) + { + MultiXactMember member; + bool multixid_valid; - /* - * Write the new offset to pg_multixact/offsets. - * - * Even if this multixid is invalid, we still need to write its - * offset if the *previous* multixid was valid. That's because - * when reading a multixid, the number of members is calculated - * from the difference between the two offsets. - */ - RecordMultiXactOffset(offsets_writer, multi, - (multixid_valid || prev_multixid_valid) ? next_offset : 0); + /* + * Read this multixid's members. + * + * Locking-only XIDs that may be part of multi-xids don't matter after + * upgrade, as there can be no transactions running across upgrade. So + * as a small optimization, we only read one member from each + * multixid: the one updating one, or if there was no update, + * arbitrarily the first locking xid. + */ + multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); - /* Write the members */ - if (multixid_valid) - { - RecordMultiXactMembers(members_writer, next_offset, 1, &member); - next_offset += 1; - } + /* + * Write the new offset to pg_multixact/offsets. + * + * Even if this multixid is invalid, we still need to write its offset + * if the *previous* multixid was valid. That's because when reading + * a multixid, the number of members is calculated from the difference + * between the two offsets. + */ + RecordMultiXactOffset(offsets_writer, multi, + (multixid_valid || prev_multixid_valid) ? next_offset : 0); - /* Advance to next multixid, handling wraparound */ - multi++; - if (multi < FirstMultiXactId) - multi = FirstMultiXactId; - prev_multixid_valid = multixid_valid; + /* Write the members */ + if (multixid_valid) + { + RecordMultiXactMembers(members_writer, next_offset, 1, &member); + next_offset += 1; } - FreeOldMultiXactReader(old_reader); + /* Advance to next multixid, handling wraparound */ + multi++; + if (multi < FirstMultiXactId) + multi = FirstMultiXactId; + prev_multixid_valid = multixid_valid; + } + + FreeOldMultiXactReader(old_reader); /* Write the final 'next' offset to the last SLRU page */ RecordMultiXactOffset(offsets_writer, to_multi, diff --git a/src/bin/pg_upgrade/pg_upgrade.c b/src/bin/pg_upgrade/pg_upgrade.c index c6af9035665..7366fd4627c 100644 --- a/src/bin/pg_upgrade/pg_upgrade.c +++ b/src/bin/pg_upgrade/pg_upgrade.c @@ -833,7 +833,7 @@ copy_xact_xlog_xid(void) * Determine the range of multixacts to convert. */ nxtmulti = old_cluster.controldata.chkpnt_nxtmulti; - oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; + oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; /* handle wraparound */ if (nxtmulti < FirstMultiXactId) nxtmulti = FirstMultiXactId; @@ -898,15 +898,15 @@ set_frozenxids(void) int i_datname; int i_datallowconn; - prep_status("Setting frozenxid and minmxid counters in new cluster"); + prep_status("Setting frozenxid and minmxid counters in new cluster"); conn_template1 = connectToServer(&new_cluster, "template1"); - /* set pg_database.datfrozenxid */ - PQclear(executeQueryOrDie(conn_template1, - "UPDATE pg_catalog.pg_database " - "SET datfrozenxid = '%u'", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_database.datfrozenxid */ + PQclear(executeQueryOrDie(conn_template1, + "UPDATE pg_catalog.pg_database " + "SET datfrozenxid = '%u'", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_database.datminmxid */ PQclear(executeQueryOrDie(conn_template1, @@ -942,16 +942,16 @@ set_frozenxids(void) conn = connectToServer(&new_cluster, datname); - /* set pg_class.relfrozenxid */ - PQclear(executeQueryOrDie(conn, - "UPDATE pg_catalog.pg_class " - "SET relfrozenxid = '%u' " - /* only heap, materialized view, and TOAST are vacuumed */ - "WHERE relkind IN (" - CppAsString2(RELKIND_RELATION) ", " - CppAsString2(RELKIND_MATVIEW) ", " - CppAsString2(RELKIND_TOASTVALUE) ")", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_class.relfrozenxid */ + PQclear(executeQueryOrDie(conn, + "UPDATE pg_catalog.pg_class " + "SET relfrozenxid = '%u' " + /* only heap, materialized view, and TOAST are vacuumed */ + "WHERE relkind IN (" + CppAsString2(RELKIND_RELATION) ", " + CppAsString2(RELKIND_MATVIEW) ", " + CppAsString2(RELKIND_TOASTVALUE) ")", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_class.relminmxid */ PQclear(executeQueryOrDie(conn, diff --git a/src/bin/pg_upgrade/relfilenumber.c b/src/bin/pg_upgrade/relfilenumber.c index ec2ff7acb21..6c467bdc8a5 100644 --- a/src/bin/pg_upgrade/relfilenumber.c +++ b/src/bin/pg_upgrade/relfilenumber.c @@ -587,32 +587,32 @@ transfer_relfile(FileNameMap *map, const char *type_suffix) /* Copying files might take some time, so give feedback. */ pg_log(PG_STATUS, "%s", old_file); - switch (user_opts.transfer_mode) - { - case TRANSFER_MODE_CLONE: - pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", - old_file, new_file); - cloneFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", - old_file, new_file); - copyFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY_FILE_RANGE: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", - old_file, new_file); - copyFileByRange(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_LINK: - pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", - old_file, new_file); - linkFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_SWAP: - /* swap mode is handled in its own code path */ - pg_fatal("should never happen"); - break; - } + switch (user_opts.transfer_mode) + { + case TRANSFER_MODE_CLONE: + pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", + old_file, new_file); + cloneFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", + old_file, new_file); + copyFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY_FILE_RANGE: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", + old_file, new_file); + copyFileByRange(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_LINK: + pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", + old_file, new_file); + linkFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_SWAP: + /* swap mode is handled in its own code path */ + pg_fatal("should never happen"); + break; + } } } diff --git a/src/bin/pg_upgrade/t/006_transfer_modes.pl b/src/bin/pg_upgrade/t/006_transfer_modes.pl index 9efa5dc863c..360d05c4b68 100644 --- a/src/bin/pg_upgrade/t/006_transfer_modes.pl +++ b/src/bin/pg_upgrade/t/006_transfer_modes.pl @@ -29,10 +29,8 @@ sub test_mode } $new->init(); - $new->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); - $old->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); + $new->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); + $old->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); # We can only test security labels if both the old and new installations # have dummy_seclabel. @@ -76,15 +74,14 @@ sub test_mode "CREATE TABLE test4 AS SELECT generate_series(400, 502)"); } - $old->safe_psql('postgres', - "CREATE TABLESPACE inplc_tblspc LOCATION ''"); - $old->safe_psql('postgres', - "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); - $old->safe_psql('postgres', - "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" - ); - $old->safe_psql('testdb3', - "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); + $old->safe_psql('postgres', "CREATE TABLESPACE inplc_tblspc LOCATION ''"); + $old->safe_psql('postgres', + "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); + $old->safe_psql('postgres', + "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" + ); + $old->safe_psql('testdb3', + "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); # While we are here, test handling of large objects. $old->safe_psql( @@ -152,12 +149,10 @@ sub test_mode } # Tests for in-place tablespaces. - $result = - $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); - is($result, '104', "test5 data after pg_upgrade $mode"); - $result = - $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); - is($result, '105', "test6 data after pg_upgrade $mode"); + $result = $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); + is($result, '104', "test5 data after pg_upgrade $mode"); + $result = $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); + is($result, '105', "test6 data after pg_upgrade $mode"); # Tests for large objects $result = $new->safe_psql('postgres', "SELECT lo_get(4532)"); diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index 44ef11d980e..c90bf8bbde2 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -6278,23 +6278,22 @@ get_create_object_cmd(EditableObjectType obj_type, Oid oid, * ensure the right view gets replaced. Also, check relation kind * to be sure it's a view. * - * Views may have WITH [LOCAL|CASCADED] - * CHECK OPTION. These are not part of the view definition - * returned by pg_get_viewdef() and so need to be retrieved - * separately. Materialized views may have - * arbitrary storage parameter reloptions. + * Views may have WITH [LOCAL|CASCADED] CHECK OPTION. These are + * not part of the view definition returned by pg_get_viewdef() + * and so need to be retrieved separately. Materialized views may + * have arbitrary storage parameter reloptions. */ printfPQExpBuffer(query, "/* %s */\n", _("Get view's definition and details")); - appendPQExpBuffer(query, - "SELECT nspname, relname, relkind, " - "pg_catalog.pg_get_viewdef(c.oid, true), " - "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " - "FROM pg_catalog.pg_class c " - "LEFT JOIN pg_catalog.pg_namespace n " - "ON c.relnamespace = n.oid WHERE c.oid = %u", - oid); + appendPQExpBuffer(query, + "SELECT nspname, relname, relkind, " + "pg_catalog.pg_get_viewdef(c.oid, true), " + "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " + "FROM pg_catalog.pg_class c " + "LEFT JOIN pg_catalog.pg_namespace n " + "ON c.relnamespace = n.oid WHERE c.oid = %u", + oid); break; } diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index ce99137c613..ac0c55e7aa5 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -387,19 +387,19 @@ describeFunctions(const char *functypes, const char *func_pattern, gettext_noop("stable"), gettext_noop("volatile"), gettext_noop("Volatility")); - appendPQExpBuffer(&buf, - ",\n CASE\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" - " END as \"%s\"", - gettext_noop("restricted"), - gettext_noop("safe"), - gettext_noop("unsafe"), - gettext_noop("Parallel")); + appendPQExpBuffer(&buf, + ",\n CASE\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" + " END as \"%s\"", + gettext_noop("restricted"), + gettext_noop("safe"), + gettext_noop("unsafe"), + gettext_noop("Parallel")); appendPQExpBuffer(&buf, ",\n pg_catalog.pg_get_userbyid(p.proowner) as \"%s\"" ",\n CASE WHEN prosecdef THEN '%s' ELSE '%s' END AS \"%s\"" @@ -599,8 +599,8 @@ describeFunctions(const char *functypes, const char *func_pattern, myopt.title = _("List of functions"); myopt.translate_header = true; - myopt.translate_columns = translate_columns; - myopt.n_translate_columns = lengthof(translate_columns); + myopt.translate_columns = translate_columns; + myopt.n_translate_columns = lengthof(translate_columns); printQuery(res, &myopt, pset.queryFout, false, pset.logfile); @@ -1086,38 +1086,38 @@ permissionsList(const char *pattern, bool showSystem) " ), E'\\n') AS \"%s\"", gettext_noop("Column privileges")); - appendPQExpBuffer(&buf, - ",\n pg_catalog.array_to_string(ARRAY(\n" - " SELECT polname\n" - " || CASE WHEN NOT polpermissive THEN\n" - " E' (RESTRICTIVE)'\n" - " ELSE '' END\n" - " || CASE WHEN polcmd != '*' THEN\n" - " E' (' || polcmd::pg_catalog.text || E'):'\n" - " ELSE E':'\n" - " END\n" - " || CASE WHEN polqual IS NOT NULL THEN\n" - " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" - " ELSE E''\n" - " END\n" - " || CASE WHEN polwithcheck IS NOT NULL THEN\n" - " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" - " ELSE E''\n" - " END" - " || CASE WHEN polroles <> '{0}' THEN\n" - " E'\\n to: ' || pg_catalog.array_to_string(\n" - " ARRAY(\n" - " SELECT rolname\n" - " FROM pg_catalog.pg_roles\n" - " WHERE oid = ANY (polroles)\n" - " ORDER BY 1\n" - " ), E', ')\n" - " ELSE E''\n" - " END\n" - " FROM pg_catalog.pg_policy pol\n" - " WHERE polrelid = c.oid), E'\\n')\n" - " AS \"%s\"", - gettext_noop("Policies")); + appendPQExpBuffer(&buf, + ",\n pg_catalog.array_to_string(ARRAY(\n" + " SELECT polname\n" + " || CASE WHEN NOT polpermissive THEN\n" + " E' (RESTRICTIVE)'\n" + " ELSE '' END\n" + " || CASE WHEN polcmd != '*' THEN\n" + " E' (' || polcmd::pg_catalog.text || E'):'\n" + " ELSE E':'\n" + " END\n" + " || CASE WHEN polqual IS NOT NULL THEN\n" + " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" + " ELSE E''\n" + " END\n" + " || CASE WHEN polwithcheck IS NOT NULL THEN\n" + " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" + " ELSE E''\n" + " END" + " || CASE WHEN polroles <> '{0}' THEN\n" + " E'\\n to: ' || pg_catalog.array_to_string(\n" + " ARRAY(\n" + " SELECT rolname\n" + " FROM pg_catalog.pg_roles\n" + " WHERE oid = ANY (polroles)\n" + " ORDER BY 1\n" + " ), E', ')\n" + " ELSE E''\n" + " END\n" + " FROM pg_catalog.pg_policy pol\n" + " WHERE polrelid = c.oid), E'\\n')\n" + " AS \"%s\"", + gettext_noop("Policies")); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_class c\n" " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n" @@ -1675,27 +1675,27 @@ describeOneTableDetails(const char *schemaname, char *footers[3] = {NULL, NULL, NULL}; printfPQExpBuffer(&buf, "/* %s */\n", _("Get sequence information")); - appendPQExpBuffer(&buf, - "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" - " seqstart AS \"%s\",\n" - " seqmin AS \"%s\",\n" - " seqmax AS \"%s\",\n" - " seqincrement AS \"%s\",\n" - " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" - " seqcache AS \"%s\"\n", - gettext_noop("Type"), - gettext_noop("Start"), - gettext_noop("Minimum"), - gettext_noop("Maximum"), - gettext_noop("Increment"), - gettext_noop("yes"), - gettext_noop("no"), - gettext_noop("Cycles?"), - gettext_noop("Cache")); - appendPQExpBuffer(&buf, - "FROM pg_catalog.pg_sequence\n" - "WHERE seqrelid = '%s';", - oid); + appendPQExpBuffer(&buf, + "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" + " seqstart AS \"%s\",\n" + " seqmin AS \"%s\",\n" + " seqmax AS \"%s\",\n" + " seqincrement AS \"%s\",\n" + " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" + " seqcache AS \"%s\"\n", + gettext_noop("Type"), + gettext_noop("Start"), + gettext_noop("Minimum"), + gettext_noop("Maximum"), + gettext_noop("Increment"), + gettext_noop("yes"), + gettext_noop("no"), + gettext_noop("Cycles?"), + gettext_noop("Cache")); + appendPQExpBuffer(&buf, + "FROM pg_catalog.pg_sequence\n" + "WHERE seqrelid = '%s';", + oid); res = PSQLexec(buf.data); if (!res) @@ -1913,7 +1913,7 @@ describeOneTableDetails(const char *schemaname, appendPQExpBufferStr(&buf, ",\n (SELECT c.collname FROM pg_catalog.pg_collation c, pg_catalog.pg_type t\n" " WHERE c.oid = a.attcollation AND t.oid = a.atttypid AND a.attcollation <> t.typcollation) AS attcollation"); attcoll_col = cols++; - appendPQExpBufferStr(&buf, ",\n a.attidentity"); + appendPQExpBufferStr(&buf, ",\n a.attidentity"); attidentity_col = cols++; if (pset.sversion >= 120000) appendPQExpBufferStr(&buf, ",\n a.attgenerated"); @@ -2326,7 +2326,7 @@ describeOneTableDetails(const char *schemaname, CppAsString2(CONSTRAINT_EXCLUSION) ") AND " "condeferred) AS condeferred,\n"); - appendPQExpBufferStr(&buf, "i.indisreplident,\n"); + appendPQExpBufferStr(&buf, "i.indisreplident,\n"); if (pset.sversion >= 150000) appendPQExpBufferStr(&buf, "i.indnullsnotdistinct,\n"); @@ -2431,7 +2431,7 @@ describeOneTableDetails(const char *schemaname, "pg_catalog.pg_get_indexdef(i.indexrelid, 0, true),\n " "pg_catalog.pg_get_constraintdef(con.oid, true), " "contype, condeferrable, condeferred"); - appendPQExpBufferStr(&buf, ", i.indisreplident"); + appendPQExpBufferStr(&buf, ", i.indisreplident"); appendPQExpBufferStr(&buf, ", c2.reltablespace"); if (pset.sversion >= 180000) appendPQExpBufferStr(&buf, ", con.conperiod"); @@ -2682,81 +2682,80 @@ describeOneTableDetails(const char *schemaname, PQclear(result); /* print any row-level policies */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get row-level policies for this table")); - appendPQExpBufferStr(&buf, "SELECT pol.polname,"); - appendPQExpBufferStr(&buf, - " pol.polpermissive,\n"); - appendPQExpBuffer(&buf, - " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" - " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" - " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" - " CASE pol.polcmd\n" - " WHEN 'r' THEN 'SELECT'\n" - " WHEN 'a' THEN 'INSERT'\n" - " WHEN 'w' THEN 'UPDATE'\n" - " WHEN 'd' THEN 'DELETE'\n" - " END AS cmd\n" - "FROM pg_catalog.pg_policy pol\n" - "WHERE pol.polrelid = '%s' ORDER BY 1;", - oid); + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get row-level policies for this table")); + appendPQExpBufferStr(&buf, "SELECT pol.polname,"); + appendPQExpBufferStr(&buf, + " pol.polpermissive,\n"); + appendPQExpBuffer(&buf, + " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" + " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" + " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" + " CASE pol.polcmd\n" + " WHEN 'r' THEN 'SELECT'\n" + " WHEN 'a' THEN 'INSERT'\n" + " WHEN 'w' THEN 'UPDATE'\n" + " WHEN 'd' THEN 'DELETE'\n" + " END AS cmd\n" + "FROM pg_catalog.pg_policy pol\n" + "WHERE pol.polrelid = '%s' ORDER BY 1;", + oid); - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - /* - * Handle cases where RLS is enabled and there are policies, or - * there aren't policies, or RLS isn't enabled but there are - * policies - */ - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies:")); + /* + * Handle cases where RLS is enabled and there are policies, or there + * aren't policies, or RLS isn't enabled but there are policies + */ + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies:")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled):")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled):")); - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); - if (!tableinfo.rowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (row security disabled):")); + if (!tableinfo.rowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (row security disabled):")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " POLICY \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " POLICY \"%s\"", + PQgetvalue(result, i, 0)); - if (*(PQgetvalue(result, i, 1)) == 'f') - appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); + if (*(PQgetvalue(result, i, 1)) == 'f') + appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); - if (!PQgetisnull(result, i, 5)) - appendPQExpBuffer(&buf, " FOR %s", - PQgetvalue(result, i, 5)); + if (!PQgetisnull(result, i, 5)) + appendPQExpBuffer(&buf, " FOR %s", + PQgetvalue(result, i, 5)); - if (!PQgetisnull(result, i, 2)) - { - appendPQExpBuffer(&buf, "\n TO %s", - PQgetvalue(result, i, 2)); - } + if (!PQgetisnull(result, i, 2)) + { + appendPQExpBuffer(&buf, "\n TO %s", + PQgetvalue(result, i, 2)); + } - if (!PQgetisnull(result, i, 3)) - appendPQExpBuffer(&buf, "\n USING (%s)", - PQgetvalue(result, i, 3)); + if (!PQgetisnull(result, i, 3)) + appendPQExpBuffer(&buf, "\n USING (%s)", + PQgetvalue(result, i, 3)); - if (!PQgetisnull(result, i, 4)) - appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", - PQgetvalue(result, i, 4)); + if (!PQgetisnull(result, i, 4)) + appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", + PQgetvalue(result, i, 4)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* print any extended statistics */ if (pset.sversion >= 140000) @@ -3025,115 +3024,115 @@ describeOneTableDetails(const char *schemaname, } /* print any publications */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get publications that publish this table")); - if (pset.sversion >= 150000) + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get publications that publish this table")); + if (pset.sversion >= 150000) + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" + " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" + "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" + "UNION\n" + "SELECT pubname\n" + " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" + " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" + " (SELECT pg_catalog.string_agg(attname, ', ')\n" + " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" + " pg_catalog.pg_attribute\n" + " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" + " ELSE NULL END) " + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" + "WHERE pr.prrelid = '%s'\n", + oid, oid, oid); + + if (pset.sversion >= 190000) { + /* + * Skip entries where this relation appears in the + * publication's EXCEPT list. + */ appendPQExpBuffer(&buf, + " AND NOT pr.prexcept\n" + "UNION\n" "SELECT pubname\n" " , NULL\n" " , NULL\n" "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" - " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" - "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" - "UNION\n" - "SELECT pubname\n" - " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" - " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" - " (SELECT pg_catalog.string_agg(attname, ', ')\n" - " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" - " pg_catalog.pg_attribute\n" - " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" - " ELSE NULL END) " - "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" - "WHERE pr.prrelid = '%s'\n", + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + " AND NOT EXISTS (\n" + " SELECT 1\n" + " FROM pg_catalog.pg_publication_rel pr\n" + " WHERE pr.prpubid = p.oid AND\n" + " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" + "ORDER BY 1;", oid, oid, oid); - - if (pset.sversion >= 190000) - { - /* - * Skip entries where this relation appears in the - * publication's EXCEPT list. - */ - appendPQExpBuffer(&buf, - " AND NOT pr.prexcept\n" - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - " AND NOT EXISTS (\n" - " SELECT 1\n" - " FROM pg_catalog.pg_publication_rel pr\n" - " WHERE pr.prpubid = p.oid AND\n" - " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" - "ORDER BY 1;", - oid, oid, oid); - } - else - { - appendPQExpBuffer(&buf, - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - "ORDER BY 1;", - oid); - } } else { appendPQExpBuffer(&buf, + "UNION\n" "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - "WHERE pr.prrelid = '%s'\n" - "UNION ALL\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" + " , NULL\n" + " , NULL\n" "FROM pg_catalog.pg_publication p\n" "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" "ORDER BY 1;", - oid, oid); + oid); } + } + else + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + "WHERE pr.prrelid = '%s'\n" + "UNION ALL\n" + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + "ORDER BY 1;", + oid, oid); + } - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - if (tuples > 0) - printTableAddFooter(&cont, _("Included in publications:")); + if (tuples > 0) + printTableAddFooter(&cont, _("Included in publications:")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " \"%s\"", + PQgetvalue(result, i, 0)); - /* column list (if any) */ - if (!PQgetisnull(result, i, 2)) - appendPQExpBuffer(&buf, " (%s)", - PQgetvalue(result, i, 2)); + /* column list (if any) */ + if (!PQgetisnull(result, i, 2)) + appendPQExpBuffer(&buf, " (%s)", + PQgetvalue(result, i, 2)); - /* row filter (if any) */ - if (!PQgetisnull(result, i, 1)) - appendPQExpBuffer(&buf, " WHERE %s", - PQgetvalue(result, i, 1)); + /* row filter (if any) */ + if (!PQgetisnull(result, i, 1)) + appendPQExpBuffer(&buf, " WHERE %s", + PQgetvalue(result, i, 1)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* Print publications where the table is in the EXCEPT clause */ if (pset.sversion >= 190000) @@ -3805,7 +3804,7 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) ncols++; } appendPQExpBufferStr(&buf, "\n, r.rolreplication"); - appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); + appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_roles r\n"); @@ -3860,8 +3859,8 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) if (strcmp(PQgetvalue(res, i, (verbose ? 9 : 8)), "t") == 0) add_role_attribute(&buf, _("Replication")); - if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) - add_role_attribute(&buf, _("Bypass RLS")); + if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) + add_role_attribute(&buf, _("Bypass RLS")); conns = atoi(PQgetvalue(res, i, 6)); if (conns >= 0) @@ -5155,14 +5154,14 @@ listCollations(const char *pattern, bool verbose, bool showSystem) gettext_noop("Schema"), gettext_noop("Name")); - appendPQExpBuffer(&buf, - " CASE c.collprovider " - "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " - "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " - "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " - "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " - "END AS \"%s\",\n", - gettext_noop("Provider")); + appendPQExpBuffer(&buf, + " CASE c.collprovider " + "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " + "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " + "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " + "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " + "END AS \"%s\",\n", + gettext_noop("Provider")); appendPQExpBuffer(&buf, " c.collcollate AS \"%s\",\n" -- 2.50.1 (Apple Git-155) --aHl3HfeiUuO3zeNC-- ^ permalink raw reply [nested|flat] 59+ messages in thread
* [PATCH v6 4/4] run pgindent and pgperltidy @ 2026-06-30 18:24 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 59+ messages in thread From: Nathan Bossart @ 2026-06-30 18:24 UTC (permalink / raw) --- src/bin/pg_dump/pg_dump.c | 464 ++++++++++----------- src/bin/pg_dump/pg_dumpall.c | 30 +- src/bin/pg_upgrade/check.c | 16 +- src/bin/pg_upgrade/controldata.c | 2 +- src/bin/pg_upgrade/exec.c | 8 +- src/bin/pg_upgrade/multixact_rewrite.c | 80 ++-- src/bin/pg_upgrade/pg_upgrade.c | 34 +- src/bin/pg_upgrade/relfilenumber.c | 54 +-- src/bin/pg_upgrade/t/006_transfer_modes.pl | 33 +- src/bin/psql/command.c | 29 +- src/bin/psql/describe.c | 461 ++++++++++---------- 11 files changed, 601 insertions(+), 610 deletions(-) diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 65bd15ebfd2..5673268b467 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -1491,8 +1491,8 @@ setup_connection(Archive *AH, const char *dumpencoding, * Disable timeouts if supported. */ ExecuteSqlStatement(AH, "SET statement_timeout = 0"); - ExecuteSqlStatement(AH, "SET lock_timeout = 0"); - ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); + ExecuteSqlStatement(AH, "SET lock_timeout = 0"); + ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); if (AH->remoteVersion >= 170000) ExecuteSqlStatement(AH, "SET transaction_timeout = 0"); @@ -1505,10 +1505,10 @@ setup_connection(Archive *AH, const char *dumpencoding, /* * Adjust row-security mode, if supported. */ - if (dopt->enable_row_security) - ExecuteSqlStatement(AH, "SET row_security = on"); - else - ExecuteSqlStatement(AH, "SET row_security = off"); + if (dopt->enable_row_security) + ExecuteSqlStatement(AH, "SET row_security = on"); + else + ExecuteSqlStatement(AH, "SET row_security = off"); /* * For security reasons, we restrict the expansion of non-system views and @@ -1933,10 +1933,9 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) addObjectDependency(dobj, ext->dobj.dumpId); /* - * Mark the member object to have any non-initial ACLs - * dumped. (Any initial ACLs will be removed later, using data from - * pg_init_privs, so that we'll dump only the delta from the extension's - * initial setup.) + * Mark the member object to have any non-initial ACLs dumped. (Any + * initial ACLs will be removed later, using data from pg_init_privs, so + * that we'll dump only the delta from the extension's initial setup.) * * In binary upgrades, we still dump all components of the members * individually, since the idea is to exactly reproduce the database @@ -1953,7 +1952,7 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) if (fout->dopt->binary_upgrade) dobj->dump = ext->dobj.dump; else - dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); + dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); return true; } @@ -1987,9 +1986,9 @@ selectDumpableNamespace(NamespaceInfo *nsinfo, Archive *fout) else if (strcmp(nsinfo->dobj.name, "pg_catalog") == 0) { /* - * We dump out any ACLs defined in pg_catalog, if - * they are interesting (and not the original ACLs which were set at - * initdb time, see pg_init_privs). + * We dump out any ACLs defined in pg_catalog, if they are interesting + * (and not the original ACLs which were set at initdb time, see + * pg_init_privs). */ nsinfo->dobj.dump_contains = nsinfo->dobj.dump = DUMP_COMPONENT_ACL; } @@ -3296,7 +3295,7 @@ dumpDatabase(Archive *fout) "datcollate, datctype, datfrozenxid, " "datacl, acldefault('d', datdba) AS acldefault, " "datistemplate, datconnlimit, "); - appendPQExpBufferStr(dbQry, "datminmxid, "); + appendPQExpBufferStr(dbQry, "datminmxid, "); if (fout->remoteVersion >= 170000) appendPQExpBufferStr(dbQry, "datlocprovider, datlocale, datcollversion, "); else if (fout->remoteVersion >= 150000) @@ -3638,11 +3637,11 @@ dumpDatabase(Archive *fout) ii_oid, ii_relminmxid; - appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" - "FROM pg_catalog.pg_class\n" - "WHERE oid IN (%u, %u, %u, %u);\n", - LargeObjectRelationId, LargeObjectLOidPNIndexId, - LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); + appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" + "FROM pg_catalog.pg_class\n" + "WHERE oid IN (%u, %u, %u, %u);\n", + LargeObjectRelationId, LargeObjectLOidPNIndexId, + LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); lo_res = ExecuteSqlQuery(fout, loFrozenQry->data, PGRES_TUPLES_OK); @@ -4274,7 +4273,7 @@ getPolicies(Archive *fout, TableInfo tblinfo[], int numTables) printfPQExpBuffer(query, "SELECT pol.oid, pol.tableoid, pol.polrelid, pol.polname, pol.polcmd, "); - appendPQExpBufferStr(query, "pol.polpermissive, "); + appendPQExpBufferStr(query, "pol.polpermissive, "); appendPQExpBuffer(query, "CASE WHEN pol.polroles = '{0}' THEN NULL ELSE " " pg_catalog.array_to_string(ARRAY(SELECT pg_catalog.quote_ident(rolname) from pg_catalog.pg_roles WHERE oid = ANY(pol.polroles)), ', ') END AS polroles, " @@ -6633,9 +6632,9 @@ getAccessMethods(Archive *fout) * Select all access methods from pg_am table. */ appendPQExpBufferStr(query, "SELECT tableoid, oid, amname, "); - appendPQExpBufferStr(query, - "amtype, " - "amhandler::pg_catalog.regproc AS amhandler "); + appendPQExpBufferStr(query, + "amtype, " + "amhandler::pg_catalog.regproc AS amhandler "); appendPQExpBufferStr(query, "FROM pg_am"); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6827,35 +6826,35 @@ getAggregates(Archive *fout) * Find all interesting aggregates. See comment in getFuncs() for the * rationale behind the filtering logic. */ - agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" - : "p.proisagg"); + agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" + : "p.proisagg"); - appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " - "p.proname AS aggname, " - "p.pronamespace AS aggnamespace, " - "p.pronargs, p.proargtypes, " - "p.proowner, " - "p.proacl AS aggacl, " - "acldefault('f', p.proowner) AS acldefault " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s AND (" - "p.pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog') OR " - "p.proacl IS DISTINCT FROM pip.initprivs", - agg_check); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - " OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); - appendPQExpBufferChar(query, ')'); + appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " + "p.proname AS aggname, " + "p.pronamespace AS aggnamespace, " + "p.pronargs, p.proargtypes, " + "p.proowner, " + "p.proacl AS aggacl, " + "acldefault('f', p.proowner) AS acldefault " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s AND (" + "p.pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog') OR " + "p.proacl IS DISTINCT FROM pip.initprivs", + agg_check); + if (dopt->binary_upgrade) + appendPQExpBufferStr(query, + " OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6957,53 +6956,53 @@ getFuncs(Archive *fout) * include them, since we want to dump extension members individually in * that mode. Also, if they are used by casts or transforms then we need * to gather the information about them, though they won't be dumped if - * they are built-in. Also, include functions in - * pg_catalog if they have an ACL different from what's shown in - * pg_init_privs (so we have to join to pg_init_privs; annoying). + * they are built-in. Also, include functions in pg_catalog if they have + * an ACL different from what's shown in pg_init_privs (so we have to join + * to pg_init_privs; annoying). */ - not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" - : "NOT p.proisagg"); + not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" + : "NOT p.proisagg"); - appendPQExpBuffer(query, - "SELECT p.tableoid, p.oid, p.proname, p.prolang, " - "p.pronargs, p.proargtypes, p.prorettype, " - "p.proacl, " - "acldefault('f', p.proowner) AS acldefault, " - "p.pronamespace, " - "p.proowner " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s" - "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " - "WHERE classid = 'pg_proc'::regclass AND " - "objid = p.oid AND deptype = 'i')" - "\n AND (" - "\n pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog')" - "\n OR EXISTS (SELECT 1 FROM pg_cast" - "\n WHERE pg_cast.oid > %u " - "\n AND p.oid = pg_cast.castfunc)" - "\n OR EXISTS (SELECT 1 FROM pg_transform" - "\n WHERE pg_transform.oid > %u AND " - "\n (p.oid = pg_transform.trffromsql" - "\n OR p.oid = pg_transform.trftosql))", - not_agg_check, - g_last_builtin_oid, - g_last_builtin_oid); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); + appendPQExpBuffer(query, + "SELECT p.tableoid, p.oid, p.proname, p.prolang, " + "p.pronargs, p.proargtypes, p.prorettype, " + "p.proacl, " + "acldefault('f', p.proowner) AS acldefault, " + "p.pronamespace, " + "p.proowner " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s" + "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " + "WHERE classid = 'pg_proc'::regclass AND " + "objid = p.oid AND deptype = 'i')" + "\n AND (" + "\n pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog')" + "\n OR EXISTS (SELECT 1 FROM pg_cast" + "\n WHERE pg_cast.oid > %u " + "\n AND p.oid = pg_cast.castfunc)" + "\n OR EXISTS (SELECT 1 FROM pg_transform" + "\n WHERE pg_transform.oid > %u AND " + "\n (p.oid = pg_transform.trffromsql" + "\n OR p.oid = pg_transform.trftosql))", + not_agg_check, + g_last_builtin_oid, + g_last_builtin_oid); + if (dopt->binary_upgrade) appendPQExpBufferStr(query, - "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); - appendPQExpBufferChar(query, ')'); + "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferStr(query, + "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -7252,31 +7251,31 @@ getTables(Archive *fout, int *numTables) appendPQExpBufferStr(query, "c.relhasoids, "); - appendPQExpBufferStr(query, - "c.relispopulated, "); + appendPQExpBufferStr(query, + "c.relispopulated, "); - appendPQExpBufferStr(query, - "c.relreplident, "); + appendPQExpBufferStr(query, + "c.relreplident, "); - appendPQExpBufferStr(query, - "c.relrowsecurity, c.relforcerowsecurity, "); + appendPQExpBufferStr(query, + "c.relrowsecurity, c.relforcerowsecurity, "); - appendPQExpBufferStr(query, - "c.relminmxid, tc.relminmxid AS tminmxid, "); + appendPQExpBufferStr(query, + "c.relminmxid, tc.relminmxid AS tminmxid, "); - appendPQExpBufferStr(query, - "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); + appendPQExpBufferStr(query, + "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); - appendPQExpBufferStr(query, - "am.amname, "); + appendPQExpBufferStr(query, + "am.amname, "); - appendPQExpBufferStr(query, - "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); + appendPQExpBufferStr(query, + "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); - appendPQExpBufferStr(query, - "c.relispartition AS ispartition "); + appendPQExpBufferStr(query, + "c.relispartition AS ispartition "); /* * Left join to pg_depend to pick up dependency info linking sequences to @@ -7296,8 +7295,8 @@ getTables(Archive *fout, int *numTables) /* * Left join to pg_am to pick up the amname. */ - appendPQExpBufferStr(query, - "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); + appendPQExpBufferStr(query, + "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); /* * We purposefully ignore toast OIDs for partitioned tables; the reason is @@ -7868,8 +7867,8 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables) "t.reloptions AS indreloptions, "); - appendPQExpBufferStr(query, - "i.indisreplident, "); + appendPQExpBufferStr(query, + "i.indisreplident, "); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -9313,8 +9312,8 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables) appendPQExpBufferStr(q, "'' AS attcompression,\n"); - appendPQExpBufferStr(q, - "a.attidentity,\n"); + appendPQExpBufferStr(q, + "a.attidentity,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(q, @@ -10717,73 +10716,73 @@ getAdditionalACLs(Archive *fout) PQclear(res); /* Fetch initial-privileges data */ - printfPQExpBuffer(query, - "SELECT objoid, classoid, objsubid, privtype, initprivs " - "FROM pg_init_privs"); + printfPQExpBuffer(query, + "SELECT objoid, classoid, objsubid, privtype, initprivs " + "FROM pg_init_privs"); - res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); + res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); - ntups = PQntuples(res); - for (i = 0; i < ntups; i++) - { - Oid objoid = atooid(PQgetvalue(res, i, 0)); - Oid classoid = atooid(PQgetvalue(res, i, 1)); - int objsubid = atoi(PQgetvalue(res, i, 2)); - char privtype = *(PQgetvalue(res, i, 3)); - char *initprivs = PQgetvalue(res, i, 4); - CatalogId objId; - DumpableObject *dobj; + ntups = PQntuples(res); + for (i = 0; i < ntups; i++) + { + Oid objoid = atooid(PQgetvalue(res, i, 0)); + Oid classoid = atooid(PQgetvalue(res, i, 1)); + int objsubid = atoi(PQgetvalue(res, i, 2)); + char privtype = *(PQgetvalue(res, i, 3)); + char *initprivs = PQgetvalue(res, i, 4); + CatalogId objId; + DumpableObject *dobj; - objId.tableoid = classoid; - objId.oid = objoid; - dobj = findObjectByCatalogId(objId); - /* OK to ignore entries we haven't got a DumpableObject for */ - if (dobj) + objId.tableoid = classoid; + objId.oid = objoid; + dobj = findObjectByCatalogId(objId); + /* OK to ignore entries we haven't got a DumpableObject for */ + if (dobj) + { + /* Cope with sub-object initprivs */ + if (objsubid != 0) { - /* Cope with sub-object initprivs */ - if (objsubid != 0) - { - if (dobj->objType == DO_TABLE) - { - /* For a column initprivs, set the table's ACL flags */ - dobj->components |= DUMP_COMPONENT_ACL; - ((TableInfo *) dobj)->hascolumnACLs = true; - } - else - pg_log_warning("unsupported pg_init_privs entry: %u %u %d", - classoid, objoid, objsubid); - continue; - } - - /* - * We ignore any pg_init_privs.initprivs entry for the public - * schema, as explained in getNamespaces(). - */ - if (dobj->objType == DO_NAMESPACE && - strcmp(dobj->name, "public") == 0) - continue; - - /* Else it had better be of a type we think has ACLs */ - if (dobj->objType == DO_NAMESPACE || - dobj->objType == DO_TYPE || - dobj->objType == DO_FUNC || - dobj->objType == DO_AGG || - dobj->objType == DO_TABLE || - dobj->objType == DO_PROCLANG || - dobj->objType == DO_FDW || - dobj->objType == DO_FOREIGN_SERVER) + if (dobj->objType == DO_TABLE) { - DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; - - daobj->dacl.privtype = privtype; - daobj->dacl.initprivs = pstrdup(initprivs); + /* For a column initprivs, set the table's ACL flags */ + dobj->components |= DUMP_COMPONENT_ACL; + ((TableInfo *) dobj)->hascolumnACLs = true; } else pg_log_warning("unsupported pg_init_privs entry: %u %u %d", classoid, objoid, objsubid); + continue; + } + + /* + * We ignore any pg_init_privs.initprivs entry for the public + * schema, as explained in getNamespaces(). + */ + if (dobj->objType == DO_NAMESPACE && + strcmp(dobj->name, "public") == 0) + continue; + + /* Else it had better be of a type we think has ACLs */ + if (dobj->objType == DO_NAMESPACE || + dobj->objType == DO_TYPE || + dobj->objType == DO_FUNC || + dobj->objType == DO_AGG || + dobj->objType == DO_TABLE || + dobj->objType == DO_PROCLANG || + dobj->objType == DO_FDW || + dobj->objType == DO_FOREIGN_SERVER) + { + DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; + + daobj->dacl.privtype = privtype; + daobj->dacl.initprivs = pstrdup(initprivs); } + else + pg_log_warning("unsupported pg_init_privs entry: %u %u %d", + classoid, objoid, objsubid); } - PQclear(res); + } + PQclear(res); destroyPQExpBuffer(query); } @@ -11128,8 +11127,8 @@ dumpRelationStats_dumper(Archive *fout, const void *userArg, const TocEntry *te) * The results must be in the order of the relations supplied in the * parameters to ensure we remain in sync as we walk through the TOC. * - * For versions before 19, the redundant filter clause on s.tablename = - * ANY(...) seems sufficient to convince the planner to use + * For versions before 19, the redundant filter clause on s.tablename + * = ANY(...) seems sufficient to convince the planner to use * pg_class_relname_nsp_index, which avoids a full scan of pg_stats. * In newer versions, pg_stats returns the table OIDs, eliminating the * need for that hack. @@ -13469,11 +13468,11 @@ dumpFunc(Archive *fout, const FuncInfo *finfo) "pg_catalog.pg_get_function_result(p.oid) AS funcresult,\n" "proleakproof,\n"); - appendPQExpBufferStr(query, - "array_to_string(protrftypes, ' ') AS protrftypes,\n"); + appendPQExpBufferStr(query, + "array_to_string(protrftypes, ' ') AS protrftypes,\n"); - appendPQExpBufferStr(query, - "proparallel,\n"); + appendPQExpBufferStr(query, + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -14963,9 +14962,9 @@ dumpCollation(Archive *fout, const CollInfo *collinfo) /* Get collation-specific details */ appendPQExpBufferStr(query, "SELECT "); - appendPQExpBufferStr(query, - "collprovider, " - "collversion, "); + appendPQExpBufferStr(query, + "collprovider, " + "collversion, "); if (fout->remoteVersion >= 120000) appendPQExpBufferStr(query, @@ -15372,23 +15371,23 @@ dumpAgg(Archive *fout, const AggInfo *agginfo) "pg_catalog.pg_get_function_arguments(p.oid) AS funcargs,\n" "pg_catalog.pg_get_function_identity_arguments(p.oid) AS funciargs,\n"); - appendPQExpBufferStr(query, - "aggkind,\n" - "aggmtransfn,\n" - "aggminvtransfn,\n" - "aggmfinalfn,\n" - "aggmtranstype::pg_catalog.regtype,\n" - "aggfinalextra,\n" - "aggmfinalextra,\n" - "aggtransspace,\n" - "aggmtransspace,\n" - "aggminitval,\n"); + appendPQExpBufferStr(query, + "aggkind,\n" + "aggmtransfn,\n" + "aggminvtransfn,\n" + "aggmfinalfn,\n" + "aggmtranstype::pg_catalog.regtype,\n" + "aggfinalextra,\n" + "aggmfinalextra,\n" + "aggtransspace,\n" + "aggmtransspace,\n" + "aggminitval,\n"); - appendPQExpBufferStr(query, - "aggcombinefn,\n" - "aggserialfn,\n" - "aggdeserialfn,\n" - "proparallel,\n"); + appendPQExpBufferStr(query, + "aggcombinefn,\n" + "aggserialfn,\n" + "aggdeserialfn,\n" + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -16848,30 +16847,30 @@ dumpTable(Archive *fout, const TableInfo *tbinfo) appendPQExpBufferStr(query, "PREPARE getColumnACLs(pg_catalog.oid) AS\n"); - /* - * In principle we should call acldefault('c', relowner) to - * get the default ACL for a column. However, we don't - * currently store the numeric OID of the relowner in - * TableInfo. We could convert the owner name using regrole, - * but that creates a risk of failure due to concurrent role - * renames. Given that the default ACL for columns is empty - * and is likely to stay that way, it's not worth extra cycles - * and risk to avoid hard-wiring that knowledge here. - */ - appendPQExpBufferStr(query, - "SELECT at.attname, " - "at.attacl, " - "'{}' AS acldefault, " - "pip.privtype, pip.initprivs " - "FROM pg_catalog.pg_attribute at " - "LEFT JOIN pg_catalog.pg_init_privs pip ON " - "(at.attrelid = pip.objoid " - "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " - "AND at.attnum = pip.objsubid) " - "WHERE at.attrelid = $1 AND " - "NOT at.attisdropped " - "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " - "ORDER BY at.attnum"); + /* + * In principle we should call acldefault('c', relowner) to get + * the default ACL for a column. However, we don't currently + * store the numeric OID of the relowner in TableInfo. We could + * convert the owner name using regrole, but that creates a risk + * of failure due to concurrent role renames. Given that the + * default ACL for columns is empty and is likely to stay that + * way, it's not worth extra cycles and risk to avoid hard-wiring + * that knowledge here. + */ + appendPQExpBufferStr(query, + "SELECT at.attname, " + "at.attacl, " + "'{}' AS acldefault, " + "pip.privtype, pip.initprivs " + "FROM pg_catalog.pg_attribute at " + "LEFT JOIN pg_catalog.pg_init_privs pip ON " + "(at.attrelid = pip.objoid " + "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " + "AND at.attnum = pip.objsubid) " + "WHERE at.attrelid = $1 AND " + "NOT at.attisdropped " + "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " + "ORDER BY at.attnum"); ExecuteSqlStatement(fout, query->data); @@ -19165,7 +19164,7 @@ collectSequences(Archive *fout) * pg_get_sequence_data(), but we only do so for non-schema-only dumps. */ if (fout->remoteVersion < 180000 || - (!fout->dopt->dumpData && !fout->dopt->sequence_data)) + (!fout->dopt->dumpData && !fout->dopt->sequence_data)) query = "SELECT seqrelid, format_type(seqtypid, NULL), " "seqstart, seqincrement, " "seqmax, seqmin, " @@ -19227,15 +19226,14 @@ dumpSequence(Archive *fout, const TableInfo *tbinfo) qseqname = pg_strdup(fmtId(tbinfo->dobj.name)); /* - * The sequence information is gathered in a sorted - * table before any calls to dumpSequence(). See collectSequences() for - * more information. + * The sequence information is gathered in a sorted table before any calls + * to dumpSequence(). See collectSequences() for more information. */ - Assert(sequences); + Assert(sequences); - key.oid = tbinfo->dobj.catId.oid; - seq = bsearch(&key, sequences, nsequences, - sizeof(SequenceItem), SequenceItemCmp); + key.oid = tbinfo->dobj.catId.oid; + seq = bsearch(&key, sequences, nsequences, + sizeof(SequenceItem), SequenceItemCmp); /* Calculate default limits for a sequence of this type */ is_ascending = (seq->incby >= 0); diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c index e68937c9934..afcd9a218d8 100644 --- a/src/bin/pg_dump/pg_dumpall.c +++ b/src/bin/pg_dump/pg_dumpall.c @@ -785,11 +785,11 @@ dropRoles(PGconn *conn) int i_rolname; int i; - printfPQExpBuffer(buf, - "SELECT rolname " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 1", role_catalog); + printfPQExpBuffer(buf, + "SELECT rolname " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 1", role_catalog); res = executeQuery(conn, buf->data); @@ -843,16 +843,16 @@ dumpRoles(PGconn *conn) * Notes: rolconfig is dumped later, and pg_authid must be used for * extracting rolcomment regardless of role_catalog. */ - printfPQExpBuffer(buf, - "SELECT oid, rolname, rolsuper, rolinherit, " - "rolcreaterole, rolcreatedb, " - "rolcanlogin, rolconnlimit, rolpassword, " - "rolvaliduntil, rolreplication, rolbypassrls, " - "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " - "rolname = current_user AS is_current_user " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 2", role_catalog); + printfPQExpBuffer(buf, + "SELECT oid, rolname, rolsuper, rolinherit, " + "rolcreaterole, rolcreatedb, " + "rolcanlogin, rolconnlimit, rolpassword, " + "rolvaliduntil, rolreplication, rolbypassrls, " + "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " + "rolname = current_user AS is_current_user " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 2", role_catalog); res = executeQuery(conn, buf->data); diff --git a/src/bin/pg_upgrade/check.c b/src/bin/pg_upgrade/check.c index 786c1474829..f725f5ee3e2 100644 --- a/src/bin/pg_upgrade/check.c +++ b/src/bin/pg_upgrade/check.c @@ -1475,15 +1475,15 @@ check_for_incompatible_polymorphics(ClusterInfo *cluster) ", 'array_cat(anyarray,anyarray)'" ", 'array_prepend(anyelement,anyarray)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_remove(anyarray,anyelement)'" - ", 'array_replace(anyarray,anyelement,anyelement)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_remove(anyarray,anyelement)'" + ", 'array_replace(anyarray,anyelement,anyelement)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_position(anyarray,anyelement)'" - ", 'array_position(anyarray,anyelement,integer)'" - ", 'array_positions(anyarray,anyelement)'" - ", 'width_bucket(anyelement,anyarray)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_position(anyarray,anyelement)'" + ", 'array_position(anyarray,anyelement,integer)'" + ", 'array_positions(anyarray,anyelement)'" + ", 'width_bucket(anyelement,anyarray)'"); /* * The query below hardcodes FirstNormalObjectId as 16384 rather than diff --git a/src/bin/pg_upgrade/controldata.c b/src/bin/pg_upgrade/controldata.c index 8f81c9e9582..02ea02df60f 100644 --- a/src/bin/pg_upgrade/controldata.c +++ b/src/bin/pg_upgrade/controldata.c @@ -228,7 +228,7 @@ get_control_data(ClusterInfo *cluster) p++; /* remove ':' char */ cluster->controldata.chkpnt_nxtepoch = str2uint(p); - p = strchr(p, ':'); + p = strchr(p, ':'); if (p == NULL || strlen(p) <= 1) pg_fatal("%d: controldata retrieval problem", __LINE__); diff --git a/src/bin/pg_upgrade/exec.c b/src/bin/pg_upgrade/exec.c index 44355feea30..a1bdbf373e3 100644 --- a/src/bin/pg_upgrade/exec.c +++ b/src/bin/pg_upgrade/exec.c @@ -55,7 +55,7 @@ get_bin_version(ClusterInfo *cluster) if (sscanf(cmd_output, "%*s %*s %d.%d", &v1, &v2) < 1) pg_fatal("could not get pg_ctl version output from %s", cmd); - cluster->bin_version = v1 * 10000; + cluster->bin_version = v1 * 10000; } @@ -344,8 +344,8 @@ check_data_dir(ClusterInfo *cluster) check_single_dir(pg_data, "pg_subtrans"); check_single_dir(pg_data, PG_TBLSPC_DIR); check_single_dir(pg_data, "pg_twophase"); - check_single_dir(pg_data, "pg_wal"); - check_single_dir(pg_data, "pg_xact"); + check_single_dir(pg_data, "pg_wal"); + check_single_dir(pg_data, "pg_xact"); } @@ -385,7 +385,7 @@ check_bin_dir(ClusterInfo *cluster, bool check_versions) */ get_bin_version(cluster); - check_exec(cluster->bindir, "pg_resetwal", check_versions); + check_exec(cluster->bindir, "pg_resetwal", check_versions); if (cluster == &new_cluster) { diff --git a/src/bin/pg_upgrade/multixact_rewrite.c b/src/bin/pg_upgrade/multixact_rewrite.c index c45b3183684..c7a1416494d 100644 --- a/src/bin/pg_upgrade/multixact_rewrite.c +++ b/src/bin/pg_upgrade/multixact_rewrite.c @@ -61,52 +61,52 @@ rewrite_multixacts(MultiXactId from_multi, MultiXactId to_multi) * Convert old multixids, if needed, by reading them one-by-one from the * old cluster. */ - old_reader = AllocOldMultiXactRead(old_cluster.pgdata, - old_cluster.controldata.chkpnt_nxtmulti, - old_cluster.controldata.chkpnt_nxtmxoff); + old_reader = AllocOldMultiXactRead(old_cluster.pgdata, + old_cluster.controldata.chkpnt_nxtmulti, + old_cluster.controldata.chkpnt_nxtmxoff); - for (MultiXactId multi = from_multi; multi != to_multi;) - { - MultiXactMember member; - bool multixid_valid; - - /* - * Read this multixid's members. - * - * Locking-only XIDs that may be part of multi-xids don't matter - * after upgrade, as there can be no transactions running across - * upgrade. So as a small optimization, we only read one member - * from each multixid: the one updating one, or if there was no - * update, arbitrarily the first locking xid. - */ - multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); + for (MultiXactId multi = from_multi; multi != to_multi;) + { + MultiXactMember member; + bool multixid_valid; - /* - * Write the new offset to pg_multixact/offsets. - * - * Even if this multixid is invalid, we still need to write its - * offset if the *previous* multixid was valid. That's because - * when reading a multixid, the number of members is calculated - * from the difference between the two offsets. - */ - RecordMultiXactOffset(offsets_writer, multi, - (multixid_valid || prev_multixid_valid) ? next_offset : 0); + /* + * Read this multixid's members. + * + * Locking-only XIDs that may be part of multi-xids don't matter after + * upgrade, as there can be no transactions running across upgrade. So + * as a small optimization, we only read one member from each + * multixid: the one updating one, or if there was no update, + * arbitrarily the first locking xid. + */ + multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); - /* Write the members */ - if (multixid_valid) - { - RecordMultiXactMembers(members_writer, next_offset, 1, &member); - next_offset += 1; - } + /* + * Write the new offset to pg_multixact/offsets. + * + * Even if this multixid is invalid, we still need to write its offset + * if the *previous* multixid was valid. That's because when reading + * a multixid, the number of members is calculated from the difference + * between the two offsets. + */ + RecordMultiXactOffset(offsets_writer, multi, + (multixid_valid || prev_multixid_valid) ? next_offset : 0); - /* Advance to next multixid, handling wraparound */ - multi++; - if (multi < FirstMultiXactId) - multi = FirstMultiXactId; - prev_multixid_valid = multixid_valid; + /* Write the members */ + if (multixid_valid) + { + RecordMultiXactMembers(members_writer, next_offset, 1, &member); + next_offset += 1; } - FreeOldMultiXactReader(old_reader); + /* Advance to next multixid, handling wraparound */ + multi++; + if (multi < FirstMultiXactId) + multi = FirstMultiXactId; + prev_multixid_valid = multixid_valid; + } + + FreeOldMultiXactReader(old_reader); /* Write the final 'next' offset to the last SLRU page */ RecordMultiXactOffset(offsets_writer, to_multi, diff --git a/src/bin/pg_upgrade/pg_upgrade.c b/src/bin/pg_upgrade/pg_upgrade.c index c6af9035665..7366fd4627c 100644 --- a/src/bin/pg_upgrade/pg_upgrade.c +++ b/src/bin/pg_upgrade/pg_upgrade.c @@ -833,7 +833,7 @@ copy_xact_xlog_xid(void) * Determine the range of multixacts to convert. */ nxtmulti = old_cluster.controldata.chkpnt_nxtmulti; - oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; + oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; /* handle wraparound */ if (nxtmulti < FirstMultiXactId) nxtmulti = FirstMultiXactId; @@ -898,15 +898,15 @@ set_frozenxids(void) int i_datname; int i_datallowconn; - prep_status("Setting frozenxid and minmxid counters in new cluster"); + prep_status("Setting frozenxid and minmxid counters in new cluster"); conn_template1 = connectToServer(&new_cluster, "template1"); - /* set pg_database.datfrozenxid */ - PQclear(executeQueryOrDie(conn_template1, - "UPDATE pg_catalog.pg_database " - "SET datfrozenxid = '%u'", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_database.datfrozenxid */ + PQclear(executeQueryOrDie(conn_template1, + "UPDATE pg_catalog.pg_database " + "SET datfrozenxid = '%u'", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_database.datminmxid */ PQclear(executeQueryOrDie(conn_template1, @@ -942,16 +942,16 @@ set_frozenxids(void) conn = connectToServer(&new_cluster, datname); - /* set pg_class.relfrozenxid */ - PQclear(executeQueryOrDie(conn, - "UPDATE pg_catalog.pg_class " - "SET relfrozenxid = '%u' " - /* only heap, materialized view, and TOAST are vacuumed */ - "WHERE relkind IN (" - CppAsString2(RELKIND_RELATION) ", " - CppAsString2(RELKIND_MATVIEW) ", " - CppAsString2(RELKIND_TOASTVALUE) ")", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_class.relfrozenxid */ + PQclear(executeQueryOrDie(conn, + "UPDATE pg_catalog.pg_class " + "SET relfrozenxid = '%u' " + /* only heap, materialized view, and TOAST are vacuumed */ + "WHERE relkind IN (" + CppAsString2(RELKIND_RELATION) ", " + CppAsString2(RELKIND_MATVIEW) ", " + CppAsString2(RELKIND_TOASTVALUE) ")", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_class.relminmxid */ PQclear(executeQueryOrDie(conn, diff --git a/src/bin/pg_upgrade/relfilenumber.c b/src/bin/pg_upgrade/relfilenumber.c index ec2ff7acb21..6c467bdc8a5 100644 --- a/src/bin/pg_upgrade/relfilenumber.c +++ b/src/bin/pg_upgrade/relfilenumber.c @@ -587,32 +587,32 @@ transfer_relfile(FileNameMap *map, const char *type_suffix) /* Copying files might take some time, so give feedback. */ pg_log(PG_STATUS, "%s", old_file); - switch (user_opts.transfer_mode) - { - case TRANSFER_MODE_CLONE: - pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", - old_file, new_file); - cloneFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", - old_file, new_file); - copyFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY_FILE_RANGE: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", - old_file, new_file); - copyFileByRange(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_LINK: - pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", - old_file, new_file); - linkFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_SWAP: - /* swap mode is handled in its own code path */ - pg_fatal("should never happen"); - break; - } + switch (user_opts.transfer_mode) + { + case TRANSFER_MODE_CLONE: + pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", + old_file, new_file); + cloneFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", + old_file, new_file); + copyFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY_FILE_RANGE: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", + old_file, new_file); + copyFileByRange(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_LINK: + pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", + old_file, new_file); + linkFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_SWAP: + /* swap mode is handled in its own code path */ + pg_fatal("should never happen"); + break; + } } } diff --git a/src/bin/pg_upgrade/t/006_transfer_modes.pl b/src/bin/pg_upgrade/t/006_transfer_modes.pl index 9efa5dc863c..360d05c4b68 100644 --- a/src/bin/pg_upgrade/t/006_transfer_modes.pl +++ b/src/bin/pg_upgrade/t/006_transfer_modes.pl @@ -29,10 +29,8 @@ sub test_mode } $new->init(); - $new->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); - $old->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); + $new->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); + $old->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); # We can only test security labels if both the old and new installations # have dummy_seclabel. @@ -76,15 +74,14 @@ sub test_mode "CREATE TABLE test4 AS SELECT generate_series(400, 502)"); } - $old->safe_psql('postgres', - "CREATE TABLESPACE inplc_tblspc LOCATION ''"); - $old->safe_psql('postgres', - "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); - $old->safe_psql('postgres', - "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" - ); - $old->safe_psql('testdb3', - "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); + $old->safe_psql('postgres', "CREATE TABLESPACE inplc_tblspc LOCATION ''"); + $old->safe_psql('postgres', + "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); + $old->safe_psql('postgres', + "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" + ); + $old->safe_psql('testdb3', + "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); # While we are here, test handling of large objects. $old->safe_psql( @@ -152,12 +149,10 @@ sub test_mode } # Tests for in-place tablespaces. - $result = - $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); - is($result, '104', "test5 data after pg_upgrade $mode"); - $result = - $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); - is($result, '105', "test6 data after pg_upgrade $mode"); + $result = $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); + is($result, '104', "test5 data after pg_upgrade $mode"); + $result = $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); + is($result, '105', "test6 data after pg_upgrade $mode"); # Tests for large objects $result = $new->safe_psql('postgres', "SELECT lo_get(4532)"); diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index 44ef11d980e..c90bf8bbde2 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -6278,23 +6278,22 @@ get_create_object_cmd(EditableObjectType obj_type, Oid oid, * ensure the right view gets replaced. Also, check relation kind * to be sure it's a view. * - * Views may have WITH [LOCAL|CASCADED] - * CHECK OPTION. These are not part of the view definition - * returned by pg_get_viewdef() and so need to be retrieved - * separately. Materialized views may have - * arbitrary storage parameter reloptions. + * Views may have WITH [LOCAL|CASCADED] CHECK OPTION. These are + * not part of the view definition returned by pg_get_viewdef() + * and so need to be retrieved separately. Materialized views may + * have arbitrary storage parameter reloptions. */ printfPQExpBuffer(query, "/* %s */\n", _("Get view's definition and details")); - appendPQExpBuffer(query, - "SELECT nspname, relname, relkind, " - "pg_catalog.pg_get_viewdef(c.oid, true), " - "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " - "FROM pg_catalog.pg_class c " - "LEFT JOIN pg_catalog.pg_namespace n " - "ON c.relnamespace = n.oid WHERE c.oid = %u", - oid); + appendPQExpBuffer(query, + "SELECT nspname, relname, relkind, " + "pg_catalog.pg_get_viewdef(c.oid, true), " + "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " + "FROM pg_catalog.pg_class c " + "LEFT JOIN pg_catalog.pg_namespace n " + "ON c.relnamespace = n.oid WHERE c.oid = %u", + oid); break; } diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index ce99137c613..ac0c55e7aa5 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -387,19 +387,19 @@ describeFunctions(const char *functypes, const char *func_pattern, gettext_noop("stable"), gettext_noop("volatile"), gettext_noop("Volatility")); - appendPQExpBuffer(&buf, - ",\n CASE\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" - " END as \"%s\"", - gettext_noop("restricted"), - gettext_noop("safe"), - gettext_noop("unsafe"), - gettext_noop("Parallel")); + appendPQExpBuffer(&buf, + ",\n CASE\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" + " END as \"%s\"", + gettext_noop("restricted"), + gettext_noop("safe"), + gettext_noop("unsafe"), + gettext_noop("Parallel")); appendPQExpBuffer(&buf, ",\n pg_catalog.pg_get_userbyid(p.proowner) as \"%s\"" ",\n CASE WHEN prosecdef THEN '%s' ELSE '%s' END AS \"%s\"" @@ -599,8 +599,8 @@ describeFunctions(const char *functypes, const char *func_pattern, myopt.title = _("List of functions"); myopt.translate_header = true; - myopt.translate_columns = translate_columns; - myopt.n_translate_columns = lengthof(translate_columns); + myopt.translate_columns = translate_columns; + myopt.n_translate_columns = lengthof(translate_columns); printQuery(res, &myopt, pset.queryFout, false, pset.logfile); @@ -1086,38 +1086,38 @@ permissionsList(const char *pattern, bool showSystem) " ), E'\\n') AS \"%s\"", gettext_noop("Column privileges")); - appendPQExpBuffer(&buf, - ",\n pg_catalog.array_to_string(ARRAY(\n" - " SELECT polname\n" - " || CASE WHEN NOT polpermissive THEN\n" - " E' (RESTRICTIVE)'\n" - " ELSE '' END\n" - " || CASE WHEN polcmd != '*' THEN\n" - " E' (' || polcmd::pg_catalog.text || E'):'\n" - " ELSE E':'\n" - " END\n" - " || CASE WHEN polqual IS NOT NULL THEN\n" - " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" - " ELSE E''\n" - " END\n" - " || CASE WHEN polwithcheck IS NOT NULL THEN\n" - " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" - " ELSE E''\n" - " END" - " || CASE WHEN polroles <> '{0}' THEN\n" - " E'\\n to: ' || pg_catalog.array_to_string(\n" - " ARRAY(\n" - " SELECT rolname\n" - " FROM pg_catalog.pg_roles\n" - " WHERE oid = ANY (polroles)\n" - " ORDER BY 1\n" - " ), E', ')\n" - " ELSE E''\n" - " END\n" - " FROM pg_catalog.pg_policy pol\n" - " WHERE polrelid = c.oid), E'\\n')\n" - " AS \"%s\"", - gettext_noop("Policies")); + appendPQExpBuffer(&buf, + ",\n pg_catalog.array_to_string(ARRAY(\n" + " SELECT polname\n" + " || CASE WHEN NOT polpermissive THEN\n" + " E' (RESTRICTIVE)'\n" + " ELSE '' END\n" + " || CASE WHEN polcmd != '*' THEN\n" + " E' (' || polcmd::pg_catalog.text || E'):'\n" + " ELSE E':'\n" + " END\n" + " || CASE WHEN polqual IS NOT NULL THEN\n" + " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" + " ELSE E''\n" + " END\n" + " || CASE WHEN polwithcheck IS NOT NULL THEN\n" + " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" + " ELSE E''\n" + " END" + " || CASE WHEN polroles <> '{0}' THEN\n" + " E'\\n to: ' || pg_catalog.array_to_string(\n" + " ARRAY(\n" + " SELECT rolname\n" + " FROM pg_catalog.pg_roles\n" + " WHERE oid = ANY (polroles)\n" + " ORDER BY 1\n" + " ), E', ')\n" + " ELSE E''\n" + " END\n" + " FROM pg_catalog.pg_policy pol\n" + " WHERE polrelid = c.oid), E'\\n')\n" + " AS \"%s\"", + gettext_noop("Policies")); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_class c\n" " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n" @@ -1675,27 +1675,27 @@ describeOneTableDetails(const char *schemaname, char *footers[3] = {NULL, NULL, NULL}; printfPQExpBuffer(&buf, "/* %s */\n", _("Get sequence information")); - appendPQExpBuffer(&buf, - "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" - " seqstart AS \"%s\",\n" - " seqmin AS \"%s\",\n" - " seqmax AS \"%s\",\n" - " seqincrement AS \"%s\",\n" - " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" - " seqcache AS \"%s\"\n", - gettext_noop("Type"), - gettext_noop("Start"), - gettext_noop("Minimum"), - gettext_noop("Maximum"), - gettext_noop("Increment"), - gettext_noop("yes"), - gettext_noop("no"), - gettext_noop("Cycles?"), - gettext_noop("Cache")); - appendPQExpBuffer(&buf, - "FROM pg_catalog.pg_sequence\n" - "WHERE seqrelid = '%s';", - oid); + appendPQExpBuffer(&buf, + "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" + " seqstart AS \"%s\",\n" + " seqmin AS \"%s\",\n" + " seqmax AS \"%s\",\n" + " seqincrement AS \"%s\",\n" + " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" + " seqcache AS \"%s\"\n", + gettext_noop("Type"), + gettext_noop("Start"), + gettext_noop("Minimum"), + gettext_noop("Maximum"), + gettext_noop("Increment"), + gettext_noop("yes"), + gettext_noop("no"), + gettext_noop("Cycles?"), + gettext_noop("Cache")); + appendPQExpBuffer(&buf, + "FROM pg_catalog.pg_sequence\n" + "WHERE seqrelid = '%s';", + oid); res = PSQLexec(buf.data); if (!res) @@ -1913,7 +1913,7 @@ describeOneTableDetails(const char *schemaname, appendPQExpBufferStr(&buf, ",\n (SELECT c.collname FROM pg_catalog.pg_collation c, pg_catalog.pg_type t\n" " WHERE c.oid = a.attcollation AND t.oid = a.atttypid AND a.attcollation <> t.typcollation) AS attcollation"); attcoll_col = cols++; - appendPQExpBufferStr(&buf, ",\n a.attidentity"); + appendPQExpBufferStr(&buf, ",\n a.attidentity"); attidentity_col = cols++; if (pset.sversion >= 120000) appendPQExpBufferStr(&buf, ",\n a.attgenerated"); @@ -2326,7 +2326,7 @@ describeOneTableDetails(const char *schemaname, CppAsString2(CONSTRAINT_EXCLUSION) ") AND " "condeferred) AS condeferred,\n"); - appendPQExpBufferStr(&buf, "i.indisreplident,\n"); + appendPQExpBufferStr(&buf, "i.indisreplident,\n"); if (pset.sversion >= 150000) appendPQExpBufferStr(&buf, "i.indnullsnotdistinct,\n"); @@ -2431,7 +2431,7 @@ describeOneTableDetails(const char *schemaname, "pg_catalog.pg_get_indexdef(i.indexrelid, 0, true),\n " "pg_catalog.pg_get_constraintdef(con.oid, true), " "contype, condeferrable, condeferred"); - appendPQExpBufferStr(&buf, ", i.indisreplident"); + appendPQExpBufferStr(&buf, ", i.indisreplident"); appendPQExpBufferStr(&buf, ", c2.reltablespace"); if (pset.sversion >= 180000) appendPQExpBufferStr(&buf, ", con.conperiod"); @@ -2682,81 +2682,80 @@ describeOneTableDetails(const char *schemaname, PQclear(result); /* print any row-level policies */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get row-level policies for this table")); - appendPQExpBufferStr(&buf, "SELECT pol.polname,"); - appendPQExpBufferStr(&buf, - " pol.polpermissive,\n"); - appendPQExpBuffer(&buf, - " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" - " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" - " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" - " CASE pol.polcmd\n" - " WHEN 'r' THEN 'SELECT'\n" - " WHEN 'a' THEN 'INSERT'\n" - " WHEN 'w' THEN 'UPDATE'\n" - " WHEN 'd' THEN 'DELETE'\n" - " END AS cmd\n" - "FROM pg_catalog.pg_policy pol\n" - "WHERE pol.polrelid = '%s' ORDER BY 1;", - oid); + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get row-level policies for this table")); + appendPQExpBufferStr(&buf, "SELECT pol.polname,"); + appendPQExpBufferStr(&buf, + " pol.polpermissive,\n"); + appendPQExpBuffer(&buf, + " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" + " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" + " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" + " CASE pol.polcmd\n" + " WHEN 'r' THEN 'SELECT'\n" + " WHEN 'a' THEN 'INSERT'\n" + " WHEN 'w' THEN 'UPDATE'\n" + " WHEN 'd' THEN 'DELETE'\n" + " END AS cmd\n" + "FROM pg_catalog.pg_policy pol\n" + "WHERE pol.polrelid = '%s' ORDER BY 1;", + oid); - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - /* - * Handle cases where RLS is enabled and there are policies, or - * there aren't policies, or RLS isn't enabled but there are - * policies - */ - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies:")); + /* + * Handle cases where RLS is enabled and there are policies, or there + * aren't policies, or RLS isn't enabled but there are policies + */ + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies:")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled):")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled):")); - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); - if (!tableinfo.rowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (row security disabled):")); + if (!tableinfo.rowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (row security disabled):")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " POLICY \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " POLICY \"%s\"", + PQgetvalue(result, i, 0)); - if (*(PQgetvalue(result, i, 1)) == 'f') - appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); + if (*(PQgetvalue(result, i, 1)) == 'f') + appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); - if (!PQgetisnull(result, i, 5)) - appendPQExpBuffer(&buf, " FOR %s", - PQgetvalue(result, i, 5)); + if (!PQgetisnull(result, i, 5)) + appendPQExpBuffer(&buf, " FOR %s", + PQgetvalue(result, i, 5)); - if (!PQgetisnull(result, i, 2)) - { - appendPQExpBuffer(&buf, "\n TO %s", - PQgetvalue(result, i, 2)); - } + if (!PQgetisnull(result, i, 2)) + { + appendPQExpBuffer(&buf, "\n TO %s", + PQgetvalue(result, i, 2)); + } - if (!PQgetisnull(result, i, 3)) - appendPQExpBuffer(&buf, "\n USING (%s)", - PQgetvalue(result, i, 3)); + if (!PQgetisnull(result, i, 3)) + appendPQExpBuffer(&buf, "\n USING (%s)", + PQgetvalue(result, i, 3)); - if (!PQgetisnull(result, i, 4)) - appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", - PQgetvalue(result, i, 4)); + if (!PQgetisnull(result, i, 4)) + appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", + PQgetvalue(result, i, 4)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* print any extended statistics */ if (pset.sversion >= 140000) @@ -3025,115 +3024,115 @@ describeOneTableDetails(const char *schemaname, } /* print any publications */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get publications that publish this table")); - if (pset.sversion >= 150000) + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get publications that publish this table")); + if (pset.sversion >= 150000) + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" + " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" + "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" + "UNION\n" + "SELECT pubname\n" + " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" + " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" + " (SELECT pg_catalog.string_agg(attname, ', ')\n" + " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" + " pg_catalog.pg_attribute\n" + " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" + " ELSE NULL END) " + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" + "WHERE pr.prrelid = '%s'\n", + oid, oid, oid); + + if (pset.sversion >= 190000) { + /* + * Skip entries where this relation appears in the + * publication's EXCEPT list. + */ appendPQExpBuffer(&buf, + " AND NOT pr.prexcept\n" + "UNION\n" "SELECT pubname\n" " , NULL\n" " , NULL\n" "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" - " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" - "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" - "UNION\n" - "SELECT pubname\n" - " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" - " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" - " (SELECT pg_catalog.string_agg(attname, ', ')\n" - " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" - " pg_catalog.pg_attribute\n" - " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" - " ELSE NULL END) " - "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" - "WHERE pr.prrelid = '%s'\n", + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + " AND NOT EXISTS (\n" + " SELECT 1\n" + " FROM pg_catalog.pg_publication_rel pr\n" + " WHERE pr.prpubid = p.oid AND\n" + " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" + "ORDER BY 1;", oid, oid, oid); - - if (pset.sversion >= 190000) - { - /* - * Skip entries where this relation appears in the - * publication's EXCEPT list. - */ - appendPQExpBuffer(&buf, - " AND NOT pr.prexcept\n" - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - " AND NOT EXISTS (\n" - " SELECT 1\n" - " FROM pg_catalog.pg_publication_rel pr\n" - " WHERE pr.prpubid = p.oid AND\n" - " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" - "ORDER BY 1;", - oid, oid, oid); - } - else - { - appendPQExpBuffer(&buf, - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - "ORDER BY 1;", - oid); - } } else { appendPQExpBuffer(&buf, + "UNION\n" "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - "WHERE pr.prrelid = '%s'\n" - "UNION ALL\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" + " , NULL\n" + " , NULL\n" "FROM pg_catalog.pg_publication p\n" "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" "ORDER BY 1;", - oid, oid); + oid); } + } + else + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + "WHERE pr.prrelid = '%s'\n" + "UNION ALL\n" + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + "ORDER BY 1;", + oid, oid); + } - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - if (tuples > 0) - printTableAddFooter(&cont, _("Included in publications:")); + if (tuples > 0) + printTableAddFooter(&cont, _("Included in publications:")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " \"%s\"", + PQgetvalue(result, i, 0)); - /* column list (if any) */ - if (!PQgetisnull(result, i, 2)) - appendPQExpBuffer(&buf, " (%s)", - PQgetvalue(result, i, 2)); + /* column list (if any) */ + if (!PQgetisnull(result, i, 2)) + appendPQExpBuffer(&buf, " (%s)", + PQgetvalue(result, i, 2)); - /* row filter (if any) */ - if (!PQgetisnull(result, i, 1)) - appendPQExpBuffer(&buf, " WHERE %s", - PQgetvalue(result, i, 1)); + /* row filter (if any) */ + if (!PQgetisnull(result, i, 1)) + appendPQExpBuffer(&buf, " WHERE %s", + PQgetvalue(result, i, 1)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* Print publications where the table is in the EXCEPT clause */ if (pset.sversion >= 190000) @@ -3805,7 +3804,7 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) ncols++; } appendPQExpBufferStr(&buf, "\n, r.rolreplication"); - appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); + appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_roles r\n"); @@ -3860,8 +3859,8 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) if (strcmp(PQgetvalue(res, i, (verbose ? 9 : 8)), "t") == 0) add_role_attribute(&buf, _("Replication")); - if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) - add_role_attribute(&buf, _("Bypass RLS")); + if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) + add_role_attribute(&buf, _("Bypass RLS")); conns = atoi(PQgetvalue(res, i, 6)); if (conns >= 0) @@ -5155,14 +5154,14 @@ listCollations(const char *pattern, bool verbose, bool showSystem) gettext_noop("Schema"), gettext_noop("Name")); - appendPQExpBuffer(&buf, - " CASE c.collprovider " - "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " - "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " - "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " - "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " - "END AS \"%s\",\n", - gettext_noop("Provider")); + appendPQExpBuffer(&buf, + " CASE c.collprovider " + "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " + "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " + "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " + "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " + "END AS \"%s\",\n", + gettext_noop("Provider")); appendPQExpBuffer(&buf, " c.collcollate AS \"%s\",\n" -- 2.50.1 (Apple Git-155) --aHl3HfeiUuO3zeNC-- ^ permalink raw reply [nested|flat] 59+ messages in thread
* [PATCH v6 4/4] run pgindent and pgperltidy @ 2026-06-30 18:24 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 59+ messages in thread From: Nathan Bossart @ 2026-06-30 18:24 UTC (permalink / raw) --- src/bin/pg_dump/pg_dump.c | 464 ++++++++++----------- src/bin/pg_dump/pg_dumpall.c | 30 +- src/bin/pg_upgrade/check.c | 16 +- src/bin/pg_upgrade/controldata.c | 2 +- src/bin/pg_upgrade/exec.c | 8 +- src/bin/pg_upgrade/multixact_rewrite.c | 80 ++-- src/bin/pg_upgrade/pg_upgrade.c | 34 +- src/bin/pg_upgrade/relfilenumber.c | 54 +-- src/bin/pg_upgrade/t/006_transfer_modes.pl | 33 +- src/bin/psql/command.c | 29 +- src/bin/psql/describe.c | 461 ++++++++++---------- 11 files changed, 601 insertions(+), 610 deletions(-) diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 65bd15ebfd2..5673268b467 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -1491,8 +1491,8 @@ setup_connection(Archive *AH, const char *dumpencoding, * Disable timeouts if supported. */ ExecuteSqlStatement(AH, "SET statement_timeout = 0"); - ExecuteSqlStatement(AH, "SET lock_timeout = 0"); - ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); + ExecuteSqlStatement(AH, "SET lock_timeout = 0"); + ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); if (AH->remoteVersion >= 170000) ExecuteSqlStatement(AH, "SET transaction_timeout = 0"); @@ -1505,10 +1505,10 @@ setup_connection(Archive *AH, const char *dumpencoding, /* * Adjust row-security mode, if supported. */ - if (dopt->enable_row_security) - ExecuteSqlStatement(AH, "SET row_security = on"); - else - ExecuteSqlStatement(AH, "SET row_security = off"); + if (dopt->enable_row_security) + ExecuteSqlStatement(AH, "SET row_security = on"); + else + ExecuteSqlStatement(AH, "SET row_security = off"); /* * For security reasons, we restrict the expansion of non-system views and @@ -1933,10 +1933,9 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) addObjectDependency(dobj, ext->dobj.dumpId); /* - * Mark the member object to have any non-initial ACLs - * dumped. (Any initial ACLs will be removed later, using data from - * pg_init_privs, so that we'll dump only the delta from the extension's - * initial setup.) + * Mark the member object to have any non-initial ACLs dumped. (Any + * initial ACLs will be removed later, using data from pg_init_privs, so + * that we'll dump only the delta from the extension's initial setup.) * * In binary upgrades, we still dump all components of the members * individually, since the idea is to exactly reproduce the database @@ -1953,7 +1952,7 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) if (fout->dopt->binary_upgrade) dobj->dump = ext->dobj.dump; else - dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); + dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); return true; } @@ -1987,9 +1986,9 @@ selectDumpableNamespace(NamespaceInfo *nsinfo, Archive *fout) else if (strcmp(nsinfo->dobj.name, "pg_catalog") == 0) { /* - * We dump out any ACLs defined in pg_catalog, if - * they are interesting (and not the original ACLs which were set at - * initdb time, see pg_init_privs). + * We dump out any ACLs defined in pg_catalog, if they are interesting + * (and not the original ACLs which were set at initdb time, see + * pg_init_privs). */ nsinfo->dobj.dump_contains = nsinfo->dobj.dump = DUMP_COMPONENT_ACL; } @@ -3296,7 +3295,7 @@ dumpDatabase(Archive *fout) "datcollate, datctype, datfrozenxid, " "datacl, acldefault('d', datdba) AS acldefault, " "datistemplate, datconnlimit, "); - appendPQExpBufferStr(dbQry, "datminmxid, "); + appendPQExpBufferStr(dbQry, "datminmxid, "); if (fout->remoteVersion >= 170000) appendPQExpBufferStr(dbQry, "datlocprovider, datlocale, datcollversion, "); else if (fout->remoteVersion >= 150000) @@ -3638,11 +3637,11 @@ dumpDatabase(Archive *fout) ii_oid, ii_relminmxid; - appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" - "FROM pg_catalog.pg_class\n" - "WHERE oid IN (%u, %u, %u, %u);\n", - LargeObjectRelationId, LargeObjectLOidPNIndexId, - LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); + appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" + "FROM pg_catalog.pg_class\n" + "WHERE oid IN (%u, %u, %u, %u);\n", + LargeObjectRelationId, LargeObjectLOidPNIndexId, + LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); lo_res = ExecuteSqlQuery(fout, loFrozenQry->data, PGRES_TUPLES_OK); @@ -4274,7 +4273,7 @@ getPolicies(Archive *fout, TableInfo tblinfo[], int numTables) printfPQExpBuffer(query, "SELECT pol.oid, pol.tableoid, pol.polrelid, pol.polname, pol.polcmd, "); - appendPQExpBufferStr(query, "pol.polpermissive, "); + appendPQExpBufferStr(query, "pol.polpermissive, "); appendPQExpBuffer(query, "CASE WHEN pol.polroles = '{0}' THEN NULL ELSE " " pg_catalog.array_to_string(ARRAY(SELECT pg_catalog.quote_ident(rolname) from pg_catalog.pg_roles WHERE oid = ANY(pol.polroles)), ', ') END AS polroles, " @@ -6633,9 +6632,9 @@ getAccessMethods(Archive *fout) * Select all access methods from pg_am table. */ appendPQExpBufferStr(query, "SELECT tableoid, oid, amname, "); - appendPQExpBufferStr(query, - "amtype, " - "amhandler::pg_catalog.regproc AS amhandler "); + appendPQExpBufferStr(query, + "amtype, " + "amhandler::pg_catalog.regproc AS amhandler "); appendPQExpBufferStr(query, "FROM pg_am"); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6827,35 +6826,35 @@ getAggregates(Archive *fout) * Find all interesting aggregates. See comment in getFuncs() for the * rationale behind the filtering logic. */ - agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" - : "p.proisagg"); + agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" + : "p.proisagg"); - appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " - "p.proname AS aggname, " - "p.pronamespace AS aggnamespace, " - "p.pronargs, p.proargtypes, " - "p.proowner, " - "p.proacl AS aggacl, " - "acldefault('f', p.proowner) AS acldefault " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s AND (" - "p.pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog') OR " - "p.proacl IS DISTINCT FROM pip.initprivs", - agg_check); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - " OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); - appendPQExpBufferChar(query, ')'); + appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " + "p.proname AS aggname, " + "p.pronamespace AS aggnamespace, " + "p.pronargs, p.proargtypes, " + "p.proowner, " + "p.proacl AS aggacl, " + "acldefault('f', p.proowner) AS acldefault " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s AND (" + "p.pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog') OR " + "p.proacl IS DISTINCT FROM pip.initprivs", + agg_check); + if (dopt->binary_upgrade) + appendPQExpBufferStr(query, + " OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6957,53 +6956,53 @@ getFuncs(Archive *fout) * include them, since we want to dump extension members individually in * that mode. Also, if they are used by casts or transforms then we need * to gather the information about them, though they won't be dumped if - * they are built-in. Also, include functions in - * pg_catalog if they have an ACL different from what's shown in - * pg_init_privs (so we have to join to pg_init_privs; annoying). + * they are built-in. Also, include functions in pg_catalog if they have + * an ACL different from what's shown in pg_init_privs (so we have to join + * to pg_init_privs; annoying). */ - not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" - : "NOT p.proisagg"); + not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" + : "NOT p.proisagg"); - appendPQExpBuffer(query, - "SELECT p.tableoid, p.oid, p.proname, p.prolang, " - "p.pronargs, p.proargtypes, p.prorettype, " - "p.proacl, " - "acldefault('f', p.proowner) AS acldefault, " - "p.pronamespace, " - "p.proowner " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s" - "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " - "WHERE classid = 'pg_proc'::regclass AND " - "objid = p.oid AND deptype = 'i')" - "\n AND (" - "\n pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog')" - "\n OR EXISTS (SELECT 1 FROM pg_cast" - "\n WHERE pg_cast.oid > %u " - "\n AND p.oid = pg_cast.castfunc)" - "\n OR EXISTS (SELECT 1 FROM pg_transform" - "\n WHERE pg_transform.oid > %u AND " - "\n (p.oid = pg_transform.trffromsql" - "\n OR p.oid = pg_transform.trftosql))", - not_agg_check, - g_last_builtin_oid, - g_last_builtin_oid); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); + appendPQExpBuffer(query, + "SELECT p.tableoid, p.oid, p.proname, p.prolang, " + "p.pronargs, p.proargtypes, p.prorettype, " + "p.proacl, " + "acldefault('f', p.proowner) AS acldefault, " + "p.pronamespace, " + "p.proowner " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s" + "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " + "WHERE classid = 'pg_proc'::regclass AND " + "objid = p.oid AND deptype = 'i')" + "\n AND (" + "\n pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog')" + "\n OR EXISTS (SELECT 1 FROM pg_cast" + "\n WHERE pg_cast.oid > %u " + "\n AND p.oid = pg_cast.castfunc)" + "\n OR EXISTS (SELECT 1 FROM pg_transform" + "\n WHERE pg_transform.oid > %u AND " + "\n (p.oid = pg_transform.trffromsql" + "\n OR p.oid = pg_transform.trftosql))", + not_agg_check, + g_last_builtin_oid, + g_last_builtin_oid); + if (dopt->binary_upgrade) appendPQExpBufferStr(query, - "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); - appendPQExpBufferChar(query, ')'); + "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferStr(query, + "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -7252,31 +7251,31 @@ getTables(Archive *fout, int *numTables) appendPQExpBufferStr(query, "c.relhasoids, "); - appendPQExpBufferStr(query, - "c.relispopulated, "); + appendPQExpBufferStr(query, + "c.relispopulated, "); - appendPQExpBufferStr(query, - "c.relreplident, "); + appendPQExpBufferStr(query, + "c.relreplident, "); - appendPQExpBufferStr(query, - "c.relrowsecurity, c.relforcerowsecurity, "); + appendPQExpBufferStr(query, + "c.relrowsecurity, c.relforcerowsecurity, "); - appendPQExpBufferStr(query, - "c.relminmxid, tc.relminmxid AS tminmxid, "); + appendPQExpBufferStr(query, + "c.relminmxid, tc.relminmxid AS tminmxid, "); - appendPQExpBufferStr(query, - "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); + appendPQExpBufferStr(query, + "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); - appendPQExpBufferStr(query, - "am.amname, "); + appendPQExpBufferStr(query, + "am.amname, "); - appendPQExpBufferStr(query, - "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); + appendPQExpBufferStr(query, + "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); - appendPQExpBufferStr(query, - "c.relispartition AS ispartition "); + appendPQExpBufferStr(query, + "c.relispartition AS ispartition "); /* * Left join to pg_depend to pick up dependency info linking sequences to @@ -7296,8 +7295,8 @@ getTables(Archive *fout, int *numTables) /* * Left join to pg_am to pick up the amname. */ - appendPQExpBufferStr(query, - "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); + appendPQExpBufferStr(query, + "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); /* * We purposefully ignore toast OIDs for partitioned tables; the reason is @@ -7868,8 +7867,8 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables) "t.reloptions AS indreloptions, "); - appendPQExpBufferStr(query, - "i.indisreplident, "); + appendPQExpBufferStr(query, + "i.indisreplident, "); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -9313,8 +9312,8 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables) appendPQExpBufferStr(q, "'' AS attcompression,\n"); - appendPQExpBufferStr(q, - "a.attidentity,\n"); + appendPQExpBufferStr(q, + "a.attidentity,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(q, @@ -10717,73 +10716,73 @@ getAdditionalACLs(Archive *fout) PQclear(res); /* Fetch initial-privileges data */ - printfPQExpBuffer(query, - "SELECT objoid, classoid, objsubid, privtype, initprivs " - "FROM pg_init_privs"); + printfPQExpBuffer(query, + "SELECT objoid, classoid, objsubid, privtype, initprivs " + "FROM pg_init_privs"); - res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); + res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); - ntups = PQntuples(res); - for (i = 0; i < ntups; i++) - { - Oid objoid = atooid(PQgetvalue(res, i, 0)); - Oid classoid = atooid(PQgetvalue(res, i, 1)); - int objsubid = atoi(PQgetvalue(res, i, 2)); - char privtype = *(PQgetvalue(res, i, 3)); - char *initprivs = PQgetvalue(res, i, 4); - CatalogId objId; - DumpableObject *dobj; + ntups = PQntuples(res); + for (i = 0; i < ntups; i++) + { + Oid objoid = atooid(PQgetvalue(res, i, 0)); + Oid classoid = atooid(PQgetvalue(res, i, 1)); + int objsubid = atoi(PQgetvalue(res, i, 2)); + char privtype = *(PQgetvalue(res, i, 3)); + char *initprivs = PQgetvalue(res, i, 4); + CatalogId objId; + DumpableObject *dobj; - objId.tableoid = classoid; - objId.oid = objoid; - dobj = findObjectByCatalogId(objId); - /* OK to ignore entries we haven't got a DumpableObject for */ - if (dobj) + objId.tableoid = classoid; + objId.oid = objoid; + dobj = findObjectByCatalogId(objId); + /* OK to ignore entries we haven't got a DumpableObject for */ + if (dobj) + { + /* Cope with sub-object initprivs */ + if (objsubid != 0) { - /* Cope with sub-object initprivs */ - if (objsubid != 0) - { - if (dobj->objType == DO_TABLE) - { - /* For a column initprivs, set the table's ACL flags */ - dobj->components |= DUMP_COMPONENT_ACL; - ((TableInfo *) dobj)->hascolumnACLs = true; - } - else - pg_log_warning("unsupported pg_init_privs entry: %u %u %d", - classoid, objoid, objsubid); - continue; - } - - /* - * We ignore any pg_init_privs.initprivs entry for the public - * schema, as explained in getNamespaces(). - */ - if (dobj->objType == DO_NAMESPACE && - strcmp(dobj->name, "public") == 0) - continue; - - /* Else it had better be of a type we think has ACLs */ - if (dobj->objType == DO_NAMESPACE || - dobj->objType == DO_TYPE || - dobj->objType == DO_FUNC || - dobj->objType == DO_AGG || - dobj->objType == DO_TABLE || - dobj->objType == DO_PROCLANG || - dobj->objType == DO_FDW || - dobj->objType == DO_FOREIGN_SERVER) + if (dobj->objType == DO_TABLE) { - DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; - - daobj->dacl.privtype = privtype; - daobj->dacl.initprivs = pstrdup(initprivs); + /* For a column initprivs, set the table's ACL flags */ + dobj->components |= DUMP_COMPONENT_ACL; + ((TableInfo *) dobj)->hascolumnACLs = true; } else pg_log_warning("unsupported pg_init_privs entry: %u %u %d", classoid, objoid, objsubid); + continue; + } + + /* + * We ignore any pg_init_privs.initprivs entry for the public + * schema, as explained in getNamespaces(). + */ + if (dobj->objType == DO_NAMESPACE && + strcmp(dobj->name, "public") == 0) + continue; + + /* Else it had better be of a type we think has ACLs */ + if (dobj->objType == DO_NAMESPACE || + dobj->objType == DO_TYPE || + dobj->objType == DO_FUNC || + dobj->objType == DO_AGG || + dobj->objType == DO_TABLE || + dobj->objType == DO_PROCLANG || + dobj->objType == DO_FDW || + dobj->objType == DO_FOREIGN_SERVER) + { + DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; + + daobj->dacl.privtype = privtype; + daobj->dacl.initprivs = pstrdup(initprivs); } + else + pg_log_warning("unsupported pg_init_privs entry: %u %u %d", + classoid, objoid, objsubid); } - PQclear(res); + } + PQclear(res); destroyPQExpBuffer(query); } @@ -11128,8 +11127,8 @@ dumpRelationStats_dumper(Archive *fout, const void *userArg, const TocEntry *te) * The results must be in the order of the relations supplied in the * parameters to ensure we remain in sync as we walk through the TOC. * - * For versions before 19, the redundant filter clause on s.tablename = - * ANY(...) seems sufficient to convince the planner to use + * For versions before 19, the redundant filter clause on s.tablename + * = ANY(...) seems sufficient to convince the planner to use * pg_class_relname_nsp_index, which avoids a full scan of pg_stats. * In newer versions, pg_stats returns the table OIDs, eliminating the * need for that hack. @@ -13469,11 +13468,11 @@ dumpFunc(Archive *fout, const FuncInfo *finfo) "pg_catalog.pg_get_function_result(p.oid) AS funcresult,\n" "proleakproof,\n"); - appendPQExpBufferStr(query, - "array_to_string(protrftypes, ' ') AS protrftypes,\n"); + appendPQExpBufferStr(query, + "array_to_string(protrftypes, ' ') AS protrftypes,\n"); - appendPQExpBufferStr(query, - "proparallel,\n"); + appendPQExpBufferStr(query, + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -14963,9 +14962,9 @@ dumpCollation(Archive *fout, const CollInfo *collinfo) /* Get collation-specific details */ appendPQExpBufferStr(query, "SELECT "); - appendPQExpBufferStr(query, - "collprovider, " - "collversion, "); + appendPQExpBufferStr(query, + "collprovider, " + "collversion, "); if (fout->remoteVersion >= 120000) appendPQExpBufferStr(query, @@ -15372,23 +15371,23 @@ dumpAgg(Archive *fout, const AggInfo *agginfo) "pg_catalog.pg_get_function_arguments(p.oid) AS funcargs,\n" "pg_catalog.pg_get_function_identity_arguments(p.oid) AS funciargs,\n"); - appendPQExpBufferStr(query, - "aggkind,\n" - "aggmtransfn,\n" - "aggminvtransfn,\n" - "aggmfinalfn,\n" - "aggmtranstype::pg_catalog.regtype,\n" - "aggfinalextra,\n" - "aggmfinalextra,\n" - "aggtransspace,\n" - "aggmtransspace,\n" - "aggminitval,\n"); + appendPQExpBufferStr(query, + "aggkind,\n" + "aggmtransfn,\n" + "aggminvtransfn,\n" + "aggmfinalfn,\n" + "aggmtranstype::pg_catalog.regtype,\n" + "aggfinalextra,\n" + "aggmfinalextra,\n" + "aggtransspace,\n" + "aggmtransspace,\n" + "aggminitval,\n"); - appendPQExpBufferStr(query, - "aggcombinefn,\n" - "aggserialfn,\n" - "aggdeserialfn,\n" - "proparallel,\n"); + appendPQExpBufferStr(query, + "aggcombinefn,\n" + "aggserialfn,\n" + "aggdeserialfn,\n" + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -16848,30 +16847,30 @@ dumpTable(Archive *fout, const TableInfo *tbinfo) appendPQExpBufferStr(query, "PREPARE getColumnACLs(pg_catalog.oid) AS\n"); - /* - * In principle we should call acldefault('c', relowner) to - * get the default ACL for a column. However, we don't - * currently store the numeric OID of the relowner in - * TableInfo. We could convert the owner name using regrole, - * but that creates a risk of failure due to concurrent role - * renames. Given that the default ACL for columns is empty - * and is likely to stay that way, it's not worth extra cycles - * and risk to avoid hard-wiring that knowledge here. - */ - appendPQExpBufferStr(query, - "SELECT at.attname, " - "at.attacl, " - "'{}' AS acldefault, " - "pip.privtype, pip.initprivs " - "FROM pg_catalog.pg_attribute at " - "LEFT JOIN pg_catalog.pg_init_privs pip ON " - "(at.attrelid = pip.objoid " - "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " - "AND at.attnum = pip.objsubid) " - "WHERE at.attrelid = $1 AND " - "NOT at.attisdropped " - "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " - "ORDER BY at.attnum"); + /* + * In principle we should call acldefault('c', relowner) to get + * the default ACL for a column. However, we don't currently + * store the numeric OID of the relowner in TableInfo. We could + * convert the owner name using regrole, but that creates a risk + * of failure due to concurrent role renames. Given that the + * default ACL for columns is empty and is likely to stay that + * way, it's not worth extra cycles and risk to avoid hard-wiring + * that knowledge here. + */ + appendPQExpBufferStr(query, + "SELECT at.attname, " + "at.attacl, " + "'{}' AS acldefault, " + "pip.privtype, pip.initprivs " + "FROM pg_catalog.pg_attribute at " + "LEFT JOIN pg_catalog.pg_init_privs pip ON " + "(at.attrelid = pip.objoid " + "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " + "AND at.attnum = pip.objsubid) " + "WHERE at.attrelid = $1 AND " + "NOT at.attisdropped " + "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " + "ORDER BY at.attnum"); ExecuteSqlStatement(fout, query->data); @@ -19165,7 +19164,7 @@ collectSequences(Archive *fout) * pg_get_sequence_data(), but we only do so for non-schema-only dumps. */ if (fout->remoteVersion < 180000 || - (!fout->dopt->dumpData && !fout->dopt->sequence_data)) + (!fout->dopt->dumpData && !fout->dopt->sequence_data)) query = "SELECT seqrelid, format_type(seqtypid, NULL), " "seqstart, seqincrement, " "seqmax, seqmin, " @@ -19227,15 +19226,14 @@ dumpSequence(Archive *fout, const TableInfo *tbinfo) qseqname = pg_strdup(fmtId(tbinfo->dobj.name)); /* - * The sequence information is gathered in a sorted - * table before any calls to dumpSequence(). See collectSequences() for - * more information. + * The sequence information is gathered in a sorted table before any calls + * to dumpSequence(). See collectSequences() for more information. */ - Assert(sequences); + Assert(sequences); - key.oid = tbinfo->dobj.catId.oid; - seq = bsearch(&key, sequences, nsequences, - sizeof(SequenceItem), SequenceItemCmp); + key.oid = tbinfo->dobj.catId.oid; + seq = bsearch(&key, sequences, nsequences, + sizeof(SequenceItem), SequenceItemCmp); /* Calculate default limits for a sequence of this type */ is_ascending = (seq->incby >= 0); diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c index e68937c9934..afcd9a218d8 100644 --- a/src/bin/pg_dump/pg_dumpall.c +++ b/src/bin/pg_dump/pg_dumpall.c @@ -785,11 +785,11 @@ dropRoles(PGconn *conn) int i_rolname; int i; - printfPQExpBuffer(buf, - "SELECT rolname " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 1", role_catalog); + printfPQExpBuffer(buf, + "SELECT rolname " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 1", role_catalog); res = executeQuery(conn, buf->data); @@ -843,16 +843,16 @@ dumpRoles(PGconn *conn) * Notes: rolconfig is dumped later, and pg_authid must be used for * extracting rolcomment regardless of role_catalog. */ - printfPQExpBuffer(buf, - "SELECT oid, rolname, rolsuper, rolinherit, " - "rolcreaterole, rolcreatedb, " - "rolcanlogin, rolconnlimit, rolpassword, " - "rolvaliduntil, rolreplication, rolbypassrls, " - "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " - "rolname = current_user AS is_current_user " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 2", role_catalog); + printfPQExpBuffer(buf, + "SELECT oid, rolname, rolsuper, rolinherit, " + "rolcreaterole, rolcreatedb, " + "rolcanlogin, rolconnlimit, rolpassword, " + "rolvaliduntil, rolreplication, rolbypassrls, " + "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " + "rolname = current_user AS is_current_user " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 2", role_catalog); res = executeQuery(conn, buf->data); diff --git a/src/bin/pg_upgrade/check.c b/src/bin/pg_upgrade/check.c index 786c1474829..f725f5ee3e2 100644 --- a/src/bin/pg_upgrade/check.c +++ b/src/bin/pg_upgrade/check.c @@ -1475,15 +1475,15 @@ check_for_incompatible_polymorphics(ClusterInfo *cluster) ", 'array_cat(anyarray,anyarray)'" ", 'array_prepend(anyelement,anyarray)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_remove(anyarray,anyelement)'" - ", 'array_replace(anyarray,anyelement,anyelement)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_remove(anyarray,anyelement)'" + ", 'array_replace(anyarray,anyelement,anyelement)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_position(anyarray,anyelement)'" - ", 'array_position(anyarray,anyelement,integer)'" - ", 'array_positions(anyarray,anyelement)'" - ", 'width_bucket(anyelement,anyarray)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_position(anyarray,anyelement)'" + ", 'array_position(anyarray,anyelement,integer)'" + ", 'array_positions(anyarray,anyelement)'" + ", 'width_bucket(anyelement,anyarray)'"); /* * The query below hardcodes FirstNormalObjectId as 16384 rather than diff --git a/src/bin/pg_upgrade/controldata.c b/src/bin/pg_upgrade/controldata.c index 8f81c9e9582..02ea02df60f 100644 --- a/src/bin/pg_upgrade/controldata.c +++ b/src/bin/pg_upgrade/controldata.c @@ -228,7 +228,7 @@ get_control_data(ClusterInfo *cluster) p++; /* remove ':' char */ cluster->controldata.chkpnt_nxtepoch = str2uint(p); - p = strchr(p, ':'); + p = strchr(p, ':'); if (p == NULL || strlen(p) <= 1) pg_fatal("%d: controldata retrieval problem", __LINE__); diff --git a/src/bin/pg_upgrade/exec.c b/src/bin/pg_upgrade/exec.c index 44355feea30..a1bdbf373e3 100644 --- a/src/bin/pg_upgrade/exec.c +++ b/src/bin/pg_upgrade/exec.c @@ -55,7 +55,7 @@ get_bin_version(ClusterInfo *cluster) if (sscanf(cmd_output, "%*s %*s %d.%d", &v1, &v2) < 1) pg_fatal("could not get pg_ctl version output from %s", cmd); - cluster->bin_version = v1 * 10000; + cluster->bin_version = v1 * 10000; } @@ -344,8 +344,8 @@ check_data_dir(ClusterInfo *cluster) check_single_dir(pg_data, "pg_subtrans"); check_single_dir(pg_data, PG_TBLSPC_DIR); check_single_dir(pg_data, "pg_twophase"); - check_single_dir(pg_data, "pg_wal"); - check_single_dir(pg_data, "pg_xact"); + check_single_dir(pg_data, "pg_wal"); + check_single_dir(pg_data, "pg_xact"); } @@ -385,7 +385,7 @@ check_bin_dir(ClusterInfo *cluster, bool check_versions) */ get_bin_version(cluster); - check_exec(cluster->bindir, "pg_resetwal", check_versions); + check_exec(cluster->bindir, "pg_resetwal", check_versions); if (cluster == &new_cluster) { diff --git a/src/bin/pg_upgrade/multixact_rewrite.c b/src/bin/pg_upgrade/multixact_rewrite.c index c45b3183684..c7a1416494d 100644 --- a/src/bin/pg_upgrade/multixact_rewrite.c +++ b/src/bin/pg_upgrade/multixact_rewrite.c @@ -61,52 +61,52 @@ rewrite_multixacts(MultiXactId from_multi, MultiXactId to_multi) * Convert old multixids, if needed, by reading them one-by-one from the * old cluster. */ - old_reader = AllocOldMultiXactRead(old_cluster.pgdata, - old_cluster.controldata.chkpnt_nxtmulti, - old_cluster.controldata.chkpnt_nxtmxoff); + old_reader = AllocOldMultiXactRead(old_cluster.pgdata, + old_cluster.controldata.chkpnt_nxtmulti, + old_cluster.controldata.chkpnt_nxtmxoff); - for (MultiXactId multi = from_multi; multi != to_multi;) - { - MultiXactMember member; - bool multixid_valid; - - /* - * Read this multixid's members. - * - * Locking-only XIDs that may be part of multi-xids don't matter - * after upgrade, as there can be no transactions running across - * upgrade. So as a small optimization, we only read one member - * from each multixid: the one updating one, or if there was no - * update, arbitrarily the first locking xid. - */ - multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); + for (MultiXactId multi = from_multi; multi != to_multi;) + { + MultiXactMember member; + bool multixid_valid; - /* - * Write the new offset to pg_multixact/offsets. - * - * Even if this multixid is invalid, we still need to write its - * offset if the *previous* multixid was valid. That's because - * when reading a multixid, the number of members is calculated - * from the difference between the two offsets. - */ - RecordMultiXactOffset(offsets_writer, multi, - (multixid_valid || prev_multixid_valid) ? next_offset : 0); + /* + * Read this multixid's members. + * + * Locking-only XIDs that may be part of multi-xids don't matter after + * upgrade, as there can be no transactions running across upgrade. So + * as a small optimization, we only read one member from each + * multixid: the one updating one, or if there was no update, + * arbitrarily the first locking xid. + */ + multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); - /* Write the members */ - if (multixid_valid) - { - RecordMultiXactMembers(members_writer, next_offset, 1, &member); - next_offset += 1; - } + /* + * Write the new offset to pg_multixact/offsets. + * + * Even if this multixid is invalid, we still need to write its offset + * if the *previous* multixid was valid. That's because when reading + * a multixid, the number of members is calculated from the difference + * between the two offsets. + */ + RecordMultiXactOffset(offsets_writer, multi, + (multixid_valid || prev_multixid_valid) ? next_offset : 0); - /* Advance to next multixid, handling wraparound */ - multi++; - if (multi < FirstMultiXactId) - multi = FirstMultiXactId; - prev_multixid_valid = multixid_valid; + /* Write the members */ + if (multixid_valid) + { + RecordMultiXactMembers(members_writer, next_offset, 1, &member); + next_offset += 1; } - FreeOldMultiXactReader(old_reader); + /* Advance to next multixid, handling wraparound */ + multi++; + if (multi < FirstMultiXactId) + multi = FirstMultiXactId; + prev_multixid_valid = multixid_valid; + } + + FreeOldMultiXactReader(old_reader); /* Write the final 'next' offset to the last SLRU page */ RecordMultiXactOffset(offsets_writer, to_multi, diff --git a/src/bin/pg_upgrade/pg_upgrade.c b/src/bin/pg_upgrade/pg_upgrade.c index c6af9035665..7366fd4627c 100644 --- a/src/bin/pg_upgrade/pg_upgrade.c +++ b/src/bin/pg_upgrade/pg_upgrade.c @@ -833,7 +833,7 @@ copy_xact_xlog_xid(void) * Determine the range of multixacts to convert. */ nxtmulti = old_cluster.controldata.chkpnt_nxtmulti; - oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; + oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; /* handle wraparound */ if (nxtmulti < FirstMultiXactId) nxtmulti = FirstMultiXactId; @@ -898,15 +898,15 @@ set_frozenxids(void) int i_datname; int i_datallowconn; - prep_status("Setting frozenxid and minmxid counters in new cluster"); + prep_status("Setting frozenxid and minmxid counters in new cluster"); conn_template1 = connectToServer(&new_cluster, "template1"); - /* set pg_database.datfrozenxid */ - PQclear(executeQueryOrDie(conn_template1, - "UPDATE pg_catalog.pg_database " - "SET datfrozenxid = '%u'", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_database.datfrozenxid */ + PQclear(executeQueryOrDie(conn_template1, + "UPDATE pg_catalog.pg_database " + "SET datfrozenxid = '%u'", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_database.datminmxid */ PQclear(executeQueryOrDie(conn_template1, @@ -942,16 +942,16 @@ set_frozenxids(void) conn = connectToServer(&new_cluster, datname); - /* set pg_class.relfrozenxid */ - PQclear(executeQueryOrDie(conn, - "UPDATE pg_catalog.pg_class " - "SET relfrozenxid = '%u' " - /* only heap, materialized view, and TOAST are vacuumed */ - "WHERE relkind IN (" - CppAsString2(RELKIND_RELATION) ", " - CppAsString2(RELKIND_MATVIEW) ", " - CppAsString2(RELKIND_TOASTVALUE) ")", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_class.relfrozenxid */ + PQclear(executeQueryOrDie(conn, + "UPDATE pg_catalog.pg_class " + "SET relfrozenxid = '%u' " + /* only heap, materialized view, and TOAST are vacuumed */ + "WHERE relkind IN (" + CppAsString2(RELKIND_RELATION) ", " + CppAsString2(RELKIND_MATVIEW) ", " + CppAsString2(RELKIND_TOASTVALUE) ")", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_class.relminmxid */ PQclear(executeQueryOrDie(conn, diff --git a/src/bin/pg_upgrade/relfilenumber.c b/src/bin/pg_upgrade/relfilenumber.c index ec2ff7acb21..6c467bdc8a5 100644 --- a/src/bin/pg_upgrade/relfilenumber.c +++ b/src/bin/pg_upgrade/relfilenumber.c @@ -587,32 +587,32 @@ transfer_relfile(FileNameMap *map, const char *type_suffix) /* Copying files might take some time, so give feedback. */ pg_log(PG_STATUS, "%s", old_file); - switch (user_opts.transfer_mode) - { - case TRANSFER_MODE_CLONE: - pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", - old_file, new_file); - cloneFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", - old_file, new_file); - copyFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY_FILE_RANGE: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", - old_file, new_file); - copyFileByRange(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_LINK: - pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", - old_file, new_file); - linkFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_SWAP: - /* swap mode is handled in its own code path */ - pg_fatal("should never happen"); - break; - } + switch (user_opts.transfer_mode) + { + case TRANSFER_MODE_CLONE: + pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", + old_file, new_file); + cloneFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", + old_file, new_file); + copyFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY_FILE_RANGE: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", + old_file, new_file); + copyFileByRange(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_LINK: + pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", + old_file, new_file); + linkFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_SWAP: + /* swap mode is handled in its own code path */ + pg_fatal("should never happen"); + break; + } } } diff --git a/src/bin/pg_upgrade/t/006_transfer_modes.pl b/src/bin/pg_upgrade/t/006_transfer_modes.pl index 9efa5dc863c..360d05c4b68 100644 --- a/src/bin/pg_upgrade/t/006_transfer_modes.pl +++ b/src/bin/pg_upgrade/t/006_transfer_modes.pl @@ -29,10 +29,8 @@ sub test_mode } $new->init(); - $new->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); - $old->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); + $new->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); + $old->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); # We can only test security labels if both the old and new installations # have dummy_seclabel. @@ -76,15 +74,14 @@ sub test_mode "CREATE TABLE test4 AS SELECT generate_series(400, 502)"); } - $old->safe_psql('postgres', - "CREATE TABLESPACE inplc_tblspc LOCATION ''"); - $old->safe_psql('postgres', - "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); - $old->safe_psql('postgres', - "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" - ); - $old->safe_psql('testdb3', - "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); + $old->safe_psql('postgres', "CREATE TABLESPACE inplc_tblspc LOCATION ''"); + $old->safe_psql('postgres', + "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); + $old->safe_psql('postgres', + "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" + ); + $old->safe_psql('testdb3', + "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); # While we are here, test handling of large objects. $old->safe_psql( @@ -152,12 +149,10 @@ sub test_mode } # Tests for in-place tablespaces. - $result = - $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); - is($result, '104', "test5 data after pg_upgrade $mode"); - $result = - $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); - is($result, '105', "test6 data after pg_upgrade $mode"); + $result = $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); + is($result, '104', "test5 data after pg_upgrade $mode"); + $result = $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); + is($result, '105', "test6 data after pg_upgrade $mode"); # Tests for large objects $result = $new->safe_psql('postgres', "SELECT lo_get(4532)"); diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index 44ef11d980e..c90bf8bbde2 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -6278,23 +6278,22 @@ get_create_object_cmd(EditableObjectType obj_type, Oid oid, * ensure the right view gets replaced. Also, check relation kind * to be sure it's a view. * - * Views may have WITH [LOCAL|CASCADED] - * CHECK OPTION. These are not part of the view definition - * returned by pg_get_viewdef() and so need to be retrieved - * separately. Materialized views may have - * arbitrary storage parameter reloptions. + * Views may have WITH [LOCAL|CASCADED] CHECK OPTION. These are + * not part of the view definition returned by pg_get_viewdef() + * and so need to be retrieved separately. Materialized views may + * have arbitrary storage parameter reloptions. */ printfPQExpBuffer(query, "/* %s */\n", _("Get view's definition and details")); - appendPQExpBuffer(query, - "SELECT nspname, relname, relkind, " - "pg_catalog.pg_get_viewdef(c.oid, true), " - "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " - "FROM pg_catalog.pg_class c " - "LEFT JOIN pg_catalog.pg_namespace n " - "ON c.relnamespace = n.oid WHERE c.oid = %u", - oid); + appendPQExpBuffer(query, + "SELECT nspname, relname, relkind, " + "pg_catalog.pg_get_viewdef(c.oid, true), " + "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " + "FROM pg_catalog.pg_class c " + "LEFT JOIN pg_catalog.pg_namespace n " + "ON c.relnamespace = n.oid WHERE c.oid = %u", + oid); break; } diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index ce99137c613..ac0c55e7aa5 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -387,19 +387,19 @@ describeFunctions(const char *functypes, const char *func_pattern, gettext_noop("stable"), gettext_noop("volatile"), gettext_noop("Volatility")); - appendPQExpBuffer(&buf, - ",\n CASE\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" - " END as \"%s\"", - gettext_noop("restricted"), - gettext_noop("safe"), - gettext_noop("unsafe"), - gettext_noop("Parallel")); + appendPQExpBuffer(&buf, + ",\n CASE\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" + " END as \"%s\"", + gettext_noop("restricted"), + gettext_noop("safe"), + gettext_noop("unsafe"), + gettext_noop("Parallel")); appendPQExpBuffer(&buf, ",\n pg_catalog.pg_get_userbyid(p.proowner) as \"%s\"" ",\n CASE WHEN prosecdef THEN '%s' ELSE '%s' END AS \"%s\"" @@ -599,8 +599,8 @@ describeFunctions(const char *functypes, const char *func_pattern, myopt.title = _("List of functions"); myopt.translate_header = true; - myopt.translate_columns = translate_columns; - myopt.n_translate_columns = lengthof(translate_columns); + myopt.translate_columns = translate_columns; + myopt.n_translate_columns = lengthof(translate_columns); printQuery(res, &myopt, pset.queryFout, false, pset.logfile); @@ -1086,38 +1086,38 @@ permissionsList(const char *pattern, bool showSystem) " ), E'\\n') AS \"%s\"", gettext_noop("Column privileges")); - appendPQExpBuffer(&buf, - ",\n pg_catalog.array_to_string(ARRAY(\n" - " SELECT polname\n" - " || CASE WHEN NOT polpermissive THEN\n" - " E' (RESTRICTIVE)'\n" - " ELSE '' END\n" - " || CASE WHEN polcmd != '*' THEN\n" - " E' (' || polcmd::pg_catalog.text || E'):'\n" - " ELSE E':'\n" - " END\n" - " || CASE WHEN polqual IS NOT NULL THEN\n" - " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" - " ELSE E''\n" - " END\n" - " || CASE WHEN polwithcheck IS NOT NULL THEN\n" - " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" - " ELSE E''\n" - " END" - " || CASE WHEN polroles <> '{0}' THEN\n" - " E'\\n to: ' || pg_catalog.array_to_string(\n" - " ARRAY(\n" - " SELECT rolname\n" - " FROM pg_catalog.pg_roles\n" - " WHERE oid = ANY (polroles)\n" - " ORDER BY 1\n" - " ), E', ')\n" - " ELSE E''\n" - " END\n" - " FROM pg_catalog.pg_policy pol\n" - " WHERE polrelid = c.oid), E'\\n')\n" - " AS \"%s\"", - gettext_noop("Policies")); + appendPQExpBuffer(&buf, + ",\n pg_catalog.array_to_string(ARRAY(\n" + " SELECT polname\n" + " || CASE WHEN NOT polpermissive THEN\n" + " E' (RESTRICTIVE)'\n" + " ELSE '' END\n" + " || CASE WHEN polcmd != '*' THEN\n" + " E' (' || polcmd::pg_catalog.text || E'):'\n" + " ELSE E':'\n" + " END\n" + " || CASE WHEN polqual IS NOT NULL THEN\n" + " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" + " ELSE E''\n" + " END\n" + " || CASE WHEN polwithcheck IS NOT NULL THEN\n" + " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" + " ELSE E''\n" + " END" + " || CASE WHEN polroles <> '{0}' THEN\n" + " E'\\n to: ' || pg_catalog.array_to_string(\n" + " ARRAY(\n" + " SELECT rolname\n" + " FROM pg_catalog.pg_roles\n" + " WHERE oid = ANY (polroles)\n" + " ORDER BY 1\n" + " ), E', ')\n" + " ELSE E''\n" + " END\n" + " FROM pg_catalog.pg_policy pol\n" + " WHERE polrelid = c.oid), E'\\n')\n" + " AS \"%s\"", + gettext_noop("Policies")); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_class c\n" " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n" @@ -1675,27 +1675,27 @@ describeOneTableDetails(const char *schemaname, char *footers[3] = {NULL, NULL, NULL}; printfPQExpBuffer(&buf, "/* %s */\n", _("Get sequence information")); - appendPQExpBuffer(&buf, - "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" - " seqstart AS \"%s\",\n" - " seqmin AS \"%s\",\n" - " seqmax AS \"%s\",\n" - " seqincrement AS \"%s\",\n" - " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" - " seqcache AS \"%s\"\n", - gettext_noop("Type"), - gettext_noop("Start"), - gettext_noop("Minimum"), - gettext_noop("Maximum"), - gettext_noop("Increment"), - gettext_noop("yes"), - gettext_noop("no"), - gettext_noop("Cycles?"), - gettext_noop("Cache")); - appendPQExpBuffer(&buf, - "FROM pg_catalog.pg_sequence\n" - "WHERE seqrelid = '%s';", - oid); + appendPQExpBuffer(&buf, + "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" + " seqstart AS \"%s\",\n" + " seqmin AS \"%s\",\n" + " seqmax AS \"%s\",\n" + " seqincrement AS \"%s\",\n" + " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" + " seqcache AS \"%s\"\n", + gettext_noop("Type"), + gettext_noop("Start"), + gettext_noop("Minimum"), + gettext_noop("Maximum"), + gettext_noop("Increment"), + gettext_noop("yes"), + gettext_noop("no"), + gettext_noop("Cycles?"), + gettext_noop("Cache")); + appendPQExpBuffer(&buf, + "FROM pg_catalog.pg_sequence\n" + "WHERE seqrelid = '%s';", + oid); res = PSQLexec(buf.data); if (!res) @@ -1913,7 +1913,7 @@ describeOneTableDetails(const char *schemaname, appendPQExpBufferStr(&buf, ",\n (SELECT c.collname FROM pg_catalog.pg_collation c, pg_catalog.pg_type t\n" " WHERE c.oid = a.attcollation AND t.oid = a.atttypid AND a.attcollation <> t.typcollation) AS attcollation"); attcoll_col = cols++; - appendPQExpBufferStr(&buf, ",\n a.attidentity"); + appendPQExpBufferStr(&buf, ",\n a.attidentity"); attidentity_col = cols++; if (pset.sversion >= 120000) appendPQExpBufferStr(&buf, ",\n a.attgenerated"); @@ -2326,7 +2326,7 @@ describeOneTableDetails(const char *schemaname, CppAsString2(CONSTRAINT_EXCLUSION) ") AND " "condeferred) AS condeferred,\n"); - appendPQExpBufferStr(&buf, "i.indisreplident,\n"); + appendPQExpBufferStr(&buf, "i.indisreplident,\n"); if (pset.sversion >= 150000) appendPQExpBufferStr(&buf, "i.indnullsnotdistinct,\n"); @@ -2431,7 +2431,7 @@ describeOneTableDetails(const char *schemaname, "pg_catalog.pg_get_indexdef(i.indexrelid, 0, true),\n " "pg_catalog.pg_get_constraintdef(con.oid, true), " "contype, condeferrable, condeferred"); - appendPQExpBufferStr(&buf, ", i.indisreplident"); + appendPQExpBufferStr(&buf, ", i.indisreplident"); appendPQExpBufferStr(&buf, ", c2.reltablespace"); if (pset.sversion >= 180000) appendPQExpBufferStr(&buf, ", con.conperiod"); @@ -2682,81 +2682,80 @@ describeOneTableDetails(const char *schemaname, PQclear(result); /* print any row-level policies */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get row-level policies for this table")); - appendPQExpBufferStr(&buf, "SELECT pol.polname,"); - appendPQExpBufferStr(&buf, - " pol.polpermissive,\n"); - appendPQExpBuffer(&buf, - " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" - " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" - " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" - " CASE pol.polcmd\n" - " WHEN 'r' THEN 'SELECT'\n" - " WHEN 'a' THEN 'INSERT'\n" - " WHEN 'w' THEN 'UPDATE'\n" - " WHEN 'd' THEN 'DELETE'\n" - " END AS cmd\n" - "FROM pg_catalog.pg_policy pol\n" - "WHERE pol.polrelid = '%s' ORDER BY 1;", - oid); + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get row-level policies for this table")); + appendPQExpBufferStr(&buf, "SELECT pol.polname,"); + appendPQExpBufferStr(&buf, + " pol.polpermissive,\n"); + appendPQExpBuffer(&buf, + " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" + " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" + " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" + " CASE pol.polcmd\n" + " WHEN 'r' THEN 'SELECT'\n" + " WHEN 'a' THEN 'INSERT'\n" + " WHEN 'w' THEN 'UPDATE'\n" + " WHEN 'd' THEN 'DELETE'\n" + " END AS cmd\n" + "FROM pg_catalog.pg_policy pol\n" + "WHERE pol.polrelid = '%s' ORDER BY 1;", + oid); - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - /* - * Handle cases where RLS is enabled and there are policies, or - * there aren't policies, or RLS isn't enabled but there are - * policies - */ - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies:")); + /* + * Handle cases where RLS is enabled and there are policies, or there + * aren't policies, or RLS isn't enabled but there are policies + */ + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies:")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled):")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled):")); - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); - if (!tableinfo.rowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (row security disabled):")); + if (!tableinfo.rowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (row security disabled):")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " POLICY \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " POLICY \"%s\"", + PQgetvalue(result, i, 0)); - if (*(PQgetvalue(result, i, 1)) == 'f') - appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); + if (*(PQgetvalue(result, i, 1)) == 'f') + appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); - if (!PQgetisnull(result, i, 5)) - appendPQExpBuffer(&buf, " FOR %s", - PQgetvalue(result, i, 5)); + if (!PQgetisnull(result, i, 5)) + appendPQExpBuffer(&buf, " FOR %s", + PQgetvalue(result, i, 5)); - if (!PQgetisnull(result, i, 2)) - { - appendPQExpBuffer(&buf, "\n TO %s", - PQgetvalue(result, i, 2)); - } + if (!PQgetisnull(result, i, 2)) + { + appendPQExpBuffer(&buf, "\n TO %s", + PQgetvalue(result, i, 2)); + } - if (!PQgetisnull(result, i, 3)) - appendPQExpBuffer(&buf, "\n USING (%s)", - PQgetvalue(result, i, 3)); + if (!PQgetisnull(result, i, 3)) + appendPQExpBuffer(&buf, "\n USING (%s)", + PQgetvalue(result, i, 3)); - if (!PQgetisnull(result, i, 4)) - appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", - PQgetvalue(result, i, 4)); + if (!PQgetisnull(result, i, 4)) + appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", + PQgetvalue(result, i, 4)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* print any extended statistics */ if (pset.sversion >= 140000) @@ -3025,115 +3024,115 @@ describeOneTableDetails(const char *schemaname, } /* print any publications */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get publications that publish this table")); - if (pset.sversion >= 150000) + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get publications that publish this table")); + if (pset.sversion >= 150000) + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" + " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" + "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" + "UNION\n" + "SELECT pubname\n" + " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" + " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" + " (SELECT pg_catalog.string_agg(attname, ', ')\n" + " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" + " pg_catalog.pg_attribute\n" + " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" + " ELSE NULL END) " + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" + "WHERE pr.prrelid = '%s'\n", + oid, oid, oid); + + if (pset.sversion >= 190000) { + /* + * Skip entries where this relation appears in the + * publication's EXCEPT list. + */ appendPQExpBuffer(&buf, + " AND NOT pr.prexcept\n" + "UNION\n" "SELECT pubname\n" " , NULL\n" " , NULL\n" "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" - " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" - "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" - "UNION\n" - "SELECT pubname\n" - " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" - " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" - " (SELECT pg_catalog.string_agg(attname, ', ')\n" - " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" - " pg_catalog.pg_attribute\n" - " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" - " ELSE NULL END) " - "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" - "WHERE pr.prrelid = '%s'\n", + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + " AND NOT EXISTS (\n" + " SELECT 1\n" + " FROM pg_catalog.pg_publication_rel pr\n" + " WHERE pr.prpubid = p.oid AND\n" + " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" + "ORDER BY 1;", oid, oid, oid); - - if (pset.sversion >= 190000) - { - /* - * Skip entries where this relation appears in the - * publication's EXCEPT list. - */ - appendPQExpBuffer(&buf, - " AND NOT pr.prexcept\n" - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - " AND NOT EXISTS (\n" - " SELECT 1\n" - " FROM pg_catalog.pg_publication_rel pr\n" - " WHERE pr.prpubid = p.oid AND\n" - " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" - "ORDER BY 1;", - oid, oid, oid); - } - else - { - appendPQExpBuffer(&buf, - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - "ORDER BY 1;", - oid); - } } else { appendPQExpBuffer(&buf, + "UNION\n" "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - "WHERE pr.prrelid = '%s'\n" - "UNION ALL\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" + " , NULL\n" + " , NULL\n" "FROM pg_catalog.pg_publication p\n" "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" "ORDER BY 1;", - oid, oid); + oid); } + } + else + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + "WHERE pr.prrelid = '%s'\n" + "UNION ALL\n" + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + "ORDER BY 1;", + oid, oid); + } - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - if (tuples > 0) - printTableAddFooter(&cont, _("Included in publications:")); + if (tuples > 0) + printTableAddFooter(&cont, _("Included in publications:")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " \"%s\"", + PQgetvalue(result, i, 0)); - /* column list (if any) */ - if (!PQgetisnull(result, i, 2)) - appendPQExpBuffer(&buf, " (%s)", - PQgetvalue(result, i, 2)); + /* column list (if any) */ + if (!PQgetisnull(result, i, 2)) + appendPQExpBuffer(&buf, " (%s)", + PQgetvalue(result, i, 2)); - /* row filter (if any) */ - if (!PQgetisnull(result, i, 1)) - appendPQExpBuffer(&buf, " WHERE %s", - PQgetvalue(result, i, 1)); + /* row filter (if any) */ + if (!PQgetisnull(result, i, 1)) + appendPQExpBuffer(&buf, " WHERE %s", + PQgetvalue(result, i, 1)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* Print publications where the table is in the EXCEPT clause */ if (pset.sversion >= 190000) @@ -3805,7 +3804,7 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) ncols++; } appendPQExpBufferStr(&buf, "\n, r.rolreplication"); - appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); + appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_roles r\n"); @@ -3860,8 +3859,8 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) if (strcmp(PQgetvalue(res, i, (verbose ? 9 : 8)), "t") == 0) add_role_attribute(&buf, _("Replication")); - if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) - add_role_attribute(&buf, _("Bypass RLS")); + if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) + add_role_attribute(&buf, _("Bypass RLS")); conns = atoi(PQgetvalue(res, i, 6)); if (conns >= 0) @@ -5155,14 +5154,14 @@ listCollations(const char *pattern, bool verbose, bool showSystem) gettext_noop("Schema"), gettext_noop("Name")); - appendPQExpBuffer(&buf, - " CASE c.collprovider " - "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " - "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " - "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " - "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " - "END AS \"%s\",\n", - gettext_noop("Provider")); + appendPQExpBuffer(&buf, + " CASE c.collprovider " + "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " + "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " + "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " + "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " + "END AS \"%s\",\n", + gettext_noop("Provider")); appendPQExpBuffer(&buf, " c.collcollate AS \"%s\",\n" -- 2.50.1 (Apple Git-155) --aHl3HfeiUuO3zeNC-- ^ permalink raw reply [nested|flat] 59+ messages in thread
* [PATCH v6 4/4] run pgindent and pgperltidy @ 2026-06-30 18:24 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 59+ messages in thread From: Nathan Bossart @ 2026-06-30 18:24 UTC (permalink / raw) --- src/bin/pg_dump/pg_dump.c | 464 ++++++++++----------- src/bin/pg_dump/pg_dumpall.c | 30 +- src/bin/pg_upgrade/check.c | 16 +- src/bin/pg_upgrade/controldata.c | 2 +- src/bin/pg_upgrade/exec.c | 8 +- src/bin/pg_upgrade/multixact_rewrite.c | 80 ++-- src/bin/pg_upgrade/pg_upgrade.c | 34 +- src/bin/pg_upgrade/relfilenumber.c | 54 +-- src/bin/pg_upgrade/t/006_transfer_modes.pl | 33 +- src/bin/psql/command.c | 29 +- src/bin/psql/describe.c | 461 ++++++++++---------- 11 files changed, 601 insertions(+), 610 deletions(-) diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 65bd15ebfd2..5673268b467 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -1491,8 +1491,8 @@ setup_connection(Archive *AH, const char *dumpencoding, * Disable timeouts if supported. */ ExecuteSqlStatement(AH, "SET statement_timeout = 0"); - ExecuteSqlStatement(AH, "SET lock_timeout = 0"); - ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); + ExecuteSqlStatement(AH, "SET lock_timeout = 0"); + ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); if (AH->remoteVersion >= 170000) ExecuteSqlStatement(AH, "SET transaction_timeout = 0"); @@ -1505,10 +1505,10 @@ setup_connection(Archive *AH, const char *dumpencoding, /* * Adjust row-security mode, if supported. */ - if (dopt->enable_row_security) - ExecuteSqlStatement(AH, "SET row_security = on"); - else - ExecuteSqlStatement(AH, "SET row_security = off"); + if (dopt->enable_row_security) + ExecuteSqlStatement(AH, "SET row_security = on"); + else + ExecuteSqlStatement(AH, "SET row_security = off"); /* * For security reasons, we restrict the expansion of non-system views and @@ -1933,10 +1933,9 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) addObjectDependency(dobj, ext->dobj.dumpId); /* - * Mark the member object to have any non-initial ACLs - * dumped. (Any initial ACLs will be removed later, using data from - * pg_init_privs, so that we'll dump only the delta from the extension's - * initial setup.) + * Mark the member object to have any non-initial ACLs dumped. (Any + * initial ACLs will be removed later, using data from pg_init_privs, so + * that we'll dump only the delta from the extension's initial setup.) * * In binary upgrades, we still dump all components of the members * individually, since the idea is to exactly reproduce the database @@ -1953,7 +1952,7 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) if (fout->dopt->binary_upgrade) dobj->dump = ext->dobj.dump; else - dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); + dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); return true; } @@ -1987,9 +1986,9 @@ selectDumpableNamespace(NamespaceInfo *nsinfo, Archive *fout) else if (strcmp(nsinfo->dobj.name, "pg_catalog") == 0) { /* - * We dump out any ACLs defined in pg_catalog, if - * they are interesting (and not the original ACLs which were set at - * initdb time, see pg_init_privs). + * We dump out any ACLs defined in pg_catalog, if they are interesting + * (and not the original ACLs which were set at initdb time, see + * pg_init_privs). */ nsinfo->dobj.dump_contains = nsinfo->dobj.dump = DUMP_COMPONENT_ACL; } @@ -3296,7 +3295,7 @@ dumpDatabase(Archive *fout) "datcollate, datctype, datfrozenxid, " "datacl, acldefault('d', datdba) AS acldefault, " "datistemplate, datconnlimit, "); - appendPQExpBufferStr(dbQry, "datminmxid, "); + appendPQExpBufferStr(dbQry, "datminmxid, "); if (fout->remoteVersion >= 170000) appendPQExpBufferStr(dbQry, "datlocprovider, datlocale, datcollversion, "); else if (fout->remoteVersion >= 150000) @@ -3638,11 +3637,11 @@ dumpDatabase(Archive *fout) ii_oid, ii_relminmxid; - appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" - "FROM pg_catalog.pg_class\n" - "WHERE oid IN (%u, %u, %u, %u);\n", - LargeObjectRelationId, LargeObjectLOidPNIndexId, - LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); + appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" + "FROM pg_catalog.pg_class\n" + "WHERE oid IN (%u, %u, %u, %u);\n", + LargeObjectRelationId, LargeObjectLOidPNIndexId, + LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); lo_res = ExecuteSqlQuery(fout, loFrozenQry->data, PGRES_TUPLES_OK); @@ -4274,7 +4273,7 @@ getPolicies(Archive *fout, TableInfo tblinfo[], int numTables) printfPQExpBuffer(query, "SELECT pol.oid, pol.tableoid, pol.polrelid, pol.polname, pol.polcmd, "); - appendPQExpBufferStr(query, "pol.polpermissive, "); + appendPQExpBufferStr(query, "pol.polpermissive, "); appendPQExpBuffer(query, "CASE WHEN pol.polroles = '{0}' THEN NULL ELSE " " pg_catalog.array_to_string(ARRAY(SELECT pg_catalog.quote_ident(rolname) from pg_catalog.pg_roles WHERE oid = ANY(pol.polroles)), ', ') END AS polroles, " @@ -6633,9 +6632,9 @@ getAccessMethods(Archive *fout) * Select all access methods from pg_am table. */ appendPQExpBufferStr(query, "SELECT tableoid, oid, amname, "); - appendPQExpBufferStr(query, - "amtype, " - "amhandler::pg_catalog.regproc AS amhandler "); + appendPQExpBufferStr(query, + "amtype, " + "amhandler::pg_catalog.regproc AS amhandler "); appendPQExpBufferStr(query, "FROM pg_am"); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6827,35 +6826,35 @@ getAggregates(Archive *fout) * Find all interesting aggregates. See comment in getFuncs() for the * rationale behind the filtering logic. */ - agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" - : "p.proisagg"); + agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" + : "p.proisagg"); - appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " - "p.proname AS aggname, " - "p.pronamespace AS aggnamespace, " - "p.pronargs, p.proargtypes, " - "p.proowner, " - "p.proacl AS aggacl, " - "acldefault('f', p.proowner) AS acldefault " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s AND (" - "p.pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog') OR " - "p.proacl IS DISTINCT FROM pip.initprivs", - agg_check); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - " OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); - appendPQExpBufferChar(query, ')'); + appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " + "p.proname AS aggname, " + "p.pronamespace AS aggnamespace, " + "p.pronargs, p.proargtypes, " + "p.proowner, " + "p.proacl AS aggacl, " + "acldefault('f', p.proowner) AS acldefault " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s AND (" + "p.pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog') OR " + "p.proacl IS DISTINCT FROM pip.initprivs", + agg_check); + if (dopt->binary_upgrade) + appendPQExpBufferStr(query, + " OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6957,53 +6956,53 @@ getFuncs(Archive *fout) * include them, since we want to dump extension members individually in * that mode. Also, if they are used by casts or transforms then we need * to gather the information about them, though they won't be dumped if - * they are built-in. Also, include functions in - * pg_catalog if they have an ACL different from what's shown in - * pg_init_privs (so we have to join to pg_init_privs; annoying). + * they are built-in. Also, include functions in pg_catalog if they have + * an ACL different from what's shown in pg_init_privs (so we have to join + * to pg_init_privs; annoying). */ - not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" - : "NOT p.proisagg"); + not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" + : "NOT p.proisagg"); - appendPQExpBuffer(query, - "SELECT p.tableoid, p.oid, p.proname, p.prolang, " - "p.pronargs, p.proargtypes, p.prorettype, " - "p.proacl, " - "acldefault('f', p.proowner) AS acldefault, " - "p.pronamespace, " - "p.proowner " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s" - "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " - "WHERE classid = 'pg_proc'::regclass AND " - "objid = p.oid AND deptype = 'i')" - "\n AND (" - "\n pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog')" - "\n OR EXISTS (SELECT 1 FROM pg_cast" - "\n WHERE pg_cast.oid > %u " - "\n AND p.oid = pg_cast.castfunc)" - "\n OR EXISTS (SELECT 1 FROM pg_transform" - "\n WHERE pg_transform.oid > %u AND " - "\n (p.oid = pg_transform.trffromsql" - "\n OR p.oid = pg_transform.trftosql))", - not_agg_check, - g_last_builtin_oid, - g_last_builtin_oid); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); + appendPQExpBuffer(query, + "SELECT p.tableoid, p.oid, p.proname, p.prolang, " + "p.pronargs, p.proargtypes, p.prorettype, " + "p.proacl, " + "acldefault('f', p.proowner) AS acldefault, " + "p.pronamespace, " + "p.proowner " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s" + "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " + "WHERE classid = 'pg_proc'::regclass AND " + "objid = p.oid AND deptype = 'i')" + "\n AND (" + "\n pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog')" + "\n OR EXISTS (SELECT 1 FROM pg_cast" + "\n WHERE pg_cast.oid > %u " + "\n AND p.oid = pg_cast.castfunc)" + "\n OR EXISTS (SELECT 1 FROM pg_transform" + "\n WHERE pg_transform.oid > %u AND " + "\n (p.oid = pg_transform.trffromsql" + "\n OR p.oid = pg_transform.trftosql))", + not_agg_check, + g_last_builtin_oid, + g_last_builtin_oid); + if (dopt->binary_upgrade) appendPQExpBufferStr(query, - "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); - appendPQExpBufferChar(query, ')'); + "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferStr(query, + "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -7252,31 +7251,31 @@ getTables(Archive *fout, int *numTables) appendPQExpBufferStr(query, "c.relhasoids, "); - appendPQExpBufferStr(query, - "c.relispopulated, "); + appendPQExpBufferStr(query, + "c.relispopulated, "); - appendPQExpBufferStr(query, - "c.relreplident, "); + appendPQExpBufferStr(query, + "c.relreplident, "); - appendPQExpBufferStr(query, - "c.relrowsecurity, c.relforcerowsecurity, "); + appendPQExpBufferStr(query, + "c.relrowsecurity, c.relforcerowsecurity, "); - appendPQExpBufferStr(query, - "c.relminmxid, tc.relminmxid AS tminmxid, "); + appendPQExpBufferStr(query, + "c.relminmxid, tc.relminmxid AS tminmxid, "); - appendPQExpBufferStr(query, - "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); + appendPQExpBufferStr(query, + "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); - appendPQExpBufferStr(query, - "am.amname, "); + appendPQExpBufferStr(query, + "am.amname, "); - appendPQExpBufferStr(query, - "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); + appendPQExpBufferStr(query, + "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); - appendPQExpBufferStr(query, - "c.relispartition AS ispartition "); + appendPQExpBufferStr(query, + "c.relispartition AS ispartition "); /* * Left join to pg_depend to pick up dependency info linking sequences to @@ -7296,8 +7295,8 @@ getTables(Archive *fout, int *numTables) /* * Left join to pg_am to pick up the amname. */ - appendPQExpBufferStr(query, - "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); + appendPQExpBufferStr(query, + "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); /* * We purposefully ignore toast OIDs for partitioned tables; the reason is @@ -7868,8 +7867,8 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables) "t.reloptions AS indreloptions, "); - appendPQExpBufferStr(query, - "i.indisreplident, "); + appendPQExpBufferStr(query, + "i.indisreplident, "); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -9313,8 +9312,8 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables) appendPQExpBufferStr(q, "'' AS attcompression,\n"); - appendPQExpBufferStr(q, - "a.attidentity,\n"); + appendPQExpBufferStr(q, + "a.attidentity,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(q, @@ -10717,73 +10716,73 @@ getAdditionalACLs(Archive *fout) PQclear(res); /* Fetch initial-privileges data */ - printfPQExpBuffer(query, - "SELECT objoid, classoid, objsubid, privtype, initprivs " - "FROM pg_init_privs"); + printfPQExpBuffer(query, + "SELECT objoid, classoid, objsubid, privtype, initprivs " + "FROM pg_init_privs"); - res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); + res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); - ntups = PQntuples(res); - for (i = 0; i < ntups; i++) - { - Oid objoid = atooid(PQgetvalue(res, i, 0)); - Oid classoid = atooid(PQgetvalue(res, i, 1)); - int objsubid = atoi(PQgetvalue(res, i, 2)); - char privtype = *(PQgetvalue(res, i, 3)); - char *initprivs = PQgetvalue(res, i, 4); - CatalogId objId; - DumpableObject *dobj; + ntups = PQntuples(res); + for (i = 0; i < ntups; i++) + { + Oid objoid = atooid(PQgetvalue(res, i, 0)); + Oid classoid = atooid(PQgetvalue(res, i, 1)); + int objsubid = atoi(PQgetvalue(res, i, 2)); + char privtype = *(PQgetvalue(res, i, 3)); + char *initprivs = PQgetvalue(res, i, 4); + CatalogId objId; + DumpableObject *dobj; - objId.tableoid = classoid; - objId.oid = objoid; - dobj = findObjectByCatalogId(objId); - /* OK to ignore entries we haven't got a DumpableObject for */ - if (dobj) + objId.tableoid = classoid; + objId.oid = objoid; + dobj = findObjectByCatalogId(objId); + /* OK to ignore entries we haven't got a DumpableObject for */ + if (dobj) + { + /* Cope with sub-object initprivs */ + if (objsubid != 0) { - /* Cope with sub-object initprivs */ - if (objsubid != 0) - { - if (dobj->objType == DO_TABLE) - { - /* For a column initprivs, set the table's ACL flags */ - dobj->components |= DUMP_COMPONENT_ACL; - ((TableInfo *) dobj)->hascolumnACLs = true; - } - else - pg_log_warning("unsupported pg_init_privs entry: %u %u %d", - classoid, objoid, objsubid); - continue; - } - - /* - * We ignore any pg_init_privs.initprivs entry for the public - * schema, as explained in getNamespaces(). - */ - if (dobj->objType == DO_NAMESPACE && - strcmp(dobj->name, "public") == 0) - continue; - - /* Else it had better be of a type we think has ACLs */ - if (dobj->objType == DO_NAMESPACE || - dobj->objType == DO_TYPE || - dobj->objType == DO_FUNC || - dobj->objType == DO_AGG || - dobj->objType == DO_TABLE || - dobj->objType == DO_PROCLANG || - dobj->objType == DO_FDW || - dobj->objType == DO_FOREIGN_SERVER) + if (dobj->objType == DO_TABLE) { - DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; - - daobj->dacl.privtype = privtype; - daobj->dacl.initprivs = pstrdup(initprivs); + /* For a column initprivs, set the table's ACL flags */ + dobj->components |= DUMP_COMPONENT_ACL; + ((TableInfo *) dobj)->hascolumnACLs = true; } else pg_log_warning("unsupported pg_init_privs entry: %u %u %d", classoid, objoid, objsubid); + continue; + } + + /* + * We ignore any pg_init_privs.initprivs entry for the public + * schema, as explained in getNamespaces(). + */ + if (dobj->objType == DO_NAMESPACE && + strcmp(dobj->name, "public") == 0) + continue; + + /* Else it had better be of a type we think has ACLs */ + if (dobj->objType == DO_NAMESPACE || + dobj->objType == DO_TYPE || + dobj->objType == DO_FUNC || + dobj->objType == DO_AGG || + dobj->objType == DO_TABLE || + dobj->objType == DO_PROCLANG || + dobj->objType == DO_FDW || + dobj->objType == DO_FOREIGN_SERVER) + { + DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; + + daobj->dacl.privtype = privtype; + daobj->dacl.initprivs = pstrdup(initprivs); } + else + pg_log_warning("unsupported pg_init_privs entry: %u %u %d", + classoid, objoid, objsubid); } - PQclear(res); + } + PQclear(res); destroyPQExpBuffer(query); } @@ -11128,8 +11127,8 @@ dumpRelationStats_dumper(Archive *fout, const void *userArg, const TocEntry *te) * The results must be in the order of the relations supplied in the * parameters to ensure we remain in sync as we walk through the TOC. * - * For versions before 19, the redundant filter clause on s.tablename = - * ANY(...) seems sufficient to convince the planner to use + * For versions before 19, the redundant filter clause on s.tablename + * = ANY(...) seems sufficient to convince the planner to use * pg_class_relname_nsp_index, which avoids a full scan of pg_stats. * In newer versions, pg_stats returns the table OIDs, eliminating the * need for that hack. @@ -13469,11 +13468,11 @@ dumpFunc(Archive *fout, const FuncInfo *finfo) "pg_catalog.pg_get_function_result(p.oid) AS funcresult,\n" "proleakproof,\n"); - appendPQExpBufferStr(query, - "array_to_string(protrftypes, ' ') AS protrftypes,\n"); + appendPQExpBufferStr(query, + "array_to_string(protrftypes, ' ') AS protrftypes,\n"); - appendPQExpBufferStr(query, - "proparallel,\n"); + appendPQExpBufferStr(query, + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -14963,9 +14962,9 @@ dumpCollation(Archive *fout, const CollInfo *collinfo) /* Get collation-specific details */ appendPQExpBufferStr(query, "SELECT "); - appendPQExpBufferStr(query, - "collprovider, " - "collversion, "); + appendPQExpBufferStr(query, + "collprovider, " + "collversion, "); if (fout->remoteVersion >= 120000) appendPQExpBufferStr(query, @@ -15372,23 +15371,23 @@ dumpAgg(Archive *fout, const AggInfo *agginfo) "pg_catalog.pg_get_function_arguments(p.oid) AS funcargs,\n" "pg_catalog.pg_get_function_identity_arguments(p.oid) AS funciargs,\n"); - appendPQExpBufferStr(query, - "aggkind,\n" - "aggmtransfn,\n" - "aggminvtransfn,\n" - "aggmfinalfn,\n" - "aggmtranstype::pg_catalog.regtype,\n" - "aggfinalextra,\n" - "aggmfinalextra,\n" - "aggtransspace,\n" - "aggmtransspace,\n" - "aggminitval,\n"); + appendPQExpBufferStr(query, + "aggkind,\n" + "aggmtransfn,\n" + "aggminvtransfn,\n" + "aggmfinalfn,\n" + "aggmtranstype::pg_catalog.regtype,\n" + "aggfinalextra,\n" + "aggmfinalextra,\n" + "aggtransspace,\n" + "aggmtransspace,\n" + "aggminitval,\n"); - appendPQExpBufferStr(query, - "aggcombinefn,\n" - "aggserialfn,\n" - "aggdeserialfn,\n" - "proparallel,\n"); + appendPQExpBufferStr(query, + "aggcombinefn,\n" + "aggserialfn,\n" + "aggdeserialfn,\n" + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -16848,30 +16847,30 @@ dumpTable(Archive *fout, const TableInfo *tbinfo) appendPQExpBufferStr(query, "PREPARE getColumnACLs(pg_catalog.oid) AS\n"); - /* - * In principle we should call acldefault('c', relowner) to - * get the default ACL for a column. However, we don't - * currently store the numeric OID of the relowner in - * TableInfo. We could convert the owner name using regrole, - * but that creates a risk of failure due to concurrent role - * renames. Given that the default ACL for columns is empty - * and is likely to stay that way, it's not worth extra cycles - * and risk to avoid hard-wiring that knowledge here. - */ - appendPQExpBufferStr(query, - "SELECT at.attname, " - "at.attacl, " - "'{}' AS acldefault, " - "pip.privtype, pip.initprivs " - "FROM pg_catalog.pg_attribute at " - "LEFT JOIN pg_catalog.pg_init_privs pip ON " - "(at.attrelid = pip.objoid " - "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " - "AND at.attnum = pip.objsubid) " - "WHERE at.attrelid = $1 AND " - "NOT at.attisdropped " - "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " - "ORDER BY at.attnum"); + /* + * In principle we should call acldefault('c', relowner) to get + * the default ACL for a column. However, we don't currently + * store the numeric OID of the relowner in TableInfo. We could + * convert the owner name using regrole, but that creates a risk + * of failure due to concurrent role renames. Given that the + * default ACL for columns is empty and is likely to stay that + * way, it's not worth extra cycles and risk to avoid hard-wiring + * that knowledge here. + */ + appendPQExpBufferStr(query, + "SELECT at.attname, " + "at.attacl, " + "'{}' AS acldefault, " + "pip.privtype, pip.initprivs " + "FROM pg_catalog.pg_attribute at " + "LEFT JOIN pg_catalog.pg_init_privs pip ON " + "(at.attrelid = pip.objoid " + "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " + "AND at.attnum = pip.objsubid) " + "WHERE at.attrelid = $1 AND " + "NOT at.attisdropped " + "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " + "ORDER BY at.attnum"); ExecuteSqlStatement(fout, query->data); @@ -19165,7 +19164,7 @@ collectSequences(Archive *fout) * pg_get_sequence_data(), but we only do so for non-schema-only dumps. */ if (fout->remoteVersion < 180000 || - (!fout->dopt->dumpData && !fout->dopt->sequence_data)) + (!fout->dopt->dumpData && !fout->dopt->sequence_data)) query = "SELECT seqrelid, format_type(seqtypid, NULL), " "seqstart, seqincrement, " "seqmax, seqmin, " @@ -19227,15 +19226,14 @@ dumpSequence(Archive *fout, const TableInfo *tbinfo) qseqname = pg_strdup(fmtId(tbinfo->dobj.name)); /* - * The sequence information is gathered in a sorted - * table before any calls to dumpSequence(). See collectSequences() for - * more information. + * The sequence information is gathered in a sorted table before any calls + * to dumpSequence(). See collectSequences() for more information. */ - Assert(sequences); + Assert(sequences); - key.oid = tbinfo->dobj.catId.oid; - seq = bsearch(&key, sequences, nsequences, - sizeof(SequenceItem), SequenceItemCmp); + key.oid = tbinfo->dobj.catId.oid; + seq = bsearch(&key, sequences, nsequences, + sizeof(SequenceItem), SequenceItemCmp); /* Calculate default limits for a sequence of this type */ is_ascending = (seq->incby >= 0); diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c index e68937c9934..afcd9a218d8 100644 --- a/src/bin/pg_dump/pg_dumpall.c +++ b/src/bin/pg_dump/pg_dumpall.c @@ -785,11 +785,11 @@ dropRoles(PGconn *conn) int i_rolname; int i; - printfPQExpBuffer(buf, - "SELECT rolname " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 1", role_catalog); + printfPQExpBuffer(buf, + "SELECT rolname " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 1", role_catalog); res = executeQuery(conn, buf->data); @@ -843,16 +843,16 @@ dumpRoles(PGconn *conn) * Notes: rolconfig is dumped later, and pg_authid must be used for * extracting rolcomment regardless of role_catalog. */ - printfPQExpBuffer(buf, - "SELECT oid, rolname, rolsuper, rolinherit, " - "rolcreaterole, rolcreatedb, " - "rolcanlogin, rolconnlimit, rolpassword, " - "rolvaliduntil, rolreplication, rolbypassrls, " - "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " - "rolname = current_user AS is_current_user " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 2", role_catalog); + printfPQExpBuffer(buf, + "SELECT oid, rolname, rolsuper, rolinherit, " + "rolcreaterole, rolcreatedb, " + "rolcanlogin, rolconnlimit, rolpassword, " + "rolvaliduntil, rolreplication, rolbypassrls, " + "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " + "rolname = current_user AS is_current_user " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 2", role_catalog); res = executeQuery(conn, buf->data); diff --git a/src/bin/pg_upgrade/check.c b/src/bin/pg_upgrade/check.c index 786c1474829..f725f5ee3e2 100644 --- a/src/bin/pg_upgrade/check.c +++ b/src/bin/pg_upgrade/check.c @@ -1475,15 +1475,15 @@ check_for_incompatible_polymorphics(ClusterInfo *cluster) ", 'array_cat(anyarray,anyarray)'" ", 'array_prepend(anyelement,anyarray)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_remove(anyarray,anyelement)'" - ", 'array_replace(anyarray,anyelement,anyelement)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_remove(anyarray,anyelement)'" + ", 'array_replace(anyarray,anyelement,anyelement)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_position(anyarray,anyelement)'" - ", 'array_position(anyarray,anyelement,integer)'" - ", 'array_positions(anyarray,anyelement)'" - ", 'width_bucket(anyelement,anyarray)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_position(anyarray,anyelement)'" + ", 'array_position(anyarray,anyelement,integer)'" + ", 'array_positions(anyarray,anyelement)'" + ", 'width_bucket(anyelement,anyarray)'"); /* * The query below hardcodes FirstNormalObjectId as 16384 rather than diff --git a/src/bin/pg_upgrade/controldata.c b/src/bin/pg_upgrade/controldata.c index 8f81c9e9582..02ea02df60f 100644 --- a/src/bin/pg_upgrade/controldata.c +++ b/src/bin/pg_upgrade/controldata.c @@ -228,7 +228,7 @@ get_control_data(ClusterInfo *cluster) p++; /* remove ':' char */ cluster->controldata.chkpnt_nxtepoch = str2uint(p); - p = strchr(p, ':'); + p = strchr(p, ':'); if (p == NULL || strlen(p) <= 1) pg_fatal("%d: controldata retrieval problem", __LINE__); diff --git a/src/bin/pg_upgrade/exec.c b/src/bin/pg_upgrade/exec.c index 44355feea30..a1bdbf373e3 100644 --- a/src/bin/pg_upgrade/exec.c +++ b/src/bin/pg_upgrade/exec.c @@ -55,7 +55,7 @@ get_bin_version(ClusterInfo *cluster) if (sscanf(cmd_output, "%*s %*s %d.%d", &v1, &v2) < 1) pg_fatal("could not get pg_ctl version output from %s", cmd); - cluster->bin_version = v1 * 10000; + cluster->bin_version = v1 * 10000; } @@ -344,8 +344,8 @@ check_data_dir(ClusterInfo *cluster) check_single_dir(pg_data, "pg_subtrans"); check_single_dir(pg_data, PG_TBLSPC_DIR); check_single_dir(pg_data, "pg_twophase"); - check_single_dir(pg_data, "pg_wal"); - check_single_dir(pg_data, "pg_xact"); + check_single_dir(pg_data, "pg_wal"); + check_single_dir(pg_data, "pg_xact"); } @@ -385,7 +385,7 @@ check_bin_dir(ClusterInfo *cluster, bool check_versions) */ get_bin_version(cluster); - check_exec(cluster->bindir, "pg_resetwal", check_versions); + check_exec(cluster->bindir, "pg_resetwal", check_versions); if (cluster == &new_cluster) { diff --git a/src/bin/pg_upgrade/multixact_rewrite.c b/src/bin/pg_upgrade/multixact_rewrite.c index c45b3183684..c7a1416494d 100644 --- a/src/bin/pg_upgrade/multixact_rewrite.c +++ b/src/bin/pg_upgrade/multixact_rewrite.c @@ -61,52 +61,52 @@ rewrite_multixacts(MultiXactId from_multi, MultiXactId to_multi) * Convert old multixids, if needed, by reading them one-by-one from the * old cluster. */ - old_reader = AllocOldMultiXactRead(old_cluster.pgdata, - old_cluster.controldata.chkpnt_nxtmulti, - old_cluster.controldata.chkpnt_nxtmxoff); + old_reader = AllocOldMultiXactRead(old_cluster.pgdata, + old_cluster.controldata.chkpnt_nxtmulti, + old_cluster.controldata.chkpnt_nxtmxoff); - for (MultiXactId multi = from_multi; multi != to_multi;) - { - MultiXactMember member; - bool multixid_valid; - - /* - * Read this multixid's members. - * - * Locking-only XIDs that may be part of multi-xids don't matter - * after upgrade, as there can be no transactions running across - * upgrade. So as a small optimization, we only read one member - * from each multixid: the one updating one, or if there was no - * update, arbitrarily the first locking xid. - */ - multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); + for (MultiXactId multi = from_multi; multi != to_multi;) + { + MultiXactMember member; + bool multixid_valid; - /* - * Write the new offset to pg_multixact/offsets. - * - * Even if this multixid is invalid, we still need to write its - * offset if the *previous* multixid was valid. That's because - * when reading a multixid, the number of members is calculated - * from the difference between the two offsets. - */ - RecordMultiXactOffset(offsets_writer, multi, - (multixid_valid || prev_multixid_valid) ? next_offset : 0); + /* + * Read this multixid's members. + * + * Locking-only XIDs that may be part of multi-xids don't matter after + * upgrade, as there can be no transactions running across upgrade. So + * as a small optimization, we only read one member from each + * multixid: the one updating one, or if there was no update, + * arbitrarily the first locking xid. + */ + multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); - /* Write the members */ - if (multixid_valid) - { - RecordMultiXactMembers(members_writer, next_offset, 1, &member); - next_offset += 1; - } + /* + * Write the new offset to pg_multixact/offsets. + * + * Even if this multixid is invalid, we still need to write its offset + * if the *previous* multixid was valid. That's because when reading + * a multixid, the number of members is calculated from the difference + * between the two offsets. + */ + RecordMultiXactOffset(offsets_writer, multi, + (multixid_valid || prev_multixid_valid) ? next_offset : 0); - /* Advance to next multixid, handling wraparound */ - multi++; - if (multi < FirstMultiXactId) - multi = FirstMultiXactId; - prev_multixid_valid = multixid_valid; + /* Write the members */ + if (multixid_valid) + { + RecordMultiXactMembers(members_writer, next_offset, 1, &member); + next_offset += 1; } - FreeOldMultiXactReader(old_reader); + /* Advance to next multixid, handling wraparound */ + multi++; + if (multi < FirstMultiXactId) + multi = FirstMultiXactId; + prev_multixid_valid = multixid_valid; + } + + FreeOldMultiXactReader(old_reader); /* Write the final 'next' offset to the last SLRU page */ RecordMultiXactOffset(offsets_writer, to_multi, diff --git a/src/bin/pg_upgrade/pg_upgrade.c b/src/bin/pg_upgrade/pg_upgrade.c index c6af9035665..7366fd4627c 100644 --- a/src/bin/pg_upgrade/pg_upgrade.c +++ b/src/bin/pg_upgrade/pg_upgrade.c @@ -833,7 +833,7 @@ copy_xact_xlog_xid(void) * Determine the range of multixacts to convert. */ nxtmulti = old_cluster.controldata.chkpnt_nxtmulti; - oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; + oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; /* handle wraparound */ if (nxtmulti < FirstMultiXactId) nxtmulti = FirstMultiXactId; @@ -898,15 +898,15 @@ set_frozenxids(void) int i_datname; int i_datallowconn; - prep_status("Setting frozenxid and minmxid counters in new cluster"); + prep_status("Setting frozenxid and minmxid counters in new cluster"); conn_template1 = connectToServer(&new_cluster, "template1"); - /* set pg_database.datfrozenxid */ - PQclear(executeQueryOrDie(conn_template1, - "UPDATE pg_catalog.pg_database " - "SET datfrozenxid = '%u'", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_database.datfrozenxid */ + PQclear(executeQueryOrDie(conn_template1, + "UPDATE pg_catalog.pg_database " + "SET datfrozenxid = '%u'", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_database.datminmxid */ PQclear(executeQueryOrDie(conn_template1, @@ -942,16 +942,16 @@ set_frozenxids(void) conn = connectToServer(&new_cluster, datname); - /* set pg_class.relfrozenxid */ - PQclear(executeQueryOrDie(conn, - "UPDATE pg_catalog.pg_class " - "SET relfrozenxid = '%u' " - /* only heap, materialized view, and TOAST are vacuumed */ - "WHERE relkind IN (" - CppAsString2(RELKIND_RELATION) ", " - CppAsString2(RELKIND_MATVIEW) ", " - CppAsString2(RELKIND_TOASTVALUE) ")", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_class.relfrozenxid */ + PQclear(executeQueryOrDie(conn, + "UPDATE pg_catalog.pg_class " + "SET relfrozenxid = '%u' " + /* only heap, materialized view, and TOAST are vacuumed */ + "WHERE relkind IN (" + CppAsString2(RELKIND_RELATION) ", " + CppAsString2(RELKIND_MATVIEW) ", " + CppAsString2(RELKIND_TOASTVALUE) ")", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_class.relminmxid */ PQclear(executeQueryOrDie(conn, diff --git a/src/bin/pg_upgrade/relfilenumber.c b/src/bin/pg_upgrade/relfilenumber.c index ec2ff7acb21..6c467bdc8a5 100644 --- a/src/bin/pg_upgrade/relfilenumber.c +++ b/src/bin/pg_upgrade/relfilenumber.c @@ -587,32 +587,32 @@ transfer_relfile(FileNameMap *map, const char *type_suffix) /* Copying files might take some time, so give feedback. */ pg_log(PG_STATUS, "%s", old_file); - switch (user_opts.transfer_mode) - { - case TRANSFER_MODE_CLONE: - pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", - old_file, new_file); - cloneFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", - old_file, new_file); - copyFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY_FILE_RANGE: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", - old_file, new_file); - copyFileByRange(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_LINK: - pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", - old_file, new_file); - linkFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_SWAP: - /* swap mode is handled in its own code path */ - pg_fatal("should never happen"); - break; - } + switch (user_opts.transfer_mode) + { + case TRANSFER_MODE_CLONE: + pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", + old_file, new_file); + cloneFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", + old_file, new_file); + copyFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY_FILE_RANGE: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", + old_file, new_file); + copyFileByRange(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_LINK: + pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", + old_file, new_file); + linkFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_SWAP: + /* swap mode is handled in its own code path */ + pg_fatal("should never happen"); + break; + } } } diff --git a/src/bin/pg_upgrade/t/006_transfer_modes.pl b/src/bin/pg_upgrade/t/006_transfer_modes.pl index 9efa5dc863c..360d05c4b68 100644 --- a/src/bin/pg_upgrade/t/006_transfer_modes.pl +++ b/src/bin/pg_upgrade/t/006_transfer_modes.pl @@ -29,10 +29,8 @@ sub test_mode } $new->init(); - $new->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); - $old->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); + $new->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); + $old->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); # We can only test security labels if both the old and new installations # have dummy_seclabel. @@ -76,15 +74,14 @@ sub test_mode "CREATE TABLE test4 AS SELECT generate_series(400, 502)"); } - $old->safe_psql('postgres', - "CREATE TABLESPACE inplc_tblspc LOCATION ''"); - $old->safe_psql('postgres', - "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); - $old->safe_psql('postgres', - "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" - ); - $old->safe_psql('testdb3', - "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); + $old->safe_psql('postgres', "CREATE TABLESPACE inplc_tblspc LOCATION ''"); + $old->safe_psql('postgres', + "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); + $old->safe_psql('postgres', + "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" + ); + $old->safe_psql('testdb3', + "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); # While we are here, test handling of large objects. $old->safe_psql( @@ -152,12 +149,10 @@ sub test_mode } # Tests for in-place tablespaces. - $result = - $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); - is($result, '104', "test5 data after pg_upgrade $mode"); - $result = - $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); - is($result, '105', "test6 data after pg_upgrade $mode"); + $result = $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); + is($result, '104', "test5 data after pg_upgrade $mode"); + $result = $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); + is($result, '105', "test6 data after pg_upgrade $mode"); # Tests for large objects $result = $new->safe_psql('postgres', "SELECT lo_get(4532)"); diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index 44ef11d980e..c90bf8bbde2 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -6278,23 +6278,22 @@ get_create_object_cmd(EditableObjectType obj_type, Oid oid, * ensure the right view gets replaced. Also, check relation kind * to be sure it's a view. * - * Views may have WITH [LOCAL|CASCADED] - * CHECK OPTION. These are not part of the view definition - * returned by pg_get_viewdef() and so need to be retrieved - * separately. Materialized views may have - * arbitrary storage parameter reloptions. + * Views may have WITH [LOCAL|CASCADED] CHECK OPTION. These are + * not part of the view definition returned by pg_get_viewdef() + * and so need to be retrieved separately. Materialized views may + * have arbitrary storage parameter reloptions. */ printfPQExpBuffer(query, "/* %s */\n", _("Get view's definition and details")); - appendPQExpBuffer(query, - "SELECT nspname, relname, relkind, " - "pg_catalog.pg_get_viewdef(c.oid, true), " - "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " - "FROM pg_catalog.pg_class c " - "LEFT JOIN pg_catalog.pg_namespace n " - "ON c.relnamespace = n.oid WHERE c.oid = %u", - oid); + appendPQExpBuffer(query, + "SELECT nspname, relname, relkind, " + "pg_catalog.pg_get_viewdef(c.oid, true), " + "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " + "FROM pg_catalog.pg_class c " + "LEFT JOIN pg_catalog.pg_namespace n " + "ON c.relnamespace = n.oid WHERE c.oid = %u", + oid); break; } diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index ce99137c613..ac0c55e7aa5 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -387,19 +387,19 @@ describeFunctions(const char *functypes, const char *func_pattern, gettext_noop("stable"), gettext_noop("volatile"), gettext_noop("Volatility")); - appendPQExpBuffer(&buf, - ",\n CASE\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" - " END as \"%s\"", - gettext_noop("restricted"), - gettext_noop("safe"), - gettext_noop("unsafe"), - gettext_noop("Parallel")); + appendPQExpBuffer(&buf, + ",\n CASE\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" + " END as \"%s\"", + gettext_noop("restricted"), + gettext_noop("safe"), + gettext_noop("unsafe"), + gettext_noop("Parallel")); appendPQExpBuffer(&buf, ",\n pg_catalog.pg_get_userbyid(p.proowner) as \"%s\"" ",\n CASE WHEN prosecdef THEN '%s' ELSE '%s' END AS \"%s\"" @@ -599,8 +599,8 @@ describeFunctions(const char *functypes, const char *func_pattern, myopt.title = _("List of functions"); myopt.translate_header = true; - myopt.translate_columns = translate_columns; - myopt.n_translate_columns = lengthof(translate_columns); + myopt.translate_columns = translate_columns; + myopt.n_translate_columns = lengthof(translate_columns); printQuery(res, &myopt, pset.queryFout, false, pset.logfile); @@ -1086,38 +1086,38 @@ permissionsList(const char *pattern, bool showSystem) " ), E'\\n') AS \"%s\"", gettext_noop("Column privileges")); - appendPQExpBuffer(&buf, - ",\n pg_catalog.array_to_string(ARRAY(\n" - " SELECT polname\n" - " || CASE WHEN NOT polpermissive THEN\n" - " E' (RESTRICTIVE)'\n" - " ELSE '' END\n" - " || CASE WHEN polcmd != '*' THEN\n" - " E' (' || polcmd::pg_catalog.text || E'):'\n" - " ELSE E':'\n" - " END\n" - " || CASE WHEN polqual IS NOT NULL THEN\n" - " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" - " ELSE E''\n" - " END\n" - " || CASE WHEN polwithcheck IS NOT NULL THEN\n" - " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" - " ELSE E''\n" - " END" - " || CASE WHEN polroles <> '{0}' THEN\n" - " E'\\n to: ' || pg_catalog.array_to_string(\n" - " ARRAY(\n" - " SELECT rolname\n" - " FROM pg_catalog.pg_roles\n" - " WHERE oid = ANY (polroles)\n" - " ORDER BY 1\n" - " ), E', ')\n" - " ELSE E''\n" - " END\n" - " FROM pg_catalog.pg_policy pol\n" - " WHERE polrelid = c.oid), E'\\n')\n" - " AS \"%s\"", - gettext_noop("Policies")); + appendPQExpBuffer(&buf, + ",\n pg_catalog.array_to_string(ARRAY(\n" + " SELECT polname\n" + " || CASE WHEN NOT polpermissive THEN\n" + " E' (RESTRICTIVE)'\n" + " ELSE '' END\n" + " || CASE WHEN polcmd != '*' THEN\n" + " E' (' || polcmd::pg_catalog.text || E'):'\n" + " ELSE E':'\n" + " END\n" + " || CASE WHEN polqual IS NOT NULL THEN\n" + " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" + " ELSE E''\n" + " END\n" + " || CASE WHEN polwithcheck IS NOT NULL THEN\n" + " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" + " ELSE E''\n" + " END" + " || CASE WHEN polroles <> '{0}' THEN\n" + " E'\\n to: ' || pg_catalog.array_to_string(\n" + " ARRAY(\n" + " SELECT rolname\n" + " FROM pg_catalog.pg_roles\n" + " WHERE oid = ANY (polroles)\n" + " ORDER BY 1\n" + " ), E', ')\n" + " ELSE E''\n" + " END\n" + " FROM pg_catalog.pg_policy pol\n" + " WHERE polrelid = c.oid), E'\\n')\n" + " AS \"%s\"", + gettext_noop("Policies")); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_class c\n" " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n" @@ -1675,27 +1675,27 @@ describeOneTableDetails(const char *schemaname, char *footers[3] = {NULL, NULL, NULL}; printfPQExpBuffer(&buf, "/* %s */\n", _("Get sequence information")); - appendPQExpBuffer(&buf, - "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" - " seqstart AS \"%s\",\n" - " seqmin AS \"%s\",\n" - " seqmax AS \"%s\",\n" - " seqincrement AS \"%s\",\n" - " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" - " seqcache AS \"%s\"\n", - gettext_noop("Type"), - gettext_noop("Start"), - gettext_noop("Minimum"), - gettext_noop("Maximum"), - gettext_noop("Increment"), - gettext_noop("yes"), - gettext_noop("no"), - gettext_noop("Cycles?"), - gettext_noop("Cache")); - appendPQExpBuffer(&buf, - "FROM pg_catalog.pg_sequence\n" - "WHERE seqrelid = '%s';", - oid); + appendPQExpBuffer(&buf, + "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" + " seqstart AS \"%s\",\n" + " seqmin AS \"%s\",\n" + " seqmax AS \"%s\",\n" + " seqincrement AS \"%s\",\n" + " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" + " seqcache AS \"%s\"\n", + gettext_noop("Type"), + gettext_noop("Start"), + gettext_noop("Minimum"), + gettext_noop("Maximum"), + gettext_noop("Increment"), + gettext_noop("yes"), + gettext_noop("no"), + gettext_noop("Cycles?"), + gettext_noop("Cache")); + appendPQExpBuffer(&buf, + "FROM pg_catalog.pg_sequence\n" + "WHERE seqrelid = '%s';", + oid); res = PSQLexec(buf.data); if (!res) @@ -1913,7 +1913,7 @@ describeOneTableDetails(const char *schemaname, appendPQExpBufferStr(&buf, ",\n (SELECT c.collname FROM pg_catalog.pg_collation c, pg_catalog.pg_type t\n" " WHERE c.oid = a.attcollation AND t.oid = a.atttypid AND a.attcollation <> t.typcollation) AS attcollation"); attcoll_col = cols++; - appendPQExpBufferStr(&buf, ",\n a.attidentity"); + appendPQExpBufferStr(&buf, ",\n a.attidentity"); attidentity_col = cols++; if (pset.sversion >= 120000) appendPQExpBufferStr(&buf, ",\n a.attgenerated"); @@ -2326,7 +2326,7 @@ describeOneTableDetails(const char *schemaname, CppAsString2(CONSTRAINT_EXCLUSION) ") AND " "condeferred) AS condeferred,\n"); - appendPQExpBufferStr(&buf, "i.indisreplident,\n"); + appendPQExpBufferStr(&buf, "i.indisreplident,\n"); if (pset.sversion >= 150000) appendPQExpBufferStr(&buf, "i.indnullsnotdistinct,\n"); @@ -2431,7 +2431,7 @@ describeOneTableDetails(const char *schemaname, "pg_catalog.pg_get_indexdef(i.indexrelid, 0, true),\n " "pg_catalog.pg_get_constraintdef(con.oid, true), " "contype, condeferrable, condeferred"); - appendPQExpBufferStr(&buf, ", i.indisreplident"); + appendPQExpBufferStr(&buf, ", i.indisreplident"); appendPQExpBufferStr(&buf, ", c2.reltablespace"); if (pset.sversion >= 180000) appendPQExpBufferStr(&buf, ", con.conperiod"); @@ -2682,81 +2682,80 @@ describeOneTableDetails(const char *schemaname, PQclear(result); /* print any row-level policies */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get row-level policies for this table")); - appendPQExpBufferStr(&buf, "SELECT pol.polname,"); - appendPQExpBufferStr(&buf, - " pol.polpermissive,\n"); - appendPQExpBuffer(&buf, - " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" - " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" - " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" - " CASE pol.polcmd\n" - " WHEN 'r' THEN 'SELECT'\n" - " WHEN 'a' THEN 'INSERT'\n" - " WHEN 'w' THEN 'UPDATE'\n" - " WHEN 'd' THEN 'DELETE'\n" - " END AS cmd\n" - "FROM pg_catalog.pg_policy pol\n" - "WHERE pol.polrelid = '%s' ORDER BY 1;", - oid); + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get row-level policies for this table")); + appendPQExpBufferStr(&buf, "SELECT pol.polname,"); + appendPQExpBufferStr(&buf, + " pol.polpermissive,\n"); + appendPQExpBuffer(&buf, + " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" + " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" + " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" + " CASE pol.polcmd\n" + " WHEN 'r' THEN 'SELECT'\n" + " WHEN 'a' THEN 'INSERT'\n" + " WHEN 'w' THEN 'UPDATE'\n" + " WHEN 'd' THEN 'DELETE'\n" + " END AS cmd\n" + "FROM pg_catalog.pg_policy pol\n" + "WHERE pol.polrelid = '%s' ORDER BY 1;", + oid); - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - /* - * Handle cases where RLS is enabled and there are policies, or - * there aren't policies, or RLS isn't enabled but there are - * policies - */ - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies:")); + /* + * Handle cases where RLS is enabled and there are policies, or there + * aren't policies, or RLS isn't enabled but there are policies + */ + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies:")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled):")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled):")); - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); - if (!tableinfo.rowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (row security disabled):")); + if (!tableinfo.rowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (row security disabled):")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " POLICY \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " POLICY \"%s\"", + PQgetvalue(result, i, 0)); - if (*(PQgetvalue(result, i, 1)) == 'f') - appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); + if (*(PQgetvalue(result, i, 1)) == 'f') + appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); - if (!PQgetisnull(result, i, 5)) - appendPQExpBuffer(&buf, " FOR %s", - PQgetvalue(result, i, 5)); + if (!PQgetisnull(result, i, 5)) + appendPQExpBuffer(&buf, " FOR %s", + PQgetvalue(result, i, 5)); - if (!PQgetisnull(result, i, 2)) - { - appendPQExpBuffer(&buf, "\n TO %s", - PQgetvalue(result, i, 2)); - } + if (!PQgetisnull(result, i, 2)) + { + appendPQExpBuffer(&buf, "\n TO %s", + PQgetvalue(result, i, 2)); + } - if (!PQgetisnull(result, i, 3)) - appendPQExpBuffer(&buf, "\n USING (%s)", - PQgetvalue(result, i, 3)); + if (!PQgetisnull(result, i, 3)) + appendPQExpBuffer(&buf, "\n USING (%s)", + PQgetvalue(result, i, 3)); - if (!PQgetisnull(result, i, 4)) - appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", - PQgetvalue(result, i, 4)); + if (!PQgetisnull(result, i, 4)) + appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", + PQgetvalue(result, i, 4)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* print any extended statistics */ if (pset.sversion >= 140000) @@ -3025,115 +3024,115 @@ describeOneTableDetails(const char *schemaname, } /* print any publications */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get publications that publish this table")); - if (pset.sversion >= 150000) + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get publications that publish this table")); + if (pset.sversion >= 150000) + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" + " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" + "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" + "UNION\n" + "SELECT pubname\n" + " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" + " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" + " (SELECT pg_catalog.string_agg(attname, ', ')\n" + " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" + " pg_catalog.pg_attribute\n" + " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" + " ELSE NULL END) " + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" + "WHERE pr.prrelid = '%s'\n", + oid, oid, oid); + + if (pset.sversion >= 190000) { + /* + * Skip entries where this relation appears in the + * publication's EXCEPT list. + */ appendPQExpBuffer(&buf, + " AND NOT pr.prexcept\n" + "UNION\n" "SELECT pubname\n" " , NULL\n" " , NULL\n" "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" - " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" - "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" - "UNION\n" - "SELECT pubname\n" - " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" - " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" - " (SELECT pg_catalog.string_agg(attname, ', ')\n" - " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" - " pg_catalog.pg_attribute\n" - " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" - " ELSE NULL END) " - "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" - "WHERE pr.prrelid = '%s'\n", + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + " AND NOT EXISTS (\n" + " SELECT 1\n" + " FROM pg_catalog.pg_publication_rel pr\n" + " WHERE pr.prpubid = p.oid AND\n" + " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" + "ORDER BY 1;", oid, oid, oid); - - if (pset.sversion >= 190000) - { - /* - * Skip entries where this relation appears in the - * publication's EXCEPT list. - */ - appendPQExpBuffer(&buf, - " AND NOT pr.prexcept\n" - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - " AND NOT EXISTS (\n" - " SELECT 1\n" - " FROM pg_catalog.pg_publication_rel pr\n" - " WHERE pr.prpubid = p.oid AND\n" - " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" - "ORDER BY 1;", - oid, oid, oid); - } - else - { - appendPQExpBuffer(&buf, - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - "ORDER BY 1;", - oid); - } } else { appendPQExpBuffer(&buf, + "UNION\n" "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - "WHERE pr.prrelid = '%s'\n" - "UNION ALL\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" + " , NULL\n" + " , NULL\n" "FROM pg_catalog.pg_publication p\n" "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" "ORDER BY 1;", - oid, oid); + oid); } + } + else + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + "WHERE pr.prrelid = '%s'\n" + "UNION ALL\n" + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + "ORDER BY 1;", + oid, oid); + } - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - if (tuples > 0) - printTableAddFooter(&cont, _("Included in publications:")); + if (tuples > 0) + printTableAddFooter(&cont, _("Included in publications:")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " \"%s\"", + PQgetvalue(result, i, 0)); - /* column list (if any) */ - if (!PQgetisnull(result, i, 2)) - appendPQExpBuffer(&buf, " (%s)", - PQgetvalue(result, i, 2)); + /* column list (if any) */ + if (!PQgetisnull(result, i, 2)) + appendPQExpBuffer(&buf, " (%s)", + PQgetvalue(result, i, 2)); - /* row filter (if any) */ - if (!PQgetisnull(result, i, 1)) - appendPQExpBuffer(&buf, " WHERE %s", - PQgetvalue(result, i, 1)); + /* row filter (if any) */ + if (!PQgetisnull(result, i, 1)) + appendPQExpBuffer(&buf, " WHERE %s", + PQgetvalue(result, i, 1)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* Print publications where the table is in the EXCEPT clause */ if (pset.sversion >= 190000) @@ -3805,7 +3804,7 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) ncols++; } appendPQExpBufferStr(&buf, "\n, r.rolreplication"); - appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); + appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_roles r\n"); @@ -3860,8 +3859,8 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) if (strcmp(PQgetvalue(res, i, (verbose ? 9 : 8)), "t") == 0) add_role_attribute(&buf, _("Replication")); - if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) - add_role_attribute(&buf, _("Bypass RLS")); + if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) + add_role_attribute(&buf, _("Bypass RLS")); conns = atoi(PQgetvalue(res, i, 6)); if (conns >= 0) @@ -5155,14 +5154,14 @@ listCollations(const char *pattern, bool verbose, bool showSystem) gettext_noop("Schema"), gettext_noop("Name")); - appendPQExpBuffer(&buf, - " CASE c.collprovider " - "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " - "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " - "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " - "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " - "END AS \"%s\",\n", - gettext_noop("Provider")); + appendPQExpBuffer(&buf, + " CASE c.collprovider " + "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " + "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " + "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " + "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " + "END AS \"%s\",\n", + gettext_noop("Provider")); appendPQExpBuffer(&buf, " c.collcollate AS \"%s\",\n" -- 2.50.1 (Apple Git-155) --aHl3HfeiUuO3zeNC-- ^ permalink raw reply [nested|flat] 59+ messages in thread
* [PATCH v6 4/4] run pgindent and pgperltidy @ 2026-06-30 18:24 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 59+ messages in thread From: Nathan Bossart @ 2026-06-30 18:24 UTC (permalink / raw) --- src/bin/pg_dump/pg_dump.c | 464 ++++++++++----------- src/bin/pg_dump/pg_dumpall.c | 30 +- src/bin/pg_upgrade/check.c | 16 +- src/bin/pg_upgrade/controldata.c | 2 +- src/bin/pg_upgrade/exec.c | 8 +- src/bin/pg_upgrade/multixact_rewrite.c | 80 ++-- src/bin/pg_upgrade/pg_upgrade.c | 34 +- src/bin/pg_upgrade/relfilenumber.c | 54 +-- src/bin/pg_upgrade/t/006_transfer_modes.pl | 33 +- src/bin/psql/command.c | 29 +- src/bin/psql/describe.c | 461 ++++++++++---------- 11 files changed, 601 insertions(+), 610 deletions(-) diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 65bd15ebfd2..5673268b467 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -1491,8 +1491,8 @@ setup_connection(Archive *AH, const char *dumpencoding, * Disable timeouts if supported. */ ExecuteSqlStatement(AH, "SET statement_timeout = 0"); - ExecuteSqlStatement(AH, "SET lock_timeout = 0"); - ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); + ExecuteSqlStatement(AH, "SET lock_timeout = 0"); + ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); if (AH->remoteVersion >= 170000) ExecuteSqlStatement(AH, "SET transaction_timeout = 0"); @@ -1505,10 +1505,10 @@ setup_connection(Archive *AH, const char *dumpencoding, /* * Adjust row-security mode, if supported. */ - if (dopt->enable_row_security) - ExecuteSqlStatement(AH, "SET row_security = on"); - else - ExecuteSqlStatement(AH, "SET row_security = off"); + if (dopt->enable_row_security) + ExecuteSqlStatement(AH, "SET row_security = on"); + else + ExecuteSqlStatement(AH, "SET row_security = off"); /* * For security reasons, we restrict the expansion of non-system views and @@ -1933,10 +1933,9 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) addObjectDependency(dobj, ext->dobj.dumpId); /* - * Mark the member object to have any non-initial ACLs - * dumped. (Any initial ACLs will be removed later, using data from - * pg_init_privs, so that we'll dump only the delta from the extension's - * initial setup.) + * Mark the member object to have any non-initial ACLs dumped. (Any + * initial ACLs will be removed later, using data from pg_init_privs, so + * that we'll dump only the delta from the extension's initial setup.) * * In binary upgrades, we still dump all components of the members * individually, since the idea is to exactly reproduce the database @@ -1953,7 +1952,7 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) if (fout->dopt->binary_upgrade) dobj->dump = ext->dobj.dump; else - dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); + dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); return true; } @@ -1987,9 +1986,9 @@ selectDumpableNamespace(NamespaceInfo *nsinfo, Archive *fout) else if (strcmp(nsinfo->dobj.name, "pg_catalog") == 0) { /* - * We dump out any ACLs defined in pg_catalog, if - * they are interesting (and not the original ACLs which were set at - * initdb time, see pg_init_privs). + * We dump out any ACLs defined in pg_catalog, if they are interesting + * (and not the original ACLs which were set at initdb time, see + * pg_init_privs). */ nsinfo->dobj.dump_contains = nsinfo->dobj.dump = DUMP_COMPONENT_ACL; } @@ -3296,7 +3295,7 @@ dumpDatabase(Archive *fout) "datcollate, datctype, datfrozenxid, " "datacl, acldefault('d', datdba) AS acldefault, " "datistemplate, datconnlimit, "); - appendPQExpBufferStr(dbQry, "datminmxid, "); + appendPQExpBufferStr(dbQry, "datminmxid, "); if (fout->remoteVersion >= 170000) appendPQExpBufferStr(dbQry, "datlocprovider, datlocale, datcollversion, "); else if (fout->remoteVersion >= 150000) @@ -3638,11 +3637,11 @@ dumpDatabase(Archive *fout) ii_oid, ii_relminmxid; - appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" - "FROM pg_catalog.pg_class\n" - "WHERE oid IN (%u, %u, %u, %u);\n", - LargeObjectRelationId, LargeObjectLOidPNIndexId, - LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); + appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" + "FROM pg_catalog.pg_class\n" + "WHERE oid IN (%u, %u, %u, %u);\n", + LargeObjectRelationId, LargeObjectLOidPNIndexId, + LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); lo_res = ExecuteSqlQuery(fout, loFrozenQry->data, PGRES_TUPLES_OK); @@ -4274,7 +4273,7 @@ getPolicies(Archive *fout, TableInfo tblinfo[], int numTables) printfPQExpBuffer(query, "SELECT pol.oid, pol.tableoid, pol.polrelid, pol.polname, pol.polcmd, "); - appendPQExpBufferStr(query, "pol.polpermissive, "); + appendPQExpBufferStr(query, "pol.polpermissive, "); appendPQExpBuffer(query, "CASE WHEN pol.polroles = '{0}' THEN NULL ELSE " " pg_catalog.array_to_string(ARRAY(SELECT pg_catalog.quote_ident(rolname) from pg_catalog.pg_roles WHERE oid = ANY(pol.polroles)), ', ') END AS polroles, " @@ -6633,9 +6632,9 @@ getAccessMethods(Archive *fout) * Select all access methods from pg_am table. */ appendPQExpBufferStr(query, "SELECT tableoid, oid, amname, "); - appendPQExpBufferStr(query, - "amtype, " - "amhandler::pg_catalog.regproc AS amhandler "); + appendPQExpBufferStr(query, + "amtype, " + "amhandler::pg_catalog.regproc AS amhandler "); appendPQExpBufferStr(query, "FROM pg_am"); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6827,35 +6826,35 @@ getAggregates(Archive *fout) * Find all interesting aggregates. See comment in getFuncs() for the * rationale behind the filtering logic. */ - agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" - : "p.proisagg"); + agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" + : "p.proisagg"); - appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " - "p.proname AS aggname, " - "p.pronamespace AS aggnamespace, " - "p.pronargs, p.proargtypes, " - "p.proowner, " - "p.proacl AS aggacl, " - "acldefault('f', p.proowner) AS acldefault " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s AND (" - "p.pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog') OR " - "p.proacl IS DISTINCT FROM pip.initprivs", - agg_check); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - " OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); - appendPQExpBufferChar(query, ')'); + appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " + "p.proname AS aggname, " + "p.pronamespace AS aggnamespace, " + "p.pronargs, p.proargtypes, " + "p.proowner, " + "p.proacl AS aggacl, " + "acldefault('f', p.proowner) AS acldefault " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s AND (" + "p.pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog') OR " + "p.proacl IS DISTINCT FROM pip.initprivs", + agg_check); + if (dopt->binary_upgrade) + appendPQExpBufferStr(query, + " OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6957,53 +6956,53 @@ getFuncs(Archive *fout) * include them, since we want to dump extension members individually in * that mode. Also, if they are used by casts or transforms then we need * to gather the information about them, though they won't be dumped if - * they are built-in. Also, include functions in - * pg_catalog if they have an ACL different from what's shown in - * pg_init_privs (so we have to join to pg_init_privs; annoying). + * they are built-in. Also, include functions in pg_catalog if they have + * an ACL different from what's shown in pg_init_privs (so we have to join + * to pg_init_privs; annoying). */ - not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" - : "NOT p.proisagg"); + not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" + : "NOT p.proisagg"); - appendPQExpBuffer(query, - "SELECT p.tableoid, p.oid, p.proname, p.prolang, " - "p.pronargs, p.proargtypes, p.prorettype, " - "p.proacl, " - "acldefault('f', p.proowner) AS acldefault, " - "p.pronamespace, " - "p.proowner " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s" - "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " - "WHERE classid = 'pg_proc'::regclass AND " - "objid = p.oid AND deptype = 'i')" - "\n AND (" - "\n pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog')" - "\n OR EXISTS (SELECT 1 FROM pg_cast" - "\n WHERE pg_cast.oid > %u " - "\n AND p.oid = pg_cast.castfunc)" - "\n OR EXISTS (SELECT 1 FROM pg_transform" - "\n WHERE pg_transform.oid > %u AND " - "\n (p.oid = pg_transform.trffromsql" - "\n OR p.oid = pg_transform.trftosql))", - not_agg_check, - g_last_builtin_oid, - g_last_builtin_oid); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); + appendPQExpBuffer(query, + "SELECT p.tableoid, p.oid, p.proname, p.prolang, " + "p.pronargs, p.proargtypes, p.prorettype, " + "p.proacl, " + "acldefault('f', p.proowner) AS acldefault, " + "p.pronamespace, " + "p.proowner " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s" + "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " + "WHERE classid = 'pg_proc'::regclass AND " + "objid = p.oid AND deptype = 'i')" + "\n AND (" + "\n pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog')" + "\n OR EXISTS (SELECT 1 FROM pg_cast" + "\n WHERE pg_cast.oid > %u " + "\n AND p.oid = pg_cast.castfunc)" + "\n OR EXISTS (SELECT 1 FROM pg_transform" + "\n WHERE pg_transform.oid > %u AND " + "\n (p.oid = pg_transform.trffromsql" + "\n OR p.oid = pg_transform.trftosql))", + not_agg_check, + g_last_builtin_oid, + g_last_builtin_oid); + if (dopt->binary_upgrade) appendPQExpBufferStr(query, - "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); - appendPQExpBufferChar(query, ')'); + "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferStr(query, + "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -7252,31 +7251,31 @@ getTables(Archive *fout, int *numTables) appendPQExpBufferStr(query, "c.relhasoids, "); - appendPQExpBufferStr(query, - "c.relispopulated, "); + appendPQExpBufferStr(query, + "c.relispopulated, "); - appendPQExpBufferStr(query, - "c.relreplident, "); + appendPQExpBufferStr(query, + "c.relreplident, "); - appendPQExpBufferStr(query, - "c.relrowsecurity, c.relforcerowsecurity, "); + appendPQExpBufferStr(query, + "c.relrowsecurity, c.relforcerowsecurity, "); - appendPQExpBufferStr(query, - "c.relminmxid, tc.relminmxid AS tminmxid, "); + appendPQExpBufferStr(query, + "c.relminmxid, tc.relminmxid AS tminmxid, "); - appendPQExpBufferStr(query, - "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); + appendPQExpBufferStr(query, + "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); - appendPQExpBufferStr(query, - "am.amname, "); + appendPQExpBufferStr(query, + "am.amname, "); - appendPQExpBufferStr(query, - "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); + appendPQExpBufferStr(query, + "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); - appendPQExpBufferStr(query, - "c.relispartition AS ispartition "); + appendPQExpBufferStr(query, + "c.relispartition AS ispartition "); /* * Left join to pg_depend to pick up dependency info linking sequences to @@ -7296,8 +7295,8 @@ getTables(Archive *fout, int *numTables) /* * Left join to pg_am to pick up the amname. */ - appendPQExpBufferStr(query, - "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); + appendPQExpBufferStr(query, + "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); /* * We purposefully ignore toast OIDs for partitioned tables; the reason is @@ -7868,8 +7867,8 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables) "t.reloptions AS indreloptions, "); - appendPQExpBufferStr(query, - "i.indisreplident, "); + appendPQExpBufferStr(query, + "i.indisreplident, "); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -9313,8 +9312,8 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables) appendPQExpBufferStr(q, "'' AS attcompression,\n"); - appendPQExpBufferStr(q, - "a.attidentity,\n"); + appendPQExpBufferStr(q, + "a.attidentity,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(q, @@ -10717,73 +10716,73 @@ getAdditionalACLs(Archive *fout) PQclear(res); /* Fetch initial-privileges data */ - printfPQExpBuffer(query, - "SELECT objoid, classoid, objsubid, privtype, initprivs " - "FROM pg_init_privs"); + printfPQExpBuffer(query, + "SELECT objoid, classoid, objsubid, privtype, initprivs " + "FROM pg_init_privs"); - res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); + res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); - ntups = PQntuples(res); - for (i = 0; i < ntups; i++) - { - Oid objoid = atooid(PQgetvalue(res, i, 0)); - Oid classoid = atooid(PQgetvalue(res, i, 1)); - int objsubid = atoi(PQgetvalue(res, i, 2)); - char privtype = *(PQgetvalue(res, i, 3)); - char *initprivs = PQgetvalue(res, i, 4); - CatalogId objId; - DumpableObject *dobj; + ntups = PQntuples(res); + for (i = 0; i < ntups; i++) + { + Oid objoid = atooid(PQgetvalue(res, i, 0)); + Oid classoid = atooid(PQgetvalue(res, i, 1)); + int objsubid = atoi(PQgetvalue(res, i, 2)); + char privtype = *(PQgetvalue(res, i, 3)); + char *initprivs = PQgetvalue(res, i, 4); + CatalogId objId; + DumpableObject *dobj; - objId.tableoid = classoid; - objId.oid = objoid; - dobj = findObjectByCatalogId(objId); - /* OK to ignore entries we haven't got a DumpableObject for */ - if (dobj) + objId.tableoid = classoid; + objId.oid = objoid; + dobj = findObjectByCatalogId(objId); + /* OK to ignore entries we haven't got a DumpableObject for */ + if (dobj) + { + /* Cope with sub-object initprivs */ + if (objsubid != 0) { - /* Cope with sub-object initprivs */ - if (objsubid != 0) - { - if (dobj->objType == DO_TABLE) - { - /* For a column initprivs, set the table's ACL flags */ - dobj->components |= DUMP_COMPONENT_ACL; - ((TableInfo *) dobj)->hascolumnACLs = true; - } - else - pg_log_warning("unsupported pg_init_privs entry: %u %u %d", - classoid, objoid, objsubid); - continue; - } - - /* - * We ignore any pg_init_privs.initprivs entry for the public - * schema, as explained in getNamespaces(). - */ - if (dobj->objType == DO_NAMESPACE && - strcmp(dobj->name, "public") == 0) - continue; - - /* Else it had better be of a type we think has ACLs */ - if (dobj->objType == DO_NAMESPACE || - dobj->objType == DO_TYPE || - dobj->objType == DO_FUNC || - dobj->objType == DO_AGG || - dobj->objType == DO_TABLE || - dobj->objType == DO_PROCLANG || - dobj->objType == DO_FDW || - dobj->objType == DO_FOREIGN_SERVER) + if (dobj->objType == DO_TABLE) { - DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; - - daobj->dacl.privtype = privtype; - daobj->dacl.initprivs = pstrdup(initprivs); + /* For a column initprivs, set the table's ACL flags */ + dobj->components |= DUMP_COMPONENT_ACL; + ((TableInfo *) dobj)->hascolumnACLs = true; } else pg_log_warning("unsupported pg_init_privs entry: %u %u %d", classoid, objoid, objsubid); + continue; + } + + /* + * We ignore any pg_init_privs.initprivs entry for the public + * schema, as explained in getNamespaces(). + */ + if (dobj->objType == DO_NAMESPACE && + strcmp(dobj->name, "public") == 0) + continue; + + /* Else it had better be of a type we think has ACLs */ + if (dobj->objType == DO_NAMESPACE || + dobj->objType == DO_TYPE || + dobj->objType == DO_FUNC || + dobj->objType == DO_AGG || + dobj->objType == DO_TABLE || + dobj->objType == DO_PROCLANG || + dobj->objType == DO_FDW || + dobj->objType == DO_FOREIGN_SERVER) + { + DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; + + daobj->dacl.privtype = privtype; + daobj->dacl.initprivs = pstrdup(initprivs); } + else + pg_log_warning("unsupported pg_init_privs entry: %u %u %d", + classoid, objoid, objsubid); } - PQclear(res); + } + PQclear(res); destroyPQExpBuffer(query); } @@ -11128,8 +11127,8 @@ dumpRelationStats_dumper(Archive *fout, const void *userArg, const TocEntry *te) * The results must be in the order of the relations supplied in the * parameters to ensure we remain in sync as we walk through the TOC. * - * For versions before 19, the redundant filter clause on s.tablename = - * ANY(...) seems sufficient to convince the planner to use + * For versions before 19, the redundant filter clause on s.tablename + * = ANY(...) seems sufficient to convince the planner to use * pg_class_relname_nsp_index, which avoids a full scan of pg_stats. * In newer versions, pg_stats returns the table OIDs, eliminating the * need for that hack. @@ -13469,11 +13468,11 @@ dumpFunc(Archive *fout, const FuncInfo *finfo) "pg_catalog.pg_get_function_result(p.oid) AS funcresult,\n" "proleakproof,\n"); - appendPQExpBufferStr(query, - "array_to_string(protrftypes, ' ') AS protrftypes,\n"); + appendPQExpBufferStr(query, + "array_to_string(protrftypes, ' ') AS protrftypes,\n"); - appendPQExpBufferStr(query, - "proparallel,\n"); + appendPQExpBufferStr(query, + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -14963,9 +14962,9 @@ dumpCollation(Archive *fout, const CollInfo *collinfo) /* Get collation-specific details */ appendPQExpBufferStr(query, "SELECT "); - appendPQExpBufferStr(query, - "collprovider, " - "collversion, "); + appendPQExpBufferStr(query, + "collprovider, " + "collversion, "); if (fout->remoteVersion >= 120000) appendPQExpBufferStr(query, @@ -15372,23 +15371,23 @@ dumpAgg(Archive *fout, const AggInfo *agginfo) "pg_catalog.pg_get_function_arguments(p.oid) AS funcargs,\n" "pg_catalog.pg_get_function_identity_arguments(p.oid) AS funciargs,\n"); - appendPQExpBufferStr(query, - "aggkind,\n" - "aggmtransfn,\n" - "aggminvtransfn,\n" - "aggmfinalfn,\n" - "aggmtranstype::pg_catalog.regtype,\n" - "aggfinalextra,\n" - "aggmfinalextra,\n" - "aggtransspace,\n" - "aggmtransspace,\n" - "aggminitval,\n"); + appendPQExpBufferStr(query, + "aggkind,\n" + "aggmtransfn,\n" + "aggminvtransfn,\n" + "aggmfinalfn,\n" + "aggmtranstype::pg_catalog.regtype,\n" + "aggfinalextra,\n" + "aggmfinalextra,\n" + "aggtransspace,\n" + "aggmtransspace,\n" + "aggminitval,\n"); - appendPQExpBufferStr(query, - "aggcombinefn,\n" - "aggserialfn,\n" - "aggdeserialfn,\n" - "proparallel,\n"); + appendPQExpBufferStr(query, + "aggcombinefn,\n" + "aggserialfn,\n" + "aggdeserialfn,\n" + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -16848,30 +16847,30 @@ dumpTable(Archive *fout, const TableInfo *tbinfo) appendPQExpBufferStr(query, "PREPARE getColumnACLs(pg_catalog.oid) AS\n"); - /* - * In principle we should call acldefault('c', relowner) to - * get the default ACL for a column. However, we don't - * currently store the numeric OID of the relowner in - * TableInfo. We could convert the owner name using regrole, - * but that creates a risk of failure due to concurrent role - * renames. Given that the default ACL for columns is empty - * and is likely to stay that way, it's not worth extra cycles - * and risk to avoid hard-wiring that knowledge here. - */ - appendPQExpBufferStr(query, - "SELECT at.attname, " - "at.attacl, " - "'{}' AS acldefault, " - "pip.privtype, pip.initprivs " - "FROM pg_catalog.pg_attribute at " - "LEFT JOIN pg_catalog.pg_init_privs pip ON " - "(at.attrelid = pip.objoid " - "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " - "AND at.attnum = pip.objsubid) " - "WHERE at.attrelid = $1 AND " - "NOT at.attisdropped " - "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " - "ORDER BY at.attnum"); + /* + * In principle we should call acldefault('c', relowner) to get + * the default ACL for a column. However, we don't currently + * store the numeric OID of the relowner in TableInfo. We could + * convert the owner name using regrole, but that creates a risk + * of failure due to concurrent role renames. Given that the + * default ACL for columns is empty and is likely to stay that + * way, it's not worth extra cycles and risk to avoid hard-wiring + * that knowledge here. + */ + appendPQExpBufferStr(query, + "SELECT at.attname, " + "at.attacl, " + "'{}' AS acldefault, " + "pip.privtype, pip.initprivs " + "FROM pg_catalog.pg_attribute at " + "LEFT JOIN pg_catalog.pg_init_privs pip ON " + "(at.attrelid = pip.objoid " + "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " + "AND at.attnum = pip.objsubid) " + "WHERE at.attrelid = $1 AND " + "NOT at.attisdropped " + "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " + "ORDER BY at.attnum"); ExecuteSqlStatement(fout, query->data); @@ -19165,7 +19164,7 @@ collectSequences(Archive *fout) * pg_get_sequence_data(), but we only do so for non-schema-only dumps. */ if (fout->remoteVersion < 180000 || - (!fout->dopt->dumpData && !fout->dopt->sequence_data)) + (!fout->dopt->dumpData && !fout->dopt->sequence_data)) query = "SELECT seqrelid, format_type(seqtypid, NULL), " "seqstart, seqincrement, " "seqmax, seqmin, " @@ -19227,15 +19226,14 @@ dumpSequence(Archive *fout, const TableInfo *tbinfo) qseqname = pg_strdup(fmtId(tbinfo->dobj.name)); /* - * The sequence information is gathered in a sorted - * table before any calls to dumpSequence(). See collectSequences() for - * more information. + * The sequence information is gathered in a sorted table before any calls + * to dumpSequence(). See collectSequences() for more information. */ - Assert(sequences); + Assert(sequences); - key.oid = tbinfo->dobj.catId.oid; - seq = bsearch(&key, sequences, nsequences, - sizeof(SequenceItem), SequenceItemCmp); + key.oid = tbinfo->dobj.catId.oid; + seq = bsearch(&key, sequences, nsequences, + sizeof(SequenceItem), SequenceItemCmp); /* Calculate default limits for a sequence of this type */ is_ascending = (seq->incby >= 0); diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c index e68937c9934..afcd9a218d8 100644 --- a/src/bin/pg_dump/pg_dumpall.c +++ b/src/bin/pg_dump/pg_dumpall.c @@ -785,11 +785,11 @@ dropRoles(PGconn *conn) int i_rolname; int i; - printfPQExpBuffer(buf, - "SELECT rolname " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 1", role_catalog); + printfPQExpBuffer(buf, + "SELECT rolname " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 1", role_catalog); res = executeQuery(conn, buf->data); @@ -843,16 +843,16 @@ dumpRoles(PGconn *conn) * Notes: rolconfig is dumped later, and pg_authid must be used for * extracting rolcomment regardless of role_catalog. */ - printfPQExpBuffer(buf, - "SELECT oid, rolname, rolsuper, rolinherit, " - "rolcreaterole, rolcreatedb, " - "rolcanlogin, rolconnlimit, rolpassword, " - "rolvaliduntil, rolreplication, rolbypassrls, " - "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " - "rolname = current_user AS is_current_user " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 2", role_catalog); + printfPQExpBuffer(buf, + "SELECT oid, rolname, rolsuper, rolinherit, " + "rolcreaterole, rolcreatedb, " + "rolcanlogin, rolconnlimit, rolpassword, " + "rolvaliduntil, rolreplication, rolbypassrls, " + "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " + "rolname = current_user AS is_current_user " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 2", role_catalog); res = executeQuery(conn, buf->data); diff --git a/src/bin/pg_upgrade/check.c b/src/bin/pg_upgrade/check.c index 786c1474829..f725f5ee3e2 100644 --- a/src/bin/pg_upgrade/check.c +++ b/src/bin/pg_upgrade/check.c @@ -1475,15 +1475,15 @@ check_for_incompatible_polymorphics(ClusterInfo *cluster) ", 'array_cat(anyarray,anyarray)'" ", 'array_prepend(anyelement,anyarray)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_remove(anyarray,anyelement)'" - ", 'array_replace(anyarray,anyelement,anyelement)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_remove(anyarray,anyelement)'" + ", 'array_replace(anyarray,anyelement,anyelement)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_position(anyarray,anyelement)'" - ", 'array_position(anyarray,anyelement,integer)'" - ", 'array_positions(anyarray,anyelement)'" - ", 'width_bucket(anyelement,anyarray)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_position(anyarray,anyelement)'" + ", 'array_position(anyarray,anyelement,integer)'" + ", 'array_positions(anyarray,anyelement)'" + ", 'width_bucket(anyelement,anyarray)'"); /* * The query below hardcodes FirstNormalObjectId as 16384 rather than diff --git a/src/bin/pg_upgrade/controldata.c b/src/bin/pg_upgrade/controldata.c index 8f81c9e9582..02ea02df60f 100644 --- a/src/bin/pg_upgrade/controldata.c +++ b/src/bin/pg_upgrade/controldata.c @@ -228,7 +228,7 @@ get_control_data(ClusterInfo *cluster) p++; /* remove ':' char */ cluster->controldata.chkpnt_nxtepoch = str2uint(p); - p = strchr(p, ':'); + p = strchr(p, ':'); if (p == NULL || strlen(p) <= 1) pg_fatal("%d: controldata retrieval problem", __LINE__); diff --git a/src/bin/pg_upgrade/exec.c b/src/bin/pg_upgrade/exec.c index 44355feea30..a1bdbf373e3 100644 --- a/src/bin/pg_upgrade/exec.c +++ b/src/bin/pg_upgrade/exec.c @@ -55,7 +55,7 @@ get_bin_version(ClusterInfo *cluster) if (sscanf(cmd_output, "%*s %*s %d.%d", &v1, &v2) < 1) pg_fatal("could not get pg_ctl version output from %s", cmd); - cluster->bin_version = v1 * 10000; + cluster->bin_version = v1 * 10000; } @@ -344,8 +344,8 @@ check_data_dir(ClusterInfo *cluster) check_single_dir(pg_data, "pg_subtrans"); check_single_dir(pg_data, PG_TBLSPC_DIR); check_single_dir(pg_data, "pg_twophase"); - check_single_dir(pg_data, "pg_wal"); - check_single_dir(pg_data, "pg_xact"); + check_single_dir(pg_data, "pg_wal"); + check_single_dir(pg_data, "pg_xact"); } @@ -385,7 +385,7 @@ check_bin_dir(ClusterInfo *cluster, bool check_versions) */ get_bin_version(cluster); - check_exec(cluster->bindir, "pg_resetwal", check_versions); + check_exec(cluster->bindir, "pg_resetwal", check_versions); if (cluster == &new_cluster) { diff --git a/src/bin/pg_upgrade/multixact_rewrite.c b/src/bin/pg_upgrade/multixact_rewrite.c index c45b3183684..c7a1416494d 100644 --- a/src/bin/pg_upgrade/multixact_rewrite.c +++ b/src/bin/pg_upgrade/multixact_rewrite.c @@ -61,52 +61,52 @@ rewrite_multixacts(MultiXactId from_multi, MultiXactId to_multi) * Convert old multixids, if needed, by reading them one-by-one from the * old cluster. */ - old_reader = AllocOldMultiXactRead(old_cluster.pgdata, - old_cluster.controldata.chkpnt_nxtmulti, - old_cluster.controldata.chkpnt_nxtmxoff); + old_reader = AllocOldMultiXactRead(old_cluster.pgdata, + old_cluster.controldata.chkpnt_nxtmulti, + old_cluster.controldata.chkpnt_nxtmxoff); - for (MultiXactId multi = from_multi; multi != to_multi;) - { - MultiXactMember member; - bool multixid_valid; - - /* - * Read this multixid's members. - * - * Locking-only XIDs that may be part of multi-xids don't matter - * after upgrade, as there can be no transactions running across - * upgrade. So as a small optimization, we only read one member - * from each multixid: the one updating one, or if there was no - * update, arbitrarily the first locking xid. - */ - multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); + for (MultiXactId multi = from_multi; multi != to_multi;) + { + MultiXactMember member; + bool multixid_valid; - /* - * Write the new offset to pg_multixact/offsets. - * - * Even if this multixid is invalid, we still need to write its - * offset if the *previous* multixid was valid. That's because - * when reading a multixid, the number of members is calculated - * from the difference between the two offsets. - */ - RecordMultiXactOffset(offsets_writer, multi, - (multixid_valid || prev_multixid_valid) ? next_offset : 0); + /* + * Read this multixid's members. + * + * Locking-only XIDs that may be part of multi-xids don't matter after + * upgrade, as there can be no transactions running across upgrade. So + * as a small optimization, we only read one member from each + * multixid: the one updating one, or if there was no update, + * arbitrarily the first locking xid. + */ + multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); - /* Write the members */ - if (multixid_valid) - { - RecordMultiXactMembers(members_writer, next_offset, 1, &member); - next_offset += 1; - } + /* + * Write the new offset to pg_multixact/offsets. + * + * Even if this multixid is invalid, we still need to write its offset + * if the *previous* multixid was valid. That's because when reading + * a multixid, the number of members is calculated from the difference + * between the two offsets. + */ + RecordMultiXactOffset(offsets_writer, multi, + (multixid_valid || prev_multixid_valid) ? next_offset : 0); - /* Advance to next multixid, handling wraparound */ - multi++; - if (multi < FirstMultiXactId) - multi = FirstMultiXactId; - prev_multixid_valid = multixid_valid; + /* Write the members */ + if (multixid_valid) + { + RecordMultiXactMembers(members_writer, next_offset, 1, &member); + next_offset += 1; } - FreeOldMultiXactReader(old_reader); + /* Advance to next multixid, handling wraparound */ + multi++; + if (multi < FirstMultiXactId) + multi = FirstMultiXactId; + prev_multixid_valid = multixid_valid; + } + + FreeOldMultiXactReader(old_reader); /* Write the final 'next' offset to the last SLRU page */ RecordMultiXactOffset(offsets_writer, to_multi, diff --git a/src/bin/pg_upgrade/pg_upgrade.c b/src/bin/pg_upgrade/pg_upgrade.c index c6af9035665..7366fd4627c 100644 --- a/src/bin/pg_upgrade/pg_upgrade.c +++ b/src/bin/pg_upgrade/pg_upgrade.c @@ -833,7 +833,7 @@ copy_xact_xlog_xid(void) * Determine the range of multixacts to convert. */ nxtmulti = old_cluster.controldata.chkpnt_nxtmulti; - oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; + oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; /* handle wraparound */ if (nxtmulti < FirstMultiXactId) nxtmulti = FirstMultiXactId; @@ -898,15 +898,15 @@ set_frozenxids(void) int i_datname; int i_datallowconn; - prep_status("Setting frozenxid and minmxid counters in new cluster"); + prep_status("Setting frozenxid and minmxid counters in new cluster"); conn_template1 = connectToServer(&new_cluster, "template1"); - /* set pg_database.datfrozenxid */ - PQclear(executeQueryOrDie(conn_template1, - "UPDATE pg_catalog.pg_database " - "SET datfrozenxid = '%u'", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_database.datfrozenxid */ + PQclear(executeQueryOrDie(conn_template1, + "UPDATE pg_catalog.pg_database " + "SET datfrozenxid = '%u'", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_database.datminmxid */ PQclear(executeQueryOrDie(conn_template1, @@ -942,16 +942,16 @@ set_frozenxids(void) conn = connectToServer(&new_cluster, datname); - /* set pg_class.relfrozenxid */ - PQclear(executeQueryOrDie(conn, - "UPDATE pg_catalog.pg_class " - "SET relfrozenxid = '%u' " - /* only heap, materialized view, and TOAST are vacuumed */ - "WHERE relkind IN (" - CppAsString2(RELKIND_RELATION) ", " - CppAsString2(RELKIND_MATVIEW) ", " - CppAsString2(RELKIND_TOASTVALUE) ")", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_class.relfrozenxid */ + PQclear(executeQueryOrDie(conn, + "UPDATE pg_catalog.pg_class " + "SET relfrozenxid = '%u' " + /* only heap, materialized view, and TOAST are vacuumed */ + "WHERE relkind IN (" + CppAsString2(RELKIND_RELATION) ", " + CppAsString2(RELKIND_MATVIEW) ", " + CppAsString2(RELKIND_TOASTVALUE) ")", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_class.relminmxid */ PQclear(executeQueryOrDie(conn, diff --git a/src/bin/pg_upgrade/relfilenumber.c b/src/bin/pg_upgrade/relfilenumber.c index ec2ff7acb21..6c467bdc8a5 100644 --- a/src/bin/pg_upgrade/relfilenumber.c +++ b/src/bin/pg_upgrade/relfilenumber.c @@ -587,32 +587,32 @@ transfer_relfile(FileNameMap *map, const char *type_suffix) /* Copying files might take some time, so give feedback. */ pg_log(PG_STATUS, "%s", old_file); - switch (user_opts.transfer_mode) - { - case TRANSFER_MODE_CLONE: - pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", - old_file, new_file); - cloneFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", - old_file, new_file); - copyFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY_FILE_RANGE: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", - old_file, new_file); - copyFileByRange(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_LINK: - pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", - old_file, new_file); - linkFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_SWAP: - /* swap mode is handled in its own code path */ - pg_fatal("should never happen"); - break; - } + switch (user_opts.transfer_mode) + { + case TRANSFER_MODE_CLONE: + pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", + old_file, new_file); + cloneFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", + old_file, new_file); + copyFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY_FILE_RANGE: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", + old_file, new_file); + copyFileByRange(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_LINK: + pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", + old_file, new_file); + linkFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_SWAP: + /* swap mode is handled in its own code path */ + pg_fatal("should never happen"); + break; + } } } diff --git a/src/bin/pg_upgrade/t/006_transfer_modes.pl b/src/bin/pg_upgrade/t/006_transfer_modes.pl index 9efa5dc863c..360d05c4b68 100644 --- a/src/bin/pg_upgrade/t/006_transfer_modes.pl +++ b/src/bin/pg_upgrade/t/006_transfer_modes.pl @@ -29,10 +29,8 @@ sub test_mode } $new->init(); - $new->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); - $old->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); + $new->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); + $old->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); # We can only test security labels if both the old and new installations # have dummy_seclabel. @@ -76,15 +74,14 @@ sub test_mode "CREATE TABLE test4 AS SELECT generate_series(400, 502)"); } - $old->safe_psql('postgres', - "CREATE TABLESPACE inplc_tblspc LOCATION ''"); - $old->safe_psql('postgres', - "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); - $old->safe_psql('postgres', - "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" - ); - $old->safe_psql('testdb3', - "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); + $old->safe_psql('postgres', "CREATE TABLESPACE inplc_tblspc LOCATION ''"); + $old->safe_psql('postgres', + "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); + $old->safe_psql('postgres', + "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" + ); + $old->safe_psql('testdb3', + "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); # While we are here, test handling of large objects. $old->safe_psql( @@ -152,12 +149,10 @@ sub test_mode } # Tests for in-place tablespaces. - $result = - $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); - is($result, '104', "test5 data after pg_upgrade $mode"); - $result = - $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); - is($result, '105', "test6 data after pg_upgrade $mode"); + $result = $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); + is($result, '104', "test5 data after pg_upgrade $mode"); + $result = $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); + is($result, '105', "test6 data after pg_upgrade $mode"); # Tests for large objects $result = $new->safe_psql('postgres', "SELECT lo_get(4532)"); diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index 44ef11d980e..c90bf8bbde2 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -6278,23 +6278,22 @@ get_create_object_cmd(EditableObjectType obj_type, Oid oid, * ensure the right view gets replaced. Also, check relation kind * to be sure it's a view. * - * Views may have WITH [LOCAL|CASCADED] - * CHECK OPTION. These are not part of the view definition - * returned by pg_get_viewdef() and so need to be retrieved - * separately. Materialized views may have - * arbitrary storage parameter reloptions. + * Views may have WITH [LOCAL|CASCADED] CHECK OPTION. These are + * not part of the view definition returned by pg_get_viewdef() + * and so need to be retrieved separately. Materialized views may + * have arbitrary storage parameter reloptions. */ printfPQExpBuffer(query, "/* %s */\n", _("Get view's definition and details")); - appendPQExpBuffer(query, - "SELECT nspname, relname, relkind, " - "pg_catalog.pg_get_viewdef(c.oid, true), " - "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " - "FROM pg_catalog.pg_class c " - "LEFT JOIN pg_catalog.pg_namespace n " - "ON c.relnamespace = n.oid WHERE c.oid = %u", - oid); + appendPQExpBuffer(query, + "SELECT nspname, relname, relkind, " + "pg_catalog.pg_get_viewdef(c.oid, true), " + "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " + "FROM pg_catalog.pg_class c " + "LEFT JOIN pg_catalog.pg_namespace n " + "ON c.relnamespace = n.oid WHERE c.oid = %u", + oid); break; } diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index ce99137c613..ac0c55e7aa5 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -387,19 +387,19 @@ describeFunctions(const char *functypes, const char *func_pattern, gettext_noop("stable"), gettext_noop("volatile"), gettext_noop("Volatility")); - appendPQExpBuffer(&buf, - ",\n CASE\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" - " END as \"%s\"", - gettext_noop("restricted"), - gettext_noop("safe"), - gettext_noop("unsafe"), - gettext_noop("Parallel")); + appendPQExpBuffer(&buf, + ",\n CASE\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" + " END as \"%s\"", + gettext_noop("restricted"), + gettext_noop("safe"), + gettext_noop("unsafe"), + gettext_noop("Parallel")); appendPQExpBuffer(&buf, ",\n pg_catalog.pg_get_userbyid(p.proowner) as \"%s\"" ",\n CASE WHEN prosecdef THEN '%s' ELSE '%s' END AS \"%s\"" @@ -599,8 +599,8 @@ describeFunctions(const char *functypes, const char *func_pattern, myopt.title = _("List of functions"); myopt.translate_header = true; - myopt.translate_columns = translate_columns; - myopt.n_translate_columns = lengthof(translate_columns); + myopt.translate_columns = translate_columns; + myopt.n_translate_columns = lengthof(translate_columns); printQuery(res, &myopt, pset.queryFout, false, pset.logfile); @@ -1086,38 +1086,38 @@ permissionsList(const char *pattern, bool showSystem) " ), E'\\n') AS \"%s\"", gettext_noop("Column privileges")); - appendPQExpBuffer(&buf, - ",\n pg_catalog.array_to_string(ARRAY(\n" - " SELECT polname\n" - " || CASE WHEN NOT polpermissive THEN\n" - " E' (RESTRICTIVE)'\n" - " ELSE '' END\n" - " || CASE WHEN polcmd != '*' THEN\n" - " E' (' || polcmd::pg_catalog.text || E'):'\n" - " ELSE E':'\n" - " END\n" - " || CASE WHEN polqual IS NOT NULL THEN\n" - " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" - " ELSE E''\n" - " END\n" - " || CASE WHEN polwithcheck IS NOT NULL THEN\n" - " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" - " ELSE E''\n" - " END" - " || CASE WHEN polroles <> '{0}' THEN\n" - " E'\\n to: ' || pg_catalog.array_to_string(\n" - " ARRAY(\n" - " SELECT rolname\n" - " FROM pg_catalog.pg_roles\n" - " WHERE oid = ANY (polroles)\n" - " ORDER BY 1\n" - " ), E', ')\n" - " ELSE E''\n" - " END\n" - " FROM pg_catalog.pg_policy pol\n" - " WHERE polrelid = c.oid), E'\\n')\n" - " AS \"%s\"", - gettext_noop("Policies")); + appendPQExpBuffer(&buf, + ",\n pg_catalog.array_to_string(ARRAY(\n" + " SELECT polname\n" + " || CASE WHEN NOT polpermissive THEN\n" + " E' (RESTRICTIVE)'\n" + " ELSE '' END\n" + " || CASE WHEN polcmd != '*' THEN\n" + " E' (' || polcmd::pg_catalog.text || E'):'\n" + " ELSE E':'\n" + " END\n" + " || CASE WHEN polqual IS NOT NULL THEN\n" + " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" + " ELSE E''\n" + " END\n" + " || CASE WHEN polwithcheck IS NOT NULL THEN\n" + " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" + " ELSE E''\n" + " END" + " || CASE WHEN polroles <> '{0}' THEN\n" + " E'\\n to: ' || pg_catalog.array_to_string(\n" + " ARRAY(\n" + " SELECT rolname\n" + " FROM pg_catalog.pg_roles\n" + " WHERE oid = ANY (polroles)\n" + " ORDER BY 1\n" + " ), E', ')\n" + " ELSE E''\n" + " END\n" + " FROM pg_catalog.pg_policy pol\n" + " WHERE polrelid = c.oid), E'\\n')\n" + " AS \"%s\"", + gettext_noop("Policies")); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_class c\n" " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n" @@ -1675,27 +1675,27 @@ describeOneTableDetails(const char *schemaname, char *footers[3] = {NULL, NULL, NULL}; printfPQExpBuffer(&buf, "/* %s */\n", _("Get sequence information")); - appendPQExpBuffer(&buf, - "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" - " seqstart AS \"%s\",\n" - " seqmin AS \"%s\",\n" - " seqmax AS \"%s\",\n" - " seqincrement AS \"%s\",\n" - " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" - " seqcache AS \"%s\"\n", - gettext_noop("Type"), - gettext_noop("Start"), - gettext_noop("Minimum"), - gettext_noop("Maximum"), - gettext_noop("Increment"), - gettext_noop("yes"), - gettext_noop("no"), - gettext_noop("Cycles?"), - gettext_noop("Cache")); - appendPQExpBuffer(&buf, - "FROM pg_catalog.pg_sequence\n" - "WHERE seqrelid = '%s';", - oid); + appendPQExpBuffer(&buf, + "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" + " seqstart AS \"%s\",\n" + " seqmin AS \"%s\",\n" + " seqmax AS \"%s\",\n" + " seqincrement AS \"%s\",\n" + " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" + " seqcache AS \"%s\"\n", + gettext_noop("Type"), + gettext_noop("Start"), + gettext_noop("Minimum"), + gettext_noop("Maximum"), + gettext_noop("Increment"), + gettext_noop("yes"), + gettext_noop("no"), + gettext_noop("Cycles?"), + gettext_noop("Cache")); + appendPQExpBuffer(&buf, + "FROM pg_catalog.pg_sequence\n" + "WHERE seqrelid = '%s';", + oid); res = PSQLexec(buf.data); if (!res) @@ -1913,7 +1913,7 @@ describeOneTableDetails(const char *schemaname, appendPQExpBufferStr(&buf, ",\n (SELECT c.collname FROM pg_catalog.pg_collation c, pg_catalog.pg_type t\n" " WHERE c.oid = a.attcollation AND t.oid = a.atttypid AND a.attcollation <> t.typcollation) AS attcollation"); attcoll_col = cols++; - appendPQExpBufferStr(&buf, ",\n a.attidentity"); + appendPQExpBufferStr(&buf, ",\n a.attidentity"); attidentity_col = cols++; if (pset.sversion >= 120000) appendPQExpBufferStr(&buf, ",\n a.attgenerated"); @@ -2326,7 +2326,7 @@ describeOneTableDetails(const char *schemaname, CppAsString2(CONSTRAINT_EXCLUSION) ") AND " "condeferred) AS condeferred,\n"); - appendPQExpBufferStr(&buf, "i.indisreplident,\n"); + appendPQExpBufferStr(&buf, "i.indisreplident,\n"); if (pset.sversion >= 150000) appendPQExpBufferStr(&buf, "i.indnullsnotdistinct,\n"); @@ -2431,7 +2431,7 @@ describeOneTableDetails(const char *schemaname, "pg_catalog.pg_get_indexdef(i.indexrelid, 0, true),\n " "pg_catalog.pg_get_constraintdef(con.oid, true), " "contype, condeferrable, condeferred"); - appendPQExpBufferStr(&buf, ", i.indisreplident"); + appendPQExpBufferStr(&buf, ", i.indisreplident"); appendPQExpBufferStr(&buf, ", c2.reltablespace"); if (pset.sversion >= 180000) appendPQExpBufferStr(&buf, ", con.conperiod"); @@ -2682,81 +2682,80 @@ describeOneTableDetails(const char *schemaname, PQclear(result); /* print any row-level policies */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get row-level policies for this table")); - appendPQExpBufferStr(&buf, "SELECT pol.polname,"); - appendPQExpBufferStr(&buf, - " pol.polpermissive,\n"); - appendPQExpBuffer(&buf, - " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" - " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" - " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" - " CASE pol.polcmd\n" - " WHEN 'r' THEN 'SELECT'\n" - " WHEN 'a' THEN 'INSERT'\n" - " WHEN 'w' THEN 'UPDATE'\n" - " WHEN 'd' THEN 'DELETE'\n" - " END AS cmd\n" - "FROM pg_catalog.pg_policy pol\n" - "WHERE pol.polrelid = '%s' ORDER BY 1;", - oid); + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get row-level policies for this table")); + appendPQExpBufferStr(&buf, "SELECT pol.polname,"); + appendPQExpBufferStr(&buf, + " pol.polpermissive,\n"); + appendPQExpBuffer(&buf, + " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" + " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" + " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" + " CASE pol.polcmd\n" + " WHEN 'r' THEN 'SELECT'\n" + " WHEN 'a' THEN 'INSERT'\n" + " WHEN 'w' THEN 'UPDATE'\n" + " WHEN 'd' THEN 'DELETE'\n" + " END AS cmd\n" + "FROM pg_catalog.pg_policy pol\n" + "WHERE pol.polrelid = '%s' ORDER BY 1;", + oid); - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - /* - * Handle cases where RLS is enabled and there are policies, or - * there aren't policies, or RLS isn't enabled but there are - * policies - */ - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies:")); + /* + * Handle cases where RLS is enabled and there are policies, or there + * aren't policies, or RLS isn't enabled but there are policies + */ + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies:")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled):")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled):")); - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); - if (!tableinfo.rowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (row security disabled):")); + if (!tableinfo.rowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (row security disabled):")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " POLICY \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " POLICY \"%s\"", + PQgetvalue(result, i, 0)); - if (*(PQgetvalue(result, i, 1)) == 'f') - appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); + if (*(PQgetvalue(result, i, 1)) == 'f') + appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); - if (!PQgetisnull(result, i, 5)) - appendPQExpBuffer(&buf, " FOR %s", - PQgetvalue(result, i, 5)); + if (!PQgetisnull(result, i, 5)) + appendPQExpBuffer(&buf, " FOR %s", + PQgetvalue(result, i, 5)); - if (!PQgetisnull(result, i, 2)) - { - appendPQExpBuffer(&buf, "\n TO %s", - PQgetvalue(result, i, 2)); - } + if (!PQgetisnull(result, i, 2)) + { + appendPQExpBuffer(&buf, "\n TO %s", + PQgetvalue(result, i, 2)); + } - if (!PQgetisnull(result, i, 3)) - appendPQExpBuffer(&buf, "\n USING (%s)", - PQgetvalue(result, i, 3)); + if (!PQgetisnull(result, i, 3)) + appendPQExpBuffer(&buf, "\n USING (%s)", + PQgetvalue(result, i, 3)); - if (!PQgetisnull(result, i, 4)) - appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", - PQgetvalue(result, i, 4)); + if (!PQgetisnull(result, i, 4)) + appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", + PQgetvalue(result, i, 4)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* print any extended statistics */ if (pset.sversion >= 140000) @@ -3025,115 +3024,115 @@ describeOneTableDetails(const char *schemaname, } /* print any publications */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get publications that publish this table")); - if (pset.sversion >= 150000) + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get publications that publish this table")); + if (pset.sversion >= 150000) + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" + " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" + "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" + "UNION\n" + "SELECT pubname\n" + " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" + " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" + " (SELECT pg_catalog.string_agg(attname, ', ')\n" + " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" + " pg_catalog.pg_attribute\n" + " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" + " ELSE NULL END) " + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" + "WHERE pr.prrelid = '%s'\n", + oid, oid, oid); + + if (pset.sversion >= 190000) { + /* + * Skip entries where this relation appears in the + * publication's EXCEPT list. + */ appendPQExpBuffer(&buf, + " AND NOT pr.prexcept\n" + "UNION\n" "SELECT pubname\n" " , NULL\n" " , NULL\n" "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" - " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" - "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" - "UNION\n" - "SELECT pubname\n" - " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" - " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" - " (SELECT pg_catalog.string_agg(attname, ', ')\n" - " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" - " pg_catalog.pg_attribute\n" - " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" - " ELSE NULL END) " - "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" - "WHERE pr.prrelid = '%s'\n", + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + " AND NOT EXISTS (\n" + " SELECT 1\n" + " FROM pg_catalog.pg_publication_rel pr\n" + " WHERE pr.prpubid = p.oid AND\n" + " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" + "ORDER BY 1;", oid, oid, oid); - - if (pset.sversion >= 190000) - { - /* - * Skip entries where this relation appears in the - * publication's EXCEPT list. - */ - appendPQExpBuffer(&buf, - " AND NOT pr.prexcept\n" - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - " AND NOT EXISTS (\n" - " SELECT 1\n" - " FROM pg_catalog.pg_publication_rel pr\n" - " WHERE pr.prpubid = p.oid AND\n" - " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" - "ORDER BY 1;", - oid, oid, oid); - } - else - { - appendPQExpBuffer(&buf, - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - "ORDER BY 1;", - oid); - } } else { appendPQExpBuffer(&buf, + "UNION\n" "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - "WHERE pr.prrelid = '%s'\n" - "UNION ALL\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" + " , NULL\n" + " , NULL\n" "FROM pg_catalog.pg_publication p\n" "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" "ORDER BY 1;", - oid, oid); + oid); } + } + else + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + "WHERE pr.prrelid = '%s'\n" + "UNION ALL\n" + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + "ORDER BY 1;", + oid, oid); + } - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - if (tuples > 0) - printTableAddFooter(&cont, _("Included in publications:")); + if (tuples > 0) + printTableAddFooter(&cont, _("Included in publications:")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " \"%s\"", + PQgetvalue(result, i, 0)); - /* column list (if any) */ - if (!PQgetisnull(result, i, 2)) - appendPQExpBuffer(&buf, " (%s)", - PQgetvalue(result, i, 2)); + /* column list (if any) */ + if (!PQgetisnull(result, i, 2)) + appendPQExpBuffer(&buf, " (%s)", + PQgetvalue(result, i, 2)); - /* row filter (if any) */ - if (!PQgetisnull(result, i, 1)) - appendPQExpBuffer(&buf, " WHERE %s", - PQgetvalue(result, i, 1)); + /* row filter (if any) */ + if (!PQgetisnull(result, i, 1)) + appendPQExpBuffer(&buf, " WHERE %s", + PQgetvalue(result, i, 1)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* Print publications where the table is in the EXCEPT clause */ if (pset.sversion >= 190000) @@ -3805,7 +3804,7 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) ncols++; } appendPQExpBufferStr(&buf, "\n, r.rolreplication"); - appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); + appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_roles r\n"); @@ -3860,8 +3859,8 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) if (strcmp(PQgetvalue(res, i, (verbose ? 9 : 8)), "t") == 0) add_role_attribute(&buf, _("Replication")); - if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) - add_role_attribute(&buf, _("Bypass RLS")); + if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) + add_role_attribute(&buf, _("Bypass RLS")); conns = atoi(PQgetvalue(res, i, 6)); if (conns >= 0) @@ -5155,14 +5154,14 @@ listCollations(const char *pattern, bool verbose, bool showSystem) gettext_noop("Schema"), gettext_noop("Name")); - appendPQExpBuffer(&buf, - " CASE c.collprovider " - "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " - "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " - "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " - "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " - "END AS \"%s\",\n", - gettext_noop("Provider")); + appendPQExpBuffer(&buf, + " CASE c.collprovider " + "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " + "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " + "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " + "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " + "END AS \"%s\",\n", + gettext_noop("Provider")); appendPQExpBuffer(&buf, " c.collcollate AS \"%s\",\n" -- 2.50.1 (Apple Git-155) --aHl3HfeiUuO3zeNC-- ^ permalink raw reply [nested|flat] 59+ messages in thread
* [PATCH v6 4/4] run pgindent and pgperltidy @ 2026-06-30 18:24 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 59+ messages in thread From: Nathan Bossart @ 2026-06-30 18:24 UTC (permalink / raw) --- src/bin/pg_dump/pg_dump.c | 464 ++++++++++----------- src/bin/pg_dump/pg_dumpall.c | 30 +- src/bin/pg_upgrade/check.c | 16 +- src/bin/pg_upgrade/controldata.c | 2 +- src/bin/pg_upgrade/exec.c | 8 +- src/bin/pg_upgrade/multixact_rewrite.c | 80 ++-- src/bin/pg_upgrade/pg_upgrade.c | 34 +- src/bin/pg_upgrade/relfilenumber.c | 54 +-- src/bin/pg_upgrade/t/006_transfer_modes.pl | 33 +- src/bin/psql/command.c | 29 +- src/bin/psql/describe.c | 461 ++++++++++---------- 11 files changed, 601 insertions(+), 610 deletions(-) diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 65bd15ebfd2..5673268b467 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -1491,8 +1491,8 @@ setup_connection(Archive *AH, const char *dumpencoding, * Disable timeouts if supported. */ ExecuteSqlStatement(AH, "SET statement_timeout = 0"); - ExecuteSqlStatement(AH, "SET lock_timeout = 0"); - ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); + ExecuteSqlStatement(AH, "SET lock_timeout = 0"); + ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); if (AH->remoteVersion >= 170000) ExecuteSqlStatement(AH, "SET transaction_timeout = 0"); @@ -1505,10 +1505,10 @@ setup_connection(Archive *AH, const char *dumpencoding, /* * Adjust row-security mode, if supported. */ - if (dopt->enable_row_security) - ExecuteSqlStatement(AH, "SET row_security = on"); - else - ExecuteSqlStatement(AH, "SET row_security = off"); + if (dopt->enable_row_security) + ExecuteSqlStatement(AH, "SET row_security = on"); + else + ExecuteSqlStatement(AH, "SET row_security = off"); /* * For security reasons, we restrict the expansion of non-system views and @@ -1933,10 +1933,9 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) addObjectDependency(dobj, ext->dobj.dumpId); /* - * Mark the member object to have any non-initial ACLs - * dumped. (Any initial ACLs will be removed later, using data from - * pg_init_privs, so that we'll dump only the delta from the extension's - * initial setup.) + * Mark the member object to have any non-initial ACLs dumped. (Any + * initial ACLs will be removed later, using data from pg_init_privs, so + * that we'll dump only the delta from the extension's initial setup.) * * In binary upgrades, we still dump all components of the members * individually, since the idea is to exactly reproduce the database @@ -1953,7 +1952,7 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) if (fout->dopt->binary_upgrade) dobj->dump = ext->dobj.dump; else - dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); + dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); return true; } @@ -1987,9 +1986,9 @@ selectDumpableNamespace(NamespaceInfo *nsinfo, Archive *fout) else if (strcmp(nsinfo->dobj.name, "pg_catalog") == 0) { /* - * We dump out any ACLs defined in pg_catalog, if - * they are interesting (and not the original ACLs which were set at - * initdb time, see pg_init_privs). + * We dump out any ACLs defined in pg_catalog, if they are interesting + * (and not the original ACLs which were set at initdb time, see + * pg_init_privs). */ nsinfo->dobj.dump_contains = nsinfo->dobj.dump = DUMP_COMPONENT_ACL; } @@ -3296,7 +3295,7 @@ dumpDatabase(Archive *fout) "datcollate, datctype, datfrozenxid, " "datacl, acldefault('d', datdba) AS acldefault, " "datistemplate, datconnlimit, "); - appendPQExpBufferStr(dbQry, "datminmxid, "); + appendPQExpBufferStr(dbQry, "datminmxid, "); if (fout->remoteVersion >= 170000) appendPQExpBufferStr(dbQry, "datlocprovider, datlocale, datcollversion, "); else if (fout->remoteVersion >= 150000) @@ -3638,11 +3637,11 @@ dumpDatabase(Archive *fout) ii_oid, ii_relminmxid; - appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" - "FROM pg_catalog.pg_class\n" - "WHERE oid IN (%u, %u, %u, %u);\n", - LargeObjectRelationId, LargeObjectLOidPNIndexId, - LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); + appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" + "FROM pg_catalog.pg_class\n" + "WHERE oid IN (%u, %u, %u, %u);\n", + LargeObjectRelationId, LargeObjectLOidPNIndexId, + LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); lo_res = ExecuteSqlQuery(fout, loFrozenQry->data, PGRES_TUPLES_OK); @@ -4274,7 +4273,7 @@ getPolicies(Archive *fout, TableInfo tblinfo[], int numTables) printfPQExpBuffer(query, "SELECT pol.oid, pol.tableoid, pol.polrelid, pol.polname, pol.polcmd, "); - appendPQExpBufferStr(query, "pol.polpermissive, "); + appendPQExpBufferStr(query, "pol.polpermissive, "); appendPQExpBuffer(query, "CASE WHEN pol.polroles = '{0}' THEN NULL ELSE " " pg_catalog.array_to_string(ARRAY(SELECT pg_catalog.quote_ident(rolname) from pg_catalog.pg_roles WHERE oid = ANY(pol.polroles)), ', ') END AS polroles, " @@ -6633,9 +6632,9 @@ getAccessMethods(Archive *fout) * Select all access methods from pg_am table. */ appendPQExpBufferStr(query, "SELECT tableoid, oid, amname, "); - appendPQExpBufferStr(query, - "amtype, " - "amhandler::pg_catalog.regproc AS amhandler "); + appendPQExpBufferStr(query, + "amtype, " + "amhandler::pg_catalog.regproc AS amhandler "); appendPQExpBufferStr(query, "FROM pg_am"); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6827,35 +6826,35 @@ getAggregates(Archive *fout) * Find all interesting aggregates. See comment in getFuncs() for the * rationale behind the filtering logic. */ - agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" - : "p.proisagg"); + agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" + : "p.proisagg"); - appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " - "p.proname AS aggname, " - "p.pronamespace AS aggnamespace, " - "p.pronargs, p.proargtypes, " - "p.proowner, " - "p.proacl AS aggacl, " - "acldefault('f', p.proowner) AS acldefault " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s AND (" - "p.pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog') OR " - "p.proacl IS DISTINCT FROM pip.initprivs", - agg_check); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - " OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); - appendPQExpBufferChar(query, ')'); + appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " + "p.proname AS aggname, " + "p.pronamespace AS aggnamespace, " + "p.pronargs, p.proargtypes, " + "p.proowner, " + "p.proacl AS aggacl, " + "acldefault('f', p.proowner) AS acldefault " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s AND (" + "p.pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog') OR " + "p.proacl IS DISTINCT FROM pip.initprivs", + agg_check); + if (dopt->binary_upgrade) + appendPQExpBufferStr(query, + " OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6957,53 +6956,53 @@ getFuncs(Archive *fout) * include them, since we want to dump extension members individually in * that mode. Also, if they are used by casts or transforms then we need * to gather the information about them, though they won't be dumped if - * they are built-in. Also, include functions in - * pg_catalog if they have an ACL different from what's shown in - * pg_init_privs (so we have to join to pg_init_privs; annoying). + * they are built-in. Also, include functions in pg_catalog if they have + * an ACL different from what's shown in pg_init_privs (so we have to join + * to pg_init_privs; annoying). */ - not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" - : "NOT p.proisagg"); + not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" + : "NOT p.proisagg"); - appendPQExpBuffer(query, - "SELECT p.tableoid, p.oid, p.proname, p.prolang, " - "p.pronargs, p.proargtypes, p.prorettype, " - "p.proacl, " - "acldefault('f', p.proowner) AS acldefault, " - "p.pronamespace, " - "p.proowner " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s" - "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " - "WHERE classid = 'pg_proc'::regclass AND " - "objid = p.oid AND deptype = 'i')" - "\n AND (" - "\n pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog')" - "\n OR EXISTS (SELECT 1 FROM pg_cast" - "\n WHERE pg_cast.oid > %u " - "\n AND p.oid = pg_cast.castfunc)" - "\n OR EXISTS (SELECT 1 FROM pg_transform" - "\n WHERE pg_transform.oid > %u AND " - "\n (p.oid = pg_transform.trffromsql" - "\n OR p.oid = pg_transform.trftosql))", - not_agg_check, - g_last_builtin_oid, - g_last_builtin_oid); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); + appendPQExpBuffer(query, + "SELECT p.tableoid, p.oid, p.proname, p.prolang, " + "p.pronargs, p.proargtypes, p.prorettype, " + "p.proacl, " + "acldefault('f', p.proowner) AS acldefault, " + "p.pronamespace, " + "p.proowner " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s" + "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " + "WHERE classid = 'pg_proc'::regclass AND " + "objid = p.oid AND deptype = 'i')" + "\n AND (" + "\n pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog')" + "\n OR EXISTS (SELECT 1 FROM pg_cast" + "\n WHERE pg_cast.oid > %u " + "\n AND p.oid = pg_cast.castfunc)" + "\n OR EXISTS (SELECT 1 FROM pg_transform" + "\n WHERE pg_transform.oid > %u AND " + "\n (p.oid = pg_transform.trffromsql" + "\n OR p.oid = pg_transform.trftosql))", + not_agg_check, + g_last_builtin_oid, + g_last_builtin_oid); + if (dopt->binary_upgrade) appendPQExpBufferStr(query, - "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); - appendPQExpBufferChar(query, ')'); + "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferStr(query, + "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -7252,31 +7251,31 @@ getTables(Archive *fout, int *numTables) appendPQExpBufferStr(query, "c.relhasoids, "); - appendPQExpBufferStr(query, - "c.relispopulated, "); + appendPQExpBufferStr(query, + "c.relispopulated, "); - appendPQExpBufferStr(query, - "c.relreplident, "); + appendPQExpBufferStr(query, + "c.relreplident, "); - appendPQExpBufferStr(query, - "c.relrowsecurity, c.relforcerowsecurity, "); + appendPQExpBufferStr(query, + "c.relrowsecurity, c.relforcerowsecurity, "); - appendPQExpBufferStr(query, - "c.relminmxid, tc.relminmxid AS tminmxid, "); + appendPQExpBufferStr(query, + "c.relminmxid, tc.relminmxid AS tminmxid, "); - appendPQExpBufferStr(query, - "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); + appendPQExpBufferStr(query, + "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); - appendPQExpBufferStr(query, - "am.amname, "); + appendPQExpBufferStr(query, + "am.amname, "); - appendPQExpBufferStr(query, - "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); + appendPQExpBufferStr(query, + "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); - appendPQExpBufferStr(query, - "c.relispartition AS ispartition "); + appendPQExpBufferStr(query, + "c.relispartition AS ispartition "); /* * Left join to pg_depend to pick up dependency info linking sequences to @@ -7296,8 +7295,8 @@ getTables(Archive *fout, int *numTables) /* * Left join to pg_am to pick up the amname. */ - appendPQExpBufferStr(query, - "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); + appendPQExpBufferStr(query, + "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); /* * We purposefully ignore toast OIDs for partitioned tables; the reason is @@ -7868,8 +7867,8 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables) "t.reloptions AS indreloptions, "); - appendPQExpBufferStr(query, - "i.indisreplident, "); + appendPQExpBufferStr(query, + "i.indisreplident, "); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -9313,8 +9312,8 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables) appendPQExpBufferStr(q, "'' AS attcompression,\n"); - appendPQExpBufferStr(q, - "a.attidentity,\n"); + appendPQExpBufferStr(q, + "a.attidentity,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(q, @@ -10717,73 +10716,73 @@ getAdditionalACLs(Archive *fout) PQclear(res); /* Fetch initial-privileges data */ - printfPQExpBuffer(query, - "SELECT objoid, classoid, objsubid, privtype, initprivs " - "FROM pg_init_privs"); + printfPQExpBuffer(query, + "SELECT objoid, classoid, objsubid, privtype, initprivs " + "FROM pg_init_privs"); - res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); + res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); - ntups = PQntuples(res); - for (i = 0; i < ntups; i++) - { - Oid objoid = atooid(PQgetvalue(res, i, 0)); - Oid classoid = atooid(PQgetvalue(res, i, 1)); - int objsubid = atoi(PQgetvalue(res, i, 2)); - char privtype = *(PQgetvalue(res, i, 3)); - char *initprivs = PQgetvalue(res, i, 4); - CatalogId objId; - DumpableObject *dobj; + ntups = PQntuples(res); + for (i = 0; i < ntups; i++) + { + Oid objoid = atooid(PQgetvalue(res, i, 0)); + Oid classoid = atooid(PQgetvalue(res, i, 1)); + int objsubid = atoi(PQgetvalue(res, i, 2)); + char privtype = *(PQgetvalue(res, i, 3)); + char *initprivs = PQgetvalue(res, i, 4); + CatalogId objId; + DumpableObject *dobj; - objId.tableoid = classoid; - objId.oid = objoid; - dobj = findObjectByCatalogId(objId); - /* OK to ignore entries we haven't got a DumpableObject for */ - if (dobj) + objId.tableoid = classoid; + objId.oid = objoid; + dobj = findObjectByCatalogId(objId); + /* OK to ignore entries we haven't got a DumpableObject for */ + if (dobj) + { + /* Cope with sub-object initprivs */ + if (objsubid != 0) { - /* Cope with sub-object initprivs */ - if (objsubid != 0) - { - if (dobj->objType == DO_TABLE) - { - /* For a column initprivs, set the table's ACL flags */ - dobj->components |= DUMP_COMPONENT_ACL; - ((TableInfo *) dobj)->hascolumnACLs = true; - } - else - pg_log_warning("unsupported pg_init_privs entry: %u %u %d", - classoid, objoid, objsubid); - continue; - } - - /* - * We ignore any pg_init_privs.initprivs entry for the public - * schema, as explained in getNamespaces(). - */ - if (dobj->objType == DO_NAMESPACE && - strcmp(dobj->name, "public") == 0) - continue; - - /* Else it had better be of a type we think has ACLs */ - if (dobj->objType == DO_NAMESPACE || - dobj->objType == DO_TYPE || - dobj->objType == DO_FUNC || - dobj->objType == DO_AGG || - dobj->objType == DO_TABLE || - dobj->objType == DO_PROCLANG || - dobj->objType == DO_FDW || - dobj->objType == DO_FOREIGN_SERVER) + if (dobj->objType == DO_TABLE) { - DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; - - daobj->dacl.privtype = privtype; - daobj->dacl.initprivs = pstrdup(initprivs); + /* For a column initprivs, set the table's ACL flags */ + dobj->components |= DUMP_COMPONENT_ACL; + ((TableInfo *) dobj)->hascolumnACLs = true; } else pg_log_warning("unsupported pg_init_privs entry: %u %u %d", classoid, objoid, objsubid); + continue; + } + + /* + * We ignore any pg_init_privs.initprivs entry for the public + * schema, as explained in getNamespaces(). + */ + if (dobj->objType == DO_NAMESPACE && + strcmp(dobj->name, "public") == 0) + continue; + + /* Else it had better be of a type we think has ACLs */ + if (dobj->objType == DO_NAMESPACE || + dobj->objType == DO_TYPE || + dobj->objType == DO_FUNC || + dobj->objType == DO_AGG || + dobj->objType == DO_TABLE || + dobj->objType == DO_PROCLANG || + dobj->objType == DO_FDW || + dobj->objType == DO_FOREIGN_SERVER) + { + DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; + + daobj->dacl.privtype = privtype; + daobj->dacl.initprivs = pstrdup(initprivs); } + else + pg_log_warning("unsupported pg_init_privs entry: %u %u %d", + classoid, objoid, objsubid); } - PQclear(res); + } + PQclear(res); destroyPQExpBuffer(query); } @@ -11128,8 +11127,8 @@ dumpRelationStats_dumper(Archive *fout, const void *userArg, const TocEntry *te) * The results must be in the order of the relations supplied in the * parameters to ensure we remain in sync as we walk through the TOC. * - * For versions before 19, the redundant filter clause on s.tablename = - * ANY(...) seems sufficient to convince the planner to use + * For versions before 19, the redundant filter clause on s.tablename + * = ANY(...) seems sufficient to convince the planner to use * pg_class_relname_nsp_index, which avoids a full scan of pg_stats. * In newer versions, pg_stats returns the table OIDs, eliminating the * need for that hack. @@ -13469,11 +13468,11 @@ dumpFunc(Archive *fout, const FuncInfo *finfo) "pg_catalog.pg_get_function_result(p.oid) AS funcresult,\n" "proleakproof,\n"); - appendPQExpBufferStr(query, - "array_to_string(protrftypes, ' ') AS protrftypes,\n"); + appendPQExpBufferStr(query, + "array_to_string(protrftypes, ' ') AS protrftypes,\n"); - appendPQExpBufferStr(query, - "proparallel,\n"); + appendPQExpBufferStr(query, + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -14963,9 +14962,9 @@ dumpCollation(Archive *fout, const CollInfo *collinfo) /* Get collation-specific details */ appendPQExpBufferStr(query, "SELECT "); - appendPQExpBufferStr(query, - "collprovider, " - "collversion, "); + appendPQExpBufferStr(query, + "collprovider, " + "collversion, "); if (fout->remoteVersion >= 120000) appendPQExpBufferStr(query, @@ -15372,23 +15371,23 @@ dumpAgg(Archive *fout, const AggInfo *agginfo) "pg_catalog.pg_get_function_arguments(p.oid) AS funcargs,\n" "pg_catalog.pg_get_function_identity_arguments(p.oid) AS funciargs,\n"); - appendPQExpBufferStr(query, - "aggkind,\n" - "aggmtransfn,\n" - "aggminvtransfn,\n" - "aggmfinalfn,\n" - "aggmtranstype::pg_catalog.regtype,\n" - "aggfinalextra,\n" - "aggmfinalextra,\n" - "aggtransspace,\n" - "aggmtransspace,\n" - "aggminitval,\n"); + appendPQExpBufferStr(query, + "aggkind,\n" + "aggmtransfn,\n" + "aggminvtransfn,\n" + "aggmfinalfn,\n" + "aggmtranstype::pg_catalog.regtype,\n" + "aggfinalextra,\n" + "aggmfinalextra,\n" + "aggtransspace,\n" + "aggmtransspace,\n" + "aggminitval,\n"); - appendPQExpBufferStr(query, - "aggcombinefn,\n" - "aggserialfn,\n" - "aggdeserialfn,\n" - "proparallel,\n"); + appendPQExpBufferStr(query, + "aggcombinefn,\n" + "aggserialfn,\n" + "aggdeserialfn,\n" + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -16848,30 +16847,30 @@ dumpTable(Archive *fout, const TableInfo *tbinfo) appendPQExpBufferStr(query, "PREPARE getColumnACLs(pg_catalog.oid) AS\n"); - /* - * In principle we should call acldefault('c', relowner) to - * get the default ACL for a column. However, we don't - * currently store the numeric OID of the relowner in - * TableInfo. We could convert the owner name using regrole, - * but that creates a risk of failure due to concurrent role - * renames. Given that the default ACL for columns is empty - * and is likely to stay that way, it's not worth extra cycles - * and risk to avoid hard-wiring that knowledge here. - */ - appendPQExpBufferStr(query, - "SELECT at.attname, " - "at.attacl, " - "'{}' AS acldefault, " - "pip.privtype, pip.initprivs " - "FROM pg_catalog.pg_attribute at " - "LEFT JOIN pg_catalog.pg_init_privs pip ON " - "(at.attrelid = pip.objoid " - "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " - "AND at.attnum = pip.objsubid) " - "WHERE at.attrelid = $1 AND " - "NOT at.attisdropped " - "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " - "ORDER BY at.attnum"); + /* + * In principle we should call acldefault('c', relowner) to get + * the default ACL for a column. However, we don't currently + * store the numeric OID of the relowner in TableInfo. We could + * convert the owner name using regrole, but that creates a risk + * of failure due to concurrent role renames. Given that the + * default ACL for columns is empty and is likely to stay that + * way, it's not worth extra cycles and risk to avoid hard-wiring + * that knowledge here. + */ + appendPQExpBufferStr(query, + "SELECT at.attname, " + "at.attacl, " + "'{}' AS acldefault, " + "pip.privtype, pip.initprivs " + "FROM pg_catalog.pg_attribute at " + "LEFT JOIN pg_catalog.pg_init_privs pip ON " + "(at.attrelid = pip.objoid " + "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " + "AND at.attnum = pip.objsubid) " + "WHERE at.attrelid = $1 AND " + "NOT at.attisdropped " + "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " + "ORDER BY at.attnum"); ExecuteSqlStatement(fout, query->data); @@ -19165,7 +19164,7 @@ collectSequences(Archive *fout) * pg_get_sequence_data(), but we only do so for non-schema-only dumps. */ if (fout->remoteVersion < 180000 || - (!fout->dopt->dumpData && !fout->dopt->sequence_data)) + (!fout->dopt->dumpData && !fout->dopt->sequence_data)) query = "SELECT seqrelid, format_type(seqtypid, NULL), " "seqstart, seqincrement, " "seqmax, seqmin, " @@ -19227,15 +19226,14 @@ dumpSequence(Archive *fout, const TableInfo *tbinfo) qseqname = pg_strdup(fmtId(tbinfo->dobj.name)); /* - * The sequence information is gathered in a sorted - * table before any calls to dumpSequence(). See collectSequences() for - * more information. + * The sequence information is gathered in a sorted table before any calls + * to dumpSequence(). See collectSequences() for more information. */ - Assert(sequences); + Assert(sequences); - key.oid = tbinfo->dobj.catId.oid; - seq = bsearch(&key, sequences, nsequences, - sizeof(SequenceItem), SequenceItemCmp); + key.oid = tbinfo->dobj.catId.oid; + seq = bsearch(&key, sequences, nsequences, + sizeof(SequenceItem), SequenceItemCmp); /* Calculate default limits for a sequence of this type */ is_ascending = (seq->incby >= 0); diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c index e68937c9934..afcd9a218d8 100644 --- a/src/bin/pg_dump/pg_dumpall.c +++ b/src/bin/pg_dump/pg_dumpall.c @@ -785,11 +785,11 @@ dropRoles(PGconn *conn) int i_rolname; int i; - printfPQExpBuffer(buf, - "SELECT rolname " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 1", role_catalog); + printfPQExpBuffer(buf, + "SELECT rolname " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 1", role_catalog); res = executeQuery(conn, buf->data); @@ -843,16 +843,16 @@ dumpRoles(PGconn *conn) * Notes: rolconfig is dumped later, and pg_authid must be used for * extracting rolcomment regardless of role_catalog. */ - printfPQExpBuffer(buf, - "SELECT oid, rolname, rolsuper, rolinherit, " - "rolcreaterole, rolcreatedb, " - "rolcanlogin, rolconnlimit, rolpassword, " - "rolvaliduntil, rolreplication, rolbypassrls, " - "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " - "rolname = current_user AS is_current_user " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 2", role_catalog); + printfPQExpBuffer(buf, + "SELECT oid, rolname, rolsuper, rolinherit, " + "rolcreaterole, rolcreatedb, " + "rolcanlogin, rolconnlimit, rolpassword, " + "rolvaliduntil, rolreplication, rolbypassrls, " + "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " + "rolname = current_user AS is_current_user " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 2", role_catalog); res = executeQuery(conn, buf->data); diff --git a/src/bin/pg_upgrade/check.c b/src/bin/pg_upgrade/check.c index 786c1474829..f725f5ee3e2 100644 --- a/src/bin/pg_upgrade/check.c +++ b/src/bin/pg_upgrade/check.c @@ -1475,15 +1475,15 @@ check_for_incompatible_polymorphics(ClusterInfo *cluster) ", 'array_cat(anyarray,anyarray)'" ", 'array_prepend(anyelement,anyarray)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_remove(anyarray,anyelement)'" - ", 'array_replace(anyarray,anyelement,anyelement)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_remove(anyarray,anyelement)'" + ", 'array_replace(anyarray,anyelement,anyelement)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_position(anyarray,anyelement)'" - ", 'array_position(anyarray,anyelement,integer)'" - ", 'array_positions(anyarray,anyelement)'" - ", 'width_bucket(anyelement,anyarray)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_position(anyarray,anyelement)'" + ", 'array_position(anyarray,anyelement,integer)'" + ", 'array_positions(anyarray,anyelement)'" + ", 'width_bucket(anyelement,anyarray)'"); /* * The query below hardcodes FirstNormalObjectId as 16384 rather than diff --git a/src/bin/pg_upgrade/controldata.c b/src/bin/pg_upgrade/controldata.c index 8f81c9e9582..02ea02df60f 100644 --- a/src/bin/pg_upgrade/controldata.c +++ b/src/bin/pg_upgrade/controldata.c @@ -228,7 +228,7 @@ get_control_data(ClusterInfo *cluster) p++; /* remove ':' char */ cluster->controldata.chkpnt_nxtepoch = str2uint(p); - p = strchr(p, ':'); + p = strchr(p, ':'); if (p == NULL || strlen(p) <= 1) pg_fatal("%d: controldata retrieval problem", __LINE__); diff --git a/src/bin/pg_upgrade/exec.c b/src/bin/pg_upgrade/exec.c index 44355feea30..a1bdbf373e3 100644 --- a/src/bin/pg_upgrade/exec.c +++ b/src/bin/pg_upgrade/exec.c @@ -55,7 +55,7 @@ get_bin_version(ClusterInfo *cluster) if (sscanf(cmd_output, "%*s %*s %d.%d", &v1, &v2) < 1) pg_fatal("could not get pg_ctl version output from %s", cmd); - cluster->bin_version = v1 * 10000; + cluster->bin_version = v1 * 10000; } @@ -344,8 +344,8 @@ check_data_dir(ClusterInfo *cluster) check_single_dir(pg_data, "pg_subtrans"); check_single_dir(pg_data, PG_TBLSPC_DIR); check_single_dir(pg_data, "pg_twophase"); - check_single_dir(pg_data, "pg_wal"); - check_single_dir(pg_data, "pg_xact"); + check_single_dir(pg_data, "pg_wal"); + check_single_dir(pg_data, "pg_xact"); } @@ -385,7 +385,7 @@ check_bin_dir(ClusterInfo *cluster, bool check_versions) */ get_bin_version(cluster); - check_exec(cluster->bindir, "pg_resetwal", check_versions); + check_exec(cluster->bindir, "pg_resetwal", check_versions); if (cluster == &new_cluster) { diff --git a/src/bin/pg_upgrade/multixact_rewrite.c b/src/bin/pg_upgrade/multixact_rewrite.c index c45b3183684..c7a1416494d 100644 --- a/src/bin/pg_upgrade/multixact_rewrite.c +++ b/src/bin/pg_upgrade/multixact_rewrite.c @@ -61,52 +61,52 @@ rewrite_multixacts(MultiXactId from_multi, MultiXactId to_multi) * Convert old multixids, if needed, by reading them one-by-one from the * old cluster. */ - old_reader = AllocOldMultiXactRead(old_cluster.pgdata, - old_cluster.controldata.chkpnt_nxtmulti, - old_cluster.controldata.chkpnt_nxtmxoff); + old_reader = AllocOldMultiXactRead(old_cluster.pgdata, + old_cluster.controldata.chkpnt_nxtmulti, + old_cluster.controldata.chkpnt_nxtmxoff); - for (MultiXactId multi = from_multi; multi != to_multi;) - { - MultiXactMember member; - bool multixid_valid; - - /* - * Read this multixid's members. - * - * Locking-only XIDs that may be part of multi-xids don't matter - * after upgrade, as there can be no transactions running across - * upgrade. So as a small optimization, we only read one member - * from each multixid: the one updating one, or if there was no - * update, arbitrarily the first locking xid. - */ - multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); + for (MultiXactId multi = from_multi; multi != to_multi;) + { + MultiXactMember member; + bool multixid_valid; - /* - * Write the new offset to pg_multixact/offsets. - * - * Even if this multixid is invalid, we still need to write its - * offset if the *previous* multixid was valid. That's because - * when reading a multixid, the number of members is calculated - * from the difference between the two offsets. - */ - RecordMultiXactOffset(offsets_writer, multi, - (multixid_valid || prev_multixid_valid) ? next_offset : 0); + /* + * Read this multixid's members. + * + * Locking-only XIDs that may be part of multi-xids don't matter after + * upgrade, as there can be no transactions running across upgrade. So + * as a small optimization, we only read one member from each + * multixid: the one updating one, or if there was no update, + * arbitrarily the first locking xid. + */ + multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); - /* Write the members */ - if (multixid_valid) - { - RecordMultiXactMembers(members_writer, next_offset, 1, &member); - next_offset += 1; - } + /* + * Write the new offset to pg_multixact/offsets. + * + * Even if this multixid is invalid, we still need to write its offset + * if the *previous* multixid was valid. That's because when reading + * a multixid, the number of members is calculated from the difference + * between the two offsets. + */ + RecordMultiXactOffset(offsets_writer, multi, + (multixid_valid || prev_multixid_valid) ? next_offset : 0); - /* Advance to next multixid, handling wraparound */ - multi++; - if (multi < FirstMultiXactId) - multi = FirstMultiXactId; - prev_multixid_valid = multixid_valid; + /* Write the members */ + if (multixid_valid) + { + RecordMultiXactMembers(members_writer, next_offset, 1, &member); + next_offset += 1; } - FreeOldMultiXactReader(old_reader); + /* Advance to next multixid, handling wraparound */ + multi++; + if (multi < FirstMultiXactId) + multi = FirstMultiXactId; + prev_multixid_valid = multixid_valid; + } + + FreeOldMultiXactReader(old_reader); /* Write the final 'next' offset to the last SLRU page */ RecordMultiXactOffset(offsets_writer, to_multi, diff --git a/src/bin/pg_upgrade/pg_upgrade.c b/src/bin/pg_upgrade/pg_upgrade.c index c6af9035665..7366fd4627c 100644 --- a/src/bin/pg_upgrade/pg_upgrade.c +++ b/src/bin/pg_upgrade/pg_upgrade.c @@ -833,7 +833,7 @@ copy_xact_xlog_xid(void) * Determine the range of multixacts to convert. */ nxtmulti = old_cluster.controldata.chkpnt_nxtmulti; - oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; + oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; /* handle wraparound */ if (nxtmulti < FirstMultiXactId) nxtmulti = FirstMultiXactId; @@ -898,15 +898,15 @@ set_frozenxids(void) int i_datname; int i_datallowconn; - prep_status("Setting frozenxid and minmxid counters in new cluster"); + prep_status("Setting frozenxid and minmxid counters in new cluster"); conn_template1 = connectToServer(&new_cluster, "template1"); - /* set pg_database.datfrozenxid */ - PQclear(executeQueryOrDie(conn_template1, - "UPDATE pg_catalog.pg_database " - "SET datfrozenxid = '%u'", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_database.datfrozenxid */ + PQclear(executeQueryOrDie(conn_template1, + "UPDATE pg_catalog.pg_database " + "SET datfrozenxid = '%u'", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_database.datminmxid */ PQclear(executeQueryOrDie(conn_template1, @@ -942,16 +942,16 @@ set_frozenxids(void) conn = connectToServer(&new_cluster, datname); - /* set pg_class.relfrozenxid */ - PQclear(executeQueryOrDie(conn, - "UPDATE pg_catalog.pg_class " - "SET relfrozenxid = '%u' " - /* only heap, materialized view, and TOAST are vacuumed */ - "WHERE relkind IN (" - CppAsString2(RELKIND_RELATION) ", " - CppAsString2(RELKIND_MATVIEW) ", " - CppAsString2(RELKIND_TOASTVALUE) ")", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_class.relfrozenxid */ + PQclear(executeQueryOrDie(conn, + "UPDATE pg_catalog.pg_class " + "SET relfrozenxid = '%u' " + /* only heap, materialized view, and TOAST are vacuumed */ + "WHERE relkind IN (" + CppAsString2(RELKIND_RELATION) ", " + CppAsString2(RELKIND_MATVIEW) ", " + CppAsString2(RELKIND_TOASTVALUE) ")", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_class.relminmxid */ PQclear(executeQueryOrDie(conn, diff --git a/src/bin/pg_upgrade/relfilenumber.c b/src/bin/pg_upgrade/relfilenumber.c index ec2ff7acb21..6c467bdc8a5 100644 --- a/src/bin/pg_upgrade/relfilenumber.c +++ b/src/bin/pg_upgrade/relfilenumber.c @@ -587,32 +587,32 @@ transfer_relfile(FileNameMap *map, const char *type_suffix) /* Copying files might take some time, so give feedback. */ pg_log(PG_STATUS, "%s", old_file); - switch (user_opts.transfer_mode) - { - case TRANSFER_MODE_CLONE: - pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", - old_file, new_file); - cloneFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", - old_file, new_file); - copyFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY_FILE_RANGE: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", - old_file, new_file); - copyFileByRange(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_LINK: - pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", - old_file, new_file); - linkFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_SWAP: - /* swap mode is handled in its own code path */ - pg_fatal("should never happen"); - break; - } + switch (user_opts.transfer_mode) + { + case TRANSFER_MODE_CLONE: + pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", + old_file, new_file); + cloneFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", + old_file, new_file); + copyFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY_FILE_RANGE: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", + old_file, new_file); + copyFileByRange(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_LINK: + pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", + old_file, new_file); + linkFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_SWAP: + /* swap mode is handled in its own code path */ + pg_fatal("should never happen"); + break; + } } } diff --git a/src/bin/pg_upgrade/t/006_transfer_modes.pl b/src/bin/pg_upgrade/t/006_transfer_modes.pl index 9efa5dc863c..360d05c4b68 100644 --- a/src/bin/pg_upgrade/t/006_transfer_modes.pl +++ b/src/bin/pg_upgrade/t/006_transfer_modes.pl @@ -29,10 +29,8 @@ sub test_mode } $new->init(); - $new->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); - $old->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); + $new->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); + $old->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); # We can only test security labels if both the old and new installations # have dummy_seclabel. @@ -76,15 +74,14 @@ sub test_mode "CREATE TABLE test4 AS SELECT generate_series(400, 502)"); } - $old->safe_psql('postgres', - "CREATE TABLESPACE inplc_tblspc LOCATION ''"); - $old->safe_psql('postgres', - "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); - $old->safe_psql('postgres', - "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" - ); - $old->safe_psql('testdb3', - "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); + $old->safe_psql('postgres', "CREATE TABLESPACE inplc_tblspc LOCATION ''"); + $old->safe_psql('postgres', + "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); + $old->safe_psql('postgres', + "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" + ); + $old->safe_psql('testdb3', + "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); # While we are here, test handling of large objects. $old->safe_psql( @@ -152,12 +149,10 @@ sub test_mode } # Tests for in-place tablespaces. - $result = - $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); - is($result, '104', "test5 data after pg_upgrade $mode"); - $result = - $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); - is($result, '105', "test6 data after pg_upgrade $mode"); + $result = $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); + is($result, '104', "test5 data after pg_upgrade $mode"); + $result = $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); + is($result, '105', "test6 data after pg_upgrade $mode"); # Tests for large objects $result = $new->safe_psql('postgres', "SELECT lo_get(4532)"); diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index 44ef11d980e..c90bf8bbde2 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -6278,23 +6278,22 @@ get_create_object_cmd(EditableObjectType obj_type, Oid oid, * ensure the right view gets replaced. Also, check relation kind * to be sure it's a view. * - * Views may have WITH [LOCAL|CASCADED] - * CHECK OPTION. These are not part of the view definition - * returned by pg_get_viewdef() and so need to be retrieved - * separately. Materialized views may have - * arbitrary storage parameter reloptions. + * Views may have WITH [LOCAL|CASCADED] CHECK OPTION. These are + * not part of the view definition returned by pg_get_viewdef() + * and so need to be retrieved separately. Materialized views may + * have arbitrary storage parameter reloptions. */ printfPQExpBuffer(query, "/* %s */\n", _("Get view's definition and details")); - appendPQExpBuffer(query, - "SELECT nspname, relname, relkind, " - "pg_catalog.pg_get_viewdef(c.oid, true), " - "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " - "FROM pg_catalog.pg_class c " - "LEFT JOIN pg_catalog.pg_namespace n " - "ON c.relnamespace = n.oid WHERE c.oid = %u", - oid); + appendPQExpBuffer(query, + "SELECT nspname, relname, relkind, " + "pg_catalog.pg_get_viewdef(c.oid, true), " + "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " + "FROM pg_catalog.pg_class c " + "LEFT JOIN pg_catalog.pg_namespace n " + "ON c.relnamespace = n.oid WHERE c.oid = %u", + oid); break; } diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index ce99137c613..ac0c55e7aa5 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -387,19 +387,19 @@ describeFunctions(const char *functypes, const char *func_pattern, gettext_noop("stable"), gettext_noop("volatile"), gettext_noop("Volatility")); - appendPQExpBuffer(&buf, - ",\n CASE\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" - " END as \"%s\"", - gettext_noop("restricted"), - gettext_noop("safe"), - gettext_noop("unsafe"), - gettext_noop("Parallel")); + appendPQExpBuffer(&buf, + ",\n CASE\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" + " END as \"%s\"", + gettext_noop("restricted"), + gettext_noop("safe"), + gettext_noop("unsafe"), + gettext_noop("Parallel")); appendPQExpBuffer(&buf, ",\n pg_catalog.pg_get_userbyid(p.proowner) as \"%s\"" ",\n CASE WHEN prosecdef THEN '%s' ELSE '%s' END AS \"%s\"" @@ -599,8 +599,8 @@ describeFunctions(const char *functypes, const char *func_pattern, myopt.title = _("List of functions"); myopt.translate_header = true; - myopt.translate_columns = translate_columns; - myopt.n_translate_columns = lengthof(translate_columns); + myopt.translate_columns = translate_columns; + myopt.n_translate_columns = lengthof(translate_columns); printQuery(res, &myopt, pset.queryFout, false, pset.logfile); @@ -1086,38 +1086,38 @@ permissionsList(const char *pattern, bool showSystem) " ), E'\\n') AS \"%s\"", gettext_noop("Column privileges")); - appendPQExpBuffer(&buf, - ",\n pg_catalog.array_to_string(ARRAY(\n" - " SELECT polname\n" - " || CASE WHEN NOT polpermissive THEN\n" - " E' (RESTRICTIVE)'\n" - " ELSE '' END\n" - " || CASE WHEN polcmd != '*' THEN\n" - " E' (' || polcmd::pg_catalog.text || E'):'\n" - " ELSE E':'\n" - " END\n" - " || CASE WHEN polqual IS NOT NULL THEN\n" - " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" - " ELSE E''\n" - " END\n" - " || CASE WHEN polwithcheck IS NOT NULL THEN\n" - " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" - " ELSE E''\n" - " END" - " || CASE WHEN polroles <> '{0}' THEN\n" - " E'\\n to: ' || pg_catalog.array_to_string(\n" - " ARRAY(\n" - " SELECT rolname\n" - " FROM pg_catalog.pg_roles\n" - " WHERE oid = ANY (polroles)\n" - " ORDER BY 1\n" - " ), E', ')\n" - " ELSE E''\n" - " END\n" - " FROM pg_catalog.pg_policy pol\n" - " WHERE polrelid = c.oid), E'\\n')\n" - " AS \"%s\"", - gettext_noop("Policies")); + appendPQExpBuffer(&buf, + ",\n pg_catalog.array_to_string(ARRAY(\n" + " SELECT polname\n" + " || CASE WHEN NOT polpermissive THEN\n" + " E' (RESTRICTIVE)'\n" + " ELSE '' END\n" + " || CASE WHEN polcmd != '*' THEN\n" + " E' (' || polcmd::pg_catalog.text || E'):'\n" + " ELSE E':'\n" + " END\n" + " || CASE WHEN polqual IS NOT NULL THEN\n" + " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" + " ELSE E''\n" + " END\n" + " || CASE WHEN polwithcheck IS NOT NULL THEN\n" + " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" + " ELSE E''\n" + " END" + " || CASE WHEN polroles <> '{0}' THEN\n" + " E'\\n to: ' || pg_catalog.array_to_string(\n" + " ARRAY(\n" + " SELECT rolname\n" + " FROM pg_catalog.pg_roles\n" + " WHERE oid = ANY (polroles)\n" + " ORDER BY 1\n" + " ), E', ')\n" + " ELSE E''\n" + " END\n" + " FROM pg_catalog.pg_policy pol\n" + " WHERE polrelid = c.oid), E'\\n')\n" + " AS \"%s\"", + gettext_noop("Policies")); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_class c\n" " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n" @@ -1675,27 +1675,27 @@ describeOneTableDetails(const char *schemaname, char *footers[3] = {NULL, NULL, NULL}; printfPQExpBuffer(&buf, "/* %s */\n", _("Get sequence information")); - appendPQExpBuffer(&buf, - "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" - " seqstart AS \"%s\",\n" - " seqmin AS \"%s\",\n" - " seqmax AS \"%s\",\n" - " seqincrement AS \"%s\",\n" - " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" - " seqcache AS \"%s\"\n", - gettext_noop("Type"), - gettext_noop("Start"), - gettext_noop("Minimum"), - gettext_noop("Maximum"), - gettext_noop("Increment"), - gettext_noop("yes"), - gettext_noop("no"), - gettext_noop("Cycles?"), - gettext_noop("Cache")); - appendPQExpBuffer(&buf, - "FROM pg_catalog.pg_sequence\n" - "WHERE seqrelid = '%s';", - oid); + appendPQExpBuffer(&buf, + "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" + " seqstart AS \"%s\",\n" + " seqmin AS \"%s\",\n" + " seqmax AS \"%s\",\n" + " seqincrement AS \"%s\",\n" + " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" + " seqcache AS \"%s\"\n", + gettext_noop("Type"), + gettext_noop("Start"), + gettext_noop("Minimum"), + gettext_noop("Maximum"), + gettext_noop("Increment"), + gettext_noop("yes"), + gettext_noop("no"), + gettext_noop("Cycles?"), + gettext_noop("Cache")); + appendPQExpBuffer(&buf, + "FROM pg_catalog.pg_sequence\n" + "WHERE seqrelid = '%s';", + oid); res = PSQLexec(buf.data); if (!res) @@ -1913,7 +1913,7 @@ describeOneTableDetails(const char *schemaname, appendPQExpBufferStr(&buf, ",\n (SELECT c.collname FROM pg_catalog.pg_collation c, pg_catalog.pg_type t\n" " WHERE c.oid = a.attcollation AND t.oid = a.atttypid AND a.attcollation <> t.typcollation) AS attcollation"); attcoll_col = cols++; - appendPQExpBufferStr(&buf, ",\n a.attidentity"); + appendPQExpBufferStr(&buf, ",\n a.attidentity"); attidentity_col = cols++; if (pset.sversion >= 120000) appendPQExpBufferStr(&buf, ",\n a.attgenerated"); @@ -2326,7 +2326,7 @@ describeOneTableDetails(const char *schemaname, CppAsString2(CONSTRAINT_EXCLUSION) ") AND " "condeferred) AS condeferred,\n"); - appendPQExpBufferStr(&buf, "i.indisreplident,\n"); + appendPQExpBufferStr(&buf, "i.indisreplident,\n"); if (pset.sversion >= 150000) appendPQExpBufferStr(&buf, "i.indnullsnotdistinct,\n"); @@ -2431,7 +2431,7 @@ describeOneTableDetails(const char *schemaname, "pg_catalog.pg_get_indexdef(i.indexrelid, 0, true),\n " "pg_catalog.pg_get_constraintdef(con.oid, true), " "contype, condeferrable, condeferred"); - appendPQExpBufferStr(&buf, ", i.indisreplident"); + appendPQExpBufferStr(&buf, ", i.indisreplident"); appendPQExpBufferStr(&buf, ", c2.reltablespace"); if (pset.sversion >= 180000) appendPQExpBufferStr(&buf, ", con.conperiod"); @@ -2682,81 +2682,80 @@ describeOneTableDetails(const char *schemaname, PQclear(result); /* print any row-level policies */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get row-level policies for this table")); - appendPQExpBufferStr(&buf, "SELECT pol.polname,"); - appendPQExpBufferStr(&buf, - " pol.polpermissive,\n"); - appendPQExpBuffer(&buf, - " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" - " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" - " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" - " CASE pol.polcmd\n" - " WHEN 'r' THEN 'SELECT'\n" - " WHEN 'a' THEN 'INSERT'\n" - " WHEN 'w' THEN 'UPDATE'\n" - " WHEN 'd' THEN 'DELETE'\n" - " END AS cmd\n" - "FROM pg_catalog.pg_policy pol\n" - "WHERE pol.polrelid = '%s' ORDER BY 1;", - oid); + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get row-level policies for this table")); + appendPQExpBufferStr(&buf, "SELECT pol.polname,"); + appendPQExpBufferStr(&buf, + " pol.polpermissive,\n"); + appendPQExpBuffer(&buf, + " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" + " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" + " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" + " CASE pol.polcmd\n" + " WHEN 'r' THEN 'SELECT'\n" + " WHEN 'a' THEN 'INSERT'\n" + " WHEN 'w' THEN 'UPDATE'\n" + " WHEN 'd' THEN 'DELETE'\n" + " END AS cmd\n" + "FROM pg_catalog.pg_policy pol\n" + "WHERE pol.polrelid = '%s' ORDER BY 1;", + oid); - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - /* - * Handle cases where RLS is enabled and there are policies, or - * there aren't policies, or RLS isn't enabled but there are - * policies - */ - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies:")); + /* + * Handle cases where RLS is enabled and there are policies, or there + * aren't policies, or RLS isn't enabled but there are policies + */ + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies:")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled):")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled):")); - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); - if (!tableinfo.rowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (row security disabled):")); + if (!tableinfo.rowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (row security disabled):")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " POLICY \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " POLICY \"%s\"", + PQgetvalue(result, i, 0)); - if (*(PQgetvalue(result, i, 1)) == 'f') - appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); + if (*(PQgetvalue(result, i, 1)) == 'f') + appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); - if (!PQgetisnull(result, i, 5)) - appendPQExpBuffer(&buf, " FOR %s", - PQgetvalue(result, i, 5)); + if (!PQgetisnull(result, i, 5)) + appendPQExpBuffer(&buf, " FOR %s", + PQgetvalue(result, i, 5)); - if (!PQgetisnull(result, i, 2)) - { - appendPQExpBuffer(&buf, "\n TO %s", - PQgetvalue(result, i, 2)); - } + if (!PQgetisnull(result, i, 2)) + { + appendPQExpBuffer(&buf, "\n TO %s", + PQgetvalue(result, i, 2)); + } - if (!PQgetisnull(result, i, 3)) - appendPQExpBuffer(&buf, "\n USING (%s)", - PQgetvalue(result, i, 3)); + if (!PQgetisnull(result, i, 3)) + appendPQExpBuffer(&buf, "\n USING (%s)", + PQgetvalue(result, i, 3)); - if (!PQgetisnull(result, i, 4)) - appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", - PQgetvalue(result, i, 4)); + if (!PQgetisnull(result, i, 4)) + appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", + PQgetvalue(result, i, 4)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* print any extended statistics */ if (pset.sversion >= 140000) @@ -3025,115 +3024,115 @@ describeOneTableDetails(const char *schemaname, } /* print any publications */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get publications that publish this table")); - if (pset.sversion >= 150000) + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get publications that publish this table")); + if (pset.sversion >= 150000) + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" + " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" + "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" + "UNION\n" + "SELECT pubname\n" + " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" + " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" + " (SELECT pg_catalog.string_agg(attname, ', ')\n" + " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" + " pg_catalog.pg_attribute\n" + " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" + " ELSE NULL END) " + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" + "WHERE pr.prrelid = '%s'\n", + oid, oid, oid); + + if (pset.sversion >= 190000) { + /* + * Skip entries where this relation appears in the + * publication's EXCEPT list. + */ appendPQExpBuffer(&buf, + " AND NOT pr.prexcept\n" + "UNION\n" "SELECT pubname\n" " , NULL\n" " , NULL\n" "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" - " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" - "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" - "UNION\n" - "SELECT pubname\n" - " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" - " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" - " (SELECT pg_catalog.string_agg(attname, ', ')\n" - " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" - " pg_catalog.pg_attribute\n" - " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" - " ELSE NULL END) " - "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" - "WHERE pr.prrelid = '%s'\n", + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + " AND NOT EXISTS (\n" + " SELECT 1\n" + " FROM pg_catalog.pg_publication_rel pr\n" + " WHERE pr.prpubid = p.oid AND\n" + " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" + "ORDER BY 1;", oid, oid, oid); - - if (pset.sversion >= 190000) - { - /* - * Skip entries where this relation appears in the - * publication's EXCEPT list. - */ - appendPQExpBuffer(&buf, - " AND NOT pr.prexcept\n" - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - " AND NOT EXISTS (\n" - " SELECT 1\n" - " FROM pg_catalog.pg_publication_rel pr\n" - " WHERE pr.prpubid = p.oid AND\n" - " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" - "ORDER BY 1;", - oid, oid, oid); - } - else - { - appendPQExpBuffer(&buf, - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - "ORDER BY 1;", - oid); - } } else { appendPQExpBuffer(&buf, + "UNION\n" "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - "WHERE pr.prrelid = '%s'\n" - "UNION ALL\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" + " , NULL\n" + " , NULL\n" "FROM pg_catalog.pg_publication p\n" "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" "ORDER BY 1;", - oid, oid); + oid); } + } + else + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + "WHERE pr.prrelid = '%s'\n" + "UNION ALL\n" + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + "ORDER BY 1;", + oid, oid); + } - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - if (tuples > 0) - printTableAddFooter(&cont, _("Included in publications:")); + if (tuples > 0) + printTableAddFooter(&cont, _("Included in publications:")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " \"%s\"", + PQgetvalue(result, i, 0)); - /* column list (if any) */ - if (!PQgetisnull(result, i, 2)) - appendPQExpBuffer(&buf, " (%s)", - PQgetvalue(result, i, 2)); + /* column list (if any) */ + if (!PQgetisnull(result, i, 2)) + appendPQExpBuffer(&buf, " (%s)", + PQgetvalue(result, i, 2)); - /* row filter (if any) */ - if (!PQgetisnull(result, i, 1)) - appendPQExpBuffer(&buf, " WHERE %s", - PQgetvalue(result, i, 1)); + /* row filter (if any) */ + if (!PQgetisnull(result, i, 1)) + appendPQExpBuffer(&buf, " WHERE %s", + PQgetvalue(result, i, 1)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* Print publications where the table is in the EXCEPT clause */ if (pset.sversion >= 190000) @@ -3805,7 +3804,7 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) ncols++; } appendPQExpBufferStr(&buf, "\n, r.rolreplication"); - appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); + appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_roles r\n"); @@ -3860,8 +3859,8 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) if (strcmp(PQgetvalue(res, i, (verbose ? 9 : 8)), "t") == 0) add_role_attribute(&buf, _("Replication")); - if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) - add_role_attribute(&buf, _("Bypass RLS")); + if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) + add_role_attribute(&buf, _("Bypass RLS")); conns = atoi(PQgetvalue(res, i, 6)); if (conns >= 0) @@ -5155,14 +5154,14 @@ listCollations(const char *pattern, bool verbose, bool showSystem) gettext_noop("Schema"), gettext_noop("Name")); - appendPQExpBuffer(&buf, - " CASE c.collprovider " - "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " - "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " - "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " - "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " - "END AS \"%s\",\n", - gettext_noop("Provider")); + appendPQExpBuffer(&buf, + " CASE c.collprovider " + "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " + "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " + "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " + "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " + "END AS \"%s\",\n", + gettext_noop("Provider")); appendPQExpBuffer(&buf, " c.collcollate AS \"%s\",\n" -- 2.50.1 (Apple Git-155) --aHl3HfeiUuO3zeNC-- ^ permalink raw reply [nested|flat] 59+ messages in thread
* [PATCH v6 4/4] run pgindent and pgperltidy @ 2026-06-30 18:24 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 59+ messages in thread From: Nathan Bossart @ 2026-06-30 18:24 UTC (permalink / raw) --- src/bin/pg_dump/pg_dump.c | 464 ++++++++++----------- src/bin/pg_dump/pg_dumpall.c | 30 +- src/bin/pg_upgrade/check.c | 16 +- src/bin/pg_upgrade/controldata.c | 2 +- src/bin/pg_upgrade/exec.c | 8 +- src/bin/pg_upgrade/multixact_rewrite.c | 80 ++-- src/bin/pg_upgrade/pg_upgrade.c | 34 +- src/bin/pg_upgrade/relfilenumber.c | 54 +-- src/bin/pg_upgrade/t/006_transfer_modes.pl | 33 +- src/bin/psql/command.c | 29 +- src/bin/psql/describe.c | 461 ++++++++++---------- 11 files changed, 601 insertions(+), 610 deletions(-) diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 65bd15ebfd2..5673268b467 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -1491,8 +1491,8 @@ setup_connection(Archive *AH, const char *dumpencoding, * Disable timeouts if supported. */ ExecuteSqlStatement(AH, "SET statement_timeout = 0"); - ExecuteSqlStatement(AH, "SET lock_timeout = 0"); - ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); + ExecuteSqlStatement(AH, "SET lock_timeout = 0"); + ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); if (AH->remoteVersion >= 170000) ExecuteSqlStatement(AH, "SET transaction_timeout = 0"); @@ -1505,10 +1505,10 @@ setup_connection(Archive *AH, const char *dumpencoding, /* * Adjust row-security mode, if supported. */ - if (dopt->enable_row_security) - ExecuteSqlStatement(AH, "SET row_security = on"); - else - ExecuteSqlStatement(AH, "SET row_security = off"); + if (dopt->enable_row_security) + ExecuteSqlStatement(AH, "SET row_security = on"); + else + ExecuteSqlStatement(AH, "SET row_security = off"); /* * For security reasons, we restrict the expansion of non-system views and @@ -1933,10 +1933,9 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) addObjectDependency(dobj, ext->dobj.dumpId); /* - * Mark the member object to have any non-initial ACLs - * dumped. (Any initial ACLs will be removed later, using data from - * pg_init_privs, so that we'll dump only the delta from the extension's - * initial setup.) + * Mark the member object to have any non-initial ACLs dumped. (Any + * initial ACLs will be removed later, using data from pg_init_privs, so + * that we'll dump only the delta from the extension's initial setup.) * * In binary upgrades, we still dump all components of the members * individually, since the idea is to exactly reproduce the database @@ -1953,7 +1952,7 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) if (fout->dopt->binary_upgrade) dobj->dump = ext->dobj.dump; else - dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); + dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); return true; } @@ -1987,9 +1986,9 @@ selectDumpableNamespace(NamespaceInfo *nsinfo, Archive *fout) else if (strcmp(nsinfo->dobj.name, "pg_catalog") == 0) { /* - * We dump out any ACLs defined in pg_catalog, if - * they are interesting (and not the original ACLs which were set at - * initdb time, see pg_init_privs). + * We dump out any ACLs defined in pg_catalog, if they are interesting + * (and not the original ACLs which were set at initdb time, see + * pg_init_privs). */ nsinfo->dobj.dump_contains = nsinfo->dobj.dump = DUMP_COMPONENT_ACL; } @@ -3296,7 +3295,7 @@ dumpDatabase(Archive *fout) "datcollate, datctype, datfrozenxid, " "datacl, acldefault('d', datdba) AS acldefault, " "datistemplate, datconnlimit, "); - appendPQExpBufferStr(dbQry, "datminmxid, "); + appendPQExpBufferStr(dbQry, "datminmxid, "); if (fout->remoteVersion >= 170000) appendPQExpBufferStr(dbQry, "datlocprovider, datlocale, datcollversion, "); else if (fout->remoteVersion >= 150000) @@ -3638,11 +3637,11 @@ dumpDatabase(Archive *fout) ii_oid, ii_relminmxid; - appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" - "FROM pg_catalog.pg_class\n" - "WHERE oid IN (%u, %u, %u, %u);\n", - LargeObjectRelationId, LargeObjectLOidPNIndexId, - LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); + appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" + "FROM pg_catalog.pg_class\n" + "WHERE oid IN (%u, %u, %u, %u);\n", + LargeObjectRelationId, LargeObjectLOidPNIndexId, + LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); lo_res = ExecuteSqlQuery(fout, loFrozenQry->data, PGRES_TUPLES_OK); @@ -4274,7 +4273,7 @@ getPolicies(Archive *fout, TableInfo tblinfo[], int numTables) printfPQExpBuffer(query, "SELECT pol.oid, pol.tableoid, pol.polrelid, pol.polname, pol.polcmd, "); - appendPQExpBufferStr(query, "pol.polpermissive, "); + appendPQExpBufferStr(query, "pol.polpermissive, "); appendPQExpBuffer(query, "CASE WHEN pol.polroles = '{0}' THEN NULL ELSE " " pg_catalog.array_to_string(ARRAY(SELECT pg_catalog.quote_ident(rolname) from pg_catalog.pg_roles WHERE oid = ANY(pol.polroles)), ', ') END AS polroles, " @@ -6633,9 +6632,9 @@ getAccessMethods(Archive *fout) * Select all access methods from pg_am table. */ appendPQExpBufferStr(query, "SELECT tableoid, oid, amname, "); - appendPQExpBufferStr(query, - "amtype, " - "amhandler::pg_catalog.regproc AS amhandler "); + appendPQExpBufferStr(query, + "amtype, " + "amhandler::pg_catalog.regproc AS amhandler "); appendPQExpBufferStr(query, "FROM pg_am"); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6827,35 +6826,35 @@ getAggregates(Archive *fout) * Find all interesting aggregates. See comment in getFuncs() for the * rationale behind the filtering logic. */ - agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" - : "p.proisagg"); + agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" + : "p.proisagg"); - appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " - "p.proname AS aggname, " - "p.pronamespace AS aggnamespace, " - "p.pronargs, p.proargtypes, " - "p.proowner, " - "p.proacl AS aggacl, " - "acldefault('f', p.proowner) AS acldefault " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s AND (" - "p.pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog') OR " - "p.proacl IS DISTINCT FROM pip.initprivs", - agg_check); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - " OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); - appendPQExpBufferChar(query, ')'); + appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " + "p.proname AS aggname, " + "p.pronamespace AS aggnamespace, " + "p.pronargs, p.proargtypes, " + "p.proowner, " + "p.proacl AS aggacl, " + "acldefault('f', p.proowner) AS acldefault " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s AND (" + "p.pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog') OR " + "p.proacl IS DISTINCT FROM pip.initprivs", + agg_check); + if (dopt->binary_upgrade) + appendPQExpBufferStr(query, + " OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6957,53 +6956,53 @@ getFuncs(Archive *fout) * include them, since we want to dump extension members individually in * that mode. Also, if they are used by casts or transforms then we need * to gather the information about them, though they won't be dumped if - * they are built-in. Also, include functions in - * pg_catalog if they have an ACL different from what's shown in - * pg_init_privs (so we have to join to pg_init_privs; annoying). + * they are built-in. Also, include functions in pg_catalog if they have + * an ACL different from what's shown in pg_init_privs (so we have to join + * to pg_init_privs; annoying). */ - not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" - : "NOT p.proisagg"); + not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" + : "NOT p.proisagg"); - appendPQExpBuffer(query, - "SELECT p.tableoid, p.oid, p.proname, p.prolang, " - "p.pronargs, p.proargtypes, p.prorettype, " - "p.proacl, " - "acldefault('f', p.proowner) AS acldefault, " - "p.pronamespace, " - "p.proowner " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s" - "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " - "WHERE classid = 'pg_proc'::regclass AND " - "objid = p.oid AND deptype = 'i')" - "\n AND (" - "\n pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog')" - "\n OR EXISTS (SELECT 1 FROM pg_cast" - "\n WHERE pg_cast.oid > %u " - "\n AND p.oid = pg_cast.castfunc)" - "\n OR EXISTS (SELECT 1 FROM pg_transform" - "\n WHERE pg_transform.oid > %u AND " - "\n (p.oid = pg_transform.trffromsql" - "\n OR p.oid = pg_transform.trftosql))", - not_agg_check, - g_last_builtin_oid, - g_last_builtin_oid); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); + appendPQExpBuffer(query, + "SELECT p.tableoid, p.oid, p.proname, p.prolang, " + "p.pronargs, p.proargtypes, p.prorettype, " + "p.proacl, " + "acldefault('f', p.proowner) AS acldefault, " + "p.pronamespace, " + "p.proowner " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s" + "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " + "WHERE classid = 'pg_proc'::regclass AND " + "objid = p.oid AND deptype = 'i')" + "\n AND (" + "\n pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog')" + "\n OR EXISTS (SELECT 1 FROM pg_cast" + "\n WHERE pg_cast.oid > %u " + "\n AND p.oid = pg_cast.castfunc)" + "\n OR EXISTS (SELECT 1 FROM pg_transform" + "\n WHERE pg_transform.oid > %u AND " + "\n (p.oid = pg_transform.trffromsql" + "\n OR p.oid = pg_transform.trftosql))", + not_agg_check, + g_last_builtin_oid, + g_last_builtin_oid); + if (dopt->binary_upgrade) appendPQExpBufferStr(query, - "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); - appendPQExpBufferChar(query, ')'); + "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferStr(query, + "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -7252,31 +7251,31 @@ getTables(Archive *fout, int *numTables) appendPQExpBufferStr(query, "c.relhasoids, "); - appendPQExpBufferStr(query, - "c.relispopulated, "); + appendPQExpBufferStr(query, + "c.relispopulated, "); - appendPQExpBufferStr(query, - "c.relreplident, "); + appendPQExpBufferStr(query, + "c.relreplident, "); - appendPQExpBufferStr(query, - "c.relrowsecurity, c.relforcerowsecurity, "); + appendPQExpBufferStr(query, + "c.relrowsecurity, c.relforcerowsecurity, "); - appendPQExpBufferStr(query, - "c.relminmxid, tc.relminmxid AS tminmxid, "); + appendPQExpBufferStr(query, + "c.relminmxid, tc.relminmxid AS tminmxid, "); - appendPQExpBufferStr(query, - "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); + appendPQExpBufferStr(query, + "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); - appendPQExpBufferStr(query, - "am.amname, "); + appendPQExpBufferStr(query, + "am.amname, "); - appendPQExpBufferStr(query, - "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); + appendPQExpBufferStr(query, + "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); - appendPQExpBufferStr(query, - "c.relispartition AS ispartition "); + appendPQExpBufferStr(query, + "c.relispartition AS ispartition "); /* * Left join to pg_depend to pick up dependency info linking sequences to @@ -7296,8 +7295,8 @@ getTables(Archive *fout, int *numTables) /* * Left join to pg_am to pick up the amname. */ - appendPQExpBufferStr(query, - "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); + appendPQExpBufferStr(query, + "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); /* * We purposefully ignore toast OIDs for partitioned tables; the reason is @@ -7868,8 +7867,8 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables) "t.reloptions AS indreloptions, "); - appendPQExpBufferStr(query, - "i.indisreplident, "); + appendPQExpBufferStr(query, + "i.indisreplident, "); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -9313,8 +9312,8 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables) appendPQExpBufferStr(q, "'' AS attcompression,\n"); - appendPQExpBufferStr(q, - "a.attidentity,\n"); + appendPQExpBufferStr(q, + "a.attidentity,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(q, @@ -10717,73 +10716,73 @@ getAdditionalACLs(Archive *fout) PQclear(res); /* Fetch initial-privileges data */ - printfPQExpBuffer(query, - "SELECT objoid, classoid, objsubid, privtype, initprivs " - "FROM pg_init_privs"); + printfPQExpBuffer(query, + "SELECT objoid, classoid, objsubid, privtype, initprivs " + "FROM pg_init_privs"); - res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); + res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); - ntups = PQntuples(res); - for (i = 0; i < ntups; i++) - { - Oid objoid = atooid(PQgetvalue(res, i, 0)); - Oid classoid = atooid(PQgetvalue(res, i, 1)); - int objsubid = atoi(PQgetvalue(res, i, 2)); - char privtype = *(PQgetvalue(res, i, 3)); - char *initprivs = PQgetvalue(res, i, 4); - CatalogId objId; - DumpableObject *dobj; + ntups = PQntuples(res); + for (i = 0; i < ntups; i++) + { + Oid objoid = atooid(PQgetvalue(res, i, 0)); + Oid classoid = atooid(PQgetvalue(res, i, 1)); + int objsubid = atoi(PQgetvalue(res, i, 2)); + char privtype = *(PQgetvalue(res, i, 3)); + char *initprivs = PQgetvalue(res, i, 4); + CatalogId objId; + DumpableObject *dobj; - objId.tableoid = classoid; - objId.oid = objoid; - dobj = findObjectByCatalogId(objId); - /* OK to ignore entries we haven't got a DumpableObject for */ - if (dobj) + objId.tableoid = classoid; + objId.oid = objoid; + dobj = findObjectByCatalogId(objId); + /* OK to ignore entries we haven't got a DumpableObject for */ + if (dobj) + { + /* Cope with sub-object initprivs */ + if (objsubid != 0) { - /* Cope with sub-object initprivs */ - if (objsubid != 0) - { - if (dobj->objType == DO_TABLE) - { - /* For a column initprivs, set the table's ACL flags */ - dobj->components |= DUMP_COMPONENT_ACL; - ((TableInfo *) dobj)->hascolumnACLs = true; - } - else - pg_log_warning("unsupported pg_init_privs entry: %u %u %d", - classoid, objoid, objsubid); - continue; - } - - /* - * We ignore any pg_init_privs.initprivs entry for the public - * schema, as explained in getNamespaces(). - */ - if (dobj->objType == DO_NAMESPACE && - strcmp(dobj->name, "public") == 0) - continue; - - /* Else it had better be of a type we think has ACLs */ - if (dobj->objType == DO_NAMESPACE || - dobj->objType == DO_TYPE || - dobj->objType == DO_FUNC || - dobj->objType == DO_AGG || - dobj->objType == DO_TABLE || - dobj->objType == DO_PROCLANG || - dobj->objType == DO_FDW || - dobj->objType == DO_FOREIGN_SERVER) + if (dobj->objType == DO_TABLE) { - DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; - - daobj->dacl.privtype = privtype; - daobj->dacl.initprivs = pstrdup(initprivs); + /* For a column initprivs, set the table's ACL flags */ + dobj->components |= DUMP_COMPONENT_ACL; + ((TableInfo *) dobj)->hascolumnACLs = true; } else pg_log_warning("unsupported pg_init_privs entry: %u %u %d", classoid, objoid, objsubid); + continue; + } + + /* + * We ignore any pg_init_privs.initprivs entry for the public + * schema, as explained in getNamespaces(). + */ + if (dobj->objType == DO_NAMESPACE && + strcmp(dobj->name, "public") == 0) + continue; + + /* Else it had better be of a type we think has ACLs */ + if (dobj->objType == DO_NAMESPACE || + dobj->objType == DO_TYPE || + dobj->objType == DO_FUNC || + dobj->objType == DO_AGG || + dobj->objType == DO_TABLE || + dobj->objType == DO_PROCLANG || + dobj->objType == DO_FDW || + dobj->objType == DO_FOREIGN_SERVER) + { + DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; + + daobj->dacl.privtype = privtype; + daobj->dacl.initprivs = pstrdup(initprivs); } + else + pg_log_warning("unsupported pg_init_privs entry: %u %u %d", + classoid, objoid, objsubid); } - PQclear(res); + } + PQclear(res); destroyPQExpBuffer(query); } @@ -11128,8 +11127,8 @@ dumpRelationStats_dumper(Archive *fout, const void *userArg, const TocEntry *te) * The results must be in the order of the relations supplied in the * parameters to ensure we remain in sync as we walk through the TOC. * - * For versions before 19, the redundant filter clause on s.tablename = - * ANY(...) seems sufficient to convince the planner to use + * For versions before 19, the redundant filter clause on s.tablename + * = ANY(...) seems sufficient to convince the planner to use * pg_class_relname_nsp_index, which avoids a full scan of pg_stats. * In newer versions, pg_stats returns the table OIDs, eliminating the * need for that hack. @@ -13469,11 +13468,11 @@ dumpFunc(Archive *fout, const FuncInfo *finfo) "pg_catalog.pg_get_function_result(p.oid) AS funcresult,\n" "proleakproof,\n"); - appendPQExpBufferStr(query, - "array_to_string(protrftypes, ' ') AS protrftypes,\n"); + appendPQExpBufferStr(query, + "array_to_string(protrftypes, ' ') AS protrftypes,\n"); - appendPQExpBufferStr(query, - "proparallel,\n"); + appendPQExpBufferStr(query, + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -14963,9 +14962,9 @@ dumpCollation(Archive *fout, const CollInfo *collinfo) /* Get collation-specific details */ appendPQExpBufferStr(query, "SELECT "); - appendPQExpBufferStr(query, - "collprovider, " - "collversion, "); + appendPQExpBufferStr(query, + "collprovider, " + "collversion, "); if (fout->remoteVersion >= 120000) appendPQExpBufferStr(query, @@ -15372,23 +15371,23 @@ dumpAgg(Archive *fout, const AggInfo *agginfo) "pg_catalog.pg_get_function_arguments(p.oid) AS funcargs,\n" "pg_catalog.pg_get_function_identity_arguments(p.oid) AS funciargs,\n"); - appendPQExpBufferStr(query, - "aggkind,\n" - "aggmtransfn,\n" - "aggminvtransfn,\n" - "aggmfinalfn,\n" - "aggmtranstype::pg_catalog.regtype,\n" - "aggfinalextra,\n" - "aggmfinalextra,\n" - "aggtransspace,\n" - "aggmtransspace,\n" - "aggminitval,\n"); + appendPQExpBufferStr(query, + "aggkind,\n" + "aggmtransfn,\n" + "aggminvtransfn,\n" + "aggmfinalfn,\n" + "aggmtranstype::pg_catalog.regtype,\n" + "aggfinalextra,\n" + "aggmfinalextra,\n" + "aggtransspace,\n" + "aggmtransspace,\n" + "aggminitval,\n"); - appendPQExpBufferStr(query, - "aggcombinefn,\n" - "aggserialfn,\n" - "aggdeserialfn,\n" - "proparallel,\n"); + appendPQExpBufferStr(query, + "aggcombinefn,\n" + "aggserialfn,\n" + "aggdeserialfn,\n" + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -16848,30 +16847,30 @@ dumpTable(Archive *fout, const TableInfo *tbinfo) appendPQExpBufferStr(query, "PREPARE getColumnACLs(pg_catalog.oid) AS\n"); - /* - * In principle we should call acldefault('c', relowner) to - * get the default ACL for a column. However, we don't - * currently store the numeric OID of the relowner in - * TableInfo. We could convert the owner name using regrole, - * but that creates a risk of failure due to concurrent role - * renames. Given that the default ACL for columns is empty - * and is likely to stay that way, it's not worth extra cycles - * and risk to avoid hard-wiring that knowledge here. - */ - appendPQExpBufferStr(query, - "SELECT at.attname, " - "at.attacl, " - "'{}' AS acldefault, " - "pip.privtype, pip.initprivs " - "FROM pg_catalog.pg_attribute at " - "LEFT JOIN pg_catalog.pg_init_privs pip ON " - "(at.attrelid = pip.objoid " - "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " - "AND at.attnum = pip.objsubid) " - "WHERE at.attrelid = $1 AND " - "NOT at.attisdropped " - "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " - "ORDER BY at.attnum"); + /* + * In principle we should call acldefault('c', relowner) to get + * the default ACL for a column. However, we don't currently + * store the numeric OID of the relowner in TableInfo. We could + * convert the owner name using regrole, but that creates a risk + * of failure due to concurrent role renames. Given that the + * default ACL for columns is empty and is likely to stay that + * way, it's not worth extra cycles and risk to avoid hard-wiring + * that knowledge here. + */ + appendPQExpBufferStr(query, + "SELECT at.attname, " + "at.attacl, " + "'{}' AS acldefault, " + "pip.privtype, pip.initprivs " + "FROM pg_catalog.pg_attribute at " + "LEFT JOIN pg_catalog.pg_init_privs pip ON " + "(at.attrelid = pip.objoid " + "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " + "AND at.attnum = pip.objsubid) " + "WHERE at.attrelid = $1 AND " + "NOT at.attisdropped " + "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " + "ORDER BY at.attnum"); ExecuteSqlStatement(fout, query->data); @@ -19165,7 +19164,7 @@ collectSequences(Archive *fout) * pg_get_sequence_data(), but we only do so for non-schema-only dumps. */ if (fout->remoteVersion < 180000 || - (!fout->dopt->dumpData && !fout->dopt->sequence_data)) + (!fout->dopt->dumpData && !fout->dopt->sequence_data)) query = "SELECT seqrelid, format_type(seqtypid, NULL), " "seqstart, seqincrement, " "seqmax, seqmin, " @@ -19227,15 +19226,14 @@ dumpSequence(Archive *fout, const TableInfo *tbinfo) qseqname = pg_strdup(fmtId(tbinfo->dobj.name)); /* - * The sequence information is gathered in a sorted - * table before any calls to dumpSequence(). See collectSequences() for - * more information. + * The sequence information is gathered in a sorted table before any calls + * to dumpSequence(). See collectSequences() for more information. */ - Assert(sequences); + Assert(sequences); - key.oid = tbinfo->dobj.catId.oid; - seq = bsearch(&key, sequences, nsequences, - sizeof(SequenceItem), SequenceItemCmp); + key.oid = tbinfo->dobj.catId.oid; + seq = bsearch(&key, sequences, nsequences, + sizeof(SequenceItem), SequenceItemCmp); /* Calculate default limits for a sequence of this type */ is_ascending = (seq->incby >= 0); diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c index e68937c9934..afcd9a218d8 100644 --- a/src/bin/pg_dump/pg_dumpall.c +++ b/src/bin/pg_dump/pg_dumpall.c @@ -785,11 +785,11 @@ dropRoles(PGconn *conn) int i_rolname; int i; - printfPQExpBuffer(buf, - "SELECT rolname " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 1", role_catalog); + printfPQExpBuffer(buf, + "SELECT rolname " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 1", role_catalog); res = executeQuery(conn, buf->data); @@ -843,16 +843,16 @@ dumpRoles(PGconn *conn) * Notes: rolconfig is dumped later, and pg_authid must be used for * extracting rolcomment regardless of role_catalog. */ - printfPQExpBuffer(buf, - "SELECT oid, rolname, rolsuper, rolinherit, " - "rolcreaterole, rolcreatedb, " - "rolcanlogin, rolconnlimit, rolpassword, " - "rolvaliduntil, rolreplication, rolbypassrls, " - "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " - "rolname = current_user AS is_current_user " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 2", role_catalog); + printfPQExpBuffer(buf, + "SELECT oid, rolname, rolsuper, rolinherit, " + "rolcreaterole, rolcreatedb, " + "rolcanlogin, rolconnlimit, rolpassword, " + "rolvaliduntil, rolreplication, rolbypassrls, " + "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " + "rolname = current_user AS is_current_user " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 2", role_catalog); res = executeQuery(conn, buf->data); diff --git a/src/bin/pg_upgrade/check.c b/src/bin/pg_upgrade/check.c index 786c1474829..f725f5ee3e2 100644 --- a/src/bin/pg_upgrade/check.c +++ b/src/bin/pg_upgrade/check.c @@ -1475,15 +1475,15 @@ check_for_incompatible_polymorphics(ClusterInfo *cluster) ", 'array_cat(anyarray,anyarray)'" ", 'array_prepend(anyelement,anyarray)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_remove(anyarray,anyelement)'" - ", 'array_replace(anyarray,anyelement,anyelement)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_remove(anyarray,anyelement)'" + ", 'array_replace(anyarray,anyelement,anyelement)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_position(anyarray,anyelement)'" - ", 'array_position(anyarray,anyelement,integer)'" - ", 'array_positions(anyarray,anyelement)'" - ", 'width_bucket(anyelement,anyarray)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_position(anyarray,anyelement)'" + ", 'array_position(anyarray,anyelement,integer)'" + ", 'array_positions(anyarray,anyelement)'" + ", 'width_bucket(anyelement,anyarray)'"); /* * The query below hardcodes FirstNormalObjectId as 16384 rather than diff --git a/src/bin/pg_upgrade/controldata.c b/src/bin/pg_upgrade/controldata.c index 8f81c9e9582..02ea02df60f 100644 --- a/src/bin/pg_upgrade/controldata.c +++ b/src/bin/pg_upgrade/controldata.c @@ -228,7 +228,7 @@ get_control_data(ClusterInfo *cluster) p++; /* remove ':' char */ cluster->controldata.chkpnt_nxtepoch = str2uint(p); - p = strchr(p, ':'); + p = strchr(p, ':'); if (p == NULL || strlen(p) <= 1) pg_fatal("%d: controldata retrieval problem", __LINE__); diff --git a/src/bin/pg_upgrade/exec.c b/src/bin/pg_upgrade/exec.c index 44355feea30..a1bdbf373e3 100644 --- a/src/bin/pg_upgrade/exec.c +++ b/src/bin/pg_upgrade/exec.c @@ -55,7 +55,7 @@ get_bin_version(ClusterInfo *cluster) if (sscanf(cmd_output, "%*s %*s %d.%d", &v1, &v2) < 1) pg_fatal("could not get pg_ctl version output from %s", cmd); - cluster->bin_version = v1 * 10000; + cluster->bin_version = v1 * 10000; } @@ -344,8 +344,8 @@ check_data_dir(ClusterInfo *cluster) check_single_dir(pg_data, "pg_subtrans"); check_single_dir(pg_data, PG_TBLSPC_DIR); check_single_dir(pg_data, "pg_twophase"); - check_single_dir(pg_data, "pg_wal"); - check_single_dir(pg_data, "pg_xact"); + check_single_dir(pg_data, "pg_wal"); + check_single_dir(pg_data, "pg_xact"); } @@ -385,7 +385,7 @@ check_bin_dir(ClusterInfo *cluster, bool check_versions) */ get_bin_version(cluster); - check_exec(cluster->bindir, "pg_resetwal", check_versions); + check_exec(cluster->bindir, "pg_resetwal", check_versions); if (cluster == &new_cluster) { diff --git a/src/bin/pg_upgrade/multixact_rewrite.c b/src/bin/pg_upgrade/multixact_rewrite.c index c45b3183684..c7a1416494d 100644 --- a/src/bin/pg_upgrade/multixact_rewrite.c +++ b/src/bin/pg_upgrade/multixact_rewrite.c @@ -61,52 +61,52 @@ rewrite_multixacts(MultiXactId from_multi, MultiXactId to_multi) * Convert old multixids, if needed, by reading them one-by-one from the * old cluster. */ - old_reader = AllocOldMultiXactRead(old_cluster.pgdata, - old_cluster.controldata.chkpnt_nxtmulti, - old_cluster.controldata.chkpnt_nxtmxoff); + old_reader = AllocOldMultiXactRead(old_cluster.pgdata, + old_cluster.controldata.chkpnt_nxtmulti, + old_cluster.controldata.chkpnt_nxtmxoff); - for (MultiXactId multi = from_multi; multi != to_multi;) - { - MultiXactMember member; - bool multixid_valid; - - /* - * Read this multixid's members. - * - * Locking-only XIDs that may be part of multi-xids don't matter - * after upgrade, as there can be no transactions running across - * upgrade. So as a small optimization, we only read one member - * from each multixid: the one updating one, or if there was no - * update, arbitrarily the first locking xid. - */ - multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); + for (MultiXactId multi = from_multi; multi != to_multi;) + { + MultiXactMember member; + bool multixid_valid; - /* - * Write the new offset to pg_multixact/offsets. - * - * Even if this multixid is invalid, we still need to write its - * offset if the *previous* multixid was valid. That's because - * when reading a multixid, the number of members is calculated - * from the difference between the two offsets. - */ - RecordMultiXactOffset(offsets_writer, multi, - (multixid_valid || prev_multixid_valid) ? next_offset : 0); + /* + * Read this multixid's members. + * + * Locking-only XIDs that may be part of multi-xids don't matter after + * upgrade, as there can be no transactions running across upgrade. So + * as a small optimization, we only read one member from each + * multixid: the one updating one, or if there was no update, + * arbitrarily the first locking xid. + */ + multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); - /* Write the members */ - if (multixid_valid) - { - RecordMultiXactMembers(members_writer, next_offset, 1, &member); - next_offset += 1; - } + /* + * Write the new offset to pg_multixact/offsets. + * + * Even if this multixid is invalid, we still need to write its offset + * if the *previous* multixid was valid. That's because when reading + * a multixid, the number of members is calculated from the difference + * between the two offsets. + */ + RecordMultiXactOffset(offsets_writer, multi, + (multixid_valid || prev_multixid_valid) ? next_offset : 0); - /* Advance to next multixid, handling wraparound */ - multi++; - if (multi < FirstMultiXactId) - multi = FirstMultiXactId; - prev_multixid_valid = multixid_valid; + /* Write the members */ + if (multixid_valid) + { + RecordMultiXactMembers(members_writer, next_offset, 1, &member); + next_offset += 1; } - FreeOldMultiXactReader(old_reader); + /* Advance to next multixid, handling wraparound */ + multi++; + if (multi < FirstMultiXactId) + multi = FirstMultiXactId; + prev_multixid_valid = multixid_valid; + } + + FreeOldMultiXactReader(old_reader); /* Write the final 'next' offset to the last SLRU page */ RecordMultiXactOffset(offsets_writer, to_multi, diff --git a/src/bin/pg_upgrade/pg_upgrade.c b/src/bin/pg_upgrade/pg_upgrade.c index c6af9035665..7366fd4627c 100644 --- a/src/bin/pg_upgrade/pg_upgrade.c +++ b/src/bin/pg_upgrade/pg_upgrade.c @@ -833,7 +833,7 @@ copy_xact_xlog_xid(void) * Determine the range of multixacts to convert. */ nxtmulti = old_cluster.controldata.chkpnt_nxtmulti; - oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; + oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; /* handle wraparound */ if (nxtmulti < FirstMultiXactId) nxtmulti = FirstMultiXactId; @@ -898,15 +898,15 @@ set_frozenxids(void) int i_datname; int i_datallowconn; - prep_status("Setting frozenxid and minmxid counters in new cluster"); + prep_status("Setting frozenxid and minmxid counters in new cluster"); conn_template1 = connectToServer(&new_cluster, "template1"); - /* set pg_database.datfrozenxid */ - PQclear(executeQueryOrDie(conn_template1, - "UPDATE pg_catalog.pg_database " - "SET datfrozenxid = '%u'", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_database.datfrozenxid */ + PQclear(executeQueryOrDie(conn_template1, + "UPDATE pg_catalog.pg_database " + "SET datfrozenxid = '%u'", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_database.datminmxid */ PQclear(executeQueryOrDie(conn_template1, @@ -942,16 +942,16 @@ set_frozenxids(void) conn = connectToServer(&new_cluster, datname); - /* set pg_class.relfrozenxid */ - PQclear(executeQueryOrDie(conn, - "UPDATE pg_catalog.pg_class " - "SET relfrozenxid = '%u' " - /* only heap, materialized view, and TOAST are vacuumed */ - "WHERE relkind IN (" - CppAsString2(RELKIND_RELATION) ", " - CppAsString2(RELKIND_MATVIEW) ", " - CppAsString2(RELKIND_TOASTVALUE) ")", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_class.relfrozenxid */ + PQclear(executeQueryOrDie(conn, + "UPDATE pg_catalog.pg_class " + "SET relfrozenxid = '%u' " + /* only heap, materialized view, and TOAST are vacuumed */ + "WHERE relkind IN (" + CppAsString2(RELKIND_RELATION) ", " + CppAsString2(RELKIND_MATVIEW) ", " + CppAsString2(RELKIND_TOASTVALUE) ")", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_class.relminmxid */ PQclear(executeQueryOrDie(conn, diff --git a/src/bin/pg_upgrade/relfilenumber.c b/src/bin/pg_upgrade/relfilenumber.c index ec2ff7acb21..6c467bdc8a5 100644 --- a/src/bin/pg_upgrade/relfilenumber.c +++ b/src/bin/pg_upgrade/relfilenumber.c @@ -587,32 +587,32 @@ transfer_relfile(FileNameMap *map, const char *type_suffix) /* Copying files might take some time, so give feedback. */ pg_log(PG_STATUS, "%s", old_file); - switch (user_opts.transfer_mode) - { - case TRANSFER_MODE_CLONE: - pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", - old_file, new_file); - cloneFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", - old_file, new_file); - copyFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY_FILE_RANGE: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", - old_file, new_file); - copyFileByRange(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_LINK: - pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", - old_file, new_file); - linkFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_SWAP: - /* swap mode is handled in its own code path */ - pg_fatal("should never happen"); - break; - } + switch (user_opts.transfer_mode) + { + case TRANSFER_MODE_CLONE: + pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", + old_file, new_file); + cloneFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", + old_file, new_file); + copyFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY_FILE_RANGE: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", + old_file, new_file); + copyFileByRange(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_LINK: + pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", + old_file, new_file); + linkFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_SWAP: + /* swap mode is handled in its own code path */ + pg_fatal("should never happen"); + break; + } } } diff --git a/src/bin/pg_upgrade/t/006_transfer_modes.pl b/src/bin/pg_upgrade/t/006_transfer_modes.pl index 9efa5dc863c..360d05c4b68 100644 --- a/src/bin/pg_upgrade/t/006_transfer_modes.pl +++ b/src/bin/pg_upgrade/t/006_transfer_modes.pl @@ -29,10 +29,8 @@ sub test_mode } $new->init(); - $new->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); - $old->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); + $new->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); + $old->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); # We can only test security labels if both the old and new installations # have dummy_seclabel. @@ -76,15 +74,14 @@ sub test_mode "CREATE TABLE test4 AS SELECT generate_series(400, 502)"); } - $old->safe_psql('postgres', - "CREATE TABLESPACE inplc_tblspc LOCATION ''"); - $old->safe_psql('postgres', - "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); - $old->safe_psql('postgres', - "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" - ); - $old->safe_psql('testdb3', - "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); + $old->safe_psql('postgres', "CREATE TABLESPACE inplc_tblspc LOCATION ''"); + $old->safe_psql('postgres', + "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); + $old->safe_psql('postgres', + "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" + ); + $old->safe_psql('testdb3', + "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); # While we are here, test handling of large objects. $old->safe_psql( @@ -152,12 +149,10 @@ sub test_mode } # Tests for in-place tablespaces. - $result = - $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); - is($result, '104', "test5 data after pg_upgrade $mode"); - $result = - $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); - is($result, '105', "test6 data after pg_upgrade $mode"); + $result = $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); + is($result, '104', "test5 data after pg_upgrade $mode"); + $result = $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); + is($result, '105', "test6 data after pg_upgrade $mode"); # Tests for large objects $result = $new->safe_psql('postgres', "SELECT lo_get(4532)"); diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index 44ef11d980e..c90bf8bbde2 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -6278,23 +6278,22 @@ get_create_object_cmd(EditableObjectType obj_type, Oid oid, * ensure the right view gets replaced. Also, check relation kind * to be sure it's a view. * - * Views may have WITH [LOCAL|CASCADED] - * CHECK OPTION. These are not part of the view definition - * returned by pg_get_viewdef() and so need to be retrieved - * separately. Materialized views may have - * arbitrary storage parameter reloptions. + * Views may have WITH [LOCAL|CASCADED] CHECK OPTION. These are + * not part of the view definition returned by pg_get_viewdef() + * and so need to be retrieved separately. Materialized views may + * have arbitrary storage parameter reloptions. */ printfPQExpBuffer(query, "/* %s */\n", _("Get view's definition and details")); - appendPQExpBuffer(query, - "SELECT nspname, relname, relkind, " - "pg_catalog.pg_get_viewdef(c.oid, true), " - "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " - "FROM pg_catalog.pg_class c " - "LEFT JOIN pg_catalog.pg_namespace n " - "ON c.relnamespace = n.oid WHERE c.oid = %u", - oid); + appendPQExpBuffer(query, + "SELECT nspname, relname, relkind, " + "pg_catalog.pg_get_viewdef(c.oid, true), " + "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " + "FROM pg_catalog.pg_class c " + "LEFT JOIN pg_catalog.pg_namespace n " + "ON c.relnamespace = n.oid WHERE c.oid = %u", + oid); break; } diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index ce99137c613..ac0c55e7aa5 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -387,19 +387,19 @@ describeFunctions(const char *functypes, const char *func_pattern, gettext_noop("stable"), gettext_noop("volatile"), gettext_noop("Volatility")); - appendPQExpBuffer(&buf, - ",\n CASE\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" - " END as \"%s\"", - gettext_noop("restricted"), - gettext_noop("safe"), - gettext_noop("unsafe"), - gettext_noop("Parallel")); + appendPQExpBuffer(&buf, + ",\n CASE\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" + " END as \"%s\"", + gettext_noop("restricted"), + gettext_noop("safe"), + gettext_noop("unsafe"), + gettext_noop("Parallel")); appendPQExpBuffer(&buf, ",\n pg_catalog.pg_get_userbyid(p.proowner) as \"%s\"" ",\n CASE WHEN prosecdef THEN '%s' ELSE '%s' END AS \"%s\"" @@ -599,8 +599,8 @@ describeFunctions(const char *functypes, const char *func_pattern, myopt.title = _("List of functions"); myopt.translate_header = true; - myopt.translate_columns = translate_columns; - myopt.n_translate_columns = lengthof(translate_columns); + myopt.translate_columns = translate_columns; + myopt.n_translate_columns = lengthof(translate_columns); printQuery(res, &myopt, pset.queryFout, false, pset.logfile); @@ -1086,38 +1086,38 @@ permissionsList(const char *pattern, bool showSystem) " ), E'\\n') AS \"%s\"", gettext_noop("Column privileges")); - appendPQExpBuffer(&buf, - ",\n pg_catalog.array_to_string(ARRAY(\n" - " SELECT polname\n" - " || CASE WHEN NOT polpermissive THEN\n" - " E' (RESTRICTIVE)'\n" - " ELSE '' END\n" - " || CASE WHEN polcmd != '*' THEN\n" - " E' (' || polcmd::pg_catalog.text || E'):'\n" - " ELSE E':'\n" - " END\n" - " || CASE WHEN polqual IS NOT NULL THEN\n" - " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" - " ELSE E''\n" - " END\n" - " || CASE WHEN polwithcheck IS NOT NULL THEN\n" - " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" - " ELSE E''\n" - " END" - " || CASE WHEN polroles <> '{0}' THEN\n" - " E'\\n to: ' || pg_catalog.array_to_string(\n" - " ARRAY(\n" - " SELECT rolname\n" - " FROM pg_catalog.pg_roles\n" - " WHERE oid = ANY (polroles)\n" - " ORDER BY 1\n" - " ), E', ')\n" - " ELSE E''\n" - " END\n" - " FROM pg_catalog.pg_policy pol\n" - " WHERE polrelid = c.oid), E'\\n')\n" - " AS \"%s\"", - gettext_noop("Policies")); + appendPQExpBuffer(&buf, + ",\n pg_catalog.array_to_string(ARRAY(\n" + " SELECT polname\n" + " || CASE WHEN NOT polpermissive THEN\n" + " E' (RESTRICTIVE)'\n" + " ELSE '' END\n" + " || CASE WHEN polcmd != '*' THEN\n" + " E' (' || polcmd::pg_catalog.text || E'):'\n" + " ELSE E':'\n" + " END\n" + " || CASE WHEN polqual IS NOT NULL THEN\n" + " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" + " ELSE E''\n" + " END\n" + " || CASE WHEN polwithcheck IS NOT NULL THEN\n" + " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" + " ELSE E''\n" + " END" + " || CASE WHEN polroles <> '{0}' THEN\n" + " E'\\n to: ' || pg_catalog.array_to_string(\n" + " ARRAY(\n" + " SELECT rolname\n" + " FROM pg_catalog.pg_roles\n" + " WHERE oid = ANY (polroles)\n" + " ORDER BY 1\n" + " ), E', ')\n" + " ELSE E''\n" + " END\n" + " FROM pg_catalog.pg_policy pol\n" + " WHERE polrelid = c.oid), E'\\n')\n" + " AS \"%s\"", + gettext_noop("Policies")); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_class c\n" " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n" @@ -1675,27 +1675,27 @@ describeOneTableDetails(const char *schemaname, char *footers[3] = {NULL, NULL, NULL}; printfPQExpBuffer(&buf, "/* %s */\n", _("Get sequence information")); - appendPQExpBuffer(&buf, - "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" - " seqstart AS \"%s\",\n" - " seqmin AS \"%s\",\n" - " seqmax AS \"%s\",\n" - " seqincrement AS \"%s\",\n" - " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" - " seqcache AS \"%s\"\n", - gettext_noop("Type"), - gettext_noop("Start"), - gettext_noop("Minimum"), - gettext_noop("Maximum"), - gettext_noop("Increment"), - gettext_noop("yes"), - gettext_noop("no"), - gettext_noop("Cycles?"), - gettext_noop("Cache")); - appendPQExpBuffer(&buf, - "FROM pg_catalog.pg_sequence\n" - "WHERE seqrelid = '%s';", - oid); + appendPQExpBuffer(&buf, + "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" + " seqstart AS \"%s\",\n" + " seqmin AS \"%s\",\n" + " seqmax AS \"%s\",\n" + " seqincrement AS \"%s\",\n" + " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" + " seqcache AS \"%s\"\n", + gettext_noop("Type"), + gettext_noop("Start"), + gettext_noop("Minimum"), + gettext_noop("Maximum"), + gettext_noop("Increment"), + gettext_noop("yes"), + gettext_noop("no"), + gettext_noop("Cycles?"), + gettext_noop("Cache")); + appendPQExpBuffer(&buf, + "FROM pg_catalog.pg_sequence\n" + "WHERE seqrelid = '%s';", + oid); res = PSQLexec(buf.data); if (!res) @@ -1913,7 +1913,7 @@ describeOneTableDetails(const char *schemaname, appendPQExpBufferStr(&buf, ",\n (SELECT c.collname FROM pg_catalog.pg_collation c, pg_catalog.pg_type t\n" " WHERE c.oid = a.attcollation AND t.oid = a.atttypid AND a.attcollation <> t.typcollation) AS attcollation"); attcoll_col = cols++; - appendPQExpBufferStr(&buf, ",\n a.attidentity"); + appendPQExpBufferStr(&buf, ",\n a.attidentity"); attidentity_col = cols++; if (pset.sversion >= 120000) appendPQExpBufferStr(&buf, ",\n a.attgenerated"); @@ -2326,7 +2326,7 @@ describeOneTableDetails(const char *schemaname, CppAsString2(CONSTRAINT_EXCLUSION) ") AND " "condeferred) AS condeferred,\n"); - appendPQExpBufferStr(&buf, "i.indisreplident,\n"); + appendPQExpBufferStr(&buf, "i.indisreplident,\n"); if (pset.sversion >= 150000) appendPQExpBufferStr(&buf, "i.indnullsnotdistinct,\n"); @@ -2431,7 +2431,7 @@ describeOneTableDetails(const char *schemaname, "pg_catalog.pg_get_indexdef(i.indexrelid, 0, true),\n " "pg_catalog.pg_get_constraintdef(con.oid, true), " "contype, condeferrable, condeferred"); - appendPQExpBufferStr(&buf, ", i.indisreplident"); + appendPQExpBufferStr(&buf, ", i.indisreplident"); appendPQExpBufferStr(&buf, ", c2.reltablespace"); if (pset.sversion >= 180000) appendPQExpBufferStr(&buf, ", con.conperiod"); @@ -2682,81 +2682,80 @@ describeOneTableDetails(const char *schemaname, PQclear(result); /* print any row-level policies */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get row-level policies for this table")); - appendPQExpBufferStr(&buf, "SELECT pol.polname,"); - appendPQExpBufferStr(&buf, - " pol.polpermissive,\n"); - appendPQExpBuffer(&buf, - " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" - " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" - " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" - " CASE pol.polcmd\n" - " WHEN 'r' THEN 'SELECT'\n" - " WHEN 'a' THEN 'INSERT'\n" - " WHEN 'w' THEN 'UPDATE'\n" - " WHEN 'd' THEN 'DELETE'\n" - " END AS cmd\n" - "FROM pg_catalog.pg_policy pol\n" - "WHERE pol.polrelid = '%s' ORDER BY 1;", - oid); + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get row-level policies for this table")); + appendPQExpBufferStr(&buf, "SELECT pol.polname,"); + appendPQExpBufferStr(&buf, + " pol.polpermissive,\n"); + appendPQExpBuffer(&buf, + " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" + " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" + " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" + " CASE pol.polcmd\n" + " WHEN 'r' THEN 'SELECT'\n" + " WHEN 'a' THEN 'INSERT'\n" + " WHEN 'w' THEN 'UPDATE'\n" + " WHEN 'd' THEN 'DELETE'\n" + " END AS cmd\n" + "FROM pg_catalog.pg_policy pol\n" + "WHERE pol.polrelid = '%s' ORDER BY 1;", + oid); - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - /* - * Handle cases where RLS is enabled and there are policies, or - * there aren't policies, or RLS isn't enabled but there are - * policies - */ - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies:")); + /* + * Handle cases where RLS is enabled and there are policies, or there + * aren't policies, or RLS isn't enabled but there are policies + */ + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies:")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled):")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled):")); - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); - if (!tableinfo.rowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (row security disabled):")); + if (!tableinfo.rowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (row security disabled):")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " POLICY \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " POLICY \"%s\"", + PQgetvalue(result, i, 0)); - if (*(PQgetvalue(result, i, 1)) == 'f') - appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); + if (*(PQgetvalue(result, i, 1)) == 'f') + appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); - if (!PQgetisnull(result, i, 5)) - appendPQExpBuffer(&buf, " FOR %s", - PQgetvalue(result, i, 5)); + if (!PQgetisnull(result, i, 5)) + appendPQExpBuffer(&buf, " FOR %s", + PQgetvalue(result, i, 5)); - if (!PQgetisnull(result, i, 2)) - { - appendPQExpBuffer(&buf, "\n TO %s", - PQgetvalue(result, i, 2)); - } + if (!PQgetisnull(result, i, 2)) + { + appendPQExpBuffer(&buf, "\n TO %s", + PQgetvalue(result, i, 2)); + } - if (!PQgetisnull(result, i, 3)) - appendPQExpBuffer(&buf, "\n USING (%s)", - PQgetvalue(result, i, 3)); + if (!PQgetisnull(result, i, 3)) + appendPQExpBuffer(&buf, "\n USING (%s)", + PQgetvalue(result, i, 3)); - if (!PQgetisnull(result, i, 4)) - appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", - PQgetvalue(result, i, 4)); + if (!PQgetisnull(result, i, 4)) + appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", + PQgetvalue(result, i, 4)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* print any extended statistics */ if (pset.sversion >= 140000) @@ -3025,115 +3024,115 @@ describeOneTableDetails(const char *schemaname, } /* print any publications */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get publications that publish this table")); - if (pset.sversion >= 150000) + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get publications that publish this table")); + if (pset.sversion >= 150000) + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" + " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" + "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" + "UNION\n" + "SELECT pubname\n" + " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" + " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" + " (SELECT pg_catalog.string_agg(attname, ', ')\n" + " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" + " pg_catalog.pg_attribute\n" + " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" + " ELSE NULL END) " + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" + "WHERE pr.prrelid = '%s'\n", + oid, oid, oid); + + if (pset.sversion >= 190000) { + /* + * Skip entries where this relation appears in the + * publication's EXCEPT list. + */ appendPQExpBuffer(&buf, + " AND NOT pr.prexcept\n" + "UNION\n" "SELECT pubname\n" " , NULL\n" " , NULL\n" "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" - " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" - "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" - "UNION\n" - "SELECT pubname\n" - " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" - " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" - " (SELECT pg_catalog.string_agg(attname, ', ')\n" - " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" - " pg_catalog.pg_attribute\n" - " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" - " ELSE NULL END) " - "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" - "WHERE pr.prrelid = '%s'\n", + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + " AND NOT EXISTS (\n" + " SELECT 1\n" + " FROM pg_catalog.pg_publication_rel pr\n" + " WHERE pr.prpubid = p.oid AND\n" + " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" + "ORDER BY 1;", oid, oid, oid); - - if (pset.sversion >= 190000) - { - /* - * Skip entries where this relation appears in the - * publication's EXCEPT list. - */ - appendPQExpBuffer(&buf, - " AND NOT pr.prexcept\n" - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - " AND NOT EXISTS (\n" - " SELECT 1\n" - " FROM pg_catalog.pg_publication_rel pr\n" - " WHERE pr.prpubid = p.oid AND\n" - " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" - "ORDER BY 1;", - oid, oid, oid); - } - else - { - appendPQExpBuffer(&buf, - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - "ORDER BY 1;", - oid); - } } else { appendPQExpBuffer(&buf, + "UNION\n" "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - "WHERE pr.prrelid = '%s'\n" - "UNION ALL\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" + " , NULL\n" + " , NULL\n" "FROM pg_catalog.pg_publication p\n" "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" "ORDER BY 1;", - oid, oid); + oid); } + } + else + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + "WHERE pr.prrelid = '%s'\n" + "UNION ALL\n" + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + "ORDER BY 1;", + oid, oid); + } - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - if (tuples > 0) - printTableAddFooter(&cont, _("Included in publications:")); + if (tuples > 0) + printTableAddFooter(&cont, _("Included in publications:")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " \"%s\"", + PQgetvalue(result, i, 0)); - /* column list (if any) */ - if (!PQgetisnull(result, i, 2)) - appendPQExpBuffer(&buf, " (%s)", - PQgetvalue(result, i, 2)); + /* column list (if any) */ + if (!PQgetisnull(result, i, 2)) + appendPQExpBuffer(&buf, " (%s)", + PQgetvalue(result, i, 2)); - /* row filter (if any) */ - if (!PQgetisnull(result, i, 1)) - appendPQExpBuffer(&buf, " WHERE %s", - PQgetvalue(result, i, 1)); + /* row filter (if any) */ + if (!PQgetisnull(result, i, 1)) + appendPQExpBuffer(&buf, " WHERE %s", + PQgetvalue(result, i, 1)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* Print publications where the table is in the EXCEPT clause */ if (pset.sversion >= 190000) @@ -3805,7 +3804,7 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) ncols++; } appendPQExpBufferStr(&buf, "\n, r.rolreplication"); - appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); + appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_roles r\n"); @@ -3860,8 +3859,8 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) if (strcmp(PQgetvalue(res, i, (verbose ? 9 : 8)), "t") == 0) add_role_attribute(&buf, _("Replication")); - if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) - add_role_attribute(&buf, _("Bypass RLS")); + if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) + add_role_attribute(&buf, _("Bypass RLS")); conns = atoi(PQgetvalue(res, i, 6)); if (conns >= 0) @@ -5155,14 +5154,14 @@ listCollations(const char *pattern, bool verbose, bool showSystem) gettext_noop("Schema"), gettext_noop("Name")); - appendPQExpBuffer(&buf, - " CASE c.collprovider " - "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " - "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " - "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " - "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " - "END AS \"%s\",\n", - gettext_noop("Provider")); + appendPQExpBuffer(&buf, + " CASE c.collprovider " + "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " + "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " + "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " + "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " + "END AS \"%s\",\n", + gettext_noop("Provider")); appendPQExpBuffer(&buf, " c.collcollate AS \"%s\",\n" -- 2.50.1 (Apple Git-155) --aHl3HfeiUuO3zeNC-- ^ permalink raw reply [nested|flat] 59+ messages in thread
* [PATCH v6 4/4] run pgindent and pgperltidy @ 2026-06-30 18:24 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 59+ messages in thread From: Nathan Bossart @ 2026-06-30 18:24 UTC (permalink / raw) --- src/bin/pg_dump/pg_dump.c | 464 ++++++++++----------- src/bin/pg_dump/pg_dumpall.c | 30 +- src/bin/pg_upgrade/check.c | 16 +- src/bin/pg_upgrade/controldata.c | 2 +- src/bin/pg_upgrade/exec.c | 8 +- src/bin/pg_upgrade/multixact_rewrite.c | 80 ++-- src/bin/pg_upgrade/pg_upgrade.c | 34 +- src/bin/pg_upgrade/relfilenumber.c | 54 +-- src/bin/pg_upgrade/t/006_transfer_modes.pl | 33 +- src/bin/psql/command.c | 29 +- src/bin/psql/describe.c | 461 ++++++++++---------- 11 files changed, 601 insertions(+), 610 deletions(-) diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 65bd15ebfd2..5673268b467 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -1491,8 +1491,8 @@ setup_connection(Archive *AH, const char *dumpencoding, * Disable timeouts if supported. */ ExecuteSqlStatement(AH, "SET statement_timeout = 0"); - ExecuteSqlStatement(AH, "SET lock_timeout = 0"); - ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); + ExecuteSqlStatement(AH, "SET lock_timeout = 0"); + ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); if (AH->remoteVersion >= 170000) ExecuteSqlStatement(AH, "SET transaction_timeout = 0"); @@ -1505,10 +1505,10 @@ setup_connection(Archive *AH, const char *dumpencoding, /* * Adjust row-security mode, if supported. */ - if (dopt->enable_row_security) - ExecuteSqlStatement(AH, "SET row_security = on"); - else - ExecuteSqlStatement(AH, "SET row_security = off"); + if (dopt->enable_row_security) + ExecuteSqlStatement(AH, "SET row_security = on"); + else + ExecuteSqlStatement(AH, "SET row_security = off"); /* * For security reasons, we restrict the expansion of non-system views and @@ -1933,10 +1933,9 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) addObjectDependency(dobj, ext->dobj.dumpId); /* - * Mark the member object to have any non-initial ACLs - * dumped. (Any initial ACLs will be removed later, using data from - * pg_init_privs, so that we'll dump only the delta from the extension's - * initial setup.) + * Mark the member object to have any non-initial ACLs dumped. (Any + * initial ACLs will be removed later, using data from pg_init_privs, so + * that we'll dump only the delta from the extension's initial setup.) * * In binary upgrades, we still dump all components of the members * individually, since the idea is to exactly reproduce the database @@ -1953,7 +1952,7 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) if (fout->dopt->binary_upgrade) dobj->dump = ext->dobj.dump; else - dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); + dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); return true; } @@ -1987,9 +1986,9 @@ selectDumpableNamespace(NamespaceInfo *nsinfo, Archive *fout) else if (strcmp(nsinfo->dobj.name, "pg_catalog") == 0) { /* - * We dump out any ACLs defined in pg_catalog, if - * they are interesting (and not the original ACLs which were set at - * initdb time, see pg_init_privs). + * We dump out any ACLs defined in pg_catalog, if they are interesting + * (and not the original ACLs which were set at initdb time, see + * pg_init_privs). */ nsinfo->dobj.dump_contains = nsinfo->dobj.dump = DUMP_COMPONENT_ACL; } @@ -3296,7 +3295,7 @@ dumpDatabase(Archive *fout) "datcollate, datctype, datfrozenxid, " "datacl, acldefault('d', datdba) AS acldefault, " "datistemplate, datconnlimit, "); - appendPQExpBufferStr(dbQry, "datminmxid, "); + appendPQExpBufferStr(dbQry, "datminmxid, "); if (fout->remoteVersion >= 170000) appendPQExpBufferStr(dbQry, "datlocprovider, datlocale, datcollversion, "); else if (fout->remoteVersion >= 150000) @@ -3638,11 +3637,11 @@ dumpDatabase(Archive *fout) ii_oid, ii_relminmxid; - appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" - "FROM pg_catalog.pg_class\n" - "WHERE oid IN (%u, %u, %u, %u);\n", - LargeObjectRelationId, LargeObjectLOidPNIndexId, - LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); + appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" + "FROM pg_catalog.pg_class\n" + "WHERE oid IN (%u, %u, %u, %u);\n", + LargeObjectRelationId, LargeObjectLOidPNIndexId, + LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); lo_res = ExecuteSqlQuery(fout, loFrozenQry->data, PGRES_TUPLES_OK); @@ -4274,7 +4273,7 @@ getPolicies(Archive *fout, TableInfo tblinfo[], int numTables) printfPQExpBuffer(query, "SELECT pol.oid, pol.tableoid, pol.polrelid, pol.polname, pol.polcmd, "); - appendPQExpBufferStr(query, "pol.polpermissive, "); + appendPQExpBufferStr(query, "pol.polpermissive, "); appendPQExpBuffer(query, "CASE WHEN pol.polroles = '{0}' THEN NULL ELSE " " pg_catalog.array_to_string(ARRAY(SELECT pg_catalog.quote_ident(rolname) from pg_catalog.pg_roles WHERE oid = ANY(pol.polroles)), ', ') END AS polroles, " @@ -6633,9 +6632,9 @@ getAccessMethods(Archive *fout) * Select all access methods from pg_am table. */ appendPQExpBufferStr(query, "SELECT tableoid, oid, amname, "); - appendPQExpBufferStr(query, - "amtype, " - "amhandler::pg_catalog.regproc AS amhandler "); + appendPQExpBufferStr(query, + "amtype, " + "amhandler::pg_catalog.regproc AS amhandler "); appendPQExpBufferStr(query, "FROM pg_am"); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6827,35 +6826,35 @@ getAggregates(Archive *fout) * Find all interesting aggregates. See comment in getFuncs() for the * rationale behind the filtering logic. */ - agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" - : "p.proisagg"); + agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" + : "p.proisagg"); - appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " - "p.proname AS aggname, " - "p.pronamespace AS aggnamespace, " - "p.pronargs, p.proargtypes, " - "p.proowner, " - "p.proacl AS aggacl, " - "acldefault('f', p.proowner) AS acldefault " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s AND (" - "p.pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog') OR " - "p.proacl IS DISTINCT FROM pip.initprivs", - agg_check); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - " OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); - appendPQExpBufferChar(query, ')'); + appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " + "p.proname AS aggname, " + "p.pronamespace AS aggnamespace, " + "p.pronargs, p.proargtypes, " + "p.proowner, " + "p.proacl AS aggacl, " + "acldefault('f', p.proowner) AS acldefault " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s AND (" + "p.pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog') OR " + "p.proacl IS DISTINCT FROM pip.initprivs", + agg_check); + if (dopt->binary_upgrade) + appendPQExpBufferStr(query, + " OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6957,53 +6956,53 @@ getFuncs(Archive *fout) * include them, since we want to dump extension members individually in * that mode. Also, if they are used by casts or transforms then we need * to gather the information about them, though they won't be dumped if - * they are built-in. Also, include functions in - * pg_catalog if they have an ACL different from what's shown in - * pg_init_privs (so we have to join to pg_init_privs; annoying). + * they are built-in. Also, include functions in pg_catalog if they have + * an ACL different from what's shown in pg_init_privs (so we have to join + * to pg_init_privs; annoying). */ - not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" - : "NOT p.proisagg"); + not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" + : "NOT p.proisagg"); - appendPQExpBuffer(query, - "SELECT p.tableoid, p.oid, p.proname, p.prolang, " - "p.pronargs, p.proargtypes, p.prorettype, " - "p.proacl, " - "acldefault('f', p.proowner) AS acldefault, " - "p.pronamespace, " - "p.proowner " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s" - "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " - "WHERE classid = 'pg_proc'::regclass AND " - "objid = p.oid AND deptype = 'i')" - "\n AND (" - "\n pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog')" - "\n OR EXISTS (SELECT 1 FROM pg_cast" - "\n WHERE pg_cast.oid > %u " - "\n AND p.oid = pg_cast.castfunc)" - "\n OR EXISTS (SELECT 1 FROM pg_transform" - "\n WHERE pg_transform.oid > %u AND " - "\n (p.oid = pg_transform.trffromsql" - "\n OR p.oid = pg_transform.trftosql))", - not_agg_check, - g_last_builtin_oid, - g_last_builtin_oid); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); + appendPQExpBuffer(query, + "SELECT p.tableoid, p.oid, p.proname, p.prolang, " + "p.pronargs, p.proargtypes, p.prorettype, " + "p.proacl, " + "acldefault('f', p.proowner) AS acldefault, " + "p.pronamespace, " + "p.proowner " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s" + "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " + "WHERE classid = 'pg_proc'::regclass AND " + "objid = p.oid AND deptype = 'i')" + "\n AND (" + "\n pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog')" + "\n OR EXISTS (SELECT 1 FROM pg_cast" + "\n WHERE pg_cast.oid > %u " + "\n AND p.oid = pg_cast.castfunc)" + "\n OR EXISTS (SELECT 1 FROM pg_transform" + "\n WHERE pg_transform.oid > %u AND " + "\n (p.oid = pg_transform.trffromsql" + "\n OR p.oid = pg_transform.trftosql))", + not_agg_check, + g_last_builtin_oid, + g_last_builtin_oid); + if (dopt->binary_upgrade) appendPQExpBufferStr(query, - "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); - appendPQExpBufferChar(query, ')'); + "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferStr(query, + "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -7252,31 +7251,31 @@ getTables(Archive *fout, int *numTables) appendPQExpBufferStr(query, "c.relhasoids, "); - appendPQExpBufferStr(query, - "c.relispopulated, "); + appendPQExpBufferStr(query, + "c.relispopulated, "); - appendPQExpBufferStr(query, - "c.relreplident, "); + appendPQExpBufferStr(query, + "c.relreplident, "); - appendPQExpBufferStr(query, - "c.relrowsecurity, c.relforcerowsecurity, "); + appendPQExpBufferStr(query, + "c.relrowsecurity, c.relforcerowsecurity, "); - appendPQExpBufferStr(query, - "c.relminmxid, tc.relminmxid AS tminmxid, "); + appendPQExpBufferStr(query, + "c.relminmxid, tc.relminmxid AS tminmxid, "); - appendPQExpBufferStr(query, - "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); + appendPQExpBufferStr(query, + "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); - appendPQExpBufferStr(query, - "am.amname, "); + appendPQExpBufferStr(query, + "am.amname, "); - appendPQExpBufferStr(query, - "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); + appendPQExpBufferStr(query, + "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); - appendPQExpBufferStr(query, - "c.relispartition AS ispartition "); + appendPQExpBufferStr(query, + "c.relispartition AS ispartition "); /* * Left join to pg_depend to pick up dependency info linking sequences to @@ -7296,8 +7295,8 @@ getTables(Archive *fout, int *numTables) /* * Left join to pg_am to pick up the amname. */ - appendPQExpBufferStr(query, - "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); + appendPQExpBufferStr(query, + "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); /* * We purposefully ignore toast OIDs for partitioned tables; the reason is @@ -7868,8 +7867,8 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables) "t.reloptions AS indreloptions, "); - appendPQExpBufferStr(query, - "i.indisreplident, "); + appendPQExpBufferStr(query, + "i.indisreplident, "); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -9313,8 +9312,8 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables) appendPQExpBufferStr(q, "'' AS attcompression,\n"); - appendPQExpBufferStr(q, - "a.attidentity,\n"); + appendPQExpBufferStr(q, + "a.attidentity,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(q, @@ -10717,73 +10716,73 @@ getAdditionalACLs(Archive *fout) PQclear(res); /* Fetch initial-privileges data */ - printfPQExpBuffer(query, - "SELECT objoid, classoid, objsubid, privtype, initprivs " - "FROM pg_init_privs"); + printfPQExpBuffer(query, + "SELECT objoid, classoid, objsubid, privtype, initprivs " + "FROM pg_init_privs"); - res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); + res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); - ntups = PQntuples(res); - for (i = 0; i < ntups; i++) - { - Oid objoid = atooid(PQgetvalue(res, i, 0)); - Oid classoid = atooid(PQgetvalue(res, i, 1)); - int objsubid = atoi(PQgetvalue(res, i, 2)); - char privtype = *(PQgetvalue(res, i, 3)); - char *initprivs = PQgetvalue(res, i, 4); - CatalogId objId; - DumpableObject *dobj; + ntups = PQntuples(res); + for (i = 0; i < ntups; i++) + { + Oid objoid = atooid(PQgetvalue(res, i, 0)); + Oid classoid = atooid(PQgetvalue(res, i, 1)); + int objsubid = atoi(PQgetvalue(res, i, 2)); + char privtype = *(PQgetvalue(res, i, 3)); + char *initprivs = PQgetvalue(res, i, 4); + CatalogId objId; + DumpableObject *dobj; - objId.tableoid = classoid; - objId.oid = objoid; - dobj = findObjectByCatalogId(objId); - /* OK to ignore entries we haven't got a DumpableObject for */ - if (dobj) + objId.tableoid = classoid; + objId.oid = objoid; + dobj = findObjectByCatalogId(objId); + /* OK to ignore entries we haven't got a DumpableObject for */ + if (dobj) + { + /* Cope with sub-object initprivs */ + if (objsubid != 0) { - /* Cope with sub-object initprivs */ - if (objsubid != 0) - { - if (dobj->objType == DO_TABLE) - { - /* For a column initprivs, set the table's ACL flags */ - dobj->components |= DUMP_COMPONENT_ACL; - ((TableInfo *) dobj)->hascolumnACLs = true; - } - else - pg_log_warning("unsupported pg_init_privs entry: %u %u %d", - classoid, objoid, objsubid); - continue; - } - - /* - * We ignore any pg_init_privs.initprivs entry for the public - * schema, as explained in getNamespaces(). - */ - if (dobj->objType == DO_NAMESPACE && - strcmp(dobj->name, "public") == 0) - continue; - - /* Else it had better be of a type we think has ACLs */ - if (dobj->objType == DO_NAMESPACE || - dobj->objType == DO_TYPE || - dobj->objType == DO_FUNC || - dobj->objType == DO_AGG || - dobj->objType == DO_TABLE || - dobj->objType == DO_PROCLANG || - dobj->objType == DO_FDW || - dobj->objType == DO_FOREIGN_SERVER) + if (dobj->objType == DO_TABLE) { - DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; - - daobj->dacl.privtype = privtype; - daobj->dacl.initprivs = pstrdup(initprivs); + /* For a column initprivs, set the table's ACL flags */ + dobj->components |= DUMP_COMPONENT_ACL; + ((TableInfo *) dobj)->hascolumnACLs = true; } else pg_log_warning("unsupported pg_init_privs entry: %u %u %d", classoid, objoid, objsubid); + continue; + } + + /* + * We ignore any pg_init_privs.initprivs entry for the public + * schema, as explained in getNamespaces(). + */ + if (dobj->objType == DO_NAMESPACE && + strcmp(dobj->name, "public") == 0) + continue; + + /* Else it had better be of a type we think has ACLs */ + if (dobj->objType == DO_NAMESPACE || + dobj->objType == DO_TYPE || + dobj->objType == DO_FUNC || + dobj->objType == DO_AGG || + dobj->objType == DO_TABLE || + dobj->objType == DO_PROCLANG || + dobj->objType == DO_FDW || + dobj->objType == DO_FOREIGN_SERVER) + { + DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; + + daobj->dacl.privtype = privtype; + daobj->dacl.initprivs = pstrdup(initprivs); } + else + pg_log_warning("unsupported pg_init_privs entry: %u %u %d", + classoid, objoid, objsubid); } - PQclear(res); + } + PQclear(res); destroyPQExpBuffer(query); } @@ -11128,8 +11127,8 @@ dumpRelationStats_dumper(Archive *fout, const void *userArg, const TocEntry *te) * The results must be in the order of the relations supplied in the * parameters to ensure we remain in sync as we walk through the TOC. * - * For versions before 19, the redundant filter clause on s.tablename = - * ANY(...) seems sufficient to convince the planner to use + * For versions before 19, the redundant filter clause on s.tablename + * = ANY(...) seems sufficient to convince the planner to use * pg_class_relname_nsp_index, which avoids a full scan of pg_stats. * In newer versions, pg_stats returns the table OIDs, eliminating the * need for that hack. @@ -13469,11 +13468,11 @@ dumpFunc(Archive *fout, const FuncInfo *finfo) "pg_catalog.pg_get_function_result(p.oid) AS funcresult,\n" "proleakproof,\n"); - appendPQExpBufferStr(query, - "array_to_string(protrftypes, ' ') AS protrftypes,\n"); + appendPQExpBufferStr(query, + "array_to_string(protrftypes, ' ') AS protrftypes,\n"); - appendPQExpBufferStr(query, - "proparallel,\n"); + appendPQExpBufferStr(query, + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -14963,9 +14962,9 @@ dumpCollation(Archive *fout, const CollInfo *collinfo) /* Get collation-specific details */ appendPQExpBufferStr(query, "SELECT "); - appendPQExpBufferStr(query, - "collprovider, " - "collversion, "); + appendPQExpBufferStr(query, + "collprovider, " + "collversion, "); if (fout->remoteVersion >= 120000) appendPQExpBufferStr(query, @@ -15372,23 +15371,23 @@ dumpAgg(Archive *fout, const AggInfo *agginfo) "pg_catalog.pg_get_function_arguments(p.oid) AS funcargs,\n" "pg_catalog.pg_get_function_identity_arguments(p.oid) AS funciargs,\n"); - appendPQExpBufferStr(query, - "aggkind,\n" - "aggmtransfn,\n" - "aggminvtransfn,\n" - "aggmfinalfn,\n" - "aggmtranstype::pg_catalog.regtype,\n" - "aggfinalextra,\n" - "aggmfinalextra,\n" - "aggtransspace,\n" - "aggmtransspace,\n" - "aggminitval,\n"); + appendPQExpBufferStr(query, + "aggkind,\n" + "aggmtransfn,\n" + "aggminvtransfn,\n" + "aggmfinalfn,\n" + "aggmtranstype::pg_catalog.regtype,\n" + "aggfinalextra,\n" + "aggmfinalextra,\n" + "aggtransspace,\n" + "aggmtransspace,\n" + "aggminitval,\n"); - appendPQExpBufferStr(query, - "aggcombinefn,\n" - "aggserialfn,\n" - "aggdeserialfn,\n" - "proparallel,\n"); + appendPQExpBufferStr(query, + "aggcombinefn,\n" + "aggserialfn,\n" + "aggdeserialfn,\n" + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -16848,30 +16847,30 @@ dumpTable(Archive *fout, const TableInfo *tbinfo) appendPQExpBufferStr(query, "PREPARE getColumnACLs(pg_catalog.oid) AS\n"); - /* - * In principle we should call acldefault('c', relowner) to - * get the default ACL for a column. However, we don't - * currently store the numeric OID of the relowner in - * TableInfo. We could convert the owner name using regrole, - * but that creates a risk of failure due to concurrent role - * renames. Given that the default ACL for columns is empty - * and is likely to stay that way, it's not worth extra cycles - * and risk to avoid hard-wiring that knowledge here. - */ - appendPQExpBufferStr(query, - "SELECT at.attname, " - "at.attacl, " - "'{}' AS acldefault, " - "pip.privtype, pip.initprivs " - "FROM pg_catalog.pg_attribute at " - "LEFT JOIN pg_catalog.pg_init_privs pip ON " - "(at.attrelid = pip.objoid " - "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " - "AND at.attnum = pip.objsubid) " - "WHERE at.attrelid = $1 AND " - "NOT at.attisdropped " - "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " - "ORDER BY at.attnum"); + /* + * In principle we should call acldefault('c', relowner) to get + * the default ACL for a column. However, we don't currently + * store the numeric OID of the relowner in TableInfo. We could + * convert the owner name using regrole, but that creates a risk + * of failure due to concurrent role renames. Given that the + * default ACL for columns is empty and is likely to stay that + * way, it's not worth extra cycles and risk to avoid hard-wiring + * that knowledge here. + */ + appendPQExpBufferStr(query, + "SELECT at.attname, " + "at.attacl, " + "'{}' AS acldefault, " + "pip.privtype, pip.initprivs " + "FROM pg_catalog.pg_attribute at " + "LEFT JOIN pg_catalog.pg_init_privs pip ON " + "(at.attrelid = pip.objoid " + "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " + "AND at.attnum = pip.objsubid) " + "WHERE at.attrelid = $1 AND " + "NOT at.attisdropped " + "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " + "ORDER BY at.attnum"); ExecuteSqlStatement(fout, query->data); @@ -19165,7 +19164,7 @@ collectSequences(Archive *fout) * pg_get_sequence_data(), but we only do so for non-schema-only dumps. */ if (fout->remoteVersion < 180000 || - (!fout->dopt->dumpData && !fout->dopt->sequence_data)) + (!fout->dopt->dumpData && !fout->dopt->sequence_data)) query = "SELECT seqrelid, format_type(seqtypid, NULL), " "seqstart, seqincrement, " "seqmax, seqmin, " @@ -19227,15 +19226,14 @@ dumpSequence(Archive *fout, const TableInfo *tbinfo) qseqname = pg_strdup(fmtId(tbinfo->dobj.name)); /* - * The sequence information is gathered in a sorted - * table before any calls to dumpSequence(). See collectSequences() for - * more information. + * The sequence information is gathered in a sorted table before any calls + * to dumpSequence(). See collectSequences() for more information. */ - Assert(sequences); + Assert(sequences); - key.oid = tbinfo->dobj.catId.oid; - seq = bsearch(&key, sequences, nsequences, - sizeof(SequenceItem), SequenceItemCmp); + key.oid = tbinfo->dobj.catId.oid; + seq = bsearch(&key, sequences, nsequences, + sizeof(SequenceItem), SequenceItemCmp); /* Calculate default limits for a sequence of this type */ is_ascending = (seq->incby >= 0); diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c index e68937c9934..afcd9a218d8 100644 --- a/src/bin/pg_dump/pg_dumpall.c +++ b/src/bin/pg_dump/pg_dumpall.c @@ -785,11 +785,11 @@ dropRoles(PGconn *conn) int i_rolname; int i; - printfPQExpBuffer(buf, - "SELECT rolname " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 1", role_catalog); + printfPQExpBuffer(buf, + "SELECT rolname " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 1", role_catalog); res = executeQuery(conn, buf->data); @@ -843,16 +843,16 @@ dumpRoles(PGconn *conn) * Notes: rolconfig is dumped later, and pg_authid must be used for * extracting rolcomment regardless of role_catalog. */ - printfPQExpBuffer(buf, - "SELECT oid, rolname, rolsuper, rolinherit, " - "rolcreaterole, rolcreatedb, " - "rolcanlogin, rolconnlimit, rolpassword, " - "rolvaliduntil, rolreplication, rolbypassrls, " - "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " - "rolname = current_user AS is_current_user " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 2", role_catalog); + printfPQExpBuffer(buf, + "SELECT oid, rolname, rolsuper, rolinherit, " + "rolcreaterole, rolcreatedb, " + "rolcanlogin, rolconnlimit, rolpassword, " + "rolvaliduntil, rolreplication, rolbypassrls, " + "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " + "rolname = current_user AS is_current_user " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 2", role_catalog); res = executeQuery(conn, buf->data); diff --git a/src/bin/pg_upgrade/check.c b/src/bin/pg_upgrade/check.c index 786c1474829..f725f5ee3e2 100644 --- a/src/bin/pg_upgrade/check.c +++ b/src/bin/pg_upgrade/check.c @@ -1475,15 +1475,15 @@ check_for_incompatible_polymorphics(ClusterInfo *cluster) ", 'array_cat(anyarray,anyarray)'" ", 'array_prepend(anyelement,anyarray)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_remove(anyarray,anyelement)'" - ", 'array_replace(anyarray,anyelement,anyelement)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_remove(anyarray,anyelement)'" + ", 'array_replace(anyarray,anyelement,anyelement)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_position(anyarray,anyelement)'" - ", 'array_position(anyarray,anyelement,integer)'" - ", 'array_positions(anyarray,anyelement)'" - ", 'width_bucket(anyelement,anyarray)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_position(anyarray,anyelement)'" + ", 'array_position(anyarray,anyelement,integer)'" + ", 'array_positions(anyarray,anyelement)'" + ", 'width_bucket(anyelement,anyarray)'"); /* * The query below hardcodes FirstNormalObjectId as 16384 rather than diff --git a/src/bin/pg_upgrade/controldata.c b/src/bin/pg_upgrade/controldata.c index 8f81c9e9582..02ea02df60f 100644 --- a/src/bin/pg_upgrade/controldata.c +++ b/src/bin/pg_upgrade/controldata.c @@ -228,7 +228,7 @@ get_control_data(ClusterInfo *cluster) p++; /* remove ':' char */ cluster->controldata.chkpnt_nxtepoch = str2uint(p); - p = strchr(p, ':'); + p = strchr(p, ':'); if (p == NULL || strlen(p) <= 1) pg_fatal("%d: controldata retrieval problem", __LINE__); diff --git a/src/bin/pg_upgrade/exec.c b/src/bin/pg_upgrade/exec.c index 44355feea30..a1bdbf373e3 100644 --- a/src/bin/pg_upgrade/exec.c +++ b/src/bin/pg_upgrade/exec.c @@ -55,7 +55,7 @@ get_bin_version(ClusterInfo *cluster) if (sscanf(cmd_output, "%*s %*s %d.%d", &v1, &v2) < 1) pg_fatal("could not get pg_ctl version output from %s", cmd); - cluster->bin_version = v1 * 10000; + cluster->bin_version = v1 * 10000; } @@ -344,8 +344,8 @@ check_data_dir(ClusterInfo *cluster) check_single_dir(pg_data, "pg_subtrans"); check_single_dir(pg_data, PG_TBLSPC_DIR); check_single_dir(pg_data, "pg_twophase"); - check_single_dir(pg_data, "pg_wal"); - check_single_dir(pg_data, "pg_xact"); + check_single_dir(pg_data, "pg_wal"); + check_single_dir(pg_data, "pg_xact"); } @@ -385,7 +385,7 @@ check_bin_dir(ClusterInfo *cluster, bool check_versions) */ get_bin_version(cluster); - check_exec(cluster->bindir, "pg_resetwal", check_versions); + check_exec(cluster->bindir, "pg_resetwal", check_versions); if (cluster == &new_cluster) { diff --git a/src/bin/pg_upgrade/multixact_rewrite.c b/src/bin/pg_upgrade/multixact_rewrite.c index c45b3183684..c7a1416494d 100644 --- a/src/bin/pg_upgrade/multixact_rewrite.c +++ b/src/bin/pg_upgrade/multixact_rewrite.c @@ -61,52 +61,52 @@ rewrite_multixacts(MultiXactId from_multi, MultiXactId to_multi) * Convert old multixids, if needed, by reading them one-by-one from the * old cluster. */ - old_reader = AllocOldMultiXactRead(old_cluster.pgdata, - old_cluster.controldata.chkpnt_nxtmulti, - old_cluster.controldata.chkpnt_nxtmxoff); + old_reader = AllocOldMultiXactRead(old_cluster.pgdata, + old_cluster.controldata.chkpnt_nxtmulti, + old_cluster.controldata.chkpnt_nxtmxoff); - for (MultiXactId multi = from_multi; multi != to_multi;) - { - MultiXactMember member; - bool multixid_valid; - - /* - * Read this multixid's members. - * - * Locking-only XIDs that may be part of multi-xids don't matter - * after upgrade, as there can be no transactions running across - * upgrade. So as a small optimization, we only read one member - * from each multixid: the one updating one, or if there was no - * update, arbitrarily the first locking xid. - */ - multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); + for (MultiXactId multi = from_multi; multi != to_multi;) + { + MultiXactMember member; + bool multixid_valid; - /* - * Write the new offset to pg_multixact/offsets. - * - * Even if this multixid is invalid, we still need to write its - * offset if the *previous* multixid was valid. That's because - * when reading a multixid, the number of members is calculated - * from the difference between the two offsets. - */ - RecordMultiXactOffset(offsets_writer, multi, - (multixid_valid || prev_multixid_valid) ? next_offset : 0); + /* + * Read this multixid's members. + * + * Locking-only XIDs that may be part of multi-xids don't matter after + * upgrade, as there can be no transactions running across upgrade. So + * as a small optimization, we only read one member from each + * multixid: the one updating one, or if there was no update, + * arbitrarily the first locking xid. + */ + multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); - /* Write the members */ - if (multixid_valid) - { - RecordMultiXactMembers(members_writer, next_offset, 1, &member); - next_offset += 1; - } + /* + * Write the new offset to pg_multixact/offsets. + * + * Even if this multixid is invalid, we still need to write its offset + * if the *previous* multixid was valid. That's because when reading + * a multixid, the number of members is calculated from the difference + * between the two offsets. + */ + RecordMultiXactOffset(offsets_writer, multi, + (multixid_valid || prev_multixid_valid) ? next_offset : 0); - /* Advance to next multixid, handling wraparound */ - multi++; - if (multi < FirstMultiXactId) - multi = FirstMultiXactId; - prev_multixid_valid = multixid_valid; + /* Write the members */ + if (multixid_valid) + { + RecordMultiXactMembers(members_writer, next_offset, 1, &member); + next_offset += 1; } - FreeOldMultiXactReader(old_reader); + /* Advance to next multixid, handling wraparound */ + multi++; + if (multi < FirstMultiXactId) + multi = FirstMultiXactId; + prev_multixid_valid = multixid_valid; + } + + FreeOldMultiXactReader(old_reader); /* Write the final 'next' offset to the last SLRU page */ RecordMultiXactOffset(offsets_writer, to_multi, diff --git a/src/bin/pg_upgrade/pg_upgrade.c b/src/bin/pg_upgrade/pg_upgrade.c index c6af9035665..7366fd4627c 100644 --- a/src/bin/pg_upgrade/pg_upgrade.c +++ b/src/bin/pg_upgrade/pg_upgrade.c @@ -833,7 +833,7 @@ copy_xact_xlog_xid(void) * Determine the range of multixacts to convert. */ nxtmulti = old_cluster.controldata.chkpnt_nxtmulti; - oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; + oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; /* handle wraparound */ if (nxtmulti < FirstMultiXactId) nxtmulti = FirstMultiXactId; @@ -898,15 +898,15 @@ set_frozenxids(void) int i_datname; int i_datallowconn; - prep_status("Setting frozenxid and minmxid counters in new cluster"); + prep_status("Setting frozenxid and minmxid counters in new cluster"); conn_template1 = connectToServer(&new_cluster, "template1"); - /* set pg_database.datfrozenxid */ - PQclear(executeQueryOrDie(conn_template1, - "UPDATE pg_catalog.pg_database " - "SET datfrozenxid = '%u'", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_database.datfrozenxid */ + PQclear(executeQueryOrDie(conn_template1, + "UPDATE pg_catalog.pg_database " + "SET datfrozenxid = '%u'", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_database.datminmxid */ PQclear(executeQueryOrDie(conn_template1, @@ -942,16 +942,16 @@ set_frozenxids(void) conn = connectToServer(&new_cluster, datname); - /* set pg_class.relfrozenxid */ - PQclear(executeQueryOrDie(conn, - "UPDATE pg_catalog.pg_class " - "SET relfrozenxid = '%u' " - /* only heap, materialized view, and TOAST are vacuumed */ - "WHERE relkind IN (" - CppAsString2(RELKIND_RELATION) ", " - CppAsString2(RELKIND_MATVIEW) ", " - CppAsString2(RELKIND_TOASTVALUE) ")", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_class.relfrozenxid */ + PQclear(executeQueryOrDie(conn, + "UPDATE pg_catalog.pg_class " + "SET relfrozenxid = '%u' " + /* only heap, materialized view, and TOAST are vacuumed */ + "WHERE relkind IN (" + CppAsString2(RELKIND_RELATION) ", " + CppAsString2(RELKIND_MATVIEW) ", " + CppAsString2(RELKIND_TOASTVALUE) ")", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_class.relminmxid */ PQclear(executeQueryOrDie(conn, diff --git a/src/bin/pg_upgrade/relfilenumber.c b/src/bin/pg_upgrade/relfilenumber.c index ec2ff7acb21..6c467bdc8a5 100644 --- a/src/bin/pg_upgrade/relfilenumber.c +++ b/src/bin/pg_upgrade/relfilenumber.c @@ -587,32 +587,32 @@ transfer_relfile(FileNameMap *map, const char *type_suffix) /* Copying files might take some time, so give feedback. */ pg_log(PG_STATUS, "%s", old_file); - switch (user_opts.transfer_mode) - { - case TRANSFER_MODE_CLONE: - pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", - old_file, new_file); - cloneFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", - old_file, new_file); - copyFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY_FILE_RANGE: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", - old_file, new_file); - copyFileByRange(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_LINK: - pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", - old_file, new_file); - linkFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_SWAP: - /* swap mode is handled in its own code path */ - pg_fatal("should never happen"); - break; - } + switch (user_opts.transfer_mode) + { + case TRANSFER_MODE_CLONE: + pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", + old_file, new_file); + cloneFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", + old_file, new_file); + copyFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY_FILE_RANGE: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", + old_file, new_file); + copyFileByRange(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_LINK: + pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", + old_file, new_file); + linkFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_SWAP: + /* swap mode is handled in its own code path */ + pg_fatal("should never happen"); + break; + } } } diff --git a/src/bin/pg_upgrade/t/006_transfer_modes.pl b/src/bin/pg_upgrade/t/006_transfer_modes.pl index 9efa5dc863c..360d05c4b68 100644 --- a/src/bin/pg_upgrade/t/006_transfer_modes.pl +++ b/src/bin/pg_upgrade/t/006_transfer_modes.pl @@ -29,10 +29,8 @@ sub test_mode } $new->init(); - $new->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); - $old->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); + $new->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); + $old->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); # We can only test security labels if both the old and new installations # have dummy_seclabel. @@ -76,15 +74,14 @@ sub test_mode "CREATE TABLE test4 AS SELECT generate_series(400, 502)"); } - $old->safe_psql('postgres', - "CREATE TABLESPACE inplc_tblspc LOCATION ''"); - $old->safe_psql('postgres', - "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); - $old->safe_psql('postgres', - "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" - ); - $old->safe_psql('testdb3', - "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); + $old->safe_psql('postgres', "CREATE TABLESPACE inplc_tblspc LOCATION ''"); + $old->safe_psql('postgres', + "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); + $old->safe_psql('postgres', + "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" + ); + $old->safe_psql('testdb3', + "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); # While we are here, test handling of large objects. $old->safe_psql( @@ -152,12 +149,10 @@ sub test_mode } # Tests for in-place tablespaces. - $result = - $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); - is($result, '104', "test5 data after pg_upgrade $mode"); - $result = - $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); - is($result, '105', "test6 data after pg_upgrade $mode"); + $result = $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); + is($result, '104', "test5 data after pg_upgrade $mode"); + $result = $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); + is($result, '105', "test6 data after pg_upgrade $mode"); # Tests for large objects $result = $new->safe_psql('postgres', "SELECT lo_get(4532)"); diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index 44ef11d980e..c90bf8bbde2 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -6278,23 +6278,22 @@ get_create_object_cmd(EditableObjectType obj_type, Oid oid, * ensure the right view gets replaced. Also, check relation kind * to be sure it's a view. * - * Views may have WITH [LOCAL|CASCADED] - * CHECK OPTION. These are not part of the view definition - * returned by pg_get_viewdef() and so need to be retrieved - * separately. Materialized views may have - * arbitrary storage parameter reloptions. + * Views may have WITH [LOCAL|CASCADED] CHECK OPTION. These are + * not part of the view definition returned by pg_get_viewdef() + * and so need to be retrieved separately. Materialized views may + * have arbitrary storage parameter reloptions. */ printfPQExpBuffer(query, "/* %s */\n", _("Get view's definition and details")); - appendPQExpBuffer(query, - "SELECT nspname, relname, relkind, " - "pg_catalog.pg_get_viewdef(c.oid, true), " - "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " - "FROM pg_catalog.pg_class c " - "LEFT JOIN pg_catalog.pg_namespace n " - "ON c.relnamespace = n.oid WHERE c.oid = %u", - oid); + appendPQExpBuffer(query, + "SELECT nspname, relname, relkind, " + "pg_catalog.pg_get_viewdef(c.oid, true), " + "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " + "FROM pg_catalog.pg_class c " + "LEFT JOIN pg_catalog.pg_namespace n " + "ON c.relnamespace = n.oid WHERE c.oid = %u", + oid); break; } diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index ce99137c613..ac0c55e7aa5 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -387,19 +387,19 @@ describeFunctions(const char *functypes, const char *func_pattern, gettext_noop("stable"), gettext_noop("volatile"), gettext_noop("Volatility")); - appendPQExpBuffer(&buf, - ",\n CASE\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" - " END as \"%s\"", - gettext_noop("restricted"), - gettext_noop("safe"), - gettext_noop("unsafe"), - gettext_noop("Parallel")); + appendPQExpBuffer(&buf, + ",\n CASE\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" + " END as \"%s\"", + gettext_noop("restricted"), + gettext_noop("safe"), + gettext_noop("unsafe"), + gettext_noop("Parallel")); appendPQExpBuffer(&buf, ",\n pg_catalog.pg_get_userbyid(p.proowner) as \"%s\"" ",\n CASE WHEN prosecdef THEN '%s' ELSE '%s' END AS \"%s\"" @@ -599,8 +599,8 @@ describeFunctions(const char *functypes, const char *func_pattern, myopt.title = _("List of functions"); myopt.translate_header = true; - myopt.translate_columns = translate_columns; - myopt.n_translate_columns = lengthof(translate_columns); + myopt.translate_columns = translate_columns; + myopt.n_translate_columns = lengthof(translate_columns); printQuery(res, &myopt, pset.queryFout, false, pset.logfile); @@ -1086,38 +1086,38 @@ permissionsList(const char *pattern, bool showSystem) " ), E'\\n') AS \"%s\"", gettext_noop("Column privileges")); - appendPQExpBuffer(&buf, - ",\n pg_catalog.array_to_string(ARRAY(\n" - " SELECT polname\n" - " || CASE WHEN NOT polpermissive THEN\n" - " E' (RESTRICTIVE)'\n" - " ELSE '' END\n" - " || CASE WHEN polcmd != '*' THEN\n" - " E' (' || polcmd::pg_catalog.text || E'):'\n" - " ELSE E':'\n" - " END\n" - " || CASE WHEN polqual IS NOT NULL THEN\n" - " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" - " ELSE E''\n" - " END\n" - " || CASE WHEN polwithcheck IS NOT NULL THEN\n" - " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" - " ELSE E''\n" - " END" - " || CASE WHEN polroles <> '{0}' THEN\n" - " E'\\n to: ' || pg_catalog.array_to_string(\n" - " ARRAY(\n" - " SELECT rolname\n" - " FROM pg_catalog.pg_roles\n" - " WHERE oid = ANY (polroles)\n" - " ORDER BY 1\n" - " ), E', ')\n" - " ELSE E''\n" - " END\n" - " FROM pg_catalog.pg_policy pol\n" - " WHERE polrelid = c.oid), E'\\n')\n" - " AS \"%s\"", - gettext_noop("Policies")); + appendPQExpBuffer(&buf, + ",\n pg_catalog.array_to_string(ARRAY(\n" + " SELECT polname\n" + " || CASE WHEN NOT polpermissive THEN\n" + " E' (RESTRICTIVE)'\n" + " ELSE '' END\n" + " || CASE WHEN polcmd != '*' THEN\n" + " E' (' || polcmd::pg_catalog.text || E'):'\n" + " ELSE E':'\n" + " END\n" + " || CASE WHEN polqual IS NOT NULL THEN\n" + " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" + " ELSE E''\n" + " END\n" + " || CASE WHEN polwithcheck IS NOT NULL THEN\n" + " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" + " ELSE E''\n" + " END" + " || CASE WHEN polroles <> '{0}' THEN\n" + " E'\\n to: ' || pg_catalog.array_to_string(\n" + " ARRAY(\n" + " SELECT rolname\n" + " FROM pg_catalog.pg_roles\n" + " WHERE oid = ANY (polroles)\n" + " ORDER BY 1\n" + " ), E', ')\n" + " ELSE E''\n" + " END\n" + " FROM pg_catalog.pg_policy pol\n" + " WHERE polrelid = c.oid), E'\\n')\n" + " AS \"%s\"", + gettext_noop("Policies")); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_class c\n" " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n" @@ -1675,27 +1675,27 @@ describeOneTableDetails(const char *schemaname, char *footers[3] = {NULL, NULL, NULL}; printfPQExpBuffer(&buf, "/* %s */\n", _("Get sequence information")); - appendPQExpBuffer(&buf, - "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" - " seqstart AS \"%s\",\n" - " seqmin AS \"%s\",\n" - " seqmax AS \"%s\",\n" - " seqincrement AS \"%s\",\n" - " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" - " seqcache AS \"%s\"\n", - gettext_noop("Type"), - gettext_noop("Start"), - gettext_noop("Minimum"), - gettext_noop("Maximum"), - gettext_noop("Increment"), - gettext_noop("yes"), - gettext_noop("no"), - gettext_noop("Cycles?"), - gettext_noop("Cache")); - appendPQExpBuffer(&buf, - "FROM pg_catalog.pg_sequence\n" - "WHERE seqrelid = '%s';", - oid); + appendPQExpBuffer(&buf, + "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" + " seqstart AS \"%s\",\n" + " seqmin AS \"%s\",\n" + " seqmax AS \"%s\",\n" + " seqincrement AS \"%s\",\n" + " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" + " seqcache AS \"%s\"\n", + gettext_noop("Type"), + gettext_noop("Start"), + gettext_noop("Minimum"), + gettext_noop("Maximum"), + gettext_noop("Increment"), + gettext_noop("yes"), + gettext_noop("no"), + gettext_noop("Cycles?"), + gettext_noop("Cache")); + appendPQExpBuffer(&buf, + "FROM pg_catalog.pg_sequence\n" + "WHERE seqrelid = '%s';", + oid); res = PSQLexec(buf.data); if (!res) @@ -1913,7 +1913,7 @@ describeOneTableDetails(const char *schemaname, appendPQExpBufferStr(&buf, ",\n (SELECT c.collname FROM pg_catalog.pg_collation c, pg_catalog.pg_type t\n" " WHERE c.oid = a.attcollation AND t.oid = a.atttypid AND a.attcollation <> t.typcollation) AS attcollation"); attcoll_col = cols++; - appendPQExpBufferStr(&buf, ",\n a.attidentity"); + appendPQExpBufferStr(&buf, ",\n a.attidentity"); attidentity_col = cols++; if (pset.sversion >= 120000) appendPQExpBufferStr(&buf, ",\n a.attgenerated"); @@ -2326,7 +2326,7 @@ describeOneTableDetails(const char *schemaname, CppAsString2(CONSTRAINT_EXCLUSION) ") AND " "condeferred) AS condeferred,\n"); - appendPQExpBufferStr(&buf, "i.indisreplident,\n"); + appendPQExpBufferStr(&buf, "i.indisreplident,\n"); if (pset.sversion >= 150000) appendPQExpBufferStr(&buf, "i.indnullsnotdistinct,\n"); @@ -2431,7 +2431,7 @@ describeOneTableDetails(const char *schemaname, "pg_catalog.pg_get_indexdef(i.indexrelid, 0, true),\n " "pg_catalog.pg_get_constraintdef(con.oid, true), " "contype, condeferrable, condeferred"); - appendPQExpBufferStr(&buf, ", i.indisreplident"); + appendPQExpBufferStr(&buf, ", i.indisreplident"); appendPQExpBufferStr(&buf, ", c2.reltablespace"); if (pset.sversion >= 180000) appendPQExpBufferStr(&buf, ", con.conperiod"); @@ -2682,81 +2682,80 @@ describeOneTableDetails(const char *schemaname, PQclear(result); /* print any row-level policies */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get row-level policies for this table")); - appendPQExpBufferStr(&buf, "SELECT pol.polname,"); - appendPQExpBufferStr(&buf, - " pol.polpermissive,\n"); - appendPQExpBuffer(&buf, - " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" - " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" - " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" - " CASE pol.polcmd\n" - " WHEN 'r' THEN 'SELECT'\n" - " WHEN 'a' THEN 'INSERT'\n" - " WHEN 'w' THEN 'UPDATE'\n" - " WHEN 'd' THEN 'DELETE'\n" - " END AS cmd\n" - "FROM pg_catalog.pg_policy pol\n" - "WHERE pol.polrelid = '%s' ORDER BY 1;", - oid); + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get row-level policies for this table")); + appendPQExpBufferStr(&buf, "SELECT pol.polname,"); + appendPQExpBufferStr(&buf, + " pol.polpermissive,\n"); + appendPQExpBuffer(&buf, + " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" + " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" + " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" + " CASE pol.polcmd\n" + " WHEN 'r' THEN 'SELECT'\n" + " WHEN 'a' THEN 'INSERT'\n" + " WHEN 'w' THEN 'UPDATE'\n" + " WHEN 'd' THEN 'DELETE'\n" + " END AS cmd\n" + "FROM pg_catalog.pg_policy pol\n" + "WHERE pol.polrelid = '%s' ORDER BY 1;", + oid); - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - /* - * Handle cases where RLS is enabled and there are policies, or - * there aren't policies, or RLS isn't enabled but there are - * policies - */ - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies:")); + /* + * Handle cases where RLS is enabled and there are policies, or there + * aren't policies, or RLS isn't enabled but there are policies + */ + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies:")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled):")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled):")); - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); - if (!tableinfo.rowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (row security disabled):")); + if (!tableinfo.rowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (row security disabled):")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " POLICY \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " POLICY \"%s\"", + PQgetvalue(result, i, 0)); - if (*(PQgetvalue(result, i, 1)) == 'f') - appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); + if (*(PQgetvalue(result, i, 1)) == 'f') + appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); - if (!PQgetisnull(result, i, 5)) - appendPQExpBuffer(&buf, " FOR %s", - PQgetvalue(result, i, 5)); + if (!PQgetisnull(result, i, 5)) + appendPQExpBuffer(&buf, " FOR %s", + PQgetvalue(result, i, 5)); - if (!PQgetisnull(result, i, 2)) - { - appendPQExpBuffer(&buf, "\n TO %s", - PQgetvalue(result, i, 2)); - } + if (!PQgetisnull(result, i, 2)) + { + appendPQExpBuffer(&buf, "\n TO %s", + PQgetvalue(result, i, 2)); + } - if (!PQgetisnull(result, i, 3)) - appendPQExpBuffer(&buf, "\n USING (%s)", - PQgetvalue(result, i, 3)); + if (!PQgetisnull(result, i, 3)) + appendPQExpBuffer(&buf, "\n USING (%s)", + PQgetvalue(result, i, 3)); - if (!PQgetisnull(result, i, 4)) - appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", - PQgetvalue(result, i, 4)); + if (!PQgetisnull(result, i, 4)) + appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", + PQgetvalue(result, i, 4)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* print any extended statistics */ if (pset.sversion >= 140000) @@ -3025,115 +3024,115 @@ describeOneTableDetails(const char *schemaname, } /* print any publications */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get publications that publish this table")); - if (pset.sversion >= 150000) + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get publications that publish this table")); + if (pset.sversion >= 150000) + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" + " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" + "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" + "UNION\n" + "SELECT pubname\n" + " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" + " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" + " (SELECT pg_catalog.string_agg(attname, ', ')\n" + " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" + " pg_catalog.pg_attribute\n" + " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" + " ELSE NULL END) " + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" + "WHERE pr.prrelid = '%s'\n", + oid, oid, oid); + + if (pset.sversion >= 190000) { + /* + * Skip entries where this relation appears in the + * publication's EXCEPT list. + */ appendPQExpBuffer(&buf, + " AND NOT pr.prexcept\n" + "UNION\n" "SELECT pubname\n" " , NULL\n" " , NULL\n" "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" - " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" - "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" - "UNION\n" - "SELECT pubname\n" - " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" - " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" - " (SELECT pg_catalog.string_agg(attname, ', ')\n" - " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" - " pg_catalog.pg_attribute\n" - " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" - " ELSE NULL END) " - "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" - "WHERE pr.prrelid = '%s'\n", + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + " AND NOT EXISTS (\n" + " SELECT 1\n" + " FROM pg_catalog.pg_publication_rel pr\n" + " WHERE pr.prpubid = p.oid AND\n" + " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" + "ORDER BY 1;", oid, oid, oid); - - if (pset.sversion >= 190000) - { - /* - * Skip entries where this relation appears in the - * publication's EXCEPT list. - */ - appendPQExpBuffer(&buf, - " AND NOT pr.prexcept\n" - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - " AND NOT EXISTS (\n" - " SELECT 1\n" - " FROM pg_catalog.pg_publication_rel pr\n" - " WHERE pr.prpubid = p.oid AND\n" - " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" - "ORDER BY 1;", - oid, oid, oid); - } - else - { - appendPQExpBuffer(&buf, - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - "ORDER BY 1;", - oid); - } } else { appendPQExpBuffer(&buf, + "UNION\n" "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - "WHERE pr.prrelid = '%s'\n" - "UNION ALL\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" + " , NULL\n" + " , NULL\n" "FROM pg_catalog.pg_publication p\n" "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" "ORDER BY 1;", - oid, oid); + oid); } + } + else + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + "WHERE pr.prrelid = '%s'\n" + "UNION ALL\n" + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + "ORDER BY 1;", + oid, oid); + } - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - if (tuples > 0) - printTableAddFooter(&cont, _("Included in publications:")); + if (tuples > 0) + printTableAddFooter(&cont, _("Included in publications:")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " \"%s\"", + PQgetvalue(result, i, 0)); - /* column list (if any) */ - if (!PQgetisnull(result, i, 2)) - appendPQExpBuffer(&buf, " (%s)", - PQgetvalue(result, i, 2)); + /* column list (if any) */ + if (!PQgetisnull(result, i, 2)) + appendPQExpBuffer(&buf, " (%s)", + PQgetvalue(result, i, 2)); - /* row filter (if any) */ - if (!PQgetisnull(result, i, 1)) - appendPQExpBuffer(&buf, " WHERE %s", - PQgetvalue(result, i, 1)); + /* row filter (if any) */ + if (!PQgetisnull(result, i, 1)) + appendPQExpBuffer(&buf, " WHERE %s", + PQgetvalue(result, i, 1)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* Print publications where the table is in the EXCEPT clause */ if (pset.sversion >= 190000) @@ -3805,7 +3804,7 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) ncols++; } appendPQExpBufferStr(&buf, "\n, r.rolreplication"); - appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); + appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_roles r\n"); @@ -3860,8 +3859,8 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) if (strcmp(PQgetvalue(res, i, (verbose ? 9 : 8)), "t") == 0) add_role_attribute(&buf, _("Replication")); - if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) - add_role_attribute(&buf, _("Bypass RLS")); + if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) + add_role_attribute(&buf, _("Bypass RLS")); conns = atoi(PQgetvalue(res, i, 6)); if (conns >= 0) @@ -5155,14 +5154,14 @@ listCollations(const char *pattern, bool verbose, bool showSystem) gettext_noop("Schema"), gettext_noop("Name")); - appendPQExpBuffer(&buf, - " CASE c.collprovider " - "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " - "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " - "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " - "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " - "END AS \"%s\",\n", - gettext_noop("Provider")); + appendPQExpBuffer(&buf, + " CASE c.collprovider " + "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " + "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " + "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " + "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " + "END AS \"%s\",\n", + gettext_noop("Provider")); appendPQExpBuffer(&buf, " c.collcollate AS \"%s\",\n" -- 2.50.1 (Apple Git-155) --aHl3HfeiUuO3zeNC-- ^ permalink raw reply [nested|flat] 59+ messages in thread
* [PATCH v6 4/4] run pgindent and pgperltidy @ 2026-06-30 18:24 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 59+ messages in thread From: Nathan Bossart @ 2026-06-30 18:24 UTC (permalink / raw) --- src/bin/pg_dump/pg_dump.c | 464 ++++++++++----------- src/bin/pg_dump/pg_dumpall.c | 30 +- src/bin/pg_upgrade/check.c | 16 +- src/bin/pg_upgrade/controldata.c | 2 +- src/bin/pg_upgrade/exec.c | 8 +- src/bin/pg_upgrade/multixact_rewrite.c | 80 ++-- src/bin/pg_upgrade/pg_upgrade.c | 34 +- src/bin/pg_upgrade/relfilenumber.c | 54 +-- src/bin/pg_upgrade/t/006_transfer_modes.pl | 33 +- src/bin/psql/command.c | 29 +- src/bin/psql/describe.c | 461 ++++++++++---------- 11 files changed, 601 insertions(+), 610 deletions(-) diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 65bd15ebfd2..5673268b467 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -1491,8 +1491,8 @@ setup_connection(Archive *AH, const char *dumpencoding, * Disable timeouts if supported. */ ExecuteSqlStatement(AH, "SET statement_timeout = 0"); - ExecuteSqlStatement(AH, "SET lock_timeout = 0"); - ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); + ExecuteSqlStatement(AH, "SET lock_timeout = 0"); + ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); if (AH->remoteVersion >= 170000) ExecuteSqlStatement(AH, "SET transaction_timeout = 0"); @@ -1505,10 +1505,10 @@ setup_connection(Archive *AH, const char *dumpencoding, /* * Adjust row-security mode, if supported. */ - if (dopt->enable_row_security) - ExecuteSqlStatement(AH, "SET row_security = on"); - else - ExecuteSqlStatement(AH, "SET row_security = off"); + if (dopt->enable_row_security) + ExecuteSqlStatement(AH, "SET row_security = on"); + else + ExecuteSqlStatement(AH, "SET row_security = off"); /* * For security reasons, we restrict the expansion of non-system views and @@ -1933,10 +1933,9 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) addObjectDependency(dobj, ext->dobj.dumpId); /* - * Mark the member object to have any non-initial ACLs - * dumped. (Any initial ACLs will be removed later, using data from - * pg_init_privs, so that we'll dump only the delta from the extension's - * initial setup.) + * Mark the member object to have any non-initial ACLs dumped. (Any + * initial ACLs will be removed later, using data from pg_init_privs, so + * that we'll dump only the delta from the extension's initial setup.) * * In binary upgrades, we still dump all components of the members * individually, since the idea is to exactly reproduce the database @@ -1953,7 +1952,7 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) if (fout->dopt->binary_upgrade) dobj->dump = ext->dobj.dump; else - dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); + dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); return true; } @@ -1987,9 +1986,9 @@ selectDumpableNamespace(NamespaceInfo *nsinfo, Archive *fout) else if (strcmp(nsinfo->dobj.name, "pg_catalog") == 0) { /* - * We dump out any ACLs defined in pg_catalog, if - * they are interesting (and not the original ACLs which were set at - * initdb time, see pg_init_privs). + * We dump out any ACLs defined in pg_catalog, if they are interesting + * (and not the original ACLs which were set at initdb time, see + * pg_init_privs). */ nsinfo->dobj.dump_contains = nsinfo->dobj.dump = DUMP_COMPONENT_ACL; } @@ -3296,7 +3295,7 @@ dumpDatabase(Archive *fout) "datcollate, datctype, datfrozenxid, " "datacl, acldefault('d', datdba) AS acldefault, " "datistemplate, datconnlimit, "); - appendPQExpBufferStr(dbQry, "datminmxid, "); + appendPQExpBufferStr(dbQry, "datminmxid, "); if (fout->remoteVersion >= 170000) appendPQExpBufferStr(dbQry, "datlocprovider, datlocale, datcollversion, "); else if (fout->remoteVersion >= 150000) @@ -3638,11 +3637,11 @@ dumpDatabase(Archive *fout) ii_oid, ii_relminmxid; - appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" - "FROM pg_catalog.pg_class\n" - "WHERE oid IN (%u, %u, %u, %u);\n", - LargeObjectRelationId, LargeObjectLOidPNIndexId, - LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); + appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" + "FROM pg_catalog.pg_class\n" + "WHERE oid IN (%u, %u, %u, %u);\n", + LargeObjectRelationId, LargeObjectLOidPNIndexId, + LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); lo_res = ExecuteSqlQuery(fout, loFrozenQry->data, PGRES_TUPLES_OK); @@ -4274,7 +4273,7 @@ getPolicies(Archive *fout, TableInfo tblinfo[], int numTables) printfPQExpBuffer(query, "SELECT pol.oid, pol.tableoid, pol.polrelid, pol.polname, pol.polcmd, "); - appendPQExpBufferStr(query, "pol.polpermissive, "); + appendPQExpBufferStr(query, "pol.polpermissive, "); appendPQExpBuffer(query, "CASE WHEN pol.polroles = '{0}' THEN NULL ELSE " " pg_catalog.array_to_string(ARRAY(SELECT pg_catalog.quote_ident(rolname) from pg_catalog.pg_roles WHERE oid = ANY(pol.polroles)), ', ') END AS polroles, " @@ -6633,9 +6632,9 @@ getAccessMethods(Archive *fout) * Select all access methods from pg_am table. */ appendPQExpBufferStr(query, "SELECT tableoid, oid, amname, "); - appendPQExpBufferStr(query, - "amtype, " - "amhandler::pg_catalog.regproc AS amhandler "); + appendPQExpBufferStr(query, + "amtype, " + "amhandler::pg_catalog.regproc AS amhandler "); appendPQExpBufferStr(query, "FROM pg_am"); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6827,35 +6826,35 @@ getAggregates(Archive *fout) * Find all interesting aggregates. See comment in getFuncs() for the * rationale behind the filtering logic. */ - agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" - : "p.proisagg"); + agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" + : "p.proisagg"); - appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " - "p.proname AS aggname, " - "p.pronamespace AS aggnamespace, " - "p.pronargs, p.proargtypes, " - "p.proowner, " - "p.proacl AS aggacl, " - "acldefault('f', p.proowner) AS acldefault " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s AND (" - "p.pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog') OR " - "p.proacl IS DISTINCT FROM pip.initprivs", - agg_check); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - " OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); - appendPQExpBufferChar(query, ')'); + appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " + "p.proname AS aggname, " + "p.pronamespace AS aggnamespace, " + "p.pronargs, p.proargtypes, " + "p.proowner, " + "p.proacl AS aggacl, " + "acldefault('f', p.proowner) AS acldefault " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s AND (" + "p.pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog') OR " + "p.proacl IS DISTINCT FROM pip.initprivs", + agg_check); + if (dopt->binary_upgrade) + appendPQExpBufferStr(query, + " OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6957,53 +6956,53 @@ getFuncs(Archive *fout) * include them, since we want to dump extension members individually in * that mode. Also, if they are used by casts or transforms then we need * to gather the information about them, though they won't be dumped if - * they are built-in. Also, include functions in - * pg_catalog if they have an ACL different from what's shown in - * pg_init_privs (so we have to join to pg_init_privs; annoying). + * they are built-in. Also, include functions in pg_catalog if they have + * an ACL different from what's shown in pg_init_privs (so we have to join + * to pg_init_privs; annoying). */ - not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" - : "NOT p.proisagg"); + not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" + : "NOT p.proisagg"); - appendPQExpBuffer(query, - "SELECT p.tableoid, p.oid, p.proname, p.prolang, " - "p.pronargs, p.proargtypes, p.prorettype, " - "p.proacl, " - "acldefault('f', p.proowner) AS acldefault, " - "p.pronamespace, " - "p.proowner " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s" - "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " - "WHERE classid = 'pg_proc'::regclass AND " - "objid = p.oid AND deptype = 'i')" - "\n AND (" - "\n pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog')" - "\n OR EXISTS (SELECT 1 FROM pg_cast" - "\n WHERE pg_cast.oid > %u " - "\n AND p.oid = pg_cast.castfunc)" - "\n OR EXISTS (SELECT 1 FROM pg_transform" - "\n WHERE pg_transform.oid > %u AND " - "\n (p.oid = pg_transform.trffromsql" - "\n OR p.oid = pg_transform.trftosql))", - not_agg_check, - g_last_builtin_oid, - g_last_builtin_oid); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); + appendPQExpBuffer(query, + "SELECT p.tableoid, p.oid, p.proname, p.prolang, " + "p.pronargs, p.proargtypes, p.prorettype, " + "p.proacl, " + "acldefault('f', p.proowner) AS acldefault, " + "p.pronamespace, " + "p.proowner " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s" + "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " + "WHERE classid = 'pg_proc'::regclass AND " + "objid = p.oid AND deptype = 'i')" + "\n AND (" + "\n pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog')" + "\n OR EXISTS (SELECT 1 FROM pg_cast" + "\n WHERE pg_cast.oid > %u " + "\n AND p.oid = pg_cast.castfunc)" + "\n OR EXISTS (SELECT 1 FROM pg_transform" + "\n WHERE pg_transform.oid > %u AND " + "\n (p.oid = pg_transform.trffromsql" + "\n OR p.oid = pg_transform.trftosql))", + not_agg_check, + g_last_builtin_oid, + g_last_builtin_oid); + if (dopt->binary_upgrade) appendPQExpBufferStr(query, - "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); - appendPQExpBufferChar(query, ')'); + "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferStr(query, + "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -7252,31 +7251,31 @@ getTables(Archive *fout, int *numTables) appendPQExpBufferStr(query, "c.relhasoids, "); - appendPQExpBufferStr(query, - "c.relispopulated, "); + appendPQExpBufferStr(query, + "c.relispopulated, "); - appendPQExpBufferStr(query, - "c.relreplident, "); + appendPQExpBufferStr(query, + "c.relreplident, "); - appendPQExpBufferStr(query, - "c.relrowsecurity, c.relforcerowsecurity, "); + appendPQExpBufferStr(query, + "c.relrowsecurity, c.relforcerowsecurity, "); - appendPQExpBufferStr(query, - "c.relminmxid, tc.relminmxid AS tminmxid, "); + appendPQExpBufferStr(query, + "c.relminmxid, tc.relminmxid AS tminmxid, "); - appendPQExpBufferStr(query, - "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); + appendPQExpBufferStr(query, + "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); - appendPQExpBufferStr(query, - "am.amname, "); + appendPQExpBufferStr(query, + "am.amname, "); - appendPQExpBufferStr(query, - "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); + appendPQExpBufferStr(query, + "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); - appendPQExpBufferStr(query, - "c.relispartition AS ispartition "); + appendPQExpBufferStr(query, + "c.relispartition AS ispartition "); /* * Left join to pg_depend to pick up dependency info linking sequences to @@ -7296,8 +7295,8 @@ getTables(Archive *fout, int *numTables) /* * Left join to pg_am to pick up the amname. */ - appendPQExpBufferStr(query, - "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); + appendPQExpBufferStr(query, + "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); /* * We purposefully ignore toast OIDs for partitioned tables; the reason is @@ -7868,8 +7867,8 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables) "t.reloptions AS indreloptions, "); - appendPQExpBufferStr(query, - "i.indisreplident, "); + appendPQExpBufferStr(query, + "i.indisreplident, "); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -9313,8 +9312,8 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables) appendPQExpBufferStr(q, "'' AS attcompression,\n"); - appendPQExpBufferStr(q, - "a.attidentity,\n"); + appendPQExpBufferStr(q, + "a.attidentity,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(q, @@ -10717,73 +10716,73 @@ getAdditionalACLs(Archive *fout) PQclear(res); /* Fetch initial-privileges data */ - printfPQExpBuffer(query, - "SELECT objoid, classoid, objsubid, privtype, initprivs " - "FROM pg_init_privs"); + printfPQExpBuffer(query, + "SELECT objoid, classoid, objsubid, privtype, initprivs " + "FROM pg_init_privs"); - res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); + res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); - ntups = PQntuples(res); - for (i = 0; i < ntups; i++) - { - Oid objoid = atooid(PQgetvalue(res, i, 0)); - Oid classoid = atooid(PQgetvalue(res, i, 1)); - int objsubid = atoi(PQgetvalue(res, i, 2)); - char privtype = *(PQgetvalue(res, i, 3)); - char *initprivs = PQgetvalue(res, i, 4); - CatalogId objId; - DumpableObject *dobj; + ntups = PQntuples(res); + for (i = 0; i < ntups; i++) + { + Oid objoid = atooid(PQgetvalue(res, i, 0)); + Oid classoid = atooid(PQgetvalue(res, i, 1)); + int objsubid = atoi(PQgetvalue(res, i, 2)); + char privtype = *(PQgetvalue(res, i, 3)); + char *initprivs = PQgetvalue(res, i, 4); + CatalogId objId; + DumpableObject *dobj; - objId.tableoid = classoid; - objId.oid = objoid; - dobj = findObjectByCatalogId(objId); - /* OK to ignore entries we haven't got a DumpableObject for */ - if (dobj) + objId.tableoid = classoid; + objId.oid = objoid; + dobj = findObjectByCatalogId(objId); + /* OK to ignore entries we haven't got a DumpableObject for */ + if (dobj) + { + /* Cope with sub-object initprivs */ + if (objsubid != 0) { - /* Cope with sub-object initprivs */ - if (objsubid != 0) - { - if (dobj->objType == DO_TABLE) - { - /* For a column initprivs, set the table's ACL flags */ - dobj->components |= DUMP_COMPONENT_ACL; - ((TableInfo *) dobj)->hascolumnACLs = true; - } - else - pg_log_warning("unsupported pg_init_privs entry: %u %u %d", - classoid, objoid, objsubid); - continue; - } - - /* - * We ignore any pg_init_privs.initprivs entry for the public - * schema, as explained in getNamespaces(). - */ - if (dobj->objType == DO_NAMESPACE && - strcmp(dobj->name, "public") == 0) - continue; - - /* Else it had better be of a type we think has ACLs */ - if (dobj->objType == DO_NAMESPACE || - dobj->objType == DO_TYPE || - dobj->objType == DO_FUNC || - dobj->objType == DO_AGG || - dobj->objType == DO_TABLE || - dobj->objType == DO_PROCLANG || - dobj->objType == DO_FDW || - dobj->objType == DO_FOREIGN_SERVER) + if (dobj->objType == DO_TABLE) { - DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; - - daobj->dacl.privtype = privtype; - daobj->dacl.initprivs = pstrdup(initprivs); + /* For a column initprivs, set the table's ACL flags */ + dobj->components |= DUMP_COMPONENT_ACL; + ((TableInfo *) dobj)->hascolumnACLs = true; } else pg_log_warning("unsupported pg_init_privs entry: %u %u %d", classoid, objoid, objsubid); + continue; + } + + /* + * We ignore any pg_init_privs.initprivs entry for the public + * schema, as explained in getNamespaces(). + */ + if (dobj->objType == DO_NAMESPACE && + strcmp(dobj->name, "public") == 0) + continue; + + /* Else it had better be of a type we think has ACLs */ + if (dobj->objType == DO_NAMESPACE || + dobj->objType == DO_TYPE || + dobj->objType == DO_FUNC || + dobj->objType == DO_AGG || + dobj->objType == DO_TABLE || + dobj->objType == DO_PROCLANG || + dobj->objType == DO_FDW || + dobj->objType == DO_FOREIGN_SERVER) + { + DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; + + daobj->dacl.privtype = privtype; + daobj->dacl.initprivs = pstrdup(initprivs); } + else + pg_log_warning("unsupported pg_init_privs entry: %u %u %d", + classoid, objoid, objsubid); } - PQclear(res); + } + PQclear(res); destroyPQExpBuffer(query); } @@ -11128,8 +11127,8 @@ dumpRelationStats_dumper(Archive *fout, const void *userArg, const TocEntry *te) * The results must be in the order of the relations supplied in the * parameters to ensure we remain in sync as we walk through the TOC. * - * For versions before 19, the redundant filter clause on s.tablename = - * ANY(...) seems sufficient to convince the planner to use + * For versions before 19, the redundant filter clause on s.tablename + * = ANY(...) seems sufficient to convince the planner to use * pg_class_relname_nsp_index, which avoids a full scan of pg_stats. * In newer versions, pg_stats returns the table OIDs, eliminating the * need for that hack. @@ -13469,11 +13468,11 @@ dumpFunc(Archive *fout, const FuncInfo *finfo) "pg_catalog.pg_get_function_result(p.oid) AS funcresult,\n" "proleakproof,\n"); - appendPQExpBufferStr(query, - "array_to_string(protrftypes, ' ') AS protrftypes,\n"); + appendPQExpBufferStr(query, + "array_to_string(protrftypes, ' ') AS protrftypes,\n"); - appendPQExpBufferStr(query, - "proparallel,\n"); + appendPQExpBufferStr(query, + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -14963,9 +14962,9 @@ dumpCollation(Archive *fout, const CollInfo *collinfo) /* Get collation-specific details */ appendPQExpBufferStr(query, "SELECT "); - appendPQExpBufferStr(query, - "collprovider, " - "collversion, "); + appendPQExpBufferStr(query, + "collprovider, " + "collversion, "); if (fout->remoteVersion >= 120000) appendPQExpBufferStr(query, @@ -15372,23 +15371,23 @@ dumpAgg(Archive *fout, const AggInfo *agginfo) "pg_catalog.pg_get_function_arguments(p.oid) AS funcargs,\n" "pg_catalog.pg_get_function_identity_arguments(p.oid) AS funciargs,\n"); - appendPQExpBufferStr(query, - "aggkind,\n" - "aggmtransfn,\n" - "aggminvtransfn,\n" - "aggmfinalfn,\n" - "aggmtranstype::pg_catalog.regtype,\n" - "aggfinalextra,\n" - "aggmfinalextra,\n" - "aggtransspace,\n" - "aggmtransspace,\n" - "aggminitval,\n"); + appendPQExpBufferStr(query, + "aggkind,\n" + "aggmtransfn,\n" + "aggminvtransfn,\n" + "aggmfinalfn,\n" + "aggmtranstype::pg_catalog.regtype,\n" + "aggfinalextra,\n" + "aggmfinalextra,\n" + "aggtransspace,\n" + "aggmtransspace,\n" + "aggminitval,\n"); - appendPQExpBufferStr(query, - "aggcombinefn,\n" - "aggserialfn,\n" - "aggdeserialfn,\n" - "proparallel,\n"); + appendPQExpBufferStr(query, + "aggcombinefn,\n" + "aggserialfn,\n" + "aggdeserialfn,\n" + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -16848,30 +16847,30 @@ dumpTable(Archive *fout, const TableInfo *tbinfo) appendPQExpBufferStr(query, "PREPARE getColumnACLs(pg_catalog.oid) AS\n"); - /* - * In principle we should call acldefault('c', relowner) to - * get the default ACL for a column. However, we don't - * currently store the numeric OID of the relowner in - * TableInfo. We could convert the owner name using regrole, - * but that creates a risk of failure due to concurrent role - * renames. Given that the default ACL for columns is empty - * and is likely to stay that way, it's not worth extra cycles - * and risk to avoid hard-wiring that knowledge here. - */ - appendPQExpBufferStr(query, - "SELECT at.attname, " - "at.attacl, " - "'{}' AS acldefault, " - "pip.privtype, pip.initprivs " - "FROM pg_catalog.pg_attribute at " - "LEFT JOIN pg_catalog.pg_init_privs pip ON " - "(at.attrelid = pip.objoid " - "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " - "AND at.attnum = pip.objsubid) " - "WHERE at.attrelid = $1 AND " - "NOT at.attisdropped " - "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " - "ORDER BY at.attnum"); + /* + * In principle we should call acldefault('c', relowner) to get + * the default ACL for a column. However, we don't currently + * store the numeric OID of the relowner in TableInfo. We could + * convert the owner name using regrole, but that creates a risk + * of failure due to concurrent role renames. Given that the + * default ACL for columns is empty and is likely to stay that + * way, it's not worth extra cycles and risk to avoid hard-wiring + * that knowledge here. + */ + appendPQExpBufferStr(query, + "SELECT at.attname, " + "at.attacl, " + "'{}' AS acldefault, " + "pip.privtype, pip.initprivs " + "FROM pg_catalog.pg_attribute at " + "LEFT JOIN pg_catalog.pg_init_privs pip ON " + "(at.attrelid = pip.objoid " + "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " + "AND at.attnum = pip.objsubid) " + "WHERE at.attrelid = $1 AND " + "NOT at.attisdropped " + "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " + "ORDER BY at.attnum"); ExecuteSqlStatement(fout, query->data); @@ -19165,7 +19164,7 @@ collectSequences(Archive *fout) * pg_get_sequence_data(), but we only do so for non-schema-only dumps. */ if (fout->remoteVersion < 180000 || - (!fout->dopt->dumpData && !fout->dopt->sequence_data)) + (!fout->dopt->dumpData && !fout->dopt->sequence_data)) query = "SELECT seqrelid, format_type(seqtypid, NULL), " "seqstart, seqincrement, " "seqmax, seqmin, " @@ -19227,15 +19226,14 @@ dumpSequence(Archive *fout, const TableInfo *tbinfo) qseqname = pg_strdup(fmtId(tbinfo->dobj.name)); /* - * The sequence information is gathered in a sorted - * table before any calls to dumpSequence(). See collectSequences() for - * more information. + * The sequence information is gathered in a sorted table before any calls + * to dumpSequence(). See collectSequences() for more information. */ - Assert(sequences); + Assert(sequences); - key.oid = tbinfo->dobj.catId.oid; - seq = bsearch(&key, sequences, nsequences, - sizeof(SequenceItem), SequenceItemCmp); + key.oid = tbinfo->dobj.catId.oid; + seq = bsearch(&key, sequences, nsequences, + sizeof(SequenceItem), SequenceItemCmp); /* Calculate default limits for a sequence of this type */ is_ascending = (seq->incby >= 0); diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c index e68937c9934..afcd9a218d8 100644 --- a/src/bin/pg_dump/pg_dumpall.c +++ b/src/bin/pg_dump/pg_dumpall.c @@ -785,11 +785,11 @@ dropRoles(PGconn *conn) int i_rolname; int i; - printfPQExpBuffer(buf, - "SELECT rolname " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 1", role_catalog); + printfPQExpBuffer(buf, + "SELECT rolname " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 1", role_catalog); res = executeQuery(conn, buf->data); @@ -843,16 +843,16 @@ dumpRoles(PGconn *conn) * Notes: rolconfig is dumped later, and pg_authid must be used for * extracting rolcomment regardless of role_catalog. */ - printfPQExpBuffer(buf, - "SELECT oid, rolname, rolsuper, rolinherit, " - "rolcreaterole, rolcreatedb, " - "rolcanlogin, rolconnlimit, rolpassword, " - "rolvaliduntil, rolreplication, rolbypassrls, " - "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " - "rolname = current_user AS is_current_user " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 2", role_catalog); + printfPQExpBuffer(buf, + "SELECT oid, rolname, rolsuper, rolinherit, " + "rolcreaterole, rolcreatedb, " + "rolcanlogin, rolconnlimit, rolpassword, " + "rolvaliduntil, rolreplication, rolbypassrls, " + "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " + "rolname = current_user AS is_current_user " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 2", role_catalog); res = executeQuery(conn, buf->data); diff --git a/src/bin/pg_upgrade/check.c b/src/bin/pg_upgrade/check.c index 786c1474829..f725f5ee3e2 100644 --- a/src/bin/pg_upgrade/check.c +++ b/src/bin/pg_upgrade/check.c @@ -1475,15 +1475,15 @@ check_for_incompatible_polymorphics(ClusterInfo *cluster) ", 'array_cat(anyarray,anyarray)'" ", 'array_prepend(anyelement,anyarray)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_remove(anyarray,anyelement)'" - ", 'array_replace(anyarray,anyelement,anyelement)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_remove(anyarray,anyelement)'" + ", 'array_replace(anyarray,anyelement,anyelement)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_position(anyarray,anyelement)'" - ", 'array_position(anyarray,anyelement,integer)'" - ", 'array_positions(anyarray,anyelement)'" - ", 'width_bucket(anyelement,anyarray)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_position(anyarray,anyelement)'" + ", 'array_position(anyarray,anyelement,integer)'" + ", 'array_positions(anyarray,anyelement)'" + ", 'width_bucket(anyelement,anyarray)'"); /* * The query below hardcodes FirstNormalObjectId as 16384 rather than diff --git a/src/bin/pg_upgrade/controldata.c b/src/bin/pg_upgrade/controldata.c index 8f81c9e9582..02ea02df60f 100644 --- a/src/bin/pg_upgrade/controldata.c +++ b/src/bin/pg_upgrade/controldata.c @@ -228,7 +228,7 @@ get_control_data(ClusterInfo *cluster) p++; /* remove ':' char */ cluster->controldata.chkpnt_nxtepoch = str2uint(p); - p = strchr(p, ':'); + p = strchr(p, ':'); if (p == NULL || strlen(p) <= 1) pg_fatal("%d: controldata retrieval problem", __LINE__); diff --git a/src/bin/pg_upgrade/exec.c b/src/bin/pg_upgrade/exec.c index 44355feea30..a1bdbf373e3 100644 --- a/src/bin/pg_upgrade/exec.c +++ b/src/bin/pg_upgrade/exec.c @@ -55,7 +55,7 @@ get_bin_version(ClusterInfo *cluster) if (sscanf(cmd_output, "%*s %*s %d.%d", &v1, &v2) < 1) pg_fatal("could not get pg_ctl version output from %s", cmd); - cluster->bin_version = v1 * 10000; + cluster->bin_version = v1 * 10000; } @@ -344,8 +344,8 @@ check_data_dir(ClusterInfo *cluster) check_single_dir(pg_data, "pg_subtrans"); check_single_dir(pg_data, PG_TBLSPC_DIR); check_single_dir(pg_data, "pg_twophase"); - check_single_dir(pg_data, "pg_wal"); - check_single_dir(pg_data, "pg_xact"); + check_single_dir(pg_data, "pg_wal"); + check_single_dir(pg_data, "pg_xact"); } @@ -385,7 +385,7 @@ check_bin_dir(ClusterInfo *cluster, bool check_versions) */ get_bin_version(cluster); - check_exec(cluster->bindir, "pg_resetwal", check_versions); + check_exec(cluster->bindir, "pg_resetwal", check_versions); if (cluster == &new_cluster) { diff --git a/src/bin/pg_upgrade/multixact_rewrite.c b/src/bin/pg_upgrade/multixact_rewrite.c index c45b3183684..c7a1416494d 100644 --- a/src/bin/pg_upgrade/multixact_rewrite.c +++ b/src/bin/pg_upgrade/multixact_rewrite.c @@ -61,52 +61,52 @@ rewrite_multixacts(MultiXactId from_multi, MultiXactId to_multi) * Convert old multixids, if needed, by reading them one-by-one from the * old cluster. */ - old_reader = AllocOldMultiXactRead(old_cluster.pgdata, - old_cluster.controldata.chkpnt_nxtmulti, - old_cluster.controldata.chkpnt_nxtmxoff); + old_reader = AllocOldMultiXactRead(old_cluster.pgdata, + old_cluster.controldata.chkpnt_nxtmulti, + old_cluster.controldata.chkpnt_nxtmxoff); - for (MultiXactId multi = from_multi; multi != to_multi;) - { - MultiXactMember member; - bool multixid_valid; - - /* - * Read this multixid's members. - * - * Locking-only XIDs that may be part of multi-xids don't matter - * after upgrade, as there can be no transactions running across - * upgrade. So as a small optimization, we only read one member - * from each multixid: the one updating one, or if there was no - * update, arbitrarily the first locking xid. - */ - multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); + for (MultiXactId multi = from_multi; multi != to_multi;) + { + MultiXactMember member; + bool multixid_valid; - /* - * Write the new offset to pg_multixact/offsets. - * - * Even if this multixid is invalid, we still need to write its - * offset if the *previous* multixid was valid. That's because - * when reading a multixid, the number of members is calculated - * from the difference between the two offsets. - */ - RecordMultiXactOffset(offsets_writer, multi, - (multixid_valid || prev_multixid_valid) ? next_offset : 0); + /* + * Read this multixid's members. + * + * Locking-only XIDs that may be part of multi-xids don't matter after + * upgrade, as there can be no transactions running across upgrade. So + * as a small optimization, we only read one member from each + * multixid: the one updating one, or if there was no update, + * arbitrarily the first locking xid. + */ + multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); - /* Write the members */ - if (multixid_valid) - { - RecordMultiXactMembers(members_writer, next_offset, 1, &member); - next_offset += 1; - } + /* + * Write the new offset to pg_multixact/offsets. + * + * Even if this multixid is invalid, we still need to write its offset + * if the *previous* multixid was valid. That's because when reading + * a multixid, the number of members is calculated from the difference + * between the two offsets. + */ + RecordMultiXactOffset(offsets_writer, multi, + (multixid_valid || prev_multixid_valid) ? next_offset : 0); - /* Advance to next multixid, handling wraparound */ - multi++; - if (multi < FirstMultiXactId) - multi = FirstMultiXactId; - prev_multixid_valid = multixid_valid; + /* Write the members */ + if (multixid_valid) + { + RecordMultiXactMembers(members_writer, next_offset, 1, &member); + next_offset += 1; } - FreeOldMultiXactReader(old_reader); + /* Advance to next multixid, handling wraparound */ + multi++; + if (multi < FirstMultiXactId) + multi = FirstMultiXactId; + prev_multixid_valid = multixid_valid; + } + + FreeOldMultiXactReader(old_reader); /* Write the final 'next' offset to the last SLRU page */ RecordMultiXactOffset(offsets_writer, to_multi, diff --git a/src/bin/pg_upgrade/pg_upgrade.c b/src/bin/pg_upgrade/pg_upgrade.c index c6af9035665..7366fd4627c 100644 --- a/src/bin/pg_upgrade/pg_upgrade.c +++ b/src/bin/pg_upgrade/pg_upgrade.c @@ -833,7 +833,7 @@ copy_xact_xlog_xid(void) * Determine the range of multixacts to convert. */ nxtmulti = old_cluster.controldata.chkpnt_nxtmulti; - oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; + oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; /* handle wraparound */ if (nxtmulti < FirstMultiXactId) nxtmulti = FirstMultiXactId; @@ -898,15 +898,15 @@ set_frozenxids(void) int i_datname; int i_datallowconn; - prep_status("Setting frozenxid and minmxid counters in new cluster"); + prep_status("Setting frozenxid and minmxid counters in new cluster"); conn_template1 = connectToServer(&new_cluster, "template1"); - /* set pg_database.datfrozenxid */ - PQclear(executeQueryOrDie(conn_template1, - "UPDATE pg_catalog.pg_database " - "SET datfrozenxid = '%u'", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_database.datfrozenxid */ + PQclear(executeQueryOrDie(conn_template1, + "UPDATE pg_catalog.pg_database " + "SET datfrozenxid = '%u'", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_database.datminmxid */ PQclear(executeQueryOrDie(conn_template1, @@ -942,16 +942,16 @@ set_frozenxids(void) conn = connectToServer(&new_cluster, datname); - /* set pg_class.relfrozenxid */ - PQclear(executeQueryOrDie(conn, - "UPDATE pg_catalog.pg_class " - "SET relfrozenxid = '%u' " - /* only heap, materialized view, and TOAST are vacuumed */ - "WHERE relkind IN (" - CppAsString2(RELKIND_RELATION) ", " - CppAsString2(RELKIND_MATVIEW) ", " - CppAsString2(RELKIND_TOASTVALUE) ")", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_class.relfrozenxid */ + PQclear(executeQueryOrDie(conn, + "UPDATE pg_catalog.pg_class " + "SET relfrozenxid = '%u' " + /* only heap, materialized view, and TOAST are vacuumed */ + "WHERE relkind IN (" + CppAsString2(RELKIND_RELATION) ", " + CppAsString2(RELKIND_MATVIEW) ", " + CppAsString2(RELKIND_TOASTVALUE) ")", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_class.relminmxid */ PQclear(executeQueryOrDie(conn, diff --git a/src/bin/pg_upgrade/relfilenumber.c b/src/bin/pg_upgrade/relfilenumber.c index ec2ff7acb21..6c467bdc8a5 100644 --- a/src/bin/pg_upgrade/relfilenumber.c +++ b/src/bin/pg_upgrade/relfilenumber.c @@ -587,32 +587,32 @@ transfer_relfile(FileNameMap *map, const char *type_suffix) /* Copying files might take some time, so give feedback. */ pg_log(PG_STATUS, "%s", old_file); - switch (user_opts.transfer_mode) - { - case TRANSFER_MODE_CLONE: - pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", - old_file, new_file); - cloneFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", - old_file, new_file); - copyFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY_FILE_RANGE: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", - old_file, new_file); - copyFileByRange(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_LINK: - pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", - old_file, new_file); - linkFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_SWAP: - /* swap mode is handled in its own code path */ - pg_fatal("should never happen"); - break; - } + switch (user_opts.transfer_mode) + { + case TRANSFER_MODE_CLONE: + pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", + old_file, new_file); + cloneFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", + old_file, new_file); + copyFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY_FILE_RANGE: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", + old_file, new_file); + copyFileByRange(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_LINK: + pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", + old_file, new_file); + linkFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_SWAP: + /* swap mode is handled in its own code path */ + pg_fatal("should never happen"); + break; + } } } diff --git a/src/bin/pg_upgrade/t/006_transfer_modes.pl b/src/bin/pg_upgrade/t/006_transfer_modes.pl index 9efa5dc863c..360d05c4b68 100644 --- a/src/bin/pg_upgrade/t/006_transfer_modes.pl +++ b/src/bin/pg_upgrade/t/006_transfer_modes.pl @@ -29,10 +29,8 @@ sub test_mode } $new->init(); - $new->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); - $old->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); + $new->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); + $old->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); # We can only test security labels if both the old and new installations # have dummy_seclabel. @@ -76,15 +74,14 @@ sub test_mode "CREATE TABLE test4 AS SELECT generate_series(400, 502)"); } - $old->safe_psql('postgres', - "CREATE TABLESPACE inplc_tblspc LOCATION ''"); - $old->safe_psql('postgres', - "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); - $old->safe_psql('postgres', - "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" - ); - $old->safe_psql('testdb3', - "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); + $old->safe_psql('postgres', "CREATE TABLESPACE inplc_tblspc LOCATION ''"); + $old->safe_psql('postgres', + "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); + $old->safe_psql('postgres', + "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" + ); + $old->safe_psql('testdb3', + "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); # While we are here, test handling of large objects. $old->safe_psql( @@ -152,12 +149,10 @@ sub test_mode } # Tests for in-place tablespaces. - $result = - $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); - is($result, '104', "test5 data after pg_upgrade $mode"); - $result = - $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); - is($result, '105', "test6 data after pg_upgrade $mode"); + $result = $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); + is($result, '104', "test5 data after pg_upgrade $mode"); + $result = $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); + is($result, '105', "test6 data after pg_upgrade $mode"); # Tests for large objects $result = $new->safe_psql('postgres', "SELECT lo_get(4532)"); diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index 44ef11d980e..c90bf8bbde2 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -6278,23 +6278,22 @@ get_create_object_cmd(EditableObjectType obj_type, Oid oid, * ensure the right view gets replaced. Also, check relation kind * to be sure it's a view. * - * Views may have WITH [LOCAL|CASCADED] - * CHECK OPTION. These are not part of the view definition - * returned by pg_get_viewdef() and so need to be retrieved - * separately. Materialized views may have - * arbitrary storage parameter reloptions. + * Views may have WITH [LOCAL|CASCADED] CHECK OPTION. These are + * not part of the view definition returned by pg_get_viewdef() + * and so need to be retrieved separately. Materialized views may + * have arbitrary storage parameter reloptions. */ printfPQExpBuffer(query, "/* %s */\n", _("Get view's definition and details")); - appendPQExpBuffer(query, - "SELECT nspname, relname, relkind, " - "pg_catalog.pg_get_viewdef(c.oid, true), " - "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " - "FROM pg_catalog.pg_class c " - "LEFT JOIN pg_catalog.pg_namespace n " - "ON c.relnamespace = n.oid WHERE c.oid = %u", - oid); + appendPQExpBuffer(query, + "SELECT nspname, relname, relkind, " + "pg_catalog.pg_get_viewdef(c.oid, true), " + "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " + "FROM pg_catalog.pg_class c " + "LEFT JOIN pg_catalog.pg_namespace n " + "ON c.relnamespace = n.oid WHERE c.oid = %u", + oid); break; } diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index ce99137c613..ac0c55e7aa5 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -387,19 +387,19 @@ describeFunctions(const char *functypes, const char *func_pattern, gettext_noop("stable"), gettext_noop("volatile"), gettext_noop("Volatility")); - appendPQExpBuffer(&buf, - ",\n CASE\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" - " END as \"%s\"", - gettext_noop("restricted"), - gettext_noop("safe"), - gettext_noop("unsafe"), - gettext_noop("Parallel")); + appendPQExpBuffer(&buf, + ",\n CASE\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" + " END as \"%s\"", + gettext_noop("restricted"), + gettext_noop("safe"), + gettext_noop("unsafe"), + gettext_noop("Parallel")); appendPQExpBuffer(&buf, ",\n pg_catalog.pg_get_userbyid(p.proowner) as \"%s\"" ",\n CASE WHEN prosecdef THEN '%s' ELSE '%s' END AS \"%s\"" @@ -599,8 +599,8 @@ describeFunctions(const char *functypes, const char *func_pattern, myopt.title = _("List of functions"); myopt.translate_header = true; - myopt.translate_columns = translate_columns; - myopt.n_translate_columns = lengthof(translate_columns); + myopt.translate_columns = translate_columns; + myopt.n_translate_columns = lengthof(translate_columns); printQuery(res, &myopt, pset.queryFout, false, pset.logfile); @@ -1086,38 +1086,38 @@ permissionsList(const char *pattern, bool showSystem) " ), E'\\n') AS \"%s\"", gettext_noop("Column privileges")); - appendPQExpBuffer(&buf, - ",\n pg_catalog.array_to_string(ARRAY(\n" - " SELECT polname\n" - " || CASE WHEN NOT polpermissive THEN\n" - " E' (RESTRICTIVE)'\n" - " ELSE '' END\n" - " || CASE WHEN polcmd != '*' THEN\n" - " E' (' || polcmd::pg_catalog.text || E'):'\n" - " ELSE E':'\n" - " END\n" - " || CASE WHEN polqual IS NOT NULL THEN\n" - " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" - " ELSE E''\n" - " END\n" - " || CASE WHEN polwithcheck IS NOT NULL THEN\n" - " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" - " ELSE E''\n" - " END" - " || CASE WHEN polroles <> '{0}' THEN\n" - " E'\\n to: ' || pg_catalog.array_to_string(\n" - " ARRAY(\n" - " SELECT rolname\n" - " FROM pg_catalog.pg_roles\n" - " WHERE oid = ANY (polroles)\n" - " ORDER BY 1\n" - " ), E', ')\n" - " ELSE E''\n" - " END\n" - " FROM pg_catalog.pg_policy pol\n" - " WHERE polrelid = c.oid), E'\\n')\n" - " AS \"%s\"", - gettext_noop("Policies")); + appendPQExpBuffer(&buf, + ",\n pg_catalog.array_to_string(ARRAY(\n" + " SELECT polname\n" + " || CASE WHEN NOT polpermissive THEN\n" + " E' (RESTRICTIVE)'\n" + " ELSE '' END\n" + " || CASE WHEN polcmd != '*' THEN\n" + " E' (' || polcmd::pg_catalog.text || E'):'\n" + " ELSE E':'\n" + " END\n" + " || CASE WHEN polqual IS NOT NULL THEN\n" + " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" + " ELSE E''\n" + " END\n" + " || CASE WHEN polwithcheck IS NOT NULL THEN\n" + " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" + " ELSE E''\n" + " END" + " || CASE WHEN polroles <> '{0}' THEN\n" + " E'\\n to: ' || pg_catalog.array_to_string(\n" + " ARRAY(\n" + " SELECT rolname\n" + " FROM pg_catalog.pg_roles\n" + " WHERE oid = ANY (polroles)\n" + " ORDER BY 1\n" + " ), E', ')\n" + " ELSE E''\n" + " END\n" + " FROM pg_catalog.pg_policy pol\n" + " WHERE polrelid = c.oid), E'\\n')\n" + " AS \"%s\"", + gettext_noop("Policies")); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_class c\n" " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n" @@ -1675,27 +1675,27 @@ describeOneTableDetails(const char *schemaname, char *footers[3] = {NULL, NULL, NULL}; printfPQExpBuffer(&buf, "/* %s */\n", _("Get sequence information")); - appendPQExpBuffer(&buf, - "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" - " seqstart AS \"%s\",\n" - " seqmin AS \"%s\",\n" - " seqmax AS \"%s\",\n" - " seqincrement AS \"%s\",\n" - " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" - " seqcache AS \"%s\"\n", - gettext_noop("Type"), - gettext_noop("Start"), - gettext_noop("Minimum"), - gettext_noop("Maximum"), - gettext_noop("Increment"), - gettext_noop("yes"), - gettext_noop("no"), - gettext_noop("Cycles?"), - gettext_noop("Cache")); - appendPQExpBuffer(&buf, - "FROM pg_catalog.pg_sequence\n" - "WHERE seqrelid = '%s';", - oid); + appendPQExpBuffer(&buf, + "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" + " seqstart AS \"%s\",\n" + " seqmin AS \"%s\",\n" + " seqmax AS \"%s\",\n" + " seqincrement AS \"%s\",\n" + " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" + " seqcache AS \"%s\"\n", + gettext_noop("Type"), + gettext_noop("Start"), + gettext_noop("Minimum"), + gettext_noop("Maximum"), + gettext_noop("Increment"), + gettext_noop("yes"), + gettext_noop("no"), + gettext_noop("Cycles?"), + gettext_noop("Cache")); + appendPQExpBuffer(&buf, + "FROM pg_catalog.pg_sequence\n" + "WHERE seqrelid = '%s';", + oid); res = PSQLexec(buf.data); if (!res) @@ -1913,7 +1913,7 @@ describeOneTableDetails(const char *schemaname, appendPQExpBufferStr(&buf, ",\n (SELECT c.collname FROM pg_catalog.pg_collation c, pg_catalog.pg_type t\n" " WHERE c.oid = a.attcollation AND t.oid = a.atttypid AND a.attcollation <> t.typcollation) AS attcollation"); attcoll_col = cols++; - appendPQExpBufferStr(&buf, ",\n a.attidentity"); + appendPQExpBufferStr(&buf, ",\n a.attidentity"); attidentity_col = cols++; if (pset.sversion >= 120000) appendPQExpBufferStr(&buf, ",\n a.attgenerated"); @@ -2326,7 +2326,7 @@ describeOneTableDetails(const char *schemaname, CppAsString2(CONSTRAINT_EXCLUSION) ") AND " "condeferred) AS condeferred,\n"); - appendPQExpBufferStr(&buf, "i.indisreplident,\n"); + appendPQExpBufferStr(&buf, "i.indisreplident,\n"); if (pset.sversion >= 150000) appendPQExpBufferStr(&buf, "i.indnullsnotdistinct,\n"); @@ -2431,7 +2431,7 @@ describeOneTableDetails(const char *schemaname, "pg_catalog.pg_get_indexdef(i.indexrelid, 0, true),\n " "pg_catalog.pg_get_constraintdef(con.oid, true), " "contype, condeferrable, condeferred"); - appendPQExpBufferStr(&buf, ", i.indisreplident"); + appendPQExpBufferStr(&buf, ", i.indisreplident"); appendPQExpBufferStr(&buf, ", c2.reltablespace"); if (pset.sversion >= 180000) appendPQExpBufferStr(&buf, ", con.conperiod"); @@ -2682,81 +2682,80 @@ describeOneTableDetails(const char *schemaname, PQclear(result); /* print any row-level policies */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get row-level policies for this table")); - appendPQExpBufferStr(&buf, "SELECT pol.polname,"); - appendPQExpBufferStr(&buf, - " pol.polpermissive,\n"); - appendPQExpBuffer(&buf, - " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" - " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" - " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" - " CASE pol.polcmd\n" - " WHEN 'r' THEN 'SELECT'\n" - " WHEN 'a' THEN 'INSERT'\n" - " WHEN 'w' THEN 'UPDATE'\n" - " WHEN 'd' THEN 'DELETE'\n" - " END AS cmd\n" - "FROM pg_catalog.pg_policy pol\n" - "WHERE pol.polrelid = '%s' ORDER BY 1;", - oid); + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get row-level policies for this table")); + appendPQExpBufferStr(&buf, "SELECT pol.polname,"); + appendPQExpBufferStr(&buf, + " pol.polpermissive,\n"); + appendPQExpBuffer(&buf, + " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" + " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" + " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" + " CASE pol.polcmd\n" + " WHEN 'r' THEN 'SELECT'\n" + " WHEN 'a' THEN 'INSERT'\n" + " WHEN 'w' THEN 'UPDATE'\n" + " WHEN 'd' THEN 'DELETE'\n" + " END AS cmd\n" + "FROM pg_catalog.pg_policy pol\n" + "WHERE pol.polrelid = '%s' ORDER BY 1;", + oid); - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - /* - * Handle cases where RLS is enabled and there are policies, or - * there aren't policies, or RLS isn't enabled but there are - * policies - */ - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies:")); + /* + * Handle cases where RLS is enabled and there are policies, or there + * aren't policies, or RLS isn't enabled but there are policies + */ + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies:")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled):")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled):")); - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); - if (!tableinfo.rowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (row security disabled):")); + if (!tableinfo.rowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (row security disabled):")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " POLICY \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " POLICY \"%s\"", + PQgetvalue(result, i, 0)); - if (*(PQgetvalue(result, i, 1)) == 'f') - appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); + if (*(PQgetvalue(result, i, 1)) == 'f') + appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); - if (!PQgetisnull(result, i, 5)) - appendPQExpBuffer(&buf, " FOR %s", - PQgetvalue(result, i, 5)); + if (!PQgetisnull(result, i, 5)) + appendPQExpBuffer(&buf, " FOR %s", + PQgetvalue(result, i, 5)); - if (!PQgetisnull(result, i, 2)) - { - appendPQExpBuffer(&buf, "\n TO %s", - PQgetvalue(result, i, 2)); - } + if (!PQgetisnull(result, i, 2)) + { + appendPQExpBuffer(&buf, "\n TO %s", + PQgetvalue(result, i, 2)); + } - if (!PQgetisnull(result, i, 3)) - appendPQExpBuffer(&buf, "\n USING (%s)", - PQgetvalue(result, i, 3)); + if (!PQgetisnull(result, i, 3)) + appendPQExpBuffer(&buf, "\n USING (%s)", + PQgetvalue(result, i, 3)); - if (!PQgetisnull(result, i, 4)) - appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", - PQgetvalue(result, i, 4)); + if (!PQgetisnull(result, i, 4)) + appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", + PQgetvalue(result, i, 4)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* print any extended statistics */ if (pset.sversion >= 140000) @@ -3025,115 +3024,115 @@ describeOneTableDetails(const char *schemaname, } /* print any publications */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get publications that publish this table")); - if (pset.sversion >= 150000) + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get publications that publish this table")); + if (pset.sversion >= 150000) + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" + " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" + "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" + "UNION\n" + "SELECT pubname\n" + " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" + " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" + " (SELECT pg_catalog.string_agg(attname, ', ')\n" + " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" + " pg_catalog.pg_attribute\n" + " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" + " ELSE NULL END) " + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" + "WHERE pr.prrelid = '%s'\n", + oid, oid, oid); + + if (pset.sversion >= 190000) { + /* + * Skip entries where this relation appears in the + * publication's EXCEPT list. + */ appendPQExpBuffer(&buf, + " AND NOT pr.prexcept\n" + "UNION\n" "SELECT pubname\n" " , NULL\n" " , NULL\n" "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" - " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" - "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" - "UNION\n" - "SELECT pubname\n" - " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" - " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" - " (SELECT pg_catalog.string_agg(attname, ', ')\n" - " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" - " pg_catalog.pg_attribute\n" - " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" - " ELSE NULL END) " - "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" - "WHERE pr.prrelid = '%s'\n", + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + " AND NOT EXISTS (\n" + " SELECT 1\n" + " FROM pg_catalog.pg_publication_rel pr\n" + " WHERE pr.prpubid = p.oid AND\n" + " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" + "ORDER BY 1;", oid, oid, oid); - - if (pset.sversion >= 190000) - { - /* - * Skip entries where this relation appears in the - * publication's EXCEPT list. - */ - appendPQExpBuffer(&buf, - " AND NOT pr.prexcept\n" - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - " AND NOT EXISTS (\n" - " SELECT 1\n" - " FROM pg_catalog.pg_publication_rel pr\n" - " WHERE pr.prpubid = p.oid AND\n" - " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" - "ORDER BY 1;", - oid, oid, oid); - } - else - { - appendPQExpBuffer(&buf, - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - "ORDER BY 1;", - oid); - } } else { appendPQExpBuffer(&buf, + "UNION\n" "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - "WHERE pr.prrelid = '%s'\n" - "UNION ALL\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" + " , NULL\n" + " , NULL\n" "FROM pg_catalog.pg_publication p\n" "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" "ORDER BY 1;", - oid, oid); + oid); } + } + else + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + "WHERE pr.prrelid = '%s'\n" + "UNION ALL\n" + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + "ORDER BY 1;", + oid, oid); + } - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - if (tuples > 0) - printTableAddFooter(&cont, _("Included in publications:")); + if (tuples > 0) + printTableAddFooter(&cont, _("Included in publications:")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " \"%s\"", + PQgetvalue(result, i, 0)); - /* column list (if any) */ - if (!PQgetisnull(result, i, 2)) - appendPQExpBuffer(&buf, " (%s)", - PQgetvalue(result, i, 2)); + /* column list (if any) */ + if (!PQgetisnull(result, i, 2)) + appendPQExpBuffer(&buf, " (%s)", + PQgetvalue(result, i, 2)); - /* row filter (if any) */ - if (!PQgetisnull(result, i, 1)) - appendPQExpBuffer(&buf, " WHERE %s", - PQgetvalue(result, i, 1)); + /* row filter (if any) */ + if (!PQgetisnull(result, i, 1)) + appendPQExpBuffer(&buf, " WHERE %s", + PQgetvalue(result, i, 1)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* Print publications where the table is in the EXCEPT clause */ if (pset.sversion >= 190000) @@ -3805,7 +3804,7 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) ncols++; } appendPQExpBufferStr(&buf, "\n, r.rolreplication"); - appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); + appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_roles r\n"); @@ -3860,8 +3859,8 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) if (strcmp(PQgetvalue(res, i, (verbose ? 9 : 8)), "t") == 0) add_role_attribute(&buf, _("Replication")); - if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) - add_role_attribute(&buf, _("Bypass RLS")); + if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) + add_role_attribute(&buf, _("Bypass RLS")); conns = atoi(PQgetvalue(res, i, 6)); if (conns >= 0) @@ -5155,14 +5154,14 @@ listCollations(const char *pattern, bool verbose, bool showSystem) gettext_noop("Schema"), gettext_noop("Name")); - appendPQExpBuffer(&buf, - " CASE c.collprovider " - "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " - "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " - "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " - "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " - "END AS \"%s\",\n", - gettext_noop("Provider")); + appendPQExpBuffer(&buf, + " CASE c.collprovider " + "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " + "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " + "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " + "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " + "END AS \"%s\",\n", + gettext_noop("Provider")); appendPQExpBuffer(&buf, " c.collcollate AS \"%s\",\n" -- 2.50.1 (Apple Git-155) --aHl3HfeiUuO3zeNC-- ^ permalink raw reply [nested|flat] 59+ messages in thread
* [PATCH v6 4/4] run pgindent and pgperltidy @ 2026-06-30 18:24 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 59+ messages in thread From: Nathan Bossart @ 2026-06-30 18:24 UTC (permalink / raw) --- src/bin/pg_dump/pg_dump.c | 464 ++++++++++----------- src/bin/pg_dump/pg_dumpall.c | 30 +- src/bin/pg_upgrade/check.c | 16 +- src/bin/pg_upgrade/controldata.c | 2 +- src/bin/pg_upgrade/exec.c | 8 +- src/bin/pg_upgrade/multixact_rewrite.c | 80 ++-- src/bin/pg_upgrade/pg_upgrade.c | 34 +- src/bin/pg_upgrade/relfilenumber.c | 54 +-- src/bin/pg_upgrade/t/006_transfer_modes.pl | 33 +- src/bin/psql/command.c | 29 +- src/bin/psql/describe.c | 461 ++++++++++---------- 11 files changed, 601 insertions(+), 610 deletions(-) diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 65bd15ebfd2..5673268b467 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -1491,8 +1491,8 @@ setup_connection(Archive *AH, const char *dumpencoding, * Disable timeouts if supported. */ ExecuteSqlStatement(AH, "SET statement_timeout = 0"); - ExecuteSqlStatement(AH, "SET lock_timeout = 0"); - ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); + ExecuteSqlStatement(AH, "SET lock_timeout = 0"); + ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); if (AH->remoteVersion >= 170000) ExecuteSqlStatement(AH, "SET transaction_timeout = 0"); @@ -1505,10 +1505,10 @@ setup_connection(Archive *AH, const char *dumpencoding, /* * Adjust row-security mode, if supported. */ - if (dopt->enable_row_security) - ExecuteSqlStatement(AH, "SET row_security = on"); - else - ExecuteSqlStatement(AH, "SET row_security = off"); + if (dopt->enable_row_security) + ExecuteSqlStatement(AH, "SET row_security = on"); + else + ExecuteSqlStatement(AH, "SET row_security = off"); /* * For security reasons, we restrict the expansion of non-system views and @@ -1933,10 +1933,9 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) addObjectDependency(dobj, ext->dobj.dumpId); /* - * Mark the member object to have any non-initial ACLs - * dumped. (Any initial ACLs will be removed later, using data from - * pg_init_privs, so that we'll dump only the delta from the extension's - * initial setup.) + * Mark the member object to have any non-initial ACLs dumped. (Any + * initial ACLs will be removed later, using data from pg_init_privs, so + * that we'll dump only the delta from the extension's initial setup.) * * In binary upgrades, we still dump all components of the members * individually, since the idea is to exactly reproduce the database @@ -1953,7 +1952,7 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) if (fout->dopt->binary_upgrade) dobj->dump = ext->dobj.dump; else - dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); + dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); return true; } @@ -1987,9 +1986,9 @@ selectDumpableNamespace(NamespaceInfo *nsinfo, Archive *fout) else if (strcmp(nsinfo->dobj.name, "pg_catalog") == 0) { /* - * We dump out any ACLs defined in pg_catalog, if - * they are interesting (and not the original ACLs which were set at - * initdb time, see pg_init_privs). + * We dump out any ACLs defined in pg_catalog, if they are interesting + * (and not the original ACLs which were set at initdb time, see + * pg_init_privs). */ nsinfo->dobj.dump_contains = nsinfo->dobj.dump = DUMP_COMPONENT_ACL; } @@ -3296,7 +3295,7 @@ dumpDatabase(Archive *fout) "datcollate, datctype, datfrozenxid, " "datacl, acldefault('d', datdba) AS acldefault, " "datistemplate, datconnlimit, "); - appendPQExpBufferStr(dbQry, "datminmxid, "); + appendPQExpBufferStr(dbQry, "datminmxid, "); if (fout->remoteVersion >= 170000) appendPQExpBufferStr(dbQry, "datlocprovider, datlocale, datcollversion, "); else if (fout->remoteVersion >= 150000) @@ -3638,11 +3637,11 @@ dumpDatabase(Archive *fout) ii_oid, ii_relminmxid; - appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" - "FROM pg_catalog.pg_class\n" - "WHERE oid IN (%u, %u, %u, %u);\n", - LargeObjectRelationId, LargeObjectLOidPNIndexId, - LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); + appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" + "FROM pg_catalog.pg_class\n" + "WHERE oid IN (%u, %u, %u, %u);\n", + LargeObjectRelationId, LargeObjectLOidPNIndexId, + LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); lo_res = ExecuteSqlQuery(fout, loFrozenQry->data, PGRES_TUPLES_OK); @@ -4274,7 +4273,7 @@ getPolicies(Archive *fout, TableInfo tblinfo[], int numTables) printfPQExpBuffer(query, "SELECT pol.oid, pol.tableoid, pol.polrelid, pol.polname, pol.polcmd, "); - appendPQExpBufferStr(query, "pol.polpermissive, "); + appendPQExpBufferStr(query, "pol.polpermissive, "); appendPQExpBuffer(query, "CASE WHEN pol.polroles = '{0}' THEN NULL ELSE " " pg_catalog.array_to_string(ARRAY(SELECT pg_catalog.quote_ident(rolname) from pg_catalog.pg_roles WHERE oid = ANY(pol.polroles)), ', ') END AS polroles, " @@ -6633,9 +6632,9 @@ getAccessMethods(Archive *fout) * Select all access methods from pg_am table. */ appendPQExpBufferStr(query, "SELECT tableoid, oid, amname, "); - appendPQExpBufferStr(query, - "amtype, " - "amhandler::pg_catalog.regproc AS amhandler "); + appendPQExpBufferStr(query, + "amtype, " + "amhandler::pg_catalog.regproc AS amhandler "); appendPQExpBufferStr(query, "FROM pg_am"); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6827,35 +6826,35 @@ getAggregates(Archive *fout) * Find all interesting aggregates. See comment in getFuncs() for the * rationale behind the filtering logic. */ - agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" - : "p.proisagg"); + agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" + : "p.proisagg"); - appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " - "p.proname AS aggname, " - "p.pronamespace AS aggnamespace, " - "p.pronargs, p.proargtypes, " - "p.proowner, " - "p.proacl AS aggacl, " - "acldefault('f', p.proowner) AS acldefault " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s AND (" - "p.pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog') OR " - "p.proacl IS DISTINCT FROM pip.initprivs", - agg_check); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - " OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); - appendPQExpBufferChar(query, ')'); + appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " + "p.proname AS aggname, " + "p.pronamespace AS aggnamespace, " + "p.pronargs, p.proargtypes, " + "p.proowner, " + "p.proacl AS aggacl, " + "acldefault('f', p.proowner) AS acldefault " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s AND (" + "p.pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog') OR " + "p.proacl IS DISTINCT FROM pip.initprivs", + agg_check); + if (dopt->binary_upgrade) + appendPQExpBufferStr(query, + " OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6957,53 +6956,53 @@ getFuncs(Archive *fout) * include them, since we want to dump extension members individually in * that mode. Also, if they are used by casts or transforms then we need * to gather the information about them, though they won't be dumped if - * they are built-in. Also, include functions in - * pg_catalog if they have an ACL different from what's shown in - * pg_init_privs (so we have to join to pg_init_privs; annoying). + * they are built-in. Also, include functions in pg_catalog if they have + * an ACL different from what's shown in pg_init_privs (so we have to join + * to pg_init_privs; annoying). */ - not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" - : "NOT p.proisagg"); + not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" + : "NOT p.proisagg"); - appendPQExpBuffer(query, - "SELECT p.tableoid, p.oid, p.proname, p.prolang, " - "p.pronargs, p.proargtypes, p.prorettype, " - "p.proacl, " - "acldefault('f', p.proowner) AS acldefault, " - "p.pronamespace, " - "p.proowner " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s" - "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " - "WHERE classid = 'pg_proc'::regclass AND " - "objid = p.oid AND deptype = 'i')" - "\n AND (" - "\n pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog')" - "\n OR EXISTS (SELECT 1 FROM pg_cast" - "\n WHERE pg_cast.oid > %u " - "\n AND p.oid = pg_cast.castfunc)" - "\n OR EXISTS (SELECT 1 FROM pg_transform" - "\n WHERE pg_transform.oid > %u AND " - "\n (p.oid = pg_transform.trffromsql" - "\n OR p.oid = pg_transform.trftosql))", - not_agg_check, - g_last_builtin_oid, - g_last_builtin_oid); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); + appendPQExpBuffer(query, + "SELECT p.tableoid, p.oid, p.proname, p.prolang, " + "p.pronargs, p.proargtypes, p.prorettype, " + "p.proacl, " + "acldefault('f', p.proowner) AS acldefault, " + "p.pronamespace, " + "p.proowner " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s" + "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " + "WHERE classid = 'pg_proc'::regclass AND " + "objid = p.oid AND deptype = 'i')" + "\n AND (" + "\n pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog')" + "\n OR EXISTS (SELECT 1 FROM pg_cast" + "\n WHERE pg_cast.oid > %u " + "\n AND p.oid = pg_cast.castfunc)" + "\n OR EXISTS (SELECT 1 FROM pg_transform" + "\n WHERE pg_transform.oid > %u AND " + "\n (p.oid = pg_transform.trffromsql" + "\n OR p.oid = pg_transform.trftosql))", + not_agg_check, + g_last_builtin_oid, + g_last_builtin_oid); + if (dopt->binary_upgrade) appendPQExpBufferStr(query, - "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); - appendPQExpBufferChar(query, ')'); + "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferStr(query, + "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -7252,31 +7251,31 @@ getTables(Archive *fout, int *numTables) appendPQExpBufferStr(query, "c.relhasoids, "); - appendPQExpBufferStr(query, - "c.relispopulated, "); + appendPQExpBufferStr(query, + "c.relispopulated, "); - appendPQExpBufferStr(query, - "c.relreplident, "); + appendPQExpBufferStr(query, + "c.relreplident, "); - appendPQExpBufferStr(query, - "c.relrowsecurity, c.relforcerowsecurity, "); + appendPQExpBufferStr(query, + "c.relrowsecurity, c.relforcerowsecurity, "); - appendPQExpBufferStr(query, - "c.relminmxid, tc.relminmxid AS tminmxid, "); + appendPQExpBufferStr(query, + "c.relminmxid, tc.relminmxid AS tminmxid, "); - appendPQExpBufferStr(query, - "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); + appendPQExpBufferStr(query, + "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); - appendPQExpBufferStr(query, - "am.amname, "); + appendPQExpBufferStr(query, + "am.amname, "); - appendPQExpBufferStr(query, - "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); + appendPQExpBufferStr(query, + "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); - appendPQExpBufferStr(query, - "c.relispartition AS ispartition "); + appendPQExpBufferStr(query, + "c.relispartition AS ispartition "); /* * Left join to pg_depend to pick up dependency info linking sequences to @@ -7296,8 +7295,8 @@ getTables(Archive *fout, int *numTables) /* * Left join to pg_am to pick up the amname. */ - appendPQExpBufferStr(query, - "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); + appendPQExpBufferStr(query, + "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); /* * We purposefully ignore toast OIDs for partitioned tables; the reason is @@ -7868,8 +7867,8 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables) "t.reloptions AS indreloptions, "); - appendPQExpBufferStr(query, - "i.indisreplident, "); + appendPQExpBufferStr(query, + "i.indisreplident, "); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -9313,8 +9312,8 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables) appendPQExpBufferStr(q, "'' AS attcompression,\n"); - appendPQExpBufferStr(q, - "a.attidentity,\n"); + appendPQExpBufferStr(q, + "a.attidentity,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(q, @@ -10717,73 +10716,73 @@ getAdditionalACLs(Archive *fout) PQclear(res); /* Fetch initial-privileges data */ - printfPQExpBuffer(query, - "SELECT objoid, classoid, objsubid, privtype, initprivs " - "FROM pg_init_privs"); + printfPQExpBuffer(query, + "SELECT objoid, classoid, objsubid, privtype, initprivs " + "FROM pg_init_privs"); - res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); + res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); - ntups = PQntuples(res); - for (i = 0; i < ntups; i++) - { - Oid objoid = atooid(PQgetvalue(res, i, 0)); - Oid classoid = atooid(PQgetvalue(res, i, 1)); - int objsubid = atoi(PQgetvalue(res, i, 2)); - char privtype = *(PQgetvalue(res, i, 3)); - char *initprivs = PQgetvalue(res, i, 4); - CatalogId objId; - DumpableObject *dobj; + ntups = PQntuples(res); + for (i = 0; i < ntups; i++) + { + Oid objoid = atooid(PQgetvalue(res, i, 0)); + Oid classoid = atooid(PQgetvalue(res, i, 1)); + int objsubid = atoi(PQgetvalue(res, i, 2)); + char privtype = *(PQgetvalue(res, i, 3)); + char *initprivs = PQgetvalue(res, i, 4); + CatalogId objId; + DumpableObject *dobj; - objId.tableoid = classoid; - objId.oid = objoid; - dobj = findObjectByCatalogId(objId); - /* OK to ignore entries we haven't got a DumpableObject for */ - if (dobj) + objId.tableoid = classoid; + objId.oid = objoid; + dobj = findObjectByCatalogId(objId); + /* OK to ignore entries we haven't got a DumpableObject for */ + if (dobj) + { + /* Cope with sub-object initprivs */ + if (objsubid != 0) { - /* Cope with sub-object initprivs */ - if (objsubid != 0) - { - if (dobj->objType == DO_TABLE) - { - /* For a column initprivs, set the table's ACL flags */ - dobj->components |= DUMP_COMPONENT_ACL; - ((TableInfo *) dobj)->hascolumnACLs = true; - } - else - pg_log_warning("unsupported pg_init_privs entry: %u %u %d", - classoid, objoid, objsubid); - continue; - } - - /* - * We ignore any pg_init_privs.initprivs entry for the public - * schema, as explained in getNamespaces(). - */ - if (dobj->objType == DO_NAMESPACE && - strcmp(dobj->name, "public") == 0) - continue; - - /* Else it had better be of a type we think has ACLs */ - if (dobj->objType == DO_NAMESPACE || - dobj->objType == DO_TYPE || - dobj->objType == DO_FUNC || - dobj->objType == DO_AGG || - dobj->objType == DO_TABLE || - dobj->objType == DO_PROCLANG || - dobj->objType == DO_FDW || - dobj->objType == DO_FOREIGN_SERVER) + if (dobj->objType == DO_TABLE) { - DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; - - daobj->dacl.privtype = privtype; - daobj->dacl.initprivs = pstrdup(initprivs); + /* For a column initprivs, set the table's ACL flags */ + dobj->components |= DUMP_COMPONENT_ACL; + ((TableInfo *) dobj)->hascolumnACLs = true; } else pg_log_warning("unsupported pg_init_privs entry: %u %u %d", classoid, objoid, objsubid); + continue; + } + + /* + * We ignore any pg_init_privs.initprivs entry for the public + * schema, as explained in getNamespaces(). + */ + if (dobj->objType == DO_NAMESPACE && + strcmp(dobj->name, "public") == 0) + continue; + + /* Else it had better be of a type we think has ACLs */ + if (dobj->objType == DO_NAMESPACE || + dobj->objType == DO_TYPE || + dobj->objType == DO_FUNC || + dobj->objType == DO_AGG || + dobj->objType == DO_TABLE || + dobj->objType == DO_PROCLANG || + dobj->objType == DO_FDW || + dobj->objType == DO_FOREIGN_SERVER) + { + DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; + + daobj->dacl.privtype = privtype; + daobj->dacl.initprivs = pstrdup(initprivs); } + else + pg_log_warning("unsupported pg_init_privs entry: %u %u %d", + classoid, objoid, objsubid); } - PQclear(res); + } + PQclear(res); destroyPQExpBuffer(query); } @@ -11128,8 +11127,8 @@ dumpRelationStats_dumper(Archive *fout, const void *userArg, const TocEntry *te) * The results must be in the order of the relations supplied in the * parameters to ensure we remain in sync as we walk through the TOC. * - * For versions before 19, the redundant filter clause on s.tablename = - * ANY(...) seems sufficient to convince the planner to use + * For versions before 19, the redundant filter clause on s.tablename + * = ANY(...) seems sufficient to convince the planner to use * pg_class_relname_nsp_index, which avoids a full scan of pg_stats. * In newer versions, pg_stats returns the table OIDs, eliminating the * need for that hack. @@ -13469,11 +13468,11 @@ dumpFunc(Archive *fout, const FuncInfo *finfo) "pg_catalog.pg_get_function_result(p.oid) AS funcresult,\n" "proleakproof,\n"); - appendPQExpBufferStr(query, - "array_to_string(protrftypes, ' ') AS protrftypes,\n"); + appendPQExpBufferStr(query, + "array_to_string(protrftypes, ' ') AS protrftypes,\n"); - appendPQExpBufferStr(query, - "proparallel,\n"); + appendPQExpBufferStr(query, + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -14963,9 +14962,9 @@ dumpCollation(Archive *fout, const CollInfo *collinfo) /* Get collation-specific details */ appendPQExpBufferStr(query, "SELECT "); - appendPQExpBufferStr(query, - "collprovider, " - "collversion, "); + appendPQExpBufferStr(query, + "collprovider, " + "collversion, "); if (fout->remoteVersion >= 120000) appendPQExpBufferStr(query, @@ -15372,23 +15371,23 @@ dumpAgg(Archive *fout, const AggInfo *agginfo) "pg_catalog.pg_get_function_arguments(p.oid) AS funcargs,\n" "pg_catalog.pg_get_function_identity_arguments(p.oid) AS funciargs,\n"); - appendPQExpBufferStr(query, - "aggkind,\n" - "aggmtransfn,\n" - "aggminvtransfn,\n" - "aggmfinalfn,\n" - "aggmtranstype::pg_catalog.regtype,\n" - "aggfinalextra,\n" - "aggmfinalextra,\n" - "aggtransspace,\n" - "aggmtransspace,\n" - "aggminitval,\n"); + appendPQExpBufferStr(query, + "aggkind,\n" + "aggmtransfn,\n" + "aggminvtransfn,\n" + "aggmfinalfn,\n" + "aggmtranstype::pg_catalog.regtype,\n" + "aggfinalextra,\n" + "aggmfinalextra,\n" + "aggtransspace,\n" + "aggmtransspace,\n" + "aggminitval,\n"); - appendPQExpBufferStr(query, - "aggcombinefn,\n" - "aggserialfn,\n" - "aggdeserialfn,\n" - "proparallel,\n"); + appendPQExpBufferStr(query, + "aggcombinefn,\n" + "aggserialfn,\n" + "aggdeserialfn,\n" + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -16848,30 +16847,30 @@ dumpTable(Archive *fout, const TableInfo *tbinfo) appendPQExpBufferStr(query, "PREPARE getColumnACLs(pg_catalog.oid) AS\n"); - /* - * In principle we should call acldefault('c', relowner) to - * get the default ACL for a column. However, we don't - * currently store the numeric OID of the relowner in - * TableInfo. We could convert the owner name using regrole, - * but that creates a risk of failure due to concurrent role - * renames. Given that the default ACL for columns is empty - * and is likely to stay that way, it's not worth extra cycles - * and risk to avoid hard-wiring that knowledge here. - */ - appendPQExpBufferStr(query, - "SELECT at.attname, " - "at.attacl, " - "'{}' AS acldefault, " - "pip.privtype, pip.initprivs " - "FROM pg_catalog.pg_attribute at " - "LEFT JOIN pg_catalog.pg_init_privs pip ON " - "(at.attrelid = pip.objoid " - "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " - "AND at.attnum = pip.objsubid) " - "WHERE at.attrelid = $1 AND " - "NOT at.attisdropped " - "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " - "ORDER BY at.attnum"); + /* + * In principle we should call acldefault('c', relowner) to get + * the default ACL for a column. However, we don't currently + * store the numeric OID of the relowner in TableInfo. We could + * convert the owner name using regrole, but that creates a risk + * of failure due to concurrent role renames. Given that the + * default ACL for columns is empty and is likely to stay that + * way, it's not worth extra cycles and risk to avoid hard-wiring + * that knowledge here. + */ + appendPQExpBufferStr(query, + "SELECT at.attname, " + "at.attacl, " + "'{}' AS acldefault, " + "pip.privtype, pip.initprivs " + "FROM pg_catalog.pg_attribute at " + "LEFT JOIN pg_catalog.pg_init_privs pip ON " + "(at.attrelid = pip.objoid " + "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " + "AND at.attnum = pip.objsubid) " + "WHERE at.attrelid = $1 AND " + "NOT at.attisdropped " + "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " + "ORDER BY at.attnum"); ExecuteSqlStatement(fout, query->data); @@ -19165,7 +19164,7 @@ collectSequences(Archive *fout) * pg_get_sequence_data(), but we only do so for non-schema-only dumps. */ if (fout->remoteVersion < 180000 || - (!fout->dopt->dumpData && !fout->dopt->sequence_data)) + (!fout->dopt->dumpData && !fout->dopt->sequence_data)) query = "SELECT seqrelid, format_type(seqtypid, NULL), " "seqstart, seqincrement, " "seqmax, seqmin, " @@ -19227,15 +19226,14 @@ dumpSequence(Archive *fout, const TableInfo *tbinfo) qseqname = pg_strdup(fmtId(tbinfo->dobj.name)); /* - * The sequence information is gathered in a sorted - * table before any calls to dumpSequence(). See collectSequences() for - * more information. + * The sequence information is gathered in a sorted table before any calls + * to dumpSequence(). See collectSequences() for more information. */ - Assert(sequences); + Assert(sequences); - key.oid = tbinfo->dobj.catId.oid; - seq = bsearch(&key, sequences, nsequences, - sizeof(SequenceItem), SequenceItemCmp); + key.oid = tbinfo->dobj.catId.oid; + seq = bsearch(&key, sequences, nsequences, + sizeof(SequenceItem), SequenceItemCmp); /* Calculate default limits for a sequence of this type */ is_ascending = (seq->incby >= 0); diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c index e68937c9934..afcd9a218d8 100644 --- a/src/bin/pg_dump/pg_dumpall.c +++ b/src/bin/pg_dump/pg_dumpall.c @@ -785,11 +785,11 @@ dropRoles(PGconn *conn) int i_rolname; int i; - printfPQExpBuffer(buf, - "SELECT rolname " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 1", role_catalog); + printfPQExpBuffer(buf, + "SELECT rolname " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 1", role_catalog); res = executeQuery(conn, buf->data); @@ -843,16 +843,16 @@ dumpRoles(PGconn *conn) * Notes: rolconfig is dumped later, and pg_authid must be used for * extracting rolcomment regardless of role_catalog. */ - printfPQExpBuffer(buf, - "SELECT oid, rolname, rolsuper, rolinherit, " - "rolcreaterole, rolcreatedb, " - "rolcanlogin, rolconnlimit, rolpassword, " - "rolvaliduntil, rolreplication, rolbypassrls, " - "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " - "rolname = current_user AS is_current_user " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 2", role_catalog); + printfPQExpBuffer(buf, + "SELECT oid, rolname, rolsuper, rolinherit, " + "rolcreaterole, rolcreatedb, " + "rolcanlogin, rolconnlimit, rolpassword, " + "rolvaliduntil, rolreplication, rolbypassrls, " + "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " + "rolname = current_user AS is_current_user " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 2", role_catalog); res = executeQuery(conn, buf->data); diff --git a/src/bin/pg_upgrade/check.c b/src/bin/pg_upgrade/check.c index 786c1474829..f725f5ee3e2 100644 --- a/src/bin/pg_upgrade/check.c +++ b/src/bin/pg_upgrade/check.c @@ -1475,15 +1475,15 @@ check_for_incompatible_polymorphics(ClusterInfo *cluster) ", 'array_cat(anyarray,anyarray)'" ", 'array_prepend(anyelement,anyarray)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_remove(anyarray,anyelement)'" - ", 'array_replace(anyarray,anyelement,anyelement)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_remove(anyarray,anyelement)'" + ", 'array_replace(anyarray,anyelement,anyelement)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_position(anyarray,anyelement)'" - ", 'array_position(anyarray,anyelement,integer)'" - ", 'array_positions(anyarray,anyelement)'" - ", 'width_bucket(anyelement,anyarray)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_position(anyarray,anyelement)'" + ", 'array_position(anyarray,anyelement,integer)'" + ", 'array_positions(anyarray,anyelement)'" + ", 'width_bucket(anyelement,anyarray)'"); /* * The query below hardcodes FirstNormalObjectId as 16384 rather than diff --git a/src/bin/pg_upgrade/controldata.c b/src/bin/pg_upgrade/controldata.c index 8f81c9e9582..02ea02df60f 100644 --- a/src/bin/pg_upgrade/controldata.c +++ b/src/bin/pg_upgrade/controldata.c @@ -228,7 +228,7 @@ get_control_data(ClusterInfo *cluster) p++; /* remove ':' char */ cluster->controldata.chkpnt_nxtepoch = str2uint(p); - p = strchr(p, ':'); + p = strchr(p, ':'); if (p == NULL || strlen(p) <= 1) pg_fatal("%d: controldata retrieval problem", __LINE__); diff --git a/src/bin/pg_upgrade/exec.c b/src/bin/pg_upgrade/exec.c index 44355feea30..a1bdbf373e3 100644 --- a/src/bin/pg_upgrade/exec.c +++ b/src/bin/pg_upgrade/exec.c @@ -55,7 +55,7 @@ get_bin_version(ClusterInfo *cluster) if (sscanf(cmd_output, "%*s %*s %d.%d", &v1, &v2) < 1) pg_fatal("could not get pg_ctl version output from %s", cmd); - cluster->bin_version = v1 * 10000; + cluster->bin_version = v1 * 10000; } @@ -344,8 +344,8 @@ check_data_dir(ClusterInfo *cluster) check_single_dir(pg_data, "pg_subtrans"); check_single_dir(pg_data, PG_TBLSPC_DIR); check_single_dir(pg_data, "pg_twophase"); - check_single_dir(pg_data, "pg_wal"); - check_single_dir(pg_data, "pg_xact"); + check_single_dir(pg_data, "pg_wal"); + check_single_dir(pg_data, "pg_xact"); } @@ -385,7 +385,7 @@ check_bin_dir(ClusterInfo *cluster, bool check_versions) */ get_bin_version(cluster); - check_exec(cluster->bindir, "pg_resetwal", check_versions); + check_exec(cluster->bindir, "pg_resetwal", check_versions); if (cluster == &new_cluster) { diff --git a/src/bin/pg_upgrade/multixact_rewrite.c b/src/bin/pg_upgrade/multixact_rewrite.c index c45b3183684..c7a1416494d 100644 --- a/src/bin/pg_upgrade/multixact_rewrite.c +++ b/src/bin/pg_upgrade/multixact_rewrite.c @@ -61,52 +61,52 @@ rewrite_multixacts(MultiXactId from_multi, MultiXactId to_multi) * Convert old multixids, if needed, by reading them one-by-one from the * old cluster. */ - old_reader = AllocOldMultiXactRead(old_cluster.pgdata, - old_cluster.controldata.chkpnt_nxtmulti, - old_cluster.controldata.chkpnt_nxtmxoff); + old_reader = AllocOldMultiXactRead(old_cluster.pgdata, + old_cluster.controldata.chkpnt_nxtmulti, + old_cluster.controldata.chkpnt_nxtmxoff); - for (MultiXactId multi = from_multi; multi != to_multi;) - { - MultiXactMember member; - bool multixid_valid; - - /* - * Read this multixid's members. - * - * Locking-only XIDs that may be part of multi-xids don't matter - * after upgrade, as there can be no transactions running across - * upgrade. So as a small optimization, we only read one member - * from each multixid: the one updating one, or if there was no - * update, arbitrarily the first locking xid. - */ - multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); + for (MultiXactId multi = from_multi; multi != to_multi;) + { + MultiXactMember member; + bool multixid_valid; - /* - * Write the new offset to pg_multixact/offsets. - * - * Even if this multixid is invalid, we still need to write its - * offset if the *previous* multixid was valid. That's because - * when reading a multixid, the number of members is calculated - * from the difference between the two offsets. - */ - RecordMultiXactOffset(offsets_writer, multi, - (multixid_valid || prev_multixid_valid) ? next_offset : 0); + /* + * Read this multixid's members. + * + * Locking-only XIDs that may be part of multi-xids don't matter after + * upgrade, as there can be no transactions running across upgrade. So + * as a small optimization, we only read one member from each + * multixid: the one updating one, or if there was no update, + * arbitrarily the first locking xid. + */ + multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); - /* Write the members */ - if (multixid_valid) - { - RecordMultiXactMembers(members_writer, next_offset, 1, &member); - next_offset += 1; - } + /* + * Write the new offset to pg_multixact/offsets. + * + * Even if this multixid is invalid, we still need to write its offset + * if the *previous* multixid was valid. That's because when reading + * a multixid, the number of members is calculated from the difference + * between the two offsets. + */ + RecordMultiXactOffset(offsets_writer, multi, + (multixid_valid || prev_multixid_valid) ? next_offset : 0); - /* Advance to next multixid, handling wraparound */ - multi++; - if (multi < FirstMultiXactId) - multi = FirstMultiXactId; - prev_multixid_valid = multixid_valid; + /* Write the members */ + if (multixid_valid) + { + RecordMultiXactMembers(members_writer, next_offset, 1, &member); + next_offset += 1; } - FreeOldMultiXactReader(old_reader); + /* Advance to next multixid, handling wraparound */ + multi++; + if (multi < FirstMultiXactId) + multi = FirstMultiXactId; + prev_multixid_valid = multixid_valid; + } + + FreeOldMultiXactReader(old_reader); /* Write the final 'next' offset to the last SLRU page */ RecordMultiXactOffset(offsets_writer, to_multi, diff --git a/src/bin/pg_upgrade/pg_upgrade.c b/src/bin/pg_upgrade/pg_upgrade.c index c6af9035665..7366fd4627c 100644 --- a/src/bin/pg_upgrade/pg_upgrade.c +++ b/src/bin/pg_upgrade/pg_upgrade.c @@ -833,7 +833,7 @@ copy_xact_xlog_xid(void) * Determine the range of multixacts to convert. */ nxtmulti = old_cluster.controldata.chkpnt_nxtmulti; - oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; + oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; /* handle wraparound */ if (nxtmulti < FirstMultiXactId) nxtmulti = FirstMultiXactId; @@ -898,15 +898,15 @@ set_frozenxids(void) int i_datname; int i_datallowconn; - prep_status("Setting frozenxid and minmxid counters in new cluster"); + prep_status("Setting frozenxid and minmxid counters in new cluster"); conn_template1 = connectToServer(&new_cluster, "template1"); - /* set pg_database.datfrozenxid */ - PQclear(executeQueryOrDie(conn_template1, - "UPDATE pg_catalog.pg_database " - "SET datfrozenxid = '%u'", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_database.datfrozenxid */ + PQclear(executeQueryOrDie(conn_template1, + "UPDATE pg_catalog.pg_database " + "SET datfrozenxid = '%u'", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_database.datminmxid */ PQclear(executeQueryOrDie(conn_template1, @@ -942,16 +942,16 @@ set_frozenxids(void) conn = connectToServer(&new_cluster, datname); - /* set pg_class.relfrozenxid */ - PQclear(executeQueryOrDie(conn, - "UPDATE pg_catalog.pg_class " - "SET relfrozenxid = '%u' " - /* only heap, materialized view, and TOAST are vacuumed */ - "WHERE relkind IN (" - CppAsString2(RELKIND_RELATION) ", " - CppAsString2(RELKIND_MATVIEW) ", " - CppAsString2(RELKIND_TOASTVALUE) ")", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_class.relfrozenxid */ + PQclear(executeQueryOrDie(conn, + "UPDATE pg_catalog.pg_class " + "SET relfrozenxid = '%u' " + /* only heap, materialized view, and TOAST are vacuumed */ + "WHERE relkind IN (" + CppAsString2(RELKIND_RELATION) ", " + CppAsString2(RELKIND_MATVIEW) ", " + CppAsString2(RELKIND_TOASTVALUE) ")", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_class.relminmxid */ PQclear(executeQueryOrDie(conn, diff --git a/src/bin/pg_upgrade/relfilenumber.c b/src/bin/pg_upgrade/relfilenumber.c index ec2ff7acb21..6c467bdc8a5 100644 --- a/src/bin/pg_upgrade/relfilenumber.c +++ b/src/bin/pg_upgrade/relfilenumber.c @@ -587,32 +587,32 @@ transfer_relfile(FileNameMap *map, const char *type_suffix) /* Copying files might take some time, so give feedback. */ pg_log(PG_STATUS, "%s", old_file); - switch (user_opts.transfer_mode) - { - case TRANSFER_MODE_CLONE: - pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", - old_file, new_file); - cloneFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", - old_file, new_file); - copyFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY_FILE_RANGE: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", - old_file, new_file); - copyFileByRange(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_LINK: - pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", - old_file, new_file); - linkFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_SWAP: - /* swap mode is handled in its own code path */ - pg_fatal("should never happen"); - break; - } + switch (user_opts.transfer_mode) + { + case TRANSFER_MODE_CLONE: + pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", + old_file, new_file); + cloneFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", + old_file, new_file); + copyFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY_FILE_RANGE: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", + old_file, new_file); + copyFileByRange(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_LINK: + pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", + old_file, new_file); + linkFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_SWAP: + /* swap mode is handled in its own code path */ + pg_fatal("should never happen"); + break; + } } } diff --git a/src/bin/pg_upgrade/t/006_transfer_modes.pl b/src/bin/pg_upgrade/t/006_transfer_modes.pl index 9efa5dc863c..360d05c4b68 100644 --- a/src/bin/pg_upgrade/t/006_transfer_modes.pl +++ b/src/bin/pg_upgrade/t/006_transfer_modes.pl @@ -29,10 +29,8 @@ sub test_mode } $new->init(); - $new->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); - $old->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); + $new->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); + $old->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); # We can only test security labels if both the old and new installations # have dummy_seclabel. @@ -76,15 +74,14 @@ sub test_mode "CREATE TABLE test4 AS SELECT generate_series(400, 502)"); } - $old->safe_psql('postgres', - "CREATE TABLESPACE inplc_tblspc LOCATION ''"); - $old->safe_psql('postgres', - "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); - $old->safe_psql('postgres', - "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" - ); - $old->safe_psql('testdb3', - "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); + $old->safe_psql('postgres', "CREATE TABLESPACE inplc_tblspc LOCATION ''"); + $old->safe_psql('postgres', + "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); + $old->safe_psql('postgres', + "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" + ); + $old->safe_psql('testdb3', + "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); # While we are here, test handling of large objects. $old->safe_psql( @@ -152,12 +149,10 @@ sub test_mode } # Tests for in-place tablespaces. - $result = - $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); - is($result, '104', "test5 data after pg_upgrade $mode"); - $result = - $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); - is($result, '105', "test6 data after pg_upgrade $mode"); + $result = $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); + is($result, '104', "test5 data after pg_upgrade $mode"); + $result = $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); + is($result, '105', "test6 data after pg_upgrade $mode"); # Tests for large objects $result = $new->safe_psql('postgres', "SELECT lo_get(4532)"); diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index 44ef11d980e..c90bf8bbde2 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -6278,23 +6278,22 @@ get_create_object_cmd(EditableObjectType obj_type, Oid oid, * ensure the right view gets replaced. Also, check relation kind * to be sure it's a view. * - * Views may have WITH [LOCAL|CASCADED] - * CHECK OPTION. These are not part of the view definition - * returned by pg_get_viewdef() and so need to be retrieved - * separately. Materialized views may have - * arbitrary storage parameter reloptions. + * Views may have WITH [LOCAL|CASCADED] CHECK OPTION. These are + * not part of the view definition returned by pg_get_viewdef() + * and so need to be retrieved separately. Materialized views may + * have arbitrary storage parameter reloptions. */ printfPQExpBuffer(query, "/* %s */\n", _("Get view's definition and details")); - appendPQExpBuffer(query, - "SELECT nspname, relname, relkind, " - "pg_catalog.pg_get_viewdef(c.oid, true), " - "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " - "FROM pg_catalog.pg_class c " - "LEFT JOIN pg_catalog.pg_namespace n " - "ON c.relnamespace = n.oid WHERE c.oid = %u", - oid); + appendPQExpBuffer(query, + "SELECT nspname, relname, relkind, " + "pg_catalog.pg_get_viewdef(c.oid, true), " + "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " + "FROM pg_catalog.pg_class c " + "LEFT JOIN pg_catalog.pg_namespace n " + "ON c.relnamespace = n.oid WHERE c.oid = %u", + oid); break; } diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index ce99137c613..ac0c55e7aa5 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -387,19 +387,19 @@ describeFunctions(const char *functypes, const char *func_pattern, gettext_noop("stable"), gettext_noop("volatile"), gettext_noop("Volatility")); - appendPQExpBuffer(&buf, - ",\n CASE\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" - " END as \"%s\"", - gettext_noop("restricted"), - gettext_noop("safe"), - gettext_noop("unsafe"), - gettext_noop("Parallel")); + appendPQExpBuffer(&buf, + ",\n CASE\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" + " END as \"%s\"", + gettext_noop("restricted"), + gettext_noop("safe"), + gettext_noop("unsafe"), + gettext_noop("Parallel")); appendPQExpBuffer(&buf, ",\n pg_catalog.pg_get_userbyid(p.proowner) as \"%s\"" ",\n CASE WHEN prosecdef THEN '%s' ELSE '%s' END AS \"%s\"" @@ -599,8 +599,8 @@ describeFunctions(const char *functypes, const char *func_pattern, myopt.title = _("List of functions"); myopt.translate_header = true; - myopt.translate_columns = translate_columns; - myopt.n_translate_columns = lengthof(translate_columns); + myopt.translate_columns = translate_columns; + myopt.n_translate_columns = lengthof(translate_columns); printQuery(res, &myopt, pset.queryFout, false, pset.logfile); @@ -1086,38 +1086,38 @@ permissionsList(const char *pattern, bool showSystem) " ), E'\\n') AS \"%s\"", gettext_noop("Column privileges")); - appendPQExpBuffer(&buf, - ",\n pg_catalog.array_to_string(ARRAY(\n" - " SELECT polname\n" - " || CASE WHEN NOT polpermissive THEN\n" - " E' (RESTRICTIVE)'\n" - " ELSE '' END\n" - " || CASE WHEN polcmd != '*' THEN\n" - " E' (' || polcmd::pg_catalog.text || E'):'\n" - " ELSE E':'\n" - " END\n" - " || CASE WHEN polqual IS NOT NULL THEN\n" - " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" - " ELSE E''\n" - " END\n" - " || CASE WHEN polwithcheck IS NOT NULL THEN\n" - " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" - " ELSE E''\n" - " END" - " || CASE WHEN polroles <> '{0}' THEN\n" - " E'\\n to: ' || pg_catalog.array_to_string(\n" - " ARRAY(\n" - " SELECT rolname\n" - " FROM pg_catalog.pg_roles\n" - " WHERE oid = ANY (polroles)\n" - " ORDER BY 1\n" - " ), E', ')\n" - " ELSE E''\n" - " END\n" - " FROM pg_catalog.pg_policy pol\n" - " WHERE polrelid = c.oid), E'\\n')\n" - " AS \"%s\"", - gettext_noop("Policies")); + appendPQExpBuffer(&buf, + ",\n pg_catalog.array_to_string(ARRAY(\n" + " SELECT polname\n" + " || CASE WHEN NOT polpermissive THEN\n" + " E' (RESTRICTIVE)'\n" + " ELSE '' END\n" + " || CASE WHEN polcmd != '*' THEN\n" + " E' (' || polcmd::pg_catalog.text || E'):'\n" + " ELSE E':'\n" + " END\n" + " || CASE WHEN polqual IS NOT NULL THEN\n" + " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" + " ELSE E''\n" + " END\n" + " || CASE WHEN polwithcheck IS NOT NULL THEN\n" + " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" + " ELSE E''\n" + " END" + " || CASE WHEN polroles <> '{0}' THEN\n" + " E'\\n to: ' || pg_catalog.array_to_string(\n" + " ARRAY(\n" + " SELECT rolname\n" + " FROM pg_catalog.pg_roles\n" + " WHERE oid = ANY (polroles)\n" + " ORDER BY 1\n" + " ), E', ')\n" + " ELSE E''\n" + " END\n" + " FROM pg_catalog.pg_policy pol\n" + " WHERE polrelid = c.oid), E'\\n')\n" + " AS \"%s\"", + gettext_noop("Policies")); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_class c\n" " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n" @@ -1675,27 +1675,27 @@ describeOneTableDetails(const char *schemaname, char *footers[3] = {NULL, NULL, NULL}; printfPQExpBuffer(&buf, "/* %s */\n", _("Get sequence information")); - appendPQExpBuffer(&buf, - "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" - " seqstart AS \"%s\",\n" - " seqmin AS \"%s\",\n" - " seqmax AS \"%s\",\n" - " seqincrement AS \"%s\",\n" - " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" - " seqcache AS \"%s\"\n", - gettext_noop("Type"), - gettext_noop("Start"), - gettext_noop("Minimum"), - gettext_noop("Maximum"), - gettext_noop("Increment"), - gettext_noop("yes"), - gettext_noop("no"), - gettext_noop("Cycles?"), - gettext_noop("Cache")); - appendPQExpBuffer(&buf, - "FROM pg_catalog.pg_sequence\n" - "WHERE seqrelid = '%s';", - oid); + appendPQExpBuffer(&buf, + "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" + " seqstart AS \"%s\",\n" + " seqmin AS \"%s\",\n" + " seqmax AS \"%s\",\n" + " seqincrement AS \"%s\",\n" + " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" + " seqcache AS \"%s\"\n", + gettext_noop("Type"), + gettext_noop("Start"), + gettext_noop("Minimum"), + gettext_noop("Maximum"), + gettext_noop("Increment"), + gettext_noop("yes"), + gettext_noop("no"), + gettext_noop("Cycles?"), + gettext_noop("Cache")); + appendPQExpBuffer(&buf, + "FROM pg_catalog.pg_sequence\n" + "WHERE seqrelid = '%s';", + oid); res = PSQLexec(buf.data); if (!res) @@ -1913,7 +1913,7 @@ describeOneTableDetails(const char *schemaname, appendPQExpBufferStr(&buf, ",\n (SELECT c.collname FROM pg_catalog.pg_collation c, pg_catalog.pg_type t\n" " WHERE c.oid = a.attcollation AND t.oid = a.atttypid AND a.attcollation <> t.typcollation) AS attcollation"); attcoll_col = cols++; - appendPQExpBufferStr(&buf, ",\n a.attidentity"); + appendPQExpBufferStr(&buf, ",\n a.attidentity"); attidentity_col = cols++; if (pset.sversion >= 120000) appendPQExpBufferStr(&buf, ",\n a.attgenerated"); @@ -2326,7 +2326,7 @@ describeOneTableDetails(const char *schemaname, CppAsString2(CONSTRAINT_EXCLUSION) ") AND " "condeferred) AS condeferred,\n"); - appendPQExpBufferStr(&buf, "i.indisreplident,\n"); + appendPQExpBufferStr(&buf, "i.indisreplident,\n"); if (pset.sversion >= 150000) appendPQExpBufferStr(&buf, "i.indnullsnotdistinct,\n"); @@ -2431,7 +2431,7 @@ describeOneTableDetails(const char *schemaname, "pg_catalog.pg_get_indexdef(i.indexrelid, 0, true),\n " "pg_catalog.pg_get_constraintdef(con.oid, true), " "contype, condeferrable, condeferred"); - appendPQExpBufferStr(&buf, ", i.indisreplident"); + appendPQExpBufferStr(&buf, ", i.indisreplident"); appendPQExpBufferStr(&buf, ", c2.reltablespace"); if (pset.sversion >= 180000) appendPQExpBufferStr(&buf, ", con.conperiod"); @@ -2682,81 +2682,80 @@ describeOneTableDetails(const char *schemaname, PQclear(result); /* print any row-level policies */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get row-level policies for this table")); - appendPQExpBufferStr(&buf, "SELECT pol.polname,"); - appendPQExpBufferStr(&buf, - " pol.polpermissive,\n"); - appendPQExpBuffer(&buf, - " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" - " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" - " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" - " CASE pol.polcmd\n" - " WHEN 'r' THEN 'SELECT'\n" - " WHEN 'a' THEN 'INSERT'\n" - " WHEN 'w' THEN 'UPDATE'\n" - " WHEN 'd' THEN 'DELETE'\n" - " END AS cmd\n" - "FROM pg_catalog.pg_policy pol\n" - "WHERE pol.polrelid = '%s' ORDER BY 1;", - oid); + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get row-level policies for this table")); + appendPQExpBufferStr(&buf, "SELECT pol.polname,"); + appendPQExpBufferStr(&buf, + " pol.polpermissive,\n"); + appendPQExpBuffer(&buf, + " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" + " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" + " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" + " CASE pol.polcmd\n" + " WHEN 'r' THEN 'SELECT'\n" + " WHEN 'a' THEN 'INSERT'\n" + " WHEN 'w' THEN 'UPDATE'\n" + " WHEN 'd' THEN 'DELETE'\n" + " END AS cmd\n" + "FROM pg_catalog.pg_policy pol\n" + "WHERE pol.polrelid = '%s' ORDER BY 1;", + oid); - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - /* - * Handle cases where RLS is enabled and there are policies, or - * there aren't policies, or RLS isn't enabled but there are - * policies - */ - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies:")); + /* + * Handle cases where RLS is enabled and there are policies, or there + * aren't policies, or RLS isn't enabled but there are policies + */ + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies:")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled):")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled):")); - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); - if (!tableinfo.rowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (row security disabled):")); + if (!tableinfo.rowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (row security disabled):")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " POLICY \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " POLICY \"%s\"", + PQgetvalue(result, i, 0)); - if (*(PQgetvalue(result, i, 1)) == 'f') - appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); + if (*(PQgetvalue(result, i, 1)) == 'f') + appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); - if (!PQgetisnull(result, i, 5)) - appendPQExpBuffer(&buf, " FOR %s", - PQgetvalue(result, i, 5)); + if (!PQgetisnull(result, i, 5)) + appendPQExpBuffer(&buf, " FOR %s", + PQgetvalue(result, i, 5)); - if (!PQgetisnull(result, i, 2)) - { - appendPQExpBuffer(&buf, "\n TO %s", - PQgetvalue(result, i, 2)); - } + if (!PQgetisnull(result, i, 2)) + { + appendPQExpBuffer(&buf, "\n TO %s", + PQgetvalue(result, i, 2)); + } - if (!PQgetisnull(result, i, 3)) - appendPQExpBuffer(&buf, "\n USING (%s)", - PQgetvalue(result, i, 3)); + if (!PQgetisnull(result, i, 3)) + appendPQExpBuffer(&buf, "\n USING (%s)", + PQgetvalue(result, i, 3)); - if (!PQgetisnull(result, i, 4)) - appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", - PQgetvalue(result, i, 4)); + if (!PQgetisnull(result, i, 4)) + appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", + PQgetvalue(result, i, 4)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* print any extended statistics */ if (pset.sversion >= 140000) @@ -3025,115 +3024,115 @@ describeOneTableDetails(const char *schemaname, } /* print any publications */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get publications that publish this table")); - if (pset.sversion >= 150000) + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get publications that publish this table")); + if (pset.sversion >= 150000) + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" + " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" + "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" + "UNION\n" + "SELECT pubname\n" + " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" + " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" + " (SELECT pg_catalog.string_agg(attname, ', ')\n" + " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" + " pg_catalog.pg_attribute\n" + " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" + " ELSE NULL END) " + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" + "WHERE pr.prrelid = '%s'\n", + oid, oid, oid); + + if (pset.sversion >= 190000) { + /* + * Skip entries where this relation appears in the + * publication's EXCEPT list. + */ appendPQExpBuffer(&buf, + " AND NOT pr.prexcept\n" + "UNION\n" "SELECT pubname\n" " , NULL\n" " , NULL\n" "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" - " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" - "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" - "UNION\n" - "SELECT pubname\n" - " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" - " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" - " (SELECT pg_catalog.string_agg(attname, ', ')\n" - " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" - " pg_catalog.pg_attribute\n" - " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" - " ELSE NULL END) " - "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" - "WHERE pr.prrelid = '%s'\n", + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + " AND NOT EXISTS (\n" + " SELECT 1\n" + " FROM pg_catalog.pg_publication_rel pr\n" + " WHERE pr.prpubid = p.oid AND\n" + " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" + "ORDER BY 1;", oid, oid, oid); - - if (pset.sversion >= 190000) - { - /* - * Skip entries where this relation appears in the - * publication's EXCEPT list. - */ - appendPQExpBuffer(&buf, - " AND NOT pr.prexcept\n" - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - " AND NOT EXISTS (\n" - " SELECT 1\n" - " FROM pg_catalog.pg_publication_rel pr\n" - " WHERE pr.prpubid = p.oid AND\n" - " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" - "ORDER BY 1;", - oid, oid, oid); - } - else - { - appendPQExpBuffer(&buf, - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - "ORDER BY 1;", - oid); - } } else { appendPQExpBuffer(&buf, + "UNION\n" "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - "WHERE pr.prrelid = '%s'\n" - "UNION ALL\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" + " , NULL\n" + " , NULL\n" "FROM pg_catalog.pg_publication p\n" "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" "ORDER BY 1;", - oid, oid); + oid); } + } + else + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + "WHERE pr.prrelid = '%s'\n" + "UNION ALL\n" + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + "ORDER BY 1;", + oid, oid); + } - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - if (tuples > 0) - printTableAddFooter(&cont, _("Included in publications:")); + if (tuples > 0) + printTableAddFooter(&cont, _("Included in publications:")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " \"%s\"", + PQgetvalue(result, i, 0)); - /* column list (if any) */ - if (!PQgetisnull(result, i, 2)) - appendPQExpBuffer(&buf, " (%s)", - PQgetvalue(result, i, 2)); + /* column list (if any) */ + if (!PQgetisnull(result, i, 2)) + appendPQExpBuffer(&buf, " (%s)", + PQgetvalue(result, i, 2)); - /* row filter (if any) */ - if (!PQgetisnull(result, i, 1)) - appendPQExpBuffer(&buf, " WHERE %s", - PQgetvalue(result, i, 1)); + /* row filter (if any) */ + if (!PQgetisnull(result, i, 1)) + appendPQExpBuffer(&buf, " WHERE %s", + PQgetvalue(result, i, 1)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* Print publications where the table is in the EXCEPT clause */ if (pset.sversion >= 190000) @@ -3805,7 +3804,7 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) ncols++; } appendPQExpBufferStr(&buf, "\n, r.rolreplication"); - appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); + appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_roles r\n"); @@ -3860,8 +3859,8 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) if (strcmp(PQgetvalue(res, i, (verbose ? 9 : 8)), "t") == 0) add_role_attribute(&buf, _("Replication")); - if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) - add_role_attribute(&buf, _("Bypass RLS")); + if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) + add_role_attribute(&buf, _("Bypass RLS")); conns = atoi(PQgetvalue(res, i, 6)); if (conns >= 0) @@ -5155,14 +5154,14 @@ listCollations(const char *pattern, bool verbose, bool showSystem) gettext_noop("Schema"), gettext_noop("Name")); - appendPQExpBuffer(&buf, - " CASE c.collprovider " - "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " - "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " - "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " - "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " - "END AS \"%s\",\n", - gettext_noop("Provider")); + appendPQExpBuffer(&buf, + " CASE c.collprovider " + "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " + "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " + "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " + "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " + "END AS \"%s\",\n", + gettext_noop("Provider")); appendPQExpBuffer(&buf, " c.collcollate AS \"%s\",\n" -- 2.50.1 (Apple Git-155) --aHl3HfeiUuO3zeNC-- ^ permalink raw reply [nested|flat] 59+ messages in thread
* [PATCH v6 4/4] run pgindent and pgperltidy @ 2026-06-30 18:24 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 59+ messages in thread From: Nathan Bossart @ 2026-06-30 18:24 UTC (permalink / raw) --- src/bin/pg_dump/pg_dump.c | 464 ++++++++++----------- src/bin/pg_dump/pg_dumpall.c | 30 +- src/bin/pg_upgrade/check.c | 16 +- src/bin/pg_upgrade/controldata.c | 2 +- src/bin/pg_upgrade/exec.c | 8 +- src/bin/pg_upgrade/multixact_rewrite.c | 80 ++-- src/bin/pg_upgrade/pg_upgrade.c | 34 +- src/bin/pg_upgrade/relfilenumber.c | 54 +-- src/bin/pg_upgrade/t/006_transfer_modes.pl | 33 +- src/bin/psql/command.c | 29 +- src/bin/psql/describe.c | 461 ++++++++++---------- 11 files changed, 601 insertions(+), 610 deletions(-) diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 65bd15ebfd2..5673268b467 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -1491,8 +1491,8 @@ setup_connection(Archive *AH, const char *dumpencoding, * Disable timeouts if supported. */ ExecuteSqlStatement(AH, "SET statement_timeout = 0"); - ExecuteSqlStatement(AH, "SET lock_timeout = 0"); - ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); + ExecuteSqlStatement(AH, "SET lock_timeout = 0"); + ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); if (AH->remoteVersion >= 170000) ExecuteSqlStatement(AH, "SET transaction_timeout = 0"); @@ -1505,10 +1505,10 @@ setup_connection(Archive *AH, const char *dumpencoding, /* * Adjust row-security mode, if supported. */ - if (dopt->enable_row_security) - ExecuteSqlStatement(AH, "SET row_security = on"); - else - ExecuteSqlStatement(AH, "SET row_security = off"); + if (dopt->enable_row_security) + ExecuteSqlStatement(AH, "SET row_security = on"); + else + ExecuteSqlStatement(AH, "SET row_security = off"); /* * For security reasons, we restrict the expansion of non-system views and @@ -1933,10 +1933,9 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) addObjectDependency(dobj, ext->dobj.dumpId); /* - * Mark the member object to have any non-initial ACLs - * dumped. (Any initial ACLs will be removed later, using data from - * pg_init_privs, so that we'll dump only the delta from the extension's - * initial setup.) + * Mark the member object to have any non-initial ACLs dumped. (Any + * initial ACLs will be removed later, using data from pg_init_privs, so + * that we'll dump only the delta from the extension's initial setup.) * * In binary upgrades, we still dump all components of the members * individually, since the idea is to exactly reproduce the database @@ -1953,7 +1952,7 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) if (fout->dopt->binary_upgrade) dobj->dump = ext->dobj.dump; else - dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); + dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); return true; } @@ -1987,9 +1986,9 @@ selectDumpableNamespace(NamespaceInfo *nsinfo, Archive *fout) else if (strcmp(nsinfo->dobj.name, "pg_catalog") == 0) { /* - * We dump out any ACLs defined in pg_catalog, if - * they are interesting (and not the original ACLs which were set at - * initdb time, see pg_init_privs). + * We dump out any ACLs defined in pg_catalog, if they are interesting + * (and not the original ACLs which were set at initdb time, see + * pg_init_privs). */ nsinfo->dobj.dump_contains = nsinfo->dobj.dump = DUMP_COMPONENT_ACL; } @@ -3296,7 +3295,7 @@ dumpDatabase(Archive *fout) "datcollate, datctype, datfrozenxid, " "datacl, acldefault('d', datdba) AS acldefault, " "datistemplate, datconnlimit, "); - appendPQExpBufferStr(dbQry, "datminmxid, "); + appendPQExpBufferStr(dbQry, "datminmxid, "); if (fout->remoteVersion >= 170000) appendPQExpBufferStr(dbQry, "datlocprovider, datlocale, datcollversion, "); else if (fout->remoteVersion >= 150000) @@ -3638,11 +3637,11 @@ dumpDatabase(Archive *fout) ii_oid, ii_relminmxid; - appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" - "FROM pg_catalog.pg_class\n" - "WHERE oid IN (%u, %u, %u, %u);\n", - LargeObjectRelationId, LargeObjectLOidPNIndexId, - LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); + appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" + "FROM pg_catalog.pg_class\n" + "WHERE oid IN (%u, %u, %u, %u);\n", + LargeObjectRelationId, LargeObjectLOidPNIndexId, + LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); lo_res = ExecuteSqlQuery(fout, loFrozenQry->data, PGRES_TUPLES_OK); @@ -4274,7 +4273,7 @@ getPolicies(Archive *fout, TableInfo tblinfo[], int numTables) printfPQExpBuffer(query, "SELECT pol.oid, pol.tableoid, pol.polrelid, pol.polname, pol.polcmd, "); - appendPQExpBufferStr(query, "pol.polpermissive, "); + appendPQExpBufferStr(query, "pol.polpermissive, "); appendPQExpBuffer(query, "CASE WHEN pol.polroles = '{0}' THEN NULL ELSE " " pg_catalog.array_to_string(ARRAY(SELECT pg_catalog.quote_ident(rolname) from pg_catalog.pg_roles WHERE oid = ANY(pol.polroles)), ', ') END AS polroles, " @@ -6633,9 +6632,9 @@ getAccessMethods(Archive *fout) * Select all access methods from pg_am table. */ appendPQExpBufferStr(query, "SELECT tableoid, oid, amname, "); - appendPQExpBufferStr(query, - "amtype, " - "amhandler::pg_catalog.regproc AS amhandler "); + appendPQExpBufferStr(query, + "amtype, " + "amhandler::pg_catalog.regproc AS amhandler "); appendPQExpBufferStr(query, "FROM pg_am"); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6827,35 +6826,35 @@ getAggregates(Archive *fout) * Find all interesting aggregates. See comment in getFuncs() for the * rationale behind the filtering logic. */ - agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" - : "p.proisagg"); + agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" + : "p.proisagg"); - appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " - "p.proname AS aggname, " - "p.pronamespace AS aggnamespace, " - "p.pronargs, p.proargtypes, " - "p.proowner, " - "p.proacl AS aggacl, " - "acldefault('f', p.proowner) AS acldefault " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s AND (" - "p.pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog') OR " - "p.proacl IS DISTINCT FROM pip.initprivs", - agg_check); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - " OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); - appendPQExpBufferChar(query, ')'); + appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " + "p.proname AS aggname, " + "p.pronamespace AS aggnamespace, " + "p.pronargs, p.proargtypes, " + "p.proowner, " + "p.proacl AS aggacl, " + "acldefault('f', p.proowner) AS acldefault " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s AND (" + "p.pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog') OR " + "p.proacl IS DISTINCT FROM pip.initprivs", + agg_check); + if (dopt->binary_upgrade) + appendPQExpBufferStr(query, + " OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6957,53 +6956,53 @@ getFuncs(Archive *fout) * include them, since we want to dump extension members individually in * that mode. Also, if they are used by casts or transforms then we need * to gather the information about them, though they won't be dumped if - * they are built-in. Also, include functions in - * pg_catalog if they have an ACL different from what's shown in - * pg_init_privs (so we have to join to pg_init_privs; annoying). + * they are built-in. Also, include functions in pg_catalog if they have + * an ACL different from what's shown in pg_init_privs (so we have to join + * to pg_init_privs; annoying). */ - not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" - : "NOT p.proisagg"); + not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" + : "NOT p.proisagg"); - appendPQExpBuffer(query, - "SELECT p.tableoid, p.oid, p.proname, p.prolang, " - "p.pronargs, p.proargtypes, p.prorettype, " - "p.proacl, " - "acldefault('f', p.proowner) AS acldefault, " - "p.pronamespace, " - "p.proowner " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s" - "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " - "WHERE classid = 'pg_proc'::regclass AND " - "objid = p.oid AND deptype = 'i')" - "\n AND (" - "\n pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog')" - "\n OR EXISTS (SELECT 1 FROM pg_cast" - "\n WHERE pg_cast.oid > %u " - "\n AND p.oid = pg_cast.castfunc)" - "\n OR EXISTS (SELECT 1 FROM pg_transform" - "\n WHERE pg_transform.oid > %u AND " - "\n (p.oid = pg_transform.trffromsql" - "\n OR p.oid = pg_transform.trftosql))", - not_agg_check, - g_last_builtin_oid, - g_last_builtin_oid); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); + appendPQExpBuffer(query, + "SELECT p.tableoid, p.oid, p.proname, p.prolang, " + "p.pronargs, p.proargtypes, p.prorettype, " + "p.proacl, " + "acldefault('f', p.proowner) AS acldefault, " + "p.pronamespace, " + "p.proowner " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s" + "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " + "WHERE classid = 'pg_proc'::regclass AND " + "objid = p.oid AND deptype = 'i')" + "\n AND (" + "\n pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog')" + "\n OR EXISTS (SELECT 1 FROM pg_cast" + "\n WHERE pg_cast.oid > %u " + "\n AND p.oid = pg_cast.castfunc)" + "\n OR EXISTS (SELECT 1 FROM pg_transform" + "\n WHERE pg_transform.oid > %u AND " + "\n (p.oid = pg_transform.trffromsql" + "\n OR p.oid = pg_transform.trftosql))", + not_agg_check, + g_last_builtin_oid, + g_last_builtin_oid); + if (dopt->binary_upgrade) appendPQExpBufferStr(query, - "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); - appendPQExpBufferChar(query, ')'); + "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferStr(query, + "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -7252,31 +7251,31 @@ getTables(Archive *fout, int *numTables) appendPQExpBufferStr(query, "c.relhasoids, "); - appendPQExpBufferStr(query, - "c.relispopulated, "); + appendPQExpBufferStr(query, + "c.relispopulated, "); - appendPQExpBufferStr(query, - "c.relreplident, "); + appendPQExpBufferStr(query, + "c.relreplident, "); - appendPQExpBufferStr(query, - "c.relrowsecurity, c.relforcerowsecurity, "); + appendPQExpBufferStr(query, + "c.relrowsecurity, c.relforcerowsecurity, "); - appendPQExpBufferStr(query, - "c.relminmxid, tc.relminmxid AS tminmxid, "); + appendPQExpBufferStr(query, + "c.relminmxid, tc.relminmxid AS tminmxid, "); - appendPQExpBufferStr(query, - "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); + appendPQExpBufferStr(query, + "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); - appendPQExpBufferStr(query, - "am.amname, "); + appendPQExpBufferStr(query, + "am.amname, "); - appendPQExpBufferStr(query, - "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); + appendPQExpBufferStr(query, + "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); - appendPQExpBufferStr(query, - "c.relispartition AS ispartition "); + appendPQExpBufferStr(query, + "c.relispartition AS ispartition "); /* * Left join to pg_depend to pick up dependency info linking sequences to @@ -7296,8 +7295,8 @@ getTables(Archive *fout, int *numTables) /* * Left join to pg_am to pick up the amname. */ - appendPQExpBufferStr(query, - "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); + appendPQExpBufferStr(query, + "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); /* * We purposefully ignore toast OIDs for partitioned tables; the reason is @@ -7868,8 +7867,8 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables) "t.reloptions AS indreloptions, "); - appendPQExpBufferStr(query, - "i.indisreplident, "); + appendPQExpBufferStr(query, + "i.indisreplident, "); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -9313,8 +9312,8 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables) appendPQExpBufferStr(q, "'' AS attcompression,\n"); - appendPQExpBufferStr(q, - "a.attidentity,\n"); + appendPQExpBufferStr(q, + "a.attidentity,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(q, @@ -10717,73 +10716,73 @@ getAdditionalACLs(Archive *fout) PQclear(res); /* Fetch initial-privileges data */ - printfPQExpBuffer(query, - "SELECT objoid, classoid, objsubid, privtype, initprivs " - "FROM pg_init_privs"); + printfPQExpBuffer(query, + "SELECT objoid, classoid, objsubid, privtype, initprivs " + "FROM pg_init_privs"); - res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); + res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); - ntups = PQntuples(res); - for (i = 0; i < ntups; i++) - { - Oid objoid = atooid(PQgetvalue(res, i, 0)); - Oid classoid = atooid(PQgetvalue(res, i, 1)); - int objsubid = atoi(PQgetvalue(res, i, 2)); - char privtype = *(PQgetvalue(res, i, 3)); - char *initprivs = PQgetvalue(res, i, 4); - CatalogId objId; - DumpableObject *dobj; + ntups = PQntuples(res); + for (i = 0; i < ntups; i++) + { + Oid objoid = atooid(PQgetvalue(res, i, 0)); + Oid classoid = atooid(PQgetvalue(res, i, 1)); + int objsubid = atoi(PQgetvalue(res, i, 2)); + char privtype = *(PQgetvalue(res, i, 3)); + char *initprivs = PQgetvalue(res, i, 4); + CatalogId objId; + DumpableObject *dobj; - objId.tableoid = classoid; - objId.oid = objoid; - dobj = findObjectByCatalogId(objId); - /* OK to ignore entries we haven't got a DumpableObject for */ - if (dobj) + objId.tableoid = classoid; + objId.oid = objoid; + dobj = findObjectByCatalogId(objId); + /* OK to ignore entries we haven't got a DumpableObject for */ + if (dobj) + { + /* Cope with sub-object initprivs */ + if (objsubid != 0) { - /* Cope with sub-object initprivs */ - if (objsubid != 0) - { - if (dobj->objType == DO_TABLE) - { - /* For a column initprivs, set the table's ACL flags */ - dobj->components |= DUMP_COMPONENT_ACL; - ((TableInfo *) dobj)->hascolumnACLs = true; - } - else - pg_log_warning("unsupported pg_init_privs entry: %u %u %d", - classoid, objoid, objsubid); - continue; - } - - /* - * We ignore any pg_init_privs.initprivs entry for the public - * schema, as explained in getNamespaces(). - */ - if (dobj->objType == DO_NAMESPACE && - strcmp(dobj->name, "public") == 0) - continue; - - /* Else it had better be of a type we think has ACLs */ - if (dobj->objType == DO_NAMESPACE || - dobj->objType == DO_TYPE || - dobj->objType == DO_FUNC || - dobj->objType == DO_AGG || - dobj->objType == DO_TABLE || - dobj->objType == DO_PROCLANG || - dobj->objType == DO_FDW || - dobj->objType == DO_FOREIGN_SERVER) + if (dobj->objType == DO_TABLE) { - DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; - - daobj->dacl.privtype = privtype; - daobj->dacl.initprivs = pstrdup(initprivs); + /* For a column initprivs, set the table's ACL flags */ + dobj->components |= DUMP_COMPONENT_ACL; + ((TableInfo *) dobj)->hascolumnACLs = true; } else pg_log_warning("unsupported pg_init_privs entry: %u %u %d", classoid, objoid, objsubid); + continue; + } + + /* + * We ignore any pg_init_privs.initprivs entry for the public + * schema, as explained in getNamespaces(). + */ + if (dobj->objType == DO_NAMESPACE && + strcmp(dobj->name, "public") == 0) + continue; + + /* Else it had better be of a type we think has ACLs */ + if (dobj->objType == DO_NAMESPACE || + dobj->objType == DO_TYPE || + dobj->objType == DO_FUNC || + dobj->objType == DO_AGG || + dobj->objType == DO_TABLE || + dobj->objType == DO_PROCLANG || + dobj->objType == DO_FDW || + dobj->objType == DO_FOREIGN_SERVER) + { + DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; + + daobj->dacl.privtype = privtype; + daobj->dacl.initprivs = pstrdup(initprivs); } + else + pg_log_warning("unsupported pg_init_privs entry: %u %u %d", + classoid, objoid, objsubid); } - PQclear(res); + } + PQclear(res); destroyPQExpBuffer(query); } @@ -11128,8 +11127,8 @@ dumpRelationStats_dumper(Archive *fout, const void *userArg, const TocEntry *te) * The results must be in the order of the relations supplied in the * parameters to ensure we remain in sync as we walk through the TOC. * - * For versions before 19, the redundant filter clause on s.tablename = - * ANY(...) seems sufficient to convince the planner to use + * For versions before 19, the redundant filter clause on s.tablename + * = ANY(...) seems sufficient to convince the planner to use * pg_class_relname_nsp_index, which avoids a full scan of pg_stats. * In newer versions, pg_stats returns the table OIDs, eliminating the * need for that hack. @@ -13469,11 +13468,11 @@ dumpFunc(Archive *fout, const FuncInfo *finfo) "pg_catalog.pg_get_function_result(p.oid) AS funcresult,\n" "proleakproof,\n"); - appendPQExpBufferStr(query, - "array_to_string(protrftypes, ' ') AS protrftypes,\n"); + appendPQExpBufferStr(query, + "array_to_string(protrftypes, ' ') AS protrftypes,\n"); - appendPQExpBufferStr(query, - "proparallel,\n"); + appendPQExpBufferStr(query, + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -14963,9 +14962,9 @@ dumpCollation(Archive *fout, const CollInfo *collinfo) /* Get collation-specific details */ appendPQExpBufferStr(query, "SELECT "); - appendPQExpBufferStr(query, - "collprovider, " - "collversion, "); + appendPQExpBufferStr(query, + "collprovider, " + "collversion, "); if (fout->remoteVersion >= 120000) appendPQExpBufferStr(query, @@ -15372,23 +15371,23 @@ dumpAgg(Archive *fout, const AggInfo *agginfo) "pg_catalog.pg_get_function_arguments(p.oid) AS funcargs,\n" "pg_catalog.pg_get_function_identity_arguments(p.oid) AS funciargs,\n"); - appendPQExpBufferStr(query, - "aggkind,\n" - "aggmtransfn,\n" - "aggminvtransfn,\n" - "aggmfinalfn,\n" - "aggmtranstype::pg_catalog.regtype,\n" - "aggfinalextra,\n" - "aggmfinalextra,\n" - "aggtransspace,\n" - "aggmtransspace,\n" - "aggminitval,\n"); + appendPQExpBufferStr(query, + "aggkind,\n" + "aggmtransfn,\n" + "aggminvtransfn,\n" + "aggmfinalfn,\n" + "aggmtranstype::pg_catalog.regtype,\n" + "aggfinalextra,\n" + "aggmfinalextra,\n" + "aggtransspace,\n" + "aggmtransspace,\n" + "aggminitval,\n"); - appendPQExpBufferStr(query, - "aggcombinefn,\n" - "aggserialfn,\n" - "aggdeserialfn,\n" - "proparallel,\n"); + appendPQExpBufferStr(query, + "aggcombinefn,\n" + "aggserialfn,\n" + "aggdeserialfn,\n" + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -16848,30 +16847,30 @@ dumpTable(Archive *fout, const TableInfo *tbinfo) appendPQExpBufferStr(query, "PREPARE getColumnACLs(pg_catalog.oid) AS\n"); - /* - * In principle we should call acldefault('c', relowner) to - * get the default ACL for a column. However, we don't - * currently store the numeric OID of the relowner in - * TableInfo. We could convert the owner name using regrole, - * but that creates a risk of failure due to concurrent role - * renames. Given that the default ACL for columns is empty - * and is likely to stay that way, it's not worth extra cycles - * and risk to avoid hard-wiring that knowledge here. - */ - appendPQExpBufferStr(query, - "SELECT at.attname, " - "at.attacl, " - "'{}' AS acldefault, " - "pip.privtype, pip.initprivs " - "FROM pg_catalog.pg_attribute at " - "LEFT JOIN pg_catalog.pg_init_privs pip ON " - "(at.attrelid = pip.objoid " - "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " - "AND at.attnum = pip.objsubid) " - "WHERE at.attrelid = $1 AND " - "NOT at.attisdropped " - "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " - "ORDER BY at.attnum"); + /* + * In principle we should call acldefault('c', relowner) to get + * the default ACL for a column. However, we don't currently + * store the numeric OID of the relowner in TableInfo. We could + * convert the owner name using regrole, but that creates a risk + * of failure due to concurrent role renames. Given that the + * default ACL for columns is empty and is likely to stay that + * way, it's not worth extra cycles and risk to avoid hard-wiring + * that knowledge here. + */ + appendPQExpBufferStr(query, + "SELECT at.attname, " + "at.attacl, " + "'{}' AS acldefault, " + "pip.privtype, pip.initprivs " + "FROM pg_catalog.pg_attribute at " + "LEFT JOIN pg_catalog.pg_init_privs pip ON " + "(at.attrelid = pip.objoid " + "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " + "AND at.attnum = pip.objsubid) " + "WHERE at.attrelid = $1 AND " + "NOT at.attisdropped " + "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " + "ORDER BY at.attnum"); ExecuteSqlStatement(fout, query->data); @@ -19165,7 +19164,7 @@ collectSequences(Archive *fout) * pg_get_sequence_data(), but we only do so for non-schema-only dumps. */ if (fout->remoteVersion < 180000 || - (!fout->dopt->dumpData && !fout->dopt->sequence_data)) + (!fout->dopt->dumpData && !fout->dopt->sequence_data)) query = "SELECT seqrelid, format_type(seqtypid, NULL), " "seqstart, seqincrement, " "seqmax, seqmin, " @@ -19227,15 +19226,14 @@ dumpSequence(Archive *fout, const TableInfo *tbinfo) qseqname = pg_strdup(fmtId(tbinfo->dobj.name)); /* - * The sequence information is gathered in a sorted - * table before any calls to dumpSequence(). See collectSequences() for - * more information. + * The sequence information is gathered in a sorted table before any calls + * to dumpSequence(). See collectSequences() for more information. */ - Assert(sequences); + Assert(sequences); - key.oid = tbinfo->dobj.catId.oid; - seq = bsearch(&key, sequences, nsequences, - sizeof(SequenceItem), SequenceItemCmp); + key.oid = tbinfo->dobj.catId.oid; + seq = bsearch(&key, sequences, nsequences, + sizeof(SequenceItem), SequenceItemCmp); /* Calculate default limits for a sequence of this type */ is_ascending = (seq->incby >= 0); diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c index e68937c9934..afcd9a218d8 100644 --- a/src/bin/pg_dump/pg_dumpall.c +++ b/src/bin/pg_dump/pg_dumpall.c @@ -785,11 +785,11 @@ dropRoles(PGconn *conn) int i_rolname; int i; - printfPQExpBuffer(buf, - "SELECT rolname " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 1", role_catalog); + printfPQExpBuffer(buf, + "SELECT rolname " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 1", role_catalog); res = executeQuery(conn, buf->data); @@ -843,16 +843,16 @@ dumpRoles(PGconn *conn) * Notes: rolconfig is dumped later, and pg_authid must be used for * extracting rolcomment regardless of role_catalog. */ - printfPQExpBuffer(buf, - "SELECT oid, rolname, rolsuper, rolinherit, " - "rolcreaterole, rolcreatedb, " - "rolcanlogin, rolconnlimit, rolpassword, " - "rolvaliduntil, rolreplication, rolbypassrls, " - "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " - "rolname = current_user AS is_current_user " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 2", role_catalog); + printfPQExpBuffer(buf, + "SELECT oid, rolname, rolsuper, rolinherit, " + "rolcreaterole, rolcreatedb, " + "rolcanlogin, rolconnlimit, rolpassword, " + "rolvaliduntil, rolreplication, rolbypassrls, " + "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " + "rolname = current_user AS is_current_user " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 2", role_catalog); res = executeQuery(conn, buf->data); diff --git a/src/bin/pg_upgrade/check.c b/src/bin/pg_upgrade/check.c index 786c1474829..f725f5ee3e2 100644 --- a/src/bin/pg_upgrade/check.c +++ b/src/bin/pg_upgrade/check.c @@ -1475,15 +1475,15 @@ check_for_incompatible_polymorphics(ClusterInfo *cluster) ", 'array_cat(anyarray,anyarray)'" ", 'array_prepend(anyelement,anyarray)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_remove(anyarray,anyelement)'" - ", 'array_replace(anyarray,anyelement,anyelement)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_remove(anyarray,anyelement)'" + ", 'array_replace(anyarray,anyelement,anyelement)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_position(anyarray,anyelement)'" - ", 'array_position(anyarray,anyelement,integer)'" - ", 'array_positions(anyarray,anyelement)'" - ", 'width_bucket(anyelement,anyarray)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_position(anyarray,anyelement)'" + ", 'array_position(anyarray,anyelement,integer)'" + ", 'array_positions(anyarray,anyelement)'" + ", 'width_bucket(anyelement,anyarray)'"); /* * The query below hardcodes FirstNormalObjectId as 16384 rather than diff --git a/src/bin/pg_upgrade/controldata.c b/src/bin/pg_upgrade/controldata.c index 8f81c9e9582..02ea02df60f 100644 --- a/src/bin/pg_upgrade/controldata.c +++ b/src/bin/pg_upgrade/controldata.c @@ -228,7 +228,7 @@ get_control_data(ClusterInfo *cluster) p++; /* remove ':' char */ cluster->controldata.chkpnt_nxtepoch = str2uint(p); - p = strchr(p, ':'); + p = strchr(p, ':'); if (p == NULL || strlen(p) <= 1) pg_fatal("%d: controldata retrieval problem", __LINE__); diff --git a/src/bin/pg_upgrade/exec.c b/src/bin/pg_upgrade/exec.c index 44355feea30..a1bdbf373e3 100644 --- a/src/bin/pg_upgrade/exec.c +++ b/src/bin/pg_upgrade/exec.c @@ -55,7 +55,7 @@ get_bin_version(ClusterInfo *cluster) if (sscanf(cmd_output, "%*s %*s %d.%d", &v1, &v2) < 1) pg_fatal("could not get pg_ctl version output from %s", cmd); - cluster->bin_version = v1 * 10000; + cluster->bin_version = v1 * 10000; } @@ -344,8 +344,8 @@ check_data_dir(ClusterInfo *cluster) check_single_dir(pg_data, "pg_subtrans"); check_single_dir(pg_data, PG_TBLSPC_DIR); check_single_dir(pg_data, "pg_twophase"); - check_single_dir(pg_data, "pg_wal"); - check_single_dir(pg_data, "pg_xact"); + check_single_dir(pg_data, "pg_wal"); + check_single_dir(pg_data, "pg_xact"); } @@ -385,7 +385,7 @@ check_bin_dir(ClusterInfo *cluster, bool check_versions) */ get_bin_version(cluster); - check_exec(cluster->bindir, "pg_resetwal", check_versions); + check_exec(cluster->bindir, "pg_resetwal", check_versions); if (cluster == &new_cluster) { diff --git a/src/bin/pg_upgrade/multixact_rewrite.c b/src/bin/pg_upgrade/multixact_rewrite.c index c45b3183684..c7a1416494d 100644 --- a/src/bin/pg_upgrade/multixact_rewrite.c +++ b/src/bin/pg_upgrade/multixact_rewrite.c @@ -61,52 +61,52 @@ rewrite_multixacts(MultiXactId from_multi, MultiXactId to_multi) * Convert old multixids, if needed, by reading them one-by-one from the * old cluster. */ - old_reader = AllocOldMultiXactRead(old_cluster.pgdata, - old_cluster.controldata.chkpnt_nxtmulti, - old_cluster.controldata.chkpnt_nxtmxoff); + old_reader = AllocOldMultiXactRead(old_cluster.pgdata, + old_cluster.controldata.chkpnt_nxtmulti, + old_cluster.controldata.chkpnt_nxtmxoff); - for (MultiXactId multi = from_multi; multi != to_multi;) - { - MultiXactMember member; - bool multixid_valid; - - /* - * Read this multixid's members. - * - * Locking-only XIDs that may be part of multi-xids don't matter - * after upgrade, as there can be no transactions running across - * upgrade. So as a small optimization, we only read one member - * from each multixid: the one updating one, or if there was no - * update, arbitrarily the first locking xid. - */ - multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); + for (MultiXactId multi = from_multi; multi != to_multi;) + { + MultiXactMember member; + bool multixid_valid; - /* - * Write the new offset to pg_multixact/offsets. - * - * Even if this multixid is invalid, we still need to write its - * offset if the *previous* multixid was valid. That's because - * when reading a multixid, the number of members is calculated - * from the difference between the two offsets. - */ - RecordMultiXactOffset(offsets_writer, multi, - (multixid_valid || prev_multixid_valid) ? next_offset : 0); + /* + * Read this multixid's members. + * + * Locking-only XIDs that may be part of multi-xids don't matter after + * upgrade, as there can be no transactions running across upgrade. So + * as a small optimization, we only read one member from each + * multixid: the one updating one, or if there was no update, + * arbitrarily the first locking xid. + */ + multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); - /* Write the members */ - if (multixid_valid) - { - RecordMultiXactMembers(members_writer, next_offset, 1, &member); - next_offset += 1; - } + /* + * Write the new offset to pg_multixact/offsets. + * + * Even if this multixid is invalid, we still need to write its offset + * if the *previous* multixid was valid. That's because when reading + * a multixid, the number of members is calculated from the difference + * between the two offsets. + */ + RecordMultiXactOffset(offsets_writer, multi, + (multixid_valid || prev_multixid_valid) ? next_offset : 0); - /* Advance to next multixid, handling wraparound */ - multi++; - if (multi < FirstMultiXactId) - multi = FirstMultiXactId; - prev_multixid_valid = multixid_valid; + /* Write the members */ + if (multixid_valid) + { + RecordMultiXactMembers(members_writer, next_offset, 1, &member); + next_offset += 1; } - FreeOldMultiXactReader(old_reader); + /* Advance to next multixid, handling wraparound */ + multi++; + if (multi < FirstMultiXactId) + multi = FirstMultiXactId; + prev_multixid_valid = multixid_valid; + } + + FreeOldMultiXactReader(old_reader); /* Write the final 'next' offset to the last SLRU page */ RecordMultiXactOffset(offsets_writer, to_multi, diff --git a/src/bin/pg_upgrade/pg_upgrade.c b/src/bin/pg_upgrade/pg_upgrade.c index c6af9035665..7366fd4627c 100644 --- a/src/bin/pg_upgrade/pg_upgrade.c +++ b/src/bin/pg_upgrade/pg_upgrade.c @@ -833,7 +833,7 @@ copy_xact_xlog_xid(void) * Determine the range of multixacts to convert. */ nxtmulti = old_cluster.controldata.chkpnt_nxtmulti; - oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; + oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; /* handle wraparound */ if (nxtmulti < FirstMultiXactId) nxtmulti = FirstMultiXactId; @@ -898,15 +898,15 @@ set_frozenxids(void) int i_datname; int i_datallowconn; - prep_status("Setting frozenxid and minmxid counters in new cluster"); + prep_status("Setting frozenxid and minmxid counters in new cluster"); conn_template1 = connectToServer(&new_cluster, "template1"); - /* set pg_database.datfrozenxid */ - PQclear(executeQueryOrDie(conn_template1, - "UPDATE pg_catalog.pg_database " - "SET datfrozenxid = '%u'", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_database.datfrozenxid */ + PQclear(executeQueryOrDie(conn_template1, + "UPDATE pg_catalog.pg_database " + "SET datfrozenxid = '%u'", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_database.datminmxid */ PQclear(executeQueryOrDie(conn_template1, @@ -942,16 +942,16 @@ set_frozenxids(void) conn = connectToServer(&new_cluster, datname); - /* set pg_class.relfrozenxid */ - PQclear(executeQueryOrDie(conn, - "UPDATE pg_catalog.pg_class " - "SET relfrozenxid = '%u' " - /* only heap, materialized view, and TOAST are vacuumed */ - "WHERE relkind IN (" - CppAsString2(RELKIND_RELATION) ", " - CppAsString2(RELKIND_MATVIEW) ", " - CppAsString2(RELKIND_TOASTVALUE) ")", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_class.relfrozenxid */ + PQclear(executeQueryOrDie(conn, + "UPDATE pg_catalog.pg_class " + "SET relfrozenxid = '%u' " + /* only heap, materialized view, and TOAST are vacuumed */ + "WHERE relkind IN (" + CppAsString2(RELKIND_RELATION) ", " + CppAsString2(RELKIND_MATVIEW) ", " + CppAsString2(RELKIND_TOASTVALUE) ")", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_class.relminmxid */ PQclear(executeQueryOrDie(conn, diff --git a/src/bin/pg_upgrade/relfilenumber.c b/src/bin/pg_upgrade/relfilenumber.c index ec2ff7acb21..6c467bdc8a5 100644 --- a/src/bin/pg_upgrade/relfilenumber.c +++ b/src/bin/pg_upgrade/relfilenumber.c @@ -587,32 +587,32 @@ transfer_relfile(FileNameMap *map, const char *type_suffix) /* Copying files might take some time, so give feedback. */ pg_log(PG_STATUS, "%s", old_file); - switch (user_opts.transfer_mode) - { - case TRANSFER_MODE_CLONE: - pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", - old_file, new_file); - cloneFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", - old_file, new_file); - copyFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY_FILE_RANGE: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", - old_file, new_file); - copyFileByRange(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_LINK: - pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", - old_file, new_file); - linkFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_SWAP: - /* swap mode is handled in its own code path */ - pg_fatal("should never happen"); - break; - } + switch (user_opts.transfer_mode) + { + case TRANSFER_MODE_CLONE: + pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", + old_file, new_file); + cloneFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", + old_file, new_file); + copyFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY_FILE_RANGE: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", + old_file, new_file); + copyFileByRange(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_LINK: + pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", + old_file, new_file); + linkFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_SWAP: + /* swap mode is handled in its own code path */ + pg_fatal("should never happen"); + break; + } } } diff --git a/src/bin/pg_upgrade/t/006_transfer_modes.pl b/src/bin/pg_upgrade/t/006_transfer_modes.pl index 9efa5dc863c..360d05c4b68 100644 --- a/src/bin/pg_upgrade/t/006_transfer_modes.pl +++ b/src/bin/pg_upgrade/t/006_transfer_modes.pl @@ -29,10 +29,8 @@ sub test_mode } $new->init(); - $new->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); - $old->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); + $new->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); + $old->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); # We can only test security labels if both the old and new installations # have dummy_seclabel. @@ -76,15 +74,14 @@ sub test_mode "CREATE TABLE test4 AS SELECT generate_series(400, 502)"); } - $old->safe_psql('postgres', - "CREATE TABLESPACE inplc_tblspc LOCATION ''"); - $old->safe_psql('postgres', - "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); - $old->safe_psql('postgres', - "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" - ); - $old->safe_psql('testdb3', - "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); + $old->safe_psql('postgres', "CREATE TABLESPACE inplc_tblspc LOCATION ''"); + $old->safe_psql('postgres', + "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); + $old->safe_psql('postgres', + "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" + ); + $old->safe_psql('testdb3', + "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); # While we are here, test handling of large objects. $old->safe_psql( @@ -152,12 +149,10 @@ sub test_mode } # Tests for in-place tablespaces. - $result = - $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); - is($result, '104', "test5 data after pg_upgrade $mode"); - $result = - $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); - is($result, '105', "test6 data after pg_upgrade $mode"); + $result = $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); + is($result, '104', "test5 data after pg_upgrade $mode"); + $result = $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); + is($result, '105', "test6 data after pg_upgrade $mode"); # Tests for large objects $result = $new->safe_psql('postgres', "SELECT lo_get(4532)"); diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index 44ef11d980e..c90bf8bbde2 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -6278,23 +6278,22 @@ get_create_object_cmd(EditableObjectType obj_type, Oid oid, * ensure the right view gets replaced. Also, check relation kind * to be sure it's a view. * - * Views may have WITH [LOCAL|CASCADED] - * CHECK OPTION. These are not part of the view definition - * returned by pg_get_viewdef() and so need to be retrieved - * separately. Materialized views may have - * arbitrary storage parameter reloptions. + * Views may have WITH [LOCAL|CASCADED] CHECK OPTION. These are + * not part of the view definition returned by pg_get_viewdef() + * and so need to be retrieved separately. Materialized views may + * have arbitrary storage parameter reloptions. */ printfPQExpBuffer(query, "/* %s */\n", _("Get view's definition and details")); - appendPQExpBuffer(query, - "SELECT nspname, relname, relkind, " - "pg_catalog.pg_get_viewdef(c.oid, true), " - "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " - "FROM pg_catalog.pg_class c " - "LEFT JOIN pg_catalog.pg_namespace n " - "ON c.relnamespace = n.oid WHERE c.oid = %u", - oid); + appendPQExpBuffer(query, + "SELECT nspname, relname, relkind, " + "pg_catalog.pg_get_viewdef(c.oid, true), " + "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " + "FROM pg_catalog.pg_class c " + "LEFT JOIN pg_catalog.pg_namespace n " + "ON c.relnamespace = n.oid WHERE c.oid = %u", + oid); break; } diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index ce99137c613..ac0c55e7aa5 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -387,19 +387,19 @@ describeFunctions(const char *functypes, const char *func_pattern, gettext_noop("stable"), gettext_noop("volatile"), gettext_noop("Volatility")); - appendPQExpBuffer(&buf, - ",\n CASE\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" - " END as \"%s\"", - gettext_noop("restricted"), - gettext_noop("safe"), - gettext_noop("unsafe"), - gettext_noop("Parallel")); + appendPQExpBuffer(&buf, + ",\n CASE\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" + " END as \"%s\"", + gettext_noop("restricted"), + gettext_noop("safe"), + gettext_noop("unsafe"), + gettext_noop("Parallel")); appendPQExpBuffer(&buf, ",\n pg_catalog.pg_get_userbyid(p.proowner) as \"%s\"" ",\n CASE WHEN prosecdef THEN '%s' ELSE '%s' END AS \"%s\"" @@ -599,8 +599,8 @@ describeFunctions(const char *functypes, const char *func_pattern, myopt.title = _("List of functions"); myopt.translate_header = true; - myopt.translate_columns = translate_columns; - myopt.n_translate_columns = lengthof(translate_columns); + myopt.translate_columns = translate_columns; + myopt.n_translate_columns = lengthof(translate_columns); printQuery(res, &myopt, pset.queryFout, false, pset.logfile); @@ -1086,38 +1086,38 @@ permissionsList(const char *pattern, bool showSystem) " ), E'\\n') AS \"%s\"", gettext_noop("Column privileges")); - appendPQExpBuffer(&buf, - ",\n pg_catalog.array_to_string(ARRAY(\n" - " SELECT polname\n" - " || CASE WHEN NOT polpermissive THEN\n" - " E' (RESTRICTIVE)'\n" - " ELSE '' END\n" - " || CASE WHEN polcmd != '*' THEN\n" - " E' (' || polcmd::pg_catalog.text || E'):'\n" - " ELSE E':'\n" - " END\n" - " || CASE WHEN polqual IS NOT NULL THEN\n" - " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" - " ELSE E''\n" - " END\n" - " || CASE WHEN polwithcheck IS NOT NULL THEN\n" - " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" - " ELSE E''\n" - " END" - " || CASE WHEN polroles <> '{0}' THEN\n" - " E'\\n to: ' || pg_catalog.array_to_string(\n" - " ARRAY(\n" - " SELECT rolname\n" - " FROM pg_catalog.pg_roles\n" - " WHERE oid = ANY (polroles)\n" - " ORDER BY 1\n" - " ), E', ')\n" - " ELSE E''\n" - " END\n" - " FROM pg_catalog.pg_policy pol\n" - " WHERE polrelid = c.oid), E'\\n')\n" - " AS \"%s\"", - gettext_noop("Policies")); + appendPQExpBuffer(&buf, + ",\n pg_catalog.array_to_string(ARRAY(\n" + " SELECT polname\n" + " || CASE WHEN NOT polpermissive THEN\n" + " E' (RESTRICTIVE)'\n" + " ELSE '' END\n" + " || CASE WHEN polcmd != '*' THEN\n" + " E' (' || polcmd::pg_catalog.text || E'):'\n" + " ELSE E':'\n" + " END\n" + " || CASE WHEN polqual IS NOT NULL THEN\n" + " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" + " ELSE E''\n" + " END\n" + " || CASE WHEN polwithcheck IS NOT NULL THEN\n" + " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" + " ELSE E''\n" + " END" + " || CASE WHEN polroles <> '{0}' THEN\n" + " E'\\n to: ' || pg_catalog.array_to_string(\n" + " ARRAY(\n" + " SELECT rolname\n" + " FROM pg_catalog.pg_roles\n" + " WHERE oid = ANY (polroles)\n" + " ORDER BY 1\n" + " ), E', ')\n" + " ELSE E''\n" + " END\n" + " FROM pg_catalog.pg_policy pol\n" + " WHERE polrelid = c.oid), E'\\n')\n" + " AS \"%s\"", + gettext_noop("Policies")); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_class c\n" " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n" @@ -1675,27 +1675,27 @@ describeOneTableDetails(const char *schemaname, char *footers[3] = {NULL, NULL, NULL}; printfPQExpBuffer(&buf, "/* %s */\n", _("Get sequence information")); - appendPQExpBuffer(&buf, - "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" - " seqstart AS \"%s\",\n" - " seqmin AS \"%s\",\n" - " seqmax AS \"%s\",\n" - " seqincrement AS \"%s\",\n" - " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" - " seqcache AS \"%s\"\n", - gettext_noop("Type"), - gettext_noop("Start"), - gettext_noop("Minimum"), - gettext_noop("Maximum"), - gettext_noop("Increment"), - gettext_noop("yes"), - gettext_noop("no"), - gettext_noop("Cycles?"), - gettext_noop("Cache")); - appendPQExpBuffer(&buf, - "FROM pg_catalog.pg_sequence\n" - "WHERE seqrelid = '%s';", - oid); + appendPQExpBuffer(&buf, + "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" + " seqstart AS \"%s\",\n" + " seqmin AS \"%s\",\n" + " seqmax AS \"%s\",\n" + " seqincrement AS \"%s\",\n" + " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" + " seqcache AS \"%s\"\n", + gettext_noop("Type"), + gettext_noop("Start"), + gettext_noop("Minimum"), + gettext_noop("Maximum"), + gettext_noop("Increment"), + gettext_noop("yes"), + gettext_noop("no"), + gettext_noop("Cycles?"), + gettext_noop("Cache")); + appendPQExpBuffer(&buf, + "FROM pg_catalog.pg_sequence\n" + "WHERE seqrelid = '%s';", + oid); res = PSQLexec(buf.data); if (!res) @@ -1913,7 +1913,7 @@ describeOneTableDetails(const char *schemaname, appendPQExpBufferStr(&buf, ",\n (SELECT c.collname FROM pg_catalog.pg_collation c, pg_catalog.pg_type t\n" " WHERE c.oid = a.attcollation AND t.oid = a.atttypid AND a.attcollation <> t.typcollation) AS attcollation"); attcoll_col = cols++; - appendPQExpBufferStr(&buf, ",\n a.attidentity"); + appendPQExpBufferStr(&buf, ",\n a.attidentity"); attidentity_col = cols++; if (pset.sversion >= 120000) appendPQExpBufferStr(&buf, ",\n a.attgenerated"); @@ -2326,7 +2326,7 @@ describeOneTableDetails(const char *schemaname, CppAsString2(CONSTRAINT_EXCLUSION) ") AND " "condeferred) AS condeferred,\n"); - appendPQExpBufferStr(&buf, "i.indisreplident,\n"); + appendPQExpBufferStr(&buf, "i.indisreplident,\n"); if (pset.sversion >= 150000) appendPQExpBufferStr(&buf, "i.indnullsnotdistinct,\n"); @@ -2431,7 +2431,7 @@ describeOneTableDetails(const char *schemaname, "pg_catalog.pg_get_indexdef(i.indexrelid, 0, true),\n " "pg_catalog.pg_get_constraintdef(con.oid, true), " "contype, condeferrable, condeferred"); - appendPQExpBufferStr(&buf, ", i.indisreplident"); + appendPQExpBufferStr(&buf, ", i.indisreplident"); appendPQExpBufferStr(&buf, ", c2.reltablespace"); if (pset.sversion >= 180000) appendPQExpBufferStr(&buf, ", con.conperiod"); @@ -2682,81 +2682,80 @@ describeOneTableDetails(const char *schemaname, PQclear(result); /* print any row-level policies */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get row-level policies for this table")); - appendPQExpBufferStr(&buf, "SELECT pol.polname,"); - appendPQExpBufferStr(&buf, - " pol.polpermissive,\n"); - appendPQExpBuffer(&buf, - " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" - " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" - " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" - " CASE pol.polcmd\n" - " WHEN 'r' THEN 'SELECT'\n" - " WHEN 'a' THEN 'INSERT'\n" - " WHEN 'w' THEN 'UPDATE'\n" - " WHEN 'd' THEN 'DELETE'\n" - " END AS cmd\n" - "FROM pg_catalog.pg_policy pol\n" - "WHERE pol.polrelid = '%s' ORDER BY 1;", - oid); + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get row-level policies for this table")); + appendPQExpBufferStr(&buf, "SELECT pol.polname,"); + appendPQExpBufferStr(&buf, + " pol.polpermissive,\n"); + appendPQExpBuffer(&buf, + " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" + " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" + " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" + " CASE pol.polcmd\n" + " WHEN 'r' THEN 'SELECT'\n" + " WHEN 'a' THEN 'INSERT'\n" + " WHEN 'w' THEN 'UPDATE'\n" + " WHEN 'd' THEN 'DELETE'\n" + " END AS cmd\n" + "FROM pg_catalog.pg_policy pol\n" + "WHERE pol.polrelid = '%s' ORDER BY 1;", + oid); - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - /* - * Handle cases where RLS is enabled and there are policies, or - * there aren't policies, or RLS isn't enabled but there are - * policies - */ - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies:")); + /* + * Handle cases where RLS is enabled and there are policies, or there + * aren't policies, or RLS isn't enabled but there are policies + */ + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies:")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled):")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled):")); - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); - if (!tableinfo.rowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (row security disabled):")); + if (!tableinfo.rowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (row security disabled):")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " POLICY \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " POLICY \"%s\"", + PQgetvalue(result, i, 0)); - if (*(PQgetvalue(result, i, 1)) == 'f') - appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); + if (*(PQgetvalue(result, i, 1)) == 'f') + appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); - if (!PQgetisnull(result, i, 5)) - appendPQExpBuffer(&buf, " FOR %s", - PQgetvalue(result, i, 5)); + if (!PQgetisnull(result, i, 5)) + appendPQExpBuffer(&buf, " FOR %s", + PQgetvalue(result, i, 5)); - if (!PQgetisnull(result, i, 2)) - { - appendPQExpBuffer(&buf, "\n TO %s", - PQgetvalue(result, i, 2)); - } + if (!PQgetisnull(result, i, 2)) + { + appendPQExpBuffer(&buf, "\n TO %s", + PQgetvalue(result, i, 2)); + } - if (!PQgetisnull(result, i, 3)) - appendPQExpBuffer(&buf, "\n USING (%s)", - PQgetvalue(result, i, 3)); + if (!PQgetisnull(result, i, 3)) + appendPQExpBuffer(&buf, "\n USING (%s)", + PQgetvalue(result, i, 3)); - if (!PQgetisnull(result, i, 4)) - appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", - PQgetvalue(result, i, 4)); + if (!PQgetisnull(result, i, 4)) + appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", + PQgetvalue(result, i, 4)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* print any extended statistics */ if (pset.sversion >= 140000) @@ -3025,115 +3024,115 @@ describeOneTableDetails(const char *schemaname, } /* print any publications */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get publications that publish this table")); - if (pset.sversion >= 150000) + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get publications that publish this table")); + if (pset.sversion >= 150000) + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" + " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" + "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" + "UNION\n" + "SELECT pubname\n" + " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" + " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" + " (SELECT pg_catalog.string_agg(attname, ', ')\n" + " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" + " pg_catalog.pg_attribute\n" + " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" + " ELSE NULL END) " + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" + "WHERE pr.prrelid = '%s'\n", + oid, oid, oid); + + if (pset.sversion >= 190000) { + /* + * Skip entries where this relation appears in the + * publication's EXCEPT list. + */ appendPQExpBuffer(&buf, + " AND NOT pr.prexcept\n" + "UNION\n" "SELECT pubname\n" " , NULL\n" " , NULL\n" "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" - " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" - "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" - "UNION\n" - "SELECT pubname\n" - " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" - " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" - " (SELECT pg_catalog.string_agg(attname, ', ')\n" - " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" - " pg_catalog.pg_attribute\n" - " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" - " ELSE NULL END) " - "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" - "WHERE pr.prrelid = '%s'\n", + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + " AND NOT EXISTS (\n" + " SELECT 1\n" + " FROM pg_catalog.pg_publication_rel pr\n" + " WHERE pr.prpubid = p.oid AND\n" + " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" + "ORDER BY 1;", oid, oid, oid); - - if (pset.sversion >= 190000) - { - /* - * Skip entries where this relation appears in the - * publication's EXCEPT list. - */ - appendPQExpBuffer(&buf, - " AND NOT pr.prexcept\n" - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - " AND NOT EXISTS (\n" - " SELECT 1\n" - " FROM pg_catalog.pg_publication_rel pr\n" - " WHERE pr.prpubid = p.oid AND\n" - " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" - "ORDER BY 1;", - oid, oid, oid); - } - else - { - appendPQExpBuffer(&buf, - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - "ORDER BY 1;", - oid); - } } else { appendPQExpBuffer(&buf, + "UNION\n" "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - "WHERE pr.prrelid = '%s'\n" - "UNION ALL\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" + " , NULL\n" + " , NULL\n" "FROM pg_catalog.pg_publication p\n" "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" "ORDER BY 1;", - oid, oid); + oid); } + } + else + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + "WHERE pr.prrelid = '%s'\n" + "UNION ALL\n" + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + "ORDER BY 1;", + oid, oid); + } - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - if (tuples > 0) - printTableAddFooter(&cont, _("Included in publications:")); + if (tuples > 0) + printTableAddFooter(&cont, _("Included in publications:")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " \"%s\"", + PQgetvalue(result, i, 0)); - /* column list (if any) */ - if (!PQgetisnull(result, i, 2)) - appendPQExpBuffer(&buf, " (%s)", - PQgetvalue(result, i, 2)); + /* column list (if any) */ + if (!PQgetisnull(result, i, 2)) + appendPQExpBuffer(&buf, " (%s)", + PQgetvalue(result, i, 2)); - /* row filter (if any) */ - if (!PQgetisnull(result, i, 1)) - appendPQExpBuffer(&buf, " WHERE %s", - PQgetvalue(result, i, 1)); + /* row filter (if any) */ + if (!PQgetisnull(result, i, 1)) + appendPQExpBuffer(&buf, " WHERE %s", + PQgetvalue(result, i, 1)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* Print publications where the table is in the EXCEPT clause */ if (pset.sversion >= 190000) @@ -3805,7 +3804,7 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) ncols++; } appendPQExpBufferStr(&buf, "\n, r.rolreplication"); - appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); + appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_roles r\n"); @@ -3860,8 +3859,8 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) if (strcmp(PQgetvalue(res, i, (verbose ? 9 : 8)), "t") == 0) add_role_attribute(&buf, _("Replication")); - if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) - add_role_attribute(&buf, _("Bypass RLS")); + if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) + add_role_attribute(&buf, _("Bypass RLS")); conns = atoi(PQgetvalue(res, i, 6)); if (conns >= 0) @@ -5155,14 +5154,14 @@ listCollations(const char *pattern, bool verbose, bool showSystem) gettext_noop("Schema"), gettext_noop("Name")); - appendPQExpBuffer(&buf, - " CASE c.collprovider " - "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " - "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " - "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " - "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " - "END AS \"%s\",\n", - gettext_noop("Provider")); + appendPQExpBuffer(&buf, + " CASE c.collprovider " + "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " + "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " + "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " + "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " + "END AS \"%s\",\n", + gettext_noop("Provider")); appendPQExpBuffer(&buf, " c.collcollate AS \"%s\",\n" -- 2.50.1 (Apple Git-155) --aHl3HfeiUuO3zeNC-- ^ permalink raw reply [nested|flat] 59+ messages in thread
* [PATCH v6 4/4] run pgindent and pgperltidy @ 2026-06-30 18:24 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 59+ messages in thread From: Nathan Bossart @ 2026-06-30 18:24 UTC (permalink / raw) --- src/bin/pg_dump/pg_dump.c | 464 ++++++++++----------- src/bin/pg_dump/pg_dumpall.c | 30 +- src/bin/pg_upgrade/check.c | 16 +- src/bin/pg_upgrade/controldata.c | 2 +- src/bin/pg_upgrade/exec.c | 8 +- src/bin/pg_upgrade/multixact_rewrite.c | 80 ++-- src/bin/pg_upgrade/pg_upgrade.c | 34 +- src/bin/pg_upgrade/relfilenumber.c | 54 +-- src/bin/pg_upgrade/t/006_transfer_modes.pl | 33 +- src/bin/psql/command.c | 29 +- src/bin/psql/describe.c | 461 ++++++++++---------- 11 files changed, 601 insertions(+), 610 deletions(-) diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 65bd15ebfd2..5673268b467 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -1491,8 +1491,8 @@ setup_connection(Archive *AH, const char *dumpencoding, * Disable timeouts if supported. */ ExecuteSqlStatement(AH, "SET statement_timeout = 0"); - ExecuteSqlStatement(AH, "SET lock_timeout = 0"); - ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); + ExecuteSqlStatement(AH, "SET lock_timeout = 0"); + ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); if (AH->remoteVersion >= 170000) ExecuteSqlStatement(AH, "SET transaction_timeout = 0"); @@ -1505,10 +1505,10 @@ setup_connection(Archive *AH, const char *dumpencoding, /* * Adjust row-security mode, if supported. */ - if (dopt->enable_row_security) - ExecuteSqlStatement(AH, "SET row_security = on"); - else - ExecuteSqlStatement(AH, "SET row_security = off"); + if (dopt->enable_row_security) + ExecuteSqlStatement(AH, "SET row_security = on"); + else + ExecuteSqlStatement(AH, "SET row_security = off"); /* * For security reasons, we restrict the expansion of non-system views and @@ -1933,10 +1933,9 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) addObjectDependency(dobj, ext->dobj.dumpId); /* - * Mark the member object to have any non-initial ACLs - * dumped. (Any initial ACLs will be removed later, using data from - * pg_init_privs, so that we'll dump only the delta from the extension's - * initial setup.) + * Mark the member object to have any non-initial ACLs dumped. (Any + * initial ACLs will be removed later, using data from pg_init_privs, so + * that we'll dump only the delta from the extension's initial setup.) * * In binary upgrades, we still dump all components of the members * individually, since the idea is to exactly reproduce the database @@ -1953,7 +1952,7 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) if (fout->dopt->binary_upgrade) dobj->dump = ext->dobj.dump; else - dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); + dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); return true; } @@ -1987,9 +1986,9 @@ selectDumpableNamespace(NamespaceInfo *nsinfo, Archive *fout) else if (strcmp(nsinfo->dobj.name, "pg_catalog") == 0) { /* - * We dump out any ACLs defined in pg_catalog, if - * they are interesting (and not the original ACLs which were set at - * initdb time, see pg_init_privs). + * We dump out any ACLs defined in pg_catalog, if they are interesting + * (and not the original ACLs which were set at initdb time, see + * pg_init_privs). */ nsinfo->dobj.dump_contains = nsinfo->dobj.dump = DUMP_COMPONENT_ACL; } @@ -3296,7 +3295,7 @@ dumpDatabase(Archive *fout) "datcollate, datctype, datfrozenxid, " "datacl, acldefault('d', datdba) AS acldefault, " "datistemplate, datconnlimit, "); - appendPQExpBufferStr(dbQry, "datminmxid, "); + appendPQExpBufferStr(dbQry, "datminmxid, "); if (fout->remoteVersion >= 170000) appendPQExpBufferStr(dbQry, "datlocprovider, datlocale, datcollversion, "); else if (fout->remoteVersion >= 150000) @@ -3638,11 +3637,11 @@ dumpDatabase(Archive *fout) ii_oid, ii_relminmxid; - appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" - "FROM pg_catalog.pg_class\n" - "WHERE oid IN (%u, %u, %u, %u);\n", - LargeObjectRelationId, LargeObjectLOidPNIndexId, - LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); + appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" + "FROM pg_catalog.pg_class\n" + "WHERE oid IN (%u, %u, %u, %u);\n", + LargeObjectRelationId, LargeObjectLOidPNIndexId, + LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); lo_res = ExecuteSqlQuery(fout, loFrozenQry->data, PGRES_TUPLES_OK); @@ -4274,7 +4273,7 @@ getPolicies(Archive *fout, TableInfo tblinfo[], int numTables) printfPQExpBuffer(query, "SELECT pol.oid, pol.tableoid, pol.polrelid, pol.polname, pol.polcmd, "); - appendPQExpBufferStr(query, "pol.polpermissive, "); + appendPQExpBufferStr(query, "pol.polpermissive, "); appendPQExpBuffer(query, "CASE WHEN pol.polroles = '{0}' THEN NULL ELSE " " pg_catalog.array_to_string(ARRAY(SELECT pg_catalog.quote_ident(rolname) from pg_catalog.pg_roles WHERE oid = ANY(pol.polroles)), ', ') END AS polroles, " @@ -6633,9 +6632,9 @@ getAccessMethods(Archive *fout) * Select all access methods from pg_am table. */ appendPQExpBufferStr(query, "SELECT tableoid, oid, amname, "); - appendPQExpBufferStr(query, - "amtype, " - "amhandler::pg_catalog.regproc AS amhandler "); + appendPQExpBufferStr(query, + "amtype, " + "amhandler::pg_catalog.regproc AS amhandler "); appendPQExpBufferStr(query, "FROM pg_am"); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6827,35 +6826,35 @@ getAggregates(Archive *fout) * Find all interesting aggregates. See comment in getFuncs() for the * rationale behind the filtering logic. */ - agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" - : "p.proisagg"); + agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" + : "p.proisagg"); - appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " - "p.proname AS aggname, " - "p.pronamespace AS aggnamespace, " - "p.pronargs, p.proargtypes, " - "p.proowner, " - "p.proacl AS aggacl, " - "acldefault('f', p.proowner) AS acldefault " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s AND (" - "p.pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog') OR " - "p.proacl IS DISTINCT FROM pip.initprivs", - agg_check); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - " OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); - appendPQExpBufferChar(query, ')'); + appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " + "p.proname AS aggname, " + "p.pronamespace AS aggnamespace, " + "p.pronargs, p.proargtypes, " + "p.proowner, " + "p.proacl AS aggacl, " + "acldefault('f', p.proowner) AS acldefault " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s AND (" + "p.pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog') OR " + "p.proacl IS DISTINCT FROM pip.initprivs", + agg_check); + if (dopt->binary_upgrade) + appendPQExpBufferStr(query, + " OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6957,53 +6956,53 @@ getFuncs(Archive *fout) * include them, since we want to dump extension members individually in * that mode. Also, if they are used by casts or transforms then we need * to gather the information about them, though they won't be dumped if - * they are built-in. Also, include functions in - * pg_catalog if they have an ACL different from what's shown in - * pg_init_privs (so we have to join to pg_init_privs; annoying). + * they are built-in. Also, include functions in pg_catalog if they have + * an ACL different from what's shown in pg_init_privs (so we have to join + * to pg_init_privs; annoying). */ - not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" - : "NOT p.proisagg"); + not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" + : "NOT p.proisagg"); - appendPQExpBuffer(query, - "SELECT p.tableoid, p.oid, p.proname, p.prolang, " - "p.pronargs, p.proargtypes, p.prorettype, " - "p.proacl, " - "acldefault('f', p.proowner) AS acldefault, " - "p.pronamespace, " - "p.proowner " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s" - "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " - "WHERE classid = 'pg_proc'::regclass AND " - "objid = p.oid AND deptype = 'i')" - "\n AND (" - "\n pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog')" - "\n OR EXISTS (SELECT 1 FROM pg_cast" - "\n WHERE pg_cast.oid > %u " - "\n AND p.oid = pg_cast.castfunc)" - "\n OR EXISTS (SELECT 1 FROM pg_transform" - "\n WHERE pg_transform.oid > %u AND " - "\n (p.oid = pg_transform.trffromsql" - "\n OR p.oid = pg_transform.trftosql))", - not_agg_check, - g_last_builtin_oid, - g_last_builtin_oid); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); + appendPQExpBuffer(query, + "SELECT p.tableoid, p.oid, p.proname, p.prolang, " + "p.pronargs, p.proargtypes, p.prorettype, " + "p.proacl, " + "acldefault('f', p.proowner) AS acldefault, " + "p.pronamespace, " + "p.proowner " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s" + "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " + "WHERE classid = 'pg_proc'::regclass AND " + "objid = p.oid AND deptype = 'i')" + "\n AND (" + "\n pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog')" + "\n OR EXISTS (SELECT 1 FROM pg_cast" + "\n WHERE pg_cast.oid > %u " + "\n AND p.oid = pg_cast.castfunc)" + "\n OR EXISTS (SELECT 1 FROM pg_transform" + "\n WHERE pg_transform.oid > %u AND " + "\n (p.oid = pg_transform.trffromsql" + "\n OR p.oid = pg_transform.trftosql))", + not_agg_check, + g_last_builtin_oid, + g_last_builtin_oid); + if (dopt->binary_upgrade) appendPQExpBufferStr(query, - "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); - appendPQExpBufferChar(query, ')'); + "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferStr(query, + "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -7252,31 +7251,31 @@ getTables(Archive *fout, int *numTables) appendPQExpBufferStr(query, "c.relhasoids, "); - appendPQExpBufferStr(query, - "c.relispopulated, "); + appendPQExpBufferStr(query, + "c.relispopulated, "); - appendPQExpBufferStr(query, - "c.relreplident, "); + appendPQExpBufferStr(query, + "c.relreplident, "); - appendPQExpBufferStr(query, - "c.relrowsecurity, c.relforcerowsecurity, "); + appendPQExpBufferStr(query, + "c.relrowsecurity, c.relforcerowsecurity, "); - appendPQExpBufferStr(query, - "c.relminmxid, tc.relminmxid AS tminmxid, "); + appendPQExpBufferStr(query, + "c.relminmxid, tc.relminmxid AS tminmxid, "); - appendPQExpBufferStr(query, - "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); + appendPQExpBufferStr(query, + "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); - appendPQExpBufferStr(query, - "am.amname, "); + appendPQExpBufferStr(query, + "am.amname, "); - appendPQExpBufferStr(query, - "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); + appendPQExpBufferStr(query, + "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); - appendPQExpBufferStr(query, - "c.relispartition AS ispartition "); + appendPQExpBufferStr(query, + "c.relispartition AS ispartition "); /* * Left join to pg_depend to pick up dependency info linking sequences to @@ -7296,8 +7295,8 @@ getTables(Archive *fout, int *numTables) /* * Left join to pg_am to pick up the amname. */ - appendPQExpBufferStr(query, - "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); + appendPQExpBufferStr(query, + "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); /* * We purposefully ignore toast OIDs for partitioned tables; the reason is @@ -7868,8 +7867,8 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables) "t.reloptions AS indreloptions, "); - appendPQExpBufferStr(query, - "i.indisreplident, "); + appendPQExpBufferStr(query, + "i.indisreplident, "); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -9313,8 +9312,8 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables) appendPQExpBufferStr(q, "'' AS attcompression,\n"); - appendPQExpBufferStr(q, - "a.attidentity,\n"); + appendPQExpBufferStr(q, + "a.attidentity,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(q, @@ -10717,73 +10716,73 @@ getAdditionalACLs(Archive *fout) PQclear(res); /* Fetch initial-privileges data */ - printfPQExpBuffer(query, - "SELECT objoid, classoid, objsubid, privtype, initprivs " - "FROM pg_init_privs"); + printfPQExpBuffer(query, + "SELECT objoid, classoid, objsubid, privtype, initprivs " + "FROM pg_init_privs"); - res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); + res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); - ntups = PQntuples(res); - for (i = 0; i < ntups; i++) - { - Oid objoid = atooid(PQgetvalue(res, i, 0)); - Oid classoid = atooid(PQgetvalue(res, i, 1)); - int objsubid = atoi(PQgetvalue(res, i, 2)); - char privtype = *(PQgetvalue(res, i, 3)); - char *initprivs = PQgetvalue(res, i, 4); - CatalogId objId; - DumpableObject *dobj; + ntups = PQntuples(res); + for (i = 0; i < ntups; i++) + { + Oid objoid = atooid(PQgetvalue(res, i, 0)); + Oid classoid = atooid(PQgetvalue(res, i, 1)); + int objsubid = atoi(PQgetvalue(res, i, 2)); + char privtype = *(PQgetvalue(res, i, 3)); + char *initprivs = PQgetvalue(res, i, 4); + CatalogId objId; + DumpableObject *dobj; - objId.tableoid = classoid; - objId.oid = objoid; - dobj = findObjectByCatalogId(objId); - /* OK to ignore entries we haven't got a DumpableObject for */ - if (dobj) + objId.tableoid = classoid; + objId.oid = objoid; + dobj = findObjectByCatalogId(objId); + /* OK to ignore entries we haven't got a DumpableObject for */ + if (dobj) + { + /* Cope with sub-object initprivs */ + if (objsubid != 0) { - /* Cope with sub-object initprivs */ - if (objsubid != 0) - { - if (dobj->objType == DO_TABLE) - { - /* For a column initprivs, set the table's ACL flags */ - dobj->components |= DUMP_COMPONENT_ACL; - ((TableInfo *) dobj)->hascolumnACLs = true; - } - else - pg_log_warning("unsupported pg_init_privs entry: %u %u %d", - classoid, objoid, objsubid); - continue; - } - - /* - * We ignore any pg_init_privs.initprivs entry for the public - * schema, as explained in getNamespaces(). - */ - if (dobj->objType == DO_NAMESPACE && - strcmp(dobj->name, "public") == 0) - continue; - - /* Else it had better be of a type we think has ACLs */ - if (dobj->objType == DO_NAMESPACE || - dobj->objType == DO_TYPE || - dobj->objType == DO_FUNC || - dobj->objType == DO_AGG || - dobj->objType == DO_TABLE || - dobj->objType == DO_PROCLANG || - dobj->objType == DO_FDW || - dobj->objType == DO_FOREIGN_SERVER) + if (dobj->objType == DO_TABLE) { - DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; - - daobj->dacl.privtype = privtype; - daobj->dacl.initprivs = pstrdup(initprivs); + /* For a column initprivs, set the table's ACL flags */ + dobj->components |= DUMP_COMPONENT_ACL; + ((TableInfo *) dobj)->hascolumnACLs = true; } else pg_log_warning("unsupported pg_init_privs entry: %u %u %d", classoid, objoid, objsubid); + continue; + } + + /* + * We ignore any pg_init_privs.initprivs entry for the public + * schema, as explained in getNamespaces(). + */ + if (dobj->objType == DO_NAMESPACE && + strcmp(dobj->name, "public") == 0) + continue; + + /* Else it had better be of a type we think has ACLs */ + if (dobj->objType == DO_NAMESPACE || + dobj->objType == DO_TYPE || + dobj->objType == DO_FUNC || + dobj->objType == DO_AGG || + dobj->objType == DO_TABLE || + dobj->objType == DO_PROCLANG || + dobj->objType == DO_FDW || + dobj->objType == DO_FOREIGN_SERVER) + { + DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; + + daobj->dacl.privtype = privtype; + daobj->dacl.initprivs = pstrdup(initprivs); } + else + pg_log_warning("unsupported pg_init_privs entry: %u %u %d", + classoid, objoid, objsubid); } - PQclear(res); + } + PQclear(res); destroyPQExpBuffer(query); } @@ -11128,8 +11127,8 @@ dumpRelationStats_dumper(Archive *fout, const void *userArg, const TocEntry *te) * The results must be in the order of the relations supplied in the * parameters to ensure we remain in sync as we walk through the TOC. * - * For versions before 19, the redundant filter clause on s.tablename = - * ANY(...) seems sufficient to convince the planner to use + * For versions before 19, the redundant filter clause on s.tablename + * = ANY(...) seems sufficient to convince the planner to use * pg_class_relname_nsp_index, which avoids a full scan of pg_stats. * In newer versions, pg_stats returns the table OIDs, eliminating the * need for that hack. @@ -13469,11 +13468,11 @@ dumpFunc(Archive *fout, const FuncInfo *finfo) "pg_catalog.pg_get_function_result(p.oid) AS funcresult,\n" "proleakproof,\n"); - appendPQExpBufferStr(query, - "array_to_string(protrftypes, ' ') AS protrftypes,\n"); + appendPQExpBufferStr(query, + "array_to_string(protrftypes, ' ') AS protrftypes,\n"); - appendPQExpBufferStr(query, - "proparallel,\n"); + appendPQExpBufferStr(query, + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -14963,9 +14962,9 @@ dumpCollation(Archive *fout, const CollInfo *collinfo) /* Get collation-specific details */ appendPQExpBufferStr(query, "SELECT "); - appendPQExpBufferStr(query, - "collprovider, " - "collversion, "); + appendPQExpBufferStr(query, + "collprovider, " + "collversion, "); if (fout->remoteVersion >= 120000) appendPQExpBufferStr(query, @@ -15372,23 +15371,23 @@ dumpAgg(Archive *fout, const AggInfo *agginfo) "pg_catalog.pg_get_function_arguments(p.oid) AS funcargs,\n" "pg_catalog.pg_get_function_identity_arguments(p.oid) AS funciargs,\n"); - appendPQExpBufferStr(query, - "aggkind,\n" - "aggmtransfn,\n" - "aggminvtransfn,\n" - "aggmfinalfn,\n" - "aggmtranstype::pg_catalog.regtype,\n" - "aggfinalextra,\n" - "aggmfinalextra,\n" - "aggtransspace,\n" - "aggmtransspace,\n" - "aggminitval,\n"); + appendPQExpBufferStr(query, + "aggkind,\n" + "aggmtransfn,\n" + "aggminvtransfn,\n" + "aggmfinalfn,\n" + "aggmtranstype::pg_catalog.regtype,\n" + "aggfinalextra,\n" + "aggmfinalextra,\n" + "aggtransspace,\n" + "aggmtransspace,\n" + "aggminitval,\n"); - appendPQExpBufferStr(query, - "aggcombinefn,\n" - "aggserialfn,\n" - "aggdeserialfn,\n" - "proparallel,\n"); + appendPQExpBufferStr(query, + "aggcombinefn,\n" + "aggserialfn,\n" + "aggdeserialfn,\n" + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -16848,30 +16847,30 @@ dumpTable(Archive *fout, const TableInfo *tbinfo) appendPQExpBufferStr(query, "PREPARE getColumnACLs(pg_catalog.oid) AS\n"); - /* - * In principle we should call acldefault('c', relowner) to - * get the default ACL for a column. However, we don't - * currently store the numeric OID of the relowner in - * TableInfo. We could convert the owner name using regrole, - * but that creates a risk of failure due to concurrent role - * renames. Given that the default ACL for columns is empty - * and is likely to stay that way, it's not worth extra cycles - * and risk to avoid hard-wiring that knowledge here. - */ - appendPQExpBufferStr(query, - "SELECT at.attname, " - "at.attacl, " - "'{}' AS acldefault, " - "pip.privtype, pip.initprivs " - "FROM pg_catalog.pg_attribute at " - "LEFT JOIN pg_catalog.pg_init_privs pip ON " - "(at.attrelid = pip.objoid " - "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " - "AND at.attnum = pip.objsubid) " - "WHERE at.attrelid = $1 AND " - "NOT at.attisdropped " - "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " - "ORDER BY at.attnum"); + /* + * In principle we should call acldefault('c', relowner) to get + * the default ACL for a column. However, we don't currently + * store the numeric OID of the relowner in TableInfo. We could + * convert the owner name using regrole, but that creates a risk + * of failure due to concurrent role renames. Given that the + * default ACL for columns is empty and is likely to stay that + * way, it's not worth extra cycles and risk to avoid hard-wiring + * that knowledge here. + */ + appendPQExpBufferStr(query, + "SELECT at.attname, " + "at.attacl, " + "'{}' AS acldefault, " + "pip.privtype, pip.initprivs " + "FROM pg_catalog.pg_attribute at " + "LEFT JOIN pg_catalog.pg_init_privs pip ON " + "(at.attrelid = pip.objoid " + "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " + "AND at.attnum = pip.objsubid) " + "WHERE at.attrelid = $1 AND " + "NOT at.attisdropped " + "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " + "ORDER BY at.attnum"); ExecuteSqlStatement(fout, query->data); @@ -19165,7 +19164,7 @@ collectSequences(Archive *fout) * pg_get_sequence_data(), but we only do so for non-schema-only dumps. */ if (fout->remoteVersion < 180000 || - (!fout->dopt->dumpData && !fout->dopt->sequence_data)) + (!fout->dopt->dumpData && !fout->dopt->sequence_data)) query = "SELECT seqrelid, format_type(seqtypid, NULL), " "seqstart, seqincrement, " "seqmax, seqmin, " @@ -19227,15 +19226,14 @@ dumpSequence(Archive *fout, const TableInfo *tbinfo) qseqname = pg_strdup(fmtId(tbinfo->dobj.name)); /* - * The sequence information is gathered in a sorted - * table before any calls to dumpSequence(). See collectSequences() for - * more information. + * The sequence information is gathered in a sorted table before any calls + * to dumpSequence(). See collectSequences() for more information. */ - Assert(sequences); + Assert(sequences); - key.oid = tbinfo->dobj.catId.oid; - seq = bsearch(&key, sequences, nsequences, - sizeof(SequenceItem), SequenceItemCmp); + key.oid = tbinfo->dobj.catId.oid; + seq = bsearch(&key, sequences, nsequences, + sizeof(SequenceItem), SequenceItemCmp); /* Calculate default limits for a sequence of this type */ is_ascending = (seq->incby >= 0); diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c index e68937c9934..afcd9a218d8 100644 --- a/src/bin/pg_dump/pg_dumpall.c +++ b/src/bin/pg_dump/pg_dumpall.c @@ -785,11 +785,11 @@ dropRoles(PGconn *conn) int i_rolname; int i; - printfPQExpBuffer(buf, - "SELECT rolname " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 1", role_catalog); + printfPQExpBuffer(buf, + "SELECT rolname " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 1", role_catalog); res = executeQuery(conn, buf->data); @@ -843,16 +843,16 @@ dumpRoles(PGconn *conn) * Notes: rolconfig is dumped later, and pg_authid must be used for * extracting rolcomment regardless of role_catalog. */ - printfPQExpBuffer(buf, - "SELECT oid, rolname, rolsuper, rolinherit, " - "rolcreaterole, rolcreatedb, " - "rolcanlogin, rolconnlimit, rolpassword, " - "rolvaliduntil, rolreplication, rolbypassrls, " - "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " - "rolname = current_user AS is_current_user " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 2", role_catalog); + printfPQExpBuffer(buf, + "SELECT oid, rolname, rolsuper, rolinherit, " + "rolcreaterole, rolcreatedb, " + "rolcanlogin, rolconnlimit, rolpassword, " + "rolvaliduntil, rolreplication, rolbypassrls, " + "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " + "rolname = current_user AS is_current_user " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 2", role_catalog); res = executeQuery(conn, buf->data); diff --git a/src/bin/pg_upgrade/check.c b/src/bin/pg_upgrade/check.c index 786c1474829..f725f5ee3e2 100644 --- a/src/bin/pg_upgrade/check.c +++ b/src/bin/pg_upgrade/check.c @@ -1475,15 +1475,15 @@ check_for_incompatible_polymorphics(ClusterInfo *cluster) ", 'array_cat(anyarray,anyarray)'" ", 'array_prepend(anyelement,anyarray)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_remove(anyarray,anyelement)'" - ", 'array_replace(anyarray,anyelement,anyelement)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_remove(anyarray,anyelement)'" + ", 'array_replace(anyarray,anyelement,anyelement)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_position(anyarray,anyelement)'" - ", 'array_position(anyarray,anyelement,integer)'" - ", 'array_positions(anyarray,anyelement)'" - ", 'width_bucket(anyelement,anyarray)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_position(anyarray,anyelement)'" + ", 'array_position(anyarray,anyelement,integer)'" + ", 'array_positions(anyarray,anyelement)'" + ", 'width_bucket(anyelement,anyarray)'"); /* * The query below hardcodes FirstNormalObjectId as 16384 rather than diff --git a/src/bin/pg_upgrade/controldata.c b/src/bin/pg_upgrade/controldata.c index 8f81c9e9582..02ea02df60f 100644 --- a/src/bin/pg_upgrade/controldata.c +++ b/src/bin/pg_upgrade/controldata.c @@ -228,7 +228,7 @@ get_control_data(ClusterInfo *cluster) p++; /* remove ':' char */ cluster->controldata.chkpnt_nxtepoch = str2uint(p); - p = strchr(p, ':'); + p = strchr(p, ':'); if (p == NULL || strlen(p) <= 1) pg_fatal("%d: controldata retrieval problem", __LINE__); diff --git a/src/bin/pg_upgrade/exec.c b/src/bin/pg_upgrade/exec.c index 44355feea30..a1bdbf373e3 100644 --- a/src/bin/pg_upgrade/exec.c +++ b/src/bin/pg_upgrade/exec.c @@ -55,7 +55,7 @@ get_bin_version(ClusterInfo *cluster) if (sscanf(cmd_output, "%*s %*s %d.%d", &v1, &v2) < 1) pg_fatal("could not get pg_ctl version output from %s", cmd); - cluster->bin_version = v1 * 10000; + cluster->bin_version = v1 * 10000; } @@ -344,8 +344,8 @@ check_data_dir(ClusterInfo *cluster) check_single_dir(pg_data, "pg_subtrans"); check_single_dir(pg_data, PG_TBLSPC_DIR); check_single_dir(pg_data, "pg_twophase"); - check_single_dir(pg_data, "pg_wal"); - check_single_dir(pg_data, "pg_xact"); + check_single_dir(pg_data, "pg_wal"); + check_single_dir(pg_data, "pg_xact"); } @@ -385,7 +385,7 @@ check_bin_dir(ClusterInfo *cluster, bool check_versions) */ get_bin_version(cluster); - check_exec(cluster->bindir, "pg_resetwal", check_versions); + check_exec(cluster->bindir, "pg_resetwal", check_versions); if (cluster == &new_cluster) { diff --git a/src/bin/pg_upgrade/multixact_rewrite.c b/src/bin/pg_upgrade/multixact_rewrite.c index c45b3183684..c7a1416494d 100644 --- a/src/bin/pg_upgrade/multixact_rewrite.c +++ b/src/bin/pg_upgrade/multixact_rewrite.c @@ -61,52 +61,52 @@ rewrite_multixacts(MultiXactId from_multi, MultiXactId to_multi) * Convert old multixids, if needed, by reading them one-by-one from the * old cluster. */ - old_reader = AllocOldMultiXactRead(old_cluster.pgdata, - old_cluster.controldata.chkpnt_nxtmulti, - old_cluster.controldata.chkpnt_nxtmxoff); + old_reader = AllocOldMultiXactRead(old_cluster.pgdata, + old_cluster.controldata.chkpnt_nxtmulti, + old_cluster.controldata.chkpnt_nxtmxoff); - for (MultiXactId multi = from_multi; multi != to_multi;) - { - MultiXactMember member; - bool multixid_valid; - - /* - * Read this multixid's members. - * - * Locking-only XIDs that may be part of multi-xids don't matter - * after upgrade, as there can be no transactions running across - * upgrade. So as a small optimization, we only read one member - * from each multixid: the one updating one, or if there was no - * update, arbitrarily the first locking xid. - */ - multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); + for (MultiXactId multi = from_multi; multi != to_multi;) + { + MultiXactMember member; + bool multixid_valid; - /* - * Write the new offset to pg_multixact/offsets. - * - * Even if this multixid is invalid, we still need to write its - * offset if the *previous* multixid was valid. That's because - * when reading a multixid, the number of members is calculated - * from the difference between the two offsets. - */ - RecordMultiXactOffset(offsets_writer, multi, - (multixid_valid || prev_multixid_valid) ? next_offset : 0); + /* + * Read this multixid's members. + * + * Locking-only XIDs that may be part of multi-xids don't matter after + * upgrade, as there can be no transactions running across upgrade. So + * as a small optimization, we only read one member from each + * multixid: the one updating one, or if there was no update, + * arbitrarily the first locking xid. + */ + multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); - /* Write the members */ - if (multixid_valid) - { - RecordMultiXactMembers(members_writer, next_offset, 1, &member); - next_offset += 1; - } + /* + * Write the new offset to pg_multixact/offsets. + * + * Even if this multixid is invalid, we still need to write its offset + * if the *previous* multixid was valid. That's because when reading + * a multixid, the number of members is calculated from the difference + * between the two offsets. + */ + RecordMultiXactOffset(offsets_writer, multi, + (multixid_valid || prev_multixid_valid) ? next_offset : 0); - /* Advance to next multixid, handling wraparound */ - multi++; - if (multi < FirstMultiXactId) - multi = FirstMultiXactId; - prev_multixid_valid = multixid_valid; + /* Write the members */ + if (multixid_valid) + { + RecordMultiXactMembers(members_writer, next_offset, 1, &member); + next_offset += 1; } - FreeOldMultiXactReader(old_reader); + /* Advance to next multixid, handling wraparound */ + multi++; + if (multi < FirstMultiXactId) + multi = FirstMultiXactId; + prev_multixid_valid = multixid_valid; + } + + FreeOldMultiXactReader(old_reader); /* Write the final 'next' offset to the last SLRU page */ RecordMultiXactOffset(offsets_writer, to_multi, diff --git a/src/bin/pg_upgrade/pg_upgrade.c b/src/bin/pg_upgrade/pg_upgrade.c index c6af9035665..7366fd4627c 100644 --- a/src/bin/pg_upgrade/pg_upgrade.c +++ b/src/bin/pg_upgrade/pg_upgrade.c @@ -833,7 +833,7 @@ copy_xact_xlog_xid(void) * Determine the range of multixacts to convert. */ nxtmulti = old_cluster.controldata.chkpnt_nxtmulti; - oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; + oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; /* handle wraparound */ if (nxtmulti < FirstMultiXactId) nxtmulti = FirstMultiXactId; @@ -898,15 +898,15 @@ set_frozenxids(void) int i_datname; int i_datallowconn; - prep_status("Setting frozenxid and minmxid counters in new cluster"); + prep_status("Setting frozenxid and minmxid counters in new cluster"); conn_template1 = connectToServer(&new_cluster, "template1"); - /* set pg_database.datfrozenxid */ - PQclear(executeQueryOrDie(conn_template1, - "UPDATE pg_catalog.pg_database " - "SET datfrozenxid = '%u'", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_database.datfrozenxid */ + PQclear(executeQueryOrDie(conn_template1, + "UPDATE pg_catalog.pg_database " + "SET datfrozenxid = '%u'", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_database.datminmxid */ PQclear(executeQueryOrDie(conn_template1, @@ -942,16 +942,16 @@ set_frozenxids(void) conn = connectToServer(&new_cluster, datname); - /* set pg_class.relfrozenxid */ - PQclear(executeQueryOrDie(conn, - "UPDATE pg_catalog.pg_class " - "SET relfrozenxid = '%u' " - /* only heap, materialized view, and TOAST are vacuumed */ - "WHERE relkind IN (" - CppAsString2(RELKIND_RELATION) ", " - CppAsString2(RELKIND_MATVIEW) ", " - CppAsString2(RELKIND_TOASTVALUE) ")", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_class.relfrozenxid */ + PQclear(executeQueryOrDie(conn, + "UPDATE pg_catalog.pg_class " + "SET relfrozenxid = '%u' " + /* only heap, materialized view, and TOAST are vacuumed */ + "WHERE relkind IN (" + CppAsString2(RELKIND_RELATION) ", " + CppAsString2(RELKIND_MATVIEW) ", " + CppAsString2(RELKIND_TOASTVALUE) ")", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_class.relminmxid */ PQclear(executeQueryOrDie(conn, diff --git a/src/bin/pg_upgrade/relfilenumber.c b/src/bin/pg_upgrade/relfilenumber.c index ec2ff7acb21..6c467bdc8a5 100644 --- a/src/bin/pg_upgrade/relfilenumber.c +++ b/src/bin/pg_upgrade/relfilenumber.c @@ -587,32 +587,32 @@ transfer_relfile(FileNameMap *map, const char *type_suffix) /* Copying files might take some time, so give feedback. */ pg_log(PG_STATUS, "%s", old_file); - switch (user_opts.transfer_mode) - { - case TRANSFER_MODE_CLONE: - pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", - old_file, new_file); - cloneFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", - old_file, new_file); - copyFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY_FILE_RANGE: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", - old_file, new_file); - copyFileByRange(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_LINK: - pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", - old_file, new_file); - linkFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_SWAP: - /* swap mode is handled in its own code path */ - pg_fatal("should never happen"); - break; - } + switch (user_opts.transfer_mode) + { + case TRANSFER_MODE_CLONE: + pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", + old_file, new_file); + cloneFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", + old_file, new_file); + copyFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY_FILE_RANGE: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", + old_file, new_file); + copyFileByRange(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_LINK: + pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", + old_file, new_file); + linkFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_SWAP: + /* swap mode is handled in its own code path */ + pg_fatal("should never happen"); + break; + } } } diff --git a/src/bin/pg_upgrade/t/006_transfer_modes.pl b/src/bin/pg_upgrade/t/006_transfer_modes.pl index 9efa5dc863c..360d05c4b68 100644 --- a/src/bin/pg_upgrade/t/006_transfer_modes.pl +++ b/src/bin/pg_upgrade/t/006_transfer_modes.pl @@ -29,10 +29,8 @@ sub test_mode } $new->init(); - $new->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); - $old->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); + $new->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); + $old->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); # We can only test security labels if both the old and new installations # have dummy_seclabel. @@ -76,15 +74,14 @@ sub test_mode "CREATE TABLE test4 AS SELECT generate_series(400, 502)"); } - $old->safe_psql('postgres', - "CREATE TABLESPACE inplc_tblspc LOCATION ''"); - $old->safe_psql('postgres', - "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); - $old->safe_psql('postgres', - "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" - ); - $old->safe_psql('testdb3', - "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); + $old->safe_psql('postgres', "CREATE TABLESPACE inplc_tblspc LOCATION ''"); + $old->safe_psql('postgres', + "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); + $old->safe_psql('postgres', + "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" + ); + $old->safe_psql('testdb3', + "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); # While we are here, test handling of large objects. $old->safe_psql( @@ -152,12 +149,10 @@ sub test_mode } # Tests for in-place tablespaces. - $result = - $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); - is($result, '104', "test5 data after pg_upgrade $mode"); - $result = - $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); - is($result, '105', "test6 data after pg_upgrade $mode"); + $result = $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); + is($result, '104', "test5 data after pg_upgrade $mode"); + $result = $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); + is($result, '105', "test6 data after pg_upgrade $mode"); # Tests for large objects $result = $new->safe_psql('postgres', "SELECT lo_get(4532)"); diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index 44ef11d980e..c90bf8bbde2 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -6278,23 +6278,22 @@ get_create_object_cmd(EditableObjectType obj_type, Oid oid, * ensure the right view gets replaced. Also, check relation kind * to be sure it's a view. * - * Views may have WITH [LOCAL|CASCADED] - * CHECK OPTION. These are not part of the view definition - * returned by pg_get_viewdef() and so need to be retrieved - * separately. Materialized views may have - * arbitrary storage parameter reloptions. + * Views may have WITH [LOCAL|CASCADED] CHECK OPTION. These are + * not part of the view definition returned by pg_get_viewdef() + * and so need to be retrieved separately. Materialized views may + * have arbitrary storage parameter reloptions. */ printfPQExpBuffer(query, "/* %s */\n", _("Get view's definition and details")); - appendPQExpBuffer(query, - "SELECT nspname, relname, relkind, " - "pg_catalog.pg_get_viewdef(c.oid, true), " - "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " - "FROM pg_catalog.pg_class c " - "LEFT JOIN pg_catalog.pg_namespace n " - "ON c.relnamespace = n.oid WHERE c.oid = %u", - oid); + appendPQExpBuffer(query, + "SELECT nspname, relname, relkind, " + "pg_catalog.pg_get_viewdef(c.oid, true), " + "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " + "FROM pg_catalog.pg_class c " + "LEFT JOIN pg_catalog.pg_namespace n " + "ON c.relnamespace = n.oid WHERE c.oid = %u", + oid); break; } diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index ce99137c613..ac0c55e7aa5 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -387,19 +387,19 @@ describeFunctions(const char *functypes, const char *func_pattern, gettext_noop("stable"), gettext_noop("volatile"), gettext_noop("Volatility")); - appendPQExpBuffer(&buf, - ",\n CASE\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" - " END as \"%s\"", - gettext_noop("restricted"), - gettext_noop("safe"), - gettext_noop("unsafe"), - gettext_noop("Parallel")); + appendPQExpBuffer(&buf, + ",\n CASE\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" + " END as \"%s\"", + gettext_noop("restricted"), + gettext_noop("safe"), + gettext_noop("unsafe"), + gettext_noop("Parallel")); appendPQExpBuffer(&buf, ",\n pg_catalog.pg_get_userbyid(p.proowner) as \"%s\"" ",\n CASE WHEN prosecdef THEN '%s' ELSE '%s' END AS \"%s\"" @@ -599,8 +599,8 @@ describeFunctions(const char *functypes, const char *func_pattern, myopt.title = _("List of functions"); myopt.translate_header = true; - myopt.translate_columns = translate_columns; - myopt.n_translate_columns = lengthof(translate_columns); + myopt.translate_columns = translate_columns; + myopt.n_translate_columns = lengthof(translate_columns); printQuery(res, &myopt, pset.queryFout, false, pset.logfile); @@ -1086,38 +1086,38 @@ permissionsList(const char *pattern, bool showSystem) " ), E'\\n') AS \"%s\"", gettext_noop("Column privileges")); - appendPQExpBuffer(&buf, - ",\n pg_catalog.array_to_string(ARRAY(\n" - " SELECT polname\n" - " || CASE WHEN NOT polpermissive THEN\n" - " E' (RESTRICTIVE)'\n" - " ELSE '' END\n" - " || CASE WHEN polcmd != '*' THEN\n" - " E' (' || polcmd::pg_catalog.text || E'):'\n" - " ELSE E':'\n" - " END\n" - " || CASE WHEN polqual IS NOT NULL THEN\n" - " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" - " ELSE E''\n" - " END\n" - " || CASE WHEN polwithcheck IS NOT NULL THEN\n" - " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" - " ELSE E''\n" - " END" - " || CASE WHEN polroles <> '{0}' THEN\n" - " E'\\n to: ' || pg_catalog.array_to_string(\n" - " ARRAY(\n" - " SELECT rolname\n" - " FROM pg_catalog.pg_roles\n" - " WHERE oid = ANY (polroles)\n" - " ORDER BY 1\n" - " ), E', ')\n" - " ELSE E''\n" - " END\n" - " FROM pg_catalog.pg_policy pol\n" - " WHERE polrelid = c.oid), E'\\n')\n" - " AS \"%s\"", - gettext_noop("Policies")); + appendPQExpBuffer(&buf, + ",\n pg_catalog.array_to_string(ARRAY(\n" + " SELECT polname\n" + " || CASE WHEN NOT polpermissive THEN\n" + " E' (RESTRICTIVE)'\n" + " ELSE '' END\n" + " || CASE WHEN polcmd != '*' THEN\n" + " E' (' || polcmd::pg_catalog.text || E'):'\n" + " ELSE E':'\n" + " END\n" + " || CASE WHEN polqual IS NOT NULL THEN\n" + " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" + " ELSE E''\n" + " END\n" + " || CASE WHEN polwithcheck IS NOT NULL THEN\n" + " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" + " ELSE E''\n" + " END" + " || CASE WHEN polroles <> '{0}' THEN\n" + " E'\\n to: ' || pg_catalog.array_to_string(\n" + " ARRAY(\n" + " SELECT rolname\n" + " FROM pg_catalog.pg_roles\n" + " WHERE oid = ANY (polroles)\n" + " ORDER BY 1\n" + " ), E', ')\n" + " ELSE E''\n" + " END\n" + " FROM pg_catalog.pg_policy pol\n" + " WHERE polrelid = c.oid), E'\\n')\n" + " AS \"%s\"", + gettext_noop("Policies")); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_class c\n" " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n" @@ -1675,27 +1675,27 @@ describeOneTableDetails(const char *schemaname, char *footers[3] = {NULL, NULL, NULL}; printfPQExpBuffer(&buf, "/* %s */\n", _("Get sequence information")); - appendPQExpBuffer(&buf, - "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" - " seqstart AS \"%s\",\n" - " seqmin AS \"%s\",\n" - " seqmax AS \"%s\",\n" - " seqincrement AS \"%s\",\n" - " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" - " seqcache AS \"%s\"\n", - gettext_noop("Type"), - gettext_noop("Start"), - gettext_noop("Minimum"), - gettext_noop("Maximum"), - gettext_noop("Increment"), - gettext_noop("yes"), - gettext_noop("no"), - gettext_noop("Cycles?"), - gettext_noop("Cache")); - appendPQExpBuffer(&buf, - "FROM pg_catalog.pg_sequence\n" - "WHERE seqrelid = '%s';", - oid); + appendPQExpBuffer(&buf, + "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" + " seqstart AS \"%s\",\n" + " seqmin AS \"%s\",\n" + " seqmax AS \"%s\",\n" + " seqincrement AS \"%s\",\n" + " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" + " seqcache AS \"%s\"\n", + gettext_noop("Type"), + gettext_noop("Start"), + gettext_noop("Minimum"), + gettext_noop("Maximum"), + gettext_noop("Increment"), + gettext_noop("yes"), + gettext_noop("no"), + gettext_noop("Cycles?"), + gettext_noop("Cache")); + appendPQExpBuffer(&buf, + "FROM pg_catalog.pg_sequence\n" + "WHERE seqrelid = '%s';", + oid); res = PSQLexec(buf.data); if (!res) @@ -1913,7 +1913,7 @@ describeOneTableDetails(const char *schemaname, appendPQExpBufferStr(&buf, ",\n (SELECT c.collname FROM pg_catalog.pg_collation c, pg_catalog.pg_type t\n" " WHERE c.oid = a.attcollation AND t.oid = a.atttypid AND a.attcollation <> t.typcollation) AS attcollation"); attcoll_col = cols++; - appendPQExpBufferStr(&buf, ",\n a.attidentity"); + appendPQExpBufferStr(&buf, ",\n a.attidentity"); attidentity_col = cols++; if (pset.sversion >= 120000) appendPQExpBufferStr(&buf, ",\n a.attgenerated"); @@ -2326,7 +2326,7 @@ describeOneTableDetails(const char *schemaname, CppAsString2(CONSTRAINT_EXCLUSION) ") AND " "condeferred) AS condeferred,\n"); - appendPQExpBufferStr(&buf, "i.indisreplident,\n"); + appendPQExpBufferStr(&buf, "i.indisreplident,\n"); if (pset.sversion >= 150000) appendPQExpBufferStr(&buf, "i.indnullsnotdistinct,\n"); @@ -2431,7 +2431,7 @@ describeOneTableDetails(const char *schemaname, "pg_catalog.pg_get_indexdef(i.indexrelid, 0, true),\n " "pg_catalog.pg_get_constraintdef(con.oid, true), " "contype, condeferrable, condeferred"); - appendPQExpBufferStr(&buf, ", i.indisreplident"); + appendPQExpBufferStr(&buf, ", i.indisreplident"); appendPQExpBufferStr(&buf, ", c2.reltablespace"); if (pset.sversion >= 180000) appendPQExpBufferStr(&buf, ", con.conperiod"); @@ -2682,81 +2682,80 @@ describeOneTableDetails(const char *schemaname, PQclear(result); /* print any row-level policies */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get row-level policies for this table")); - appendPQExpBufferStr(&buf, "SELECT pol.polname,"); - appendPQExpBufferStr(&buf, - " pol.polpermissive,\n"); - appendPQExpBuffer(&buf, - " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" - " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" - " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" - " CASE pol.polcmd\n" - " WHEN 'r' THEN 'SELECT'\n" - " WHEN 'a' THEN 'INSERT'\n" - " WHEN 'w' THEN 'UPDATE'\n" - " WHEN 'd' THEN 'DELETE'\n" - " END AS cmd\n" - "FROM pg_catalog.pg_policy pol\n" - "WHERE pol.polrelid = '%s' ORDER BY 1;", - oid); + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get row-level policies for this table")); + appendPQExpBufferStr(&buf, "SELECT pol.polname,"); + appendPQExpBufferStr(&buf, + " pol.polpermissive,\n"); + appendPQExpBuffer(&buf, + " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" + " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" + " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" + " CASE pol.polcmd\n" + " WHEN 'r' THEN 'SELECT'\n" + " WHEN 'a' THEN 'INSERT'\n" + " WHEN 'w' THEN 'UPDATE'\n" + " WHEN 'd' THEN 'DELETE'\n" + " END AS cmd\n" + "FROM pg_catalog.pg_policy pol\n" + "WHERE pol.polrelid = '%s' ORDER BY 1;", + oid); - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - /* - * Handle cases where RLS is enabled and there are policies, or - * there aren't policies, or RLS isn't enabled but there are - * policies - */ - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies:")); + /* + * Handle cases where RLS is enabled and there are policies, or there + * aren't policies, or RLS isn't enabled but there are policies + */ + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies:")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled):")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled):")); - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); - if (!tableinfo.rowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (row security disabled):")); + if (!tableinfo.rowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (row security disabled):")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " POLICY \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " POLICY \"%s\"", + PQgetvalue(result, i, 0)); - if (*(PQgetvalue(result, i, 1)) == 'f') - appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); + if (*(PQgetvalue(result, i, 1)) == 'f') + appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); - if (!PQgetisnull(result, i, 5)) - appendPQExpBuffer(&buf, " FOR %s", - PQgetvalue(result, i, 5)); + if (!PQgetisnull(result, i, 5)) + appendPQExpBuffer(&buf, " FOR %s", + PQgetvalue(result, i, 5)); - if (!PQgetisnull(result, i, 2)) - { - appendPQExpBuffer(&buf, "\n TO %s", - PQgetvalue(result, i, 2)); - } + if (!PQgetisnull(result, i, 2)) + { + appendPQExpBuffer(&buf, "\n TO %s", + PQgetvalue(result, i, 2)); + } - if (!PQgetisnull(result, i, 3)) - appendPQExpBuffer(&buf, "\n USING (%s)", - PQgetvalue(result, i, 3)); + if (!PQgetisnull(result, i, 3)) + appendPQExpBuffer(&buf, "\n USING (%s)", + PQgetvalue(result, i, 3)); - if (!PQgetisnull(result, i, 4)) - appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", - PQgetvalue(result, i, 4)); + if (!PQgetisnull(result, i, 4)) + appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", + PQgetvalue(result, i, 4)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* print any extended statistics */ if (pset.sversion >= 140000) @@ -3025,115 +3024,115 @@ describeOneTableDetails(const char *schemaname, } /* print any publications */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get publications that publish this table")); - if (pset.sversion >= 150000) + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get publications that publish this table")); + if (pset.sversion >= 150000) + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" + " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" + "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" + "UNION\n" + "SELECT pubname\n" + " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" + " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" + " (SELECT pg_catalog.string_agg(attname, ', ')\n" + " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" + " pg_catalog.pg_attribute\n" + " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" + " ELSE NULL END) " + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" + "WHERE pr.prrelid = '%s'\n", + oid, oid, oid); + + if (pset.sversion >= 190000) { + /* + * Skip entries where this relation appears in the + * publication's EXCEPT list. + */ appendPQExpBuffer(&buf, + " AND NOT pr.prexcept\n" + "UNION\n" "SELECT pubname\n" " , NULL\n" " , NULL\n" "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" - " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" - "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" - "UNION\n" - "SELECT pubname\n" - " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" - " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" - " (SELECT pg_catalog.string_agg(attname, ', ')\n" - " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" - " pg_catalog.pg_attribute\n" - " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" - " ELSE NULL END) " - "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" - "WHERE pr.prrelid = '%s'\n", + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + " AND NOT EXISTS (\n" + " SELECT 1\n" + " FROM pg_catalog.pg_publication_rel pr\n" + " WHERE pr.prpubid = p.oid AND\n" + " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" + "ORDER BY 1;", oid, oid, oid); - - if (pset.sversion >= 190000) - { - /* - * Skip entries where this relation appears in the - * publication's EXCEPT list. - */ - appendPQExpBuffer(&buf, - " AND NOT pr.prexcept\n" - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - " AND NOT EXISTS (\n" - " SELECT 1\n" - " FROM pg_catalog.pg_publication_rel pr\n" - " WHERE pr.prpubid = p.oid AND\n" - " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" - "ORDER BY 1;", - oid, oid, oid); - } - else - { - appendPQExpBuffer(&buf, - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - "ORDER BY 1;", - oid); - } } else { appendPQExpBuffer(&buf, + "UNION\n" "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - "WHERE pr.prrelid = '%s'\n" - "UNION ALL\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" + " , NULL\n" + " , NULL\n" "FROM pg_catalog.pg_publication p\n" "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" "ORDER BY 1;", - oid, oid); + oid); } + } + else + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + "WHERE pr.prrelid = '%s'\n" + "UNION ALL\n" + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + "ORDER BY 1;", + oid, oid); + } - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - if (tuples > 0) - printTableAddFooter(&cont, _("Included in publications:")); + if (tuples > 0) + printTableAddFooter(&cont, _("Included in publications:")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " \"%s\"", + PQgetvalue(result, i, 0)); - /* column list (if any) */ - if (!PQgetisnull(result, i, 2)) - appendPQExpBuffer(&buf, " (%s)", - PQgetvalue(result, i, 2)); + /* column list (if any) */ + if (!PQgetisnull(result, i, 2)) + appendPQExpBuffer(&buf, " (%s)", + PQgetvalue(result, i, 2)); - /* row filter (if any) */ - if (!PQgetisnull(result, i, 1)) - appendPQExpBuffer(&buf, " WHERE %s", - PQgetvalue(result, i, 1)); + /* row filter (if any) */ + if (!PQgetisnull(result, i, 1)) + appendPQExpBuffer(&buf, " WHERE %s", + PQgetvalue(result, i, 1)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* Print publications where the table is in the EXCEPT clause */ if (pset.sversion >= 190000) @@ -3805,7 +3804,7 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) ncols++; } appendPQExpBufferStr(&buf, "\n, r.rolreplication"); - appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); + appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_roles r\n"); @@ -3860,8 +3859,8 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) if (strcmp(PQgetvalue(res, i, (verbose ? 9 : 8)), "t") == 0) add_role_attribute(&buf, _("Replication")); - if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) - add_role_attribute(&buf, _("Bypass RLS")); + if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) + add_role_attribute(&buf, _("Bypass RLS")); conns = atoi(PQgetvalue(res, i, 6)); if (conns >= 0) @@ -5155,14 +5154,14 @@ listCollations(const char *pattern, bool verbose, bool showSystem) gettext_noop("Schema"), gettext_noop("Name")); - appendPQExpBuffer(&buf, - " CASE c.collprovider " - "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " - "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " - "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " - "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " - "END AS \"%s\",\n", - gettext_noop("Provider")); + appendPQExpBuffer(&buf, + " CASE c.collprovider " + "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " + "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " + "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " + "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " + "END AS \"%s\",\n", + gettext_noop("Provider")); appendPQExpBuffer(&buf, " c.collcollate AS \"%s\",\n" -- 2.50.1 (Apple Git-155) --aHl3HfeiUuO3zeNC-- ^ permalink raw reply [nested|flat] 59+ messages in thread
* [PATCH v6 4/4] run pgindent and pgperltidy @ 2026-06-30 18:24 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 59+ messages in thread From: Nathan Bossart @ 2026-06-30 18:24 UTC (permalink / raw) --- src/bin/pg_dump/pg_dump.c | 464 ++++++++++----------- src/bin/pg_dump/pg_dumpall.c | 30 +- src/bin/pg_upgrade/check.c | 16 +- src/bin/pg_upgrade/controldata.c | 2 +- src/bin/pg_upgrade/exec.c | 8 +- src/bin/pg_upgrade/multixact_rewrite.c | 80 ++-- src/bin/pg_upgrade/pg_upgrade.c | 34 +- src/bin/pg_upgrade/relfilenumber.c | 54 +-- src/bin/pg_upgrade/t/006_transfer_modes.pl | 33 +- src/bin/psql/command.c | 29 +- src/bin/psql/describe.c | 461 ++++++++++---------- 11 files changed, 601 insertions(+), 610 deletions(-) diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 65bd15ebfd2..5673268b467 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -1491,8 +1491,8 @@ setup_connection(Archive *AH, const char *dumpencoding, * Disable timeouts if supported. */ ExecuteSqlStatement(AH, "SET statement_timeout = 0"); - ExecuteSqlStatement(AH, "SET lock_timeout = 0"); - ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); + ExecuteSqlStatement(AH, "SET lock_timeout = 0"); + ExecuteSqlStatement(AH, "SET idle_in_transaction_session_timeout = 0"); if (AH->remoteVersion >= 170000) ExecuteSqlStatement(AH, "SET transaction_timeout = 0"); @@ -1505,10 +1505,10 @@ setup_connection(Archive *AH, const char *dumpencoding, /* * Adjust row-security mode, if supported. */ - if (dopt->enable_row_security) - ExecuteSqlStatement(AH, "SET row_security = on"); - else - ExecuteSqlStatement(AH, "SET row_security = off"); + if (dopt->enable_row_security) + ExecuteSqlStatement(AH, "SET row_security = on"); + else + ExecuteSqlStatement(AH, "SET row_security = off"); /* * For security reasons, we restrict the expansion of non-system views and @@ -1933,10 +1933,9 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) addObjectDependency(dobj, ext->dobj.dumpId); /* - * Mark the member object to have any non-initial ACLs - * dumped. (Any initial ACLs will be removed later, using data from - * pg_init_privs, so that we'll dump only the delta from the extension's - * initial setup.) + * Mark the member object to have any non-initial ACLs dumped. (Any + * initial ACLs will be removed later, using data from pg_init_privs, so + * that we'll dump only the delta from the extension's initial setup.) * * In binary upgrades, we still dump all components of the members * individually, since the idea is to exactly reproduce the database @@ -1953,7 +1952,7 @@ checkExtensionMembership(DumpableObject *dobj, Archive *fout) if (fout->dopt->binary_upgrade) dobj->dump = ext->dobj.dump; else - dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); + dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL); return true; } @@ -1987,9 +1986,9 @@ selectDumpableNamespace(NamespaceInfo *nsinfo, Archive *fout) else if (strcmp(nsinfo->dobj.name, "pg_catalog") == 0) { /* - * We dump out any ACLs defined in pg_catalog, if - * they are interesting (and not the original ACLs which were set at - * initdb time, see pg_init_privs). + * We dump out any ACLs defined in pg_catalog, if they are interesting + * (and not the original ACLs which were set at initdb time, see + * pg_init_privs). */ nsinfo->dobj.dump_contains = nsinfo->dobj.dump = DUMP_COMPONENT_ACL; } @@ -3296,7 +3295,7 @@ dumpDatabase(Archive *fout) "datcollate, datctype, datfrozenxid, " "datacl, acldefault('d', datdba) AS acldefault, " "datistemplate, datconnlimit, "); - appendPQExpBufferStr(dbQry, "datminmxid, "); + appendPQExpBufferStr(dbQry, "datminmxid, "); if (fout->remoteVersion >= 170000) appendPQExpBufferStr(dbQry, "datlocprovider, datlocale, datcollversion, "); else if (fout->remoteVersion >= 150000) @@ -3638,11 +3637,11 @@ dumpDatabase(Archive *fout) ii_oid, ii_relminmxid; - appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" - "FROM pg_catalog.pg_class\n" - "WHERE oid IN (%u, %u, %u, %u);\n", - LargeObjectRelationId, LargeObjectLOidPNIndexId, - LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); + appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid, relfilenode, oid\n" + "FROM pg_catalog.pg_class\n" + "WHERE oid IN (%u, %u, %u, %u);\n", + LargeObjectRelationId, LargeObjectLOidPNIndexId, + LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId); lo_res = ExecuteSqlQuery(fout, loFrozenQry->data, PGRES_TUPLES_OK); @@ -4274,7 +4273,7 @@ getPolicies(Archive *fout, TableInfo tblinfo[], int numTables) printfPQExpBuffer(query, "SELECT pol.oid, pol.tableoid, pol.polrelid, pol.polname, pol.polcmd, "); - appendPQExpBufferStr(query, "pol.polpermissive, "); + appendPQExpBufferStr(query, "pol.polpermissive, "); appendPQExpBuffer(query, "CASE WHEN pol.polroles = '{0}' THEN NULL ELSE " " pg_catalog.array_to_string(ARRAY(SELECT pg_catalog.quote_ident(rolname) from pg_catalog.pg_roles WHERE oid = ANY(pol.polroles)), ', ') END AS polroles, " @@ -6633,9 +6632,9 @@ getAccessMethods(Archive *fout) * Select all access methods from pg_am table. */ appendPQExpBufferStr(query, "SELECT tableoid, oid, amname, "); - appendPQExpBufferStr(query, - "amtype, " - "amhandler::pg_catalog.regproc AS amhandler "); + appendPQExpBufferStr(query, + "amtype, " + "amhandler::pg_catalog.regproc AS amhandler "); appendPQExpBufferStr(query, "FROM pg_am"); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6827,35 +6826,35 @@ getAggregates(Archive *fout) * Find all interesting aggregates. See comment in getFuncs() for the * rationale behind the filtering logic. */ - agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" - : "p.proisagg"); + agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'" + : "p.proisagg"); - appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " - "p.proname AS aggname, " - "p.pronamespace AS aggnamespace, " - "p.pronargs, p.proargtypes, " - "p.proowner, " - "p.proacl AS aggacl, " - "acldefault('f', p.proowner) AS acldefault " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s AND (" - "p.pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog') OR " - "p.proacl IS DISTINCT FROM pip.initprivs", - agg_check); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - " OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); - appendPQExpBufferChar(query, ')'); + appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, " + "p.proname AS aggname, " + "p.pronamespace AS aggnamespace, " + "p.pronargs, p.proargtypes, " + "p.proowner, " + "p.proacl AS aggacl, " + "acldefault('f', p.proowner) AS acldefault " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s AND (" + "p.pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog') OR " + "p.proacl IS DISTINCT FROM pip.initprivs", + agg_check); + if (dopt->binary_upgrade) + appendPQExpBufferStr(query, + " OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -6957,53 +6956,53 @@ getFuncs(Archive *fout) * include them, since we want to dump extension members individually in * that mode. Also, if they are used by casts or transforms then we need * to gather the information about them, though they won't be dumped if - * they are built-in. Also, include functions in - * pg_catalog if they have an ACL different from what's shown in - * pg_init_privs (so we have to join to pg_init_privs; annoying). + * they are built-in. Also, include functions in pg_catalog if they have + * an ACL different from what's shown in pg_init_privs (so we have to join + * to pg_init_privs; annoying). */ - not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" - : "NOT p.proisagg"); + not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'" + : "NOT p.proisagg"); - appendPQExpBuffer(query, - "SELECT p.tableoid, p.oid, p.proname, p.prolang, " - "p.pronargs, p.proargtypes, p.prorettype, " - "p.proacl, " - "acldefault('f', p.proowner) AS acldefault, " - "p.pronamespace, " - "p.proowner " - "FROM pg_proc p " - "LEFT JOIN pg_init_privs pip ON " - "(p.oid = pip.objoid " - "AND pip.classoid = 'pg_proc'::regclass " - "AND pip.objsubid = 0) " - "WHERE %s" - "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " - "WHERE classid = 'pg_proc'::regclass AND " - "objid = p.oid AND deptype = 'i')" - "\n AND (" - "\n pronamespace != " - "(SELECT oid FROM pg_namespace " - "WHERE nspname = 'pg_catalog')" - "\n OR EXISTS (SELECT 1 FROM pg_cast" - "\n WHERE pg_cast.oid > %u " - "\n AND p.oid = pg_cast.castfunc)" - "\n OR EXISTS (SELECT 1 FROM pg_transform" - "\n WHERE pg_transform.oid > %u AND " - "\n (p.oid = pg_transform.trffromsql" - "\n OR p.oid = pg_transform.trftosql))", - not_agg_check, - g_last_builtin_oid, - g_last_builtin_oid); - if (dopt->binary_upgrade) - appendPQExpBufferStr(query, - "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " - "classid = 'pg_proc'::regclass AND " - "objid = p.oid AND " - "refclassid = 'pg_extension'::regclass AND " - "deptype = 'e')"); + appendPQExpBuffer(query, + "SELECT p.tableoid, p.oid, p.proname, p.prolang, " + "p.pronargs, p.proargtypes, p.prorettype, " + "p.proacl, " + "acldefault('f', p.proowner) AS acldefault, " + "p.pronamespace, " + "p.proowner " + "FROM pg_proc p " + "LEFT JOIN pg_init_privs pip ON " + "(p.oid = pip.objoid " + "AND pip.classoid = 'pg_proc'::regclass " + "AND pip.objsubid = 0) " + "WHERE %s" + "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " + "WHERE classid = 'pg_proc'::regclass AND " + "objid = p.oid AND deptype = 'i')" + "\n AND (" + "\n pronamespace != " + "(SELECT oid FROM pg_namespace " + "WHERE nspname = 'pg_catalog')" + "\n OR EXISTS (SELECT 1 FROM pg_cast" + "\n WHERE pg_cast.oid > %u " + "\n AND p.oid = pg_cast.castfunc)" + "\n OR EXISTS (SELECT 1 FROM pg_transform" + "\n WHERE pg_transform.oid > %u AND " + "\n (p.oid = pg_transform.trffromsql" + "\n OR p.oid = pg_transform.trftosql))", + not_agg_check, + g_last_builtin_oid, + g_last_builtin_oid); + if (dopt->binary_upgrade) appendPQExpBufferStr(query, - "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); - appendPQExpBufferChar(query, ')'); + "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " + "classid = 'pg_proc'::regclass AND " + "objid = p.oid AND " + "refclassid = 'pg_extension'::regclass AND " + "deptype = 'e')"); + appendPQExpBufferStr(query, + "\n OR p.proacl IS DISTINCT FROM pip.initprivs"); + appendPQExpBufferChar(query, ')'); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -7252,31 +7251,31 @@ getTables(Archive *fout, int *numTables) appendPQExpBufferStr(query, "c.relhasoids, "); - appendPQExpBufferStr(query, - "c.relispopulated, "); + appendPQExpBufferStr(query, + "c.relispopulated, "); - appendPQExpBufferStr(query, - "c.relreplident, "); + appendPQExpBufferStr(query, + "c.relreplident, "); - appendPQExpBufferStr(query, - "c.relrowsecurity, c.relforcerowsecurity, "); + appendPQExpBufferStr(query, + "c.relrowsecurity, c.relforcerowsecurity, "); - appendPQExpBufferStr(query, - "c.relminmxid, tc.relminmxid AS tminmxid, "); + appendPQExpBufferStr(query, + "c.relminmxid, tc.relminmxid AS tminmxid, "); - appendPQExpBufferStr(query, - "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); + appendPQExpBufferStr(query, + "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); - appendPQExpBufferStr(query, - "am.amname, "); + appendPQExpBufferStr(query, + "am.amname, "); - appendPQExpBufferStr(query, - "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); + appendPQExpBufferStr(query, + "(d.deptype = 'i') IS TRUE AS is_identity_sequence, "); - appendPQExpBufferStr(query, - "c.relispartition AS ispartition "); + appendPQExpBufferStr(query, + "c.relispartition AS ispartition "); /* * Left join to pg_depend to pick up dependency info linking sequences to @@ -7296,8 +7295,8 @@ getTables(Archive *fout, int *numTables) /* * Left join to pg_am to pick up the amname. */ - appendPQExpBufferStr(query, - "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); + appendPQExpBufferStr(query, + "LEFT JOIN pg_am am ON (c.relam = am.oid)\n"); /* * We purposefully ignore toast OIDs for partitioned tables; the reason is @@ -7868,8 +7867,8 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables) "t.reloptions AS indreloptions, "); - appendPQExpBufferStr(query, - "i.indisreplident, "); + appendPQExpBufferStr(query, + "i.indisreplident, "); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -9313,8 +9312,8 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables) appendPQExpBufferStr(q, "'' AS attcompression,\n"); - appendPQExpBufferStr(q, - "a.attidentity,\n"); + appendPQExpBufferStr(q, + "a.attidentity,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(q, @@ -10717,73 +10716,73 @@ getAdditionalACLs(Archive *fout) PQclear(res); /* Fetch initial-privileges data */ - printfPQExpBuffer(query, - "SELECT objoid, classoid, objsubid, privtype, initprivs " - "FROM pg_init_privs"); + printfPQExpBuffer(query, + "SELECT objoid, classoid, objsubid, privtype, initprivs " + "FROM pg_init_privs"); - res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); + res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); - ntups = PQntuples(res); - for (i = 0; i < ntups; i++) - { - Oid objoid = atooid(PQgetvalue(res, i, 0)); - Oid classoid = atooid(PQgetvalue(res, i, 1)); - int objsubid = atoi(PQgetvalue(res, i, 2)); - char privtype = *(PQgetvalue(res, i, 3)); - char *initprivs = PQgetvalue(res, i, 4); - CatalogId objId; - DumpableObject *dobj; + ntups = PQntuples(res); + for (i = 0; i < ntups; i++) + { + Oid objoid = atooid(PQgetvalue(res, i, 0)); + Oid classoid = atooid(PQgetvalue(res, i, 1)); + int objsubid = atoi(PQgetvalue(res, i, 2)); + char privtype = *(PQgetvalue(res, i, 3)); + char *initprivs = PQgetvalue(res, i, 4); + CatalogId objId; + DumpableObject *dobj; - objId.tableoid = classoid; - objId.oid = objoid; - dobj = findObjectByCatalogId(objId); - /* OK to ignore entries we haven't got a DumpableObject for */ - if (dobj) + objId.tableoid = classoid; + objId.oid = objoid; + dobj = findObjectByCatalogId(objId); + /* OK to ignore entries we haven't got a DumpableObject for */ + if (dobj) + { + /* Cope with sub-object initprivs */ + if (objsubid != 0) { - /* Cope with sub-object initprivs */ - if (objsubid != 0) - { - if (dobj->objType == DO_TABLE) - { - /* For a column initprivs, set the table's ACL flags */ - dobj->components |= DUMP_COMPONENT_ACL; - ((TableInfo *) dobj)->hascolumnACLs = true; - } - else - pg_log_warning("unsupported pg_init_privs entry: %u %u %d", - classoid, objoid, objsubid); - continue; - } - - /* - * We ignore any pg_init_privs.initprivs entry for the public - * schema, as explained in getNamespaces(). - */ - if (dobj->objType == DO_NAMESPACE && - strcmp(dobj->name, "public") == 0) - continue; - - /* Else it had better be of a type we think has ACLs */ - if (dobj->objType == DO_NAMESPACE || - dobj->objType == DO_TYPE || - dobj->objType == DO_FUNC || - dobj->objType == DO_AGG || - dobj->objType == DO_TABLE || - dobj->objType == DO_PROCLANG || - dobj->objType == DO_FDW || - dobj->objType == DO_FOREIGN_SERVER) + if (dobj->objType == DO_TABLE) { - DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; - - daobj->dacl.privtype = privtype; - daobj->dacl.initprivs = pstrdup(initprivs); + /* For a column initprivs, set the table's ACL flags */ + dobj->components |= DUMP_COMPONENT_ACL; + ((TableInfo *) dobj)->hascolumnACLs = true; } else pg_log_warning("unsupported pg_init_privs entry: %u %u %d", classoid, objoid, objsubid); + continue; + } + + /* + * We ignore any pg_init_privs.initprivs entry for the public + * schema, as explained in getNamespaces(). + */ + if (dobj->objType == DO_NAMESPACE && + strcmp(dobj->name, "public") == 0) + continue; + + /* Else it had better be of a type we think has ACLs */ + if (dobj->objType == DO_NAMESPACE || + dobj->objType == DO_TYPE || + dobj->objType == DO_FUNC || + dobj->objType == DO_AGG || + dobj->objType == DO_TABLE || + dobj->objType == DO_PROCLANG || + dobj->objType == DO_FDW || + dobj->objType == DO_FOREIGN_SERVER) + { + DumpableObjectWithAcl *daobj = (DumpableObjectWithAcl *) dobj; + + daobj->dacl.privtype = privtype; + daobj->dacl.initprivs = pstrdup(initprivs); } + else + pg_log_warning("unsupported pg_init_privs entry: %u %u %d", + classoid, objoid, objsubid); } - PQclear(res); + } + PQclear(res); destroyPQExpBuffer(query); } @@ -11128,8 +11127,8 @@ dumpRelationStats_dumper(Archive *fout, const void *userArg, const TocEntry *te) * The results must be in the order of the relations supplied in the * parameters to ensure we remain in sync as we walk through the TOC. * - * For versions before 19, the redundant filter clause on s.tablename = - * ANY(...) seems sufficient to convince the planner to use + * For versions before 19, the redundant filter clause on s.tablename + * = ANY(...) seems sufficient to convince the planner to use * pg_class_relname_nsp_index, which avoids a full scan of pg_stats. * In newer versions, pg_stats returns the table OIDs, eliminating the * need for that hack. @@ -13469,11 +13468,11 @@ dumpFunc(Archive *fout, const FuncInfo *finfo) "pg_catalog.pg_get_function_result(p.oid) AS funcresult,\n" "proleakproof,\n"); - appendPQExpBufferStr(query, - "array_to_string(protrftypes, ' ') AS protrftypes,\n"); + appendPQExpBufferStr(query, + "array_to_string(protrftypes, ' ') AS protrftypes,\n"); - appendPQExpBufferStr(query, - "proparallel,\n"); + appendPQExpBufferStr(query, + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -14963,9 +14962,9 @@ dumpCollation(Archive *fout, const CollInfo *collinfo) /* Get collation-specific details */ appendPQExpBufferStr(query, "SELECT "); - appendPQExpBufferStr(query, - "collprovider, " - "collversion, "); + appendPQExpBufferStr(query, + "collprovider, " + "collversion, "); if (fout->remoteVersion >= 120000) appendPQExpBufferStr(query, @@ -15372,23 +15371,23 @@ dumpAgg(Archive *fout, const AggInfo *agginfo) "pg_catalog.pg_get_function_arguments(p.oid) AS funcargs,\n" "pg_catalog.pg_get_function_identity_arguments(p.oid) AS funciargs,\n"); - appendPQExpBufferStr(query, - "aggkind,\n" - "aggmtransfn,\n" - "aggminvtransfn,\n" - "aggmfinalfn,\n" - "aggmtranstype::pg_catalog.regtype,\n" - "aggfinalextra,\n" - "aggmfinalextra,\n" - "aggtransspace,\n" - "aggmtransspace,\n" - "aggminitval,\n"); + appendPQExpBufferStr(query, + "aggkind,\n" + "aggmtransfn,\n" + "aggminvtransfn,\n" + "aggmfinalfn,\n" + "aggmtranstype::pg_catalog.regtype,\n" + "aggfinalextra,\n" + "aggmfinalextra,\n" + "aggtransspace,\n" + "aggmtransspace,\n" + "aggminitval,\n"); - appendPQExpBufferStr(query, - "aggcombinefn,\n" - "aggserialfn,\n" - "aggdeserialfn,\n" - "proparallel,\n"); + appendPQExpBufferStr(query, + "aggcombinefn,\n" + "aggserialfn,\n" + "aggdeserialfn,\n" + "proparallel,\n"); if (fout->remoteVersion >= 110000) appendPQExpBufferStr(query, @@ -16848,30 +16847,30 @@ dumpTable(Archive *fout, const TableInfo *tbinfo) appendPQExpBufferStr(query, "PREPARE getColumnACLs(pg_catalog.oid) AS\n"); - /* - * In principle we should call acldefault('c', relowner) to - * get the default ACL for a column. However, we don't - * currently store the numeric OID of the relowner in - * TableInfo. We could convert the owner name using regrole, - * but that creates a risk of failure due to concurrent role - * renames. Given that the default ACL for columns is empty - * and is likely to stay that way, it's not worth extra cycles - * and risk to avoid hard-wiring that knowledge here. - */ - appendPQExpBufferStr(query, - "SELECT at.attname, " - "at.attacl, " - "'{}' AS acldefault, " - "pip.privtype, pip.initprivs " - "FROM pg_catalog.pg_attribute at " - "LEFT JOIN pg_catalog.pg_init_privs pip ON " - "(at.attrelid = pip.objoid " - "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " - "AND at.attnum = pip.objsubid) " - "WHERE at.attrelid = $1 AND " - "NOT at.attisdropped " - "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " - "ORDER BY at.attnum"); + /* + * In principle we should call acldefault('c', relowner) to get + * the default ACL for a column. However, we don't currently + * store the numeric OID of the relowner in TableInfo. We could + * convert the owner name using regrole, but that creates a risk + * of failure due to concurrent role renames. Given that the + * default ACL for columns is empty and is likely to stay that + * way, it's not worth extra cycles and risk to avoid hard-wiring + * that knowledge here. + */ + appendPQExpBufferStr(query, + "SELECT at.attname, " + "at.attacl, " + "'{}' AS acldefault, " + "pip.privtype, pip.initprivs " + "FROM pg_catalog.pg_attribute at " + "LEFT JOIN pg_catalog.pg_init_privs pip ON " + "(at.attrelid = pip.objoid " + "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass " + "AND at.attnum = pip.objsubid) " + "WHERE at.attrelid = $1 AND " + "NOT at.attisdropped " + "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) " + "ORDER BY at.attnum"); ExecuteSqlStatement(fout, query->data); @@ -19165,7 +19164,7 @@ collectSequences(Archive *fout) * pg_get_sequence_data(), but we only do so for non-schema-only dumps. */ if (fout->remoteVersion < 180000 || - (!fout->dopt->dumpData && !fout->dopt->sequence_data)) + (!fout->dopt->dumpData && !fout->dopt->sequence_data)) query = "SELECT seqrelid, format_type(seqtypid, NULL), " "seqstart, seqincrement, " "seqmax, seqmin, " @@ -19227,15 +19226,14 @@ dumpSequence(Archive *fout, const TableInfo *tbinfo) qseqname = pg_strdup(fmtId(tbinfo->dobj.name)); /* - * The sequence information is gathered in a sorted - * table before any calls to dumpSequence(). See collectSequences() for - * more information. + * The sequence information is gathered in a sorted table before any calls + * to dumpSequence(). See collectSequences() for more information. */ - Assert(sequences); + Assert(sequences); - key.oid = tbinfo->dobj.catId.oid; - seq = bsearch(&key, sequences, nsequences, - sizeof(SequenceItem), SequenceItemCmp); + key.oid = tbinfo->dobj.catId.oid; + seq = bsearch(&key, sequences, nsequences, + sizeof(SequenceItem), SequenceItemCmp); /* Calculate default limits for a sequence of this type */ is_ascending = (seq->incby >= 0); diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c index e68937c9934..afcd9a218d8 100644 --- a/src/bin/pg_dump/pg_dumpall.c +++ b/src/bin/pg_dump/pg_dumpall.c @@ -785,11 +785,11 @@ dropRoles(PGconn *conn) int i_rolname; int i; - printfPQExpBuffer(buf, - "SELECT rolname " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 1", role_catalog); + printfPQExpBuffer(buf, + "SELECT rolname " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 1", role_catalog); res = executeQuery(conn, buf->data); @@ -843,16 +843,16 @@ dumpRoles(PGconn *conn) * Notes: rolconfig is dumped later, and pg_authid must be used for * extracting rolcomment regardless of role_catalog. */ - printfPQExpBuffer(buf, - "SELECT oid, rolname, rolsuper, rolinherit, " - "rolcreaterole, rolcreatedb, " - "rolcanlogin, rolconnlimit, rolpassword, " - "rolvaliduntil, rolreplication, rolbypassrls, " - "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " - "rolname = current_user AS is_current_user " - "FROM %s " - "WHERE rolname !~ '^pg_' " - "ORDER BY 2", role_catalog); + printfPQExpBuffer(buf, + "SELECT oid, rolname, rolsuper, rolinherit, " + "rolcreaterole, rolcreatedb, " + "rolcanlogin, rolconnlimit, rolpassword, " + "rolvaliduntil, rolreplication, rolbypassrls, " + "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, " + "rolname = current_user AS is_current_user " + "FROM %s " + "WHERE rolname !~ '^pg_' " + "ORDER BY 2", role_catalog); res = executeQuery(conn, buf->data); diff --git a/src/bin/pg_upgrade/check.c b/src/bin/pg_upgrade/check.c index 786c1474829..f725f5ee3e2 100644 --- a/src/bin/pg_upgrade/check.c +++ b/src/bin/pg_upgrade/check.c @@ -1475,15 +1475,15 @@ check_for_incompatible_polymorphics(ClusterInfo *cluster) ", 'array_cat(anyarray,anyarray)'" ", 'array_prepend(anyelement,anyarray)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_remove(anyarray,anyelement)'" - ", 'array_replace(anyarray,anyelement,anyelement)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_remove(anyarray,anyelement)'" + ", 'array_replace(anyarray,anyelement,anyelement)'"); - appendPQExpBufferStr(&old_polymorphics, - ", 'array_position(anyarray,anyelement)'" - ", 'array_position(anyarray,anyelement,integer)'" - ", 'array_positions(anyarray,anyelement)'" - ", 'width_bucket(anyelement,anyarray)'"); + appendPQExpBufferStr(&old_polymorphics, + ", 'array_position(anyarray,anyelement)'" + ", 'array_position(anyarray,anyelement,integer)'" + ", 'array_positions(anyarray,anyelement)'" + ", 'width_bucket(anyelement,anyarray)'"); /* * The query below hardcodes FirstNormalObjectId as 16384 rather than diff --git a/src/bin/pg_upgrade/controldata.c b/src/bin/pg_upgrade/controldata.c index 8f81c9e9582..02ea02df60f 100644 --- a/src/bin/pg_upgrade/controldata.c +++ b/src/bin/pg_upgrade/controldata.c @@ -228,7 +228,7 @@ get_control_data(ClusterInfo *cluster) p++; /* remove ':' char */ cluster->controldata.chkpnt_nxtepoch = str2uint(p); - p = strchr(p, ':'); + p = strchr(p, ':'); if (p == NULL || strlen(p) <= 1) pg_fatal("%d: controldata retrieval problem", __LINE__); diff --git a/src/bin/pg_upgrade/exec.c b/src/bin/pg_upgrade/exec.c index 44355feea30..a1bdbf373e3 100644 --- a/src/bin/pg_upgrade/exec.c +++ b/src/bin/pg_upgrade/exec.c @@ -55,7 +55,7 @@ get_bin_version(ClusterInfo *cluster) if (sscanf(cmd_output, "%*s %*s %d.%d", &v1, &v2) < 1) pg_fatal("could not get pg_ctl version output from %s", cmd); - cluster->bin_version = v1 * 10000; + cluster->bin_version = v1 * 10000; } @@ -344,8 +344,8 @@ check_data_dir(ClusterInfo *cluster) check_single_dir(pg_data, "pg_subtrans"); check_single_dir(pg_data, PG_TBLSPC_DIR); check_single_dir(pg_data, "pg_twophase"); - check_single_dir(pg_data, "pg_wal"); - check_single_dir(pg_data, "pg_xact"); + check_single_dir(pg_data, "pg_wal"); + check_single_dir(pg_data, "pg_xact"); } @@ -385,7 +385,7 @@ check_bin_dir(ClusterInfo *cluster, bool check_versions) */ get_bin_version(cluster); - check_exec(cluster->bindir, "pg_resetwal", check_versions); + check_exec(cluster->bindir, "pg_resetwal", check_versions); if (cluster == &new_cluster) { diff --git a/src/bin/pg_upgrade/multixact_rewrite.c b/src/bin/pg_upgrade/multixact_rewrite.c index c45b3183684..c7a1416494d 100644 --- a/src/bin/pg_upgrade/multixact_rewrite.c +++ b/src/bin/pg_upgrade/multixact_rewrite.c @@ -61,52 +61,52 @@ rewrite_multixacts(MultiXactId from_multi, MultiXactId to_multi) * Convert old multixids, if needed, by reading them one-by-one from the * old cluster. */ - old_reader = AllocOldMultiXactRead(old_cluster.pgdata, - old_cluster.controldata.chkpnt_nxtmulti, - old_cluster.controldata.chkpnt_nxtmxoff); + old_reader = AllocOldMultiXactRead(old_cluster.pgdata, + old_cluster.controldata.chkpnt_nxtmulti, + old_cluster.controldata.chkpnt_nxtmxoff); - for (MultiXactId multi = from_multi; multi != to_multi;) - { - MultiXactMember member; - bool multixid_valid; - - /* - * Read this multixid's members. - * - * Locking-only XIDs that may be part of multi-xids don't matter - * after upgrade, as there can be no transactions running across - * upgrade. So as a small optimization, we only read one member - * from each multixid: the one updating one, or if there was no - * update, arbitrarily the first locking xid. - */ - multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); + for (MultiXactId multi = from_multi; multi != to_multi;) + { + MultiXactMember member; + bool multixid_valid; - /* - * Write the new offset to pg_multixact/offsets. - * - * Even if this multixid is invalid, we still need to write its - * offset if the *previous* multixid was valid. That's because - * when reading a multixid, the number of members is calculated - * from the difference between the two offsets. - */ - RecordMultiXactOffset(offsets_writer, multi, - (multixid_valid || prev_multixid_valid) ? next_offset : 0); + /* + * Read this multixid's members. + * + * Locking-only XIDs that may be part of multi-xids don't matter after + * upgrade, as there can be no transactions running across upgrade. So + * as a small optimization, we only read one member from each + * multixid: the one updating one, or if there was no update, + * arbitrarily the first locking xid. + */ + multixid_valid = GetOldMultiXactIdSingleMember(old_reader, multi, &member); - /* Write the members */ - if (multixid_valid) - { - RecordMultiXactMembers(members_writer, next_offset, 1, &member); - next_offset += 1; - } + /* + * Write the new offset to pg_multixact/offsets. + * + * Even if this multixid is invalid, we still need to write its offset + * if the *previous* multixid was valid. That's because when reading + * a multixid, the number of members is calculated from the difference + * between the two offsets. + */ + RecordMultiXactOffset(offsets_writer, multi, + (multixid_valid || prev_multixid_valid) ? next_offset : 0); - /* Advance to next multixid, handling wraparound */ - multi++; - if (multi < FirstMultiXactId) - multi = FirstMultiXactId; - prev_multixid_valid = multixid_valid; + /* Write the members */ + if (multixid_valid) + { + RecordMultiXactMembers(members_writer, next_offset, 1, &member); + next_offset += 1; } - FreeOldMultiXactReader(old_reader); + /* Advance to next multixid, handling wraparound */ + multi++; + if (multi < FirstMultiXactId) + multi = FirstMultiXactId; + prev_multixid_valid = multixid_valid; + } + + FreeOldMultiXactReader(old_reader); /* Write the final 'next' offset to the last SLRU page */ RecordMultiXactOffset(offsets_writer, to_multi, diff --git a/src/bin/pg_upgrade/pg_upgrade.c b/src/bin/pg_upgrade/pg_upgrade.c index c6af9035665..7366fd4627c 100644 --- a/src/bin/pg_upgrade/pg_upgrade.c +++ b/src/bin/pg_upgrade/pg_upgrade.c @@ -833,7 +833,7 @@ copy_xact_xlog_xid(void) * Determine the range of multixacts to convert. */ nxtmulti = old_cluster.controldata.chkpnt_nxtmulti; - oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; + oldstMulti = old_cluster.controldata.chkpnt_oldstMulti; /* handle wraparound */ if (nxtmulti < FirstMultiXactId) nxtmulti = FirstMultiXactId; @@ -898,15 +898,15 @@ set_frozenxids(void) int i_datname; int i_datallowconn; - prep_status("Setting frozenxid and minmxid counters in new cluster"); + prep_status("Setting frozenxid and minmxid counters in new cluster"); conn_template1 = connectToServer(&new_cluster, "template1"); - /* set pg_database.datfrozenxid */ - PQclear(executeQueryOrDie(conn_template1, - "UPDATE pg_catalog.pg_database " - "SET datfrozenxid = '%u'", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_database.datfrozenxid */ + PQclear(executeQueryOrDie(conn_template1, + "UPDATE pg_catalog.pg_database " + "SET datfrozenxid = '%u'", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_database.datminmxid */ PQclear(executeQueryOrDie(conn_template1, @@ -942,16 +942,16 @@ set_frozenxids(void) conn = connectToServer(&new_cluster, datname); - /* set pg_class.relfrozenxid */ - PQclear(executeQueryOrDie(conn, - "UPDATE pg_catalog.pg_class " - "SET relfrozenxid = '%u' " - /* only heap, materialized view, and TOAST are vacuumed */ - "WHERE relkind IN (" - CppAsString2(RELKIND_RELATION) ", " - CppAsString2(RELKIND_MATVIEW) ", " - CppAsString2(RELKIND_TOASTVALUE) ")", - old_cluster.controldata.chkpnt_nxtxid)); + /* set pg_class.relfrozenxid */ + PQclear(executeQueryOrDie(conn, + "UPDATE pg_catalog.pg_class " + "SET relfrozenxid = '%u' " + /* only heap, materialized view, and TOAST are vacuumed */ + "WHERE relkind IN (" + CppAsString2(RELKIND_RELATION) ", " + CppAsString2(RELKIND_MATVIEW) ", " + CppAsString2(RELKIND_TOASTVALUE) ")", + old_cluster.controldata.chkpnt_nxtxid)); /* set pg_class.relminmxid */ PQclear(executeQueryOrDie(conn, diff --git a/src/bin/pg_upgrade/relfilenumber.c b/src/bin/pg_upgrade/relfilenumber.c index ec2ff7acb21..6c467bdc8a5 100644 --- a/src/bin/pg_upgrade/relfilenumber.c +++ b/src/bin/pg_upgrade/relfilenumber.c @@ -587,32 +587,32 @@ transfer_relfile(FileNameMap *map, const char *type_suffix) /* Copying files might take some time, so give feedback. */ pg_log(PG_STATUS, "%s", old_file); - switch (user_opts.transfer_mode) - { - case TRANSFER_MODE_CLONE: - pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", - old_file, new_file); - cloneFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", - old_file, new_file); - copyFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_COPY_FILE_RANGE: - pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", - old_file, new_file); - copyFileByRange(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_LINK: - pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", - old_file, new_file); - linkFile(old_file, new_file, map->nspname, map->relname); - break; - case TRANSFER_MODE_SWAP: - /* swap mode is handled in its own code path */ - pg_fatal("should never happen"); - break; - } + switch (user_opts.transfer_mode) + { + case TRANSFER_MODE_CLONE: + pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"", + old_file, new_file); + cloneFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"", + old_file, new_file); + copyFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_COPY_FILE_RANGE: + pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range", + old_file, new_file); + copyFileByRange(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_LINK: + pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"", + old_file, new_file); + linkFile(old_file, new_file, map->nspname, map->relname); + break; + case TRANSFER_MODE_SWAP: + /* swap mode is handled in its own code path */ + pg_fatal("should never happen"); + break; + } } } diff --git a/src/bin/pg_upgrade/t/006_transfer_modes.pl b/src/bin/pg_upgrade/t/006_transfer_modes.pl index 9efa5dc863c..360d05c4b68 100644 --- a/src/bin/pg_upgrade/t/006_transfer_modes.pl +++ b/src/bin/pg_upgrade/t/006_transfer_modes.pl @@ -29,10 +29,8 @@ sub test_mode } $new->init(); - $new->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); - $old->append_conf('postgresql.conf', - "allow_in_place_tablespaces = true"); + $new->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); + $old->append_conf('postgresql.conf', "allow_in_place_tablespaces = true"); # We can only test security labels if both the old and new installations # have dummy_seclabel. @@ -76,15 +74,14 @@ sub test_mode "CREATE TABLE test4 AS SELECT generate_series(400, 502)"); } - $old->safe_psql('postgres', - "CREATE TABLESPACE inplc_tblspc LOCATION ''"); - $old->safe_psql('postgres', - "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); - $old->safe_psql('postgres', - "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" - ); - $old->safe_psql('testdb3', - "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); + $old->safe_psql('postgres', "CREATE TABLESPACE inplc_tblspc LOCATION ''"); + $old->safe_psql('postgres', + "CREATE DATABASE testdb3 TABLESPACE inplc_tblspc"); + $old->safe_psql('postgres', + "CREATE TABLE test5 TABLESPACE inplc_tblspc AS SELECT generate_series(503, 606)" + ); + $old->safe_psql('testdb3', + "CREATE TABLE test6 AS SELECT generate_series(607, 711)"); # While we are here, test handling of large objects. $old->safe_psql( @@ -152,12 +149,10 @@ sub test_mode } # Tests for in-place tablespaces. - $result = - $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); - is($result, '104', "test5 data after pg_upgrade $mode"); - $result = - $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); - is($result, '105', "test6 data after pg_upgrade $mode"); + $result = $new->safe_psql('postgres', "SELECT COUNT(*) FROM test5"); + is($result, '104', "test5 data after pg_upgrade $mode"); + $result = $new->safe_psql('testdb3', "SELECT COUNT(*) FROM test6"); + is($result, '105', "test6 data after pg_upgrade $mode"); # Tests for large objects $result = $new->safe_psql('postgres', "SELECT lo_get(4532)"); diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index 44ef11d980e..c90bf8bbde2 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -6278,23 +6278,22 @@ get_create_object_cmd(EditableObjectType obj_type, Oid oid, * ensure the right view gets replaced. Also, check relation kind * to be sure it's a view. * - * Views may have WITH [LOCAL|CASCADED] - * CHECK OPTION. These are not part of the view definition - * returned by pg_get_viewdef() and so need to be retrieved - * separately. Materialized views may have - * arbitrary storage parameter reloptions. + * Views may have WITH [LOCAL|CASCADED] CHECK OPTION. These are + * not part of the view definition returned by pg_get_viewdef() + * and so need to be retrieved separately. Materialized views may + * have arbitrary storage parameter reloptions. */ printfPQExpBuffer(query, "/* %s */\n", _("Get view's definition and details")); - appendPQExpBuffer(query, - "SELECT nspname, relname, relkind, " - "pg_catalog.pg_get_viewdef(c.oid, true), " - "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " - "FROM pg_catalog.pg_class c " - "LEFT JOIN pg_catalog.pg_namespace n " - "ON c.relnamespace = n.oid WHERE c.oid = %u", - oid); + appendPQExpBuffer(query, + "SELECT nspname, relname, relkind, " + "pg_catalog.pg_get_viewdef(c.oid, true), " + "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption " + "FROM pg_catalog.pg_class c " + "LEFT JOIN pg_catalog.pg_namespace n " + "ON c.relnamespace = n.oid WHERE c.oid = %u", + oid); break; } diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index ce99137c613..ac0c55e7aa5 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -387,19 +387,19 @@ describeFunctions(const char *functypes, const char *func_pattern, gettext_noop("stable"), gettext_noop("volatile"), gettext_noop("Volatility")); - appendPQExpBuffer(&buf, - ",\n CASE\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" - " WHEN p.proparallel = " - CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" - " END as \"%s\"", - gettext_noop("restricted"), - gettext_noop("safe"), - gettext_noop("unsafe"), - gettext_noop("Parallel")); + appendPQExpBuffer(&buf, + ",\n CASE\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_RESTRICTED) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n" + " WHEN p.proparallel = " + CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n" + " END as \"%s\"", + gettext_noop("restricted"), + gettext_noop("safe"), + gettext_noop("unsafe"), + gettext_noop("Parallel")); appendPQExpBuffer(&buf, ",\n pg_catalog.pg_get_userbyid(p.proowner) as \"%s\"" ",\n CASE WHEN prosecdef THEN '%s' ELSE '%s' END AS \"%s\"" @@ -599,8 +599,8 @@ describeFunctions(const char *functypes, const char *func_pattern, myopt.title = _("List of functions"); myopt.translate_header = true; - myopt.translate_columns = translate_columns; - myopt.n_translate_columns = lengthof(translate_columns); + myopt.translate_columns = translate_columns; + myopt.n_translate_columns = lengthof(translate_columns); printQuery(res, &myopt, pset.queryFout, false, pset.logfile); @@ -1086,38 +1086,38 @@ permissionsList(const char *pattern, bool showSystem) " ), E'\\n') AS \"%s\"", gettext_noop("Column privileges")); - appendPQExpBuffer(&buf, - ",\n pg_catalog.array_to_string(ARRAY(\n" - " SELECT polname\n" - " || CASE WHEN NOT polpermissive THEN\n" - " E' (RESTRICTIVE)'\n" - " ELSE '' END\n" - " || CASE WHEN polcmd != '*' THEN\n" - " E' (' || polcmd::pg_catalog.text || E'):'\n" - " ELSE E':'\n" - " END\n" - " || CASE WHEN polqual IS NOT NULL THEN\n" - " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" - " ELSE E''\n" - " END\n" - " || CASE WHEN polwithcheck IS NOT NULL THEN\n" - " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" - " ELSE E''\n" - " END" - " || CASE WHEN polroles <> '{0}' THEN\n" - " E'\\n to: ' || pg_catalog.array_to_string(\n" - " ARRAY(\n" - " SELECT rolname\n" - " FROM pg_catalog.pg_roles\n" - " WHERE oid = ANY (polroles)\n" - " ORDER BY 1\n" - " ), E', ')\n" - " ELSE E''\n" - " END\n" - " FROM pg_catalog.pg_policy pol\n" - " WHERE polrelid = c.oid), E'\\n')\n" - " AS \"%s\"", - gettext_noop("Policies")); + appendPQExpBuffer(&buf, + ",\n pg_catalog.array_to_string(ARRAY(\n" + " SELECT polname\n" + " || CASE WHEN NOT polpermissive THEN\n" + " E' (RESTRICTIVE)'\n" + " ELSE '' END\n" + " || CASE WHEN polcmd != '*' THEN\n" + " E' (' || polcmd::pg_catalog.text || E'):'\n" + " ELSE E':'\n" + " END\n" + " || CASE WHEN polqual IS NOT NULL THEN\n" + " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n" + " ELSE E''\n" + " END\n" + " || CASE WHEN polwithcheck IS NOT NULL THEN\n" + " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n" + " ELSE E''\n" + " END" + " || CASE WHEN polroles <> '{0}' THEN\n" + " E'\\n to: ' || pg_catalog.array_to_string(\n" + " ARRAY(\n" + " SELECT rolname\n" + " FROM pg_catalog.pg_roles\n" + " WHERE oid = ANY (polroles)\n" + " ORDER BY 1\n" + " ), E', ')\n" + " ELSE E''\n" + " END\n" + " FROM pg_catalog.pg_policy pol\n" + " WHERE polrelid = c.oid), E'\\n')\n" + " AS \"%s\"", + gettext_noop("Policies")); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_class c\n" " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n" @@ -1675,27 +1675,27 @@ describeOneTableDetails(const char *schemaname, char *footers[3] = {NULL, NULL, NULL}; printfPQExpBuffer(&buf, "/* %s */\n", _("Get sequence information")); - appendPQExpBuffer(&buf, - "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" - " seqstart AS \"%s\",\n" - " seqmin AS \"%s\",\n" - " seqmax AS \"%s\",\n" - " seqincrement AS \"%s\",\n" - " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" - " seqcache AS \"%s\"\n", - gettext_noop("Type"), - gettext_noop("Start"), - gettext_noop("Minimum"), - gettext_noop("Maximum"), - gettext_noop("Increment"), - gettext_noop("yes"), - gettext_noop("no"), - gettext_noop("Cycles?"), - gettext_noop("Cache")); - appendPQExpBuffer(&buf, - "FROM pg_catalog.pg_sequence\n" - "WHERE seqrelid = '%s';", - oid); + appendPQExpBuffer(&buf, + "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" + " seqstart AS \"%s\",\n" + " seqmin AS \"%s\",\n" + " seqmax AS \"%s\",\n" + " seqincrement AS \"%s\",\n" + " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n" + " seqcache AS \"%s\"\n", + gettext_noop("Type"), + gettext_noop("Start"), + gettext_noop("Minimum"), + gettext_noop("Maximum"), + gettext_noop("Increment"), + gettext_noop("yes"), + gettext_noop("no"), + gettext_noop("Cycles?"), + gettext_noop("Cache")); + appendPQExpBuffer(&buf, + "FROM pg_catalog.pg_sequence\n" + "WHERE seqrelid = '%s';", + oid); res = PSQLexec(buf.data); if (!res) @@ -1913,7 +1913,7 @@ describeOneTableDetails(const char *schemaname, appendPQExpBufferStr(&buf, ",\n (SELECT c.collname FROM pg_catalog.pg_collation c, pg_catalog.pg_type t\n" " WHERE c.oid = a.attcollation AND t.oid = a.atttypid AND a.attcollation <> t.typcollation) AS attcollation"); attcoll_col = cols++; - appendPQExpBufferStr(&buf, ",\n a.attidentity"); + appendPQExpBufferStr(&buf, ",\n a.attidentity"); attidentity_col = cols++; if (pset.sversion >= 120000) appendPQExpBufferStr(&buf, ",\n a.attgenerated"); @@ -2326,7 +2326,7 @@ describeOneTableDetails(const char *schemaname, CppAsString2(CONSTRAINT_EXCLUSION) ") AND " "condeferred) AS condeferred,\n"); - appendPQExpBufferStr(&buf, "i.indisreplident,\n"); + appendPQExpBufferStr(&buf, "i.indisreplident,\n"); if (pset.sversion >= 150000) appendPQExpBufferStr(&buf, "i.indnullsnotdistinct,\n"); @@ -2431,7 +2431,7 @@ describeOneTableDetails(const char *schemaname, "pg_catalog.pg_get_indexdef(i.indexrelid, 0, true),\n " "pg_catalog.pg_get_constraintdef(con.oid, true), " "contype, condeferrable, condeferred"); - appendPQExpBufferStr(&buf, ", i.indisreplident"); + appendPQExpBufferStr(&buf, ", i.indisreplident"); appendPQExpBufferStr(&buf, ", c2.reltablespace"); if (pset.sversion >= 180000) appendPQExpBufferStr(&buf, ", con.conperiod"); @@ -2682,81 +2682,80 @@ describeOneTableDetails(const char *schemaname, PQclear(result); /* print any row-level policies */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get row-level policies for this table")); - appendPQExpBufferStr(&buf, "SELECT pol.polname,"); - appendPQExpBufferStr(&buf, - " pol.polpermissive,\n"); - appendPQExpBuffer(&buf, - " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" - " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" - " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" - " CASE pol.polcmd\n" - " WHEN 'r' THEN 'SELECT'\n" - " WHEN 'a' THEN 'INSERT'\n" - " WHEN 'w' THEN 'UPDATE'\n" - " WHEN 'd' THEN 'DELETE'\n" - " END AS cmd\n" - "FROM pg_catalog.pg_policy pol\n" - "WHERE pol.polrelid = '%s' ORDER BY 1;", - oid); + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get row-level policies for this table")); + appendPQExpBufferStr(&buf, "SELECT pol.polname,"); + appendPQExpBufferStr(&buf, + " pol.polpermissive,\n"); + appendPQExpBuffer(&buf, + " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n" + " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n" + " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n" + " CASE pol.polcmd\n" + " WHEN 'r' THEN 'SELECT'\n" + " WHEN 'a' THEN 'INSERT'\n" + " WHEN 'w' THEN 'UPDATE'\n" + " WHEN 'd' THEN 'DELETE'\n" + " END AS cmd\n" + "FROM pg_catalog.pg_policy pol\n" + "WHERE pol.polrelid = '%s' ORDER BY 1;", + oid); - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - /* - * Handle cases where RLS is enabled and there are policies, or - * there aren't policies, or RLS isn't enabled but there are - * policies - */ - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies:")); + /* + * Handle cases where RLS is enabled and there are policies, or there + * aren't policies, or RLS isn't enabled but there are policies + */ + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies:")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled):")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled):")); - if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); + if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (row security enabled): (none)")); - if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) - printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); + if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0) + printTableAddFooter(&cont, _("Policies (forced row security enabled): (none)")); - if (!tableinfo.rowsecurity && tuples > 0) - printTableAddFooter(&cont, _("Policies (row security disabled):")); + if (!tableinfo.rowsecurity && tuples > 0) + printTableAddFooter(&cont, _("Policies (row security disabled):")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " POLICY \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " POLICY \"%s\"", + PQgetvalue(result, i, 0)); - if (*(PQgetvalue(result, i, 1)) == 'f') - appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); + if (*(PQgetvalue(result, i, 1)) == 'f') + appendPQExpBufferStr(&buf, " AS RESTRICTIVE"); - if (!PQgetisnull(result, i, 5)) - appendPQExpBuffer(&buf, " FOR %s", - PQgetvalue(result, i, 5)); + if (!PQgetisnull(result, i, 5)) + appendPQExpBuffer(&buf, " FOR %s", + PQgetvalue(result, i, 5)); - if (!PQgetisnull(result, i, 2)) - { - appendPQExpBuffer(&buf, "\n TO %s", - PQgetvalue(result, i, 2)); - } + if (!PQgetisnull(result, i, 2)) + { + appendPQExpBuffer(&buf, "\n TO %s", + PQgetvalue(result, i, 2)); + } - if (!PQgetisnull(result, i, 3)) - appendPQExpBuffer(&buf, "\n USING (%s)", - PQgetvalue(result, i, 3)); + if (!PQgetisnull(result, i, 3)) + appendPQExpBuffer(&buf, "\n USING (%s)", + PQgetvalue(result, i, 3)); - if (!PQgetisnull(result, i, 4)) - appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", - PQgetvalue(result, i, 4)); + if (!PQgetisnull(result, i, 4)) + appendPQExpBuffer(&buf, "\n WITH CHECK (%s)", + PQgetvalue(result, i, 4)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* print any extended statistics */ if (pset.sversion >= 140000) @@ -3025,115 +3024,115 @@ describeOneTableDetails(const char *schemaname, } /* print any publications */ - printfPQExpBuffer(&buf, "/* %s */\n", - _("Get publications that publish this table")); - if (pset.sversion >= 150000) + printfPQExpBuffer(&buf, "/* %s */\n", + _("Get publications that publish this table")); + if (pset.sversion >= 150000) + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" + " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" + "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" + "UNION\n" + "SELECT pubname\n" + " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" + " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" + " (SELECT pg_catalog.string_agg(attname, ', ')\n" + " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" + " pg_catalog.pg_attribute\n" + " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" + " ELSE NULL END) " + "FROM pg_catalog.pg_publication p\n" + " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" + "WHERE pr.prrelid = '%s'\n", + oid, oid, oid); + + if (pset.sversion >= 190000) { + /* + * Skip entries where this relation appears in the + * publication's EXCEPT list. + */ appendPQExpBuffer(&buf, + " AND NOT pr.prexcept\n" + "UNION\n" "SELECT pubname\n" " , NULL\n" " , NULL\n" "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" - " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n" - "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n" - "UNION\n" - "SELECT pubname\n" - " , pg_catalog.pg_get_expr(pr.prqual, c.oid)\n" - " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n" - " (SELECT pg_catalog.string_agg(attname, ', ')\n" - " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n" - " pg_catalog.pg_attribute\n" - " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n" - " ELSE NULL END) " - "FROM pg_catalog.pg_publication p\n" - " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n" - "WHERE pr.prrelid = '%s'\n", + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + " AND NOT EXISTS (\n" + " SELECT 1\n" + " FROM pg_catalog.pg_publication_rel pr\n" + " WHERE pr.prpubid = p.oid AND\n" + " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" + "ORDER BY 1;", oid, oid, oid); - - if (pset.sversion >= 190000) - { - /* - * Skip entries where this relation appears in the - * publication's EXCEPT list. - */ - appendPQExpBuffer(&buf, - " AND NOT pr.prexcept\n" - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - " AND NOT EXISTS (\n" - " SELECT 1\n" - " FROM pg_catalog.pg_publication_rel pr\n" - " WHERE pr.prpubid = p.oid AND\n" - " (pr.prrelid = '%s' OR pr.prrelid = pg_catalog.pg_partition_root('%s')))\n" - "ORDER BY 1;", - oid, oid, oid); - } - else - { - appendPQExpBuffer(&buf, - "UNION\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" - "ORDER BY 1;", - oid); - } } else { appendPQExpBuffer(&buf, + "UNION\n" "SELECT pubname\n" - " , NULL\n" - " , NULL\n" - "FROM pg_catalog.pg_publication p\n" - "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" - "WHERE pr.prrelid = '%s'\n" - "UNION ALL\n" - "SELECT pubname\n" - " , NULL\n" - " , NULL\n" + " , NULL\n" + " , NULL\n" "FROM pg_catalog.pg_publication p\n" "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" "ORDER BY 1;", - oid, oid); + oid); } + } + else + { + appendPQExpBuffer(&buf, + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" + "WHERE pr.prrelid = '%s'\n" + "UNION ALL\n" + "SELECT pubname\n" + " , NULL\n" + " , NULL\n" + "FROM pg_catalog.pg_publication p\n" + "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n" + "ORDER BY 1;", + oid, oid); + } - result = PSQLexec(buf.data); - if (!result) - goto error_return; - else - tuples = PQntuples(result); + result = PSQLexec(buf.data); + if (!result) + goto error_return; + else + tuples = PQntuples(result); - if (tuples > 0) - printTableAddFooter(&cont, _("Included in publications:")); + if (tuples > 0) + printTableAddFooter(&cont, _("Included in publications:")); - /* Might be an empty set - that's ok */ - for (i = 0; i < tuples; i++) - { - printfPQExpBuffer(&buf, " \"%s\"", - PQgetvalue(result, i, 0)); + /* Might be an empty set - that's ok */ + for (i = 0; i < tuples; i++) + { + printfPQExpBuffer(&buf, " \"%s\"", + PQgetvalue(result, i, 0)); - /* column list (if any) */ - if (!PQgetisnull(result, i, 2)) - appendPQExpBuffer(&buf, " (%s)", - PQgetvalue(result, i, 2)); + /* column list (if any) */ + if (!PQgetisnull(result, i, 2)) + appendPQExpBuffer(&buf, " (%s)", + PQgetvalue(result, i, 2)); - /* row filter (if any) */ - if (!PQgetisnull(result, i, 1)) - appendPQExpBuffer(&buf, " WHERE %s", - PQgetvalue(result, i, 1)); + /* row filter (if any) */ + if (!PQgetisnull(result, i, 1)) + appendPQExpBuffer(&buf, " WHERE %s", + PQgetvalue(result, i, 1)); - printTableAddFooter(&cont, buf.data); - } - PQclear(result); + printTableAddFooter(&cont, buf.data); + } + PQclear(result); /* Print publications where the table is in the EXCEPT clause */ if (pset.sversion >= 190000) @@ -3805,7 +3804,7 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) ncols++; } appendPQExpBufferStr(&buf, "\n, r.rolreplication"); - appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); + appendPQExpBufferStr(&buf, "\n, r.rolbypassrls"); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_roles r\n"); @@ -3860,8 +3859,8 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) if (strcmp(PQgetvalue(res, i, (verbose ? 9 : 8)), "t") == 0) add_role_attribute(&buf, _("Replication")); - if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) - add_role_attribute(&buf, _("Bypass RLS")); + if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0) + add_role_attribute(&buf, _("Bypass RLS")); conns = atoi(PQgetvalue(res, i, 6)); if (conns >= 0) @@ -5155,14 +5154,14 @@ listCollations(const char *pattern, bool verbose, bool showSystem) gettext_noop("Schema"), gettext_noop("Name")); - appendPQExpBuffer(&buf, - " CASE c.collprovider " - "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " - "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " - "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " - "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " - "END AS \"%s\",\n", - gettext_noop("Provider")); + appendPQExpBuffer(&buf, + " CASE c.collprovider " + "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' " + "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' " + "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' " + "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' " + "END AS \"%s\",\n", + gettext_noop("Provider")); appendPQExpBuffer(&buf, " c.collcollate AS \"%s\",\n" -- 2.50.1 (Apple Git-155) --aHl3HfeiUuO3zeNC-- ^ permalink raw reply [nested|flat] 59+ messages in thread
end of thread, other threads:[~2026-06-30 18:24 UTC | newest] Thread overview: 59+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2019-11-08 13:12 [PATCH] Add pg_tablespace_avail() functions Christoph Berg <[email protected]> 2024-09-26 20:03 [PATCH v1 1/1] micro-optimize nbtcompare.c routines Nathan Bossart <[email protected]> 2024-09-26 20:03 [PATCH v1 1/1] micro-optimize nbtcompare.c routines Nathan Bossart <[email protected]> 2026-06-30 18:24 [PATCH v6 4/4] run pgindent and pgperltidy Nathan Bossart <[email protected]> 2026-06-30 18:24 [PATCH v6 4/4] run pgindent and pgperltidy Nathan Bossart <[email protected]> 2026-06-30 18:24 [PATCH v6 4/4] run pgindent and pgperltidy Nathan Bossart <[email protected]> 2026-06-30 18:24 [PATCH v6 4/4] run pgindent and pgperltidy Nathan Bossart <[email protected]> 2026-06-30 18:24 [PATCH v6 4/4] run pgindent and pgperltidy Nathan Bossart <[email protected]> 2026-06-30 18:24 [PATCH v6 4/4] run pgindent and pgperltidy Nathan Bossart <[email protected]> 2026-06-30 18:24 [PATCH v6 4/4] run pgindent and pgperltidy Nathan Bossart <[email protected]> 2026-06-30 18:24 [PATCH v6 4/4] run pgindent and pgperltidy Nathan Bossart <[email protected]> 2026-06-30 18:24 [PATCH v6 4/4] run pgindent and pgperltidy Nathan Bossart <[email protected]> 2026-06-30 18:24 [PATCH v6 4/4] run pgindent and pgperltidy Nathan Bossart <[email protected]> 2026-06-30 18:24 [PATCH v6 4/4] run pgindent and pgperltidy Nathan Bossart <[email protected]> 2026-06-30 18:24 [PATCH v6 4/4] run pgindent and pgperltidy Nathan Bossart <[email protected]> 2026-06-30 18:24 [PATCH v6 4/4] run pgindent and pgperltidy Nathan Bossart <[email protected]> 2026-06-30 18:24 [PATCH v6 4/4] run pgindent and pgperltidy Nathan Bossart <[email protected]> 2026-06-30 18:24 [PATCH v6 4/4] run pgindent and pgperltidy Nathan Bossart <[email protected]> 2026-06-30 18:24 [PATCH v6 4/4] run pgindent and pgperltidy Nathan Bossart <[email protected]> 2026-06-30 18:24 [PATCH v6 4/4] run pgindent and pgperltidy Nathan Bossart <[email protected]> 2026-06-30 18:24 [PATCH v6 4/4] run pgindent and pgperltidy Nathan Bossart <[email protected]> 2026-06-30 18:24 [PATCH v6 4/4] run pgindent and pgperltidy Nathan Bossart <[email protected]> 2026-06-30 18:24 [PATCH v6 4/4] run pgindent and pgperltidy Nathan Bossart <[email protected]> 2026-06-30 18:24 [PATCH v6 4/4] run pgindent and pgperltidy Nathan Bossart <[email protected]> 2026-06-30 18:24 [PATCH v6 4/4] run pgindent and pgperltidy Nathan Bossart <[email protected]> 2026-06-30 18:24 [PATCH v6 4/4] run pgindent and pgperltidy Nathan Bossart <[email protected]> 2026-06-30 18:24 [PATCH v6 4/4] run pgindent and pgperltidy Nathan Bossart <[email protected]> 2026-06-30 18:24 [PATCH v6 4/4] run pgindent and pgperltidy Nathan Bossart <[email protected]> 2026-06-30 18:24 [PATCH v6 4/4] run pgindent and pgperltidy Nathan Bossart <[email protected]> 2026-06-30 18:24 [PATCH v6 4/4] run pgindent and pgperltidy Nathan Bossart <[email protected]> 2026-06-30 18:24 [PATCH v6 4/4] run pgindent and pgperltidy Nathan Bossart <[email protected]> 2026-06-30 18:24 [PATCH v6 4/4] run pgindent and pgperltidy Nathan Bossart <[email protected]> 2026-06-30 18:24 [PATCH v6 4/4] run pgindent and pgperltidy Nathan Bossart <[email protected]> 2026-06-30 18:24 [PATCH v6 4/4] run pgindent and pgperltidy Nathan Bossart <[email protected]> 2026-06-30 18:24 [PATCH v6 4/4] run pgindent and pgperltidy Nathan Bossart <[email protected]> 2026-06-30 18:24 [PATCH v6 4/4] run pgindent and pgperltidy Nathan Bossart <[email protected]> 2026-06-30 18:24 [PATCH v6 4/4] run pgindent and pgperltidy Nathan Bossart <[email protected]> 2026-06-30 18:24 [PATCH v6 4/4] run pgindent and pgperltidy Nathan Bossart <[email protected]> 2026-06-30 18:24 [PATCH v6 4/4] run pgindent and pgperltidy Nathan Bossart <[email protected]> 2026-06-30 18:24 [PATCH v6 4/4] run pgindent and pgperltidy Nathan Bossart <[email protected]> 2026-06-30 18:24 [PATCH v6 4/4] run pgindent and pgperltidy Nathan Bossart <[email protected]> 2026-06-30 18:24 [PATCH v6 4/4] run pgindent and pgperltidy Nathan Bossart <[email protected]> 2026-06-30 18:24 [PATCH v6 4/4] run pgindent and pgperltidy Nathan Bossart <[email protected]> 2026-06-30 18:24 [PATCH v6 4/4] run pgindent and pgperltidy Nathan Bossart <[email protected]> 2026-06-30 18:24 [PATCH v6 4/4] run pgindent and pgperltidy Nathan Bossart <[email protected]> 2026-06-30 18:24 [PATCH v6 4/4] run pgindent and pgperltidy Nathan Bossart <[email protected]> 2026-06-30 18:24 [PATCH v6 4/4] run pgindent and pgperltidy Nathan Bossart <[email protected]> 2026-06-30 18:24 [PATCH v6 4/4] run pgindent and pgperltidy Nathan Bossart <[email protected]> 2026-06-30 18:24 [PATCH v6 4/4] run pgindent and pgperltidy Nathan Bossart <[email protected]> 2026-06-30 18:24 [PATCH v6 4/4] run pgindent and pgperltidy Nathan Bossart <[email protected]> 2026-06-30 18:24 [PATCH v6 4/4] run pgindent and pgperltidy Nathan Bossart <[email protected]> 2026-06-30 18:24 [PATCH v6 4/4] run pgindent and pgperltidy Nathan Bossart <[email protected]> 2026-06-30 18:24 [PATCH v6 4/4] run pgindent and pgperltidy Nathan Bossart <[email protected]> 2026-06-30 18:24 [PATCH v6 4/4] run pgindent and pgperltidy Nathan Bossart <[email protected]> 2026-06-30 18:24 [PATCH v6 4/4] run pgindent and pgperltidy Nathan Bossart <[email protected]> 2026-06-30 18:24 [PATCH v6 4/4] run pgindent and pgperltidy Nathan Bossart <[email protected]> 2026-06-30 18:24 [PATCH v6 4/4] run pgindent and pgperltidy Nathan Bossart <[email protected]> 2026-06-30 18:24 [PATCH v6 4/4] run pgindent and pgperltidy Nathan Bossart <[email protected]> 2026-06-30 18:24 [PATCH v6 4/4] run pgindent and pgperltidy Nathan Bossart <[email protected]>
This inbox is served by agora; see mirroring instructions for how to clone and mirror all data and code used for this inbox