Why did a Heroku PGBackup fail with "Could not connect to database to initialize transfer"?


When using Heroku PGBackups (ref: https://devcenter.heroku.com/articles/heroku-postgres-backups) to backup or copy across a database, you receive the error message "Could not connect to database to initialize transfer".


In the majority of cases, this is caused by the database connections being maxed out, for example, having 20/20 connections reported for a basic (formerly hobby-basic) tier Heroku Postgres database. This can be checked using heroku pg:info:

Plan:                  Hobby-basic
Status:                Available
Connections:           20/20
PG Version:            10.6
Created:               2018-11-12 02:23 UTC
Data Size:             11.5 MB
Tables:                17
Rows:                  10000/10000000 (In compliance)
Fork/Follow:           Unsupported
Rollback:              Unsupported
Continuous Protection: Off
Add-on:                postgresql-adjective-12345

In order for the backup process to succeed, Heroku must be able to connect to the database. As a result, you will need to put the application into maintenance mode (ref: https://devcenter.heroku.com/articles/maintenance-mode) and/or scale down dynos to reduce the number of connections to your Heroku Postgres database.

Ask on Stack Overflow

Engage with a community of passionate experts to get the answers you need

Ask on Stack Overflow

Heroku Support

Create a support ticket and our support experts will get back to you

Contact Heroku Support