postgresql
БесплатноБез исполняемых скриптовНе проверенPostgreSQL relational database. Covers SQL queries, indexes, constraints, and performance. Use when working with PostgreSQL. USE WHEN: user mentions…
от claude-dev-suite★ 51 звезда на GitHubОб этом скилле
PostgreSQL Core Knowledge
Deep Knowledge: Use
mcp__documentation__fetch_docswith technology:postgresqlfor comprehensive documentation.
Table Definition
CREATE TABLE users (
id SERIAL PRIMARY KEY,
name VARCHAR(100) NOT NULL,
email VARCHAR(255) UNIQUE NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
is_active BOOLEAN DEFAULT TRUE
);
CREATE INDEX idx_users_email ON users(email);
CREATE INDEX idx_users_created ON users(created_at DESC);
Common Queries
-- Select with pagination
SELECT * FROM users
WHERE is_active = TRUE
ORDER BY created_at DESC
LIMIT 20 OFFSET 0;
-- Join
SELECT u.*, p.title
FROM users u
LEFT JOIN posts p ON p.user_id = u.id
WHERE u.id = $1;
-- Aggregate
SELECT
DATE_TRUNC('day', created_at) as day,
COUNT(*) as count
FROM users
GROUP BY DATE_TRUNC('day', created_at)
ORDER BY day DESC;
-- Upsert
INSERT INTO users (email, name)
VALUES ($1, $2)
ON CONFLICT (email)
DO UPDATE SET name = EXCLUDED.name;
Data Types
| Type | Use For |
|---|---|
SERIAL |
Auto-increment IDs |
UUID |
Unique identifiers |
VARCHAR(n) |
Variable strings |
TEXT |
Long text |
JSONB |
JSON data (indexed) |
TIMESTAMP |
Date and time |
BOOLEAN |
True/false |
Performance
- Use
EXPLAIN ANALYZEto check queries - Add indexes for WHERE/JOIN columns
- Use
JSONBoverJSONfor queries - Partial indexes for filtered queries
When NOT to Use This Skill
- MySQL-specific syntax - Use
mysqlskill for MySQL databases (AUTO_INCREMENT, GROUP_CONCAT) - NoSQL operations - Use
mongodborredisskills for document/key-value stores - Oracle PL/SQL - Use
plsqlskill for Oracle-specific procedural code - SQL Server T-SQL - Use
tsqlskill for SQL Server-specific features - ORM abstractions - Use framework-specific skills (Prisma, TypeORM, Spring Data JPA)
Anti-Patterns
| Anti-Pattern | Issue | Solution |
|---|---|---|
SELECT * in production |
Transfers unnecessary data, breaks when schema changes | Specify needed columns explicitly |
Missing WHERE on UPDATE/DELETE |
Modifies all rows unintentionally | Always include WHERE clause, use transactions |
| Missing indexes on JOIN/WHERE columns | Full table scans, slow queries | Add indexes on frequently queried columns |
| Using functions on indexed columns | Prevents index usage: WHERE UPPER(email) = 'X' |
Use functional indexes or change query |
LIKE '%pattern' |
Cannot use index, full scan | Use LIKE 'pattern%' or full-text search |
Missing LIMIT on large tables |
Can crash application, memory issues | Always paginate results |
| Storing comma-separated values | Cannot query efficiently, violates normalization | Use array type or junction table |
| Missing foreign keys | Data integrity issues, orphaned records | Define proper FK constraints |
| N+1 query problem | One query per row in loop | Use JOINs or batch queries |
| Long-running transactions | Locks resources, blocks other queries | Keep transactions short, use appropriate isolation |
Quick Troubleshooting
| Problem | Diagnostic | Fix |
|---|---|---|
| Slow queries | EXPLAIN ANALYZE query |
Add indexes, rewrite query, update statistics |
| High CPU usage | pg_stat_statements to find slow queries |
Optimize top queries, add connection pooling |
| Connection limit reached | SELECT count(*) FROM pg_stat_activity |
Increase max_connections, use PgBouncer |
| Lock contention | SELECT * FROM pg_locks WHERE NOT granted |
Reduce transaction time, use lower isolation |
| Disk space full | SELECT pg_size_pretty(pg_database_size('mydb')) |
VACUUM, archive old data, increase storage |
| Replication lag | Check pg_stat_replication |
Increase resources, tune checkpoint settings |
| Cache hit ratio < 95% | SELECT sum(blks_hit)/sum(blks_hit+blks_read) FROM pg_stat_database |
Increase shared_buffers |
| Dead tuples accumulating | SELECT n_dead_tup FROM pg_stat_user_tables |
Run VACUUM, tune autovacuum |
Production Readiness
Security Configuration
-- Create application user with limited privileges
CREATE USER app_user WITH PASSWORD 'secure_password';
GRANT CONNECT ON DATABASE mydb TO app_user;
GRANT USAGE ON SCHEMA public TO app_user;
GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA public TO app_user;
GRANT USAGE, SELECT ON ALL SEQUENCES IN SCHEMA public TO app_user;
-- Row Level Security (RLS)
ALTER TABLE users ENABLE ROW LEVEL SECURITY;
CREATE POLICY users_tenant_isolation ON users
USING (tenant_id = current_setting('app.tenant_id')::uuid);
-- Force SSL connections
-- In postgresql.conf:
-- ssl = on
-- ssl_cert_file = '/path/to/server.crt'
-- ssl_key_file = '/path/to/server.key'
-- Connection with SSL
psql "postgresql://user:pass@host:5432/db?sslmode=require"
Connection Pooling (PgBouncer)
# pgbouncer.ini
[databases]
mydb = host=127.0.0.1 port=5432
Установить postgresql в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
ReadGrepGlobWriteEditВложенные файлы
FAQ
Что делает скилл postgresql?
PostgreSQL relational database. Covers SQL queries, indexes, constraints, and performance. Use when working with PostgreSQL. USE WHEN: user mentions "postgres", "postgresql", "pg_", asks about "JSONB queries", "window functions", "recursive CTE", "row level security", "full text search", "partitioning", "pgBouncer", "replication" DO NOT USE FOR: MySQL syntax - use `mysql` instead, MongoDB - use `mongodb` instead, Oracle PL/SQL - use `plsql` instead, SQL Server T-SQL - use `tsql` instead
Как установить скилл postgresql?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл postgresql запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
mcp-builder
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
от Anthropicclaude-api
Reference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
от Anthropicalgorithmic-art
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
от Anthropicmcp-integration
This skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…
от Anthropic