Monday, July 8, 2019

[google-cloud-sql-discuss] Cloud SQL Replica & LoadBalance Clarification

We have setup a Cloud SQL Postgres Regional HA. As of today we have no read replicas in the zones where HA does not have a primary / seconday failover instance. My question is if I setup Postgres read replicas, will it be exposed by the same Regional Cloud SQL HA Ip address or I have to reach out to the replica Postgres IP directly. This is not very clear from documentation. The reason I am asking is that if my Regional HA Ip address is say 10.x.y.z, I connect to this Ip assuming that when master goes down in that zone, the failover will happen and my app will continue to work as the seconday instance will take its place.  But what about read replicas. Lets say read replicas has ip addresses 10.a.b.c, does my app need to be configured with 10.x.y.z AND 10.a.b.c ( both ip addresses) . Another question is that, when Cloud SQL will under maintenance, will my Read replicas also go down with it for maintenance. https://cloud.google.com/sql/docs/postgres/replication/tips 

 I am trying to use Postgres JDBC driver for loadbalancing https://jdbc.postgresql.org/documentation/head/connect.html  

Connection Fail-over
To support simple connection fail-over it is possible to define multiple endpoints (host and port pairs) in the connection url separated by commas. The driver will try to once connect to each of them in order until the connection succeeds. If none succeed, a normal connection exception is thrown.

The syntax for the connection url is:

jdbc:postgresql://host1:port1,host2:port2/database

The simple connection fail-over is useful when running against a high availability postgres installation that has identical data on each node. For example streaming replication postgres or postgres-xc cluster.

For example an application can create two connection pools. One data source is for writes, another for reads. The write pool limits connections only to master node:

jdbc:postgresql://node1,node2,node3/accounting?targetServerType=master.

And read pool balances connections between slaves nodes, but allows connections also to master if no slaves are available:

jdbc:postgresql://node1,node2,node3/accounting?targetServerType=preferSlave&loadBalanceHosts=true

If a slave fails, all slaves in the list will be tried first. If the case that there are no available slaves the master will be tried. If all of the servers are marked as "can't connect" in the cache then an attempt will be made to connect to all of the hosts in the URL in order.


Please advice. 

--
You received this message because you are subscribed to the Google Groups "Google Cloud SQL discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-cloud-sql-discuss+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-cloud-sql-discuss/4bcd4a1d-1bb0-4598-8848-bb3cf481b562%40googlegroups.com.

No comments:

Post a Comment