Skip to main content
Version: v6 - stable

连接池

如果你从单个进程连接到数据库,则应该仅创建一个 Sequelize 实例。Sequelize 将在初始化时设置一个连接池。这个连接池可以通过构造函数的 options 参数(使用 options.pool)来配置,如下例所示:

¥If you're connecting to the database from a single process, you should create only one Sequelize instance. Sequelize will set up a connection pool on initialization. This connection pool can be configured through the constructor's options parameter (using options.pool), as is shown in the following example:

const sequelize = new Sequelize(/* ... */, {
// ...
pool: {
max: 5,
min: 0,
acquire: 30000,
idle: 10000
}
});

Sequelize 构造函数的 API 参考 中了解更多信息。如果你从多个进程连接到数据库,则必须为每个进程创建一个实例,但每个实例都应具有最大连接池大小,以便遵守总最大大小。例如,如果你希望最大连接池大小为 90 并且拥有三个进程,则每个进程的 Sequelize 实例的最大连接池大小应为 30。

¥Learn more in the API Reference for the Sequelize constructor. If you're connecting to the database from multiple processes, you'll have to create one instance per process, but each instance should have a maximum connection pool size of such that the total maximum size is respected. For example, if you want a max connection pool size of 90 and you have three processes, the Sequelize instance of each process should have a max connection pool size of 30.