From vilson.farias@digitro.com.br Mon Aug 26 19:26:52 2002 Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 4E5FE475B22 for ; Mon, 26 Aug 2002 15:26:52 -0400 (EDT) Received: from ias.digitro.com.br (unknown [200.247.100.134]) by postgresql.org (Postfix) with ESMTP id CA1D2475AEB for ; Mon, 26 Aug 2002 15:26:50 -0400 (EDT) Received: from serverdgt.daf.digitro.com.br (serverdgt.daf.digitro.com.br [192.2.2.10]) by ias.digitro.com.br (8.11.6/8.11.1) with ESMTP id g7QJMGb11304 for ; Mon, 26 Aug 2002 16:22:16 -0300 Received: from dgtac ([192.168.160.152]) by serverdgt.daf.digitro.com.br (8.11.1/8.8.7) with SMTP id g7QJQIt30344 for ; Mon, 26 Aug 2002 16:26:18 -0300 Message-ID: <00ee01c24d36$7246a3c0$98a0a8c0@dgtac> From: "Vilson farias" To: Subject: Deleting large amount of data. Date: Mon, 26 Aug 2002 16:26:14 -0300 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_00EB_01C24D1D.4C0806E0" X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2600.0000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200208/307 X-Sequence-Number: 5421 This is a multi-part message in MIME format. ------=_NextPart_000_00EB_01C24D1D.4C0806E0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Greetings, I'm having some perfomance problems related with large amount of tuples= in a table, so I decided to start programming some shell scripts to be pla= ced in crontad to remove old data every night.=20 Now, my questions are :=20 If I just execute a DELETE * FROM WHERE call_start < '2002-08-21' and cal= l_start > '2002-08-20', and that interval has 100.000 tuples, does DELETE s= tart and commit a transaction for every single deletion? And If I put a BEGIN at the beginning and a COMMIT at the end, do deleted= tuples overload transaction logs?=20 Finally, what's the best thing to do? Best regards. ---------------------------------------------------------------------------= ----- Jos=E9 Vilson de Mello de Farias Software Engineer D=EDgitro Tecnologia Ltda - www.digitro.com.br - Brazil APC - Customer Oriented Applications E-mail: vilson.farias@digitro.com.br Tel.: +55 48 281 7158=20 ICQ 11866179 ---------------------------------------------------------------------------= ----- Jos=E9 Vilson de Mello de Farias Analista de Sistemas =20 D=EDgitro Tecnologia Ltda - www.digitro.com.br APC - Aplicativos Orientados ao Cliente E-mail: vilson.farias@digitro.com.br Tel.: +55 48 281 7158=20 ICQ 11866179 ------=_NextPart_000_00EB_01C24D1D.4C0806E0 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
Greetings,
 
    I'm having some perfo= mance=20 problems related with large amount of tuples in a table, so I decided to st= art=20 programming some shell scripts to be placed in crontad to remove old data e= very=20 night.
 
   Now, my questions are :=20
 
  If I just execute a DELETE * FROM= =20 WHERE call_start < '2002-08-21' and call_start >=20 '2002-08-20', and that interval has 100.000 tuples, does DELETE start and c= ommit=20 a transaction for every single deletion?
 
  And If I put a BEGIN at the begin= ning and=20 a COMMIT at the end, do deleted tuples overload transaction logs?
 
  Finally, what's the best thing to= =20 do?
 
Best regards.
 
------------------------------------------------------------------= --------------
Jos=E9=20 Vilson de Mello de Farias
Software Engineer
 
D=EDgitro Tecnologia Ltda - www.digitro.com.br - Brazil
= APC -=20 Customer Oriented Applications
E-mail: vilson.farias@digitro.com.br
Tel.:=20 +55 48 281 7158
ICQ 11866179
------------------------------------------------------------------= --------------
Jos=E9=20 Vilson de Mello de Farias
Analista de Sistemas
 
D=EDgitro&nb= sp;=20 Tecnologia  Ltda   -   www.digitro.com.br
APC - Aplicati= vos=20 Orientados ao Cliente
E-mail: vilson.farias@digitro.com.br
Tel.:=20 +55 48 281 7158
ICQ 11866179
------=_NextPart_000_00EB_01C24D1D.4C0806E0-- From sszabo@megazone23.bigpanda.com Mon Aug 26 19:49:31 2002 Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 88F09475AEB for ; Mon, 26 Aug 2002 15:49:31 -0400 (EDT) Received: from megazone.bigpanda.com (megazone.bigpanda.com [63.150.15.178]) by postgresql.org (Postfix) with ESMTP id 16DE1475A3F for ; Mon, 26 Aug 2002 15:49:28 -0400 (EDT) Received: by megazone.bigpanda.com (Postfix, from userid 1001) id 7C418D5FA; Mon, 26 Aug 2002 12:49:27 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by megazone.bigpanda.com (Postfix) with ESMTP id 67EAE5C02; Mon, 26 Aug 2002 12:49:27 -0700 (PDT) Date: Mon, 26 Aug 2002 12:49:27 -0700 (PDT) From: Stephan Szabo To: Vilson farias Cc: Subject: Re: Deleting large amount of data. In-Reply-To: <00ee01c24d36$7246a3c0$98a0a8c0@dgtac> Message-ID: <20020826124628.C64199-100000@megazone23.bigpanda.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200208/308 X-Sequence-Number: 5422 On Mon, 26 Aug 2002, Vilson farias wrote: > Greetings, > > I'm having some perfomance problems related with large amount of > tuples in a table, so I decided to start programming some shell > scripts to be placed in crontad to remove old data every night. Hmm, you might want to send some info on the schema/queries/explain output, maybe someone'll be able to help. > > Now, my questions are : > > If I just execute a DELETE * FROM WHERE call_start < '2002-08-21' > and call_start > '2002-08-20', and that interval has 100.000 tuples, > does DELETE start and commit a transaction for every single deletion? No. It's all one statement, so it'll be in its containing transaction (if you haven't started one, it'll be put into its own). From vilson.farias@digitro.com.br Tue Aug 27 12:36:55 2002 Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 839314758BB for ; Tue, 27 Aug 2002 08:36:55 -0400 (EDT) Received: from ias.digitro.com.br (unknown [200.247.100.134]) by postgresql.org (Postfix) with ESMTP id 3855C474E4E for ; Tue, 27 Aug 2002 08:36:54 -0400 (EDT) Received: from serverdgt.daf.digitro.com.br (serverdgt.daf.digitro.com.br [192.2.2.10]) by ias.digitro.com.br (8.11.6/8.11.1) with ESMTP id g7RCWRb23423 for ; Tue, 27 Aug 2002 09:32:27 -0300 Received: from dgtac ([192.168.160.152]) by serverdgt.daf.digitro.com.br (8.11.1/8.8.7) with SMTP id g7RCaYt27577 for ; Tue, 27 Aug 2002 09:36:34 -0300 Message-ID: <016e01c24dc6$5bf743f0$98a0a8c0@dgtac> From: "Vilson farias" To: References: <20020826124628.C64199-100000@megazone23.bigpanda.com> Subject: Re: Deleting large amount of data. Date: Tue, 27 Aug 2002 09:36:24 -0300 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2600.0000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200208/310 X-Sequence-Number: 5424 Thanks for ask my post, Mr. Szabo. Thanks for worry about my performance problems, but they are natural for my database, once my hardware isn't a Ferrari and my table has more than 2 milion of touples and it's related with a lot of other very high populated tables. I realized I can keep no longer than 6 mounths of data in these tables, so I would like to remove older data every night. I didn't write any code yet and I can't start testing the best way in my databases, so I'm posting here to get some advices. I'm worried about performance problems that could raise when a start removing 12000 touples in a single transaction once I don't know how PostgreSQL works internally. Can a single transaction deal with so many data without problem or overloading transaction buffers (or something like that) or do I need to split deletion process in smaller sets of data? My main table wich has more than 2milion of touples : CREATE TABLE cham_chamada ( cod_bxs integer NOT NULL, chave integer NOT NULL, identificacao integer NOT NULL, dt_inicial timestamp NOT NULL, indicadora integer, cod_categoria integer, identidadea varchar(20), dt_final timestamp , juntor integer, indicadorb integer, identidadeb varchar(20), flg_chamada char(1), flg_liberacao char(1), temp_total integer, ddd smallint, cod_liberjuntor integer, cod_resultcham integer, cod_fds integer, cifra_origem integer, csp char(2), conta integer, ramal varchar(20), ultimo_ramal varchar(20), CONSTRAINT XPKcham_chamada PRIMARY KEY (dt_inicial, cod_bxs, chave, identificacao) ) ; CREATE INDEX XIE1cham_chamada ON cham_chamada ( dt_final , identidadea ); CREATE INDEX XIE2cham_chamada ON cham_chamada ( dt_final , flg_chamada ); From sszabo@megazone23.bigpanda.com Tue Aug 27 15:16:57 2002 Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 89FA447653A for ; Tue, 27 Aug 2002 11:16:57 -0400 (EDT) Received: from megazone.bigpanda.com (megazone.bigpanda.com [63.150.15.178]) by postgresql.org (Postfix) with ESMTP id BC1FA476525 for ; Tue, 27 Aug 2002 11:16:53 -0400 (EDT) Received: by megazone.bigpanda.com (Postfix, from userid 1001) id C7EFBD60C; Tue, 27 Aug 2002 08:16:54 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by megazone.bigpanda.com (Postfix) with ESMTP id BDA255C02; Tue, 27 Aug 2002 08:16:54 -0700 (PDT) Date: Tue, 27 Aug 2002 08:16:54 -0700 (PDT) From: Stephan Szabo To: Vilson farias Cc: Subject: Re: Deleting large amount of data. In-Reply-To: <016e01c24dc6$5bf743f0$98a0a8c0@dgtac> Message-ID: <20020827081250.G72641-100000@megazone23.bigpanda.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200208/312 X-Sequence-Number: 5426 On Tue, 27 Aug 2002, Vilson farias wrote: > > > Thanks for ask my post, Mr. Szabo. > > Thanks for worry about my performance problems, but they are natural for > my database, once my hardware isn't a Ferrari and my table has more than 2 > milion of touples and it's related with a lot of other very high populated > tables. I realized I can keep no longer than 6 mounths of data in these > tables, so I would like to remove older data every night. I didn't write any > code yet and I can't start testing the best way in my databases, so I'm > posting here to get some advices. I'm worried about performance problems > that could raise when a start removing 12000 touples in a single transaction > once I don't know how PostgreSQL works internally. Can a single transaction > deal with so many data without problem or overloading transaction buffers > (or something like that) or do I need to split deletion process in smaller > sets of data? 12000 rows shouldn't be a big deal. I assume you're adding about the same number per day basically, so it's a rotating window. The things to be sure of are that the column you're deleting by is indexed (using the definition below this means dt_inicial or dt_final has to be part of the constraint). You should check with explain to make sure it's using the index (if it says it's not, you should analyze the table and try again). Also, if you're running 7.2, you should probably do a vacuum afterwards (without full) and after say a couple of weeks of this, if you notice your disk space is increasing, there are some configuration options which can help (look for the free space map options in the configuration file). > > My main table wich has more than 2milion of touples : > CREATE TABLE cham_chamada ( > cod_bxs integer NOT NULL, > chave integer NOT NULL, > identificacao integer NOT NULL, > dt_inicial timestamp NOT NULL, > indicadora integer, > cod_categoria integer, > identidadea varchar(20), > dt_final timestamp , > juntor integer, > indicadorb integer, > identidadeb varchar(20), > flg_chamada char(1), > flg_liberacao char(1), > temp_total integer, > ddd smallint, > cod_liberjuntor integer, > cod_resultcham integer, > cod_fds integer, > cifra_origem integer, > csp char(2), > conta integer, > ramal varchar(20), > ultimo_ramal varchar(20), > CONSTRAINT XPKcham_chamada PRIMARY KEY (dt_inicial, cod_bxs, chave, > identificacao) > > ) > ; > > CREATE INDEX XIE1cham_chamada ON cham_chamada > ( > dt_final , > identidadea > ); > > CREATE INDEX XIE2cham_chamada ON cham_chamada > ( > dt_final , > flg_chamada > );