Install
openclaw skills install postgresql-skillExecute PostgreSQL database operations using psycopg2. List tables, describe schema, execute SQL queries.
openclaw skills install postgresql-skillPure Python PostgreSQL skill using psycopg2 (no psql client needed).
Use this skill when the user needs to:
Before using this skill, ensure:
pip install psycopg2-binary pyyamlconfig.yaml exists with valid database connection detailsIf config.yaml is missing, instruct the user to:
cp config.example.yaml config.yaml
# Then edit config.yaml with real database credentials
| User Intent | Command | Example |
|---|---|---|
| List tables | python scripts/pgsql_skill.py list-tables | Get all table names |
| Describe table | python scripts/pgsql_skill.py describe-table <table> | describe-table users |
| Query data | python scripts/pgsql_skill.py execute-sql "<SQL>" | execute-sql "SELECT * FROM users LIMIT 10" |
| Schema overview | python scripts/pgsql_skill.py schema-summary | Full database structure |
All commands return JSON (except schema-summary):
list-tables output:
{"tables": ["users", "orders", "products"]}
describe-table output:
{
"table": "users",
"columns": [
{"name": "id", "type": "integer", "nullable": false, "default": null},
{"name": "username", "type": "varchar", "nullable": false, "default": null}
]
}
execute-sql SELECT output:
{
"columns": ["id", "username", "email"],
"rows": [
{"values": ["1", "alice", "alice@example.com"]},
{"values": ["2", "bob", "bob@example.com"]}
]
}
execute-sql INSERT/UPDATE/DELETE output:
{"affected_rows": 1}
If a command fails, check the error message:
"error": "config.yaml not found" → Guide user to create config"error": "psycopg2 not installed" → Run pip install psycopg2-binary"error": "connection failed" → Verify database credentials"error": "Forbidden operation" → SQL violates safety rulesThis skill enforces strict SQL safety:
✅ Allowed:
❌ Blocked:
Example of blocked query:
python scripts/pgsql_skill.py execute-sql "DROP TABLE users"
# Output: {"error": "Forbidden operation: DROP"}
For advanced usage, import directly in Python:
import sys
from pathlib import Path
sys.path.insert(0, 'scripts')
from pgsql_skill import Database, load_config
# Initialize database connection
config = load_config()
db = Database(
host=config['host'],
port=config['port'],
dbname=config['dbname'],
user=config['user'],
password=config.get('password', '')
)
# Use database methods
tables = db.list_tables()
structure = db.describe_table("users")
result = db.execute_sql("SELECT count(*) FROM users")
# Always close connection
db.close()
pip install psycopg2-binary
pip install psycopg2-binary --no-binary :all: