postgres-best-practices
PostgreSQL-Abfragen und Schemata optimieren
Kämpfen Sie mit langsamen Datenbankabfragen und schlechter Performance? Diese Skill bietet erprobte PostgreSQL-Optimierungsregeln von Supabase mit konkreten SQL-Beispielen und messbaren Leistungsverbesserungen.
下载技能 ZIP
在 Claude 中上传
前往 设置 → 功能 → 技能 → 上传技能
开启并开始使用
测试它
正在使用“postgres-best-practices”。 This query takes 5 seconds on 100k rows: SELECT * FROM orders WHERE customer_id = 42 AND status = 'pending'
预期结果:
Create a composite index: CREATE INDEX idx_orders_customer_status ON orders (customer_id, status). This changes the execution plan from sequential scan to index scan, reducing query time to under 10ms. The column order matters: place the equality filter (customer_id) before the status filter for optimal index usage.
正在使用“postgres-best-practices”。 How do I prevent N+1 queries when fetching users with their profile data?
预期结果:
Replace individual queries with a JOIN: SELECT u.*, p.bio, p.avatar_url FROM users u LEFT JOIN user_profiles p ON p.user_id = u.id. Add an index on user_profiles(user_id) for fast lookups. This reduces 101 queries (1 for users + 100 for profiles) to a single query.
安全审计
安全This skill contains educational documentation for PostgreSQL best practices from Supabase. All 711 static analysis findings are false positives: the 'external_commands' detections are SQL code blocks in markdown documentation (not shell commands), 'network' URLs are reference links to postgresql.org and supabase.com, 'scripts' findings are SQL WITH clauses (CTEs), and 'crypto' warnings are text pattern matches in documentation. No executable code or security risks present.
质量评分
你能构建什么
Backend-Entwickler optimiert langsame Abfragen
Fehlende Indexe identifizieren, N+1-Muster beheben und Abfrageoptimierungstechniken anwenden, um Antwortzeiten von Sekunden auf Millisekunden zu reduzieren.
Datenbank-Architekt entwirft neue Schemata
Best Practices für Datentypen, Constraints, Fremdschlüssel und Indexierungsstrategien während des initialen Schema-Designs anwenden.
DevOps-Ingenieur optimiert Produktionsdatenbanken
Connection-Limits, Vacuum-Einstellungen und Monitoring konfigurieren, um die Datenbankgesundheit unter Last aufrechtzuerhalten.
试试这些提示
Review this PostgreSQL query for performance issues and suggest improvements: [paste query]
Analyze this table schema and query workload. What indexes should I create for optimal performance? Schema: [paste schema], Queries: [paste queries]
I'm fetching users and their orders with separate queries. Show me how to rewrite this as a single efficient JOIN with proper indexing.
Create a Row-Level Security policy for a multi-tenant SaaS where users can only access data belonging to their organization. Table structure: [paste schema]
最佳实践
- Immer Indexe auf WHERE-, JOIN- und ORDER BY-Spalten hinzufügen
- EXPLAIN ANALYZE verwenden, um Abfrage-Ausführungspläne vor dem Deployment zu verifizieren
- Connection Pooling implementieren, um Datenbank-Erschöpfung zu verhindern
避免
- Unindexierte Abfragen auf großen Tabellen ausführen, was Sequential Scans verursacht
- Alle Spalten mit SELECT * statt spezifischer Felder abrufen
- LIKE mit führenden Wildcards verwenden, was Index-Nutzung verhindert