[Full version] Postgresql database backup and recovery process

0. preparations

The above must be installed on the machine linux pg database 
is then required to pg main directory into the inside environment variable to facilitate the implementation of the command.

1. To back

1 . Backup target database: 
pg_dump -h 10.24 . 193.25 -U Postgres -p 5432   -F c -f / TestPG / TestDS0816.dmp TestDS0816 
# - H to the target server lowercase 
# - U users use uppercase 
# - the p-lowercase pg database the port used by 
# - F c refers only export format is custom format of pg_dump.. 
# - f refer to catalog 
# target database last. 

content man is:
        - F format
        --format = format 
           Selects at the . The Output the format of the format of CAN BE One The following: 

           P 
           Plain 
               the Output A Plain-text SQL script file (the default).

           c
           custom
               Output a custom-format archive suitable for input into pg_restore. Together with the directory output format, this is the most flexible output format in that it allows manual selection and reordering of archived items during restore. This format is
               also compressed by default.

           d
           directory
               Output a directory-format archive suitable for input into pg_restore. This will create a directory with one file for each table and blob being dumped, plus a so-called Table of Contents file describing the dumped objects in a machine-readable
               format that pg_restore can read. A directory format archive can be manipulated with standard Unix tools; for example, files in an uncompressed archive can be compressed with the gzip tool. This format is compressed by default and also supports
               parallel dumps.

           t
           tar
               Output a tar-format archive suitable for input into pg_restore. The tar format is compatible with the directory format: extracting a tar-format archive produces a valid directory-format archive. However, the tar format does not support compression.
               Also, when using tar format the relative order of table data items cannot be changed during restore.

2. Create a user and create a database

Log database 

 psql -U Postgres 

create a user database and create attention and there are a lot of time to create a pit is not case sensitive, but because the recovery is case-sensitive, so you must add a "" double quotes around the database and the user's name . can
(thanks to the platform to assist the Ministry of Liu Wei .. this one fucked me half an hour.)

create a user
create role "TestDS0816" superuser login;
create a database
create database "TestDS0816";
password
alter role "TestDS0816" with password 'Test6530';
exit database command:
\ q

 

3. Perform recovery

-U Postgres -d TestDS0816 /TestPG/TestDS0816.dmp pg_restore 
# -U Uppercase user
# -d lowercase refer target.

 

Guess you like

Origin www.cnblogs.com/jinanxiaolaohu/p/11447639.html