| @@ -67,6 +67,20 @@ type SqlRuntime = { · 66 unmodified lines |
| 67 | close: () => Promise<void>; | 67 | close: () => Promise<void>; |
| 68 | }; | 68 | }; |
| 69 | | 69 | |
| | 70 | const resolvePostgresMaxConnections = (): number => { |
| | 71 | const configured = process.env.CONTROL_PLANE_POSTGRES_MAX_CONNECTIONS |
| | 72 | ?? process.env.POSTGRES_MAX_CONNECTIONS; |
| | 73 | |
| | 74 | if (configured) { |
| | 75 | const parsed = Number.parseInt(configured, 10); |
| | 76 | if (Number.isFinite(parsed) && parsed > 0) { |
| | 77 | return parsed; |
| | 78 | } |
| | 79 | } |
| | 80 | |
| | 81 | return process.env.NODE_ENV === "production" ? 1 : 10; |
| | 82 | }; |
| | 83 | |
| 70 | const sanitizePostgresUrl = (value: string): string => { | 84 | const sanitizePostgresUrl = (value: string): string => { |
| 71 | try { | 85 | try { |
| 72 | const parsed = new URL(value); | 86 | const parsed = new URL(value); |
| @@ -108,7 +122,7 @@ const createPostgresRuntime = async ( · 35 unmodified lines |
| 108 | ): Promise<SqlRuntime> => { | 122 | ): Promise<SqlRuntime> => { |
| 109 | const client = postgres(sanitizePostgresUrl(databaseUrl), { | 123 | const client = postgres(sanitizePostgresUrl(databaseUrl), { |
| 110 | prepare: false, | 124 | prepare: false, |
| 111 | max: 10, | 125 | max: resolvePostgresMaxConnections(), |
| 112 | ...(applicationName ? { connection: { application_name: applicationName } } : {}), | 126 | ...(applicationName ? { connection: { application_name: applicationName } } : {}), |
| 113 | }); | 127 | }); |
| 114 | | 128 | |