Connect to a database
To create a database, or to stop, resize or delete one, see Create and manage a database.
Every database is reached by its own hostname under db.leafcloud.app, over TLS. Use the hostname from
the dashboard’s Connection panel, never the database node’s IP address: TLS routing uses the
hostname (SNI), so the IP has no certificate and no route.
Before you connect: the IP allowlist
Section titled “Before you connect: the IP allowlist”Each database has an access list. There are two states:
- Open to the internet: the list is empty, and any source may try to connect. The password and TLS are the only protection.
- Only from the listed addresses: connections from any other address are refused, even with the correct password. Entries are IPv4 or IPv6 addresses or CIDR blocks.
Add your address before you try the first connection:
- Dashboard: Databases → your database → Access → add your IP, or press Add my IP in the Connection panel when it warns that your current address is not on the list.
- CLI:
leaf db allow <database> <your-ip>/32. The command replaces the whole list, so pass every address you want to keep; runleaf db allow <database>with no CIDRs to print the current list first.leaf db allow <database> --clearopens it to the internet again.
The dashboard’s Connection panel says which mode your database is in and whether the IP you are browsing from is allowed. That check uses the address tb-api sees for you (behind the same trusted proxy headers as the rate limits); a change of ISP, VPN or office network can move you outside the list. When that happens the server answers with an error that says so instead of closing the connection silently:
connections from 198.51.100.23 are not allowed for this database. Add your IP on the database'sAccess page in the dashboard, or with leaf db allow.Connection details
Section titled “Connection details”| Field | Postgres | MySQL | Valkey |
|---|---|---|---|
| Host | <name>-<suffix>.db.leafcloud.app | <name>-<suffix>.db.leafcloud.app | <name>-<suffix>.db.leafcloud.app |
| Port | 5432 | the port shown in the dashboard | 6379 |
| Database | postgres for new databases | the database shown in the dashboard | none (0) |
| User | leaf_admin | leaf_admin | leaf_admin |
| Password | reveal it in the dashboard or with your CLI | same | same |
| TLS | required, verify the hostname | required, verify the hostname | required, send SNI |
New Postgres databases keep their data in the postgres database, so that is the value to use in
psql, pgAdmin and application settings. Databases created before this change, and restores of them,
keep their old database name (the internal db-<hex> id). The dashboard’s Database field always
shows the exact value for the database you are looking at.
The password is shown once when a database is created and can be revealed or reset later in the
dashboard. Use the TLS settings below for every client. sslmode=require alone encrypts the
connection but does not prove you reached LeafCloud; verify-full checks both the certificate chain
and the hostname.
What verify-full needs
Section titled “What verify-full needs”The database certificate is issued by Let’s Encrypt. Its root (ISRG Root X1) is in current operating
system trust stores, but libpq does not use that store for verify-full unless you ask it to: by
default it looks for ~/.postgresql/root.crt, which a stock machine does not have.
The connection string in the dashboard and the API therefore ends with:
?sslmode=verify-full&sslrootcert=systemsslrootcert=system (libpq 16 and newer, so psql 16+) loads the operating system’s trusted roots.
It also makes verify-full the only accepted mode. On a stock machine with psql 16–18 that string
connects without any root certificate file. On an older libpq, replace sslrootcert=system with the
path to your operating system’s CA bundle, for example /etc/ssl/certs/ca-certificates.crt on
Debian/Ubuntu or /etc/ssl/cert.pem on macOS. GUI clients linked against an older libpq need the
same file in their root-certificate field.
Use the connection string from the dashboard, paste it after psql, and enter the password when
asked:
psql "postgresql://leaf_admin@shop-a1b2c3.db.leafcloud.app:5432/postgres?sslmode=verify-full&sslrootcert=system"The equivalent keyword form, if your shell or password manager makes the URI awkward:
psql "host=shop-a1b2c3.db.leafcloud.app port=5432 dbname=postgres user=leaf_admin \ sslmode=verify-full sslrootcert=system"Older libpq (psql 15 or earlier) does not know the system value:
psql "host=shop-a1b2c3.db.leafcloud.app port=5432 dbname=postgres user=leaf_admin \ sslmode=verify-full sslrootcert=/etc/ssl/certs/ca-certificates.crt"Keep the hostname in host. If you put the IP there, the certificate name check fails and psql
reports that the certificate does not match the host name.
pgAdmin
Section titled “pgAdmin”- Register → Server, then the General tab: any name you like.
- Connection tab:
- Host name/address: the hostname from the dashboard (not the IP).
- Port:
5432. - Maintenance database:
postgres. - Username:
leaf_admin. - Password: the database password.
- SSL tab:
- SSL mode:
Verify-Full. - Root certificate: your operating system’s CA bundle (Linux:
/etc/ssl/certs/ca-certificates.crt; macOS:/etc/ssl/cert.pem). pgAdmin passes this file assslrootcert; leaving it empty makes libpq look for~/.postgresql/root.crtinstead.
- SSL mode:
- Save, then connect. The first connection can take a second while the node’s route is resolved.
pgAdmin’s Query Tool connects to the maintenance database, so you land in postgres. Create your
own schemas and tables there; you own them. CREATE DATABASE works too if you prefer a separate
database, but the trial’s leaf_admin user and connection details stay the same.
DBeaver
Section titled “DBeaver”- Database → New Database Connection → PostgreSQL.
- Main tab: Host = the hostname, Port =
5432, Database =postgres, Username =leaf_admin, Password = the database password. - SSL tab: tick Use SSL, set SSL mode to
verify-full, and set Root certificate to your operating system’s CA bundle (the same paths as above). - Test Connection. If DBeaver asks for the PostgreSQL driver, let it download one.
TablePlus
Section titled “TablePlus”- Create a new connection → PostgreSQL.
- Name: any name. Host: the hostname. Port:
5432. User:leaf_admin. Password: the database password. Database:postgres. - Open TLS/SSL, choose SSL mode: verify-full, and select your operating system’s CA bundle as the root certificate. If your TablePlus version names the field Server certificate or CA certificate, that is the same file.
- Test, then Connect.
DataGrip
Section titled “DataGrip”- Database Explorer → + → Data Source → PostgreSQL.
- General tab: Host = the hostname, Port =
5432, Database =postgres, User =leaf_admin, Password = the database password. - SSH/SSL tab: enable Use SSL, set SSL mode to
verify-full, and choose your operating system’s CA bundle as the CA file. - Test Connection. DataGrip uses its own PostgreSQL JDBC driver, not libpq, so it always needs
the CA file path; it cannot use
sslrootcert=system.
Node.js (pg)
Section titled “Node.js (pg)”import pg from 'pg';
const pool = new pg.Pool({ host: 'shop-a1b2c3.db.leafcloud.app', port: 5432, database: 'postgres', user: 'leaf_admin', password: process.env.DATABASE_PASSWORD, ssl: { rejectUnauthorized: true },});rejectUnauthorized: true is Node’s default for TLS, but write it down so a future edit cannot
silently turn verification off. Node trusts the system store, including the Let’s Encrypt root.
Do not paste the dashboard URL with sslrootcert=system into pg: node-postgres reads
sslrootcert as a file path and tries to open a file literally named system. The
?sslmode=verify-full part is enough for pg; or drop the query string and keep the ssl object
above. If your Node version or a corporate proxy does not trust the system store, pass the CA bundle
explicitly:
import fs from 'node:fs';
ssl: { rejectUnauthorized: true, ca: fs.readFileSync('/etc/ssl/certs/ca-certificates.crt', 'utf8') }The hostname is also the TLS SNI name, so keep the pool’s host set to it.
Prisma
Section titled “Prisma”With Prisma ORM 7 and the pg driver adapter, the SSL object is the same as above. Keep
sslrootcert=system out of DATABASE_URL:
import { PrismaPg } from '@prisma/adapter-pg';import { PrismaClient } from './generated/prisma';
const adapter = new PrismaPg({ connectionString: process.env.DATABASE_URL, // .../postgres?sslmode=verify-full ssl: { rejectUnauthorized: true },});const prisma = new PrismaClient({ adapter });For Prisma versions that use their own query engine, put sslmode=verify-full in DATABASE_URL and,
if the engine asks for a root certificate, add sslrootcert= followed by your operating system’s CA
bundle path. Run npx prisma db push or npx prisma migrate deploy with the same URL; migrations
land in postgres and create their own tables there.
Python (psycopg)
Section titled “Python (psycopg)”psycopg 3 uses libpq, so it accepts the same settings as psql:
import osimport psycopg
with psycopg.connect( host="shop-a1b2c3.db.leafcloud.app", port=5432, dbname="postgres", user="leaf_admin", password=os.environ["DATABASE_PASSWORD"], sslmode="verify-full", sslrootcert="system",) as conn: with conn.cursor() as cur: cur.execute("select current_user, current_database()") print(cur.fetchone())On libpq 15 or earlier, use sslrootcert="/etc/ssl/certs/ca-certificates.crt" (or your platform’s
CA bundle) instead of "system". psycopg2 takes the same keyword arguments.
Django
Section titled “Django”Django’s PostgreSQL backend hands these options to libpq:
import os
DATABASES = { "default": { "ENGINE": "django.db.backends.postgresql", "NAME": "postgres", "USER": "leaf_admin", "PASSWORD": os.environ["DATABASE_PASSWORD"], "HOST": "shop-a1b2c3.db.leafcloud.app", "PORT": "5432", "OPTIONS": { "sslmode": "verify-full", "sslrootcert": "system", }, }}On libpq 15 or earlier, replace "system" with the path to your CA bundle. Run python manage.py migrate as usual; Django creates its tables in postgres.
Create the connection with the hostname the dashboard shows and the database’s own port:
mysql --ssl-mode=VERIFY_IDENTITY \ -h shop-a1b2c3.db.leafcloud.app -P <port from the dashboard> \ -u leaf_admin -p <database from the dashboard>TLS is required: the proxy refuses a plaintext connection with TLS required. Keep
--ssl-mode=VERIFY_IDENTITY so the client checks both the certificate and the hostname. If your
client insists on a CA file, add --ssl-ca=/etc/ssl/certs/ca-certificates.crt (your platform’s
bundle). MySQL clients show an allowlist refusal as an access-denied error with the
not allowed for this database text.
Valkey
Section titled “Valkey”Valkey shares port 6379, so the hostname is what selects your database. Clients must send it as
SNI; valkey-cli does that with --sni:
valkey-cli --tls --sni shop-a1b2c3.db.leafcloud.app \ -h shop-a1b2c3.db.leafcloud.app -p 6379 \ --user leaf_admin --askpassThe connection URI is rediss://leaf_admin@shop-a1b2c3.db.leafcloud.app:6379/0. Application clients
need TLS with server-name verification and SNI set to the hostname; without SNI the proxy answers
-ERR SNI required: use your database hostname or -ERR unknown SNI. If your client needs a CA file,
point it at your operating system’s bundle. -ERR TLS required means TLS is off.
Troubleshooting
Section titled “Troubleshooting”| Error you see | Cause | Fix |
|---|---|---|
connections from <ip> are not allowed for this database (Postgres FATAL 28000, MySQL access denied, Valkey -ERR) | Your source address is not on the database’s allowlist. | Add <ip>/32 in Databases → your database → Access, press Add my IP, or run leaf db allow <database> <ip>/32 with the rest of the list. |
unknown or missing SNI (Postgres) / unknown SNI (Valkey) / SNI required: use your database hostname | The Host field is the node’s IP, an old db-<hex> name, or the client does not send SNI at all. | Use the exact hostname from the dashboard. Do not use the IP. |
TLS required | SSL is disabled or the client tried plaintext. | Set SSL mode to verify-full (psql: sslmode=verify-full; MySQL: --ssl-mode=VERIFY_IDENTITY; Valkey: --tls). |
password authentication failed for user "leaf_admin" / Access denied for user 'leaf_admin' / WRONGPASS or NOAUTH | Wrong or rotated password. | Reveal the current password again, or reset it, in the dashboard. |
root certificate file ".../.postgresql/root.crt" does not exist | verify-full without a root certificate, on a machine with no ~/.postgresql/root.crt. | Add sslrootcert=system (libpq 16+), or point sslrootcert at your operating system’s CA bundle. |
certificate verify failed | The client’s trust store does not know the Let’s Encrypt root, or it is out of date. | Update the OS CA bundle, or set sslrootcert/CA file to a current bundle. |
server certificate for "..." does not match host name "..." | The Host field is an IP address instead of the database hostname. | Use the hostname. |
database db-<hex> is stopped (Postgres or MySQL) / -ERR database is stopped (Valkey) | The database is stopped or paused. | Start or resume it in the dashboard, then retry. |
database is starting or unavailable, retry | The database has no backend yet (starting, restoring, moving). | Wait a few seconds and retry; the dashboard shows the state. |
too many failed logins from this address, try again later (or host is blocked after too many failed logins) | Ten failed logins from your address for this database within five minutes. | Wait fifteen minutes, then use the correct password. |
too many connections | The connection cap for the plan is reached. | Close idle clients, or raise the plan’s connection limit by resizing. |