【LightDB】pgbouncer解决postgres不兼容问题

LightDB在22.4版本中为了解决在Oracle或MySQL模式下导致的Postgres第三方应用不兼容问题,集成了pgbouncer。通过配置生成工具生成配置文件,并启动pgbouncer,用户可以实现更顺畅的数据库连接和应用迁移。连接pgbouncer后,应用可以使用新的端口进行通信。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

背景介绍

LightDB支持oracle兼容模式和mysql兼容模式,方便用户迁移应用到LightDB。这会导致问题: 在oracle模式或mysql模式下,postgres的一些第三方应用将无法正常工作。为了解决这个问题,LightDB在22.4版本集成了pgbouncer。下面举个不兼容的例子:

lightdb@test_oracle=# \c test_off;
You are now connected to database "test_off" as user "lightdb".
lightdb@test_off=# select substr('12345',-2,2);
 substr 
--------
 
(1 row)

lightdb@test_off=# \c test_oracle;
You are now connected to database "test_oracle" as user "lightdb".
lightdb@test_oracle=# select substr('12345',-2,2);
 substr 
--------
 45
(1 row)

使用方法

生成配置

LightDB提供了一个配置生成工具,通过这个工具可以生成配置。

[lightdb@localhost pgbouncer]$ $LTHOME/etc/pgbouncer/generate_pgbouncer_conf.sh lightdb 5432 7000
auth_user lightdb, lightdb_port 5432, pgbouhcer_port 7000
/home/lightdb/stage/lightdb-x/etc/pgbouncer/pgbouncer.ini generated

示例中lightdb是用于密码验证的用户名,5432是数据库端口号, 7000 是pgbouncer的端口号。

启动pgbouncer

pgbouncer启动命令示例如下:

[lightdb@localhost pgbouncer]$ pgbouncer  -d $LTHOME/etc/pgbouncer/pgbouncer.ini
[lightdb@localhost pgbouncer]$ ps -ef|grep pgbouncer 
lightdb    10594       1  0 15:04 ?        00:00:00 pgbouncer -d /home/lightdb/stage/lightdb-x/etc/pgbouncer/pgbouncer.ini
lightdb    10609    2486  0 15:04 pts/1    00:00:00 grep --color=auto pgbouncer

连接验证

除了连接端口外,连接pgbouncer和连接pgbouncer没啥区别,下面是连接示例:

[lightdb@localhost pgbouncer]$ ltsql -h 127.0.0.1 -p 7000  -U test
Password for user test: 
ltsql (13.8-22.4)
Type "help" for help.

test@postgres=> show search_path;
        search_path        
---------------------------
 "$user",public,lt_catalog
(1 row)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值