Hacker News 中文摘要

RSS订阅

显示 HN: SQL-tap – PostgreSQL 和 MySQL 的实时 SQL 流量查看器 -- Show HN: SQL-tap – Real-time SQL traffic viewer for PostgreSQL and MySQL

文章摘要

sql-tap是一个GitHub开源项目,提供实时监控SQL流量的终端用户界面(TUI)工具,方便开发者查看数据库查询情况。该项目由mickamy开发维护。

文章总结

GitHub 项目:sql-tap - 实时监控 SQL 流量的 TUI 工具
项目地址:https://github.com/mickamy/sql-tap

核心功能

  • 实时 SQL 监控:通过代理中间件捕获应用与数据库(PostgreSQL/MySQL)之间的所有查询,无需修改代码。
  • 交互式终端界面:支持查询检查、事务分析、执行计划分析(EXPLAIN)等功能。
  • 多协议支持:解析 PostgreSQL 和 MySQL 的通信协议,透明拦截查询。

安装方式

  1. Homebrewbrew install --cask mickamy/tap/sql-tap
  2. Go 安装go install github.com/mickamy/sql-tap@latest
  3. 源码编译:克隆仓库后运行 make install
  4. Docker:提供 PostgreSQL 和 MySQL 的预配置镜像。

快速入门

  1. 启动代理守护进程(sql-tapd),配置监听端口和上游数据库地址。
  2. 将应用连接指向代理端口。
  3. 启动 TUI 客户端(sql-tap)连接代理的 gRPC 服务。

关键特性

  • 代理功能:捕获查询、预处理语句、事务、执行时间及错误。
  • TUI 操作
    • 列表视图:支持排序、搜索、查询复制、执行计划分析。
    • 分析视图:按查询统计耗时、调用次数等指标。
    • 快捷键:提供丰富的键盘操作(如 j/k 导航、x 查看 EXPLAIN)。

技术架构

应用 → sql-tapd(代理,解析协议) → 数据库 ↓ TUI 客户端(通过 gRPC 接收实时数据)

许可证

MIT 开源协议。

项目状态

  • 251 Stars,3 Forks,最新版本 v0.0.5(2026年2月发布)。
  • 主要语言:Go(98.9%)。

(注:原文中的导航菜单、页脚链接等非核心内容已精简,保留关键功能说明和操作指南。)

评论总结

总结评论内容:

正面评价: 1. 工具实用性和易用性受到好评 - "Nice. I like how you made it an easy to drop in proxy. Will definitely use this when debugging issues!"(评论1) - "That's some sick observability, nice."(评论2) - "Just tried it out. Works fine. Love it!"(评论11)

  1. 对数据库查询监控功能表示赞赏
  • "IMO inspecting the queries the agents run on the database is a better approach to understand how the code works"(评论3)
  • "Traditionally it was database activity monitoring which kind of fell out of fashion, but i think it is going to be back with advent of agents."(评论4)

改进建议: 1. 功能增强建议 - "some kind of sorting: eg. by excecution time or order. So I can see the slowest queries."(评论11) - "search/filter feature...maybe how often the same query was executed."(评论11)

  1. 命名冲突问题
  • "Maybe consider renaming this since pgTAP exists and has nothing to do with this."(评论8)

替代方案讨论: 1. 其他监控方法 - "Can you explain how this is a better option than just enabling the general log for MySQL as needed?"(评论7) - "Why do you need a proxy? Pull the queries off the network."(评论10) - "I prefer to use eBPF; no additional software, proxy or configuration needed."(评论12)

  1. 类似工具分享
  • "I built a similar tool https://dbfor.dev for the exact purpose"(评论3)
  • "We do something similar in adaptive"(评论4)

技术疑问: 1. 开发方式询问 - "Was AI used to build this? If so, would you mind sharing which model(s) you used and what tooling?"(评论9)