Contributing#
Thank you for your interest in contributing to pgcue!. Contributions are welcome, whether they are bug reports, feature requests, code improvements, documentation updates, or new features. Contributions are welcome in form of Pull Requests. This guide will help you get started with the contributing process.
For significant changes, such as new rules, please consider creating an issue to outline your proposed feature for discussion.
Development#
You need:
- the tool versions in
.tool-versions: Go, golangci-lint and GoReleaser; - Docker, for the integration tests;
- uv, for the pre-commit hooks, the docs and releases.
git clone https://github.com/bolajiwahab/pgcue.git
cd pgcue
uv run --locked --no-build --only-group dev pre-commit install
make build
pre-commit install adds the commit hook and the commit message hook.
Add a check#
A check is one YAML file, and its path sets its ID. Use the bundled activity.idle_transactions check in knowledge/topics/activity/checks/idle_transactions.yaml as a model for a new check.
---
name: Idle transactions
description: Shows sessions left idle inside a transaction beyond a specified duration.
requires_monitor: true
result: current
guidance:
use_when:
- Vacuum cannot remove old row versions or tables are accumulating dead tuples.
- Applications may be leaving transactions open between requests.
inspect:
- Old transaction start times and long idle durations.
- Repeated application names, users, or query patterns.
related:
- activity.long_transactions
columns:
application_name: Client-supplied application name.
database_name: Database to which the session is connected.
duration: Time elapsed since the transaction began.
pid: PostgreSQL backend process ID.
query: Most recently observed statement in the session.
state: Current backend state.
transaction_started: Time at which the current transaction began.
user_name: Connected PostgreSQL role.
parameters:
minimum_duration:
type: duration
default: 5m
description: Minimum time a transaction must have remained open.
limit:
type: integer
minimum: 1
nullable: true
default: 20
description: Maximum number of rows to show. Use NULL for no limit.
sql:
- requires:
postgresql: "14"
statement: |
SELECT pid
, usename AS user_name
, datname AS database_name
, application_name
, xact_start AS transaction_started
, pg_catalog.now() - xact_start AS duration
, state
, query
FROM pg_catalog.pg_stat_activity
WHERE state IN ('idle in transaction', 'idle in transaction (aborted)')
AND xact_start IS NOT NULL
AND pid <> pg_catalog.pg_backend_pid()
AND pg_catalog.now() - xact_start >= @minimum_duration::interval
ORDER BY xact_start
, pid
LIMIT @limit;
| Field | Meaning |
|---|---|
requires_monitor |
Results are incomplete without pg_monitor, so pgcue warns when it runs the check as a role that lacks it. |
result |
current for a state at the moment of the run, cumulative for counters since the last statistics reset. |
guidance |
What describe shows: when to use the check, what to inspect, and related checks. |
columns |
Every column the SQL returns, with its meaning. |
parameters |
Each parameter's type (string, integer, boolean or duration), default, and optionally minimum, nullable or required. The SQL refers to it as @name. |
sql |
One or more variants, each with the minimum PostgreSQL or extension version it requires. |
Version variants#
When a catalog view changes between PostgreSQL versions, add SQL variants that return the same columns. pgcue runs the most specific variant the server satisfies. For example, wal.statistics has variants for PostgreSQL 14+ and 18+. The 18+ variant returns NULL for the write and sync fields that were removed from pg_stat_wal.
A variant can also require an extension. statements.top has variants for different versions of pg_stat_statements.
Validate#
make test-unit # loads and validates every check
PG_MAJOR_VERSION=18 make test-integration # runs every variant on that version
go run ./cmd/pgcue describe activity.idle_transactions
make docs # regenerates the check and investigation pages
Run the integration tests on the oldest and newest version each variant supports, and commit the regenerated pages with the check. To use the check in an investigation, add it as a step, with its check ID and a reason, in knowledge/investigations/<id>.yaml.
Build and test#
| Command | Does |
|---|---|
make build |
Builds ./pgcue. |
make fmt |
Formats the Go code. |
make lint |
Runs golangci-lint. |
make test-unit |
Runs the unit tests. |
make test-integration |
Runs every test against PostgreSQL in Docker. Set PG_MAJOR_VERSION to choose the version, 14 by default. |
make check-coverage |
Measures coverage from the integration tests. Every file must reach 100%. |
make tidy |
Tidies go.mod and go.sum. |
make docs |
Regenerates the check and investigation pages and the command help. CI fails when they are out of date. |
make docs-serve |
Serves the existing docs locally. |
make vulncheck |
Scans the dependencies with govulncheck. |
make check |
Runs the formatting check, lint, govulncheck, the pre-commit hooks and the integration tests. |
make snapshot |
Builds the release archives locally with GoReleaser. |
Docs#
The site is served at http://localhost:8000.
Run make docs after changing the catalogue or CLI help to refresh the generated pages.
Pull requests#
Title pull requests as Conventional Commits, such as feat: add a replication check or fix(deps): update module x. The title becomes the commit message, which decides the release notes section and the next version:
| Type | Release notes | Version |
|---|---|---|
feat! |
Breaking changes | Minor, until 1.0.0 |
feat, perf |
Features | Minor for feat, patch for perf |
fix |
Bug fixes | Patch |
refactor |
Refactor | Patch |
chore, build, ci, docs |
Their own sections | None |
Releases#
make release-preview # the next version and changelog, without changing anything
make release # bump, tag and push from the default branch
The pushed tag starts the release workflow, which publishes the archives and the container image.