Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1YBtfc-0002xH-Jq for pgsql-general@arkaria.postgresql.org; Thu, 15 Jan 2015 23:17:45 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1YBtfb-0001C8-Va for pgsql-general@arkaria.postgresql.org; Thu, 15 Jan 2015 23:17:44 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1YBtfa-0001C2-DW for pgsql-general@postgresql.org; Thu, 15 Jan 2015 23:17:42 +0000 Received: from nm25-vm6.bullet.mail.ir2.yahoo.com ([212.82.97.39]) by makus.postgresql.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1YBtfM-0006js-Qy for pgsql-general@postgresql.org; Thu, 15 Jan 2015 23:17:40 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ymail.com; s=s2048; t=1421363846; bh=PbTOfdcoV76NvO3m5ESD2gAUj5ITyUZzKma7MQuYz+E=; h=Date:From:To:Subject:From:Subject; b=m2/TRT97H+JE2IHbVN8/0QrR3U0IslunJxX/XHIAfUX9LQZt48nSn3Sh/j3xKNeXlT531kIaolVjus4rGkq2S7W/DvBj+FuBCQfc2UonyOZcACgTJ2PEiCmMVCQf6vAIKycljlvJMdOfXnKIelpenHiOb73G56HumnAO/aA8YuvkYDldOXvM1MTBH5V82pKtuBgqbfojVHv4MfFK5dh2ICmcnOTv/yhDlxKHhf09TFbgoxJfpEgjiHwjIc+iOl6iEAdFyiZfnkaFW98QOrsNP2PKeow0RRVY0QYFUypby/fMabqzGfyVQInBoa0V5g0wZnClpZ2Meg18o+v1Tl+jGQ== Received: from [212.82.98.55] by nm25.bullet.mail.ir2.yahoo.com with NNFMP; 15 Jan 2015 23:17:26 -0000 Received: from [46.228.39.71] by tm8.bullet.mail.ir2.yahoo.com with NNFMP; 15 Jan 2015 23:17:26 -0000 Received: from [127.0.0.1] by smtp108.mail.ir2.yahoo.com with NNFMP; 15 Jan 2015 23:17:26 -0000 X-Yahoo-Newman-Id: 22108.72761.bm@smtp108.mail.ir2.yahoo.com X-Yahoo-Newman-Property: ymail-3 X-YMail-OSG: sGIRQ3oVM1nEPBQNZvmIPbLCK3YhkQ2rE1PS9ivLDcD6RLU aOO2je3U56KeLQKlJCuSorAGBk5L3KsrQnyzEDmywt9wbPbxjKqrWsTa8XDF XQrInVRFEWmgU1nZADdKJZTanOp3QUVwFVvhn_EZ5eeGK9QqXYpCxDMnrC0z VBKw0TtZIijRS.wn2z.BBRUqz8Qn26ozd1aD1XrxXRIsGxhMORIwVWgDVBTr bdYjhtJFLjNNsnCUt_unwJLX2OCplVKLmd1miaWGO.ri5G1t1.s0MLhNxBPu HPkUjQONUnUZUUcPUj9b.KEWYZEXaAUz4obckPZhV8L8QRlOglCq.zha3efN FdX2D5RDsGczpqMY1DgKHyfuQ3biouKt98G_q8Xz1lBzqHK2aYJVPaXt8Fvs yVa1X77A.gEmLq9_9M2SPAnLPuBiFoDi0plz8_WzpEheENEwQHpGqg8tOGNF kPEsoVYhcCxYPble3Y0T2M51Qtp3M8AMRbseMHjdpzMkhLHYJsDL0cVxdxRU fqi_nX8D1eAjVWzlgIPPnN38zML6AVVhhlef1uK4RCR8LsV_UJWMePrLi2Q- - X-Yahoo-SMTP: 3uDVuluswBBbOWxip8ozdb.._tg10pMkLWhFGuowizMhZ4W.SQ-- Message-ID: <54B84A83.9020003@ymail.com> Date: Fri, 16 Jan 2015 00:17:23 +0100 From: Enrico Bianchi User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.3.0 MIME-Version: 1.0 To: pgsql-general@postgresql.org Subject: Out of Memory Content-Type: multipart/alternative; boundary="------------010706010403020803030905" X-Pg-Spam-Score: -0.2 (/) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-general Precedence: bulk Sender: pgsql-general-owner@postgresql.org This is a multi-part message in MIME format. --------------010706010403020803030905 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit I have this situation: Machine: VPS with CentOS 6.6 x86_64 64GB of RAM 2GB of swap (unused) Ulimit settings: postgres soft nproc 2047 postgres hard nproc 16384 postgres soft nofile 1024 postgres hard nofile 65536 postgres hard stack 10240 PostgreSQL 9.4.0 from official repositories. Postgresql.conf is: listen_addresses = '*' port = 5432 max_connections = 20 shared_buffers = 16GB effective_cache_size = 48GB work_mem = 419430kB maintenance_work_mem = 2GB checkpoint_segments = 128 checkpoint_completion_target = 0.9 wal_buffers = 16MB default_statistics_target = 500 When I launch a query (the principal field is JSONb), the database return this: ERROR: out of memory DETAIL: Failed on request of size 110558. This is the query: SELECT CASE substring((field_id ->'comment')::text,1,1) WHEN '{' THEN field_id ->'comment'->>'id' WHEN '[' THEN jsonb_array_elements(field_id ->'comment')->>'id' ELSE NULL END AS comment_id, CASE substring((field_id ->'comment')::text,1,1) WHEN '{' THEN field_id ->'comment'->'from'->>'id' WHEN '[' THEN jsonb_array_elements(field_id ->'comment')->'from'->>'id' ELSE NULL END AS user_id, field_id ->> '_id' post_id, CASE substring((field_id ->'comment')::text,1,1) WHEN '{' THEN (field_id ->'comment'->>'created_timestamp')::timestamp without time zone WHEN '[' THEN (jsonb_array_elements(field_id ->'comment')->>'created_time')::timestamp without time zone ELSE NULL END AS comment_create_date, CASE substring((field_id ->'comment')::text,1,1) WHEN '{' THEN cast(to_char((field_id ->'comment'->>'created_time')::timestamp without time zone,'YYYYMMDD') as numeric) WHEN '[' THEN cast(to_char((jsonb_array_elements(field_id ->'comment')->>'created_time')::timestamp without time zone,'YYYYMMDD') as numeric) ELSE NULL END AS comment_created_day, field_id ->> 'pageId' page_id, CASE substring(field_id->>'feedtype',1,1) WHEN 'f' THEN 2 WHEN 'b' THEN 1 ELSE 3 END AS owner_type, 'WALL' comment_type, CASE substring((field_id ->'comment')::text,1,1) WHEN '{' THEN to_char((field_id ->'comment'->>'created_time')::timestamp without time zone,'HH24')::numeric WHEN '[' THEN to_char((jsonb_array_elements(field_id ->'comment')->>'created_time')::timestamp without time zone,'HH24')::numeric ELSE NULL END AS comment_time_slot, CASE substring((field_id ->'comment')::text,1,1) WHEN '{' THEN (field_id ->'comment'->>'like_count')::numeric WHEN '[' THEN (jsonb_array_elements(field_id ->'comment')->>'like_count')::numeric ELSE NULL END AS like_count, 1 as sn_id, 17 AS group_id FROM stage.fbcomment WHERE field_id ->> 'pageId' in (SELECT stage.eng_page.identifier::text FROM stage.eng_group_page, stage.eng_page where stage.eng_group_page.page_id=stage.eng_page._id AND stage.eng_group_page.group_id=17 ) ; And this is the query plan: QUERY PLAN --------------------------------------------------------------------------------------------------- Nested Loop (cost=49.52..57597.31 rows=6729600 width=989) -> HashAggregate (cost=41.38..42.02 rows=64 width=12) Group Key: (eng_page.identifier)::text -> Hash Join (cost=32.54..41.22 rows=64 width=12) Hash Cond: (eng_group_page.page_id = eng_page._id) -> Bitmap Heap Scan on eng_group_page (cost=4.77..12.57 rows=64 width=5) Recheck Cond: (group_id = 17::numeric) -> Bitmap Index Scan on pk_eng_group_page (cost=0.00..4.76 rows=64 width=0) Index Cond: (group_id = 17::numeric) -> Hash (cost=17.34..17.34 rows=834 width=17) -> Seq Scan on eng_page (cost=0.00..17.34 rows=834 width=17) -> Bitmap Heap Scan on fbcomment (cost=8.14..103.95 rows=673 width=989) Recheck Cond: ((field_id ->> 'pageId'::text) = (eng_page.identifier)::text) -> Bitmap Index Scan on fbcomment_idx (cost=0.00..7.97 rows=673 width=0) Index Cond: ((field_id ->> 'pageId'::text) = (eng_page.identifier)::text) (15 rows) The query goes wrong also a subset of data extracted from the subquery. With this subset (5 values with generate 336500 records), vmstat is this: procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu----- r b swpd free buff cache si so bi bo in cs us sy id wa st 0 0 0 64467148 16888 996464 0 0 5 1 75 40 5 1 94 0 0 2 0 0 64365252 16888 996464 0 0 0 0 734 167 13 2 82 0 2 1 0 0 63471488 16888 996464 0 0 0 1 1102 176 21 4 75 0 0 1 0 0 62257732 16888 996464 0 0 0 12 1070 160 21 4 74 0 2 1 0 0 60939172 16888 996464 0 0 0 0 1072 158 21 4 75 0 0 1 0 0 59627188 16888 996464 0 0 0 6 1071 161 21 4 75 0 0 1 0 0 58324692 16888 996464 0 0 0 0 1069 152 21 4 75 0 0 1 0 0 57002732 16888 996464 0 0 0 0 1049 133 21 4 75 0 0 1 0 0 55671200 16888 996464 0 0 0 1 1076 152 21 4 75 0 0 1 0 0 54316064 16896 996460 0 0 0 4 1056 140 21 4 75 0 0 1 0 0 52939020 16896 996464 0 0 0 0 1052 140 22 3 75 0 0 1 0 0 51558644 16896 996464 0 0 0 5 1069 156 21 4 75 0 0 1 0 0 50188544 16896 996464 0 0 0 0 1069 156 21 4 75 0 0 0 0 0 64464804 16896 996476 0 0 0 0 557 269 6 7 88 0 0 Any hint for resolving the problem is appreciated Cheers, Enrico --------------010706010403020803030905 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit I have this situation:

Machine:
VPS with CentOS 6.6 x86_64
64GB of RAM
2GB of swap (unused)

Ulimit settings:
postgres            soft    nproc   2047                                                               
postgres            hard    nproc   16384                                                              
postgres            soft    nofile  1024                                                               
postgres            hard    nofile  65536                                                              
postgres            hard    stack   10240

PostgreSQL 9.4.0 from official repositories. Postgresql.conf is:

listen_addresses = '*'                                                                                 
port = 5432
max_connections = 20                                                                                   
shared_buffers = 16GB                                                                                  
effective_cache_size = 48GB                                                                            
work_mem = 419430kB                                                                                    
maintenance_work_mem = 2GB                                                                             
checkpoint_segments = 128                                                                              
checkpoint_completion_target = 0.9                                                                     
wal_buffers = 16MB                                                                                     
default_statistics_target = 500

When I launch a query (the principal field is JSONb), the database return this:

ERROR:  out of memory
DETAIL:  Failed on request of size 110558.

This is the query:

SELECT CASE substring((field_id ->'comment')::text,1,1)
          WHEN '{' THEN field_id ->'comment'->>'id'
          WHEN '[' THEN jsonb_array_elements(field_id ->'comment')->>'id'
          ELSE NULL
        END AS comment_id,
        CASE substring((field_id ->'comment')::text,1,1)
          WHEN '{' THEN field_id ->'comment'->'from'->>'id'
          WHEN '[' THEN jsonb_array_elements(field_id ->'comment')->'from'->>'id'
          ELSE NULL
        END AS user_id,
        field_id ->> '_id' post_id,
        CASE substring((field_id ->'comment')::text,1,1)
          WHEN '{' THEN (field_id ->'comment'->>'created_timestamp')::timestamp without time zone
          WHEN '[' THEN (jsonb_array_elements(field_id ->'comment')->>'created_time')::timestamp without time zone
          ELSE NULL
        END AS comment_create_date,
        CASE substring((field_id ->'comment')::text,1,1)
          WHEN '{' THEN cast(to_char((field_id ->'comment'->>'created_time')::timestamp without time zone,'YYYYMMDD') as numeric)
          WHEN '[' THEN  cast(to_char((jsonb_array_elements(field_id ->'comment')->>'created_time')::timestamp without time zone,'YYYYMMDD') as numeric)
          ELSE NULL
        END AS comment_created_day,
        field_id ->> 'pageId' page_id,
        CASE substring(field_id->>'feedtype',1,1)
          WHEN 'f' THEN 2
          WHEN 'b' THEN 1
          ELSE 3
        END AS owner_type,
        'WALL' comment_type,
       CASE substring((field_id ->'comment')::text,1,1)
          WHEN '{' THEN to_char((field_id ->'comment'->>'created_time')::timestamp without time zone,'HH24')::numeric
          WHEN '[' THEN  to_char((jsonb_array_elements(field_id ->'comment')->>'created_time')::timestamp without time zone,'HH24')::numeric
          ELSE NULL
        END AS comment_time_slot,
        CASE substring((field_id ->'comment')::text,1,1)
          WHEN '{' THEN (field_id ->'comment'->>'like_count')::numeric
          WHEN '[' THEN (jsonb_array_elements(field_id ->'comment')->>'like_count')::numeric
          ELSE NULL
        END AS like_count,
        1 as sn_id,
        17 AS group_id
 FROM stage.fbcomment
 WHERE field_id ->> 'pageId' in (SELECT stage.eng_page.identifier::text
                                    FROM  stage.eng_group_page,
                                         stage.eng_page
                                   where stage.eng_group_page.page_id=stage.eng_page._id
                                     AND stage.eng_group_page.group_id=17
                                 )
;

And this is the query plan:

                                            QUERY PLAN
---------------------------------------------------------------------------------------------------
 Nested Loop  (cost=49.52..57597.31 rows=6729600 width=989)
   ->  HashAggregate  (cost=41.38..42.02 rows=64 width=12)
         Group Key: (eng_page.identifier)::text
         ->  Hash Join  (cost=32.54..41.22 rows=64 width=12)
               Hash Cond: (eng_group_page.page_id = eng_page._id)
               ->  Bitmap Heap Scan on eng_group_page (cost=4.77..12.57 rows=64 width=5)
                     Recheck Cond: (group_id = 17::numeric)
                     ->  Bitmap Index Scan on pk_eng_group_page (cost=0.00..4.76 rows=64 width=0)
                           Index Cond: (group_id = 17::numeric)
               ->  Hash  (cost=17.34..17.34 rows=834 width=17)
                     ->  Seq Scan on eng_page  (cost=0.00..17.34 rows=834 width=17)
   ->  Bitmap Heap Scan on fbcomment  (cost=8.14..103.95 rows=673 width=989)
         Recheck Cond: ((field_id ->> 'pageId'::text) = (eng_page.identifier)::text)
         ->  Bitmap Index Scan on fbcomment_idx  (cost=0.00..7.97 rows=673 width=0)
               Index Cond: ((field_id ->> 'pageId'::text) = (eng_page.identifier)::text)
(15 rows)

The query goes wrong also a subset of data extracted from the subquery. With this subset (5 values with generate 336500 records), vmstat is this:

procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu-----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
 0  0      0 64467148  16888 996464    0    0     5     1   75   40 5  1 94  0  0
 2  0      0 64365252  16888 996464    0    0     0     0  734  167 13  2 82  0  2
 1  0      0 63471488  16888 996464    0    0     0     1 1102  176 21  4 75  0  0
 1  0      0 62257732  16888 996464    0    0     0    12 1070  160 21  4 74  0  2
 1  0      0 60939172  16888 996464    0    0     0     0 1072  158 21  4 75  0  0
 1  0      0 59627188  16888 996464    0    0     0     6 1071  161 21  4 75  0  0
 1  0      0 58324692  16888 996464    0    0     0     0 1069  152 21  4 75  0  0
 1  0      0 57002732  16888 996464    0    0     0     0 1049  133 21  4 75  0  0
 1  0      0 55671200  16888 996464    0    0     0     1 1076  152 21  4 75  0  0
 1  0      0 54316064  16896 996460    0    0     0     4 1056  140 21  4 75  0  0
 1  0      0 52939020  16896 996464    0    0     0     0 1052  140 22  3 75  0  0
 1  0      0 51558644  16896 996464    0    0     0     5 1069  156 21  4 75  0  0
 1  0      0 50188544  16896 996464    0    0     0     0 1069  156 21  4 75  0  0
 0  0      0 64464804  16896 996476    0    0     0     0  557  269 6  7 88  0  0

Any hint for resolving the problem is appreciated

Cheers,
Enrico
--------------010706010403020803030905--