Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bT1Lk-0002is-Ts for pgsql-performance@arkaria.postgresql.org; Fri, 29 Jul 2016 06:32:49 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1bT1Lj-0008CS-Pg for pgsql-performance@arkaria.postgresql.org; Fri, 29 Jul 2016 06:32:47 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bT1K2-0006JF-Pg for pgsql-performance@postgresql.org; Fri, 29 Jul 2016 06:31:02 +0000 Received: from mail-io0-x232.google.com ([2607:f8b0:4001:c06::232]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1bT1Jy-00067J-A8 for pgsql-performance@postgresql.org; Fri, 29 Jul 2016 06:31:01 +0000 Received: by mail-io0-x232.google.com with SMTP id q83so120891894iod.1 for ; Thu, 28 Jul 2016 23:30:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding; bh=4o/tIqbOja4ilaTpVHjSiuFubGFtj9YY47x6jsgY4e4=; b=cXnaHa7v+OcJClfZ/Rp3dIw+MruzxX8dzjsTINLwX65NiOoKr3Qp5kJc2k2LCs8Tfr 5DeLammvAGMNErjJf5tyS5QFGxEqVPW9CRxYJuz1+pT8c5Q/oI3MCJxFvRABfLWRhgOw Yvure2a1yI2OeGC/5xuybR29sQB4N6GZI4BrQybmAxT4umV+p4SaptBpUKnxtRDoV4Ok hIkzQ/gTXnG2W8Cx1a1udDvkVXYVUArRzm8yNR23nm15jYQpq/uEXF+L1KaZnSx6BDqH AsDnHAuHD1BzDlfGMXcaFZtH+knamwog2dTKjHTBAvZyLve0qhXinEWpQngx/PauU/tn LKDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=4o/tIqbOja4ilaTpVHjSiuFubGFtj9YY47x6jsgY4e4=; b=GVj3JmvKHlsnvM2pz9jZjIR//X8dRFQtGdjogKTUgR457fBym+HO67P4HY+MhTgJiT HbguUFd7SiKpKP85LT2CTWcGlQzP7WUJquPSdrJieZVhwx5NtRskRWwM6os5yx7/owmQ zBQfDpd0sqXcrIujct5Vq0QxaUkLTLp57zQ6ifRcKSQfZX9J4EJ0XGcv7SgCZ0lhftqM IWPfI3DS/0E09Hxp713eX/sV1BBUXC3CWwqeA/oL+ROZfvZHNKUamiKIf4nPZyUzBYDR Wh7U5PCoCp0ASV91Uh3dMZMT+NJU5HyrBhEzT6sX0R0mlgqyAFfHRlZAHHCXZxafP/8E mM9g== X-Gm-Message-State: AEkoouuS1jTydgazZlKWRZtRsDFvbXYje4vCdIRG+yHL/6R4Ih096+DUZDF5eLe+yiSIv3VdGdU1/6hXKVKCoiEhmDvdO4HDKA7ExLqlbpXZTJ3JgpEV8RAr71lyO9ncKVHaLc3SxtAHE1ubHIUCH1anXT6dYN74yFMEHAWAvsqSJ2tl78I9QSTe3OxMsVh+XeAO2s5VPNvYTZhR/w== X-Received: by 10.107.25.14 with SMTP id 14mr41128507ioz.168.1469773855090; Thu, 28 Jul 2016 23:30:55 -0700 (PDT) Received: from [10.137.2.20] ([96.88.31.205]) by smtp.gmail.com with ESMTPSA id s84sm6635539ioe.39.2016.07.28.23.30.53 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 Jul 2016 23:30:54 -0700 (PDT) Subject: Re: PostgreSQL on ZFS: performance tuning To: pgsql-performance@postgresql.org References: <1cdf08f7-de8f-c55f-c1ec-29a5f15d5011@mail.ru> From: Tomas Vondra Message-ID: Date: Fri, 29 Jul 2016 08:30:49 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:46.0) Gecko/20100101 Thunderbird/46.0a2 MIME-Version: 1.0 In-Reply-To: <1cdf08f7-de8f-c55f-c1ec-29a5f15d5011@mail.ru> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-performance Precedence: bulk Sender: pgsql-performance-owner@postgresql.org On 07/29/2016 08:04 AM, trafdev wrote: > Hi. > > I have an OLAP-oriented DB (light occasional bulk writes and heavy > aggregated selects over large periods of data) based on Postgres 9.5.3. > > Server is a FreeBSD 10.3 with 64GB of RAM and 2x500GB SSD (root on ZFS, > mirror). > > The largest table is 13GB (with a 4GB index on it), other tables are 4, > 2 and less than 1GB. > > After reading a lot of articles and "howto-s" I've collected following > set of tweaks and hints: > > > ZFS pools creation: > zfs create zroot/ara/sqldb > zfs create -o recordsize=8k -o primarycache=all zroot/ara/sqldb/pgsql > > > zfs get primarycache,recordsize,logbias,compression zroot/ara/sqldb/pgsql > NAME PROPERTY VALUE SOURCE > zroot/ara/sqldb/pgsql primarycache all local > zroot/ara/sqldb/pgsql recordsize 8K local > zroot/ara/sqldb/pgsql logbias latency local > zroot/ara/sqldb/pgsql compression lz4 inherited from zroot > > L2ARC is disabled > VDEV cache is disabled > > > pgsql -c "mkdir /ara/sqldb/pgsql/data_ix" > pgsql -c "initdb --locale=en_US.UTF-8 -E UTF-8 -D /ara/sqldb/pgsql/data" > > > /etc/sysctl.conf > vfs.zfs.metaslab.lba_weighting_enabled=0 > > > postgresql.conf: > listen_addresses = '*' > max_connections = 100 > shared_buffers = 16GB > effective_cache_size = 48GB It may not be a problem for your workload, but this effective_cache_size value is far too high. > work_mem = 500MB > maintenance_work_mem = 2GB > min_wal_size = 4GB > max_wal_size = 8GB > checkpoint_completion_target = 0.9 You probably need to increase the checkpoint_timeout too. > wal_buffers = 16MB > default_statistics_target = 500 > random_page_cost = 1 > log_lock_waits = on > log_directory = 'pg_log' > log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log' > log_destination = 'csvlog' > logging_collector = on > log_min_duration_statement = 10000 > shared_preload_libraries = 'pg_stat_statements' > track_activity_query_size = 10000 > track_io_timing = on > > > zfs-stats -A > ------------------------------------------------------------------------ > ZFS Subsystem Report Thu Jul 28 21:58:46 2016 > ------------------------------------------------------------------------ > ARC Summary: (HEALTHY) > Memory Throttle Count: 0 > ARC Misc: > Deleted: 14.92b > Recycle Misses: 7.01m > Mutex Misses: 4.72m > Evict Skips: 1.28b > ARC Size: 53.27% 32.59 GiB > Target Size: (Adaptive) 53.28% 32.60 GiB > Min Size (Hard Limit): 12.50% 7.65 GiB > Max Size (High Water): 8:1 61.18 GiB > ARC Size Breakdown: > Recently Used Cache Size: 92.83% 30.26 GiB > Frequently Used Cache Size: 7.17% 2.34 GiB > ARC Hash Breakdown: > Elements Max: 10.36m > Elements Current: 78.09% 8.09m > Collisions: 9.63b > Chain Max: 26 > Chains: 1.49m > ------------------------------------------------------------------------ > > zfs-stats -E > ------------------------------------------------------------------------ > ZFS Subsystem Report Thu Jul 28 21:59:57 2016 > ------------------------------------------------------------------------ > ARC Efficiency: 49.85b > Cache Hit Ratio: 70.94% 35.36b > Cache Miss Ratio: 29.06% 14.49b > Actual Hit Ratio: 66.32% 33.06b > Data Demand Efficiency: 84.85% 25.39b > Data Prefetch Efficiency: 17.85% 12.90b > CACHE HITS BY CACHE LIST: > Anonymously Used: 4.10% 1.45b > Most Recently Used: 37.82% 13.37b > Most Frequently Used: 55.67% 19.68b > Most Recently Used Ghost: 0.58% 203.42m > Most Frequently Used Ghost: 1.84% 649.83m > CACHE HITS BY DATA TYPE: > Demand Data: 60.92% 21.54b > Prefetch Data: 6.51% 2.30b > Demand Metadata: 32.56% 11.51b > Prefetch Metadata: 0.00% 358.22k > CACHE MISSES BY DATA TYPE: > Demand Data: 26.55% 3.85b > Prefetch Data: 73.13% 10.59b > Demand Metadata: 0.31% 44.95m > Prefetch Metadata: 0.00% 350.48k > > zfs-stats -Z > ------------------------------------------------------------------------ > ZFS Subsystem Report Thu Jul 28 22:02:46 2016 > ------------------------------------------------------------------------ > File-Level Prefetch: (HEALTHY) > DMU Efficiency: 49.97b > Hit Ratio: 55.85% 27.90b > Miss Ratio: 44.15% 22.06b > Colinear: 22.06b > Hit Ratio: 0.04% 7.93m > Miss Ratio: 99.96% 22.05b > Stride: 17.85b > Hit Ratio: 99.61% 17.78b > Miss Ratio: 0.39% 69.46m > DMU Misc: > Reclaim: 22.05b > Successes: 0.05% 10.53m > Failures: 99.95% 22.04b > Streams: 10.14b > +Resets: 0.10% 9.97m > -Resets: 99.90% 10.13b > Bogus: 0 > > > Notes\concerns: > > - primarycache=metadata (recommended in most articles) produces a > significant performance degradation (in SELECT queries); Those articles are wrong. PostgreSQL relies of filesystem cache, so it needs primarycache=all. > > - from what I can see, Postgres uses memory too carefully. I would like > somehow to force it to keep accessed data in memory as long as possible. > Instead I often see that even frequently accessed data is pushed out of > memory cache for no apparent reasons. > This is probably a consequence of the primarycache misconfiguration. > > Do I miss something important in my configs? Are there any double > writes\reads somewhere because of OS\ZFS\Postgres caches? How to avoid > them? > > Please share your experience\tips. Thanks. > > -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance