Running Discourse with pg_bouncer and a separate DB

I’m trying to set up our Discourse instance to connect to a separate Postgres DB hosted on Azure (set up as described here) via pg_bouncer and I’m having issues.

Our discourse is hosted on a VM in Azure. I have pg_bouncer installed on it and configured, and I am able to verify that I can connect to the hosted DB from the VM via:

psql -h -p 5432 -U [username] -d [database]

In my app.yml, I changed from using the DB hostname to using

DISCOURSE_DB_HOST: [was hostname, tried]

When rebuilding the app I get the following error:

I, [2020-09-18T20:48:51.653890 #1]  INFO -- : > cd /var/www/discourse && su discourse -c 'bundle exec rake db:migrate'
rake aborted!
PG::ConnectionBad: could not connect to server: Connection refused
	Is the server running on host "" and accepting
	TCP/IP connections on port 5432?

The only thing that I can think of that’s different between how I’m connecting via psql and the setup of my app.yml is that there’s a password specified in app.yml that isn’t necessary in psql because it’s set up in the pg_bouncer userlist.

Any help would be appreciated.

1 Like

I believe that you’ll need to use an ip that the container can access. It has its own local host, I believe


Oh duh! Using my 10.x.x.x address it works just fine.

Now, this might not be the best solution, so if there’s any preferred way to access the host from the Discourse docker container I’m all ears.


1 Like