flora-pm / flora-server

A package index for the Haskell ecosystem
https://flora.pm/about
Other
125 stars 38 forks source link

`make db-provision` fails due to postgres complaining about "too many clients" #371

Closed kenranunderscore closed 1 year ago

kenranunderscore commented 1 year ago

Environment

Also, I'm using the database docker postgres image (tried a couple of versions) as database. If I can find the time, I'll see if I can test this with a postgres systemd service instead as well.

Expected Behaviour

I can run make db-provision without errors.

Actual Behaviour

It never seems to finish in the test-packages step, and there are the following errors in the docker compose logs database:

database  | 2023-04-07 13:51:07.581 UTC [1] LOG:  database system is ready to accept connections
database  | 2023-04-07 13:57:11.025 UTC [199] FATAL:  sorry, too many clients already
database  | 2023-04-07 13:57:11.038 UTC [200] FATAL:  sorry, too many clients already
database  | 2023-04-07 13:57:11.051 UTC [208] FATAL:  sorry, too many clients already
database  | 2023-04-07 13:57:11.051 UTC [209] FATAL:  sorry, too many clients already
database  | 2023-04-07 13:57:11.051 UTC [210] FATAL:  sorry, too many clients already
database  | 2023-04-07 13:57:11.051 UTC [205] FATAL:  sorry, too many clients already
database  | 2023-04-07 13:57:11.055 UTC [213] FATAL:  sorry, too many clients already
database  | 2023-04-07 13:57:11.056 UTC [211] FATAL:  sorry, too many clients already
database  | 2023-04-07 13:57:11.056 UTC [214] FATAL:  sorry, too many clients already
database  | 2023-04-07 13:57:11.056 UTC [212] FATAL:  sorry, too many clients already
database  | 2023-04-07 13:57:11.063 UTC [215] FATAL:  sorry, too many clients already
database  | 2023-04-07 13:57:11.064 UTC [216] FATAL:  sorry, too many clients already
database  | 2023-04-07 13:57:11.064 UTC [217] FATAL:  sorry, too many clients already
database  | 2023-04-07 13:57:11.065 UTC [218] FATAL:  sorry, too many clients already
database  | 2023-04-07 13:57:11.071 UTC [223] FATAL:  sorry, too many clients already
database  | 2023-04-07 13:57:11.072 UTC [225] FATAL:  sorry, too many clients already
database  | 2023-04-07 13:57:11.073 UTC [224] FATAL:  sorry, too many clients already

Instructions for reproduction

I can reproduce this in two setups. Please let me know if I'm doing something wrong here. I thought it should not be a problem using the docker image as database. This is the last thing preventing me from trying my hands on some Haskell :) What I'd love is to have some test data in the database in order to try out stuff.

Local setup with docker database

  1. docker compose up -d database
  2. source environment.sh
  3. make db-reset

Sometimes the make db-provision that is called also fails, sometimes it's stuck as written above.

Docker-only (using #370)

  1. make docker-build
  2. make docker-enter
  3. source environment.docker.sh
  4. make db-reset
tchoutri commented 1 year ago

@kenranunderscore How many connections do you have configured in your postgres? This is the max_connections parameter that you can see with SHOW max_connections; in a psql shell.

kenranunderscore commented 1 year ago

100 with Docker.

I could just now reproduce the problem when using the postgresql_14 nixos systemd service as well, where max_connections is also set to 100.

tchoutri commented 1 year ago

hmm, could you tweak either the parameter for postgres or $FLORA_DB_POOL_CONNECTIONS? If you set the latter to something like 90, does it still fail?

kenranunderscore commented 1 year ago

Ah, sorry that I didn't realize I could set this myself. I "bisected" the value and it seems like the magic number is 96 :grin: everything higher than that provokes the error.

So since I can work around this myself, I can of course close the issue. But since 100 seems to be the default postgres value, it might be wise to have a slightly lower default value of FLORA_DB_POOL_CONNECTIONS?

tchoutri commented 1 year ago

Yep, I'll integrate that change in the PR I'm working on right now. Thank you for the ticket. :)