Postgresql Driver does not accept heroku postgres database url - postgresql

I configured the database in application.properties with the spring.datasource.url property, using the DATABASE_URL that I see when running
heroku config
from terminal
I get "Postgresql Driver Claims to not accept JDBC URL" error when running the app from IntelliJ.
Tried solutions in thispost, but none of them helped.

I am deployiong on Heroku Postgres.
I found a working solution in Heroku docs.
The correct jdbc url can be accessed through the heroku cli in your terminal:
heroku run echo \$JDBC_DATABASE_URL
I put the url into src/main/resources/application.properties like this:
spring.datasource.url=<your jdbc url>

Related

How to reset the DB on each deployment on heroku?

So currently I'm working on a project on Heroku with Drupal and my issue is that I want to reset the database each time I deploy to master, yes I know it not ideal but its a development env because I'm working Drupal plugin and it would be nice if changes happened it could just reset to a state.
But when I try to connect using psql and some variables I just get password authentication failed for user even tho I know its the right password because I got it from Heroku itself.
Currently, I have tried using the console to try to make in connection soi could run a DROP TABLE command for me to afterword import an SQL file with the basic setup using pg_dump, and put it into a .sh script and run it with and release: in a procfile
Until now I have this as a release.sh file where I only tried in the console on heroku
PGHOST=HOST PGPORT=5432 \
PGDATABASE=DB \
PGUSER=USER PGPASSWORD=SOMEPASS \
psql
Try below command to reset DB
heroku pg:reset DATABASE_URL

Heroku pg:backups:restore from public_url. Backup not found.

I am trying to copy my local Postgres database to Heroku.
So I use pg:backups:restore from a publicly accessible URL.
As mentioned in the documentation, I have downloaded my Postgres dump to Amazon S3 and gave the public access. The link to file is: https://s3.eu-west-2.amazonaws.com/kirillch/localizedb.sql.
So now I run a command:
heroku pg:backups:restore 'https://s3.eu-west-2.amazonaws.com/kirillch/localizedb.sql' DATABASE_URL -a my_app_name
and get an error:
Backup https://s3.eu-west-2.amazonaws.com/kirillch/localizedb.sql
not found for my_app
What could be done to fix the issue?
For windows users;
heroku pg:backups:restore "https://s3.amazonaws.com/me/items/3H0q/mydb.dump" DATABASE_URL
According to the official docs, be sure to use double-quotes around the remote url if you're using windows. see official docs

Heroku PostgreSQL user and database creation

Currently I have my Ruby on Rails program running great on my Linux Ubuntu development environment, and now I want to run it live on my website, and get it hosted on Heroku.
The problem is that I don't know how to create a user and a database on Heroku. I have tried the command
heroku run rake db:create
I got the error:
permission denied for database - user does nothave connect privilage
I also tried the command
heroku run su - postgres
and it posted that I need to use the terminal so I do not know how to proceed.
This is my database.yml
default: &default
adapter: postgresql
host: localhost
development:
<<: *default
database: app_development
test:
<<: *default
database: app_test
production:
<<: *default
database: app_production
How do I set up my database and the proper connections with my Heroku PostgreSQL database?
i also did this
heroku pg:info
which gave me this
shrouded-reaches-3063 has no heroku-postgresql databases.
also tried this
heroku addons | grep POSTGRES
but nothing was printed
heroku addons:create heroku-postgresql:hobby-dev
! `addons:create` is not a heroku command.
! See `heroku help` for a list of available commands.
also this
heroku pg:wait
and displayed nothing... this really is something T_T really need some major help here , and will be really greatful for any help
Have you provisioned a database? What does heroku addons say? You can create an add-on as documented here with heroku addons:create heroku-postgresql:hobby-dev
!!!NOT IN THE DOCUMENTATION!!!
heroku addons:create heroku-postgresql:hobby-dev --version=12 --app "APPNAME" --name "APPNAME-database"
--app : Specify the heroku app you want to add the database too. Really good if you have more than one heroku app.
--name : The name you would like to give your database. I like to take my application name and postfix it with "database" as a nice convention. Better than whatever randomly generated name you'll get.
APPNAME: A placeholder for whatever your application name is.
No mention of any of this on heroku.com documentation pages for addons in general or postgres addon. I think I came to this via guessing based on documentation for creating apps. But I don't remember. This was in my notes from 5+ years ago. However, I just tried it, still works as of 2022.05.14.

Console access to Dokku's PostgreSQL plugin?

Is there a way to get console access to Dokku's PostgreSQL plugin? On Heroku I'd do heroku pg:psql. Is this possible in a Dokku environment and if so how?
There is in fact a way to do this directly with the dokku-pg-plugin.
The command postgresql:restore <db> < dump_file.sql connects to the specified database and restores it with the provided dump file. If you simply omit the dump file part (< dump_file.sql), a psql console session opens.
Since postgresql:restore <db> is semantically not the best way to open a console session, I have opened a pull request to add the command postgresql:console <db>.
So, until my PR is merged, the options for opening a psql console for a database are either:
doing it manually with psql -h 172.17.42.1 -p <port> -U root db with the <port> and password taken from the output of dokku postgresql:info <db>,
using the semantically incorrect command dokku postgresql:restore <db>, or
use my forked and patched version of the plugin which adds the command postgresql:console <db>.
Edit:
The owner of the dokku-pg-plugin has merged my pull request. If you're using this plugin and are looking for a way to access your PostgreSQL console with it, you might want to update it to the latest version. Once you have done that, you can use the command postgresql:console <db> to open a psql session to the specified database.
This worked for me for my Rails app that I'm running on Dokku:
dokku run <app-name> rails db
That brought up the console for the PostgreSQL container I created (via dokku postgresql:create <db>). I couldn't figure out another way to get at the PostgreSQL instance in that container, short of attempting to directly connect to the DB, with the connection info/credentials listed when you do this:
dokku postgresql:info <db>
I haven't tried that, though I suspect it would work.

Heroku postgresql db sharing between 2 apps error

I can't manage to share two PostgreSQL heroku dbases between two heroku apps.
Doesn't work
What I've tried so far (I'm using the Heroku CLI):
$ heroku config:set DATABASE_URL=`heroku config:get DATABASE_URL -a my-heroku-app-original`
Setting config vars and restarting my-heroku-app... done, v20
DATABASE_URL: postgres://...correct url...
$ heroku config
=== msite-poniai Config Vars
DATABASE_URL: postgres://...correct url...
When I try to access psql, depending on whether I've added a new db or not, I get these two answer (I both cases heroku doesn't see the DATABASE_URL I've just provided.
$ heroku pg:psql
! Your app has no databases.
$ heroku pg:psql
! Unknown database. Valid options are: HEROKU_POSTGRESQL_NEWLYADDED_URL
Works
If I provide psql with the exact location of the db (in this case the original app that has the db as an add-on) it does manage to connect.
$ heroku pg:psql HEROKU_POSTGRESQL_ORIGINAL_URL --app my-heroku-app-original
psql (9.1.9)
I've read
I've closely followed advice given in Share database between 2 apps in Heroku and heroku-postgresql#create-new-db.
Simply copying a config var from one app to another does not attach the referenced database to the app. Were the host or password to change on the first, your second app would be broken. There is a highly alpha plugin you can try https://github.com/heroku/heroku-attachable-resources but it does some weird things like no longer give default names to databases, and overwrites DATABASE_URL if you don't pass in --config and sometimes doesn't let you remove databases.