I'm looking for help with TypeORM and PostgreSQL. To avoid long running queries, I would like to set a statement timeout at the connection level.
How can I do this?
Connection config that's working for me:
{
name: "default",
// .....
extra: {
application_name: "your_app_name",
statement_timeout: 30000 // 30s
}
}
We can check how these extra options are used in the driver: https://github.com/typeorm/typeorm/blob/68a5c230776f6ad4e3ee7adea5ad4ecdce033c7e/src/driver/postgres/PostgresDriver.ts#L1361
Available options are listed here: https://node-postgres.com/api/pool
And here: https://node-postgres.com/api/client
The config passed to the pool is also passed to every client instance within the pool when the pool creates that client.
maxQueryExecutionTimeIf query execution time exceed this given max execution time (in milliseconds) then logger will log this query.
If that doesn't do what you want you can use extra to send postgres driver configuration.
extra- Extra connection options to be passed to the underlying driver. Use it if you want to pass extra settings to underlying database driver.
maxQueryExecutionTime which is why I also pointed out extra and you can send more postgres specifc params through that. node-postgres.com/api/clientextra. Thank you very much for your time Jim, I'll take a look further. I already upvoted your answer.For PostgreSQL you can pass query_timeout option directly to pg driver through extra.
{
type: 'postgres',
...
extra: {
query_timeout: 2500
}
}
https://github.com/typeorm/typeorm/issues/5429#issuecomment-939919873