FATAL error message : Peer authentication failed for user "gitlab" when upgrading to 14.5.0

Summary

When upgrading our Community Edition on Staging from v14.4.1 to v14.5 using command : apt-get install gitlab-ce=14.5.0-ce.0 -y the migrations step appeared to hang and in the postgresql (v12.7) log we saw a FATAL error message : Peer authentication failed for user "gitlab".

Hung at this point :

Recipe: gitlab::database_migrations
  * ruby_block[check remote PG version] action nothing (skipped due to action :nothing)
  * rails_migration[gitlab-rails] action run
    * bash[migrate gitlab-rails database] action run

Steps to reproduce

From a server running v14.4.1 run : apt-get update && apt-get install gitlab-ce=14.5.0-ce.0 -y

What is the current bug behavior?

Tried this step a number of times and the FATAL error occurs every time.

What is the expected correct behavior?

Migrations should complete successfully and no FATAL error in the Postgresql logs.

Relevant logs

Relevant logs
Postgresql logs :
```
2021-11-24_11:13:21.86345 DETAIL:  Connection matched pg_hba.conf line 70: "local   all         all                               peer map=gitlab"
2021-11-24_11:13:21.91698 LOG:  no match in usermap "gitlab" for user "gitlab" authenticated as "root"
2021-11-24_11:13:21.91699 FATAL:  Peer authentication failed for user "gitlab"
2021-11-24_11:13:21.91699 DETAIL:  Connection matched pg_hba.conf line 70: "local   all         all                               peer map=gitlab"
```

Other relevant section of the logs :

* file[/opt/gitlab/service/postgresql/log/supervise/ok] action touch (skipped due to only_if)
    * file[/opt/gitlab/service/postgresql/supervise/status] action touch
      - change owner from 'root' to 'gitlab-psql'
      - change group from 'root' to 'gitlab-psql'
      - update utime on file /opt/gitlab/service/postgresql/supervise/status
    * file[/opt/gitlab/service/postgresql/log/supervise/status] action touch
      - change owner from 'root' to 'gitlab-psql'
      - change group from 'root' to 'gitlab-psql'
      - update utime on file /opt/gitlab/service/postgresql/log/supervise/status
    * file[/opt/gitlab/service/postgresql/supervise/control] action touch (skipped due to only_if)

cat /var/opt/gitlab/postgresql/data/pg_ident.conf |grep -v "#"
gitlab  git  gitlab
gitlab  mattermost  gitlab_mattermost
gitlab  /^(.*)$  \1

Details of package version

Provide the package version installation details
apt-get install gitlab-ce=14.5.0-ce.0

Environment details

  • Operating System: Ubuntu 18.04.5 LTS
  • Installation Target, remove incorrect values:
    • VM: AWS
  • Installation Type, remove incorrect values:
    • Upgrade from version v14.4.1
  • Is there any other software running on the machine: Nope.
  • Is this a single or multiple node installation? Single
  • Resources
    • CPU: 8
    • Memory total: 16

Configuration details

Provide the relevant sections of `/etc/gitlab/gitlab.rb`
postgresql['shared_buffers'] = "4GB" # recommend value is 1/4 of total RAM, up to 14GB.
postgresql['idle_in_transaction_session_timeout'] = "900000"