pgx/pgconn
smaher-edb f47f0cf823 connect_timeout is not obeyed for sslmode=allow|prefer
connect_timeout given in conn string was not obeyed if sslmode is not specified (default is prefer) or equals sslmode=allow|prefer. It took twice the amount of time specified by connect_timeout in conn string. While this behavior is correct if multi-host is provided in conn string, it doesn't look correct in case of single host. This behavior was also not matching with libpq.

The root cause was to implement sslmode=allow|prefer conn are tried twice. First with TLSConfig and if that doesn't work then without TLSConfig. The fix for this issue now uses the same context if same host is being tried out. This change won't affect the existing multi-host behavior.

This PR goal is to close issue [jackc/pgx/issues/1672](https://github.com/jackc/pgx/issues/1672)
2023-07-15 09:49:09 -05:00
..
internal Add PgConn.SyncConn 2023-07-11 21:29:11 -05:00
README.md Improve testing / contributing instructions 2022-10-29 17:14:09 -05:00
auth_scram.go Handle writes that could deadlock with reads from the server 2023-06-12 09:39:26 -05:00
benchmark_private_test.go Use string internally for CommandTag 2022-07-11 21:09:03 -05:00
benchmark_test.go pgconn and pgproto use same environment variable for tests as pgx 2022-10-29 13:23:25 -05:00
config.go Use Go 1.19's lists for proper formatting 2023-01-23 19:54:30 -06:00
config_test.go skipping some config parsing tests on Windows 2023-06-03 06:45:28 -05:00
defaults.go Make Chunkreader an internal implementation detail 2022-02-26 08:50:46 -06:00
defaults_windows.go Make Chunkreader an internal implementation detail 2022-02-26 08:50:46 -06:00
doc.go Add pipeline mode to pgconn 2022-07-02 21:48:16 -05:00
errors.go pgconn.Timeout() no longer considers `context.Canceled` as a timeout error. 2022-09-17 10:18:06 -05:00
errors_test.go Bump module version to v5 2021-12-11 13:29:03 -06:00
export_test.go Import to pgx main repo in pgconn subdir 2021-12-04 13:51:24 -06:00
helper_test.go Drastically increase allowed test times for potato CI 2023-07-11 21:16:08 -05:00
krb5.go Handle writes that could deadlock with reads from the server 2023-06-12 09:39:26 -05:00
pgconn.go connect_timeout is not obeyed for sslmode=allow|prefer 2023-07-15 09:49:09 -05:00
pgconn_private_test.go Use string internally for CommandTag 2022-07-11 21:09:03 -05:00
pgconn_stress_test.go pgconn and pgproto use same environment variable for tests as pgx 2022-10-29 13:23:25 -05:00
pgconn_test.go Add PgConn.SyncConn 2023-07-11 21:29:11 -05:00

README.md

pgconn

Package pgconn is a low-level PostgreSQL database driver. It operates at nearly the same level as the C library libpq. It is primarily intended to serve as the foundation for higher level libraries such as https://github.com/jackc/pgx. Applications should handle normal queries with a higher level library and only use pgconn directly when required for low-level access to PostgreSQL functionality.

Example Usage

pgConn, err := pgconn.Connect(context.Background(), os.Getenv("DATABASE_URL"))
if err != nil {
	log.Fatalln("pgconn failed to connect:", err)
}
defer pgConn.Close(context.Background())

result := pgConn.ExecParams(context.Background(), "SELECT email FROM users WHERE id=$1", [][]byte{[]byte("123")}, nil, nil, nil)
for result.NextRow() {
	fmt.Println("User 123 has email:", string(result.Values()[0]))
}
_, err = result.Close()
if err != nil {
	log.Fatalln("failed reading result:", err)
}

Testing

See CONTRIBUTING.md for setup instructions.