Skip to content

Migrate from github.com/jackc/pgx to github.com/jackc/pglogrepl#12

Merged
tamalsaha merged 4 commits intomasterfrom
migrate-to-pglogrepl
Jan 6, 2026
Merged

Migrate from github.com/jackc/pgx to github.com/jackc/pglogrepl#12
tamalsaha merged 4 commits intomasterfrom
migrate-to-pglogrepl

Conversation

@tamalsaha
Copy link

@tamalsaha tamalsaha commented Jan 4, 2026

Summary

This PR migrates the PostgreSQL logical replication implementation from the legacy pgx v3 API to the modern pglogrepl library with pgx/v5.

Changes

Dependencies (go.mod)

  • Replaced github.com/jackc/pgx v3.6.2+incompatible with:
    • github.com/jackc/pglogrepl v0.0.0-20251213150135-2e8d0df862c1
    • github.com/jackc/pgx/v5 v5.8.0
  • Removed obsolete indirect dependencies (cockroachdb/apd, jackc/fake, pkg/errors, etc.)

Main Application (cmd/pgoutbox/init.go)

  • Created replicationConn wrapper struct that adapts *pgconn.PgConn to the replication interface expected by the listener
  • Wrapper implements: CreateReplicationSlot, DropReplicationSlot, StartReplication, ReceiveMessage, SendStandbyStatusUpdate, IsAlive, Close
  • Updated imports to use pgx/v5 and pglogrepl packages

Listener (internal/listener/listener.go)

  • Changed lsn field type from uint64 to pglogrepl.LSN
  • Updated replication interface to use pglogrepl types:
    • CreateReplicationSlot returns pglogrepl.CreateReplicationSlotResult
    • StartReplication uses pglogrepl.LSN and pglogrepl.StartReplicationOptions
    • SendStandbyStatusUpdate uses pglogrepl.StandbyStatusUpdate
    • ReceiveMessage returns raw []byte instead of structured messages
  • Rewrote processRawMessage to handle raw byte messages using pglogrepl.ParseXLogData and pglogrepl.ParsePrimaryKeepaliveMessage
  • Updated SendStandbyStatus and AckWalMessage to take context parameter

Repository (internal/listener/repository.go)

  • Updated to pgx/v5 API (QueryRow instead of QueryRowEx)
  • Close now takes context parameter
  • IsAlive uses IsClosed() method

Tests

  • Updated all mock implementations for new interface signatures
  • Rewrote test helper functions to use pglogrepl types
  • Simplified test cases by removing obsolete NewStandbyStatus calls

Testing

  • All listener tests pass
  • Code compiles successfully
  • TestListener_Stream remains skipped (pre-existing, requires further work)

@tamalsaha tamalsaha force-pushed the migrate-to-pglogrepl branch from 08c18f2 to b9da36e Compare January 4, 2026 04:22
@tamalsaha tamalsaha force-pushed the migrate-to-pglogrepl branch 2 times, most recently from 8f32d26 to 5d80af4 Compare January 4, 2026 04:38
kodiakhq[bot]
kodiakhq bot previously approved these changes Jan 4, 2026
@tamalsaha tamalsaha force-pushed the migrate-to-pglogrepl branch from d108b21 to cc35c68 Compare January 4, 2026 14:49
This commit migrates the PostgreSQL logical replication implementation
from the legacy pgx v3 API to the modern pglogrepl library with pgx/v5.

## Changes

### Dependencies (go.mod)
- Replaced github.com/jackc/pgx v3.6.2+incompatible with:
  - github.com/jackc/pglogrepl v0.0.0-20251213150135-2e8d0df862c1
  - github.com/jackc/pgx/v5 v5.7.4
- Removed obsolete indirect dependencies (cockroachdb/apd, jackc/fake, etc.)

### Main Application (cmd/pgoutbox/init.go)
- Created replicationConn wrapper struct that adapts *pgconn.PgConn to
  the replication interface expected by the listener
- Wrapper implements: CreateReplicationSlot, DropReplicationSlot,
  StartReplication, ReceiveMessage, SendStandbyStatusUpdate, IsAlive, Close
- Updated imports to use pgx/v5 and pglogrepl packages

### Listener (internal/listener/listener.go)
- Changed lsn field type from uint64 to pglogrepl.LSN
- Updated replication interface to use pglogrepl types:
  - CreateReplicationSlot returns pglogrepl.CreateReplicationSlotResult
  - StartReplication uses pglogrepl.LSN and pglogrepl.StartReplicationOptions
  - SendStandbyStatusUpdate uses pglogrepl.StandbyStatusUpdate
  - ReceiveMessage returns raw []byte instead of structured messages
- Rewrote processRawMessage to handle raw byte messages using
  pglogrepl.ParseXLogData and pglogrepl.ParsePrimaryKeepaliveMessage
- Updated SendStandbyStatus and AckWalMessage to take context parameter

### Repository (internal/listener/repository.go)
- Updated to pgx/v5 API (QueryRow instead of QueryRowEx)
- Close now takes context parameter
- IsAlive uses IsClosed() method

### Tests
- Updated all mock implementations for new interface signatures
- Rewrote test helper functions to use pglogrepl types
- Simplified test cases by removing obsolete NewStandbyStatus calls

All listener tests pass.

Signed-off-by: Tamal Saha <tamal@appscode.com>
Signed-off-by: Tamal Saha <tamal@appscode.com>
Signed-off-by: Tamal Saha <tamal@appscode.com>
@tamalsaha tamalsaha force-pushed the migrate-to-pglogrepl branch from cc35c68 to d593e92 Compare January 5, 2026 12:51
Signed-off-by: Imtiaz Uddin <imtiaz@appscode.com>
@tamalsaha tamalsaha merged commit 2cc3f59 into master Jan 6, 2026
4 checks passed
@tamalsaha tamalsaha deleted the migrate-to-pglogrepl branch January 6, 2026 08:39
tamalsaha added a commit that referenced this pull request Jan 6, 2026
* Migrate from github.com/jackc/pgx to github.com/jackc/pglogrepl

This commit migrates the PostgreSQL logical replication implementation
from the legacy pgx v3 API to the modern pglogrepl library with pgx/v5.

## Changes

### Dependencies (go.mod)
- Replaced github.com/jackc/pgx v3.6.2+incompatible with:
  - github.com/jackc/pglogrepl v0.0.0-20251213150135-2e8d0df862c1
  - github.com/jackc/pgx/v5 v5.7.4
- Removed obsolete indirect dependencies (cockroachdb/apd, jackc/fake, etc.)

### Main Application (cmd/pgoutbox/init.go)
- Created replicationConn wrapper struct that adapts *pgconn.PgConn to
  the replication interface expected by the listener
- Wrapper implements: CreateReplicationSlot, DropReplicationSlot,
  StartReplication, ReceiveMessage, SendStandbyStatusUpdate, IsAlive, Close
- Updated imports to use pgx/v5 and pglogrepl packages

### Listener (internal/listener/listener.go)
- Changed lsn field type from uint64 to pglogrepl.LSN
- Updated replication interface to use pglogrepl types:
  - CreateReplicationSlot returns pglogrepl.CreateReplicationSlotResult
  - StartReplication uses pglogrepl.LSN and pglogrepl.StartReplicationOptions
  - SendStandbyStatusUpdate uses pglogrepl.StandbyStatusUpdate
  - ReceiveMessage returns raw []byte instead of structured messages
- Rewrote processRawMessage to handle raw byte messages using
  pglogrepl.ParseXLogData and pglogrepl.ParsePrimaryKeepaliveMessage
- Updated SendStandbyStatus and AckWalMessage to take context parameter

### Repository (internal/listener/repository.go)
- Updated to pgx/v5 API (QueryRow instead of QueryRowEx)
- Close now takes context parameter
- IsAlive uses IsClosed() method

### Tests
- Updated all mock implementations for new interface signatures
- Rewrote test helper functions to use pglogrepl types
- Simplified test cases by removing obsolete NewStandbyStatus calls

All listener tests pass.

---------

Signed-off-by: Tamal Saha <tamal@appscode.com>
Signed-off-by: Imtiaz Uddin <imtiaz@appscode.com>
Co-authored-by: Imtiaz Uddin <imtiaz@appscode.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants