時間:2024-02-05 12:47作者:下載吧人氣:25
在 MySQL ShardingSphere-Proxy 逐漸成熟并被廣泛采用的同時,ShardingSphere 團隊也在 PostgreSQL ShardingSphere-Proxy 上持續發力。相比前期的 alpha 與 beta,5.0.0 正式版對 PostgreSQL 的協議實現、SQL 支持度、權限控制等方面進行了大量的完善,為后續全面對接 PostgreSQL 生態打下基礎。ShardingSphere-Proxy 與 PostgreSQL 的生態對接,讓用戶能夠在 PostgreSQL 數據庫的基礎上獲得如數據分片、讀寫分離、影子庫、數據加密/脫敏、分布式治理等透明化的增量能力。
除了 PostgreSQL 方面,由華為開源的國產數據庫 openGauss 的熱度持續攀升。openGauss 具備優秀的單機性能,配合 ShardingSphere 的能力和生態,能夠打造出覆蓋更多場景的國產分布式數據庫解決方案。
ShardingSphere PostgreSQL/openGauss Proxy 目前能夠支持數據分片、讀寫分離、影子庫、數據加密/脫敏、分布式治理等 Apache ShardingSphere 生態中大部分能力,在完善程度上逐漸對齊 ShardingSphere MySQL Proxy。
本文將給大家介紹 ShardingSphere-Proxy 5.0.0 在 PostgreSQL 上所做的提升以及與 openGauss 的生態對接。
吳偉杰
Apache ShardingSphere Committer,SphereEx 中間件工程師。目前專注于 Apache ShardingSphere 及其子項目 ElasticJob 的研發。
ShardingSphere-Proxy 是 ShardingSphere 生態中的一個接入端,定位為對客戶端透明的數據庫代理。ShardingSphere Proxy 不局限于 Java,其實現了 MySQL、PostgreSQL 數據庫協議,可以使用各種兼容 MySQL / PostgreSQL 協議的客戶端連接并操作數據。
ShardingSphere-JDBC | ShardingSphere-Proxy | |
---|---|---|
數據庫 | 任意 | 基于 MySQL / PostgreSQL 協議的數據庫 |
連接消耗數 | 高 | 低 |
異構語言 | 支持 Java 等基于 JVM 語言 | 任意 |
性能 | 損耗低 | 損耗略高 |
無中心化 | 是 | 否 |
靜態入口 | 無 | 有 |
在做了分庫分表或其他規則的情況下,數據會分散到多個數據庫實例上,在管理上難免會有一些不便;或者使用非 Java 語言的開發者,需要 ShardingSphere 所提供的能力…… 以上這些情況,正是 ShardingSphere-Proxy 力所能及之處。
ShardingSphere-Proxy 隱藏了后端實際數據庫,對于客戶端來說就是在使用一個數據庫,不需要關心 ShardingSphere 如何協調背后的數據庫,對于使用非 Java 語言的開發者或 DBA 更友好。
在協議方面,ShardingSphere PostgreSQL Proxy 實現了 Simple Query 與大部分 Extended Query 協議,支持異構語言通過 PostgreSQL/openGauss 驅動連接 Proxy。ShardingSphere openGauss Proxy 在復用 PostgreSQL 協議的基礎上,還支持 openGauss 特有的批量插入協議。
不過,由于 ShardingSphere-Proxy 相比 ShardingSphere-JDBC 增加了一層網絡交互,SQL 執行的延時會有所增加,損耗相比 ShardingSphere-JDBC 略高。
兼容 PostgreSQL Simple Query 與 Extended Query
Simple Query 與 Extended Query 是大多數用戶在使用 PostgreSQL 時最常用的協議。
比如,使用如下命令行工具 psql
連接 PostgreSQL 數據庫進行 CRUD 操作時,主要使用 Simple Query 協議與數據庫交互。
$ psql -h 127.0.0.1 -U postgres
psql (14.0 (Debian 14.0-1.pgdg110+1))
Type “help” for help.
postgres=# select id, name from person where age < 35;
id | name
—-+——
1 | Foo
(1 row)
網友評論