Sleep when idle
A database can shut itself down after a period with no connections, and start again when something connects. This frees memory and CPU on a database you are not using, without deleting anything.
Sleeping does not change the database:
- Its data stays on its disk.
- The hostname, port, database name, user, password and IP allowlist stay the same.
- Backups and restore points keep working. A restore point for a sleeping database is the moment it went to sleep, because that is the last change that reached the repository.
What you see
Section titled “What you see”A sleeping database shows Sleeping on its page and in the database list, with the note that the next connection wakes it. While it is starting, it shows Waking.
The first connection after it sleeps waits while the database starts, usually a few seconds. If it takes longer than the node allows, the client gets the engine’s own message instead of hanging:
database is waking up, retry in a few secondsRetry the connection after a few seconds. Applications with a connection pool recover by themselves on the next attempt.
Turn it on or off
Section titled “Turn it on or off”The delay is per database, and it is off unless you turn it on.
Dashboard: Databases → your database → Settings → Sleep when idle. Choose Off, 5 minutes, 15 minutes, 30 minutes, 1 hour, 6 hours or 24 hours, then Save sleep setting. The change applies without restarting the database.
CLI:
leaf db update shop --sleep-after 30mleaf db update shop --sleep-after offAccepted delays are 5m, 15m, 30m, 1h, 6h and 24h, or any whole number of minutes or hours
from 5 minutes to 24 hours. leaf db info shop and leaf db list --json show the current value in
sleep_after_seconds (seconds, or null when it never sleeps).
While it is asleep
Section titled “While it is asleep”- Connecting wakes it; nothing else has to be done first.
- Start, stop, restart and delete work as they do for a running database. Delete does not need to wake it first.
- Monitoring does not report a sleeping database as failed, and scheduled health checks do not wake it.
- The memory and disk of its plan stay reserved, so a wake never fails for lack of memory and the space is always there when it wakes.