I use Apartment gem in Rails 4 to support multi-tenancy in Postgres 9.3.3 on Heroku.
An error is occurred when Apartment gem creates a new tenant.
Deep investigation showed that a schema was created, but no tables inside.
Heroku logs showed an error:
PG::Error: ERROR: function pg_stat_statements_reset() does not exist
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 doesn't give you superuser privileges. So you need to disable extension pg_stat_statements.
Solution 1 - Quick hot fix directly in DB
Access the Rails Console for your Heroku app:
heroku run rails c
Execute SQL statement in schema public:
ActiveRecord::Base.connection.execute("DROP EXTENSION pg_stat_statements;")
Solution 2 - via migration
Check the file db/schema.rb. Most probably it contains a line
enable_extension "pg_stat_statements"
Create a migration file
rails g migration DropExtensionPgStatStatements
define self.up method
def self.up disable_extension "pg_stat_statements" end
apply the migration
rake db:migrate
Now the file db/schema.rb should not contain that line
Commit changes (schema and migration files) and deploy to Heroku
rake deploy:production:migrations
Regarding the rake task see deploy.rake
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With