How to split reads/writes with ProxySQL


Reads and writes goes primary node by default, right? Within our organization we have one team which has their own, custom built setup and all database nodes respond to read queries.

How we should configure ProxySQL so that it would use all database nodes (pxc-0, 1, 2) for reads? Can this be done also with writes without split brain or any negative effect?

1 Like

Hi Katajistok,

You can route traffic to different nodes by using query rules , hostgroups and default hostgroups for users as explained on the following links:
PXC proxysql example setup: ProxySQL Native Support for Percona XtraDB Cluster (PXC) - Percona Database Performance Blog
query rules: ProxySQL Query Rules: Notes From Production | Official Pythian®® Blog
setting default hostgroup example: change MYSQL USER default_hostgroup not effect immediately · Issue #1265 · sysown/proxysql · GitHub



What is the proper way to make changes to ProxySQL configuration? I know that configuration can be initially set on cr.yaml and creating a new configmap also works, but how about changing runtime configuration? I found out that from ProxySQL Pod and proxysql container I can change the runtime configuration with proxysql-admin cli.
Is there some examples of how to change hostgroups and node weights in example?
I was able to change weights for nodes, but still only one MySQL node was taking all the reads. I didn’t make any changes on rules.

1 Like

We use proxysql-admin in the operator to configure proxysql.
So whatever changes you make in the hostgroups - they will be overwritten by proxysql-admin and the operator.

We have this issue right now that is exactly about using only one server for reads: [K8SPXC-735] ProxySQL uses only one server for reads - Percona JIRA

We are working on its resolution, but it requires some work.
As a workaround some of our users tend to use haproxy with Operator and setup proxySQL as a standalone server.


Thank you. This explains it. So we will try with HAProxy and read-only-replicas and configure application so that it’s able to use two endpoints for database queries.

1 Like