@carllee1983/dbcli 1.5.2 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +28 -0
- package/README.dev.md +51 -54
- package/README.md +85 -17
- package/README.zh-TW.md +79 -15
- package/assets/SKILL.md +95 -500
- package/assets/reference.md +510 -0
- package/assets/snippets/.keep +0 -0
- package/assets/snippets/README.md +18 -0
- package/assets/snippets/diag/cache-hit.mysql.sql +19 -0
- package/assets/snippets/diag/cache-hit.postgres.sql +18 -0
- package/assets/snippets/diag/connections.mysql.sql +16 -0
- package/assets/snippets/diag/connections.postgres.sql +16 -0
- package/assets/snippets/diag/db-size.mysql.sql +10 -0
- package/assets/snippets/diag/db-size.postgres.sql +9 -0
- package/assets/snippets/diag/index-usage.mysql.sql +15 -0
- package/assets/snippets/diag/index-usage.postgres.sql +14 -0
- package/assets/snippets/diag/locks.mysql.sql +14 -0
- package/assets/snippets/diag/locks.postgres.sql +15 -0
- package/assets/snippets/diag/long-running.mysql.sql +14 -0
- package/assets/snippets/diag/long-running.postgres.sql +19 -0
- package/assets/snippets/diag/missing-indexes.mysql.sql +13 -0
- package/assets/snippets/diag/missing-indexes.postgres.sql +15 -0
- package/assets/snippets/diag/table-sizes.mysql.sql +14 -0
- package/assets/snippets/diag/table-sizes.postgres.sql +13 -0
- package/dist/cli.mjs +2591 -514
- package/package.json +2 -2
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
-- ---
|
|
2
|
+
-- name: Lock waits (postgres)
|
|
3
|
+
-- description: Sessions blocked by other sessions with both queries shown.
|
|
4
|
+
-- engine: postgres
|
|
5
|
+
-- ---
|
|
6
|
+
SELECT blocked.pid AS blocked_pid,
|
|
7
|
+
blocked.usename AS blocked_user,
|
|
8
|
+
blocked.query AS blocked_query,
|
|
9
|
+
blocking.pid AS blocking_pid,
|
|
10
|
+
blocking.usename AS blocking_user,
|
|
11
|
+
blocking.query AS blocking_query
|
|
12
|
+
FROM pg_stat_activity AS blocked
|
|
13
|
+
JOIN pg_stat_activity AS blocking
|
|
14
|
+
ON blocking.pid = ANY(pg_blocking_pids(blocked.pid))
|
|
15
|
+
WHERE blocked.pid <> blocking.pid;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
-- ---
|
|
2
|
+
-- name: Long-running queries (mysql)
|
|
3
|
+
-- description: Non-sleep processes whose elapsed time exceeds min_seconds.
|
|
4
|
+
-- engine: mysql
|
|
5
|
+
-- params:
|
|
6
|
+
-- min_seconds:
|
|
7
|
+
-- type: int
|
|
8
|
+
-- default: 30
|
|
9
|
+
-- ---
|
|
10
|
+
SELECT id, user, host, db, time AS duration_seconds, state, info AS query
|
|
11
|
+
FROM information_schema.processlist
|
|
12
|
+
WHERE command <> 'Sleep'
|
|
13
|
+
AND time > :min_seconds
|
|
14
|
+
ORDER BY time DESC;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
-- ---
|
|
2
|
+
-- name: Long-running queries (postgres)
|
|
3
|
+
-- description: Queries running longer than min_seconds.
|
|
4
|
+
-- engine: postgres
|
|
5
|
+
-- params:
|
|
6
|
+
-- min_seconds:
|
|
7
|
+
-- type: int
|
|
8
|
+
-- default: 30
|
|
9
|
+
-- ---
|
|
10
|
+
SELECT pid,
|
|
11
|
+
usename AS user,
|
|
12
|
+
NOW() - query_start AS duration,
|
|
13
|
+
state,
|
|
14
|
+
query
|
|
15
|
+
FROM pg_stat_activity
|
|
16
|
+
WHERE state IS NOT NULL
|
|
17
|
+
AND state <> 'idle'
|
|
18
|
+
AND NOW() - query_start > make_interval(secs => :min_seconds)
|
|
19
|
+
ORDER BY duration DESC;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
-- ---
|
|
2
|
+
-- name: Missing indexes (mysql)
|
|
3
|
+
-- description: Tables with significant full-scan I/O and no index used.
|
|
4
|
+
-- engine: mysql
|
|
5
|
+
-- ---
|
|
6
|
+
SELECT object_schema AS `schema`,
|
|
7
|
+
object_name AS `table`,
|
|
8
|
+
count_read AS full_scan_reads
|
|
9
|
+
FROM performance_schema.table_io_waits_summary_by_index_usage
|
|
10
|
+
WHERE index_name IS NULL
|
|
11
|
+
AND object_schema NOT IN ('mysql','performance_schema','sys')
|
|
12
|
+
AND count_read > 1000
|
|
13
|
+
ORDER BY count_read DESC;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
-- ---
|
|
2
|
+
-- name: Missing indexes (postgres)
|
|
3
|
+
-- description: User tables where seq scans dominate over index scans (>1k rows).
|
|
4
|
+
-- engine: postgres
|
|
5
|
+
-- ---
|
|
6
|
+
SELECT schemaname AS schema,
|
|
7
|
+
relname AS table,
|
|
8
|
+
seq_scan,
|
|
9
|
+
seq_tup_read,
|
|
10
|
+
idx_scan,
|
|
11
|
+
n_live_tup AS estimated_rows
|
|
12
|
+
FROM pg_stat_user_tables
|
|
13
|
+
WHERE seq_scan > COALESCE(idx_scan, 0)
|
|
14
|
+
AND n_live_tup > 1000
|
|
15
|
+
ORDER BY seq_tup_read DESC;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
-- ---
|
|
2
|
+
-- name: Table sizes (mysql)
|
|
3
|
+
-- description: Data + index size in MB with estimated row count.
|
|
4
|
+
-- engine: mysql
|
|
5
|
+
-- ---
|
|
6
|
+
SELECT table_schema AS `schema`,
|
|
7
|
+
table_name AS `table`,
|
|
8
|
+
ROUND((data_length + index_length) / 1024 / 1024, 2) AS total_mb,
|
|
9
|
+
ROUND(data_length / 1024 / 1024, 2) AS data_mb,
|
|
10
|
+
ROUND(index_length / 1024 / 1024, 2) AS index_mb,
|
|
11
|
+
table_rows AS estimated_rows
|
|
12
|
+
FROM information_schema.tables
|
|
13
|
+
WHERE table_schema NOT IN ('mysql','information_schema','performance_schema','sys')
|
|
14
|
+
ORDER BY data_length + index_length DESC;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
-- ---
|
|
2
|
+
-- name: Table sizes (postgres)
|
|
3
|
+
-- description: Total / table / index size with estimated row count.
|
|
4
|
+
-- engine: postgres
|
|
5
|
+
-- ---
|
|
6
|
+
SELECT schemaname AS schema,
|
|
7
|
+
tablename AS table,
|
|
8
|
+
pg_size_pretty(pg_total_relation_size(schemaname||'.'||tablename)) AS total_size,
|
|
9
|
+
pg_size_pretty(pg_relation_size(schemaname||'.'||tablename)) AS table_size,
|
|
10
|
+
pg_size_pretty(pg_indexes_size(schemaname||'.'||tablename)) AS index_size,
|
|
11
|
+
n_live_tup AS estimated_rows
|
|
12
|
+
FROM pg_stat_user_tables
|
|
13
|
+
ORDER BY pg_total_relation_size(schemaname||'.'||tablename) DESC;
|