Skip to content

Commit 7b301de

Browse files
committed
Merge branch 'master' into oauth-pg18
2 parents 644ea6b + 77fcc7e commit 7b301de

133 files changed

Lines changed: 4902 additions & 1410 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.devcontainer/Dockerfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
FROM mcr.microsoft.com/devcontainers/go:2-1.25-trixie
2+
3+
RUN apt-get update && apt-get install -y postgresql-common \
4+
&& yes | /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh \
5+
&& apt-get install -y postgresql-client-18 \
6+
&& rm -rf /var/lib/apt/lists/*
7+
8+
USER vscode
9+
RUN go install golang.org/x/tools/cmd/goimports@latest

.devcontainer/devcontainer.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"name": "pgx",
3+
"dockerComposeFile": "docker-compose.yml",
4+
"service": "app",
5+
"workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}"
6+
}

.devcontainer/docker-compose.yml

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
volumes:
2+
postgres-14-data:
3+
postgres-15-data:
4+
postgres-16-data:
5+
postgres-17-data:
6+
postgres-18-data:
7+
8+
services:
9+
app:
10+
build:
11+
context: .
12+
dockerfile: Dockerfile
13+
14+
volumes:
15+
- ../..:/workspaces:cached
16+
17+
environment:
18+
PGUSER: postgres
19+
PGPASSWORD: postgres
20+
PGDATABASE: pgx_test
21+
PGHOST: localhost
22+
23+
# Overrides default command so things don't shut down after the process ends.
24+
command: sleep infinity
25+
26+
postgres-14:
27+
image: postgres:14
28+
restart: unless-stopped
29+
volumes:
30+
- postgres-14-data:/var/lib/postgresql
31+
- ../testsetup/postgresql_setup.sql:/docker-entrypoint-initdb.d/01-setup.sql:ro
32+
network_mode: service:app
33+
environment:
34+
POSTGRES_USER: postgres
35+
POSTGRES_PASSWORD: postgres
36+
POSTGRES_DB: pgx_test
37+
POSTGRES_HOSTNAME: localhost
38+
command: postgres -c port=5414
39+
40+
postgres-15:
41+
image: postgres:15
42+
restart: unless-stopped
43+
volumes:
44+
- postgres-15-data:/var/lib/postgresql
45+
- ../testsetup/postgresql_setup.sql:/docker-entrypoint-initdb.d/01-setup.sql:ro
46+
network_mode: service:app
47+
environment:
48+
POSTGRES_USER: postgres
49+
POSTGRES_PASSWORD: postgres
50+
POSTGRES_DB: pgx_test
51+
POSTGRES_HOSTNAME: localhost
52+
command: postgres -c port=5415
53+
54+
postgres-16:
55+
image: postgres:16
56+
restart: unless-stopped
57+
volumes:
58+
- postgres-16-data:/var/lib/postgresql
59+
- ../testsetup/postgresql_setup.sql:/docker-entrypoint-initdb.d/01-setup.sql:ro
60+
network_mode: service:app
61+
environment:
62+
POSTGRES_USER: postgres
63+
POSTGRES_PASSWORD: postgres
64+
POSTGRES_DB: pgx_test
65+
POSTGRES_HOSTNAME: localhost
66+
command: postgres -c port=5416
67+
68+
postgres-17:
69+
image: postgres:17
70+
restart: unless-stopped
71+
volumes:
72+
- postgres-17-data:/var/lib/postgresql
73+
- ../testsetup/postgresql_setup.sql:/docker-entrypoint-initdb.d/01-setup.sql:ro
74+
network_mode: service:app
75+
environment:
76+
POSTGRES_USER: postgres
77+
POSTGRES_PASSWORD: postgres
78+
POSTGRES_DB: pgx_test
79+
POSTGRES_HOSTNAME: localhost
80+
command: postgres -c port=5417
81+
82+
postgres-18:
83+
image: postgres:18
84+
restart: unless-stopped
85+
volumes:
86+
- postgres-18-data:/var/lib/postgresql
87+
- ../testsetup/postgresql_setup.sql:/docker-entrypoint-initdb.d/01-setup.sql:ro
88+
network_mode: service:app
89+
environment:
90+
POSTGRES_USER: postgres
91+
POSTGRES_PASSWORD: postgres
92+
POSTGRES_DB: pgx_test
93+
POSTGRES_HOSTNAME: localhost
94+
95+
cockroachdb:
96+
image: cockroachdb/cockroach:v25.4.4
97+
restart: unless-stopped
98+
network_mode: service:app
99+
command: start-single-node --insecure --listen-addr=127.0.0.1:26257 --store=type=mem,size=1024MiB

.github/FUNDING.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
github: jackc

.github/workflows/ci.yml

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,8 @@ jobs:
1414
strategy:
1515
matrix:
1616
go-version: ["1.24", "1.25"]
17-
pg-version: [13, 14, 15, 16, 17, cockroachdb]
17+
pg-version: [14, 15, 16, 17, 18, cockroachdb]
1818
include:
19-
- pg-version: 13
20-
pgx-test-database: "host=127.0.0.1 user=pgx_md5 password=secret dbname=pgx_test"
21-
pgx-test-unix-socket-conn-string: "host=/var/run/postgresql dbname=pgx_test"
22-
pgx-test-tcp-conn-string: "host=127.0.0.1 user=pgx_md5 password=secret dbname=pgx_test"
23-
pgx-test-scram-password-conn-string: "host=127.0.0.1 user=pgx_scram password=secret dbname=pgx_test"
24-
pgx-test-md5-password-conn-string: "host=127.0.0.1 user=pgx_md5 password=secret dbname=pgx_test"
25-
pgx-test-plain-password-conn-string: "host=127.0.0.1 user=pgx_pw password=secret dbname=pgx_test"
26-
pgx-test-tls-conn-string: "host=localhost user=pgx_ssl password=secret sslmode=verify-full sslrootcert=/tmp/ca.pem dbname=pgx_test"
27-
pgx-ssl-password: certpw
28-
pgx-test-tls-client-conn-string: "host=localhost user=pgx_sslcert sslmode=verify-full sslrootcert=/tmp/ca.pem sslcert=/tmp/pgx_sslcert.crt sslkey=/tmp/pgx_sslcert.key dbname=pgx_test"
2919
- pg-version: 14
3020
pgx-test-database: "host=127.0.0.1 user=pgx_md5 password=secret dbname=pgx_test"
3121
pgx-test-unix-socket-conn-string: "host=/var/run/postgresql dbname=pgx_test"
@@ -82,10 +72,10 @@ jobs:
8272

8373
steps:
8474
- name: Check out code into the Go module directory
85-
uses: actions/checkout@v4
75+
uses: actions/checkout@v5
8676

8777
- name: Set up Go ${{ matrix.go-version }}
88-
uses: actions/setup-go@v5
78+
uses: actions/setup-go@v6
8979
with:
9080
go-version: ${{ matrix.go-version }}
9181

@@ -147,10 +137,10 @@ jobs:
147137
database: pgx_test
148138

149139
- name: Check out code into the Go module directory
150-
uses: actions/checkout@v4
140+
uses: actions/checkout@v5
151141

152142
- name: Set up Go ${{ matrix.go-version }}
153-
uses: actions/setup-go@v5
143+
uses: actions/setup-go@v6
154144
with:
155145
go-version: ${{ matrix.go-version }}
156146

@@ -162,7 +152,10 @@ jobs:
162152
shell: bash
163153

164154
- name: Test
165-
# parallel testing is disabled because somehow parallel testing causes Github Actions to kill the runner.
166-
run: go test -parallel=1 -race ./...
155+
# Parallel testing is disabled because somehow parallel testing causes Github Actions to kill the runner.
156+
# Disabling CGO because that is not working on the Windows runner. Apparently, we could install MingW and set up
157+
# CGO to work, but disabling CGO takes less CI time. Without CGO, we also must not use the race detector.
158+
run: go test -parallel=1 ./...
167159
env:
160+
CGO_ENABLED: 0
168161
PGX_TEST_DATABASE: ${{ steps.postgres.outputs.connection-uri }}

.golangci.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
# See for configurations: https://golangci-lint.run/usage/configuration/
2-
version: 2
2+
version: "2"
3+
4+
linters:
5+
default: none
6+
enable:
7+
- govet
8+
- ineffassign
39

410
# See: https://golangci-lint.run/usage/formatters/
511
formatters:
6-
default: none
712
enable:
813
- gofmt # https://pkg.go.dev/cmd/gofmt
914
- gofumpt # https://github.com/mvdan/gofumpt

CHANGELOG.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,27 @@
1+
# 5.8.0 (December 26, 2025)
2+
3+
* Require Go 1.24+
4+
* Remove golang.org/x/crypto dependency
5+
* Add OptionShouldPing to control ResetSession ping behavior (ilyam8)
6+
* Fix: Avoid overflow when MaxConns is set to MaxInt32
7+
* Fix: Close batch pipeline after a query error (Anthonin Bonnefoy)
8+
* Faster shutdown of pgxpool.Pool background goroutines (Blake Gentry)
9+
* Add pgxpool ping timeout (Amirsalar Safaei)
10+
* Fix: Rows.FieldDescriptions for empty query
11+
* Scan unknown types into *any as string or []byte based on format code
12+
* Optimize pgtype.Numeric (Philip Dubé)
13+
* Add AfterNetConnect hook to pgconn.Config
14+
* Fix: Handle for preparing statements that fail during the Describe phase
15+
* Fix overflow in numeric scanning (Ilia Demianenko)
16+
* Fix: json/jsonb sql.Scanner source type is []byte
17+
* Migrate from math/rand to math/rand/v2 (Mathias Bogaert)
18+
* Optimize internal iobufpool (Mathias Bogaert)
19+
* Optimize stmtcache invalidation (Mathias Bogaert)
20+
* Fix: missing error case in interval parsing (Maxime Soulé)
21+
* Fix: invalidate statement/description cache in Exec (James Hartig)
22+
* ColumnTypeLength method return the type length for varbit type (DengChan)
23+
* Array and Composite codecs handle typed nils
24+
125
# 5.7.6 (September 8, 2025)
226

327
* Use ParseConfigError in pgx.ParseConfig and pgxpool.ParseConfig (Yurasov Ilia)

CLAUDE.md

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Project Overview
6+
7+
pgx is a PostgreSQL driver and toolkit for Go (`github.com/jackc/pgx/v5`). It provides both a native PostgreSQL interface and a `database/sql` compatible driver. Requires Go 1.24+ and supports PostgreSQL 14+ and CockroachDB.
8+
9+
## Build & Test Commands
10+
11+
```bash
12+
# Run all tests (requires PGX_TEST_DATABASE to be set)
13+
go test ./...
14+
15+
# Run a specific test
16+
go test -run TestFunctionName ./...
17+
18+
# Run tests for a specific package
19+
go test ./pgconn/...
20+
21+
# Run tests with race detector
22+
go test -race ./...
23+
24+
# DevContainer: run tests against specific PostgreSQL versions
25+
./test.sh pg18 # Default: PostgreSQL 18
26+
./test.sh pg16 -run TestConnect # Specific test against PG16
27+
./test.sh crdb # CockroachDB
28+
./test.sh all # All targets (pg14-18 + crdb)
29+
30+
# Format
31+
goimports -w .
32+
33+
# Lint
34+
golangci-lint run ./...
35+
```
36+
37+
## Test Database Setup
38+
39+
Tests require `PGX_TEST_DATABASE` environment variable. In the devcontainer, `test.sh` handles this. For local development:
40+
41+
```bash
42+
export PGX_TEST_DATABASE="host=localhost user=postgres password=postgres dbname=pgx_test"
43+
```
44+
45+
The test database needs extensions: `hstore`, `ltree`, and a `uint64` domain. See `testsetup/postgresql_setup.sql` for full setup. Many tests are skipped unless additional `PGX_TEST_*` env vars are set (for TLS, SCRAM, MD5, unix socket, PgBouncer testing).
46+
47+
## Architecture
48+
49+
The codebase is a layered architecture, bottom-up:
50+
51+
- **pgproto3/** — PostgreSQL wire protocol v3 encoder/decoder. Defines `FrontendMessage` and `BackendMessage` types for every protocol message.
52+
- **pgconn/** — Low-level connection layer (roughly libpq-equivalent). Handles authentication, TLS, query execution, COPY protocol, and notifications. `PgConn` is the core type.
53+
- **pgx** (root package) — High-level query interface built on `pgconn`. Provides `Conn`, `Rows`, `Tx`, `Batch`, `CopyFrom`, and generic helpers like `CollectRows`/`ForEachRow`. Includes automatic statement caching (LRU).
54+
- **pgtype/** — Type system mapping between Go and PostgreSQL types (70+ types). Key interfaces: `Codec`, `Type`, `TypeMap`. Custom types (enums, composites, domains) are registered through `TypeMap`.
55+
- **pgxpool/** — Concurrency-safe connection pool built on `puddle/v2`. `Pool` is the main type; wraps `pgx.Conn`.
56+
- **stdlib/**`database/sql` compatibility adapter.
57+
58+
Supporting packages:
59+
- **internal/stmtcache/** — Prepared statement cache with LRU eviction
60+
- **internal/sanitize/** — SQL query sanitization
61+
- **tracelog/** — Logging adapter that implements tracer interfaces
62+
- **multitracer/** — Composes multiple tracers into one
63+
- **pgxtest/** — Test helpers for running tests across connection types
64+
65+
## Key Design Conventions
66+
67+
- **Semantic versioning** — strictly followed. Do not break the public API (no removing or renaming exported types, functions, methods, or fields; no changing function signatures).
68+
- **Minimal dependencies** — adding new dependencies is strongly discouraged (see CONTRIBUTING.md).
69+
- **Context-based** — all blocking operations take `context.Context`.
70+
- **Tracer interfaces** — observability via `QueryTracer`, `BatchTracer`, `CopyFromTracer`, `PrepareTracer` on `ConnConfig.Tracer`.
71+
- **Formatting** — use `goimports -w .` to format code. CI checks formatting via `gofmt -l -s -w . && git diff --exit-code`. `gofumpt` with extra rules is also enforced via `golangci-lint`.
72+
- **Linters**`govet` and `ineffassign` only (configured in `.golangci.yml`).
73+
- **CI matrix** — tests run against Go 1.24/1.25 × PostgreSQL 14-18 + CockroachDB, on Linux and Windows. Race detector enabled on Linux only.

CONTRIBUTING.md

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,31 @@ proposal. This will help to ensure your proposed change has a reasonable chance
1010
Adding a dependency is a big deal. While on occasion a new dependency may be accepted, the default answer to any change
1111
that adds a dependency is no.
1212

13+
## AI
14+
15+
Using AI is acceptable (not that it can really be stopped) under one the following conditions.
16+
17+
* AI was used, but you deeply understand the code and you can answer questions regarding your change. You are not going
18+
to answer questions with "I don't know", AI did it. You are not going to "answer" questions by relaying them to your
19+
agent. This is wasteful of the code reviewer's time.
20+
* AI was used to solve a problem without your deep understanding. This can still be a good starting point for a fix or
21+
feature. But you need to clearly state that this is an AI proposal. You should include additional information such as
22+
the AI used and what prompts were used. You should also be aware that large, complicated, or subtle changes may be
23+
rejected simply because the reviewer is not confident in a change that no human understands.
24+
1325
## Development Environment Setup
1426

1527
pgx tests naturally require a PostgreSQL database. It will connect to the database specified in the `PGX_TEST_DATABASE`
1628
environment variable. The `PGX_TEST_DATABASE` environment variable can either be a URL or key-value pairs. In addition,
1729
the standard `PG*` environment variables will be respected. Consider using [direnv](https://github.com/direnv/direnv) to
1830
simplify environment variable handling.
1931

20-
### Using an Existing PostgreSQL Cluster
32+
### Devcontainer
33+
34+
The easiest way to start development is with the included devcontainer. It includes containers for each supported
35+
PostgreSQL version as well as CockroachDB. `./test.sh all` will run the tests against all database types.
36+
37+
### Using an Existing PostgreSQL Cluster Outside of a Devcontainer
2138

2239
If you already have a PostgreSQL development server this is the quickest way to start and run the majority of the pgx
2340
test suite. Some tests will be skipped that require server configuration changes (e.g. those testing different
@@ -49,7 +66,7 @@ go test ./...
4966

5067
This will run the vast majority of the tests, but some tests will be skipped (e.g. those testing different connection methods).
5168

52-
### Creating a New PostgreSQL Cluster Exclusively for Testing
69+
### Creating a New PostgreSQL Cluster Exclusively for Testing Outside of a Devcontainer
5370

5471
The following environment variables need to be set both for initial setup and whenever the tests are run. (direnv is
5572
highly recommended). Depending on your platform, you may need to change the host for `PGX_TEST_UNIX_SOCKET_CONN_STRING`.

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ See the presentation at Golang Estonia, [PGX Top to Bottom](https://www.youtube.
9292

9393
## Supported Go and PostgreSQL Versions
9494

95-
pgx supports the same versions of Go and PostgreSQL that are supported by their respective teams. For [Go](https://golang.org/doc/devel/release.html#policy) that is the two most recent major releases and for [PostgreSQL](https://www.postgresql.org/support/versioning/) the major releases in the last 5 years. This means pgx supports Go 1.24 and higher and PostgreSQL 13 and higher. pgx also is tested against the latest version of [CockroachDB](https://www.cockroachlabs.com/product/).
95+
pgx supports the same versions of Go and PostgreSQL that are supported by their respective teams. For [Go](https://golang.org/doc/devel/release.html#policy) that is the two most recent major releases and for [PostgreSQL](https://www.postgresql.org/support/versioning/) the major releases in the last 5 years. This means pgx supports Go 1.24 and higher and PostgreSQL 14 and higher. pgx also is tested against the latest version of [CockroachDB](https://www.cockroachlabs.com/product/).
9696

9797
## Version Policy
9898

@@ -120,6 +120,7 @@ pgerrcode contains constants for the PostgreSQL error codes.
120120

121121
* [github.com/jackc/pgx-gofrs-uuid](https://github.com/jackc/pgx-gofrs-uuid)
122122
* [github.com/jackc/pgx-shopspring-decimal](https://github.com/jackc/pgx-shopspring-decimal)
123+
* [github.com/ColeBurch/pgx-govalues-decimal](https://github.com/ColeBurch/pgx-govalues-decimal)
123124
* [github.com/twpayne/pgx-geos](https://github.com/twpayne/pgx-geos) ([PostGIS](https://postgis.net/) and [GEOS](https://libgeos.org/) via [go-geos](https://github.com/twpayne/go-geos))
124125
* [github.com/vgarvardt/pgx-google-uuid](https://github.com/vgarvardt/pgx-google-uuid)
125126

0 commit comments

Comments
 (0)