Setting libpq TCP keepalive parameters from environment

From: Oleksandr Shulgin <oleksandr(dot)shulgin(at)zalando(dot)de>
To: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Setting libpq TCP keepalive parameters from environment
Date: 2018-05-08 08:15:47
Message-ID: CACACo5SBUUiXcL6pPyNV8-V5YSjs1KidScD0mHuD7aub9oAwKg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi Hackers,

I didn't find the original discussion which led to introduction of the
client-side set of keepalive parameters back in [1].

The issue I'm facing is that it doesn't seem to be possible to set these
parameters from the environment variables. The block of option
definitions[2] added for these parameters doesn't specify any corresponding
env var names.

I wonder if this is an oversight or was there a conscious decision not to
allow it?

To give a specific example, I have a (legacy) Python script which talks to
the database in two ways: by directly using psycopg2.connect(host=..., )
and also by running some shell commands with psql's \copy + gzip, mainly
for convenience.

Now when I needed to tune the keepalives_idle value, I had to include it
everywhere a database connection is made:
- For psycopg2 it's straightforward: you just add an extra keyword
parameter to connect().
- For psql it's trickier, since the only way to achieve this seems to pack
it together with -d as: -d 'dbname=mydb keepalives_idle=NNN'.

In case of a binary that would amount to recompiling, I guess. I have no
permission to tweak sysctl directly on the host, unfortunately.

It would be much more convenient to just set the environment variable when
running the script and let it affect the whole process and its children.

Would a patch be welcome?

Regards,
--
Alex

[1] https://www.postgresql.org/message-id/flat/20100623215414.053427541D4%
40cvs.postgresql.org
[2] https://git.postgresql.org/gitweb/?p=postgresql.git;
a=blob;f=src/interfaces/libpq/fe-connect.c;h=a7e969d7c1cecdc8743c43cea09906
8196a4a5fe;hb=HEAD#l251

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Pavlo Golub 2018-05-08 08:19:39 Re: Porting PG Extension from UNIX to Windows
Previous Message Ashutosh Bapat 2018-05-08 07:20:48 Re: Expression errors with "FOR UPDATE" and postgres_fdw with partition wise join enabled.