User check - Mailing list pgsql-novice

From Ben Clewett
Subject User check
Date
Msg-id 3E79BE4C.5000000@roadrunner.uk.com
Whole thread Raw
In response to Re: Problems with copy  ("Duncan Adams (DNS)" <duncan.adams@vcontractor.co.za>)
List pgsql-novice
PostgreSQL,

I want to definitively check whether a user is logged in.  I see there
is a table pg_stat_activity:

ben=# SELECT DISTINCT datname FROM ps_stat_activity

Are these better ways, or is this about right?

If right, does this table ever become corrupt, eg a TCP connection
failure without termination?



Whilst I am writing, something which has been bothering me.  Does any
person know the quickest method for checking the existence of a record,
selected by Primary Key?

ben=# SELECT pk FROM table WHERE pk = value

I guess this way might be performance impared as it has to create the
output table with the extracted value.

ben=# SELECT COUNT(*) FROM table WHERE pk = value

I guess this might be faster, since it's only counting results without
creating a table.  Or it might be slower if the table has already been
created, and then counted...



Ever a Novice, Ben.



pgsql-novice by date:

Previous
From: "Duncan Adams (DNS)"
Date:
Subject: Re: Problems with copy
Next
From: Josh Berkus
Date:
Subject: Re: Admin tool for windows