decoder_raw

Output plugin for logical replication in Raw SQL format

Overview

PackageVersionCategoryLicenseLanguage
decoder_raw1.0ETLPostgreSQLC
IDExtensionBinLibLoadCreateTrustRelocSchema
9660decoder_rawNoYesNoNoNoNo-
Relatedpglogical wal2json decoderbufs test_decoding pg_failover_slots pgactive wal2mongo pgoutput

Version

TypeRepoVersionPG VerPackageDeps
EXTPIGSTY1.01817161514decoder_raw-
RPMPIGSTY1.01817161514decoder_raw_$v-
DEBPIGSTY1.01817161514postgresql-$v-decoder-raw-
OS / PGPG18PG17PG16PG15PG14
el8.x86_64
el8.aarch64
el9.x86_64
el9.aarch64
el10.x86_64PIGSTY MISSPIGSTY MISSPIGSTY MISS
el10.aarch64PIGSTY MISSPIGSTY MISSPIGSTY MISS
d12.x86_64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
d12.aarch64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
d13.x86_64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY MISSPIGSTY MISSPIGSTY MISS
d13.aarch64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY MISSPIGSTY MISSPIGSTY MISS
u22.x86_64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
u22.aarch64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
u24.x86_64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
u24.aarch64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0

Build

You can build the RPM / DEB packages for decoder_raw using pig build:

pig build pkg decoder_raw         # build RPM / DEB packages

Install

You can install decoder_raw directly. First, make sure the PGDG and PIGSTY repositories are added and enabled:

pig repo add pgsql -u          # Add repo and update cache

Install the extension using pig or apt/yum/dnf:

pig install decoder_raw;          # Install for current active PG version
pig ext install -y decoder_raw -v 18  # PG 18
pig ext install -y decoder_raw -v 17  # PG 17
pig ext install -y decoder_raw -v 16  # PG 16
pig ext install -y decoder_raw -v 15  # PG 15
pig ext install -y decoder_raw -v 14  # PG 14
dnf install -y decoder_raw_18       # PG 18
dnf install -y decoder_raw_17       # PG 17
dnf install -y decoder_raw_16       # PG 16
dnf install -y decoder_raw_15       # PG 15
dnf install -y decoder_raw_14       # PG 14
apt install -y postgresql-18-decoder-raw   # PG 18
apt install -y postgresql-17-decoder-raw   # PG 17
apt install -y postgresql-16-decoder-raw   # PG 16
apt install -y postgresql-15-decoder-raw   # PG 15
apt install -y postgresql-14-decoder-raw   # PG 14

This extension does not require CREATE EXTENSION

Usage

decoder_raw: Output plugin for logical replication in Raw SQL format

A logical decoding output plugin that converts WAL changes into raw SQL statements. Part of the pg_plugins collection by Michael Paquier.

Configuration

In postgresql.conf:

wal_level = logical
max_replication_slots = 10
max_wal_senders = 10

Using with SQL Functions

-- Create a logical replication slot
SELECT * FROM pg_create_logical_replication_slot('raw_slot', 'decoder_raw');

-- Perform DML operations
INSERT INTO my_table VALUES (1, 'hello');
UPDATE my_table SET val = 'world' WHERE id = 1;
DELETE FROM my_table WHERE id = 1;

-- Get changes as raw SQL
SELECT data FROM pg_logical_slot_get_changes('raw_slot', NULL, NULL);
-- Output:
-- INSERT INTO public.my_table (id, val) VALUES (1, 'hello');
-- UPDATE public.my_table SET val = 'world' WHERE id = 1;
-- DELETE FROM public.my_table WHERE id = 1;

-- Drop the slot
SELECT pg_drop_replication_slot('raw_slot');

Using with pg_recvlogical

# Create slot
pg_recvlogical -d postgres --slot raw_slot --create-slot -P decoder_raw

# Stream changes as SQL statements
pg_recvlogical -d postgres --slot raw_slot --start -f -

# Drop slot
pg_recvlogical -d postgres --slot raw_slot --drop-slot

Key Features

  • Outputs changes as executable SQL statements (INSERT, UPDATE, DELETE)
  • Useful for debugging logical decoding or replaying changes on another database
  • Tables should have REPLICA IDENTITY set for proper UPDATE/DELETE output
  • Lightweight plugin designed as a template for custom logical decoding plugins

Last Modified 2026-03-12: add pg extension catalog (95749bf)