0

I am trying to connect to GitLab production (installed with omnibus package) postgresql database with psycopg2.

My configuration is like below:

onn = psycopg2.connect(database="gitlabhq_production", user="gitlab-psql", host="/var/opt/gitlab/postgresql", port="5432")

It gives the following error:

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

I can connect to the postgresql server on command line with:

sudo -u gitlab-psql -i bash /opt/gitlab/embedded/bin/psql --port 5432 -h /var/opt/gitlab/postgresql -d gitlabhq_production

Does anyone know what will be the correct parameters to pass into?

1 Answer 1

1

Peer authentication works by checking the user the process is running as. In your command line example you switch to gitlab-psql using sudo.

There are two ways to fix this:

  1. Assign a password to the gitlab-psql postgres user (not the system user!) and use that to connect via python. Setting the password is just another query you need to run as a superuser like so:

    sudo -u postgres psql -c "ALTER USER gitlab-psql WITH PASSWORD 'ReplaceThisWithYourLongAndSecurePassword';"
    
  2. Run your python script as gitlab-psql like so:

    sudo -u gitlab-psql python /path/to/your/script.py
    
Sign up to request clarification or add additional context in comments.

1 Comment

Does the omnibus-gitlab application require any changes via gitlab-ctl reconfigure after adding a password to postgresql user gitlab-psql?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.