Skip to content

Commit d2373d0

Browse files
Update guide to add example for cleaning up leftover publications in database upgrade guide and ensure caution message formatting is consistent.(#368)
Co-authored-by: raj <raj@turbot.com>
1 parent 44b0250 commit d2373d0

File tree

1 file changed

+58
-3
lines changed
  • docs/guides/hosting-guardrails/disaster-recovery/database-upgrade

1 file changed

+58
-3
lines changed

docs/guides/hosting-guardrails/disaster-recovery/database-upgrade/index.md

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ In a new session, initiate the `pg_dump` process using the `snapshot ID` obtaine
260260
nohup time pg_dump -h $SOURCE -U master --snapshot="00000062-000182C4-1" -F c -b -v -f data.dump turbot > dump.log 2>&1 &
261261
```
262262

263-
> [!CAUTION]
263+
> [!CAUTION]
264264
> Enabling logical replication before a long pg_dump/restore can lead to WAL buildup and storage exhaustion. It is recommended to enable RDS storage autoscaling to prevent out-of-space errors during migration.
265265
### Monitor
266266

@@ -523,7 +523,7 @@ Run smoke tests to Test both the restored and new database instances to confirm
523523
<!-- TO CHECK IF THIS WILL TERMINATE THE OLD RDS INSTANCE turbot-einstein-blue? -->
524524
<!-- INCLUDE TERMINATION PROTECTION NOTE HERE FOR RDS INSTANCE -->
525525

526-
Delete the new TED stack i.e. `turbot-einstein-green` along with its associated resources, including the S3 bucket, log groups, and AWS Backup. Clean up replication slots and subscriptions.
526+
After verifying a successful upgrade and switchover, delete the new TED stack i.e `turbot-einstein-green` and remove its associated resources such as the S3 bucket, CloudWatch log groups, and AWS Backup configurations. Clean up replication slots and subscriptions.
527527

528528
<!-- When the old DB is terminated from the TED stack, the following will be automatically cleaned up.
529529
@@ -533,11 +533,66 @@ select * from pg_replication_slots;
533533
select * from pg_drop_replication_slot('rs_blue');
534534
drop schema migration_turbot cascade; -->
535535

536+
### In Case of Upgrade Failure or Aborted Migration
537+
538+
If the database upgrade fails or is manually aborted before completion, it’s important to clean up replication artifacts from the **source database** to avoid lingering replication objects and ensure a clean state for future upgrade attempts.
539+
540+
Run the following SQL commands on the source (blue) database to drop replication artifacts:
541+
542+
```sql
543+
-- Check for existing publications
544+
SELECT * FROM pg_publication;
545+
546+
-- Drop the publication used for replication
547+
DROP PUBLICATION pub_blue;
548+
549+
-- Check for replication slots
550+
SELECT * FROM pg_replication_slots;
551+
552+
-- Drop the replication slot used for streaming
553+
SELECT * FROM pg_drop_replication_slot('rs_blue');
554+
555+
-- Check for existing subscriptions
556+
SELECT * FROM pg_subscription;
557+
558+
-- Drop the subscription created during upgrade
559+
DROP SUBSCRIPTION sub_blue;
560+
```
561+
562+
**Example:**
563+
564+
Here's an example showing how to check for and clean up a leftover publication:
565+
566+
`select * from pg_publication` indicates the presence of left over `PUBLICATION` `pub_blue`, this needs to be dropped. Recheck after dropping the `PUBLICATION`
567+
568+
```
569+
turbot=> select * from pg_publication
570+
turbot-> ;
571+
oid | pubname | pubowner | puballtables | pubinsert | pubupdate | pubdelete | pubtruncate | pubviaroot
572+
------------+----------+----------+--------------+-----------+-----------+-----------+-------------+------------
573+
2142597123 | pub_blue | 16397 | t | t | t | t | t | f
574+
(1 row)
575+
576+
turbot=> DROP PUBLICATION pub_blue;
577+
DROP PUBLICATION
578+
579+
turbot=> select * from pg_publication
580+
;
581+
oid | pubname | pubowner | puballtables | pubinsert | pubupdate | pubdelete | pubtruncate | pubviaroot
582+
-----+---------+----------+--------------+-----------+-----------+-----------+-------------+------------
583+
(0 rows)
584+
```
585+
586+
Also, make sure to delete associated resources created as part of the upgrade attempt:
587+
- S3 bucket
588+
- CloudWatch Log Groups
589+
- AWS Backup plans and vaults
590+
- Any temporary RDS instances or TED-related infrastructure
591+
536592
## Step 18: Disable and Delete Subscriptions
537593

538594
Disable and delete subscription and replication slots.
539595

540-
541596
```sql
542597
select * from pg_subscription;
543598
alter subscription sub_blue disable;

0 commit comments

Comments
 (0)