[HACKERS] Client Connection redirection support for PostgreSQL - Mailing list pgsql-hackers

From Satyanarayana Narlapuram
Subject [HACKERS] Client Connection redirection support for PostgreSQL
Date
Msg-id CY1PR21MB00246DE1F9E9C58455A78A37915C0@CY1PR21MB0024.namprd21.prod.outlook.com
Whole thread Raw
Responses Re: [HACKERS] Client Connection redirection support for PostgreSQL  (David Fetter <david@fetter.org>)
Re: [HACKERS] Client Connection redirection support for PostgreSQL  (Craig Ringer <craig@2ndquadrant.com>)
List pgsql-hackers

Proposal:

Add the ability to the PostgreSQL server instance to route the traffic to a different server instance based on the rules defined in server’s pg_bha.conf configuration file. At a high level this enables offloading the user requests to a different server instance based on the rules defined in the pg_hba.conf configuration file. Some of the interesting scenarios this enables include but not limited to - rerouting traffic based on the client hosts, users, database, etc. specified, redirecting read-only query traffic to the hot stand by replicas, and in multi-master scenarios.

The rules to route the traffic will be provided in the pg_hba.conf file. The proposal is to add a new optional field ‘RoutingList’ to the record format. The RoutingList contains comma-seperated list of one or more servers that can be routed the traffic to. In the absence of this new field there is no change to the current login code path for both the server and the client. RoutingList can be updated for each new connection to balance the load across multiple server instances

RoutingList format:

server_address1:port, server_address2:port…

The message flow

  1. Client connects to the server, and server accepts the connections
  2. Client sends the startup message
  3. Server looks at the rules configured in the pg_hba.conf file and
    1. If the rule matches redirection

                                                               i.      Send a special message with the RoutingList described above

                                                             ii.      Server disconnects

    1. If the rule doesn’t have RoutingList defined

                                                               i.      Server proceeds in the existing code path and sends auth request

  1. Client gets the list of addresses and attempts to connect to a server in the list provided until the first successful connections is established or the list is exhausted. If the client can’t connect to any server instance on the RoutingList, client reports the login failure message.

 

Backward compatibility:

There are a few ways to provide the backward compatibility, and each approach has their own advantages and disadvantage and are listed below

  1. Bumping the protocol version – old server instances may not understand the new client protocol
  2. Adding additional optional parameter routing_enabled, without bumping the protocol version. In this approach, old Postgres server instances may not understand this and fail the connections.
  3. The current proposal – to keep it in the hba.conf and let the server admin deal with the configuration by taking conscious choice on the configuration of routing list based on the clients connecting to the server instance.

Backward compatibility scenarios:

  • The feature is not usable for the existing clients, and the new servers shouldn’t set the routing list if they expect any connections from the legacy clients. We should do either (1) or (2) in the above list to achieve this. Otherwise need to rely on the admin to take care of the settings.
  • For the new client connecting to the old server, there is no change in the message flow
  • For the new clients to the new server, the message flow will be based on the routing list filed in the configuration.

This proposal is in very early stage, comments and feedback is very much appreciated.

Thanks,

Satya

 

pgsql-hackers by date:

Previous
From: Vladimir Sitnikov
Date:
Subject: Re: [HACKERS] Statement-level rollback
Next
From: Craig Ringer
Date:
Subject: Re: [HACKERS] Statement-level rollback