Production Cutover Gate
3.2 TB transactional database migrated with 48-second application write pause
Initial parallel table copy and index creation ran online over 18 hours while the source served full traffic. At cutover, PgBouncer PAUSE held client connections for 48 seconds while logical replication drained to 0 bytes lag and sequences were synchronized.
1. Native logical publication & parallel-streaming subscription
-- On Source Primary: verify REPLICA IDENTITY and create publication SELECT n.nspname, c.relname FROM pg_class c JOIN pg_namespace n ON n.oid = c.relnamespace WHERE c.relkind = 'r' AND n.nspname = 'public' AND c.relreplident = 'd' AND NOT EXISTS (SELECT 1 FROM pg_constraint k WHERE k.conrelid = c.oid AND k.contype = 'p'); CREATE PUBLICATION pub_migration_all FOR ALL TABLES WITH (publish_via_partition_root = true); -- On Target PostgreSQL 17: stream in-progress transactions in parallel CREATE SUBSCRIPTION sub_migration_cutover CONNECTION 'host=10.24.1.10 port=5432 dbname=app_prod user=repl_migrator sslmode=verify-full' PUBLICATION pub_migration_all WITH (copy_data = true, streaming = parallel, synchronous_commit = off);
2. Zero-byte LSN lag gate & sequence synchronization at cutover
-- Verify replication slot has drained to 0 bytes before switching traffic
SELECT slot_name, active,
pg_wal_lsn_diff(pg_current_wal_lsn(), confirmed_flush_lsn) AS lag_bytes
FROM pg_replication_slots WHERE slot_name = 'sub_migration_cutover';
-- Synchronize all target sequences to table MAX(id) + safety buffer
SELECT format(
'SELECT setval(%L, COALESCE((SELECT MAX(%I) FROM %I.%I), 1) + 1000, true);',
pg_get_serial_sequence(format('%I.%I', table_schema, table_name), column_name),
column_name, table_schema, table_name
)
FROM information_schema.columns
WHERE table_schema = 'public'
AND pg_get_serial_sequence(format('%I.%I', table_schema, table_name), column_name) IS NOT NULL;






