Security News
Highlights from the 2024 Rails Community Survey
A record 2,709 developers participated in the 2024 Ruby on Rails Community Survey, revealing key tools, practices, and trends shaping the Rails ecosystem.
pg-logical-replication
Advanced tools
PostgreSQL Location Replication client - logical WAL replication streaming
$ npm install pg-logical-replication
new LogicalReplication( object config ) : Stream
var LogicalReplication = require('pg-logical-replication');
var stream = new LogicalReplication({/*config*/});
stream.getChanges( /*string*/ slotName, /*string*/ uptoLsn, /*object*/ option, /*function(err)*/ initialErrorCallback );
uptoLsn
can be null, the minimum value is "0/00000000".option
can contain any of the following optional properties
standbyMessageTimeout
: maximum seconds between keepalive messages (default: 10)includeXids
: bool (default: false)includeTimestamp
: bool (default: false)queryOptions
: object containing decoder specific options (optional)
'include-types': false
'filter-tables': 'foo.bar'
stream.stop();
stream.on('data', (/*object*/ msg)=>{/*...*/});
msg
contains lsn (string)
, log (buffer)
stream.on('error', (/*object*/ err)=>{/*...*/});
test_decoding
, this plugin will be useful.var PluginTestDecoding = LogicalReplication.LoadPlugin('output/test_decoding');
PluginTestDecoding.parse(msg.log.toString('utf8'));
/*
* Test progress
* 1. Create logical replication slot with test_decoding output plugin : SELECT * FROM pg_create_logical_replication_slot('test_slot', 'test_decoding');
* 2. Launch nodejs with this file : node test.js
* 3. Modify data of database
*/
var LogicalReplication = require('pg-logical-replication');
var PluginTestDecoding = LogicalReplication.LoadPlugin('output/test_decoding');
//Connection parameter : https://github.com/brianc/node-postgres/wiki/Client#parameters
var connInfo = {};
//Initialize with last LSN value
var lastLsn = null;
var stream = (new LogicalReplication(connInfo))
.on('data', function(msg) {
lastLsn = msg.lsn || lastLsn;
var log = (msg.log || '').toString('utf8');
try {
console.log(PluginTestDecoding.parse(log));
//TODO: DO SOMETHING. eg) replicate to other dbms(pgsql, mysql, ...)
} catch (e) {
console.trace(log, e);
}
}).on('error', function(err) {
console.trace('Error #2', err);
setTimeout(proc, 1000);
});
(function proc() {
stream.getChanges('test_slot', lastLsn, {
includeXids: false, //default: false
includeTimestamp: false, //default: false
}, function(err) {
if (err) {
console.trace('Logical replication initialize error', err);
setTimeout(proc, 1000);
}
});
})();
wal_level = logical
max_wal_senders = [bigger than 1]
max_replication_slots = [bigger than 1]
SELECT * FROM pg_create_logical_replication_slot('test_slot', 'test_decoding');
SELECT pg_drop_replication_slot('test_slot');
FAQs
PostgreSQL Location Replication client - logical WAL replication streaming
The npm package pg-logical-replication receives a total of 4,340 weekly downloads. As such, pg-logical-replication popularity was classified as popular.
We found that pg-logical-replication demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A record 2,709 developers participated in the 2024 Ruby on Rails Community Survey, revealing key tools, practices, and trends shaping the Rails ecosystem.
Security News
In 2023, data breaches surged 78% from zero-day and supply chain attacks, but developers are still buried under alerts that are unable to prevent these threats.
Security News
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.