@@ -156,9 +156,9 @@ GetBTPageStatistics(BlockNumber blkno, Buffer buffer, BTPageStat *stat)
156156}
157157
158158/* -----------------------------------------------
159- *bt_page ()
159+ *bt_page_stats ()
160160 *
161- * Usage: SELECT * FROMbt_page ('t1_pkey', 1);
161+ * Usage: SELECT * FROMbt_page_stats ('t1_pkey', 1);
162162 * -----------------------------------------------
163163 */
164164Datum
@@ -204,13 +204,17 @@ bt_page_stats(PG_FUNCTION_ARGS)
204204CHECK_RELATION_BLOCK_RANGE (rel ,blkno );
205205
206206buffer = ReadBuffer (rel ,blkno );
207+ LockBuffer (buffer ,BUFFER_LOCK_SHARE );
207208
208209/* keep compiler quiet */
209210stat .btpo_prev = stat .btpo_next = InvalidBlockNumber ;
210211stat .btpo_flags = stat .free_size = stat .avg_item_size = 0 ;
211212
212213GetBTPageStatistics (blkno ,buffer ,& stat );
213214
215+ UnlockReleaseBuffer (buffer );
216+ relation_close (rel ,AccessShareLock );
217+
214218/* Build a tuple descriptor for our result type */
215219if (get_call_result_type (fcinfo ,NULL ,& tupleDesc )!= TYPEFUNC_COMPOSITE )
216220elog (ERROR ,"return type must be a row type" );
@@ -247,10 +251,6 @@ bt_page_stats(PG_FUNCTION_ARGS)
247251
248252result = HeapTupleGetDatum (tuple );
249253
250- ReleaseBuffer (buffer );
251-
252- relation_close (rel ,AccessShareLock );
253-
254254PG_RETURN_DATUM (result );
255255}
256256
@@ -322,6 +322,7 @@ bt_page_items(PG_FUNCTION_ARGS)
322322CHECK_RELATION_BLOCK_RANGE (rel ,blkno );
323323
324324buffer = ReadBuffer (rel ,blkno );
325+ LockBuffer (buffer ,BUFFER_LOCK_SHARE );
325326
326327/*
327328 * We copy the page into local storage to avoid holding pin on the
@@ -335,7 +336,7 @@ bt_page_items(PG_FUNCTION_ARGS)
335336uargs -> page = palloc (BLCKSZ );
336337memcpy (uargs -> page ,BufferGetPage (buffer ),BLCKSZ );
337338
338- ReleaseBuffer (buffer );
339+ UnlockReleaseBuffer (buffer );
339340relation_close (rel ,AccessShareLock );
340341
341342uargs -> offset = FirstOffsetNumber ;
@@ -466,6 +467,8 @@ bt_metap(PG_FUNCTION_ARGS)
466467errmsg ("cannot access temporary tables of other sessions" )));
467468
468469buffer = ReadBuffer (rel ,0 );
470+ LockBuffer (buffer ,BUFFER_LOCK_SHARE );
471+
469472page = BufferGetPage (buffer );
470473metad = BTPageGetMeta (page );
471474
@@ -492,8 +495,7 @@ bt_metap(PG_FUNCTION_ARGS)
492495
493496result = HeapTupleGetDatum (tuple );
494497
495- ReleaseBuffer (buffer );
496-
498+ UnlockReleaseBuffer (buffer );
497499relation_close (rel ,AccessShareLock );
498500
499501PG_RETURN_DATUM (result );