---
title: "Navigating PostgreSQL Locks with Neon and Atlas"
description: "Adding a UNIQUE constraint or setting a column NOT NULL in Postgres triggers a full table scan under an ACCESS EXCLUSIVE lock, which blocks all reads and writes and can take down an API on large tables."
url: "https://swe.quest/articles/navigating-postgresql-locks-with-neon-and-atlas-61f1baeebb69a86a"
canonical: "https://neon.com/blog/postgres-locks-neon-atlas"
source: "Neon"
published: "2025-03-14"
difficulty: "medium"
kind: "How-to"
reading_minutes: 11
tags: ["schema-migrations","postgres","ci-cd","static-analysis"]
---

# Navigating PostgreSQL Locks with Neon and Atlas

A post on [Neon](https://swe.quest/sources/neon.md), published 2025-03-14, 11 min read, How-to. Original: [https://neon.com/blog/postgres-locks-neon-atlas](https://neon.com/blog/postgres-locks-neon-atlas)

## Summary

Adding a UNIQUE constraint or setting a column NOT NULL in Postgres triggers a full table scan under an ACCESS EXCLUSIVE lock, which blocks all reads and writes and can take down an API on large tables. The safer sequences are CREATE UNIQUE INDEX CONCURRENTLY followed by ADD UNIQUE USING INDEX, and a NOT VALID CHECK constraint followed by VALIDATE before SET NOT NULL. To catch such migrations automatically, a GitHub Actions pipeline runs Atlas's migrate lint (check PG105) on pull requests. It then applies the migration to a Neon branch cloned from production, with a 10s statement\_timeout hook, so long-locking migrations fail the build before deployment.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [Schema migrations](https://swe.quest/tags/schema-migrations.md) (Data & databases)
- [PostgreSQL](https://swe.quest/tags/postgres.md) (Data & databases)
- [CI/CD](https://swe.quest/tags/ci-cd.md) (Reliability & operations)
- [Static analysis](https://swe.quest/tags/static-analysis.md) (Engineering practices)

## Prerequisites

- PostgreSQL DDL ([easy posts on PostgreSQL](https://swe.quest/tags/postgres.md?difficulty=easy))
- GitHub Actions ([easy posts on CI/CD](https://swe.quest/tags/ci-cd.md?difficulty=easy))
- database schema migrations ([easy posts on Databases](https://swe.quest/tags/databases.md?difficulty=easy))

## Keywords

PostgreSQL, Neon, Atlas, ACCESS EXCLUSIVE lock, CREATE INDEX CONCURRENTLY, GitHub Actions, statement\_timeout

## Related posts

- [Incident Report: October 28th, 2025](https://swe.quest/articles/incident-report-october-28th-2025-842ec59ef90dc7e9.md): Railway · 2025-10-28 · Medium · 2 min read · PostgreSQL, Schema migrations, Incidents & postmortems, Databases
  A schema migration that added an indexed column to a ~1 billion-row Postgres table without \`CREATE INDEX CONCURRENTLY\` took an exclusive table lock, queuing nearly all backend API queries and taking down Railway's dashboard, CLI, Public API and GitHub webhook deploys for about 40 minutes.
- [Safely Adding NOT NULL Columns to Your Database Tables](https://swe.quest/articles/safely-adding-not-null-columns-to-your-database-tables-0c4b04a1141f0507.md): Shopify Engineering · 2022-10-04 · Medium · 7 min read · Schema migrations, MySQL, Databases
  Adding a NOT NULL column through LHM's shadow-table migration (new table, replication triggers, batched copy, rename) can break writes or silently lose data depending on the DEFAULT clause, an added UNIQUE INDEX and the MySQL SQL mode.
- [LLM Rules for Postgres](https://swe.quest/articles/llm-rules-for-postgres-ad82e8ad652f6e5a.md): Neon · 2025-08-29 · Medium · 4 min read · PostgreSQL, Code review, Schema migrations, AI for coding, LLMs
  Six explicit Postgres rules, drawn from building the wispbit review bot, let an LLM code reviewer or coding agent catch common migration and query mistakes before production.
- [I don't trust ON DELETE CASCADE](https://swe.quest/articles/i-don-t-trust-on-delete-cascade-44280f7ae72c78f6.md): PlanetScale · 2026-10-21 · Medium · 5 min read · PostgreSQL, Schema migrations, Replication, Databases
  Postgres ON DELETE CASCADE turns a single-row delete into an unbounded transaction that can cause outages at scale.
- [PostgreSQL 15: Three features you can try with Neon](https://swe.quest/articles/postgresql-15-three-features-you-can-try-with-neon-d9568102bec3b3d5.md): Neon · 2022-10-26 · Medium · 3 min read · PostgreSQL, SQL
  Neon now supports PostgreSQL 15, and three of its features can be tried from Neon's SQL Editor with runnable examples.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
