Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Postgres. role "root" does not exist. When trying to pg:pull database from Heroku

Im new to Postgres and to Heroku. I am trying to pull the database from Heroku but I'm missing something simple. I did:

heroku pg:pull HEROKU_POSTGRESQL_IVORY_URL localdb 

And I got the error:

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

Then I tried the same with "sudo". and I got:

createdb: could not connect to database template1: FATAL:  role "root" does not exist 

So, it must be I'm missing some simple commands I can't find. Im on Linux, I have Postgres installed and working.

like image 700
Alejandro Veintimilla Avatar asked Jul 31 '14 01:07

Alejandro Veintimilla


1 Answers

createdb is a wrapper around the SQL statement CREATE DATABASE and as such it needs to connect to the database.

By default all Postgres commandline tools try to connect to the database using the current operating system user. As the error message indicates there is not user named root in the database. So you need to pass the name of the Postgres superuser in order for createdb to be able to connect. This user is usually named postgres.

Another option is to switch the Linux user to to postgres if such a Linux user exists.

I don't know Heroku and I don't know how you started createdb, but the parameter to pass a username is -U (for all Postgres command line programs). So you'd need

 createdb -U postgres name_of_new_database 
like image 124
a_horse_with_no_name Avatar answered Sep 17 '22 23:09

a_horse_with_no_name