Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

heroku pg:pull password authentication failed

I'm trying to run the heroku pg:pull command, but I can't seem to get the amazingly cryptic authentication process.

The command I'm running:

> heroku pg:pull app_name::RED localdb

I then get a password prompt, which I can't, for the life of me, figure out. After 2 guesses I get password authentication failed for user "Hanan", and that's it.

I tried Heroku's password, my Windows account password, every password I use, but nothing happens. I checked, and "Hanan" is not a role in Postgresql, so trying to change the password through psql doesn't work. I have no problem logging in to Postgresql through other roles, but it's this 'default' log-in process which I can't seem to crack.

Also, since I'm using windows, I'm not sure how to run commands like sudo -u postgres psql, which I see as a possible solution.

Will appreciate any help regarding this issue, I'm really frustrated by now...

like image 452
hananamar Avatar asked Jan 19 '14 17:01

hananamar


4 Answers

I'm using Windows 10, 64-bit, Powershell and had to use the following commands to properly set the local PostgreSQL environment variables:

C:\> $Env:PGUSER="[pg_username]"  
C:\> $Env:PGPASSWORD="[pg_password]"  

To verify that these are set properly, list all local environment variables with this:

C:\> Get-ChildItem Env: 

After doing this, I was able to run heroku pg:pull without being prompted for a password.

like image 146
Paul Maurer Avatar answered Oct 19 '22 09:10

Paul Maurer


Apparently it's possible to set the environment variables PGUSER and PGPASSWORD, as described here.

However, this won't work on windows in the given syntax. To do this on windows run the following:

SET PGUSER=[pg_username]

SET PGPASSWORD=[pg_password]

after entering these two lines Postgres will log you in with the given authentication info, instead of trying to sign in with the windows username

like image 32
hananamar Avatar answered Oct 19 '22 10:10

hananamar


The previous answers did not work for me or were not to my liking so I kept searching. Thanks to the answer provided by Rayz on this post How to add a user to PostgreSQL in Windows? I was able to come up with this one liner for windows powershell.

 & { $env:PGUSER="username";$env:PGPASSWORD="password"; heroku pg:push local-db DATABASE_URL --app heroku-app}

You apparently have to pass the variables as a list seperated by semicolons, surrounded by braces which are preceeded by an ampersand. Your funtion (heroku pg:pull/ pg:push/...) has to be a member of the list. As of my current testing it works in powershell with pg:push and the order of items within the braces does not matter.

like image 36
Rad Avatar answered Oct 19 '22 11:10

Rad


I've run into this problem a lot when running heroku pg:pull. The issue in my case was that the pg:pull command only works if my local PostgreSQL server has a password set.

To set a password, run psql localdb and execute this SQL:

ALTER USER my_user_name with password 'my_new_password';

(You won't necessarily be required to use this password all the time. Run psql localdb and see whether you're prompted; in my case, I can still log in to psql without the password.)

Now run heroku pg:pull --app my_heroku_app POSTGRESQL_COLOR localdb, and enter your new password (twice) when prompted.

like image 7
joel3822021 Avatar answered Oct 19 '22 11:10

joel3822021