Backup restore failing on clean dev docker env: FATAL: Peer authentication failed for user “postgres”

Hi over in the beginners guide to install discourse for development using docker some of the comments mention this issue which I think is actually a bug that should be raised as such here. Correct me if I am wrong.

I tend to create a copy of production to test major config changes and have many times created a clean slate like this before. However now the backups fail with this error conerning the peer authentication failing.

Just to provide context on what I am doing (wrong potentially)

  1. delete the local discourse directory altogether
  2. stop and remove any containers
  3. start fresh git cloning discourse and also the plugins I use directly after in the plugins directory
  4. do the boot_dev --init incantations, bundle install if needed, migrate database if needed.
  5. with the dummy admin account i log in, upload the backup I downloaded from my live site
  6. hit restore backup.

Let me know if I can provide anymore info. The backup logs are below. And oh yes, I checked the pg_hba.conf in data/postgres/ had all the authentication methods set to “trust”.

[2021-11-03 20:55:35] 'koen' has started the restore!
[2021-11-03 20:55:35] Marking restore as running...
[2021-11-03 20:55:35] Making sure /src/tmp/restores/default/2021-11-03-205535 exists...
[2021-11-03 20:55:35] Copying archive to tmp directory...
[2021-11-03 20:55:35] Extracting dump file...
[2021-11-03 20:55:36] Validating metadata...
[2021-11-03 20:55:36]   Current version: 20211022154420
[2021-11-03 20:55:36]   Restored version: 20211022154420
[2021-11-03 20:55:36] Enabling readonly mode...
[2021-11-03 20:55:36] Pausing sidekiq...
[2021-11-03 20:55:36] Waiting up to 60 seconds for Sidekiq to finish running jobs...
[2021-11-03 20:55:42] Creating missing functions in the discourse_functions schema...
[2021-11-03 20:55:42] Restoring dump file... (this may take a while)
[2021-11-03 20:55:42] psql: error: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: FATAL:  Peer authentication failed for user "postgres"
[2021-11-03 20:55:42] EXCEPTION: psql failed: psql: error: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: FATAL:  Peer authentication failed for user "postgres"
[2021-11-03 20:55:42] /src/lib/backup_restore/database_restorer.rb:92:in `restore_dump'
/src/lib/backup_restore/database_restorer.rb:26:in `restore'
/src/lib/backup_restore/restorer.rb:51:in `run'
/src/script/spawn_backup_restore.rb:23:in `restore'
/src/script/spawn_backup_restore.rb:36:in `block in <main>'
/src/script/spawn_backup_restore.rb:4:in `fork'
/src/script/spawn_backup_restore.rb:4:in `<main>'
[2021-11-03 20:55:42] Trying to rollback...
[2021-11-03 20:55:42] There was no need to rollback
[2021-11-03 20:55:42] Cleaning stuff up...
[2021-11-03 20:55:42] Dropping functions from the discourse_functions schema...
[2021-11-03 20:55:42] Removing tmp '/src/tmp/restores/default/2021-11-03-205535' directory...
[2021-11-03 20:55:42] Unpausing sidekiq...
[2021-11-03 20:55:42] Marking restore as finished...
[2021-11-03 20:55:42] Notifying 'koen' of the end of the restore...
[2021-11-03 20:55:46] Finished!
1 Like

Hi all, just wondering, does this classify as a bug and will it be accepeted as such? Should I write it up differently or add more info? What’s the next step is all I am wondering, I am not pushing for any resolution date whatsoever.

Hi all, couple of weeks down the line I thought I’d give another shot. So went all cleanslate again, set up and logged into the fresh development environment on my local machine. Then added the plugins to match my PROD env. Pulled a back-up from the live site and try to restore that on my DTA environment. Alas still the same error.

Can anyone reproduce this? I have one upon a time had the native development environment running but then got rid of that when I noticed the ease of use of the docker setup. Could something be biting me from that legacy? Something wrong stemming from the former local postgres database platform? Can that even bite each other if the clean slate runs from docker? Just conjecturing. Can anyone point me in the right direction or the right people? Taking a copy of the live site for testing purposes is a pretty important use case I would imagine? Anything I can do to provide more info? Running the auto test thing as we speak but that doesn’t yield anything either…

[2021-11-29 19:43:39] 'koen' has started the restore!
[2021-11-29 19:43:39] Marking restore as running...
[2021-11-29 19:43:39] Making sure /src/tmp/restores/default/2021-11-29-194339 exists...
[2021-11-29 19:43:39] Copying archive to tmp directory...
[2021-11-29 19:43:39] Extracting dump file...
[2021-11-29 19:43:40] Validating metadata...
[2021-11-29 19:43:40]   Current version: 20211124161346
[2021-11-29 19:43:40]   Restored version: 20211123033311
[2021-11-29 19:43:40] Enabling readonly mode...
[2021-11-29 19:43:40] Pausing sidekiq...
[2021-11-29 19:43:40] Waiting up to 60 seconds for Sidekiq to finish running jobs...
[2021-11-29 19:43:46] Creating missing functions in the discourse_functions schema...
[2021-11-29 19:43:46] Restoring dump file... (this may take a while)
[2021-11-29 19:43:47] psql: error: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: FATAL:  Peer authentication failed for user "postgres"
[2021-11-29 19:43:47] EXCEPTION: psql failed: psql: error: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: FATAL:  Peer authentication failed for user "postgres"

[2021-11-29 19:43:47] /src/lib/backup_restore/database_restorer.rb:92:in `restore_dump'
/src/lib/backup_restore/database_restorer.rb:26:in `restore'
/src/lib/backup_restore/restorer.rb:51:in `run'
/src/script/spawn_backup_restore.rb:23:in `restore'
/src/script/spawn_backup_restore.rb:36:in `block in <main>'
/src/script/spawn_backup_restore.rb:4:in `fork'
/src/script/spawn_backup_restore.rb:4:in `<main>'
[2021-11-29 19:43:47] Trying to rollback...
[2021-11-29 19:43:47] There was no need to rollback
[2021-11-29 19:43:47] Cleaning stuff up...
[2021-11-29 19:43:47] Dropping functions from the discourse_functions schema...
[2021-11-29 19:43:47] Removing tmp '/src/tmp/restores/default/2021-11-29-194339' directory...
[2021-11-29 19:43:47] Unpausing sidekiq...
[2021-11-29 19:43:47] Marking restore as finished...
[2021-11-29 19:43:47] Notifying 'koen' of the end of the restore...
[2021-11-29 19:43:51] Finished!

Koen

Well, d/rake autospec did yield 14 failures, the first 6 of which seem to be related to the PEER authentication issue.

Can’t make heads or tails of it but thought I’d post it here for when someone is able to investigate. Looks like the same error but with different Postgres versions everytime.

Hope this helps

Failures:

  1) BackupRestore::DatabaseRestorer#restore with real psql restores from PostgreSQL 9.5
     Failure/Error: raise DatabaseRestoreError.new("psql failed: #{last_line}") if Process.last_status&.exitstatus != 0
     
     BackupRestore::DatabaseRestoreError:
       psql failed: psql: error: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: FATAL:  Peer authentication failed for user "postgres"                                                                                        
     # ./lib/backup_restore/database_restorer.rb:92:in `restore_dump'
     # ./lib/backup_restore/database_restorer.rb:26:in `restore'
     # ./spec/lib/backup_restore/shared_context_for_backup_restore.rb:59:in `execute_stubbed_restore'
     # ./spec/lib/backup_restore/database_restorer_spec.rb:41:in `restore'
     # ./spec/lib/backup_restore/database_restorer_spec.rb:45:in `expect_restore_to_work'
     # ./spec/lib/backup_restore/database_restorer_spec.rb:61:in `block (4 levels) in <main>'
     # ./spec/rails_helper.rb:284:in `block (2 levels) in <top (required)>'

  2) BackupRestore::DatabaseRestorer#restore with real psql restores from PostgreSQL 9.3
     Failure/Error: raise DatabaseRestoreError.new("psql failed: #{last_line}") if Process.last_status&.exitstatus != 0
     
     BackupRestore::DatabaseRestoreError:
       psql failed: psql: error: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: FATAL:  Peer authentication failed for user "postgres"                                                                                        
     # ./lib/backup_restore/database_restorer.rb:92:in `restore_dump'
     # ./lib/backup_restore/database_restorer.rb:26:in `restore'
     # ./spec/lib/backup_restore/shared_context_for_backup_restore.rb:59:in `execute_stubbed_restore'
     # ./spec/lib/backup_restore/database_restorer_spec.rb:41:in `restore'
     # ./spec/lib/backup_restore/database_restorer_spec.rb:45:in `expect_restore_to_work'
     # ./spec/lib/backup_restore/database_restorer_spec.rb:51:in `block (4 levels) in <main>'
     # ./spec/rails_helper.rb:284:in `block (2 levels) in <top (required)>'

  3) BackupRestore::DatabaseRestorer#restore with real psql restores from PostgreSQL 12
     Failure/Error: raise DatabaseRestoreError.new("psql failed: #{last_line}") if Process.last_status&.exitstatus != 0
     
     BackupRestore::DatabaseRestoreError:
       psql failed: psql: error: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: FATAL:  Peer authentication failed for user "postgres"                                                                                        
     # ./lib/backup_restore/database_restorer.rb:92:in `restore_dump'
     # ./lib/backup_restore/database_restorer.rb:26:in `restore'
     # ./spec/lib/backup_restore/shared_context_for_backup_restore.rb:59:in `execute_stubbed_restore'
     # ./spec/lib/backup_restore/database_restorer_spec.rb:41:in `restore'
     # ./spec/lib/backup_restore/database_restorer_spec.rb:45:in `expect_restore_to_work'
     # ./spec/lib/backup_restore/database_restorer_spec.rb:74:in `block (4 levels) in <main>'
     # ./spec/rails_helper.rb:284:in `block (2 levels) in <top (required)>'

  4) BackupRestore::DatabaseRestorer#restore with real psql restores from PostgreSQL 11
     Failure/Error: raise DatabaseRestoreError.new("psql failed: #{last_line}") if Process.last_status&.exitstatus != 0
     
     BackupRestore::DatabaseRestoreError:
       psql failed: psql: error: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: FATAL:  Peer authentication failed for user "postgres"                                                                                        
     # ./lib/backup_restore/database_restorer.rb:92:in `restore_dump'
     # ./lib/backup_restore/database_restorer.rb:26:in `restore'
     # ./spec/lib/backup_restore/shared_context_for_backup_restore.rb:59:in `execute_stubbed_restore'
     # ./spec/lib/backup_restore/database_restorer_spec.rb:41:in `restore'
     # ./spec/lib/backup_restore/database_restorer_spec.rb:45:in `expect_restore_to_work'
     # ./spec/lib/backup_restore/database_restorer_spec.rb:70:in `block (4 levels) in <main>'
     # ./spec/rails_helper.rb:284:in `block (2 levels) in <top (required)>'

  5) BackupRestore::DatabaseRestorer#restore with real psql restores from PostgreSQL 9.5.5
     Failure/Error: raise DatabaseRestoreError.new("psql failed: #{last_line}") if Process.last_status&.exitstatus != 0
     
     BackupRestore::DatabaseRestoreError:
       psql failed: psql: error: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: FATAL:  Peer authentication failed for user "postgres"                                                                                        
     # ./lib/backup_restore/database_restorer.rb:92:in `restore_dump'
     # ./lib/backup_restore/database_restorer.rb:26:in `restore'
     # ./spec/lib/backup_restore/shared_context_for_backup_restore.rb:59:in `execute_stubbed_restore'
     # ./spec/lib/backup_restore/database_restorer_spec.rb:41:in `restore'
     # ./spec/lib/backup_restore/database_restorer_spec.rb:45:in `expect_restore_to_work'
     # ./spec/lib/backup_restore/database_restorer_spec.rb:56:in `block (4 levels) in <main>'
     # ./spec/rails_helper.rb:284:in `block (2 levels) in <top (required)>'

  6) BackupRestore::DatabaseRestorer#restore with real psql restores from PostgreSQL 10
     Failure/Error: raise DatabaseRestoreError.new("psql failed: #{last_line}") if Process.last_status&.exitstatus != 0
     
     BackupRestore::DatabaseRestoreError:
       psql failed: psql: error: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: FATAL:  Peer authentication failed for user "postgres"                                                                                        
     # ./lib/backup_restore/database_restorer.rb:92:in `restore_dump'
     # ./lib/backup_restore/database_restorer.rb:26:in `restore'
     # ./spec/lib/backup_restore/shared_context_for_backup_restore.rb:59:in `execute_stubbed_restore'
     # ./spec/lib/backup_restore/database_restorer_spec.rb:41:in `restore'
     # ./spec/lib/backup_restore/database_restorer_spec.rb:45:in `expect_restore_to_work'
     # ./spec/lib/backup_restore/database_restorer_spec.rb:66:in `block (4 levels) in <main>'
     # ./spec/rails_helper.rb:284:in `block (2 levels) in <top (required)>'