我在Rails 4中使用Apartment gem在Heroku上的Postgres 9.3.3中支持多租户。
I use Apartment gem in Rails 4 to support multi-tenancy in Postgres 9.3.3 on Heroku.
Apartment gem创建新租户时发生错误。
An error is occurred when Apartment gem creates a new tenant.
深入调查显示,已创建模式,但内部没有表。
Deep investigation showed that a schema was created, but no tables inside.
Heroku日志显示错误:
Heroku logs showed an error:
PG::Error: ERROR: function pg_stat_statements_reset() does not exist推荐答案
创建新的模式Postgres试图通过执行功能 pg_stat_statements_reset()
When a new schema is created Postgres is trying to reset stats by executing the function pg_stat_statements_reset()
来重置统计信息,默认情况下,该功能只能由超级用户执行(来自原始文档)。
By default, this function can only be executed by superusers (from original doc).
Heroku没有给您超级用户特权。 因此,您需要禁用扩展pg_stat_statements。
Heroku doesn't give you superuser privileges. So you need to disable extension pg_stat_statements.
解决方案1-直接在数据库中快速快速修复
在架构 public
DROP EXTENSION pg_stat_statements;解决方案2-通过迁移
1)检查文件 db / schema.rb 。
enable_extension "pg_stat_statements"2)创建迁移文件
rails g migration DropExtensionPgStatStatements3)定义self.up方法
3) define self.up method
def self.up disable_extension "pg_stat_statements" end4)应用迁移
rake db:migrate5)现在文件 db / schema.rb 不应包含该行
5) Now the file db/schema.rb should not contain that line
6)提交更改(模式和迁移文件)并部署到Heroku
6) Commit changes (schema and migration files) and deploy to Heroku
rake deploy:production:migrations关于耙任务,请参见 deploy.rake
更多推荐
Heroku +公寓PG ::错误:错误:函数pg
发布评论