All documentation

Managed databases

PostgreSQL with pgvector and PostGIS, MySQL and Redis in your account network: password, connecting to an app, extensions, connection pool, backups.

A managed database is a separate resource type. We run a pinned engine image, generate the password, size the memory to the plan, take backups and change the password at the press of a button. The database is not reachable from the internet: only your resources in the same datacenter see it.

PostgreSQL 16 runs on our own image that already contains pgvector (vectors and similarity search) and PostGIS (geodata). You enable them with a button, the app user does not need superuser rights.

Creating

“New resource” → “Database” → PostgreSQL 16, MySQL 8.4 or Redis 7 → plan. The password is shown once, right after creation — save it. Later it can only be changed.

Connecting to an app

“Connection” tab → pick your app, container or hosting → “Connect”. The connection URL goes into its DATABASE_URL variable (REDIS_URL for Redis) and is updated automatically when the password or the database address changes.

The URL looks like this:

postgresql://app:PASSWORD@ADDRESS:5432/app

The database and the app must run on the same server of the datacenter. Connecting from outside over TLS comes in the next stage.

Inside a project you can reference the database from a variable instead: DATABASE_URL = ${{shop-db.DATABASE_URL}}, and through the pool — ${{shop-db.POOL_URL}}.

PostgreSQL extensions

“Connection” tab → “Extensions” → “Enable”. The platform installs the extension as the database administrator within a minute; the app user app stays a regular owner of the database without superuser rights. From the command line: uc db ext shop-db enable vector.

Allowed: vector, postgis, postgis_topology, pg_trgm, uuid-ossp, hstore, citext, pgcrypto, unaccent, btree_gin, btree_gist, fuzzystrmatch, pg_stat_statements. Extensions that give access to server files or the network (dblink, file_fdw, plpython languages) are not available.

pgvector: embeddings and similarity search

Enable vector. The column dimension matches your embedding model (1536 here):

CREATE TABLE documents (
  id bigserial PRIMARY KEY,
  body text NOT NULL,
  embedding vector(1536) NOT NULL
);

-- HNSW index on cosine distance: fast approximate search.
CREATE INDEX documents_embedding_idx ON documents USING hnsw (embedding vector_cosine_ops);

-- The five documents most similar to the query embedding ($1 is the array of numbers from the model).
SELECT id, body, 1 - (embedding <=> $1) AS similarity
FROM documents
ORDER BY embedding <=> $1
LIMIT 5;

Operators: <=> is cosine distance, <-> Euclidean, <#> negative inner product. The index is built in the database memory: for large tables take a bigger plan or raise SET maintenance_work_mem = '256MB' in the session before CREATE INDEX. HNSW recall is tuned with SET hnsw.ef_search = 100 (higher is more accurate and slower).

PostGIS: points and distances

Enable postgis. Example — cafés within a kilometre of a point:

CREATE TABLE places (
  id bigserial PRIMARY KEY,
  name text NOT NULL,
  location geography(Point, 4326) NOT NULL
);
CREATE INDEX places_location_idx ON places USING gist (location);

INSERT INTO places (name, location)
VALUES ('Cafe by the Registan', ST_GeogFromText('POINT(66.9750 39.6547)'));

-- Everything within 1000 m of a point (longitude, latitude), nearest first.
SELECT name, ST_Distance(location, ST_MakePoint(66.9690, 39.6542)::geography) AS meters
FROM places
WHERE ST_DWithin(location, ST_MakePoint(66.9690, 39.6542)::geography, 1000)
ORDER BY meters;

The geography type measures distances in metres on the Earth's surface. The spatial_ref_sys table of coordinate systems belongs to the extension: you can read it, there is no need to change it.

Connection pool (PgBouncer)

Every PostgreSQL connection is a separate process and memory of the database. Many workers, functions and serverless handlers quickly hit the connection limit of the plan. A pool solves this: “Connection” tab → “Connection pool” → “Pool enabled” → “Save” (or uc db pool shop-db on).

  • PgBouncer starts next to the database in your account network, port 6432.
  • Connected resources get a second variable DATABASE_POOL_URL next to DATABASE_URL and restart by themselves. The password is the same; both URLs are masked in deploy logs.
  • The pool size follows the database plan: the pool keeps at most half of the database connection limit and accepts ten times more clients.
  • PgBouncer stores the password not in plain text but as a SCRAM-SHA-256 hash.

Modes. transaction (default): a database connection is given out for one transaction, so hundreds of clients share a dozen connections. Session settings (SET), temporary tables, LISTEN, advisory locks and SQL-level PREPARE do not persist between transactions. Protocol-level prepared statements of drivers are handled by PgBouncer itself. session: a connection belongs to the client until it disconnects — everything works, but the savings are smaller.

ORMs, beware. Some ORMs break prepared statements in transaction mode. Prisma needs ?pgbouncer=true on the pool URL: create a variable PRISMA_URL = ${{shop-db.POOL_URL}}?pgbouncer=true and set url = env("PRISMA_URL") and directUrl = env("DATABASE_URL") in schema.prisma. Run migrations (prisma migrate, alembic, knex migrate) over the direct DATABASE_URL. Django: DISABLE_SERVER_SIDE_CURSORS = True. If the ORM complains about prepared statement already exists, switch the pool to session or turn off prepared statements in the driver.

When you turn the pool off, DATABASE_POOL_URL disappears from the connected resources. The pool is included in the database price.

Changing the password

“Connection” → “Change password”. The new password is shown once; connected resources get the new URL and restart by themselves, replace the password elsewhere by hand.

Backups

Attach a backup package on the “Backups” tab: a backup contains the data volume and a logical dump. Backups are stored in the same datacenter — this protects against mistakes, it is not fault tolerance.

Limits

The database gets the plan memory: PostgreSQL and MySQL buffers and the Redis memory limit are sized to it automatically. When the plan changes, the database restarts with the new limits, the data stays.