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:
-
Add in
JAVA_OPTS
the following parameter.As an alternative can be defined the following environmental variable:
GEONETWORK_DB_TYPE
. -
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: 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
-
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>
-
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
-
-
Once configured, copy the
geonetwork.xml
file to$CATALINA_HOME/conf/Catalina/localhost
. -
Copy the Postgresql JDBC driver to
$CATALINA_HOME/lib
.
See the deploy instructions for more information.
Example for PostgreSQL:
-
The
geonetwork.db
value will bepostgres
: -
Postgres connection example:
-
Define java system properties by appending the following lines to
setenv.sh
(Linux) -
These settings are used by the postgresql jdbc driver included in the
geonetwork.war
.
-
PostgreSQL connection example:
-
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
- Add to environment, example