Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nOqKq-00060g-QB for pgsql-admin@arkaria.postgresql.org; Tue, 01 Mar 2022 00:25:48 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nOqKp-0001v2-JH for pgsql-admin@arkaria.postgresql.org; Tue, 01 Mar 2022 00:25:47 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nOqKp-0001uf-5O for pgsql-admin@lists.postgresql.org; Tue, 01 Mar 2022 00:25:47 +0000 Received: from mail-qt1-x82d.google.com ([2607:f8b0:4864:20::82d]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1nOqKm-0001bz-5Y for pgsql-admin@lists.postgresql.org; Tue, 01 Mar 2022 00:25:46 +0000 Received: by mail-qt1-x82d.google.com with SMTP id s15so8624326qtk.10 for ; Mon, 28 Feb 2022 16:25:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:date:mime-version:user-agent:subject:content-language:to :references:from:in-reply-to; bh=y7T3B6gA5X5WUT6y+mCdCW+ZmDI3dJLWsMQnoQjUfPw=; b=QhgLCfBjVTqIOoHrGozHal4x/uxj6bGYeOyBYkEhBrx6k3HZ1G6in+aDp/SVNirBDl Rvj90s0qvBzyo7ijkvHcUPkADXwGjqccv7pcwrNdmqQP0ys7rT0ue28YVDt22ZC9dIJN 2/vi5sHIbYGvIJ+Z4CxNnG6rKZTulDgs4oVRwbhA1aE/lw5NzTjwBqylqtiqOhDHhMMs Aj3xvM/ODd5gLZygRtb2/z8AqFMOQouT+1UlyeCOibgHTiGqhr9JuLAnSiauoSdkoHaR cd719TM1vB9LmHKH88T+ofjoHSXuseRVKnj8flOQkzMVIjQ0k/CknahF0sSQDxaUBZKy brzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:references:from:in-reply-to; bh=y7T3B6gA5X5WUT6y+mCdCW+ZmDI3dJLWsMQnoQjUfPw=; b=6WkWYjRpToIXH1SpQPnkOJc2/RcKUdZntMGs75X/k+osKA3iiE23JBIwmFBmnYV0Sb l52j8Z29HC7RSah/d5caa0Udk4jYMq3Cni4PUFTFcMP0ieRfSiOqk9aj1MyIy8/kGU4D ZfCOeMqjs9c9LJINX+GBRtk5JJLRV3Y/mX8cH7wpSDkYwN48C1sui3PE/RIZrlLIPXqy gnhPybELM3PTSv5TYTxyv5e9Gs4f7npbfRccULvGFx9u7mOZHC/PkZuNoRBr46kYuZCg agLTldbcBauobFCNOSJ+cLHkcLNlgvVlhrFlhc7CtiPgyeOqgRYRp6SfJj6kF7CKTvZC WcTQ== X-Gm-Message-State: AOAM531T71lzlEvVpZ3ixB6VAKBgwG0B8rg/e1+gEDyslMXwqDlDNmaG jJ0hxBsqY7p1lx7Sba96VmgsezGKY0Q= X-Google-Smtp-Source: ABdhPJw04Js5MSIYRevp1HjkYsIim3dHpNdbjcVQtMTTTn7JBGPcMcqz+S0fkuixAdmBBinG2kUOGA== X-Received: by 2002:a05:622a:124e:b0:2db:9b2c:1b58 with SMTP id z14-20020a05622a124e00b002db9b2c1b58mr18031645qtx.318.1646094341457; Mon, 28 Feb 2022 16:25:41 -0800 (PST) Received: from [192.168.2.100] (pool-72-79-19-93.nwrknj.east.verizon.net. [72.79.19.93]) by smtp.gmail.com with ESMTPSA id 141-20020a370393000000b00649498f69dbsm5877713qkd.91.2022.02.28.16.25.39 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 28 Feb 2022 16:25:40 -0800 (PST) Content-Type: multipart/alternative; boundary="------------CoHZPlfoygfLf7d70d3yINJx" Message-ID: <29d1112e-0bc5-02d2-5f2f-7ed256edcea9@gmail.com> Date: Mon, 28 Feb 2022 19:25:39 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.0 Subject: Re: Identifying "cold" data Content-Language: en-US To: pgsql-admin@lists.postgresql.org References: <9f1103cf-6073-4552-fb0e-84862bb226c3@gmail.com> From: Mladen Gogala In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------CoHZPlfoygfLf7d70d3yINJx Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 2/28/22 18:54, Keith Fiske wrote: > > On Thu, Feb 24, 2022 at 9:48 PM Ron wrote: > > On 2/24/22 12:37 PM, Joseph Hammerman wrote: >> Hi postgresql-admins, >> >> Has anyone put any thought or effort into figuring out how to >> measure the total volume of data in a database against *how much >> of it is hot*? I'm looking for some automatable approaches. >> Similarly, is there a way to measure rarely queried columns, or >> unused functions & triggers? > > https://www.postgresql.org/docs/9.6/monitoring-stats.html > > pg_stat_user_tables tells you how many records have been inserted, > updated and deleted since the instance was started.  It does not, > though, say *which* records were updated, > > > -- > Angular momentum makes the world go 'round. > > > For monitoring data itself, I'm not sure of anything else built in > other than what Ron shared with the stats table. If this is something > you really need to monitor, perhaps look into adding a "changed_at" > column to the tables that really need it and set a trigger to > automatically update the timestamp of that column whenever the row is > updated. Not sure how to track column usage. > > For tracking whether functions are used, you can look at the > pg_stat_user_functions catalog > (https://www.postgresql.org/docs/14/monitoring-stats.html#MONITORING-PG-STAT-USER-FUNCTIONS-VIEW), > but as the documentation there notes, you do have to enable > the "track_functions" parameter. I think this tracks trigger function > usage as well, but would be good to test to make sure. > > -- > Keith Fiske > Senior Database Engineer > Crunchy Data - http://crunchydata.com One way would be the proper table design, with TIMESTAMP column which records the time of the last modification. Another way would be a table trigger which would do time accounting for the table. You can implement a "clock" algorithm which would set a "modified" column to 0 and then wait for any application to modify the column and set it to 1. The second hand of the clock would  then set the "old" column. That is roughly analogous to the way Unix and Linux paging systems work. -- Mladen Gogala Database Consultant Tel: (347) 321-1217 https://dbwhisperer.wordpress.com --------------CoHZPlfoygfLf7d70d3yINJx Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit
On 2/28/22 18:54, Keith Fiske wrote:

On Thu, Feb 24, 2022 at 9:48 PM Ron <ronljohnsonjr@gmail.com> wrote:
On 2/24/22 12:37 PM, Joseph Hammerman wrote:
Hi postgresql-admins,

Has anyone put any thought or effort into figuring out how to measure the total volume of data in a database against how much of it is hot? I'm looking for some automatable approaches. Similarly, is there a way to measure rarely queried columns, or unused functions & triggers?

https://www.postgresql.org/docs/9.6/monitoring-stats.html

pg_stat_user_tables tells you how many records have been inserted, updated and deleted since the instance was started.  It does not, though, say which records were updated,


--
Angular momentum makes the world go 'round.

For monitoring data itself, I'm not sure of anything else built in other than what Ron shared with the stats table. If this is something you really need to monitor, perhaps look into adding a "changed_at" column to the tables that really need it and set a trigger to automatically update the timestamp of that column whenever the row is updated. Not sure how to track column usage.

For tracking whether functions are used, you can look at the pg_stat_user_functions catalog (https://www.postgresql.org/docs/14/monitoring-stats.html#MONITORING-PG-STAT-USER-FUNCTIONS-VIEW), but as the documentation there notes, you do have to enable the "track_functions" parameter. I think this tracks trigger function usage as well, but would be good to test to make sure.

--
Keith Fiske
Senior Database Engineer
Crunchy Data - http://crunchydata.com


One way would be the proper table design, with TIMESTAMP column which records the time of the last modification. Another way would be a table trigger which would do time accounting for the table. You can implement a "clock" algorithm which would set a "modified" column to 0 and then wait for any application to modify the column and set it to 1. The second hand of the clock would  then set the "old" column. That is roughly analogous to the way Unix and Linux paging systems work.

-- 
Mladen Gogala
Database Consultant
Tel: (347) 321-1217
https://dbwhisperer.wordpress.com
--------------CoHZPlfoygfLf7d70d3yINJx--