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 1fQalv-0003sl-Ls for pgsql-general@arkaria.postgresql.org; Wed, 06 Jun 2018 15:54:52 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fQalu-0003Rw-H8 for pgsql-general@arkaria.postgresql.org; Wed, 06 Jun 2018 15:54:50 +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 1fQalt-0003Ri-Sc for pgsql-general@lists.postgresql.org; Wed, 06 Jun 2018 15:54:50 +0000 Received: from resqmta-ch2-01v.sys.comcast.net ([2001:558:fe21:29:69:252:207:33]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fQalp-0005lc-UV for pgsql-general@postgresql.org; Wed, 06 Jun 2018 15:54:49 +0000 Received: from resomta-ch2-12v.sys.comcast.net ([69.252.207.108]) by resqmta-ch2-01v.sys.comcast.net with ESMTP id QXzffIS4caW5AQalkfSq50; Wed, 06 Jun 2018 15:54:40 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=comcast.net; s=q20161114; t=1528300480; bh=5SRhrzI9FykxQogdY6+YzCTXjx74chrVZmYhOsZvo2M=; h=Received:Received:Received:From:To:Subject:Date:Message-ID: MIME-Version:Content-Type; b=ovwNVvt/74B+qAe0pIlvIBL79agcMpPgRSHIc2HWzDo5CZHr3yxvyR1ECwT+X/rj7 Rcr72nOrkKs1HM0S61LkK91blbDCaFtx1VzBp/5prhxAZi7lBi4ocdmjJ3WP8/CliP S4TlD9OIbI0aMq1AJ0Zw2Be92nELOdrP8hZR96eId8drQfu+Slz/FdLF6tbs+BxZS0 7LavDsxdGsssSlR0Rp4NOXMJ8xNE+toBR8m1gWv3lhnA5zXzYlYqYmznf6tCJylU+J LpURtR81c6Dkc1L5iSMW9ixYI42uWZ/k9tKRpGuSYybM8wxlpiT0mchpGo+WFOtJqn /khFfgCii0XOw== Received: from jsievers.comcast.net ([71.57.79.23]) by resomta-ch2-12v.sys.comcast.net with ESMTPA id QalkfeCIwJxqiQalkfFXru; Wed, 06 Jun 2018 15:54:40 +0000 Received: from jsievers.enova.com (localhost [127.0.0.1]) by jsievers.comcast.net (Postfix) with ESMTP id 0695A260056; Wed, 6 Jun 2018 10:54:40 -0500 (CDT) From: Jerry Sievers To: Adrian Klaver Cc: Jerry Sievers , pgsql-general@postgresql.org Subject: Re: Which backend using which pg_temp_N schema? References: <87o9go3nok.fsf@jsievers.enova.com> <81d847d2-59eb-0094-59cf-b91565213f44@aklaver.com> <87k1rc3ibz.fsf@jsievers.enova.com> <52ec7e75-9159-7879-fdeb-8d5d120b6ac9@aklaver.com> Date: Wed, 06 Jun 2018 10:54:40 -0500 In-Reply-To: <52ec7e75-9159-7879-fdeb-8d5d120b6ac9@aklaver.com> (Adrian Klaver's message of "Wed, 6 Jun 2018 07:06:37 -0700") Message-ID: <877enbsyf3.fsf@jsievers.enova.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-CMAE-Envelope: MS4wfNng0JliW1G5l0dEwCaTxcSNIFgj09NxQ/NlW80qis0p9hlHxfNhM2PFFVN5DvvDqx2SoIpkN03bAzihWazyXtO22rvH/E9zVKFfSF0m3cGe3WpYfeWn 7PZpr0BzRabWlyKQhkKrg4yIjJjP5K9V/VxPKi8AObb4dUWsdeZHMAHydtMMRY9PwjtNgVUPwmKzFOmDzNgEYUiW5Di7wv8fpOmn0CU6zraPpRrUC9zI6S/G HLUOZDrXysNnkHcDQtT3g02H9EGxfI6Dgd/YpmQG7UA= List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Adrian Klaver writes: > 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: Yep thanks... but IMO something that simply exposes whatever internal registry of temp schemas/PIDs (which I presume must exist) to DBA SQL avoids any perhaps unreliable hackery such as having to scrape query text from pg_stat_activity or similar. To wit; A long standing session might have any number of temp objects existing for which records of same in the aforementioned views has long since been overwritten. > > 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 >>>> >> -- Jerry Sievers Postgres DBA/Development Consulting e: postgres.consulting@comcast.net p: 312.241.7800