Issue
I am running centOS 7 and trying to create a postgresql database
I entered to following to install and initiate database
yum install https://download.postgresql.org/pub/repos/yum/11/redhat/rhel-7-x86_64/pgdg-centos11-11-2.noarch.rpm
sudo yum install postgresql11
sudo yum install postgresql11-server
sudo /usr/pgsql-11/bin/postgresql-11-setup initdb
sudo systemctl enable postgresql-11
sudo systemctl start postgresql-11
so after this i try to create a database by entering
sudo createdb mydb
receive:
createdb: could not connect to database template1: FATAL: role "root" does not exist
so now i realize i need to be on the postgre user
and cannot create a db with this command:
sudo -u postgres createdb mydb
Recieve:
could not change directory to "/home/<user>": Permission denied
I am able to get the postgre prompt by entering the following
sudo -u postgres -i
psql
but when i enter sudo -u postgres -1
i get a new bash prompt -bash-4.2$
when i try to create a database in this prompt with sudo createdb mydb
it asks for a password for postgres and can't go on from there,
what is this password? i read that by default it shouldn't
Solution
Did you try
sudo -i -u postgres
psql
CREATE DATABASE yourbase;
\c yourbase
?
Answered By - G.D