createdb: database creation failed: ERROR: permission denied to create database

SonamGupta picture SonamGupta · May 2, 2017 · Viewed 49.7k times · Source

I am pretty much confused about root user,super user,user and permissions! I am not able to create a database inside user "athleticu". Following are the commands I used:-

athleticu@ip-172-30-4-103:/home/ubuntu$ createdb -T template0 simple_db1
createdb: database creation failed: ERROR:  permission denied to create database
athleticu@ip-172-30-4-103:/home/ubuntu$ sudo createdb -T template0 simple_db1
sudo: unable to resolve host ip-172-30-4-103
createdb: could not connect to database template1: FATAL:  role "root" does not exist

Please somebody clarify my doubts and tell me what should I write!

Answer

SonamGupta picture SonamGupta · May 8, 2017

Hey I have already solved this. What you have to do is to first login as postgres user as follows:

$ su postgres

$ psql

postgres=# alter user athleticu createdb;
ALTER ROLE

Hope it helps you :)