Typeorm Postgres ConnectionPool opening and closing for each request when using ssl

Viewed 1465

I am trying to establish a fixed connection pool using the typeorm for postgres in my rest service.

let option = {
 name: 'default',
 type: 'postgres',
 host: 'host',
 port: port,
 username: 'username',
 password: 'password',
 database: 'database',
 synchronize: true,
 dropSchema: false,
 logging: true,
 ssl: {
   ca: process.env.SSL_CERT,
 },
 entities: ['src/**/*.entity.ts'],
}

In app.ts

await createConnection(option).then(() => {
  logger.debug('Database connection established');
}).catch((error: any) => {
  logger.error('Database connection failed', error);
  throw new Error(error);
});

When the app gets initialised the connectionpool gets established via ssl but it then closes, every time a query is executed the connection is created and then closed.

But without the ssl the connectionpool does not close until the .close method is called.

It would be helpful if someone could let me know on how to prevent the connectionpool from closing.

Or is there an option to set the time to live in ssl connection for postgres but I couldn't find reference for that in typeorm documentation.

0 Answers
Related