# Disable Constraints

> [!NOTE]
> If you are migrating data and before deciding on the fully manual approach using `aiven_extras` consider checking if 
> [logical replication](https://aiven.io/docs/products/postgresql/howto/setup-logical-replication) suits better your 
> use case. The approach outlined below is done automatically via logical replication.


Access to [super-user functionality](https://docs.aiven.io/docs/products/postgresql/concepts/dba-tasks-pg) 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](https://github.com/aiven/aiven-extras) plugin.

Step 1: In the database shell install the `aiven_extras` extension with 

```sql
CREATE EXTENSION aiven_extras CASCADE;
```

Step 2: Disable constraints with:

```sql
SELECT aiven_extras.session_replication_role('replica');
```

Step 3: Import your data or another task that requires disabled constraints

Step 4: Re-enable triggers

```sql
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.
