postgresql data backup and recovery

 

In doing recently when data migration, data tables into the encounter, always prompt string too long or sequence problems. It is easy to locate the problem: the character encoding. View the database character encoding by sql statement: select datname, pg_encoding_to_char (encoding) from pg_database. Was found in a UTF8, and the other is SQL_ASCII, you can change the database character encoding, be consistent.  

A first: consistent character encoding and user name of the database.

Second, the transfer of data and then do:

When data migration, by pg_dump command

(1) specify the library specified table pg_dump -d db_name -t table_name -f filename

   恢复:psql -h $host -p $port  -U $user -W $password -d $database < $backup_file 

(2) 压缩 pg_dump -d db_name -t table_name | gzip file_name.gz

   恢复:gunzip -c filename.gz | psql dbname 或者 cat filename.gz | gunzip | psql dbname

(3) cut into small files multi-threaded execution pg_dump dbname | split -b 1m - filename

   Recovery: cat filename * | psql dbname

 

 

 

 

Guess you like

Origin www.cnblogs.com/greys/p/11811678.html