Skip to content

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.

  • 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: del for Delhi or blr for Bengaluru.
  • Decide which addresses may connect. A database created without --allow is open to the internet, and the password is the only protection.
TerminalTerminal windowsh
leaf db create --engine postgres --plan trial-postgres --city blr \
--name shop --allow 203.0.113.10/32
  • --engine is required. Customers can create postgres only.
  • --plan and --city are required.
  • --name is optional. Without it, the CLI chooses a name such as postgres-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-version pins the engine version, for example 17 for Postgres.
  • --yes skips the confirmation. --json prints 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>.

leaf db allow shows or replaces the access list:

TerminalTerminal windowsh
leaf db allow shop
leaf db allow shop 203.0.113.10/32
leaf db allow shop --clear

With 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.

TerminalTerminal windowsh
leaf db list
leaf db info shop

leaf 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.

TerminalTerminal windowsh
leaf db url shop

This prints the Postgres connection string, including the password, for use as an environment variable:

TerminalTerminal windowsh
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.

CommandWhat it does
leaf db start shopStarts a stopped database.
leaf db stop shopStops a running database.
leaf db pause shopFreezes the running database without shutting it down.
leaf db resume shopContinues 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.

TerminalTerminal windowsh
leaf db resize shop --plan dedicated-4g-postgres

Resize 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.

TerminalTerminal windowsh
leaf db delete shop

The 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.