Skip to content

Commit bae4759

Browse files
author
Commitfest Bot
committed
[CF 5319] Changing shared_buffers without restart
This branch was automatically generated by a robot using patches from an email thread registered at: https://commitfest.postgresql.org/patch/5319 The branch will be overwritten each time a new patch version is posted to the thread, and also periodically to check for bitrot caused by changes on the master branch. Patch(es): https://www.postgresql.org/message-id/CAExHW5vB8sAmDtkEN5dcYYeBok3D8eAzMFCOH1k+krxht1yFjA@mail.gmail.com Author(s): Dmitry Dolgov
2 parents 74b41f5 + adf52ae commit bae4759

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+2538
-361
lines changed

doc/src/sgml/system-views.sgml

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@
7171
<entry>backend memory contexts</entry>
7272
</row>
7373

74+
<row>
75+
<entry><link linkend="view-pg-buffer-lookup-table"><structname>pg_buffer_lookup_table</structname></link></entry>
76+
<entry>shared buffer lookup table</entry>
77+
</row>
78+
7479
<row>
7580
<entry><link linkend="view-pg-config"><structname>pg_config</structname></link></entry>
7681
<entry>compile-time configuration parameters</entry>
@@ -896,6 +901,90 @@ AND c1.path[c2.level] = c2.path[c2.level];
896901
</para>
897902
</sect1>
898903

904+
<sect1 id="view-pg-buffer-lookup-table">
905+
<title><structname>pg_buffer_lookup_table</structname></title>
906+
<indexterm>
907+
<primary>pg_buffer_lookup_table</primary>
908+
</indexterm>
909+
<para>
910+
The <structname>pg_buffer_lookup_table</structname> view exposes the current
911+
contents of the shared buffer lookup table. Each row represents an entry in
912+
the lookup table mapping a relation page to the ID of buffer in which it is
913+
cached. The shared buffer lookup table is locked for a short duration while
914+
reading so as to ensure consistency. This may affect performance if this view
915+
is queried very frequently.
916+
</para>
917+
<table id="pg-buffer-lookup-table-view" xreflabel="pg_buffer_lookup_table">
918+
<title><structname>pg_buffer_lookup_table</structname> View</title>
919+
<tgroup cols="1">
920+
<thead>
921+
<row>
922+
<entry role="catalog_table_entry"><para role="column_definition">
923+
Column Type
924+
</para>
925+
<para>
926+
Description
927+
</para></entry>
928+
</row>
929+
</thead>
930+
<tbody>
931+
<row>
932+
<entry role="catalog_table_entry"><para role="column_definition">
933+
<structfield>tablespace</structfield> <type>oid</type>
934+
</para>
935+
<para>
936+
OID of the tablespace containing the relation
937+
</para></entry>
938+
</row>
939+
<row>
940+
<entry role="catalog_table_entry"><para role="column_definition">
941+
<structfield>database</structfield> <type>oid</type>
942+
</para>
943+
<para>
944+
OID of the database containing the relation (zero for shared relations)
945+
</para></entry>
946+
</row>
947+
<row>
948+
<entry role="catalog_table_entry"><para role="column_definition">
949+
<structfield>relfilenode</structfield> <type>oid</type>
950+
</para>
951+
<para>
952+
relfilenode identifying the relation
953+
</para></entry>
954+
</row>
955+
<row>
956+
<entry role="catalog_table_entry"><para role="column_definition">
957+
<structfield>forknum</structfield> <type>int2</type>
958+
</para>
959+
<para>
960+
Fork number within the relation (see <xref linkend="storage-file-layout"/>)
961+
</para></entry>
962+
</row>
963+
<row>
964+
<entry role="catalog_table_entry"><para role="column_definition">
965+
<structfield>blocknum</structfield> <type>int8</type>
966+
</para>
967+
<para>
968+
Block number within the relation
969+
</para></entry>
970+
</row>
971+
<row>
972+
<entry role="catalog_table_entry"><para role="column_definition">
973+
<structfield>bufferid</structfield> <type>int4</type>
974+
</para>
975+
<para>
976+
ID of the buffer caching the page
977+
</para></entry>
978+
</row>
979+
</tbody>
980+
</tgroup>
981+
</table>
982+
<para>
983+
Access to this view is restricted to members of the
984+
<literal>pg_read_all_stats</literal> role by default.
985+
</para>
986+
</sect1>
987+
899988
<sect1 id="view-pg-config">
900989
<title><structname>pg_config</structname></title>
901990

@@ -4078,6 +4167,15 @@ SELECT * FROM pg_locks pl LEFT JOIN pg_prepared_xacts ppx
40784167
</para></entry>
40794168
</row>
40804169

4170+
<row>
4171+
<entry role="catalog_table_entry"><para role="column_definition">
4172+
<structfield>segment</structfield> <type>text</type>
4173+
</para>
4174+
<para>
4175+
The name of the shared memory segment concerning the allocation.
4176+
</para></entry>
4177+
</row>
4178+
40814179
<row>
40824180
<entry role="catalog_table_entry"><para role="column_definition">
40834181
<structfield>off</structfield> <type>int8</type>

src/backend/access/transam/xlog.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2197,7 +2197,7 @@ CalculateCheckpointSegments(void)
21972197
}
21982198

21992199
void
2200-
assign_max_wal_size(int newval, void *extra)
2200+
assign_max_wal_size(int newval, void *extra, bool *pending)
22012201
{
22022202
max_wal_size_mb = newval;
22032203
CalculateCheckpointSegments();

src/backend/catalog/system_views.sql

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,13 @@ GRANT SELECT ON pg_shmem_allocations TO pg_read_all_stats;
658658
REVOKE EXECUTE ON FUNCTION pg_get_shmem_allocations() FROM PUBLIC;
659659
GRANT EXECUTE ON FUNCTION pg_get_shmem_allocations() TO pg_read_all_stats;
660660

661+
CREATE VIEW pg_shmem_segments AS
662+
SELECT * FROM pg_get_shmem_segments();
663+
664+
REVOKE ALL ON pg_shmem_segments FROM PUBLIC;
665+
GRANT SELECT ON pg_shmem_segments TO pg_read_all_stats;
666+
REVOKE EXECUTE ON FUNCTION pg_get_shmem_segments() FROM PUBLIC;
667+
GRANT EXECUTE ON FUNCTION pg_get_shmem_segments() TO pg_read_all_stats;
661668
CREATE VIEW pg_shmem_allocations_numa AS
662669
SELECT * FROM pg_get_shmem_allocations_numa();
663670

@@ -1420,3 +1427,10 @@ REVOKE ALL ON pg_aios FROM PUBLIC;
14201427
GRANT SELECT ON pg_aios TO pg_read_all_stats;
14211428
REVOKE EXECUTE ON FUNCTION pg_get_aios() FROM PUBLIC;
14221429
GRANT EXECUTE ON FUNCTION pg_get_aios() TO pg_read_all_stats;
1430+
1431+
CREATE VIEW pg_buffer_lookup_table AS
1432+
SELECT * FROM pg_get_buffer_lookup_table();
1433+
REVOKE ALL ON pg_buffer_lookup_table FROM PUBLIC;
1434+
GRANT SELECT ON pg_buffer_lookup_table TO pg_read_all_stats;
1435+
REVOKE EXECUTE ON FUNCTION pg_get_buffer_lookup_table() FROM PUBLIC;
1436+
GRANT EXECUTE ON FUNCTION pg_get_buffer_lookup_table() TO pg_read_all_stats;

src/backend/commands/variable.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,7 +1143,7 @@ check_cluster_name(char **newval, void **extra, GucSource source)
11431143
* GUC assign_hook for maintenance_io_concurrency
11441144
*/
11451145
void
1146-
assign_maintenance_io_concurrency(int newval, void *extra)
1146+
assign_maintenance_io_concurrency(int newval, void *extra, bool *pending)
11471147
{
11481148
/*
11491149
* Reconfigure recovery prefetching, because a setting it depends on
@@ -1161,12 +1161,12 @@ assign_maintenance_io_concurrency(int newval, void *extra)
11611161
* they may be assigned in either order.
11621162
*/
11631163
void
1164-
assign_io_max_combine_limit(int newval, void *extra)
1164+
assign_io_max_combine_limit(int newval, void *extra, bool *pending)
11651165
{
11661166
io_combine_limit = Min(newval, io_combine_limit_guc);
11671167
}
11681168
void
1169-
assign_io_combine_limit(int newval, void *extra)
1169+
assign_io_combine_limit(int newval, void *extra, bool *pending)
11701170
{
11711171
io_combine_limit = Min(io_max_combine_limit, newval);
11721172
}

src/backend/libpq/pqcomm.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1951,7 +1951,7 @@ pq_settcpusertimeout(int timeout, Port *port)
19511951
* GUC assign_hook for tcp_keepalives_idle
19521952
*/
19531953
void
1954-
assign_tcp_keepalives_idle(int newval, void *extra)
1954+
assign_tcp_keepalives_idle(int newval, void *extra, bool *pending)
19551955
{
19561956
/*
19571957
* The kernel API provides no way to test a value without setting it; and
@@ -1984,7 +1984,7 @@ show_tcp_keepalives_idle(void)
19841984
* GUC assign_hook for tcp_keepalives_interval
19851985
*/
19861986
void
1987-
assign_tcp_keepalives_interval(int newval, void *extra)
1987+
assign_tcp_keepalives_interval(int newval, void *extra, bool *pending)
19881988
{
19891989
/* See comments in assign_tcp_keepalives_idle */
19901990
(void) pq_setkeepalivesinterval(newval, MyProcPort);
@@ -2007,7 +2007,7 @@ show_tcp_keepalives_interval(void)
20072007
* GUC assign_hook for tcp_keepalives_count
20082008
*/
20092009
void
2010-
assign_tcp_keepalives_count(int newval, void *extra)
2010+
assign_tcp_keepalives_count(int newval, void *extra, bool *pending)
20112011
{
20122012
/* See comments in assign_tcp_keepalives_idle */
20132013
(void) pq_setkeepalivescount(newval, MyProcPort);
@@ -2030,7 +2030,7 @@ show_tcp_keepalives_count(void)
20302030
* GUC assign_hook for tcp_user_timeout
20312031
*/
20322032
void
2033-
assign_tcp_user_timeout(int newval, void *extra)
2033+
assign_tcp_user_timeout(int newval, void *extra, bool *pending)
20342034
{
20352035
/* See comments in assign_tcp_keepalives_idle */
20362036
(void) pq_settcpusertimeout(newval, MyProcPort);

src/backend/port/posix_sema.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ PGSemaphoreShmemSize(int maxSemas)
193193
* we don't have to expose the counters to other processes.)
194194
*/
195195
void
196-
PGReserveSemaphores(int maxSemas)
196+
PGReserveSemaphores(int maxSemas, int shmem_segment)
197197
{
198198
struct stat statbuf;
199199

@@ -220,7 +220,7 @@ PGReserveSemaphores(int maxSemas)
220220
* ShmemAlloc() won't be ready yet.
221221
*/
222222
sharedSemas = (PGSemaphore)
223-
ShmemAllocUnlocked(PGSemaphoreShmemSize(maxSemas));
223+
ShmemAllocUnlockedInSegment(PGSemaphoreShmemSize(maxSemas), shmem_segment);
224224
#endif
225225

226226
numSems = 0;

src/backend/port/sysv_sema.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ PGSemaphoreShmemSize(int maxSemas)
327327
* have clobbered.)
328328
*/
329329
void
330-
PGReserveSemaphores(int maxSemas)
330+
PGReserveSemaphores(int maxSemas, int shmem_segment)
331331
{
332332
struct stat statbuf;
333333

@@ -348,7 +348,7 @@ PGReserveSemaphores(int maxSemas)
348348
* ShmemAlloc() won't be ready yet.
349349
*/
350350
sharedSemas = (PGSemaphore)
351-
ShmemAllocUnlocked(PGSemaphoreShmemSize(maxSemas));
351+
ShmemAllocUnlockedInSegment(PGSemaphoreShmemSize(maxSemas), shmem_segment);
352352
numSharedSemas = 0;
353353
maxSharedSemas = maxSemas;
354354

0 commit comments

Comments
 (0)