Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8d0ddcc

Browse files
committed
Avoid "invalid memory alloc request size" while reading pg_stat_activity.
On a 64-bit machine, if you set track_activity_query_size andmax_connections such that their product exceeds 1GB, shared memorysetup will still succeed (given enough RAM), but attempts to readpg_stat_activity fail with "invalid memory alloc request size".Work around that by using MemoryContextAllocHuge to allocate thelocal copy of the activity strings. Using the "huge" API costs usnothing extra in normal cases, and it seems better than throwingan error and/or explaining to people why they can't do this.This situation seems insanely profligate today, but who knows whatpeople will consider normal in ten or twenty years? So let's fix itin HEAD but not worry about a back-patch.Per report from James Tomson.Discussion:https://postgr.es/m/1CFDCCD6-B268-48D8-85C8-400D2790B2C3@pushd.com
1 parentb753bc0 commit8d0ddcc

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

‎src/backend/postmaster/pgstat.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3319,6 +3319,14 @@ pgstat_read_current_status(void)
33193319

33203320
pgstat_setup_memcxt();
33213321

3322+
/*
3323+
* Allocate storage for local copy of state data. We can presume that
3324+
* none of these requests overflow size_t, because we already calculated
3325+
* the same values using mul_size during shmem setup. However, with
3326+
* probably-silly values of pgstat_track_activity_query_size and
3327+
* max_connections, the localactivity buffer could exceed 1GB, so use
3328+
* "huge" allocation for that one.
3329+
*/
33223330
localtable= (LocalPgBackendStatus*)
33233331
MemoryContextAlloc(pgStatLocalContext,
33243332
sizeof(LocalPgBackendStatus)*NumBackendStatSlots);
@@ -3329,8 +3337,8 @@ pgstat_read_current_status(void)
33293337
MemoryContextAlloc(pgStatLocalContext,
33303338
NAMEDATALEN*NumBackendStatSlots);
33313339
localactivity= (char*)
3332-
MemoryContextAlloc(pgStatLocalContext,
3333-
pgstat_track_activity_query_size*NumBackendStatSlots);
3340+
MemoryContextAllocHuge(pgStatLocalContext,
3341+
pgstat_track_activity_query_size*NumBackendStatSlots);
33343342
#ifdefUSE_SSL
33353343
localsslstatus= (PgBackendSSLStatus*)
33363344
MemoryContextAlloc(pgStatLocalContext,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp