1

So I built a chat app and deployed it with heroku. Since I'm on hobby-dev I can only have 20 connections to postgres, so following some suggestions online I decided using pgbouncer may be a good idea. The heroku document on setting the buildpack up (for example, last part of https://devcenter.heroku.com/articles/python-concurrency-and-database-connections#number-of-active-connections) are limited and everything I found asked me to change something in the Procfile. The problem is that I was using a docker container and thus ended up using heroku.yml and a daphne command to run the program. Directly adding bin/start-pgbouncer in web simply cause the entire application to fail.

This is my current run command

run:
  web: daphne test_project.asgi:application --port $PORT --bind 0.0.0.0 -v2

I tried

run:
  web: bin/start-pgbouncer-stunnel daphne test_project.asgi:application --port $PORT --bind 0.0.0.0 -v2

and

run:
  web: start-pgbouncer-stunnel daphne test_project.asgi:application --port $PORT --bind 0.0.0.0 -v2

Both failed. I also found out on heroku logs that heroku seems to automatically append /bin/sh -c to my run command (ex, /bin/sh -c daphne\ test_project.asgi:application\ --port\ \53166\ --bind\ 0.0.0.0\ -v2).

Could this be causing the problem? What should I put in web to run pg-bouncer alongside my app?

Lucy Gu
  • 369
  • 1
  • 3
  • 10
  • Did you find a solution to this problem, or a way to close the connections in daphne? – r_j May 05 '20 at 16:38

1 Answers1

0

The simplest solution for this is to create a bash script run.sh.

set -ev

service pgbouncer start
daphne test_project.asgi:application --port $PORT --bind 0.0.0.0 -v2
service pgbouncer stop

run:
  web: run.sh
Matthaus Woolard
  • 2,310
  • 11
  • 13