PostgreSQL
Add a PostgreSQL database to an environment, find its connection details, and connect an app to it.
A database is added to one environment of a project, and any app in that environment can connect to it. This guide adds PostgreSQL to the Dev environment and connects an app that is already running there.
Add PostgreSQL
On the project canvas, click + Service, then Database or cache. Pick PostgreSQL.

The list also has TimescaleDB: PostgreSQL on a TimescaleDB image, for time-series data, with the timescaledb extension already created in the app database. It is the open-source edition ("no compression or continuous aggregates"). It's a separate choice when you add the database: an existing database can't be switched to or from it.

A PostgreSQL card appears under Databases marked Ready to deploy. Nothing has been created yet.

Review and deploy
Click the card. The catalog defaults are PostgreSQL 17, one instance, a 1 GiB volume, the user postgres and the database app. The panel says the database "deploys with the catalog defaults", and that size, high availability and connections are tuned in this panel once it is running. Click Deploy.

If you change your mind, Remove from canvas takes the card away without creating anything.
When it is ready, the card shows Running.

Find the connection details
Click PostgreSQL on the card, open Settings, and look under Access:
- Connect from apps: the Host, the short Service name, Username, Password and Database. The port is
5432. - Connection URL: the same details as a
postgresql://URL, plus a JDBC URL. These work from apps in this environment and are "not reachable from the public internet". - Environment snippet: ready-made lines (
DATABASE_URL,PGHOST,PGPORT,PGUSER,PGPASSWORD,PGDATABASE, …) to paste into an app's variables.

Connect an app
Further down, Connections lists the apps in the environment. Turn on the switch next to your app. The change is staged.

Close the panel, click Commit 1 change, then Deploy 1 change. The app redeploys.

Check the app's variables
Open the app and go to Variables. Connecting added:
| Variable | |
|---|---|
PGHOST, PGPORT | the database's in-cluster address (the primary) |
PGHOST_RO, PGPORT_RO | the read-only address of the replicas, which only has instances behind it once high availability is on |
PGUSER, PGDATABASE | the user and database name |
PGPASSWORD | read from the database's secret ("Provided by add-on") |

Connecting also adds DATABASE_URL, a postgres:// URL built from the PG* values. A variable you set yourself with the same name always wins.
When the database includes its own connection pooler (some templates add one), connecting also adds PGHOST_POOLER and PGPORT_POOLER, the pooler's address.
Build steps and the Pre-deploy command get the same variables. When the service has no usable DATABASE_URL of its own, they get one built from the PG* values, so a migration that reads DATABASE_URL works at build time too.
If the app is connected to two databases that both set DATABASE_URL (for example PostgreSQL and MariaDB), the first keeps the plain names and the second also gets its whole set under its own prefix, such as MARIADB_DATABASE_URL and MARIADB_MYSQL_HOST.
From the connected app, psql "$DATABASE_URL" reached the database:
$ psql "$DATABASE_URL" -At -c "show server_version;" -c "select current_database();"
17.5 (Debian 17.5-1.pgdg110+1)
appTo disconnect, turn the switch off and deploy the change; the PG* variables are removed from the app.
The database card
The card on the canvas shows the database's address for the SQL console (see below) and its status. The instance count (1 with an arrow) opens the list of the database's volumes, with their size.

Connect from your machine
stackblaze connect postgres opens a psql shell on the database without opening it to the internet. Name the app it's connected to:
stackblaze connect postgres -p shop -e dev -a web # psql runs inside the app
stackblaze connect postgres --local -p shop -e dev -a web # psql runs on your machine
stackblaze connect postgres --tunnel -p shop -e dev -a web # keep a local port open for GUI tools- By default
psqlruns inside the app's instance. --localruns your ownpsqlthrough a private tunnel:Tunnel 127.0.0.1:33567 → postgres addon "postgresql-u0kr". Running local psql…--tunnelkeeps the tunnel open and prints the host, port, user and database for a GUI tool.--print-onlyprints apostgresql://…@127.0.0.1:<port>/…connection string instead of starting a client, and--portpicks the local port.
The tunnel listens on 127.0.0.1 only, closes after 30 minutes idle, and needs write access to the app. When the app has several databases, add --instance <name>.
Connect from outside StackBlaze
By default the database is only reachable from apps in the same environment. Public access opens it to clients outside the platform (a laptop, a BI tool, another cloud), only from IP addresses you allow, and only over TLS.
Allow your IP addresses
Open the database's Settings → Access and find Public access. In Allowed IPs, enter the addresses that may connect, separated by commas. Ranges in CIDR form (like 198.51.100.0/24) work too.
Allow any IP lets anyone who has the password connect. The panel marks it "not recommended".

Turn it on
Turn on the Public access switch. You get an Address and a Connection string that ends in ?sslmode=require.

Connect
Copy the Connection string and use it from an allowed address, for example:
psql "postgresql://postgres:<password>@<address>/app?sslmode=require"When we did this, the address refused connections for a short while after the switch turned on, then accepted them.
To change the list later, edit Allowed IPs and click Save allowed IPs. Turning the switch off asks "Turn off public access? Clients outside the platform will be disconnected." After that, the address no longer accepts connections.
SQL console
The address on the database card (db.…) opens a SQL console in a new tab. You are signed in, and the database is listed under Shared.

Open a SQL editor, choose the database's connection if the editor asks for one, type a query and press Ctrl+Enter.

The Database console page covers the rest: the navigator, scripts, the execution plan, editing rows and exporting results.
Extensions
Settings → Extensions lists the PostgreSQL extensions available on the database's image and how many are enabled. Extensions are per database: pick the database (for example app) in the menu next to Refresh. Use Filter by name… to find one, then turn its switch on.

Some extensions are marked needs restart: they load a library into shared_preload_libraries.

Turning one on asks first. The dialog warns that it "triggers a rolling restart of the PostgreSQL cluster. Existing connections will be briefly interrupted while the primary restarts." Click Restart & enable.


Storage
Settings → Storage shows each volume, how much of it is used, and Expand storage. Volumes can only grow.

Choose a new size and click Expand.

The resize can take a few minutes. Once it is done, the volume shows its new size.

High availability
A new database runs as a Single primary. Settings → HA → Enable HA turns it into a cluster of three.

The dialog says it "Scales the Postgres cluster to 3 instances. This is a one-way upgrade — there is no in-place downgrade to a single primary." Click Enable HA.

When it is done, the section shows the cluster: its health, 3/3 replicas ready, which instance is the primary, the mode (Streaming replication), and each member with its role (one primary, two replica).

Connected apps keep the same variables: PGHOST still points at the primary, and PGHOST_RO now reaches the two replicas, so you can send read-only queries there.
Deployments
The Deployment tab lists the database's deploys and restarts, with the image each one ran.

The ⋯ menu on a deploy has Redeploy and Inspect Deployment.

Inspect Deployment opens that deploy's logs.

Redeploy asks first ("This will restart the add-on with the exact same configuration"), then restarts the database. The deploy's time in the list changes to when it restarted.


Logs
The Logs tab streams the database's logs.

- All pods: show every instance, or pick one (for example
primary · postgresql-…-1). - App logs / System events: the database's own output, or platform events about it.
- Search logs: filter the lines.
- Live tail, Last 15 minutes, Last 1 hour, Last 6 hours, Last 24 hours, All loaded: the time range.
- The expand button opens the logs full size. The ⋯ menu has Refresh, Copy logs and Download logs.


Metrics
The Metrics tab shows the last 2h, 24h or 7d, with Refresh. At the top: Connections (open sessions), Queries (statement rate), Replica lag and Data size.

Below that are charts in four groups:
| Group | Charts |
|---|---|
| Host resources | Memory usage, CPU usage |
| Workload | Open connections, Queries / s, Writes / s (each Overall or Per-pod) |
| Health | Query time, Waiting on locks |
| Storage & replicas | Data on disk, Replica lag |


Plan limits
The top of Settings shows what your plan allows for this database: how many clients can connect at once (Connections) and how long its backups are kept (Backup retention).

Import a dump
To load an existing database, see Import a database dump.
Backups
Back up the database, restore it as a copy, and move your apps onto the copy with Switch instance: see Backups and restore. A recovery point holds a dump of the database.
PostgreSQL also has point-in-time recovery, through the API only.
Delete
Delete add-on, at the bottom of Settings, deletes the database and its data. It is only available once no apps are connected: disconnect them first in Connections.