Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qBckU-0003Vy-FX for pgsql-general@arkaria.postgresql.org; Tue, 20 Jun 2023 14:54:26 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1qBckT-0004Tg-7n for pgsql-general@arkaria.postgresql.org; Tue, 20 Jun 2023 14:54:25 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qBckS-0004TX-TI for pgsql-general@lists.postgresql.org; Tue, 20 Jun 2023 14:54:24 +0000 Received: from mail.hjp.at ([212.17.106.138] helo=rorschach.hjp.at) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qBckL-003dy3-Eu for pgsql-general@lists.postgresql.org; Tue, 20 Jun 2023 14:54:24 +0000 Received: by rorschach.hjp.at (Postfix, from userid 1000) id 0163E6953F; Tue, 20 Jun 2023 16:54:14 +0200 (CEST) Date: Tue, 20 Jun 2023 16:54:14 +0200 From: "Peter J. Holzer" To: pgsql-general@lists.postgresql.org Subject: Re: Question: Multiple pg clusters on one server can be reached with the standard port. Message-ID: <20230620145414.qjkdzctlja3z53u4@hjp.at> Mail-Followup-To: pgsql-general@lists.postgresql.org References: <0c2dd853-08ec-dbed-00c3-a680ae711d89@proventis.net> <71943c04e05c3c13d5cd2b287909f351@weiller.eu> <20230619103335.xyagd43uhneducxz@hjp.at> <0f467ff1-8cdb-2460-75d6-0e0e4497890f@gmail.com> <20230619171536.2kcrdor36rqchicq@hjp.at> <47751285-8c76-c31f-97a4-5c6e2e7db72e@gmail.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="ruztbblsp5utqiad" Content-Disposition: inline In-Reply-To: <47751285-8c76-c31f-97a4-5c6e2e7db72e@gmail.com> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --ruztbblsp5utqiad Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 2023-06-19 16:09:34 -0500, Ron wrote: > On 6/19/23 12:15, Peter J. Holzer wrote: > On 2023-06-19 07:49:49 -0500, Ron wrote: > On 6/19/23 05:33, Peter J. Holzer wrote: > So (again, as Francisco already wrote) the best way is probab= ly to write > a simple proxy which uses the database (not DNS) name for rou= ting. I > seem to remember that nginx has a plugin architecture for pro= tocols so > it might make sense to write that as an nginx plugin instead = of a > standalone server, but that's really a judgement call the pro= grammer has > to make. Another possibility would of course be to extend pgb= ouncer to > do what the OP needs. >=20 > How would this work with JDBC clients? >=20 > Same as with any other client, I guess. Any reason why it should be > different? >=20 >=20 > That goes to my ultimate point: why would this work, when the point of a > database client is to connect to a database instance on a specific port l= ike > 5432, not connect to a web server. Consider this scenario: You have several databases scattered across several hosts and ports: db1 host1.example.com:5432 db2 host1.example.com:5433 db3 host2.example.com:5432 db4 host3.example.com:5432 Then you have your proxy/gateway/bouncer (whatever you want to call it) listening on proxy.example.com:5432. The clients all connect to proxy.example.com:5432. The proxy does the TLS handshake (if necessary) and reads the first packet. This contains the database name. The proxy then uses the database name to look up where that database resides (e.g. for db3 it gets host2.example.com:5432) opens a connection to that port (plus TLS handshake, if necessary) and forwards the packet. After that it just has to forward packets in both directions until the connection is closed. The client never knows that the databases are actually on different hosts and/or ports. As far as it is concerned, all the databases are on proxy.example.com:5432. There is one caveat: All the database names need to be unique. Such a proxy should be straightforward to write. It only needs to understand two requests of postgresql protocol (initiate TLS and connect). It would be much simpler than e.g. pg_bouncer which has to know about authentication, transactions, etc.[1]. Depending on the expected number of parallel connections and throughput you might want to consider what programming language and concurrency model (multi-threaded, async, state machine, ...) to use. hp [1] But of course, if pgbouncer already does what you want, don't reinvent the wheel. --=20 _ | Peter J. Holzer | Story must make more sense than reality. |_|_) | | | | | hjp@hjp.at | -- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!" --ruztbblsp5utqiad Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEETtJbRjyPwVTYGJ5k8g5IURL+KF0FAmSRvZAACgkQ8g5IURL+ KF2WlA/9GwIuIpoPbX4uXikUbTowkkD0eX/BKKN4SlwU7rylLOpdAQLDyBXfYYKA nXLz5eiIkkap/Qr7Di24xNV3jy+N7/t+a0Xo74vrJ1a5piNLLWsOOdOKxpE1qNFL fh72i6Tdz+2UQTCwvJBxhk7xK3F9/DWwsh05Pm89xwh7jWOpgY69GoznHp4QNmCU NcIQo26uLyh3uA0mbMSZSmjYCkVkQiLkVS+HYlD6AC4m4y4nkJAJOW3mCQu2wTQU PgkaLXDj+9RAGL8HMFJpzSxjvVt17dGlmHl2r8QwcfvOW0YnQ4xuOBlDoqBBbDoZ qEbxpQ7egzHMiw7St54yehiWCFRQozXn/HfvKjwsxM6cNDktvuVzd7Kb8rRnS3Bu 8cieRQTulbySJ7VnBr99EAvyN/Ad7062BcTwoLbjhvvQSHXu73TKktbBjOdKgyam CbLcZILny1h8gNyhFoz9vRWJmGMRwo4/h/BHC2up2bQ29PQwk7yKBx4IckOLYJnN Cci5Fjc32U1aIe/puk/NVAX/ylp6UPnKupF+vZz9ZrMZG1VVpj5jM+qEYf3ZIMPi 2FMptQ7Xx13gXiecSWt0o348h8pCp9/yv+QUog49wdBTV4v8ksibjpInG71p0A1v DrRxIke/9pSMZ6wB6n8sR8bV954YZvSFx/JoTK7KqsBdYCicq0M= =7Uoj -----END PGP SIGNATURE----- --ruztbblsp5utqiad--