Error while using pg:push to a Heroku PostgreSQL database - postgresql

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.

Related

On any of my Heroku apps, several `heroku pg:` commands fail immediately with “Cannot read property 'includes' of undefined."

(When I asked this previously, it was incorrectly flagged as a duplicate of this one. They are not related.)
On any of my Heroku apps, several heroku pg: commands fail immediately with Cannot read property 'includes' of undefined.
For example:
$ heroku pg:push mydb DATABASE_URL -a $myapp
heroku-cli: Pushing mydb ---> postgresql-vertical-12345
case
------
(1 row)
▸ Cannot read property 'includes' of undefined
$ heroku pg:ps -a $myapp
?column?
----------
(0 rows)
▸ Cannot read property 'includes' of undefined
This started within maybe the past two weeks. I have created/destroyed many apps, always with the same result. My goal is just to be able to push my local data. This error message doesn't exactly give me much in the way of next steps.
Is this a bug, or am I doing something wrong (in which case, how do I fix it)?
I have the same issue here and have created a support ticket, they responded by linking me to your github heroku/cli ticket.
I now see they have updated the docs on how to push a local db and recommend using s3 https://devcenter.heroku.com/articles/heroku-postgres-import-export#import:
Generate a signed URL using the aws console:
aws s3 presign s3://your-bucket-address/your-object
Use the raw file URL in the pg:backups restore command:
heroku pg:backups:restore '<SIGNED URL>' DATABASE_URL
I haven't tried it yet but might be a workaround
just had the same issue.. Updating the CLI fixed it for me. Just need to run heroku update ..

Heroku database restore issue

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.

heroku postgreslq push one table

I have a demo heroku app running rails 4 on the free heroku tier with pgsql.
Somehow, probably due to a bug, a table appears to have been dropped, but I can't find anything in the logs that shows what happened.
Is there a way to restore JUST the missing table via the heroku command line, without blowing away the other data in the dev site? Or is it only possible to push the entire local database to heroku at one time?
If you're running PostgreSQL locally too, you can:
pg_dump -h localhost ... -t thetablename | psql $(heroku pg:credentials DATABASE)
to selectively dump that table locally and restore it to the remote DB.

Heroku pg:pull is giving sh: createdb: command not found

When I try to do heroku pg:pull DATABASE_URL myappspassword, I get this error:
my-computer:a-folder (master*) · heroku pg:pull DATABASE_URL myappspassword
! sh: createdb: command not found
!
! Unable to create new local database. Ensure your local Postgres is working and try again.
For once Googling doesn't return a result. I'm wondering if it's related to the fact that when I do which psql, there is no result. Maybe I need to do something special with pgAdmin to get this working (e.g. export command line tools)?
Are you on a Mac, by chance, and using Postgres App?
If so, the problem might be that createdb isn't on your path. Try adding it by inserting the following into ~/.bash_profile.
export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/9.4/bin
Then run source ~/.bash_profile and try again.
There's more info on the Postgres App site: http://postgresapp.com/documentation/cli-tools.html
Your instincts are correct. You need to be able to access the Postgres from your command line. pg:pull is attempting to create a new local database and drop the relevant data from your Heroku database into it. From the docs:
This command will create a new local database named “mylocaldb” and then pull data from database at DATABASE_URL...
Basically, your local machine is trying to run createdb locally but your terminal isn't recognizing it.
I battled this damn error for a few hours. I can't say for certain if this will work for everyone but I found my issue stemmed from running the command via iTerm/ZSH instead of just normal bash. I opened up plain-old vanilla terminal, ran the command, and everything fired off like it should.

heroku postgres : creating a database off of a backup creates a empty database

We're having trouble with the heroku fork command so are manually trying to create a staging environment. I tried creating a new database off of a backup from our prod db but the created db has no rows and is only 6.4MB. The actual backup is 15.7 GB.
I did this via the web console clicking "restore".
Whats the right way to do this?
From the command line, you want to do:
heroku pgbackups:restore DATABASE -a example-staging `heroku pgbackups:url -a example`
We use this command every few days, whenever we want the staging database to be replaced with the production database. This comes from: https://devcenter.heroku.com/articles/migrate-heroku-postgres-with-pgbackups#transfer-to-target-database