5

I have a PostgreSQL replication M-S with pgpool as a load balancer on master server only. The replication is going OK and there is no delay on the process. The problem is that the master server is receiving more request than the slave even when I have configured a balance different from 50% for each server.

This is the pgpool show_pool_nodes with backend weigth M(1)-S(2)

node_id |  hostname   | port | status | lb_weight |  role   | select_cnt | load_balance_node | replication_delay
---------+-------------+------+--------+-----------+---------+------------+-------------------+-------------------
 0       | master-ip   | 9999 | up     | 0.333333  | primary | 56348331   | false             | 0
 1       | slave-ip    | 9999 | up     | 0.666667  | standby | 3691734    | true              | 0

as you can appreciate the master server is receiving +10x request than slave

This is the pgpool show_pool_nodes with backend weigth M(1)-S(5)

 node_id |  hostname   | port | status | lb_weight |  role   | select_cnt | load_balance_node | replication_delay
---------+-------------+------+--------+-----------+---------+------------+-------------------+-------------------
 0       | master-ip   | 9999 | up     | 0.166667  | primary | 10542201   | false             | 0
 1       | slave-ip    | 9999 | up     | 0.833333  | standby | 849494     | true              | 0

The behave is quite similar when I assign M(1)-S(1)

Now I wonder if I miss understood the pgpool functioning:

  1. Pgpool only balances read queries(as write queries are sent to master always)

  2. Backend Weight parameter is assigned to calculate distribution only in balancing mode. As greater the value is more likely to be chosen for pgpool, so if a server has a greater lb_weight it would be selected more times than others with lower values.

If I'm right why is happening this? Is there a way that I can actually assign a proper balancing configuration of select_cnt queries? My intention is to overcharge the slave with read queries and let to master only a "few" read queries as it is taking all the writing.

Juan I. Morales Pestana
  • 1,057
  • 1
  • 10
  • 34

2 Answers2

0

You are right on pgpool load balancing. There could be some reasons why this doesn't seem to work. For start, notice that you have the same port number for both backends. Try configuring your backend connection settings like shown in the sample pgpool.conf: https://github.com/pgpool/pgpool2/blob/master/src/sample/pgpool.conf.sample (lines 66-87), (where you also set the weights to your needs) and assign different port numbers to each backend.

Also check (assuming your running mode is master/slave):

  • load_balance_mode = on
  • master_slave_mode = on

-- changes require restart

There is a relevant FAQ entry " It seems my pgpool-II does not do load balancing. Why?" here: https://www.pgpool.net/mediawiki/index.php/FAQ (if pgpool version 4.1 also consider statement_level_load_balance). So far, i have assumed that the general conditions for load balancing (https://www.pgpool.net/docs/latest/en/html/runtime-config-load-balancing.html) are met.

adatzer
  • 556
  • 1
  • 4
  • 6
0

You can try to adjust below one configs in pgpool.conf file: 1. wal lag delay size delay_threshold = 10000000

it is used to let pgpool know if the slave postgresql wal is too delay to use. Change large more query can be pass to slave. Change small more query will go to master.

Besides, the pgbench testing parameter is also key. Use -C parameter, it will let connection per query, otherwise connection per session.

pgpoll load balance decision making depends of a matrix of parameter combination. not only a single parameter

Here is reference. https://www.pgpool.net/docs/latest/en/html/runtime-config-load-balancing.html#GUC-LOAD-BALANCE-MODE

Yong Wang
  • 1,200
  • 10
  • 15