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

本文涉及的产品
云原生数据库 PolarDB MySQL 版,Serverless 5000PCU 100GB
简介: 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

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

相关文章
|
3月前
|
关系型数据库 MySQL 数据库
Python tk dos命令备份mysql数据库
Python tk dos命令备份mysql数据库
24 0
|
3月前
|
数据库 数据安全/隐私保护 Python
写一个定时备份数据库的脚本,且只保留最近3天
写一个定时备份数据库的脚本,且只保留最近3天
67 3
|
3月前
|
存储 关系型数据库 MySQL
mysql数据库如何做到定期备份
mysql数据库如何做到定期备份
288 2
|
1月前
|
关系型数据库 分布式数据库 数据库
PolarDB PostgreSQL版:Oracle兼容的高性能数据库
PolarDB PostgreSQL版是一款高性能的数据库,具有与Oracle兼容的特性。它采用了分布式架构,可以轻松处理大量的数据,同时还支持多种数据类型和函数,具有高可用性和可扩展性。它还提供了丰富的管理工具和性能优化功能,为企业提供了可靠的数据存储和处理解决方案。PolarDB PostgreSQL版在数据库领域具有很高的竞争力,可以满足各种企业的需求。
|
9天前
|
数据库
使用Navicat Premium 12进行数据库定期自动备份(定时任务)--图文详解
使用Navicat Premium 12进行数据库定期自动备份(定时任务)--图文详解
18 0
|
1月前
|
存储 关系型数据库 MySQL
TiDB与MySQL、PostgreSQL等数据库的比较分析
【2月更文挑战第25天】本文将对TiDB、MySQL和PostgreSQL等数据库进行详细的比较分析,探讨它们各自的优势和劣势。TiDB作为一款分布式关系型数据库,在扩展性、并发性能等方面表现突出;MySQL以其易用性和成熟性受到广泛应用;PostgreSQL则在数据完整性、扩展性等方面具有优势。通过对比这些数据库的特点和适用场景,帮助企业更好地选择适合自己业务需求的数据库系统。
|
1月前
|
SQL 存储 数据库
数据安全无忧,SQL Server 2014数据库定时备份解密
数据安全无忧,SQL Server 2014数据库定时备份解密
|
2月前
|
关系型数据库 MySQL Linux
Linux环境下定时备份mysql数据库
Linux环境下定时备份mysql数据库
|
2月前
|
数据库 对象存储 数据安全/隐私保护
在oceanbase数据库中,有没有遇到备份到oss环境,备份进度到98%就一直卡着的问题?
在oceanbase数据库中,有没有遇到备份到oss环境,备份进度到98%就一直卡着的问题?
27 6
|
2月前
|
SQL 存储 关系型数据库
备份数据库
备份数据库
22 9