How Zenifra PostgreSQL works
This page shows how Zenifra managed PostgreSQL is configured: the workload it is tuned for, how memory and connections are split in each plan, how data is protected and what happens when the database has more than one instance. To create and connect, see Database and Connect your application to the database.
Summary
| Item | How it works |
|---|---|
| Workload | OLTP: short transactions and many small concurrent reads and writes |
| Versions | 15, 16, 17 and 18 (default 18), created on the latest minor version |
| Engine | Community PostgreSQL, no fork |
| Data page (block size) | 8 KiB (8,192 bytes), also in the WAL |
| Memory | 25% of the plan's RAM for the database cache (shared_buffers) |
Memory per operation (work_mem) | limited per plan: 4 MB up to db-premium and 16 MB on db-enterprise |
| Connections | limit per plan and per instance, from 15 to 598 |
| Writes | COMMIT only returns after the data is on the primary's disk; with the Write to 2 instances option, also on a replica |
| Encryption | data and backups encrypted at rest; TLS 1.3 in transit |
| User | app, owner of the app database, no superuser |
| Instances | 1 to 6; with 2 or more, automatic failover and a read URI on the replicas |
| Query statistics | pg_stat_statements on in every database |
Built for OLTP
Zenifra PostgreSQL is tuned for OLTP, the typical application workload: sign-ups, orders, sessions, job queues, APIs. That means many short transactions, each reading or writing a few rows through indexes, with many connections at the same time.
The settings follow that profile:
- a quarter of the memory goes to the database cache, and the rest serves the connections and the operating system cache;
- the working memory of each operation (
work_mem) is small, so many connections fit in the plan without running out of memory; - every committed transaction is already on disk.
Heavy reports, aggregations over millions of rows and event analytics run better on a columnar database. For that, use Analytics with ClickHouse and keep PostgreSQL for the application's transactions.
8 KiB data pages
PostgreSQL stores tables and indexes in 8 KiB pages (8,192 bytes), the community default. The WAL also uses 8 KiB blocks. In practice:
- a row must fit in a page; large values (text, JSON,
bytea) above about 2 KB are compressed and stored separately automatically (TOAST); - extensions, tools and dumps made for standard PostgreSQL work without changes;
pg_dumpandpg_restorefrom another provider with the default block size work as is.
To check it on your database:
SHOW block_size; -- 8192Memory per plan
The values below are set when the database is created and applied again on every plan change. They apply to each instance.
| Plan | RAM | shared_buffers | work_mem | maintenance_work_mem | effective_cache_size |
|---|---|---|---|---|---|
db-starter and db-free | 256 MB | 64 MB | 4 MB | 16 MB | 192 MB |
db-basic | 1 GB | 256 MB | 4 MB | 64 MB | 768 MB |
db-premium | 2 GB | 512 MB | 4 MB | 128 MB | 1,536 MB |
db-enterprise | 8 GB | 2 GB | 16 MB | 512 MB | 6 GB |
work_memis limited on purpose: each sort or join of each connection can use up to this value, so a high limit with many connections would exhaust the plan's memory. The rule is 1/512 of the RAM, with a minimum of 4 MB and a maximum of 32 MB. A query that goes over it uses temporary files on disk and gets slower. If a specific query needs more, raise it only for the session or the transaction:SET LOCAL work_mem = '32MB';.maintenance_work_memis used byCREATE INDEX,VACUUMandALTER TABLE.- WAL: the maximum WAL size between checkpoints is a quarter of the disk, up to 1 GB, so the write log does not take the space of the data on small disks.
Server parameters are managed by Zenifra and follow the plan. Settings you can change per session or transaction with SET (such as work_mem, statement_timeout and lock_timeout) are up to you.
Connections
Each instance accepts a maximum number of connections from your application, depending on the plan:
| Plan | Connections per instance |
|---|---|
db-free | 15 |
db-starter | 15 |
db-basic | 72 |
db-premium | 147 |
db-enterprise | 598 |
- The limit exists because each PostgreSQL connection is a process with its own memory. It is sized so that all connections fit in the plan's memory together with the cache.
- A few extra connections are reserved for the platform (administration and metrics). They are not counted above and keep the database monitored and operable even when every application connection is in use.
- Above the limit, a new connection is refused with
remaining connection slots are reserved. - Use a connection pool in the driver or ORM, with a maximum size equal to or below the limit, adding up every instance of your application. For example: on
db-basic, 3 application instances with a pool of 20 use 60 of the 72 connections. - Orphaned connections are closed automatically. If the network drops or the application process dies without closing the connection, the database notices in about 2 minutes and frees the slot.
- With 2 or more instances, each replica has its own limit. Queries sent through the read-only URI use the replicas' connections, not the primary's.
To see how many connections are open:
SELECT count(*) FROM pg_stat_activity WHERE usename = 'app';Writes and durability
- Commit on disk: when
COMMITreturns, the transaction is already on the primary instance's disk and survives a restart. - Write to 2 instances: with 2 or more instances, you can require each
COMMITto also wait for a replica, for every write or only in the transactions that need it. See Write to 2 instances. - Persistent disk: data lives on persistent storage. With 1 instance, the database disk is replicated in 3 copies on different servers, so a server failure does not lose the data.
- Automatic backups included in the plan, 1 to 3 per day, kept for 3 to 30 days. See Automatic backups.
Encryption
- At rest: PostgreSQL database disks and backups are encrypted with AES-XTS. Data is never stored in the clear, not even in the copies.
- In transit: connections use TLS 1.3, the minimum accepted version. The console URI already includes
sslmode=require. TLS is required by default and only stops being required if you turn it off in the TLS card (see Require TLS on PostgreSQL). - Password: login uses SCRAM-SHA-256, and the password generated by Zenifra is shown only on creation or after a renewal.
User and permissions
- The application user is
app, owner of theappdatabase. It creates and changes tables, indexes, views, functions and schemas in its own database. - There is no superuser access. Server administration (parameters, replication, backups and versions) is handled by Zenifra.
apphas thepg_read_all_statsrole, which lets it see statistics and every query inpg_stat_activityandpg_stat_statements.pg_stat_statementscomes enabled and records up to 10,000 distinct queries, including the ones inside functions. To find the slowest queries:
SELECT calls, round(mean_exec_time::numeric, 1) AS avg_ms, query
FROM pg_stat_statements
ORDER BY mean_exec_time DESC
LIMIT 10;- Replication connections from outside Zenifra are not accepted. To bring data from another provider, use
pg_dumpandpg_restore.
I/O performance
- PostgreSQL 16 or newer: read-ahead with up to 16 concurrent operations (
effective_io_concurrencyandmaintenance_io_concurrency). - PostgreSQL 17 or newer: sequential reads combined into blocks of up to 128 kB.
- PostgreSQL 18: asynchronous I/O on (
io_method = worker), which fetches disk reads ahead while the query processes the data already read.
With 2 or more instances
With 2 to 6 instances, the database has a primary instance and replicas:
| Primary | Replicas | |
|---|---|---|
| Accepts | writes and reads | reads only |
| Address | console host and port (main URI) | console read-only URI |
| Address on the private network (private connections) | <project>.<organization-id>.zenifra.local | ro.<project>.<organization-id>.zenifra.local |
| Connections | plan limit | plan limit on each replica |
How replication works
- Every change written on the primary is continuously sent to the replicas through the WAL (streaming replication). In normal use, a replica is a fraction of a second behind the primary.
- Default: the primary confirms
COMMITas soon as it writes to its own disk, without waiting for the replicas. It is the fastest mode, and writes do not get slower when you add instances. - With the Write to 2 instances option: each
COMMITis only confirmed after a replica has also received the transaction. See Write to 2 instances. - Read what you just wrote from the primary. A query through the read-only URI right after a write may not see the change yet, even with Write to 2 instances: the replica confirms it received the transaction, and it becomes visible there a moment later. Use the read-only URI for reports, listings and searches that tolerate this small delay.
- On plans with metrics (
db-premiumanddb-enterprise), each replica's lag shows in the Metrics tab.
Write to 2 instances
The option is off by default. Turn it on in the Write to 2 instances card, on the database edit page, or through the API, with PATCH /v1/project/:id/database/synchronous-writes.
- On: every
COMMITwaits for a replica to confirm it received the transaction. The committed transaction is on 2 instances and, while a replica is available, a primary failure does not lose a committed write. - Cost: each transaction that waits gets slower by the round trip to the replica. Reads do not change.
- No replica available: if no replica is available, writes continue on the primary only, without blocking the application. Waiting resumes when a replica comes back.
- With 1 instance: the option has no effect, because there is no replica. In the console, the switch is available from 2 instances.
- No restart: the change applies to the next transactions, without restarting the database. It requires the database to be running and the
database.exposure.updatepermission.
Per transaction
You can also choose the guarantee in each transaction, with SET LOCAL synchronous_commit. The setting applies only to the current transaction:
- Option off: ask for the guarantee in the transactions that need it, such as a payment, with
SET LOCAL synchronous_commit = on. - Option on: skip the wait in the transactions that do not need it, such as an access log, with
SET LOCAL synchronous_commit = local.
BEGIN;
SET LOCAL synchronous_commit = on;
INSERT INTO payments (order_id, amount) VALUES (42, 199.90);
UPDATE orders SET status = 'paid' WHERE id = 42;
COMMIT; -- only returns after a replica received the transactionTo apply it to every transaction on a connection, use SET synchronous_commit = on (or local), without LOCAL.
Where queries go
- The main URI always points to the primary, including after a failover: the address stays the same and leads to the new primary.
- The read-only URI spreads connections across the replicas. It does not reach the primary.
- A write sent through the read-only URI fails with
cannot execute INSERT in a read-only transaction. - Many ORMs accept two connections, one for writes and one for reads (for example, read replicas in Prisma,
DATABASESwith a router in Django andread/writein Laravel). Set the write connection to the main URI and the read connection to the read-only URI.
Failover
- If the primary fails, the most up-to-date replica is promoted to new primary automatically, with no action on your side.
- Connections open to the old primary drop. Configure the application to reconnect and retry idempotent operations.
- With Write to 2 instances off, a transaction committed at the very last moment before the failure may not have reached the promoted replica. With it on, or with
SET LOCAL synchronous_commit = onin the transaction, the committed transaction was already on a replica. - Instances always run on different servers, close to each other on the network, so a single server failure does not take down the primary and the replicas together.
Disk and billing with several instances
- Each instance has its own disk, of the chosen size. On hourly billing, storage is charged per GB on each instance.
- Each instance is charged at the plan price. For example, 3
db-basicinstances cost 3 times the plan price, plus the storage of all 3. - Adding instances creates new replicas from a copy of the primary. The primary keeps serving during the copy.
- Removing instances removes replicas. When going back to 1 instance, the primary moves once to an instance with a replicated disk, and open connections drop at that moment.
- The number of instances can change on hourly billing, from 1 to 6. On monthly and yearly, it stays fixed for the contract. See Database configuration.
Next steps
Last updated on
Database
Managed PostgreSQL, MariaDB and Valkey Key-Value on Zenifra: versions, TLS connection, public access, replicas and failover, storage, backups and metrics.
How to Create a PostgreSQL Database on Zenifra via Console
Create your first managed PostgreSQL on Zenifra from the console: plan and payment, versions 15 to 18, 1 to 6 instances with failover, storage, and TLS.