Skip to content

Commit ba72318

Browse files
Update tutorial-azure-postgresql-to-azure-postgresql-online-portal.md
Removed the script for handling foreign keys and triggers. DMS handles it automatically for all PG platforms.
1 parent ced55e6 commit ba72318

File tree

1 file changed

+3
-54
lines changed

1 file changed

+3
-54
lines changed

articles/dms/tutorial-azure-postgresql-to-azure-postgresql-online-portal.md

Lines changed: 3 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -100,60 +100,9 @@ To complete all the database objects like table schemas, indexes and stored proc
100100
```
101101
psql -h mypgserver-source.postgres.database.azure.com -U pguser@mypgserver-source -d dvdrental citus < dvdrentalSchema.sql
102102
```
103-
104-
4. To extract the drop foreign key script and add it at the destination (Azure Database for PostgreSQL), in PgAdmin or in psql, run the following script.
105-
106-
> [!IMPORTANT]
107-
> Foreign keys in your schema will cause the initial load and continuous sync of the migration to fail.
108-
109-
```
110-
SELECT Q.table_name
111-
,CONCAT('ALTER TABLE ','"', table_schema,'"', '.','"', table_name ,'"', STRING_AGG(DISTINCT CONCAT(' DROP CONSTRAINT ','"', foreignkey,'"'), ','), ';') as DropQuery
112-
,CONCAT('ALTER TABLE ','"', table_schema,'"', '.','"', table_name,'"', STRING_AGG(DISTINCT CONCAT(' ADD CONSTRAINT ','"', foreignkey,'"', ' FOREIGN KEY (','"', column_name,'"', ')', ' REFERENCES ','"', foreign_table_schema,'"', '.','"', foreign_table_name,'"', '(','"', foreign_column_name,'"', ')',' ON UPDATE ',update_rule,' ON DELETE ',delete_rule), ','), ';') as AddQuery
113-
FROM
114-
(SELECT
115-
S.table_schema,
116-
S.foreignkey,
117-
S.table_name,
118-
STRING_AGG(DISTINCT S.column_name, ',') AS column_name,
119-
S.foreign_table_schema,
120-
S.foreign_table_name,
121-
STRING_AGG(DISTINCT S.foreign_column_name, ',') AS foreign_column_name,
122-
S.update_rule,
123-
S.delete_rule
124-
FROM
125-
(SELECT DISTINCT
126-
tc.table_schema,
127-
tc.constraint_name AS foreignkey,
128-
tc.table_name,
129-
kcu.column_name,
130-
ccu.table_schema AS foreign_table_schema,
131-
ccu.table_name AS foreign_table_name,
132-
ccu.column_name AS foreign_column_name,
133-
rc.update_rule AS update_rule,
134-
rc.delete_rule AS delete_rule
135-
FROM information_schema.table_constraints AS tc
136-
JOIN information_schema.key_column_usage AS kcu ON tc.constraint_name = kcu.constraint_name AND tc.table_schema = kcu.table_schema
137-
JOIN information_schema.constraint_column_usage AS ccu ON ccu.constraint_name = tc.constraint_name AND ccu.table_schema = tc.table_schema
138-
JOIN information_schema.referential_constraints as rc ON rc.constraint_name = tc.constraint_name AND rc.constraint_schema = tc.table_schema
139-
WHERE constraint_type = 'FOREIGN KEY'
140-
) S
141-
GROUP BY S.table_schema, S.foreignkey, S.table_name, S.foreign_table_schema, S.foreign_table_name,S.update_rule,S.delete_rule
142-
) Q
143-
GROUP BY Q.table_schema, Q.table_name;
144-
```
145-
146-
5. Run the drop foreign key (which is the second column) in the query result.
147-
148-
6. To disable triggers in target database, run the script below.
149-
150-
> [!IMPORTANT]
151-
> Triggers (insert or update) in the data enforce data integrity in the target ahead of the data being replicated from the source. As a result, it's recommended that you disable triggers in all the tables **at the target** during migration, and then re-enable the triggers after migration is complete.
152-
153-
```
154-
SELECT DISTINCT CONCAT('ALTER TABLE ', event_object_schema, '.', event_object_table, ' DISABLE TRIGGER ', trigger_name, ';')
155-
FROM information_schema.triggers
156-
```
103+
104+
> [!NOTE]
105+
> The migration service internally handles the enable/disable of foreign keys and triggers to ensure a reliable and robust data migration. As a result, you do not have to worry about making any modifications to the target database schema.
157106
158107
[!INCLUDE [resource-provider-register](../../includes/database-migration-service-resource-provider-register.md)]
159108

0 commit comments

Comments
 (0)