PgSQL/rdkit is a PostgreSQL contribution module, which implements 
*mol* datatype to describe molecules and *fp* datatype for fingerprints,  
basic comparison operations, similarity operation (tanimoto, dice) and  index 
support (using GiST indexing framework).

Compatibility: PostgreSQL 9.1+
 If using PostgreSQL packages from your linux distribution, be sure
 that you have the -devel package installed.

Installation:
Cartridge is build from the root RDKit level, i.e. you need to tell CMake to 
build it too by including the following switch:
    -D RDK_BUILD_PGSQL=ON

if PostgreSQL is installed in a location where CMake is unable to find it,
either set the environment variable PostgreSQL_ROOT or add a
"-DPostgreSQL_ROOT" switch to the cmake command line, pointing to the
PostgreSQL root directory, e.g. C:\Program Files\PostgreSQL\9.6
Under Linux, if you install PostgreSQL using the RHEL/CentOS RPMs provided by
the PostgreSQL RPM Building Project
(http://yum.postgresql.org/repopackages.php),
PostgreSQL lives under /usr/pgsql-9.x, and the
include files are located under a path that the current FindPostgreSQL.cmake
module is unable to find without a little help. Therefore, you will need to
add a "-DPostgreSQL_TYPE_INCLUDE_DIR" switch pointing to the location of the
"server" include directory. E.g., for PostgreSQL 9.6 the CMake PostgreSQL-
related switches would be:
-DPostgreSQL_ROOT=/usr/pgsql-9.6
-DPostgreSQL_TYPE_INCLUDE_DIR=/usr/pgsql-9.6/include/server

After building the RDKit, carry out the following steps:
1) Open a shell (CMD under Windows) with administrator privileges
2) Stop the PostgreSQL service:
   "C:\Program Files\PostgreSQL\9.6\bin\pg_ctl.exe" ^
   -N "postgresql-9.6"  -D "C:\Program Files\PostgreSQL\9.6\data" ^
   -w stop (Windows)
   service postgresql stop (Linux)
   
3) run the "pgsql_install" script (note that it is built by the root CMake):
   
   ${CMAKE_BINARY_DIR}\Code\PgSQL\rdkit\pgsql_install.bat (Windows)
   sh ${CMAKE_BINARY_DIR}/Code/PgSQL/rdkit/pgsql_install.sh (Linux)
   
   which will install rdkit--3.5.sql, rdkit.control and rdkit.dll
   into PostgreSQL 
4) Under Windows, make sure that the Boost DLLs against which the RDKit
   is built are in the SYSTEM path, or PostgreSQL will fail to create the
   rdkit extension with a deceptive error message such as:

   ERROR:  could not load library
   "C:/Program Files/PostgreSQL/9.6/lib/rdkit.dll":
   The specified module could not be found.
   Under Linux, make sure to add to the .bashrc of the postgres user
   an "export LD_LIBRARY_PATH" directive pointing to any dynamic
   libraries that the postgresql service may need (e.g., Boost or
   PostgreSQL libraries) which are not in the system ldconfig path.
   Alternatively, in some PostgreSQL distributions you may add a
   LD_LIBRARY_PATH = '/path/to/dynamic/libraries'
   line to /etc/postgresql/9.6/main/environment

5) Start the PostgreSQL service, e.g.:
   "C:\Program Files\PostgreSQL\9.6\bin\pg_ctl.exe" ^
   -N "postgresql-9.6"  -D "C:\Program Files\PostgreSQL\9.6\data" ^
   -w start (Windows)
   service postgresql start (Linux)

Before running ctest, make sure that your current user has enough
PostgreSQL privileges to carry out the database operations required by
the tests. You might need to set the PGPASSWORD environment variable
in your shell to avoid authentication issues.

To install the rdkit cartridge into the database DB: 
 psql -c 'CREATE EXTENSION rdkit' DB

Uninstall cartridge from database DB:
 psql -c 'DROP EXTENSION rdkit CASCADE' DB

Example:

  See sql/* and the cartridge tutorial for examples.

Further Reading:

Cartridge tutorial (https://rdkit.org/docs/Cartridge.html)
