Heroku + Apartment PG :: Error: ERROR: pg_stat_statements_reset () function does not exist

I use the pearl of apartments in Rails 4 to support multi-tenancy at Postgres 9.3.3 on Heroku.

An error occurred when the pearl of the apartment creates a new tenant.

An in-depth study showed that a diagram was created, but there are no tables inside.

Heroku logs showed an error:

PG::Error: ERROR: function pg_stat_statements_reset() does not exist 
+5
source share
1 answer

When creating a new schema, Postgres tries to reset statistics by executing the pg_stat_statements_reset () function

By default, this function can only be performed by superusers (from the original document) .

Heroku does not give you superuser privileges. Therefore, you need to disable the pg_stat_statements extension.

Solution 1 - Quick fix directly in DB

Executing an SQL statement in a public schema

 DROP EXTENSION pg_stat_statements; 

Solution 2 - Using Migration

1) Check the db / schema.rb file. Most likely it contains a string

 enable_extension "pg_stat_statements" 

2) Create a migration file

 rails g migration DropExtensionPgStatStatements 

3) define the self.up method

 def self.up disable_extension "pg_stat_statements" end 

4) apply migration

 rake db:migrate 

5) Now the db / schema.rb file should not contain this line

6) Commit the changes (schemas and migration files) and deploy them to Heroku

 rake deploy:production:migrations 

Regarding the rake task, see deploy.rake

+11
source

Source: https://habr.com/ru/post/1213123/


All Articles