postgres heroku, no response - postgresql

I'm just getting started with postgres, sorry for the very novice question.
I have the my heroku psql databade initiated and postgres client installed, but nothing really seems to responding and printing any response other than $ help. Is there anything I need to do after installing the postgres client?
I'm following this post: heroku_postgres database create table
And the command i'm trying is: psql -h XXXXXXX -U XXXXXXXX XXXXXXXX
EDIT: heroku pg:psql
---> Connecting to HEROKU_POSTGRESQL_MAROON_URL (DATABASE_URL)
sh: psql: command not found

Did you try running heroku pg:psql ?

Related

With Gitpod, Heroku Postgres returning Error: FATAL: role ... does not exist

I have a Heroku app and it has a Heroku postgres addon attached. Im trying to connect to the remote heroku database from the Gitpod (online IDE) command line.
heroku pg:psql -a my-heroku-app
But its giving the following error:
--> Connecting to postgresql-rigid-XXXXX
psql: error: could not connect to server: FATAL: role "xxxxxxxxxxxxxxx" does not exist
And I get the same error when I try to connect with the connection URL
psql postgres://xxxxxxxxxxxxxxx:ppppppppppppppppp#ec2-0000000000.compute-1.amazonaws.com:5432/ddddddddddddd
I have properly installed postgres and heroku-cli in Gitpod and they work fine.
Appreciate your help.
Thanks!
Ok I found the answer thanks to this and this.
heroku pg:psql does'nt seem to work in Gitpod. So I followed this to import a db dump file into heroku postgres. From Gitpot command line I did
pg_dump -Fc --no-acl --no-owner -h localhost -U myuser mydb > mydb.dump
and got the db dump file from my local (Gitpod) database. Uploaded it to my google drive and got the publicly downloadable link. Then did
heroku pg:backups:restore https://drive.google.com/u/0/uc?xxxxxxxx DATABASE_URL -a my-heroku-app
Now I have all the data in my heroku postgres database.
Cheers!

psql connection to AWS PostgreSQL 10.4 results in pw auth failed?

Question
I set up an AWS RDS PostgreSQL 10.4 database. The dataset is in a private network, therefore, I use a bastion to forward the connection to it. I can then connect using Postico but not using psql.
Details
I installed PostgreSQL locally using brew install postgres. The command output is (and on a AWS instance see update):
❯ psql --version
psql (PostgreSQL) 10.5
Then I use the following SSH command to tunnel:
ssh -q -o "ConnectTimeout 3" -o "StrictHostKeyChecking no" -o "UserKnownHostsFile /dev/null" -i bastion-key.pem -L 5432:xxxxxx.xxxxx.eu-central-1.rds.amazonaws.com:5432 ec2-user#xx.xx.xx.xx -N
Then I connect using Postico .. everything fine!
Last but not least I try to connect using the following command:
❯ psql \
--host=127.0.0.1 \
--port=5432 \
--username=USERNAME \
--password \
--dbname=DBNAME
Password for user USERNAME:
psql: FATAL: password authentication failed for user "USERNAME"
FATAL: password authentication failed for user "USERNAME"
I use a macOS High Sierra Version 10.13.6 Macbook 13".
Update 2018-12-05:
Tried it also from a Amazon image running Amazon Linux release 2 (Karoo) same result with psql 9 as version 10. Version 10 was installed following this recommendation.
Solved, still a really shitty problem!
I generated my PostgreSQL passwords using secrets.token_urlsafe(90) Python3 method, which resulted in strings including [_-] which psql could not handle.
Using secrets.choice(string.ascii_uppercase) 1 with the right selection solved the problem!
Long story short: Use only characters and digits for your password and you will have no problems!

PostgreSQL: Can't log into Postgres - sudo broken?

Hey so after I ran into somes issues I decided to uninstall Postgres and re-install it (re install a newer version btw).
I'm trying to access postgres to create a new db for my Rails app so I run su postgresor su _postgres then I am asked a password but nothing that I enter works.
So I tried sudo -u postgres psql and got
sudo: unknown user: postgres
sudo: unable to initialize policy plugin
I tried also to disable SIP (see: here)
but it didn't work either. same results.
I don't know what to do. Any idea ? I am using Mac OS High Sierra 10.13.6.
Thanks to #gordon Davidson and #wildplasser 's help, I found the solution:
sudo -u myusername psql postgres
I had this same challenge when trying to access a PostgreSQL database.
When I run the command below:
sudo -u postgres psql
I get the error below:
sudo: unknown user: postgres
sudo: unable to initialize policy plugin
The issue was that I did not have the PostgreSQL database server installed on the server. The server only had a MySQL database server set up on it.
That's all.
I hope this helps
From your EC2 node issue the following command to test if database is reachable.
/opt/gitlab/embedded/bin/psql -U YourExistingUsername -d template1 -h AWS-RDS-POSTGRES-ENDPOINT

Importing a postgresql dump to Heroku

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).

Redmine postgresql FATAL: Ident authentication failed for user "redmine"

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.