PostgreSQL exists in two forms on Webgune: a managed database, on the shared database servers, and a project database, in PostgreSQL 16. The full comparison is on Databases.
| Managed database | Project database | |
|---|---|---|
| Port | 5432 | 5432 |
| TLS | required | not required |
| User | same name as the database (wg_<prefix>_<name>) | kxuser, unless you chose otherwise at creation |
| Size | 500 MB without a subscription, 10 GB with one | 5 GB volume |
| Simultaneous connections per account | 10 without a subscription, 50 with one | PostgreSQL's default setting |
Connection string
# Managed database: the URI is shown at creation, with the password
DATABASE_URL=postgresql://wg_ab12cd_boutique:MOT_DE_PASSE@HOTE:5432/wg_ab12cd_boutique?sslmode=require
# Project database: full string in the service's Database tab
DATABASE_URL=postgresql://kxuser:MOT_DE_PASSE@ma-db.kx-boutique-1a2b3c4d.svc.cluster.local:5432/ma-db
A managed database's password is shown only once. If it is lost, Rotate password in the Accounts section generates another.
A project database's address answers only the services of the same project. Its default database has the service's name.
Prisma
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
model User {
id String @id @default(uuid())
email String @unique
createdAt DateTime @default(now())
}
npx prisma migrate deploy
With several instances, limit the pool in the URL (?connection_limit=10, combined with sslmode=require using &). Three instances at 10 connections open 30.
node-postgres
import { Pool } from "pg";
const pool = new Pool({ connectionString: process.env.DATABASE_URL, max: 10 });
const { rows } = await pool.query("SELECT now()");
SQLAlchemy (Python)
import os
from sqlalchemy import create_engine, text
# SQLAlchemy expects the postgresql:// scheme, not postgres://
engine = create_engine(os.environ["DATABASE_URL"], pool_size=5, max_overflow=5)
with engine.connect() as conn:
print(conn.execute(text("SELECT 1")).scalar())
Connect from your machine
Managed database: add your address in Network access (My address button), then:
psql "postgresql://USER:MOT_DE_PASSE@HOTE:5432/BASE?sslmode=require"
Project database: turn on Public access in the Database tab, then use the public host and port shown. Turn the access off after the intervention, this port is open to the whole Internet.
psql "postgresql://kxuser:MOT_DE_PASSE@HOTE_PUBLIC:PORT_PUBLIC/ma-db"
Queries from the panel
For a managed database, the Data tab shows the tables, the structure, the indexes and an SQL console (1,000 rows per result). For a project database, the console in the Database tab runs the query with psql and stops it after 30 seconds. Its default query lists the tables of the public schema:
SELECT table_name FROM information_schema.tables WHERE table_schema = 'public';
Migrations
Run migrations with a dedicated command (prisma migrate deploy, alembic upgrade head) rather than by hand in the console. A migration must stay readable by the previous version of the application: add a column in one version, remove the old one in the next. Details are on Database migrations.
The build has no access to the database. prisma generate works during the build, prisma migrate deploy does not.
Back up and import
# Export
pg_dump "postgresql://USER:MOT_DE_PASSE@HOTE:5432/BASE?sslmode=require" > sauvegarde.sql
# Import
psql "postgresql://USER:MOT_DE_PASSE@HOTE:5432/BASE?sslmode=require" < sauvegarde.sql
The Data tab of a managed database imports an SQL or CSV file of up to 64 MB and exports up to 100,000 rows. The Backups tab of a project database schedules dumps (Backups and restore).
Limits to know
- On a managed database, your account owns its database and nothing else. It creates neither a database nor a role: additional accounts are created in the Accounts section.
- A project database runs as a single instance, with at most 1 vCPU and 1 GB of memory.
- Webgune does not create indexes for you. Index the columns of your
WHEREandJOINclauses.
Common errors
| Message | Cause | What to do |
|---|---|---|
too many connections for role | the account's connection limit is reached | reduce the pool, close the pool on receiving SIGTERM |
no pg_hba.conf entry ... no encryption or SSL required | connection without TLS to a managed database | add ?sslmode=require |
password authentication failed | stale password after a rotation | update DATABASE_URL |
could not translate host name | internal address used outside the project | use public access or a managed database |
permission denied to create database | a managed database's account does not create databases | create another managed database in the panel |
Updated on