Skip to content

Commit 68c0f8e

Browse files
authored
chore: use native libpq for postgres access (#304)
1 parent 27f2a68 commit 68c0f8e

File tree

4 files changed

+51
-4
lines changed

4 files changed

+51
-4
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
FROM node:20
22

33
RUN apt-get -y update && \
4-
apt-get install -y git && \
4+
apt-get install -y git libpq-dev && \
55
mkdir -p /home/node/app/node_modules && \
66
chown -R node:node /home/node/app
77

package-lock.json

Lines changed: 43 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
"node_extra_ca_certs_mozilla_bundle": "^1.0.7",
6464
"pg": "^8.16.2",
6565
"pg-format": "^1.0.4",
66+
"pg-native": "^3.5.2",
6667
"pg-pool": "^3.10.1",
6768
"postgrator": "^8.0.0",
6869
"postgrator-cli": "^9.0.0",

src/database/repository.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ import format from "pg-format";
33
import { ALGORITHM_VERSION } from "../constants.js";
44
import pg from "pg";
55

6-
const { Pool } = pg;
6+
// Use native bindings instead of standard bindings
7+
// @ts-ignore - pg.native is optional and may not be in types
8+
const { Pool } = pg.native || pg; // Fallback to standard pg if native not available
79

810
/**
911
* @typedef {import("pg").Pool} Pool
@@ -19,10 +21,11 @@ export const poolOptions = {
1921
password: CONFIG.database.pass,
2022
port: CONFIG.database.port,
2123
ssl: CONFIG.database.sslmode,
22-
max: 80, // set pool max size to 80
23-
idleTimeoutMillis: 10000, // close idle clients after 10 seconds
24+
max: 40, // set pool max size to 40
25+
idleTimeoutMillis: 60000, // close idle clients after 60 seconds
2426
connectionTimeoutMillis: 2000, // return an error after 2 seconds if connection could not be established
2527
maxUses: 10000, // close (and replace) a connection after it has been used 10000 times
28+
native: true,
2629
};
2730

2831
/**

0 commit comments

Comments
 (0)