Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Supporting multiple databases with libpq #2798

Open
steve-chavez opened this issue May 23, 2023 · 4 comments
Open

Supporting multiple databases with libpq #2798

steve-chavez opened this issue May 23, 2023 · 4 comments
Labels
idea Needs of discussion to become an enhancement, not ready for implementation

Comments

@steve-chavez
Copy link
Member

Problem

libpq offers a native way to use multiple hosts, yet we don't support it. See:

https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-MULTIPLE-HOSTS

PostgreSQL libpq 16 will even support load balancing natively on these hosts: https://mydbops.wordpress.com/2023/05/07/postgresql-16-brings-load-balancing-support-in-libpq-psql/

Solution

AFAICT, we already support using the PGHOST env var. But we don't support multiple values, we would need to create multiple instances of our connection pool.


We could consider using the HTTP Host header to let the user choose a database.

@steve-chavez steve-chavez added the idea Needs of discussion to become an enhancement, not ready for implementation label May 23, 2023
@mkleczek
Copy link
Contributor

What I have prototyped is something similar: Let hasql-pool implement a kind of a multi-pool where you can create multiple connection pools where all would share a single global pool size limit but also each one would have its own "local" pool size limit. Example:

global size: 30
pool1: maximum size: 25
pool2: maximum size: 25

Additionally Postgrest would keep two sets of pools:

  1. A single read/write connection pool
  2. A set of read-only connection pools

The whole thing is designed to spread read queries among read-only replicas of a single master.

The set-up is designed to support https://cloudnative-pg.io where separate k8s services are provided for master and replicas.

@wolfgangwalther
Copy link
Member

Everything that connects to multiple databases, will need multiple sets of connection credentials etc. - so a hugely different interface for configuration.

I think the best way forward would be to improve the separation between what is part of the postgrest library and what is part of the current single-database executable.

We can then re-use the library for other executables:

  • something that maps Host to multiple databases
  • or a read/write connection pooler

@steve-chavez
Copy link
Member Author

steve-chavez commented Jul 5, 2023

If we had this I think then an Ubuntu/Debian package would make more sense since it could have a single systemd service. Right now we need systemd services for each db.

@steve-chavez
Copy link
Member Author

Related discussion on #3101 (comment) for using a psql compatible ini file for multiple databases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
idea Needs of discussion to become an enhancement, not ready for implementation
Development

No branches or pull requests

3 participants