Skip to content

Commit

Permalink
roles/dspace: Use a JNDI database pool for PostgreSQL
Browse files Browse the repository at this point in the history
We have been having database pool issues for years, especially in the
last half of 2017 when the site grew in popularity with both bots and
other "real" users like our partners harvesting us. DSpace's database
stuff is pretty ghetto in that the default pool that is configured in
dspace.cfg is per web application, ie XMLUI, JSPUI, REST, etc all use
their own pool.

This setup is more or less according to the Tomcat JNDI documentation
but borrows some initial pool parameters from Mark Wood's comments on
the DSpace issue tracker[0]. I will monitor this and adjust it later.

The PostgreSQL JDBC library comes directly from the upstream site. It
is possible to use DSpace's bundled library by copying it to Tomcat's
library directory, but since we need to copy it anyways, I thought it
would be cleaner to get a fresh copy from upstream.

[0] https://jira.duraspace.org/browse/DS-3564
[1] https://jdbc.postgresql.org/download.html
  • Loading branch information
alanorth committed Dec 19, 2017
1 parent 8098ecd commit 1959d9c
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 1 deletion.
Binary file added roles/dspace/files/postgresql-42.1.4.jar
Binary file not shown.
7 changes: 7 additions & 0 deletions roles/dspace/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,13 @@
- restart tomcat{{ tomcat_version_major }}
tags: tomcat

# From upstream: https://jdbc.postgresql.org/download.html
- name: Copy PostgreSQL JDBC library
copy: src=postgresql-42.1.4.jar dest=/usr/share/tomcat7/lib/postgresql-42.1.4.jar mode=0644 owner=root group=root
notify:
- restart tomcat{{ tomcat_version_major }}
tags: tomcat

- name: Prepare Tomcat web application contexts
template: src=tomcat/context.xml.j2 dest={{ item.context_path }}
with_items: "{{ dspace_webapps }}"
Expand Down
4 changes: 3 additions & 1 deletion roles/dspace/templates/tomcat/context.xml.j2
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
<Context docBase="{{ item.app_path }}"/>
<Context docBase="{{ item.app_path }}">
<ResourceLink global="jdbc/dspace" name="jdbc/dspace" type="javax.sql.DataSource"/>
</Context>
15 changes: 15 additions & 0 deletions roles/dspace/templates/tomcat/server-tomcat7.xml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,21 @@
description="User database that can be updated and saved"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
pathname="conf/tomcat-users.xml" />

<Resource name="jdbc/dspace" auth="Container"
type="javax.sql.DataSource"
driverClassName="org.postgresql.Driver"
url="jdbc:postgresql://localhost:5432/{{ dspace_db_name }}"
username="{{ dspace_db_user}}"
password="{{ dspace_db_password }}"
initialSize='5'
maxActive='50'
maxIdle='15'
minIdle='5'
maxWait='5000'
validationQuery='SELECT 1'
testOnBorrow='true' />

</GlobalNamingResources>

<!-- A "Service" is a collection of one or more "Connectors" that share
Expand Down
15 changes: 15 additions & 0 deletions roles/dspace/templates/tomcat/server-tomcat8.xml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,21 @@
description="User database that can be updated and saved"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
pathname="conf/tomcat-users.xml" />

<Resource name="jdbc/dspace" auth="Container"
type="javax.sql.DataSource"
driverClassName="org.postgresql.Driver"
url="jdbc:postgresql://localhost:5432/{{ dspace_db_name }}"
username="{{ dspace_db_user}}"
password="{{ dspace_db_password }}"
initialSize='5'
maxActive='50'
maxIdle='15'
minIdle='5'
maxWait='5000'
validationQuery='SELECT 1'
testOnBorrow='true' />

</GlobalNamingResources>

<!-- A "Service" is a collection of one or more "Connectors" that share
Expand Down

0 comments on commit 1959d9c

Please sign in to comment.