postgresql
SKILL.md
PostgreSQL 16+ Reference
Version: 16+. All syntax is standard; most features apply to PostgreSQL 13+.
<quick_reference>
Quick patterns
-- Check running queries
SELECT pid, state, wait_event_type, query FROM pg_stat_activity WHERE state != 'idle';
-- Explain a slow query
EXPLAIN (ANALYZE, BUFFERS, FORMAT TEXT) SELECT ...;
-- List table sizes
SELECT relname, pg_size_pretty(pg_total_relation_size(oid)) FROM pg_class
WHERE relkind = 'r' ORDER BY pg_total_relation_size(oid) DESC;
-- Kill a blocking query
SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE pid = <pid>;
</quick_reference>
Key non-obvious facts
- Every statement runs in a transaction. Without
BEGIN, each statement auto-commits. jsonbstores parsed binary (faster queries);jsonstores raw text (exact input preserved). Preferjsonb.LIKE 'foo%'can use B-tree;LIKE '%foo'cannot — usepg_trgmGIN for suffix search.CREATE INDEX CONCURRENTLYavoids table lock but cannot run inside a transaction block.EXPLAINwithoutANALYZEshows the planner's estimate. Always useEXPLAIN (ANALYZE, BUFFERS)for real data.- Null values are stored in indexes by B-tree (unlike some other databases).
IS NULLcan use an index. SERIAL/BIGSERIALare shorthand for sequence + default; preferGENERATED ALWAYS AS IDENTITY(SQL standard).- Default isolation level is Read Committed.
SERIALIZABLEprevents all anomalies but may abort transactions.
Reference files
Load the relevant file when working on a specific topic:
| Topic | File | When to read |
|---|---|---|
| SELECT, JOINs, CTEs, window functions | references/queries.md | Writing or debugging any query |
| CREATE TABLE, ALTER TABLE, constraints | references/ddl-schema.md | Designing or modifying schemas |
| Index types, creation, strategy | references/indexes.md | Adding indexes or fixing slow queries |
| Transactions, savepoints, isolation | references/transactions.md | Concurrency, locking, isolation issues |
| JSONB operators, GIN, jsonpath | references/jsonb.md | Working with JSON/JSONB columns |
| EXPLAIN output, VACUUM, stats | references/performance.md | Query tuning or performance analysis |
| psql meta-commands | references/psql-cli.md | Working interactively in psql |
Weekly Installs
15
Repository
jgamaraalv/ts-dev-kitGitHub Stars
12
First Seen
Feb 21, 2026
Security Audits
Installed on
opencode15
gemini-cli15
github-copilot15
codex15
kimi-cli15
cursor15