DB backup config error

AI-generated summary

DB Backup Config Error

The issue began after a Discourse upgrade to the latest stable version. netpositive encountered a PostgreSQL connection error during the automatic backup process, despite the PostgreSQL server (version 9.6) being accessible on port 5433.

Initially, it was suggested that the PostgreSQL version might be the cause, but michaeld clarified that Discourse still supports version 9.6.

/netpositive then upgraded to PostgreSQL 10, but the error persisted. gerhard suggested running the pg_dump command used by Discourse, which revealed that the port 5432 was being used instead of 5433.

The solution was found by gerhard, who pointed out that backups use the default PostgreSQL port unless specified otherwise. To resolve the issue, netpositive set DISCOURSE_DB_BACKUP_PORT: 5433 in the container config, which fixed the problem.

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

[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? :confused:

Thanks a lot!

I have a feeling this may be your problem

discourse/docs/INSTALL.md at main · discourse/discourse · GitHub

Software Requirements

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

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

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

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

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

[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"

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

It looks like backups use the default PostgreSQL port unless specified otherwise. I think you might be able to override it by configuring DISCOURSE_DB_BACKUP_PORT: 5433 in your container config.

Thank you, that setting did the trick :relaxed: