Summary ¶
弊宅の監視は Vultr に乗せているが、 Disk 容量が足を引っ張り月額 $28 (4,000 円, $1= 144 ) を払っている。
SLA などの要因があれど監視を実施するためだけに維持するには高いので VPS への移設を検討している。
そこで、 Ubuntu 22.04 で稼働している本サーバーの TimescaleDB をバージョンアップする必要が出たので手順をまとめる。
事前準備 ¶
まず、 PostgreSQL を利用しているサービスをすべて止める。
弊宅では zabbix-server
と netbox
のため下記で停止させる
1
2
3
4
5
| > systemctl stop zabbix-server netbox
> systemctl is-active zabbix-server netbox
inactive
inactive
|
バックアップの確認 ¶
PostgreSQL ではいくつかのバックアップ手法があるが弊宅ではお手軽ということもあり WAL-G を使った方法と日次で取っているスナップショットで対応している。
WAL-G での取得状況を確認する
今回は base_00000002000015C1000000CC
が 2025-05-05 00:22:58 +0900
取得されたバックアップのため、一番新しい(変更実施時点では)物で以降は差分バックアップを入手することになる
1
2
3
4
5
6
7
8
9
10
11
| > sudo -u postgres /usr/local/bin/wal-g backup-list
name modified wal_segment_backup_start
base_00000002000015A5000000D2 2025-04-29T16:06:22Z 00000002000015A5000000D2
base_00000002000015AB00000059 2025-04-30T15:33:47Z 00000002000015AB00000059
base_00000002000015B0000000DD 2025-05-01T15:06:03Z 00000002000015B0000000DD
base_00000002000015B60000008C 2025-05-02T15:21:42Z 00000002000015B60000008C
base_00000002000015BC0000003B 2025-05-03T15:37:35Z 00000002000015BC0000003B
base_00000002000015C1000000CC 2025-05-04T15:22:58Z 00000002000015C1000000CC
> date '+%Y-%m-%d %H:%M:%S %z' --date '2025-05-04T15:22:58Z'
2025-05-05 00:22:58 +0900
|
バックアップの取得 ¶
差分バックアップを全行戻すのはかなり時間時間がかかるため作業前にフルバックアップを取得しておく
base_00000002000015C60000002C
が今回取得したフルバックアップ
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
| > sudo -u postgres /usr/local/bin/wal-g backup-push
...(ship)...
INFO: 2025/05/06 11:31:28.257303 maxTarSize exceeded. Closing this tar.
INFO: 2025/05/06 11:31:42.185744 Finishing backup
INFO: 2025/05/06 11:31:42.185781 If wal-g hangs during this step, please Postgres log file for details.
INFO: 2025/05/06 11:31:42.190538 Updating metadata
INFO: 2025/05/06 11:31:42.190591 Uploading metadata
INFO: 2025/05/06 11:31:43.027046 Wrote backup with name base_00000002000015C60000002C
> sudo -u postgres /usr/local/bin/wal-g backup-list
name modified wal_segment_backup_start
base_00000002000015A5000000D2 2025-04-29T16:06:22Z 00000002000015A5000000D2
base_00000002000015AB00000059 2025-04-30T15:33:47Z 00000002000015AB00000059
base_00000002000015B0000000DD 2025-05-01T15:06:03Z 00000002000015B0000000DD
base_00000002000015B60000008C 2025-05-02T15:21:42Z 00000002000015B60000008C
base_00000002000015BC0000003B 2025-05-03T15:37:35Z 00000002000015BC0000003B
base_00000002000015C1000000CC 2025-05-04T15:22:58Z 00000002000015C1000000CC
base_00000002000015C60000002C 2025-05-06T02:31:43Z 00000002000015C60000002C
|
Zabbix の確認 ¶
Important
Zabbix では TimescaleDB の対応したバージョンが明確に決まっている、
これを確認せずに latest にあげてしまうと無事 Zabbix が起動しなくなる
今回だと、Zabbix 6.0.40、 TimescaleDB 2.7.2 からアップグレードで、 TimescaleDB は最新が 2.19.3 である。
そのため、 latest にすると上がってこない()
1
2
3
4
5
6
7
8
9
10
11
12
13
14
| Added support for TimescaleDB versions:
- 2.6 since Zabbix 6.0.7;
- 2.7 since Zabbix 6.0.8;
- 2.8 since Zabbix 6.0.10;
- 2.9 since Zabbix 6.0.13;
- 2.10 since Zabbix 6.0.15;
- 2.11 since Zabbix 6.0.19;
- 2.12 since Zabbix 6.0.24;
- 2.13 since Zabbix 6.0.25;
- 2.14 since Zabbix 6.0.28;
- 2.15 since Zabbix 6.0.32;
- 2.16 since Zabbix 6.0.34;
- 2.17 since Zabbix 6.0.36;
- 2.18 since Zabbix 6.0.39.
|
パッケージなど ¶
1
2
3
4
5
6
7
8
9
10
11
12
13
14
| > sudo su - postgres
> psql -X -d zabbix-server -c "SELECT version();"
version
----------------------------------------------------------------------------------------------------------------------------------------
PostgreSQL 14.17 (Ubuntu 14.17-0ubuntu0.22.04.1) on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0, 64-bit
(1 row)
> psql -X -d zabbix-server -c "\dx timescaledb;"
List of installed extensions
Name | Version | Schema | Description
-------------+---------+--------+-------------------------------------------------------------------
timescaledb | 2.7.2 | public | Enables scalable inserts and complex queries for time-series data
(1 row)
|
1
2
3
4
5
6
7
8
9
| > dpkg -l timescaledb*
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name Version Architecture Description
+++-==================================-==================-============-=========================================================================
ii timescaledb-2-2.7.2-postgresql-14 2.7.2~ubuntu22.04 amd64 An open-source time-series database based on PostgreSQL, as an extension.
ii timescaledb-2-loader-postgresql-14 2.7.2~ubuntu22.04 amd64 The loader for TimescaleDB to load individual versions.
ii timescaledb-tools 0.18.0~ubuntu22.04 amd64 A suite of tools that can be used with TimescaleDB.
|
アップグレード ¶
アップグレート方法は公式手順を参考に実施する
古いバージョンのアンインストール ¶
1
2
3
4
| > apt remove timescaledb*
> dpkg -l timescaledb*
dpkg-query: no packages found matching timescaledb*
|
Pin している場合は解除
/etc/apt/preferences.d/92_timescaledb
1
2
3
4
5
6
7
| # Package: timescaledb-2-2.7.2-postgresql-14
# Pin: version 2.7.2*
# Pin-Priority: 1001
#
# Package: timescaledb-2-loader-postgresql-14
# Pin: version 2.7.2*
# Pin-Priority: 1001
|
インストール ¶
今回は TimescaleDB 2.18 である必要があるのでそれに合わせてインストールする
1
2
3
4
5
6
7
8
9
10
11
12
13
14
| > sudo apt install \
timescaledb-2-postgresql-14='2.18*' \
timescaledb-2-loader-postgresql-14='2.18*'
> dpkg -l timescaledb*
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name Version Architecture Description
+++-==================================-====================-============-==============================================================================>
ii timescaledb-2-loader-postgresql-14 2.18.2~ubuntu22.04 amd64 The loader for TimescaleDB to load individual versions.
ii timescaledb-2-postgresql-14 2.18.2~ubuntu22.04 amd64 An open-source time-series database based on PostgreSQL, as an extension.
ii timescaledb-toolkit-postgresql-14 1:1.19.0~ubuntu22.04 amd64 Library of analytical hyperfunctions, time-series pipelining, and other SQL ut>
ii timescaledb-tools 0.18.0~ubuntu22.04 amd64 A suite of tools that can be used with TimescaleDB.
|
完了したら PostgreSQL を起動し、アップグレード処理をする
1
2
3
4
5
6
7
8
9
10
11
12
13
14
| > sudo systemctl restart [email protected]
> sudo su - postgres
> psql -X -d zabbix-server -c "ALTER EXTENSION timescaledb UPDATE TO '2.18.2';"
ALTER EXTENSION
> psql -X -d zabbix-server -c "\dx timescaledb;"
List of installed extensions
Name | Version | Schema | Description
-------------+---------+--------+---------------------------------------------------------------------------------------
timescaledb | 2.18.2 | public | Enables scalable inserts and complex queries for time-series data (Community Edition)
(1 row)
|
完了後の確認 ¶
1
2
3
4
5
6
7
8
9
10
11
12
13
14
| > sudo su - postgres
> psql -X -d zabbix-server -c "SELECT version();"
version
----------------------------------------------------------------------------------------------------------------------------------------
PostgreSQL 14.17 (Ubuntu 14.17-0ubuntu0.22.04.1) on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0, 64-bit
(1 row)
> psql -X -d zabbix-server -c "\dx timescaledb;"
List of installed extensions
Name | Version | Schema | Description
-------------+---------+--------+---------------------------------------------------------------------------------------
timescaledb | 2.18.2 | public | Enables scalable inserts and complex queries for time-series data (Community Edition)
(1 row)
|
1
2
3
4
5
6
7
8
9
10
| > dpkg -l timescaledb*
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name Version Architecture Description
+++-==================================-====================-============-==============================================================================>
ii timescaledb-2-loader-postgresql-14 2.18.2~ubuntu22.04 amd64 The loader for TimescaleDB to load individual versions.
ii timescaledb-2-postgresql-14 2.18.2~ubuntu22.04 amd64 An open-source time-series database based on PostgreSQL, as an extension.
ii timescaledb-toolkit-postgresql-14 1:1.19.0~ubuntu22.04 amd64 Library of analytical hyperfunctions, time-series pipelining, and other SQL ut>
ii timescaledb-tools 0.18.0~ubuntu22.04 amd64 A suite of tools that can be used with TimescaleDB.
|
1
2
3
4
5
6
7
| > systemctl start zabbix-server netbox
> systemctl is-active zabbix-server netbox
active
active
> tail -f /var/log/postgresql/postgresql-14-main.log
|
Pin する ¶
Important
前述の通り Zabbix で対応してないバージョンへアップグレードされるとインシデントなため、固定しておく
/etc/apt/preferences.d/92_timescaledb
1
2
3
4
5
6
7
| Package: timescaledb-2-postgresql-14
Pin: version 2.18.2*
Pin-Priority: 1001
Package: timescaledb-2-loader-postgresql-14
Pin: version 2.18.2*
Pin-Priority: 1001
|
1
2
3
4
5
| > apt policy | grep -A8 -E '^Pinned packages:'
Pinned packages:
timescaledb-2-postgresql-14 -> 2.18.2~ubuntu22.04 with priority 1001
timescaledb-2-loader-postgresql-14 -> 2.18.2~ubuntu22.04 with priority 1001
|
完了後バックアップ ¶
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
| > sudo -u postgres /usr/local/bin/wal-g backup-push
INFO: 2025/05/06 12:44:12.826689 maxTarSize exceeded. Closing this tar.
INFO: 2025/05/06 12:44:26.766291 Finishing backup
INFO: 2025/05/06 12:44:26.766329 If wal-g hangs during this step, please Postgres log file for details.
INFO: 2025/05/06 12:44:26.771083 Updating metadata
INFO: 2025/05/06 12:44:26.771164 Uploading metadata
INFO: 2025/05/06 12:44:27.568273 Wrote backup with name base_00000002000015C600000048
> sudo -u postgres /usr/local/bin/wal-g backup-list
name modified wal_segment_backup_start
base_00000002000015A5000000D2 2025-04-29T16:06:22Z 00000002000015A5000000D2
base_00000002000015AB00000059 2025-04-30T15:33:47Z 00000002000015AB00000059
base_00000002000015B0000000DD 2025-05-01T15:06:03Z 00000002000015B0000000DD
base_00000002000015B60000008C 2025-05-02T15:21:42Z 00000002000015B60000008C
base_00000002000015BC0000003B 2025-05-03T15:37:35Z 00000002000015BC0000003B
base_00000002000015C1000000CC 2025-05-04T15:22:58Z 00000002000015C1000000CC
base_00000002000015C3000000F6 2025-05-05T15:51:39Z 00000002000015C3000000F6
base_00000002000015C40000004D 2025-05-05T18:07:56Z 00000002000015C40000004D
base_00000002000015C60000001C 2025-05-06T01:49:41Z 00000002000015C60000001C
base_00000002000015C60000002C 2025-05-06T02:31:43Z 00000002000015C60000002C
base_00000002000015C600000048 2025-05-06T03:44:28Z 00000002000015C600000048
|