11

I can't find any documentation for the node-postgres drive on setting the maximum connection pool size, or even finding out what it is if it's not configurable. Does anyone know how I can set the maximum number of connections, or what it is by default?

0

2 Answers 2

14

defaults are defined in node-postgres/lib/defaults https://github.com/brianc/node-postgres/blob/master/lib/defaults.js

poolSize is set to 10 by default, 0 will disable any pooling.

var pg = require('pg');
pg.defaults.poolSize = 20;

Note that the pool is only used when using the connect method, and not when initiating an instance of Client directly.

Sign up to request clarification or add additional context in comments.

Comments

-9

node.js is single threaded why want to have more then 1 connection to db per process ? Even when you will cluster node.js processes you should have 1 connection per process max. Else you are doing something wrong.

2 Comments

node.js battle cry is non-blocking IO, having a single connection basically makes it a blocking call for that resource! Simply, a query that takes 1 minute can only handle 1 query per minute, so a connection pool of 10 connections would allow 10 queries per minute
@Jakub - Each connection has a query queue, so yeah, if you had only one connection, the n'th query would be dispatched only as the n-1'th query is completed. If you have multiple connections, you have multiple queues and none of them necessarily block each other. The reason we pool connections is because they are relatively expensive to create and destroy.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.