Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fQZ75-0004Ts-B4 for pgsql-general@arkaria.postgresql.org; Wed, 06 Jun 2018 14:08:35 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fQZ74-0003vj-EG for pgsql-general@arkaria.postgresql.org; Wed, 06 Jun 2018 14:08:34 +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.89) (envelope-from ) id 1fQZ5J-0006hB-SU for pgsql-general@lists.postgresql.org; Wed, 06 Jun 2018 14:06:46 +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.89) (envelope-from ) id 1fQZ5E-0003HB-2M for pgsql-general@postgresql.org; Wed, 06 Jun 2018 14:06:44 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 8D2F121C45; Wed, 6 Jun 2018 10:06:38 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Wed, 06 Jun 2018 10:06:38 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= cc: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; s=fm3; bh=Hbmf+JH0MyaltC9TmbsnyF1o7VRIj /3vI7QAUAAF9PY=; b=noIR2zq/7gIz5FjmfZN/RHeT9U80KNVB3vN2mwRMkpoi/ GqiUy5WesHBOPIuaEKHg/piK3Ku1QTltwPPV0QPKp4XgU+VuJ2coGAclnU+NiDDF 4bb0WnMvsz2/E+UMyqlP4bO2X5RfUU7CqhygfNw9SjS+Jq00isDDvA4Ww4lvHj7m cgCAsHJg5s+NzN2i9qCBlY3caf9wChJKtnU5oRzXlVhm/YFNivzmDyL+Afsiqak6 kjDGSZ0feVzby/T8JhCruM4/KlRaNsbBLdHuK/FLsDXL1c2kcYzRpiLpqAndkhlq QFjbFm2EuL2A0KujuGOLP33uMPw2DYdfr5QCvJhrQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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; s=fm2; bh=Hbmf+J H0MyaltC9TmbsnyF1o7VRIj/3vI7QAUAAF9PY=; b=VJ+itZ5V2aPZV3EhL27vGc /3/izrX7XRihhB/mjpIDObbmu8k4jufDg29NtkyKs1ZRHzrxvbSk1TXsASEsrA+e +ahhWCn5TmzEotqJL3n4iqt+373L48d89dCAYHXpdrjp5z/2/jjs/BL5aTLZaCZP 4NSkPGnDbBcvW2q0hDhRkhPIJwKliwvejmQrgO3tt6NLdrf9+DeLdljEKvrsuAE+ Xq2b52/Z/8Jp466AM/zR4/zXCCDd5CFT6rVrlmpGELItB9QlCiDLwUQFKzLh+xBj 9f+jEhCf2pbos5rKZ9L5gHVnNACgu5ntTdsmRk0edy7vdx3V+sYIMpxQP7cbFwCw == X-ME-Proxy: X-ME-Proxy: X-ME-Proxy: X-ME-Proxy: X-ME-Proxy: X-ME-Proxy: X-ME-Sender: Received: from [192.168.1.3] (unknown [71.212.159.209]) by mail.messagingengine.com (Postfix) with ESMTPA id F04CBE425A; Wed, 6 Jun 2018 10:06:37 -0400 (EDT) Subject: Re: Which backend using which pg_temp_N schema? To: Jerry Sievers Cc: pgsql-general@postgresql.org References: <87o9go3nok.fsf@jsievers.enova.com> <81d847d2-59eb-0094-59cf-b91565213f44@aklaver.com> <87k1rc3ibz.fsf@jsievers.enova.com> From: Adrian Klaver Message-ID: <52ec7e75-9159-7879-fdeb-8d5d120b6ac9@aklaver.com> Date: Wed, 6 Jun 2018 07:06:37 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 In-Reply-To: <87k1rc3ibz.fsf@jsievers.enova.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 06/05/2018 04:49 PM, Jerry Sievers wrote: > Adrian Klaver writes: > >> On 06/05/2018 02:53 PM, Jerry Sievers wrote: >> >>> Was just studying a legacy DB to learn about temp table activity. >>> >>> Felt like being able to tie temp schemas to live backends s/b useful but >>> then didn't find a function/view for doing this. >> >> I don't understand what the above is getting at. >> Can you explain more about what you are trying to do? > > Sure... A backend may or not have a pg_temp_N schema assigned to it > depending whether or not it ever needs one for temp objects... > > Suppose we query pg_class and pg_namespace to see what temp tables exist > at some particular time. We find some tables and thus have info about > which role ownes them and the usual. > > But it's a complex and monolithic app with too many aspects all running > as same role. > > Having a way to relate PID to such a temp schema then gives us perhaps a > lot more info about the app behavior. To wit; source IP might lead us > to know that this is a batching aspect of the app and not the OLTP > aspect etc. Just thinking out loud here. The issues I see are: 1) A temporary table is tied to a session and therefore its existence will be some degree of fleeting. 2) A PID will not exist unless an action is done against the table. 3) Said action maybe contain references to other objects which are in the temporary schema and objects that are out of it. So you would have to parse the action statement to determine whether the temporary table/schema is actually involved. To me the solution would be to work from the other direction. When you query pg_class/pg_namespace to determine that temporary tables are present, then query pg_stat_activity to see what statements are being run: https://www.postgresql.org/docs/10/static/monitoring-stats.html#PG-STAT-ACTIVITY-VIEW For a longer term view there is pg_stat_statements: https://www.postgresql.org/docs/10/static/pgstatstatements.html > > Yes of course there might be folks somewhere around this organization > that can answer some of those questions but IMO knowing which PID is > doing temp stuff in some schema tells us a lot that I am not sure can be > machine-gotten any other way. > >> >>> >>> A quic \df for functions with names likely to be fruitful revealed >>> nothing. Did likewise for sysinfo views. >>> >>> Am I missing it or does feature not exist? >>> >>> Thx >>> > -- Adrian Klaver adrian.klaver@aklaver.com