Managed PostgreSQL
A managed PostgreSQL is a PostgreSQL server of your own that Zaroz runs for you. You choose a plan, the number of copies and the version; Zaroz takes care of backups, certificates, failover and minor updates. This page is the guide to everything you can do with one, in the console and with the API.
The ten small databases that come with a subscription live on a shared server and are a different thing: they are described in PostgreSQL databases. To reach your database from an app, see Connect an app to a managed database, which this page does not repeat.
The curl samples use $ZAROZ_API, $AUTH and the helper from Using the Zaroz API, and $ID for the service instance id of your database (it is in the address of the database page in the console). Everything below is under /service-instances/$ID/database.
A deployment can run without managed PostgreSQL. Then the console does not offer it and the API answers 404 capability-not-available. See Enabling managed PostgreSQL if you run the deployment yourself.
What managed PostgreSQL is
- Your own server. Each database is its own PostgreSQL instance, with its own address, users and storage. It is not shared with anyone.
- Copies. A database runs from one to several copies of your data on separate servers. One copy is standalone: if its server fails, the database restarts on the same storage, which takes minutes. Two or more copies are high availability: one primary and standbys, and if the primary fails Zaroz switches to a standby on its own and connections reconnect to the same address. The plan describes one copy, and each copy keeps the whole volume, so storage is billed for every copy (for example
20 GB x 3 copies). The product sets the range of copies you can choose. A region needs at least one schedulable server per copy, otherwise the purchase is refused with a sentence that says so. - Backups are included. WAL is archived continuously and a base backup is taken daily. You can restore to any moment inside the recovery window: 7 days with one copy, 14 days with two or more.
- TLS is always on. Every address requires TLS and your client verifies the server. The settings for each client are on Connect to PostgreSQL.
- Versions. You pick a major version when you buy, written as one number such as
18. Only versions that are on sale are offered; the newest is preselected. The minor release inside a major version (18.6, for example) is updated for you in the maintenance window. Versions only go up.
Create a managed PostgreSQL
In the console
Open Databases in your project, choose PostgreSQL and Create. Pick the region, the plan, the version, the number of copies and, if you want, the weekly maintenance window (it defaults to Sunday 03:00 in the region's time zone). Review the quote and pay the invoice. When the payment settles, Zaroz asks you to finish the setup (the database name and its administrator) and then starts the database. The first start takes a few minutes: the page shows what it is doing (finding a place to run, creating storage, initializing, configuring TLS and users). If it takes longer than usual, the page tells you.
With the API
Ask whether this deployment sells it and where:
Code
For each engine, the answer says whether it is available, the regions (ids) it is offered in and the versions that can be bought. When it is not available, unavailable lists why: not_configured, no_region or no_image.
Read what the product offers in your region (versions, copies and the default maintenance window), then quote and buy through the same checkout every product uses. PRODUCT, PLAN and REGION are the ids from the catalog.
Code
Every field of database is optional: left out, you get the product's default version, its default number of copies and the Sunday 03:00 window. A version, a number of copies or a window the product does not list is refused with a sentence, never replaced by a default. You may also send quoted (the copies and billed_storage_gb of the quote you accepted): if either moved since, the purchase is refused with database_changed_since_quote and nothing is written. Checkout returns an invoice; pay it as for any product, and the database is provisioned when it settles.
Read the database any time, for its health, version, copies, storage, maintenance window, deletion protection and the operations in flight:
Code
Connect
The Connect tab of the database shows its addresses, user and a ready-to-run snippet for every client, with the right TLS settings. The same snippets, with placeholders, are on Connect to PostgreSQL. For linking an app on Zaroz in one step, downloading the certificate and fixing connection errors, read Connect an app to a managed database. Do not write your own TLS options.
From the API, GET /connection lists every address and the snippets for a chosen one:
Code
endpoint is primary, read_only or pooler, and scope is internal (from an app in the same project) or external (from the internet, while public access is on). The answer also carries delivery, which says whether the public address answers yet (pending, active or failed); do not use it until it is active. The snippets carry the literal <password> instead of the real one.
The endpoints:
| Endpoint | Use it for |
|---|---|
Main (primary) | Reads and writes. Use this one unless you have a reason not to. |
Read only (read_only) | Reads from a standby copy, for reports that should not slow your app down. Only a database with more than one copy has it. |
Pooled (pooler) | The connection pooler, when you turn it on. See the next section. |
The password of the main user is never in a list or a snippet. Show it once more, on demand (each view is recorded in the events), or change it:
Code
grace is how long the old password keeps working: none (the default, it stops at once), one_hour or twenty_four_hours. Read the new password with reveal once the operation has finished. Apps still using the old one fail to connect when it stops working; to change a password without downtime, create a second user, move your apps to it and delete the old one.
The connection pooler
A pooler sits between your app and the database and lets many app connections share a few database ones. It helps apps that open many short connections (serverless and PHP apps do) and keeps you under the plan's connection limit. It is included in every plan.
Code
modeistransaction(recommended: a database connection is lent out only while a transaction runs, which shares the most; not for apps that rely on per-connection settings or prepared statements) orsession(a connection stays with a client until it disconnects; works with everything, shares less).external_targetis where the public address leads:direct(to the database) orpooler(connections from outside use the pooler too).- Once it is on, the pooled address appears in
GET /connectionwithendpoint=pooler. A database with more than one copy runs two pooler pods, so the pooler is not a single point of failure. - Turning it off stops apps that connect through the pooled address: point them at the database address first.
Users
The main user is created with the database. You can add more, each with a preset and, optionally, the databases it applies to. Create a separate user for each app so you can revoke one without touching the others.
| Preset | What the user can do |
|---|---|
read_only | Look at the data but not change it. |
read_write | Read, add, change and delete data. |
owner | Also change the structure: create and drop tables. |
Code
- The password of a new user (and of a reset) is generated and shown once, in the answer. It cannot be read again; only the main user's password can be revealed later.
- A name uses lowercase letters, digits and underscores, starts with a letter and has at most 32 characters. Names the platform reserves are refused.
- A database can have at most 20 users. The main user cannot be deleted.
- Resetting a password or deleting a user stops the apps that connect as that user.
Network access and public access
From apps in the same project, the database is always reachable. Public access lets clients on the internet reach it, and it is off for a new database.
Code
- With public access on, an empty list means any address can try to connect, and a strong password is the only barrier. Allow only the addresses that need it.
- Sources are IPv4 or IPv6 addresses or CIDR ranges, at most 50, with no overlaps and never the whole internet. Labels have at most 64 characters.
PUT .../networkcan also replace the whole list. Send theversionyou read: if someone changed the list in between, it is refused with409 concurrent-modificationinstead of being overwritten.- If the answer says
allowlist_supportedisfalse, the region cannot yet filter sources: only the on and off switch applies. - The public address is
NAME.db.zone.ZONE.zaroz.cloud, and it does not change when you restore a backup or upgrade.
Backups and point-in-time restore
Code
The first answer gives restorable_from and restorable_to (the span you can restore to; absent until the first backup completes), the base backups newest first, how many days they are kept (retention_days), undo_until and archiving_failing_since (set when archiving has been failing, so the span is not growing). The first backup runs within a day of the database starting. The second call backs up now; it is refused while the database is not running or when a backup was taken moments ago.
Restore
A restore target is the newest recoverable moment, any moment inside the span, or a listed backup:
Code
The call answers 202 with an operation to follow. Zaroz builds a new copy beside the running one and moves the address to it once it is healthy, so the address and the credentials do not change. Anything written after the restore point is lost. A moment before restorable_from, in the future, or a backup that is not listed is refused with 422.
Undo a restore
The data as it was just before the restore is kept for 24 hours, so a restore that was not what you wanted can be undone:
Code
undo_until in the backups answer tells you until when. After that the old copy is removed and there is nothing to undo (undo-window-closed).
Import and export
Import a dump or export your data at any time, with a size limit of 5 GiB each. Only one import or export runs at a time.
- Import takes a plain SQL file (
sql), a compressed one (sql_gz) or a PostgreSQL custom dump (pg_custom).clean(drop existing objects first) anddata_only(import only the data, not the structure) work only with a custom dump, and you cannot send both. - Export writes a custom dump (
pg_custom) or a SQL file (sql).
An import is three calls. Announce the file, send it in parts, start it:
Code
Use the part_count and part_bytes of the announcement, and send the same format, size_bytes and options when you start. Sending a part again replaces it, so a failed part is simply retried. An upload that is not started within a day is dropped. Starting joins the parts and checks the size you announced, then queues the import as the application user. Follow it in the operations list.
An export is one call and a link:
Code
The link lives 24 hours and the file is kept 7 days; ask for a fresh link until then. For a dump larger than 5 GiB, restore it with pg_restore over TLS instead.
Extensions
Extensions add abilities to your database, such as searching text that is spelled a little wrong (pg_trgm), ignoring accents (unaccent), query statistics (pg_stat_statements) or vector search (vector). Only extensions Zaroz has tested and allowlisted for your major version are offered; the list differs between versions and deployments, so read it:
Code
Each extension reports its state (not_installed, installing, installed, failed with PostgreSQL's own message, removing) and whether adding it restarts the database (restarts_database).
Code
- Most extensions are ready within a moment and need no restart. One that does restart the database makes a standalone database unavailable for about ten seconds, and on high availability switches over to a standby, so connections drop for a moment.
timingisnow(the default) ornext_window, and only a change that restarts the database can wait.- Removing an extension is refused, with PostgreSQL's reason, if something still depends on it. To remove it together with everything that depends on it (which permanently deletes those tables, columns and their data), add
?cascade=true&confirm=NAME, whereNAMEis the extension's name typed exactly.
Parameters
You can change a few PostgreSQL settings. Everything else follows your plan and is managed by Zaroz.
| Field | What it does |
|---|---|
log_min_duration_statement_ms | Queries slower than this are written to your logs. 0 records every query. |
statement_timeout_ms | A query still running after this long is cancelled. 0 turns the limit off. |
idle_in_transaction_session_timeout_ms | A connection that opened a transaction and went quiet for this long is disconnected. 0 turns the limit off. |
timezone | The time zone dates and times are shown in, such as Europe/Madrid or UTC. |
default_text_search_config | The language of text search, such as english or spanish. |
Code
The GET answer lists the bounds each value is checked against and whether a change applies right away or after a restart. A field you leave out is unchanged. A value outside its bounds, or a setting that is not on this list, is refused.
Major version upgrade
Code
The GET answer gives the running version and the newer versions on offer, each with its blockers: the database is not running, there is not enough free disk (at least 10 percent is needed), an extension you use has no build for that version, or another operation is running. Upgrade when no blockers are listed.
- You upgrade when you choose, not only in the maintenance window. The database restarts during the upgrade; do it at a quiet moment. Your address and password do not change.
- Zaroz takes a backup first. If that backup fails or takes too long, the upgrade does not start. If the upgrade itself fails, the database is left on its previous version.
- Versions only go up. To go back, restore a backup from before the upgrade (see above).
- When a version approaches the end of its life, Zaroz stops offering it for new databases and tells you ahead of time. Nobody is upgraded without asking.
Maintenance window and minor updates
Zaroz updates the minor release of PostgreSQL and applies changes that restart the database in a weekly two-hour window, in the region's time zone. The default is Sunday at 03:00. You are told 72 hours before a window in which something will happen.
Code
day_of_week counts from Sunday (0) to Saturday (6) and hour is the local start hour, 0 to 23. The first call shows the next window and the work waiting for it; any pending item can be applied now. With two or more copies, an update restarts the standbys first and then switches over, so the downtime is a moment.
Plan, storage and copies changes
-
Copies. Preview what a number of copies would do and cost, then change it. Adding copies is invoiced for the rest of the paid period and starts when the invoice is paid; the database keeps serving meanwhile, with no downtime. Removing copies runs at the end of the period you paid for and refunds nothing.
CodeThe change answers
202with either an invoice to pay or an operation to watch. A number of copies the database already runs, or one the product does not sell, is refused in words. -
Plan and storage. CPU, memory and storage change together through the subscription's resize, the same as for any service (Subscriptions and billing):
GET /subscriptions/{id}/resize/optionssays what is allowed,POST .../resize/quoteprices it andPOST .../resizerequests it. Growth is invoiced now; a reduction takes effect at the end of the paid period. Storage can only grow, never shrink, and cannot be changed on its own apart from the plan.
Metrics, logs and alerts
Metrics
Code
range is 1h (the default), 6h, 24h, 7d or 30d, and panel narrows the answer to some panels, comma separated. The console shows CPU, memory, storage, network and connections, then the PostgreSQL panels: database size, transactions per second, how many reads are served from memory, deadlocks, the longest running transaction and, with more than one copy, how far a standby is behind. It also shows the time since the last backup. Panels update every 30 seconds, and the first points appear within two minutes of the database starting. A panel that could not be read right now answers unavailable: true instead of drawing a flat line.
Logs
The log is the database's own, newest first. Pick a preset:
| Preset | What it shows |
|---|---|
server (the default) | Everything the database writes: connections, errors and slow queries. A quiet database writes nothing, so an empty log is normal. |
errors_only | Failed queries, refused logins and crashes. |
slow_queries | Queries slower than the slow-query limit, which you set in Parameters. |
connections | Each connection and disconnection, and failed logins. |
Code
from and to bound the time range, search is plain text and cursor continues a previous page (direction=forward follows new output). The platform's own pods and containers never appear in the log.
Alerts
Zaroz raises an alert on its own thresholds. An alert marks the database as needing attention, writes an event and notifies the members of the project.
| Alert | It fires when | Severity |
|---|---|---|
| Storage | Storage used reaches 80 percent of the disk | Warning |
| Storage | Storage used reaches 90 percent | Critical |
| Connections | Connections in use reach 90 percent of the plan's limit | Warning |
| Replication lag | A standby is more than 30 seconds behind | Warning |
| Backups | The last backup failed, or no backup succeeded for more than two backup periods (two days) | Warning |
Each alert offers the fix: Add storage for storage, Change plan for connections, Back up now for backups. For a standby that keeps falling behind, contact support.
Deletion protection and deletion
Deletion protection is on by default. While it is on, the database cannot be deleted.
Code
Deleting asks for the database's name typed exactly and is refused with 409 deletion-protected while protection is on. Only an Owner or Admin can delete. Every app connected to it stops working. A final backup is kept so Zaroz support can recover the data if you ask.
Events
The events are the database's timeline, newest first: created and ready, operations started, finished or failed, health, maintenance, backups, alerts, and access (a password viewed or changed, a user created or deleted, network access or deletion protection changed). An event never carries a password.
Code
kinds filters, comma separated, and limit is between 1 and 200. To go further back, send next of the previous page as after_created_at and after_id. The operations list shows every backup, restore, upgrade, import, export and password change with its state (queued, running, succeeded, failed or cancelled), its progress and, if it failed, the reason in plain words.
