2

I'm doing massive tests on a Postgres database...

so basically I have 2 table where I inserted 40.000.000 records on, let's say table1 and 80.000.000 on table2

after this I deleted all those records.

Now if I do SELECT * FROM table1 it takes 199000ms ?

I can't understand what's happening?

can anyone help me on this?

2
  • How much data is each row? How are the tables configured? What types of key are you using? Commented Jun 16, 2010 at 12:35
  • What Postgres version? Is Autovac running? Commented Jun 16, 2010 at 13:09

3 Answers 3

7

If you delete all the rows from a table, they are marked as deleted but not actually removed from disk immediately. In order to remove them you need to do a "vacuum" operation- this should kick in automatically some time after such a big delete. Even so, that will just leave the pages empty but taking up quite a bit of disk space without a "vacuum full".

If you regularly need to do delete all the rows from a large table, consider using "truncate" instead, which simply zaps the table data file.

Sign up to request clarification or add additional context in comments.

Comments

3

The tuples are logically deleted, not fisically. You should perform a VACUUM on the db. More info here

Comments

0

If you are deleting all records, use truncate not delete. Further the first time you run it the relation will not be cached (file cache or shared buffers), so it will be slower than subsequent times.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.