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 1jkbOD-0007vP-4B for pgsql-performance@arkaria.postgresql.org; Sun, 14 Jun 2020 22:46:09 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jkbOA-0001cL-EA for pgsql-performance@arkaria.postgresql.org; Sun, 14 Jun 2020 22:46:06 +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 1jkbO9-0001c7-EJ for pgsql-performance@lists.postgresql.org; Sun, 14 Jun 2020 22:46:06 +0000 Received: from sonic316-21.consmr.mail.ne1.yahoo.com ([66.163.187.147]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jkbO1-0002j0-Be for pgsql-performance@lists.postgresql.org; Sun, 14 Jun 2020 22:46:03 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1592174755; bh=JjaM5+HChM9eTlz2/9gHZcgTTtZmuP6DRCoXA0CyfNo=; h=Date:From:To:Subject:References:From:Subject; b=SbQ88bbeGGtLM/GSR37xxJOgLk4AVi3f8/xny/mh1HdCQqJCz4fC1qmFBAjY94MUe3sgtQGTiCeFzPeG3wlHibJrhAWFu0cOh5qrNUGgMNxxidtEWEpA539XMx/pDZgf7CqGPtIPDrIZ6GHBwdd9TkikkFOPMM9kjaQswGmT43paHbwIa9RoGpYM/x6XPhWn589Qf/CdTO8uYgs+Uay0AoeD3v4No++BH/U63j2tUuORvdIfC0kUYgzSdjMA6oUYxRW0AGnsdX0pdaOyTuqZpB206OLeXAYslK4EHLVuek2XRhZ0JrErrdS9IYaq8vIx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zA9VgZ9OB6 F9sDiN4BoLnjgdHPugcqTbTY_WLkUqe5.1Ujl_2A2f0EEGqLZzBAZNW5pDbyLOrhDRfcyde44dqE KiLMKzhPXAfWO9AXs4qITMTXl.cULPKWwyOXSLxfGduQCi92YECldg9cBWCduWBvVazBzE61b6m3 mT45iVEq4OeBSXvNIEAL5yAT1b6ZEGzD0UIq9nxovrFFU8UiPCzUDpR6BsX46Xs9_7xfLg_sQwPx 7fIBnlARfnccpVxm9.Hfw4fbhlRHJ82YHYjPiLb2LnZyh3hipQHPvTA_ppTfrrwjOTaUCI7KiTIJ 29jswQlIOE.2PcJNwXHVM9qf7An8ro2thwJ8dR4Y1hFO8kX9lU4WZ.AW3qEsgAERiSewzK9MUvO. Rn87g6J5ptYbM1DdreCiIgeiz4Dkh_ZfMJI3aoMVAARourt8O2sNzwSaUs4RhAQ-- Received: from sonic.gate.mail.ne1.yahoo.com by sonic316.consmr.mail.ne1.yahoo.com with HTTP; Sun, 14 Jun 2020 22:45:55 +0000 Date: Sun, 14 Jun 2020 22:45:52 +0000 (UTC) From: Nagaraj Raj To: Pgsql Performance Message-ID: <1211705382.726951.1592174752720@mail.yahoo.com> Subject: Performance issue MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit References: <1211705382.726951.1592174752720.ref@mail.yahoo.com> X-Mailer: WebService/1.1.16119 YMailNodin Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36 Content-Length: 8141 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hello My PostgreSQL server 10.11 running on windows which are running very slow. DB has two tables with ~200Mil records in each. user queries are very slow even explain analyze also taking a longer. Could you please help me to tune this query and any suggestions to improve system performance? Table structures: Table1: -- Records 213621151 CREATE TABLE test1 ( individual_entity_proxy_id bigint NOT NULL, household_entity_proxy_id bigint, individual_personal_link_sid bigint NOT NULL, city_name character varying(100) COLLATE pg_catalog."default", state_prov_cd character varying(40) COLLATE pg_catalog."default", pstl_code character varying(40) COLLATE pg_catalog."default", npa integer, nxx integer, email_domain character varying(400) COLLATE pg_catalog."default", email_preference character varying(40) COLLATE pg_catalog."default", direct_mail_preference character varying(40) COLLATE pg_catalog."default", profane_wrd_ind character(1) COLLATE pg_catalog."default", tmo_ofnsv_name_ind character(1) COLLATE pg_catalog."default", census_block_id character varying(40) COLLATE pg_catalog."default", has_first_name character(1) COLLATE pg_catalog."default", has_middle_name character(1) COLLATE pg_catalog."default", has_last_name character(1) COLLATE pg_catalog."default", has_email_address character(1) COLLATE pg_catalog."default", has_individual_address character(1) COLLATE pg_catalog."default", email_address_sid bigint, person_name_sid bigint, physical_address_sid bigint, telephone_number_sid bigint, shared_email_with_customer_ind character(1) COLLATE pg_catalog."default", shared_paddr_with_customer_ind character(1) COLLATE pg_catalog."default", last_contacted_email_datetime timestamp without time zone, last_contacted_dm_datetime timestamp without time zone, last_contacted_digital_datetime timestamp without time zone, last_contacted_anychannel_dttm timestamp without time zone, hard_bounce_ind integer, src_sys_id integer NOT NULL, insrt_prcs_id bigint, updt_prcs_id bigint, stg_prcs_id bigint, load_dttm timestamp without time zone NOT NULL, updt_dttm timestamp without time zone, md5_chk_sum character varying(200) COLLATE pg_catalog."default", deld_from_src_ind character(1) COLLATE pg_catalog."default" NOT NULL, orphan_ind character(1) COLLATE pg_catalog."default" NOT NULL, CONSTRAINT pk_i_entity_proxy_id PRIMARY KEY (individual_entity_proxy_id) ); CREATE INDEX indx_prospect_indv_entty_id ON test1 USING btree (individual_entity_proxy_id ) Table 2: -- Records 260652202 CREATE TABLE test2 ( individual_entity_proxy_id bigint NOT NULL, cstmr_prspct_ind character varying(40) COLLATE pg_catalog."default", last_appnd_dttm timestamp without time zone, last_sprsn_dttm timestamp without time zone, infrrd_gender_code character varying(40) COLLATE pg_catalog."default", govt_prison_ind character(1) COLLATE pg_catalog."default", tax_bnkrpt_dcsd_ind character(1) COLLATE pg_catalog."default", underbank_rank_nbr integer, hvy_txn_rank_nbr integer, prominence_nbr integer, ocptn_code character varying(40) COLLATE pg_catalog."default", educ_lvl_nbr integer, gender_code character varying(40) COLLATE pg_catalog."default", infrrd_hh_rank_nbr integer, econmc_stable_nbr integer, directv_sbscrbr_propnsty_code character varying(40) COLLATE pg_catalog."default", dish_sbscrbr_propnsty_code character varying(40) COLLATE pg_catalog."default", iphone_user_propnsty_code character varying(40) COLLATE pg_catalog."default", smrt_hm_devc_propnsty_code character varying(40) COLLATE pg_catalog."default", sml_busi_ownr_propnsty_code character varying(40) COLLATE pg_catalog."default", tv_internet_bndl_propnsty_code character varying(40) COLLATE pg_catalog."default", dog_ownr_propnsty_code character varying(40) COLLATE pg_catalog."default", cat_ownr_propnsty_code character varying(40) COLLATE pg_catalog."default", dine_out_propnsty_code character varying(40) COLLATE pg_catalog."default", taco_bell_diner_propnsty_code character varying(40) COLLATE pg_catalog."default", auto_insrnc_byr_propnsty_code character varying(40) COLLATE pg_catalog."default", src_sys_id integer NOT NULL, insrt_prcs_id bigint, updt_prcs_id bigint, stg_prcs_id bigint, load_dttm timestamp without time zone NOT NULL, updt_dttm timestamp without time zone, deld_from_src_ind character(1) COLLATE pg_catalog."default" NOT NULL, orphan_ind character(1) COLLATE pg_catalog."default" NOT NULL, CONSTRAINT pk_entity_proxy_id PRIMARY KEY (individual_entity_proxy_id) ); User query: explain analyze select COUNT(*) as "DII_1" from ( select distinct table0."individual_entity_proxy_id" as "INDIVIDUAL_ENTITY_PROXY_ID" from test1 table0 inner join test2 table1 on table0."individual_entity_proxy_id" = table1."individual_entity_proxy_id" where ((table0."shared_paddr_with_customer_ind" = 'N') and (table0."profane_wrd_ind" = 'N') and (table0."tmo_ofnsv_name_ind" = 'N') and ((table0."last_contacted_dm_datetime" is null) or (table0."last_contacted_dm_datetime" < TIMESTAMP '2020-03-15 0:00:00.000000')) and (table0."has_individual_address" = 'Y') and (table0."has_last_name" = 'Y') and (table0."has_first_name" = 'Y') and (table0."direct_mail_preference" is null)) and ((table1."tax_bnkrpt_dcsd_ind" = 'N') and (table1."cstmr_prspct_ind" = 'Prospect') and (table1."govt_prison_ind" = 'N')) ) TXT_1; Explain Analyze : "Aggregate (cost=5345632.91..5345632.92 rows=1 width=8) (actual time=442688.462..442688.462 rows=1 loops=1)" " -> Unique (cost=150.13..4943749.39 rows=32150682 width=8) (actual time=0.022..439964.214 rows=32368180 loops=1)" " -> Merge Join (cost=150.13..4863372.68 rows=32150682 width=8) (actual time=0.021..435818.276 rows=32368180 loops=1)" " Merge Cond: (table0.individual_entity_proxy_id = table1.individual_entity_proxy_id)" " -> Index Scan using indx_prospect_indv_entty_id on test1 table0 (cost=0.56..2493461.92 rows=32233405 width=8) (actual time=0.011..63009.551 rows=32368180 loops=1)" " Filter: ((direct_mail_preference IS NULL) AND ((last_contacted_dm_datetime IS NULL) OR (last_contacted_dm_datetime < '2020-03-15 00:00:00'::timestamp without time zone)) AND (shared_paddr_with_customer_ind = 'N'::bpchar) AND (profane_wrd_ind = 'N'::bpchar) AND (tmo_ofnsv_name_ind = 'N'::bpchar) AND (has_individual_address = 'Y'::bpchar) AND (has_last_name = 'Y'::bpchar) AND (has_first_name = 'Y'::bpchar))" " Rows Removed by Filter: 7709177" " -> Index Scan using pk_entity_proxy_id on test2 table1 (cost=0.56..1867677.94 rows=40071417 width=8) (actual time=0.008..363534.437 rows=40077727 loops=1)" " Filter: ((tax_bnkrpt_dcsd_ind = 'N'::bpchar) AND (govt_prison_ind = 'N'::bpchar) AND ((cstmr_prspct_ind)::text = 'Prospect'::text))" " Rows Removed by Filter: 94756" "Planning time: 0.400 ms" "Execution time: 442688.523 ms" Server config: PostgreSQL v10.11 RAM: 380GB vCore: 32 Shared_buffers: 65GB work_mem:104857kB maintenance_work_mem:256MB effective_cache_size: 160GB https://dba.stackexchange.com/questions/269138/postgresql-server-running-very-slow-at-minimal-work-load Thanks, Raj