postgresql 如何配置TypeScript连接池?

hgncfbus  于 2023-11-18  发布在  PostgreSQL
关注(0)|答案(1)|浏览(165)

我使用了TypeScript和NestJS
我想配置连接池超过10个。
但总是最大连接10.

// My Typeorm config
import { TypeOrmModuleOptions } from '@nestjs/typeorm'
import * as dotenv from 'dotenv'
import { SnakeNamingStrategy } from 'typeorm-naming-strategies'

const config: TypeOrmModuleOptions = {
  type: 'postgres',
  host: process.env.POSTGRES_HOST,
  port: parseInt(process.env.POSTGRES_PORT || '5432'),
  username: process.env.POSTGRES_USER,
  password: process.env.POSTGRES_PASS,
  database: process.env.POSTGRES_DATABASE,
  entities: ['src/**/*.entity{.ts,.js}'],
  namingStrategy: new SnakeNamingStrategy(),
  migrationsTableName: 'migration',
  migrations: ['src/db/migrations/*.ts'],
  cli: {
    migrationsDir: 'src/db/migrations',
  },
  extra: {
    max: 30
  }
}

export default config

字符串
我应该做什么postgres连接超过10?

wfsdck30

wfsdck301#

您需要调整poolSize,下面的示例将其调整为20。

// My Typeorm config
import { TypeOrmModuleOptions } from '@nestjs/typeorm'
import * as dotenv from 'dotenv'
import { SnakeNamingStrategy } from 'typeorm-naming-strategies'

const config: TypeOrmModuleOptions = {
  type: 'postgres',
  host: process.env.POSTGRES_HOST,
  port: parseInt(process.env.POSTGRES_PORT || '5432'),
  username: process.env.POSTGRES_USER,
  password: process.env.POSTGRES_PASS,
  database: process.env.POSTGRES_DATABASE,
  entities: ['src/**/*.entity{.ts,.js}'],
  namingStrategy: new SnakeNamingStrategy(),
  migrationsTableName: 'migration',
  migrations: ['src/db/migrations/*.ts'],
  cli: {
    migrationsDir: 'src/db/migrations',
  },
  poolSize: 20,
}

export default config

字符串
来源:https://typeorm.io/data-source-options#common-data-source-options

相关问题