Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dI0Gj-0003Mo-KO for pgsql-sql@arkaria.postgresql.org; Mon, 05 Jun 2017 22:14:37 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1dI0Gj-0006l0-6i for pgsql-sql@arkaria.postgresql.org; Mon, 05 Jun 2017 22:14:37 +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 1dI0Gg-0006dF-TW for pgsql-sql@postgresql.org; Mon, 05 Jun 2017 22:14:35 +0000 Received: from out1-smtp.messagingengine.com ([66.111.4.25]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1dI0Gc-0000rh-Vz for pgsql-sql@postgresql.org; Mon, 05 Jun 2017 22:14:34 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 4511F20909; Mon, 5 Jun 2017 18:14:29 -0400 (EDT) Received: from frontend2 ([10.202.2.161]) by compute6.internal (MEProxy); Mon, 05 Jun 2017 18:14:29 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc:x-sasl-enc; s=fm1; bh=apiIsWs8IvCdqHTOTm coquB5SdRw/zFfyXrLI2z9cB0=; b=CIuQ8PMFI9s0phOmTwkWRM7kfjgi1vJFCE VaonaCM2KDbQdzrtWvrLpDmTmBJFbBuVuMI/a4bsLVbRC5gGr92jzbNp4UHYThUr 578kDwon/AvI0bUbQ2y07GxZeA6AI6ACTdFLquP5Y30lCDddzYcCXG6eQV6WwYnM AnpgvOzHumhujl1LhJxItYCiO2Wp4HfRHsxZ/3j2PqMpeL0mLr6TwuSXhqHDJR9f oGquKtWd872SnUHbcxWlHdR3WfDnhBSmoh979hBWNLdgjvCD0y1ZzLS4GpwmK5Eq Y+k1Bkiy8nKWWmXWfujcEQwSpaxkz3gcue57+ZfvQdoT9bdEgbDA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc:x-sasl-enc; s= fm1; bh=apiIsWs8IvCdqHTOTmcoquB5SdRw/zFfyXrLI2z9cB0=; b=noqQnlJY xF8+QpeFLGRft4oExz7+0Noa6DJs7Jtu58DugFojQ35LlV12vEGkNGfzJFzp9L1g 2LTaIazwRU+47OBzvW3tFImjeLM/ypB1/gE2Lp91ColxDcjEEmjMolXO6jJQF3Sd TKivujQJzXDirG21B+3Uey17DoaFNubpJNI2iMNYUaTw8rreRBOeQ5fpIv4rRq4/ xkHmNMWLS/0jQIn0Lq3qN+KYd4cGDOV+2Ozc23aYS85zNzRiqr87guN4yHqAlzer jWJI6MwfFaBcum2iPEP1Za5DF4QlV/jktbh2W4wA6oZSv98/di8mGuudmo6TrjEb mmKf4HFHzwnwkA== X-ME-Sender: X-Sasl-enc: Ir2C8vpXXC+lqOXi83W8Zp9We18pYs8Tr74HHHOH8PhY 1496700868 Received: from [192.168.1.2] (75-172-126-41.tukw.qwest.net [75.172.126.41]) by mail.messagingengine.com (Postfix) with ESMTPA id BDB6C241D3; Mon, 5 Jun 2017 18:14:28 -0400 (EDT) Subject: Re: Delete failing with -- permission denied To: anand086 , pgsql-sql@postgresql.org References: <1496695493471-5964882.post@n3.nabble.com> From: Adrian Klaver Message-ID: <5af9dd50-8b18-0562-8cbb-620b1b228759@aklaver.com> Date: Mon, 5 Jun 2017 15:14:27 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.1.1 MIME-Version: 1.0 In-Reply-To: <1496695493471-5964882.post@n3.nabble.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -2.7 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-sql Precedence: bulk Sender: pgsql-sql-owner@postgresql.org On 06/05/2017 01:44 PM, anand086 wrote: > Delete from table test.entities_all is failing with "permission denied for > relation". The table from which row has to be deleted, is referenced by > another table "attribute_types" with ON DELETE CASCADE. > > I tried deleting the row from attribute_types table and then deleting from > test.entities_all succeed. > > I am not able to understand why this delete sql is failing. > > ###################### > Delete from table is failing with > ###################### > > user_test@testdbpg # delete from test.entities_all where entity_type_id = > 254 AND entity_id = 20043093223; > ERROR: permission denied for relation current_change$tmp > CONTEXT: PL/pgSQL function test.current_change() line 11 at RETURN QUERY > SQL statement "SELECT > change_num > FROM test.current_change" > PL/pgSQL function test."changes_package$get_change_num"() line 5 at SQL > statement > PL/pgSQL function test."attribute_types_history$attribute_types"() line 6 at > assignment > SQL statement "DELETE FROM ONLY "test"."attribute_types" WHERE $1 > OPERATOR(pg_catalog.=) "attribute_type_entity_id"" > Time: 65.536 ms You seem to have a chain of triggers/functions on this table. It would be nice to see how those cascade. In particular from above: PL/pgSQL function test."attribute_types_history$attribute_types"() line 6 at assignment SQL statement "DELETE FROM ONLY "test"."attribute_types" WHERE $1 OPERATOR(pg_catalog.=) "attribute_type_entity_id"" which leads me to believe this is the problem: CREATE OR REPLACE FUNCTION test."attribute_types_history$attribute_types"() ... new_change_num := test.changes_package$get_change_num(); ... which then leads to what is in test.changes_package$get_change_num(), though I suspect it includes: SQL statement "DELETE FROM ONLY "test"."attribute_types" WHERE $1 OPERATOR(pg_catalog.=) "attribute_type_entity_id"" Also would be nice to know what user(s) the functions are running as? -- Adrian Klaver adrian.klaver@aklaver.com -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql