Wiring this database into a NestJS backend running on the same host, next to Elasticsearch and Redis.
Scope: this is an integration reference only. This repository provides the database — it contains no NestJS application code. The snippets below belong in your separate NestJS project; copy what you need. Nothing here needs to be added to this repo.
Host: 127.0.0.1
Port: 15409
User: local_dev
Password: <your .env value>
Database: local_db
URL: postgresql://local_dev:<password>@127.0.0.1:15409/local_db
Put it in your NestJS app's .env (separate from this repo's .env):
DATABASE_URL=postgresql://local_dev:<password>@127.0.0.1:15409/local_db// app.module.ts
TypeOrmModule.forRoot({
type: 'postgres',
url: process.env.DATABASE_URL,
autoLoadEntities: true,
synchronize: false, // use migrations, even in dev
// Keep the pool small — Postgres max_connections is 50 and shared.
extra: { max: 10, idleTimeoutMillis: 30000 },
});// schema.prisma
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}# Cap the pool so NestJS doesn't exhaust connections.
DATABASE_URL="postgresql://local_dev:<password>@127.0.0.1:15409/local_db?connection_limit=10&pool_timeout=20"Enable extensions you use (e.g. pgvector) in a migration:
// already created by this repo, but Prisma can manage them too:
generator client {
provider = "prisma-client-js"
previewFeatures = ["postgresqlExtensions"]
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
extensions = [vector, pg_trgm, uuid_ossp(map: "uuid-ossp")]
}max_connections = 50 is shared by all clients. If you run NestJS in watch
mode (which may spawn extra connections), plus a migration tool, plus a GUI, you
can exhaust it. Guidance:
- Keep each app pool ≤ 10.
- For many short-lived connections, add PgBouncer in front (transaction
pooling). A drop-in service can be added to
docker-compose.ymllater. - Symptoms of exhaustion:
FATAL: sorry, too many clients already. Fix: lower app pool size, or raisemax_connections(costs RAM — see doc 5).
If your NestJS service is also a Compose service and you want it on the same
Docker network, attach it to this repo's network and use the service name
instead of 127.0.0.1:
# in your app's compose file
services:
api:
networks: [local_net]
environment:
DATABASE_URL: postgresql://local_dev:<password>@local-postgres:5432/local_db
networks:
local_net:
external: true
name: local_netInside the Docker network the port is 5432 (container port), not 15409.
CREATE TABLE documents (
id bigserial PRIMARY KEY,
content text,
embedding vector(1536)
);
CREATE INDEX ON documents USING hnsw (embedding vector_cosine_ops);// nearest neighbours
await dataSource.query(
`SELECT id, content FROM documents ORDER BY embedding <=> $1 LIMIT 5`,
[`[${embedding.join(',')}]`],
);✅ Next: never lose data → 7. Backup & Restore »