Upgrade do PostgreSQL 15 para 17 e TimescaleDB 2.17.2 para 2.21.4

🎥 Vídeo tutorial:
👉 CLIQUE AQUI PARA ASSISTIR: Upgrade do PostgreSQL e TimescaleDB no Zabbix 7


Introdução

No tutorial de hoje, vamos realizar o upgrade de versão do PostgreSQL e do TimescaleDB em um ambiente que executa o Zabbix 7.

Nosso cenário inicial possui o PostgreSQL 15 e o TimescaleDB 2.17.2. Após o procedimento, o ambiente será atualizado para o PostgreSQL 17 e o TimescaleDB 2.21.4.

Antes de iniciar, lembre-se de instalar os repositórios do PostgreSQL e do TimescaleDB para garantir que as versões estejam disponíveis.


Passo a passo

1. Parar o Zabbix Server

service zabbix-server stop

2. Listar as versões disponíveis do TimescaleDB para PostgreSQL 17

apt list -a timescaledb-2-postgresql-17

3. Instalar PostgreSQL 17 + TimescaleDB 2.17.2

apt install timescaledb-2-postgresql-17='2.17.2*' timescaledb-2-loader-postgresql-17='2.17.2*'

4. Listar os clusters ativos

pg_lsclusters

5. Criar o cluster da versão 17

pg_createcluster 17 main --start

6. Parar ambos os clusters antes do upgrade

systemctl stop postgresql@15-main
systemctl stop postgresql@17-main

7. Configurar a extensão TimescaleDB no PostgreSQL 17

echo "shared_preload_libraries = 'timescaledb'" >> /etc/postgresql/17/main/postgresql.conf

8. Checar compatibilidade dos clusters

sudo su - postgres
cd /tmp
/usr/lib/postgresql/17/bin/pg_upgrade \
--old-datadir=/var/lib/postgresql/15/main \
--new-datadir=/var/lib/postgresql/17/main \
--old-bindir=/usr/lib/postgresql/15/bin \
--new-bindir=/usr/lib/postgresql/17/bin \
--old-options '-c config_file=/etc/postgresql/15/main/postgresql.conf' \
--new-options '-c config_file=/etc/postgresql/17/main/postgresql.conf' \
--new-options "-c timescaledb.restoring='on'" \
--check

9. Efetuar o upgrade real

/usr/lib/postgresql/17/bin/pg_upgrade \
--old-datadir=/var/lib/postgresql/15/main \
--new-datadir=/var/lib/postgresql/17/main \
--old-bindir=/usr/lib/postgresql/15/bin \
--new-bindir=/usr/lib/postgresql/17/bin \
--old-options '-c config_file=/etc/postgresql/15/main/postgresql.conf' \
--new-options '-c config_file=/etc/postgresql/17/main/postgresql.conf' \
--new-options "-c timescaledb.restoring='on'"

10. Ajustar as portas e conexões dos clusters

Editar o conf do PostgreSQL 17:

nano /etc/postgresql/17/main/postgresql.conf

Defina:

port = 5432
max_connections = 300
reserved_connections = 10
superuser_reserved_connections = 10

Editar o conf do PostgreSQL 15:

nano /etc/postgresql/15/main/postgresql.conf

Ajuste:

port = 5433

11. Reiniciar o cluster da versão 17

systemctl restart postgresql@17-main

12. Executar o Analyze com VacuumDB

sudo -u postgres /usr/lib/postgresql/17/bin/vacuumdb --all --analyze-in-stages

13. Validar a versão do TimescaleDB no banco Zabbix

echo "SELECT default_version, installed_version FROM pg_available_extensions WHERE name = 'timescaledb';" | sudo -u postgres psql zabbix

14. Reiniciar o Zabbix Server

service zabbix-server restart

Verifique os logs:

tail -n 200 /var/log/zabbix/zabbix_server.log

15. Atualizando o TimescaleDB para 2.21.4

Pare o serviço do zabbix-server:

service zabbix-server stop

Instale a nova versão:

apt install timescaledb-2-postgresql-17='2.21.4*' timescaledb-2-loader-postgresql-17='2.21.4*'

Atualize a extensão:

su postgres
psql -X
\c zabbix
ALTER EXTENSION timescaledb UPDATE TO '2.21.4';

Reinicie os serviços:

systemctl restart postgresql@17-main
service zabbix-server restart

Valide os logs:

tail -n 200 /var/log/zabbix/zabbix_server.log

Conclusão

Com o processo concluído, seu ambiente Zabbix 7 está agora utilizando o PostgreSQL 17 com o TimescaleDB 2.21.4, garantindo compatibilidade, performance aprimorada.