https://github.com/marselester/pg-keepalive
Available options to control TCP keepalive in lib/pq.
https://github.com/marselester/pg-keepalive
Last synced: about 1 month ago
JSON representation
Available options to control TCP keepalive in lib/pq.
- Host: GitHub
- URL: https://github.com/marselester/pg-keepalive
- Owner: marselester
- Created: 2020-10-01T01:18:26.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-10-01T17:56:45.000Z (over 4 years ago)
- Last Synced: 2024-05-02T00:42:26.890Z (about 1 year ago)
- Language: Go
- Size: 4.88 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Postgres keepalive
This repository shows a few approaches to control
[TCP keepalive](https://www.ibm.com/support/pages/ibm-aix-tcp-keepalive-probes)
in `lib/pq` based on https://github.com/lib/pq/pull/999.Custom driver `sql.Open("postgres-custom", dsn)`.
```sh
$ go build ./cmd/driver
$ strace -e trace=network ./driversetsockopt(3, SOL_SOCKET, SO_KEEPALIVE, [1], 4) = 0
setsockopt(3, SOL_TCP, TCP_KEEPINTVL, [5], 4) = 0
setsockopt(3, SOL_TCP, TCP_KEEPIDLE, [5], 4) = 0
```Ubiquitous `sql.Open("postgres", dsn)`.
```sh
$ go build ./cmd/sqlopen
$ strace -e trace=network ./sqlopensetsockopt(3, SOL_SOCKET, SO_KEEPALIVE, [1], 4) = 0
setsockopt(3, SOL_TCP, TCP_KEEPINTVL, [5], 4) = 0
setsockopt(3, SOL_TCP, TCP_KEEPIDLE, [5], 4) = 0
```Rarely used `pq.Open(dsn)`.
```sh
$ go build ./cmd/open
$ strace -e trace=network ./opensetsockopt(3, SOL_SOCKET, SO_KEEPALIVE, [1], 4) = 0
setsockopt(3, SOL_TCP, TCP_KEEPINTVL, [5], 4) = 0
setsockopt(3, SOL_TCP, TCP_KEEPIDLE, [5], 4) = 0
```Connector `sql.OpenDB(connector)`.
```sh
$ go build ./cmd/connector
$ strace -e trace=network ./connectorsetsockopt(3, SOL_SOCKET, SO_KEEPALIVE, [1], 4) = 0
setsockopt(3, SOL_TCP, TCP_KEEPINTVL, [5], 4) = 0
setsockopt(3, SOL_TCP, TCP_KEEPIDLE, [5], 4) = 0
```