App template
PostgreSQL with pgvector
A PostgreSQL 18 database with pgvector.
- Memory when idle
- about 50 MiB
- CI measures it once the app is ready and before any traffic. Leave room for more.
- Tested on
- x86 servers
Introduction
This template runs a PostgreSQL 18 database managed by the CloudNativePG operator. The extension pgvector is already enabled, so you can store vectors and search for the nearest ones with SQL.
The database is called zeabur and is owned by the user app. There is one instance with a 10Gi volume.
Values you provide
You don’t fill in anything when you deploy.
Getting started
-
In Zeabur OSS, open the
postgresqldatabase in your project. When Overview shows it as ready, it is up. The database has no domain and no web page. -
Apps in the same project connect to Service
postgresql-rwon port5432, with databasezeaburand userapp. Under Overview, the Connections section shows the Host, Port, Database and Username. Click Show next to the password to read it. To give an app these values as variables, click Connect to a service in the same section. -
The operator also creates Secret
postgresql-app. No service in the project reads it as a variable, so read it with kubectl. The password is in keypassword:kubectl -n <namespace> get secret postgresql-app -o jsonpath='{.data.password}' | base64 -dKey
uriholds a ready connection string:kubectl -n <namespace> get secret postgresql-app -o jsonpath='{.data.uri}' | base64 -dThere is no superuser login. Use the connection string from an app or a client pod inside the project.
Configuration
Create a vector column and search it
Create a table with a vector column, insert rows, and order by a distance operator:
CREATE TABLE items (id bigserial PRIMARY KEY, embedding vector(3));
INSERT INTO items (embedding) VALUES ('[1,2,3]'), ('[4,5,6]');
SELECT * FROM items ORDER BY embedding <-> '[3,1,2]' LIMIT 5;
<-> is L2 distance. pgvector also has <#> for inner product and <=> for cosine distance. See Getting started in the pgvector docs.
Add an index
Without an index, pgvector does an exact search. For large tables, add an HNSW index that matches the distance you use:
CREATE INDEX ON items USING hnsw (embedding vector_l2_ops);
Use vector_cosine_ops for <=> and vector_ip_ops for <#>. See HNSW.
Back up the data
In Zeabur OSS, open the postgresql database and go to Backups → Set up backups to back up on a schedule to an S3 bucket. PostgreSQL backups need the Barman Cloud plugin. To get a copy now, click More at the top right of the database page, then Export. The browser downloads a .dump file made by pg_dump --format=custom. See Set up S3 backups and Download a database dump.
Troubleshooting
A query does not use the index
The query needs ORDER BY with a distance operator in ascending order, and a LIMIT. An expression such as 1 - (embedding <=> '[3,1,2]') stops the planner from using the index. On a small table a table scan can be faster. See Troubleshooting.
Resources
Each service is guaranteed the first amount and can use up to the second.
postgresql
Ports
5432
CPU
0.1 cores to 1 core
Memory
256 MiB to 1 GiB
Technical details
This release
- Version
- 18-standard-trixie
- Licence
- PostgreSQL AND Apache-2.0
- Homepage
- github.com
Tested in CI
CI installs these exact files on a new cluster, waits until they are ready, then records the idle memory.
| Distribution | Platform | Kubernetes | Passed | Idle memory |
|---|---|---|---|---|
| kind | linux/amd64 | v1.37.0 | 51 MiB |
Security
The CloudNativePG operator (CNPG) runs the database pods without root rights and sets up permissions for each cluster. There is no public database port and no superuser login. SQL extensions are created only when the database is first set up.
Known risks
Risk
The database pods need a Kubernetes API token, which the operator manages. The template itself creates no Role or binding.
How it is handled
Check the permissions the catalog operator creates and the pods it generates. Leave token automount on for the database pods, because the operator needs it.
Risk
Local-path storage has no snapshots and no availability across nodes. The extension and plugin images are extra software you have to trust.
How it is handled
Check the operator release, the database image digest and your backups. Test a restore with pgvector before you go to production and before upgrades.
Risk
A backup that finished without errors does not prove that your vectors and indexes restore correctly.
How it is handled
Run a restore drill with representative vectors before production.
What the cluster needs
Zeabur OSS suggests the components a cluster is missing. Without it, install them first.