Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iUfSt-0001aT-Ea for pgsql-general@arkaria.postgresql.org; Tue, 12 Nov 2019 23:20:51 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iUfSq-0007Rp-Cm for pgsql-general@arkaria.postgresql.org; Tue, 12 Nov 2019 23:20:48 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iUfSp-0007Ri-TV for pgsql-general@lists.postgresql.org; Tue, 12 Nov 2019 23:20:48 +0000 Received: from post.visena.com ([46.226.10.50]) by makus.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.92) (envelope-from ) id 1iUfSl-0001Av-5S for pgsql-general@postgresql.org; Tue, 12 Nov 2019 23:20:46 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=visena.com; s=20141101.wh; h=Content-Type:MIME-Version:Subject:In-Reply-To:Message-ID:Cc:To:From:Date; bh=/9rp9U6rq0nn5cyO/xuhPQT5h8ZvNHWMZVskd0zIiDA=; b=DAdZd7e7aUFFJBa+XCgbOpDteb86oOOm2HQOBbG9uDp2XIxDfvig/JGyuCSFgi14+uE7Gr2q99R0eIYB8awEGaatWn4TRVfsloD8L3m9mHlkt/AyRXVyEioB96iR9z1gG4Lqwkq6LHztgQaU3ClfKhnFkQ3I8Vg0mzEL6BOiL7U=; Received: from [10.0.1.10] (helo=tc7-visena.wh.internal.visena.com) by post.visena.com with esmtp (Exim 4.82) (envelope-from ) id 1iUfSf-0004q9-1N; Wed, 13 Nov 2019 00:20:39 +0100 Received: from localhost ([127.0.0.1] helo=tc7-visena.wh.internal.visena.com) by tc7-visena.wh.internal.visena.com with esmtp (Exim 4.90_1) (envelope-from ) id 1iUfSe-0005zS-Vq; Wed, 13 Nov 2019 00:20:36 +0100 Date: Wed, 13 Nov 2019 00:20:36 +0100 (CET) From: Andreas Joseph Krogh To: DrakoRod Cc: pgsql-general@postgresql.org Message-ID: In-Reply-To: <1573598838391-0.post@n3.nabble.com> Subject: Sv: DELETE Query Hang MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_Part_375_202989638.1573600836886" X-Mailer: Visena Mail 2.2.164 X-Spam-Score: -1.0 X-Spam-Report: SpamAssasin (score=-1.0, required 5.0 ALL_TRUSTED=-1,HTML_MESSAGE=0.001) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk ------=_Part_375_202989638.1573600836886 Content-Type: multipart/related; boundary="----=_Part_376_1495096443.1573600836886" ------=_Part_376_1495096443.1573600836886 Content-Type: multipart/alternative; boundary="----=_Part_377_61829410.1573600836896" ------=_Part_377_61829410.1573600836896 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable P=C3=A5 tirsdag 12. november 2019 kl. 23:47:18, skrev DrakoRod < drakoflames@hotmail.com >:=20 Hi folks! I Have a question, in a database are a table with many files (bytea) store= d (I support this database a don't design it), but we need delete many rows (38000 rows approx), but I when execute query: BEGIN; ALTER TABLE my_file_table DISABLE TRIGGER ALL; DELETE FROM my_file_table WHERE id_table <> 230; This query hang... 50 minutes and the query do not finish. Any suggestion?=20 Check for locks and blocking statements:=20 https://wiki.postgresql.org/wiki/Lock_Monitoring=20 =20 You can delete in chunks like this:=20 do $_$ declare num_rows bigint; begin loop delete from YourTable where id= in=20 (select id from YourTable where id < 500 limit 100); get diagnostics num_ro= ws =3D=20 row_count; raise notice 'deleted % rows', num_rows; exit when num_rows =3D = 0; end=20 loop; end;$_$;=20 -- Andreas Joseph Krogh=20 ------=_Part_377_61829410.1573600836896 Content-Type: text/html;charset=UTF-8 Content-Transfer-Encoding: quoted-printable
P=C3=A5 tirsdag 12. november 2019 kl. 23:47:18, skrev DrakoRod <drakoflames@hotmail.com>:
Hi = folks!

I Have a question, in a database are a table with many files (bytea) stored=
(I support this database a don't design it), but we need delete many rows (38000 rows approx),=C2=A0 but I when execute query:

BEGIN;
ALTER TABLE my_file_table DISABLE TRIGGER ALL;
DELETE FROM my_file_table WHERE id_table <> 230;

This query hang... 50 minutes and the query do not finish.

Any suggestion?
=C2=A0
Check for locks and blocking statements:
=C2=A0
You can delete in chunks like this:
=C2=A0
do $_$
declare
    num_rows =
bigint;
begin
    loop
        delete from =
YourTable where id in
                    =
                (sel=
ect id from Y=
ourTable where id &l=
t; 500 limit 100);
        get diagnostics num_rows =3D row_count<=
/span>;
        raise notice 'deleted % rows', n=
um_rows;
        exit when nu=
m_rows =3D 0;
    end loop;
end;$_$;
=C2=A0
">
--
Andreas Joseph Krogh
=C2=A0
------=_Part_377_61829410.1573600836896-- ------=_Part_376_1495096443.1573600836886-- ------=_Part_375_202989638.1573600836886--