Strange behavior: row won't delete

Started by Phoenix Kiulaabout 17 years ago14 messagesgeneral
Jump to latest
#1Phoenix Kiula
phoenix.kiula@gmail.com

HI. I made a small alteration to a table (added a column).

Now when I do:

vacuum analyze TABLENAME

or

delete from TABLENAME where id = 99

Nothing happens! The carriage return means the my shell cursor goes to
the next line, but it just stays there. I thought something may be
happening silently but it has been sitting this way since an hour.

How can I debug this? Nothing in the logs at all.

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Phoenix Kiula (#1)
Re: Strange behavior: row won't delete

Phoenix Kiula <phoenix.kiula@gmail.com> writes:

Now when I do:
vacuum analyze TABLENAME
or
delete from TABLENAME where id = 99
Nothing happens! The carriage return means the my shell cursor goes to
the next line, but it just stays there.

Did you forget the semicolon?

regards, tom lane

#3Alan Hodgson
ahodgson@simkin.ca
In reply to: Phoenix Kiula (#1)
Re: Strange behavior: row won't delete

On Tuesday 03 March 2009, Phoenix Kiula <phoenix.kiula@gmail.com> wrote:

HI. I made a small alteration to a table (added a column).

Now when I do:

vacuum analyze TABLENAME

or

delete from TABLENAME where id = 99

Nothing happens! The carriage return means the my shell cursor goes to
the next line, but it just stays there. I thought something may be
happening silently but it has been sitting this way since an hour.

How can I debug this? Nothing in the logs at all.

commit the transaction where you altered the table. It has an open lock on
the table.

--
Even a sixth-grader can figure out that you can’t borrow money to pay off
your debt

#4Phoenix Kiula
phoenix.kiula@gmail.com
In reply to: Tom Lane (#2)
Re: Strange behavior: row won't delete

On Wed, Mar 4, 2009 at 12:10 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:

Phoenix Kiula <phoenix.kiula@gmail.com> writes:

Now when I do:
  vacuum analyze TABLENAME
or
  delete from TABLENAME where id = 99
Nothing happens! The carriage return means the my shell cursor goes to
the next line, but it just stays there.

Did you forget the semicolon?

Cute. But no :)

myuser=# delete from visitcount where id = 99;

#5Phoenix Kiula
phoenix.kiula@gmail.com
In reply to: Alan Hodgson (#3)
Re: Strange behavior: row won't delete

commit the transaction where you altered the table. It has an open lock on
the table.

=# commit;

WARNING: there is no transaction in progress
COMMIT
Time: 0.282 ms

So no, there's nothing pending.

#6Phoenix Kiula
phoenix.kiula@gmail.com
In reply to: Phoenix Kiula (#5)
Re: Strange behavior: row won't delete

Although when I try this:

select pg_class.relname,pg_locks.* from pg_class,pg_locks where
pg_class.relfilenode=pg_locks.relation;

There are many rows!

How can I get rid of these open locks?

#7Adrian Klaver
adrian.klaver@aklaver.com
In reply to: Phoenix Kiula (#5)
Re: Strange behavior: row won't delete

----- "Phoenix Kiula" <phoenix.kiula@gmail.com> wrote:

commit the transaction where you altered the table. It has an open

lock on

the table.

=# commit;

WARNING: there is no transaction in progress
COMMIT
Time: 0.282 ms

So no, there's nothing pending.

--

Are you connected to the right database?. I have been in that situation, looking at the log for db A and doing things in db B.

Adrian Klaver
aklaver@comcast.net

#8Phoenix Kiula
phoenix.kiula@gmail.com
In reply to: Adrian Klaver (#7)
Re: Strange behavior: row won't delete

On Wed, Mar 4, 2009 at 12:36 AM, Adrian Klaver <aklaver@comcast.net> wrote:

Are you connected to the right database?. I have been in that situation, looking at the log for db A and doing things in db B.

Thanks. I only have one database, so yes I am connected to it.

I have the lock file in /tmp: .s.PGSQL.5432.lock

Should I delete this file?

#9Adrian Klaver
adrian.klaver@aklaver.com
In reply to: Phoenix Kiula (#8)
Re: Strange behavior: row won't delete

----- "Phoenix Kiula" <phoenix.kiula@gmail.com> wrote:

On Wed, Mar 4, 2009 at 12:36 AM, Adrian Klaver <aklaver@comcast.net>
wrote:

Are you connected to the right database?. I have been in that

situation, looking at the log for db A and doing things in db B.

Thanks. I only have one database, so yes I am connected to it.

I have the lock file in /tmp: .s.PGSQL.5432.lock

Should I delete this file?

No, that is the lock file for the entire cluster.

Adrian Klaver
aklaver@comcast.net

#10Phoenix Kiula
phoenix.kiula@gmail.com
In reply to: Adrian Klaver (#9)
Re: Strange behavior: row won't delete

I guess my question is, how should I remove all pending locks on a
table so that I can get on with the rest of the stuff?

I mean, even if I can now find an offending RULE on the table, I
cannot replace or remove it. '

Thanks for any pointers!

#11Tom Lane
tgl@sss.pgh.pa.us
In reply to: Phoenix Kiula (#6)
Re: Strange behavior: row won't delete

Phoenix Kiula <phoenix.kiula@gmail.com> writes:

How can I get rid of these open locks?

Close the transactions that are holding them. Look into
pg_stat_activity and pg_prepared_xacts.

regards, tom lane

#12Phoenix Kiula
phoenix.kiula@gmail.com
In reply to: Tom Lane (#11)
Re: Strange behavior: row won't delete

On Wed, Mar 4, 2009 at 1:17 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:

Phoenix Kiula <phoenix.kiula@gmail.com> writes:

How can I get rid of these open locks?

Close the transactions that are holding them.  Look into
pg_stat_activity and pg_prepared_xacts.

Thanks for this. But can I simply delete all the pg_locks table? Or
delete all rows in pg_stat_activity? In my case the _xacts table is
empty. Ideally I don't want to lose pg_stat_activity. I just want to
change a RULE on a table. Is there any place I can do that?

#13Phoenix Kiula
phoenix.kiula@gmail.com
In reply to: Phoenix Kiula (#12)
Re: Strange behavior: row won't delete

On Wed, Mar 4, 2009 at 1:23 AM, Phoenix Kiula <phoenix.kiula@gmail.com> wrote:

On Wed, Mar 4, 2009 at 1:17 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:

Phoenix Kiula <phoenix.kiula@gmail.com> writes:

How can I get rid of these open locks?

Close the transactions that are holding them.  Look into
pg_stat_activity and pg_prepared_xacts.

Thanks for this. But can I simply delete all the pg_locks table? Or
delete all rows in pg_stat_activity? In my case the _xacts table is
empty. Ideally I don't want to lose pg_stat_activity. I just want to
change a RULE on a table. Is there any place I can do that?

I found 232 rows in pg_stat_activity of offending "current_query". How
can I delete them?

----
=# delete from pg_stat_activity where current_query like 'UPDATE visitcount%';
ERROR: cannot delete from a view
HINT: You need an unconditional ON DELETE DO INSTEAD rule
----

Thanks!

#14Bruce Momjian
bruce@momjian.us
In reply to: Phoenix Kiula (#10)
Re: Strange behavior: row won't delete

Phoenix Kiula <phoenix.kiula@gmail.com> writes:

I guess my question is, how should I remove all pending locks on a
table so that I can get on with the rest of the stuff?

I mean, even if I can now find an offending RULE on the table, I
cannot replace or remove it. '

You're off on the wrong track. Locks are held by transactions until the
transaction commits. You need to find the transactions which are holding these
locks and either commit or roll them back.

You look in pg_locks to see what locks transactions are holding. In particular
look for rows with "granted" set to "t", especially locks on relations and
especially ExclusiveLocks.

Then you take the pid of those transactions and look in pg_stat_activity to
see what they're up to. If they say "<idle in transaction>" then they're
waiting for the client to do something. If they stay that way for any length
of time while holding locks which block other transactions that's bad.

Alternately if you see a query in pg_stat_transaction which is taking a long
time to run you might check whether you have a bad plan or a bad query running
while holding locks effectively doing the same thing.

--
Gregory Stark
EnterpriseDB http://www.enterprisedb.com
Ask me about EnterpriseDB's RemoteDBA services!