Support Questions

Find answers, ask questions, and share your expertise

Unable to create hive database using Ambari embedded postgres database

Explorer

I installed Ambari as root user with its default/embedded Postgresql db and would like to use it to create hive and oozie databases. Ambari was installed successfully and postgress is running. But when running the following command to create hive database as root user

echo "CREATE DATABASE hive;" | psql -U postgres

I get the following error:

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

Here is /var/lib/pgsql/data/pg_hba.conf

local all postgres peer
# IPv4 local connections:
host    all   postgres             127.0.0.1/32            ident
local  all  ambari,mapred md5
host  all   ambari,mapred 0.0.0.0/0  md5
host  all   ambari,mapred ::/0 md5


3 REPLIES 3

Super Mentor

@Zaili Xu

Please try to do "su - postgres" first.

Example:

# su - postgres
Last login: Thu Feb 22 00:52:08 UTC 2018 on pts/0


$ echo "CREATE DATABASE hive;" | psql -U postgres
CREATE DATABASE

.

Explorer

Thank you, Jay, for the prompt response. I used the following cmd to to run from script and it worked

cmd="echo ${sql}|psql -U postgres"
su - postgres -c "$cmd"

Super Mentor

@Zaili Xu

Good to know your issue is resolved.

The actual cause of the following error can be solved by using "su - postgres". after that you can execute whatever command you want. The Key to fix the following error us to use "su - postgres"

psql: FATAL:  Peer authentication failed for user "postgres"
Take a Tour of the Community
Don't have an account?
Your experience may be limited. Sign in to explore more.