postgresql
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 |
More from jgamaraalv/ts-dev-kit
bullmq
BullMQ queue system reference for Redis-backed job queues, workers, flows, and schedulers. Use when: (1) creating queues and workers with BullMQ, (2) adding jobs (delayed, prioritized, repeatable, deduplicated), (3) setting up FlowProducer parent-child job hierarchies, (4) configuring retry strategies, rate limiting, or concurrency, (5) implementing job schedulers with cron/interval patterns, (6) preparing BullMQ for production (graceful shutdown, Redis config, monitoring), or (7) debugging stalled jobs or connection issues
46owasp-security-review
Review code and architectures against the OWASP Top 10:2025 — the ten most critical web application security risks. Use when: (1) reviewing code for security vulnerabilities, (2) auditing a feature or codebase against OWASP categories, (3) providing remediation guidance for identified vulnerabilities, (4) writing new code and needing secure coding patterns. Triggers: 'review for security', 'OWASP audit', 'check for vulnerabilities','security checklist', 'is this code secure', 'security review', 'fix vulnerability'.
42ioredis
ioredis v5 reference for Node.js Redis client — connection setup, RedisOptions, pipelines, transactions, Pub/Sub, Lua scripting, Cluster, and Sentinel. Use when: (1) creating or configuring Redis connections (standalone, cluster, sentinel), (2) writing Redis commands with ioredis (get/set, pipelines, multi/exec), (3) setting up Pub/Sub or Streams, (4) configuring retryStrategy, TLS, or auto-pipelining, (5) working with Redis Cluster options (scaleReads, NAT mapping), or (6) debugging ioredis connection issues. Important: use named import `import { Redis } from 'ioredis'` for correct TypeScript types with NodeNext.
35nextjs-best-practices
Next.js App Router best practices — file conventions, RSC boundaries, data patterns, async APIs, metadata, error handling, route handlers, image/font optimization, bundling. Use when writing, reviewing, or debugging Next.js App Router code.
29ui-ux-guidelines
Review UI code for Web Interface Guidelines compliance. Use when asked to review UI, check accessibility, audit design, review UX, or check against best practices.
26service-worker
Service Worker API implementation guide — registration, lifecycle management, caching strategies, push notifications, and background sync. Use when: (1) creating or modifying service worker files (sw.js), (2) implementing offline-first caching (cache-first, network-first, stale-while-revalidate), (3) setting up push notifications or background sync, (4) debugging service worker registration, scope, or update issues, (5) implementing navigation preload, (6) user mentions 'service worker', 'sw.js', 'offline support', 'cache strategy', 'push notification', 'background sync', 'workbox alternative', or 'PWA caching'.
25