{"action":"created","issue":{"url":"https://api.github.com/repos/postgrespro/pg_pathman/issues/21","repository_url":"https://api.github.com/repos/postgrespro/pg_pathman","labels_url":"https://api.github.com/repos/postgrespro/pg_pathman/issues/21/labels{/name}","comments_url":"https://api.github.com/repos/postgrespro/pg_pathman/issues/21/comments","events_url":"https://api.github.com/repos/postgrespro/pg_pathman/issues/21/events","html_url":"https://github.com/postgrespro/pg_pathman/issues/21","id":165355619,"number":21,"title":"segfault in pg_pathman.so with Postgres 9.5.2 on ubuntu, debian, OSX","user":{"login":"pavel-kolla-kampiki","id":12799815,"avatar_url":"https://avatars.githubusercontent.com/u/12799815?v=3","gravatar_id":"","url":"https://api.github.com/users/pavel-kolla-kampiki","html_url":"https://github.com/pavel-kolla-kampiki","followers_url":"https://api.github.com/users/pavel-kolla-kampiki/followers","following_url":"https://api.github.com/users/pavel-kolla-kampiki/following{/other_user}","gists_url":"https://api.github.com/users/pavel-kolla-kampiki/gists{/gist_id}","starred_url":"https://api.github.com/users/pavel-kolla-kampiki/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pavel-kolla-kampiki/subscriptions","organizations_url":"https://api.github.com/users/pavel-kolla-kampiki/orgs","repos_url":"https://api.github.com/users/pavel-kolla-kampiki/repos","events_url":"https://api.github.com/users/pavel-kolla-kampiki/events{/privacy}","received_events_url":"https://api.github.com/users/pavel-kolla-kampiki/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/postgrespro/pg_pathman/labels/bug","name":"bug","color":"fc2929"}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2016-07-13T15:49:40Z","updated_at":"2016-07-15T15:09:14Z","closed_at":null,"body":"From my workstation running Xubuntu 16.04 with 9.5.2:\r\n\r\n`0x00007ffbd1a821e4 in pathman_rel_pathlist_hook () from /usr/lib/postgresql/9.5/lib/pg_pathman.so`\r\n\r\nsimilar issue (with lack of core dumps though) in same situation on Debian 8 and OSX 10.11.4\r\n\r\nfrom postgres log:\r\n```\r\n2016-07-13 18:13:20 EEST [18360-2] LOG:  server process (PID 18701) was terminated by signal 11: Segmentation fault\r\n2016-07-13 18:13:20 EEST [18360-3] DETAIL:  Failed process was running: \r\n        SELECT facebook.status_upsert(\r\n            '1_1',\r\n            'link',\r\n            1,\r\n            0,\r\n            4,\r\n            NULL,\r\n            '',\r\n            'name value',\r\n            '2016-02-01T11:02:00+00:00'::timestamptz,\r\n            '2016-02-01T11:01:00+00:00'::timestamptz\r\n        )\r\n2016-07-13 18:13:20 EEST [18360-4] LOG:  terminating any other active server processes\r\n```\r\n               \r\ntable facebook.status is range-partitioned on id\r\n\r\nculprit function:\r\n```\r\nCREATE OR REPLACE FUNCTION facebook.status_upsert (\r\n    _eid TEXT,\r\n    _etype TEXT,\r\n    _status_type INT4,\r\n    _streaming_status INT4,\r\n    _story_id INT4,\r\n    _stream_id INT4,\r\n    _description TEXT,\r\n    _caption TEXT,\r\n    _as_at_ TIMESTAMPTZ,\r\n    _published_at_ TIMESTAMPTZ\r\n) RETURNS INT AS $$\r\nDECLARE\r\n  _id INT;\r\n  _unchanged BOOL;\r\nBEGIN\r\n\r\n-- should only update the row it something has changed. but cannot just put that condition in the criteria of the update\r\n-- statement since we must return the id of the row regardless if it is changed or not\r\nSELECT\r\n  id,\r\n  as_at = _as_at_\r\n  AND etype = _etype\r\n  AND status_type = _status_type\r\n  AND streaming_status = _streaming_status\r\n  AND story_id = _story_id\r\n  AND description = _description\r\n  AND caption = _caption\r\n  AND published_at =  _published_at_\r\n  INTO _id, _unchanged\r\nFROM\r\n  facebook.status fs\r\nWHERE\r\n  eid = _eid\r\n;\r\n\r\nIF FOUND AND _unchanged THEN\r\n    RETURN _id;\r\nEND IF;\r\n\r\nLOOP\r\n    -- updates on partitioned tables do return the id of the record updated unlike inserts\r\n    UPDATE facebook.status SET\r\n      etype = _etype,\r\n      status_type = _status_type,\r\n      streaming_status = _streaming_status,\r\n      story_id = _story_id,\r\n      description = _description,\r\n      caption = _caption,\r\n      as_at = _as_at_,\r\n      published_at = _published_at_,\r\n      _as_at = EXTRACT(EPOCH FROM _as_at_),\r\n      _published_at = EXTRACT(EPOCH FROM _published_at_)\r\n    WHERE\r\n      id = _id;\r\n\r\n    IF FOUND THEN\r\n        RETURN _id;\r\n    END IF;\r\n\r\n    BEGIN\r\n\r\n        -- believe that it is highly unlikely that will get a unique_violation for this table\r\n        -- therefore its more efficient to increment the sequence inside the loop right before the insert\r\n        SELECT NEXTVAL('facebook.status_id_seq') INTO _id;\r\n\r\n        -- take this out when acquisition can reliable give me the stream_id\r\n        SELECT COALESCE(_stream_id, (SELECT stream_id FROM facebook.page WHERE eid = split_part(_eid, '_', 1))) INTO _stream_id;\r\n\r\n        -- inserts on partitioned do not return the id of the record inserted so use explicitly allocated sequence id\r\n        INSERT INTO facebook.status (\r\n          id,\r\n          eid,\r\n          etype,\r\n          status_type,\r\n          streaming_status,\r\n          story_id,\r\n          stream_id,\r\n          description,\r\n          caption,\r\n          as_at,\r\n          published_at,\r\n          _as_at,\r\n          _published_at\r\n        ) VALUES (\r\n          _id,\r\n          _eid,\r\n          _etype,\r\n          _status_type,\r\n          _streaming_status,\r\n          _story_id,\r\n          _stream_id,\r\n          _description,\r\n          _caption,\r\n          _as_at_,\r\n          _published_at_,\r\n          EXTRACT(EPOCH FROM _as_at_),\r\n          EXTRACT(EPOCH FROM _published_at_)\r\n        );\r\n        RETURN _id;\r\n\r\n    EXCEPTION WHEN unique_violation THEN\r\n        -- loop again\r\n    END;\r\nEND LOOP;\r\nEND\r\n$$ language plpgsql;\r\n```\r\n[ubuntu's .crash](https://drive.google.com/file/d/0BzVPZYVEEJKTd0l1dWFKYm55aHM/view)\r\n"},"comment":{"url":"https://api.github.com/repos/postgrespro/pg_pathman/issues/comments/232978153","html_url":"https://github.com/postgrespro/pg_pathman/issues/21#issuecomment-232978153","issue_url":"https://api.github.com/repos/postgrespro/pg_pathman/issues/21","id":232978153,"user":{"login":"zilder","id":1409693,"avatar_url":"https://avatars.githubusercontent.com/u/1409693?v=3","gravatar_id":"","url":"https://api.github.com/users/zilder","html_url":"https://github.com/zilder","followers_url":"https://api.github.com/users/zilder/followers","following_url":"https://api.github.com/users/zilder/following{/other_user}","gists_url":"https://api.github.com/users/zilder/gists{/gist_id}","starred_url":"https://api.github.com/users/zilder/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zilder/subscriptions","organizations_url":"https://api.github.com/users/zilder/orgs","repos_url":"https://api.github.com/users/zilder/repos","events_url":"https://api.github.com/users/zilder/events{/privacy}","received_events_url":"https://api.github.com/users/zilder/received_events","type":"User","site_admin":false},"created_at":"2016-07-15T15:09:14Z","updated_at":"2016-07-15T15:09:14Z","body":"@pavel-kolla-kampiki, thanks! I still couldn't reproduce an error. But based on your backtrace I assume that some variables (lists actually) have been already freed due to a memory context reset. The last commit should fix this. Could you please test this on your setup?"}}
{"actor":{"display_login":"zilder"}}