itechmeat/llm-code/postgresql
Claude Code and agent skill by itechmeat/llm-code
- community
Checking that the SKILL.md file is still in the repository.
PostgreSQL best practices: multi-tenancy with RLS, schema design, Alembic migrations, async SQLAlchemy, and query optimization. Use when designing multi-tenant tables with Row-Level Security, debugging tenant isolation, creating/changing Alembic migrations, or optimizing PostgreSQL queries. Keywords: PostgreSQL, RLS, Alembic, SQLAlchemy, multi-tenancy.
Install
npx vskill@latest install itechmeat/llm-code/postgresqlSKILL.md
PostgreSQL
RLS Multi-tenancy Pattern
Non-negotiables
- RLS context is mandatory for any tenant-scoped query
- Context must be set inside the same transaction as the queries
- No fallbacks for tenant ID (fail fast if missing)
- Async-only DB access when using async frameworks
Setting RLS Context
RLS works only if the current transaction has the context set:
Must run before the first tenant-scoped query in that transaction.
Common Failure Modes
- Setting
SET LOCAL ...after the firstselect() - Setting the context in one session, then querying in another
- Running queries outside the expected transaction scope
Typical RLS Policy
Multi-tenant Table Checklist
- Tenant ID column is UUID
- FK to tenants table with
ON DELETE CASCADE - Indexes aligned with access patterns (usually tenant_id first)
- PostgreSQL does not auto-index FK columns — add explicit indexes
- UNIQUE allows multiple NULLs unless using
NULLS NOT DISTINCT(PG15+) - RLS is enabled and policies exist
- Application code sets RLS context at transaction start
Alembic Migrations Checklist
- Add/modify schema (columns, constraints, FKs)
- Create/update indexes
- Enable RLS and create/adjust policies
- Add verification (tests) for isolation
- Provide a real downgrade (no stubs)
Version Notes
PostgreSQL 19 (RC 1)
- 19 is at RC 1 (2026-10-15): the feature set is frozen and matches the upcoming general availability, planned for 2026-11-19. RC 2 ships on 2026-11-12 together with the November update release, so that release's fixes land in 19 before GA. Latest stable line is
18.6. - Headline changes:
REPACK/REPACK CONCURRENTLYreplacingVACUUM FULLandCLUSTER, parallel autovacuum with a scoring system, logical replication of sequences, SQL/PGQ property graphs,GROUP BY ALL,FOR PORTION OF, and online checksum enable/disable. - 18 incompatible changes to plan for, including forced
standard_conforming_strings, RADIUS removal,jitoff by default,default_toast_compressionswitching tolz4, andmax_locks_per_transactiondefaulting to 128 with changed sizing. - Full detail and the upgrade checklist: postgresql-19.md
PostgreSQL 18.4
18.4is a security/robustness patch release; no dump/restore is required for existing18.xclusters.- The patch line hardens startup packet parsing, backup tools (
pg_basebackup,pg_rewind,pg_verifybackup), and several logical replication code paths. - Planner/executor fixes also land for
MERGE, nondeterministic collations, generated columns, and assorted aggregate/window edge cases.
RLS Isolation Testing Recipe
Goal:
- Data for tenant A is visible to tenant A
- Data for tenant A is NOT visible to tenant B
Canonical flow:
- Setup data through an admin session (RLS bypass) for tenant A and B
- Assert via an RLS session:
- set context to tenant A → sees only tenant A data
- set context to tenant B → does not see tenant A data
Destructive Operations Safety
Hard rules:
- Never run
DELETEwithout a narrowWHEREtargeting specific data - Never run
TRUNCATE/DROPwithout explicit confirmation
Pre-flight before destructive actions:
- Confirm exact target (tables / IDs / date range)
- Run a
SELECT/row count first and show results - Ask for final confirmation, then execute
References
Versions
- postgresql-19.md — PostgreSQL 19 (beta): new features by area, full incompatible-changes list, upgrade checklist
Schema & Design
- table-design.md — Data types, constraints, indexing, partitioning, JSONB, safe schema evolution
- charset-encoding.md — Character sets, encoding, collation, ICU, locale settings
Authentication
- authentication.md — pg_hba.conf, SCRAM-SHA-256, md5, peer, cert, LDAP, GSSAPI
- authentication-oauth.md — OAuth 2.0 (PostgreSQL 18+), SASL OAUTHBEARER, validators
- user-management.md — CREATE/ALTER/DROP ROLE, membership, GRANT/REVOKE, predefined roles
Runtime Configuration
- connection-settings.md — listen_addresses, max_connections, SSL, TCP keepalives
- query-tuning.md — Planner settings, work_mem, parallel query, cost constants
- replication.md — Streaming replication, WAL, synchronous commit, logical replication
- vacuum.md — Autovacuum, vacuum cost model, freeze ages, per-table tuning
- error-handling.md — exit_on_error, restart_after_crash, data_sync_retry
Internals
- internals.md — Query processing pipeline, parser/rewriter/planner/executor, system catalogs, wire protocol, access methods
- protocol.md — Wire protocol v3.2: message format, startup, auth, query, COPY, replication
Links
See Also
- sql-expert — Query patterns, EXPLAIN workflow, optimization
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewNot runA model review is scheduled for the next rescan.
Quality evaluation
- Task evaluationWarning, 80 of 100Marginal. 1 run. Evaluated 7 months ago.
Source
- SKILL.md in the repositoryCheckingskills/postgresql/SKILL.md
Popularity
- Repository stars
- 15
- 7-day trend score
- 14
Stars and forks are for the whole GitHub repository, not this skill alone. Refreshed 8 May 2026, 5 months ago.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/itechmeat/llm-code/postgresql)