Skip to content

Add migration to create logical replication slot - #4946

Merged
DilwoarH merged 1 commit into
mainfrom
create-replication-slot
Oct 29, 2026
Merged

DilwoarH merged 1 commit into
mainfrom
create-replication-slot

Conversation

@DilwoarH

@DilwoarH DilwoarH commented Aug 28, 2026 •

Copy link
Copy Markdown
Contributor

This creates a wal2json replication slot to allow us to listen to changes to the notifications table.

@DilwoarH
DilwoarH force-pushed the create-replication-slot branch 2 times, most recently from a778ebf to 95f43b1 Compare September 1, 2026 12:06
@DilwoarH
DilwoarH requested review from klssmith and risicle September 2, 2026 09:52
@klssmith

klssmith commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Can we test this on a dev env? It seems like we're going to run into the problem of output_plugin_libraries now needing to include wal2json. This PR added that to the Concourse test image, but I'd expect us to need the same change in our environments

@DilwoarH

DilwoarH commented Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

Can we test this on a dev env?

Good point, Will run another test.

It seems like we're going to run into the problem of output_plugin_libraries now needing to include wal2json. This PR added that to the Concourse test image, but I'd expect us to need the same change in our environments

I noticed that I missed the default ones, it should have been:

pgoutput, test_decoding, wal2json

I'll have a look at adding this in.

@risicle

risicle commented Sep 2, 2026

Copy link
Copy Markdown
Member

Dude before we consider enabling this for production we need to choose and set a max_slot_wal_keep_size. I think it's currently set to "infinite", which means this would just start eating up our disk space forever if nothing were consuming the slot.

@DilwoarH

DilwoarH commented Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

Dude before we consider enabling this for production we need to choose and set a max_slot_wal_keep_size. I think it's currently set to "infinite", which means this would just start eating up our disk space forever if nothing were consuming the slot.

Yeah - I'm avoiding merging this in before the processing code (#4930).

@DilwoarH

DilwoarH commented Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

Can we test this on a dev env?

Good point, Will run another test.

It seems like we're going to run into the problem of output_plugin_libraries now needing to include wal2json. This PR added that to the Concourse test image, but I'd expect us to need the same change in our environments

I noticed that I missed the default ones, it should have been:

pgoutput, test_decoding, wal2json

I'll have a look at adding this in.

A PR was merged to fix the concourse test dbs - #4955

@DilwoarH

DilwoarH commented Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

Can we test this on a dev env? It seems like we're going to run into the problem of output_plugin_libraries now needing to include wal2json. This PR added that to the Concourse test image, but I'd expect us to need the same change in our environments

@klssmith additional test ran on dev-d - worked fine.

@DilwoarH

DilwoarH commented Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

Todo before merging this in:

  • Set max size limit
  • Set output_plugin_libraries

@DilwoarH

DilwoarH commented Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

@klssmith

klssmith commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

I realised this will work in our environments now because we're using Postgres 15.17, and the restriction on output_plugin_libraries was only introduced in 15.19. But we will presumably have issues when we do upgrade Postgres - it feels like it would be best just to update output_plugin_libraries now before we're using wal2json and in case we don't remember we need to do that before upgrading Postgres. That wouldn't block this PR but might be something to discuss

@risicle

risicle commented Sep 3, 2026

Copy link
Copy Markdown
Member

@risicle - looks like there is a default limit set of 2GB already:

That's not the same config setting.

@DilwoarH

DilwoarH commented Sep 3, 2026

Copy link
Copy Markdown
Contributor Author

@risicle - looks like there is a default limit set of 2GB already:

That's not the same config setting.

PR added: https://github.com/alphagov/notifications-aws/pull/3094

@DilwoarH

DilwoarH commented Sep 4, 2026

Copy link
Copy Markdown
Contributor Author

#3094 has been merged in but requires reboot to apply changes

@DilwoarH

DilwoarH commented Sep 7, 2026

Copy link
Copy Markdown
Contributor Author

#3094 has been merged in but requires reboot to apply changes

Restart not required: https://github.com/alphagov/notifications-aws/pull/3096

@DilwoarH

DilwoarH commented Sep 7, 2026

Copy link
Copy Markdown
Contributor Author

@risicle @klssmith - are you both happy with this now?

@klssmith

klssmith commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

It doesn't block this, but I still think we need a definite plan or PR for when we'll change output_plugin_libraries to include wal2json. Otherwise it will get forgotten about and cause an incident when the Postgres version is upgraded and our code no longer works

@DilwoarH

DilwoarH commented Sep 9, 2026

Copy link
Copy Markdown
Contributor Author

It doesn't block this, but I still think we need a definite plan or PR for when we'll change output_plugin_libraries to include wal2json. Otherwise it will get forgotten about and cause an incident when the Postgres version is upgraded and our code no longer works

PR added to support this:

https://github.com/alphagov/notifications-aws/pull/3100

@DilwoarH
DilwoarH force-pushed the create-replication-slot branch from 95f43b1 to 247589b Compare September 9, 2026 14:25
@DilwoarH
DilwoarH force-pushed the create-replication-slot branch 2 times, most recently from 38c43f5 to 194a659 Compare September 29, 2026 08:59
@risicle

risicle commented Sep 29, 2026

Copy link
Copy Markdown
Member

So ... are we happy we have max_slot_wal_keep_size set now? Are we ready to merge this?

@risicle risicle left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You'll need to rebase though.

@DilwoarH
DilwoarH force-pushed the create-replication-slot branch 2 times, most recently from 8ca8bb0 to 60ed784 Compare October 6, 2026 09:40

revision = "0576_create_replacation_slot"
down_revision = "0575_invusr_srv_id_null_valid"
slot_name = "notify_dashboard_replication_slot"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not crazy about this name. I'd call it dbstreamer_replication_slot because dbstreamer is what we probably want to call the daemon that we eventually run to consume this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think it makes it clear what it is - dbstreamer sounds very generic

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

That's the point - we're probably going to use this for a lot more than the dashboard.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Then a better name is probably notify_replication_slot

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

But we also use replication for our read-replicas, and when we do our postgres upgrade we're going to be using it for logical replication to sync the dbs before we switch.

Comment thread migrations/versions/0576_create_replacation_slot.py Outdated
@DilwoarH
DilwoarH force-pushed the create-replication-slot branch 2 times, most recently from 772005f to 2b55234 Compare October 8, 2026 10:11
@risicle

risicle commented Oct 8, 2026

Copy link
Copy Markdown
Member

Just noticed the migration name misspells replication.

@risicle

risicle commented Oct 9, 2026 •

Copy link
Copy Markdown
Member

Also notify_replication_slot isn't really a helpful name because we use replication in like 3 different ways. I want to call the app consuming this the "db streamer" because it's a term that isn't already overloaded.

@DilwoarH
DilwoarH force-pushed the create-replication-slot branch from 2b55234 to 1a52e5c Compare October 11, 2026 14:18
@DilwoarH

Copy link
Copy Markdown
Contributor Author

Also notify_replication_slot isn't really a helpful name because we use replication in like 3 different ways. I want to call the app consuming this the "db streamer" because it's a term that isn't already overloaded.

Renamed it to notify_wal2json_slot. This will avoid any confusion with any other terms used as well as specifically refer back to the plugin used to initialise the slot.

I initially changed it to notify_db_streamer_slot but decided against it because it is not obvious what it is it for. Happy to chat about this offline to come to an agreement if there are any further suggestions.

@DilwoarH
DilwoarH force-pushed the create-replication-slot branch from 1a52e5c to 0122850 Compare October 29, 2026 10:11
@DilwoarH
DilwoarH merged commit c864555 into main Oct 29, 2026
10 checks passed
@DilwoarH
DilwoarH deleted the create-replication-slot branch October 29, 2026 13:55
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.

3 participants