Skip to content

Commit bdbee68

Browse files
committed
Apply CORE-190, pg_buffercache patch
1 parent 597873d commit bdbee68

File tree

5 files changed

+18
-24
lines changed

5 files changed

+18
-24
lines changed

contrib/pg_buffercache/Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ MODULE_big = pg_buffercache
44
OBJS = pg_buffercache_pages.o $(WIN32RES)
55

66
EXTENSION = pg_buffercache
7-
DATA = pg_buffercache--1.2.sql pg_buffercache--1.1--1.2.sql \
8-
pg_buffercache--1.0--1.1.sql pg_buffercache--unpackaged--1.0.sql
7+
DATA = pg_buffercache--1.3.sql pg_buffercache--1.2--1.3.sql \
8+
pg_buffercache--1.1--1.2.sql pg_buffercache--1.0--1.1.sql \
9+
pg_buffercache--unpackaged--1.0.sql
910
PGFILEDESC = "pg_buffercache - monitoring of shared buffer cache in real-time"
1011

1112
ifdef USE_PGXS
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/* contrib/pg_buffercache/pg_buffercache--1.2--1.3.sql */
2+
3+
-- complain if script is sourced in psql, rather than via ALTER EXTENSION
4+
\echo Use "ALTER EXTENSION pg_buffercache(text) UPDATE TO '1.3'" to load this file. \quit
5+
6+
ALTER FUNCTION pg_buffercache_pages() PARALLEL SAFE;

contrib/pg_buffercache/pg_buffercache--1.2.sql renamed to contrib/pg_buffercache/pg_buffercache--1.3.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* contrib/pg_buffercache/pg_buffercache--1.2.sql */
1+
/* contrib/pg_buffercache/pg_buffercache--1.3.sql */
22

33
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
44
\echo Use "CREATE EXTENSION pg_buffercache" to load this file. \quit
@@ -18,4 +18,4 @@ CREATE VIEW pg_buffercache AS
1818

1919
-- Don't want these to be available to public.
2020
REVOKE ALL ON FUNCTION pg_buffercache_pages() FROM PUBLIC;
21-
REVOKE ALL ON pg_buffercache FROM PUBLIC;
21+
REVOKE ALL ON pg_buffercache FROM PUBLIC;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# pg_buffercache extension
22
comment = 'examine the shared buffer cache'
3-
default_version = '1.2'
3+
default_version = '1.3'
44
module_pathname = '$libdir/pg_buffercache'
55
relocatable = true

contrib/pg_buffercache/pg_buffercache_pages.c

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -135,15 +135,6 @@ pg_buffercache_pages(PG_FUNCTION_ARGS)
135135
/* Return to original context when allocating transient memory */
136136
MemoryContextSwitchTo(oldcontext);
137137

138-
/*
139-
* To get a consistent picture of the buffer state, we must lock all
140-
* partitions of the buffer map. Needless to say, this is horrible
141-
* for concurrency. Must grab locks in increasing order to avoid
142-
* possible deadlocks.
143-
*/
144-
for (i = 0; i < NUM_BUFFER_PARTITIONS; i++)
145-
LWLockAcquire(BufMappingPartitionLockByIndex(i), LW_SHARED);
146-
147138
/*
148139
* Scan through all the buffers, saving the relevant fields in the
149140
* fctx->record structure.
@@ -154,6 +145,12 @@ pg_buffercache_pages(PG_FUNCTION_ARGS)
154145
uint32 buf_state;
155146

156147
bufHdr = GetBufferDescriptor(i);
148+
if (bufHdr->tag.forkNum == -1)
149+
{
150+
fctx->record[i].blocknum = InvalidBlockNumber;
151+
continue;
152+
}
153+
157154
/* Lock each buffer header before inspecting. */
158155
buf_state = LockBufHdr(bufHdr);
159156

@@ -179,16 +176,6 @@ pg_buffercache_pages(PG_FUNCTION_ARGS)
179176

180177
UnlockBufHdr(bufHdr, buf_state);
181178
}
182-
183-
/*
184-
* And release locks. We do this in reverse order for two reasons:
185-
* (1) Anyone else who needs more than one of the locks will be trying
186-
* to lock them in increasing order; we don't want to release the
187-
* other process until it can get all the locks it needs. (2) This
188-
* avoids O(N^2) behavior inside LWLockRelease.
189-
*/
190-
for (i = NUM_BUFFER_PARTITIONS; --i >= 0;)
191-
LWLockRelease(BufMappingPartitionLockByIndex(i));
192179
}
193180

194181
funcctx = SRF_PERCALL_SETUP();

0 commit comments

Comments
 (0)