Giter Site home page Giter Site logo

node-wal2json's Introduction

CircleCI npm

node-wal2json

Small nodejs implementation for wal2json. Supports polling-mode (via pg_logical_slot_get_changes) or streaming-mode (streaming-replication-protocol) to read changes from a given replication_slot

Installation

npm i -s @figedi/node-wal2json

Usage

In order to use this library, make sure that you have install all prerequisites:

  1. Install wal2json, follow the configuration setup
  2. On your postgres-installation, create a user with REPLICATION-attribute
  3. You are all set, run the library as follows:

Polling mode

const clientOpts = { replication: "database", connectionString: "postgres://..." };
const wal2json = new PGPollingReplication(clientOpts, { 
  pollTimeoutMs: 100, // poll every 100ms
  slotName: "test_slot", // create slot-name 'test'-slot'
});


// the instance is a readable-stream, so it can be iterated over
for await (const change of wal2json) {
  console.log(change);
}
Options

The 2nd parameter of PGPollingReplication allows the following options:

Opt Meaning
slotName The slotname for pg_logical, will be created if not exists
pollTimeoutMs Interval for polling for changes in ms
temporary (Optional) Creates a temporary slot bound to the connection
destroySlotOnClose (Optional) If a permanent slot is chosen and client is stopped, destroy slot

Streaming mode

const clientOpts = { connectionString: "postgres://..." };
const wal2json = new PGStreamingReplication(clientOpts, {
  startLsn: "0/5711970", // start at given LSN
  updateIntervalMs: 1000, // send updates to pg roughly every 1000ms
  slotName: "test_slot", // use slot-name 'test'-slot'
});

// the instance is a readable-stream, so it can be iterated over
for await (const change of wal2json) {
  console.log(change);
}

The 2nd parameter of PGStreamingReplication allows the following options:

Opt Meaning
slotName The slotname for pg_logical, will be created if not exists
updateIntervalMs (Optional) Interval for sending-back updates to pg, set 0 for reducing updates to the max
startLsn (Optional) The start-LSN for the replication, note when the slot is already advanced this is ignored
autoAckLsn (Optional) When set to true, set all received LSN directly as flushed upon next update-interval
temporary (Optional) Creates a temporary slot bound to the connection
destroySlotOnClose (Optional) If a permanent slot is chosen and client is stopped, destroy slot

node-wal2json's People

Contributors

figedi avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.