I'm new to postgresql, and locally, I use pgadmin3. On the remote server, however, I have no such luxury.
I've already created the backup of the database and copied it over, but, is there a way to restore a backup from the command line? I only see things related to GUI or to pg_dumps, so, if someone can tell me how to go about this, that'd be terrific!
You might need to be logged in as
postgres
in order to have full privileges on databases.pg_dump/pg_restore
switch
-F
specify format of backup file:c
will use custom PostgreSQL format which is compressed and results in smallest backup file sized
for directory where each file is one tablet
for TAR archive (bigger than custom format)-h
/--host
Specifies the host name of the machine on which the server is running-W
/--password
Forcepg_dump
to prompt for a password before connecting to a databaserestore backup:
Parameter
-C
should create database before importing data. If it doesn't work you can always create database eg. with command (as userpostgres
or other account that has rights to create databases)createdb db_name -O owner
pg_dump/psql
In case that you didn't specify the argument
-F
default plain text SQL format was used (or with-F p
). Then you can't usepg_restore
. You can import data withpsql
.backup:
restore:
If you create a backup using pg_dump you can easily restore it in the following way:
cd "C:\ProgramFiles\PostgreSQL\9.5\bin"
For example: psql.exe -U postgres -d YourDatabase -f D:\Backup\.sql
POSTGRESQL 9.1.12
DUMP:
put the user password and press enter.
RESTORE:
put the user password and press enter.
Restoring a postgres backup file depends on how did you take the backup in the first place.
If you used pg_dump with -F c or -F d you need to use pg_restore otherwise you can just use
9 ways to backup and restore postgres databases
1.open the terminal.
2.backup your database with following command
your postgres bin - /opt/PostgreSQL/9.1/bin/
your source database server - 192.168.1.111
your backup file location and name - /home/dinesh/db/mydb.backup
your source db name - mydatabase
/opt/PostgreSQL/9.1/bin/pg_dump --host '192.168.1.111' --port 5432 --username "postgres" --no-password --format custom --blobs --file "/home/dinesh/db/mydb.backup" "mydatabase"
3.restore mydb.backup file into destination.
your destination server - localhost
your destination database name - mydatabase
create database for restore the backup.
/opt/PostgreSQL/9.1/bin/psql -h 'localhost' -p 5432 -U postgres -c "CREATE DATABASE mydatabase"
restore the backup.
/opt/PostgreSQL/9.1/bin/pg_restore --host 'localhost' --port 5432 --username "postgres" --dbname "mydatabase" --no-password --clean "/home/dinesh/db/mydb.backup"
try this:
Restore DB psql from .sql file