Postgres Configuration
This page is for documenting PostgreSQL Configuration.
Child Pages
Postgres is configured by importing the configuration file persistence_postgres.xml
in the OpenSRP spring configuration.
The file enables component scan for OpenSRP base package "org.opensrp"
while excluding the CouchDb specific beans. This means that the CouchDb beans are not loaded in the spring container and are not candidate for dependency injection leaving only Postgres beans as the active beans.
Note: The form submission and atom feed databases were not migrated to be able to use Postgres. Anyone using form submission or atom feed and wants to store the data on Postgres must first implement the Postgres repository to be able to store formsubmission and or atomfeed data on Postgres. However its possible to run both Postgres and CouchDb together in a configuration where Postgres store the data for the main OpenSRP database and error trace trace on CouchDb while the other databases still use CouchDb.
Motech scheduling library should still store its data on couchdb. For this its not possible to remove couchdb entirely until the scheduling library is changed to a library that can support Postgres e.g Quartz scheduling library
Technologies used
- Mybatis library is used as the persistence framework.
- Spring container managed transactions are used for transaction management
- Tomcat JDBC pool is used as the pooled datasource
The documentation for each technology above is below respectively
- http://www.mybatis.org/mybatis-3/
- https://docs.spring.io/spring/docs/3.1.x/spring-framework-reference/html/transaction.html
- https://tomcat.apache.org/tomcat-7.0-doc/jdbc-pool.html
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"> <context:component-scan base-package="org.opensrp"> <context:exclude-filter type="regex" expression="org.opensrp.repository.couch.*" /> <context:exclude-filter type="regex" expression="org.opensrp.repository.lucene.*" /> <context:exclude-filter type="regex" expression="org.opensrp.scheduler.repository.couch.*" /> <context:exclude-filter type="regex" expression="org.opensrp.service.formSubmission.FormSubmission..*" /> <context:exclude-filter type="regex" expression="org.opensrp.service.formSubmission.ziggy.*" /> <context:exclude-filter type="regex" expression="org.opensrp.service.FormSubmissionDataMigrationService" /> </context:component-scan> <bean id="openSRPDataSource" class="org.springframework.jndi.JndiObjectFactoryBean"> <property name="jndiName" value="java:comp/env/jdbc/openSRPDB" /> </bean> <tx:annotation-driven transaction-manager="openSRPTransactionManager" /> <bean id="openSRPTransactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="openSRPDataSource" /> </bean> <bean id="OpenSRPSqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="openSRPDataSource" /> <property name="typeAliasesPackage" value="org.opensrp.domain.postgres" /> <property name="mapperLocations" value="classpath*:org/opensrp/repository/postgres/mapper/**/*.xml" /> </bean> <bean id="OpenSRPSqlSession" class="org.mybatis.spring.SqlSessionTemplate"> <constructor-arg index="0" ref="OpenSRPSqlSessionFactory" /> </bean> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="org.opensrp.repository.postgres.mapper;org.opensrp.repository.postgres.mapper.custom" /> </bean> </beans>
This site is no longer maintained. Please visit docs.opensrp.io for current documentation.