Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1komFS-0001VW-Nq for pgsql-general@arkaria.postgresql.org; Mon, 14 Dec 2020 11:42:38 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1komFR-00056v-NQ for pgsql-general@arkaria.postgresql.org; Mon, 14 Dec 2020 11:42:37 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1komC2-0007K1-3k for pgsql-general@lists.postgresql.org; Mon, 14 Dec 2020 11:39:06 +0000 Received: from mail1.sandvine.com ([207.219.248.234]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.92) (envelope-from ) id 1komBv-0001bo-Kh for pgsql-general@postgresql.org; Mon, 14 Dec 2020 11:39:05 +0000 Received: from WTL-EXCHSV2-1.sandvine.com (192.168.194.58) by WTL-EXCHSV2-1.sandvine.com (192.168.194.58) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P521) id 15.1.2106.2; Mon, 14 Dec 2020 06:38:43 -0500 Received: from blr-exchsv1-1.sandvine.com (10.30.4.73) by WTL-EXCHSV2-1.sandvine.com (192.168.194.58) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P521) id 15.1.2106.2 via Frontend Transport; Mon, 14 Dec 2020 06:38:42 -0500 Received: from blr-exchsv1-1.sandvine.com (10.30.4.73) by blr-exchsv1-1.sandvine.com (10.30.4.73) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P521) id 15.1.2106.2; Mon, 14 Dec 2020 17:08:37 +0530 Received: from blr-exchsv1-1.sandvine.com ([fe80::8cb6:e09c:f011:98f6]) by blr-exchsv1-1.sandvine.com ([fe80::8cb6:e09c:f011:98f6%23]) with mapi id 15.01.2106.002; Mon, 14 Dec 2020 17:08:37 +0530 From: Karthik Shivashankar To: "pgsql-general@postgresql.org" Subject: Improving performance of select query Thread-Topic: Improving performance of select query Thread-Index: AdbSDPnAJniAPuwVSSScNcsVx5SD1g== Date: Mon, 14 Dec 2020 11:38:37 +0000 Message-ID: <20c57bfb287749c2a5ff22d7ddd3df93@sandvine.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.30.14.21] x-c2processedorg: b2f06e69-072f-40ee-90c5-80a34e700794 Content-Type: multipart/alternative; boundary="_000_20c57bfb287749c2a5ff22d7ddd3df93sandvinecom_" MIME-Version: 1.0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --_000_20c57bfb287749c2a5ff22d7ddd3df93sandvinecom_ Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Hi, I have a postgres(v9.5) table named customer holding 1 billion rows. It is = not partitioned but it has an index against the primary key (integer). I ne= ed to keep a very few records (say, about 10k rows) and remove everything e= lse. insert into customer_backup select * from customer where customer_id in (,,..); If I go for something like above I'm afraid the insert-select may take a ve= ry long time as when I ran select count(*) from customer; it is taking about 45 minutes to return the count. Are there ways to improve the efficiency of the insert-select by , say, tun= ing some configurations related to memory to improve the efficiency ? This is a box with 96GB of RAM overall and I can stop all the data load and= DML operations if needed. But need a way to run this query as much effici= ently as possible Thanks and Regards, Karthik Disclaimer: This communication (including any attachments) is intended for the use of t= he intended recipient(s) only and may contain information that is considere= d confidential, proprietary, sensitive and/or otherwise legally protected. = Any unauthorized use or dissemination of this communication is strictly pro= hibited. If you have received this communication in error, please immediate= ly notify the sender by return e-mail message and delete all copies of the = original communication. Thank you for your cooperation. --_000_20c57bfb287749c2a5ff22d7ddd3df93sandvinecom_ Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable

Hi,

 

I have a postgres(v9.5= ) table named customer holding 1 billion rows. It is not partitioned but it= has an index against the primary key (integer). I need to keep a very few records (say, about 10k rows) and remove everyth= ing else.

 

insert into customer_backup select * from custome= r where customer_id in (<id1>,<id2>,..);

 

If I go for something = like above I'm afraid the insert-select may take a very long time as when I= ran

 

select count(*) from customer;

 

it is taking about 45 minutes to return the count.=

Are there ways to improve the efficiency of the insert-select = by , say, tuning some configurations related to memory to improve the effic= iency ?

 

This is a box with 96GB of RAM overall and I can sto= p all the data load and DML operations if needed.  But need a way to r= un this query as much efficiently as possible

 

Thanks and Regards,

Karthik

Disclaimer:
This communication (including any attachments) is intended for the use of t= he intended recipient(s) only and may contain information that is considere= d confidential, proprietary, sensitive and/or otherwise legally protected. = Any unauthorized use or dissemination of this communication is strictly prohibited. If you have received this co= mmunication in error, please immediately notify the sender by return e-mail= message and delete all copies of the original communication. Thank you for= your cooperation.

--_000_20c57bfb287749c2a5ff22d7ddd3df93sandvinecom_--