When connecting to a pg 11 instance and executing
select setting, source from pg_settings
where name='tcp_keepalives_interval';
I get two different responses between connecting via psql and a script with using Npgsql;
The command line psql client returns
0 | default
while the Npgsql script will return
75 | default
75 matches net.ipv4.tcp_keepalive_intvl
but I still would have expected 0.
What is the cause of this discrepancy and how can I account for it generally in C# with Npgsql?
Looking into my crystal ball, I see that your database server is not on Windows and the psql
session is running on the database server. Your psql
session is connected via UNIX sockets (a local
connection).
The documentation says (emphasis mine):
keepalives_count
Controls the number of TCP keepalives that can be lost before the client's connection to the server is considered dead. A value of zero uses the system default. This parameter is ignored for connections made via a Unix-domain socket, or if keepalives are disabled. It is only supported on systems where
TCP_KEEPCNT
or an equivalent socket option is available; on other systems, it has no effect.
If you connect with psql
via TCP, you should see 75 as well.