Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tbor8-00Dcts-0G for pgsql-performance@arkaria.postgresql.org; Sat, 25 Jan 2025 22:42:22 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1tbor5-0059MU-Jn for pgsql-performance@arkaria.postgresql.org; Sat, 25 Jan 2025 22:42:19 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tbor5-0059MM-6F for pgsql-performance@lists.postgresql.org; Sat, 25 Jan 2025 22:42:19 +0000 Received: from mail-ej1-x62a.google.com ([2a00:1450:4864:20::62a]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1tbor1-001Vhb-2b for pgsql-performance@lists.postgresql.org; Sat, 25 Jan 2025 22:42:18 +0000 Received: by mail-ej1-x62a.google.com with SMTP id a640c23a62f3a-aaeef97ff02so563347466b.1 for ; Sat, 25 Jan 2025 14:42:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737844935; x=1738449735; darn=lists.postgresql.org; h=to:in-reply-to:cc:references:message-id:date:subject:mime-version :from:content-transfer-encoding:from:to:cc:subject:date:message-id :reply-to; bh=ijCZyI4ioNjh3WUoLgLCUKgEwSpHd/yvn8rMBoZlmHM=; b=Uq1RQeZp8TdEW8VutKOlRw08P7zwwsEdikvjcFxPYrJAcJQzZJK+3AMZyWa739PHUZ QqbnjzY1Qih4aSWtFCA3xaCjK1WATZ2edPsHDVvBRgaqqMCmgaU3MYlMTVjeDzBqQAKw TvgoZoV9TDwcuUmIjbA1YIKnp1R9hY1IaZS/CpZzws1n9c9oeKA39QeG6163bNN2XDps l1H1pw21DO4R3nZzN2y8NW9GUJh5mi/ge3jd75r/ayLstA+XKW1vt6HnI1MnrPHlaQzO tVtOUqiyqdMmEMZnBs9f24II0SOTH0rD0CP7kRhtlvjnm97QOu7VTxG0uIgfVoOOm2AW MEmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737844935; x=1738449735; h=to:in-reply-to:cc:references:message-id:date:subject:mime-version :from:content-transfer-encoding:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ijCZyI4ioNjh3WUoLgLCUKgEwSpHd/yvn8rMBoZlmHM=; b=InMFwKNyzfK1TsxXURci3rK0glVejQDFeB+VK9xqkPGaUYd0tXDjkjwCTPepWKuLhW Xikvdjll9AKmjMdqCjEC4OQVyw7XmQV/4pC5elVnnZxYlFBVOIUmpvDZekdW0vnqrCFn Wl3v1GRniZ0nV4YyUGchPhDZKRzyUnE6dNFZluPdqoGBvJV/pd1Jp+4FZLqJMHGZFqhH xbMnVQ6F7zCRKAXH9JqA0/8CbRKGlc2dhAYH6yzzyJN1WX+xPHa1kf9KRbdjqQmF9KM3 vXqVfHaAS2aQqsEy2dgESmFyHvdbB2Qvgog9PZKKzV4l+T35Gqb8/TD+kREj59mfQzOX WbFA== X-Forwarded-Encrypted: i=1; AJvYcCVttjYVvl89L5r5xb1QQb9x2jNvh9najRtW6JQ0LrFypuqsspkaYQGgiNi3MaXmSAst50T8S2Wl6Kt19dt5tlBxOA==@lists.postgresql.org X-Gm-Message-State: AOJu0YyBC1q6hk/amJLZpuq1skB02WSa8PHt/IPazg77NkNRSX8Ie4G3 /djLbP0XMIRrSSHTauUn/Bik4o+zfz0zoV4Jb8N/bER55O66UzEe X-Gm-Gg: ASbGncuOrkXr9aSpc+9yVqkr6nWZxMsYcFwWCcrmZY4mlK9i9DCI67BXcujSJZ/cJhI yy6w9yIWWkcb9CnBtQQS5RZ5v/AIOefn/rIDq8xC8N2PJULnrHnV/cSFgeUyX5RtUotXuW2N8cj 6SvTuSi0rxuzFZKgwv+pCQo97lzfTtbPRry/axnno4qWRwj8xQNGb9rscfB6F4AYmeAjFa0/+19 I83G87lwy+1kI5iZP9fJo1Qn+nQWwAW8CH9QwUTP5PTjs2967nFsG5cY6vKGXovWNI/7A4MZ0dD FjK1Tk1UJvg5Adkv2ZjoGfEhsLMfqlIhKeCD6GN5JBwqVDEIJPRXS8rSbbNHW8cdcBKpilk+TvV dmocVTY4u4GQy4y+X5W36Iif7RKAl9GuaVL68bfW7 X-Google-Smtp-Source: AGHT+IHIF+sdeqNiNDfxPsE+PZvssdxAdKgC69MznaalXuY9ec7TMfE6uLb8gYpbd0TDGPdokVW/nA== X-Received: by 2002:a17:907:94cb:b0:aa6:423c:850e with SMTP id a640c23a62f3a-ab38b29954bmr3226735066b.27.1737844934943; Sat, 25 Jan 2025 14:42:14 -0800 (PST) Received: from smtpclient.apple (2001-1c04-0681-7700-d9d9-e773-99ab-6d8f.cable.dynamic.v6.ziggo.nl. [2001:1c04:681:7700:d9d9:e773:99ab:6d8f]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ab6760ab31dsm346186666b.89.2025.01.25.14.42.12 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 25 Jan 2025 14:42:13 -0800 (PST) Content-Type: multipart/alternative; boundary=Apple-Mail-7337F8C6-0C6A-480D-8C19-55D3F894A566 Content-Transfer-Encoding: 7bit From: frits.hoogland@gmail.com Mime-Version: 1.0 (1.0) Subject: Re: Any risk or overhead considerations for frequently executing queries against catalog tables? Date: Sat, 25 Jan 2025 23:42:02 +0100 Message-Id: <0C899A03-5B27-4380-9EA9-59DE2047FDFD@gmail.com> References: <62B9D71B-DD8C-45DE-8A15-1C1D716CA645@gmail.com> Cc: Pavel Stehule , pgsql-performance@lists.postgresql.org In-Reply-To: <62B9D71B-DD8C-45DE-8A15-1C1D716CA645@gmail.com> To: peter plachta X-Mailer: iPhone Mail (22C161) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --Apple-Mail-7337F8C6-0C6A-480D-8C19-55D3F894A566 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable Thank you, I will look, very interesting!
One thing I found is that because certain statistics are p= rovided after a query has run, measuring them in a fine grained way shows a p= eak for something that in reality is taking place over a period of time. &nb= sp;

If anyone has a url of where this can be found,= I would be very grateful!

Verstuurd vanaf mijn iPhone

<= blockquote type=3D"cite">Op 25 jan 2025 om 23:08 heeft peter plachta <ppl= achta@gmail.com> het volgende geschreven:

=EF=BB=BFDataDog =E2=80=94 which implemen= ts such metrics for Postgres - has ran into multiple issues doing this type o= f thing. You may be able to search their bugs / repo to see what they were. I= just can=E2=80=99t remember them off hand, it=E2=80=99s been a while.
<= br id=3D"lineBreakAtBeginningOfSignature">
Sent from my iPho= ne

On Jan 25, 2025, at 1= 2:01=E2=80=AFPM, Frits Hoogland <frits.hoogland@gmail.com> wrote:
<= br>
=EF=BB=BFI am l= ooking at whether sampling key database catalog information per second would= have any drawback whatsoever.
I think you're saying that you think isn'= t the case, except maybe for pg_database, and I figure that is because of th= e frozen and multi xact fields per database.

If the= database client application is too unpredictable to know what SQL it will p= roduce, then having runtime data available at that granularity, so it can be= reasonably constructed what is going on is very convenient and allows treme= ndous insight. It would also allow usage of the waitevents to spot any weird= behavior, such as short-lived peaks. (pg_stat_statements can do that on a b= usy database, for example).
And if there is no known drawback, if s= uch a low interval can be organized: why not? I am not saying you are doing i= t wrong, this is about trying to figure out what are the borders of what wou= ld be technically possible without unreasonably affecting the database, a th= ought experiment.

If course the gathered data needs= to be organized so that you don't swamp in it, and it shouldn't lead to the= monitoring data swamping the system, either in memory or on disk, but that i= s a given.

Why would per second be too much for loc= ks? Is there overhead to select from pg_locks, or pg_blocking_pids()?
<= div>
Again, please realise I am happy and appreciative of the t= ime you take, I am toying with the above described idea.

Frits Hoogland

=



On 25 Jan 2025, at 19:18, Pavel Steh= ule <pavel.stehule@gmail.com> wrote:

Hi

so 25. 1. 2025 v 18:00 odes=C3=ADlatel Frits Hoogland <frits.hoogland@gmail.com> napsa= l:
Thank you P= avel, that is really useful. I can imagine other people thinking about getti= ng fine grained data from postgres might wonder the same as I do about this.=
And really from a computer's perspective I would say that once a second= isn't really a high frequency?

= I usually work with minute sampling and usually it is good enough (statistic= s are cumulative, so you can lose the timestamp, but you never lose data.

Only when we try to investigate some special case, th= en I use second sampling. When you investigate lock issues, then seconds are= too much

Regards

Pave= l
 
If I time the amount of time that these queries take, it's around= 20ms (local connection), so there is a relative long time of all the object= s including pg_database are not actively queried.

I g= it grepped the sourcecode, it seems that there is a rowexclusive lock for pg= _database manipulation in case of addition, removal and change of a database= in dbcommands.c, but I do think your reasoning is based on the columns datf= rozenxid and datminmxid?

There is a lock for updati= ng the frozenxid and mxid for a database in (vacuum.c:LockDatabaseFrozenIds,= ExclusiveLock), but it seems a select should play nice with that?

btw, it's interesting to see that both datfrozenxid and datm= inmxid are in place updated, with no read consistency provided.
Frits Hoogland

<= br>

On 25 Jan 2025, at 14:32, Pavel Steh= ule <pavel.s= tehule@gmail.com> wrote:

Hi

so 2= 5. 1. 2025 v 12:23 odes=C3=ADlatel Frits Hoogland <frits.hoogland@gmail.com>= ; napsal:
For= monitoring database behaviour and trying to build an history of activity, i= f I would create an application that creates a single connection and execute= something like:
select * from pg_stat_activity;
select * from= pg_stat_database;
select * from pg_stat_bgwriter;
selec= t * from pg_stat_wal;
select * from pg_settings;
select *= from pg_database;
For which the query is prepared, and execute th= at every 1 second, would there be any realistic danger or overhead that shou= ld be considered?
My thinking is that the data for these catalogs a= re all in shared memory and when executed serially and do not cause any sign= ificant resources to be taken?

T= he queries to all tables excluding pg_database every 1 sec will have probabl= y zero impact to performance.

I am not sure about p= g_database - it is a very important table, and your query can block operatio= ns that need exclusive lock to this table. So theoretically, there can be so= me impact to performance.

Regards

Pavel
 

Thanks,

<= div>
Frits Hoogland






= --Apple-Mail-7337F8C6-0C6A-480D-8C19-55D3F894A566--