Unix Technical Forum

[PATCH] Add size/acl information when listing databases

This is a discussion on [PATCH] Add size/acl information when listing databases within the pgsql Hackers forums, part of the PostgreSQL category; --> Greetings, Attached is a rather small change to src/bin/psql/describe.c to show database size and permissions when using the psql ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > pgsql Hackers

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-15-2008, 10:42 PM
Andrew Gilligan
 
Posts: n/a
Default [PATCH] Add size/acl information when listing databases

Greetings,

Attached is a rather small change to src/bin/psql/describe.c to
show database size and permissions when using the psql \l command.

Typical output would be:

List of databases
Name | Owner | Encoding | Size | Access privileges
-----------+-------+----------+---------
+-------------------------------------------
andy | andy | UTF8 | 734 MB | {andy=CTc/andy}
postgres | pgsql | UTF8 | 3914 kB |
template0 | pgsql | UTF8 | 3656 kB | {=c/pgsql,pgsql=CTc/pgsql}
template1 | pgsql | UTF8 | 4034 kB | {=c/pgsql,pgsql=CTc/pgsql}


Hope someone finds this useful.

Best regards,
-Andy






---------------------------(end of broadcast)---------------------------
TIP 7: You can help support the PostgreSQL project by donating at

http://www.postgresql.org/about/donate

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-15-2008, 10:42 PM
Tom Lane
 
Posts: n/a
Default Re: [PATCH] Add size/acl information when listing databases

Andrew Gilligan <andy@tcpd.net> writes:
> Attached is a rather small change to src/bin/psql/describe.c to
> show database size and permissions when using the psql \l command.


Doesn't this slow down \l by several orders of magnitude? There's
also the small problem that the query will fail entirely if there are
any databases the current user cannot connect to.

The ACL part is fine, the database size not so much. I could see
relegating the size to a \l+ option, but you still have to deal with the
permissions problem.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faq

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-15-2008, 10:42 PM
Andrew Gilligan
 
Posts: n/a
Default Re: [PATCH] Add size/acl information when listing databases


On 20 Jan 2008, at 02:06, Tom Lane wrote:

> Andrew Gilligan <andy@tcpd.net> writes:
>> Attached is a rather small change to src/bin/psql/describe.c to
>> show database size and permissions when using the psql \l command.

>
> Doesn't this slow down \l by several orders of magnitude? There's
> also the small problem that the query will fail entirely if there are
> any databases the current user cannot connect to.


I didn't run into the permissions issue while testing on 8.2.6, but
you're quite correct, after trying 8.3.x it fails entirely. Sorry.

On databases containing around 50 tables it seems to return in under
10ms, but I haven't been able to test with larger than that.

> The ACL part is fine, the database size not so much. I could see
> relegating the size to a \l+ option, but you still have to deal with
> the
> permissions problem.


Showing the size on \l+ probably makes more sense, but I imagine that
would require a very different approach due to the permissions changes?

Best regards,
-Andy

---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-15-2008, 10:42 PM
Tom Lane
 
Posts: n/a
Default Re: [PATCH] Add size/acl information when listing databases

Andrew Gilligan <andy@tcpd.net> writes:
> Showing the size on \l+ probably makes more sense, but I imagine that
> would require a very different approach due to the permissions changes?


I haven't experimented, but perhaps something along the lines of

case when has_database_privilege(current_user, db.oid, 'connect')
then pg_database_size...
else null
end

would fix it.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 04-15-2008, 10:42 PM
Andrew Gilligan
 
Posts: n/a
Default Re: [PATCH] Add size/acl information when listing databases


On 20 Jan 2008, at 04:34, Tom Lane wrote:
> Andrew Gilligan <andy@tcpd.net> writes:
>> Showing the size on \l+ probably makes more sense, but I imagine that
>> would require a very different approach due to the permissions
>> changes?

>
> I haven't experimented, but perhaps something along the lines of
>
> case when has_database_privilege(current_user, db.oid, 'connect')
> then pg_database_size...
> else null
> end
>
> would fix it.



Yep, that seems to do the trick.

I've attached an updated patch (based on 8.3RC2) that adds the ACL
information to \l and the size to \l+ if available.

Best regards,
-Andy






---------------------------(end of broadcast)---------------------------
TIP 7: You can help support the PostgreSQL project by donating at

http://www.postgresql.org/about/donate

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 04-15-2008, 10:49 PM
Tom Lane
 
Posts: n/a
Default Re: [PATCH] Add size/acl information when listing databases

Andrew Gilligan <andy@tcpd.net> writes:
> I've attached an updated patch (based on 8.3RC2) that adds the ACL
> information to \l and the size to \l+ if available.


Applied, thanks.

regards, tom lane

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 11:07 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com