PG Bench on Heroku - postgresql

Is it possible to run pgbench on heroku?
I see here it's a CLI argument (not a postgres command)
As of nearly 10 years ago, it wasn't a thing. But is it now? https://github.com/heroku/heroku-pg-extras/issues/7

When you connect to your Heroku database using heroku pg:psql you actually use a psql running locally on your machine to connect to the remote server.
Similarly, you should be able to use a local pgbench even though there isn't a Heroku CLI wrapper for it. Retrieve your database connection information using heroku config:get DATABASE_URL or heroku pg:credentials, then run the command with the common connection options:
pgbench -h HOST -p 5432 -U USER DATABASE_NAME
Since it is a standard URI, you can pull the hostname, username, password, and port out of Heroku's database URL like so:
postgres://user:password#host:port/database

Related

pg_restore -h localhost VS pg_restore -h 127.0.0.1

I was following a tutorial about downloading a db from a heroku app and pairing it with your local version. This was the process:
To view database in Heroku
heroku pg:backups
To download
heroku pg:backups:capture
Public URL
heroku pg:backups public-url
curl `heroku pg:backups public-url`> heroku.dump
Pair db with local repo.
rails db:drop db:create
then run postgres restore command
pg_restore --verbose --clean --no-acl --no-owner -h localhost -d <YOUR DB NAME> ./heroku.dump
Now I have a situation, when I launch a server using localhost, I can access the app and see the added database records. But if I launch a server from 127.0.0.1:3000 , the app is still accessible but no data is retrieved.
I thought that localhost and 127.0.0.1 are not essentially different from each other?
UPDATE
So I have realised why this question is confusing people... and I believe I now have the answer to my question:
localhost and 127.0.0.1 are the same but the configuration in my Rails app is defining localhost as the port to listen to. That is why data is showing up when using localhost but not showing up when using 127.0.0.1.

PgAdmin 4 password-less connection to local database via unix socket

I have initialized a pg database as such:
user_name#my_machine$ sudo -u postgres createuser -s user_name
user_name#my_machine$ createdb -T template0 db_name
I can now connect to it via psql via user_name#my_machine$ psql db_name
and everything works well with the CLI tooling.
The relevant auth line of /etc/postgresql/13/main/pg_hba.conf is:
local all all peer
Now I'd like to connect to it via PgAdmin 4, and I can't find a way to tell the interface that I want to connect via unix socket and don't need a password.
The sanest way I can think is:
but the connection is still rejected with a fe_sendauth: no password supplied.
I know I could configure a password for my user and give it, but I'd like to know if I can make PgAdmin behave properly.
Short answer: put /var/run/postgresql in host name/address.

Unable to connect to docker postgres with password

I am trying to connect to a locally running postgres on docker.
I am running the basic tutorial initialization:
docker run --name some-postgres -e POSTGRES_PASSWORD=mysecretpassword -d postgres
when I try: pgcli -h localhost -U postgres postgres I get password denied. I have also tried with pguser. I have also tried setting the username as well with the same result.
When I try with a generic database application, DBeaver, same result password denied.
I have tried going in to the running container and resetting the password as well: docker exec -it <hash> bash and then manually setting the password again to something simple.
I was getting a similar error with port 5432 (default) and I had a local postgres installation too, which is creating the problem. To avoid the two instances fighting for same port, two things can be done.
Stop instance of local postgres
In docker container postgres path, open postgresql.conf and change default port.
I faintly remember postgresql to
a) have a different password for a postgresql account than the one you have to set for the linux user account and
b) having to activate logging in with a username and password somewhere in the config
Hope this helps, just something off the top of my head

Heroku Postgres database : connecting from outside Heroku

I have added a configured postgres database add-on to a heroku app.
When I try to connect to the database outside the heroku (from my local machine) it always gives an error
SSL SYSCALL error: Connection reset by peer (0x00002746/10054)
I have tried connection from Heroku CLI as well as PGAdmin. I have tried configuring SSL mode to Require.
psql -h ec2-79-125-6-82.eu-west-1.compute.amazonaws.com -U d168639egmjee csjpgbglovnmah
Any idea how can I connect to the postgres DB added in heroku app?
Any help will be appreciated.

Ruby On Rails How to Copy local Postgres db to Heroku

I tried this on RubyMine Terminal:
heroku pg:push ror_development postgres://budobqbtsbzmlx:hUNYKkaMap-cExovtPJat4ajPm#ec2-54-217-208-1 58.eu-west-1.compute.amazonaws.com:5432/dbhsnsvf36h8tu
But its return me error:
Unknown database: postgres://budobqbtsbzmlx:hUNYKkaMap-cExovtPJat4ajPm#ec2-54-217-208-158.eu-west-1.compute.amazonaws.
com:5432/dbhsnsvf36h8tu. Valid options are: DATABASE_URL, HEROKU_POSTGRESQL_ONYX_URL
and also this error:
Connecting to HEROKU_POSTGRESQL_ONYX_URL (DATABASE_URL)
'psql' is not recognized as an internal or external command,
operable program or batch file.
Can somebody show detail sample of doing this action on windows ?
The error message states that you should use the environment variables rather than explicit names. The documentation states you should do something like:
heroku pg:push mylocaldb HEROKU_POSTGRESQL_ONYX
That said, I've never used this technique but did manage to successfully push my local db to heroku postgresql using this procedure.
Here's the short version:
install pgbackups:
heroku addons:add pgbackups
backup your local db:
pg_dump -Fc --no-acl --no-owner -h localhost -U <user> <dbname> > local_pg.dump
upload this file to a web server (I use S3 or dropbox). Let's assume http://www.dropbox.com/me/local_pg.dump
now restore into your heroky db:
heroku pgbackups:restore DATABASE 'http://www.dropbox.com/me/local_pg.dump'