Installation and Administration

This manual serves as Administration Guide of JChem PostgreSQL Cartridge (JPC). Here you can find the description of software requirements, installation and configuration steps and running of JPC. See also Getting started guide for easy setup and use cases.

System requirement

Software

  • CentOS, RedHat, Debian or Ubuntu operating system x86_64 version.

Find information for cases of other linux systems

  • postgreSQL 9.4 relational database (preferred download page) for JPC versions up to 2.0

  • postgreSQL 9.5 relational database for JPC versions starting from 2.1

See help to upgrade of postgreSQL 9.4 to postgreSQL 9.5

  • postgreSQL 10 relational database for JPC versions starting from 3.0

  • availability of hstore extension of postgresql (e.g., contrib package)

  • Java8 runtime environment

Hardware

The memory need of JChem PostgreSQL Cartridge strongly depends on the format of the chemical structures to be stored. In the next table, the approximate memory need of 10 M PubChem molecules in SD file format and in SMILES format are compared. The presented memory setup is optimized for execution speed. Lower amount of memory may be used, in this case performance drop is expected. Further details can be found in the Performance tuning section.

Indexed column containing

10 M PubChem molecules in

Service jchem-psql

[GB]

Postgres shared buffer

[GB]

Total

[GB]

SD file format

9

21

30

SMILES format

9

2

11

Installation and Setup

Install PostgreSQL Cartridge

Download the latest version of PostgreSQL Cartridge from here. In order to install the latest version (as root), change the x.y (version information) in the following statement to the current one:

In CentOS:

sudo yum localinstall jchem-psql/jchem-psql-x.y.x86_64.rpm

In RedHat or Debian:

sudo dpkg -i jchem-psql-x.y.x86_64.deb

See also Getting started guide for PostgreSQL and Java8 installation.

Before the first use

  1. Install your license file

    Copy a valid ChemAxon license to /etc/chemaxon/license.cxl or set its location in /etc/chemaxon/jchem-psql.conf file. Required license in the license file is 'Postgres Cartridge'.
    The jchem-psql user should have read access to the license file.

  2. Initialize index directory

    sudo service jchem-psql init

    If you encounter any problem in your java installation, set your JAVA_HOME in the file /etc/default/jchem-psql.

    Initialization does not start the service, you must start it manually.

  3. First start

    sudo service jchem-psql manual-start

Create extension in a database

Each chemical database should have the following extensions created separately.

  1. Create a new user and database

    sudo su postgres
    createuser testuser
    createdb testdb -O testuser
  2. Install the extensions (you must be postgres user or any other user who has create extension privilege)

    psql testdb
    testdb> CREATE EXTENSION chemaxon_type;
    testdb> CREATE EXTENSION hstore;
    testdb> CREATE EXTENSION chemaxon_framework;

    If you experience any error during the CREATE EXTENSION steps, please check this page which gives hints relating non-standard PostgreSQL setup.

  3. Checking JChem PostgreSQL Cartridge installation

    If jchem-psql service is running, the following query can be executed without any problem:

    testdb> SELECT 'C'::Molecule('sample') |<| 'CC'::Molecule;

    This select statement executes a substructure search, with a Carbon atom as the query and ethane as the target structure. You must receive true (t) as output. See details of Molecule type below.

Service

The service can be started/stopped using:

sudo service jchem-psql start
sudo service jchem-psql stop

ENABLED=1 (default) setting in /etc/default/jchem-psql file makes the service start on system boot and start manually by start.

If you want the service not to start on system boot, set ENABLED=0 in the /etc/default/jchem-psql file. In that case, manual-start must be run.

sudo service jchem-psql manual-start

Configure JChem-psql server

The following configuration parameters are available on PostgreSQL side:

Parameter name

Default value

Description

chemaxon.hit_retrieval_batch_size

5000

Number of hits in a batch between jchem-psql server and postgresql database. Higher value generates higher initial latency, lower value creates communication overhead.

chemaxon.index_creation_batch_size

5000 (up to version 2.6)

25000 (from version 2.7)

Number of records in a batch between jchem-psql server and postgresql database during index creation.

Higher value generates higher memory footprint, but better throughput for traditional hard disk. Cancelling the index creation is slower in case of higher values.

chemaxon.search_wall_time_limit

600000

(10 minutes)

The maximum wall time available for a search operation in milliseconds.

shared_buffers

(typically) 128MB

Sets the amount of memory the database server uses for shared memory buffers. This parameter can be set for performance tuning in big tables . Requires restart of postgres service.

They - with the exception of shared_buffers - can be edited as an ordinary Postgres configuration parameter:

  • in the postgresql.conf file (e.g., /etc/postgresql/9.4/main/postgresql.conf)

  • can be overwritten in the current session:

    SET chemaxon.hit_retrieval_batch_size to 1000;
  • to see the current value:

    SHOW chemaxon.hit_retrieval_batch_size;

The following configuration parameters are available on JChem-psql server side:

Parameter name

Description

com.chemaxon.jchem.psql.runtime.molecule.cachedObjectCount

Number of molecules in cache. Only the screened objects are searched for, so this cache can be left at a small size. Only the number of the objects can be set, so the total size of used memory depends on the current structures and can vary from time to time.

com.chemaxon.jchem.psql.runtime.fingerprint.cachedObjectCount

Number of fingerprints in cache. All of them are needed at every search, so it is advised always to keep them in memory for the frequently used tables.

com.chemaxon.jchem.psql.runtime.label.cachedObjectCount

Number of molecule labels in cache.

com.chemaxon.jchem.psql.runtime.auxiliary.cachedObjectCount

Number of basic information items in cache.

com.chemaxon.jchem.psql.env.indexDir

Directory storing the indexes needed by the cartridge.

com.chemaxon.jchem.psql.env.userTypeDir

Directory storing the molecule type files.

com.chemaxon.jchem.psql.runtime.maxOpenSessionCount

Limits the number of open service sessions at same time (0 means unlimited, default is 100).

Each PSQL command which uses jchem-psql service opens a new service session and closes it at the end.

Service session requests above the set value of the open sessions are rejected with a message.

Be aware that the JDBC driver doesn't close the sessions at closing the statement if autocommit is turned off.

In this case call commit explicitly to close the session.

Available from version 2.0.

com.chemaxon.jchem.psql.runtime.threadCount

Parallel worker thread count at search queries. Default value is the number of processors.

Available from version 3.0.

These parameters can be configured in the /etc/chemaxon/jchem-psql.conf file.

Changing these parameters except maxOpenSessionCount requires new initialization of jchem-psql service. Please note that this will purge all jchem-psql index data hence the indexes need to be dropped and recreated again.

Molecule types

Molecule types define the interpretation mode of the chemical structures. Molecule types are based on the extension chemaxon_type. The definition of these types has to be stored in /etc/chemaxon/types/ folder as a <molecule_type_name>.type file. You can add, modify, delete molecule type files according to your needs.

We provide a sample type, see file /etc/chemaxon/types/sample.type.

The following settings can be defined in a <molecule_type_name>.type file:

  • Version of the type descriptor (at the moment, only '1' is accepted)

  • Type ID: positive unique identifier among types

  • Tautomer mode: OFF, GENERIC

  • Standardizer action string or Standardizer file containing standardization requirements

Standardizer action string must follow the syntax of command line standardizer actions:

Example:

aromatize:basic..addexplicitH..replaceatoms:queryatom='C':replaceatom='N'

Standardizer configuration file can be created as described in Creating a Configuration page.

The types stored in /etc/chemaxon/types/ are loaded when the jchem-psql service is initialized. Therefore, if you add a new molecule type or change an existing one, the following steps have to be executed (using the current version of JChem Postgres Cartridge):

  1. Create/modify/delete molecule type file(s) according to needs

  2. Stop the service: sudo service jchem-psql stop

  3. Delete the content of the index directory: sudo rm -rf /var/lib/jchem-psql/store/*

  4. Initialize the service: sudo service jchem-psql init

  5. Start the service: sudo service jchem-psql manual-start

  6. Change to postgres user: sudo su postgres

  7. Login to your database: psql

  8. Reindex the database: reindex database <database name>

The query structure and the target structure(s) must always have the same molecule type. There is an auto-casting implemented; this means, that in the case of comparing two molecules, it is enough to define the molecule type of either of them. The following three statements have the same meaning:

	SELECT 'C'::Molecule('sample') |<| 'CC'::Molecule('sample');
	SELECT 'C'::Molecule('sample') |<| 'CC'::Molecule;
	SELECT 'C'::Molecule |<| 'CC'::Molecule('sample');

Invalid select statements

  • missing molecule type definition

	SELECT 'C'::Molecule |<| 'CC'::Molecule;
  • different molecule type definition

	SELECT 'C'::Molecule('type1') |<| 'CC'::Molecule('type2');

In the case of database search, the molecule type of the structure column relates to the query structure as well.

Upgrade

Upgrade with keeping existing molecule type data

If not only JChem PostgreSQL Cartridge, but postgreSQL database upgrade is also needed ( e. g., from JPC 2.1 postgreSQL 9.5 is required), find an example of how to upgrade of postgreSQL 9.4 to postgreSQL 9.5.

  1. Stop the service

    sudo service jchem-psql stop
  2. Install the new version

  3. Initialize the service (this step deletes the old indexes)

    sudo service jchem-psql init

    Only the index contents are deleted, the molecule records stored in the PostgreSQL database stay untouched.

  4. Start the service

    sudo service jchem-psql manual-start
  5. Upgrade your existing postgresql database

    1. Update the extensions

      sudo su postgres
      psql
       
      # ALTER EXTENSION chemaxon_type UPDATE;
      # ALTER EXTENSION chemaxon_framework UPDATE;

      In some cases of the upgrade process, you have to drop the indexes before altering the chemaxon_framework extension. If you receive an error message like

      "ERROR: cannot drop operator class chemindex_int_ops for access method chemindex because other objects depend on it

      DETAIL: index upg_ind depends on operator class chemindex_int_ops for access method chemindex

      HINT: Use DROP ... CASCADE to drop the dependent objects too.",

      you have to drop the index referred in the DETAIL part of the message and repeat step

      # ALTER EXTENSION chemaxon_framework UPDATE;
    2. Reindex the database

      Upgrade to 2.7 or above

      When you upgrade to JPC 2.7 or above and want to take the advantage of performance improvements implemented in 2.7, you have to update the tables storing chemical structures. The indexes should be dropped before the upgrade and recreated thereafter.

      update table_name set structure_column_name = structure_column_name::text::molecule('molecule_type_name');

      Example:

      drop index myindex;
      update mytable set mol = mol::text::molecule('sample');
      create index myindex on mytable using chemindex(mol);
      //or
      create index myindex on mytable using sortedchemindex(mol);

      If the above table update is skipped, reindex database is necessary:

      psql
      # reindex database <database name>;

      If you miss this step, all indexes of type chemindex will not function properly.

Upgrade without keeping existing molecule type data

If not only JChem PostgreSQL Cartridge, but postgreSQL database upgrade is also needed ( e. g., from JPC 2.1 postgreSQL 9.5 is required), find an example of how to upgrade of postgreSQL 9.4 to postgreSQL 9.5.

  1. Before installing the new version, drop the following extensions

    DROP EXTENSION chemaxon_framework CASCADE;
    DROP EXTENSION chemaxon_type CASCADE;

    If you drop the chemaxon_type extension, it will implicitly drop all chemical columns.

  2. Stop the service

    sudo service jchem-psql stop
  3. Delete the content of the index directory

    sudo rm -rf /var/lib/jchem-psql/store/*
  4. Install the new version

Uninstall

The present chemaxon_framework extension must be dropped:

DROP EXTENSION chemaxon_framework;
DROP EXTENSION chemaxon_type;

If you drop the chemaxon_type type extension, it will implicitly drop all chemical columns.

The installed jchem-psql-x.y.x86_64 package can be removed.

Logging

Available from version 3.0.

Apache Log4j Java-based utility serves for logging JChem PostgreSQL Cartridge.

The configuration file is /etc/chemaxon/jpc-log4j.xml

Default jpc-log4j.xml :

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<Appenders>
<RollingFile name="InfoFile" fileName="/var/log/jchem-psql/info.log"
filePattern="logs/$${date:yyyy-MM}/jchem-psql-%d{yyyy-MM-dd}-%i.log">
<PatternLayout pattern="%d{MMM dd, HH:mm:ss.SSS} [%t] %-5level %logger{36} %msg%n"/>
<Policies>
<TimeBasedTriggeringPolicy />
<SizeBasedTriggeringPolicy size="20 MB"/>
</Policies>
</RollingFile>
<RollingFile name="ErrorFile" fileName="/var/log/jchem-psql/error.log"
filePattern="logs/$${date:yyyy-MM}/jchem-psql-%d{yyyy-MM-dd}-%i.log">
<PatternLayout pattern="%d{MMM dd, HH:mm:ss.SSS} [%t] %-5level %logger{36} %msg%n"/>
<Policies>
<TimeBasedTriggeringPolicy />
<SizeBasedTriggeringPolicy size="20 MB"/>
</Policies>
</RollingFile>
</Appenders>
<Loggers>
<Root level="info">
<AppenderRef ref="InfoFile" level="info"/>
<AppenderRef ref="ErrorFile" level="error"/>
</Root>
</Loggers>
</Configuration>

By default, rolling logging is applied (every day or after 20 MB a new folder starts to collect the log files) on INFO and on ERROR level. If you want to modify the logging configuration, see Apache Log4j guideline.

Archiving

To archive the content of the following directories might be useful:

  • /var/lib/jchem-psql

This directory contains the indexing data. If this folder is restored, the same indexes will be usable again without reindexing.

  • /var/log/jchem-psql

This directory contains the log files. If jchem-psql server is restarted, the old log files will be removed. So it may be important to save these files before restarting the service to find out why it stopped.

  • /etc/chemaxon

This directory contains the user settings, e.g., custom molecule types or custom memory settings.

Performance tuning

Performance of the cartridge highly depends on the cache, JVM memory and PostgreSQL settings.

Here you find a guide on how to configure

  • Cache size settings

  • JVM memory settings

  • PostgreSQL settings

Cache sizes

Xmx and Cache Size Calculator

JChem PostgreSQL Cartridge Cache and Memory Calculator is provided for calculating cache parameters and JVM memory settings according to the size of your database.

The table below shows the cache memory needs of the PostgreSQL Cartridge when a chemical index of 1 million structures is in use. Memory size values are represented in megabytes. The first value in each cell shows the size of cache memory required by the corresponding backend for every 1 million of stored chemical structures. Values in parentheses represent the same memory need in the case when not only duplicate, full fragment, substructure, similarity search but also superstructure search is to be carried out. In this case an increased amount of cache is necessary.

Values in square brackets depend on the number of chemical indexes present in database. Number of chemical indexes is denoted by ‘idx’. These values do not scale with number of structures but depend only on the number of chemical indexes.

For example, in case of 10 million structures when a single sorted chemindex is used with 1024 bits fingerprint, fingerprint cache requires 10 * 132 MB + 88 MB = 1408 MB.

Required size of molecule cache depends significantly on the molecule set stored. In general larger structures need more space, and smiles format is more compact than mrv or mol format. Cache sizes in the table are measured using the PubChem database in mol format.

 

Chemindex

Sorted chemindex

Fingerprint bits

512

1024 (default)

512

1024 (default)

 

Cache size used (MB)

Fingerprint cache

70 (*2)

132 (*2)

70 + [22 * idx] (*2)

132 + [88 * idx] (*2)

Molecule cache

290 (610)

290 (610)

290 (610)

290 (610)

Label cache

44 (88)

44 (88)

44 (88)

44 (88)

Auxiliary cache

1

1

1

1

Fingerprint bits

Fingerprint bit length can be set in the relevant type file by applying:

  • fpLength=512

  • fpOnes=1

or

  • fpLength=1024

  • fpOnes=2

Setup strategies

All fits into cache

When there is enough memory available it is recommended to set up all cache sizes so that every record fits into. This configuration results in the fastest DB operations in general, however its memory need is the highest.

Label cache is left out

In this case label cache size is set 0. This is the second fastest configuration. Search operations are speedy but modification operations (insert, update, vacuum) might be slower.

When setting cache count to zero, it is recommended to switch off caching for the corresponding backend completely. This can be done using the following configuration parameter:

com.chemaxon.jchem.psql.runtime.label.cachePolicy=DISABLED

Label and molecule cache is left out

In this case only fingerprint and auxiliary caches are in use. Label and molecule cache sizes are set to 0. Limited search operations remain still fast but search operations without hit limit may be slower. Modification operations (insert, update, vacuum) might be slower.

When setting cache count to zero, it is recommended to switch off caching for the corresponding backend completely. This can be done using the following configuration parameters:

com.chemaxon.jchem.psql.runtime.label.cachePolicy=DISABLED
com.chemaxon.jchem.psql.runtime.molecule.cachePolicy=DISABLED

Cache setup

Current PostgreSQL Cartridge version uses MapDB as storage backend. This allows to configure cache object counts, not cache sizes. Cache object counts may be configured in file: /etc/chemaxon/jchem-psql.conf

The jchem-psql service has to be restarted after changes have been made to this file. The following keys have to be used:

com.chemaxon.jchem.psql.runtime.molecule.cachedObjectCount
 
com.chemaxon.jchem.psql.runtime.fingerprint.cachedObjectCount
 
com.chemaxon.jchem.psql.runtime.label.cachedObjectCount
 
com.chemaxon.jchem.psql.runtime.auxiliary.cachedObjectCount

Object count is the number of structures that have to fit into cache.

In case of auxiliary cache an object count value of [6000 * idx + 3400 * M] should be defined, where ‘idx’ is the number of chemical indexes present in database and M is the number of molecules present in the database in millions.

An extra fingerprint object count for every sorted chemindex has to be calculated with. This extra count is 320,000 per index in case of 512 bit fingerprints and 640,000 per index for 1024 bit fingerprints. This overhead affects only the fingerprint cache count. The extra counts must be included only when using sorted chemindex (in contrast with “normal” chemindex). For example, in case of two structure tables, both consisting of 5 million entries, when two sorted chemindexes are used with 1024 bits fingerprints, fingerprint cache count requires: 2 * 5,000,000 + 2 * 640,000 = 11,280,000.

Java VM heap memory setup

Maximum memory allowed for the Java VM has to be configured, as well. The amount of required memory can be calculated as:

MaxMem = 2500 MB + 1.33 * Cache size (fingerprint + molecule + label + auxiliary caches)

Maximal VM memory can be configured in file /etc/default/jchem-psql

The setting ‘-Xmx’ in entry ‘JCHEM_PSQL_OPTS’ has to be modified.

PostgreSQL settings

If the user would like to execute queries

  1. on big tables - containing many entries and big row data. E.g., the molecule source is a verbose one (sdf, mrv, ...)

  2. and PostgreSQL needs to fetch majority of the rows. E.g., sql query without any additional restricting condition or limit parameter

then it is advisable to increase the size of PostgreSQL shared buffer so that PostgreSQL can fetch all rows rapidly using cache. In order to achieve this, set the shared_buffers parameter in postgresql.conf to be able to store your table.

Table size can be checked by \dt+ <tablename> command from the psql client.

Additionally, to enhance PostgreSQL performance, it may be advisable to increase linux's shared memory with the following command:

sysctl -w kernel.shmall = <shared memory size in bytes>/<page size>

The default value of page size is usually 4096. It can be checked by getconf PAGESIZE.To store the value of kernel.shmall permanently, add it it to the sysctl.conf file. For more details about required shared memory settings for PostgreSQL server please visit the PostgreSQL documentation.

To reduce the needed buffer size, you may consider the following possibilities.

  1. Change the input format to a concise one: smiles, smarts, ...
    (e.g., 8M rows of a PubChem dataset need ca. 17 GB when the molecules are in sdf format, but only ca. 1.4 GB when they are in smiles format).

  2. Avoid queries that require the fetching of all table data through adding additional "where" condition or limit parameter.

    For example, instead of

    SELECT <id_column_name> FROM <table_name> WHERE 'c1ccccc1' |<| mol;

    which may return several millions of hits, use the following statement applying LIMIT <n> and relevance sorting in order to obtain the most relevant n hits:

    SELECT <id_column_name> FROM <table_name> WHERE 'c1ccccc1' |<| mol ORDER BY relevance LIMIT 100;
  3. Increase the fillfactor to 90% instead of the above recommended 50% and perform vacuum regularly.

  4. As PostgreSQL is not optimized for the COUNT() method, it may take a long time if it returns large value. For obtaining an estimation of the count of hits we rather suggest using the EXPLAIN command.

Please also check that the JVM heap size plus the PostgreSQL shared buffer size is not more than 2/3-rd of the total available memory to avoid slow-down of the operation system.

If the required amount of physical memory is not available, then for optimizing the performance it is more important to setup proper JVM heap size than to increase the PostgreSQL shared buffer size.