Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to set poolSize for postgres driver? #3388

Closed
wederer opened this issue Jan 8, 2019 · 13 comments · Fixed by #9305 · May be fixed by antz-snyk1/gradle-npm-monorepo-example#5
Closed

How to set poolSize for postgres driver? #3388

wederer opened this issue Jan 8, 2019 · 13 comments · Fixed by #9305 · May be fixed by antz-snyk1/gradle-npm-monorepo-example#5

Comments

@wederer
Copy link
Contributor

wederer commented Jan 8, 2019

Issue type:

[x] question
[ ] bug report
[ ] feature request
[ ] documentation issue

Database system/driver:

[ ] cordova
[ ] mongodb
[ ] mssql
[ ] mysql / mariadb
[ ] oracle
[x] postgres
[ ] sqlite
[ ] sqljs
[ ] react-native
[ ] expo

TypeORM version:

[x] latest
[ ] @next
[ ] 0.x.x (or put your version here)

I have found this answer on Stackoverflow how to set the poolSize for node-postgres. How can I set it wit TypeORM?
@pleerock commented here that the extra argument can be used.

So like this?

{
  ...,
  "extra": { poolSize: 10 }
}

Thanks

@vlapo
Copy link
Contributor

vlapo commented Jan 9, 2019

Typeorm will pass extra to node-postgres Pool. Config is here https://node-postgres.com/api/pool.

So you have to define extra as:

{
  ...,
  "extra": { max: 10 }
}

But I think we should add this options to PostgresConnectionOptions since we are using pooling every time.

@damianmigo
Copy link

According to the Pool class of the Postgres driver, both options (max or poolSize) should work:

class Pool extends EventEmitter {
  constructor (options, Client) {
    super()
    this.options = Object.assign({}, options)
    this.options.max = this.options.max || this.options.poolSize || 10

@wederer
Copy link
Contributor Author

wederer commented Jan 13, 2019

@damianmigo Thanks!

@pleerock
Copy link
Member

Since most of drivers support connection pool, we should extract this option into top-level connection options and add docs to it.

@wederer
Copy link
Contributor Author

wederer commented Jan 21, 2019

@pleerock Should I open a seperate issue for your suggestion?

@pleerock
Copy link
Member

@wederer no, we can keep this open until somebody create a PR

@jpollard-cs
Copy link

jpollard-cs commented Jul 9, 2019

to save future travelers time - if you're wondering if the typeorm pg driver uses the pg Pool under the hood: it does indeed (at least at the time of this writing)

@emlynmac
Copy link

emlynmac commented Mar 14, 2020

I arrived here because I need to do some performance tuning of a production instance. One of the things I don't see how to do currently is to get the number of connections active or waiting.
It would be really great to pull out the pool object to be available externally for logging purposes.
From the pg driver:

pool.totalCount: int

The total number of clients existing within the pool.

pool.idleCount: int

The number of clients which are not checked out but are currently idle in the pool.

pool.waitingCount: int

The number of queued requests waiting on a client when all clients are checked out. It can be helpful to monitor this number to see if you need to adjust the size of the pool.

@Esqarrouth
Copy link

Typeorm will pass extra to node-postgres Pool. Config is here https://node-postgres.com/api/pool.

So you have to define extra as:

{
  ...,
  "extra": { max: 10 }
}

But I think we should add this options to PostgresConnectionOptions since we are using pooling every time.

inside ormconfig?

@jacobgoh101
Copy link

"extra": { max: 10 }

This works for controlling the connection pool size. But when my server has more than 10 concurrent queries, I need to add connectionTimeoutMillis: 1000 as well. Otherwise, some TypeORM queries will never respond.

  extra: {
    // based on  https://node-postgres.com/api/pool
    // max connection pool size
    max: 10,
    // connection timeout
    connectionTimeoutMillis: 1000,
  },

pleerock pushed a commit that referenced this issue Sep 19, 2022
Added `poolSize` option everywhere to controll pool option

Closes: #3388

Co-authored-by: mortzprk <mortz.prk@gmail.com>
@beez-dev
Copy link

According to the Pool class of the Postgres driver, both options (max or poolSize) should work:

class Pool extends EventEmitter {
  constructor (options, Client) {
    super()
    this.options = Object.assign({}, options)
    this.options.max = this.options.max || this.options.poolSize || 10

is there any tool to given a statistically verifiable output , if pooling is working as expected?

@anandrmedia
Copy link

There is a common poolSize property in DataSourceOptions that specifies the maximum number of active connections in the pool.

@albr74
Copy link

albr74 commented Apr 24, 2024

Hi guys.

I would like have more control on connection pool, but I couldn´t find more options about the pool. Please, can you help me about this?

For example:

  1. Max connections: I think it is the parameter max cited previously.
  2. Min connections: The minimum available connections when the application starts. It is important in applications with a high number of clients. When the application starts this number of connections are available initially. And if there are no interactions with the application this number of connection is kept opened all the time.
  3. Increase connections: if min connections is consumed, new connections need to be created. This parameter sets how many new connections will be created.

Are there these parameters (2 and 3) in TypeORM?

Thanks :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet