All skills
planetscale avatar

/postgres

@2b8cda6 official

PostgreSQL best practices, query optimization, connection troubleshooting, and performance improvement. Load when working with Postgres databases.

Use this Skill: https://skilld.dev/gh/planetscale/database-skills/postgres

This session only. Nothing lands on disk.

referencesbackup-recovery.md

≈672 tokens on demand. Your agent reads this file only when SKILL.md points to it.

Backup and Recovery

FUNDAMENTAL RULE: Backups are useless until you've successfully tested recovery.

Logical Backups (pg_dump)

Exports as SQL or custom format; portable across PG versions and architectures. Formats: -Fp (plain SQL), -Fc (custom compressed, selective restore), -Fd (directory, parallel with -j), -Ft (tar, avoid). Use -Fd -j 4 for large DBs. Restore: pg_restore -d dbname file.dump; add -j for parallel restore. Selective table restore: pg_restore -t tablename. Slow for large DBs; RPO = backup frequency (typically 24h).

Physical Backups (pg_basebackup)

Copies raw PGDATA; same major version and platform required; cross-architecture works if same endianness (e.g., x86_64 ↔ ARM64). Faster for large clusters; includes all databases. Flags: -Ft -z -P for compressed tar with progress. Manual alternative: pg_backup_start() → copy PGDATA → pg_backup_stop() (complex; must write returned backup_label).

PITR (Point-in-Time Recovery)

Requires base backup + continuous WAL archiving. Restores to any timestamp, transaction, or named restore point. Without PITR: restore only to backup time (potentially lose hours). With PITR: RPO = minutes. archive_command must return 0 ONLY when file is safely stored—premature 0 = data loss risk. wal_level must be replica or logical (not minimal).

WAL Archiving

archive_mode=on, archive_command='test ! -f /archive/%f && cp %p /archive/%f'. Test archive command as postgres user (not root) since permission issues are common. Monitor pg_stat_archiver for failed_count, last_archived_time. Archive failures prevent WAL recycling → disk fills.

Tool Comparison

Tool Use case
pg_dump Small DBs, migrations, selective restore
pg_basebackup Basic PITR, built-in
pgBackRest Production—parallel, incremental, S3/GCS/Azure, retention
Barman Enterprise PITR, retention policies
WAL-G Cloud-native, S3/GCS/Azure

RPO/RTO

Logical only: RPO = backup interval (hours); RTO = hours. PITR: RPO = minutes; RTO = hours. Synchronous replication: RPO = 0; RTO = seconds to minutes (failover).

Operational Rules

  • Verify integrity with pg_verifybackup (PG 13+)
  • Test recovery / PITR regularly
  • Take backups from standby to avoid impacting primary
  • Retention: 7 daily, 4 weekly, 12 monthly
  • Monitor archive growth and backup age
  • Never assume backups work without testing

Source: SKILL.md on GitHub

1 alert17d5 checks · Risk SAFE
  • Gen Agent Trust Hub17d

    The skill provides comprehensive documentation, best practices, and diagnostic SQL queries for PostgreSQL and PlanetScale-specific features. No security issues were identified.

  • Socket17d

    No alerts

  • Snyk17d

    Risk: LOW · No issues

  • Runlayer6mo

    18/23 files flagged

  • ZeroLeaks5mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at 2b8cda6. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub last month.

Activeupdated 7 months ago
metadata
{
  "author": "planetscale",
  "version": "1.0.0"
}
  • Database
  • postgres
  • schema-design
  • indexing
  • query-optimization
  • replication
  • monitoring
  • backup-recovery
  • planetscale

README badge

README badge for planetscale/database-skills/postgres

Provides Postgres best practices, query optimization guidance, indexing strategies, and schema design patterns. Includes PlanetScale-specific connection pooling, monitoring, and CLI reference for hosted Postgres deployments.

Generated from the current SKILL.md.

Does this skill cover PlanetScale-specific features like connection pooling?
Yes. The skill includes references for PlanetScale connection pooling, PgBouncer configuration, the pscale CLI, and PlanetScale Insights for slow query analysis.
What topics does this skill cover?
Schema design, indexing, query optimization, partitioning, MVCC and transactions, replication, WAL operations, monitoring, backup/recovery, and PlanetScale-specific connection and deployment workflows.
Does this skill help with query performance troubleshooting?
Yes. It includes guidance on query patterns, index optimization, MVCC transaction isolation, and monitoring via pg_stat views and pg_stat_statements.
Can I use this skill if I self-host Postgres instead of PlanetScale?
Yes. The skill covers generic Postgres best practices and operations. PlanetScale-specific references are optional and only used if you choose PlanetScale for hosting.

Generated from the current SKILL.md. These answers refresh after source changes.