Migrating from MySQL to PostgreSQL



The publication is based on the report of Alexander Petrov-Gavrilov, trainer and Zabbix technical support engineer.



Many people are worried about how to migrate from MySQL to PostgreSQL and take advantage of TimescaleDB.



Why migrate



The first question that usually arises is why migrate from MySQL to PostgreSQL when using Zabbix.



, . :



  • PostgeSQL.
  • TimescaleDB, .
  • PostgreSQL Pro.


. , , . , , . Zabbix .



  • PostgreSQL MySQL Zabbix DB.
  • , buffer transaction log.
  • MySQL , PostgreSQL.
  • PostgreSQL foreign key, . . .
  • PostgreSQL IO.




, MySQL PostgreSQL :



  • Zabbix 5.0,
  • CentOS 7,
  • MariaDB 5.5.65 ( « » CentOS ).


. .



:



  • PostgreSQL,
  • PGloader,
  • Zabbix.


. PGloader .



1). PostgreSQL.



# yum install https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm



# yum install postgresql12-server



# /usr/pgsql-12/bin/postgresql-12-setup initdb # systemctl enable postgresql-12 # systemctl start postgresql-12



PostgreSQL PostgreSQL, , . , pg_hba.conf, .



2). pgloader.



# yum install pgloader



# pgloader -V



# pgloader version "3.6.2



pgloader PosgreSQL, # yum install pgloader. PosgreSQL 12, , pgloader 3.6.2.



3). .



# mkdir myzabbix-pgzabbix



# cd myzabbix-pgzabbix



, . Zabbix.



4). Zabbix.



# yum install wget



# wget https://cdn.zabbix.com/zabbix/sources/stable/5.0/zabbix -5.0.1.tar.gz



CentOS, wget, « », CentOS. Zabbix, Zabbix, , Zabbix Zabbix.



5). , , , .



# tar -zxvf zabbix -5.0.1.tar.gz



6). schema.sql create.sql alter.sql.



Zabbix sql- PostgreSQL, MySQL. , schema.sql, , . . alter.sql, , . .



# cd myzabbix-pgzabbix/zabbix-5.0.1/database/postgresql/



# sed -n '/CREATE.*/,/INSERT.*$/p' schema.sql | head -n-1 > create.sql



# grep ALTER schema.sql > alter.sql



7). PostgreSQL



# sudo -u postgres createuser --pwprompt zabbix



# sudo -u postgres createdb -O zabbix zabbix



PosgreSQL Zabbix.



. Zabbix .



8). , create.sql alter.sql



LOAD DATABASE FROM mysql://zabbix:zabbix-password@localhost/zabbix INTO postgresql://zabbix:zabbix-password@localhost/zabbix WITH include no drop, truncate, create no tables, create no indexes, no foreign keys, reset sequences, data only SET maintenance_work_mem TO '1024MB', work_mem to '256MB' ALTER SCHEMA 'zabbix' RENAME TO 'public' BEFORE LOAD EXECUTE create.sql AFTER LOAD EXECUTE alter.sql;



, , , , . pgloader COPY) PostgreSQL.



, . , , , ( , ).



. pgloader public.



. schema.sql Zabbix, , alter.sql.





1). Zabbix Server.



systemctl stop zabbix -server



Zabbix Server , - .



. . . csv-.



. , , .



2). pgloader.



# pgloader zabbix -migrate.load



pgloader , .



3). Warnings — .







4). .



, , , , , ( ).







5). .



PostgreSQL — , , . .





PostgreSQL



, .





PostgreSQL





1). Zabbix MySQL.



# yum remove Zabbix -server -mysql



2). MySQL.



# yum remove zabbix -web - *



3). Zabbix PostgreSQL.



# yum install zabbix -server -pgsql



4). PostgreSQL.



# yum install zabbix -web -pgsql -scl zabbix -apache -conf -scl



5). zabbix_server.conf



# vi /etc/zabbix/zabbix_server.conf



6). .



# DBPassword=zabbix



7). ().



# rm /etc/zabbix/web/zabbix.conf.php



8). .



# vi /etc/httpd/conf.d/zabbix.conf



9). Zabbix Server, httpd.



# systemctl restart zabbix -server httpd



10). - PostgreSQL.





11). .





12). MySQL.



# systemctl stop mariadb





, Zabbix 4.0 , TimescaleDB. Zabbix.






All Articles