@indiekitai/pg-dash 0.2.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 IndieKit
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,196 @@
1
+ [English](README.md) | [中文](README.zh-CN.md)
2
+
3
+ # pg-dash
4
+
5
+ **Lightweight PostgreSQL monitoring dashboard.** One command to start, built-in web UI, actionable fix suggestions.
6
+
7
+ Think **pganalyze for indie devs** — no Grafana, no Prometheus, no Docker. Just `npx` and go.
8
+
9
+ ```bash
10
+ npx @indiekitai/pg-dash postgres://user:pass@host/db
11
+ ```
12
+
13
+ ## Why?
14
+
15
+ | Tool | Price | Setup | For |
16
+ |------|-------|-------|-----|
17
+ | pganalyze | $149+/mo | SaaS signup | Enterprises |
18
+ | Grafana+Prometheus | Free | 3 services to configure | DevOps teams |
19
+ | pgAdmin | Free | Complex UI | DBAs |
20
+ | **pg-dash** | **Free** | **One command** | **Developers** |
21
+
22
+ ## Features
23
+
24
+ ### 📊 Real-time Monitoring
25
+ - Live connection count, TPS, cache hit ratio, DB size
26
+ - Time-series charts with range selector (5m → 7d)
27
+ - WebSocket-powered auto-refresh
28
+ - Active query list with cancel support
29
+
30
+ ### 🏥 Health Advisor
31
+ - **46+ automated checks** across performance, maintenance, schema, and security
32
+ - A-F health grade with category breakdown
33
+ - **One-click fixes** — not just "here's what's wrong" but "click to fix it"
34
+ - SQL allowlist (only safe operations: VACUUM, ANALYZE, REINDEX, etc.)
35
+
36
+ ### 📋 Schema Browser
37
+ - Browse all tables, columns, indexes, constraints, foreign keys
38
+ - Sample data preview
39
+ - Index usage stats
40
+ - Extension and enum type listing
41
+
42
+ ### 🔄 Schema Change Tracking
43
+ - Automatic schema snapshots (every 6 hours)
44
+ - Detects: tables added/removed, columns changed, indexes modified
45
+ - Timeline view with diff comparison
46
+ - The sticky feature — gets more valuable over time
47
+
48
+ ### 🔔 Alerts
49
+ - 7 default alert rules (connection utilization, cache ratio, long queries, etc.)
50
+ - Custom rules via API
51
+ - Cooldown support (no alert spam)
52
+ - Webhook notifications
53
+ - Alert history
54
+
55
+ ### 🤖 MCP Server
56
+ - 8 tools for AI agent integration
57
+ - `pg-dash-mcp postgres://...` — works with Claude, Cursor, etc.
58
+
59
+ ### 🖥️ CLI
60
+ ```bash
61
+ # Start dashboard
62
+ pg-dash postgres://user:pass@host/db
63
+
64
+ # Health check (great for CI/CD)
65
+ pg-dash check postgres://user:pass@host/db
66
+ pg-dash check postgres://... --format json --threshold 70
67
+
68
+ # Schema changes
69
+ pg-dash schema-diff postgres://user:pass@host/db
70
+
71
+ # JSON dump
72
+ pg-dash postgres://... --json
73
+ ```
74
+
75
+ ## Quick Start
76
+
77
+ ```bash
78
+ # Using npx (no install needed)
79
+ npx @indiekitai/pg-dash postgres://user:pass@localhost/mydb
80
+
81
+ # Or install globally
82
+ npm install -g @indiekitai/pg-dash
83
+ pg-dash postgres://user:pass@localhost/mydb
84
+
85
+ # With individual options
86
+ pg-dash --host localhost --user postgres --db mydb --port 3480
87
+ ```
88
+
89
+ Opens your browser at `http://localhost:3480` with the full dashboard.
90
+
91
+ ## CLI Options
92
+
93
+ ```
94
+ pg-dash <connection-string> Start dashboard
95
+ pg-dash check <connection-string> Run health check and exit
96
+ pg-dash schema-diff <connection-string> Show schema changes
97
+
98
+ Options:
99
+ -p, --port <port> Dashboard port (default: 3480)
100
+ --no-open Don't auto-open browser
101
+ --json Dump health check as JSON and exit
102
+ --host <host> PostgreSQL host
103
+ -u, --user <user> PostgreSQL user
104
+ --password <pass> PostgreSQL password
105
+ -d, --db <database> PostgreSQL database
106
+ --pg-port <port> PostgreSQL port (default: 5432)
107
+ --data-dir <dir> Data directory (default: ~/.pg-dash)
108
+ -i, --interval <sec> Collection interval (default: 30)
109
+ --threshold <score> Score threshold for check command (default: 70)
110
+ -f, --format <fmt> Output format: text|json (default: text)
111
+ -v, --version Show version
112
+ ```
113
+
114
+ ## MCP Server
115
+
116
+ For AI agent integration:
117
+
118
+ ```bash
119
+ # Start MCP server
120
+ pg-dash-mcp postgres://user:pass@host/db
121
+
122
+ # Or with env var
123
+ PG_DASH_CONNECTION_STRING=postgres://... pg-dash-mcp
124
+ ```
125
+
126
+ Available tools: `pg_dash_overview`, `pg_dash_health`, `pg_dash_tables`, `pg_dash_table_detail`, `pg_dash_activity`, `pg_dash_schema_changes`, `pg_dash_fix`, `pg_dash_alerts`
127
+
128
+ ## Health Checks
129
+
130
+ pg-dash runs 46+ automated checks:
131
+
132
+ **Performance**
133
+ - Missing indexes (high sequential scans on large tables)
134
+ - Bloated indexes (index size vs table size)
135
+ - Table bloat (dead tuple ratio)
136
+ - Cache efficiency per table
137
+ - Slow queries (from pg_stat_statements)
138
+
139
+ **Maintenance**
140
+ - VACUUM overdue
141
+ - ANALYZE overdue
142
+ - Transaction ID wraparound risk
143
+ - Idle connection detection
144
+ - Idle in transaction detection
145
+
146
+ **Schema**
147
+ - Missing primary keys
148
+ - Unused indexes (0 scans, >1MB)
149
+ - Duplicate indexes
150
+ - Missing foreign key indexes
151
+
152
+ **Security**
153
+ - Remote superuser connections
154
+ - SSL disabled
155
+ - Trust authentication (no password)
156
+
157
+ ## CI/CD Integration
158
+
159
+ ```bash
160
+ # Fail pipeline if health score < 70
161
+ pg-dash check postgres://... --threshold 70 --format json
162
+
163
+ # Example GitHub Actions
164
+ - name: Database Health Check
165
+ run: npx @indiekitai/pg-dash check ${{ secrets.DATABASE_URL }} --threshold 70
166
+ ```
167
+
168
+ ## Data Storage
169
+
170
+ pg-dash stores metrics locally in `~/.pg-dash/`:
171
+ - `metrics.db` — Time-series metrics (7-day retention)
172
+ - `schema.db` — Schema snapshots and change history
173
+ - `alerts.db` — Alert rules and history
174
+
175
+ All SQLite. No external dependencies. Delete the folder to reset.
176
+
177
+ ## Tech Stack
178
+
179
+ - **Backend**: Hono + Node.js
180
+ - **Frontend**: React + Tailwind CSS (bundled)
181
+ - **Storage**: SQLite (better-sqlite3)
182
+ - **Charts**: Recharts
183
+ - **Zero external services required**
184
+
185
+ ## Requirements
186
+
187
+ - Node.js 18+
188
+ - PostgreSQL 12+ (some features require 15+)
189
+
190
+ ## License
191
+
192
+ MIT
193
+
194
+ ---
195
+
196
+ Built by [IndieKit](https://github.com/indiekitai) 🛠️
@@ -0,0 +1,196 @@
1
+ [English](README.md) | [中文](README.zh-CN.md)
2
+
3
+ # pg-dash
4
+
5
+ **轻量级 PostgreSQL 监控面板。** 一条命令启动,内置 Web UI,提供可操作的修复建议。
6
+
7
+ 可以理解为**给独立开发者的 pganalyze** —— 不需要 Grafana,不需要 Prometheus,不需要 Docker。只需 `npx` 即可运行。
8
+
9
+ ```bash
10
+ npx @indiekitai/pg-dash postgres://user:pass@host/db
11
+ ```
12
+
13
+ ## 为什么选 pg-dash?
14
+
15
+ | 工具 | 价格 | 部署 | 适合 |
16
+ |------|------|------|------|
17
+ | pganalyze | $149+/月 | SaaS 注册 | 企业 |
18
+ | Grafana+Prometheus | 免费 | 配置 3 个服务 | DevOps 团队 |
19
+ | pgAdmin | 免费 | 界面复杂 | DBA |
20
+ | **pg-dash** | **免费** | **一条命令** | **开发者** |
21
+
22
+ ## 功能
23
+
24
+ ### 📊 实时监控
25
+ - 实时连接数、TPS、缓存命中率、数据库大小
26
+ - 带范围选择器的时序图(5分钟 → 7天)
27
+ - WebSocket 自动刷新
28
+ - 活跃查询列表,支持取消操作
29
+
30
+ ### 🏥 健康顾问
31
+ - **46+ 项自动化检查**,覆盖性能、维护、Schema、安全等维度
32
+ - A-F 健康评级,按类别分项展示
33
+ - **一键修复** —— 不只告诉你哪里有问题,还能直接修复
34
+ - SQL 白名单(仅允许安全操作:VACUUM、ANALYZE、REINDEX 等)
35
+
36
+ ### 📋 Schema 浏览器
37
+ - 浏览所有表、列、索引、约束、外键
38
+ - 数据预览
39
+ - 索引使用统计
40
+ - Extension 和 Enum 类型列表
41
+
42
+ ### 🔄 Schema 变更追踪
43
+ - 自动 Schema 快照(每 6 小时)
44
+ - 检测:新增/删除表、列变更、索引修改
45
+ - 时间线视图,支持 diff 对比
46
+ - 越用越有价值的粘性功能
47
+
48
+ ### 🔔 告警
49
+ - 7 条默认告警规则(连接使用率、缓存比率、长查询等)
50
+ - 通过 API 自定义规则
51
+ - 冷却机制(避免告警轰炸)
52
+ - Webhook 通知
53
+ - 告警历史
54
+
55
+ ### 🤖 MCP Server
56
+ - 8 个工具,支持 AI Agent 集成
57
+ - `pg-dash-mcp postgres://...` —— 可配合 Claude、Cursor 等使用
58
+
59
+ ### 🖥️ CLI
60
+ ```bash
61
+ # 启动面板
62
+ pg-dash postgres://user:pass@host/db
63
+
64
+ # 健康检查(适合 CI/CD)
65
+ pg-dash check postgres://user:pass@host/db
66
+ pg-dash check postgres://... --format json --threshold 70
67
+
68
+ # Schema 变更
69
+ pg-dash schema-diff postgres://user:pass@host/db
70
+
71
+ # JSON 输出
72
+ pg-dash postgres://... --json
73
+ ```
74
+
75
+ ## 快速开始
76
+
77
+ ```bash
78
+ # 使用 npx(无需安装)
79
+ npx @indiekitai/pg-dash postgres://user:pass@localhost/mydb
80
+
81
+ # 或全局安装
82
+ npm install -g @indiekitai/pg-dash
83
+ pg-dash postgres://user:pass@localhost/mydb
84
+
85
+ # 使用独立参数
86
+ pg-dash --host localhost --user postgres --db mydb --port 3480
87
+ ```
88
+
89
+ 浏览器将自动打开 `http://localhost:3480`,展示完整的监控面板。
90
+
91
+ ## CLI 参数
92
+
93
+ ```
94
+ pg-dash <connection-string> 启动面板
95
+ pg-dash check <connection-string> 运行健康检查并退出
96
+ pg-dash schema-diff <connection-string> 显示 Schema 变更
97
+
98
+ Options:
99
+ -p, --port <port> 面板端口(默认:3480)
100
+ --no-open 不自动打开浏览器
101
+ --json 以 JSON 格式输出健康检查结果并退出
102
+ --host <host> PostgreSQL 主机
103
+ -u, --user <user> PostgreSQL 用户
104
+ --password <pass> PostgreSQL 密码
105
+ -d, --db <database> PostgreSQL 数据库
106
+ --pg-port <port> PostgreSQL 端口(默认:5432)
107
+ --data-dir <dir> 数据目录(默认:~/.pg-dash)
108
+ -i, --interval <sec> 采集间隔(默认:30)
109
+ --threshold <score> check 命令的分数阈值(默认:70)
110
+ -f, --format <fmt> 输出格式:text|json(默认:text)
111
+ -v, --version 显示版本
112
+ ```
113
+
114
+ ## MCP Server
115
+
116
+ 用于 AI Agent 集成:
117
+
118
+ ```bash
119
+ # 启动 MCP server
120
+ pg-dash-mcp postgres://user:pass@host/db
121
+
122
+ # 或通过环境变量
123
+ PG_DASH_CONNECTION_STRING=postgres://... pg-dash-mcp
124
+ ```
125
+
126
+ 可用工具:`pg_dash_overview`、`pg_dash_health`、`pg_dash_tables`、`pg_dash_table_detail`、`pg_dash_activity`、`pg_dash_schema_changes`、`pg_dash_fix`、`pg_dash_alerts`
127
+
128
+ ## 健康检查
129
+
130
+ pg-dash 运行 46+ 项自动化检查:
131
+
132
+ **性能**
133
+ - 缺失索引(大表上的高频顺序扫描)
134
+ - 膨胀索引(索引大小 vs 表大小)
135
+ - 表膨胀(死元组比例)
136
+ - 每张表的缓存效率
137
+ - 慢查询(来自 pg_stat_statements)
138
+
139
+ **维护**
140
+ - VACUUM 过期
141
+ - ANALYZE 过期
142
+ - Transaction ID 回卷风险
143
+ - 空闲连接检测
144
+ - Idle in transaction 检测
145
+
146
+ **Schema**
147
+ - 缺失主键
148
+ - 未使用的索引(0 次扫描,>1MB)
149
+ - 重复索引
150
+ - 缺失外键索引
151
+
152
+ **安全**
153
+ - 远程超级用户连接
154
+ - SSL 未启用
155
+ - Trust 认证(无密码)
156
+
157
+ ## CI/CD 集成
158
+
159
+ ```bash
160
+ # 健康分低于 70 时让流水线失败
161
+ pg-dash check postgres://... --threshold 70 --format json
162
+
163
+ # GitHub Actions 示例
164
+ - name: Database Health Check
165
+ run: npx @indiekitai/pg-dash check ${{ secrets.DATABASE_URL }} --threshold 70
166
+ ```
167
+
168
+ ## 数据存储
169
+
170
+ pg-dash 将指标存储在本地 `~/.pg-dash/` 目录:
171
+ - `metrics.db` —— 时序指标(保留 7 天)
172
+ - `schema.db` —— Schema 快照和变更历史
173
+ - `alerts.db` —— 告警规则和历史
174
+
175
+ 全部使用 SQLite,无外部依赖。删除该目录即可重置。
176
+
177
+ ## 技术栈
178
+
179
+ - **后端**:Hono + Node.js
180
+ - **前端**:React + Tailwind CSS(已打包)
181
+ - **存储**:SQLite (better-sqlite3)
182
+ - **图表**:Recharts
183
+ - **无需任何外部服务**
184
+
185
+ ## 环境要求
186
+
187
+ - Node.js 18+
188
+ - PostgreSQL 12+(部分功能需要 15+)
189
+
190
+ ## 许可证
191
+
192
+ MIT
193
+
194
+ ---
195
+
196
+ 由 [IndieKit](https://github.com/indiekitai) 构建 🛠️