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 1tboKS-00DYor-MR for pgsql-performance@arkaria.postgresql.org; Sat, 25 Jan 2025 22:08:37 +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 1tboKR-00500m-QY for pgsql-performance@arkaria.postgresql.org; Sat, 25 Jan 2025 22:08:35 +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 1tboKR-00500E-Fc for pgsql-performance@lists.postgresql.org; Sat, 25 Jan 2025 22:08:35 +0000 Received: from mail-pj1-x102a.google.com ([2607:f8b0:4864:20::102a]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1tboKO-001VVe-2x for pgsql-performance@lists.postgresql.org; Sat, 25 Jan 2025 22:08:35 +0000 Received: by mail-pj1-x102a.google.com with SMTP id 98e67ed59e1d1-2ee76befe58so5749364a91.2 for ; Sat, 25 Jan 2025 14:08:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737842911; x=1738447711; 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=FqqgKHhLZizawr+Tr8hFxHdsSi1C3Nxhk7xfotmu4o0=; b=gJPGKt8TKqDcslQ/O4vVYfKtIwPXS6sVCgcE1PREaVCP0FSJmReR8s5a00hjX7sQfq 7VzQaydbEcFvnlw9ELuFjoFoG14orHQSsJNhawWVwY/AYQH4IZqx9tSQqbmo2BMamHFG zvbRMJydGR2XqxpD9xjuCeZn42vJUPpfaO26SR7n2xYVYsDpRqV1RRKhdNAQvAsLFD5s LdsQcxnOjxiUpE+HhosAF5DBQMOk8rwUxqcCz+RQsoglKSewI2J2e/y1dmYa7OniTI6C Y9kvqPHKQL7+ZsBEyxdVxgknNJCDdrrDCWL90bdFzc2BGc5vd4irPUsCN8iFCkqzXK+1 nIOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737842911; x=1738447711; 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=FqqgKHhLZizawr+Tr8hFxHdsSi1C3Nxhk7xfotmu4o0=; b=PAOOmMo+Zs4RPLh/zk6gxJPKOj/2f9IvWSW9dOwnJisL4Sog/uOqsg/XJBMaZjd8e1 kyomF+lmQAhkGYrZvJWmA+b/WUGCqECqgU6lgnQZ4/YDZ5Ov7GGs31a/ZayKR6hWgypH RQKGj+TwL+1JucbrA5CHE0UBre16116cuspa7RHqd5pYRSevN0e6bF63tc97HFOjWkmc z6MkiCD8g+TqM47HY8k9exlRvhULBrAMPtMNCn6w1JlOepjQ7qjqjeRoT625i3Se/4ZV 3DCqNV8nqtaADqpppZoVrxi1cclFhW6DaYkLE6ELgcAcNlJ9dslaEpdYYjOJyRsVy2W9 tFmA== X-Forwarded-Encrypted: i=1; AJvYcCXctVGdv0Iq0BDvrysNXwXQ5kxnwCZ9v/SUDfT5NApABkAbhAL0ADS04kJs2lLerTcXY4XU6EgYwdvA8avFu2WyqA==@lists.postgresql.org X-Gm-Message-State: AOJu0YxyH1tA+EGn2sieTEwDtcZiwioyUxEdHHCd2151N+YB6gnLn4mO 8XzvRWYKLjeoMLCmXp+nPtOTy4wZlWDaO8N2E3MJ6HGDdhPdYvOX9+hvRA== X-Gm-Gg: ASbGnct8L2va/9fIbxn23CAzzhNyxH6bUz0hNg5fdUM51X8YI4/RwRf8xNkjGsNb9Pz igmaaXqyenFHJDbMrrnOI+e1BZn9umgzZ3UeAIvTffvqggIZz3ljtIWdHeGkMTfGfm2wI8dhxt+ aXCCTx4gWny864lVbBn0+JSQfMI9u/EF1JtoPjE78X8MDKuMOoIaFECyrIYq4zDpgvRrbydmmXf hqqaYnYS+F8rMOqmk7hl8MTXeGHETT193s1Wwx1jVn6YJ3CewV+HZgmuxhVPuenhQU43r8uhVtN RjBR/MTcLfSignR9x0/9m2/wbDcSFUGmf4Fja0/HIIadqVrThfZ1a+Wxim/FkOKtKrPR X-Google-Smtp-Source: AGHT+IGOJC8siNhVibILJKLxzNNfi6On8W8Vwxhhyhd5gn87hWrxnd2Vkd5zYZTDajXM/IX3R0zSZg== X-Received: by 2002:a05:6a00:4647:b0:725:d1d5:6d86 with SMTP id d2e1a72fcca58-72dafb91467mr52131755b3a.19.1737842911451; Sat, 25 Jan 2025 14:08:31 -0800 (PST) Received: from smtpclient.apple (172-15-11-90.lightspeed.snjsca.sbcglobal.net. [172.15.11.90]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72f8a78e2e6sm4182022b3a.161.2025.01.25.14.08.30 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 25 Jan 2025 14:08:30 -0800 (PST) Content-Type: multipart/alternative; boundary=Apple-Mail-30F8AE05-2BB8-44DC-BD5B-E8C17F40CF05 Content-Transfer-Encoding: 7bit From: peter plachta 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 14:08:29 -0800 Message-Id: <62B9D71B-DD8C-45DE-8A15-1C1D716CA645@gmail.com> References: <1C9EF412-CED3-40F6-9081-A9464CC87C4B@gmail.com> Cc: Pavel Stehule , pgsql-performance@lists.postgresql.org In-Reply-To: <1C9EF412-CED3-40F6-9081-A9464CC87C4B@gmail.com> To: Frits Hoogland X-Mailer: iPhone Mail (21F90) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --Apple-Mail-30F8AE05-2BB8-44DC-BD5B-E8C17F40CF05 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable DataDog =E2=80=94 which implements such met= rics for Postgres - has ran into multiple issues doing this type of thing. Y= ou 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.

Sent from my iPhone
<= div dir=3D"ltr">
On Jan 25, 2025, at 12:01=E2=80= =AFPM, Frits Hoogland <frits.hoogland@gmail.com> wrote:

=EF=BB=BFI am looking 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 cas= e, except maybe for pg_database, and I figure that is because of the frozen a= nd multi xact fields per database.

If the database c= lient application is too unpredictable to know what SQL it will produce, the= n having runtime data available at that granularity, so it can be reasonably= constructed what is going on is very convenient and allows tremendous insig= ht. It would also allow usage of the waitevents to spot any weird behavior, s= uch as short-lived peaks. (pg_stat_statements can do that on a busy database= , for example).
And if there is no known drawback, if such a low i= nterval can be organized: why not? I am not saying you are doing it wrong, t= his is about trying to figure out what are the borders of what would be tech= nically possible without unreasonably affecting the database, a thought expe= riment.

If course the gathered data needs to be org= anized so that you don't swamp in it, and it shouldn't lead to the monitorin= g data swamping the system, either in memory or on disk, but that is a given= .

Why would per second be too much for locks? Is th= ere overhead to select from pg_locks, or pg_blocking_pids()?

<= /div>
Again, please realise I am happy and appreciative of the time you t= ake, 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-30F8AE05-2BB8-44DC-BD5B-E8C17F40CF05--