{"id":50812733,"url":"https://github.com/pgx-contrib/pgxprof","last_synced_at":"2026-06-13T06:33:39.636Z","repository":{"id":352126811,"uuid":"860448713","full_name":"pgx-contrib/pgxprof","owner":"pgx-contrib","description":"Query profiler for pgx v5 — drop-in tracer that captures EXPLAIN (ANALYZE, FORMAT JSON) plans via inline SQL annotations and a pluggable Reporter interface","archived":false,"fork":false,"pushed_at":"2026-06-06T08:02:34.000Z","size":78,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-06-06T10:05:16.497Z","etag":null,"topics":["explain-analyze","go","golang","pgx","pgxpool","postgresql","profiler","query-plan","query-profiler","tracing"],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/github.com/pgx-contrib/pgxprof","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pgx-contrib.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-09-20T13:05:00.000Z","updated_at":"2026-06-06T08:02:36.000Z","dependencies_parsed_at":null,"dependency_job_id":"207fc38a-617e-444e-867c-08981f8cd371","html_url":"https://github.com/pgx-contrib/pgxprof","commit_stats":null,"previous_names":["pgx-contrib/pgxprof"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/pgx-contrib/pgxprof","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pgx-contrib%2Fpgxprof","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pgx-contrib%2Fpgxprof/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pgx-contrib%2Fpgxprof/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pgx-contrib%2Fpgxprof/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pgx-contrib","download_url":"https://codeload.github.com/pgx-contrib/pgxprof/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pgx-contrib%2Fpgxprof/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34275068,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-13T02:00:06.617Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["explain-analyze","go","golang","pgx","pgxpool","postgresql","profiler","query-plan","query-profiler","tracing"],"created_at":"2026-06-13T06:33:38.919Z","updated_at":"2026-06-13T06:33:39.631Z","avatar_url":"https://github.com/pgx-contrib.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# pgxprof\n\n[![CI](https://github.com/pgx-contrib/pgxprof/actions/workflows/ci.yml/badge.svg)](https://github.com/pgx-contrib/pgxprof/actions/workflows/ci.yml)\n[![Release](https://img.shields.io/github/v/release/pgx-contrib/pgxprof)](https://github.com/pgx-contrib/pgxprof/releases)\n[![Go Reference](https://pkg.go.dev/badge/github.com/pgx-contrib/pgxprof.svg)](https://pkg.go.dev/github.com/pgx-contrib/pgxprof)\n[![License](https://img.shields.io/github/license/pgx-contrib/pgxprof)](LICENSE)\n[![Go Version](https://img.shields.io/github/go-mod/go-version/pgx-contrib/pgxprof)](go.mod)\n[![pgx Version](https://img.shields.io/badge/pgx-v5-blue)](https://github.com/jackc/pgx)\n\nQuery profiler for [pgx v5](https://github.com/jackc/pgx).\n\n## Features\n\n- Transparent `EXPLAIN (ANALYZE, FORMAT JSON)` wrapping for `Query`, `QueryRow`, and `SendBatch`\n- Inline SQL annotation directives control profiling per query\n- Decoded `QueryPlan` / `QueryTrace` Go structs ready for further processing\n- Pluggable `Reporter` interface with built-in JSON writer and `log/slog` sinks\n- Works with any `pgx`-compatible connection: `*pgx.Conn`, `*pgxpool.Pool`, or `pgx.Tx`\n\n## Installation\n\n```bash\ngo get github.com/pgx-contrib/pgxprof\n```\n\n## Usage\n\n### Basic pool setup\n\n```go\nconfig, err := pgxpool.ParseConfig(os.Getenv(\"PGX_DATABASE_URL\"))\nif err != nil {\n    panic(err)\n}\n\nconfig.ConnConfig.Tracer = \u0026pgxprof.QueryTracer{\n    // Default options applied when a query has no inline annotations.\n    Options: \u0026pgxprof.QueryOptions{\n        Explain: true,\n        Analyze: true,\n    },\n    // Defaults to a WriterReporter that prints JSON to stdout.\n    Reporter: \u0026pgxprof.LoggerReporter{Logger: slog.Default()},\n}\n\npool, err := pgxpool.NewWithConfig(ctx, config)\n```\n\n### Per-query annotations\n\nEmbed profiler directives in SQL comments. Annotations override the default `Options` for that statement:\n\n```sql\n-- @explain true\n-- @analyze true\nSELECT id, name FROM users WHERE active = true\n```\n\n```go\nrows, err := pool.Query(ctx, `\n    -- @explain true\n    -- @analyze true\n    SELECT id, name FROM users WHERE active = $1`, true)\n```\n\n### Custom reporter\n\nImplement the `Reporter` interface to ship traces anywhere:\n\n```go\ntype Reporter interface {\n    Report(ctx context.Context, trace *TraceQueryData)\n    ReportBatch(ctx context.Context, trace *TraceBatchData)\n}\n```\n\n## Annotation directives\n\n| Directive | Value | Description |\n|---|---|---|\n| `@explain` | `true` / `false` | Wrap the query in `EXPLAIN`. Required for profiling. |\n| `@analyze` | `true` / `false` | Add the `ANALYZE` clause. Ignored when `@explain` is `false`. |\n\n## Performance caveat\n\n`EXPLAIN ANALYZE` **executes the query** inside a transaction that `pgxprof`\nrolls back, so profiling runs every matching statement twice: once for the\ncaller and once for the plan. This roughly doubles per-query latency and\ndatabase load.\n\nUse `pgxprof` in development and staging environments, or gate it behind\nper-query directives so only the queries you're investigating pay the cost.\n\n## Development\n\n### DevContainer\n\nOpen in VS Code with the Dev Containers extension. The environment provides Go,\nPostgreSQL 18, and Nix automatically.\n\n```\nPGX_DATABASE_URL=postgres://vscode@postgres:5432/pgxprof?sslmode=disable\n```\n\n### Nix\n\n```bash\nnix develop          # enter shell with Go\ngo tool ginkgo run -r\n```\n\n### Run tests\n\n```bash\n# Unit tests only (no database required)\ngo tool ginkgo run -r\n\n# With integration tests\nexport PGX_DATABASE_URL=\"postgres://localhost/pgxprof?sslmode=disable\"\ngo tool ginkgo run -r\n```\n\n## License\n\n[MIT](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpgx-contrib%2Fpgxprof","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpgx-contrib%2Fpgxprof","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpgx-contrib%2Fpgxprof/lists"}