@@ -158,9 +158,9 @@ GetBTPageStatistics(BlockNumber blkno, Buffer buffer, BTPageStat *stat)
158
158
}
159
159
160
160
/* -----------------------------------------------
161
- *bt_page ()
161
+ *bt_page_stats ()
162
162
*
163
- * Usage: SELECT * FROMbt_page ('t1_pkey', 1);
163
+ * Usage: SELECT * FROMbt_page_stats ('t1_pkey', 1);
164
164
* -----------------------------------------------
165
165
*/
166
166
Datum
@@ -206,13 +206,17 @@ bt_page_stats(PG_FUNCTION_ARGS)
206
206
CHECK_RELATION_BLOCK_RANGE (rel ,blkno );
207
207
208
208
buffer = ReadBuffer (rel ,blkno );
209
+ LockBuffer (buffer ,BUFFER_LOCK_SHARE );
209
210
210
211
/* keep compiler quiet */
211
212
stat .btpo_prev = stat .btpo_next = InvalidBlockNumber ;
212
213
stat .btpo_flags = stat .free_size = stat .avg_item_size = 0 ;
213
214
214
215
GetBTPageStatistics (blkno ,buffer ,& stat );
215
216
217
+ UnlockReleaseBuffer (buffer );
218
+ relation_close (rel ,AccessShareLock );
219
+
216
220
/* Build a tuple descriptor for our result type */
217
221
if (get_call_result_type (fcinfo ,NULL ,& tupleDesc )!= TYPEFUNC_COMPOSITE )
218
222
elog (ERROR ,"return type must be a row type" );
@@ -249,10 +253,6 @@ bt_page_stats(PG_FUNCTION_ARGS)
249
253
250
254
result = HeapTupleGetDatum (tuple );
251
255
252
- ReleaseBuffer (buffer );
253
-
254
- relation_close (rel ,AccessShareLock );
255
-
256
256
PG_RETURN_DATUM (result );
257
257
}
258
258
@@ -324,6 +324,7 @@ bt_page_items(PG_FUNCTION_ARGS)
324
324
CHECK_RELATION_BLOCK_RANGE (rel ,blkno );
325
325
326
326
buffer = ReadBuffer (rel ,blkno );
327
+ LockBuffer (buffer ,BUFFER_LOCK_SHARE );
327
328
328
329
/*
329
330
* We copy the page into local storage to avoid holding pin on the
@@ -337,7 +338,7 @@ bt_page_items(PG_FUNCTION_ARGS)
337
338
uargs -> page = palloc (BLCKSZ );
338
339
memcpy (uargs -> page ,BufferGetPage (buffer ),BLCKSZ );
339
340
340
- ReleaseBuffer (buffer );
341
+ UnlockReleaseBuffer (buffer );
341
342
relation_close (rel ,AccessShareLock );
342
343
343
344
uargs -> offset = FirstOffsetNumber ;
@@ -468,6 +469,8 @@ bt_metap(PG_FUNCTION_ARGS)
468
469
errmsg ("cannot access temporary tables of other sessions" )));
469
470
470
471
buffer = ReadBuffer (rel ,0 );
472
+ LockBuffer (buffer ,BUFFER_LOCK_SHARE );
473
+
471
474
page = BufferGetPage (buffer );
472
475
metad = BTPageGetMeta (page );
473
476
@@ -494,8 +497,7 @@ bt_metap(PG_FUNCTION_ARGS)
494
497
495
498
result = HeapTupleGetDatum (tuple );
496
499
497
- ReleaseBuffer (buffer );
498
-
500
+ UnlockReleaseBuffer (buffer );
499
501
relation_close (rel ,AccessShareLock );
500
502
501
503
PG_RETURN_DATUM (result );