From 7a8d4f3dfd83af5779eef8090f74d953e5dbce20 Mon Sep 17 00:00:00 2001 From: pritha Date: Tue, 19 Nov 2024 18:02:43 +0530 Subject: [PATCH 1/2] Update guide - database-upgrade-storage-optimization doc. Closes #210. --- .../index.md | 26 ++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/docs/guides/hosting-guardrails/disaster-recovery/database-upgrade-storage-optimization/index.md b/docs/guides/hosting-guardrails/disaster-recovery/database-upgrade-storage-optimization/index.md index 5cf09fa4..aae1ebd9 100644 --- a/docs/guides/hosting-guardrails/disaster-recovery/database-upgrade-storage-optimization/index.md +++ b/docs/guides/hosting-guardrails/disaster-recovery/database-upgrade-storage-optimization/index.md @@ -20,12 +20,16 @@ Efficient management of database resources ensures optimal storage utilization, - PostgreSQL client installed on the [bastion host](https://github.com/turbot/guardrails-samples/tree/main/enterprise_installation/turbot_bastion_host). - Ensure logical replication is supported and enabled on the database engine. - Knowledge of the current database usage (storage and version). +- TED stack version is atleast 1.45.0. + +## Warnings - +1. After creating replication slots (steps #7 below), we won't be able to upgrade any existing workspaces or create a new one till the end of the process. Basically, no DDL changes. ## Step 1: Spin up a new TED - Create a new [TED](/guardrails/docs/reference/glossary#turbot-guardrails-enterprise-database-ted) with the same name as the original, appending `-blue` or `-green` to the end. - If performing a database version upgrade, use the `DB Engine Version` and `Read Replica DB Engine Version` parameters under the "Database - Advanced - Engine" section. Set the appropriate `DB Engine Parameter Group Family` and the `Hive RDS Parameter Group` under the "Database - Advanced - Parameters" section. -- Set the allocated storage to match the current disk usage (e.g., if 210 GB out of 500 GB is used, set allocated storage to 210 GB) using the `Allocated Storage in GB` parameter under the "Database - Advanced - Storage" section. +- Set the allocated storage to match the current disk usage using the `Allocated Storage in GB` parameter under the "Database - Advanced - Storage" section. For example - if 210 GB out of 500 GB is used, set allocated storage to 210 GB. Check the `FreeStorageSpace` metrics to get the size. - Set the maximum allocated storage to a suitable value using the `Maximum Allocated Storage limit in GB` parameter under the "Database - Advanced - Storage" section. - Set up encryption by configuring the `Custom Hive Key` parameter to use the original KMS key under the "Advanced - Infrastructure" section. This should be the Key ID, typically formatted as: 1111233-abcd-4444-2322-123456789012. - Keep the other parameters the same. @@ -34,6 +38,7 @@ Efficient management of database resources ensures optimal storage utilization, - Go to the AWS Console and navigate to the relevant parameter group. - Set `rds.logical_replical` to **`1`** if it’s not already set. +- Turn off events - https://turbot.com/guardrails/docs/enterprise/FAQ/pause-events - Reboot the DB instance (expected downtime is ~50 seconds). ## Step 3: Set Master Password @@ -105,6 +110,11 @@ Use pg_dump to create a dump of the source database: nohup pg_dump -h $SOURCE -U master -F c -b -v -f data.dump turbot > dump.log 2>&1 ``` +Check for errors in the dump file +```shell +cat dump.log | grep error +``` + ## Step 9: Restore the Dump in the Target DB Restore the database in the target instance: @@ -129,7 +139,7 @@ set local search_path to , public; ``` ```sql -set local search_path to ; +set local search_path to , public; create trigger control_category_path_au after update on control_categories for each row when (old.path is distinct from new.path) execute procedure types_path_au('controls', 'control_category_id', 'control_category_path'); create trigger control_resource_category_path_au after update on resource_categories for each row when (old.path is distinct from new.path) execute procedure types_path_au('controls', 'resource_category_id', 'resource_category_path'); create trigger control_resource_types_path_au after update on resource_types for each row when (old.path is distinct from new.path) execute procedure types_path_au('controls', 'resource_type_id', 'resource_type_path'); @@ -204,7 +214,7 @@ SELECT n.nspname AS schema_name, COUNT(c.conname) AS constraint_count FROM pg_ca SELECT count(tgname), tgenabled FROM pg_trigger GROUP by tgenabled; ``` -## Step 14: Turn Off Events (Optional) +## Step 14: Turn Off Events Disable events as per the guidelines: [Pause Events](https://turbot.com/guardrails/docs/guides/hosting-guardrails/troubleshooting/pause-events). @@ -213,6 +223,16 @@ Disable events as per the guidelines: [Pause Events](https://turbot.com/guardrai - Rename the primary instance by appending -green. - Rename the new instance by removing the -blue suffix. +## Step 16: Disable and delete subscription + +- Delete subscription and replication slots +```sql +SELECT subname AS "Subscription Name", subowner AS "Owner ID", subenabled AS "Is Enabled", subpublications AS "Publications" FROM pg_subscription; +alter subscription disable; +alter subscription set (slot_name=NONE); +drop subscription ; +``` + ## Step 16: Turn On Events Refer to the documentation: [Turn On Events](https://turbot.com/guardrails/docs/guides/hosting-guardrails/troubleshooting/pause-events). From af46101b5f091491daafc5069d79f5d78b92acc1 Mon Sep 17 00:00:00 2001 From: raj Date: Tue, 26 Nov 2024 12:39:07 +0530 Subject: [PATCH 2/2] Updates --- .../index.md | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/docs/guides/hosting-guardrails/disaster-recovery/database-upgrade-storage-optimization/index.md b/docs/guides/hosting-guardrails/disaster-recovery/database-upgrade-storage-optimization/index.md index aae1ebd9..166d738a 100644 --- a/docs/guides/hosting-guardrails/disaster-recovery/database-upgrade-storage-optimization/index.md +++ b/docs/guides/hosting-guardrails/disaster-recovery/database-upgrade-storage-optimization/index.md @@ -5,14 +5,15 @@ sidebar_label: "Database Upgrade and Storage Optimization" # Database Upgrade and Storage Optimization -In this guide, you will +In this guide, you will: - Resize and/or upgrade a database engine version with minimal downtime using AWS and PostgreSQL tools. +- Monitor and troubleshoot the upgrade process. -Efficient management of database resources ensures optimal storage utilization, minimizes costs, and enhances performance by reducing unused storage. This process also ensures seamless version upgrades with minimal disruption. +[Turbot Guardrails Enterprise Database (TED)](/guardrails/docs/reference/glossary#turbot-guardrails-enterprise-database-ted) is an AWS Service Catalog product that provides automated configuration and management of the infrastructure needed to run the enterprise version of Turbot Guardrails in your AWS account. Efficient management of database resources ensures optimal storage utilization, minimizes costs, and enhances performance by reducing unused storage. This process also ensures seamless version upgrades with minimal disruption. ## Prerequisites @@ -20,26 +21,26 @@ Efficient management of database resources ensures optimal storage utilization, - PostgreSQL client installed on the [bastion host](https://github.com/turbot/guardrails-samples/tree/main/enterprise_installation/turbot_bastion_host). - Ensure logical replication is supported and enabled on the database engine. - Knowledge of the current database usage (storage and version). -- TED stack version is atleast 1.45.0. +- TED stack version is at-least 1.45.0. -## Warnings - -1. After creating replication slots (steps #7 below), we won't be able to upgrade any existing workspaces or create a new one till the end of the process. Basically, no DDL changes. +> [!WARNING] +> After creating replication slots (steps #7 below), we won't be able to upgrade any existing workspaces or create a new one till the end of the process. Basically, no DDL changes. ## Step 1: Spin up a new TED - Create a new [TED](/guardrails/docs/reference/glossary#turbot-guardrails-enterprise-database-ted) with the same name as the original, appending `-blue` or `-green` to the end. -- If performing a database version upgrade, use the `DB Engine Version` and `Read Replica DB Engine Version` parameters under the "Database - Advanced - Engine" section. Set the appropriate `DB Engine Parameter Group Family` and the `Hive RDS Parameter Group` under the "Database - Advanced - Parameters" section. +- If performing a database version upgrade, use the `DB Engine Version` and `Read Replica DB Engine Version` parameters under the `Database - Advanced - Engine` section. Set the appropriate `DB Engine Parameter Group Family` and the `Hive RDS Parameter Group` under the `Database - Advanced - Parameters` section. - Set the allocated storage to match the current disk usage using the `Allocated Storage in GB` parameter under the "Database - Advanced - Storage" section. For example - if 210 GB out of 500 GB is used, set allocated storage to 210 GB. Check the `FreeStorageSpace` metrics to get the size. - Set the maximum allocated storage to a suitable value using the `Maximum Allocated Storage limit in GB` parameter under the "Database - Advanced - Storage" section. -- Set up encryption by configuring the `Custom Hive Key` parameter to use the original KMS key under the "Advanced - Infrastructure" section. This should be the Key ID, typically formatted as: 1111233-abcd-4444-2322-123456789012. +- Set up encryption by configuring the `Custom Hive Key` parameter to use the original KMS key under the `Advanced - Infrastructure` section. This should be the Key ID, typically formatted as: `1111233-abcd-4444-2322-123456789012`. - Keep the other parameters the same. ## Step 2: Enable Logical Replication - Go to the AWS Console and navigate to the relevant parameter group. - Set `rds.logical_replical` to **`1`** if it’s not already set. -- Turn off events - https://turbot.com/guardrails/docs/enterprise/FAQ/pause-events -- Reboot the DB instance (expected downtime is ~50 seconds). +- Turn off events - refer [here](https://turbot.com/guardrails/docs/enterprise/FAQ/pause-events) for more details. +- **Reboot** the DB instance (expected downtime is ~50 seconds). ## Step 3: Set Master Password