jackc / jackc/pgx

Support libpq compatible load_balance_hosts parameter

Open
#2,059 7 comments 3 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
14.3k
Forks
1.1k
Avg merge
6d 9h
Merged PRs (30d)
11

Description

Hello @jackc,

I understand that we can use multiple hosts as described in the question #1184. This is supported by client applications relying on `plbpq` since PostgreSQL 10.

Do `pgx` suport/has a similar option as `libpq` to perform random load balance at client level added to PostgreSQL 16?

The new feature was added to be complaint with the existing JDBC implementation, introducing a new parameter to the connection string called `load_balance_hosts`, and new `env` variable `PGLOADBALANCEHOST`.

The option `load_balance_hosts` has two options, `Disable` where `libpq` will attempt to establish a connection using the host list provided(in order), with no load balancing, and `Random` providing attempt to connect to a randomly selected host from the list.

Do we have an option like that available currently in the project?

Thank you very much.

See:
- [PostgreSQL 16 brings Load Balancing support in libpq](https://www.mydbops.com/blog/postgresql-16-brings-load-balancing-support-in-libpq-psql)
- [Commit message from the PostgreSQL user list](https://www.postgresql.org/message-id/flat/PR3PR83MB04768E2FF04818EEB2179949F7A69@PR3PR83MB0476.EURPRD83.prod.outlook.com)

Contributor guide

Open the contributing guide

Research direction

The issue names no files or tests; start by locating pgx's existing multi-host connection handling and connection-string and environment-option parsing. Compare that behavior with PostgreSQL 16's libpq load_balance_hosts options. Done means pgx has a documented compatible option that selects hosts in order or randomly as requested, with coverage for both modes.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, postgresql
Domain
backend, databases
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.