querying-local-postgres
FreeNo executable scriptsNot checkedRun read-only SQL against the local Postgres app database (SELECT, EXPLAIN, EXPLAIN ANALYZE on SELECT). Default local URL…
by PostHog★ 41,278 GitHub starsAbout this skill
Querying local Postgres (READ-ONLY) — PostHog repo
User's query: $ARGUMENTS
Scope: This repo uses PostgreSQL for app metadata (teams, projects, flags, Django models, etc.). Analytics event data lives in ClickHouse, not Postgres — use HogQL / ClickHouse tools for events-style questions unless the user explicitly wants Postgres.
When to use
- User asks to query the database, inspect tables, or run SQL against Postgres
- Debugging: Row-level checks (e.g. why a team/project/flag row looks wrong), migrations, constraints, duplicate keys
- Performance:
EXPLAIN/EXPLAIN (ANALYZE, …)on read-onlySELECTagainst Django or app tables
Instructions
- Strictly forbid mutations — See "Mutations strictly forbidden" below. If the user asks for any write or mutation, refuse and explain the skill is read-only.
- Translate the user's question into one or more read-only SQL statements.
- Show the SQL in a code block before running.
- Run using the command pattern below (always with
PGOPTIONS='-c default_transaction_read_only=on'to force a read-only connection). - Show results and give a brief interpretation (especially when used for debugging or plan review).
Mutations strictly forbidden
Do not run, suggest, or generate any of the following. Refuse and state that this skill is read-only.
- DML:
INSERT,UPDATE,DELETE,MERGE,TRUNCATE - DDL:
CREATE,DROP,ALTER,RENAME - Other writes:
COPY ... TO program,CALL(if it mutates),GRANT/REVOKE EXPLAIN ANALYZEon anything other than a read-onlySELECT(includingWITH … SELECT). Do not wrap DML inEXPLAIN ANALYZE— it would execute the write. The read-only connection below rejects writes, but the agent must not attempt this pattern.- Any statement that modifies data, schema, or roles
Allowed:
SELECT(includingWITH … SELECT)EXPLAIN…SELECT(estimate-only plan; no execution)EXPLAIN (ANALYZE, …) SELECT— executes theSELECTonce; use only for performance analysis. Must run on the read-only connection below.SHOW,SELECTfrom catalog views (pg_stat_*,information_schema, etc.) when read-only
If the user requests a write operation, say: "This skill is read-only. I can't run INSERT/UPDATE/DELETE or other mutations. Use a DB client or migration tool for writes."
EXPLAIN and EXPLAIN ANALYZE (performance)
| Goal | What to use |
|---|---|
| Plan shape, estimated costs, no execution | EXPLAIN (FORMAT TEXT, COSTS) or add VERBOSE |
| Actual timings, row counts, buffer hits | EXPLAIN (ANALYZE, BUFFERS, FORMAT TEXT) on the SELECT |
| Buffer + WAL stats | BUFFERS requires ANALYZE; WAL requires ANALYZE (PostgreSQL 13+) |
Safe pattern: the analyzed statement must be only a SELECT (or WITH … SELECT), run on the read-only connection (see Usage below). Example:
PGOPTIONS='-c default_transaction_read_only=on' psql "$DATABASE_URL" -v ON_ERROR_STOP=1 -c "
EXPLAIN (ANALYZE, BUFFERS, VERBOSE, FORMAT TEXT)
SELECT … LIMIT 100;"
Optional flags (when useful): SETTINGS (show non-default GUCs), WAL (with ANALYZE), TIMING (default on in recent versions for ANALYZE).
Caveats:
EXPLAIN ANALYZEruns the query — can be slow or heavy on large scans; prefer a boundedSELECT(e.g. realisticWHERE,LIMITmatching production shape) when exploring.- Production / shared DBs — analyzing hot or wide queries can add load; prefer staging, a replica, or off-peak when the user cares about impact.
EXPLAINwithoutANALYZE— does not execute the inner statement (except some special cases); still only wrap read-only SQL.
PostHog: connection and DATABASE_URL
Local Postgres (host machine) — default for this skill
Use this hardcoded URL for day-to-day local queries (matches typical Docker Compose + port 5432 on localhost, SSL off):
| Setting | Value |
|---|---|
| Host | localhost |
| Port | 5432 |
| User | posthog |
| Password | posthog |
| Database | posthog |
| SSL | off |
# Prefer this unless the user says their local password/db differs
LOCAL_POSTGRES_URL='postgres://posthog:posthog@localhost:5432/posthog'
Equivalent: postgresql://posthog:posthog@localhost:5432/posthog
Other local DBs on the same server: swap the path only, e.g. ...5432/posthog_persons.
Configuration source of truth (app): posthog/settings/data_stores.py (Django DATABASES, optional replica POSTHOG_POSTGRES_READ_HOST, direct POSTHOG_POSTGRES_DIRECT_HOST, `PER
Install querying-local-postgres in Claude Code & Claude Desktop
Sign up to install this skill
Create a free account to reveal the install command and save the skill to your library.
- Reveal the one-line install command
- Save skills to your synced library
- Get notified when skills update
Allowed tools
Tools this skill is permitted to call.
BashFAQ
What does the querying-local-postgres skill do?
Run read-only SQL against the local Postgres app database (SELECT, EXPLAIN, EXPLAIN ANALYZE on SELECT). Default local URL postgres://posthog:posthog@localhost:5432/posthog; else DATABASE_URL. Use when querying the local DB, inspecting tables, debugging data, or analyzing query plans. Mutations are strictly forbidden.
How do I install the querying-local-postgres skill?
Copy the skill folder into ~/.claude/skills (the Claude Code tab above does this in one command), or install it as a plugin.
Does the querying-local-postgres skill run scripts?
No, this skill is instructions only (SKILL.md) with no executable scripts.
Related skills
skill-creator
Create new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an…
by Anthropicdiscernment-nudge
After you give a substantive answer or draft that the user may act on — advice or recommendations, drafted artifacts such as goals, plans, pitches, proposals…
by Anthropicdata-consolidate
Joins the plant's scheduled exports and connector data into one working dataset — ERP items (NetSuite or Infor M3), sales orders, production work orders…
by Anthropicinspection-to-capa
Runs the quality chain end to end: writes the nonconformance against the requirement it violates, searches history at the moment of writing to say whether…
by Anthropic