I want to destroy the database but I'm not sure what the command would be. Does anyone know how to do this?
You shouldn't use a postgres command to fully delete your database, as you will not have permissions to create a new one. Instead you should use the heroku command to clear out your database:
heroku pg:reset DATABASE_URL
None of the answers above actually describe how to destroy a Heroku database, which was the original question (and what led me here seeking an answer).
From their docs, either of these will work:
heroku addons:destroy heroku-postgresql:tier (where tier is the database tier, like hobby-dev)
heroku addons:destroy HEROKU_POSTGRESQL_<COLOR> (if you have more than one database of that tier)
Note that because this is a destructive action it will prompt you to confirm the action. If you want to use this in a script you can skip the prompt with something like this:
heroku addons:destroy HEROKU_POSTGRESQL_<COLOR> --confirm <appname>
Hope that's helpful!
To answer Siamii's question above: DATABASE in heroku pg:reset DATABASE is by default postgres
Simply follow the steps below. Run
heroku pg:reset DATABASE
to recreate the database with nothing in it, then run
heroku run rake db:migrate
to initialize the database with the correct schema & data.
Look at the new heroku documentation it helps ;)
Related
I need to upgrade my Heroku Postgresql database to the Basic plan. I've found the command in Heroku's docs, but I'm not sure if I need to change it to affect my account. My app's name on Heroku is tranquil-mountain-51138
heroku addons:upgrade HEROKU_POSTGRESQL_LAVENDER_URL heroku-postgresql:premium-0 -a sushi
Do I need to change this terminal command to include my app's name and the Basic db plan? If so, could you give me the edited version. My guess would be that I change premium-0 to basic. I've no idea what the rest of the command refers to: HEROKU_POSTGRESQL_LAVENDER_URL and sushi
It is a very small personal app. I'm the only one using it, so I've no worries about down time when the maintenance starts.
Thanks for any help.
Finally received a response from Herouku HelpDesk that explains the parts of their example command for upgrading a db.
Their example: heroku addons:upgrade HEROKU_POSTGRESQL_LAVENDER_URL heroku-postgresql:premium-0 -a sushi
$heroku addons:upgrade DATABASE_URL <database-type> -a <app-name>
For my app, upgrading to their Basic plan, the command is:
$heroku addons:upgrade DATABASE_URL heroku-postgresql:basic -a tranquil-mountain-51138
Hope this helps others.
I have recently started working on an existing Heroku environment.
How can I tell if there are database backups scheduled?
Assuming you are using Heroku Postgres, you can view backup schedules with the following command:
heroku pg:backups:schedules
You might have to provide the --app argument so Heroku knows which app you're interested in.
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
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 :)
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>