PostgreSQL 内省机制的难点(构建原生客户端的经验教训)

2作者: debba大约 21 小时前
我正在开发 Tabularis,一个原生数据库客户端(Rust + Tauri)。 MySQL 的支持已经比较完善,但要正确处理 PostgreSQL 却难得多——这并非因为性能问题,而是因为**内省**。 Postgres “能用”,但一旦涉及到基本表和列之外的内容,问题就会迅速变得棘手。 到目前为止,我遇到的一些问题: * **类型系统:** 数组、JSON/JSONB、域、自定义类型、范围、几何类型——大多数客户端要么将它们扁平化为文本,要么处理得不一致。 * **模式内省:** information\_schema 的功能有限。 pg\_catalog 功能强大,但使用起来很微妙。 触发器、函数、分区表、继承、物化视图都需要特殊处理。 * **Postgres 特有的用户体验:** 包含 CTE 的复杂查询、EXPLAIN ANALYZE 的输出、PostGIS / pgvector 等扩展——这些都不能直接映射到通用的数据库抽象。 目前,我正在使用 SQLx,并结合 information\_schema 和 pg\_catalog 查询,但我确信我遗漏了更好的模式。 我希望得到以下人士的反馈: * 编写过重要的 Postgres 内省查询的人 * 对 Postgres 客户端**应该**如何表示模式和类型有看法的人 * 对现有的 Postgres GUI 感到沮丧的人 代码仓库(Apache 2.0 许可证):[https://github.com/debba/tabularis](https://github.com/debba/tabularis) 乐于学习、迭代和纠正错误的假设。
查看原文
I’m building Tabularis, a native database client (Rust + Tauri). MySQL support is in a good place, but PostgreSQL has been much harder to get right — not for performance, but for <i>introspection</i>.<p>Postgres “works”, but once you go beyond basic tables and columns, things get tricky fast.<p>Some gaps I’ve hit so far:<p>- Type system: Arrays, JSON&#x2F;JSONB, domains, custom types, ranges, geometric types — most clients either flatten them to text or handle them inconsistently.<p>- Schema introspection: information_schema only goes so far. pg_catalog is powerful but subtle. Triggers, functions, partitioned tables, inheritance, materialized views all require special handling.<p>- Postgres-specific UX: CTE-heavy queries, EXPLAIN ANALYZE output, extensions like PostGIS &#x2F; pgvector — these don’t map cleanly to generic DB abstractions.<p>I’m currently using SQLx and a mix of information_schema + pg_catalog queries, but I’m sure there are better patterns I’m missing.<p>I’d love feedback from people who: - Have written serious Postgres introspection queries - Have opinions on how Postgres clients <i>should</i> represent schemas and types - Have been frustrated by existing Postgres GUIs<p>Repo (Apache 2.0): https:&#x2F;&#x2F;github.com&#x2F;debba&#x2F;tabularis<p>Happy to learn, iterate, and fix wrong assumptions.