@@ -154,9 +154,9 @@ GetBTPageStatistics(BlockNumber blkno, Buffer buffer, BTPageStat * stat)
154
154
}
155
155
156
156
/* -----------------------------------------------
157
- * bt_page ()
157
+ * bt_page_stats ()
158
158
*
159
- * Usage: SELECT * FROM bt_page ('t1_pkey', 1);
159
+ * Usage: SELECT * FROM bt_page_stats ('t1_pkey', 1);
160
160
* -----------------------------------------------
161
161
*/
162
162
Datum
@@ -202,13 +202,17 @@ bt_page_stats(PG_FUNCTION_ARGS)
202
202
CHECK_RELATION_BLOCK_RANGE (rel , blkno );
203
203
204
204
buffer = ReadBuffer (rel , blkno );
205
+ LockBuffer (buffer , BUFFER_LOCK_SHARE );
205
206
206
207
/* keep compiler quiet */
207
208
stat .btpo_prev = stat .btpo_next = InvalidBlockNumber ;
208
209
stat .btpo_flags = stat .free_size = stat .avg_item_size = 0 ;
209
210
210
211
GetBTPageStatistics (blkno , buffer , & stat );
211
212
213
+ UnlockReleaseBuffer (buffer );
214
+ relation_close (rel , AccessShareLock );
215
+
212
216
/* Build a tuple descriptor for our result type */
213
217
if (get_call_result_type (fcinfo , NULL , & tupleDesc ) != TYPEFUNC_COMPOSITE )
214
218
elog (ERROR , "return type must be a row type" );
@@ -245,10 +249,6 @@ bt_page_stats(PG_FUNCTION_ARGS)
245
249
246
250
result = HeapTupleGetDatum (tuple );
247
251
248
- ReleaseBuffer (buffer );
249
-
250
- relation_close (rel , AccessShareLock );
251
-
252
252
PG_RETURN_DATUM (result );
253
253
}
254
254
@@ -320,6 +320,7 @@ bt_page_items(PG_FUNCTION_ARGS)
320
320
CHECK_RELATION_BLOCK_RANGE (rel , blkno );
321
321
322
322
buffer = ReadBuffer (rel , blkno );
323
+ LockBuffer (buffer , BUFFER_LOCK_SHARE );
323
324
324
325
/*
325
326
* We copy the page into local storage to avoid holding pin on the
@@ -333,7 +334,7 @@ bt_page_items(PG_FUNCTION_ARGS)
333
334
uargs -> page = palloc (BLCKSZ );
334
335
memcpy (uargs -> page , BufferGetPage (buffer ), BLCKSZ );
335
336
336
- ReleaseBuffer (buffer );
337
+ UnlockReleaseBuffer (buffer );
337
338
relation_close (rel , AccessShareLock );
338
339
339
340
uargs -> offset = FirstOffsetNumber ;
@@ -464,6 +465,8 @@ bt_metap(PG_FUNCTION_ARGS)
464
465
errmsg ("cannot access temporary tables of other sessions" )));
465
466
466
467
buffer = ReadBuffer (rel , 0 );
468
+ LockBuffer (buffer , BUFFER_LOCK_SHARE );
469
+
467
470
page = BufferGetPage (buffer );
468
471
metad = BTPageGetMeta (page );
469
472
@@ -490,8 +493,7 @@ bt_metap(PG_FUNCTION_ARGS)
490
493
491
494
result = HeapTupleGetDatum (tuple );
492
495
493
- ReleaseBuffer (buffer );
494
-
496
+ UnlockReleaseBuffer (buffer );
495
497
relation_close (rel , AccessShareLock );
496
498
497
499
PG_RETURN_DATUM (result );
0 commit comments