Unix Technical Forum

Who's attached to the database?

This is a discussion on Who's attached to the database? within the pgsql Admins forums, part of the PostgreSQL category; --> Hi, Guys, I'm trying to drop a database and I'm getting an error that says that the database is ...


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

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 07-04-2008, 06:50 AM
Carol Walter
 
Posts: n/a
Default Who's attached to the database?

Hi, Guys,

I'm trying to drop a database and I'm getting an error that says that
the database is being accessed by other users. Is there a way I can
find out who these users are or if there really is a user accessing it?

Carol

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 07-04-2008, 06:50 AM
Kevin Grittner
 
Posts: n/a
Default Re: Who's attached to the database?

>>> Carol Walter <walterc@indiana.edu> wrote:
> I'm trying to drop a database and I'm getting an error that says that


> the database is being accessed by other users. Is there a way I can


> find out who these users are or if there really is a user accessing

it?

select * from pg_stat_activity where datname = 'yourdb';

-Kevin

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 07-04-2008, 06:50 AM
Tom Lane
 
Posts: n/a
Default Re: Who's attached to the database?

Carol Walter <walterc@indiana.edu> writes:
> I'm trying to drop a database and I'm getting an error that says that
> the database is being accessed by other users. Is there a way I can
> find out who these users are or if there really is a user accessing it?


pg_stat_activity ... or if you turned that off, "ps auxww | grep postgres"
(or local equivalent) might help.

regards, tom lane

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 07-04-2008, 06:50 AM
Jeff Frost
 
Posts: n/a
Default Re: Who's attached to the database?

Carol Walter wrote:
> I'm trying to drop a database and I'm getting an error that says that
> the database is being accessed by other users. Is there a way I can
> find out who these users are or if there really is a user accessing it?

Carol, depending on version and options turned on in the
postgresql.conf, you probably can have a look in the pg_stat_activity
system view:

SELECT datname, client_addr FROM pg_stat_activity WHERE datname = '<db
you're trying to drop>';

Otherwise, you can also have a look at the command line on linux servers
like this:

ps -ef|grep postgres

or

ps aux | grep postgres

depending what ps variant your system includes.

--
Jeff Frost, Owner <jeff@frostconsultingllc.com>
Frost Consulting, LLC http://www.frostconsultingllc.com/
Phone: 650-780-7908 FAX: 650-649-1954


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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 07-04-2008, 06:50 AM
paul socha
 
Posts: n/a
Default Re: Who's attached to the database?


On 2008-07-03, at 21:45, Carol Walter wrote:

> Hi, Guys,
>
> I'm trying to drop a database and I'm getting an error that says
> that the database is being accessed by other users. Is there a way
> I can find out who these users are or if there really is a user
> accessing it?
>
> Carol
>
> --
> Sent via pgsql-admin mailing list (pgsql-admin@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-admin




select * from pg_stat_activity where datname='<database2drop>';


--

Pawel Socha
pawel.socha@gmail.com


perl -le 's**02).4^&-%2,).^9%4^!./4(%2^3,!#+7!2%^53%2&**y%& -;^[%"`-
{ a%%s%%$_%ee'


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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 07-04-2008, 06:50 AM
Carol Walter
 
Posts: n/a
Default Re: Who's attached to the database?

Thanks, guys,

This told me that the user that has it open is the interface user
called db_user. Is there a command to disconnect this user?

Carol

On Jul 3, 2008, at 3:53 PM, Kevin Grittner wrote:

>>>> Carol Walter <walterc@indiana.edu> wrote:

>> I'm trying to drop a database and I'm getting an error that says that

>
>> the database is being accessed by other users. Is there a way I can

>
>> find out who these users are or if there really is a user accessing

> it?
>
> select * from pg_stat_activity where datname = 'yourdb';
>
> -Kevin



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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 07-04-2008, 06:50 AM
Carol Walter
 
Posts: n/a
Default Re: Who's attached to the database?

Oh, thanks so much. This is something I really needed.

Carol

On Jul 3, 2008, at 5:17 PM, Bricklen Anderson wrote:

> Carol Walter wrote:
>> Thanks, guys,
>> This told me that the user that has it open is the interface user
>> called db_user. Is there a command to disconnect this user?
>> Carol

>
> select pg_cancel_backend(<procpid of connection>);



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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 07-04-2008, 06:50 AM
Bricklen Anderson
 
Posts: n/a
Default Re: Who's attached to the database?

Carol Walter wrote:
> Thanks, guys,
>
> This told me that the user that has it open is the interface user called
> db_user. Is there a command to disconnect this user?
>
> Carol


select pg_cancel_backend(<procpid of connection>);

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 07-04-2008, 06:50 AM
Kevin Grittner
 
Posts: n/a
Default Re: Who's attached to the database?

>>> Bricklen Anderson <banderson@presinet.com> wrote:

>> Is there a command to disconnect this user?

>
> select pg_cancel_backend(<procpid of connection>);


I thought that just canceled the currently active statement (if any).
Don't you need to use pg_ctl kill (or the OS kill command) to actually
close the connection?

http://www.postgresql.org/docs/8.3/i...ons-admin.html

http://www.postgresql.org/docs/8.3/i...pp-pg-ctl.html

-Kevin

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 07-04-2008, 03:38 PM
Lennin Caro
 
Posts: n/a
Default Re: Who's attached to the database?

ps auxw | grep postgres

list the user and some time the process in execution


--- On Thu, 7/3/08, Carol Walter <walterc@indiana.edu> wrote:

> From: Carol Walter <walterc@indiana.edu>
> Subject: [ADMIN] Who's attached to the database?
> To: pgsql-admin@postgresql.org
> Date: Thursday, July 3, 2008, 7:45 PM
> Hi, Guys,
>
> I'm trying to drop a database and I'm getting an
> error that says that
> the database is being accessed by other users. Is there a
> way I can
> find out who these users are or if there really is a user
> accessing it?
>
> Carol
>
> --
> Sent via pgsql-admin mailing list
> (pgsql-admin@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-admin






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

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 02:39 PM.


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