How to see what is in your Heroku-Postgress DB - postgresql

I recently uploaded a WebApplication to Heroku. I developed it using sqlite; however, I then changed it to Heroku-Postgres.
Nonetheless, I am not able to view in any way the data that is in my database.
There are no problems with the code and the WebApplication works perfectly however it would be very useful to be able to tap into the data.

Download the Heroku CLI and get access to the postgres admin console.
heroku pg:psql -a appName
Use this command in terminal, This will connect you to pgadmin console.

You can use dbeaver database client, but it is very slow because it is free db from heroku.
https://dbeaver.io/download/
Or you can use heroku CLI, psql

Related

Accessing Postgresql Database on Heroku After doing git push heroku

Please I need your help.
I have a Django app that is running on heroku.
The Django app initially uses an sqlite3 database.
The local and the remote versions of the app worked fine.
I could access the sqlite3 database on my local machine. However, I have no idea, e.g. an interface, through which I could access the database version that is running on heroku.
Then, I changed the database to Postgresql.
The local version of the database worked fine with the application, as I could see the data being written into the local posgresql whenever I have a need to check the data in the database.
However, I need to be able to see how data is being written into the remote postgresql.
When I try to connect to the database on postgresql, I get an error as shown in the snapshot below.
Please, how can I connect to the database on heroku and see my database.
I am currently using a free heroku account. I hope that is also not a problem?
enter image description here

How to display rows in heroku database?

This page says with this command heroku pg:psql you can see see all the rows.
https://devcenter.heroku.com/articles/getting-started-with-python#provision-a-database
but after using this command I got something like this.
You will have to take a backup of the hosted Postgres DB add-on and restore it to your local machine. Here's a useful article from their site.
Postgres-import-export

Database transfer from Heroku to Digital Ocean

I'm currently in the process of switching my cloud server from Heroku to Digital Ocean. However is there a way to migrate the database from the heroku server to the digital ocean one? I use postgresql for my database
I hope you already got a solution, but in case you didn’t, I’ll provide a simple guide on how I did it. I am going to assume that you have already created a postgres database on digitalocean. Also you need navigate to your project directory and log in to heroku using the heroku cli. And, you need to have postgresql installed or a psql client. Installing postgresql would do it as it comes with psql.
Step 1: Create a backup and download the backup from heroku postgres
heroku pg:backups:capture --app <app_name>
heroku pg:backups:download --app <app_name>
The first command will create a backup of your database and the second command will download it to your current directory, its a .dump file. If you would like to read more, here is an article.
Step 2: Connect to your remote (digital ocean’s) database using psql
Before you can do this, you need to go and add your machine you are connecting from to the list of database’s list of trusted sources, If you don’t, you’ll get a Connection Timed Out error. That’s because the database’s firewall doesn’t allow you to connect to the database from your local machine or resource (for security reasons).
Step 3: Import the Database
pg_restore -d "postgresql://<database_username>:<database_password>#<host>:<port>/<database>?sslmode=require" --jobs 4 -c "/path/to/dump_file.dump"
This will import your database from your dump file. Just substitute the variables will your connection parameters that you get from your dashboard. If you would like to read more, here is another article for this step.
Another thing to make clear is, sometimes, you will see some harmless error messages when running this command, but it will push through anyway. To learn more about pg_restore read this article.
And that’s it, your database has been migrated. Now, can you confirm it worked?, well, as for me, I used pgAdmin to connect to the remote database and I saw the tables and data as expected.
Hope this helps anyone with the same problem :)

How to deploy a FastAPI app using PostgreSQL as a database on Heroku

I developed a FastAPI app in a Virtual Environment using an SQLite database but deployed it on Heroku with a PostgresSQL database on Heroku as suggested in the tutorial. Although it worked on my PC, adding PostegresSQL as an addon & replacing the value of SQLALCHEMY_DATABASE_URL in the database.py broke everything. Note that I've properly frozen the dependencies on the requirements.txt file. Yet I can't figure out what went wrong.
For further clarification, I've pushed my code to GitHub & it can be accessed at this repository - Self_calculation.
If you are using Postgres Addon on Heroku, probably your solution is simple.
Use os.environ to get the connection parameters , don't try to connect directly, it's Heroku's recommended solution from Heroku Postgres
import os
DATABASE_URL = os.environ.get('DATABASE_URL')
I just need to run this:
1)heroku git:remote -a my_heroku_app_name
2)heroku logs --tail
after that I could see my problem.
In my case I forgot to change postgres url in alembic.ini file

Is there a way to copy a postgres db to heroku?

I have a django project that I was initially running on pythonanywhere using a postgres database. However, pythonanywhere doesn't support ASGI, so I am migrating the project over to heroku. Since heroku either much prefers or mandates use of its own postgres functionality, I need to migrate the data from elephantsql. However, I'm really coming up short on how... I tried running pg_dumpall but it didn't seem to want to work and/or the file disappeared into the ether. I'm at a loss for how to make this migration... If anyone could help, I'd appreciate it so much. T-T
After hours of searching and doing what I can to scour heroku's listed info, I found it by running heroku pg:push --help.
For a locally running server, run
heroku pg:push '<db_name>' <heroku_db_name> --app <app_name>
For a hosted one, run
heroku pg:push <postgres_link> <heroku_db_name> --app <app_name>