Skip to content
Sanjeev Kumar Pandit edited this page Apr 11, 2017 · 11 revisions

The configuration is loaded from /etc/pglistend/config.yml file which looks like this:

# postgresql connection
default:
    connection:
        host: localhost
        user: 'YOUR_USERNAME'
        database: 'DATABASE'
        password: 'PASSWORD'
        port: 5432
        max: 10,
        idleTimeoutMillis: 10000

connections:
    - /path/to/pglistend-db.yml
    - /path/to/another/pglistend-db.yml
  • default is the default connection.
  • connections is the list of configuration files.
  • connection parameters refer to the database connection parameters

A sample connection file pglistend-db.yml:

# postgresql connection
connection:
    user: 'USERNAME'
    database: 'DATABASE_NAME'
    password: 'PASSWORD'
    port: 5432
    max: 4

# channels to LISTEN to
channels:
    - update
    - insert
    - delete
    - news_update
    - foo

# scripts
scripts:
    - /path/to/test_project/listener-script.js
    - /path/to/another/test_project/listener-script.js
  • connection parameters refer to the database connection parameters
  • channels is a list of postgres channel names to LISTEN to
  • scripts is a list of listener scripts that registers callbacks/handlers for the channels we're listening to. You can define here what actions are to be carried out when notification is received for any of the channels.

Listener scripts

To register a new listener script you can create a new javascript file like this:

module.exports = {
    // Register a handler function on a channel that should be triggered
    // whenever any notification is received on that channel from 
    // postgres using `NOTIFY`.
    const {throttle, log, query} = h;

    'channel_1': function(payload) {
        // Do something
    },

    'channel_2': function(payload) {
        // Do something else
    },

    'channel_3': throttle((payload) => {
        // Do something
    }, 3000),

    'channel_4': throttle((payload) => {
        // Do something
    }, 3000, { 'leading': false, 'trailing': true })
};

Click here to know more about setting up scripts.

NOTE: Every time you alter the configuration you need to reload the daemon using:

sudo systemctl restart pglistend

In case it is not yet started you can do:

sudo systemctl start pglistend
Clone this wiki locally