pg_dump导出psql导入举例

来源:互联网 发布:oracle创建数据库语句 编辑:程序博客网 时间:2024/06/07 03:10
备份:
[postgres9.6@db bin]$ pg_dump -h localhost -U postgres9.6 test > /tmp/test.bak
恢复: 
postgres# drop database test;
DROP DATABASE
[postgres9.6@db tmp]$ psql -h localhost -U postgres9.6 -d test < /tmp/test.bak
psql: FATAL:  database "test" does not exist


postgres# create database test;
CREATE DATABASE


[postgres9.6@db tmp]$ psql -h localhost -U postgres9.6 -d test < /tmp/test.bak
Null display is "NULL".
Pager is always used.
Timing is on.
SET
Time: 0.137 ms
SET
Time: 0.444 ms
SET
Time: 0.085 ms
SET
Time: 0.069 ms
SET
Time: 0.072 ms
SET
Time: 0.060 ms
SET
Time: 0.060 ms
SET
Time: 0.058 ms
CREATE SCHEMA
Time: 5.376 ms
ALTER SCHEMA
Time: 4.268 ms
CREATE SCHEMA
Time: 1.322 ms
ALTER SCHEMA
Time: 4.456 ms
CREATE EXTENSION
Time: 1.637 ms
COMMENT
Time: 1.165 ms
SET
Time: 0.180 ms
SET
Time: 0.106 ms
SET
Time: 0.067 ms
CREATE TABLE
Time: 9.446 ms
ALTER TABLE
Time: 4.524 ms
SET
Time: 0.372 ms
CREATE TABLE
Time: 4.539 ms
ALTER TABLE
Time: 1.581 ms
SET
Time: 4.129 ms
COPY 6
Time: 3.604 ms
SET
Time: 0.110 ms
COPY 0
Time: 0.192 ms
SET
Time: 0.061 ms
GRANT
Time: 1.086 ms
[postgres9.6@db tmp]$ 




[postgres9.6@db tmp]$ psql test a
Null display is "NULL".
Pager is always used.
Timing is on.
psql (9.6.1)
Type "help" for help.


a@[local]:5432 test# select * from test;
 id 
----
  1
  1
  1
  1
  1
  1
(6 rows)


Time: 0.795 ms








[postgres9.6@db tmp]$ pg_restore --host localhost --port 5432 --username "postgres9.6" --dbname "test" --no-password  --verbose "/tmp/test.bak"
pg_restore: [archiver] input file appears to be a text format dump. Please use psql.


一个数据库(或者部分对象)导出为脚本文本文件,用psql恢复。
一个数据库(或者部分对象)导出为归档文件,用pg_restore恢复。
原创粉丝点击