mirror of
https://github.com/postgres/postgres.git
synced 2025-07-20 05:03:10 +03:00
Don't prematurely free the BufferAccessStrategy in pgstat_heap().
This function continued to use it after heap_endscan() freed it. In passing, don't explicit create a strategy here. Instead, use the one created by heap_beginscan_strat(), if any. Back-patch to 9.2, where use of a BufferAccessStrategy here was introduced.
This commit is contained in:
@ -274,7 +274,6 @@ pgstat_heap(Relation rel, FunctionCallInfo fcinfo)
|
|||||||
BlockNumber tupblock;
|
BlockNumber tupblock;
|
||||||
Buffer buffer;
|
Buffer buffer;
|
||||||
pgstattuple_type stat = {0};
|
pgstattuple_type stat = {0};
|
||||||
BufferAccessStrategy bstrategy;
|
|
||||||
SnapshotData SnapshotDirty;
|
SnapshotData SnapshotDirty;
|
||||||
|
|
||||||
/* Disable syncscan because we assume we scan from block zero upwards */
|
/* Disable syncscan because we assume we scan from block zero upwards */
|
||||||
@ -283,10 +282,6 @@ pgstat_heap(Relation rel, FunctionCallInfo fcinfo)
|
|||||||
|
|
||||||
nblocks = scan->rs_nblocks; /* # blocks to be scanned */
|
nblocks = scan->rs_nblocks; /* # blocks to be scanned */
|
||||||
|
|
||||||
/* prepare access strategy for this table */
|
|
||||||
bstrategy = GetAccessStrategy(BAS_BULKREAD);
|
|
||||||
scan->rs_strategy = bstrategy;
|
|
||||||
|
|
||||||
/* scan the relation */
|
/* scan the relation */
|
||||||
while ((tuple = heap_getnext(scan, ForwardScanDirection)) != NULL)
|
while ((tuple = heap_getnext(scan, ForwardScanDirection)) != NULL)
|
||||||
{
|
{
|
||||||
@ -320,26 +315,28 @@ pgstat_heap(Relation rel, FunctionCallInfo fcinfo)
|
|||||||
{
|
{
|
||||||
CHECK_FOR_INTERRUPTS();
|
CHECK_FOR_INTERRUPTS();
|
||||||
|
|
||||||
buffer = ReadBufferExtended(rel, MAIN_FORKNUM, block, RBM_NORMAL, bstrategy);
|
buffer = ReadBufferExtended(rel, MAIN_FORKNUM, block,
|
||||||
|
RBM_NORMAL, scan->rs_strategy);
|
||||||
LockBuffer(buffer, BUFFER_LOCK_SHARE);
|
LockBuffer(buffer, BUFFER_LOCK_SHARE);
|
||||||
stat.free_space += PageGetHeapFreeSpace((Page) BufferGetPage(buffer));
|
stat.free_space += PageGetHeapFreeSpace((Page) BufferGetPage(buffer));
|
||||||
UnlockReleaseBuffer(buffer);
|
UnlockReleaseBuffer(buffer);
|
||||||
block++;
|
block++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
heap_endscan(scan);
|
|
||||||
|
|
||||||
while (block < nblocks)
|
while (block < nblocks)
|
||||||
{
|
{
|
||||||
CHECK_FOR_INTERRUPTS();
|
CHECK_FOR_INTERRUPTS();
|
||||||
|
|
||||||
buffer = ReadBufferExtended(rel, MAIN_FORKNUM, block, RBM_NORMAL, bstrategy);
|
buffer = ReadBufferExtended(rel, MAIN_FORKNUM, block,
|
||||||
|
RBM_NORMAL, scan->rs_strategy);
|
||||||
LockBuffer(buffer, BUFFER_LOCK_SHARE);
|
LockBuffer(buffer, BUFFER_LOCK_SHARE);
|
||||||
stat.free_space += PageGetHeapFreeSpace((Page) BufferGetPage(buffer));
|
stat.free_space += PageGetHeapFreeSpace((Page) BufferGetPage(buffer));
|
||||||
UnlockReleaseBuffer(buffer);
|
UnlockReleaseBuffer(buffer);
|
||||||
block++;
|
block++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
heap_endscan(scan);
|
||||||
relation_close(rel, AccessShareLock);
|
relation_close(rel, AccessShareLock);
|
||||||
|
|
||||||
stat.table_len = (uint64) nblocks *BLCKSZ;
|
stat.table_len = (uint64) nblocks *BLCKSZ;
|
||||||
|
Reference in New Issue
Block a user