From: raghu ram <raghuchennuru@gmail.com>
To: Didik Prasetyo <prasetyodidik62@yahoo.com>
Cc: pgsql-admin@postgresql.org
Subject: Re:
Date: Sat, 7 May 2011 15:49:47 +0530
Message-ID: <BANLkTiku+xw8Shmgs93_Gu06HCrLUYK-XA@mail.gmail.com> (raw)
In-Reply-To: <183696.23692.qm@web77310.mail.sg1.yahoo.com>
References: <183696.23692.qm@web77310.mail.sg1.yahoo.com>
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@yahoo.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@203.142.85.52's password:
> Last login: Fri May 6 11:32:08 2011 from 10.10.5.22
> cd /us [root@dev ~]# cd /usr/local/pgsql/bin/
> [root@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@dev ~]# cd /usr/local/pgsql/bin/
> [root@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
>
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-admin@postgresql.org
Cc: raghuchennuru@gmail.com, prasetyodidik62@yahoo.com
Subject: Re:
In-Reply-To: <BANLkTiku+xw8Shmgs93_Gu06HCrLUYK-XA@mail.gmail.com>
References: <183696.23692.qm@web77310.mail.sg1.yahoo.com> <BANLkTiku+xw8Shmgs93_Gu06HCrLUYK-XA@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox