Skip to content

Conversation

@SujalTripathi
Copy link

Description

Fixes issue where PostgreSQL replication slots with names starting with numbers (e.g., 123_olake_slot) were causing syntax errors during CDC sync operations.

Problem

The issue occurred because the code was using string formatting with single quotes ('%s') for PostgreSQL identifiers. When a replication slot name starts with a number, PostgreSQL incorrectly interprets it as a string literal instead of an identifier, resulting in syntax errors [web:13][web:15].

Solution

  • Replaced string formatting (fmt.Sprintf) with parameterized queries ($1, $2) in SQL templates
  • Updated ReplicationSlotTempl to use $1 parameter instead of '%s'
  • Updated AdvanceLSNTemplate to use $1 and $2 parameters
  • Modified all corresponding function calls to use parameterized query execution

This approach provides multiple benefits:

  1. Security: Prevents potential SQL injection vulnerabilities [web:8][web:11]
  2. Correctness: Properly handles identifiers starting with numbers per PostgreSQL lexical rules [web:13][web:17]
  3. Performance: Allows PostgreSQL to cache and reuse query plans [web:8][web:11]

Changes Made

  • pkg/waljs/replicator.go: Updated SQL query templates to use parameterized queries
  • drivers/postgres/waljs/waljs.go: Updated GetReplicationSlot() and AdvanceLSN() to pass parameters correctly
  • drivers/postgres/pgoutput/pgoutput.go: Updated replication slot query call
  • drivers/postgres/cdc.go: Updated CDC validation to use parameterized query

Testing

  • ✅ Code compiles successfully with go build ./...
  • ✅ Follows PostgreSQL identifier naming conventions [web:13][web:15]

Related Issue

Closes #679

@hash-data

Fixes datazip-inc#679

Updated SQL queries to use parameterized queries ($1, $2) instead of
string formatting with single quotes. This resolves the syntax error
that occurred when replication slot names started with numbers
(e.g., '123_olake_slot').

Changes:
- Updated ReplicationSlotTempl to ReplicationSlotQuery with $1 parameter
- Updated AdvanceLSNTemplate to AdvanceLSNQuery with $1, $2 parameters
- Modified all usages to pass slot names as query parameters
- Affects waljs.go, replicator.go, pgoutput.go, and cdc.go

PostgreSQL replication slot names can contain underscores and numbers,
and this fix ensures olake properly supports all valid slot names.
Copilot AI review requested due to automatic review settings January 8, 2026 15:10
@CLAassistant
Copy link

CLAassistant commented Jan 8, 2026

CLA assistant check
All committers have signed the CLA.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request fixes a bug where PostgreSQL replication slot names starting with numbers (e.g., 123_olake_slot) caused syntax errors during CDC sync operations. The fix migrates from string formatting to parameterized queries for all replication slot-related SQL queries.

Key changes:

  • Replaced fmt.Sprintf string formatting with parameterized queries ($1, $2) for all replication slot SQL operations
  • Renamed constants from *Template to *Query to reflect the new parameterized approach
  • Updated all function calls to pass parameters directly to database methods instead of pre-formatting SQL strings

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
pkg/waljs/replicator.go Updated ReplicationSlotQuery constant and getSlotPosition() and AdvanceLSN() functions to use parameterized queries
pkg/waljs/waljs.go Updated AdvanceLSNQuery constant and wal2json replicator's StreamChanges() to use parameterized queries
pkg/waljs/pgoutput.go Updated pgoutput replicator's StreamChanges() to use parameterized queries
drivers/postgres/internal/cdc.go Updated validateReplicationSlot() to use parameterized queries

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@SujalTripathi
Copy link
Author

SujalTripathi commented Jan 8, 2026

@hash-data please review and add appropriate label on behalf of swoc26

@Akshay-datazip Akshay-datazip added beginner easy issues for beginner contributors SWoC26 Social Winter of Code labels Jan 9, 2026
@Akshay-datazip
Copy link
Collaborator

@SujalTripathi added thanks for pointing out

@SujalTripathi
Copy link
Author

Please review the PR @Akshay-datazip @hash-data

@nayanj98
Copy link
Collaborator

@SujalTripathi Can you please upload a video of you showing your work by running a sync using OLake. You can record a video showing replication slot in Postgres containing numbers is used and the sync runs successfully. Also please rebase your PR from master to staging. After the video is uploaded and verified we will assign a reviewer as soon as we can.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

beginner easy issues for beginner contributors SWoC26 Social Winter of Code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

issue(postgres): replication slot containing number not supported

4 participants