AI & Agent Dev Bug Sandbox logo
AI & Agent Dev Bug Sandbox
Back to Radar

PostgREST Schema Cache Permanently Corrupted After DROP + CREATE FUNCTION — NOTIFY Reload Has No Effect

After dropping and recreating a PostgreSQL function, PostgREST returns error 42725 (ambiguous function) on all RPC calls, even for newly created functions. Neither NOTIFY pgrst, 'reload schema' nor a full project restart clears the corrupted cache.

highConfidence 70%PostgREST

Origin Analysis

PostgREST's schema cache invalidation fails to remove stale function entries after DROP/CREATE, leading to duplicate function signatures in the cache. Subsequent reload attempts are ignored due to a race condition where reload notifications are dropped while a reload is already in progress, leaving the cache permanently corrupted.
1. Create a function with RETURNS SETOF "tablename". 2. DROP the function and recreate it with the same signature (required when changing return type). 3. Call POST /rest/v1/rpc/<function_name>. 4. Observe error 42725 from PostgREST. 5. Run NOTIFY pgrst, 'reload schema' — no effect. 6. Restart project via dashboard — no effect. 7. Create a brand new function with a different name and same signature — still 42725.

Fixing Code Block

Edge Case Audit

Terminating connections will cause a brief interruption to all RPC and REST requests served by PostgREST. This hotfix addresses the symptom but does not fix the underlying cache invalidation bug; if the corruption recurs after future DROP/CREATE operations, the same workaround must be repeated. Rollback: simply allow PostgREST to reconnect automatically; no manual rollback is required. For a permanent fix, upgrade to a PostgREST version where reload notifications are queued and stale function entries are properly purged.

Ecosystem Topology