All Projects → xstevens → Decoderbufs

xstevens / Decoderbufs

Licence: mit
INACTIVE: A PostgreSQL logical decoder output plugin to deliver data as Protocol Buffers

Programming Languages

c
50402 projects - #5 most used programming language

Projects that are alternatives of or similar to Decoderbufs

Incubator Age
Graph database optimized for fast analysis and real-time data processing. It is provided as an extension to PostgreSQL.
Stars: ✭ 244 (+110.34%)
Mutual labels:  postgresql, postgresql-extension
Pgaudit
PostgreSQL Audit Extension
Stars: ✭ 532 (+358.62%)
Mutual labels:  postgresql, postgresql-extension
Orafce
The "orafce" project implements in Postgres some of the functions from the Oracle database that are missing (or behaving differently).Those functions were verified on Oracle 10g, and the module is useful for production work.
Stars: ✭ 274 (+136.21%)
Mutual labels:  postgresql, postgresql-extension
Plsh
PL/sh is a procedural language handler for PostgreSQL that allows you to write stored procedures in a shell of your choice.
Stars: ✭ 111 (-4.31%)
Mutual labels:  postgresql, postgresql-extension
Pgx
Build Postgres Extensions with Rust!
Stars: ✭ 903 (+678.45%)
Mutual labels:  postgresql, postgresql-extension
Tds fdw
A PostgreSQL foreign data wrapper to connect to TDS databases (Sybase and Microsoft SQL Server)
Stars: ✭ 238 (+105.17%)
Mutual labels:  postgresql, postgresql-extension
Plpgsql check
plpgsql_check is linter tool for language PL/pgSQL (native language for PostgreSQL store procedures).
Stars: ✭ 322 (+177.59%)
Mutual labels:  postgresql, postgresql-extension
Plgo
easily create postgresql extensions in golang; moved to gitlab.com/microo8/plgo
Stars: ✭ 286 (+146.55%)
Mutual labels:  postgresql, postgresql-extension
Es Cqrs Shopping Cart
A resilient and scalable shopping cart system designed using Event Sourcing (ES) and Command Query Responsibility Segregation (CQRS)
Stars: ✭ 19 (-83.62%)
Mutual labels:  protocol-buffers, postgresql
Pg acoustid
PostgreSQL extension for working with AcoustID fingerprints
Stars: ✭ 6 (-94.83%)
Mutual labels:  postgresql, postgresql-extension
Pguri
uri type for PostgreSQL
Stars: ✭ 235 (+102.59%)
Mutual labels:  postgresql, postgresql-extension
Plv8
V8 Engine Javascript Procedural Language add-on for PostgreSQL
Stars: ✭ 1,195 (+930.17%)
Mutual labels:  postgresql, postgresql-extension
Agensgraph Extension
A graph database extension for PostgreSQL
Stars: ✭ 170 (+46.55%)
Mutual labels:  postgresql, postgresql-extension
Wasmer Postgres
💽🕸 Postgres library to run WebAssembly binaries.
Stars: ✭ 245 (+111.21%)
Mutual labels:  postgresql, postgresql-extension
Pg hashids
Short unique id generator for PostgreSQL, using hashids
Stars: ✭ 164 (+41.38%)
Mutual labels:  postgresql, postgresql-extension
Pg auto failover
Postgres extension and service for automated failover and high-availability
Stars: ✭ 564 (+386.21%)
Mutual labels:  postgresql, postgresql-extension
Pg partman
Partition management extension for PostgreSQL
Stars: ✭ 1,085 (+835.34%)
Mutual labels:  postgresql, postgresql-extension
Bgworker
Background Worker Processes for PostgreSQL written in Go
Stars: ✭ 77 (-33.62%)
Mutual labels:  postgresql, postgresql-extension
Xgenecloud
XgeneCloud is now https://github.com/nocodb/nocodb
Stars: ✭ 1,629 (+1304.31%)
Mutual labels:  postgresql
Streak.club
a website for running creative streaks
Stars: ✭ 109 (-6.03%)
Mutual labels:  postgresql

WARNING

I worked on this code as a PoC 4 years ago. I have not actively maintained it and I've moved on to other projects. You're still free to use it, but keep this in mind. If you're looking for something more actively maintained check out Debezium's fork.

decoderbufs

A PostgreSQL logical decoder output plugin to deliver data as Protocol Buffers

decoderbufs

Version: 0.2.0

decoderbufs is a PostgreSQL logical decoder output plugin to deliver data as Protocol Buffers.

decoderbufs is released under the MIT license (See LICENSE file).

Shoutouts:

Version Compatability

This code is built with the following assumptions. You may get mixed results if you deviate from these versions.

Requirements

  • PostgreSQL
  • PostGIS
  • Protocol Buffers
  • protobuf-c

Building

To build you will need to install PostgreSQL (for pg_config) and PostgreSQL server development packages. On Debian based distributions you can usually do something like this:

apt-get install -y postgresql postgresql-server-dev-9.6

You will also need to make sure that protobuf-c and it's header files have been installed. See their Github page for further details.

If you have all of the prerequisites installed you should be able to just:

make && make install

Once the extension has been installed you just need to enable it and logical replication in postgresql.conf:

# MODULES
shared_preload_libraries = 'decoderbufs'

# REPLICATION
wal_level = logical             # minimal, archive, hot_standby, or logical (change requires restart)
max_wal_senders = 8             # max number of walsender processes (change requires restart)
wal_keep_segments = 4           # in logfile segments, 16MB each; 0 disables
#wal_sender_timeout = 60s       # in milliseconds; 0 disables
max_replication_slots = 4       # max number of replication slots (change requires restart)

In addition, permissions will have to be added for the user that connects to the DB to be able to replicate. This can be modified in pg_hba.conf like so:

local   replication     <youruser>                          trust
host    replication     <youruser>  127.0.0.1/32            trust
host    replication     <youruser>  ::1/128                 trust

And restart PostgreSQL.

Usage

-- can use SQL for demo purposes
select * from pg_create_logical_replication_slot('decoderbufs_demo', 'decoderbufs');

-- DO SOME TABLE MODIFICATIONS (see below about UPDATE/DELETE)

-- peek at WAL changes using decoderbufs debug mode for SQL console
select data from pg_logical_slot_peek_changes('decoderbufs_demo', NULL, NULL, 'debug-mode', '1');
-- get WAL changes using decoderbufs to update the WAL position
select data from pg_logical_slot_get_changes('decoderbufs_demo', NULL, NULL, 'debug-mode', '1');

-- check the WAL position of logical replicators
select * from pg_replication_slots where slot_type = 'logical';

If you're performing an UPDATE/DELETE on your table and you don't see results for those operations from logical decoding, make sure you have set REPLICA IDENTITY appropriately for your use case.

For consuming the binary format, I have implemented a custom PostgreSQL logical replication client that publishes to Apache Kafka. I'm hoping to clean that up a bit and open source the project.

Type Mappings

The following table shows how current PostgreSQL type OIDs are mapped to which decoderbuf fields:

PostgreSQL Type OID Decoderbuf Field
BOOLOID datum_boolean
INT2OID datum_int32
INT4OID datum_int32
INT8OID datum_int64
OIDOID datum_int64
FLOAT4OID datum_float
FLOAT8OID datum_double
NUMERICOID datum_double
CHAROID datum_string
VARCHAROID datum_string
BPCHAROID datum_string
TEXTOID datum_string
JSONOID datum_string
XMLOID datum_string
UUIDOID datum_string
TIMESTAMPOID datum_string
TIMESTAMPTZOID datum_string
BYTEAOID datum_bytes
POINTOID datum_point
PostGIS geometry datum_point
PostGIS geography datum_point

Support

File bug reports, feature requests and questions using GitHub Issues

Notes

This approach is the one we wanted when we first started kicking around ideas for how to replicate our Postgres DBs in near-realtime. It should provide much better resiliency in the face of network outages and unplanned downtime than a push mechanism (like using pg_kafka with a trigger) would.

The PostgreSQL docs are pretty good and are definitely worth a read.

NOT ALL OID TYPES ARE SUPPORTED CURRENTLY. I really want to iterate this point. There are lots of OIDs in Postgres. Right now I'm translating the ones that I see used a lot, but it is by no means comprehensive. I hope to update this project to support most if not all types at some point.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].