'No need to run 'GRANT postgres_exporter TO <MASTER_USER>' on aws RDS PostgreSQL?

Per postgresql_exporter doc. In order to create one new user postgres_exporter for Prometheus PostgreSQL exporter. Here are the sample codes

ALTER USER postgres_exporter WITH PASSWORD 'password';
ALTER USER postgres_exporter SET SEARCH_PATH TO postgres_exporter,pg_catalog;
-- If deploying as non-superuser (for example in AWS RDS), uncomment the GRANT
-- line below and replace <MASTER_USER> with your root user.
-- GRANT postgres_exporter TO <MASTER_USER>;
GRANT CONNECT ON DATABASE postgres TO postgres_exporter;

One special SQL is GRANT postgres_exporter TO <MASTER_USER>. I am confused about it. I just remove it and run with the following codes to create one new user postgres_exporter

CREATE OR REPLACE FUNCTION __tmp_create_user() returns void as $$
BEGIN
  IF NOT EXISTS (
          SELECT
          FROM   pg_catalog.pg_user
          WHERE  usename = 'postgres_exporter') THEN
    CREATE USER postgres_exporter;
  END IF;
END;
$$ language plpgsql;

SELECT __tmp_create_user();
DROP FUNCTION __tmp_create_user();

ALTER USER postgres_exporter WITH PASSWORD 'password';
ALTER USER postgres_exporter SET SEARCH_PATH TO pg_catalog;

GRANT CONNECT ON DATABASE postgres TO postgres_exporter;

GRANT pg_monitor to postgres_exporter;

And this new user works well in PostgreSQL exporter with PostgreSQL version 10.

Shall we think this operation GRANT postgres_exporter1 TO <MASTER_USER> is useless? Please correct us if something is wrong or anything missing?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source