Disabling Constraints
NOTE
If you are migrating data and before deciding on the fully manual approach usingaiven_extras
consider checking if logical replication suits better your use case. The approach outlined below is done automatically via logical replication.
Access to super-user functionality is restricted in order to have a clear demarcation line for service availability. Disabling triggers is one of them.
Fortunately an alternative is available using aiven_extras plugin.
Step 1: In the database shell install the aiven_extras
extension with
CREATE EXTENSION aiven_extras CASCADE;
Step 2: Disable constraints with:
SELECT aiven_extras.session_replication_role('replica');
Step 3: Import your data or another task that requires disabled constraints
Step 4: Re-enable triggers
SELECT aiven_extras.session_replication_role('origin');
Keep in mind that as all constraints get disabled there’s a risk of creating orphaned records or inconsistent data.
Changes made without constraints can affect other transactions in progress, leading to data anomalies, so ideally should be done when users don’t insert data into the database.
Re-enabling constraints might trigger a check of all rows, which can be resource-intensive for large tables.