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 1tbjW1-00Cwvy-4B for pgsql-performance@arkaria.postgresql.org; Sat, 25 Jan 2025 17:00:13 +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 1tbjVz-003hI1-PZ for pgsql-performance@arkaria.postgresql.org; Sat, 25 Jan 2025 17:00:11 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tbjVz-003hHj-B6 for pgsql-performance@lists.postgresql.org; Sat, 25 Jan 2025 17:00:11 +0000 Received: from mail-ed1-x52d.google.com ([2a00:1450:4864:20::52d]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1tbjVx-001TBc-0X for pgsql-performance@lists.postgresql.org; Sat, 25 Jan 2025 17:00:10 +0000 Received: by mail-ed1-x52d.google.com with SMTP id 4fb4d7f45d1cf-5d3bdccba49so5646618a12.1 for ; Sat, 25 Jan 2025 09:00:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737824408; x=1738429208; darn=lists.postgresql.org; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:from:to:cc:subject:date:message-id:reply-to; bh=MFFAjqZIS34FTNPulVMFKLXqVSX6JYeQr7Db23/QjeU=; b=dsSWXqt7v91lKhLjn7gNlOGV568I2nzi4/+bVBY2s6ioXNARCIzm02dLbHplAybSoR wktVIyuUpIsATLoll5KkGjvsr/lDJQg+ZhqyZSY03Tg9ZQBI813JnH3cWVKL9QJ9tSMa C7ys0IU8fC05YgkG/hfPxh9bT/ILbJLZFZDPwYEutsOC35Z1GOxrOHmlXYyJxPRDi3tE OnsW8reD+GmsEi6MLyIw9QHWFa/U60s8FtG9FD7eHfcOcEPuTsU89ikhzmRnYxy0E0o6 Pce5vhCHBwS7emtd8Mvxrx/6kNI+6+PbBgSUIP4pMIil4ID3gPOlgD6QXoZIXANUahne aRFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737824408; x=1738429208; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=MFFAjqZIS34FTNPulVMFKLXqVSX6JYeQr7Db23/QjeU=; b=XV36UJ7GjACg5JnTANsbwNh0GkPkT30e5CskIJCjluZuLbq3DAJPYrgdzwiabwU/8k HjltwAKe0AqyaxwSYc6rtXAGdRpwGetsM4L7ZoHrB/T6DjoPiYn9Gi5nm1ZJtBsnibDZ /I8v2ebBdufd7IOMeN9zOP9KRm8hJSlOFK/ZQV0Yxz8b2/9VwHF6y6u9x2hUlTAy+MdQ tMow1iNEYIY/eGEztWK+vihDclWKrNnVPk6F1nSndUYJr8gpC9QmPiORy/nPH9IJhmkv TnSNRwNUtbszE0ZBQDLod7qt5Lo9iIF+HQ1+902RIDK8WNVl0LOuQ9oxXbmZgrT9/xnJ 1xRw== X-Gm-Message-State: AOJu0Yy2jCyuPpeNaXJma2iQUeKKVhjiNm6YyPDJt7Z4+wzM3tHj06Xd ZE3KpN1yzPordkoUmbnqk0XQM2v/5m2LYZGtcw5X5Ed/EhQ/yowSoVxUKtlVE/0= X-Gm-Gg: ASbGnctomZDlVt22bYL7j8EVwPrdP7z/x1B6XWai47GC/egUl7EOdYP/C8eJ5P7KqkX BMw/iR0D0n63zzgHl5dl/ntZTjkQwm7uACDGM2zY1jhmq4JvQ3R1ExuBh/VA0LovHdg/rfvw/q0 8TI0xhycdszd2t1IR/jI02zUuGaZ5ZvFdo0rSXT3Ti+iU07i/BZjZZ5ZnnkQbg+QgmFk+X7xjFl jBcXa0k9kazqWk8hhFtzGL4sgAo81ia8eFjXHN3zciV/0pEsQ9D5Y8F+z3Eb5sU1w/f8fzOIWeY vMkBzVEm3mci/utNJgUiH3RQc1ShTp3Ez6rkiAg2hXj/zrP+9WIzkELeEPOxkoFQuKvk23Ebem8 3duXmLrBAmTgOJXzio44/CG6v4WAy7tPIoCrUx/IQ X-Google-Smtp-Source: AGHT+IG3rTvbywbyRgCZN1EMLC2N4yynU8gfS5D/tXK7bFsZHzpdAMoqNviGxpwfZhzst11na+DPTg== X-Received: by 2002:a05:6402:4313:b0:5dc:100c:1567 with SMTP id 4fb4d7f45d1cf-5dc100c180amr9759602a12.15.1737824407618; Sat, 25 Jan 2025 09:00:07 -0800 (PST) Received: from smtpclient.apple (2001-1c04-0681-7700-a50d-7275-da0b-78f3.cable.dynamic.v6.ziggo.nl. [2001:1c04:681:7700:a50d:7275:da0b:78f3]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5dc186b3760sm2744747a12.57.2025.01.25.09.00.06 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 25 Jan 2025 09:00:07 -0800 (PST) From: Frits Hoogland Message-Id: <0E68C6B4-391F-481E-9764-B0D2FE4CF15D@gmail.com> Content-Type: multipart/alternative; boundary="Apple-Mail=_6321713D-D65E-4459-82B4-D30232398673" Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3826.300.87.4.3\)) Subject: Re: Any risk or overhead considerations for frequently executing queries against catalog tables? Date: Sat, 25 Jan 2025 17:59:55 +0100 In-Reply-To: Cc: pgsql-performance@lists.postgresql.org To: Pavel Stehule References: X-Mailer: Apple Mail (2.3826.300.87.4.3) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --Apple-Mail=_6321713D-D65E-4459-82B4-D30232398673 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 Thank you Pavel, that is really useful. I can imagine other people = thinking about getting 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? 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 objects = including pg_database are not actively queried. I git 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 datfrozenxid and datminmxid? There is a lock for updating 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 datminmxid are = in place updated, with no read consistency provided. Frits Hoogland > On 25 Jan 2025, at 14:32, Pavel Stehule = wrote: >=20 > Hi >=20 > so 25. 1. 2025 v 12:23 odes=C3=ADlatel Frits Hoogland = > napsal: >> For monitoring database behaviour and trying to build an history of = activity, if 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; >> select * from pg_stat_wal; >> select * from pg_settings; >> select * from pg_database; >> For which the query is prepared, and execute that every 1 second, = would there be any realistic danger or overhead that should be = considered? >> My thinking is that the data for these catalogs are all in shared = memory and when executed serially and do not cause any significant = resources to be taken? >=20 > The queries to all tables excluding pg_database every 1 sec will have = probably zero impact to performance. >=20 > I am not sure about pg_database - it is a very important table, and = your query can block operations that need exclusive lock to this table. = So theoretically, there can be some impact to performance. >=20 > Regards >=20 > Pavel > =20 >>=20 >> Thanks, >>=20 >> Frits Hoogland >>=20 >>=20 >>=20 >>=20 --Apple-Mail=_6321713D-D65E-4459-82B4-D30232398673 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8 Thank you = Pavel, that is really useful. I can imagine other people thinking about = getting 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?
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 objects = including pg_database are not actively queried.

I = git 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 datfrozenxid and datminmxid?

There = is a lock for updating 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 datminmxid are in place = updated, with no read consistency provided.

Frits = Hoogland




On 25 Jan 2025, at 14:32, Pavel = Stehule <pavel.stehule@gmail.com> wrote:

Hi

so 25. 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, if 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;
select * from pg_stat_wal;
select = * from pg_settings;
select * from pg_database;
For = which the query is prepared, and execute that every 1 second, would = there be any realistic danger or overhead that should be = considered?
My thinking is that the data for these catalogs = are all in shared memory and when executed serially and do not cause any = significant resources to be = taken?

The queries to all = tables excluding pg_database every 1 sec will have probably zero impact = to performance.

I am not sure about pg_database = - it is a very important table, and your query can block operations that = need exclusive lock to this table. So theoretically, there can be some = impact to = performance.

Regards

Pav= el
 

Thanks,
<= div>
Frits = Hoogland





= --Apple-Mail=_6321713D-D65E-4459-82B4-D30232398673--