home / skills / openclaw / skills / postgres

postgres skill

/skills/0xterrybit/postgres

This skill helps you manage PostgreSQL databases by running queries, handling schemas, backups, monitoring, and performance tuning.

npx playbooks add skill openclaw/skills --skill postgres

Review the files below or copy the command above to add this skill to your agents.

Files (2)
SKILL.md
816 B
---
name: postgres
description: PostgreSQL database management. Run queries, manage schemas, and monitor performance.
metadata: {"clawdbot":{"emoji":"🐘","always":true,"requires":{"bins":["curl","jq"]}}}
---

# PostgreSQL 🐘

PostgreSQL database management.

## Setup

```bash
export DATABASE_URL="postgresql://user:pass@localhost:5432/dbname"
```

## Features

- SQL query execution
- Schema management
- Index optimization
- Backup and restore
- Performance monitoring
- Extensions management

## Usage Examples

```
"Show all tables"
"Run query: SELECT * FROM users"
"Create index on email column"
"Show slow queries"
```

## Commands

```bash
psql "$DATABASE_URL" -c "SELECT * FROM users LIMIT 10"
```

## Safety Rules

1. **ALWAYS** confirm before destructive operations
2. **BACKUP** before schema changes

Overview

This skill manages PostgreSQL databases: run queries, manage schemas, optimize indexes, perform backups, and monitor performance. It provides command-style interactions for common tasks and safety checks to prevent accidental data loss. Use it to inspect database state, apply schema changes, and troubleshoot slow queries quickly.

How this skill works

The skill accepts natural-language or command-style requests (for example, run a SQL query or show slow queries) and maps them to PostgreSQL operations using the configured DATABASE_URL. It can execute read and write queries, create or modify indexes and schemas, trigger backups or restores, and report performance metrics such as slow queries and index usage. Destructive actions require explicit confirmation and recommending backups before changes.

When to use it

  • Exploring database contents with ad-hoc SELECT queries
  • Adding or modifying schema elements like tables, columns, or indexes
  • Diagnosing performance issues and identifying slow queries
  • Creating backups or restoring data from backups
  • Managing extensions and database configuration changes

Best practices

  • Always set DATABASE_URL to point to the intended environment before running commands
  • Require explicit confirmation for destructive operations (DROP, DELETE, ALTER) and back up first
  • Test schema changes on a staging copy before applying to production
  • Limit large data-modifying queries with TRANSACTION and small batches
  • Use indexes judiciously and monitor their effectiveness with EXPLAIN ANALYZE

Example use cases

  • Run: SELECT * FROM users LIMIT 10 to inspect recent user rows
  • Create an index on email column to speed up authentication queries
  • Show slow queries to identify and optimize long-running statements
  • Backup the database before applying a major schema migration
  • Restore a backup to recover from accidental data deletion

FAQ

How do I connect the skill to my database?

Set the DATABASE_URL environment variable to a valid PostgreSQL connection string before using the skill.

Will the skill perform destructive actions automatically?

No. Destructive operations require explicit confirmation and it will recommend making a backup first.