K2BAudit PostgreSQL Configuration

This page applies to K2B Audit 5.0 and earlier versions. K2B Audit 6.0 and up does not requiere any manual configuration.

Introduction

This page contains configuration instructions to use K2BAudit with PostgreSQL. These instructions steps must be followed whenever a new environment using this DBMS is created. Some of them also apply when deploying an application with K2BAudit that uses PostgreSQL.

Step 1 - Configure the K2BAudit datastore

In your KB, a new DataStore called “K2BAudit” will appear after executing the “Initialize Audit” action. This DataStore is the location where the audit logs are stored. This DataStore must be configured to connect to the K2BAuditAnalyzer database.

If you are configuring the DataStore in the GeneXus IDE, you can find it in the DataStores section of your environment’s configuration.

K2BAuditDataStorePostgreSQL
K2BAudit DataStore

If you are configuring the DataStore in the generated application, you must use the configuration file.

Step 2 - Application user retrieval configuration

When an operation is audited, the user that is currently using the application is saved together with the operation values.

In order to get the application user, K2BAudit uses a procedure that is configured in the “After connect” property in the generator. The procedure that should be used in PostgreSQL environments is the “K2BSaveAuditUserPostgreSQL”.

K2BAuditAfterConnectProcedures
K2BAudit After connect procedures

In this procedure there is a section delimited by comments with the text “Set User Code”. The developer must update this section’s contents to load the correct User Code in the &User variable. The default implementation loads the user code from the application context.

K2BAuditAfterConnectSetUserCodeSection
Set User Code section

After updating the procedure’s code, the “After connect” property in the model must be updated to reference this procedure.

K2BAuditAfterConnectPropertyPostgreSQL
After connect property

Step 3 - PostgreSQL configuration

3.1 - Edit the postgresql.conf file

Edit the postgresql.conf file located in the PostgreSQL installation folder, and append the following lines at the end:

genaudit.usuario = ''
genaudit.ip = ''
genaudit.tenant = ''

Restart the server after saving the file.

3.2 - Create the “K2BSetAppInfo” stored procedure

This stored procedure is used by the GeneXus procedure configured in the second step. In order to create this stored procedure, open the PostgreSQL console, select the application’s database and execute the script located in: <GX_INSTALL_DIR>\Packages\K2BTools\Audit\PostgreSQL\ K2BAuditProcedures.sql