Restore pg_dump with pgAdmin - postgresql

i'm trying to restore a pg_dump with pgAdmin 4.
this is the command i've used to create the backup pg_dump -U {dbUser} -h localhost -Fc {dbName} > {backupFolder}/{backupName}, but when i try to restore it using pgAdmin i get this:
If i execute the command pg_restore manually i get this error
pg_restore: error: could not read from input file: end of file
I've created the dump on a linux machine and trying to restore it with pgAdmin from a windows machine to the linux machine
any help? thanks!

The problem was actually the ftp method i was using to transfer the dump... The file was a bit bigger after the ftp transfer, fixing the ftp transfer have solved the problem!

Related

pg_dump 0 bytes backup file, stuck after saving database definition

I am trying to backup Postgres database but I always get 0 bytes backup size. If I use the verbose switch, I can see that it is stuck at
pg_dump: saving database definition
I have tried taking backup of specific table and it works fine. Below is my command:
pg_dump -U backupuser -p 5432 -Ft -v -d database > database.tar
I was able to resolve this. When I was creating the backup, I checked the postgres logs and it was clearly written there that during backup the server wasn't reachable. Now to resolve this, I have added a command to restart the postgres before the scheduled backup and it is working fine now.

Importing existing database into new Dokku application

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.

Copying Postgresql DB dump from remote server to local

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.

postgresql dump on ubuntu for user postgres

I'm logged into remote using ssh
ubuntu#ubuntu:~$
now I switch to postgres account using sudo su - postgres command and it send me to postgres#ubuntu:~$
now here I'm able to take dump using pg_dump command.
e.g. postgres#ubuntu:~$ pg_dump db_name > mydbdump.sql
so far looks good. but from here I want to copy this dump file to my local machine or even to my origin/default ubuntu user on remote(ubuntu#ubuntu:~$). so that from there I can scp.
how do I copy these dump sql files from postgres acccount to ubuntu on remote?
If you are using ubuntu, default directory would be /var/lib/postgresql
so you can directly scp from remote to local.
On your local machine run this command
user#user:~$ scp ubuntu#someaddress.com:/var/lib/postgresql/mydbdump.sql /path/to/local/dir

How to restore PostgreSQL database backup without psql and pg_restore?

I am using postgresql on an embedded device running yocto (customized linux). The package containing postgresql does not provide psql or pg_restore. /usr/bin provides the following tools:
pg_basebackup indicates that I am able to create backups. But how am I supposed to restore a backup within a terminal? With pg_restore or psql this would not be a problem for me.
Please note: I want to use a backup created on my windows/linux computer to create the initial database on the embedded device.
Create backup of the db using command:
pg_basebackup -h {host_ip} -D pg_backup -U {USER}
for restoring just change the data folder to pg_backup. Now start the psql server.