Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Permission denied for function pg_stat_statements_reset on Azure Postgres Flexible Server #511

Closed
fpapadamis opened this issue Nov 14, 2024 · 1 comment

Comments

@fpapadamis
Copy link

fpapadamis commented Nov 14, 2024

After moving my database to Azure Postgres Flexible Server I am not able to run bin/rake pghero:capture_query_stats.
When running, I get:

rake aborted!
ActiveRecord::StatementInvalid: PG::InsufficientPrivilege: ERROR:  permission denied for function pg_stat_statements_reset
CONTEXT:  SQL function "pg_stat_statements_reset" statement 1
/usr/local/bundle/gems/activerecord-7.0.4.3/lib/active_record/connection_adapters/postgresql/database_statements.rb:48:in `exec'
/usr/local/bundle/gems/activerecord-7.0.4.3/lib/active_record/connection_adapters/postgresql/database_statements.rb:48:in `block (2 levels) in execute'
/usr/local/bundle/gems/activesupport-7.0.4.3/lib/active_support/concurrency/share_lock.rb:187:in `yield_shares'
/usr/local/bundle/gems/activesupport-7.0.4.3/lib/active_support/dependencies/interlock.rb:41:in `permit_concurrent_loads'
/usr/local/bundle/gems/activerecord-7.0.4.3/lib/active_record/connection_adapters/postgresql/database_statements.rb:47:in `block in execute'
/usr/local/bundle/gems/activesupport-7.0.4.3/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `handle_interrupt'
/usr/local/bundle/gems/activesupport-7.0.4.3/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `block in synchronize'
/usr/local/bundle/gems/activesupport-7.0.4.3/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `handle_interrupt'
/usr/local/bundle/gems/activesupport-7.0.4.3/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `synchronize'
/usr/local/bundle/gems/activerecord-7.0.4.3/lib/active_record/connection_adapters/abstract_adapter.rb:765:in `block in log'
/usr/local/bundle/gems/activesupport-7.0.4.3/lib/active_support/notifications/instrumenter.rb:24:in `instrument'
/usr/local/bundle/gems/activerecord-7.0.4.3/lib/active_record/connection_adapters/abstract_adapter.rb:756:in `log'
/usr/local/bundle/gems/activerecord-7.0.4.3/lib/active_record/connection_adapters/postgresql/database_statements.rb:46:in `execute'
/usr/local/bundle/gems/pghero-3.3.3/lib/pghero/methods/basic.rb:104:in `execute'
/usr/local/bundle/gems/pghero-3.3.3/lib/pghero/methods/query_stats.rb:94:in `reset_instance_query_stats'
/usr/local/bundle/gems/pghero-3.3.3/lib/pghero/methods/query_stats.rb:152:in `block in capture_query_stats'
/usr/local/bundle/gems/pghero-3.3.3/lib/pghero/methods/query_stats.rb:151:in `each'
/usr/local/bundle/gems/pghero-3.3.3/lib/pghero/methods/query_stats.rb:151:in `capture_query_stats'
/usr/local/bundle/gems/pghero-3.3.3/lib/pghero.rb:195:in `block in capture_query_stats'
/usr/local/bundle/gems/pghero-3.3.3/lib/pghero.rb:264:in `block in each_database'
/usr/local/bundle/gems/pghero-3.3.3/lib/pghero.rb:262:in `each'
/usr/local/bundle/gems/pghero-3.3.3/lib/pghero.rb:262:in `each_database'
/usr/local/bundle/gems/pghero-3.3.3/lib/pghero.rb:192:in `capture_query_stats'
/usr/local/bundle/gems/pghero-3.3.3/lib/tasks/pghero.rake:4:in `block (2 levels) in <top (required)>

Dropped and recreated the schema but I keep getting the same error.
Granted access to the user for the function but still the same.

When I am trying to run execute("SELECT pg_stat_statements_reset(#{quote(user_id.to_i)}, #{quote(database_id.to_i)}, #{quote(query_id.to_i)})") directly in psql like SELECT pg_stat_statements_reset(16384, 24680, 0); it runs without any errors

Context:
This database was running on GCP (pghero worked without any issues) and is now moved to Azure.

@ankane
Copy link
Owner

ankane commented Nov 14, 2024

Hi @fpapadamis, check out the Contributing Guide for where to get help.

@ankane ankane closed this as completed Nov 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants