# DB backup config error

**URL:** https://meta.discourse.org/t/db-backup-config-error/100604
**Category:** Self-hosting
**Created:** [October 27, 2018, 4:49am UTC](https://meta.discourse.org/t/db-backup-config-error/100604 "2018-10-27T04:49:43Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![netpositive](https://avatars.discourse-cdn.com/v4/letter/n/8edcca/32.png) [@netpositive](https://meta.discourse.org/u/netpositive)
#### Post date: [October 27, 2018, 4:49am UTC](https://meta.discourse.org/t/db-backup-config-error/100604/1 "2018-10-27T04:49:44Z")

</div>

I upgraded Discourse to latest stable version with complete rebuild yesterday. I’ve got this strange error this morning:

```plaintext
[2018-10-27 04:21:44] 'netpositive' has started the backup! 
[2018-10-27 04:21:44] Marking backup as running... 
[2018-10-27 04:21:44] Making sure '/var/www/discourse/tmp/backups/default/2018-10-27-042144' exists... 
[2018-10-27 04:21:44] Making sure '/var/www/discourse/public/backups/default' exists... 
[2018-10-27 04:21:44] Pausing sidekiq... 
[2018-10-27 04:21:44] Waiting for sidekiq to finish running jobs... 
[2018-10-27 04:21:44] Dumping the public schema of the database... 
[2018-10-27 04:21:44] pg_dump: [archiver (db)] connection to database "discourse" failed: could not connect to server: Connection refused 
[2018-10-27 04:21:44] Is the server running on host "172.17.0.1" and accepting 
[2018-10-27 04:21:44] TCP/IP connections on port 5432? 
[2018-10-27 04:21:44] EXCEPTION: pg_dump failed 
[2018-10-27 04:21:44]
 /var/www/discourse/lib/backup_restore/backuper.rb:172:in `dump_public_schema'
 /var/www/discourse/lib/backup_restore/backuper.rb:37:in `run'
 /var/www/discourse/lib/backup_restore/backup_restore.rb:167:in `block in start!'
 /var/www/discourse/lib/backup_restore/backup_restore.rb:164:in `fork'
 /var/www/discourse/lib/backup_restore/backup_restore.rb:164:in `start!'
 /var/www/discourse/lib/backup_restore/backup_restore.rb:18:in `backup!'
 /var/www/discourse/app/controllers/admin/backups_controller.rb:32:in `create'
[2018-10-27 04:21:44] Notifying 'netpositive' of the end of the backup... 
[2018-10-27 04:21:53] Removing old backups...

```

The postgresql 9.6 server is running outside the container and it’s accessible on port 5433. If I manually run the pg\_dump command inside the container then it works flawlessly and I haven’t detected any other DB related issue in Discourse.

Any idea why does it take wrong config settings? 😕

Thanks a lot!

---

<div class="post-metadata">

### Author: ![Mittineague](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mittineague/32/114259_2.png) [@Mittineague](https://meta.discourse.org/u/Mittineague)
#### Post date: [October 27, 2018, 5:14am UTC](https://meta.discourse.org/t/db-backup-config-error/100604/2 "2018-10-27T05:14:33Z")

</div>

> [@netpositive](#):
>
> postgresql 9.6 server

I have a feeling this may be your problem

[discourse/docs/INSTALL.md at main · discourse/discourse · GitHub](https://github.com/discourse/discourse/blob/master/docs/INSTALL.md)

> Software Requirements
> 
> - [Postgres 10+](http://www.postgresql.org/download/)

---

<div class="post-metadata">

### Author: ![michaeld](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/michaeld/32/1594_2.png) [@michaeld](https://meta.discourse.org/u/michaeld)
#### Post date: [October 27, 2018, 5:53am UTC](https://meta.discourse.org/t/db-backup-config-error/100604/3 "2018-10-27T05:53:12Z")

</div>

No, Discourse works still fine with 9.6 and it definitely should not get a connection refused because of the Pg version.

---

<div class="post-metadata">

### Author: ![netpositive](https://avatars.discourse-cdn.com/v4/letter/n/8edcca/32.png) [@netpositive](https://meta.discourse.org/u/netpositive)
#### Post date: [October 27, 2018, 9:28am UTC](https://meta.discourse.org/t/db-backup-config-error/100604/4 "2018-10-27T09:28:04Z")

</div>

Thanks, somehow I’ve overlooked that. Now on postgresql 10 but the problem still persists 🙄

---

<div class="post-metadata">

### Author: ![gerhard](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gerhard/32/119479_2.png) [@gerhard](https://meta.discourse.org/u/gerhard)
#### Post date: [October 29, 2018, 5:40pm UTC](https://meta.discourse.org/t/db-backup-config-error/100604/5 "2018-10-29T17:40:48Z")

</div>

> [@netpositive](#):
>
> If I manually run the pg\_dump command inside the container then it works flawlessly

You could try running the same command Discourse uses for dumps. You can get it by executing the following inside the container:

```plaintext
rails c
BackupRestore::Backuper.new(Discourse.system_user.id, {}).send(:pg_dump_command)

```

---

<div class="post-metadata">

### Author: ![netpositive](https://avatars.discourse-cdn.com/v4/letter/n/8edcca/32.png) [@netpositive](https://meta.discourse.org/u/netpositive)
#### Post date: [October 29, 2018, 6:52pm UTC](https://meta.discourse.org/t/db-backup-config-error/100604/6 "2018-10-29T18:52:02Z")

</div>

It doesn’t work because the port 5432 is used instead of 5433 ☹

```
[1] pry(main)> BackupRestore::Backuper.new(Discourse.system_user.id, {}).send(:pg_dump_command)
=> "PGPASSWORD='redacted' pg_dump --schema=public --file='/var/www/discourse/tmp/backups/default/2018-10-29-184350/dump.sql.gz' --no-owner --no-privileges --verbose --compress=4 --host=172.17.0.1 --port=5432 --username=discourse discourse"

```

---

<div class="post-metadata">

### Author: ![gerhard](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gerhard/32/119479_2.png) [@gerhard](https://meta.discourse.org/u/gerhard)
#### Post date: [October 29, 2018, 10:57pm UTC](https://meta.discourse.org/t/db-backup-config-error/100604/7 "2018-10-29T22:57:44Z")

</div>

Oh, I totally missed the different ports in your first post. 😅

It looks like [backups use the default PostgreSQL port](https://github.com/discourse/discourse/blob/f8305f53c787ad0b6cd865d56a7b8b0f77f9dcc2/config/discourse_defaults.conf#L40-L41) unless specified otherwise. I think you might be able to override it by configuring `DISCOURSE_DB_BACKUP_PORT: 5433` in your container config.

---

<div class="post-metadata">

### Author: ![netpositive](https://avatars.discourse-cdn.com/v4/letter/n/8edcca/32.png) [@netpositive](https://meta.discourse.org/u/netpositive)
#### Post date: [October 31, 2018, 5:41am UTC](https://meta.discourse.org/t/db-backup-config-error/100604/8 "2018-10-31T05:41:53Z")

</div>

Thank you, that setting did the trick 😌

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [November 30, 2018, 5:42am UTC](https://meta.discourse.org/t/db-backup-config-error/100604/9 "2018-11-30T05:42:17Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
