PostgreSQL数据库备份之pg_dump并行备份

简介: PostgreSQL数据库备份之pg_dump并行备份。
 在数据库导出的时候,可以通过 -j 参数设置并行度,可以在一定程度上提高备份的速度,代价是消耗更多的系统资源。

话不多说,咱们边走边聊,实验走起!~~~

操作过程:
找一个大一点的表,里面有200万条数据:
music=# select count(*) from test;
  count  
---------
 2000005
(1 行记录)

数据库里仅有一张2G左右的表:
music=# select pg_size_pretty(pg_relation_size('test'));
 pg_size_pretty 
----------------
 1968 MB
(1 行记录)

单进程导出:
开始导出music数据库:
-bash-3.2$ date
2015年 07月 30日 星期四 13:39:14 CST
-bash-3.2$ pg_dump music >/tmp/music20150916.dmp
-bash-3.2$ date 
2015年 07月 30日 星期四 13:39:44 CST

在单行导出的时候看到的后台进程:
[root@dbserver music]# ps -ef|grep postgres
postgres  3540     1  0 12:52 ?        00:00:00 /usr/pgsql-9.4/bin/postmaster -D /var/lib/pgsql/9.4/data
postgres  3542  3540  0 12:52 ?        00:00:00 postgres: logger process                               
postgres  3544  3540  0 12:52 ?        00:00:03 postgres: checkpointer process                         
postgres  3545  3540  0 12:52 ?        00:00:00 postgres: writer process                               
postgres  3546  3540  0 12:52 ?        00:00:01 postgres: wal writer process                           
postgres  3547  3540  0 12:52 ?        00:00:00 postgres: autovacuum launcher process                  
postgres  3548  3540  0 12:52 ?        00:00:00 postgres: archiver process   last was 0000000100000001000000B0
postgres  3549  3540  0 12:52 ?        00:00:00 postgres: stats collector process                      
root      5444  5030  0 13:28 pts/0    00:00:00 su - postgres
postgres  5445  5444  0 13:28 pts/0    00:00:00 -bash
postgres  5955  3540  0 13:35 ?        00:00:00 postgres: autovacuum worker process   music            
postgres  6143  5445  1 13:39 pts/0    00:00:00 pg_dump music
postgres  6144  3540 38 13:39 ?        00:00:04 postgres: postgres music [local] COPY                  
root      6151  5515  0 13:39 pts/1    00:00:00 grep postgres
导出的时间是30毫秒。

并行导出:
因为测试系统的CPU是设置的2个单核CPU,因此设置成2度的并行:
-bash-3.2$ date
2015年 07月 30日 星期四 13:41:23 CST
-bash-3.2$ pg_dump music -j 2 -Fd -f music_j2
-bash-3.2$ date
2015年 07月 30日 星期四 13:41:44 CST
导出时间是11毫秒。

在并行导出的时候看到后台的进程:
[root@dbserver music]# ps -ef|grep postgres
postgres  3540     1  0 12:52 ?        00:00:00 /usr/pgsql-9.4/bin/postmaster -D /var/lib/pgsql/9.4/data
postgres  3542  3540  0 12:52 ?        00:00:00 postgres: logger process                               
postgres  3544  3540  0 12:52 ?        00:00:03 postgres: checkpointer process                         
postgres  3545  3540  0 12:52 ?        00:00:00 postgres: writer process                               
postgres  3546  3540  0 12:52 ?        00:00:01 postgres: wal writer process                           
postgres  3547  3540  0 12:52 ?        00:00:00 postgres: autovacuum launcher process                  
postgres  3548  3540  0 12:52 ?        00:00:00 postgres: archiver process   last was 0000000100000001000000B3
postgres  3549  3540  0 12:52 ?        00:00:00 postgres: stats collector process                      
root      5444  5030  0 13:28 pts/0    00:00:00 su - postgres
postgres  5445  5444  0 13:28 pts/0    00:00:00 -bash
postgres  5955  3540  0 13:35 ?        00:00:00 postgres: autovacuum worker process   music           
postgres  6180  5445  0 13:41 pts/0    00:00:00 pg_dump music -j 2 -Fd -f music_j2
postgres  6181  3540  1 13:41 ?        00:00:00 postgres: postgres music [local] idle in transaction   
postgres  6182  6180 52 13:41 pts/0    00:00:06 pg_dump music -j 2 -Fd -f music_j2
postgres  6183  3540 26 13:41 ?        00:00:03 postgres: postgres music [local] COPY                  
postgres  6184  6180  0 13:41 pts/0    00:00:00 pg_dump music -j 2 -Fd -f music_j2
postgres  6185  3540  0 13:41 ?        00:00:00 postgres: postgres music [local] idle in transaction   
root      6190  5515  0 13:41 pts/1    00:00:00 grep postgres

由于数据类型较单一并且数据量较小,且使用的是固态硬盘,因此时间差别不是特别明显,有意使用者可在数据量大和数据类型丰富的环境中验证其导出效果。

相关文章
|
消息中间件 存储 关系型数据库
PostgreSQL技术大讲堂 - 第33讲:并行查询管理
PostgreSQL从小白到专家,技术大讲堂 - 第33讲:并行查询管理
950 1
|
SQL 监控 Oracle
关系型数据库Oracle并行执行
【7月更文挑战第12天】
617 14
|
存储 关系型数据库 数据库
PostgreSQL的备份策略
【8月更文挑战第4天】PostgreSQL的备份策略
477 4
|
关系型数据库 数据库 PostgreSQL
postgresql|【基于pg_basebackup命令的归档备份和恢复---热备冷恢复方式】
postgresql|【基于pg_basebackup命令的归档备份和恢复---热备冷恢复方式】
1099 0
|
存储 监控 关系型数据库
PostgreSQL的备份策略是什么?
【8月更文挑战第4天】PostgreSQL的备份策略是什么?
321 7
|
SQL 关系型数据库 数据库
PostgreSQL常用命令,启动连接,pg_dump导入导出
PostgreSQL常用命令,启动连接,pg_dump导入导出
|
关系型数据库 数据库 PostgreSQL
Linux 环境手动备份postgresql数据库
【8月更文挑战第12天】在Docker环境中使用命令行工具对PostgreSQL数据库进行备份和恢复。首先,通过dockerexec进入容器,使用pg_dump进行数据库模式的备份,然后使用dockercp将备份文件导出。接着,若需导入数据到另一数据库,先将备份文件复制到目标容器,再利用psql命令进行数据恢复。整个过程需确保目标数据库无同名模式,以防止导入失败
606 3
|
存储 Ubuntu 关系型数据库
如何在 Ubuntu VPS 上备份 PostgreSQL 数据库
如何在 Ubuntu VPS 上备份 PostgreSQL 数据库
304 1
|
SQL 关系型数据库 数据库
[postgresql]逻辑备份与还原
[postgresql]逻辑备份与还原
268 2
|
存储 关系型数据库 分布式数据库
PolarDB产品使用问题之如何查看PolarDB for PostgreSQL的备份信息
PolarDB产品使用合集涵盖了从创建与管理、数据管理、性能优化与诊断、安全与合规到生态与集成、运维与支持等全方位的功能和服务,旨在帮助企业轻松构建高可用、高性能且易于管理的数据库环境,满足不同业务场景的需求。用户可以通过阿里云控制台、API、SDK等方式便捷地使用这些功能,实现数据库的高效运维与持续优化。

热门文章

最新文章

推荐镜像

更多