Skip to content

Commit e6f1e42

Browse files
MMeenttristan957
authored andcommitted
Patch PostgreSQL v16 with squashed patchset
This prepares PostgreSQL for compatibility with Neon's storage. Significant changes compared to the PostgreSQL 15 patchset include: - Backported changes for users and roles are no longer required - Use RM_NEON_ID for changes in WAL, instead of modifying core WAL records
1 parent b78fa85 commit e6f1e42

Some content is hidden

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

84 files changed

+3755
-516
lines changed

configure

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,7 @@ with_libxml
711711
with_uuid
712712
with_readline
713713
with_systemd
714+
with_libseccomp
714715
with_selinux
715716
with_ldap
716717
with_krb_srvnam
@@ -861,6 +862,7 @@ with_bsd_auth
861862
with_ldap
862863
with_bonjour
863864
with_selinux
865+
with_libseccomp
864866
with_systemd
865867
with_readline
866868
with_libedit_preferred
@@ -1571,6 +1573,7 @@ Optional Packages:
15711573
--with-ldap build with LDAP support
15721574
--with-bonjour build with Bonjour support
15731575
--with-selinux build with SELinux support
1576+
--with-libseccomp build with libseccomp support
15741577
--with-systemd build with systemd support
15751578
--without-readline do not use GNU Readline nor BSD Libedit for editing
15761579
--with-libedit-preferred
@@ -8868,6 +8871,39 @@ fi
88688871
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $with_selinux" >&5
88698872
$as_echo "$with_selinux" >&6; }
88708873

8874+
#
8875+
# libseccomp
8876+
#
8877+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to build with libseccomp support" >&5
8878+
$as_echo_n "checking whether to build with libseccomp support... " >&6; }
8879+
8880+
8881+
8882+
# Check whether --with-libseccomp was given.
8883+
if test "${with_libseccomp+set}" = set; then :
8884+
withval=$with_libseccomp;
8885+
case $withval in
8886+
yes)
8887+
:
8888+
;;
8889+
no)
8890+
:
8891+
;;
8892+
*)
8893+
as_fn_error $? "no argument expected for --with-libseccomp option" "$LINENO" 5
8894+
;;
8895+
esac
8896+
8897+
else
8898+
with_libseccomp=no
8899+
8900+
fi
8901+
8902+
8903+
8904+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $with_libseccomp" >&5
8905+
$as_echo "$with_libseccomp" >&6; }
8906+
88718907
#
88728908
# Systemd
88738909
#
@@ -14350,6 +14386,56 @@ else
1435014386
fi
1435114387

1435214388

14389+
fi
14390+
14391+
if test "$with_libseccomp" = yes ; then
14392+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for seccomp_init in -lseccomp" >&5
14393+
$as_echo_n "checking for seccomp_init in -lseccomp... " >&6; }
14394+
if ${ac_cv_lib_seccomp_seccomp_init+:} false; then :
14395+
$as_echo_n "(cached) " >&6
14396+
else
14397+
ac_check_lib_save_LIBS=$LIBS
14398+
LIBS="-lseccomp $LIBS"
14399+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
14400+
/* end confdefs.h. */
14401+
14402+
/* Override any GCC internal prototype to avoid an error.
14403+
Use char because int might match the return type of a GCC
14404+
builtin and then its argument prototype would still apply. */
14405+
#ifdef __cplusplus
14406+
extern "C"
14407+
#endif
14408+
char seccomp_init ();
14409+
int
14410+
main ()
14411+
{
14412+
return seccomp_init ();
14413+
;
14414+
return 0;
14415+
}
14416+
_ACEOF
14417+
if ac_fn_c_try_link "$LINENO"; then :
14418+
ac_cv_lib_seccomp_seccomp_init=yes
14419+
else
14420+
ac_cv_lib_seccomp_seccomp_init=no
14421+
fi
14422+
rm -f core conftest.err conftest.$ac_objext \
14423+
conftest$ac_exeext conftest.$ac_ext
14424+
LIBS=$ac_check_lib_save_LIBS
14425+
fi
14426+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_seccomp_seccomp_init" >&5
14427+
$as_echo "$ac_cv_lib_seccomp_seccomp_init" >&6; }
14428+
if test "x$ac_cv_lib_seccomp_seccomp_init" = xyes; then :
14429+
cat >>confdefs.h <<_ACEOF
14430+
#define HAVE_LIBSECCOMP 1
14431+
_ACEOF
14432+
14433+
LIBS="-lseccomp $LIBS"
14434+
14435+
else
14436+
as_fn_error $? "library 'libseccomp' is required for Seccomp BPF support" "$LINENO" 5
14437+
fi
14438+
1435314439
fi
1435414440

1435514441
# for contrib/uuid-ossp

configure.ac

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -972,6 +972,14 @@ PGAC_ARG_BOOL(with, selinux, no, [build with SELinux support])
972972
AC_SUBST(with_selinux)
973973
AC_MSG_RESULT([$with_selinux])
974974

975+
#
976+
# libseccomp
977+
#
978+
AC_MSG_CHECKING([whether to build with libseccomp support])
979+
PGAC_ARG_BOOL(with, libseccomp, no, [build with libseccomp support])
980+
AC_SUBST(with_libseccomp)
981+
AC_MSG_RESULT([$with_libseccomp])
982+
975983
#
976984
# Systemd
977985
#
@@ -1624,6 +1632,11 @@ dnl If you want to use Apple's own Bonjour code on another platform,
16241632
dnl just add -ldns_sd to LIBS manually.
16251633
fi
16261634

1635+
if test "$with_libseccomp" = yes ; then
1636+
AC_CHECK_LIB(seccomp, seccomp_init, [],
1637+
[AC_MSG_ERROR([library 'libseccomp' is required for Seccomp BPF support])])
1638+
fi
1639+
16271640
# for contrib/uuid-ossp
16281641
if test "$with_uuid" = bsd ; then
16291642
AC_CHECK_HEADERS(uuid.h,

contrib/pg_prewarm/autoprewarm.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@
5454
#include "utils/rel.h"
5555
#include "utils/relfilenumbermap.h"
5656
#include "utils/resowner.h"
57+
#include "utils/spccache.h"
58+
5759

5860
#define AUTOPREWARM_FILE "autoprewarm.blocks"
5961

@@ -448,10 +450,12 @@ void
448450
autoprewarm_database_main(Datum main_arg)
449451
{
450452
int pos;
453+
int io_concurrency;
451454
BlockInfoRecord *block_info;
452455
Relation rel = NULL;
453456
BlockNumber nblocks = 0;
454457
BlockInfoRecord *old_blk = NULL;
458+
BlockInfoRecord *prefetch_blk = NULL;
455459
dsm_segment *seg;
456460

457461
/* Establish signal handlers; once that's done, unblock signals. */
@@ -498,6 +502,7 @@ autoprewarm_database_main(Datum main_arg)
498502
{
499503
relation_close(rel, AccessShareLock);
500504
rel = NULL;
505+
io_concurrency = -1;
501506
CommitTransactionCommand();
502507
}
503508

@@ -517,6 +522,8 @@ autoprewarm_database_main(Datum main_arg)
517522

518523
if (!rel)
519524
CommitTransactionCommand();
525+
else
526+
io_concurrency = get_tablespace_maintenance_io_concurrency(rel->rd_rel->reltablespace);
520527
}
521528
if (!rel)
522529
{
@@ -549,6 +556,35 @@ autoprewarm_database_main(Datum main_arg)
549556
continue;
550557
}
551558

559+
/* if prefetching is enabled for this relation */
560+
if (io_concurrency > 0)
561+
{
562+
/* make prefetch_blk catch up */
563+
if (blk > prefetch_blk)
564+
{
565+
prefetch_blk = blk;
566+
}
567+
568+
/* now, prefetch all following blocks */
569+
while (prefetch_blk <= &block_info[apw_state->prewarm_stop_idx])
570+
{
571+
/* unless they're of a different relfilenode */
572+
if (prefetch_blk->filenumber != blk->filenumber ||
573+
prefetch_blk->forknum != blk->forknum ||
574+
prefetch_blk->blocknum >= nblocks)
575+
break;
576+
577+
/* or unless they are more than io_concurrency blocks ahead */
578+
if (blk + io_concurrency <= prefetch_blk)
579+
break;
580+
581+
PrefetchBuffer(rel, prefetch_blk->forknum, prefetch_blk->blocknum);
582+
583+
/* continue with the next block */
584+
prefetch_blk++;
585+
}
586+
}
587+
552588
/* Prewarm buffer. */
553589
buf = ReadBufferExtended(rel, blk->forknum, blk->blocknum, RBM_NORMAL,
554590
NULL);

contrib/pg_prewarm/pg_prewarm.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@
1818
#include "access/relation.h"
1919
#include "fmgr.h"
2020
#include "miscadmin.h"
21+
#include "optimizer/cost.h"
2122
#include "storage/bufmgr.h"
2223
#include "storage/smgr.h"
2324
#include "utils/acl.h"
2425
#include "utils/builtins.h"
2526
#include "utils/lsyscache.h"
2627
#include "utils/rel.h"
28+
#include "utils/spccache.h"
2729

2830
PG_MODULE_MAGIC;
2931

@@ -183,14 +185,26 @@ pg_prewarm(PG_FUNCTION_ARGS)
183185
}
184186
else if (ptype == PREWARM_BUFFER)
185187
{
188+
BlockNumber prefetch_block = first_block;
189+
Oid nspOid;
190+
int io_concurrency;
191+
192+
nspOid = rel->rd_rel->reltablespace;
193+
io_concurrency = get_tablespace_maintenance_io_concurrency(nspOid);
194+
186195
/*
187196
* In buffer mode, we actually pull the data into shared_buffers.
188197
*/
189198
for (block = first_block; block <= last_block; ++block)
190199
{
191-
Buffer buf;
192-
200+
Buffer buf;
201+
BlockNumber prefetch_stop = block + Min(last_block - block + 1,
202+
io_concurrency);
193203
CHECK_FOR_INTERRUPTS();
204+
while (prefetch_block < prefetch_stop)
205+
{
206+
PrefetchBuffer(rel, forkNumber, prefetch_block++);
207+
}
194208
buf = ReadBufferExtended(rel, forkNumber, block, RBM_NORMAL, NULL);
195209
ReleaseBuffer(buf);
196210
++blocks_done;

contrib/pg_prewarm/pg_prewarm.control

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ comment = 'prewarm relation data'
33
default_version = '1.2'
44
module_pathname = '$libdir/pg_prewarm'
55
relocatable = true
6+
trusted = true

contrib/pg_walinspect/pg_walinspect.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ GetWALBlockInfo(FunctionCallInfo fcinfo, XLogReaderState *record,
271271
{
272272
DecodedBkpBlock *blk;
273273
BlockNumber blkno;
274-
RelFileLocator rnode;
274+
RelFileLocator rlocator;
275275
ForkNumber forknum;
276276
Datum values[PG_GET_WAL_BLOCK_INFO_COLS] = {0};
277277
bool nulls[PG_GET_WAL_BLOCK_INFO_COLS] = {0};
@@ -286,7 +286,7 @@ GetWALBlockInfo(FunctionCallInfo fcinfo, XLogReaderState *record,
286286
blk = XLogRecGetBlock(record, block_id);
287287

288288
(void) XLogRecGetBlockTagExtended(record, block_id,
289-
&rnode, &forknum, &blkno, NULL);
289+
&rlocator, &forknum, &blkno, NULL);
290290

291291
/* Save block_data_len */
292292
if (blk->has_data)

src/Makefile.global.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ with_tcl = @with_tcl@
186186
with_ssl = @with_ssl@
187187
with_readline = @with_readline@
188188
with_selinux = @with_selinux@
189+
with_libseccomp = @with_libseccomp@
189190
with_systemd = @with_systemd@
190191
with_gssapi = @with_gssapi@
191192
with_krb_srvnam = @with_krb_srvnam@

src/backend/access/brin/brin_xlog.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ brin_xlog_insert_update(XLogReaderState *record,
6969
}
7070

7171
/* need this page's blkno to store in revmap */
72-
regpgno = BufferGetBlockNumber(buffer);
72+
//ZENITH XXX Don't use BufferGetBlockNumber because wal-redo doesn't pin buffer.
73+
XLogRecGetBlockTag(record, 0, NULL, NULL, &regpgno);
7374

7475
/* insert the index item into the page */
7576
if (action == BLK_NEEDS_REDO)

src/backend/access/gin/gininsert.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,8 @@ ginbuild(Relation heap, Relation index, IndexInfo *indexInfo)
335335
elog(ERROR, "index \"%s\" already contains data",
336336
RelationGetRelationName(index));
337337

338+
smgr_start_unlogged_build(index->rd_smgr);
339+
338340
initGinState(&buildstate.ginstate, index);
339341
buildstate.indtuples = 0;
340342
memset(&buildstate.buildStats, 0, sizeof(GinStatsData));
@@ -408,6 +410,8 @@ ginbuild(Relation heap, Relation index, IndexInfo *indexInfo)
408410
buildstate.buildStats.nTotalPages = RelationGetNumberOfBlocks(index);
409411
ginUpdateStats(index, &buildstate.buildStats, true);
410412

413+
smgr_finish_unlogged_build_phase_1(index->rd_smgr);
414+
411415
/*
412416
* We didn't write WAL records as we built the index, so if WAL-logging is
413417
* required, write all pages to the WAL now.
@@ -417,8 +421,12 @@ ginbuild(Relation heap, Relation index, IndexInfo *indexInfo)
417421
log_newpage_range(index, MAIN_FORKNUM,
418422
0, RelationGetNumberOfBlocks(index),
419423
true);
424+
SetLastWrittenLSNForBlockRange(XactLastRecEnd, index->rd_smgr->smgr_rlocator.locator, MAIN_FORKNUM, 0, RelationGetNumberOfBlocks(index));
425+
SetLastWrittenLSNForRelation(XactLastRecEnd, index->rd_smgr->smgr_rlocator.locator, MAIN_FORKNUM);
420426
}
421427

428+
smgr_end_unlogged_build(index->rd_smgr);
429+
422430
/*
423431
* Return statistics
424432
*/

src/backend/access/gin/ginxlog.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,7 @@ ginRedoSplit(XLogReaderState *record)
407407
rootbuf;
408408
bool isLeaf = (data->flags & GIN_INSERT_ISLEAF) != 0;
409409
bool isRoot = (data->flags & GIN_SPLIT_ROOT) != 0;
410+
XLogRedoAction action;
410411

411412
/*
412413
* First clear incomplete-split flag on child page if this finishes a
@@ -415,21 +416,27 @@ ginRedoSplit(XLogReaderState *record)
415416
if (!isLeaf)
416417
ginRedoClearIncompleteSplit(record, 3);
417418

418-
if (XLogReadBufferForRedo(record, 0, &lbuffer) != BLK_RESTORED)
419+
action = XLogReadBufferForRedo(record, 0, &lbuffer);
420+
if (action != BLK_RESTORED && action != BLK_DONE)
419421
elog(ERROR, "GIN split record did not contain a full-page image of left page");
420422

421-
if (XLogReadBufferForRedo(record, 1, &rbuffer) != BLK_RESTORED)
423+
action = XLogReadBufferForRedo(record, 1, &rbuffer);
424+
if (action != BLK_RESTORED && action != BLK_DONE)
422425
elog(ERROR, "GIN split record did not contain a full-page image of right page");
423426

424427
if (isRoot)
425428
{
426-
if (XLogReadBufferForRedo(record, 2, &rootbuf) != BLK_RESTORED)
429+
action = XLogReadBufferForRedo(record, 2, &rootbuf);
430+
if (action != BLK_RESTORED && action != BLK_DONE)
427431
elog(ERROR, "GIN split record did not contain a full-page image of root page");
428-
UnlockReleaseBuffer(rootbuf);
432+
if (rootbuf != InvalidBuffer)
433+
UnlockReleaseBuffer(rootbuf);
429434
}
430435

431-
UnlockReleaseBuffer(rbuffer);
432-
UnlockReleaseBuffer(lbuffer);
436+
if (rbuffer != InvalidBuffer)
437+
UnlockReleaseBuffer(rbuffer);
438+
if (lbuffer != InvalidBuffer)
439+
UnlockReleaseBuffer(lbuffer);
433440
}
434441

435442
/*

0 commit comments

Comments
 (0)