1:备份
pg_dump -Fc --inserts -h 192.168.1.1 -U postgres -f small_data2.backup -v -C small_data
注意如果不加-Fc 则文件格式是sql语句
2:查看备份文件信息
pg_restore -l small_data2.backup
不是-Fc创建的文件报错:
pg_restore: [归档] 输入文件看上去不象有效的归档
3:还原数据库方法1
3.1创建数据库
CREATE DATABASE small_data
WITH OWNER = recluser
ENCODING = 'UTF8'
TABLESPACE = table_space_20
LC_COLLATE = 'Chinese (Simplified)_People''s Republic of China.936'
LC_CTYPE = 'Chinese (Simplified)_People''s Republic of China.936'
CONNECTION LIMIT = -1;
3.2还原数据库
pg_restore -C -d small_data -v -h 127.0.0.1 -U recluser small_data2.backup
pg_restore --host localhost --port 5432 --username "postgres" --dbname "data_a" --role "usera" --no-password --verbose "data_a_fc.backup"
4还原数据库方法2
4.1创建数据库
4.2还原不加-Fc备份的文件
psql -U postgres < small_data.backup
pg_dump -Fc --inserts -h 192.168.1.1 -U postgres -f small_data2.backup -v -C small_data
注意如果不加-Fc 则文件格式是sql语句
2:查看备份文件信息
pg_restore -l small_data2.backup
不是-Fc创建的文件报错:
pg_restore: [归档] 输入文件看上去不象有效的归档
3:还原数据库方法1
3.1创建数据库
CREATE DATABASE small_data
WITH OWNER = recluser
ENCODING = 'UTF8'
TABLESPACE = table_space_20
LC_COLLATE = 'Chinese (Simplified)_People''s Republic of China.936'
LC_CTYPE = 'Chinese (Simplified)_People''s Republic of China.936'
CONNECTION LIMIT = -1;
3.2还原数据库
pg_restore -C -d small_data -v -h 127.0.0.1 -U recluser small_data2.backup
pg_restore --host localhost --port 5432 --username "postgres" --dbname "data_a" --role "usera" --no-password --verbose "data_a_fc.backup"
4还原数据库方法2
4.1创建数据库
4.2还原不加-Fc备份的文件
psql -U postgres < small_data.backup