Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1agA6O-0003ZC-SI for pgsql-sql@arkaria.postgresql.org; Wed, 16 Mar 2016 11:59:00 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1agA6O-0001Xu-5c for pgsql-sql@arkaria.postgresql.org; Wed, 16 Mar 2016 11:59:00 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1agA5Q-0007tU-DL for pgsql-sql@postgresql.org; Wed, 16 Mar 2016 11:58:00 +0000 Received: from mailout02.ims-firmen.de ([213.174.32.97]) by makus.postgresql.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1agA5M-0005Vq-NJ for pgsql-sql@postgresql.org; Wed, 16 Mar 2016 11:57:59 +0000 Received: from mailin01.ims-firmen.de ([192.168.1.141]) by mailout02.ims-firmen.de with esmtp (envelope-from ) id 1agA5K-0002RM-kJ for pgsql-sql@postgresql.org; Wed, 16 Mar 2016 12:57:54 +0100 Received: from [79.204.179.3] (helo=a-kretschmer.de) by mailin01.ims-firmen.de with esmtpsa (TLSv1:AES256-SHA:256) (envelope-from ) id 1agA5K-0001zZ-0X for pgsql-sql@postgresql.org; Wed, 16 Mar 2016 12:57:54 +0100 Received: from kretschmer by a-kretschmer.de with local (Exim 4.69) (envelope-from ) id 1agA5J-0001jl-LO for pgsql-sql@postgresql.org; Wed, 16 Mar 2016 12:57:53 +0100 Date: Wed, 16 Mar 2016 12:57:53 +0100 From: Andreas Kretschmer To: pgsql-sql@postgresql.org Subject: Re: delete taking long time Message-ID: <20160316115753.GA6081@tux> References: <503958962.9182.1458090747344.JavaMail.open-xchange@oxweb01.ims-firmen.de> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-OS: Debian/GNU Linux - weil ich es mir Wert bin! X-GPG-Fingerprint: EE16 3C01 7B9C 10F7 2C8B 3B86 4DB3 D9EE 7F45 84DA X-Message-Flag: "Windows" is not the answer. "Windows" is the question and the answer is "no"! X-Lugdd: Gerd Kube X-Info: My name is root. Just root. And I am licensed to kill -9 User-Agent: Mutt/1.5.18 (2008-05-17) X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-sql Precedence: bulk Sender: pgsql-sql-owner@postgresql.org ivo liondov wrote: > > explain (analyze) delete from connection where uid in (select uid from > connection where ts > '2016-03-10 01:00:00' and ts < '2016-03-10 01:10:00'); > > > ------------------------------------------------------------------------------------------------------------------------------------------------- > >  Delete on connection  (cost=0.43..174184.31 rows=7756 width=12) (actual time= > 529.739..529.739 rows=0 loops=1) > >    ->  Nested Loop  (cost=0.43..174184.31 rows=7756 width=12) (actual time= > 0.036..526.295 rows=2156 loops=1) > >          ->  Seq Scan on connection connection_1  (cost=0.00..115684.55 rows= > 7756 width=24) (actual time=0.020..505.012 rows=2156 loops=1) > >                Filter: ((ts > '2016-03-10 01:00:00'::timestamp without time > zone) AND (ts < '2016-03-10 01:10:00'::timestamp without time zone)) there is no index on the ts-column. > >                Rows Removed by Filter: 3108811 > >          ->  Index Scan using connection_pkey on connection  (cost=0.43..7.53 > rows=1 width=24) (actual time=0.009..0.010 rows=1 loops=2156) > >                Index Cond: ((uid)::text = (connection_1.uid)::text) > >  Planning time: 0.220 ms > >  Trigger for constraint dns_uid_fkey: time=133.046 calls=2156 > >  Trigger for constraint files_uid_fkey: time=39780.799 calls=2156 > >  Trigger for constraint http_uid_fkey: time=99300.851 calls=2156 > >  Trigger for constraint notice_uid_fkey: time=128.653 calls=2156 > >  Trigger for constraint snmp_uid_fkey: time=59.491 calls=2156 > >  Trigger for constraint ssl_uid_fkey: time=74.052 calls=2156 > >  Trigger for constraint weird_uid_fkey: time=25868.651 calls=2156 > >  Execution time: 165880.419 ms i guess there are no indexes for this tables and the relevant columns > I think you are right, fk seem to take the biggest chunk of time from the hole > delete operation. I made a test with 10.000 rows, it took 12 minutes. 20.000 > rows took about 25 minutes to delete.  create the missing indexes now and come back with the new duration. Andreas -- Really, I'm not out to destroy Microsoft. That will just be a completely unintentional side effect. (Linus Torvalds) "If I was god, I would recompile penguin with --enable-fly." (unknown) Kaufbach, Saxony, Germany, Europe. N 51.05082°, E 13.56889° -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql