# Create PostgreSQL engines with Agno's defaults

> Agno's create_postgres_engine and create_async_postgres_engine build SQLAlchemy engines with Agno's pool and JSON settings. One tuned pool can then back your database, files and vectors.

- Published: 2026-09-08
- Author: Ashpreet Bedi
- Categories: Changelog
- Canonical: https://www.agno.com/articles/create-postgresql-engines-with-agnos-defaults
- Markdown: https://www.agno.com/articles/create-postgresql-engines-with-agnos-defaults.md

Agno's `create_postgres_engine` and `create_async_postgres_engine` live in `agno.db.postgres` and take only the pool settings you want to change. You used to copy Agno's defaults into your own engine to tune the pool.

```python
from agno.db.postgres import PostgresDb, create_postgres_engine

engine = create_postgres_engine(
    "postgresql://ai:ai@localhost:5532/ai",
    pool_size=5,
    connect_args={"connect_timeout": 5},
)
db = PostgresDb(db_engine=engine)
```

The factories default to `pool_pre_ping=True`, `pool_recycle=3600` and Agno's JSON serializer, and any keyword you pass overrides them. A plain `postgres://` or `postgresql://` URL selects Psycopg 3. An explicit driver and its TLS settings stay as written. Neither factory opens a connection until something uses the engine.

![create_postgres_engine builds one engine with pool_pre_ping, pool_recycle, Agno's JSON serializer and your settings on top. PostgresDb takes it as db_engine, and PgVector and DbFileSystem borrow it through db, so sessions, vectors and files share the same connections.](https://www.agno.com/images/v3-0-8-shared-postgres-engine.png)

Pass the engine to `PostgresDb(db_engine=...)`, and `PgVector(db=db)` and `DbFileSystem(db=db)` can borrow the same pool. `PostgresDb(db_url=...)` picks its driver the same way it did before.

See the [cookbook](https://github.com/agno-agi/agno/blob/main/cookbook/06_storage/postgres/shared_engine.py), and learn more about [PostgresDb](https://docs.agno.com/reference/storage/postgres) in the documentation.
