473,387 Members | 1,548 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

GRANT question

Is there a shortcut to grant all privileges on a schema and it's objects to
a user without having to issue GRANT statements for each individual object
in the schema? Given all the possible types of objects I doubt it but
thought I would ask just in case there was a way to do it.

Chris
---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to ma*******@postgresql.org)

Nov 23 '05 #1
3 1752
On Wed, Jun 02, 2004 at 07:51:58 -0700,
Chris Ochs <ch***@paymentonline.com> wrote:
Is there a shortcut to grant all privileges on a schema and it's objects to
a user without having to issue GRANT statements for each individual object
in the schema? Given all the possible types of objects I doubt it but
thought I would ask just in case there was a way to do it.


No. People have asked about similar ways to do lots of grants at once,
but I haven't seen anyone claim to be working on this.

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to ma*******@postgresql.org)

Nov 23 '05 #2
Chris Ochs said:
Is there a shortcut to grant all privileges on a schema and it's objects
to
a user without having to issue GRANT statements for each individual
object
in the schema? Given all the possible types of objects I doubt it but
thought I would ask just in case there was a way to do it.


There is a roundabout way, but it's a bit cludgey - but I use it a lot as
we add new tables, views and functions to our development db.

There are some examples below.

For example, select 'grant all on '||schemaname||'.'||tablename||' to
MYUSERNAME;'
from pg_tables
where schemaname in ('SOMESCHEMA1', 'SOMESCHEMA2', ... etc)
order by schemaname, tablename;

This creates a series of grant statements which you can then apply against
the database (using psql for example).

I guess that there is no reason why you couldn't create a function (using
a temp table, and the execute statement) which you passed the schema name
to grant rights for, and the user to receive the rights, and possibly
specify the kind of rights to grant. Invoking the function would then
apply the grants for you. I haven't bothered with this as the simple
queries below work fine for me.

Here are the queries I use:

For TABLES
==========
select 'grant all on '||schemaname||'.'||tablename||' to SOMEUSERNAME;'
from pg_tables
where schemaname in ('SOMESCHEMA1', 'SOMESCHEMA2')
order by schemaname, tablename;

For VIEWS
=========
SELECT 'grant all on '||n.nspname||'.'||c.relname||' to SOMEUSERNAME;'
FROM pg_catalog.pg_class c
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
WHERE n.nspname in ('SOMESCHEMA1', 'SOMESCHEMA2')
and c.relkind = 'v'
ORDER BY n.nspname, c.relname;

For FUNCTIONS
=============
select 'grant all on function
'||n.nspname||'.'||p.proname||'('||oidvectortypes( p.proargtypes)||') to
SOMEUSERNAME;'
from pg_proc p, pg_namespace n
where n.oid = p.pronamespace
and n.nspname in ('SOMESCHEMA1', 'SOMESCHEMA2')
order by n.nspname, p.proname;

Hope that helps some.

John Sidney-Woollett

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Nov 23 '05 #3
Missed one out, ... the script for sequences is:

select 'grant all on '||n.nspname||'.'||c.relname||' to MYUSERNAME;'
from pg_class c, pg_namespace n
where n.oid = c.relnamespace
and c.relkind IN ('S')
and n.nspname in ('SOMESCHEMA1', 'SOMESCHEMA2');

John Sidney-Woollett

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Nov 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Martin v. Löwis | last post by:
The Python Software Foundation is seeking grant proposals for projects related to the further development of Python, Python-related technology, and educational resources. The PSF plans to issue...
4
by: Amardeep Verma | last post by:
Hi, I have a quick question. Which role/privileges are required before a user can give the statement "GRANT ALL PRIVILEGES"? Thanking you in Advance Have a nice day
0
by: Charles Cantrell | last post by:
I have recently set up mySQL on a Mandrake release of Linux (Version 7 of Mandrake, I believe), using the binary 4.0.13 standard release. The set up and start up all were normal, as far as I...
0
by: Charles Cantrell | last post by:
I have recently set up mySQL on a Mandrake release of Linux (Version 7 of Mandrake, I believe), using the binary 4.0.13 standard release. The set up and start up all were normal, as far as I...
1
by: Adam Smith | last post by:
I have a new DB provided by my ISP don't know details of installation, setup etc. I can log in as anybody except root. mysql -h localhost -u mysql Welcome to the MySQL monitor. Commands end...
27
by: Igor V. Rafienko | last post by:
Hi, I am trying to understand how cElementTree's clear works: I have a (relatively) large XML file, that I do not wish to load into memory. So, naturally, I tried something like this: from...
7
by: Barbara Lindsey | last post by:
What kind of grant do you need to give a user so that they can have permission to do a "SELECT nextval(ID)" on a sequence? I granted the user SELECT,UPDATE,INSERT,DELETE on all the tables,...
1
by: everymn | last post by:
Hi, Supposedly the Alter Routine privilege can be granted at the level of a single routine but I haven't been able to get that to work. I've tried it a number of different ways like: GRANT...
7
by: MNNovice | last post by:
Please forgive me for this is a long request. I am designing a DB to capture expenses related to Federal Grants and to generate appropriate reports. Each grant starts with a Notice of Grant Award...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.