gpt4 book ai didi

postgresql - 无法将 PPGool 与 Amazon RDS Postgres 一起使用

转载 作者:行者123 更新时间:2023-11-29 11:49:38 26 4
gpt4 key购买 nike

我有一个带多可用区的 Postgres 9.4 RDS 实例,还有一个从属、只读副本。

到目前为止,负载平衡是在我的应用程序的业务层中进行的,但效率低下,我希望使用 PPGool,因此该应用程序与单个 Postgres 连接进行交互。

事实证明,使用 PPGool 一直是一件令人头疼的事情。如果我将它设置为充当负载平衡器,简单的 SELECT 查询会抛出如下错误:

 SQLSTATE[HY000]: General error: 7 
message contents do not agree with length in message type "N"
server sent data ("D" message)
without prior row description ("T" message)

如果我将它设置为在具有流复制的主/从模式下运行(如 suggested in Postgres mail list ),我得到:

psql: ERROR:  MD5 authentication is unsupported 
in replication and master-slave modes.
HINT: check pg_hba.conf

是的,pg_hba.conf 如果不在 RDS 中,那么我无法更改它。

有没有人让 PPGool 在 RDS 中工作?是否有其他工具可以充当中间件来利用 RDS 中的读取副本?

最佳答案

我能够让它工作,这里是我的工作配置文件:

您必须使用 md5 身份验证,并将用户名/密码从您的数据库同步到 pool_passwd 文件。还需要开启 enable_pool_hba、load_balance_mode 和 master_slave_mode。

pgpool.conf

listen_addresses = '*'
port = 9999
pcp_listen_addresses = '*'
pcp_port = 9898
pcp_socket_dir = '/tmp'
listen_backlog_multiplier = 1
backend_hostname0 = 'master-rds-database-with-multi-AZ.us-west-2.rds.amazonaws.com'
backend_port0 = 5432
backend_weight0 = 0
backend_flag0 = 'ALWAYS_MASTER'
backend_hostname1 = 'readonly-replica.us-west-2.rds.amazonaws.com'
backend_port1 = 5432
backend_weight1 = 999
backend_flag1 = 'ALWAYS_MASTER'
enable_pool_hba = on
pool_passwd = 'pool_passwd'
ssl = on
num_init_children = 1
max_pool = 2
connection_cache = off
replication_mode = off
load_balance_mode = on
master_slave_mode = on

pool_hba.conf

local   all         all                               md5
host all all 127.0.0.1/32 md5

池密码

username:md5d51c9a7e9353746a6020f9602d452929

要更新 pool_password,您可以使用 pg_md5

echo username:md5`echo -n usernamepassword | md5sum`
username:md5d51c9a7e9353746a6020f9602d452929 -

运行示例的输出:

psql --dbname=database --host=localhost --username=username --port=9999

database=> SHOW POOL_NODES;

node_id | hostname | port | status | lb_weight | role | select_cnt | load_balance_node | replication_delay
---------+-------------------------------------------------+------+--------+-----------+---------+------------+-------------------+-------------------
0 | master-rds-database.us-west-2.rds.amazonaws.com | 8193 | up | 0.000000 | primary | 0 | false | 0
1 | readonly-replica.us-west-2.rds.amazonaws.com | 8193 | up | 1.000000 | standby | 0 | true | 0

database=> select now();

node_id | hostname | port | status | lb_weight | role | select_cnt | load_balance_node | replication_delay
---------+-------------------------------------------------+------+--------+-----------+---------+------------+-------------------+-------------------
0 | master-rds-database.us-west-2.rds.amazonaws.com | 8193 | up | 0.000000 | primary | 0 | false | 0
1 | readonly-replica.us-west-2.rds.amazonaws.com | 8193 | up | 1.000000 | standby | 1 | true | 1

database=> CREATE TABLE IF NOT EXISTS tmp_test_read_write ( data varchar(40) );
CREATE TABLE
database=> INSERT INTO tmp_test_read_write (data) VALUES (concat('',inet_server_addr()));
INSERT 0 1
database=> select data as master_ip,inet_server_addr() as replica_ip from tmp_test_read_write;
master_ip | replica_ip
--------------+---------------
172.31.37.69 | 172.31.20.121
(1 row)

从日志id也可以看出两个数据库:

2018-10-16 07:56:37: pid 124528: LOG:  DB node id: 0 backend pid: 21731 statement: CREATE TABLE IF NOT EXISTS tmp_test_read_write ( data varchar(40) );
2018-10-16 07:56:47: pid 124528: LOG: DB node id: 0 backend pid: 21731 statement: INSERT INTO tmp_test_read_write (data) VALUES (concat('',inet_server_addr()));
2018-10-16 07:56:52: pid 124528: LOG: DB node id: 1 backend pid: 24890 statement: select data as master_ip,inet_server_addr() as replica_ip from tmp_test_read_write;

注意insert使用的是master的ip_address,下一个select使用的是read only replica的ip_address。

我可以在更多测试后更新,但 psql 客户端测试看起来很有希望。

关于postgresql - 无法将 PPGool 与 Amazon RDS Postgres 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40424206/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com