Piotr
07/09/2025, 12:03 PMMarvin
07/09/2025, 12:03 PMMarvin
07/09/2025, 12:04 PMyaml
server:
extraPipPackages:
- "psycopg2-binary"
2. Build a custom image (Alternative approach):
Create a Dockerfile:
dockerfile
FROM prefecthq/prefect:3-python3.11
RUN pip install psycopg2-binary
The first approach using extraPipPackages
is simpler and doesn't require maintaining a custom image.
After making this change, redeploy your Helm chart:
bash
helm upgrade prefect prefecthq/prefect -f values.yaml
A few additional notes:
- Use psycopg2-binary
instead of psycopg2
to avoid requiring additional system-level dependencies
- Make sure your PostgreSQL instance has the pg_trgm
extension enabled
- Verify your connection string is properly formatted as: <postgresql://user:password@host:port/dbname>
If you continue to experience issues after implementing these changes, please check the server logs for any additional error messages.Piotr
07/09/2025, 12:10 PMMarvin
07/09/2025, 12:10 PMMarvin
07/09/2025, 12:10 PMpsycopg2
dependency should indeed be included by default when PostgreSQL is configured, as it's a core requirement for PostgreSQL functionality. The fact that it isn't is a bug.
For now, you'll need to use the workaround I mentioned earlier (adding psycopg2-binary
via extraPipPackages
), but I'd encourage you to open an issue on the Prefect GitHub repository to track this. This would help ensure it gets properly fixed in future releases.
The reason psycopg2-binary
is recommended over psycopg2
is that it includes all necessary binary dependencies, avoiding the need for additional system-level PostgreSQL development packages that would be required to build psycopg2
from source.
Would you like me to provide the exact issue template to use when reporting this bug?Piotr
07/09/2025, 12:40 PMpostgresql://
, while according to https://github.com/PrefectHQ/prefect/issues/6548, it should be postgresql+asyncpg://
to allow prefect to use asyncpg which is already installedMarvin
07/09/2025, 12:40 PMMarvin
07/09/2025, 12:40 PMasyncpg
driver rather than psycopg2
. The connection string format needs to explicitly specify this:
<postgresql+asyncpg://user:password@host:port/dbname>
This is actually a much better solution because:
1. asyncpg
is already included in the Prefect image by default
2. It's significantly faster than psycopg2
due to its native async implementation
3. It aligns better with Prefect's async architecture
Thank you for the correction. This is a common point of confusion that comes up, as the standard PostgreSQL connection string format (postgresql://
) will try to use psycopg2
by default, while postgresql+asyncpg://
explicitly tells SQLAlchemy to use the async driver.