Skip to content

Latest commit

 

History

History
56 lines (36 loc) · 1.09 KB

README.md

File metadata and controls

56 lines (36 loc) · 1.09 KB

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)