Opensourcetechブログ

OpensourcetechによるNGINX/Kubernetes/Zabbix/Neo4j/Linuxなどオープンソース技術に関するブログです。

Zabbix4.2でデータベースにTimescaleDBを使ってみた

こんにちは、LinuCエバンジェリストこと、鯨井貴博@opensourcetechです。

Alexei Vladishevさんと一緒


 

今回は、Zabbix4.2でサポートされたTimescaleDBを使ってみます。

https://blog.zabbix.com/zabbix-time-series-data-and-timescaledb/6642/

 

なお、TimescaleDBはPostgreSQLの拡張機能になるので、

PostgreSQLで構築されたZabbix4.2が必要です。

PostgreSQL11を使ってZabbix 4.2を構築する - Opensourcetechブログ

 

 

 

参考サイト

zabbix4.2のドキュメントとTimescaleDBのドキュメントのみが武器ですw

https://www.zabbix.com/documentation/4.2/manual/appendix/install/db_scripts

https://docs.timescale.com/v1.1/using-timescaledb

 

 

TimescaleDBのインストール

TimescaleDB用のレポジトリを追加し、yumでインストールします。

[root@localhost ~]# ls /etc/yum.repos.d/
CentOS-Base.repo CentOS-Debuginfo.repo CentOS-Sources.repo CentOS-fasttrack.repo pgdg-redhat-all.repo
CentOS-CR.repo CentOS-Media.repo CentOS-Vault.repo nginx.repo zabbix.repo
[root@localhost ~]# vi /etc/yum.repos.d/timescale_timescaledb.repo
[root@localhost ~]# cat /etc/yum.repos.d/timescale_timescaledb.repo
[timescale_timescaledb]
name=timescale_timescaledb
baseurl=https://packagecloud.io/timescale/timescaledb/el/7/\$basearch
repo_gpgcheck=1
gpgcheck=0
enabled=1
gpgkey=https://packagecloud.io/timescale/timescaledb/gpgkey
sslverify=1
sslcacert=/etc/pki/tls/certs/ca-bundle.crt
metadata_expire=300
[root@localhost ~]# yum update
読み込んだプラグイン:fastestmirror
Loading mirror speeds from cached hostfile
* base: ftp.jaist.ac.jp
* extras: ftp.jaist.ac.jp
* updates: ftp.jaist.ac.jp
base | 3.6 kB 00:00:00
extras | 3.4 kB 00:00:00
nginx | 2.9 kB 00:00:00
pgdg10 | 4.1 kB 00:00:00
pgdg11 | 4.1 kB 00:00:00
pgdg94 | 4.1 kB 00:00:00
pgdg95 | 4.1 kB 00:00:00
pgdg96 | 4.1 kB 00:00:00
timescale_timescaledb/x86_64/signature | 833 B 00:00:00
https://packagecloud.io/timescale/timescaledb/gpgkey から鍵を取得中です。
Importing GPG key 0x47F24417:
Userid : "https://packagecloud.io/timescale/timescaledb (https://packagecloud.io/docs#gpg_signing) <support@packagecloud.io>"
Fingerprint: 1005 fb68 604c e9b8 f687 9cf7 59f1 8edf 47f2 4417
From : https://packagecloud.io/timescale/timescaledb/gpgkey
上記の処理を行います。よろしいでしょうか? [y/N]y
timescale_timescaledb/x86_64/signature | 1.0 kB 00:00:02 !!!
updates | 3.4 kB 00:00:00
zabbix | 2.9 kB 00:00:00
zabbix-non-supported | 951 B 00:00:00
(1/6): pgdg11/7/x86_64/primary_db | 166 kB 00:00:02
(2/6): pgdg94/7/x86_64/primary_db | 236 kB 00:00:02
(3/6): pgdg96/7/x86_64/primary_db | 225 kB 00:00:02
(4/6): pgdg95/7/x86_64/primary_db | 227 kB 00:00:03
(5/6): pgdg10/7/x86_64/primary_db | 204 kB 00:00:03
(6/6): updates/7/x86_64/primary_db | 4.2 MB 00:00:01
timescale_timescaledb/x86_64/primary | 4.2 kB 00:00:02
timescale_timescaledb 32/32
依存性の解決をしています
--> トランザクションの確認を実行しています。
---> パッケージ glibc.x86_64 0:2.17-260.el7_6.4 を 更新
---> パッケージ glibc.x86_64 0:2.17-260.el7_6.5 を アップデート
---> パッケージ glibc-common.x86_64 0:2.17-260.el7_6.4 を 更新
---> パッケージ glibc-common.x86_64 0:2.17-260.el7_6.5 を アップデート
---> パッケージ postgresql11.x86_64 0:11.2-2PGDG.rhel7 を 更新
---> パッケージ postgresql11.x86_64 0:11.3-1PGDG.rhel7 を アップデート
---> パッケージ postgresql11-contrib.x86_64 0:11.2-2PGDG.rhel7 を 更新
---> パッケージ postgresql11-contrib.x86_64 0:11.3-1PGDG.rhel7 を アップデート
---> パッケージ postgresql11-devel.x86_64 0:11.2-2PGDG.rhel7 を 更新
---> パッケージ postgresql11-devel.x86_64 0:11.3-1PGDG.rhel7 を アップデート
---> パッケージ postgresql11-docs.x86_64 0:11.2-2PGDG.rhel7 を 更新
---> パッケージ postgresql11-docs.x86_64 0:11.3-1PGDG.rhel7 を アップデート
---> パッケージ postgresql11-libs.x86_64 0:11.2-2PGDG.rhel7 を 更新
---> パッケージ postgresql11-libs.x86_64 0:11.3-1PGDG.rhel7 を アップデート
---> パッケージ postgresql11-plpython.x86_64 0:11.2-2PGDG.rhel7 を 更新
---> パッケージ postgresql11-plpython.x86_64 0:11.3-1PGDG.rhel7 を アップデート
---> パッケージ postgresql11-server.x86_64 0:11.2-2PGDG.rhel7 を 更新
---> パッケージ postgresql11-server.x86_64 0:11.3-1PGDG.rhel7 を アップデート
---> パッケージ postgresql11-test.x86_64 0:11.2-2PGDG.rhel7 を 更新
---> パッケージ postgresql11-test.x86_64 0:11.3-1PGDG.rhel7 を アップデート
--> 依存性解決を終了しました。

依存性を解決しました

=======================================================================================================================
Package アーキテクチャー バージョン リポジトリー 容量
=======================================================================================================================
更新します:
glibc x86_64 2.17-260.el7_6.5 updates 3.7 M
glibc-common x86_64 2.17-260.el7_6.5 updates 12 M
postgresql11 x86_64 11.3-1PGDG.rhel7 pgdg11 1.7 M
postgresql11-contrib x86_64 11.3-1PGDG.rhel7 pgdg11 616 k
postgresql11-devel x86_64 11.3-1PGDG.rhel7 pgdg11 2.0 M
postgresql11-docs x86_64 11.3-1PGDG.rhel7 pgdg11 11 M
postgresql11-libs x86_64 11.3-1PGDG.rhel7 pgdg11 360 k
postgresql11-plpython x86_64 11.3-1PGDG.rhel7 pgdg11 82 k
postgresql11-server x86_64 11.3-1PGDG.rhel7 pgdg11 4.7 M
postgresql11-test x86_64 11.3-1PGDG.rhel7 pgdg11 1.8 M

トランザクションの要約
=======================================================================================================================
更新 10 パッケージ

総ダウンロード容量: 37 M
Is this ok [y/d/N]: y
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
(1/10): glibc-2.17-260.el7_6.5.x86_64.rpm | 3.7 MB 00:00:01
(2/10): glibc-common-2.17-260.el7_6.5.x86_64.rpm | 12 MB 00:00:02
(3/10): postgresql11-11.3-1PGDG.rhel7.x86_64.rpm | 1.7 MB 00:00:03
(4/10): postgresql11-contrib-11.3-1PGDG.rhel7.x86_64.rpm | 616 kB 00:00:03
(5/10): postgresql11-devel-11.3-1PGDG.rhel7.x86_64.rpm | 2.0 MB 00:00:01
(6/10): postgresql11-libs-11.3-1PGDG.rhel7.x86_64.rpm | 360 kB 00:00:00
(7/10): postgresql11-plpython-11.3-1PGDG.rhel7.x86_64.rpm | 82 kB 00:00:00
(8/10): postgresql11-server-11.3-1PGDG.rhel7.x86_64.rpm | 4.7 MB 00:00:03
(9/10): postgresql11-docs-11.3-1PGDG.rhel7.x86_64.rpm | 11 MB 00:00:06
(10/10): postgresql11-test-11.3-1PGDG.rhel7.x86_64.rpm | 1.8 MB 00:00:01
-----------------------------------------------------------------------------------------------------------------------
合計 3.3 MB/s | 37 MB 00:00:11
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
更新します : glibc-common-2.17-260.el7_6.5.x86_64 1/20
更新します : glibc-2.17-260.el7_6.5.x86_64 2/20
更新します : postgresql11-libs-11.3-1PGDG.rhel7.x86_64 3/20
更新します : postgresql11-11.3-1PGDG.rhel7.x86_64 4/20
更新します : postgresql11-server-11.3-1PGDG.rhel7.x86_64 5/20
更新します : postgresql11-devel-11.3-1PGDG.rhel7.x86_64 6/20
更新します : postgresql11-test-11.3-1PGDG.rhel7.x86_64 7/20
更新します : postgresql11-plpython-11.3-1PGDG.rhel7.x86_64 8/20
更新します : postgresql11-contrib-11.3-1PGDG.rhel7.x86_64 9/20
更新します : postgresql11-docs-11.3-1PGDG.rhel7.x86_64 10/20
整理中 : postgresql11-contrib-11.2-2PGDG.rhel7.x86_64 11/20
整理中 : postgresql11-test-11.2-2PGDG.rhel7.x86_64 12/20
整理中 : postgresql11-devel-11.2-2PGDG.rhel7.x86_64 13/20
整理中 : postgresql11-plpython-11.2-2PGDG.rhel7.x86_64 14/20
整理中 : postgresql11-server-11.2-2PGDG.rhel7.x86_64 15/20
整理中 : postgresql11-11.2-2PGDG.rhel7.x86_64 16/20
整理中 : postgresql11-libs-11.2-2PGDG.rhel7.x86_64 17/20
整理中 : postgresql11-docs-11.2-2PGDG.rhel7.x86_64 18/20
整理中 : glibc-common-2.17-260.el7_6.4.x86_64 19/20
整理中 : glibc-2.17-260.el7_6.4.x86_64 20/20
検証中 : postgresql11-11.3-1PGDG.rhel7.x86_64 1/20
検証中 : postgresql11-plpython-11.3-1PGDG.rhel7.x86_64 2/20
検証中 : postgresql11-libs-11.3-1PGDG.rhel7.x86_64 3/20
検証中 : postgresql11-server-11.3-1PGDG.rhel7.x86_64 4/20
検証中 : postgresql11-devel-11.3-1PGDG.rhel7.x86_64 5/20
検証中 : postgresql11-contrib-11.3-1PGDG.rhel7.x86_64 6/20
検証中 : postgresql11-docs-11.3-1PGDG.rhel7.x86_64 7/20
検証中 : glibc-2.17-260.el7_6.5.x86_64 8/20
検証中 : postgresql11-test-11.3-1PGDG.rhel7.x86_64 9/20
検証中 : glibc-common-2.17-260.el7_6.5.x86_64 10/20
検証中 : postgresql11-11.2-2PGDG.rhel7.x86_64 11/20
検証中 : postgresql11-libs-11.2-2PGDG.rhel7.x86_64 12/20
検証中 : postgresql11-docs-11.2-2PGDG.rhel7.x86_64 13/20
検証中 : postgresql11-devel-11.2-2PGDG.rhel7.x86_64 14/20
検証中 : postgresql11-server-11.2-2PGDG.rhel7.x86_64 15/20
検証中 : glibc-common-2.17-260.el7_6.4.x86_64 16/20
検証中 : glibc-2.17-260.el7_6.4.x86_64 17/20
検証中 : postgresql11-test-11.2-2PGDG.rhel7.x86_64 18/20
検証中 : postgresql11-plpython-11.2-2PGDG.rhel7.x86_64 19/20
検証中 : postgresql11-contrib-11.2-2PGDG.rhel7.x86_64 20/20

更新:
glibc.x86_64 0:2.17-260.el7_6.5 glibc-common.x86_64 0:2.17-260.el7_6.5
postgresql11.x86_64 0:11.3-1PGDG.rhel7 postgresql11-contrib.x86_64 0:11.3-1PGDG.rhel7
postgresql11-devel.x86_64 0:11.3-1PGDG.rhel7 postgresql11-docs.x86_64 0:11.3-1PGDG.rhel7
postgresql11-libs.x86_64 0:11.3-1PGDG.rhel7 postgresql11-plpython.x86_64 0:11.3-1PGDG.rhel7
postgresql11-server.x86_64 0:11.3-1PGDG.rhel7 postgresql11-test.x86_64 0:11.3-1PGDG.rhel7

完了しました!


[root@localhost ~]# yum install timescaledb-postgresql-11
読み込んだプラグイン:fastestmirror
Loading mirror speeds from cached hostfile
* base: ftp.jaist.ac.jp
* extras: ftp.jaist.ac.jp
* updates: ftp.jaist.ac.jp
依存性の解決をしています
--> トランザクションの確認を実行しています。
---> パッケージ timescaledb-postgresql-11.x86_64 0:1.3.0-0.el7 を インストール
--> 依存性の処理をしています: timescaledb-tools >= 0.3 のパッケージ: timescaledb-postgresql-11-1.3.0-0.el7.x86_64
--> トランザクションの確認を実行しています。
---> パッケージ timescaledb-tools.x86_64 0:0.6.0-0.el7 を インストール
--> 依存性解決を終了しました。

依存性を解決しました

=======================================================================================================================
Package アーキテクチャー バージョン リポジトリー 容量
=======================================================================================================================
インストール中:
timescaledb-postgresql-11 x86_64 1.3.0-0.el7 timescale_timescaledb 214 k
依存性関連でのインストールをします:
timescaledb-tools x86_64 0.6.0-0.el7 timescale_timescaledb 2.4 M

トランザクションの要約
=======================================================================================================================
インストール 1 パッケージ (+1 個の依存関係のパッケージ)

総ダウンロード容量: 2.6 M
インストール容量: 10 M
Is this ok [y/d/N]: y
Downloading packages:
(1/2): timescaledb-postgresql-11-1.3.0-0.el7.x86_64.rpm | 214 kB 00:00:02
(2/2): timescaledb-tools-0.6.0-0.el7.x86_64.rpm | 2.4 MB 00:00:02
-----------------------------------------------------------------------------------------------------------------------
合計 897 kB/s | 2.6 MB 00:00:02
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
インストール中 : timescaledb-tools-0.6.0-0.el7.x86_64 1/2
インストール中 : timescaledb-postgresql-11-1.3.0-0.el7.x86_64 2/2
Using pg_config located at /usr/pgsql-11/bin/pg_config to finish installation...

TimescaleDB has been installed. You need to update your postgresql.conf file
to load the library by adding 'timescaledb' to your shared_preload_libraries.
The easiest way to do this (and more configuration) is to use timescaledb-tune:

timescaledb-tune --pg-config=/usr/pgsql-11/bin/pg_config

検証中 : timescaledb-postgresql-11-1.3.0-0.el7.x86_64 1/2
検証中 : timescaledb-tools-0.6.0-0.el7.x86_64 2/2

インストール:
timescaledb-postgresql-11.x86_64 0:1.3.0-0.el7

依存性関連をインストールしました:
timescaledb-tools.x86_64 0:0.6.0-0.el7

完了しました!

 

 

PostgreSQLの設定変更

PostgreSQLの設定ファイル(/var/lib/pgsql/11/data/postgresql.conf)に、TimescaleDBを使用するように変更を加えます。

617行目にある「shared_preload_libraries = 'timescaledb'」を追記します。

[root@localhost ~]# vi /var/lib/pgsql/11/data/postgresql.conf
[root@localhost ~]# cat -n /var/lib/pgsql/11/data/postgresql.conf
1 # -----------------------------
2 # PostgreSQL configuration file
3 # -----------------------------
4 #
5 # This file consists of lines of the form:
6 #
7 # name = value
8 #
9 # (The "=" is optional.) Whitespace may be used. Comments are introduced with
10 # "#" anywhere on a line. The complete list of parameter names and allowed
11 # values can be found in the PostgreSQL documentation.
12 #
13 # The commented-out settings shown in this file represent the default values.
14 # Re-commenting a setting is NOT sufficient to revert it to the default value;
15 # you need to reload the server.
16 #
17 # This file is read on server startup and when the server receives a SIGHUP
18 # signal. If you edit the file on a running system, you have to SIGHUP the
19 # server for the changes to take effect, run "pg_ctl reload", or execute
20 # "SELECT pg_reload_conf()". Some parameters, which are marked below,
21 # require a server shutdown and restart to take effect.
22 #
23 # Any parameter can also be given as a command-line option to the server, e.g.,
24 # "postgres -c log_connections=on". Some parameters can be changed at run time
25 # with the "SET" SQL command.
26 #
27 # Memory units: kB = kilobytes Time units: ms = milliseconds
28 # MB = megabytes s = seconds
29 # GB = gigabytes min = minutes
30 # TB = terabytes h = hours
31 # d = days
32
33
34 #------------------------------------------------------------------------------
35 # FILE LOCATIONS
36 #------------------------------------------------------------------------------
37
38 # The default values of these variables are driven from the -D command-line
39 # option or PGDATA environment variable, represented here as ConfigDir.
40
41 #data_directory = 'ConfigDir' # use data in another directory
42 # (change requires restart)
43 #hba_file = 'ConfigDir/pg_hba.conf' # host-based authentication file
44 # (change requires restart)
45 #ident_file = 'ConfigDir/pg_ident.conf' # ident configuration file
46 # (change requires restart)
47
48 # If external_pid_file is not explicitly set, no extra PID file is written.
49 #external_pid_file = '' # write an extra PID file
50 # (change requires restart)
51
52
53 #------------------------------------------------------------------------------
54 # CONNECTIONS AND AUTHENTICATION
55 #------------------------------------------------------------------------------
56
57 # - Connection Settings -
58
59 listen_addresses = '*' # what IP address(es) to listen on;
60 #listen_addresses = 'localhost' # what IP address(es) to listen on;
61 # comma-separated list of addresses;
62 # defaults to 'localhost'; use '*' for all
63 # (change requires restart)
64 port = 5432 # (change requires restart)
65 max_connections = 100 # (change requires restart)
66 #superuser_reserved_connections = 3 # (change requires restart)
67 #unix_socket_directories = '/var/run/postgresql, /tmp' # comma-separated list of directories
68 # (change requires restart)
69 #unix_socket_group = '' # (change requires restart)
70 #unix_socket_permissions = 0777 # begin with 0 to use octal notation
71 # (change requires restart)
72 #bonjour = off # advertise server via Bonjour
73 # (change requires restart)
74 #bonjour_name = '' # defaults to the computer name
75 # (change requires restart)
76
77 # - TCP Keepalives -
78 # see "man 7 tcp" for details
79
80 #tcp_keepalives_idle = 0 # TCP_KEEPIDLE, in seconds;
81 # 0 selects the system default
82 #tcp_keepalives_interval = 0 # TCP_KEEPINTVL, in seconds;
83 # 0 selects the system default
84 #tcp_keepalives_count = 0 # TCP_KEEPCNT;
85 # 0 selects the system default
86
87 # - Authentication -
88
89 #authentication_timeout = 1min # 1s-600s
90 #password_encryption = md5 # md5 or scram-sha-256
91 #db_user_namespace = off
92
93 # GSSAPI using Kerberos
94 #krb_server_keyfile = ''
95 #krb_caseins_users = off
96
97 # - SSL -
98
99 #ssl = off
100 #ssl_ca_file = ''
101 #ssl_cert_file = 'server.crt'
102 #ssl_crl_file = ''
103 #ssl_key_file = 'server.key'
104 #ssl_ciphers = 'HIGH:MEDIUM:+3DES:!aNULL' # allowed SSL ciphers
105 #ssl_prefer_server_ciphers = on
106 #ssl_ecdh_curve = 'prime256v1'
107 #ssl_dh_params_file = ''
108 #ssl_passphrase_command = ''
109 #ssl_passphrase_command_supports_reload = off
110
111
112 #------------------------------------------------------------------------------
113 # RESOURCE USAGE (except WAL)
114 #------------------------------------------------------------------------------
115
116 # - Memory -
117
118 shared_buffers = 128MB # min 128kB
119 # (change requires restart)
120 #huge_pages = try # on, off, or try
121 # (change requires restart)
122 #temp_buffers = 8MB # min 800kB
123 #max_prepared_transactions = 0 # zero disables the feature
124 # (change requires restart)
125 # Caution: it is not advisable to set max_prepared_transactions nonzero unless
126 # you actively intend to use prepared transactions.
127 #work_mem = 4MB # min 64kB
128 #maintenance_work_mem = 64MB # min 1MB
129 #autovacuum_work_mem = -1 # min 1MB, or -1 to use maintenance_work_mem
130 #max_stack_depth = 2MB # min 100kB
131 dynamic_shared_memory_type = posix # the default is the first option
132 # supported by the operating system:
133 # posix
134 # sysv
135 # windows
136 # mmap
137 # use none to disable dynamic shared memory
138 # (change requires restart)
139
140 # - Disk -
141
142 #temp_file_limit = -1 # limits per-process temp file space
143 # in kB, or -1 for no limit
144
145 # - Kernel Resources -
146
147 #max_files_per_process = 1000 # min 25
148 # (change requires restart)
149
150 # - Cost-Based Vacuum Delay -
151
152 #vacuum_cost_delay = 0 # 0-100 milliseconds
153 #vacuum_cost_page_hit = 1 # 0-10000 credits
154 #vacuum_cost_page_miss = 10 # 0-10000 credits
155 #vacuum_cost_page_dirty = 20 # 0-10000 credits
156 #vacuum_cost_limit = 200 # 1-10000 credits
157
158 # - Background Writer -
159
160 #bgwriter_delay = 200ms # 10-10000ms between rounds
161 #bgwriter_lru_maxpages = 100 # max buffers written/round, 0 disables
162 #bgwriter_lru_multiplier = 2.0 # 0-10.0 multiplier on buffers scanned/round
163 #bgwriter_flush_after = 512kB # measured in pages, 0 disables
164
165 # - Asynchronous Behavior -
166
167 #effective_io_concurrency = 1 # 1-1000; 0 disables prefetching
168 #max_worker_processes = 8 # (change requires restart)
169 #max_parallel_maintenance_workers = 2 # taken from max_parallel_workers
170 #max_parallel_workers_per_gather = 2 # taken from max_parallel_workers
171 #parallel_leader_participation = on
172 #max_parallel_workers = 8 # maximum number of max_worker_processes that
173 # can be used in parallel operations
174 #old_snapshot_threshold = -1 # 1min-60d; -1 disables; 0 is immediate
175 # (change requires restart)
176 #backend_flush_after = 0 # measured in pages, 0 disables
177
178
179 #------------------------------------------------------------------------------
180 # WRITE-AHEAD LOG
181 #------------------------------------------------------------------------------
182
183 # - Settings -
184
185 #wal_level = replica # minimal, replica, or logical
186 # (change requires restart)
187 #fsync = on # flush data to disk for crash safety
188 # (turning this off can cause
189 # unrecoverable data corruption)
190 #synchronous_commit = on # synchronization level;
191 # off, local, remote_write, remote_apply, or on
192 #wal_sync_method = fsync # the default is the first option
193 # supported by the operating system:
194 # open_datasync
195 # fdatasync (default on Linux)
196 # fsync
197 # fsync_writethrough
198 # open_sync
199 #full_page_writes = on # recover from partial page writes
200 #wal_compression = off # enable compression of full-page writes
201 #wal_log_hints = off # also do full page writes of non-critical updates
202 # (change requires restart)
203 #wal_buffers = -1 # min 32kB, -1 sets based on shared_buffers
204 # (change requires restart)
205 #wal_writer_delay = 200ms # 1-10000 milliseconds
206 #wal_writer_flush_after = 1MB # measured in pages, 0 disables
207
208 #commit_delay = 0 # range 0-100000, in microseconds
209 #commit_siblings = 5 # range 1-1000
210
211 # - Checkpoints -
212
213 #checkpoint_timeout = 5min # range 30s-1d
214 max_wal_size = 1GB
215 min_wal_size = 80MB
216 #checkpoint_completion_target = 0.5 # checkpoint target duration, 0.0 - 1.0
217 #checkpoint_flush_after = 256kB # measured in pages, 0 disables
218 #checkpoint_warning = 30s # 0 disables
219
220 # - Archiving -
221
222 #archive_mode = off # enables archiving; off, on, or always
223 # (change requires restart)
224 #archive_command = '' # command to use to archive a logfile segment
225 # placeholders: %p = path of file to archive
226 # %f = file name only
227 # e.g. 'test ! -f /mnt/server/archivedir/%f && cp %p /mnt/server/archivedir/%f'
228 #archive_timeout = 0 # force a logfile segment switch after this
229 # number of seconds; 0 disables
230
231
232 #------------------------------------------------------------------------------
233 # REPLICATION
234 #------------------------------------------------------------------------------
235
236 # - Sending Servers -
237
238 # Set these on the master and on any standby that will send replication data.
239
240 #max_wal_senders = 10 # max number of walsender processes
241 # (change requires restart)
242 #wal_keep_segments = 0 # in logfile segments; 0 disables
243 #wal_sender_timeout = 60s # in milliseconds; 0 disables
244
245 #max_replication_slots = 10 # max number of replication slots
246 # (change requires restart)
247 #track_commit_timestamp = off # collect timestamp of transaction commit
248 # (change requires restart)
249
250 # - Master Server -
251
252 # These settings are ignored on a standby server.
253
254 #synchronous_standby_names = '' # standby servers that provide sync rep
255 # method to choose sync standbys, number of sync standbys,
256 # and comma-separated list of application_name
257 # from standby(s); '*' = all
258 #vacuum_defer_cleanup_age = 0 # number of xacts by which cleanup is delayed
259
260 # - Standby Servers -
261
262 # These settings are ignored on a master server.
263
264 #hot_standby = on # "off" disallows queries during recovery
265 # (change requires restart)
266 #max_standby_archive_delay = 30s # max delay before canceling queries
267 # when reading WAL from archive;
268 # -1 allows indefinite delay
269 #max_standby_streaming_delay = 30s # max delay before canceling queries
270 # when reading streaming WAL;
271 # -1 allows indefinite delay
272 #wal_receiver_status_interval = 10s # send replies at least this often
273 # 0 disables
274 #hot_standby_feedback = off # send info from standby to prevent
275 # query conflicts
276 #wal_receiver_timeout = 60s # time that receiver waits for
277 # communication from master
278 # in milliseconds; 0 disables
279 #wal_retrieve_retry_interval = 5s # time to wait before retrying to
280 # retrieve WAL after a failed attempt
281
282 # - Subscribers -
283
284 # These settings are ignored on a publisher.
285
286 #max_logical_replication_workers = 4 # taken from max_worker_processes
287 # (change requires restart)
288 #max_sync_workers_per_subscription = 2 # taken from max_logical_replication_workers
289
290
291 #------------------------------------------------------------------------------
292 # QUERY TUNING
293 #------------------------------------------------------------------------------
294
295 # - Planner Method Configuration -
296
297 #enable_bitmapscan = on
298 #enable_hashagg = on
299 #enable_hashjoin = on
300 #enable_indexscan = on
301 #enable_indexonlyscan = on
302 #enable_material = on
303 #enable_mergejoin = on
304 #enable_nestloop = on
305 #enable_parallel_append = on
306 #enable_seqscan = on
307 #enable_sort = on
308 #enable_tidscan = on
309 #enable_partitionwise_join = off
310 #enable_partitionwise_aggregate = off
311 #enable_parallel_hash = on
312 #enable_partition_pruning = on
313
314 # - Planner Cost Constants -
315
316 #seq_page_cost = 1.0 # measured on an arbitrary scale
317 #random_page_cost = 4.0 # same scale as above
318 #cpu_tuple_cost = 0.01 # same scale as above
319 #cpu_index_tuple_cost = 0.005 # same scale as above
320 #cpu_operator_cost = 0.0025 # same scale as above
321 #parallel_tuple_cost = 0.1 # same scale as above
322 #parallel_setup_cost = 1000.0 # same scale as above
323
324 #jit_above_cost = 100000 # perform JIT compilation if available
325 # and query more expensive than this;
326 # -1 disables
327 #jit_inline_above_cost = 500000 # inline small functions if query is
328 # more expensive than this; -1 disables
329 #jit_optimize_above_cost = 500000 # use expensive JIT optimizations if
330 # query is more expensive than this;
331 # -1 disables
332
333 #min_parallel_table_scan_size = 8MB
334 #min_parallel_index_scan_size = 512kB
335 #effective_cache_size = 4GB
336
337 # - Genetic Query Optimizer -
338
339 #geqo = on
340 #geqo_threshold = 12
341 #geqo_effort = 5 # range 1-10
342 #geqo_pool_size = 0 # selects default based on effort
343 #geqo_generations = 0 # selects default based on effort
344 #geqo_selection_bias = 2.0 # range 1.5-2.0
345 #geqo_seed = 0.0 # range 0.0-1.0
346
347 # - Other Planner Options -
348
349 #default_statistics_target = 100 # range 1-10000
350 #constraint_exclusion = partition # on, off, or partition
351 #cursor_tuple_fraction = 0.1 # range 0.0-1.0
352 #from_collapse_limit = 8
353 #join_collapse_limit = 8 # 1 disables collapsing of explicit
354 # JOIN clauses
355 #force_parallel_mode = off
356 #jit = off # allow JIT compilation
357
358
359 #------------------------------------------------------------------------------
360 # REPORTING AND LOGGING
361 #------------------------------------------------------------------------------
362
363 # - Where to Log -
364
365 log_destination = 'stderr' # Valid values are combinations of
366 # stderr, csvlog, syslog, and eventlog,
367 # depending on platform. csvlog
368 # requires logging_collector to be on.
369
370 # This is used when logging to stderr:
371 logging_collector = on # Enable capturing of stderr and csvlog
372 # into log files. Required to be on for
373 # csvlogs.
374 # (change requires restart)
375
376 # These are only used if logging_collector is on:
377 log_directory = 'log' # directory where log files are written,
378 # can be absolute or relative to PGDATA
379 log_filename = 'postgresql-%a.log' # log file name pattern,
380 # can include strftime() escapes
381 #log_file_mode = 0600 # creation mode for log files,
382 # begin with 0 to use octal notation
383 log_truncate_on_rotation = on # If on, an existing log file with the
384 # same name as the new log file will be
385 # truncated rather than appended to.
386 # But such truncation only occurs on
387 # time-driven rotation, not on restarts
388 # or size-driven rotation. Default is
389 # off, meaning append to existing files
390 # in all cases.
391 log_rotation_age = 1d # Automatic rotation of logfiles will
392 # happen after that time. 0 disables.
393 log_rotation_size = 0 # Automatic rotation of logfiles will
394 # happen after that much log output.
395 # 0 disables.
396
397 # These are relevant when logging to syslog:
398 #syslog_facility = 'LOCAL0'
399 #syslog_ident = 'postgres'
400 #syslog_sequence_numbers = on
401 #syslog_split_messages = on
402
403 # This is only relevant when logging to eventlog (win32):
404 # (change requires restart)
405 #event_source = 'PostgreSQL'
406
407 # - When to Log -
408
409 #log_min_messages = warning # values in order of decreasing detail:
410 # debug5
411 # debug4
412 # debug3
413 # debug2
414 # debug1
415 # info
416 # notice
417 # warning
418 # error
419 # log
420 # fatal
421 # panic
422
423 #log_min_error_statement = error # values in order of decreasing detail:
424 # debug5
425 # debug4
426 # debug3
427 # debug2
428 # debug1
429 # info
430 # notice
431 # warning
432 # error
433 # log
434 # fatal
435 # panic (effectively off)
436
437 #log_min_duration_statement = -1 # -1 is disabled, 0 logs all statements
438 # and their durations, > 0 logs only
439 # statements running at least this number
440 # of milliseconds
441
442
443 # - What to Log -
444
445 #debug_print_parse = off
446 #debug_print_rewritten = off
447 #debug_print_plan = off
448 #debug_pretty_print = on
449 #log_checkpoints = off
450 #log_connections = off
451 #log_disconnections = off
452 #log_duration = off
453 #log_error_verbosity = default # terse, default, or verbose messages
454 #log_hostname = off
455 log_line_prefix = '%m [%p] ' # special values:
456 # %a = application name
457 # %u = user name
458 # %d = database name
459 # %r = remote host and port
460 # %h = remote host
461 # %p = process ID
462 # %t = timestamp without milliseconds
463 # %m = timestamp with milliseconds
464 # %n = timestamp with milliseconds (as a Unix epoch)
465 # %i = command tag
466 # %e = SQL state
467 # %c = session ID
468 # %l = session line number
469 # %s = session start timestamp
470 # %v = virtual transaction ID
471 # %x = transaction ID (0 if none)
472 # %q = stop here in non-session
473 # processes
474 # %% = '%'
475 # e.g. '<%u%%%d> '
476 #log_lock_waits = off # log lock waits >= deadlock_timeout
477 #log_statement = 'none' # none, ddl, mod, all
478 #log_replication_commands = off
479 #log_temp_files = -1 # log temporary files equal or larger
480 # than the specified size in kilobytes;
481 # -1 disables, 0 logs all temp files
482 log_timezone = 'Japan'
483
484 #------------------------------------------------------------------------------
485 # PROCESS TITLE
486 #------------------------------------------------------------------------------
487
488 #cluster_name = '' # added to process titles if nonempty
489 # (change requires restart)
490 #update_process_title = on
491
492
493 #------------------------------------------------------------------------------
494 # STATISTICS
495 #------------------------------------------------------------------------------
496
497 # - Query and Index Statistics Collector -
498
499 #track_activities = on
500 #track_counts = on
501 #track_io_timing = off
502 #track_functions = none # none, pl, all
503 #track_activity_query_size = 1024 # (change requires restart)
504 #stats_temp_directory = 'pg_stat_tmp'
505
506
507 # - Monitoring -
508
509 #log_parser_stats = off
510 #log_planner_stats = off
511 #log_executor_stats = off
512 #log_statement_stats = off
513
514
515 #------------------------------------------------------------------------------
516 # AUTOVACUUM
517 #------------------------------------------------------------------------------
518
519 #autovacuum = on # Enable autovacuum subprocess? 'on'
520 # requires track_counts to also be on.
521 #log_autovacuum_min_duration = -1 # -1 disables, 0 logs all actions and
522 # their durations, > 0 logs only
523 # actions running at least this number
524 # of milliseconds.
525 #autovacuum_max_workers = 3 # max number of autovacuum subprocesses
526 # (change requires restart)
527 #autovacuum_naptime = 1min # time between autovacuum runs
528 #autovacuum_vacuum_threshold = 50 # min number of row updates before
529 # vacuum
530 #autovacuum_analyze_threshold = 50 # min number of row updates before
531 # analyze
532 #autovacuum_vacuum_scale_factor = 0.2 # fraction of table size before vacuum
533 #autovacuum_analyze_scale_factor = 0.1 # fraction of table size before analyze
534 #autovacuum_freeze_max_age = 200000000 # maximum XID age before forced vacuum
535 # (change requires restart)
536 #autovacuum_multixact_freeze_max_age = 400000000 # maximum multixact age
537 # before forced vacuum
538 # (change requires restart)
539 #autovacuum_vacuum_cost_delay = 20ms # default vacuum cost delay for
540 # autovacuum, in milliseconds;
541 # -1 means use vacuum_cost_delay
542 #autovacuum_vacuum_cost_limit = -1 # default vacuum cost limit for
543 # autovacuum, -1 means use
544 # vacuum_cost_limit
545
546
547 #------------------------------------------------------------------------------
548 # CLIENT CONNECTION DEFAULTS
549 #------------------------------------------------------------------------------
550
551 # - Statement Behavior -
552
553 #client_min_messages = notice # values in order of decreasing detail:
554 # debug5
555 # debug4
556 # debug3
557 # debug2
558 # debug1
559 # log
560 # notice
561 # warning
562 # error
563 #search_path = '"$user", public' # schema names
564 #row_security = on
565 #default_tablespace = '' # a tablespace name, '' uses the default
566 #temp_tablespaces = '' # a list of tablespace names, '' uses
567 # only default tablespace
568 #check_function_bodies = on
569 #default_transaction_isolation = 'read committed'
570 #default_transaction_read_only = off
571 #default_transaction_deferrable = off
572 #session_replication_role = 'origin'
573 #statement_timeout = 0 # in milliseconds, 0 is disabled
574 #lock_timeout = 0 # in milliseconds, 0 is disabled
575 #idle_in_transaction_session_timeout = 0 # in milliseconds, 0 is disabled
576 #vacuum_freeze_min_age = 50000000
577 #vacuum_freeze_table_age = 150000000
578 #vacuum_multixact_freeze_min_age = 5000000
579 #vacuum_multixact_freeze_table_age = 150000000
580 #vacuum_cleanup_index_scale_factor = 0.1 # fraction of total number of tuples
581 # before index cleanup, 0 always performs
582 # index cleanup
583 #bytea_output = 'hex' # hex, escape
584 #xmlbinary = 'base64'
585 #xmloption = 'content'
586 #gin_fuzzy_search_limit = 0
587 #gin_pending_list_limit = 4MB
588
589 # - Locale and Formatting -
590
591 datestyle = 'iso, ymd'
592 #intervalstyle = 'postgres'
593 timezone = 'Japan'
594 #timezone_abbreviations = 'Default' # Select the set of available time zone
595 # abbreviations. Currently, there are
596 # Default
597 # Australia (historical usage)
598 # India
599 # You can create your own file in
600 # share/timezonesets/.
601 #extra_float_digits = 0 # min -15, max 3
602 #client_encoding = sql_ascii # actually, defaults to database
603 # encoding
604
605 # These settings are initialized by initdb, but they can be changed.
606 lc_messages = 'ja_JP.UTF-8' # locale for system error message
607 # strings
608 lc_monetary = 'ja_JP.UTF-8' # locale for monetary formatting
609 lc_numeric = 'ja_JP.UTF-8' # locale for number formatting
610 lc_time = 'ja_JP.UTF-8' # locale for time formatting
611
612 # default configuration for text search
613 default_text_search_config = 'pg_catalog.simple'
614
615 # - Shared Library Preloading -
616
617 shared_preload_libraries = 'timescaledb'
618 #shared_preload_libraries = '' # (change requires restart)
619 #local_preload_libraries = ''
620 #session_preload_libraries = ''
621 #jit_provider = 'llvmjit' # JIT library to use
622
623 # - Other Defaults -
624
625 #dynamic_library_path = '$libdir'
626
627
628 #------------------------------------------------------------------------------
629 # LOCK MANAGEMENT
630 #------------------------------------------------------------------------------
631
632 #deadlock_timeout = 1s
633 #max_locks_per_transaction = 64 # min 10
634 # (change requires restart)
635 #max_pred_locks_per_transaction = 64 # min 10
636 # (change requires restart)
637 #max_pred_locks_per_relation = -2 # negative values mean
638 # (max_pred_locks_per_transaction
639 # / -max_pred_locks_per_relation) - 1
640 #max_pred_locks_per_page = 2 # min 0
641
642
643 #------------------------------------------------------------------------------
644 # VERSION AND PLATFORM COMPATIBILITY
645 #------------------------------------------------------------------------------
646
647 # - Previous PostgreSQL Versions -
648
649 #array_nulls = on
650 #backslash_quote = safe_encoding # on, off, or safe_encoding
651 #default_with_oids = off
652 #escape_string_warning = on
653 #lo_compat_privileges = off
654 #operator_precedence_warning = off
655 #quote_all_identifiers = off
656 #standard_conforming_strings = on
657 #synchronize_seqscans = on
658
659 # - Other Platforms and Clients -
660
661 #transform_null_equals = off
662
663
664 #------------------------------------------------------------------------------
665 # ERROR HANDLING
666 #------------------------------------------------------------------------------
667
668 #exit_on_error = off # terminate session on any error?
669 #restart_after_crash = on # reinitialize after backend crash?
670 #data_sync_retry = off # retry or panic on failure to fsync data?
671
672
673 #------------------------------------------------------------------------------
674 # CONFIG FILE INCLUDES
675 #------------------------------------------------------------------------------
676
677 # These options allow settings to be loaded from files other than the
678 # default postgresql.conf.
679
680 #include_dir = 'conf.d' # include files ending in '.conf' from
681 # directory 'conf.d'
682 #include_if_exists = 'exists.conf' # include file only if it exists
683 #include = 'special.conf' # include file
684
685
686 #------------------------------------------------------------------------------
687 # CUSTOMIZED OPTIONS
688 #------------------------------------------------------------------------------
689
690 # Add settings for extensions here

 

設定を反映するため、PostgreSQLを再起動します。

[root@localhost ~]# systemctl restart postgresql-11
[root@localhost ~]# systemctl status postgresql-11
● postgresql-11.service - PostgreSQL 11 database server
Loaded: loaded (/usr/lib/systemd/system/postgresql-11.service; enabled; vendor preset: disabled)
Active: active (running) since 月 2019-05-06 18:58:38 JST; 5s ago
Docs: https://www.postgresql.org/docs/11/static/
Process: 18644 ExecStartPre=/usr/pgsql-11/bin/postgresql-11-check-db-dir ${PGDATA} (code=exited, status=0/SUCCESS)
Main PID: 18649 (postmaster)
CGroup: /system.slice/postgresql-11.service
├─18649 /usr/pgsql-11/bin/postmaster -D /var/lib/pgsql/11/data/
├─18651 postgres: logger
├─18653 postgres: checkpointer
├─18654 postgres: background writer
├─18655 postgres: walwriter
├─18656 postgres: autovacuum launcher
├─18657 postgres: stats collector
├─18658 postgres: TimescaleDB Background Worker Launcher
├─18659 postgres: logical replication launcher
├─18663 postgres: zabbix zabbix ::1(37444) idle
├─18664 postgres: zabbix zabbix ::1(37446) idle
├─18665 postgres: zabbix zabbix ::1(37448) idle
├─18666 postgres: zabbix zabbix ::1(37450) idle
├─18668 postgres: zabbix zabbix ::1(37452) idle
├─18669 postgres: zabbix zabbix ::1(37454) idle
└─18670 postgres: zabbix zabbix ::1(37456) idle

5月 6 18:58:37 localhost.localdomain systemd[1]: Starting PostgreSQL 11 database server...
5月 6 18:58:38 localhost.localdomain postmaster[18649]: 2019-05-06 18:58:38.046 JST [18649] LOG: IPv4アドレス…ます
5月 6 18:58:38 localhost.localdomain postmaster[18649]: 2019-05-06 18:58:38.046 JST [18649] LOG: IPv6アドレス…ます
5月 6 18:58:38 localhost.localdomain postmaster[18649]: 2019-05-06 18:58:38.078 JST [18649] LOG: Unixソケット…ます
5月 6 18:58:38 localhost.localdomain postmaster[18649]: 2019-05-06 18:58:38.085 JST [18649] LOG: Unixソケット…ます
5月 6 18:58:38 localhost.localdomain postmaster[18649]: 2019-05-06 18:58:38.128 JST [18649] LOG: ログ出力をロ…ます
5月 6 18:58:38 localhost.localdomain postmaster[18649]: 2019-05-06 18:58:38.128 JST [18649] ヒント: ここからの…す。
5月 6 18:58:38 localhost.localdomain systemd[1]: Started PostgreSQL 11 database server.
Hint: Some lines were ellipsized, use -l to show in full.

 

 

データベースでTimescaleDB extensionを有効化

以下のコマンドを実行し、TimescaleDB extensionを有効化します。

[root@localhost ~]# echo "CREATE EXTENSION IF NOT EXISTS timescaledb CASCADE;" | sudo -u postgres psql zabbix
could not change directory to "/root": 許可がありません
WARNING:
WELCOME TO
_____ _ _ ____________
|_ _(_) | | | _ \ ___ \
| | _ _ __ ___ ___ ___ ___ __ _| | ___| | | | |_/ /
| | | | _ ` _ \ / _ \/ __|/ __/ _` | |/ _ \ | | | ___ \
| | | | | | | | | __/\__ \ (_| (_| | | __/ |/ /| |_/ /
|_| |_|_| |_| |_|\___||___/\___\__,_|_|\___|___/ \____/
Running version 1.3.0
For more information on TimescaleDB, please visit the following links:

1. Getting started: https://docs.timescale.com/getting-started
2. API reference documentation: https://docs.timescale.com/api
3. How TimescaleDB is designed: https://docs.timescale.com/introduction/architecture

Note: TimescaleDB collects anonymous reports to better understand and assist our users.
For more information and how to disable, please see our docs https://docs.timescaledb.com/using-timescaledb/telemetry.

CREATE EXTENSION

 

 

TimescaleDBのスキーマスクリプトを実施

/usr/share/doc/zabbix-server-pgsql-4.2.1/にある「timescaledb.sql.gz」を読み込み、TimescaleDBのスキーマを追加します。

[root@localhost ~]# ls /usr/share/doc/zabbix-server-pgsql-4.2.1/
AUTHORS COPYING ChangeLog NEWS README create.sql.gz timescaledb.sql.gz
[root@localhost ~]# zcat /usr/share/doc/zabbix-server-pgsql-4.2.1/timescaledb.sql.gz | sudo -u zabbix psql zabbix
could not change directory to "/root": 許可がありません
NOTICE: migrating data to chunks
DETAIL: Migration might take a while depending on the amount of data.
create_hypertable
----------------------
(1,public,history,t)
(1 row)

NOTICE: migrating data to chunks
DETAIL: Migration might take a while depending on the amount of data.
create_hypertable
---------------------------
(2,public,history_uint,t)
(1 row)

create_hypertable
--------------------------
(3,public,history_log,t)
(1 row)

create_hypertable
---------------------------
(4,public,history_text,t)
(1 row)

NOTICE: migrating data to chunks
DETAIL: Migration might take a while depending on the amount of data.
create_hypertable
--------------------------
(5,public,history_str,t)
(1 row)

NOTICE: migrating data to chunks
DETAIL: Migration might take a while depending on the amount of data.
create_hypertable
---------------------
(6,public,trends,t)
(1 row)

NOTICE: migrating data to chunks
DETAIL: Migration might take a while depending on the amount of data.
create_hypertable
--------------------------
(7,public,trends_uint,t)
(1 row)

UPDATE 1

 

 

TimescaleDB用に調整

ドキュメントを見る限り、

Zabbixダッシュボードで Administration > General > Housekeepingと進み、

Override item history period/Override item trend periodを調整すればいいようです。

TimescaleDB用パラメータに関する画像

 

HouseKeepingの画面

 

実際に使ってみてどうなるかわ、今後試してみようと思います。

 

p> アフィリエイトのアクセストレード

 

www.slideshare.net

github.com

www.facebook.com

twitter.com

www.instagram.com

 

 

にほんブログ村 IT技術ブログ Linuxへ
Linux

にほんブログ村 IT技術ブログ オープンソースへ
オープンソース

 

 

Opensourcetech by Takahiro Kujirai