# postgresql\_user and granting select on pg\_stat\_database

**URL:** <https://forum.ansible.com/t/postgresql-user-and-granting-select-on-pg-stat-database/17782>\
**Category:** Ansible Project\
**Created:** [March 19, 2015, 1:51am UTC](https://forum.ansible.com/t/postgresql-user-and-granting-select-on-pg-stat-database/17782 "2015-03-19T01:51:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Brent\_Clark](https://avatars.discourse-cdn.com/v4/letter/b/ba9def/32.png) [@Brent\_Clark](https://forum.ansible.com/u/Brent_Clark)\
**Post date:** [March 19, 2015, 1:51am UTC](https://forum.ansible.com/t/postgresql-user-and-granting-select-on-pg-stat-database/17782/1 "2015-03-19T01:51:22Z")

</div>

Hello,

I am trying to use the postgresql\_user function to create and grant privs on the user. Im getting failure messages relating to the priv.

- postgresql\_user: name=bobby password={{ pg\_dd\_password }} db=pg\_stat\_database priv=SELECT state=present

What I want basically to do is the following

create user bobby with password ‘some\_password’;

grant SELECT ON pg\_stat\_database to bobby;

I think my issue is that pg\_stat\_database isnt really a database or a table, but a collection of views, if I am understanding postgresql correctly.

Any help is appreciated.

---

<div class="post-metadata">

**Author:** ![An\_Internet\_Denizen](https://avatars.discourse-cdn.com/v4/letter/a/e47c2d/32.png) [@An\_Internet\_Denizen](https://forum.ansible.com/u/An_Internet_Denizen)\
**Post date:** [March 19, 2015, 3:59am UTC](https://forum.ansible.com/t/postgresql-user-and-granting-select-on-pg-stat-database/17782/2 "2015-03-19T03:59:39Z")

</div>

pg\_stat\_database is a view : [http://www.postgresql.org/docs/9.4/static/monitoring-stats.html#PG-STAT-DATABASE-VIEW](http://www.postgresql.org/docs/9.4/static/monitoring-stats.html#PG-STAT-DATABASE-VIEW)

---

<div class="post-metadata">

**Author:** ![Brent\_Clark](https://avatars.discourse-cdn.com/v4/letter/b/ba9def/32.png) [@Brent\_Clark](https://forum.ansible.com/u/Brent_Clark)\
**Post date:** [March 19, 2015, 4:41pm UTC](https://forum.ansible.com/t/postgresql-user-and-granting-select-on-pg-stat-database/17782/3 "2015-03-19T16:41:25Z")

</div>

Im guessing grant privs on views isnt supported with postgresql\_user or postgresql\_privs?

---

<div class="post-metadata">

**Author:** ![Brent\_Clark](https://avatars.discourse-cdn.com/v4/letter/b/ba9def/32.png) [@Brent\_Clark](https://forum.ansible.com/u/Brent_Clark)\
**Post date:** [March 19, 2015, 4:50pm UTC](https://forum.ansible.com/t/postgresql-user-and-granting-select-on-pg-stat-database/17782/4 "2015-03-19T16:50:10Z")

</div>

I was able to get this working. Was just thinking about it in the wrong context. Place working code here for others. Thanks everyone!

- postgresql\_user: name=bobby password={{ pg\_dd\_password }} db=postgres priv=pg\_stat\_database:SELECT state=present
