Re: Patch: Implement failover on libpq connect level.

From: Mithun Cy <mithun(dot)cy(at)enterprisedb(dot)com>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>, Peter van Hardenberg <pvh(at)pvh(dot)ca>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Patch: Implement failover on libpq connect level.
Date: 2016-11-16 04:31:54
Message-ID: CAD__OujrhLNB6QtWLxZtvJt5n=gT+waWtRMLSLk=7J+fiOAFqg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-jdbc

>
> > So I am tempted to just
> > hold my nose and hard-code the SQL as JDBC is presumably already
> doing.

JDBC is sending "show transaction_read_only" to find whether it is master
or not.
Victor's patch also started with it, but later it was transformed into
pg_is_in_recovery
by him as it appeared more appropriate to identify the master / slave.

ConnectionFactoryImpl.java:685

+ private boolean isMaster(QueryExecutor queryExecutor, Logger logger)
+ throws SQLException, IOException {
+ byte[][] results = SetupQueryRunner.run(queryExecutor, "show
transaction_read_only", true);
+ String value = queryExecutor.getEncoding().decode(results[0]);
+ return value.equalsIgnoreCase("off");
}

--
Thanks and Regards
Mithun C Y
EnterpriseDB: http://www.enterprisedb.com

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Craig Ringer 2016-11-16 04:44:07 Re: [PATCH] Logical decoding timeline following take II
Previous Message Ashutosh Bapat 2016-11-16 04:10:10 Re: Push down more UPDATEs/DELETEs in postgres_fdw

Browse pgsql-jdbc by date

  From Date Subject
Next Message Tatsuo Ishii 2016-11-16 05:03:44 Re: Patch: Implement failover on libpq connect level.
Previous Message Robert Haas 2016-11-15 18:28:47 Re: Patch: Implement failover on libpq connect level.