\du in psql patchp

Started by Alex Perelover 25 years ago10 messagespatches
Jump to latest
#1Alex Perel
aperel@verticalscope.com

Hi everyone,

I quickly put together a patch to psql that allows one to view current
system users. The code is very simple, but it seems to work.

The usage is as follows:

database=# \du [username]

I apologize in advance for my lack of C skills, and I will gladly
accept any criticism or advice. I'm hoping I can figure out a way
to write an equivalent for groups, once I determine how to
get around the grolist integer[] column in pg_group.

Please take a look at the patch and see if it's worth anything.

Thanks

Alex

Alex G. Perel -=- AP5081
veers@disturbed.net -=- aperel@verticalscope.com
play -=- work

Disturbed Networks - Powered exclusively by FreeBSD
== The Power to Serve -=- http://www.freebsd.org/

Attachments:

slash-du.difftext/plain; charset=US-ASCII; name=slash-du.diffDownload+107-1
#2Peter Eisentraut
peter_e@gmx.net
In reply to: Alex Perel (#1)
Re: \du in psql patchp

Alex Perel writes:

I quickly put together a patch to psql that allows one to view current
system users. The code is very simple, but it seems to work.

The usage is as follows:

database=# \du [username]

Hi, we're currently in beta, but this one seems reasonable to add in 7.2.

I apologize in advance for my lack of C skills, and I will gladly
accept any criticism or advice. I'm hoping I can figure out a way
to write an equivalent for groups, once I determine how to
get around the grolist integer[] column in pg_group.

I think the pg_group table will be redesigned in 7.2 so it can be queried
better.

--
Peter Eisentraut peter_e@gmx.net http://yi.org/peter-e/

#3Alex Perel
aperel@verticalscope.com
In reply to: Peter Eisentraut (#2)
Re: \du in psql patchp

On Mon, 8 Jan 2001, Peter Eisentraut wrote:

Alex Perel writes:

I quickly put together a patch to psql that allows one to view current
system users. The code is very simple, but it seems to work.

The usage is as follows:

database=# \du [username]

Hi, we're currently in beta, but this one seems reasonable to add in 7.2.

Great, that's perfectly fine for me.

I apologize in advance for my lack of C skills, and I will gladly
accept any criticism or advice. I'm hoping I can figure out a way
to write an equivalent for groups, once I determine how to
get around the grolist integer[] column in pg_group.

I think the pg_group table will be redesigned in 7.2 so it can be queried
better.

Excellent! Is there any way I can help out with that? Do you have any
pointers to where the relevant code is? I've tried looking but didn't
come up with anything.

Alex G. Perel -=- AP5081
veers@disturbed.net -=- aperel@verticalscope.com
play -=- work

Disturbed Networks - Powered exclusively by FreeBSD
== The Power to Serve -=- http://www.freebsd.org/

#4Bruce Momjian
bruce@momjian.us
In reply to: Alex Perel (#1)
Re: \du in psql patchp

I will keep it for 7.2.

Hi everyone,

I quickly put together a patch to psql that allows one to view current
system users. The code is very simple, but it seems to work.

The usage is as follows:

database=# \du [username]

I apologize in advance for my lack of C skills, and I will gladly
accept any criticism or advice. I'm hoping I can figure out a way
to write an equivalent for groups, once I determine how to
get around the grolist integer[] column in pg_group.

Please take a look at the patch and see if it's worth anything.

Thanks

Alex

Alex G. Perel -=- AP5081
veers@disturbed.net -=- aperel@verticalscope.com
play -=- work

Disturbed Networks - Powered exclusively by FreeBSD
== The Power to Serve -=- http://www.freebsd.org/

Content-Description:

[ Attachment, skipping... ]

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026
#5Bruce Momjian
bruce@momjian.us
In reply to: Alex Perel (#1)
Re: \du in psql patchp

Patch applied. I removed the reference to asprintf() and changed it to
a string constant. I have also added documentation changes. Patch
attached.

The new feature looks like:

test=> \du
List of Users
User Name | User ID | Attributes
-----------+---------+------------------------
demouser2 | 140 | create DB
postgres | 139 | create user, create DB

Very nice.

Hi everyone,

I quickly put together a patch to psql that allows one to view current
system users. The code is very simple, but it seems to work.

The usage is as follows:

database=# \du [username]

I apologize in advance for my lack of C skills, and I will gladly
accept any criticism or advice. I'm hoping I can figure out a way
to write an equivalent for groups, once I determine how to
get around the grolist integer[] column in pg_group.

Please take a look at the patch and see if it's worth anything.

Thanks

Alex

Alex G. Perel -=- AP5081
veers@disturbed.net -=- aperel@verticalscope.com
play -=- work

Disturbed Networks - Powered exclusively by FreeBSD
== The Power to Serve -=- http://www.freebsd.org/

Content-Description:

[ Attachment, skipping... ]

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026

Attachments:

/bjm/difftext/plainDownload+113-0
#6Peter Eisentraut
peter_e@gmx.net
In reply to: Bruce Momjian (#5)
Re: \du in psql patchp

Bruce Momjian writes:

Patch applied. I removed the reference to asprintf() and changed it to
a string constant. I have also added documentation changes. Patch
attached.

I think there's a memory leak, count your xmalloc's. Also, perhaps the
user ids should be right-aligned (printTable, 5th argument).

Very nice.

Yes.

--
Peter Eisentraut peter_e@gmx.net http://funkturm.homeip.net/~peter

#7Bruce Momjian
bruce@momjian.us
In reply to: Peter Eisentraut (#6)
Re: \du in psql patchp

Bruce Momjian writes:

Patch applied. I removed the reference to asprintf() and changed it to
a string constant. I have also added documentation changes. Patch
attached.

I think there's a memory leak, count your xmalloc's. Also, perhaps the

I thought I had too many mallocs, but when I started looking, I couldn't
find the second one anymore. I see it now, and fixed. Looped through
cell and free'ed:

for (i = 0; i < PQntuples(res); i++)
free(cells[i * cols + 2]);
free(cells);

user ids should be right-aligned (printTable, 5th argument).

Got it:

test=> \du
List of Users
User Name | User ID | Attributes
-----------+---------+------------------------
demouser2 | 140 | create DB
postgres | 139 | create user, create DB

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026
#8Alex Perel
aperel@verticalscope.com
In reply to: Peter Eisentraut (#6)
Re: \du in psql patchp

On Wed, 9 May 2001, Peter Eisentraut wrote:

Thanks for the catch, I'll keep an eye on this in the future.

(my C skills aren't what I'd like them to be...)

Bruce Momjian writes:

Patch applied. I removed the reference to asprintf() and changed it to
a string constant. I have also added documentation changes. Patch
attached.

I think there's a memory leak, count your xmalloc's. Also, perhaps the
user ids should be right-aligned (printTable, 5th argument).

Very nice.

Yes.

--
Peter Eisentraut peter_e@gmx.net http://funkturm.homeip.net/~peter

Alex Perel
Lead Database Analyst
T. 416.341.8950 ext. 238
F. 416.341.8959
E. aperel@verticalscope.com
www.verticalscope.com

#9Bruce Momjian
bruce@momjian.us
In reply to: Alex Perel (#8)
Re: \du in psql patchp

On Wed, 9 May 2001, Peter Eisentraut wrote:

Thanks for the catch, I'll keep an eye on this in the future.

(my C skills aren't what I'd like them to be...)

Hey, but a nice feature.

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026
#10Alex Perel
aperel@verticalscope.com
In reply to: Bruce Momjian (#9)
Re: \du in psql patchp

On Wed, 9 May 2001, Bruce Momjian wrote:

Thanks. :)

On a related note, do either of you know a good way to join the contents
of the grolist[] array in pg_group with pg_user's? I'd like to add a similar
\dg function, because I think that would be even more useful.

Thanks

Alex

On Wed, 9 May 2001, Peter Eisentraut wrote:

Thanks for the catch, I'll keep an eye on this in the future.

(my C skills aren't what I'd like them to be...)

Hey, but a nice feature.

-- 
Bruce Momjian                        |  http://candle.pha.pa.us
pgman@candle.pha.pa.us               |  (610) 853-3000
+  If your life is a hard drive,     |  830 Blythe Avenue
+  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026

Alex Perel
Lead Database Analyst
T. 416.341.8950 ext. 238
F. 416.341.8959
E. aperel@verticalscope.com
www.verticalscope.com