Thread: jdbc targetServerType=slave with readonly connection

jdbc targetServerType=slave with readonly connection

From
Vladimír Houba ml.
Date:
Hello,

the slave replication server does not seem to be recognized correctly when using read-only jdbc connection and targetServerType=preferSlave.

Sample conn str
<entry key="jdbc.url.readonly">jdbc:postgresql://master,slave/up?user=***&password=***&sslmode=require&ApplicationName=***&targetServerType=preferSlave&loadBalanceHosts=true&readOnly=true</entry>

From the docs I understands that since writes are not allowed in RO transactions, the jdbc driver thinks it is connected to a slave. I think the master/slave check should be corrected, or configurable.

Docs:
The master/slave distinction is currently done by observing if the server allows writes

Thank you
Vladimir

Re: jdbc targetServerType=slave with readonly connection

From
Vladimir Sitnikov
Date:
>the slave replication server does not seem to be recognized correctly

Could you elaborate on what do you mean by "does not seem to be recognized correctly"?

You might be hitting https://github.com/pgjdbc/pgjdbc/pull/844 , so would you please check if pgjdbc 42.2.0-SNAPSHOT (e.g. https://oss.sonatype.org/content/repositories/snapshots/org/postgresql/postgresql/42.2.0-SNAPSHOT/ ) resolves your issue?

>jdbc driver thinks it is connected to a slave

pjgdbc uses "show transaction_read_only" query to tell master from secondary.

"readOnly=true" connection option is used/activated _after_ the connection, so it should not impact master/secondary selection.

PS. There's 10 second-long (hostRecheckSeconds) cache of the host status. That is, pgjdbc caches master/secondary state of the host for 10 seconds by default, so it might "fail" to identify recently activated secondary. 

Vladimir

Re: jdbc targetServerType=slave with readonly connection

From
Vladimir Sitnikov
Date:
>the slave replication server does not seem to be recognized correctly

Could you elaborate on what do you mean by "does not seem to be recognized correctly"?

You might be hitting https://github.com/pgjdbc/pgjdbc/pull/844 , so would you please check if pgjdbc 42.2.0-SNAPSHOT (e.g. https://oss.sonatype.org/content/repositories/snapshots/org/postgresql/postgresql/42.2.0-SNAPSHOT/ ) resolves your issue?

>jdbc driver thinks it is connected to a slave

pjgdbc uses "show transaction_read_only" query to tell master from secondary.

"readOnly=true" connection option is used/activated _after_ the connection, so it should not impact master/secondary selection.

PS. There's 10 second-long (hostRecheckSeconds) cache of the host status. That is, pgjdbc caches master/secondary state of the host for 10 seconds by default, so it might "fail" to identify recently activated secondary. 

Vladimir