Pavan Akurathi
Pavan Akurathi
DTDrizzle Team
Created by Pavan Akurathi on 4/25/2024 in #help
max connections time out
import { Injectable, Scope } from '@nestjs/common';
import { Pool, PoolConfig } from 'pg';
import { drizzle, NodePgDatabase } from 'drizzle-orm/node-postgres';
import { ConfigService } from '@nestjs/config';
import { sql } from 'drizzle-orm';
import { migrate } from 'drizzle-orm/node-postgres/migrator';
import { join } from 'path';

@Injectable({
scope: Scope.TRANSIENT,
})
export class DrizzleService {
private pool: Pool;
private db: NodePgDatabase;

constructor(private configService: ConfigService) {
void this.connect();
}

private async connect(): Promise<void> {
const poolConfig = {
connectionString: this.configService.getOrThrow('database.databaseUrl'),
ssl: false,
keepAlive: true,
max: this.configService.get('database.maxConnections') ?? 1,
};
this.pool = new Pool(poolConfig);
this.db = drizzle(this.pool, {
logger: true,
});
try {
await migrate(this.db, {
migrationsFolder: join(__dirname, '/migrations'),
});
} catch (error) {
console.log(error, '-=-=-=-=-=-=->>');
}
}
import { Injectable, Scope } from '@nestjs/common';
import { Pool, PoolConfig } from 'pg';
import { drizzle, NodePgDatabase } from 'drizzle-orm/node-postgres';
import { ConfigService } from '@nestjs/config';
import { sql } from 'drizzle-orm';
import { migrate } from 'drizzle-orm/node-postgres/migrator';
import { join } from 'path';

@Injectable({
scope: Scope.TRANSIENT,
})
export class DrizzleService {
private pool: Pool;
private db: NodePgDatabase;

constructor(private configService: ConfigService) {
void this.connect();
}

private async connect(): Promise<void> {
const poolConfig = {
connectionString: this.configService.getOrThrow('database.databaseUrl'),
ssl: false,
keepAlive: true,
max: this.configService.get('database.maxConnections') ?? 1,
};
this.pool = new Pool(poolConfig);
this.db = drizzle(this.pool, {
logger: true,
});
try {
await migrate(this.db, {
migrationsFolder: join(__dirname, '/migrations'),
});
} catch (error) {
console.log(error, '-=-=-=-=-=-=->>');
}
}
I am trying to initiate the migrations and end it once done but it is going in loop error: Authentication error, reason: "Authentication query failed: %DBConnection.ConnectionError{message: "connection not available and request was dropped from queue after 10000ms. This means requests are coming in and your connection pool cannot serve them fast enough. You can address this by:\n\n 1. Ensuring your database is available and that you can connect to it\n 2. Tracking down slow queries and making sure they are running fast enough\n 3. Increasing the pool_size (although this increases resource consumption)\n 4. Allowing requests to wait longer by increasing :queue_target and :queue_interval\n\nSee DBConnection.start_link/2 for more information\n", severity: :error, reason: :queue_timeout}"
1 replies