473,398 Members | 2,125 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Very slow delete.

Hello,

I have a table with 29268 odd records. Deleting records is VERY slow,
and I don't know why.

I explained analysed the following query:
delete from people where id < '2000'

Index Scan using people_pkey on people (cost=0.00..71.68 rows=2792
width=6) (actual time=1.361..5.657 rows=2000 loops=1)
Index Cond: (id < 3000)
Total runtime: 13.006 ms
3 row(s)
Total runtime: 63,869.322 ms

using phppgadmin (it's also slow via command line or Perl/DBD).

I haven't optimized postgresql yet (kernel.shmmax, etc), but I don't
see why it is taking this long. Why is it 13ms, and then 63869ms?

There is 1 fkey relationship, and it is primary key to a few other
(now empty) tables.

The fkey's are on update cascade on delete restrict. Deletes on other
tables are quick.

Any ideas?

Thanks

Brock

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Nov 23 '05 #1
2 10029
Brock Henry <br*********@gmail.com> writes:
delete from people where id < '2000' Index Scan using people_pkey on people (cost=0.00..71.68 rows=2792
width=6) (actual time=1.361..5.657 rows=2000 loops=1)
Index Cond: (id < 3000)
Total runtime: 13.006 ms
3 row(s)
Total runtime: 63,869.322 ms


So 13 msec to find the rows to delete, and 63850+ msec in overhead.
Which is certainly from the foreign keys that reference this table,
because the referencing tables have to be checked to see if they
contain copies of the key values being deleted.

You either don't have indexes on the referencing columns, or there
is a datatype mismatch, or possibly you need to update statistics
for those tables.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Nov 23 '05 #2
Hi Tom,

Thanks for your help. I checked types and indexes, to no avail. Vacuum
didn't help. but vacuum full did, it's now fast again.

Cheers,

Brock

On Mon, 11 Oct 2004 23:38:49 -0400, Tom Lane <tg*@sss.pgh.pa.us> wrote:
Brock Henry <br*********@gmail.com> writes:
delete from people where id < '2000'

Index Scan using people_pkey on people (cost=0.00..71.68 rows=2792
width=6) (actual time=1.361..5.657 rows=2000 loops=1)
Index Cond: (id < 3000)
Total runtime: 13.006 ms
3 row(s)
Total runtime: 63,869.322 ms


So 13 msec to find the rows to delete, and 63850+ msec in overhead.
Which is certainly from the foreign keys that reference this table,
because the referencing tables have to be checked to see if they
contain copies of the key values being deleted.

You either don't have indexes on the referencing columns, or there
is a datatype mismatch, or possibly you need to update statistics
for those tables.

regards, tom lane


---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to ma*******@postgresql.org)

Nov 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: mamo74 | last post by:
Hello. I am administering a SQL Server (Enterprise Edition on Windows 2003) from some month and can't understand what is going on in the latest week (when the db grow a lot). The DB is around...
5
by: Jan Suchanek | last post by:
Hi, I am using the DB2 GUI to delete all entries of a table (delete from table). The table has app. 900 enties and the removeal takes "forever". The table gets lock (so no select is possible)...
0
by: roiavidan | last post by:
Hi, I'm having a bit of a problem with a small application I wrote in C#, which uses an Access database (mdb file) for storing financial data. After looking for a similiar topic and failing to...
6
by: Rory Campbell-Lange | last post by:
The following query on some small datasets takes over a second to run. I'd be grateful for some help in understanding the explain output, and to remake the code. Looks like the sort is using up...
2
by: Cornelius Buschka | last post by:
Hi, we saw the following problem: We deleted all rows from a table B referencing table A (~500000 records). No problem, but the following try to delete all records from table A (~180000) lead...
50
by: diffuser78 | last post by:
I have just started to learn python. Some said that its slow. Can somebody pin point the issue. Thans
2
by: hikums | last post by:
Hi, Can someone recommend a better approach, I already have clustered indexes on the t1 column in table td. This takes more than 30 hours to complete!! The slowdown is with deletes within the...
1
by: sunith | last post by:
I have a simple delete query like delete from table_name where (col1=:b0 and col2=:b1) This delete would actually delete around 100 records out of 4 Lakh records. This delete is...
3
Atran
by: Atran | last post by:
Hello, When I format my pc, the pc is good. But when I install my useful programs (Many Programs) the computer be slow. So I till to myself cause of many program, then I come to delete many of the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.