简体   繁体   中英

struggling with connection idle timeout settings on ubuntu with postgresql

I'm a beginner at linux server configuration and I don't have much knowledges about it. I use a linux ubuntu root server for a website with a postgres database. My operation system on my PC is windows 7.

After some minutes (I'm not quite sure, how long it takes, maybe 5 minutes or so, not a lot) without doing anything I lose my connection, which is really annoying. I googled how to fix it, but didn't really found a solution, or didn't understand them.

For example I tried to update my postgresql.conf and edited this values:

#tcp_keepalives_idle 
#tcp_keepalives_interval        
#tcp_keepalives_count

which didn't really help. I want to have to opportunity to idle for 30 minutes, without losing the connection.

Then I read another solution:

http://www.gnugk.org/keepalive.html

I honestly didn't really understand, what those lines I have to add, are for. Because when I check this:

sysctl -A | grep net.ipv4

it shows me:

net.ipv4.tcp_keepalive_intvl = 75
net.ipv4.tcp_keepalive_probes = 9
net.ipv4.tcp_keepalive_time = 7200

which should mean that I won't lose my connection for 2 hours, doesn't it?

I also don't really understand what does lines are for... Does that mean, that every service a client is connected, he will still be connected for 2 hours, even if he is inactive? No matter if it is for example postgresql or ftp or something?

Please help me! Thanks!

André

Okay it seems, that I solved the problem. Allthough there is no answer here, I just want to explain my solution.

My ISP seems to break up my connection very fast, when I idle on a connection for just a few minutes. Seems to be a problem with CGN (Carrier-grade NAT).

I solved the problem, to setup keepalive packages with sysctl .

So I used those parameter values:

net.ipv4.tcp_keepalive_intvl = 60
net.ipv4.tcp_keepalive_probes = 20
net.ipv4.tcp_keepalive_time = 180

which means that after 3 minutes the first keepalive package will be sent and when there is no connection alive every minute (60 sec) a new keep alive package will be sent and this 20 times. All in all that prevents my connection to break up.

Maybe if another one is having that issues too here, that might be a solution for it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM