Slow Inserts, two different scenarios.

From: Andre Lopes <lopes80andre(at)gmail(dot)com>
To: postgresql Forums <pgsql-general(at)postgresql(dot)org>
Subject: Slow Inserts, two different scenarios.
Date: 2011-02-07 14:12:59
Message-ID: AANLkTimTxjGTGBKiqUfmoi0-pmHuLzZxg8R8HQFGXCvu@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,

I have a problem when doing INSERT's in a table.

The table structure is:

uri (varchar 10000) PK
id_language (varchar 10) PK
id_category (int4) PK
id_data (varchar 50) PK
id_ordinal (int4) PK (this field have a trigger to auto increment)
n_text (text)

When I run this function to do 900000 INSERT's it runs well and in few time:

CREATE OR REPLACE FUNCTION doInserts() RETURNS integer AS
$BODY$
DECLARE
i integer;
BEGIN
i := 1;

while i <= 900000 loop
insert into tdir_uris_text (uri, id_language, id_category, id_data,
n_text) values ('http://localhos/teste' || i, 'PORT', '2',
'pagetitle', 'Pagina teste ' || i);

i := i + 1;
end loop;
RETURN i;
END
$BODY$
LANGUAGE 'plpgsql' ;

But when I do this with 100000 INSERT's it seems to never end the
INSERT's operation, It is running at 5h now...

CREATE OR REPLACE FUNCTION doInserts() RETURNS integer AS
$BODY$
DECLARE
i integer;
BEGIN
i := 1;

while i <= 100000 loop
insert into tdir_uris_text (uri, id_language, id_category, id_data,
n_text) values ('http://localhos/teste' || i, 'PORT', '2',
'pagetitle', 'Pagina teste ' || i);
insert into tdir_uris_text (uri, id_language, id_category, id_data,
n_text) values ('http://localhos/teste' || i, 'PORT', '2',
'country_ad', 'italy');
insert into tdir_uris_text (uri, id_language, id_category, id_data,
n_text) values ('http://localhos/teste' || i, 'PORT', '2',
'services_available', 'service 1');
insert into tdir_uris_text (uri, id_language, id_category, id_data,
n_text) values ('http://localhos/teste' || i, 'PORT', '2',
'services_available', 'service 2');

i := i + 1;
end loop;
RETURN i;
END
$BODY$
LANGUAGE 'plpgsql' ;

What could be the problem here? Any clues?

Best Regards,

Browse pgsql-general by date

  From Date Subject
Next Message Vick Khera 2011-02-07 14:23:45 Re: tuning postgresql writes to disk
Previous Message A B 2011-02-07 14:00:54 How to create index on only some of the rows