Re:

From: raghu ram <raghuchennuru(at)gmail(dot)com>
To: Didik Prasetyo <prasetyodidik62(at)yahoo(dot)com>
Cc: pgsql-admin(at)postgresql(dot)org
Subject: Re:
Date: 2011-05-07 10:19:47
Message-ID: BANLkTiku+xw8Shmgs93_Gu06HCrLUYK-XA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

We can not Grant SELECT privileges to entire Database. Granting access to a
schema allows use of that schema. It does not grant access to objects
contained in the schema. You will need to do a grant for each object.

*Bash Script To Provide Read Only Access To Every Table In A PostgreSQL
Database:*

#!/bin/sh
#
# Provide Read Only Access On PostgreSQL Database
# Use: ./pgaccess $database $username
#
tables=$(psql $1 -A -t -c "SELECT table_name FROM information_schema.tables
WHERE table_schema = 'public';")
for table in $tables
do
echo "Providing select to $2 on $table"
psql $1 -c "GRANT SELECT ON $table to $2;"
done

As you can see there are now two variables required to run the script which
are database and username. The script above should be run in the below
format. I name the script pgaccess.sh so that is what is used in the example
below.

*Read Only User Script Syntax:*

./pgaccess $database $username

Just replace $database with the name of the database you are providing
access to and replace $username with the name of the user that will be
provided SELECT access to the PostgreSQL database.

--Raghu Ram

On Sat, May 7, 2011 at 12:58 PM, Didik Prasetyo
<prasetyodidik62(at)yahoo(dot)com>wrote:

> I want to ask how to make GRANT, where users can only perform SELECT on all
> the TABLE, in the database, which I have done the following
>
>
> login as: root
> root(at)203(dot)142(dot)85(dot)52's password:
> Last login: Fri May 6 11:32:08 2011 from 10.10.5.22
> cd /us [root(at)dev ~]# cd /usr/local/pgsql/bin/
> [root(at)dev bin]# ./psql -U postgres
> psql (8.4.1)
> Type "help" for help.
>
> postgres=# CREATE USER udin WITH PASSWORD 'udin';
> CREATE ROLE
> postgres=# \du
> List of roles
> Role name | Attributes | Member of
> -----------+-------------+-----------
> dba | | {}
> postgres | Superuser | {}
> : Create role
> : Create DB
> udin | | {}
>
> postgres=# \q
>
> [root(at)dev ~]# cd /usr/local/pgsql/bin/
> [root(at)dev bin]# ./psql -U postgres
> psql (8.4.1)
> Type "help" for help.
>
> postgres=# GRANT SELECT ON DATABASE dbmufins to udin;
> ERROR: invalid privilege type SELECT for database
>
> but still there is error, I beg of solutions, from friends all
>
> thank you for your help
>

In response to

  • at 2011-05-07 07:28:58 from Didik Prasetyo

Browse pgsql-admin by date

  From Date Subject
Next Message Thomas Kellerer 2011-05-07 11:00:29 Re: (unknown)
Previous Message Didik Prasetyo 2011-05-07 07:28:58