Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1XkMeJ-0001Dy-3K for pgsql-jdbc@arkaria.postgresql.org; Sat, 01 Nov 2014 00:34:35 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1XkMeI-0003kO-Aw for pgsql-jdbc@arkaria.postgresql.org; Sat, 01 Nov 2014 00:34:34 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1XkMeH-0003kI-MR for pgsql-jdbc@postgresql.org; Sat, 01 Nov 2014 00:34:33 +0000 Received: from mail-am1on0682.outbound.protection.outlook.com ([2a01:111:f400:fe00::682] helo=emea01-am1-obe.outbound.protection.outlook.com) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1XkMeD-0000CO-C0 for pgsql-jdbc@postgresql.org; Sat, 01 Nov 2014 00:34:32 +0000 Received: from AM2PR07MB0659.eurprd07.prod.outlook.com (25.160.55.150) by AM2PR07MB0753.eurprd07.prod.outlook.com (25.160.57.25) with Microsoft SMTP Server (TLS) id 15.1.11.14; Sat, 1 Nov 2014 00:34:21 +0000 Received: from AM2PR07MB0659.eurprd07.prod.outlook.com (25.160.55.150) by AM2PR07MB0659.eurprd07.prod.outlook.com (25.160.55.150) with Microsoft SMTP Server (TLS) id 15.1.11.14; Sat, 1 Nov 2014 00:34:20 +0000 Received: from AM2PR07MB0659.eurprd07.prod.outlook.com ([25.160.55.150]) by AM2PR07MB0659.eurprd07.prod.outlook.com ([25.160.55.150]) with mapi id 15.01.0011.000; Sat, 1 Nov 2014 00:34:20 +0000 From: Mikko Tiihonen To: "pgsql-jdbc@postgresql.org" Subject: Pull request for better handling of master/slave and load balancing when connecting to multiple hosts Thread-Topic: Pull request for better handling of master/slave and load balancing when connecting to multiple hosts Thread-Index: AQHP9Wo0JOMYvOWYkECK2NTbV/VLgA== Date: Sat, 1 Nov 2014 00:34:19 +0000 Message-ID: <1414802059544.34620@nitorcreations.com> Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [93.106.85.162] x-microsoft-antispam: BCL:0;PCL:0;RULEID:;SRVR:AM2PR07MB0659;UriScan:; x-exchange-antispam-report-test: UriScan:; x-forefront-prvs: 03827AF76E x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(189002)(199003)(122556002)(16236675004)(66066001)(46102003)(20776003)(15975445006)(110136001)(99396003)(551934003)(86362001)(92566001)(92726001)(19580395003)(19580405001)(2656002)(19627405001)(87936001)(40100003)(117636001)(101416001)(77156002)(450100001)(77096003)(120916001)(19617315012)(64706001)(31966008)(50986999)(36756003)(2351001)(106116001)(54356999)(106356001)(95666004)(97736003)(105586002)(21056001)(229853001)(107886001)(107046002)(4396001)(62966003); DIR:OUT; SFP:1101; SCL:1; SRVR:AM2PR07MB0659; H:AM2PR07MB0659.eurprd07.prod.outlook.com; FPR:; MLV:sfv; PTR:InfoNoRecords; MX:1; A:1; LANG:en; Content-Type: multipart/alternative; boundary="_000_141480205954434620nitorcreationscom_" MIME-Version: 1.0 X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:;SRVR:AM2PR07MB0753; X-OriginatorOrg: nitorcreations.com X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-jdbc Precedence: bulk Sender: pgsql-jdbc-owner@postgresql.org --_000_141480205954434620nitorcreationscom_ Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable https://github.com/pgjdbc/pgjdbc/pull/209 It is a rewrite of the original request from 2011 by chenhj@cn.fujitsu.com. If multiple hosts are specified in the jdbc connection url then: * Adds optional querying of node writability and possibility to restric= t connections to writable or read-only nodes. * Adds optional load balancing of connections. * Uses a JVM global cache of known node states. By default the functionality stays the same compared to previous versions. To run the unit tests one needs to configure a replication slave and config= ure slaveServer and slavePort properties in addition to the normal server a= nd port. I have a few questions about how to best detect the master/slave node: 1. Is the method show transaction_read_only =3D off still the best way o= n more modern postgresql to detect if we are connection to the master or sl= ave? 2. Are there some other settings/functions that should be invoked to get= better information about nodes to choose. Like how far behind the replica = is from the master. We might not want to use slaves if they are too much be= hind. -Mikko --_000_141480205954434620nitorcreationscom_ Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable

ht= tps://github.com/pgjdbc/pgjdbc/pull/209

It is a rewrite of the original request from 2011 by chenhj@cn.fujitsu.c= om.


If multiple hosts are specified in the jdbc connection url then:

  • Adds optional querying of node writability and possibility to restrict = connections to writable or read-only nodes.
  • Adds optional load bala= ncing of connections.
  • Uses a JVM global cache of known node states.=

By default the functionality stays the same compared to previous version= s.


To run the unit tests one needs to configure a replication slave and con= figure slaveServer and slavePort properties in addition to the normal serve= r and port.


I have a few questions about how to best detect the master/slave node:

  1. Is the method show transaction_read_only =3D off still the bes= t way on more modern postgresql to detect if we are connection to the maste= r or slave?
  2. Are there some other settings/functions that should be = invoked to get better information about nodes to choose. Like how far behin= d the replica is from the master. We might not want to use slaves if they a= re too much behind.

-Mikko

--_000_141480205954434620nitorcreationscom_--