Mimic-code: Problem building database - peer authentication failed for user "postgres"

Created on 1 Sep 2017  ·  11Comments  ·  Source: MIT-LCP/mimic-code

Hi,

I'm new to MIMIC-III, and have downloaded and unzipped the csv files. When I try to build the databse though I get this error, (apologies I'm also a newb to postgres).

(tf_011_v2) ajay@ajay-h8-1170uk:~/PythonProjects/mimic-code-master/buildmimic/postgres$ make mimic  datadir="/home/ajay/PythonProjects/mimic-code-master/data/"

-----------------------
-- Checking for data --
-----------------------

Data path:  /home/ajay/PythonProjects/mimic-code-master/data/
All data present!

------------------------
-- Building MIMIC-III --
------------------------

MIMICUSER="postgres" MIMIC_DB="mimic" MIMIC_PASSWORD="postgres" MIMIC_SCHEMA="mimiciii" ./create_mimic_user.sh
MIMIC_PASSWORD is set
MIMIC_DB is set to 'mimic'
User is unset, using default 'postgres'
postgres

psql: FATAL:  Peer authentication failed for user "postgres"
make: *** [create-user] Error 2

I tried changing my OS user to postgres, using

sudo su - postgres

but then I can't access the makefile or the folder with the csv files?

postgres@ajay-h8-1170uk:~$ cd /home/ajay/PythonProjects/mimic-code-master/buildmimic/postgre
-su: cd: /home/ajay/PythonProjects/mimic-code-master/buildmimic/postgres: Permission denied

I think my problem might be similar to another closed issue

Difficulty Building Database Using PostgreSQL - https://github.com/MIT-LCP/mimic-code/issues/259

So I guess I need to change the makefile somehow, any advice?

Most helpful comment

I encountered the same issue as in the OP, which I resolved by invoking the make script with DBUSER="$USER" like so:

make create-user mimic-gz datadir="$datadir" DBUSER="$USER"

All 11 comments

@AjayTalati it looks like authentication is failing because your pg_hba.conf file requires peer authentication and postgres user doesn't exist on your system.

You can solve this issue by editing your pg_hba.conf file or by setting the user to your system username. For more detail, see: https://stackoverflow.com/questions/17443379/psql-fatal-peer-authentication-failed-for-user-dev

Changing the following line in pg_hba.conf:

# TYPE DATABASE USER ADDRESS METHOD
local  all      all          peer

to:

# TYPE DATABASE USER ADDRESS METHOD
local  all      all          md5

...will allow you to input the password to login.

Hi @tompollard thanks very much for the help :)

Kind of a dumb question, but how do you find where pg_hba.conf is on an ubuntu system? I just tried,

(tf_011_v2) ajay@ajay-h8-1170uk:~$ find . -type f -name "pg_hba.conf"

but no luck finding pg_hba.conf ?

You might find it easier to change the user from 'postgres' to your system (unix) user. The file pg_hba.conf will most likely be at /etc/postgresql/9.x/main/pg_hba.conf

I could'nt find a postgresql folder in my home/etc
empty_etc

so maybe that's a problem?

I'm not sure how to "_change the user from 'postgres' to your system (unix) user_", but I tried running the command using sudo, but still got the same problem,

(tf_011_v2) ajay@ajay-h8-1170uk:~/PythonProjects/mimic-code-master/buildmimic/postgres$ sudo make mimic  datadir="/home/ajay/PythonProjects/mimic-code-master/data/"
[sudo] password for ajay: 

-----------------------
-- Checking for data --
-----------------------

Data path:  /home/ajay/PythonProjects/mimic-code-master/data/
All data present!

------------------------
-- Building MIMIC-III --
------------------------

MIMICUSER="postgres" MIMIC_DB="mimic" MIMIC_PASSWORD="postgres" MIMIC_SCHEMA="mimiciii" ./create_mimic_user.sh
MIMIC_PASSWORD is set
MIMIC_DB is set to 'mimic'
User is unset, using default 'postgres'
postgres

psql: FATAL:  Peer authentication failed for user "postgres"
make: *** [create-user] Error 2

sorry for the novice problems?

I guess I should try to follow the steps here

https://mimic.physionet.org/tutorials/install-mimic-locally-ubuntu/

The make files should work - you don't need sudo. Your find command won't work because it only looked in the local folder, which at the time was ~/. Try running locate pg_hba.conf. If the locate doesn't find anything, try running sudo find / -type f -name "pg_hba.conf". The sudo is to avoid a lot of messages about "Permission denied". Once you find the pg_hba.conf, edit it like @tompollard suggests, then restart postgres with sudo service postgresql restart

Of course, you can follow the tutorial that you linked as well, it's a bit more manual but you may find it useful as you learn a bit more postgres syntax and learn a bit more about how the data is structured!

Hi @alistairewj thanks a lot,

I did as you said and found pg_hba.conf, and edited it as advised, and then restarted postgres.

edit_pg_hdaconf

Unfortunately I'm still getting the same _peer authentication failed for user "postgres"_ problem

ajay@ajay-h8-1170uk:~/PythonProjects/mimic-code-master/buildmimic/postgres$ make mimic  datadir="/home/ajay/PythonProjects/mimic-code-master/data/"

-----------------------
-- Checking for data --
-----------------------

Data path:  /home/ajay/PythonProjects/mimic-code-master/data/
All data present!

------------------------
-- Building MIMIC-III --
------------------------

MIMICUSER="postgres" MIMIC_DB="mimic" MIMIC_PASSWORD="postgres" MIMIC_SCHEMA="mimiciii" ./create_mimic_user.sh
MIMIC_PASSWORD is set
MIMIC_DB is set to 'mimic'
User is unset, using default 'postgres'
postgres

psql: FATAL:  Peer authentication failed for user "postgres"
make: *** [create-user] Error 2
ajay@ajay-h8-1170uk:~/PythonProjects/mimic-code-master/buildmimic/postgres$

Oh well,...., I followed the manual build tutorial, and it seems the csv files are now being imported - will let you know if this works?

ajay@ajay-h8-1170uk:~/PythonProjects/mimic-code-master/buildmimic/postgres$ psql 'dbname=mimic user=ajay options=--search_path=mimiciii' -f postgres_load_data.sql -v mimic_data_dir="/home/ajay/PythonProjects/mimic-code-master/data/"
Password: 
COPY 58976
COPY 34499
COPY 7567

Looks like it's worked,

ajay@ajay-h8-1170uk:~/PythonProjects/mimic-code-master/buildmimic/postgres$ psql 'dbname=mimic user=ajay options=--search_path=mimiciii' -f postgres_load_data.sql -v mimic_data_dir="/home/ajay/PythonProjects/mimic-code-master/data/"
Password: 
COPY 58976
COPY 34499
COPY 7567




COPY 0
COPY 573146
COPY 4485937
COPY 651047
COPY 125557
COPY 134
COPY 14567
COPY 3882
COPY 12487
COPY 753
COPY 61532
COPY 17527935
COPY 3618991
COPY 27854055
COPY 631726
COPY 2083180
COPY 4349218
COPY 46520
COPY 4156450
COPY 258066
COPY 240095
COPY 73343
COPY 261897

so I'll close this issue - thanks very much for your help :+1:

I encountered the same issue as in the OP, which I resolved by invoking the make script with DBUSER="$USER" like so:

make create-user mimic-gz datadir="$datadir" DBUSER="$USER"

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jeblundell picture jeblundell  ·  30Comments

w-is-h picture w-is-h  ·  4Comments

EarlGlynn picture EarlGlynn  ·  3Comments

khalid-hussain picture khalid-hussain  ·  23Comments

lmockus picture lmockus  ·  27Comments