Skip to content

Commit 39715af

Browse files
committed
Fix broken mmap failure-detection code, and improve error message.
Per an observation by Thom Brown that my previous commit made an overly large shmem allocation crash the server, on Linux.
1 parent b0fc0df commit 39715af

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/backend/port/sysv_shmem.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -419,10 +419,17 @@ PGSharedMemoryCreate(Size size, bool makePrivate, int port)
419419
*/
420420
AnonymousShmem = mmap(NULL, size, PROT_READ|PROT_WRITE, PG_MMAP_FLAGS,
421421
-1, 0);
422-
if (AnonymousShmem == NULL)
422+
if (AnonymousShmem == MAP_FAILED)
423423
ereport(FATAL,
424-
(errmsg("could not map %lu bytes of anonymous shared memory: %m",
425-
(unsigned long) AnonymousShmemSize)));
424+
(errmsg("could not map anonymous shared memory: %m"),
425+
(errno == ENOMEM) ?
426+
errhint("This error usually means that PostgreSQL's request "
427+
"for a shared memory segment exceeded available memory "
428+
"or swap space. To reduce the request size (currently "
429+
"%lu bytes), reduce PostgreSQL's shared memory usage, "
430+
"perhaps by reducing shared_buffers or "
431+
"max_connections.",
432+
(unsigned long) AnonymousShmemSize) : 0));
426433

427434
/* Now we can allocate a minimal SHM block. */
428435
allocsize = sizeof(PGShmemHeader);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy