pg_dump导出psql导入举例
2017-09-13 21:46
441 查看
备份:
[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恢复。
[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恢复。
相关文章推荐
- PG数据库之间的导入导出(pg_dumpall,pg_dump,psql,pg_restore)
- PostgreSQL pg_dump&pg_restore 数据的导出和导入
- oracle导入和导出遇到may be an original export dump file的问题
- redis中使用redis-dump导出、导入、还原数据实例
- PostgreSQL数据库导出命令pg_dump详解
- Oracle:dump文件导入报错:只有DBA才能导入由其他DBA导出的文件
- Oracle创建用户、表空间、导入导出数据的命令举例
- PG数据库之间的导入导出
- PostgreSQL pg_dump&psql 数据的备份与恢复
- Oracle数据泵(Dump)导出、导入
- myqldump 导入导出数据库
- 导入和导出表空间:复制文件比mysqldump&restore快
- mysql账号增删改、数据导入导出命令举例
- 有关于postgresql的pg_dump导出命令
- mysql 导入(mysql.exe)导出(mysqldump.exe)
- dump数据泵导入导出(并发)
- PostgreSQL:pgloader导入导出处理重复数据简单示例
- redis中使用redis-dump导出、导入、还原数据实例
- Redis 数据导入导出,redis-dump命令
- Web.config配置数据库(Excel导入导出举例)