Every now and then, a PostgreSQL database needs changes: adding a column, creating an index, updating data, or modifying constraints. Changes like these are called migrations. They can finish in seconds and go unnoticed, or lead to blocking, replication lag, unexpected load, or even downtime.

Of course, no checklist can guarantee a trouble-free migration. However, asking the right questions beforehand can significantly reduce the risk.

In this article, we’ll go through a checklist that can help prepare for PostgreSQL migrations more confidently:

  • What will PostgreSQL actually do?
  • Which lock will it take?
  • Is the database ready?
  • Will replication be affected?
  • Can the migration be made safer?
  • What if something goes wrong?
  • What should be monitored while it runs?
  • What should I verify afterwards?

1. What will PostgreSQL actually do?

A statement can look simple, but its execution cost can vary significantly depending on the operation, table size, indexes and existing data.

Will it rewrite the table?

A table rewrite means PostgreSQL creates a new physical copy of the table.
On large tables this can be expensive, because every row has to be rewritten, which in turn may generate a significant amount of WAL. Indexes are rebuilt as well, and the table is locked against both reads and writes while the rewrite runs.

For example, changing a column’s data type or adding a column with a volatile DEFAULT, may rewrite the table.

Will it scan the table?

Some operations do not rewrite the table but still need to read all existing rows. For example, constraint validation.

A full table scan may consume significant system resources and take a long time on large tables. Whether it also blocks concurrent activity depends on the specific statement.

Could excessive WAL generation become a problem?

Large updates, deletes, table rewrites, and index creation can generate a significant amount of WAL. As a result, you may observe increased I/O, growing disk usage, or replication lag during the migration.

Understanding this helps distinguish expected migration behaviour from an actual production issue.


2. Which lock will it take?

Will it block reads or writes?

Check the PostgreSQL documentation to understand which lock level your migration requires and what it conflicts with. Different statements acquire different lock modes. Some of them block reads, writes, or both.

Could it create a lock queue?

Check whether other transactions are likely to hold locks that conflict with the migration.

If a migration cannot acquire the required lock because another transaction already holds an incompatible lock, the migration will wait. Later transactions that would normally proceed will end up waiting behind it, creating a lock queue. This is how a waiting DDL statement can affect application traffic.

Should timeouts be used?

Consider setting lock_timeout to avoid waiting indefinitely for a lock and statement_timeout to prevent unacceptably long-running migrations.


3. Is the database ready?

Are there long-running transactions?

Check for long-running transactions before starting the migration. If any are found, verify that they will not conflict with the migration by holding incompatible locks or significantly increasing migration’s impact.

Is maintenance already running or scheduled to start?

Check whether maintenance tasks, backups, or other resource-intensive operations are already running or scheduled to start. Even if they do not conflict with the migration, they may compete for CPU, I/O, memory, and other resources, increasing execution time.

Remember to coordinate the migration with your team to avoid unexpected overlap.

Are there enough available resources?

Verify that the system has enough free disk space and sufficient I/O and CPU capacity for the migration. Large migrations may temporarily increase resource usage well beyond normal workload.

How large is the affected table?

Check the size of the affected table before estimating the migration time or choosing a migration strategy. Operations that complete in seconds on a small table may take hours on a bigger one.


4. Will replication be affected?

Is the table part of logical replication?

Verify whether the table is replicated using logical replication. If so, ensure that the planned schema changes are compatible with downstream consumers.

Operations such as dropping or renaming columns, or changing data types, may require coordinated changes outside PostgreSQL beforehand.

Is replication lag acceptable?

Large updates, deletes, and table rewrites may temporarily increase replication lag. If your application or downstream systems depend on up-to-date data, monitor replication lag during the migration and make sure colleagues are aware of the expected lag if it may affect their work.


5. Can the migration be made safer?

Before executing the planned migration, consider whether the same goal can be achieved using a safer migration strategy.

Many migrations do not have to be completed in a single step. You can reduce risk, minimise blocking, and make the migration easier to monitor and recover from by breaking it into smaller steps.


6. What if something goes wrong?

Was it tested on production-like data?

Whenever possible, test the migration on a realistic dataset. This helps confirm that it behaves as expected, uncover potential issues, and provide a more realistic estimate of its execution time and overall impact.

Do I have a rollback plan?

Decide what to do if it does not go as planned. Consider whether the changes can be rolled back, whether the migration can be safely stopped, and how the application will recover.


7. What should be monitored while it runs?

Pay particular attention to:

  • long-running or blocked queries;
  • replication lag;
  • CPU, I/O, memory, and disk usage;
  • errors and warnings in PostgreSQL logs.

When supported by the operation, also monitor its progress.


8. What should I verify afterwards?

Depending on the migration, this may include:

  • confirming that performance has not degraded;
  • running ANALYZE if planner statistics are no longer representative;
  • checking for table or index bloat after large data modifications;
  • confirming that replication has caught up;
  • reviewing PostgreSQL logs for errors and warnings.

With that in mind, although every migration is different, the questions worth asking are often the same.

You can adapt this checklist to your own environment, workload, and operational requirements, so going through it before each production migration can make changes more predictable and significantly reduce risk.

If you would like to go deeper, we cover lock-aware schema changes, batched data updates, migration testing, rollback plans and monitoring, with practical examples, in our session Best Practices for DDL/DML Migration, part of our PostgreSQL developer course series.

The post PostgreSQL DDL/DML Migration Checklist for the Anxious appeared first on Data Egret.