Sail.js启动时有多个连接

问题描述 投票:2回答:3

我有一个奇怪的问题 - 在启动我的风帆应用程序(连接postgres并部署在heroku上)有多个连接(大约10个)到数据库,并且由于它是免费帐户,如果我然后尝试启动应用程序localhost测试一些新代码我得到一个错误“角色连接太多”。那么有谁知道为什么有这么多的数据库连接,我可以更改它,每个应用程序只有一个连接?

编辑:创建与Postgresql的连接时出错:错误:角色“xwoellnkvjcupt”连接太多错误创建与Postgresql的连接时出错:错误:角色“xwoellnkvjcupt”的连接太多错误:挂钩无法加载:orm(错误:连接太多for role“xwoellnkv jcupt”)错误:加载Sails核心时遇到错误!错误:错误:Connection.parseMessage上Connection.parseE(C:\ Studia \ szachman2 \ node_modules \ sails-postgresql \ node _modules \ pg \ lib \ connection.js:561:11)中角色“xwoellnkvjcupt”的连接太多( C:\ Studia \ szachman2 \ node_modules \ sails-postgresq l \ node_modules \ pg \ lib \ connection.js:390:17)at null。 (C:\ Studia \ szachman2 \ node_modules \ sails-postgresql \ node_ modules \ pg \ lib \ connection.js:98:18)在CleartextStream的CleartextStream.EventEmitter.emit(events.js:95:17)。 (_stream_readable.js:746:14)位于emit_adable_j上的发文阅读时,发送者可以在发票阅读时发送电子邮件发送电子邮箱,发送电子邮箱发送电子邮箱,发送电子邮箱,发送电子邮件发送电子邮箱中JS:459:13)

这是我在尝试在localhost上测试一些新代码时经常遇到的错误。

postgresql heroku sails.js waterline
3个回答
5
投票

@jantar @ sgress454我just addedsails-postgresql中的一个故障排除消息,试图让这更好。这就是它所说的:

- >也许你的poolSize配置设置得太高了?例如如果你的Postgresql数据库只支持20个并发连接,你应该确保你的poolSize设置为<20。默认的poolSize是10。

要覆盖默认的poolSize,请在相关的Postgresql“connection”配置对象上指定poolSize属性。如果您正在使用Sails,则通常位于config/connections.js中,或者设置特定于环境的数据库配置的位置。

- >你有多个Sails实例共享同一个Postgresql数据库吗?每个Sails实例最多可使用配置的poolSize连接数。假设所有Sails实例都只是彼此的副本(合理的最佳实践),我们可以通过将配置的poolSize(P)乘以Sails实例(N)的数量来计算所使用的Postgresql连接的实际数量(C)。如果实际连接数(C)超过了Postgresql数据库(V)的AVAILABLE连接总数,那么就会出现问题。如果这适用于您,请尝试减少poolSize配置。合理的poolSize设置为V / N.


1
投票

这是由于Sails的自动迁移功能,它试图让您的模型和数据库同步。它不打算用于生产。您可以通过将migrate: safe添加到模型定义来关闭单个模型上的自动迁移:

module.exports = {
    migrate: 'safe',
    attributes: {...}
}

您可以通过添加model配置来关闭所有型号的自动迁移,通常在您的config/locals.js中:

module.exports = {

    model: {
        migrate: 'safe'
    },
    environment: 'production',
    ...other local config...
}

0
投票

V1的一点点更新。如果要为连接池设置最大大小,config / datastore.js中的适配器应如下所示:

{
  adapter: 'sails-postgresql',
  url: 'yourconnectionurl',
  max: 1 // This is the important part for poolSize, I set 1 because I don't want more than 1 connection ^^
}

如果你想知道你可以设置的所有信息,请看这里:https://github.com/sailshq/machinepack-postgresql/blob/176413efeab90dc5099dc60718e8b520942ce3be/machines/create-manager.js,第162行:

// Basic:
        'host', 'port', 'database', 'user', 'password', 'ssl',

        // Advanced Client Config:
        'application_name', 'fallback_application_name',

        // General Pool Config:
        'max', 'min', 'refreshIdle', 'idleTimeoutMillis',

        // Advanced Pool Config:
        // These should only be used if you know what you are doing.
        // https://github.com/coopernurse/node-pool#documentation
        'name', 'create', 'destroy', 'reapIntervalMillis', 'returnToHead',
        'priorityRange', 'validate', 'validateAsync', 'log'
© www.soinside.com 2019 - 2024. All rights reserved.