← 返回 Skills 市场
lrg913427-dot

Db Explorer

作者 lrg913427-dot · GitHub ↗ · v2.0.0 · MIT-0
cross-platform ✓ 安全检测通过
71
总下载
0
收藏
0
当前安装
1
版本数
在 OpenClaw 中安装
/install hermes-db-explorer
功能描述
Connect to and explore databases (PostgreSQL, MySQL, SQLite, MongoDB, Redis). Run queries, inspect schemas, export data. Use when user wants to query a datab...
使用说明 (SKILL.md)

DB Explorer

Connect to databases, run queries, explore schemas, and export data — all from the terminal.

When to Use

Activate this skill when the user:

  • Says "check the database", "query the DB", "show me the data"
  • Wants to see table structure, row counts, or sample data
  • Needs to export data to CSV/JSON
  • Wants to find slow queries or check DB health
  • Mentions a database connection string or DB name

Supported Databases

Database CLI Tool Install (macOS) Install (Linux)
PostgreSQL psql brew install postgresql apt install postgresql-client
MySQL mysql brew install mysql apt install mysql-client
SQLite sqlite3 (built-in on macOS) apt install sqlite3
MongoDB mongosh brew install mongosh See mongodb.com/docs/shell
Redis redis-cli brew install redis apt install redis-tools

Quick Start

1. Identify the Database

Ask the user for:

  • Database type (postgres/mysql/sqlite/mongo/redis)
  • Connection string OR host/port/database/user/password
  • For SQLite: just the file path

2. Connect and Explore

# PostgreSQL
psql "postgresql://user:password@host:5432/dbname" -c "\dt"           # list tables
psql "postgresql://user:password@host:5432/dbname" -c "\d table_name" # describe table
psql "postgresql://user:password@host:5432/dbname" -c "SELECT count(*) FROM table_name;"

# MySQL
mysql -h host -u user -p dbname -e "SHOW TABLES;"
mysql -h host -u user -p dbname -e "DESCRIBE table_name;"
mysql -h host -u user -p dbname -e "SELECT count(*) FROM table_name;"

# SQLite
sqlite3 /path/to/db.db ".tables"                    # list tables
sqlite3 /path/to/db.db ".schema table_name"         # describe table
sqlite3 /path/to/db.db "SELECT count(*) FROM table_name;"

# MongoDB
mongosh "mongodb://user:password@host:27017/dbname" --eval "db.getCollectionNames()"
mongosh "mongodb://user:password@host:27017/dbname" --eval "db.collection_name.countDocuments()"

# Redis
redis-cli -h host -p 6379 -a password INFO keyspace
redis-cli -h host -p 6379 -a password DBSIZE
redis-cli -h host -p 6379 -a password KEYS "*"

3. Safety Rules

ALWAYS follow these rules:

  1. Read-only by default — Never run INSERT/UPDATE/DELETE/DROP without explicit user confirmation
  2. Limit results — Always add LIMIT 100 (or equivalent) to SELECT queries unless user asks for all
  3. Show before execute — For any write operation, show the exact SQL/command and ask for confirmation
  4. No passwords in history — Use environment variables or connection strings, don't echo passwords
  5. Transaction safety — For writes, wrap in BEGIN/ROLLBACK first, show results, then ask to COMMIT

4. Schema Exploration Workflow

When user says "explore the database" or "show me the schema":

# Step 1: List all tables
# Step 2: For each table, show columns, types, and constraints
# Step 3: Show row counts
# Step 4: Show foreign key relationships
# Step 5: Summarize as a readable schema map

PostgreSQL full schema dump:

psql "$CONN" -c "
SELECT table_name, column_name, data_type, is_nullable, column_default
FROM information_schema.columns
WHERE table_schema = 'public'
ORDER BY table_name, ordinal_position;
"

MySQL full schema dump:

mysql "$CONN" -e "
SELECT TABLE_NAME, COLUMN_NAME, DATA_TYPE, IS_NULLABLE, COLUMN_DEFAULT
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = DATABASE()
ORDER BY TABLE_NAME, ORDINAL_POSITION;
"

5. Export Formats

Export query results to common formats:

# CSV (PostgreSQL)
psql "$CONN" -c "\copy (SELECT * FROM table_name) TO '/tmp/export.csv' WITH CSV HEADER"

# CSV (MySQL)
mysql "$CONN" -e "SELECT * FROM table_name" | sed 's/	/,/g' > /tmp/export.csv

# JSON (PostgreSQL)
psql "$CONN" -t -c "SELECT json_agg(t) FROM (SELECT * FROM table_name LIMIT 100) t;" > /tmp/export.json

# SQLite to CSV
sqlite3 /path/to/db.db ".mode csv" ".headers on" ".output /tmp/export.csv" "SELECT * FROM table_name;" ".quit"

6. Common Diagnostic Queries

-- PostgreSQL: Table sizes
SELECT schemaname, tablename, pg_size_pretty(pg_total_relation_size(schemaname||'.'||tablename))
FROM pg_tables WHERE schemaname = 'public' ORDER BY pg_total_relation_size(schemaname||'.'||tablename) DESC;

-- PostgreSQL: Active connections
SELECT pid, usename, application_name, client_addr, state, query_start, query
FROM pg_stat_activity WHERE state != 'idle';

-- PostgreSQL: Slow queries (> 1s)
SELECT pid, now() - pg_stat_activity.query_start AS duration, query
FROM pg_stat_activity WHERE state = 'active' AND now() - pg_stat_activity.query_start > interval '1 second';

-- MySQL: Table sizes
SELECT table_name, ROUND(data_length/1024/1024, 2) AS data_mb, table_rows
FROM information_schema.tables WHERE table_schema = DATABASE() ORDER BY data_length DESC;

-- MySQL: Process list
SHOW FULL PROCESSLIST;

Performance Analysis

PostgreSQL Performance

# Slow queries (active for > 1s)
psql "$CONN" -c "
SELECT pid, now() - query_start AS duration, query
FROM pg_stat_activity
WHERE state = 'active' AND now() - query_start > interval '1 second'
ORDER BY duration DESC;
"

# Index usage
psql "$CONN" -c "
SELECT schemaname, tablename, indexname, idx_scan, idx_tup_read
FROM pg_stat_user_indexes
ORDER BY idx_scan ASC LIMIT 20;
"

# Table bloat
psql "$CONN" -c "
SELECT schemaname, tablename,
  pg_size_pretty(pg_total_relation_size(schemaname||'.'||tablename)) AS total_size,
  pg_size_pretty(pg_relation_size(schemaname||'.'||tablename)) AS table_size,
  pg_size_pretty(pg_total_relation_size(schemaname||'.'||tablename) - pg_relation_size(schemaname||'.'||tablename)) AS index_size
FROM pg_tables
WHERE schemaname = 'public'
ORDER BY pg_total_relation_size(schemaname||'.'||tablename) DESC LIMIT 10;
"

# Cache hit ratio (should be > 99%)
psql "$CONN" -c "
SELECT
  sum(heap_blks_hit) / (sum(heap_blks_hit) + sum(heap_blks_read)) AS cache_hit_ratio
FROM pg_statio_user_tables;
"

MySQL Performance

# Slow queries
mysql "$CONN" -e "SELECT * FROM information_schema.processlist WHERE TIME > 1 ORDER BY TIME DESC;"

# Index usage
mysql "$CONN" -e "
SELECT table_name, index_name, cardinality
FROM information_schema.statistics
WHERE table_schema = DATABASE()
ORDER BY cardinality DESC LIMIT 20;
"

# Table sizes
mysql "$CONN" -e "
SELECT table_name,
  ROUND(data_length/1024/1024, 2) AS data_mb,
  ROUND(index_length/1024/1024, 2) AS index_mb,
  table_rows
FROM information_schema.tables
WHERE table_schema = DATABASE()
ORDER BY data_length DESC LIMIT 10;
"

Backup & Restore

PostgreSQL

# Backup single database
pg_dump "$CONN" > backup_$(date +%Y%m%d).sql

# Backup single table
pg_dump "$CONN" -t table_name > table_backup.sql

# Restore
psql "$CONN" \x3C backup.sql

# Backup with compression
pg_dump "$CONN" | gzip > backup_$(date +%Y%m%d).sql.gz

MySQL

# Backup single database
mysqldump -h host -u user -p dbname > backup_$(date +%Y%m%d).sql

# Backup single table
mysqldump -h host -u user -p dbname table_name > table_backup.sql

# Restore
mysql -h host -u user -p dbname \x3C backup.sql

SQLite

# Backup
sqlite3 /path/to/db.db ".backup /tmp/backup.db"

# Or just copy
cp /path/to/db.db /tmp/backup_$(date +%Y%m%d).db

Data Migration Helpers

Copy table between databases

# PostgreSQL to CSV to MySQL
psql "$PG_CONN" -c "\copy table_name TO '/tmp/export.csv' WITH CSV HEADER"
mysql "$MYSQL_CONN" -e "LOAD DATA LOCAL INFILE '/tmp/export.csv' INTO TABLE table_name FIELDS TERMINATED BY ',' ENCLOSED BY '\"' LINES TERMINATED BY '\
' IGNORE 1 ROWS;"

Schema comparison

# Get PostgreSQL schema hash for comparison
psql "$CONN" -c "
SELECT md5(string_agg(table_name || column_name || data_type, '' ORDER BY table_name, ordinal_position))
FROM information_schema.columns
WHERE table_schema = 'public';
"

Pitfalls

  • Connection strings with special chars — URL-encode passwords containing @, :, /, etc.
  • SSL requirements — Many cloud databases (RDS, Cloud SQL, Supabase) require ?sslmode=require or --ssl-mode=REQUIRED
  • Timeout on large tables — Always LIMIT unless user explicitly wants full export
  • SQLite locking — Only one writer at a time; use WAL mode for concurrent reads: PRAGMA journal_mode=WAL;
  • MongoDB auth database — Sometimes auth is on admin db, not the target db: ?authSource=admin
  • Redis SELECT — Redis has 16 databases (0-15); check which one: redis-cli INFO keyspace

Verification

After connecting:

  1. Run a simple query to confirm connection works
  2. List tables/collections to show the schema
  3. Run a count query on a key table to verify data access
  4. Check cache hit ratio (PostgreSQL) or slow queries (MySQL)
  5. Verify backup capability with a test dump

Environment Variables

The skill uses these if available:

  • DATABASE_URL — Full connection string (takes priority)
  • DB_HOST, DB_PORT, DB_NAME, DB_USER, DB_PASSWORD — Individual params
  • DB_TYPE — postgres/mysql/sqlite/mongo/redis
安全使用建议
Install only if you are comfortable giving the agent database connection details and supervising its queries. Prefer read-only or temporary credentials, avoid production admin accounts, review commands before execution, and be careful with exports because they may write sensitive data to local files.
功能分析
Type: OpenClaw Skill Name: hermes-db-explorer Version: 2.0.0 The 'hermes-db-explorer' skill is a comprehensive tool for database management and exploration across multiple platforms (PostgreSQL, MySQL, SQLite, MongoDB, Redis). The instructions in SKILL.md include strong safety guidelines for the AI agent, such as enforcing read-only operations by default, limiting query results, and requiring explicit user confirmation for write operations. No evidence of malicious intent, data exfiltration to external endpoints, or unauthorized execution was found.
能力评估
Purpose & Capability
The stated purpose—connecting to databases, inspecting schemas, running queries, and exporting results—matches the instructions. These capabilities can expose sensitive database contents, but they are disclosed and purpose-aligned.
Instruction Scope
The skill includes safety rules for read-only default behavior, result limits, and explicit confirmation before writes. Users should still scope queries and exports carefully, especially for production databases or large tables.
Install Mechanism
There is no install spec or bundled code. The skill documents manual installation of standard database CLI tools through package managers, which is expected for the purpose.
Credentials
The registry declares no credential requirement, while the SKILL.md asks users for database connection strings or passwords at runtime. This is expected for a database tool, but users should provide least-privilege, temporary credentials where possible.
Persistence & Privilege
The artifacts show no background service, persistence mechanism, self-start behavior, or hidden privilege escalation. File writes appear limited to user-directed exports such as CSV or JSON output.
如何使用
  1. 确保已安装 OpenClaw(本地或 Docker 部署)
  2. 在对话框中输入安装命令:/install hermes-db-explorer
  3. 安装完成后,直接呼叫该 Skill 的名称或使用 /hermes-db-explorer 触发
  4. 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v2.0.0
Version 2.0.0 of db-explorer is a major update introducing multi-database support and safer workflows: - Now supports PostgreSQL, MySQL, SQLite, MongoDB, and Redis for querying, schema exploration, export, and diagnostics. - Concise quick-start guides for each database, including connection, schema, and data exploration examples. - Enforces safety: read-only by default, user confirmation for write actions, results limiting, and password handling best practices. - Includes workflows for schema mapping, exporting to CSV/JSON, and running diagnostic or performance queries. - Adds backup and restore steps for PostgreSQL, MySQL, and SQLite. - Enhanced guidance for performance tuning, diagnosing slow queries, and exploring table/index usage.
元数据
Slug hermes-db-explorer
版本 2.0.0
许可证 MIT-0
累计安装 0
当前安装数 0
历史版本数 1
常见问题

Db Explorer 是什么?

Connect to and explore databases (PostgreSQL, MySQL, SQLite, MongoDB, Redis). Run queries, inspect schemas, export data. Use when user wants to query a datab... 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 71 次。

如何安装 Db Explorer?

在 OpenClaw 或 Claude Code 对话框中运行命令「/install hermes-db-explorer」即可一键安装,无需额外配置。

Db Explorer 是免费的吗?

是的,Db Explorer 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。

Db Explorer 支持哪些平台?

Db Explorer 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。

谁开发了 Db Explorer?

由 lrg913427-dot(@lrg913427-dot)开发并维护,当前版本 v2.0.0。

💬 留言讨论