Skip to content

Commit 67a79a8

Browse files
committed
new doc
1 parent 47b4e05 commit 67a79a8

File tree

7 files changed

+217
-0
lines changed

7 files changed

+217
-0
lines changed

201406/20140617_03.md

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
## PostgreSQL centrol PITR backup with kvm and zfs and nfs or zvol
2+
3+
### 作者
4+
digoal
5+
6+
### 日期
7+
2014-06-17
8+
9+
### 标签
10+
PostgreSQL , ZFS , Linux , snapshot , PITR
11+
12+
----
13+
14+
## 背景
15+
在实际的生产环境中, 当数据库越来越多, 越来越大.
16+
17+
备份可能会成为比较大的问题, 传统的逻辑备份对于大的数据库不适用(因为备份和还原可能是比较耗时的, 而且也不能回到任意时间点,还会造成数据库膨胀(长时间repeatable read iso), 好处是可以跨平台恢复, 可选恢复表等).
18+
19+
但是基于XLOG的增量备份, 又需要结构一致, 如果要做集中的备份, 可能导致不同数据库集群占用同一个文件夹带来冲突(当然解决办法是重定向一个文件夹就好了)
20+
21+
那么如果环境中已有虚拟机的话, 可以使用虚拟机来解决文件夹冲突的问题. (不过个人还是推荐使用重定向, 可以省掉一层虚拟机的管理成本)
22+
23+
zfs在这里主要用到它的压缩, 去重和snapshot功能. 减少存储空间, 加快恢复速度等. 可以放在crontab定时执行, 例如2小时1次.
24+
25+
以下是使用虚拟机和zfs来管理存储的一种集中式XLOG增量备份的场景举例 ;
26+
27+
环境 :
28+
29+
```
30+
DELL R720xd
31+
32G mem
32+
8 核 Intel(R) Xeon(R) CPU E5-2609 v2 @ 2.50GHz
33+
CentOS 6.5 x64
34+
```
35+
36+
虚拟化, KVM
37+
38+
存储管理, ZFS, 开启压缩, dedup. (也可以考虑开源的分布式文件系统)
39+
40+
虚拟机数据分区, nfs或zvol.
41+
42+
方案图 :
43+
44+
这里的虚拟机数据分区用法, 分为两种, 一种是NFS, (VM中挂载NFS来实现PGDATA的存储)
45+
46+
zvol则是直接使用zfs卷来管理的, 效率比nfs更高一点.
47+
48+
![pic](20140617_03_pic_001.png)
49+
50+
使用nfs的好处, 虚拟机和ZFS设备不需要在同一台主机.
51+
52+
使用zvol的话, 虚拟机和ZVOL必须是同一主机的.
53+
54+
整体的架构.
55+
56+
![pic](20140617_03_pic_002.png)
57+
58+
归档wal存储可以考虑zfs或分布式存储. 归档方法很多, 可以使用rsync, cp, nfs等.
59+
60+
使用ZFS snapshot加速PITR.
61+
62+
使用本地用户的话, 架构图如下 :
63+
64+
每个用户配置独立的zfs存储对应的$PGDATA, 每个用户建议编译独立的$PGHOME.
65+
66+
![pic](20140617_03_pic_003.png)
67+
68+
使用ZFS snapshot加速PITR.
69+
70+
## 参考
71+
1\. http://blog.163.com/digoal@126/blog/static/16387704020144183320807/
72+
73+
2\. http://blog.163.com/digoal@126/blog/static/163877040201322462042878/
74+
75+
3\. http://blog.163.com/digoal@126/blog/static/163877040201451332042136/
76+
77+
4\. https://access.redhat.com/site/documentation/en-US
78+
79+
<a rel="nofollow" href="http://info.flagcounter.com/h9V1" ><img src="http://s03.flagcounter.com/count/h9V1/bg_FFFFFF/txt_000000/border_CCCCCC/columns_2/maxflags_12/viewers_0/labels_0/pageviews_0/flags_0/" alt="Flag Counter" border="0" ></a>
80+

201406/20140617_03_pic_001.png

77.2 KB
Loading

201406/20140617_03_pic_002.png

19.5 KB
Loading

201406/20140617_03_pic_003.png

19.5 KB
Loading

201406/20140617_04.md

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
## PostgreSQL central stream replication unlinked use (scp, cp, pg_basebackup ...)
2+
3+
### 作者
4+
digoal
5+
6+
### 日期
7+
2014-06-17
8+
9+
### 标签
10+
PostgreSQL , ZFS , Linux , snapshot , PITR
11+
12+
----
13+
14+
## 背景
15+
前面介绍了集中式PITR备份的架构.
16+
17+
http://blog.163.com/digoal@126/blog/static/163877040201451711013770/
18+
19+
本文介绍一下不使用虚拟机的情况下, 稍微细节的东西, 即创建基础数据时规避文件夹冲突问题.
20+
21+
创建基础备份的方法比较多, 例如scp, cp或者pg_basebackup , 下面分别介绍一下.
22+
23+
1\. 使用scp
24+
25+
```
26+
-r Recursively copy entire directories. Note that scp follows symbolic links encountered in the tree
27+
traversal.
28+
```
29+
30+
格式
31+
32+
```
33+
scp -r $PGDATA $user@$dest_ip:$dir
34+
```
35+
36+
用法
37+
38+
```
39+
psql
40+
# select pg_startup_backup(now()::text);
41+
scp -r $PGDATA $user@$dest_ip:$dir
42+
# select pg_stop_backup();
43+
```
44+
45+
已经将表空间等在$PGDATA下使用软链接的都去除软链接了.
46+
47+
删除隐藏的sock文件.
48+
49+
后面的事情就是配置流复制了.
50+
51+
2\. 使用cp
52+
53+
```
54+
-R, -r, --recursive
55+
copy directories recursively
56+
-L, --dereference
57+
always follow symbolic links in SOURCE
58+
cp -rL $PGDATA/* $dir/*
59+
```
60+
61+
软链接将被去除, 直接使用本地文件夹替代.
62+
63+
删除隐藏的sock文件.
64+
65+
后面的事情就是配置流复制了.
66+
67+
3\. 使用pg_basebackup
68+
69+
因为直接使用pg_basebackup的plain格式的话, 会创建表空间对应的目录, 所以不建议直接使用.
70+
71+
建议使用tar模式, 这种模式的话会创建base.tar以及表空间.tar.
72+
73+
到目的地解压, 分类即可.
74+
75+
例如 :
76+
77+
```
78+
mkdir ~/testbase
79+
chmod 700 ~/testbase
80+
cd ~/testbase
81+
pg_basebackup -D ~/testbase -F t -x -h 127.0.0.1
82+
pg93@db-172-16-3-150-> pwd
83+
/home/pg93/testbase
84+
pg93@db-172-16-3-150-> ll
85+
total 3.1G
86+
-rw-rw-r-- 1 pg93 pg93 483K Jun 17 13:44 20270.tar
87+
-rw-rw-r-- 1 pg93 pg93 3.1G Jun 17 13:44 base.tar
88+
```
89+
90+
将base解压到当前目录
91+
92+
```
93+
pg93@db-172-16-3-150-> tar -xvf base.tar
94+
```
95+
96+
删除表空间软链接
97+
98+
```
99+
pg93@db-172-16-3-150-> cd pg_tblspc/
100+
pg93@db-172-16-3-150-> ll
101+
total 0
102+
lrwxrwxrwx 1 pg93 pg93 19 Jun 17 13:45 20270 -> /ssd4/pg93/tbs_test
103+
pg93@db-172-16-3-150-> rm -rf 20270
104+
pg93@db-172-16-3-150-> mkdir 20270
105+
pg93@db-172-16-3-150-> chmod 700 20270
106+
pg93@db-172-16-3-150-> cd 20270/
107+
pg93@db-172-16-3-150-> tar -xvf ../../20270.tar
108+
PG_9.3_201306121/
109+
PG_9.3_201306121/16393/
110+
PG_9.3_201306121/16393/20271
111+
PG_9.3_201306121/16393/20271_fsm
112+
pg93@db-172-16-3-150-> ll
113+
total 4.0K
114+
drwx------ 3 pg93 pg93 4.0K Jun 17 11:53 PG_9.3_201306121
115+
```
116+
117+
删除tar文件
118+
119+
```
120+
pg93@db-172-16-3-150-> rm -f ~/testbase/20270.tar ~/testbase/base.tar
121+
```
122+
123+
删除隐藏的sock文件.
124+
125+
后面的事情就是配置流复制了.
126+
127+
如果pg_basebackup可以增加一个选项, follow link的话 , (像cp和scp), 用起来就更方便了.
128+
129+
## 参考
130+
1\. http://blog.163.com/digoal@126/blog/static/163877040201451711013770/
131+
132+
<a rel="nofollow" href="http://info.flagcounter.com/h9V1" ><img src="http://s03.flagcounter.com/count/h9V1/bg_FFFFFF/txt_000000/border_CCCCCC/columns_2/maxflags_12/viewers_0/labels_0/pageviews_0/flags_0/" alt="Flag Counter" border="0" ></a>
133+

201406/readme.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
----
55
##### 20140628_01.md [《PostgreSQL IOPS performance tuning by flashcache》](20140628_01.md)
66
##### 20140618_01.md [《单网卡绑多个IP时如何指定IP出口(VIP出口绑定) - use ip modify route table use vip as src trans in multi-IP bonded env》](20140618_01.md)
7+
##### 20140617_04.md [《PostgreSQL central stream replication unlinked use (scp, cp, pg_basebackup ...)》](20140617_04.md)
8+
##### 20140617_03.md [《PostgreSQL centrol PITR backup with kvm and zfs and nfs or zvol》](20140617_03.md)
79
##### 20140617_02.md [《test zfs dedup vs compress which suit in your environment》](20140617_02.md)
810
##### 20140617_01.md [《zpool raidz vdev how many under block dev choose for optimal performance (Best Practices and Caveats)》](20140617_01.md)
911
##### 20140614_01.md [《使用 ssh -R 建立反向/远程TCP端口转发代理》](20140614_01.md)

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1385,6 +1385,8 @@ digoal's|PostgreSQL|文章|归类
13851385
----
13861386
##### 201406/20140628_01.md [《PostgreSQL IOPS performance tuning by flashcache》](201406/20140628_01.md)
13871387
##### 201406/20140618_01.md [《单网卡绑多个IP时如何指定IP出口(VIP出口绑定) - use ip modify route table use vip as src trans in multi-IP bonded env》](201406/20140618_01.md)
1388+
##### 201406/20140617_04.md [《PostgreSQL central stream replication unlinked use (scp, cp, pg_basebackup ...)》](201406/20140617_04.md)
1389+
##### 201406/20140617_03.md [《PostgreSQL centrol PITR backup with kvm and zfs and nfs or zvol》](201406/20140617_03.md)
13881390
##### 201406/20140617_02.md [《test zfs dedup vs compress which suit in your environment》](201406/20140617_02.md)
13891391
##### 201406/20140617_01.md [《zpool raidz vdev how many under block dev choose for optimal performance (Best Practices and Caveats)》](201406/20140617_01.md)
13901392
##### 201406/20140614_01.md [《使用 ssh -R 建立反向/远程TCP端口转发代理》](201406/20140614_01.md)

0 commit comments

Comments
 (0)