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

本文涉及的产品
云数据库 PolarDB MySQL 版,列存表分析加速 4核8GB
PolarDB Agent Express,2核4GB
简介: 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

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

相关文章
|
存储 关系型数据库 MySQL
mysql数据库备份与恢复
MySQL数据库的备份与恢复是确保数据安全性和业务连续性的关键操作。
713 4
|
存储 关系型数据库 分布式数据库
PolarDB开源数据库进阶课5 在线备份
本文介绍了如何在PolarDB RAC一写多读集群中进行在线备份,特别针对共享存储模式。通过使用`polar_basebackup`工具,可以将实例的本地数据和共享数据备份到本地盘中。实验环境依赖于Docker容器中用loop设备模拟的共享存储。
430 1
|
存储 关系型数据库 MySQL
利用Cron表达式实现MySQL数据库的定时备份
以上就是如何使用Cron表达式和mysqldump命令实现MySQL数据库的定时备份。这种方法的优点是简单易用,而且可以根据需要定制备份的时间和频率。但是,它也有一些限制,例如,它不能备份MySQL服务器的配置文件和用户账户信息,也不能实现增量备份。如果需要更复杂的备份策略,可能需要使用专门的备份工具或服务。
375 15
|
关系型数据库 Shell 网络安全
定期备份数据库:基于 Shell 脚本的自动化方案
本篇文章分享一个简单的 Shell 脚本,用于定期备份 MySQL 数据库,并自动将备份传输到远程服务器,帮助防止数据丢失。
|
关系型数据库 MySQL Linux
Linux环境下MySQL数据库自动定时备份实践
数据库备份是确保数据安全的重要措施。在Linux环境下,实现MySQL数据库的自动定时备份可以通过多种方式完成。本文将介绍如何使用`cron`定时任务和`mysqldump`工具来实现MySQL数据库的每日自动备份。
939 3
|
监控 关系型数据库 MySQL
Linux环境下MySQL数据库自动定时备份策略
在Linux环境下,MySQL数据库的自动定时备份是确保数据安全和可靠性的重要措施。通过设置定时任务,我们可以每天自动执行数据库备份,从而减少人为错误和提高数据恢复的效率。本文将详细介绍如何在Linux下实现MySQL数据库的自动定时备份。
495 3
|
关系型数据库 MySQL 数据库
Navicat备份数据库
涵盖`Navicat`数据库备份、数据安全及备份策略等主题。文库采用精美主题,提升阅读体验。
445 1
Navicat备份数据库
|
存储 定位技术 数据库
介绍一下数据库的备份和恢复策略
【10月更文挑战第21】介绍一下数据库的备份和恢复策略
|
SQL 数据库 数据安全/隐私保护
如何手动备份数据库?
如何手动备份数据库?
550 1
|
数据库
【赵渝强老师】数据库的备份方式
备份数据库是指将数据库中的数据及相关信息保存起来,以便在系统故障时恢复。备份对象不仅限于数据本身,还包括数据库对象、用户权限等。根据备份策略、类型和模式的不同,可分为整体/部分备份、完全/增量备份、一致/非一致备份。文中还附有相关视频讲解。
297 0

推荐镜像

更多