Kelly Michels 6 min read DevOps

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

ItemDetail
DateDecember 3, 2026 (evening, Central Time)
TypeService outage, software defect
ImpactSigned-in pages returned an error page or opened blank. The sign-in page still worked.
Injuries or data lossNone
Detected byA person testing the live site, at 7:31 PM
RestoredWithin minutes, by restarting the app container
Permanent fixMerged 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 exist from 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)

TimeEvent
~4:30 PMA routine deploy starts the app with a fresh database connection pool
7:31 PMSite reported offline while testing
7:33 PMServer checked: host and container healthy, the app log shows the missing-table error
7:37 PMFault reproduced on a test machine: the schema setting is gone after a rollback
~7:40 PMFix and regression test opened for review; root cause analysis started
Same eveningApp 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.

  1. Why did pages fail? Queries could not find the plants table.
  2. Why not? The connection was looking in the default schemas ("$user", public) instead of app, where all tables live.
  3. Why was the schema wrong? The app set it once, when each new pooled connection opened, with the plain SET above. With autocommit off, which is the default for psycopg 3 and psycopg2, the driver opens a transaction for the first statement, so the SET ran inside a transaction that nobody had committed yet.
  4. Why did that not stick? In Postgres, a SET made 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.
  5. 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.

#ActionStatus
1Pass the schema as a connection startup option, which a rollback or pool reset cannot undoDone, live
2Commit right after the old SET, as a second guardDone, live
3Regression test that the Postgres engine carries the startup optionDone
4The error page's link goes to the workspace Home, not the public home pageDone, live

Preventive actions

Preventive actions address the contributing factors, so this kind of fault is caught sooner next time.

#ActionStatus
1A health check that runs a real query in the app schema, so this kind of fault shows as unhealthyOpen
2A CI test on a real Postgres connection that rolls back and confirms the schema is still setOpen
3Mark error emails URGENT when the same error repeats within a few minutesOpen
4A list of recent error reports for support, so an error reference can be looked up without the serverOpen

Verification of effectiveness

  • On a test machine, search_path now stays app after 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 in public.
  • The app sets that schema with SET search_path TO ... when each connection opens, for example in a SQLAlchemy connect event.
  • 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.

This incident was in WindsockEHS, which tracks incidents, root causes and CAPA for EHS teams the same way. Also on the WindsockEHS blog. Questions? Get in touch. ← Back to Blog