Upgrade Zabbix
Upgrade PostgreSQL
Checando o PostgreSQL Atual
$ sudo su - postgres
$ psql
# select version();
version
---------------------------------------------------------------------------------------------------------
PostgreSQL 13.7 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 8.5.0 20210514 (Red Hat 8.5.0-10), 64-bit
(1 row)
# \db+
List of tablespaces
Name | Owner | Location | Access privileges | Options | Size | Description
------------+----------+---------------+-------------------+---------+--------+-------------
pg_default | postgres | | | | 23 MB |
pg_global | postgres | | | | 567 kB |
tbzabbix | postgres | /pgsql/zabbix | | | 46 MB |
# \l+
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges | Size | Tablespace | Description
-----------+----------+----------+-------------+-------------+-----------------------+---------+------------+--------------------------------------------
postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | | 7925 kB | pg_default | default administrative connection database
template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +| 7753 kB | pg_default | unmodifiable empty database
| | | | | postgres=CTc/postgres | | |
template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +| 7753 kB | pg_default | default template for new databases
| | | | | postgres=CTc/postgres | | |
zabbix | zabbix | UTF8 | en_US.UTF-8 | en_US.UTF-8 | | 46 MB | tbzabbix |
(4 rows)
# \du+
List of roles
Role name | Attributes | Member of | Description
-----------+------------------------------------------------------------+-----------+-------------
postgres | Superuser, Create role, Create DB, Replication, Bypass RLS | {} |
zabbix | | {} |
Fazendo upgrade do PostgreSQL
$ sudo dnf install postgresql14-server postgresql14-contrib timescaledb-2-postgresql-14
$ sudo postgresql-14-setup initdb
$ sudo vim /var/lib/pgsql/14/data/postgresql.conf
[...]
#port = 5432 # (change requires restart)
port = 5433 # (change requires restart)
[...]
$ sudo systemctl start postgresql-14
$ sudo su - postgres
$ psql -p 5433
# select version();
version
---------------------------------------------------------------------------------------------------------
PostgreSQL 14.4 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 8.5.0 20210514 (Red Hat 8.5.0-10), 64-bit
(1 row)
postgres=# show port;
port
------
5433
(1 row)
postgres=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+-------------+-------------+-----------------------
postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
(3 rows)
postgres=# \du
List of roles
Role name | Attributes | Member of
-----------+------------------------------------------------------------+-----------
postgres | Superuser, Create role, Create DB, Replication, Bypass RLS | {}
postgres=# \q
$ ps -ef | grep postmaster
postgres 6869 1 0 19:41 ? 00:00:01 /usr/pgsql-13/bin/postmaster -D /var/lib/pgsql/13/data/
postgres 10188 1 0 20:51 ? 00:00:00 /usr/pgsql-14/bin/postmaster -D /var/lib/pgsql/14/data/
postgres 10381 10222 0 20:55 pts/0 00:00:00 grep --color=auto postmaster
$ /usr/pgsql-13/bin/pg_ctl -D /var/lib/pgsql/13/data status
pg_ctl: server is running (PID: 6869)
/usr/pgsql-13/bin/postgres "-D" "/var/lib/pgsql/13/data/"
$ /usr/pgsql-14/bin/pg_ctl -D /var/lib/pgsql/14/data status
pg_ctl: server is running (PID: 10188)
/usr/pgsql-14/bin/postgres "-D" "/var/lib/pgsql/14/data/"
$ /usr/pgsql-13/bin/pg_ctl -D /var/lib/pgsql/13/data stop
waiting for server to shut down.... done
server stopped
$ /usr/pgsql-14/bin/pg_ctl -D /var/lib/pgsql/14/data stop
waiting for server to shut down.... done
server stopped
$ /usr/pgsql-14/bin/pg_upgrade --help
pg_upgrade upgrades a PostgreSQL cluster to a different major version.
Usage:
pg_upgrade [OPTION]...
Options:
-b, --old-bindir=BINDIR old cluster executable directory
-B, --new-bindir=BINDIR new cluster executable directory (default
same directory as pg_upgrade)
-c, --check check clusters only, don't change any data
-d, --old-datadir=DATADIR old cluster data directory
-D, --new-datadir=DATADIR new cluster data directory
-j, --jobs=NUM number of simultaneous processes or threads to use
-k, --link link instead of copying files to new cluster
-o, --old-options=OPTIONS old cluster options to pass to the server
-O, --new-options=OPTIONS new cluster options to pass to the server
-p, --old-port=PORT old cluster port number (default 50432)
-P, --new-port=PORT new cluster port number (default 50432)
-r, --retain retain SQL and log files after success
-s, --socketdir=DIR socket directory to use (default current dir.)
-U, --username=NAME cluster superuser (default "postgres")
-v, --verbose enable verbose internal logging
-V, --version display version information, then exit
--clone clone instead of copying files to new cluster
-?, --help show this help, then exit
Before running pg_upgrade you must:
create a new database cluster (using the new version of initdb)
shutdown the postmaster servicing the old cluster
shutdown the postmaster servicing the new cluster
When you run pg_upgrade, you must provide the following information:
the data directory for the old cluster (-d DATADIR)
the data directory for the new cluster (-D DATADIR)
the "bin" directory for the old version (-b BINDIR)
the "bin" directory for the new version (-B BINDIR)
For example:
pg_upgrade -d oldCluster/data -D newCluster/data -b oldCluster/bin -B newCluster/bin
or
$ export PGDATAOLD=oldCluster/data
$ export PGDATANEW=newCluster/data
$ export PGBINOLD=oldCluster/bin
$ export PGBINNEW=newCluster/bin
$ pg_upgrade
Report bugs to <pgsql-bugs@lists.postgresql.org>.
PostgreSQL home page: <https://www.postgresql.org/>
Upgrade do timescaledb
$ timescaledb-tune --pg-config=/usr/pgsql-14/bin/pg_config
Using postgresql.conf at this path:
/var/lib/pgsql/14/data/postgresql.conf
Is this correct? [(y)es/(n)o]: y
Writing backup to:
/tmp/timescaledb_tune.backup202207191237
shared_preload_libraries needs to be updated
Current:
#shared_preload_libraries = ''
Recommended:
shared_preload_libraries = 'timescaledb'
Is this okay? [(y)es/(n)o]: y
success: shared_preload_libraries will be updated
Tune memory/parallelism/WAL and other settings? [(y)es/(n)o]: y
Recommendations based on 3.56 GB of available memory and 2 CPUs for PostgreSQL 14
Memory settings recommendations
Current:
shared_buffers = 128MB
#effective_cache_size = 4GB
#maintenance_work_mem = 64MB
#work_mem = 4MB
Recommended:
shared_buffers = 932008kB
effective_cache_size = 2730MB
maintenance_work_mem = 466004kB
work_mem = 9320kB
Is this okay? [(y)es/(s)kip/(q)uit]: y
success: memory settings will be updated
Parallelism settings recommendations
Current:
missing: timescaledb.max_background_workers
#max_worker_processes = 8
#max_parallel_workers_per_gather = 2
#max_parallel_workers = 8
Recommended:
timescaledb.max_background_workers = 8
max_worker_processes = 13
max_parallel_workers_per_gather = 1
max_parallel_workers = 2
Is this okay? [(y)es/(s)kip/(q)uit]: y
success: parallelism settings will be updated
WAL settings recommendations
Current:
#wal_buffers = -1
min_wal_size = 80MB
Recommended:
wal_buffers = 16MB
min_wal_size = 512MB
Is this okay? [(y)es/(s)kip/(q)uit]: y
success: WAL settings will be updated
Miscellaneous settings recommendations
Current:
#default_statistics_target = 100
#random_page_cost = 4.0
#checkpoint_completion_target = 0.9
max_connections = 100
#max_locks_per_transaction = 64
#autovacuum_max_workers = 3
#autovacuum_naptime = 1min
#effective_io_concurrency = 1
Recommended:
default_statistics_target = 500
random_page_cost = 1.1
checkpoint_completion_target = 0.9
max_connections = 50
max_locks_per_transaction = 64
autovacuum_max_workers = 10
autovacuum_naptime = 10
effective_io_concurrency = 256
Is this okay? [(y)es/(s)kip/(q)uit]: y
success: miscellaneous settings will be updated
Saving changes to: /var/lib/pgsql/14/data/postgresql.conf
$ /usr/pgsql-14/bin/pg_upgrade --old-datadir "/var/lib/pgsql/13/data" --new-datadir "/var/lib/pgsql/14/data" --old-bindir "/usr/pgsql-13/bin" --new-bindir "/usr/pgsql-14/bin"
Performing Consistency Checks
-----------------------------
Checking cluster versions ok
Checking database user is the install user ok
Checking database connection settings ok
Checking for prepared transactions ok
Checking for system-defined composite types in user tables ok
Checking for reg* data types in user tables ok
Checking for contrib/isn with bigint-passing mismatch ok
Checking for user-defined encoding conversions ok
Checking for user-defined postfix operators ok
Creating dump of global objects ok
Creating dump of database schemas
ok
Checking for presence of required libraries ok
Checking database user is the install user ok
Checking for prepared transactions ok
Checking for new cluster tablespace directories ok
If pg_upgrade fails after this point, you must re-initdb the
new cluster before continuing.
Performing Upgrade
------------------
Analyzing all rows in the new cluster ok
Freezing all rows in the new cluster ok
Deleting files from new pg_xact ok
Copying old pg_xact to new server ok
Setting oldest XID for new cluster ok
Setting next transaction ID and epoch for new cluster ok
Deleting files from new pg_multixact/offsets ok
Copying old pg_multixact/offsets to new server ok
Deleting files from new pg_multixact/members ok
Copying old pg_multixact/members to new server ok
Setting next multixact ID and offset for new cluster ok
Resetting WAL archives ok
Setting frozenxid and minmxid counters in new cluster ok
Restoring global objects in the new cluster ok
Restoring database schemas in the new cluster
ok
Copying user relation files
ok
Setting next OID for new cluster ok
Sync data directory to disk ok
Creating script to delete old cluster ok
Checking for extension updates ok
Upgrade Complete
----------------
Optimizer statistics are not transferred by pg_upgrade.
Once you start the new server, consider running:
/usr/pgsql-14/bin/vacuumdb --all --analyze-in-stages
Running this script will delete the old cluster's data files:
./delete_old_cluster.sh
$ vim 14/data/postgresql.conf
[...]
port = 5432 # (change requires restart)
#port = 5433 # (change requires restart)
[...]
$ /usr/pgsql-14/bin/pg_ctl -D /var/lib/pgsql/14/data start
waiting for server to start....2022-07-19 12:45:13.782 UTC [49292] LOG: redirecting log output to logging collector process
2022-07-19 12:45:13.782 UTC [49292] HINT: Future log output will appear in directory "log".
done
server started
$ psql
psql (14.4)
Type "help" for help.
postgres=# select version();
version
---------------------------------------------------------------------------------------------------------
PostgreSQL 14.4 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 8.5.0 20210514 (Red Hat 8.5.0-10), 64-bit
(1 row)
postgres=# \l+
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges | Size | Tablespace | Description
-----------+----------+----------+-------------+-------------+-----------------------+---------+------------+--------------------------------------------
postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | | 8569 kB | pg_default | default administrative connection database
template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +| 8593 kB | pg_default | unmodifiable empty database
| | | | | postgres=CTc/postgres | | |
template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | postgres=CTc/postgres+| 8569 kB | pg_default | default template for new databases
| | | | | =c/postgres | | |
zabbix | zabbix | UTF8 | en_US.UTF-8 | en_US.UTF-8 | | 60 MB | tbzabbix |
(4 rows)
postgres=# \db+
List of tablespaces
Name | Owner | Location | Access privileges | Options | Size | Description
------------+----------+---------------+-------------------+---------+--------+-------------
pg_default | postgres | | | | 25 MB |
pg_global | postgres | | | | 568 kB |
tbzabbix | postgres | /pgsql/zabbix | | | 60 MB |
(3 rows)
postgres=# \du+
List of roles
Role name | Attributes | Member of | Description
-----------+------------------------------------------------------------+-----------+-------------
postgres | Superuser, Create role, Create DB, Replication, Bypass RLS | {} |
zabbix | | {} |
Atualizando o acesso do zabbix
$ vim /var/lib/pgsql/13/data/pg_hba.conf
[...]
# Acesso Zabbix
host zabbix zabbix 127.0.0.1/32 scram-sha-256
host zabbix zabbix 10.0.240.0/24 scram-sha-256
$ vim /var/lib/pgsql/13/data/postgresql.conf
[...]
listen_addresses = 'localhost,10.0.240.100'
[...]
$ /usr/pgsql-14/bin/pg_ctl -D /var/lib/pgsql/14/data stop
$ exit
$ sudo systemctl start postgresql-14
$ sudo systemctl enable postgresql-14
$ sudo systemctl disable postgresql-13
Upgrade do zabbix server
$ sudo systemctl stop zabbix-server
$ sudo systemctl stop zabbix-agent2
$ sudo rpm -Uvh https://repo.zabbix.com/zabbix/6.2/rhel/8/x86_64/zabbix-release-6.2-1.el8.noarch.rpm
Retrieving https://repo.zabbix.com/zabbix/6.2/rhel/8/x86_64/zabbix-release-6.2-1.el8.noarch.rpm
Verifying... ################################# [100%]
Preparing... ################################# [100%]
Updating / installing...
1:zabbix-release-6.2-1.el8 ################################# [ 50%]
Cleaning up / removing...
2:zabbix-release-6.0-2.el8 ################################# [100%]
$ sudo dnf clean all
$ sudo dnf upgrade zabbix-server-pgsql zabbix-agent2 zabbix-selinux-policy zabbix-sql-scripts
$ sudo systemctl start zabbix-server
$ sudo systemctl start zabbix-agent2
$ cat /var/log/zabbix/zabbix_server.log | grep database | tail -n 4
10586:20220719:132353.438 completed 97% of database upgrade
10586:20220719:132353.449 completed 98% of database upgrade
10586:20220719:132353.458 completed 100% of database upgrade
10586:20220719:132353.460 database upgrade fully completed
Upgrade zabbix web
$ sudo rpm -Uvh https://repo.zabbix.com/zabbix/6.2/rhel/8/x86_64/zabbix-release-6.2-1.el8.noarch.rpm
Retrieving https://repo.zabbix.com/zabbix/6.2/rhel/8/x86_64/zabbix-release-6.2-1.el8.noarch.rpm
Verifying... ################################# [100%]
Preparing... ################################# [100%]
Updating / installing...
1:zabbix-release-6.2-1.el8 ################################# [ 50%]
Cleaning up / removing...
2:zabbix-release-6.0-2.el8 ################################# [100%]
$ sudo dnf clean all
$ sudo dnf upgrade zabbix-web-pgsql zabbix-apache-conf zabbix-agent2 zabbix-selinux-policy
$ sudo systemctl restart httpd
ReferĂȘncias