I'm trying to take a cluster backup of my localhost but throwing an exception like below.
Currently using postgres 9.6.2
pg_basebackup -U repuser -h localhost -D backup -Ft -z -P
Error message:
pg_basebackup: unsupported server version 9.6.2
Can anyone suggest me to resolve.
If you have mlocate installed, run locate pg_basebackup, if not run find / -name pg_basebackup. It will give you the list of binaries you have, like:
-bash-4.2$ locate pg_basebackup
/usr/bin/pg_basebackup93
/usr/lib64/pgsql93/bin/pg_basebackup
/home/pg/9.1/bin/pg_basebackup
/usr/share/locale/cs/LC_MESSAGES/pg_basebackup-9.3.mo
/usr/share/locale/de/LC_MESSAGES/pg_basebackup-9.3.mo
then run pg_basebackup with full path, like:
/usr/lib64/pgsql96/bin/pg_basebackup -U repuser -h localhost -D backup -Ft -z -P
Related
I'm using the following command to backup my database (PostgreSQL 11.8):
pg_basebackup -D "C:\\temp" -F tar -X f -z -P -U myUser
And the following to restore:
I manually unpack the base.tar.gz => base.tar
pg_restore -h localhost -W -U myUser -c -C -d myDatabase -F tar -v "C:\\temp\\base.tar"
This results in the following error:
pg_restore: [tar archiver] could not find header for file "toc.dat" in tar archive
What am I doing wrong?
Also, I tried different versions of the restore (only data, etc.) but of course the missing header file issue persists.
Thanks for your help!
You cannot use pg_basebackup and pg_restore together:
pg_basebackup is a physical backup tool
pg_restore can only be used with a logical backup created by pg_dump.
There is no single PostgreSQL command to restore a backup created with pg_basebackup.
To restore a physical backup see https://www.postgresql.org/docs/12/continuous-archiving.html#BACKUP-PITR-RECOVERY
Need help backing up a database in enterprisedb. The pg_dumpall command doesn't work. When I run the command, it says can't connect to the database. I connect to the database and run the command, it doesn't give any errors, but the file doesn't show up in the location I saved it.
Try using pg_dumpall -d dbname -f outputfile.
Or if your database is in a different server, use pg_dumpall -h hostname -p port -U username -d dbname -f outputfile
I've got my own machine with postgres dmp file, which I want to restore on the remote virtual machine (e.g. ip is 192.168.0.190 and postgres port is 5432) in my network. Is it possible to restore this dump using pg_restore without copying dump to remote machine? Because the size of dump about 12GB and the disk space on the virtual machine is 20GB.
Thanks
You can run a restore over the network without copying the dump to the remote host.
Just invoke pg_restore with -h <hostname> and -p <port> (and probably -U <username> to authenticate as different user) on the host you got the dump file, for example:
pg_restore -h 192.168.0.190 -p 5432 -d databasename -U myuser mydump.dump
References:
pg_restore documentation
Alternatively, you can use psql:
psql -h 192.168.0.190 -p 5432 -d <dbname> -U <username> -W -f mydump.dump
An example for a remote RDS instance on AWS
psql -h mydb.dsdreetr34.eu-west-1.rds.amazonaws.com -p 5432 -d mydbname -U mydbuser -W -f mydatabase-dump.sql
-f, --file=FILENAME execute commands from file, then exit
-W, --password force password prompt (should happen automatically)
You can pass the password parameter in your script before "pg_restore" using PGPASSWORD="your_database_password"
I run this and works to me:
scp backup.dump user#remotemachine:~
ssh user#remotemachine "pg_restore -h localhost -p 5432 -U databaseuser -W -F c -d databasename -v backup.dump"
You can write a script to automate this.
i am trying to use Docker. So i installed in Docker postgresql image.
Until now, when i imported osm data into postql i used this command:
psql -U postgres mydb
CREATE EXTENSION postgis;
osm2pgsql -U postgres -d mydb -s -S ./osm_stylesheet /home/ramnikov/Downloads/hessen-latest.osm
How can i do the same inside Docker after this command
$ sudo docker exec -it postgresql sudo -u postgres psql
or before this command ?
Tnx
Andrey
You can execute osm2pgsql outside of Docker:
-H|--host Database server host name or socket location.
As well as psql:
-h, --host=HOSTNAME database server host or socket directory
Like this:
psql -h dockerIP -U postgres -d mydb -c 'create extension postgis'
osm2pgsql -H dockerIP -U postgres -d mydb -s -S ./osm_stylesheet /home/ramnikov/Downloads/hessen-latest.osm
I've got my own machine with postgres dmp file, which I want to restore on the remote virtual machine (e.g. ip is 192.168.0.190 and postgres port is 5432) in my network. Is it possible to restore this dump using pg_restore without copying dump to remote machine? Because the size of dump about 12GB and the disk space on the virtual machine is 20GB.
Thanks
You can run a restore over the network without copying the dump to the remote host.
Just invoke pg_restore with -h <hostname> and -p <port> (and probably -U <username> to authenticate as different user) on the host you got the dump file, for example:
pg_restore -h 192.168.0.190 -p 5432 -d databasename -U myuser mydump.dump
References:
pg_restore documentation
Alternatively, you can use psql:
psql -h 192.168.0.190 -p 5432 -d <dbname> -U <username> -W -f mydump.dump
An example for a remote RDS instance on AWS
psql -h mydb.dsdreetr34.eu-west-1.rds.amazonaws.com -p 5432 -d mydbname -U mydbuser -W -f mydatabase-dump.sql
-f, --file=FILENAME execute commands from file, then exit
-W, --password force password prompt (should happen automatically)
You can pass the password parameter in your script before "pg_restore" using PGPASSWORD="your_database_password"
I run this and works to me:
scp backup.dump user#remotemachine:~
ssh user#remotemachine "pg_restore -h localhost -p 5432 -U databaseuser -W -F c -d databasename -v backup.dump"
You can write a script to automate this.