You are on page 1of 6

Nuxeo with PostgreSQL

Mon, 2009-04-13 17:38 — ericdes


http://notes.tela-web.com/nuxeo-with-postgresql

Pre-requisites on PostgreSQL

From this document: http://doc.nuxeo.org/xwiki/bin/view/FAQ/UsingPostgreSQL83


These conversion functions (in pg_catalog) need to be rewritten to allow a less strict
environment for casting in PostgreSQL:

 text(integer)
 text(bigint) in pg_catalog

After installing these functions all newly created databases will use these new cast
functions.
Do this before creating the nuxeo database:

psql -U postgres template1

CREATE FUNCTION pg_catalog.text(integer) RETURNS text STRICT


IMMUTABLE LANGUAGE SQL AS 'SELECT textin(int4out($1));';
CREATE CAST (integer AS text) WITH FUNCTION
pg_catalog.text(integer) AS IMPLICIT;
COMMENT ON FUNCTION pg_catalog.text(integer) IS 'convert
integer to text';

CREATE FUNCTION pg_catalog.text(bigint) RETURNS text STRICT


IMMUTABLE LANGUAGE SQL AS 'SELECT textin(int8out($1));';
CREATE CAST (bigint AS text) WITH FUNCTION
pg_catalog.text(bigint) AS IMPLICIT;
COMMENT ON FUNCTION pg_catalog.text(bigint) IS 'convert
bigint to text';

Create the database


su - postgres
export db=nuxeo
createuser -U postgres --no-createdb --no-adduser -P $db
createdb -U postgres -O $db --encoding=UNICODE $db
exit

To review: Shall the new role be allowed to create more new roles? (y/n) y
psql -U nuxeo nuxeo
CREATE LANGUAGE 'plpgsql';

Install PostgreSQL driver

Get the driver at this page: http://jdbc.postgresql.org/

mkdir -p /opt/jdbc-drivers
cd ~
wget http://jdbc.postgresql.org/download/postgresql-8.3-
604.jdbc3.jar
cp postgresql-8.3-604.jdbc3.jar
/opt/jboss/server/default/lib/
ls -l /opt/jboss/server/default/lib

Set up the configuration for the repository

http://doc.nuxeo.org/xwiki/bin/view/FAQ/Nuxeo52VcsPostgreSQL

cd /opt/jboss/server/default/deploy/nuxeo.ear/

It is a good idea to have a versioning repository (example: Mercurial) in the directory


'deploy': Add the nuxeo.ear directory in the repository. The directory nuxeo.ear gets erased
each time you rebuild Nuxeo. With a repository in place you can revert these 4
configuration files.

Notice: We use the Visible Content Store, aka the SQL storage (which is installed by
default) and not JCR:
nano datasources/default-repository-ds.xml

<?xml version="1.0"?>
<connection-factories>
<tx-connection-factory>
<jndi-name>NXRepository/default</jndi-name>
<xa-transaction/>
<track-connection-by-tx/>
<adapter-display-name>Nuxeo SQL Repository
DataSource</adapter-display-name>
<rar-name>nuxeo.ear#nuxeo-core-storage-sql-ra-1.5-
SNAPSHOT.rar</rar-name>
<connection-
definition>org.nuxeo.ecm.core.storage.sql.Repository</connect
ion-definition>
<config-property name="name">default</config-property>

<!-- Configuration for H2


<config-property name="xaDataSource"
type="java.lang.String">
org.h2.jdbcx.JdbcDataSource</config-property>
<config-property name="property"
type="java.lang.String">URL=jdbc:h2:${jboss.server.data.dir}/
h2/nuxeo</config-property>
<config-property name="property"
type="java.lang.String">User=sa</config-property>
<config-property name="property"
type="java.lang.String">Password=</config-property>
-->

<!-- Configuration for PostgreSQL: -->


<config-property name="xaDataSource"
type="java.lang.String">org.postgresql.xa.PGXADataSource</con
fig-property>
<config-property name="property"
type="java.lang.String">ServerName=localhost</config-
property>
<config-property name="property"
type="java.lang.String">PortNumber/Integer=5432</config-
property>
<config-property name="property"
type="java.lang.String">DatabaseName=nuxeo-g2</config-
property>
<config-property name="property"
type="java.lang.String">User=nuxeo-g2</config-property>
<config-property name="property"
type="java.lang.String">Password=12345</config-property>

<!-- Configuration for Derby:


<config-property name="xaDataSource"
type="java.lang.String">
org.apache.derby.jdbc.EmbeddedXADataSource</config-property>
<config-property name="property"
type="java.lang.String">createDatabase=create</config-
property>
<config-property name="property"
type="java.lang.String">databaseName=${jboss.server.data.dir}
/derby/nuxeo</config-property>
<config-property name="property"
type="java.lang.String">user=sa</config-property>
<config-property name="property"
type="java.lang.String">password=</config-property>
-->

<max-pool-size>20</max-pool-size>
</tx-connection-factory>
</connection-factories>

nano config/default-repository-config.xml

<?xml version="1.0"?>
<component name="default-repository-config">
<extension
target="org.nuxeo.ecm.core.repository.RepositoryService"
point="repository">
<repository name="default"
factory="org.nuxeo.ecm.core.storage.sql.coremodel.SQLRe
positoryFactory">
<repository name="default">
<indexing>
<!-- for H2 (Lucene Analyzer):
<fulltext
analyzer="org.apache.lucene.analysis.fr.FrenchAnalyzer"/>

-->
<!-- for PostgreSQL (Text Search Configuration): --
>
<fulltext analyzer="english"/>
</indexing>
</repository>
</repository>
</extension>
</component>

Moreover we want to configure datasources/unified-nuxeo-ds.xml to store all other data in


our PostgreSQL database:
nano config/sql.properties

# Jena database type and transaction mode

# Derby
#org.nuxeo.ecm.sql.jena.databaseType=Derby
#org.nuxeo.ecm.sql.jena.databaseTransactionEnabled=false

# PostgreSQL
org.nuxeo.ecm.sql.jena.databaseType=PostgreSQL

nano datasources/unified-nuxeo-ds.xml

<?xml version="1.0" encoding="UTF-8"?>


<datasources>
<!-- DEFAULT UNIFIED DATASOURCE CONFIGURATION -->
<!--
This is the default unified datasource configuration. All
datasources from nuxeo
points to this datasource so it will use only 1 database.
To use another database than Derby, comment out the
following section and uncomment
your database configuration or add it if not present.
If you wish to use a different database for a service,
comment out the link in the relevant
xxx-ds.xml file and add a datasource configuration.
-->
<!-- nuxeo datasource
<local-tx-datasource>

<jndi-name>NuxeoDS</jndi-name>
<connection-url>
jdbc:derby:${jboss.server.data.dir}/derby/nuxeo;create=
true
</connection-url>
<driver-
class>org.apache.derby.jdbc.EmbeddedDriver</driver-class>
<user-name>sa</user-name>
<password></password>
</local-tx-datasource>
-->

<!-- Configuration for Postgres -->


<local-tx-datasource>
<jndi-name>NuxeoDS</jndi-name>
<connection-url>jdbc:postgresql://localhost:5432/nuxeo-
g2</connection-url>
<driver-class>org.postgresql.Driver</driver-class>
<user-name>nuxeo-g2</user-name>
<password>12345</password>
<check-valid-connection-sql>;</check-valid-connection-
sql>
</local-tx-datasource>

</datasources>

Start JBoss

This will create the tables in database nuxeo

Verify if you can log in

elinks http://localhost:8080/nuxeo
Commit changes

If you've used Mercurial:

hg diff
hg commit (Reason: Enable VCS with PostgreSQL backend)
hg log
up