Lazer_Pope (Vossi / Hendrik)
DTDrizzle Team
•Created by Lazer_Pope (Vossi / Hendrik) on 1/14/2025 in #help
Connection pool size > 1 leads to very erroneous DB behaviour
Heyo,
I am using SvelteKit and Drizzle with a Postgres DB.
When doing a lot of concurrent requests to my backend and with a connection pool with a max values > 1, I get a lot of weird behaviour.
Sometimes after an insert, drizzle returns a correct looking DBO with an ID, but that row has never been inserted into postgres.
The same happens for deletes, the drizzle response tells me that the row has been deleted, but it just remains in the database.
I am not getting any errors, only warnings in postgres about transactions either being already in postgres or not existing. But these warnings to not directly correlate with the stated behaviour.
4 replies
DTDrizzle Team
•Created by Lazer_Pope (Vossi / Hendrik) on 1/13/2025 in #help
Missing database entries under heavy load
If my server is under heavy load with many concurrent requests, inserts sometimes pretend to save a new object to the databse, return the DBO (which look correct), but then selecting that same entries returns nothing?
export async function insertProject(projectDto: InsertProject, userId: number) {
const formFiles = projectDto.addFiles;
try {
if (!isModuleEnabled('projectCustomFields')) projectDto.isMeasurementApproved = true;
const dbos = await db
.insert(projects)
.values({ ...projectDto, updatedBy: userId })
.returning();
const dbo = dbos[0];
await updateProjectDependencies(dbo.id, projectDto);
const projectJobs = await db.select().from(jobs).where(eq(jobs.projectId, dbo.id));
await setJobUsers(projectJobs, dbo, projectDto.measurementUsers ?? []);
if (projectDto.changeNote) await insertProjectChangeNote(userId, dbo.id, projectDto.changeNote);
await insertFiles(formFiles, dbo.id, 'projects', 'project');
sendEventTo('projects');
await insertProjectHistory(userId, 'project:create', dbo);
await recalculateProjectStartAndEndDates(dbo.id);
const test = await db.select().from(projects).where(eq(projects.id, dbo.id));
console.log('Inserted project with ID: ', dbo.id, dbos.length);
console.log('🚀 ~ insertProject ~ test:', dbo.id, test.length);
return dbo;
} catch (e) {
console.error('🚀 ~ insertProject ~ e:', e);
handleErrorBackend(e);
}
}
The variable dbos always looks correct, with the expected values and a matching ID. But selecting that same id in the variable test sometimes returns an empty array (even though dbos contained the correct object)
0|solid | Inserted project with ID: 78763 1
0|solid | 🚀 ~ insertProject ~ test: 78763 0
0|solid | Inserted project with ID: 78761 1
0|solid | 🚀 ~ insertProject ~ test: 78761 1
0|solid | Inserted project with ID: 78764 1
0|solid | 🚀 ~ insertProject ~ test: 78764 02 replies
DTDrizzle Team
•Created by Lazer_Pope (Vossi / Hendrik) on 6/25/2024 in #help
Connection terminated unexpectedly after adding postgres.conf
Heyo, after adding a postgres.conf to my db, I always get 'Connection terminated unexpectedly'. I've tried multiple config setups, and this error arises as soon as I add any config to postgres.
This is my docker postgres setup:
db:
container_name: db
image: postgres:13
platform: linux/x86_64
ports:
- '5432:5432'
environment:
POSTGRES_USER: root
POSTGRES_PASSWORD: 123
POSTGRES_DB: solid-hour-2
volumes:
- ./postgres.conf:/etc/postgresql/postgresql.conf
- ./data:/var/lib/postgresql/data
command: postgres -c config_file=/etc/postgresql/postgresql.conf
This is a conf straight from the postgres website:
# This is a comment
log_connections = yes
log_destination = 'syslog'
search_path = '"$user", public'
shared_buffers = 128MB
And this is the error from drizzle:
Error: Connection terminated unexpectedly
at /Users/user/Documents/solid-hour/repos/solid-hour-2-fullstack/node_modules/pg-pool/index.js:45:11
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async PgDialect.migrate (file:///Users/user/Documents/solid-hour/repos/solid-hour-2-fullstack/node_modules/drizzle-orm/pg-core/dialect.js:37:5)
at async Module.migrate (file:///Users/user/Documents/solid-hour/repos/solid-hour-2-fullstack/node_modules/drizzle-orm/node-postgres/migrator.js:4:3)
at async Module.initDb (/Users/user/Documents/solid-hour/repos/solid-hour-2-fullstack/src/lib/server/db/db.ts:66:5)
at async eval (/Users/user/Documents/solid-hour/repos/solid-hour-2-fullstack/src/hooks.server.ts:13:3)
at async instantiateModule (file:///Users/user/Documents/solid-hour/repos/solid-hour-2-fullstack/node_modules/vite/dist/node/chunks/dep-jvB8WLp9.js:54897:9)
Adding the same settings via environment variables works, though.7 replies
DTDrizzle Team
•Created by Lazer_Pope (Vossi / Hendrik) on 10/16/2023 in #help
Automatic migrationbs
Heyo,
I am currently thinking about using SvelteKit with drizzle for a new project. Currently I use NestJs +TypeOrm, and one thing I like is that my migrations get automatically applied whenever I push an update into production.
(Work locally, change database entities (e.g. add a column, create a new seed query), and I don't have to worry about manually starting any migrations on the client's server).
Is the same possible in drizzle?
2 replies