Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit cabefd5

Browse files
committed
Fix pg_prewarm and pg_buffercache extensions
1 parent b2a3d70 commit cabefd5

File tree

28 files changed

+254
-95
lines changed

28 files changed

+254
-95
lines changed

contrib/pg_buffercache/pg_buffercache_pages.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,9 @@ pg_buffercache_pages(PG_FUNCTION_ARGS)
153153
buf_state = LockBufHdr(bufHdr);
154154

155155
fctx->record[i].bufferid = BufferDescriptorGetBuffer(bufHdr);
156-
fctx->record[i].relfilenode = bufHdr->tag.rnode.relNode;
157-
fctx->record[i].reltablespace = bufHdr->tag.rnode.spcNode;
158-
fctx->record[i].reldatabase = bufHdr->tag.rnode.dbNode;
156+
fctx->record[i].relfilenode = bufHdr->tag.rnode.node.relNode;
157+
fctx->record[i].reltablespace = bufHdr->tag.rnode.node.spcNode;
158+
fctx->record[i].reldatabase = bufHdr->tag.rnode.node.dbNode;
159159
fctx->record[i].forknum = bufHdr->tag.forkNum;
160160
fctx->record[i].blocknum = bufHdr->tag.blockNum;
161161
fctx->record[i].usagecount = BUF_STATE_GET_USAGECOUNT(buf_state);

contrib/pg_prewarm/autoprewarm.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -608,9 +608,9 @@ apw_dump_now(bool is_bgworker, bool dump_unlogged)
608608
if (buf_state & BM_TAG_VALID &&
609609
((buf_state & BM_PERMANENT) || dump_unlogged))
610610
{
611-
block_info_array[num_blocks].database = bufHdr->tag.rnode.dbNode;
612-
block_info_array[num_blocks].tablespace = bufHdr->tag.rnode.spcNode;
613-
block_info_array[num_blocks].filenode = bufHdr->tag.rnode.relNode;
611+
block_info_array[num_blocks].database = bufHdr->tag.rnode.node.dbNode;
612+
block_info_array[num_blocks].tablespace = bufHdr->tag.rnode.node.spcNode;
613+
block_info_array[num_blocks].filenode = bufHdr->tag.rnode.node.relNode;
614614
block_info_array[num_blocks].forknum = bufHdr->tag.forkNum;
615615
block_info_array[num_blocks].blocknum = bufHdr->tag.blockNum;
616616
++num_blocks;

src/backend/access/gin/ginxlog.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,13 @@ ginRedoInsertEntry(Buffer buffer, bool isLeaf, BlockNumber rightblkno, void *rda
9595

9696
if (PageAddItem(page, (Item) itup, IndexTupleSize(itup), offset, false, false) == InvalidOffsetNumber)
9797
{
98-
RelFileNode node;
98+
RelFileNodeBackend rnode;
9999
ForkNumber forknum;
100100
BlockNumber blknum;
101101

102-
BufferGetTag(buffer, &node, &forknum, &blknum);
102+
BufferGetTag(buffer, &rnode, &forknum, &blknum);
103103
elog(ERROR, "failed to add item to index page in %u/%u/%u",
104-
node.spcNode, node.dbNode, node.relNode);
104+
rnode.node.spcNode, rnode.node.dbNode, rnode.node.relNode);
105105
}
106106
}
107107

src/backend/access/heap/heapam_handler.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,7 @@ heapam_relation_copy_data(Relation rel, const RelFileNode *newrnode)
671671
* init fork of an unlogged relation.
672672
*/
673673
if (rel->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT ||
674+
rel->rd_rel->relpersistence == RELPERSISTENCE_SESSION ||
674675
(rel->rd_rel->relpersistence == RELPERSISTENCE_UNLOGGED &&
675676
forkNum == INIT_FORKNUM))
676677
log_smgrcreate(newrnode, forkNum);

src/backend/access/nbtree/nbtpage.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,11 @@ _bt_getbuf(Relation rel, BlockNumber blkno, int access)
763763
/* Read an existing block of the relation */
764764
buf = ReadBuffer(rel, blkno);
765765
LockBuffer(buf, access);
766-
_bt_checkpage(rel, buf);
766+
/* Session temporary relation may be not yet initialized for this backend. */
767+
if (blkno == BTREE_METAPAGE && PageIsNew(BufferGetPage(buf)) && IsSessionRelationBackendId(rel->rd_backend))
768+
_bt_initmetapage(BufferGetPage(buf), P_NONE, 0);
769+
else
770+
_bt_checkpage(rel, buf);
767771
}
768772
else
769773
{

src/backend/access/transam/xloginsert.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ void
213213
XLogRegisterBuffer(uint8 block_id, Buffer buffer, uint8 flags)
214214
{
215215
registered_buffer *regbuf;
216+
RelFileNodeBackend rnode;
216217

217218
/* NO_IMAGE doesn't make sense with FORCE_IMAGE */
218219
Assert(!((flags & REGBUF_FORCE_IMAGE) && (flags & (REGBUF_NO_IMAGE))));
@@ -227,7 +228,8 @@ XLogRegisterBuffer(uint8 block_id, Buffer buffer, uint8 flags)
227228

228229
regbuf = &registered_buffers[block_id];
229230

230-
BufferGetTag(buffer, &regbuf->rnode, &regbuf->forkno, &regbuf->block);
231+
BufferGetTag(buffer, &rnode, &regbuf->forkno, &regbuf->block);
232+
regbuf->rnode = rnode.node;
231233
regbuf->page = BufferGetPage(buffer);
232234
regbuf->flags = flags;
233235
regbuf->rdata_tail = (XLogRecData *) &regbuf->rdata_head;
@@ -919,7 +921,7 @@ XLogSaveBufferForHint(Buffer buffer, bool buffer_std)
919921
int flags;
920922
PGAlignedBlock copied_buffer;
921923
char *origdata = (char *) BufferGetBlock(buffer);
922-
RelFileNode rnode;
924+
RelFileNodeBackend rnode;
923925
ForkNumber forkno;
924926
BlockNumber blkno;
925927

@@ -948,7 +950,7 @@ XLogSaveBufferForHint(Buffer buffer, bool buffer_std)
948950
flags |= REGBUF_STANDARD;
949951

950952
BufferGetTag(buffer, &rnode, &forkno, &blkno);
951-
XLogRegisterBlock(0, &rnode, forkno, blkno, copied_buffer.data, flags);
953+
XLogRegisterBlock(0, &rnode.node, forkno, blkno, copied_buffer.data, flags);
952954

953955
recptr = XLogInsert(RM_XLOG_ID, XLOG_FPI_FOR_HINT);
954956
}
@@ -1009,7 +1011,7 @@ XLogRecPtr
10091011
log_newpage_buffer(Buffer buffer, bool page_std)
10101012
{
10111013
Page page = BufferGetPage(buffer);
1012-
RelFileNode rnode;
1014+
RelFileNodeBackend rnode;
10131015
ForkNumber forkNum;
10141016
BlockNumber blkno;
10151017

@@ -1018,7 +1020,7 @@ log_newpage_buffer(Buffer buffer, bool page_std)
10181020

10191021
BufferGetTag(buffer, &rnode, &forkNum, &blkno);
10201022

1021-
return log_newpage(&rnode, forkNum, blkno, page, page_std);
1023+
return log_newpage(&rnode.node, forkNum, blkno, page, page_std);
10221024
}
10231025

10241026
/*

src/backend/catalog/catalog.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,9 @@ GetNewRelFileNode(Oid reltablespace, Relation pg_class, char relpersistence)
409409
case RELPERSISTENCE_TEMP:
410410
backend = BackendIdForTempRelations();
411411
break;
412+
case RELPERSISTENCE_SESSION:
413+
backend = BackendIdForSessionRelations();
414+
break;
412415
case RELPERSISTENCE_UNLOGGED:
413416
case RELPERSISTENCE_PERMANENT:
414417
backend = InvalidBackendId;

src/backend/catalog/index.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3612,7 +3612,7 @@ reindex_relation(Oid relid, int flags, int options)
36123612
if (flags & REINDEX_REL_FORCE_INDEXES_UNLOGGED)
36133613
persistence = RELPERSISTENCE_UNLOGGED;
36143614
else if (flags & REINDEX_REL_FORCE_INDEXES_PERMANENT)
3615-
persistence = RELPERSISTENCE_PERMANENT;
3615+
persistence = rel->rd_rel->relpersistence == RELPERSISTENCE_SESSION ? RELPERSISTENCE_SESSION : RELPERSISTENCE_PERMANENT;
36163616
else
36173617
persistence = rel->rd_rel->relpersistence;
36183618

src/backend/catalog/storage.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ RelationCreateStorage(RelFileNode rnode, char relpersistence)
9393
backend = InvalidBackendId;
9494
needs_wal = false;
9595
break;
96+
case RELPERSISTENCE_SESSION:
97+
backend = BackendIdForSessionRelations();
98+
needs_wal = false;
99+
break;
96100
case RELPERSISTENCE_PERMANENT:
97101
backend = InvalidBackendId;
98102
needs_wal = true;

src/backend/commands/cluster.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1400,7 +1400,7 @@ finish_heap_swap(Oid OIDOldHeap, Oid OIDNewHeap,
14001400
*/
14011401
if (newrelpersistence == RELPERSISTENCE_UNLOGGED)
14021402
reindex_flags |= REINDEX_REL_FORCE_INDEXES_UNLOGGED;
1403-
else if (newrelpersistence == RELPERSISTENCE_PERMANENT)
1403+
else if (newrelpersistence != RELPERSISTENCE_TEMP)
14041404
reindex_flags |= REINDEX_REL_FORCE_INDEXES_PERMANENT;
14051405

14061406
/* Report that we are now reindexing relations */

src/backend/commands/tablecmds.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7678,6 +7678,12 @@ ATAddForeignKeyConstraint(List **wqueue, AlteredTableInfo *tab, Relation rel,
76787678
(errcode(ERRCODE_INVALID_TABLE_DEFINITION),
76797679
errmsg("constraints on unlogged tables may reference only permanent or unlogged tables")));
76807680
break;
7681+
case RELPERSISTENCE_SESSION:
7682+
if (pkrel->rd_rel->relpersistence != RELPERSISTENCE_SESSION)
7683+
ereport(ERROR,
7684+
(errcode(ERRCODE_INVALID_TABLE_DEFINITION),
7685+
errmsg("constraints on session tables may reference only session tables")));
7686+
break;
76817687
case RELPERSISTENCE_TEMP:
76827688
if (pkrel->rd_rel->relpersistence != RELPERSISTENCE_TEMP)
76837689
ereport(ERROR,
@@ -14082,6 +14088,13 @@ ATPrepChangePersistence(Relation rel, bool toLogged)
1408214088
RelationGetRelationName(rel)),
1408314089
errtable(rel)));
1408414090
break;
14091+
case RELPERSISTENCE_SESSION:
14092+
ereport(ERROR,
14093+
(errcode(ERRCODE_INVALID_TABLE_DEFINITION),
14094+
errmsg("cannot change logged status of session table \"%s\"",
14095+
RelationGetRelationName(rel)),
14096+
errtable(rel)));
14097+
break;
1408514098
case RELPERSISTENCE_PERMANENT:
1408614099
if (toLogged)
1408714100
/* nothing to do */

src/backend/parser/gram.y

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3265,20 +3265,11 @@ OptTemp: TEMPORARY { $$ = RELPERSISTENCE_TEMP; }
32653265
| TEMP { $$ = RELPERSISTENCE_TEMP; }
32663266
| LOCAL TEMPORARY { $$ = RELPERSISTENCE_TEMP; }
32673267
| LOCAL TEMP { $$ = RELPERSISTENCE_TEMP; }
3268-
| GLOBAL TEMPORARY
3269-
{
3270-
ereport(WARNING,
3271-
(errmsg("GLOBAL is deprecated in temporary table creation"),
3272-
parser_errposition(@1)));
3273-
$$ = RELPERSISTENCE_TEMP;
3274-
}
3275-
| GLOBAL TEMP
3276-
{
3277-
ereport(WARNING,
3278-
(errmsg("GLOBAL is deprecated in temporary table creation"),
3279-
parser_errposition(@1)));
3280-
$$ = RELPERSISTENCE_TEMP;
3281-
}
3268+
| GLOBAL TEMPORARY { $$ = RELPERSISTENCE_SESSION; }
3269+
| GLOBAL TEMP { $$ = RELPERSISTENCE_SESSION; }
3270+
| SESSION { $$ = RELPERSISTENCE_SESSION; }
3271+
| SESSION TEMPORARY { $$ = RELPERSISTENCE_SESSION; }
3272+
| SESSION TEMP { $$ = RELPERSISTENCE_SESSION; }
32823273
| UNLOGGED { $$ = RELPERSISTENCE_UNLOGGED; }
32833274
| /*EMPTY*/ { $$ = RELPERSISTENCE_PERMANENT; }
32843275
;

src/backend/replication/logical/reorderbuffer.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3483,6 +3483,7 @@ ResolveCminCmaxDuringDecoding(HTAB *tuplecid_data,
34833483
{
34843484
ReorderBufferTupleCidKey key;
34853485
ReorderBufferTupleCidEnt *ent;
3486+
RelFileNodeBackend rnode;
34863487
ForkNumber forkno;
34873488
BlockNumber blockno;
34883489
bool updated_mapping = false;
@@ -3496,7 +3497,8 @@ ResolveCminCmaxDuringDecoding(HTAB *tuplecid_data,
34963497
* get relfilenode from the buffer, no convenient way to access it other
34973498
* than that.
34983499
*/
3499-
BufferGetTag(buffer, &key.relnode, &forkno, &blockno);
3500+
BufferGetTag(buffer, &rnode, &forkno, &blockno);
3501+
key.relnode = rnode.node;
35003502

35013503
/* tuples can only be in the main fork */
35023504
Assert(forkno == MAIN_FORKNUM);

0 commit comments

Comments
 (0)