The following covers setting up your database and creating database indexes.
To maximize performance EJBCA runs with Optimistic Locking turned on, which sacrifices concurrent transactions to the same database row in place of shorter database roundtrips. If connecting multiple instances of EJBCA to the same database schema, ensure that these will not update the same end entities concurrently, or this will result in attempting to write data onto dirty table rows and thus failed transactions.
Database Setup #
Create a database and database user according to the following examples for MariaDB/MySQL, Oracle XE, and PostgreSQL.
MariaDB/MySQL #
In MariaDB, use the following commands to create the database, matching the DataSource in the next step, and add privileges to connect to the database:
You should define secure passwords for your database in production. You can also improve security by limiting access to tables. For more information, see Database Privileges.
If you do not set utf8 as character set, then EJBCA may not start because of index limitations if using the default charset utf8mb4 in some configurations of MariaDB/MySQL. It will result in the following error: Specified key was too long; max key length is 767 bytes
Thus, you can use a command like the following instead:
In some configurations for InnoDB the binlog_format defaults to statement. Running EJBCA requires is to be set to row. For example: binlog_format=row
MySQL version 8 or later
As of MySQL version 8, users cannot be implicitly created using the GRANT command. If running MySQL version 8 or later, create the ejbca user first according to the following example:
Oracle XE version 11g Release 2 #
Connect to Oracle database using sqlplus (or similar tool) as sysdba:
And create an ejbca user and grant it the following permissions:
On the EJBCA side in the database.properties file, set the following parameters:
PostgreSQL #
-
After installing the PostgreSQL database, set the client authentication for local UNIX domain socket connections from
peer
tomd5
:If the
pg_hba.conf
file is not located under the path/etc/postgresql/10/main/pg_hba.conf,
log in to the PostgreSQL CLI and use the following to find the location of the file: -
Restart the PostgreSQL service:
-
Login to the user postgres and assign a password:
-
Create a new database and username:
-
Create EJBCA tables and indexes:
Create Database Indexes #
As the database grows, it is important to have correct database indexes to maintain good performance.
The following SQL file that is ready to run on your database contains a set of recommended database indexes that can be applied to your database:
doc/sql-scripts/create-index-ejbca.sql
.
If you are confident in what you are doing, you may also apply partitions and compression. The following SQL example file, provided for MariaDB / MySQL, should be analyzed for your specific workload and database maintenance processes and not applied blindly:
doc/sql-scripts/optimize-ejbca-mysql.sql
Applying partitions and compression may cause adverse effects if used incorrectly.
EJBCA will run well without this optimization and it can be ignored for most installations.