pg.ddx.io pgsql-jdbc@postgresql.org mailing list archive
help / color / mirror / Atom feedHow to send queries to master and failover to slave ?
8+ messages / 5 participants
[nested] [flat]
* How to send queries to master and failover to slave ?
@ 2016-06-28 09:41 Benoit Salotti <benoit.salotti@gmail.com>
0 siblings, 3 replies; 8+ messages in thread
From: Benoit Salotti @ 2016-06-28 09:41 UTC (permalink / raw)
To: pgsql-jdbc
Hi all,
I have a setup with 1 master and 1 slave (hot standy to serve read queries
if necessary).
I would like the JDBC driver to talk preferrably to the master (to be sure
to get the freshest data). If the master is not available I would like to
send the queries to the slave.
The documentation mentions the following values for the parameter
targetServerType: any, master, slave, preferSlave.
I'm surprised there is no preferMaster option which would allow me to
implement easily my requirement.
Anyone already encountered the same need ?
Regards,
Benoit
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: How to send queries to master and failover to slave ?
@ 2016-06-28 10:09 Mikko Tiihonen <mikko.tiihonen@nitor.fi>
parent: Benoit Salotti <benoit.salotti@gmail.com>
2 siblings, 1 reply; 8+ messages in thread
From: Mikko Tiihonen @ 2016-06-28 10:09 UTC (permalink / raw)
To: Benoit Salotti <benoit.salotti@gmail.com>; pgsql-jdbc
Assuming that the old slave will become new master if master ever goes down then the option "master" would do what you want. Right?
But if you do take the master down for maintenance without failing over to slave then yes. A small code change could be done to add support for preferMaster.
-Mikko
________________________________
From: pgsql-jdbc-owner@postgresql.org <pgsql-jdbc-owner@postgresql.org> on behalf of Benoit Salotti <benoit.salotti@gmail.com>
Sent: 28 June 2016 12:41
To: pgsql-jdbc@postgresql.org
Subject: [JDBC] How to send queries to master and failover to slave ?
Hi all,
I have a setup with 1 master and 1 slave (hot standy to serve read queries if necessary).
I would like the JDBC driver to talk preferrably to the master (to be sure to get the freshest data). If the master is not available I would like to send the queries to the slave.
The documentation mentions the following values for the parameter targetServerType: any, master, slave, preferSlave.
I'm surprised there is no preferMaster option which would allow me to implement easily my requirement.
Anyone already encountered the same need ?
Regards,
Benoit
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: How to send queries to master and failover to slave ?
@ 2016-06-28 10:37 John R Pierce <pierce@hogranch.com>
parent: Benoit Salotti <benoit.salotti@gmail.com>
2 siblings, 1 reply; 8+ messages in thread
From: John R Pierce @ 2016-06-28 10:37 UTC (permalink / raw)
To: pgsql-jdbc
On 6/28/2016 2:41 AM, Benoit Salotti wrote:
>
> I have a setup with 1 master and 1 slave (hot standy to serve read
> queries if necessary).
> I would like the JDBC driver to talk preferrably to the master (to be
> sure to get the freshest data). If the master is not available I would
> like to send the queries to the slave.
>
> The documentation mentions the following values for the parameter
> targetServerType: any, master, slave, preferSlave.
> I'm surprised there is no preferMaster option which would allow me to
> implement easily my requirement.
>
normally, if the master is not available, that means its failed, and
your HA cluster management will promote the slave to be the new master,
fencing off the old master until it can be manually reset and restored
as the new slave.
--
john r pierce, recycling bits in santa cruz
--
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: How to send queries to master and failover to slave ?
@ 2016-06-28 13:48 Benoit Salotti <benoit.salotti@gmail.com>
parent: Mikko Tiihonen <mikko.tiihonen@nitor.fi>
0 siblings, 0 replies; 8+ messages in thread
From: Benoit Salotti @ 2016-06-28 13:48 UTC (permalink / raw)
To: Mikko Tiihonen <mikko.tiihonen@nitor.fi>; pgsql-jdbc
Hi Mikko,
I agree, everything works as expected but as long as the failover is not
done (about 1 minute with our settings, we are using repmgr) we are unable
to serve queries... I'd like the system to serve at least the reads in the
meantime :)
If the preferMaster feature can be done "easily" at the driver level I take
it.
Benoit
2016-06-28 12:09 GMT+02:00 Mikko Tiihonen <mikko.tiihonen@nitor.fi>:
> Assuming that the old slave will become new master if master ever goes
> down then the option "master" would do what you want. Right?
>
> But if you do take the master down for maintenance without failing over to
> slave then yes. A small code change could be done to add support for
> preferMaster.
>
>
> -Mikko
>
> ------------------------------
> *From:* pgsql-jdbc-owner@postgresql.org <pgsql-jdbc-owner@postgresql.org>
> on behalf of Benoit Salotti <benoit.salotti@gmail.com>
> *Sent:* 28 June 2016 12:41
> *To:* pgsql-jdbc@postgresql.org
> *Subject:* [JDBC] How to send queries to master and failover to slave ?
>
> Hi all,
>
> I have a setup with 1 master and 1 slave (hot standy to serve read queries
> if necessary).
> I would like the JDBC driver to talk preferrably to the master (to be sure
> to get the freshest data). If the master is not available I would like to
> send the queries to the slave.
>
> The documentation mentions the following values for the parameter
> targetServerType: any, master, slave, preferSlave.
> I'm surprised there is no preferMaster option which would allow me to
> implement easily my requirement.
>
> Anyone already encountered the same need ?
>
> Regards,
>
> Benoit
>
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: How to send queries to master and failover to slave ?
@ 2016-06-28 14:01 Benoit Salotti <benoit.salotti@gmail.com>
parent: John R Pierce <pierce@hogranch.com>
0 siblings, 0 replies; 8+ messages in thread
From: Benoit Salotti @ 2016-06-28 14:01 UTC (permalink / raw)
To: John R Pierce <pierce@hogranch.com>; +Cc: pgsql-jdbc
I totally agree with you but this is not immediate. We use repmgr to handle
the failures and the DBAs have setup 6 retries with 10 seconds delay
between each retry.
So during 1 minute I'm not able to serve read queries even if my slave is
available, the preferMaster option would allow me to do it very easily.
2016-06-28 12:37 GMT+02:00 John R Pierce <pierce@hogranch.com>:
> On 6/28/2016 2:41 AM, Benoit Salotti wrote:
>
>>
>> I have a setup with 1 master and 1 slave (hot standy to serve read
>> queries if necessary).
>> I would like the JDBC driver to talk preferrably to the master (to be
>> sure to get the freshest data). If the master is not available I would like
>> to send the queries to the slave.
>>
>> The documentation mentions the following values for the parameter
>> targetServerType: any, master, slave, preferSlave.
>> I'm surprised there is no preferMaster option which would allow me to
>> implement easily my requirement.
>>
>>
>
> normally, if the master is not available, that means its failed, and your
> HA cluster management will promote the slave to be the new master, fencing
> off the old master until it can be manually reset and restored as the new
> slave.
>
>
>
> --
> john r pierce, recycling bits in santa cruz
>
>
>
^ permalink raw reply [nested|flat] 8+ messages in thread
* RE: How to send queries to master and failover to slave ?
@ 2019-02-28 12:00 Švorc Martin <svorc@sefira.cz>
parent: Benoit Salotti <benoit.salotti@gmail.com>
2 siblings, 1 reply; 8+ messages in thread
From: Švorc Martin @ 2019-02-28 12:00 UTC (permalink / raw)
To: pgsql-jdbc
Hello,
We have the very same scenario as Benoit describes – if the master instance fails, we would like the driver to communicate with the secondary instance for read-only operations before the failover process is commenced. The second use-case is when the master instance is deliberately shut down for maintenance reasons and we do not want to fail over to the secondary instance, but instead allow it to process user queries throughout the maintenance.
For this, we intend to implement "preferMaster" targetServerType in the JDBC driver paramater. Would you consider it a good idea to integrate this feature into the official JDBC driver?
Cheers
Martin
From: pgsql-jdbc-owner@postgresql.org [mailto:pgsql-jdbc-owner@postgresql.org] On Behalf Of Benoit Salotti
Sent: Tuesday, June 28, 2016 11:41 AM
To: pgsql-jdbc@postgresql.org
Subject: How to send queries to master and failover to slave ?
Hi all,
I have a setup with 1 master and 1 slave (hot standy to serve read queries if necessary).
I would like the JDBC driver to talk preferrably to the master (to be sure to get the freshest data). If the master is not available I would like to send the queries to the slave.
The documentation mentions the following values for the parameter targetServerType: any, master, slave, preferSlave.
I'm surprised there is no preferMaster option which would allow me to implement easily my requirement.
Anyone already encountered the same need ?
Regards,
Benoit
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: How to send queries to master and failover to slave ?
@ 2019-02-28 12:23 Dave Cramer <pg@fastcrypt.com>
parent: Švorc Martin <svorc@sefira.cz>
0 siblings, 1 reply; 8+ messages in thread
From: Dave Cramer @ 2019-02-28 12:23 UTC (permalink / raw)
To: Švorc Martin <svorc@sefira.cz>; +Cc: pgsql-jdbc
If you have a use case for it then I think it's a good idea
Dave Cramer
davec@postgresintl.com
www.postgresintl.com
On Thu, 28 Feb 2019 at 07:01, Švorc Martin <svorc@sefira.cz> wrote:
> Hello,
>
>
>
> We have the very same scenario as Benoit describes – if the master
> instance fails, we would like the driver to communicate with the secondary
> instance for read-only operations before the failover process is commenced.
> The second use-case is when the master instance is deliberately shut down
> for maintenance reasons and we do not want to fail over to the secondary
> instance, but instead allow it to process user queries throughout the
> maintenance.
>
>
>
> For this, we intend to implement "preferMaster" targetServerType in the
> JDBC driver paramater. Would you consider it a good idea to integrate this
> feature into the official JDBC driver?
>
>
>
> Cheers
>
>
>
> Martin
>
>
>
> *From:* pgsql-jdbc-owner@postgresql.org [mailto:
> pgsql-jdbc-owner@postgresql.org] *On Behalf Of *Benoit Salotti
> *Sent:* Tuesday, June 28, 2016 11:41 AM
> *To:* pgsql-jdbc@postgresql.org
> *Subject:* How to send queries to master and failover to slave ?
>
>
>
> Hi all,
>
>
>
> I have a setup with 1 master and 1 slave (hot standy to serve read queries
> if necessary).
>
> I would like the JDBC driver to talk preferrably to the master (to be sure
> to get the freshest data). If the master is not available I would like to
> send the queries to the slave.
>
>
>
> The documentation mentions the following values for the parameter
> targetServerType: any, master, slave, preferSlave.
>
> I'm surprised there is no preferMaster option which would allow me to
> implement easily my requirement.
>
>
>
> Anyone already encountered the same need ?
>
>
>
> Regards,
>
>
>
> Benoit
>
^ permalink raw reply [nested|flat] 8+ messages in thread
* RE: How to send queries to master and failover to slave ?
@ 2019-03-01 10:16 Švorc Martin <svorc@sefira.cz>
parent: Dave Cramer <pg@fastcrypt.com>
0 siblings, 0 replies; 8+ messages in thread
From: Švorc Martin @ 2019-03-01 10:16 UTC (permalink / raw)
To: Dave Cramer <pg@fastcrypt.com>; +Cc: pgsql-jdbc
Okay thanks, I have opened a pull request for the feature: #1430
Martin
From: Dave Cramer [mailto:pg@fastcrypt.com]
Sent: Thursday, February 28, 2019 1:24 PM
To: Švorc Martin
Cc: pgsql-jdbc@postgresql.org
Subject: Re: How to send queries to master and failover to slave ?
If you have a use case for it then I think it's a good idea
Dave Cramer
davec@postgresintl.com<mailto:davec@postgresintl.com>
www.postgresintl.com<http://www.postgresintl.com;
On Thu, 28 Feb 2019 at 07:01, Švorc Martin <svorc@sefira.cz<mailto:svorc@sefira.cz>> wrote:
Hello,
We have the very same scenario as Benoit describes – if the master instance fails, we would like the driver to communicate with the secondary instance for read-only operations before the failover process is commenced. The second use-case is when the master instance is deliberately shut down for maintenance reasons and we do not want to fail over to the secondary instance, but instead allow it to process user queries throughout the maintenance.
For this, we intend to implement "preferMaster" targetServerType in the JDBC driver paramater. Would you consider it a good idea to integrate this feature into the official JDBC driver?
Cheers
Martin
From: pgsql-jdbc-owner@postgresql.org<mailto:pgsql-jdbc-owner@postgresql.org> [mailto:pgsql-jdbc-owner@postgresql.org<mailto:pgsql-jdbc-owner@postgresql.org>] On Behalf Of Benoit Salotti
Sent: Tuesday, June 28, 2016 11:41 AM
To: pgsql-jdbc@postgresql.org<mailto:pgsql-jdbc@postgresql.org>
Subject: How to send queries to master and failover to slave ?
Hi all,
I have a setup with 1 master and 1 slave (hot standy to serve read queries if necessary).
I would like the JDBC driver to talk preferrably to the master (to be sure to get the freshest data). If the master is not available I would like to send the queries to the slave.
The documentation mentions the following values for the parameter targetServerType: any, master, slave, preferSlave.
I'm surprised there is no preferMaster option which would allow me to implement easily my requirement.
Anyone already encountered the same need ?
Regards,
Benoit
^ permalink raw reply [nested|flat] 8+ messages in thread
end of thread, other threads:[~2019-03-01 10:16 UTC | newest]
Thread overview: 8+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2016-06-28 09:41 How to send queries to master and failover to slave ? Benoit Salotti <benoit.salotti@gmail.com>
2016-06-28 10:09 ` Mikko Tiihonen <mikko.tiihonen@nitor.fi>
2016-06-28 13:48 ` Benoit Salotti <benoit.salotti@gmail.com>
2016-06-28 10:37 ` John R Pierce <pierce@hogranch.com>
2016-06-28 14:01 ` Benoit Salotti <benoit.salotti@gmail.com>
2019-02-28 12:00 ` Švorc Martin <svorc@sefira.cz>
2019-02-28 12:23 ` Dave Cramer <pg@fastcrypt.com>
2019-03-01 10:16 ` Švorc Martin <svorc@sefira.cz>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox