Skip to content

Database Configuration

GeoNetwork Enterprise uses a database to persist aspects such as metadata records, privileges and configurations. The database default structure is created by the application on initial startup. Subsequent releases of GeoNetwork will update the database structure automatically.

A jdbc driver is included for PostgreSQL, Oracle and H2. Other dialects require a jdbc driver to be installed.

GeoNetwork Enterprise is bundle with a H2 database, the following sections describe how to configure GeoNetwork to use your database. The database connection can be configured using Java Naming and Directory Interface (JNDI) or a direct database connection.

Reference:

Database Connection

Java Naming and Directory Interface (JNDI) provides naming and directory functionality to applications written in Java and is the optimal choice in production situations, because it doesn't require configuration script updates at (re)deployment. JNDI is set up at the container level (e.g. Tomcat).

To configure GeoNetwork to use JNDI, follow these steps:

  1. Add in JAVA_OPTS the following parameter.

    -Dgeonetwork.db.type=jndi
    

    As an alternative can be defined the following environmental variable: GEONETWORK_DB_TYPE.

    export GEONETWORK_DB_TYPE=jndi
    
  2. Download one of the following geonetwork.xml files, depending on the database that you are using.

  3. Copy the file to the $CATALINA_HOME/conf/Catalina/localhost folder.

  4. Place the corresponding jar for the driver you want to use in the $CATALINA_HOME/lib folder. JDBC drivers can be obtained for the different databases:

    • Oracle: The driver is bundle with GeoNetwork web-archive, please copy the file $CATALINA_HOME/webapps/geonetwork/WEB-INF/lib/**.ojdbc8.jar.

      You may unzip the geoentwork.war to retrieve the driver.

    • SqlServer: https://docs.microsoft.com/en-us/sql/connect/jdbc/download-microsoft-jdbc-driver-for-sql-server

    • Postgres: The driver is bundle with GeoNetwork web-archive, please copy the file $CATALINA_HOME/webapps/geonetwork/WEB-INF/lib/postgresql-9.4.1211.jar.

      You may unzip the geoentwork.war to retrieve the driver.

    • MySql: The driver is bundle with GeoNetwork, please copy the file $CATALINA_HOME/webapps/geonetwork/WEB-INF/lib/mysql-connector-java-5.1.38.jar.

Using JAVA_OPTS, adding the following parameters:

  • Type of database (geonetwork.db). Valid values are : h2, postgres, sqlserver, mysql, oracle, db2, postgres-postgis.

  • Database connection parameters:

    • jdbc.database=DATABASE_NAME
    • jdbc.username=DATABASE_USERNAME
    • jdbc.password=DATABASE_PASSWORD
    • jdbc.host=DATABASE_HOSTNAME
    • jdbc.port=DATABASE_PORT

Alternatively can be configured using environment variables. The following environment variable can also be for connecting to the database:

  • GEONETWORK_DB_TYPE
  • GEONETWORK_DB_HOST
  • GEONETWORK_DB_PORT
  • GEONETWORK_DB_NAME
  • GEONETWORK_DB_USERNAME
  • GEONETWORK_DB_PASSWORD
  • GEONETWORK_DB_CONNECTION_PROPERTIES

PostgreSQL, Oracle and MySql JDBC drivers are bundled with GeoNetwork, for other databases it is required to download them and copy to $CATALINA_HOME/webapps/geonetwork/WEB-INF/lib.

Configuration Example

PostgreSQL JNDI configuration example

  1. For a PostgreSQL database use the geonetwork.xml file (same as linked above).

    <Context>
      <Environment name="gnDatabaseDialect" value="POSTGRESQL" type="java.lang.String" override="false"/>
      <Resource name="jdbc/geonetwork" auth="Container"
                factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
                type="javax.sql.DataSource" driverClassName="org.postgresql.Driver"
                url="jdbc:postgresql://localhost:5432/postgres"
                username="postgres" password="postgres"
                maxActive="20" maxIdle="10" defaultAutoCommit="false" maxWait="-1"/>
    </Context>
    
  2. Configuring the following parameters:

    • url: JDBC connection string for Postgresql database, typically fill the hostname/port/database name. See additional parameters in https://jdbc.postgresql.org/documentation/head/connect.html

    • username: database username with read/write permissions in the database

    • password: database user password.

    For other parameters check additional documentation in https://tomcat.apache.org/tomcat-8.5-doc/jndi-resources-howto.html#JDBC_Data_Sources

  3. Once configured, copy the geonetwork.xml file to $CATALINA_HOME/conf/Catalina/localhost.

  4. Copy the Postgresql JDBC driver to $CATALINA_HOME/lib.

See the deploy instructions for more information.

Example for PostgreSQL:

  1. The geonetwork.db value will be postgres:

    -Dgeonetwork.db.type=postgres
    
  2. Postgres connection example:

    -Djdbc.database=geonetworkdb
    -Djdbc.username=geonetwork
    -Djdbc.password=mypassword
    -Djdbc.host=localhost
    -Djdbc.port=5436
    
  3. Define java system properties by appending the following lines to setenv.sh (Linux)

    # append database connection details
    JAVA_OPTS="${JAVA_OPTS} -Dgeonetwork.db.type=postgres"
    JAVA_OPTS="${JAVA_OPTS} -Djdbc.database=geonetworkdb"
    JAVA_OPTS="${JAVA_OPTS} -Djdbc.username=geonetwork -Djdbc.password=mypassword"
    JAVA_OPTS="${JAVA_OPTS} -Djdbc.host=localhost -Djdbc.port=5436"
    
  4. These settings are used by the postgresql jdbc driver included in the geonetwork.war.

  1. PostgreSQL connection example:

    export GEONETWORK_DB_TYPE=postgres
    export GEONETWORK_DB_HOST=localhost
    export GEONETWORK_DB_PORT=5436
    export GEONETWORK_DB_NAME=geonetworkdb
    export GEONETWORK_DB_USERNAME=geonetwork
    export GEONETWORK_DB_PASSWORD=mypassword
    
  2. These environmental variables must be supplied to the apache tomcat service.

    • Add to environment, example ~/.bashrc
    • Add to service definiton, example /etc/systemd/system/tomcat.service
    • Append lines to setenv.sh