Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1krLLA-0006wp-T3 for pgsql-admin@arkaria.postgresql.org; Mon, 21 Dec 2020 13:35:09 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1krLL9-0000BR-KS for pgsql-admin@arkaria.postgresql.org; Mon, 21 Dec 2020 13:35:07 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1krLL9-0000BK-9o for pgsql-admin@lists.postgresql.org; Mon, 21 Dec 2020 13:35:07 +0000 Received: from mail-ej1-x62f.google.com ([2a00:1450:4864:20::62f]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1krLL3-0006uW-Gm for pgsql-admin@postgresql.org; Mon, 21 Dec 2020 13:35:06 +0000 Received: by mail-ej1-x62f.google.com with SMTP id b9so13521745ejy.0 for ; Mon, 21 Dec 2020 05:35:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec-at.20150623.gappssmtp.com; s=20150623; h=message-id:subject:from:to:date:in-reply-to:references:user-agent :mime-version:content-transfer-encoding; bh=YXDkMD7Hntih5mqWKjB9lUQleXExOH7f6E3bdJJEqX0=; b=tV0s8MVlBdSv6/VmUJrcs5ROs1o509ZhTgApRXf4nnAiXrKnjGsFpkoN2HucRvaI8z mi5eNsto3zj+79vuW3sWduUJFkBivvC9Q4KfcSVjxln2KLda7/cTvsUjIdN3BBvCVwG6 Uxf90pk4LHsx0/mMbRat8kFZkHi2EYeo0TR03imNvBQC5CGPnSxZqOapN+aXzgqvOVVQ kY+UYeMeEJqOvIhtI0INb6ESzC++HiTiHIherAym4t2WXDYeX+b0jqdcpGnIrjBz3rRN 16SHbyzuVV36U0sZcruHDOXfJB3p0txTpAK+JgrJgz6+gRJHgfGisdDZGClBqNJAL7QD taPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:subject:from:to:date:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=YXDkMD7Hntih5mqWKjB9lUQleXExOH7f6E3bdJJEqX0=; b=PES2N5OgGhfmtyFh8clDvUT0/tPcTUb0BoeGz2Daz8i54VeFomlzVYBKwP/0vLrRJo e7ltElholHcneEqJdHWRN474wa+ah8gpgtdyrHGaFCGEhO7XPS9vmi6Qiq/POEsyKmi2 PehF1ZNzaKosSWGWWM0sXxllcCw32ZJqiqh4HZzquezkXCfgbwMFceX03ttAohSsHmy5 P9LmxV2MDBRQMv3z7/d/W7ZqOr+IzM6uHt+FK8/emXzHzo174KvXiZd0JZgyjT1Wpind /FV742gWV2gsS3jJEDMzsKHZackxU6Fe2hZbqKOCiA6wDwTusE3bIdyPk7gbQv0Mo+bl EQqw== X-Gm-Message-State: AOAM533qFZkqyzESAGbvoCT7422a4GVv+2FpMdFywW50lxS5ycp/+36z rYpU81nP55NFHAXPvHv9gZ9zEg== X-Google-Smtp-Source: ABdhPJwu8xIIo4bStEtGMRQqwmWV0+olpXqLgDWVC84SFrI1iFDBPp9fqQoPLuFgeTMZTJvdbiFdBA== X-Received: by 2002:a17:907:3e23:: with SMTP id hp35mr15513715ejc.254.1608557699550; Mon, 21 Dec 2020 05:34:59 -0800 (PST) Received: from localhost.localdomain (217-149-168-145.nat.highway.telekom.at. [217.149.168.145]) by smtp.gmail.com with ESMTPSA id h16sm8992777eji.110.2020.12.21.05.34.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Dec 2020 05:34:59 -0800 (PST) Message-ID: Subject: Re: Error: "could not fork new process for connection: Cannot allocate memory" From: Laurenz Albe To: frank picabia , pgsql-admin@postgresql.org Date: Mon, 21 Dec 2020 14:34:58 +0100 In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.36.5 (3.36.5-2.fc32) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Mon, 2020-12-21 at 09:17 -0400, frank picabia wrote: > This error occurred a couple of days ago and it is unlikely to repeat as > it was a series of exams being done in moodle with over 500 students. > However I'd like to tune Postgres to see if it can be prevented. > > First of all, we did not run out of memory within the OS. This system is monitored by cacti and > Real Used memory never exceeded 30 GB on a server having 64 GB ram plus some swap. > > I can also see in the messages log, the Linux kernel OOM killer was never triggered. > > The postgres user running the DB has no ulimits on memory which might apply. > > Here is the entry in the Postgres log: > > <2020-12-19 13:19:29 GMT>LOG: could not fork new process for connection: Cannot allocate memory > TopMemoryContext: 136704 total in 13 blocks; 6688 free (4 chunks); 130016 used > smgr relation table: 24576 total in 2 blocks; 13904 free (4 chunks); 10672 used > TopTransactionContext: 8192 total in 1 blocks; 6152 free (5 chunks); 2040 used > <2020-12-19 13:19:29 GMT>LOG: could not fork new process for connection: Cannot allocate memory > TransactionAbortContext: 32768 total in 1 blocks; 32728 free (0 chunks); 40 used > Portal hash: 8192 total in 1 blocks; 1672 free (0 chunks); 6520 used > PortalMemory: 0 total in 0 blocks; 0 free (0 chunks); 0 used > > My conclusion is this memory error must be related to limits within Postgres tunables, or perhaps > something like SHM memory, which we have not set up in the sysctl.conf , so this is just a default amount. > > The values we have in postgres.conf are mostly suggested by pgtune script. The one exception being > max_connections=500, which was increased to try to avoid bottlenecks being reached with Apache client > numbers, and gradually over time as we saw we still had lots of memory available with a higher connection limit. > > Which tunables do you need to see? You probably have to increase the operating system limit for open files for the "postgres" user (ulimit -n). Yours, Laurenz Albe -- Cybertec | https://www.cybertec-postgresql.com