Configuring Database management
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.
Java Naming and Directory Interface (JNDI) configuration
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:
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
Download one of the following
geonetwork.xml
files, depending on the database that you are using.geonetwork.xml
(for H2 databases)geonetwork.xml
(for Postgres databases)geonetwork.xml
(for Oracle databases)
Copy the file to the
$CATALINA_HOME/conf/Catalina/localhost
folder.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: https://www.oracle.com/database/technologies/appdev/jdbc-downloads.html
SqlServer: https://docs.microsoft.com/en-us/sql/connect/jdbc/download-microsoft-jdbc-driver-for-sql-server
Postgres: The driver is bundle with GeoNetwork, please copy the file
$CATALINA_HOME/webapps/geonetwork/WEB-INF/lib/postgresql-9.4.1211.jar
.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
.
Postgres JNDI configuration example
For a Postgres database use the corresponding file linked above, 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.htmlusername
: database username with read/write permissions in the databasepassword
: 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
<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>
Once configured, copy the file it to $CATALINA_HOME/conf/Catalina/localhost
.
Copy the Postgresql JDBC driver to $CATALINA_HOME/lib
.
Postgis support
Additionally if you want to enable the spatial index to be stored in Postgis, you should add the Postgis extension to your database:
CREATE EXTENSION postgis;
See additional details in https://postgis.net/install/
And uncomment the following Spring beans in the file $CATALINA_HOME/webapps/geonetwork/WEB-INF/config-db/jndi.xml
:
<!-- Enable for PostGis configuration with JNDI -->
<bean id="datastoreFactory" class="org.geotools.data.postgis.PostgisNGJNDIDataStoreFactory"/>
<bean id="datastore" factory-bean="datastoreFactory" factory-method="createDataStore">
<constructor-arg>
<map>
<description>The datastore factory parameters see Geotools documentation for details.
http://docs.geotools.org/latest/userguide/library/data/datastore.html
</description>
<entry key="dbtype" value="postgis"/>
<entry key="Data Source" value-ref="jdbcDataSource"/>
<entry key="Loose bbox" value="true"/>
<entry key="Estimated extends" value="true"/>
<entry key="encode functions" value="true"/>
<entry key="validate connections" value="true"/>
<entry key="fetch size" value="1000"/>
<entry key="Expose primary keys" value="true"/>
</map>
</constructor-arg>
</bean>
Direct database connection
Using JAVA_OPTS
, adding the following parameters:
Type of database (
geonetwork.db
). Valid values are :h2
,postgres
,sqlserver
,mysql
,oracle
,db2
,postgres-postgis
.Example for postgres:
-Dgeonetwork.db.type=postgres
Database connection parameters:
jdbc.database=DATABASE_NAME
jdbc.username=DATABASE_USERNAME
jdbc.password=DATABASE_PASSWORD
jdbc.host=DATABASE_HOSTNAME
jdbc.port=DATABASE_PORT
Postgres connection example:
-Djdbc.database=geonetworkdb -Djdbc.username=geonetwork -Djdbc.password=mypassword -Djdbc.host=localhost -Djdbc.port=5436
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
Postgres 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
Postgres 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
.