Benchmarking PostgreSQL Drivers in Node.js: node-postgres vs postgres.js



This content originally appeared on DEV Community and was authored by Nigro Simone

When building high-performance Node.js applications with PostgreSQL, choosing the right driver can have a noticeable impact on query latency and throughput. To compare the most popular options, we ran a benchmark using mitata to test four approaches:

Source code at https://github.com/nigrosimone/postgres-benchmarks

Running benchmarks... --iterations=50000
GC is exposed
clk: ~3.37 GHz
cpu: Intel(R) Core(TM) i7-1065G7 CPU @ 1.30GHz
runtime: node 24.7.0 (x64-linux)

benchmark                       avg (min … max) p75 / p99    (min … top 1%)
----------------------------------------------- -------------------------------
brianc/node-postgres (pg-native) 162.75 µs/iter 154.46 µs  █
                          (113.08 µs … 1.12 ms) 429.87 µs  █▆
                        (  7.07 kb …   2.87 mb)  11.79 kb ▁██▄▂▂▂▂▂▂▁▁▁▁▁▁▂▁▁▁▁

brianc/node-postgres (pg)        172.63 µs/iter 180.84 µs  █
                          (126.98 µs … 1.15 ms) 432.69 µs ▃█
                        (376.00  b …   3.11 mb)  14.99 kb ██▆▅▃▃▃▂▃▂▂▁▁▁▁▁▁▁▁▁▁

porsager/postgres (postgres)     182.95 µs/iter 205.09 µs  █
                          (126.69 µs … 1.16 ms) 449.84 µs  █▇
                        (  2.26 kb … 980.01 kb)  11.69 kb ▁██▄▃▄▅▃▃▂▂▁▁▁▁▁▁▁▁▁▁

porsager/postgres (unsafe)       193.00 µs/iter 193.41 µs  █
                          (143.72 µs … 1.14 ms) 547.31 µs  █
                        (  6.77 kb … 517.28 kb)   9.30 kb ███▅▃▃▂▂▂▁▁▁▁▁▁▁▁▁▁▁▁

summary
  brianc/node-postgres(pg-native)
   1.06x faster than brianc/node-postgres (pg)
   1.12x faster than porsager/postgres (postgres)
   1.19x faster than porsager/postgres (unsafe)

pg-native Wins

The pg-native driver leverages libpq, the official PostgreSQL C client library. This allows faster query parsing, lower overhead on network I/O, and better memory handling than the pure JavaScript implementation (pg). Essentially, pg-native skips part of the JS-to-database abstraction cost.

pg Is Close Behind

Despite being pure JavaScript, pg remains very efficient and stable. The performance gap (~6%) is small and might not be noticeable in real-world apps unless you’re processing tens of thousands of queries per second.

Conclusion

For high-throughput Node.js applications where microseconds matter, pg-native consistently outperforms both pg and postgres.js. However, the difference isn’t massive — your choice should balance performance, API design, and operational complexity.


This content originally appeared on DEV Community and was authored by Nigro Simone