net.ipv4.tcp_keepalive_time = 600
net.ipv4.tcp_keepalive_probes = 3
net.ipv4.tcp_keepalive_intvl = 15
同时要注意postgresql.conf中以下几项设置:
#tcp_keepalives_idle = 0 # TCP_KEEPIDLE, in seconds; 0 selects the system default
#tcp_keepalives_interval = 0 # TCP_KEEPINTVL, in seconds;0 selects the system default
#tcp_keepalives_count = 0 # TCP_KEEPCNT;0 selects the system default
系统是debian7,默认的超时设置太长,而外网网络状况不佳,所以导致这种问题。
这个配置的思路是让pg更频繁地发出探测数据包来保持tcp连接。