> ## Documentation Index
> Fetch the complete documentation index at: https://getfloo.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Hybrid Postgres

> Postgres 17 that floo runs on its own infrastructure, for low-traffic apps, internal tools, and scheduled jobs. Beta, on Starter and up.

Hybrid Postgres is Postgres 17 that floo runs on its own infrastructure: a
lower-cost engine for low-traffic apps, internal tools, and scheduled jobs. It
is in beta, on the Starter plan and up. See [pricing](https://getfloo.com/pricing).

Set `engine = "hybrid"` on a Postgres block:

```toml floo.app.toml theme={null}
[managed.default]
type = "postgres"
engine = "hybrid"
```

Leaving `engine` out, or setting `engine = "neon"`, keeps the default engine
described in [Postgres](https://getfloo.com/docs/guides/postgres.md). Declaring, attaching, and removing
work as for any [managed service](https://getfloo.com/docs/guides/managed-services.md).

## What gets injected

The same variables as default Postgres: `DATABASE_URL` plus `PGHOST`, `PGPORT`,
`PGDATABASE`, `PGUSER`, and `PGPASSWORD` for `[managed.default]`, and
`DATABASE_URL_<NAME>` for a named service. Dev and prod each get their own
database and password:

```text theme={null}
postgresql://app.<id>:<password>@db.getfloo.com:5432/app?sslmode=require
```

The user name `app.<id>` is how floo finds your database, so pass it unchanged.

The server presents a publicly trusted TLS certificate, so `sslmode=verify-full`
works. With libpq 16 or newer, add `sslrootcert=system` to verify against the
system's trusted certificates.

## Sleep and wake

The database sleeps when idle and wakes on the first query. That first query
takes about a second longer. `keep_warm` is not available on this engine.

## Connection pools

An idle connection can be closed when the database sleeps or when floo updates
the machine it runs on. Validate a pooled connection before each use, and
reconnect when one drops.

SQLAlchemy:

```python theme={null}
engine = create_engine(os.environ["DATABASE_URL"], pool_pre_ping=True)
```

psycopg\_pool:

```python theme={null}
from psycopg_pool import ConnectionPool

pool = ConnectionPool(os.environ["DATABASE_URL"], check=ConnectionPool.check_connection)
```

node-postgres: handle the pool's `error` event, and retry a query that fails on
a dropped connection. Retry only statements that are safe to run twice.

```js theme={null}
import pg from "pg";

const pool = new pg.Pool({ connectionString: process.env.DATABASE_URL });
pool.on("error", (err) => console.error("idle Postgres client closed", err.message));

const DROPPED = new Set(["ECONNRESET", "EPIPE", "57P01"]);

export async function query(text, params) {
  try {
    return await pool.query(text, params);
  } catch (err) {
    if (!DROPPED.has(err.code) && !/Connection terminated/.test(err.message)) throw err;
    return pool.query(text, params);
  }
}
```

## Durability and backups

* Every commit is synced to disk before it returns.
* The write-ahead log is archived off the machine continuously, at least once a
  minute while the database writes.
* A full base backup is taken daily.
* Backups are kept for 8 days.

If a database is lost, floo restores it from the latest base backup and the
archived log. The app reaches the restored database after that environment's
next restart or deploy. There is no self-serve restore: `floo db restore`
answers `POSTGRES_NOT_RESTORABLE` for a hybrid database.

## Limits

| Limit | Detail |
| - | - |
| Previews | No preview databases. A preview of an app that attaches a hybrid database fails to provision. |
| Changing engine | An existing service keeps its engine. Changing `engine` on it fails the deploy with `MANAGED_SERVICE_ENGINE_CHANGED`. To move, see [Move an existing database](#move-an-existing-database). |
| Keys | `keep_warm`, `size`, `users`, and `tier` are rejected with `engine = "hybrid"`. [User accounts](https://getfloo.com/docs/guides/user-accounts.md) needs the default engine. |
| Size | One size. |
| Extensions | pgvector is not installed. |
| Traffic | Built for low to moderate traffic. |

## Move an existing database

A database never changes engine, so moving means a new service and a copy of the
data.

1. Declare a second Postgres service with `engine = "hybrid"`. If a service
   lists `managed` under `[services.<name>.env]`, add `postgres:hybrid` there.

   ```toml floo.app.toml theme={null}
   [managed.default]
   type = "postgres"

   [managed.hybrid]
   type = "postgres"
   engine = "hybrid"
   ```

2. Deploy. The new database's URL is `DATABASE_URL_HYBRID`.

3. Stop writes to the old database, then copy each environment. `floo db dump`
   runs your local `pg_dump`, which must be PostgreSQL 17 or newer:

   ```bash theme={null}
   floo db dump --app my-app --env prod -o my-app.sql
   psql "$(floo env get DATABASE_URL_HYBRID --app my-app --env prod --reveal-secrets)" -f my-app.sql
   ```

   Repeat with `--env dev`. [Export the database](https://getfloo.com/docs/migrate/leave-floo.md#with-floo-db-dump) lists
   dump errors and options.

4. Point the app at `DATABASE_URL_HYBRID` and deploy.

5. Once the app runs on the new database, remove the old block and delete it
   with [`floo services remove`](https://getfloo.com/docs/cli/services#remove).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.