I've been trying to dump a database file to my heroku app.
I generated a PG dump file by calling
pg_dump mydb > db.sql
Then I uploaded that to an amazons3 and uploaded it to heroku via:
C:\Users\user\Documents\GitHub\gvf-api>heroku pgbackups:restore
HEROKU_POSTGRESQL_GREEN_URL 's3.amazonaws.com/mydb'
The fictional url really works so that's not the issue
I get a Retrieving... done and a Restoring... done message when I run the call.
Problem is no data in the tables.
also I've used the dump file to re-create the database on my local machine successfully.
Any suggestions?
I added the following modifiers to the dump command as suggested here,
pg_dump -Fc --no-acl --no-owner -h localhost -U myuser mydb > mydb.dump
After a few minutes the data did show up.
Related
I have building and testing a psql database on my local machine, and the time is come to move it to a server. I have my dump file, but I'm not sure how to actually get it on the server to restore it there. Obviously something like the following doesn't work:
psql -U user -d datbase < C:/dbbackups/dbbackup.dump
But what is the proper way to get my dump on the server from my local to properly restore it?
You can use pg_dump.
pg_dump -C -h localhost -U localuser dbname | psql -h remotehost -U remoteuser dbname
If you want to use your dump you could of course also transfer your dump file over to the new server securly using e.g. SFTP and then restore it there as you would on your local machine.
I have an existing application that I am trying to port over to Dokku, and part of that is getting the existing data store copied over. I am using the Dokku Postgres plugin, but am having trouble getting the database ported over.
In my existing app I am creating a dump of the database:
// Create dump file
pg_dump app_database > db.dump
// Copy over to server hosting Dokku app
scp db.dump sshdetails
// SSH into new server, then attempt to import dump file
dokku postgres:import db < db.dump
When I run the last command, I get the message:
pg_restore: error: input file appears to be a text format dump. Please use psql.
I have tried formatting the dump in a few different formats but no luck. Any advice would be greatly appreciated. Thanks
From the source of dokku postgres:export command in dokku-postgres plugin :
docker exec "$SERVICE_NAME" env PGPASSWORD="$PASSWORD" pg_dump -Fc --no-acl --no-owner -h localhost -U postgres -w "$DATABASE_NAME"
The dokku postgres:export command have -Fc argument for pg_dump which export dump as archive suitable for input into pg_restore (more information into pg_dump man page) and pg_restore command seems to only accept custom format from pg_dump (cf. pg_restore man), so you should use the same -Fc argument in pg_dump command.
I want to take a DB dump from a remote server and then copy this dump to my local.
I tried couple of commands but didn't worked.
Lastly I tried the command below;
pg_dump -h 10.10.10.70 -p 5432 -U postgres -d mydb | gzip > db1.gz
I succesffully take the DB and tried with restore from Pgadmin, it gives;
pg_restore: error: input file appears to be a text format dump. Please use psql
But at this point I can't use psql, I have to use Pgadmin and not sure if I'm able to get successfully DB dump to my local. I mean I can't verify with restore.
How can I take DB dump from remote server to my local?
Thanks!
Use the "custom" format:
pg_dump -F c -h 10.10.10.70 -p 5432 -U postgres -f mydb.dmp mydb
That can be restores with pg_restore and hence with pgAdmin.
You do not have to use pgAdmin. pgAdmin uses pg_restore, and there is nothing that keeps you from using it too.
I am attempting to restore a local snapshot of a database into a heroku dev instance.
heroku pgbackups:restore --app app_name HEROKU_POSTGRESQL_AMBER_URL https://www.dropbox.com/etc
But I consistently receive the following error
HEROKU_POSTGRESQL_AMBER_URL <---restore--- db.dump
Retrieving... done
! An error occurred and your restore did not finish.
The database snapshot was captured using the pg_dump string in the heroku docs:
PGPASSWORD=pwd pg_dump -Fc --no-acl --no-owner -h localhost -U postgres db > db.dump
and the dump file is in a dropbox share (so available with direct URL access)
Both Heroku and the local database are PG 9.2.
Heroku logs contain all of the output from pgbackups, which will help track down the issue.
I have a java app and postgresql database to go with it that is running on Heroku. I can push my app just fine, but what about the DB contents? I have exported a full dump from the database, but I don't know how I could import that.
By googling, you can find about db:push which is a limited rubygem, not pushing all the stuff needed. I have sequences, bigint datatypes etc. I also tried importing using heroku pg:psql --app MYAPP < db_all.out which just connects and stops, and going to heroku pg:psql --app MYAPP and issuing \i db_all.out complaints about permissions.
How should I do it?
You can run the pg_restore command from your local machine using the credentials given by heroku pg:credentials HEROKU_POSTGRESQL_<COLOR>.
To help others who still stumble upon this issue, what works for me is hgmnz's answer, but with a few modifications.
To be more precise:
Create a dump from the source PostgreSQL database
$ PGPASSWORD=YOUR_PG_PASSWORD pg_dump -Fc --no-acl --no-owner -h localhost -U YOUR_PG_USER YOUR_DB_NAME > YOUR_DB_NAME.dump
Get the Heroku Postgres credentials for your heroku app
$ heroku pg:credentials:url -a YOUR_APP_NAME
Attempt to import PostgreSQL dump to Heroku using the credentials above
$ pg_restore --verbose --clean --no-acl --no-owner -h HOSTNAME -U USER -d DATABASE -p PORT PATH/TO/YOUR_DB_NAME.dump --password
Enter the password received from the Heroku Postgres credentials
It should then import the dump successfully
This is very simple and had worked for me:
heroku pg:psql -a {YOUR_APP} -f {YOUR_DUMP_PATH}
I find this a better way then using the standard input syntax (like in the OP example), since it uses an option given by the Heroku command itself.
You may want to check if your dump file it's OK before submitting (in my case it wasn't).