Problem
When creating a PostgreSQL database with the AGE extension, the default search_path is set to:
ag_catalog, "$user", public
This causes issues with Alembic migrations because:
- Alembic creates its
alembic_version table during migrations
- With
ag_catalog first in the search path, the table is created in the ag_catalog schema instead of public
- Subsequent migration operations fail because they look for
alembic_version in the wrong schema
Error Observed
relation "alembic_version" does not exist
[SQL: INSERT INTO alembic_version (version_num) VALUES ('000000000000')]
The table exists but in ag_catalog schema, not public.
Current Workaround
In ThinIce, we added a workaround in alembic/env.py:
# CRITICAL: Reset search_path to public BEFORE configuring context.
# AGE extension may modify the default search_path, putting ag_catalog
# before public. This causes Alembic's alembic_version table to be
# created in the wrong schema.
connection.execute(text("SET search_path TO public"))
Suggested Fix
When creating databases that will use AGE, the search_path should be set to have public first:
ALTER DATABASE dbname SET search_path TO public, ag_catalog, "$user";
Or ensure the database creation script sets an appropriate default search_path.
Reference
Problem
When creating a PostgreSQL database with the AGE extension, the default
search_pathis set to:This causes issues with Alembic migrations because:
alembic_versiontable during migrationsag_catalogfirst in the search path, the table is created in theag_catalogschema instead ofpublicalembic_versionin the wrong schemaError Observed
The table exists but in
ag_catalogschema, notpublic.Current Workaround
In ThinIce, we added a workaround in
alembic/env.py:Suggested Fix
When creating databases that will use AGE, the
search_pathshould be set to havepublicfirst:Or ensure the database creation script sets an appropriate default search_path.
Reference