Re: "ulimit -n" in postgresql/pgbouncer init scripts. - Mailing list pgsql-pkg-debian

From Greg Smith
Subject Re: "ulimit -n" in postgresql/pgbouncer init scripts.
Date
Msg-id 50DB32C7.50608@2ndQuadrant.com
Whole thread Raw
In response to "ulimit -n" in postgresql/pgbouncer init scripts.  (Kirill Kuznetsov <kir@evilmartians.com>)
Responses Re: "ulimit -n" in postgresql/pgbouncer init scripts.  (Christoph Berg <myon@debian.org>)
List pgsql-pkg-debian
On 12/26/12 6:43 AM, Kirill Kuznetsov wrote:
> But we actually need to set open files limit (ulimit -n) for these
> processes. In our packages we modified init.d script so that it
> invokes "ulimit -n" command.
> ULIMIT=1024
>      ulimit -n $ULIMIT
> Is it possible for something like this to appear in PGDG packages or
> are we doing it wrong?

That would be B) doing it wrong.  Packages aren't the right place to be
touching ulimit values.  On Debian there are other ways to approach this
problem.  One way is that you can:

-Add lines to /etc/security/limits.conf (or its include files, see [1])
to increase the values for the user like this:

postgres    hard    nofile    1024
postgres    soft    nofile    1024

Modify with the user names you want to change.  * changes all users
*except* for the superuser, so that might not impact how you're running
things.

[1] You can create a file in /etc/security/limits.d/ instead with these
changes.  That might be a cleaner way to manage things in your
environment.  It's a good idea to check if any limit changes are
happening in that directory too, they can override yours if read in the
wrong order.

-Edit either /etc/pam.d/su and/or /etc/pam.d/common-session and make
sure this line is there:

session required pam_limits.so

That makes the way PAM is involved in switching users references the new
user's ulimit values.

There's more information about things like checking if this works as you
expect at
http://serverfault.com/questions/397553/how-does-ulimit-come-into-effect-on-the-fly
and
http://www.cyberciti.biz/faq/linux-increase-the-maximum-number-of-open-files/

--
Greg Smith   2ndQuadrant US    greg@2ndQuadrant.com   Baltimore, MD
PostgreSQL Training, Services, and 24x7 Support www.2ndQuadrant.com


pgsql-pkg-debian by date:

Previous
From: Kirill Kuznetsov
Date:
Subject: "ulimit -n" in postgresql/pgbouncer init scripts.
Next
From: Christoph Berg
Date:
Subject: Re: "ulimit -n" in postgresql/pgbouncer init scripts.