名称: database-postgresql 描述: PostgreSQL数据库检查和查询。用于调查表结构、运行查询、检查锁、复制状态或长时间运行的查询。 允许的工具: Bash(python *)
PostgreSQL数据库
认证
重要提示: 凭证由代理层自动注入。不要在环境变量中检查 POSTGRES_PASSWORD - 您将看不到它。直接运行脚本;认证透明处理。
您可以检查的配置环境变量(非秘密):
POSTGRES_HOST- 数据库主机POSTGRES_PORT- 数据库端口(默认: 5432)POSTGRES_DATABASE- 数据库名称POSTGRES_SCHEMA- 默认模式(默认: public)
强制:先调查模式
在运行查询前理解模式。
列出表 → 描述表 → 执行查询 → 检查健康
可用脚本
所有脚本都在 .claude/skills/database-postgresql/scripts/ 中
list_tables.py - 列出表(从此开始)
python .claude/skills/database-postgresql/scripts/list_tables.py [--schema public]
describe_table.py - 表结构详情
python .claude/skills/database-postgresql/scripts/describe_table.py --table TABLE_NAME [--schema public]
execute_query.py - 运行SQL查询
python .claude/skills/database-postgresql/scripts/execute_query.py --query "SELECT * FROM users WHERE created_at > now() - interval '1 hour'" [--limit 100]
list_indexes.py - 索引信息
python .claude/skills/database-postgresql/scripts/list_indexes.py [--table TABLE_NAME] [--schema public]
get_table_sizes.py - 表大小分析
python .claude/skills/database-postgresql/scripts/get_table_sizes.py [--table TABLE_NAME] [--schema public]
get_locks.py - 当前锁和阻塞查询
python .claude/skills/database-postgresql/scripts/get_locks.py
get_replication_status.py - 复制健康
python .claude/skills/database-postgresql/scripts/get_replication_status.py
get_long_running_queries.py - 长时间运行查询
python .claude/skills/database-postgresql/scripts/get_long_running_queries.py [--min-duration 60]
调查工作流
锁争用
1. get_locks.py (查找阻塞关系)
2. get_long_running_queries.py --min-duration 30
3. execute_query.py --query "SELECT * FROM pg_stat_activity WHERE state = 'active'"
复制延迟
1. get_replication_status.py (检查lag_bytes/lag_seconds)
2. get_long_running_queries.py (查询阻塞复制)
表增长调查
1. get_table_sizes.py (查找最大表)
2. list_indexes.py --table <table> (检查索引健康)
3. describe_table.py --table <table>