The code i tried in bash executed by root.
#!/bin/bash
su - postgres <<EOF1
F="$(psql -d postgres --tuples-only -P format=unaligned -c "SELECT datname FROM pg_database JOIN pg_authid ON pg_database.datdba = pg_authid.oid WHERE rolname = 'username'")"
EOF1
echo $F
It gives output as ERROR: permission denied for relation pg_authid
But when i try
su - postgres <<EOF1
psql -d postgres --tuples-only -P format=unaligned -c "SELECT datname FROM pg_database JOIN pg_authid ON pg_database.datdba = pg_authid.oid WHERE rolname = 'username'"
EOF1
This prints all db of that username. Why so?
I need to store the ouput to a bash variable for further processing.
Is there any mistake or anyother way to try this out..
Thanks.