3.8 Create a new database for Retain

3.8.1 MySQL

NOTE:Requires that Connector/J also be installed.

  1. Download and install the latest 5.6x MySQL server and client and configure according to local system needs.

    Install the server: rpm -ivh MySQL-server-5.6.3.5-1.sles11.x86_64.rpm

    install the client: rpm -ivh MySQL-client-5.6.3.5-1.sles11.x86_64.rpm

    Modify /usr/my.cnf, to move the database to a data volume, by adding the line datadir=/path/to/where/you/want/the/MySQL/data

    Find the root password in /root/.mysql_secret

    cat /root/.mysql_secret

    Start MySQL:

    rcmysql start

    Change the root password:

    /usr/bin/mysql_secure_installation

  2. Log in to MySQL using the client:

    mysql -u root -p

  3. Create the database: * This is critical. Not storing the database in UTF-8 format guarantees irreparable corruption for non-US-ASCII characters. *

    CREATE DATABASE retain DEFAULT CHARACTER SET 'utf8' DEFAULT COLLATE 'utf8_bin';

    1. If you make a mistake, enter this command:

      DROP DATABASE retain;

      …and repeat step 3 to create the database.

  4. Retain needs a user account created that has full rights to the Retain database. It is strongly recommended that the ‘root’ account is not used. While logged in to MySQL, enter the following commands. Replace (UserName) and (Password) with the desired user name and password (Both commands are needed. The ‘%’ is a wildcard. If you want to restrict the connection to a specific IP address, put that address instead of the ‘%’ sign.):

    GRANT ALL PRIVILEGES ON retain.* TO '(UserName)'@'%' IDENTIFIED BY '(Password)';

    GRANT ALL PRIVILEGES ON retain.* TO '(Username)'@'localhost' IDENTIFIED BY '(Password)';

    For example, if the database user's name is "retain" and the password is "Password1":

    GRANT ALL PRIVILEGES ON retain.* TO 'retain'@'%' IDENTIFIED BY 'P@ssword1';

    GRANT ALL PRIVILEGES ON retain.* TO 'retain'@'localhost' IDENTIFIED BY 'P@ssword1';

3.8.2 MySQL Connector/J (JDBC driver for MySQL) Installation

The MySQL Connector/J driver must be provided to the Retain Server and/or the Reporting and Monitoring Server. This must be installed after Retain has been installed but before Retain is configured.

  1. Download the MySQL Connector/J (JDBC driver for MySQL) version 5.1.21 or later ZIP file.

  2. Extract the mysql-connector-java-5.1.X-bin.jar file (X being the current version number) from the ZIP. For example, on Linux use the command:

    unzip mysql-connector-java-5.1.41.zip

  3. Stop Tomcat service

    SLES12:

    service retain-tomcat8 stop

    SLES11:

    rcretain-tomcat8 stop

    Windows:

    Start | Services | Retain Tomcat | Stop the service

  4. Copy the mysql-connector-java-5.1.X-bin.jar file (X being the current version number) to the following Retain directories or where Retain was installed:

    /opt/beginfinite/retain/RetainServer/WEB-INF/lib (for Retain Server)

    /opt/beginfinite/retain/RetainStatsServer/WEB-INF/lib (for the Reporting and Monitoring Server)

    /opt/beginfinite/retain/RetainStubbingServer/WEB-INF/lib (for the Stubbing Server)

    For example:

    cp mysql-connector-java-5.1.41-bin.jar /opt/beginfinite/retain/RetainServer/WEB-INF/lib/

    1. If on Linux, change ownership of the file to match the other files with the terminal command:

      chown tomcat:www mysql-connector-java-5.1.41-bin.jar

    2. If on Linux, change rights of the file to match the other files with the terminal command:

      chmod 774 mysql-connector-java-5.1.41-bin.jar

  5. Start Tomcat service

    SLES12:

    service retain-tomcat8 start

    SLES11:

    rcretain-tomcat8 start

    Windows:

    Start | Services | Retain Tomcat | Start the service

Schema update note: On Linux, some systems have encountered an error after a schema update caused when MySQL cannot create a temporary file for the result of a Retain query.

The following appears in the Retain Server log:

2008-10-27 00:00:59,786 [TP-Processor2] ERROR com.maintainet.dao.HibernateUtil - SCHEMA UPDATE FAILURE: Something went wrong during Schema Update - contact tech support immediately 2008-10-27 00:00:59,786 [TP-Processor2] ERROR com.GWAVA.utils.ErrorHandle - reportError: SchemaUpdate :: EXCEPTION : org.hibernate.exception.GenericJDBCException: could not get table metadata: Audit org.hibernate.exception.GenericJDBCException: could not get table metadata: Audit

This is usually caused when MySQL cannot create or has lost rights to the tmp working directory. Try the following from a system terminal:

  1. Add rights to the tmp working directory:

    mkdir /var/lib/mysql/tmp

    chown mysql:mysql /var/lib/mysql/tmp

  2. Add the following line into the [mysqld] section of /etc/my.cnf:

    tmpdir = /var/lib/mysql/tmp

  3. Restart the Server

3.8.3 MS SQL Server 2008 R2, 2012, 2014

  1. Install as default instance, with Latin 1_ General_C1_AS as standard encoding.

  2. Enable SQL Server Authentication in addition to Windows Authentication

  3. Once installed, verify the server is listening on port 1433 (on the command line run: telnet <IP address> 1433)

  4. Ensure TCP/IP is enabled - Run SQL Server Configuration Manager

  5. Expand SQL Server Network Configuration

  6. Protocols for MSSQLSERVER

  7. Enable TCP/IP

  8. Run SQL Server Management Studio, connect to Server

  9. Under Security/Logins, right click and select "create Login, (for example Retainuser) that uses SQL Server authentication. Assign a password.

  10. Right click on Databases, and create a new database named Retain and assign Retainuser as the owner. (There are other ways to grant the permissions but this is easiest)

3.8.4 ORACLE 10/11g/12c

Retain supports the usage of Oracle 10, 11g, and 12c on all platforms. However, it is the customer’s responsibility to employ an experienced Oracle DBA to install, maintain, and tune Oracle.

The instructions below serve as a guideline, but may result in poorly performing, insecure environments.

Oracle Installation instructions vary wildly depending the version, OS, storage, clustering, etc. so consult your DBA. There is no one-size-fits-all. This is also true of other SQL Server products, but Oracle even more so.

Using Oracle with Retain consists of:

  • Installation of the Oracle Server

  • Setting up a TCP IP listener

  • Setting up a new database named Retain

  • Creating a user to access the database, and granting sufficient rights.

3.8.5 Installation

Install your Oracle Server normally, according to your standards and practices. One option is to use the Universal Installer, specifying a custom installation, choose the type of Oracle Server to install, and to Install Files Only

3.8.6 TCPIP Listener

Next use the Net Configuration Assistant (or manually edit the Oracle Listener configuration) to create a TCP based listener on port 1521. This allows TCPIP clients to connect to Oracle and is required for Retain.

3.8.7 Database Creation

Next, either use the Database Configuration Assistant or manually create the database with your favorite tool. Regardless, you want to create a database and sid, named Retain, and create your SYSTEM account

An example of a create statement (which should not be used as is):

connect "SYS"/"&&sysPassword" as SYSDBA
set echo on
spool C:\oracle\product\10.2.0\admin\Retain\scripts\CreateDB.log
startup nomount pfile="C:\oracle\product\10.2.0\admin\Retain\scripts\init.ora";
CREATE DATABASE "Retain"
MAXINSTANCES 8
MAXLOGHISTORY 1
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
DATAFILE 'C:\oracle\product\10.2.0\oradata\Retain\system01.dbf' SIZE 300M REUSE AUTOEXTEND ON NEXT 10240K MAXSIZE UNLIMITED
EXTENT MANAGEMENT LOCAL
SYSAUX DATAFILE 'C:\oracle\product\10.2.0\oradata\Retain\sysaux01.dbf' SIZE 120M REUSE AUTOEXTEND ON NEXT 10240K MAXSIZE UNLIMITED
SMALLFILE DEFAULT TEMPORARY TABLESPACE TEMP TEMPFILE 'C:\oracle\product\10.2.0\oradata\Retain\temp01.dbf' SIZE 20M REUSE AUTOEXTEND ON NEXT 640K MAXSIZE UNLIMITED
SMALLFILE UNDO TABLESPACE "UNDOTBS1" DATAFILE 'C:\oracle\product\10.2.0\oradata\Retain\undotbs01.dbf' SIZE 200M REUSE AUTOEXTEND ON NEXT 5120K MAXSIZE UNLIMITED
CHARACTER SET AL32UTF8
NATIONAL CHARACTER SET AL16UTF16
LOGFILE GROUP 1 ('C:\oracle\product\10.2.0\oradata\Retain\redo01.log') SIZE 51200K,
GROUP 2 ('C:\oracle\product\10.2.0\oradata\Retain\redo02.log') SIZE 51200K,
GROUP 3 ('C:\oracle\product\10.2.0\oradata\Retain\redo03.log') SIZE 51200K
USER SYS IDENTIFIED BY "&&sysPassword" USER SYSTEM IDENTIFIED BY "&&systemPassword";
spool off

The most critical items to note are the CHARACTER SET (AL32UTF8 aka UTF8), and the NATIONAL CHARACTER SET (AL16UTF16). If using a GUI based installed, be careful to set these - they are easily missed. (They are located on the Encoding tab of the 10th step or so of the wizard).

3.8.8 User Account Creation

Finally, using the SYSTEM account, connect to the database, create a user, and grant full system privileges to the account. An example is shown below:

CREATE USER user-name IDENTIFIED BY password;

grant dba to user-name;

Restart everything, and verify you can telnet on the TCP LISTENER's PORT (1521 if as above).

If a restricted user is desired, Retain requires a user with the following roles:

RESOURCE CONNECT

And the following database privileges to the Retain database:

CREATE PROCEDURE

CREATE SESSION

CREATE SYNONYM

CREATE TABLE

CREATE TYPE

CREATE VIEW

3.8.9 Tuning

Tuning Oracle is quite far beyond the scope of this manual. The manuals on Oracle's site, as well as an experienced DBA or extensive training is strongly recommended.

3.8.10 Postgres 9

When creating a PostgreSQL database for use by Retain, specify UTF8 encoding. If the Retain Server is on a different machine, you will need to configure PostgreSQL to accept connections from that machine's IP address.

  1. Connect to PostgreSQL using its psql utility.

  2. Create a new database and user for use by Retain. In the example below, we are creating a user named "retainuser":

CREATE DATABASE retain WITH OWNER = retainuser ENCODING = 'UTF8' TABLESPACE = pg_default CONNECTION LIMIT = -1;

3.8.11 MariaDB

MariaDB comes with SLES 12, it is a drop-in replacement for MySQL.

Install MariaDB from YaST.

Log into MariaDB, and set up the Retain database and user.

  1. Create the database: * This is critical. Not storing the database in UTF-8 format guarantees irreparable corruption for non-US-ASCII characters. *

    CREATE DATABASE retain DEFAULT CHARACTER SET 'utf8' DEFAULT COLLATE 'utf8_bin';

    1a. If you make a mistake, enter this command:

    DROP DATABASE retain;

    …and repeat step to create the database.

  2. Retain needs a user account created that has full rights to the Retain database. It is strongly recommended that the ‘root’ account is not used. While logged in to MySQL, enter the following commands. Replace (UserName) and (Password) with the desired user name and password (Both commands are needed. The ‘%’ is a wildcard. If you want to restrict the connection to a specific IP address, put that address instead of the ‘%’ sign.):

    GRANT ALL PRIVILEGES ON retain.* TO '(UserName)'@'%' IDENTIFIED BY '(Password)';

    GRANT ALL PRIVILEGES ON retain.* TO '(Username)'@'localhost' IDENTIFIED BY '(Password)';

    For example, if the database user's name is "retain" and the password is "Password1":

    GRANT ALL PRIVILEGES ON retain.* TO 'retain'@'%' IDENTIFIED BY 'Password1';

    GRANT ALL PRIVILEGES ON retain.* TO 'retain'@'localhost' IDENTIFIED BY 'Password1';

3.8.12 Further tuning

It is the customer’s responsibility to learn more about and tune the SQL Database Server. Tuning database servers for performance often requires an experienced DBA. It is the customer’s responsibility to back up, store, and make the database is fault tolerant.

3.8.13 MySQL

As a recommended best practice, customers should periodically optimize the Retain tables in order to achieve optimum query and update performance. This can have a big impact on the performance of archive jobs, deletion jobs, etc. It is also a good idea to optimize the memory settings for MySQL.

As always, it is recommended to first backup (dump) the database before performing any maintenance. If on a VM, you can alternatively back up the VM or take a snapshot.

Optimize Tables

Like hard disks, database tables' indices can become fragmented resulting in poor performance. We've seen dramatic improvements in archive job and deletion job performance for customers who have optimized their retain tables.

From a command line, type: mysqlcheck -o -u root -p retain

  • "-o" instructs it to optimize all tables in the database.

  • "-u root" specifies the user "root".

  • "-p" will cause it to prompt for the retain database password.

  • "retain" instructs it to run against the "retain" database (or whatever you named it during installation - "retain" is the default).

WARNING:This should be done during a maintenance window, as it locks the tables and can take hours to complete; and for larger databases, possibly days. We haven't received feedback from any customer on this, but a 50G database took hours. This, of course, is more of a function of the number of records in the tables (not the database size), the power of the underlying hardware, and RAM. The more innodb_buffer_pool_size you can give to MySQL, the more tablespace it can load into RAM.

The aforementioned will do ALL Retain tables; however, many are static and would not necessarily be subject to fragmentation issues; thus, you can paste the following query into the MySQL prompt after logging into MySQL. It will optimize the tables one by one.

These are the Retain 3.x tables you might consider optimizing:

OPTIMIZE TABLE retain.Audit;
OPTIMIZE TABLE retain.s_AddressBookCache;
OPTIMIZE TABLE retain.t_abook;
OPTIMIZE TABLE retain.t_document;
OPTIMIZE TABLE retain.t_dsref;
OPTIMIZE TABLE retain.t_message;
OPTIMIZE TABLE retain.t_message_attachments;
OPTIMIZE TABLE retain.t_message_properties;
OPTIMIZE TABLE retain.t_message_recipients;
OPTIMIZE TABLE retain.t_recipient;

These are the Retain 2.x tables you might consider optimizing if you are planning on migrating to Retain 3.x in the next few days or weeks:

OPTIMIZE TABLE retain.Audit;
OPTIMIZE TABLE retain.Document;
OPTIMIZE TABLE retain.Email;
OPTIMIZE TABLE retain.t_Node;
OPTIMIZE TABLE retain.t_attachment;
OPTIMIZE TABLE retain.t_msg_properties;
OPTIMIZE TABLE retain.t_recp_properties;
OPTIMIZE TABLE retain.t_recipients;

You can check on the progress of the queries by opening a separate terminal window and launching the following command:

watch -n 1 "mysqladmin -u root -p[password] processlist"

(note: no space between "-p" and your mysql root user password!)

NOTE:Retain uses the innoDB engine in MySQL, which does not support the optimize option; however, by running this option, it will automatically perform a re-create action on the tables, which will eliminate the fragmentation. There might be better ways to accomplish this, so this information is supplied to point you in the right direction.

For more detailed information and other mysqlcheck options, you may want to research this on the Internet. For your convenience, here are a couple of helpful articles:

4.5.3. mysqlcheck - A Table Maintenance Program

MySQL Back to Basics: Analyze, Check, Optimize, and Repair (written in 2008)

MySQL Reference Manual on getting a dump of a corrupted database This is sometimes the only option for recovering data from a corrupted INNODB database.

Memory Optimization

Memory for your innoDB can be configured in /etc/my.cnf (Linux) or, for Windows, in the [drive]:\Program Files\MySQL\MySQL Server 5.x/my.ini (where "x" is the MySQL version). This article only mentions a few items. A customer will want to do its own research on these and other settings.

You'll find the following section in your my.cnf and there will be identical lines in the my.ini on Windows although they may not be in this same order. The settings you may want to consider modifying are in red. This will be followed by indented explanations in blue and are additional comments made for this article - those additional comments are not found in the my.cnf or my.ini.

Be sure to stop tomcat Starting and Stopping Tomcat before working with MySQL.

# Uncomment the following if you are using InnoDB tables. If it does not exist, create it. innodb_file_per_table

The "innodb_file_per_table" is not included in the default my.cnf or my.ini and has to be typed in manually. It causes MySQL to create an .idx file for every table in the database. The benefits of this is up for debate. Some swear by it because they feel it eliminates contention for a single file containing all the tables (ibdata1); however, others have written that it is fast at first and then bogs down. We have found that, for Retain databases, it seems to positively impact performance. Do your own research and determine what is best for your system.

#innodb_data_home_dir = /var/lib/mysql
#innodb_data_file_path = ibdata1:10M:autoextend
#innodb_log_group_home_dir = /var/lib/mysql
# You can set .._buffer_pool_size up to 50 - 80 %
# of RAM but beware of setting memory usage too high
innodb_buffer_pool_size = 4G

This allocates buffer memory for MySQL into which it can load table and index data. Obviously, accessing RAM is faster than disk, so the more memory you can give for the buffer pool, the more MySQL can load into the buffer. MySQL will be using memory for other things, so if you have 6G to play with, you probably do not want the buffer pool to be larger than 4G. You'll have to experiment on your own system.

A helpful tool that is free is called mysqltuner.pl. It is a perl script that runs against your database to help you tune it's memory, security, etc. To get it, create a directory on your Linux server and change to that directory. Then type: wget mysqltuner.pl. Once it is down donwloading (takes 1 second), type: chmod +x *.pl so that it can be executed; then, execute it by typing: ./mysqltuner.pl.

innodb_additional_mem_pool_size = 204M

From what we've seen, this should be set to 5% of the buffer pool size. But, again, do your research.

# Set .._log_file_size to 25 % of buffer pool size
innodb_log_file_size = 1024M

This affects the ib_logfile0 and ib_logfile1 files in your MySQL data directory. These files hold statements/transactions. The maximum size these can be set to (regardless of your buffer pool size) is 1024M (or 1G, totaling 2 GB for all log files together) for MySQL 5.5 and 255 G (total for all log files together can be up to 512 GB) for 5.6. For more information check out the MySQL website here. There is also some discussion on what values you should set the log files to (see https://www.percona.com/blog/2008/11/21/how-to-calculate-a-good-innodb-log-file-size/. The maximum size these can be set to is 1024M.

IMPORTANT:If you change this setting, it would be a good idea to flush the existing logs (ib_logfile0 and ib_logfile1). To do this, take the following steps:

a) Log into MySQL: mysql -u root -p

b) From the MySQL prompt, type: SET GLOBAL innodb_fast_shutdown=0;

Then type "quit" to log out of MySQL.

c) Shut down MySQL: rcmysql stop

d) Rename the ib_logfile0 and ib_logfile1 files.

g) Start up MySQL: rcmysql start

h) If MySQL starts up successfully, you can delete the ib_logfile* files.

If you do not delete or move the exisiting ib_logfile0 and ib_logfile1 files from the MySQL data directory when changing the logfile size, MySQL will not load.

innodb_log_buffer_size = 8M

The log buffer allows transactions to run without having to write the log to disk before the transactions commit. If the transactions are large, then making the log buffer larger saves disk I/O. There is a status called "innodb_log_waits" in MySQL. This shows the number of times a wait was required for it to be flushed before continuing. If you have any waits, then the buffer size is too small. Here is the query you can run on that status: SHOW GLOBAL STATUS LIKE 'innodb_log_waits';

#innodb_flush_log_at_trx_commit = 1
#innodb_lock_wait_timeout = 50

To enable any one of those settings, remove the hash mark ("#") preceding it. The following is an example for a typical system that has 16G of total RAM, where 2G is allocated for the Linux OS and 8G to Tomcat. The amount allocated to Tomcat versus the database will vary per customer. A system where a lot of queries/searches are made in Retain for items or runs multiple workers on the Retain Server itself will want to lean towards more memory to Tomcat, like in this example; otherwise, a customer may want to favor MySQL a bit and give Tomcat a little less.

Changes to the my.cnf will not take affect until after MySQL is restarted. Again, if you changed the log file size setting, you must follow the steps listed above or MySQL will fail to load.

Once MySQL loads successfully, you can start tomcat Starting and Stopping Tomcat.