Heroku database restore issue - postgresql

Have gone through different solutions available on stackoverflowand also on different forums. But none addresses the precise problem.
As per the documentation: https://devcenter.heroku.com/articles/heroku-postgres-import-export
I have the dump file created from my local database, with this command:
pg_dump -Fc --no-acl --no-owner -h localhost -U postgres dss_iaya>dss_iaya_db_dump1.dump
Then as per documentation, uploaded to a server with public access URL: https://firebasestorage.googleapis.com/v0/b/iaya-664f3.appspot.com/o/dss_iaya_db_dump1.dump?alt=media&token=06167d04-1e98-4e4b-b0e0-9d83a86dd167
Now when I try to restore on Heroku as per its documentation syntax heroku pg:backups:restore [BACKUP] [DATABASE] --app APP using following command, it returns error message when restoring.
heroku pg:backups:restore --app heroku-postgres-*** 'https://firebasestorage.***/dss_iaya_db_dump1.dump?alt=media&token=***' 'postgres://quesu***:I***#ec2-54-***.eu-west-1.compute.amazonaws.com:5432/d3n***k0'
I have used *** for security purpose only, as can not mention full credentials. But I believe one can understand the whole syntax.
When I restore same .dump file on a newly created local database it works without any issues and creates/restores the whole database with tables and data.

Just found the solution, actually two things were wrong in my case.
One, the uploaded .dump file was not well readable/usable by the heroku.
Two, the heroku postgresql DB complete URL was not required to be provided.
So, the right way that worked for me was that the uploaded file should be accessible without any token and also without any virtual/indirect path, etc. The URL to the file should point to the file directly. In my questioned problem, I was using firebase to host my DB file temporarily to do the heroku operation. And firebase was not giving direct URL to the uploaded physical file.
heroku pg:backups:restore --app heroku-postgres-f3*** 'https://www.h***.com/dss_iaya_db_dump2.dump' DATABASE_URL
After typing this command, I was asked to retype the heroku app name just to confirm the operation. Once done, everything worked like a charm.

In logs you see dump size: 0 Bytes. Also you see aborting and 403,
so if you check your file: https://llfirebasestorage.googleapis.com/vo/b/iaya-664f3.appspot.com/0/dss_iaya_db_dump1.dump?a1t=media
you get:
404. That’s an error.
The requested URL /vo/b/iaya-664f3.appspot.com/0/dss_iaya_db_dump1.dump was not found on
this server. That’s all we know.

Related

Error while using pg:push to a Heroku PostgreSQL database

I'm trying to push a local PostgreSQL database to one I've created on a Heroku app. To set up the Heroku database, I ran heroku addons:create heroku-postgresql:hobby-dev -a jasons-react-jobly-app, where jasons-react-jobly-app is the name of my Heroku app.
Then I ran heroku pg:push jobly DATABASE_URL -a jasons-react-jobly-app, where jobly is the name of my local database.
This throws the below error:
heroku-cli: Pushing jobly ---> postgresql-animate-30221
case
------------------------------------
0.9992547478473790.999254747847379
(1 row)
! Cannot read property 'includes' of undefined
The error looks like an error that JavaScript throws when it tries to read properties of an undefined object or something, but I'm not sure where that would be happening in this database push. The app runs completely fine on my local machine with no errors. There is no case column in any of my database tables, so I'm not sure where that number is coming from either.
Also, if I check my Heroku config variables with heroku config, I see:
DATABASE_URL: postgres://iqawqkjfiybndd:c3e921131c239ccd6c880ad4b601deeaa4558339a90ebedc562a5575c9099f42#ec2-54-156-85-145.compute-1.amazonaws.com:5432/dul2u6r13aq5i
So I know the database exists.
Any help with solving this error?
You need to fetch the name of the DB that you see attached to the heroku app on heroku dashboard.
At this url https://dashboard.heroku.com/apps/{put-your-app-name-here}/resources
To get all app names in heroku cli do heroku apps and you will know which app's DB name you want from its dashboard.
Once you have the name of the DB (it will look like this "postgresql-pointy-81624")
use that name in the command to push local db to that db on heroku .
Here are steps to make sure everything works correctly
1- Check the connectivity to the heroku db first by doing
heroku pg:psql postgresql-[somedb name as found above] --app {your-app-name}
2- If it says to reset the DB and you can afford to reset then reset it using
heroku pg:reset -a {your-app-name}
3- Lastly do the migration of DB using this command
heroku pg:push jobly postgresql-[db name found above] -a {your-app-name}
if everything works as expected you will see this message
heroku-cli: Pushing complete.

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

Heroku pg:restore failing to find dump file?

I am having troubles restoring my backups to the heroku database via an external dump file. I run this command:
heroku pg:backups:restore 'https://s3.us-east-2.amazonaws.com/some-bucket/some-dump.dump' DATABASE_URL
And I get this error in return:
Backup 'https://s3.us-east-2.amazonaws.com/some-bucket/some-dump.dump' not found for some-heroku-app
I can access the file from the browser, but it seems that pg:backups can't access the file. I've also tried different methods of hosting the file (including a private FTP server and Dropbox).I've searched for other people with the same problems, but none of the questions seemed to be answered

How I can copy my local PostgreSQL database to Heroku for SpringBoot app

I have deployed my SpringBoot app to Heroku. Now I would like to copy my local PostgreSQL to Heroku.
I have found some information on devcenter.heroku.com.
However I don't understand enough about the using of file db.changelog-master.yaml.
Could anyone give me details about the simplest solutions to copy the database?
Create a valid dump of your local postgres database and host it somewhere publicly available. Now you will be able to restore this entire dataset (schema and records) with pg:backups:restore as shown here. The sole caveat here is that the target database must be completely empty for this to work. You can empty a Heroku postgres database with heroku pg:reset.
If you cannot take the approach listed above then you can run pg_restore directly from your local instance, provided your local version of Postgres is >= the target version of Postgres. This also applies to creating the dumpfile and is a requirement because pg utilities are not guaranteed to be forward compatible. Documentation for pg_restore is here.

HEROKU: What to do with my dump file (PGBACKUPS)

I'm done with the pgbackups process.
First, I installed the pgbackups addon (HEROKU)
via command: heroku addons:add pgbackups
Second, I login using heroku auth:login command
Third, I capture the backup by running the command: heroku pgbackups:capture --app myapp
Fourth, I get the url of the backup by
heroku pgbackups:url b002
So I accessed the url that I saw after running the command: heroku pgbackups: url b002
in this format: https://s3.amazonaws.com/hkpgbackups/app2955630#heroku.com/b002.dump?AWSAccessKeyId=.......
something like that.
After that, I downloaded the file in .dump format
So now, I have the dump file and dont know what to do where to specifically use it...
Can somebody give me an advise to how to use the .dump file?
Please help me. I'm in trouble right now. I've to get a copy of our existing database from heroku.
Your .dump file should be a pg_dump file so you'd need to set up PostgreSQL somewhere and then use pg_restore to load the .dump file into your local database.