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

原始链接: https://github.com/mickamy/sql-tap

## sql-tap:实时 SQL 流量监控 sql-tap 是一款用于实时观察 SQL 查询的工具,它充当您的应用程序与 PostgreSQL 或 MySQL 数据库之间的透明代理。它不需要任何应用程序代码的更改。 该系统由两个组件组成:`sql-tapd`,一个通过数据库网络协议捕获查询的代理守护进程,以及 `sql-tap`,一个显示捕获流量的终端用户界面 (TUI) 客户端。 您安装 `sql-tapd` 并将您的应用程序指向其监听端口,而不是数据库。然后,TUI 通过 gRPC 连接到 `sql-tapd`,以显示查询、事务和执行细节的实时流。 主要功能包括检查查询、查看事务以及直接从 TUI 运行 `EXPLAIN`(和 `EXPLAIN ANALYZE`)。安装可通过 `brew` 或 `go install` 进行,并提供 Docker 镜像以方便设置。

黑客新闻 新的 | 过去的 | 评论 | 提问 | 展示 | 工作 | 提交 登录 Show HN: SQL-tap – PostgreSQL 和 MySQL 的实时 SQL 流量查看器 (github.com/mickamy) 7 分,由 mickamy 1 小时前发布 | 隐藏 | 过去的 | 收藏 | 1 评论 sql-tap 是一个透明代理,通过解析 PostgreSQL/MySQL 的网络协议来捕获 SQL 查询,并在终端 UI 中显示它们。你可以对任何捕获的查询运行 EXPLAIN。无需更改应用程序代码 — 只需要更改端口。 nwellinghoff 10 分钟前 [–] 不错。我喜欢你把它做成一个易于插入的代理。调试问题时肯定会使用这个!回复 指南 | 常见问题 | 列表 | API | 安全 | 法律 | 申请 YC | 联系 搜索:
相关文章

原文

Real-time SQL traffic viewer — proxy daemon + TUI client.

sql-tap sits between your application and your database (PostgreSQL or MySQL), capturing every query and displaying it in an interactive terminal UI. Inspect queries, view transactions, and run EXPLAIN — all without changing your application code.

demo

brew install --cask mickamy/tap/sql-tap
go install github.com/mickamy/sql-tap@latest
go install github.com/mickamy/sql-tap/cmd/sql-tapd@latest
git clone https://github.com/mickamy/sql-tap.git
cd sql-tap
make install

PostgreSQL

FROM postgres:18-alpine
ARG SQL_TAP_VERSION=0.0.1
ARG TARGETARCH``
ADD https://github.com/mickamy/sql-tap/releases/download/v${SQL_TAP_VERSION}/sql-tap_${SQL_TAP_VERSION}_linux_${TARGETARCH}.tar.gz /tmp/sql-tap.tar.gz
RUN tar -xzf /tmp/sql-tap.tar.gz -C /usr/local/bin sql-tapd && rm /tmp/sql-tap.tar.gz
ENTRYPOINT ["sql-tapd", "--driver=postgres", "--listen=:5433", "--upstream=localhost:5432", "--grpc=:9091"]

MySQL

FROM mysql:8
ARG SQL_TAP_VERSION=0.0.1
ARG TARGETARCH
ADD https://github.com/mickamy/sql-tap/releases/download/v${SQL_TAP_VERSION}/sql-tap_${SQL_TAP_VERSION}_linux_${TARGETARCH}.tar.gz /tmp/sql-tap.tar.gz
RUN tar -xzf /tmp/sql-tap.tar.gz -C /usr/local/bin sql-tapd && rm /tmp/sql-tap.tar.gz
ENTRYPOINT ["sql-tapd", "--driver=mysql", "--listen=:3307", "--upstream=localhost:3306", "--grpc=:9091"]

1. Start the proxy daemon

# PostgreSQL: proxy listens on :5433, forwards to PostgreSQL on :5432
DATABASE_URL="postgres://user:pass@localhost:5432/db?sslmode=disable" \
  sql-tapd --driver=postgres --listen=:5433 --upstream=localhost:5432

# MySQL: proxy listens on :3307, forwards to MySQL on :3306
DATABASE_URL="user:pass@tcp(localhost:3306)/db" \
  sql-tapd --driver=mysql --listen=:3307 --upstream=localhost:3306

2. Point your application at the proxy

Connect your app to the proxy port instead of the database port. No code changes needed — sql-tapd speaks the native wire protocol.

3. Launch the TUI

All queries flowing through the proxy appear in real-time.

sql-tapd — SQL proxy daemon for sql-tap

Usage:
  sql-tapd [flags]

Flags:
  -driver    database driver: postgres, mysql (required)
  -listen    client listen address (required)
  -upstream  upstream database address (required)
  -grpc      gRPC server address for TUI (default: ":9091")
  -dsn-env   env var holding DSN for EXPLAIN (default: "DATABASE_URL")
  -version   show version and exit

Set DATABASE_URL (or the env var specified by -dsn-env) to enable EXPLAIN support. Without it, the proxy still captures queries but EXPLAIN is disabled.

sql-tap — Watch SQL traffic in real-time

Usage:
  sql-tap [flags] <addr>

Flags:
  -version  Show version and exit

<addr> is the gRPC address of sql-tapd (e.g. localhost:9091).

Key Action
j / Move down
k / Move up
Enter Inspect query / transaction
Space Toggle transaction expand / collapse
x EXPLAIN
X EXPLAIN ANALYZE
e Edit query, then EXPLAIN
E Edit query, then EXPLAIN ANALYZE
c Copy query
C Copy query with bound args
q Quit
Key Action
j / Scroll down
k / Scroll up
x EXPLAIN
X EXPLAIN ANALYZE
e / E Edit and EXPLAIN / ANALYZE
c Copy query
C Copy query with bound args
q Back to list
Key Action
j / Scroll down
k / Scroll up
h / Scroll left
l / Scroll right
c Copy explain plan
e / E Edit and re-explain / re-analyze
q Back to list
┌─────────────┐      ┌───────────────────────┐      ┌────────────────────┐
│ Application │─────▶│  sql-tapd (proxy)     │─────▶│ PostgreSQL / MySQL │
└─────────────┘      │                       │      └────────────────────┘
                     │  captures queries     │
                     │  via wire protocol    │
                     └───────────┬───────────┘
                                 │ gRPC stream
                     ┌───────────▼───────────┐
                     │  sql-tap (TUI)        │
                     └───────────────────────┘

sql-tapd parses the database wire protocol (PostgreSQL or MySQL) to intercept queries transparently. It tracks prepared statements, parameter bindings, transactions, execution time, rows affected, and errors. Events are streamed to connected TUI clients via gRPC.

MIT

联系我们 contact @ memedata.com