pg_stat_statements_reset() schedule

4.9k Views Asked by At

Aurora Postgres 11.8

Is there any way possible that a non-superadmin user can run pg_stat_statements_reset()?

Details:

Have to schedule pg_stat_statements_reset() on an hourly basis, since there is no internal scheduler available in Aurora Postgres 11.8, I want to go for lambda/cronjob as only the superadmin can run it so its a security risk in my environment to expose superadmin password in a lambda/cronjob. So is there any way out in my case? can there be an sp that starts execution from non-superuser and then switch user within etc?

Thanks

1

There are 1 best solutions below

2
On

The documentation for pg_stat_statements_reset says:

pg_stat_statements_reset discards statistics gathered so far by pg_stat_statements corresponding to the specified userid, dbid and queryid. If any of the parameters are not specified, the default value 0(invalid) is used for each of them and the statistics that match with other parameters will be reset. If no parameter is specified or all the specified parameters are 0(invalid), it will discard all statistics. By default, this function can only be executed by superusers. Access may be granted to others using GRANT.

Let me repeat that: Access may be granted to others using GRANT.