Official agent skill

Querying Local Postgres

by PostHog in PostHog/posthog-foss

Run read-only SQL against the local Postgres app database (SELECT, EXPLAIN, EXPLAIN ANALYZE on SELECT).

OfficialMITAuto-check: notesDatabases

Install Querying Local Postgres

skills CLI
$ npx skills add PostHog/posthog-foss --skill querying-local-postgres -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install PostHog/posthog-foss querying-local-postgres --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/PostHog/posthog-foss.git skills-src && mkdir -p .claude/skills && cp -r skills-src/.agents/skills/querying-local-postgres .claude/skills/querying-local-postgres && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
querying-local-postgres
GitHub stars
721
Token cost
~2.5k tokens
SKILL.md length
1,043 words
Files
1
Skills in repo
213
Repo updated
First seen
Licence
MIT

At a glance

Run read-only SQL against the local Postgres app database (SELECT, EXPLAIN, EXPLAIN ANALYZE on SELECT).

  • Works in 5 steps: Strictly forbid mutations — See… → Translate the user's question into one… → Show the SQL in a code block before… → …
  • Querying the local DB
  • SKILL.md covers When to use, Instructions, Mutations strictly forbidden and EXPLAIN and EXPLAIN ANALYZE…, plus 5 more sections
  • Calls psql and npx

What it does

Querying Local Postgres is an agent skill from PostHog/posthog-foss, published by the product's own GitHub organization. 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 DATABASEURL. Use when querying the local DB, inspecting tables, debugging data, or analyzing query plans. Mutations are strictly forbidden.

Its SKILL.md is about 2.5k tokens, which your agent loads only when the skill is triggered. It is a single SKILL.md file with no bundled scripts.

It sits in Databases, covering Query optimization and SQL. It works with PostgreSQL, PostHog and SQL. The repository describes itself as: PostHog FOSS is a read-only mirror of PostHog, with all proprietary code removed. NOTE: This repo is synced automatically from the main PostHog repo. Please raise any issues and… The licence is MIT.

When your agent uses it

  • Querying the local DB
  • Inspecting tables
  • Analyzing query plans

Example prompts

  • “/querying-local-postgres”

Requirements

  • Node.js
  • Docker
  • Pre-approved tools (allowed-tools): Bash

Workflow steps

5 steps, taken from the first numbered list in SKILL.md.

  1. Strictly forbid mutations — See "Mutations strictly forbidden" below. If the user asks for any write or mutation, refuse and explain the…
  2. Translate the user's question into one or more read-only SQL statements.
  3. Show the SQL in a code block before running.
  4. Run using the command pattern below (always with PGOPTIONS='-c default_transaction_read_only=on' to force a read-only connection).
  5. Show results and give a brief interpretation (especially when used for debugging or plan review).

What it can do on your machine

Read from SKILL.md and the folder at commit 2c48221. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves these tools, so the agent can use them without asking each time:

    • Bash

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    Shell commands in SKILL.md call:

    • psql
    • npx

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md. Its commands use npx, which can reach the network depending on how they are called.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Querying Local Postgres loads about 2.5k tokens when it runs. Until then it costs about 86 tokens; SKILL.md has 1,043 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~86
When it runs · the whole SKILL.md, loaded when a task matches
~2.5k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check: notes

The automated check noted patterns worth knowing about, such as sudo or a known installer.

  • NoteMentions a .env fileSKILL.md:111
    **Rust / sqlx:** Some services use `rust/.env` for `DATABASE_URL` when working from `posthog/rust` — see `rust/README.md
  • NoteMentions a .env fileSKILL.md:143
    npx dotenv -e .env -- bash -c "PGOPTIONS='-c default_transaction_read_only=on' psql \"\$DATABASE_URL\" -c 'SELECT ...'"
  • NotePre-approves every shell command (allowed-tools: Bash)SKILL.md
    allowed-tools: Bash

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from PostHog/posthog-foss at commit 2c48221, republished under its MIT licence (© PostHog). 1,043 words, ~2,480 tokens.

Download SKILL.mdSave it as .claude/skills/querying-local-postgres/SKILL.md (or your agent's skills folder).
name
querying-local-postgres
description
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.
allowed-tools
Bash

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-only SELECT against Django or app tables

Instructions

  1. 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.
  2. Translate the user's question into one or more read-only SQL statements.
  3. Show the SQL in a code block before running.
  4. Run using the command pattern below (always with PGOPTIONS='-c default_transaction_read_only=on' to force a read-only connection).
  5. 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 ANALYZE on anything other than a read-only SELECT (including WITH … SELECT). Do not wrap DML in EXPLAIN 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 (including WITH … SELECT)
  • EXPLAIN … SELECT (estimate-only plan; no execution)
  • EXPLAIN (ANALYZE, …) SELECT — executes the SELECT once; use only for performance analysis. Must run on the read-only connection below.
  • SHOW, SELECT from 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)

GoalWhat to use
Plan shape, estimated costs, no executionEXPLAIN (FORMAT TEXT, COSTS) or add VERBOSE
Actual timings, row counts, buffer hitsEXPLAIN (ANALYZE, BUFFERS, FORMAT TEXT) on the SELECT
Buffer + WAL statsBUFFERS 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:

bash
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 ANALYZE runs the query — can be slow or heavy on large scans; prefer a bounded SELECT (e.g. realistic WHERE, LIMIT matching 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.
  • EXPLAIN without ANALYZE — 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):

SettingValue
Hostlocalhost
Port5432
Userposthog
Passwordposthog
Databaseposthog
SSLoff
bash
# 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, PERSONS_DB_WRITER_URL, product DB routing from products/db_routing.yaml).

When not using the hardcoded URL: Connecting from the host with the same credentials is documented in Developing locally (fe_sendauth troubleshooting). Ensure containers are running.

Default env when DEBUG is on: Django builds a default DATABASE_URL from PGHOST (default db), PGUSER / PGPASSWORD, PGPORT, PGDATABASE — matching in-container hostnames. From the host, use localhost and the same user/password/database name unless your shell already exports DATABASE_URL.

Multiple PostgreSQL databases (same server in local compose; separate logical DBs):

  • Main app DB: usually posthog
  • Persons DB: posthog_persons (PERSONS_DB_WRITER_URL / PERSONS_DB_READER_URL)
  • Product-isolated DBs: posthog_<name> per products/db_routing.yaml (created by docker/postgres-init-scripts/create-product-dbs.sh)
  • Other init scripts may create additional DBs (e.g. cyclotron) — inspect docker/postgres-init-scripts/ if needed

Point psql at the right database by changing the path in DATABASE_URL (e.g. .../posthog_persons).

Rust / sqlx: Some services use rust/.env for DATABASE_URL when working from posthog/rust — see rust/README.md.

Show full SKILL.md (354 more words)Show less

Usage (command pattern)

Always force the connection read-only via PGOPTIONS='-c default_transaction_read_only=on' so Postgres rejects writes even if the generated SQL is wrong.

Why PGOPTIONS, not SET SESSION CHARACTERISTICS AS TRANSACTION READ ONLY? A psql -c "..." string with multiple statements runs as a single implicit transaction. SET SESSION CHARACTERISTICS AS TRANSACTION READ ONLY only sets the default for subsequent transactions — the in-progress one keeps the read-write mode it was given at BEGIN, so a write in the same -c would not be rejected. PGOPTIONS='-c default_transaction_read_only=on' sets the GUC at connection startup, so every transaction (including the implicit -c one) starts read-only. The inline equivalent is SET TRANSACTION READ ONLY; as the first statement of the -c string (it affects the current transaction, unlike SET SESSION CHARACTERISTICS).

Run from the PostHog repo root so relative env paths resolve.

Default — local hardcoded URL (posthog / posthog @ localhost:5432 / db posthog):

bash
PGOPTIONS='-c default_transaction_read_only=on' psql "postgres://posthog:posthog@localhost:5432/posthog" -v ON_ERROR_STOP=1 -c "SELECT 1;"

Option A — DATABASE_URL already in the shell (e.g. after flox activate or manual export):

bash
PGOPTIONS='-c default_transaction_read_only=on' psql "$DATABASE_URL" -v ON_ERROR_STOP=1 -c "SELECT 1;"

Option B — load from a gitignored env file at repo root (if DATABASE_URL is set there):

bash
npx dotenv -e .env -- bash -c "PGOPTIONS='-c default_transaction_read_only=on' psql \"\$DATABASE_URL\" -c 'SELECT ...'"
  • Use single quotes for string literals in SQL inside the shell as usual; escape carefully when nesting quotes in -c.
  • Default LIMIT 100 unless the user specifies otherwise.
  • For wide rows use -x: psql ... -x -c "...".

Schema reference (PostHog)

  • Django models → tables: see posthog/models/ (and product packages under products/). Table names are usually prefixed with posthog_ and snake-cased (e.g. posthog_team, posthog_user). Confirm with \dt posthog_* in psql, or check the model's Meta.db_table if nonstandard.
  • Migrations: posthog/migrations/ (and product migration paths) define the authoritative DDL over time.
  • Person table name: configurable via PERSON_TABLE_NAME (see data_stores.py); default posthog_person.

Debugging with the query runner (PostHog-flavored)

  • Confirm a row exists for a team, project, user, or feature-flag linkage; check soft-delete / deleted fields where applicable.
  • Compare counts and joins to what the app assumes (e.g. membership, project access).
  • Validate replica vs primary read differences only if the user is connected to the right host (replica: POSTHOG_POSTGRES_READ_HOST).
  • Use EXPLAIN ANALYZE on SELECT for slow Django queries replicated as SQL — mind loading production-sized data.

Cross-reference

  • Local setup and DB gotchas: docs/published/handbook/engineering/developing-locally.md
  • Repo CLI: hogli (see .agents/skills/hogli/SKILL.md)

© PostHog, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

Just SKILL.md in .agents/skills/querying-local-postgres of PostHog/posthog-foss.

Open the folder on GitHubat commit 2c48221

Compare with similar skills

Querying Local Postgres next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Querying Local Postgres compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Querying Local Postgres this skillPostHog/posthog-foss721—~2.5kAutomated safety check: NotesMIT
PostgreSQL Documentation Reference2025Emma/vibe-coding-cn23k1 repos~19kAutomated safety check: PassMIT
Postgresql Best Practices CloudbaseTencentCloudBase/CloudBase-AI-Toolkit1.1k1 repos~1.3kAutomated safety check: PassMIT
SQL ProJeffallan/claude-skills12k—~1.3kAutomated safety check: PassMIT
SQL Insightzebbern/claude-code-guide4.6k—~2.1kAutomated safety check: PassMIT
Discover Databaserand/cc-polymath181—~2kAutomated safety check: PassMIT

Similar skills

  • PostgreSQL Documentation Reference

    2025Emma/vibe-coding-cn

    PostgreSQL database documentation - SQL queries, database design, administration, performance tuning, and advanced features. Use when working with PostgreSQL…

    23k GitHub starsUsed in 1 repo~19k tokens
    DatabasesAuto-check passed
  • Postgresql Best Practices Cloudbase

    TencentCloudBase/CloudBase-AI-Toolkit

    CloudBase PostgreSQL access-pattern and slow-query quality guidance.

    1.1k GitHub starsUsed in 1 repo~1.3k tokens
    DatabasesAuto-check passed
  • SQL Pro

    Jeffallan/claude-skills

    Optimizes SQL queries and designs schemas using CTEs, window functions, covering indexes and EXPLAIN ANALYZE, with notes on dialect differences between major databases.

    12k GitHub stars~1.3k tokensUpdated 4 days ago
    DatabasesAuto-check passed
  • SQL Insight

    zebbern/claude-code-guide

    Translate natural language to SQL, optimize query performance, and interpret EXPLAIN plans for SQLite and PostgreSQL.

    4.6k GitHub stars~2.1k tokensUpdated today
    DatabasesAuto-check passed
  • Discover Database

    rand/cc-polymath

    Automatically discover database skills when working with SQL, PostgreSQL, MongoDB, Redis, database schema design, query optimization, migrations, connection pooling, ORMs, or database selection.

    181 GitHub stars~2k tokensUpdated 7 mo ago
    DatabasesAuto-check passed
  • SQL Optimization

    github/awesome-copilot

    Official

    Universal SQL performance optimization assistant for comprehensive query tuning, indexing strategies, and database performance analysis across all SQL databases (MySQL, PostgreSQL, SQL Server…

    40k GitHub starsUsed in 2 repos~2.3k tokens
    DatabasesAuto-check passed

More from PostHog/posthog-foss

All 213 skills in this repo
  • Authoring Log Alerts

    PostHog/posthog-foss

    Official

    Author useful, low-noise log alerts on services in a PostHog project.

    721 GitHub stars~3k tokensUpdated today
    Auto-check passed
  • Autoresolving PR Conflicts

    PostHog/posthog-foss

    Official

    Operating procedure for the conflict-autoresolver agent: sweep open PostHog/posthog PRs that conflict with master, resolve the trivial conflicts (generated artifacts deterministically, source…

    721 GitHub stars~4.2k tokensUpdated today
    Auto-check passed
  • Official

    Help users debug PostHog Error Tracking stack-trace symbolication for any supported platform — JavaScript/TypeScript web, React Native (Hermes), Android (Proguard / R8), or iOS / macOS (dSYM).

    721 GitHub stars~2.2k tokensUpdated today
    Auto-check passed
  • Exploring Apm Traces

    PostHog/posthog-foss

    Official

    Investigates distributed application performance using PostHog APM (OpenTelemetry span) data via MCP.

    721 GitHub stars~3.5k tokensUpdated today
    Auto-check passed
  • Exploring LLM Traces

    PostHog/posthog-foss

    Official

    Debug and inspect LLM/AI agent traces using PostHog's MCP tools.

    721 GitHub stars~4.4k tokensUpdated today
    Auto-check passed
  • Investigate Metric

    PostHog/posthog-foss

    Official

    Diagnose why a product metric changed (dropped, spiked, or plateaued) by orchestrating breakdowns, actors, paths, lifecycle, retention, and annotations queries.

    721 GitHub stars~1.9k tokensUpdated today
    Auto-check passed

Categories

Questions about Querying Local Postgres

What does Querying Local Postgres do?

Run read-only SQL against the local Postgres app database (SELECT, EXPLAIN, EXPLAIN ANALYZE on SELECT). Querying Local Postgres is an agent skill from PostHog/posthog-foss, published by the product's own GitHub organization. Run read-only SQL against the local Postgres app database (SELECT, EXPLAIN, EXPLAIN ANALYZE on SELECT).

When should I use Querying Local Postgres?

Querying Local Postgres fits situations like: querying the local DB; inspecting tables; analyzing query plans.

How do I install Querying Local Postgres in Claude Code?

Run `npx skills add PostHog/posthog-foss --skill querying-local-postgres -a claude-code`. Or copy the skill folder (.agents/skills/querying-local-postgres in PostHog/posthog-foss) into .claude/skills/querying-local-postgres in your project. Claude Code loads it when a task matches its description.

How do I install Querying Local Postgres in Codex?

Run `npx skills add PostHog/posthog-foss --skill querying-local-postgres -a codex`. Or copy the skill folder (.agents/skills/querying-local-postgres in PostHog/posthog-foss) into .agents/skills/querying-local-postgres in your project. Codex loads it when a task matches its description.

Can I use Querying Local Postgres in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add PostHog/posthog-foss --skill querying-local-postgres -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/querying-local-postgres, .gemini/skills/querying-local-postgres, .github/skills/querying-local-postgres and .opencode/skills/querying-local-postgres in your project.

What does Querying Local Postgres need to run?

Going by SKILL.md and its folder, Querying Local Postgres needs the command-line tools its instructions call (psql and npx). Our summary lists: Node.js; Docker. Its frontmatter pre-approves these tools: Bash.

Does Querying Local Postgres access the network?

SKILL.md contains no URLs. Its commands use npx, which can reach the network depending on how they are called. This is read from the text; nothing was executed.

Is Querying Local Postgres safe to install?

Our automated static check of SKILL.md found notes only (mentions a .env file; pre-approves every shell command (allowed-tools: bash)), nothing it rates as a warning. It is not a guarantee. Review the folder before installing.

What licence does Querying Local Postgres use?

Querying Local Postgres is published under the MIT licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Querying Local Postgres use?

About 2.5k tokens (SKILL.md is roughly 9.9k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to Querying Local Postgres?

Skills that share tags, products or a category with Querying Local Postgres: PostgreSQL Documentation Reference (2025Emma/vibe-coding-cn, 23k stars), Postgresql Best Practices Cloudbase (TencentCloudBase/CloudBase-AI-Toolkit, 1.1k stars), SQL Pro (Jeffallan/claude-skills, 12k stars) and SQL Insight (zebbern/claude-code-guide, 4.6k stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Querying Local Postgres?

PostHog (a GitHub organization, an official publisher) maintains it in PostHog/posthog-foss, which has 721 GitHub stars. The repository holds 213 skills in this directory. The repository was last updated on October 7, 2026.

Source: PostHog/posthog-foss on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.