Project: YugabyteDB (App Definition and Development / Database)
File: disaster-recovery-tables.md

title: Manage tables and indexes for disaster recovery headerTitle: Manage tables and indexes linkTitle: Tables and indexes description: Manage tables and indexes in universes with disaster recovery headContent: Add and remove tables and indexes in universes with disaster recovery menu: stable_yugabyte-platform: parent: disaster-recovery identifier: disaster-recovery-tables weight: 50 type: docs When DDL changes are made to databases in replication for xCluster disaster recovery (DR) (such as creating, altering, or dropping tables or partitions), the changes must be: performed at the SQL level on both the DR primary and replica, and then updated at the YBA level in the DR configuration. You should perform these actions in a specific order, depending on whether performing a CREATE, DROP, ALTER, and so forth, as indicated by the sequence number of the operation in the table below. | DB Change&nbsp;on&nbsp;DR&nbsp;primary | On DR replica | In YBA | | :-- | :-- | : | | 1. CREATE TABLE | 2. CREATE TABLE | 3. Add the table to replication | | 2. DROP TABLE | 3. DROP TABLE | 1. Remove the table from replication. | | 1. CREATE INDEX | 2. CREATE INDEX | 3. | | 2. DROP INDEX | 1. DROP INDEX | 3. | | 1. CREATE TABLE foo PARTITION OF bar | 2. CREATE TABLE foo PARTITION OF bar | 3. Add the table to replication | | 2. ALTER TABLE or INDEX | 1. ALTER TABLE or INDEX | No changes needed | In addition, keep in mind the following: If you are using Colocated tables, you CREATE TABLE on DR primary, then CREATE TABLE on DR replica making sure that you force the Colocation ID to be identical to that on DR primary. If you try to make a DDL change on DR primary and it fails, you must also make the same attempt on DR replica and get the same failure. Use the following guidance when managing tables and indexes in universes with DR configured. If you are performing application upgrades involving both adding and dropping tables, perform the upgrade in two parts: first add tables, then drop tables. To ensure that data is protected at all times, set up DR on a new table before starting any workload. If a table already has data before adding it to DR, then adding the table to replication can result in a backup and restore of the entire database from DR primary to replica. Add tables to DR in the following sequence: Create the table on the DR primary (if it doesn't already exist). Create the table on the DR replica. Navigate to your DR primary and select xCluster Disaster Recovery. Click Actions and choose Select Databases and Tables. Select the tables and click Validate Selection. If data needs to be copied, click Next: Confirm Full Copy. Click Apply

Note the following: If the newly added table already has data, then adding the table can trigger a full copy of that entire database from DR primary to replica. It is recommended that you set up replication on the new table before starting any workload to ensure that data is protected at all times. This approach also avoids the full copy. This operation also automatically adds any associated index tables of this table to the DR configuration. If using colocation, colocated tables on the DR primary and replica should be created with the same colocation ID if they already exist on both the DR primary and replica prior to DR setup. When dropping a table, remove the table from DR before dropping the table in the DR primary and replica databases. Remove tables from DR in the following sequence: Navigate to your DR primary and select xCluster Disaster Recovery. Click Actions and choose Select Databases and Tables. Deselect the tables and click Validate Selection. Click Next: Confirm Full Copy. Click Apply Changes. Drop the table from both DR primary and replica databases separately. Indexes are automatically added to replication in an atomic fashion after you create the indexes separately on DR primary and replica. You don't need to stop the writes on the DR primary. CREATE INDEX may kill some in-flight transactions. This is a temporary error. Retry any failed transactions. Add indexes to replication in the following sequence: Create an index on the DR primary. Wait for index backfill to finish. Create the same index on the DR replica. Wait for index backfill to finish. For instructions on monitoring backfill, refer to . . When an index is dropped it is automatically removed from DR. Remove indexes from replication in the following sequence: Drop the index on the DR replica. Drop the index on the DR primary. . Adding a table partition is similar to adding a table. The caveat is that the parent table (if not already) along with each new partition has to be added to DR, as DDL changes are not replicated automatically. Each partition is treated as a separate table and is added to DR separately (like a table). For example, you can create a table with partitions as follows: ```sql CREATE TABLE order_changes ( order_id int, change_date date, type text, description text) PARTITION BY RANGE (change_date); ``` ```sql CREATE TABLE orderchangesdefault PARTITION OF order_changes DEFAULT; ``` Create a new partition: ```sql CREATE TABLE orderchanges202301 PARTITION OF orderchanges FOR VALUES FROM ('2023-01-01') TO ('2023-03-30'); ``` Assume the parent table and default partition are included in the replication stream. To add a table partition to DR, follow the same steps for . To remove a table partition from DR, follow the same steps as . To ensure changes made outside of YugabyteDB Anywhere are reflected in YBA, resynchronize the YBA UI as follows: Navigate to your DR primary and select xCluster Disaster Recovery. Click Actions > Advanced and choose Reconcile Config with Database.