update some content

This commit is contained in:
2021-10-28 14:13:06 +08:00
parent 97eb780aa4
commit 4f99455d8f
242 changed files with 1826 additions and 2616 deletions

View File

@@ -13,7 +13,7 @@
"articleSection" : "post",
"name" : "[筆記] 在Ubuntu 18.04 下 透過 pgbarman streaming backup 備份 postgresql 10\/ backup postgresql 10 with pgbarman straming backup in ubuntu 18.04",
"headline" : "[筆記] 在Ubuntu 18.04 下 透過 pgbarman streaming backup 備份 postgresql 10\/ backup postgresql 10 with pgbarman straming backup in ubuntu 18.04",
"description" : "\x3cp\x3e很久以前就有看到這個用來備份postgresql 的 pgbarman\x3c\/p\x3e\n\x3cp\x3e\x3ca href=\x22https:\/\/www.pgbarman.org\/\x22\x3ehttps:\/\/www.pgbarman.org\/\x3c\/a\x3e\x3c\/p\x3e\n\x3cp\x3e前幾天老闆在slack 上面又提到,所以這次就花了點時間來玩玩看\x3c\/p\x3e\n\x3cp\x3e不過呢雖然有弄起來但是還真不知道有些問題是怎麼解決的\x26hellip;\x3c\/p\x3e",
"description" : "\u003cp\u003e很久以前就有看到這個用來備份postgresql 的 pgbarman\u003c\/p\u003e\n\u003cp\u003e\u003ca href=\u0022https:\/\/www.pgbarman.org\/\u0022\u003ehttps:\/\/www.pgbarman.org\/\u003c\/a\u003e\u003c\/p\u003e\n\u003cp\u003e前幾天老闆在slack 上面又提到,所以這次就花了點時間來玩玩看\u003c\/p\u003e\n\u003cp\u003e不過呢雖然有弄起來但是還真不知道有些問題是怎麼解決的\u0026hellip;\u003c\/p\u003e",
"inLanguage" : "en",
"author" : "Eric Chang",
"creator" : "Eric Chang",
@@ -21,8 +21,8 @@
"accountablePerson" : "Eric Chang",
"copyrightHolder" : "Eric Chang",
"copyrightYear" : "2019",
"datePublished": "2019-08-23 13:53:40 \x2b0800 CST",
"dateModified" : "2019-08-23 13:53:40 \x2b0800 CST",
"datePublished": "2019-08-23 13:53:40 \u002b0800 CST",
"dateModified" : "2019-08-23 13:53:40 \u002b0800 CST",
"url" : "https:\/\/h.cowbay.org\/post\/pgbarman-in-ubuntu-1804-postgresql-10\/",
"wordCount" : "776",
"image" : "https://h.cowbay.orghttps://h.cowbay.org/images/post-default-4.jpg"",
@@ -45,9 +45,9 @@
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.3.1/css/all.css" integrity="sha384-mzrmE5qonljUremFsqc01SB46JvROS7bZs3IO2EmfFsd15uHvIt+Y8vEf7N7fWAU" crossorigin="anonymous">
<link href="https://h.cowbay.org/css/style.css?v=1632901489" rel="stylesheet" id="theme-stylesheet" type='text/css' media='all'>
<link href="https://h.cowbay.org/css/style.css?v=1634607506" rel="stylesheet" id="theme-stylesheet" type='text/css' media='all'>
<link href="https://h.cowbay.org/css/custom.css?v=1632901489" rel="stylesheet" type='text/css' media='all'>
<link href="https://h.cowbay.org/css/custom.css?v=1634607506" rel="stylesheet" type='text/css' media='all'>
<link rel="shortcut icon" href="https://h.cowbay.org/img/favicon.ico" type="image/x-icon">
<link rel="icon" href="https://h.cowbay.org/img/favicon.ico" type="image/x-icon">
@@ -313,10 +313,10 @@ if (!doNotTrack) {
<p>原理就不說了,我一直沒搞懂 postgresql 的 streaming ..</p>
<p>依照官方網站上的說法,比較推薦 streaming 備份的方式</p>
<p>原因是設定相對簡單WTF !</p>
<pre><code>On a general basis, starting from Barman 2.0, backup over streaming replication is the recommended setup for PostgreSQL 9.4 or higher
<pre tabindex="0"><code>On a general basis, starting from Barman 2.0, backup over streaming replication is the recommended setup for PostgreSQL 9.4 or higher
The reason why we recommend streaming backup is that, based on our experience, it is easier to setup than the traditional one
</code></pre><p>事實上呢,設定的確是很簡單,可是有個致命的缺點</p>
<pre><code>Because Barman transparently makes use of pg_basebackup, features such as incremental backup, parallel backup, deduplication, and network compression are currently not available. In this case, bandwidth limitation has some restrictions - compared to the traditional method via rsync.
<pre tabindex="0"><code>Because Barman transparently makes use of pg_basebackup, features such as incremental backup, parallel backup, deduplication, and network compression are currently not available. In this case, bandwidth limitation has some restrictions - compared to the traditional method via rsync.
</code></pre><p>如果要做差異/增量備份, streaming backup 不能做</p>
<p>所以每次備份都是完整備份也因此barman server 需要準備很大的硬碟空間</p>
<p>以我測試的資料庫來說一次備份目前是133G ,如果一天四次,保留七天</p>
@@ -331,20 +331,20 @@ hostname: hqs019</p>
<p>streaming backup 需要先在postgresql Server 上建立一個具有 superuser 權限的帳號</p>
<p>以及一個用來做replication 的資料庫帳號</p>
<p>這裡就簡單帶過</p>
<pre><code>sudo su - postgres
<pre tabindex="0"><code>sudo su - postgres
psql
create user barman with login superuser login password 'barmanpassword';
CREATE ROLE stream_barman WITH REPLICATION PASSWORD 'password' LOGIN;
</code></pre><h5 id="鄉改-pg_hbaconf">鄉改 pg_hba.conf</h5>
<p>然後修改 pg_hba.conf加入底下兩行</p>
<pre><code># for barman test
<pre tabindex="0"><code># for barman test
host database_name barman 192.168.11.192/32 md5
host replication stream_barman 192.168.11.192/32 md5
</code></pre><p>當然,如果不考慮安全性問題, md5 直接改成用 trust ,可以省去一些麻煩。</p>
<h5 id="修改-postgresqlconf">修改 postgresql.conf</h5>
<p>接著修改postgresql.conf</p>
<pre><code>### for barman test
<pre tabindex="0"><code>### for barman test
max_wal_senders = 5
max_replication_slots = 3
wal_level = 'archive'
@@ -356,16 +356,16 @@ hostname: barman</p>
<h5 id="安裝-barman">安裝 barman</h5>
<p>barman 在18.04 中已經被放到標準repository 中</p>
<p>所以只要直接</p>
<pre><code>sudo apt install barman
<pre tabindex="0"><code>sudo apt install barman
</code></pre><p>就可以了</p>
<h5 id="設定-barmanconf">設定 barman.conf</h5>
<p>安裝完成後,在/etc/barman.d/ 底下會有兩個範例檔案</p>
<pre><code>streaming-server.conf-template
<pre tabindex="0"><code>streaming-server.conf-template
ssh-server.conf-template
</code></pre><p>複製 streaming-server 檔案</p>
<pre><code>sudo cp /etc/barman.d/streaming-server.conf-template /etc/barman.d/hqs019.conf
<pre tabindex="0"><code>sudo cp /etc/barman.d/streaming-server.conf-template /etc/barman.d/hqs019.conf
</code></pre><p>內容如下</p>
<pre><code>[hqs019]
<pre tabindex="0"><code>[hqs019]
description = &quot;hqs019 &quot;
conninfo = host=192.168.11.19 user=barman dbname=database_name password=barmanpassword
streaming_conninfo = host=192.168.11.19 user=stream_barman dbname=database_name password=password
@@ -374,7 +374,7 @@ retention_policy_mode = auto
streaming_archiver = on
slot_name = barman
</code></pre><p>接著修改 /etc/barman.conf</p>
<pre><code>[barman]
<pre tabindex="0"><code>[barman]
barman_user = barman
configuration_files_directory = /etc/barman.d
barman_home = /var/lib/barman
@@ -388,8 +388,8 @@ last_backup_maximum_age = 1 DAYS
</code></pre><p>基本上這樣就設定完成了</p>
<h5 id="檢查設定">檢查設定</h5>
<p>barman 有一些指令可以用來檢查目前的設定</p>
<p>barman show-server hqs019 可以看到所有的設定,這裡的 hqs019 跟 barman.d/hqs019.conf 裡面用&rdquo;[ ]&rdquo; 包起來的名稱要一致</p>
<pre><code>barman@barman:~$ barman show-server hqs019
<p>barman show-server hqs019 可以看到所有的設定,這裡的 hqs019 跟 barman.d/hqs019.conf 裡面用&quot;[ ]&quot; 包起來的名稱要一致</p>
<pre tabindex="0"><code>barman@barman:~$ barman show-server hqs019
Server hqs019:
active: True
archiver: False
@@ -477,7 +477,7 @@ Server hqs019:
wals_directory: /var/lib/barman/hqs019/wals
xlogpos: 264/BA000F08
</code></pre><p>然後用 barman check hqs019 來檢查config 有沒有問題</p>
<pre><code>barman@barman:~$ barman check hqs019
<pre tabindex="0"><code>barman@barman:~$ barman check hqs019
Server hqs019:
PostgreSQL: OK
is_superuser: OK
@@ -501,7 +501,7 @@ barman@barman:~$
</code></pre><p>那個backup maximum age FAILED 不用管他,因為都還沒跑過備份,這邊錯誤是正常的</p>
<p>其他都OK 的話,就可以開始備份了</p>
<p>barman backup hqs019</p>
<pre><code>barman@ubuntu:~$ barman backup hqs019
<pre tabindex="0"><code>barman@ubuntu:~$ barman backup hqs019
Starting backup using postgres method for server hqs019 in /var/lib/barman/hqs019/base/20190823T082258
Backup start at LSN: 264/A10001A8 (0000000100000264000000A1, 000001A8)
Starting backup copy via pg_basebackup for 20190823T082258
@@ -520,10 +520,10 @@ Processing xlog segments from streaming for hqs019
barman@ubuntu:~$
</code></pre><p>跑完可以用 barman list-backup hqs019 檢查</p>
<pre><code>barman@ubuntu:~$ barman list-backup hqs019
<pre tabindex="0"><code>barman@ubuntu:~$ barman list-backup hqs019
hqs019 20190823T082258 - Thu Aug 22 17:29:26 2019 - Size: 133.0 GiB - WAL Size: 0 B (tablespaces: tablespace_a:/var/lib/postgresql/10/main/tablespace_A, tablespace_b:/var/lib/postgresql/10/main/tablespace_B)
</code></pre><p>要刪除的話,要加入 backupID</p>
<pre><code>barman@ubuntu:~$ barman delete hqs019 20190822T171355
<pre tabindex="0"><code>barman@ubuntu:~$ barman delete hqs019 20190822T171355
Deleting backup 20190822T171355 for server hqs019
Delete associated WAL segments:
00000001000002640000009F
@@ -822,7 +822,7 @@ title="pinterest icon"></i>
</div>
<script src="https://h.cowbay.org/js/jquery.min.js"></script>
<script src="https://h.cowbay.org/js/jquerymigrate.js"></script>
<script src="https://h.cowbay.org/js/production.min.js?v=1632901489"></script>
<script src="https://h.cowbay.org/js/production.min.js?v=1634607506"></script>
</body>
</html>