You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is an example using wal2json. A replication slot(test_slot_wal2json) must be created on the PostgreSQL server.
SELECT * FROM pg_create_logical_replication_slot('test_slot_wal2json', 'wal2json')
constslotName='test_slot_wal2json';constservice=newLogicalReplicationService(/** * node-postgres Client options for connection * https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/pg/index.d.ts#L16 */{database: 'playground',// ...},/** * Logical replication service config * https://github.com/kibae/pg-logical-replication/blob/main/src/logical-replication-service.ts#L9 */{acknowledge: {auto: true,timeoutSeconds: 10}})// `TestDecodingPlugin` for test_decoding and `ProtocolBuffersPlugin` for decoderbufs are also available.constplugin=newWal2JsonPlugin({/** * Plugin options for wal2json * https://github.com/kibae/pg-logical-replication/blob/main/src/output-plugins/wal2json/wal2json-plugin-options.type.ts *///...});/** * Wal2Json.Output * https://github.com/kibae/pg-logical-replication/blob/ts-main/src/output-plugins/wal2json/wal2json-plugin-output.type.ts */service.on('data',(lsn: string,log: Wal2Json.Output)=>{// Do something what you want.// log.change.filter((change) => change.kind === 'insert').length;});// Start subscribing to data change events.(functionproc(){service.subscribe(plugin,slotName).catch((e)=>{console.error(e);}).then(()=>{setTimeout(proc,100);});})();
constservice=newLogicalReplicationService(/** * node-postgres Client options for connection * https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/pg/index.d.ts#L16 */clientConfig: {user?: string|undefined;database?: string|undefined;password?: string|(()=>string|Promise<string>)|undefined;port?: number|undefined;host?: string|undefined;connectionString?: string|undefined;keepAlive?: boolean|undefined;stream?: stream.Duplex|undefined;statement_timeout?: false|number|undefined;parseInputDatesAsUTC?: boolean|undefined;ssl?: boolean|ConnectionOptions|undefined;query_timeout?: number|undefined;keepAliveInitialDelayMillis?: number|undefined;idle_in_transaction_session_timeout?: number|undefined;application_name?: string|undefined;connectionTimeoutMillis?: number|undefined;types?: CustomTypesConfig|undefined;options?: string|undefined;},/** * Logical replication service config * https://github.com/kibae/pg-logical-replication/blob/main/src/logical-replication-service.ts#L9 */config?: Partial<{acknowledge?: {/** * If the value is false, acknowledge must be done manually. * Default: true */auto: boolean;/** * Acknowledge is performed every set time (sec). If 0, do not do it. * Default: 10 */timeoutSeconds: 0|10|number;};}>)