Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ag00o-0006BT-L7 for pgsql-sql@arkaria.postgresql.org; Wed, 16 Mar 2016 01:12:34 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1ag00o-00033l-6u for pgsql-sql@arkaria.postgresql.org; Wed, 16 Mar 2016 01:12:34 +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 1ag00n-00033Z-IF for pgsql-sql@postgresql.org; Wed, 16 Mar 2016 01:12:33 +0000 Received: from mailout01.ims-firmen.de ([213.174.32.96]) by makus.postgresql.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1ag00k-0000lZ-FV for pgsql-sql@postgresql.org; Wed, 16 Mar 2016 01:12:32 +0000 Received: from mailin01.ims-firmen.de ([192.168.1.141]) by mailout01.ims-firmen.de with esmtp (envelope-from ) id 1ag00h-0008NT-hO; Wed, 16 Mar 2016 02:12:27 +0100 Received: from [213.174.32.191] (helo=oxweb01.ims-firmen.de) by mailin01.ims-firmen.de with esmtpsa (TLSv1:RC4-MD5:128) (envelope-from ) id 1ag00h-0005qv-1B; Wed, 16 Mar 2016 02:12:27 +0100 Date: Wed, 16 Mar 2016 02:12:27 +0100 (CET) From: Andreas Kretschmer Reply-To: Andreas Kretschmer To: ivo liondov , pgsql-sql@postgresql.org Message-ID: <503958962.9182.1458090747344.JavaMail.open-xchange@oxweb01.ims-firmen.de> In-Reply-To: References: Subject: Re: delete taking long time MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Priority: 3 Importance: Medium X-Mailer: Open-Xchange Mailer v7.6.2-Rev12 X-Originating-Client: com.openexchange.ox.gui.dhtml 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 > > I am trying to delete the connections with date 2016-03-10 by using the > following: > > > delete from connection where uid in (select uid from connection where ts > > '2016-03-10 00:30:00'); try to rewrite that to : delete from connection where ts > '2016-03-10 00:30:00'; It's simpler - and (maybe) faster. > There are around 800.000 records matching this rule, and seems to be taking > an awful lot of time - 4 hours and counting. What could be the reason for > such a performance hit and how could I optimise this for future cases? > > Regards. the db has to touch such many rows, and has to write the transaction log. And update every index. And it has to check the referenced tables for the constraints. Do you have proper indexes? How large is shared_buffers set? Can you show us the explain (analyse)? Regards, Andreas -- Andreas Kretschmer http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql