|
|
|
@ -1,7 +1,8 @@ |
|
|
|
import pg from "pg"; |
|
|
|
|
|
|
|
export async function getClient() { |
|
|
|
// Create a connection pool instead of individual connections
|
|
|
|
const pool = new pg.Pool({ |
|
|
|
const pool = new pg.Pool({ |
|
|
|
user: process.env.POSTGRES_USER, |
|
|
|
password: process.env.POSTGRES_PASSWORD, |
|
|
|
host: process.env.POSTGRES_HOST, |
|
|
|
@ -11,9 +12,9 @@ const pool = new pg.Pool({ |
|
|
|
idleTimeoutMillis: 30000, // Close idle connections after 30 seconds
|
|
|
|
connectionTimeoutMillis: 10000, // Increased timeout to 10 seconds
|
|
|
|
acquireTimeoutMillis: 10000, // Wait up to 10 seconds for a connection
|
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
export async function getClient() { |
|
|
|
// Use pool.connect() instead of creating new clients
|
|
|
|
return await pool.connect(); |
|
|
|
} |
|
|
|
|