Check Your Postgres search_path: A Rollback Can Undo It
An outage investigated like an EHS incident: four steps, root causes, CAPA.
On December 3, 2026, WindsockEHS had a short outage: signed-in pages failed with relation "plants" does not exist, while the sign-in page and the container health check kept saying everything was fine. The table was there the whole time.
A software outage is an incident like any other, so this one is investigated the way an EHS incident should be: with the four steps in OSHA's Incident Investigations: A Guide for Employers, aimed at root causes and corrective actions, not blame. If your project uses a Postgres schema other than public and sets search_path on connect, the last section shows how to check it today.
Incident summary
| Item | Detail |
|---|---|
| Date | December 3, 2026 (evening, Central Time) |
| Type | Service outage, software defect |
| Impact | Signed-in pages returned an error page or opened blank. The sign-in page still worked. |
| Injuries or data loss | None |
| Detected by | A person testing the live site, at 7:31 PM |
| Restored | Within minutes, by restarting the app container |
| Permanent fix | Merged the same evening, live on the next release |
Step 1: Preserve and document the scene
The site had to be made safe first, the same way emergency response comes before an investigation. Before the restart cleared the evidence, the facts were recorded:
- The error and its reference number from the error page.
- The server state: the host up 8 days, the app container up 3 hours and reporting healthy.
- The app log, which showed
relation "plants" does not existfrom a background job. - Confirmation that the database, its tables and the data were intact.
Then the app container was restarted, which threw away every bad connection and restored the site.
Step 2: Collect information
Timeline (Central Time)
| Time | Event |
|---|---|
| ~4:30 PM | A routine deploy starts the app with a fresh database connection pool |
| 7:31 PM | Site reported offline while testing |
| 7:33 PM | Server checked: host and container healthy, the app log shows the missing-table error |
| 7:37 PM | Fault reproduced on a test machine: the schema setting is gone after a rollback |
| ~7:40 PM | Fix and regression test opened for review; root cause analysis started |
| Same evening | App container restarted, site restored; fix merged |
Records reviewed: the app log, the error report, the connection setup code, the database driver's transaction rules, and the test suite's setup.
The connection setup in place at the time:
@event.listens_for(engine, "connect")
def set_search_path(dbapi_connection, record):
cursor = dbapi_connection.cursor()
cursor.execute("SET search_path TO app")
cursor.close()
Step 3: Determine root causes (5 Whys)
Problem statement: signed-in pages could not find the plants table, although it existed.
- Why did pages fail? Queries could not find the
plantstable. - Why not? The connection was looking in the default schemas (
"$user", public) instead ofapp, where all tables live. - Why was the schema wrong? The app set it once, when each new pooled connection opened, with the plain
SETabove. With autocommit off, which is the default for psycopg 3 and psycopg2, the driver opens a transaction for the first statement, so theSETran inside a transaction that nobody had committed yet. - Why did that not stick? In Postgres, a
SETmade inside a transaction is undone if that transaction rolls back. The pool rolls back whenever a connection is handed back, and a page that only reads data never commits. So when a brand new connection's first job ended in a rollback, its schema setting went with it, until the app restarted. - Why was it not caught before release? The test suite ran on SQLite, which has no schemas, so nothing ever exercised a rollback on a fresh Postgres connection.
Root cause: the schema was set with a plain SET inside a transaction that could be rolled back, instead of as a connection default.
Contributing factors
- It was intermittent. Only connections whose first use rolled back were affected. Opening many pages quickly makes the pool open new connections, so the fault showed up during fast testing and then stayed.
- The health check passed. The health check and the sign-in page did not touch the database, so the container reported healthy while every signed-in page failed.
- The error page sent people to the public home page, which made the outage look wider than it was.
- Error reports were email only. There was no list of recent errors to look up, so the details had to be pulled from the server by hand.
Step 4: Implement corrective actions (CAPA)
Corrective actions
Corrective actions fix this incident's root cause.
| # | Action | Status |
|---|---|---|
| 1 | Pass the schema as a connection startup option, which a rollback or pool reset cannot undo | Done, live |
| 2 | Commit right after the old SET, as a second guard | Done, live |
| 3 | Regression test that the Postgres engine carries the startup option | Done |
| 4 | The error page's link goes to the workspace Home, not the public home page | Done, live |
Preventive actions
Preventive actions address the contributing factors, so this kind of fault is caught sooner next time.
| # | Action | Status |
|---|---|---|
| 1 | A health check that runs a real query in the app schema, so this kind of fault shows as unhealthy | Open |
| 2 | A CI test on a real Postgres connection that rolls back and confirms the schema is still set | Open |
| 3 | Mark error emails URGENT when the same error repeats within a few minutes | Open |
| 4 | A list of recent error reports for support, so an error reference can be looked up without the server | Open |
Verification of effectiveness
- On a test machine,
search_pathnow staysappafter a rollback. - The fix is live, and the pages that failed during the outage are checked again on the live site before this incident is closed.
- Each preventive action is closed only once it is live and tested.
Lessons learned: check your project
Who should check
You are likely affected if all of these are true:
- Your tables live in a named Postgres schema, such as
app, not inpublic. - The app sets that schema with
SET search_path TO ...when each connection opens, for example in a SQLAlchemyconnectevent. - The database driver does not run in autocommit mode. That is the default for psycopg 3 and psycopg2.
- The app uses a connection pool, which nearly every web app does.
How to check
Open a connection the way your app does, roll back, and look at the setting again:
from sqlalchemy import text
with engine.connect() as conn:
print(conn.execute(text("SHOW search_path")).scalar()) # app
conn.rollback()
print(conn.execute(text("SHOW search_path")).scalar()) # still app?
If the second line prints "$user", public, your project has the same fault.
The fix
Pass the schema as a startup option, so it becomes the connection's default instead of a change made inside a transaction:
engine = create_engine(
database_url,
pool_pre_ping=True,
connect_args={"options": "-csearch_path=app"},
)
If you keep a SET in the connect event, commit right after it, or turn on autocommit for that one statement as the SQLAlchemy PostgreSQL documentation shows. A database role default (ALTER ROLE ... SET search_path) also works, but it lives outside your code, where a new server or restored backup can lose it.