Skip to content

Commit bbe1921

Browse files
authored
Upgrade pg_wrapper to PostgreSQL 14.3 (#6334)
1 parent 3c3738a commit bbe1921

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+13854
-12901
lines changed

ydb/library/yql/parser/pg_wrapper/copy_src.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env bash
22
set -eu
33

4-
VERSION="14.2"
4+
VERSION="14.3"
55

66
errexit() {
77
echo $1

ydb/library/yql/parser/pg_wrapper/postgresql/src/backend/access/brin/brin.c

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1007,6 +1007,9 @@ brin_summarize_range(PG_FUNCTION_ARGS)
10071007
Oid heapoid;
10081008
Relation indexRel;
10091009
Relation heapRel;
1010+
Oid save_userid;
1011+
int save_sec_context;
1012+
int save_nestlevel;
10101013
double numSummarized = 0;
10111014

10121015
if (RecoveryInProgress())
@@ -1033,7 +1036,22 @@ brin_summarize_range(PG_FUNCTION_ARGS)
10331036
*/
10341037
heapoid = IndexGetRelation(indexoid, true);
10351038
if (OidIsValid(heapoid))
1039+
{
10361040
heapRel = table_open(heapoid, ShareUpdateExclusiveLock);
1041+
1042+
/*
1043+
* Autovacuum calls us. For its benefit, switch to the table owner's
1044+
* userid, so that any index functions are run as that user. Also
1045+
* lock down security-restricted operations and arrange to make GUC
1046+
* variable changes local to this command. This is harmless, albeit
1047+
* unnecessary, when called from SQL, because we fail shortly if the
1048+
* user does not own the index.
1049+
*/
1050+
GetUserIdAndSecContext(&save_userid, &save_sec_context);
1051+
SetUserIdAndSecContext(heapRel->rd_rel->relowner,
1052+
save_sec_context | SECURITY_RESTRICTED_OPERATION);
1053+
save_nestlevel = NewGUCNestLevel();
1054+
}
10371055
else
10381056
heapRel = NULL;
10391057

@@ -1048,7 +1066,7 @@ brin_summarize_range(PG_FUNCTION_ARGS)
10481066
RelationGetRelationName(indexRel))));
10491067

10501068
/* User must own the index (comparable to privileges needed for VACUUM) */
1051-
if (!pg_class_ownercheck(indexoid, GetUserId()))
1069+
if (heapRel != NULL && !pg_class_ownercheck(indexoid, save_userid))
10521070
aclcheck_error(ACLCHECK_NOT_OWNER, OBJECT_INDEX,
10531071
RelationGetRelationName(indexRel));
10541072

@@ -1066,6 +1084,12 @@ brin_summarize_range(PG_FUNCTION_ARGS)
10661084
/* OK, do it */
10671085
brinsummarize(indexRel, heapRel, heapBlk, true, &numSummarized, NULL);
10681086

1087+
/* Roll back any GUC changes executed by index functions */
1088+
AtEOXact_GUC(false, save_nestlevel);
1089+
1090+
/* Restore userid and security context */
1091+
SetUserIdAndSecContext(save_userid, save_sec_context);
1092+
10691093
relation_close(indexRel, ShareUpdateExclusiveLock);
10701094
relation_close(heapRel, ShareUpdateExclusiveLock);
10711095

@@ -1107,6 +1131,9 @@ brin_desummarize_range(PG_FUNCTION_ARGS)
11071131
* passed indexoid isn't an index then IndexGetRelation() will fail.
11081132
* Rather than emitting a not-very-helpful error message, postpone
11091133
* complaining, expecting that the is-it-an-index test below will fail.
1134+
*
1135+
* Unlike brin_summarize_range(), autovacuum never calls this. Hence, we
1136+
* don't switch userid.
11101137
*/
11111138
heapoid = IndexGetRelation(indexoid, true);
11121139
if (OidIsValid(heapoid))

ydb/library/yql/parser/pg_wrapper/postgresql/src/backend/access/gist/gistbuild.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,21 @@ gist_indexsortbuild(GISTBuildState *state)
461461

462462
pfree(pagestate->page);
463463
pfree(pagestate);
464+
465+
/*
466+
* When we WAL-logged index pages, we must nonetheless fsync index files.
467+
* Since we're building outside shared buffers, a CHECKPOINT occurring
468+
* during the build has no way to flush the previously written data to
469+
* disk (indeed it won't know the index even exists). A crash later on
470+
* would replay WAL from the checkpoint, therefore it wouldn't replay our
471+
* earlier WAL entries. If we do not fsync those pages here, they might
472+
* still not be on disk when the crash occurs.
473+
*/
474+
if (RelationNeedsWAL(state->indexrel))
475+
{
476+
RelationOpenSmgr(state->indexrel);
477+
smgrimmedsync(state->indexrel->rd_smgr, MAIN_FORKNUM);
478+
}
464479
}
465480

466481
/*

0 commit comments

Comments
 (0)