背景介绍
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)