15

I am running the AWS AMI from gitlab. I am trying to access the postgres database directly using psql. I thought I could just use the credentials in database.yml, since the rails application is working fine:

/opt/gitlab/embedded/bin/psql -U gitlab -d gitlabhq_production

But I get:

psql: FATAL:  Peer authentication failed for user "gitlab"

How can the rails app be connecting to the database while psql cannot?

monteguy
  • 153
  • 1
  • 1
  • 6
  • @Daniel Alder's comment pointed my in the right direction: `ubuntu@gitlab:~$ sudo -u gitlab-psql /opt/gitlab/embedded/bin/psql -h /var/opt/gitlab/postgresql/ gitlabhq_production psql: could not connect to server: No such file or directory Is the server running locally and accepting connections on Unix domain socket "/var/opt/gitlab/postgresql//.s.PGSQL.5432"? ubuntu@gitlab:~$ sudo -u gitlab-psql /opt/gitlab/embedded/bin/psql gitlabhq_production psql (9.2.9) Type "help" for help. gitlabhq_production=#` – monteguy Aug 11 '16 at 18:05
  • Please note [GitLab's `Use at your own risk` warning](https://docs.gitlab.com/ee/administration/troubleshooting/postgresql.html) for any such direct DB access. – Katrin Leinweber May 06 '21 at 08:16

5 Answers5

34
sudo -u gitlab-psql /opt/gitlab/embedded/bin/psql -h /var/opt/gitlab/postgresql/ gitlabhq_production
Daniel Alder
  • 5,031
  • 2
  • 45
  • 55
  • This answer is closest to what ended up working for me. I had to leave off the `-h /var/opt/gitlab/postgresql/` though, as that caused an error: `psql: could not connect to server: No such file or directory`, even though that dir does exist and is the `gitlab-psql` user's home dir. – monteguy Aug 11 '16 at 18:16
  • Please note [GitLab's `Use at your own risk` warning](https://docs.gitlab.com/ee/administration/troubleshooting/postgresql.html) for any such direct DB access. – Katrin Leinweber May 06 '21 at 08:16
  • @KatrinLeinweber good point. but I think if you come to the point where you search for how you can access the database, it doesn't matter anymore.. – Daniel Alder May 06 '21 at 14:59
12

googled and found an issue about this.

so, just type sudo gitlab-rails dbconsole :D

tdihp
  • 2,329
  • 2
  • 23
  • 40
0

But this one does give you full access:

sudo -u gitlab-psql psql template1
sorin
  • 161,544
  • 178
  • 535
  • 806
0
sudo -u gitlab-psql /opt/gitlab/embedded/bin/psql -h /var/opt/gitlab/postgresql -d gitlabhq_production
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
gladiator
  • 722
  • 1
  • 9
  • 16
0

su - git
/opt/gitlab/embedded/bin/psql -U gitlab -d gitlabhq_production -h /var/opt/gitlab/postgresql

works for me with gitlab-ce and the embedded postgres. Optional for better interactive working start a bash as git. The (unix)-user git seems to be a peer to the postgresuser gitlab, authenticates without a password (/var/opt/gitlab/postgresql/data/pg_hba.conf).