Postgresql logo

Postgresql

Community
iliaal
postgresql

PostgreSQL schema design, query optimization, indexing, and administration. Use when writing schemas, queries, migrations, or mentions PostgreSQL, Postgres, JSONB, partitioning, RLS, CTEs, window functions, EXPLAIN ANALYZE, or connection pooling.

Overview

Publisheriliaal
Repositorywhetstone
Skill namepostgresql
Stars
36
Forks
5
Bundled files
1
LicenseMIT
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • 1 bundled files

    Scripts, templates, and references the model can read while it works. Files are read-only and never executed.

  • Open source

    Published by iliaal on GitHub. Read the source before you install it.

Installation

Install the Postgresql AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/iliaal/whetstone/tree/master/distillery/generated-skills/postgresql
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/iliaal/whetstone.git /tmp/whetstone
mkdir -p .claude/skills
cp -r /tmp/whetstone/distillery/generated-skills/postgresql .claude/skills/postgresql
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Postgresql in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Postgresql on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Postgresql is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

PostgreSQL

Data Type Defaults

NeedUseAvoid
Primary keyBIGINT GENERATED ALWAYS AS IDENTITYSERIAL, BIGSERIAL
TimestampsTIMESTAMPTZTIMESTAMP (loses timezone)
TextTEXTVARCHAR(n) unless constraint needed
MoneyNUMERIC(precision, scale)MONEY, FLOAT
BooleanBOOLEAN with NOT NULL DEFAULTnullable booleans
JSONJSONBJSON (no indexing), text JSON
UUIDgen_random_uuid() (PG13+)uuid-ossp extension
IP addressesINET / CIDRtext
RangesTSTZRANGE, INT4RANGE, etc.pair of columns

Schema Rules

  • Every FK column gets an index (PG does NOT auto-create these)
  • NOT NULL on every column unless NULL has business meaning
  • CHECK constraints for domain rules at DB level
  • EXCLUDE constraints for range overlaps: EXCLUDE USING gist (room WITH =, during WITH &&)
  • Default created_at TIMESTAMPTZ NOT NULL DEFAULT now()
  • Separate updated_at with trigger, never trust app layer alone
  • Use BIGINT PKs — cheaper JOINs than UUID, better index locality

Index Strategy

TypeUse When
B-tree (default)Equality, range, sorting, LIKE 'prefix%'
GINJSONB (@>, ?, ?&), arrays, full-text (tsvector)
GiSTGeometry, ranges, full-text (smaller but slower than GIN)
BRINLarge tables with natural ordering (timestamps, serial IDs)

Index rules:

  • Composite: most selective column first, max 3-4 columns
  • Partial: WHERE status = 'active' — smaller, faster
  • Covering: INCLUDE (col) — avoids heap lookup
  • Expression: ON (lower(email)) — for function-based WHERE
  • Drop unused indexes: SELECT * FROM pg_stat_user_indexes WHERE idx_scan = 0

JSONB Patterns

sql
-- GIN index for containment queries
CREATE INDEX ON items USING gin (metadata);
SELECT * FROM items WHERE metadata @> '{"status": "active"}';

-- Expression index for specific key access
CREATE INDEX ON items ((metadata->>'category'));
SELECT * FROM items WHERE metadata->>'category' = 'electronics';

Prefer typed columns over JSONB for frequently queried, well-structured data. Use JSONB for truly dynamic/variable attributes.

Query Optimization

  • Always EXPLAIN (ANALYZE, BUFFERS, FORMAT TEXT) before optimizing
  • Sequential scan on large table → add index or check WHERE for function wrapping
  • High rows removed by filter → index doesn't match predicate
  • CTE is an optimization fence before PG12; use MATERIALIZED/NOT MATERIALIZED hints (PG12+)
  • Prefer EXISTS over IN for correlated subqueries
  • Use LATERAL JOIN when subquery needs outer row reference
  • Cursor pagination (WHERE id > $last ORDER BY id LIMIT $n) over OFFSET

Partitioning

Use when table exceeds ~100M rows or needs TTL purge:

  • RANGE — time-series (by month/year), most common
  • LIST — categorical (by region, tenant)
  • HASH — even distribution when no natural key

Partition key must be in every unique/PK constraint. Create indexes on partitions, not parent.

Transactions & Locking

  • Keep transactions short — long txns block vacuum and bloat tables
  • SELECT ... FOR UPDATE SKIP LOCKED — job queue / work claiming pattern
  • Advisory locks for application-level mutual exclusion: pg_advisory_xact_lock(key)
  • Check blocked queries: SELECT * FROM pg_stat_activity WHERE wait_event_type = 'Lock'

Full-Text Search

sql
-- Weighted tsvector column with trigger
ALTER TABLE articles ADD COLUMN search_vector tsvector
  GENERATED ALWAYS AS (
    setweight(to_tsvector('english', coalesce(title,'')), 'A') ||
    setweight(to_tsvector('english', coalesce(body,'')), 'B')
  ) STORED;
CREATE INDEX ON articles USING gin (search_vector);
SELECT * FROM articles WHERE search_vector @@ websearch_to_tsquery('english', $1);

Performance Tuning

Key postgresql.conf parameters (adjust for available RAM):

  • shared_buffers = 25% of RAM
  • effective_cache_size = 75% of RAM
  • work_mem = RAM / max_connections / 4 (start 4-16MB)
  • maintenance_work_mem = 256MB-1GB
  • random_page_cost = 1.1 for SSD (default 4.0 is for HDD)

Connection Pooling

Always pool in production. Direct connections cost ~10MB each.

  • PgBouncer in transaction mode for most workloads
  • statement mode if no session-level features (prepared statements, temp tables, advisory locks)

Maintenance

  • pg_stat_statements extension — find slow queries by total time, not just duration
  • pg_stat_user_tables — check n_dead_tup for vacuum needs
  • autovacuum tuning: lower thresholds for hot tables
  • Monitor cache hit ratio: SELECT sum(heap_blks_hit) / sum(heap_blks_hit + heap_blks_read) FROM pg_statio_user_tables — should be > 99%

Anti-Patterns

Anti-PatternFix
SERIAL / BIGSERIAL for PKsBIGINT GENERATED ALWAYS AS IDENTITY
No FK indexesAdd index on every FK column
OFFSET paginationCursor-based: WHERE id > $last
SELECT *List needed columns
TIMESTAMP without timezoneTIMESTAMPTZ
Functions in WHERE (lower(col))Expression index or citext extension
Storing structured data as textJSONB with GIN index
Long-running transactionsKeep txns short, use idle_in_transaction_session_timeout

Bundled files

The model reads these on demand while the skill is loaded. They are exposed as readable files and are never executed.

Frequently asked questions

What does the Postgresql AI skill do?

PostgreSQL schema design, query optimization, indexing, and administration. Use when writing schemas, queries, migrations, or mentions PostgreSQL, Postgres, JSONB, partitioning, RLS, CTEs, window functions, EXPLAIN ANALYZE, or connection pooling.

Why use Postgresql on TypingMind?

Because you install it once and use it with any model. Postgresql is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Postgresql in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/iliaal/whetstone/tree/master/distillery/generated-skills/postgresql. TypingMind reads its SKILL.md and bundles its files and installs it as a skill you can enable per chat.

Which AI models can use Postgresql?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Postgresql?

As many as you like. As long as a model supports skills, you can use Postgresql with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Postgresql AI skill free?

Yes. It is published on GitHub by iliaal under the MIT license. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇