Skip to content

Stream Postgresql database changes to TCP socket.

Notifications You must be signed in to change notification settings

wiwwo/pg_wal2socket

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pg_wal2socket


Send Postgresql WAL content to socket.
AKA
Stream Postgresql database changes to TCP socket.

I've seen other solutions around, but they relied on LISTEN/NOTIFY, which has some limitations.
This solution uses native Logical replication and wal2json plugin to stream database changes via sockets.

Far from being "production ready", but not that far. It just works.

IMPORTANT: use of this code in business context is strictly forbidden unless with explicit consent.


Small HOWTO

Change config file.

Terminal 1:

$ python3 pg_wal2socket.py

Terminal 2:

$ python3 pg_wal2socket-client.py localhost 8080

Terminal 3:

$ pgbench -i  -h 127.0.0.1 -Uuser db 

Requisites

  • A running Postgresql, with logical replication enabled and wal2json plugin enabled
  • A logical replication slot, as in select pg_create_logical_replication_slot('pg_wal2socket', 'wal2json');
  • python 3.10
  • psycopg2-binary==2.9.1

Thanks to

Nathan Jennings for Socket Programming in Python (Guide)

About

Stream Postgresql database changes to TCP socket.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages