Received: from localhost (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id E86B763262B for ; Fri, 27 Feb 2009 08:51:09 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 50167-04 for ; Fri, 27 Feb 2009 08:50:59 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail.gmx.net (mail.gmx.net [213.165.64.20]) by mail.postgresql.org (Postfix) with SMTP id 0A807634747 for ; Fri, 27 Feb 2009 08:50:58 -0400 (AST) Received: (qmail invoked by alias); 27 Feb 2009 12:50:55 -0000 Received: from gmp-ea-fw-1.sun.com (EHLO dhcp-eesp05-101-226.Finland.Sun.COM) [192.18.1.36] by mail.gmx.net (mp022) with SMTP; 27 Feb 2009 13:50:55 +0100 X-Authenticated: #495269 X-Provags-ID: V01U2FsdGVkX1/m4oh5mjzmtouLQ3r0UilAMfZ92jed7Xl4ky9a4i SwmTDROkqsZDHu Message-ID: <49A7E1A9.6050405@gmx.net> Date: Fri, 27 Feb 2009 14:50:49 +0200 From: Peter Eisentraut User-Agent: Thunderbird 2.0.0.19 (Macintosh/20081209) MIME-Version: 1.0 To: PG Hackers Subject: Patch for not going beyond NOFILE system limit (updated) Content-Type: multipart/mixed; boundary="------------080601000709060804040106" X-Y-GMX-Trusted: 0 X-FuHaFi: 0.62 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200902/1351 X-Sequence-Number: 134641 This is a multi-part message in MIME format. --------------080601000709060804040106 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit This is an updated and properly autoconf-guarded patch for this previously reported issue: """ Jacek Drobiecki recently sent me a patch which stops postgresql to actively violate the system limit of maximum open files (RLIMIT_NOFILE) in src/backend/storage/file/fd.c, function count_usable_fds(). This avoids irritating kernel logs (if system overstep violations are enabled) and also the grsecurity alert when starting PostgreSQL. """ References: http://archives.postgresql.org/pgsql-bugs/2004-05/msg00103.php http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=248967 I think we can put this into 8.4 or the first commit fest of 8.5. --------------080601000709060804040106 Content-Type: text/x-diff; name="check-rlimits-nofile.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="check-rlimits-nofile.patch" Index: src/backend/storage/file/fd.c =================================================================== RCS file: /cvsroot/pgsql/src/backend/storage/file/fd.c,v retrieving revision 1.147 diff -u -3 -p -r1.147 fd.c --- src/backend/storage/file/fd.c 12 Jan 2009 05:10:44 -0000 1.147 +++ src/backend/storage/file/fd.c 27 Feb 2009 12:45:25 -0000 @@ -45,6 +45,9 @@ #include #include #include +#ifdef HAVE_SYS_RESOURCE_H +#include /* for getrlimit */ +#endif #include "miscadmin.h" #include "access/xact.h" @@ -361,15 +364,35 @@ count_usable_fds(int max_to_probe, int * int used = 0; int highestfd = 0; int j; +#ifdef HAVE_GETRLIMIT + struct rlimit rlim; + int getrlimit_status; +#endif size = 1024; fd = (int *) palloc(size * sizeof(int)); +#ifdef HAVE_GETRLIMIT +# ifdef RLIMIT_NOFILE /* most platforms use RLIMIT_NOFILE */ + getrlimit_status = getrlimit(RLIMIT_NOFILE, &rlim); +# else /* but BSD doesn't ... */ + getrlimit_status = getrlimit(RLIMIT_OFILE, &rlim); +# endif /* RLIMIT_NOFILE */ + if (getrlimit_status != 0) + ereport(WARNING, (errmsg("getrlimit failed: %m"))); +#endif /* HAVE_GETRLIMIT */ + /* dup until failure or probe limit reached */ for (;;) { int thisfd; +#ifdef HAVE_GETRLIMIT + /* don't go beyond RLIMIT_NOFILE */ + if (getrlimit_status == 0 && highestfd >= rlim.rlim_cur - 1) + break; +#endif + thisfd = dup(0); if (thisfd < 0) { --------------080601000709060804040106--