Database Patterns

Provides SQL database design, indexing, query optimization, migration, security and monitoring best practices.

Updated Jun 7, 2024
One-click install
npx skills add https://github.com/ashishgurprit/ANLP_A3 --skill database-patterns-ashishgurprit
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: Database Patterns
Source: https://github.com/ashishgurprit/ANLP_A3/tree/main/.claude.backup/skills/database-patterns
Command: npx skills add https://github.com/ashishgurprit/ANLP_A3 --skill database-patterns-ashishgurprit

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill provides best practices and actionable guidance for designing efficient, scalable, and secure databases, along with strategies for optimization and maintenance.

Core Features & Use Cases

  • Schema Design: Enforces naming conventions, appropriate data types, and relationship definitions.
  • Indexing Strategies: Guides on when and how to use various index types for optimal query performance.
  • Query Optimization: Techniques to identify and resolve performance bottlenecks like N+1 queries and inefficient pagination.
  • Migrations: Best practices for safe and reversible database schema changes.
  • Security & Monitoring: Implements principles of least privilege, row-level security, and monitoring for performance and issues.
  • Use Case: A developer can use this Skill to ensure their new database schema adheres to industry best practices, preventing common pitfalls and improving application performance from the start.

Quick Start

Show me the best practices for naming conventions in SQL database tables and columns.

Frequently Asked Questions about Database Patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I optimize slow PostgreSQL queries?

Optimize slow PostgreSQL queries by running EXPLAIN ANALYZE to identify bottlenecks, resolving N+1 problems with batch operations, and applying appropriate indexing strategies like B-tree or partial indexes to speed up data retrieval.

What are the best practices for SQL schema design and migrations?

SQL schema design best practices include enforcing naming conventions, selecting appropriate data types, defining clear relationships, and ensuring safe, reversible database migrations to prevent data loss during application updates.

When should I use different index types like GIN or partial indexes in a database?

Use specific index types like GIN for complex data queries, partial indexes to optimize subsets of frequently accessed data, and expression indexes for computed columns to improve query performance without increasing storage overhead.

How do I secure my database with row-level security and least privilege?

Secure your database by implementing row-level security (RLS) to restrict data access at the row level, applying encryption for data protection, and enforcing least privilege principles to limit user permissions to only necessary operations.

Can I use pg_dump and pg_restore for database backup and recovery?

Yes, use pg_dump to create logical database backups and pg_restore to recover them, ensuring data durability and providing reliable mechanisms to restore database states during failure or migration scenarios.