Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replication should now work from PG 16 Standbys #858

Merged
merged 4 commits into from
Dec 20, 2023

Conversation

saisrirampur
Copy link
Contributor

@saisrirampur saisrirampur commented Dec 20, 2023

I tried PeerDB on Read Replicas in PG 16:

  1. Initial Load worked as expected
  2. SyncFlows were erroring out:
ERROR:  recovery is in progress
HINT:  WAL control functions cannot be executed during recovery.

The reason was pg_current_wal_lsn() cannot be run on a standby. I changed that function to pg_last_wal_replay_lsn() if Replica.

@saisrirampur saisrirampur changed the title Replication should now work from standbys for pg16 Replication should now work from PG 16 Standbys Dec 20, 2023
@saisrirampur
Copy link
Contributor Author

@Amogh-Bharadwaj I am still seeing issues on the UI because to get slot information because we use pg_current_wal_lsn() in the GetSlotInfo function. That needs separate fixing.

@serprex
Copy link
Contributor

serprex commented Dec 20, 2023

Can you try keeping it down to a single query roundtrip using

CASE WHEN pg_is_in_recovery()
  THEN pg_last_wal_receive_lsn()
  ELSE pg_current_wal_lsn()
END

GetSlotInfo could use the same expression

@saisrirampur
Copy link
Contributor Author

Below works @serprex. Just checked on a standby server. This PR introduces isReplica() function which might be useful to be present in code otherwise. However I'll leave it to you on deciding the right approach.

CASE WHEN pg_is_in_recovery()
  THEN pg_last_wal_receive_lsn()
  ELSE pg_current_wal_lsn()
END

@serprex
Copy link
Contributor

serprex commented Dec 20, 2023

Tested. Problem: CREATE PUBLICATION has to be run on primary, not standby. So a followup will need to be made where mirror can be configured to create publication on a different peer than source. But in the meantime one can create the publication slot for peerdb based on error message & things work after that

@serprex serprex merged commit 6b4e0e3 into main Dec 20, 2023
7 checks passed
@serprex serprex deleted the replication_from_standby_pg16 branch December 25, 2023 21:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants