I know similar questions have been asked but none of the solutions have worked. I am trying to push my local db to my Heroku db, and I keep getting psql: FATAL: password authentication failed for user "windows username".
I am on windows, so I tried SET PGUSER=postgres SET PGPASSWORD=password
Then ran heroku pg:push localdb DATABASE_URL --app herokuapp
But am still getting this stupid password error. The thing is it still looks like it is using my windows user name and not postgres username.... how do I resolve this?
Thanks to Heroku support I was finally able to get this to work. So for Windows users, these are the steps:
First you want to dump your local database out to a dump file:
pg_dump --verbose -F c -Z 0 -U postgres -h localhost -p 5432 yourdbname > local.dump
Then you want to grab the connection string from your heroku application config vars:
heroku config:get DATABASE_URL
Then you want to pick out the username / hostname / databasename parts from the connection string, ie: postgres:// username : password # hostname : port / databasename
One warning, running this against a production database with real data is something you want to avoid so be careful with pg_restore. When running this manually you run the risk of mangling your data without the CLI check, so you may want to manually verify that the target database is empty first.
pg_restore --verbose --no-acl --no-owner -U username -h hostname -p 5432 -d databasename < local.dump
Then when prompted for a password, just paste in the password from the connection string
Run SET PGUSER=postgres. This is important as otherwise heroku will use a different user and your password will not work.
Run heroku pg:push localdb DATABASE_URL --app herokuapp
Enter your password for postgres when it prompts.
I just faced the exact same problem and was successful in resolving this.
Rather than use the single line 'heroku pg:push' command with / without username/password, I relied instead on 2-steps:
Step-1: pg_dump
Step-2: pg_restore
This as pointed out by https://stackoverflow.com/users/4051445/na-peters above
as well as briefly hinted by Heroku at:
https://devcenter.heroku.com/articles/heroku-postgresql#pg-psql
Key thing is the password to enter is NOT the password you'd use when accessing your local Postgresql database. Instead, the password is a 64-character string you will obtain from:
heroku config:get DATABASE_URL -a
To extract it follow instructions by NA Peters above (it is the y string between : and # in the postgres://xxxxxxx:yyyyyyyyyyyyyyyyyyyyyyyy#hhhhhh:5432/dddddd
Expect it to work
For you Windows PowerShell folks out there struggling with the restore, try:
Get-Content -raw local.dump | pg_restore -F c --verbose --no-acl --no-owner -U <username> -h <hostname> -p 5432 -d <databasename>
Then paste the password in when prompted.
Related
after hours of searching through Google I couldn't find a working solution to my problem.
I am using Heroku with Postgres the very first time and want to download a database backup and store it locally. I followed the instructions from here https://devcenter.heroku.com/articles/heroku-postgresql#local-setup but I fail when importing the backup into my local db.
I did heroku pg:backups:download --app appname and received the file on my desktop. Now when doing pg_restore --verbose --clean --no-acl --no-owner -h localhost -U myuser -d mydb latest.dump I have to enter a password but I don't know which password I have to enter here. I already tried to set the username + password as variable but I am always ending up with a failed authentification. I also tried heroku pg:pull DATABASE_URL localdb --app appname but the story is the same as above.
Can anyone please clarify how I can do this?
I am new to Postrgresql. I want to create a backup of a production database and restore it in my development instance. Before I touch production, however, I want to make and restore a backup in development. I figured this would be a trivial effort, but that has not been the case.
I connected to psql using the command below.
sudo -u postgres psql
I ran the following command to create my backup inside psql.
\ pg_dump -U postgres -d dbname > /tmp/kp.bak
I included the "!" with the ""of the command above, but Stackoverflow is having trouble rendering that combination of characters
After that it prompted for a password. When I give it the correct password I get the following error. I reset the password for the PostgreSQL user using the ALTER PASSWORD command, so I know I have the correct password.
FATAL: password authentication failed for user "postgresql"
Since that doesn't work, I configured the pg_hba.conf to not require one and restarted the service. This has had no effect, as I am still prompted for a password when I try to restore. This is the first uncommented line in pg_hba.conf.
local all all trust
Here is the command I am using to do the restore.
\ pg_dump -U postgresql -h localhost -f \tmp\kp.bak dbname;
I am at a loss at how to move forward with this. Can anyone tell me what I am missing?
Thanks
Starting psql just to shell out to pg_dump doesn't make any sense. Just do it directly:
sudo -u postgres pg_dump ....
But once you have moved away from "peer" as your authentication method, there is no point in using the sudo at all, so just do it even more directly:
pg_dump ....
FATAL: password authentication failed for user "postgresql"
I don't find it believable that you specified -U postgres, yet the error message says user "postgresql". Please double check your post for spelling and typing errors.
I eventually got it to work with the following commands
sudo -U postgres psql
Then
\! pg_dump -U postgres -d dbname > /tmp/dbname.bak
Doing this outside of psql did not work. I received the following error despite running with sudo.
bash: /tmp/dbname.bak: Permission denied
In Ubuntu 16.04 I created second postgres database cluster, called cmg, with a local user as the admin user:
pg_create -u "local_username" -g "local_usergroup" -d /path/to/data/dir 9.5 cmg
The cluster was started with:
pg_ctrlcluster 9.5 cmg start
which ran successfully (pg_lsclusters show both are online)
The problem is I cannot connect to the cluster using psql as is normally done.
I tried using:
psql -h 127.0.0.1 -w -p5433 -U local_username
which fails with:
psql: fe_sendauth: no password supplied"
Is there any way to connect to the specific cluster?
use psql -h your_socket_dir -p5433 -U postgres to connect locally (uses peer auth by default - thus high chahce to login wothout password)
once logged in - set up password (create user if needed) and use it connecting remotely
psql -h 127.0.0.1 -p5433 -U local_username
in your connect string you had -w which is never ask for a password https://www.postgresql.org/docs/current/static/app-psql.html which would by default work only for local connections
I think the default pg_hba.conf when you start up a new cluster expects you to authenticate with peer connections, so you need to change user to your local user before connecting
[root#server~]# su - local_username
>> Enter password:
> password
[local_username#server~]# psql -h 127.0.0.1 -p 5433
You can check your pg_hba.conf file in /path/to/data/dir/pg_hba.conf to see how it expects you to authenticate.
Alternatively, if you cannot get access as your 'local_username' then instead su to postgres user in the instructions above and it should work
I have a java app and postgresql database to go with it that is running on Heroku. I can push my app just fine, but what about the DB contents? I have exported a full dump from the database, but I don't know how I could import that.
By googling, you can find about db:push which is a limited rubygem, not pushing all the stuff needed. I have sequences, bigint datatypes etc. I also tried importing using heroku pg:psql --app MYAPP < db_all.out which just connects and stops, and going to heroku pg:psql --app MYAPP and issuing \i db_all.out complaints about permissions.
How should I do it?
You can run the pg_restore command from your local machine using the credentials given by heroku pg:credentials HEROKU_POSTGRESQL_<COLOR>.
To help others who still stumble upon this issue, what works for me is hgmnz's answer, but with a few modifications.
To be more precise:
Create a dump from the source PostgreSQL database
$ PGPASSWORD=YOUR_PG_PASSWORD pg_dump -Fc --no-acl --no-owner -h localhost -U YOUR_PG_USER YOUR_DB_NAME > YOUR_DB_NAME.dump
Get the Heroku Postgres credentials for your heroku app
$ heroku pg:credentials:url -a YOUR_APP_NAME
Attempt to import PostgreSQL dump to Heroku using the credentials above
$ pg_restore --verbose --clean --no-acl --no-owner -h HOSTNAME -U USER -d DATABASE -p PORT PATH/TO/YOUR_DB_NAME.dump --password
Enter the password received from the Heroku Postgres credentials
It should then import the dump successfully
This is very simple and had worked for me:
heroku pg:psql -a {YOUR_APP} -f {YOUR_DUMP_PATH}
I find this a better way then using the standard input syntax (like in the OP example), since it uses an option given by the Heroku command itself.
You may want to check if your dump file it's OK before submitting (in my case it wasn't).
Following the these instructions (using postgresql instead of mysql):
http://www.redmine.org/projects/redmine/wiki/Redmine_on_CentOS_installation_HOWTO
when run this command :
RAILS_ENV=production bundle exec rake db:migrate
rake show an error message:
FATAL: Ident authentication failed for user "redmine"
??
It should not be necessary to modify pg_hba.conf for redmine. First check that your database role is configured correctly:
su - postgres
psql -d redmine -U redmine -h localhost
<password challenge>
If the password is accepted, then the next step is to confirm that you have libopenssl-ruby installed.
You should have the postgres user name the same as your linux username
It's easier than modifying "pg_hba.conf" file
This works for me:
psql redmine redmine -h localhost
The -h localhost part makes the difference.