1 Database creation

Overview

A Zabbix database must be created during the installation of Zabbix server or proxy.

This section provides instructions for creating a Zabbix database. A separate set of instructions is available for each supported database.

UTF-8 is the only encoding supported by Zabbix. It is known to work without any security flaws. Users should be aware that there are known security issues if using some of the other encodings.

If installing from Zabbix Git repository, you need to run the following command prior to proceeding to the next steps:

$ make dbschema

MySQL

Character set utf8 and utf8_bin collation is required for Zabbix server/proxy to work properly with MySQL database.

If you are installing from Zabbix packages, proceed to the instructions for your platform.

If you are installing Zabbix from sources:

  • Create and configure a database and a user.
mysql -uroot -p<password>
       
       mysql> create database zabbix character set utf8 collate utf8_bin;
       mysql> create user 'zabbix'@'localhost' identified by '<password>';
       mysql> grant all privileges on zabbix.* to 'zabbix'@'localhost';
       mysql> quit;
  • Import the data into the database. For a Zabbix proxy database, only schema.sql should be imported (no images.sql nor data.sql).
cd database/mysql
       mysql -uzabbix -p<password> zabbix < schema.sql
       # stop here if you are creating database for Zabbix proxy
       mysql -uzabbix -p<password> zabbix < images.sql
       mysql -uzabbix -p<password> zabbix < data.sql

PostgreSQL

You need to have database user with permissions to create database objects.

If you are installing from Zabbix packages, proceed to the instructions for your platform.

If you are installing Zabbix from sources:

  • Create a database user.

The following shell command will create user zabbix. Specify a password when prompted and repeat the password (note, you may first be asked for sudo password):

sudo -u postgres createuser --pwprompt zabbix
  • Create a database.

The following shell command will create the database zabbix (last parameter) with the previously created user as the owner (-O zabbix).

sudo -u postgres createdb -O zabbix -E Unicode -T template0 zabbix
  • Import the initial schema and data (assuming you are in the root directory of Zabbix sources).

For a Zabbix proxy database, only schema.sql should be imported (no images.sql nor data.sql).

cd database/postgresql
       cat schema.sql | sudo -u zabbix psql zabbix
       # stop here if you are creating database for Zabbix proxy
       cat images.sql | sudo -u zabbix psql zabbix
       cat data.sql | sudo -u zabbix psql zabbix

The above commands are provided as an example that will work in most of GNU/Linux installations. You can use different commands depending on how your system/database is configured, for example:

psql -U <username>

If you have any trouble setting up the database, please consult your Database administrator.

TimescaleDB

Instructions for creating and configuring TimescaleDB are provided in a separate section.

Oracle

We assume that a zabbix database user with password password exists and has permissions to create database objects in ORCL service located on the host Oracle database server with a user shell user having write access to /tmp directory. Zabbix requires a Unicode database character set and a UTF8 national character set. Check current settings:

sqlplus> select parameter,value from v$nls_parameters where parameter='NLS_CHARACTERSET' or parameter='NLS_NCHAR_CHARACTERSET';

If you are creating a database for Zabbix server you need to have images from Zabbix sources on the host where Oracle is running. Copy them to a directory /tmp/zabbix_images on the Oracle host:

cd /path/to/zabbix-sources
       ssh user@oracle_host "mkdir /tmp/zabbix_images"
       scp -r misc/images/png_modern user@oracle_host:/tmp/zabbix_images/

Now prepare the database:

cd /path/to/zabbix-sources/database/oracle
       sqlplus zabbix/password@oracle_host/ORCL
       
       sqlplus> @schema.sql
       # stop here if you are creating database for Zabbix proxy
       sqlplus> @images.sql
       sqlplus> @data.sql

Please set the initialization parameter CURSOR_SHARING=FORCE for best performance.

Now the temporary directory can be removed:

ssh user@oracle_host "rm -rf /tmp/zabbix_images"

SQLite

Using SQLite is supported for Zabbix proxy only!

The database will be automatically created if it does not exist.

Return to the installation section.

Additional patches

In some cases, Zabbix might generate non-optimized queries to the database. This may happen, for example, as a result of using an older database version.
Additional DB patches are available for resolving such issues on the specific database or, sometimes, a specific database version. See Known issues for the list of known problems and available patches.