PgJSON session backend
This backend is the recommended one for production installations of LemonLDAP::NG.
Prerequisites
First, make sure you have installed the DBD::Pg perl module.
On Debian-based distributions
apt install libdbd-pg-perl libapache-session-browseable-perl
On Fedora-based distributions
yum install 'perl(DBD::Pg)' 'perl(Apache::Session::Browseable)'
The minimum required version of PostgreSQL is 9.3 with support for JSON column types
Make sure you are using at least version 1.2.9 of Apache::Session::Browseable, this might require installing it from Debian Backports or CPAN.
Create database schema
You can find the database schema in /usr/share/lemonldap-ng/ressources/sessions.pg.sql.
Its indexes follow List of fields to index by session type. With PgJSON, the indexes are created
in the database instead of being listed in an Index option:
An index is only used by a query with the very same expression:
a_session ->> 'field', orcast(a_session ->> 'field' as bigint)for_utime. Replace_whatToTracewith your main session identifier if needed.The sessions explorer searches users, IP addresses, persistent and offline sessions by prefix (
LIKE 'abc%'). Unless the database collation isC, a plain index can’t serve these searches: the schema creates these indexes withtext_pattern_ops, which serves both equality and prefixes.Session updates are never “HOT” with these expression indexes: each index costs on every session update. Don’t create the indexes of the features you don’t use.
On an existing database, create the new indexes with
CREATE INDEX CONCURRENTLY, which doesn’t block the session writes. The indexes whose definition changes (i_s__whatToTrace,i_s_ipAddr,i_s__session_uid,i_p__session_uid) must be replaced, for example:CREATE INDEX CONCURRENTLY i_s__whatToTrace_new ON sessions ((a_session ->> '_whatToTrace') text_pattern_ops); DROP INDEX CONCURRENTLY i_s__whatToTrace; ALTER INDEX i_s__whatToTrace_new RENAME TO i_s__whatToTrace;
LemonLDAP::NG configuration
Go in the Manager and set the session module to Apache::Session::Browseable::PgJSON for each session type you intend to use:
General parameters»Sessions»Session storage»Apache::Session moduleGeneral parameters»Sessions»Persistent sessions»Apache::Session moduleCAS Service»CAS sessions module nameOpenID Connect Service»Sessions»Sessions module nameSAML2 Service»Advanced»SAML sessions module name
Then, set the following module options:
Parameter name |
Comment |
Example |
|---|---|---|
DataSource |
The DBI string |
|
UserName |
The database username |
|
Password |
The database password |
|
TableName |
Table name (optional) |
|
Commit |
This setting is mandatory for PostgreSQL to work |
|
Tip
Unlike other browseable modules, Pg::JSON does not require an Index parameter
Tip
We recommend adding the tcp_user_timeout and keepalives_idle options to the DBI string Refer to the full list of PostgreSQL connection options
Patroni support
Starting from version 1.3.17, Apache::Session::Browseable provides a direct Patroni PostgreSQL cluster
This works like PgJSON but can take an additional parameter PatroniUrl
which lists the Patroni servers available, then if there is a failure, the
driver will check for Patroni API to find the PostgreSQL leader and change
its DataSource to use it. To use it, set Apache::Session::Browseable::Patroni
as Sessions module and set corresponding options. Example:
Parameters |
Example |
Comment |
|---|---|---|
DataSource |
|
Unless an error occurs, the driver will use this data source |
UserName |
|
|
Password |
|
|
TableName |
|
|
Commit |
|
This setting is mandatory for PostgreSQL to work |
PatroniUrl |
|
List here all |