@@ -158,9 +158,9 @@ GetBTPageStatistics(BlockNumber blkno, Buffer buffer, BTPageStat *stat)
158158}
159159
160160/* -----------------------------------------------
161- *bt_page ()
161+ *bt_page_stats ()
162162 *
163- * Usage: SELECT * FROMbt_page ('t1_pkey', 1);
163+ * Usage: SELECT * FROMbt_page_stats ('t1_pkey', 1);
164164 * -----------------------------------------------
165165 */
166166Datum
@@ -206,13 +206,17 @@ bt_page_stats(PG_FUNCTION_ARGS)
206206CHECK_RELATION_BLOCK_RANGE (rel ,blkno );
207207
208208buffer = ReadBuffer (rel ,blkno );
209+ LockBuffer (buffer ,BUFFER_LOCK_SHARE );
209210
210211/* keep compiler quiet */
211212stat .btpo_prev = stat .btpo_next = InvalidBlockNumber ;
212213stat .btpo_flags = stat .free_size = stat .avg_item_size = 0 ;
213214
214215GetBTPageStatistics (blkno ,buffer ,& stat );
215216
217+ UnlockReleaseBuffer (buffer );
218+ relation_close (rel ,AccessShareLock );
219+
216220/* Build a tuple descriptor for our result type */
217221if (get_call_result_type (fcinfo ,NULL ,& tupleDesc )!= TYPEFUNC_COMPOSITE )
218222elog (ERROR ,"return type must be a row type" );
@@ -249,10 +253,6 @@ bt_page_stats(PG_FUNCTION_ARGS)
249253
250254result = HeapTupleGetDatum (tuple );
251255
252- ReleaseBuffer (buffer );
253-
254- relation_close (rel ,AccessShareLock );
255-
256256PG_RETURN_DATUM (result );
257257}
258258
@@ -324,6 +324,7 @@ bt_page_items(PG_FUNCTION_ARGS)
324324CHECK_RELATION_BLOCK_RANGE (rel ,blkno );
325325
326326buffer = ReadBuffer (rel ,blkno );
327+ LockBuffer (buffer ,BUFFER_LOCK_SHARE );
327328
328329/*
329330 * We copy the page into local storage to avoid holding pin on the
@@ -337,7 +338,7 @@ bt_page_items(PG_FUNCTION_ARGS)
337338uargs -> page = palloc (BLCKSZ );
338339memcpy (uargs -> page ,BufferGetPage (buffer ),BLCKSZ );
339340
340- ReleaseBuffer (buffer );
341+ UnlockReleaseBuffer (buffer );
341342relation_close (rel ,AccessShareLock );
342343
343344uargs -> offset = FirstOffsetNumber ;
@@ -468,6 +469,8 @@ bt_metap(PG_FUNCTION_ARGS)
468469errmsg ("cannot access temporary tables of other sessions" )));
469470
470471buffer = ReadBuffer (rel ,0 );
472+ LockBuffer (buffer ,BUFFER_LOCK_SHARE );
473+
471474page = BufferGetPage (buffer );
472475metad = BTPageGetMeta (page );
473476
@@ -494,8 +497,7 @@ bt_metap(PG_FUNCTION_ARGS)
494497
495498result = HeapTupleGetDatum (tuple );
496499
497- ReleaseBuffer (buffer );
498-
500+ UnlockReleaseBuffer (buffer );
499501relation_close (rel ,AccessShareLock );
500502
501503PG_RETURN_DATUM (result );