Create and manage a database
This page covers creating a database and the commands that change it. To connect from psql, pgAdmin, DBeaver or an application, see Connect to a database.
Before you create
Section titled “Before you create”- Databases must be enabled for your account. See Getting access.
- Choose a plan with
leaf db plans. The plan id is the value you pass to--plan. - Choose a city:
delfor Delhi orblrfor Bengaluru. - Decide which addresses may connect. A database created without
--allowis open to the internet, and the password is the only protection.
Create
Section titled “Create”leaf db create --engine postgres --plan trial-postgres --city blr \ --name shop --allow 203.0.113.10/32--engineis required. Customers can createpostgresonly.--planand--cityare required.--nameis optional. Without it, the CLI chooses a name such aspostgres-3128456710.--allow <CIDR>may be repeated, for example--allow 203.0.113.10/32 --allow 2001:db8::/32. The list is the database’s initial access list.--engine-versionpins the engine version, for example17for Postgres.--yesskips the confirmation.--jsonprints the API’s object.
Without --allow, the command warns that anyone on the internet can try to connect and asks for
confirmation unless you pass --yes.
The command prints the new database’s engine, plan and city, and suggests leaf db connect <name>.
Open or close access
Section titled “Open or close access”leaf db allow shows or replaces the access list:
leaf db allow shopleaf db allow shop 203.0.113.10/32leaf db allow shop --clearWith no addresses, it prints the current list. With addresses, it replaces the whole list, so pass every
address you want to keep. --clear allows every source again. The dashboard does the same: the
Connection panel can add the address you are browsing from, and Settings → Allowed IPs edits the
list by hand.
An empty list means open to the internet. For the connection errors and the exact behaviour, see Before you connect: the IP allowlist.
Read the details
Section titled “Read the details”leaf db listleaf db info shopleaf db list lists your databases with their state. --wide adds the ID, memory, disk and created
date. leaf db info shop is the detail view: connection, plan, access, backups and details. Add
--json to either command for the API’s objects.
Get a connection URL
Section titled “Get a connection URL”leaf db url shopThis prints the Postgres connection string, including the password, for use as an environment variable:
DATABASE_URL=$(leaf db url shop)The URL contains the password, so on a terminal the command refuses to print it unless you pass
--show. Its output is only the URL, so it can be captured directly. It works for Postgres only.
Start, stop, pause and resume
Section titled “Start, stop, pause and resume”| Command | What it does |
|---|---|
leaf db start shop | Starts a stopped database. |
leaf db stop shop | Stops a running database. |
leaf db pause shop | Freezes the running database without shutting it down. |
leaf db resume shop | Continues a paused database. |
These commands ask the server for the change and print accepted wording, such as Starting shop…; they
do not wait for it to finish. Run leaf db info shop to see the current state.
A stopped or paused database refuses connections. Start or resume it to accept connections again.
Resize
Section titled “Resize”leaf db resize shop --plan dedicated-4g-postgresResize changes the plan. It is available for Postgres. A plan with a smaller disk than the current one
is refused. The command is accepted at once and the database’s node applies the new plan; leaf db info shop shows the plan on the database.
Delete
Section titled “Delete”leaf db delete shopThe command asks you to type the database’s name. In a script, pass --yes. Deleting permanently removes
the database’s data volume and its connection endpoint. Encrypted backups are kept; email
admin@leafcloud.in if you need them purged.