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…
Run read-only SQL against the local Postgres app database (SELECT, EXPLAIN, EXPLAIN ANALYZE on SELECT).
$ npx skills add PostHog/posthog-foss --skill querying-local-postgres -a claude-codeProject install by default; add -g for ~/.claude/skills/.
$ gh skill install PostHog/posthog-foss querying-local-postgres --agent claude-codeProject scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).
$ 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-srcUse ~/.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/
Install the "querying-local-postgres" agent skill from https://github.com/PostHog/posthog-foss/tree/master/.agents/skills/querying-local-postgres into .claude/skills/querying-local-postgres/ in this project. Copy the whole folder (SKILL.md and every file beside it), keep the folder name "querying-local-postgres", then confirm the skill loads.Claude Code copies the folder itself, the same result as the manual copy. Check what it changed before you commit it.
$skill-installer install https://github.com/PostHog/posthog-foss/tree/master/.agents/skills/querying-local-postgresType this inside Codex. $skill-installer <name> installs a curated skill from openai/skills. The installer writes to $CODEX_HOME/skills (default ~/.codex/skills). Restart Codex if the skill does not show up.
$ npx skills add PostHog/posthog-foss --skill querying-local-postgres -a codexProject install goes to .agents/skills/; add -g for ~/.codex/skills/.
$ gh skill install PostHog/posthog-foss querying-local-postgres --agent codexProject scope by default (.agents/skills/); add --scope user for a personal install.
$ git clone --depth 1 https://github.com/PostHog/posthog-foss.git skills-src && mkdir -p .agents/skills && cp -r skills-src/.agents/skills/querying-local-postgres .agents/skills/querying-local-postgres && rm -rf skills-srcUse ~/.agents/skills/ instead of .agents/skills for a personal install.
Codex skills documentation · loads skills from .agents/skills/
Install the "querying-local-postgres" agent skill from https://github.com/PostHog/posthog-foss/tree/master/.agents/skills/querying-local-postgres into .agents/skills/querying-local-postgres/ in this project. Copy the whole folder (SKILL.md and every file beside it), keep the folder name "querying-local-postgres", then confirm the skill loads.Codex copies the folder itself, the same result as the manual copy. Check what it changed before you commit it.
$ npx skills add PostHog/posthog-foss --skill querying-local-postgres -a cursorProject install goes to .agents/skills/; add -g for ~/.cursor/skills/.
$ gh skill install PostHog/posthog-foss querying-local-postgres --agent cursorProject scope by default (.agents/skills/); add --scope user for a personal install.
$ git clone --depth 1 https://github.com/PostHog/posthog-foss.git skills-src && mkdir -p .cursor/skills && cp -r skills-src/.agents/skills/querying-local-postgres .cursor/skills/querying-local-postgres && rm -rf skills-srcUse ~/.cursor/skills/ instead of .cursor/skills for a personal install.
Cursor skills documentation · loads skills from .cursor/skills/, .agents/skills/, .claude/skills/, .codex/skills/
Install the "querying-local-postgres" agent skill from https://github.com/PostHog/posthog-foss/tree/master/.agents/skills/querying-local-postgres into .cursor/skills/querying-local-postgres/ in this project. Copy the whole folder (SKILL.md and every file beside it), keep the folder name "querying-local-postgres", then confirm the skill loads.Cursor copies the folder itself, the same result as the manual copy. Check what it changed before you commit it.
$ gemini skills install https://github.com/PostHog/posthog-foss.git --path .agents/skills/querying-local-postgres--scope user (default) or --scope workspace; --path is the subfolder of the repo that holds the skill; --consent skips the security confirmation prompt.
$ npx skills add PostHog/posthog-foss --skill querying-local-postgres -a gemini-cliProject install goes to .agents/skills/; add -g for ~/.gemini/skills/.
$ gh skill install PostHog/posthog-foss querying-local-postgres --agent gemini-cliProject scope by default (.agents/skills/); add --scope user for a personal install.
$ git clone --depth 1 https://github.com/PostHog/posthog-foss.git skills-src && mkdir -p .gemini/skills && cp -r skills-src/.agents/skills/querying-local-postgres .gemini/skills/querying-local-postgres && rm -rf skills-srcUse ~/.gemini/skills/ instead of .gemini/skills for a personal install, then run /skills reload.
Gemini CLI skills documentation · loads skills from .gemini/skills/, .agents/skills/
Install the "querying-local-postgres" agent skill from https://github.com/PostHog/posthog-foss/tree/master/.agents/skills/querying-local-postgres into .gemini/skills/querying-local-postgres/ in this project. Copy the whole folder (SKILL.md and every file beside it), keep the folder name "querying-local-postgres", then confirm the skill loads.Gemini CLI copies the folder itself, the same result as the manual copy. Check what it changed before you commit it.
$ gh skill install PostHog/posthog-foss querying-local-postgresInstalls for Copilot at project scope by default; add --scope user for a personal install. Preview a skill first with gh skill preview. Needs GitHub CLI 2.90.0 or later (public preview).
$ npx skills add PostHog/posthog-foss --skill querying-local-postgres -a github-copilotProject install goes to .agents/skills/; add -g for ~/.copilot/skills/.
$ git clone --depth 1 https://github.com/PostHog/posthog-foss.git skills-src && mkdir -p .github/skills && cp -r skills-src/.agents/skills/querying-local-postgres .github/skills/querying-local-postgres && rm -rf skills-srcUse ~/.copilot/skills/ instead of .github/skills for a personal install. Commit .github/skills so cloud agent and code review can use it.
GitHub Copilot skills documentation · loads skills from .github/skills/, .claude/skills/, .agents/skills/
Install the "querying-local-postgres" agent skill from https://github.com/PostHog/posthog-foss/tree/master/.agents/skills/querying-local-postgres into .github/skills/querying-local-postgres/ in this project. Copy the whole folder (SKILL.md and every file beside it), keep the folder name "querying-local-postgres", then confirm the skill loads.GitHub Copilot copies the folder itself, the same result as the manual copy. Check what it changed before you commit it.
$ npx skills add PostHog/posthog-foss --skill querying-local-postgres -a opencodeOpenCode documents no install command of its own. Project install goes to .agents/skills/; add -g for ~/.config/opencode/skills/.
$ gh skill install PostHog/posthog-foss querying-local-postgres --agent opencodeProject scope by default (.agents/skills/); add --scope user for a personal install.
$ git clone --depth 1 https://github.com/PostHog/posthog-foss.git skills-src && mkdir -p .opencode/skills && cp -r skills-src/.agents/skills/querying-local-postgres .opencode/skills/querying-local-postgres && rm -rf skills-srcUse ~/.config/opencode/skills/ instead of .opencode/skills for a personal install.
OpenCode skills documentation · loads skills from .opencode/skills/, .claude/skills/, .agents/skills/
Install the "querying-local-postgres" agent skill from https://github.com/PostHog/posthog-foss/tree/master/.agents/skills/querying-local-postgres into .opencode/skills/querying-local-postgres/ in this project. Copy the whole folder (SKILL.md and every file beside it), keep the folder name "querying-local-postgres", then confirm the skill loads.OpenCode copies the folder itself, the same result as the manual copy. Check what it changed before you commit it.
querying-local-postgresRun 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). 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.
5 steps, taken from the first numbered list in SKILL.md.
Read from SKILL.md and the folder at commit 2c48221. It shows what the files ask for, not the result of running them.
Pre-approves these tools, so the agent can use them without asking each time:
BashFrom allowed-tools in the SKILL.md frontmatter.
Shell commands in SKILL.md call:
psqlnpxFrom the folder's file list and the shell code blocks in SKILL.md.
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.
Names no API keys, tokens, secrets or passwords.
From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.
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.
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.
The automated check noted patterns worth knowing about, such as sudo or a known installer.
**Rust / sqlx:** Some services use `rust/.env` for `DATABASE_URL` when working from `posthog/rust` — see `rust/README.mdnpx dotenv -e .env -- bash -c "PGOPTIONS='-c default_transaction_read_only=on' psql \"\$DATABASE_URL\" -c 'SELECT ...'"allowed-tools: BashAutomated 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.
The full file from PostHog/posthog-foss at commit 2c48221, republished under its MIT licence (© PostHog). 1,043 words, ~2,480 tokens.
.claude/skills/querying-local-postgres/SKILL.md (or your agent's skills folder).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.
EXPLAIN / EXPLAIN (ANALYZE, …) on read-only SELECT against Django or app tablesPGOPTIONS='-c default_transaction_read_only=on' to force a read-only connection).Do not run, suggest, or generate any of the following. Refuse and state that this skill is read-only.
INSERT, UPDATE, DELETE, MERGE, TRUNCATECREATE, DROP, ALTER, RENAMECOPY ... TO program, CALL (if it mutates), GRANT/REVOKEEXPLAIN 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.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-onlyIf 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."
| 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 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.EXPLAIN without ANALYZE — does not execute the inner statement (except some special cases); still only wrap read-only SQL.DATABASE_URLUse 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, 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):
posthogposthog_persons (PERSONS_DB_WRITER_URL / PERSONS_DB_READER_URL)posthog_<name> per products/db_routing.yaml (created by docker/postgres-init-scripts/create-product-dbs.sh)docker/postgres-init-scripts/ if neededPoint 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.
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, notSET SESSION CHARACTERISTICS AS TRANSACTION READ ONLY? Apsql -c "..."string with multiple statements runs as a single implicit transaction.SET SESSION CHARACTERISTICS AS TRANSACTION READ ONLYonly sets the default for subsequent transactions — the in-progress one keeps the read-write mode it was given atBEGIN, so a write in the same-cwould not be rejected.PGOPTIONS='-c default_transaction_read_only=on'sets the GUC at connection startup, so every transaction (including the implicit-cone) starts read-only. The inline equivalent isSET TRANSACTION READ ONLY;as the first statement of the-cstring (it affects the current transaction, unlikeSET SESSION CHARACTERISTICS).
Run from the PostHog repo root so relative env paths resolve.
Default — local hardcoded URL (posthog / posthog @ localhost:5432 / db posthog):
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):
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):
npx dotenv -e .env -- bash -c "PGOPTIONS='-c default_transaction_read_only=on' psql \"\$DATABASE_URL\" -c 'SELECT ...'"-c.LIMIT 100 unless the user specifies otherwise.-x: psql ... -x -c "...".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.posthog/migrations/ (and product migration paths) define the authoritative DDL over time.PERSON_TABLE_NAME (see data_stores.py); default posthog_person.deleted fields where applicable.POSTHOG_POSTGRES_READ_HOST).EXPLAIN ANALYZE on SELECT for slow Django queries replicated as SQL — mind loading production-sized data.docs/published/handbook/engineering/developing-locally.mdhogli (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
Just SKILL.md in .agents/skills/querying-local-postgres of PostHog/posthog-foss.
Open the folder on GitHubat commit 2c48221
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.
| Skill | Stars | Used in | Tokens | Auto-check | Licence | Repo updated |
|---|---|---|---|---|---|---|
| Querying Local Postgres this skillPostHog/posthog-foss | 721 | — | ~2.5k | Automated safety check: Notes | MIT | |
| PostgreSQL Documentation Reference2025Emma/vibe-coding-cn | 23k | 1 repos | ~19k | Automated safety check: Pass | MIT | |
| Postgresql Best Practices CloudbaseTencentCloudBase/CloudBase-AI-Toolkit | 1.1k | 1 repos | ~1.3k | Automated safety check: Pass | MIT | |
| SQL ProJeffallan/claude-skills | 12k | — | ~1.3k | Automated safety check: Pass | MIT | |
| SQL Insightzebbern/claude-code-guide | 4.6k | — | ~2.1k | Automated safety check: Pass | MIT | |
| Discover Databaserand/cc-polymath | 181 | — | ~2k | Automated safety check: Pass | MIT |
2025Emma/vibe-coding-cn
PostgreSQL database documentation - SQL queries, database design, administration, performance tuning, and advanced features. Use when working with PostgreSQL…
TencentCloudBase/CloudBase-AI-Toolkit
CloudBase PostgreSQL access-pattern and slow-query quality guidance.
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.
zebbern/claude-code-guide
Translate natural language to SQL, optimize query performance, and interpret EXPLAIN plans for SQLite and PostgreSQL.
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.
github/awesome-copilot
Universal SQL performance optimization assistant for comprehensive query tuning, indexing strategies, and database performance analysis across all SQL databases (MySQL, PostgreSQL, SQL Server…
PostHog/posthog-foss
Author useful, low-noise log alerts on services in a PostHog project.
PostHog/posthog-foss
Operating procedure for the conflict-autoresolver agent: sweep open PostHog/posthog PRs that conflict with master, resolve the trivial conflicts (generated artifacts deterministically, source…
PostHog/posthog-foss
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).
PostHog/posthog-foss
Investigates distributed application performance using PostHog APM (OpenTelemetry span) data via MCP.
PostHog/posthog-foss
Debug and inspect LLM/AI agent traces using PostHog's MCP tools.
PostHog/posthog-foss
Diagnose why a product metric changed (dropped, spiked, or plateaued) by orchestrating breakdowns, actors, paths, lifecycle, retention, and annotations queries.
Works with
Categories
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).
Querying Local Postgres fits situations like: querying the local DB; inspecting tables; analyzing query plans.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.