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 1qHJXu-00080z-1M for pgsql-hackers@arkaria.postgresql.org; Thu, 06 Jul 2023 07:36:58 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1qHJXs-0003sJ-Iu for pgsql-hackers@arkaria.postgresql.org; Thu, 06 Jul 2023 07:36:56 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qHJXs-0003sA-6j for pgsql-hackers@lists.postgresql.org; Thu, 06 Jul 2023 07:36:56 +0000 Received: from mail-lj1-x22d.google.com ([2a00:1450:4864:20::22d]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1qHJXp-002Ja9-7p for pgsql-hackers@postgresql.org; Thu, 06 Jul 2023 07:36:55 +0000 Received: by mail-lj1-x22d.google.com with SMTP id 38308e7fff4ca-2b6c3e23c5fso744451fa.0 for ; Thu, 06 Jul 2023 00:36:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1688629011; x=1691221011; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=R5AIOqMNEUg6FgVwimMR6ohx0V9/sSk7vbbUJL/2oLc=; b=eTGta3eBOwkBhpAqwc/zUSZhlDQq6radml33CEfzdf2AZRG+p7yp5sDDUyc3wpSn1I gXLgjjg8Ah0zMwFWfdpGN7N9DPeDhBYXtP9bxslyDKMrSFi0iS9Pu5Mc7cGYkxmLRKtJ YQ13+EB448qdKOwdtHdGqtRFN2TSuDzoGEzak4Q5+mj3qbRznf9iNHJ1Ybr1bJ3uolTZ oID5HKn4EQt9o2c7MY1w11E0ROF19jRuzGkXKgjrqNKq2UkIHt+CsDChqiSlRs2OhF3L OFCGsVQit6Eqg5rV5NpHzvZW+HQFwlJeJ2gQYhJXZtbzq0BG1EfuixfkCDroRNqlmnEU /1Gw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688629011; x=1691221011; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=R5AIOqMNEUg6FgVwimMR6ohx0V9/sSk7vbbUJL/2oLc=; b=bbSUyKYMi9FYZAWMclKZ74vYC72mry56uN6m4HooCs/0Q/+E4jNAx9qHCgWZpwePxu 2wjwB0xGjela9/3hmGGMSkrQH9RNjMTJF3XNIFgx0lsJYJTz3Gnaww+IhfLPwKg1HmX0 XHF1wF53lR0Ainl3NbkH5qCcVpchPhSGyd+C5UqMzXsC1qS9U10q7qXV62Jnb6bLxyIk 0gmkwPl4IKitfIkt2Uu0dhYnd06lzv+b6XPn8NinPS3XeVT3lTTyUYREgT+Ix6h0E9He L0aNh7WooERlkuYnqEE/sfyJBYegY0QxSijwoCSGYTQ27AxrCLBVWBzeOIJ7iXTZPuMF 33NQ== X-Gm-Message-State: ABy/qLazwrqeO1ZB7ToQxqAxubPPsG6XXbdApmnaQvvIFz5esTpXbg4B eaM7yZSqheRvkyXEiViNItZZXz5CIty8YycQ8YcYQ+w+ X-Google-Smtp-Source: APBJJlH5JPjYS4qUo2T1ml97/MEreXGm1lNvYJcEQp+9qBj+geZnn3GGWeS4JHrPh6Gqa9Uqnm37L7L96mFF0X2BSgE= X-Received: by 2002:a2e:a70a:0:b0:2b6:7c3a:6adc with SMTP id s10-20020a2ea70a000000b002b67c3a6adcmr425114lje.5.1688629010560; Thu, 06 Jul 2023 00:36:50 -0700 (PDT) MIME-Version: 1.0 References: <89742024-d51a-c66b-90b9-67f837072cd2@joeconway.com> In-Reply-To: <89742024-d51a-c66b-90b9-67f837072cd2@joeconway.com> From: Masahiko Sawada Date: Thu, 6 Jul 2023 16:36:13 +0900 Message-ID: Subject: Re: RFC: pg_stat_logmsg To: Joe Conway Cc: PostgreSQL-development Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, On Sat, Jul 1, 2023 at 8:57=E2=80=AFAM Joe Conway wrot= e: > > Greetings, > > Attached please find a tarball (rather than a patch) for a proposed new > contrib extension, pg_stat_logmsg. > > The basic idea is to mirror how pg_stat_statements works, except the > logged messages keyed by filename, lineno, and elevel are saved with a > aggregate count. The format string is displayed (similar to a query > jumble) for context, along with function name and sqlerrcode. > > > Part of the thinking is that people with fleets of postgres instances > can use this to scan for various errors that they care about. > Additionally it would be useful to look for "should not happen" errors. Interesting idea and use cases. I'm concerned that displaying the format string could not be helpful in some cases. For example, when raising an ERROR while reading WAL records, we typically write the error message stored in record->errormsg_buf: in ReadRecord(): if (errormsg) ereport(emode_for_corrupt_record(emode, xlogreader->EndRecP= tr), (errmsg_internal("%s", errormsg) /* already translated */ )); In this case, the error message stored in pg_stat_logmsg is just '%s'. The filename and line number columns might help identify the actual error but it requires users to read the source code and cannot know the actual error message. A similar case is where we construct the error message on the fly. For example, in LogRecoveryConflict() the string of the recovery conflict description comes from get_recovery_conflict_desc(): in LogRecoveryConflict(): ereport(LOG, errmsg("recovery still waiting after %ld.%03d ms: %s", msecs, usecs, get_recovery_conflict_desc(reason)), nprocs > 0 ? errdetail_log_plural("Conflicting process: %s.= ", "Conflicting processes: %= s.", nprocs, buf.data) : 0); The user might want to search the error message by the actual conflict reason, but cannot. In this case, I'd like to see the actual error message (I'd like to normalize the number part, though). That being said, using the format string for the error messages like "ERROR: relation "nonexist_table" does not exist" makes sense to me since we can avoid having too many similar entries. So I feel that we might need to figure out what part of the log message should be normalized like pg_stat_statement does for query strings. Regards, -- Masahiko Sawada Amazon Web Services: https://aws.amazon.com