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 1p2NO3-0001gs-QE for pgsql-admin@arkaria.postgresql.org; Tue, 06 Dec 2022 02:08:47 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1p2NO2-00077w-H1 for pgsql-admin@arkaria.postgresql.org; Tue, 06 Dec 2022 02:08:46 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1p2NO2-00077Y-3U for pgsql-admin@lists.postgresql.org; Tue, 06 Dec 2022 02:08:46 +0000 Received: from mail-qt1-x82d.google.com ([2607:f8b0:4864:20::82d]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1p2NNz-0001qN-EO for pgsql-admin@lists.postgresql.org; Tue, 06 Dec 2022 02:08:45 +0000 Received: by mail-qt1-x82d.google.com with SMTP id ay32so4764602qtb.11 for ; Mon, 05 Dec 2022 18:08:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=in-reply-to:from:content-language:references:to:subject:user-agent :mime-version:date:message-id:from:to:cc:subject:date:message-id :reply-to; bh=JnDgs2fiNUysbUnYgJ8BHzUsfCp5HoX+0NLA/EPHo0k=; b=fxAnacVh2s8+DMVwR346KXPTbEsEYPEUKN7IEJsalgLRRhRi+XNO4q8Eml/Hw2GLki wqSMYvM+gnceYeiM6BlLgH971IdybQwMurMuJoO2fjTNXVC1Zp5gis3YiMx1chXsCUaL XBLxN8h+BZb0j1AbIxVz1e8wn5wKVmeHdQl4izdL0sH5dBPWSRYgoKMcIeMGNDp0Nss9 mAo2B2SLT1OP4TGePWTxRI3+iWEJNbqAr1CI9uOKgLuv/0SNjFMbJLDY3rlxWi1YfU8T LWpjp2i/Iak09cShWgF+taKQcP7wgjVu2f0K5CSlM8XLfCt9QtX0NG2lv/gs4PgtB6cG YQ5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:from:content-language:references:to:subject:user-agent :mime-version:date:message-id:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=JnDgs2fiNUysbUnYgJ8BHzUsfCp5HoX+0NLA/EPHo0k=; b=ejDsxR4ziQ9VXL0iNgAkwDEjv3KQiruNV0Hve9YdUNnF2qcCE6P6pDTEptJkes3nzj 1ag0loOzZovvEhfb+DSgqWaQ+uVLyBZwvNTcOzwGrkUuhmhz5P9Ndfiwj+YJE8GYBCHa ITAd613mv2pRr4+DRgYnWQZ/1vTYwyKr1rLM1YecO7dQ42x+lRD8Sh9Kwy1DWEBPKg4m PRCpLXSJFjg2oOR9MsToWGYiZrP53z6vlky5qouic4Pnd73PAgICy1CKHSh/a4WfuaBt hfBmEoJqSRkurzKjvQ0M91Gdefsh563kuRt+dLtt6wt/Mm9oRmK6tK4FBzhFtO2zWVzi JZ4w== X-Gm-Message-State: ANoB5pnG/qP74nANQ5sY9R4KiJX0N8PsfQ3h+ZwK0CAtVv3pUoNgztyC CnKzhT+pSmsGLt2tLZY30cqs9pgawfKxDA== X-Google-Smtp-Source: AA0mqf7N2K02m9k2vuCtFU2RRg0RRAHTk7if74d88F4MUx8Id0xucd9CSxWXZyP94O3Z2khuwLo59w== X-Received: by 2002:ac8:4448:0:b0:3a6:9ac9:67fe with SMTP id m8-20020ac84448000000b003a69ac967femr14609072qtn.148.1670292521004; Mon, 05 Dec 2022 18:08:41 -0800 (PST) Received: from [192.168.2.100] (pool-72-79-30-4.nwrknj.east.verizon.net. [72.79.30.4]) by smtp.gmail.com with ESMTPSA id dm12-20020a05620a1d4c00b006fb11eee465sm13337794qkb.64.2022.12.05.18.08.39 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 05 Dec 2022 18:08:40 -0800 (PST) Content-Type: multipart/alternative; boundary="------------niwtTtewKkjk0041AkU8dK06" Message-ID: <21a62556-f7dd-ee9f-3a9b-d4221f87d3e2@gmail.com> Date: Mon, 5 Dec 2022 21:08:39 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.5.0 Subject: Re: need suggestion on querying big tables To: pgsql-admin@lists.postgresql.org References: Content-Language: en-US From: Mladen Gogala In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------niwtTtewKkjk0041AkU8dK06 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 12/5/22 01:29, Ebin Jozer wrote: > Hi Team, > in postgresql 11 version we have two tables of size 435 GB and 347 GB. > if we query on single table or if we are doing inner join on both the > big tables, it is not displacing any output, it keeps running > > We can see the wait event is IO and directDatafile . > > Server Spec : 8 cores and  64GB RAM > PG config : 53 GB(effective_cache), 12 GB(shared buffer) > > can you please suggest some ideas , how we can query on big tables and > fasten them to get the output?? > > Thanks & Regards, > /Ebin/ The first thing you should realize is that your server is really small. Things like NVME, more memory and more cores should help. It's a business decision. If your application is important to your business, you should invest some money in the appropriate hardware. You should also consider partitioning both tables and upgrading to at least Postgres 14. The fear of the latest version is understandable and I feel it myself. Newer versions behave much better with respect to partitioning. Be aware, though, that you will have to add partitioning key as a leading column to any global index. Also, parallelism in a query helps. 64 GB and 8 cores is a desktop class machine. Here is my desktop machine: [mgogala@umajor ~]$ tail -20 /proc/cpuinfo cache size    : 512 KB physical id    : 0 siblings    : 16 _*core id        : 7*__* *__*cpu cores    : 8*_ apicid        : 15 initial apicid    : 15 fpu        : yes fpu_exception    : yes cpuid level    : 13 wp        : yes flags        : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt pdpe1gb rdtscp lm constant_tsc rep_good nopl nonstop_tsc cpuid extd_apicid aperfmperf rapl pni pclmulqdq monitor ssse3 fma cx16 sse4_1 sse4_2 movbe popcnt aes xsave avx f16c rdrand lahf_lm cmp_legacy svm extapic cr8_legacy abm sse4a misalignsse 3dnowprefetch osvw skinit wdt tce topoext perfctr_core perfctr_nb bpext perfctr_llc mwaitx cpb hw_pstate ssbd ibpb vmmcall fsgsbase bmi1 avx2 smep bmi2 rdseed adx smap clflushopt sha_ni xsaveopt xsavec xgetbv1 xsaves clzero irperf xsaveerptr arat npt lbrv svm_lock nrip_save tsc_scale vmcb_clean flushbyasid decodeassists pausefilter pfthreshold avic v_vmsave_vmload vgif overflow_recov succor smca sev sev_es bugs        : sysret_ss_attrs null_seg spectre_v1 spectre_v2 spec_store_bypass retbleed bogomips    : 7385.36 TLB size    : 2560 4K pages clflush size    : 64 cache_alignment    : 64 address sizes    : 43 bits physical, 48 bits virtual power management: ts ttp tm hwpstate cpb eff_freq_ro [13] [14] [mgogala@umajor ~]$ head /proc/meminfo MemTotal:       65781164 kB MemFree:        48364252 kB MemAvailable:   47110532 kB Buffers:           14812 kB Cached:         10199584 kB SwapCached:            0 kB Active:          3949732 kB Inactive:        9434600 kB Active(anon):       4304 kB Inactive(anon):  3211636 kB It's faster than your DB server and it has a NVME drive. And this is a $2K machine from the late 2018. Today, I would go for a DDR5 machine, with at least 64 cores, 1TB RAM and at least 20TB of NVME drives. Such a machine would cost around $50K. -- Mladen Gogala Database Consultant Tel: (347) 321-1217 https://dbwhisperer.wordpress.com --------------niwtTtewKkjk0041AkU8dK06 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit
On 12/5/22 01:29, Ebin Jozer wrote:
Hi Team,
in postgresql 11 version we have two tables of size 435 GB and 347 GB. 
if we query on single table or if we are doing inner join on both the big tables, it is not displacing any output, it keeps running 

We can see the wait event is IO and directDatafile .

Server Spec : 8 cores and  64GB RAM
PG config : 53 GB(effective_cache), 12 GB(shared buffer) 

can you please suggest some ideas , how we can query on big tables and fasten them to get the output??

Thanks & Regards,
Ebin


The first thing you should realize is that your server is really small. Things like NVME, more memory and more cores should help. It's a business decision. If your application is important to your business, you should invest some money in the appropriate hardware. You should also consider partitioning both tables and upgrading to at least Postgres 14. The fear of the latest version is understandable and I feel it myself. Newer versions behave much better with respect to partitioning. Be aware, though, that you will have to add partitioning key as a leading column to any global index. Also, parallelism in a query helps.

64 GB and 8 cores is a desktop class machine. Here is my desktop machine:

[mgogala@umajor ~]$ tail -20 /proc/cpuinfo
cache size    : 512 KB
physical id    : 0
siblings    : 16
core id        : 7
cpu cores    : 8
apicid        : 15
initial apicid    : 15
fpu        : yes
fpu_exception    : yes
cpuid level    : 13
wp        : yes
flags        : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt pdpe1gb rdtscp lm constant_tsc rep_good nopl nonstop_tsc cpuid extd_apicid aperfmperf rapl pni pclmulqdq monitor ssse3 fma cx16 sse4_1 sse4_2 movbe popcnt aes xsave avx f16c rdrand lahf_lm cmp_legacy svm extapic cr8_legacy abm sse4a misalignsse 3dnowprefetch osvw skinit wdt tce topoext perfctr_core perfctr_nb bpext perfctr_llc mwaitx cpb hw_pstate ssbd ibpb vmmcall fsgsbase bmi1 avx2 smep bmi2 rdseed adx smap clflushopt sha_ni xsaveopt xsavec xgetbv1 xsaves clzero irperf xsaveerptr arat npt lbrv svm_lock nrip_save tsc_scale vmcb_clean flushbyasid decodeassists pausefilter pfthreshold avic v_vmsave_vmload vgif overflow_recov succor smca sev sev_es
bugs        : sysret_ss_attrs null_seg spectre_v1 spectre_v2 spec_store_bypass retbleed
bogomips    : 7385.36
TLB size    : 2560 4K pages
clflush size    : 64
cache_alignment    : 64
address sizes    : 43 bits physical, 48 bits virtual
power management: ts ttp tm hwpstate cpb eff_freq_ro [13] [14]

[mgogala@umajor ~]$ head /proc/meminfo
MemTotal:       65781164 kB
MemFree:        48364252 kB
MemAvailable:   47110532 kB
Buffers:           14812 kB
Cached:         10199584 kB
SwapCached:            0 kB
Active:          3949732 kB
Inactive:        9434600 kB
Active(anon):       4304 kB
Inactive(anon):  3211636 kB

It's faster than your DB server and it has a NVME drive. And this is a $2K machine from the late 2018. Today, I would go for a DDR5 machine, with at least 64 cores, 1TB RAM and at least 20TB of NVME drives. Such a machine would cost around $50K.

-- 
Mladen Gogala
Database Consultant
Tel: (347) 321-1217
https://dbwhisperer.wordpress.com
--------------niwtTtewKkjk0041AkU8dK06--