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 1nZCzj-000458-Gw for pgsql-hackers@arkaria.postgresql.org; Tue, 29 Mar 2022 14:38:52 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nZCzi-0002B2-06 for pgsql-hackers@arkaria.postgresql.org; Tue, 29 Mar 2022 14:38:50 +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 1nZCzg-0002Ar-UH for pgsql-hackers@lists.postgresql.org; Tue, 29 Mar 2022 14:38:49 +0000 Received: from wout1-smtp.messagingengine.com ([64.147.123.24]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nZCza-0007LH-Ce for pgsql-hackers@lists.postgresql.org; Tue, 29 Mar 2022 14:38:47 +0000 Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.west.internal (Postfix) with ESMTP id 9290932003F4; Tue, 29 Mar 2022 10:38:38 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Tue, 29 Mar 2022 10:38:39 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm3; bh=LNPt5j8EEMHpiwx/uTliyrJgaIkYJnLqb32AwERBz 5o=; b=DBchygmGW/R+zVDA5MJoUZ0FynZPSJZaPSZOp3IA9FIcwZBe+/6AmawWu Lqu2Rt7mjZVsE6CY8SKKgk1s/vW3wdkManZfZB3jFLOW5yVWesQrSziZUdk1Zo8T s32w1kNtaG5pKicFi5doY98cm5Qs0SZ6OdQvm5Am0Sv+inr8y+sTOPc8UYoVSQfF 1NIkiew3XFTiIkb9n/KuDilM8zbSJmG/ALk7m56amPdiyfqlSoMtgU/Raw047e0V MVNtbMDfPNn5CgmUuE7HxNOlM+eqa8xaMudjkCsTzvGSJohXHczYKtsayn3TyBYm 5h/dJ/qN/Ql0aQN+5DfYjpbz9AwEw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvvddrudeitddgheefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepkfffgggfuffvfhfhjggtgfesthejredttdefjeenucfhrhhomheprfgvthgv rhcugfhishgvnhhtrhgruhhtuceophgvthgvrhdrvghishgvnhhtrhgruhhtsegvnhhtvg hrphhrihhsvggusgdrtghomheqnecuggftrfgrthhtvghrnhepffevgfeuudeuleeiueef jedvhffftedttddugedvueeutdduvdehvdehffdujefhnecuffhomhgrihhnpehpohhsth hgrhgvshhqlhdrohhrghenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgr ihhlfhhrohhmpehpvghtvghrrdgvihhsvghnthhrrghuthesvghnthgvrhhprhhishgvug gsrdgtohhm X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 29 Mar 2022 10:38:36 -0400 (EDT) Message-ID: Date: Tue, 29 Mar 2022 16:38:35 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Thunderbird/91.7.0 Subject: Re: Frontend error logging style Content-Language: en-US To: Daniel Gustafsson , Tom Lane Cc: Andres Freund , Robert Haas , Michael Paquier , PostgreSQL Hackers References: <913687.1645572199@sss.pgh.pa.us> <6fdb3ab3-f093-27b9-dfdc-c391e69163fc@enterprisedb.com> <1346360.1645715441@sss.pgh.pa.us> <1895619.1645809325@sss.pgh.pa.us> <20220322015135.k4tcd3tsjq5xydqa@alap3.anarazel.de> <2446238.1647914437@sss.pgh.pa.us> <20220322021348.pvtvgrseyfohkxob@alap3.anarazel.de> <471299.1648412393@sss.pgh.pa.us> <191BF874-CB92-4F0A-9F0B-414465DE35CB@yesql.se> From: Peter Eisentraut In-Reply-To: <191BF874-CB92-4F0A-9F0B-414465DE35CB@yesql.se> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 29.03.22 12:13, Daniel Gustafsson wrote: Most of these should probably be addressed separately from Tom's patch. >> @@ -508,24 +502,15 @@ writefile(char *path, char **lines) > >> if (fclose(out_file)) >> - { >> - pg_log_error("could not write file \"%s\": %m", path); >> - exit(1); >> - } >> + pg_fatal("could not write file \"%s\": %m", path); >> } > > Should we update this message to differentiate it from the fwrite error case? > Something like "an error occurred during writing.." Should be "could not close ...", no? >> @@ -2057,10 +2004,7 @@ check_locale_name(int category, const char *locale, char **canonname) >> >> save = setlocale(category, NULL); >> if (!save) >> - { >> - pg_log_error("setlocale() failed"); >> - exit(1); >> - } >> + pg_fatal("setlocale() failed"); > > Should this gain a hint message for those users who have no idea what this > really means? My setlocale() man page says: ERRORS No errors are defined. So uh ... ;-) >> @@ -3089,18 +2979,14 @@ main(int argc, char *argv[]) >> else if (strcmp(optarg, "libc") == 0) >> locale_provider = COLLPROVIDER_LIBC; >> else >> - { >> - pg_log_error("unrecognized locale provider: %s", optarg); >> - exit(1); >> - } >> + pg_fatal("unrecognized locale provider: %s", optarg); > > Should this %s be within quotes to match how we usually emit user-input? Usually not done after colon, but could be. >> @@ -1123,9 +1097,9 @@ verify_btree_slot_handler(PGresult *res, PGconn *conn, void *context) >> pg_log_warning("btree index \"%s.%s.%s\": btree checking function returned unexpected number of rows: %d", >> rel->datinfo->datname, rel->nspname, rel->relname, ntups); >> if (opts.verbose) >> - pg_log_info("query was: %s", rel->sql); >> - pg_log_warning("Are %s's and amcheck's versions compatible?", >> - progname); >> + pg_log_warning_detail("Query was: %s", rel->sql); >> + pg_log_warning_hint("Are %s's and amcheck's versions compatible?", >> + progname); > > Should "amcheck's" be a %s parameter to make translation reusable (which it > miht never be) and possibly avoid translation mistake? We don't have translations set up for contrib modules. Otherwise, this kind of thing would probably be something to look into. >> --- a/src/bin/pg_basebackup/receivelog.c >> +++ b/src/bin/pg_basebackup/receivelog.c >> @@ -140,7 +140,7 @@ open_walfile(StreamCtl *stream, XLogRecPtr startpoint) >> /* fsync file in case of a previous crash */ >> if (stream->walmethod->sync(f) != 0) >> { >> - pg_log_fatal("could not fsync existing write-ahead log file \"%s\": %s", >> + pg_log_error("could not fsync existing write-ahead log file \"%s\": %s", >> fn, stream->walmethod->getlasterror()); >> stream->walmethod->close(f, CLOSE_UNLINK); >> exit(1); > > In the case where we already have IO related errors, couldn't the close() call > cause an additional error message which potentially could be helpful for > debugging? Yeah, I think in general we have been sloppy with reporting file-closing errors properly. Those presumably happen very rarely, but when they do, things are probably very bad. >> @@ -597,31 +570,19 @@ main(int argc, char *argv[]) > >> if (ControlFile->data_checksum_version == 0 && >> mode == PG_MODE_CHECK) >> - { >> - pg_log_error("data checksums are not enabled in cluster"); >> - exit(1); >> - } >> + pg_fatal("data checksums are not enabled in cluster"); > Fatal seems sort of out place here, it's not really a case of "something > terrible happened" but rather "the preconditions weren't met". Couldn't these > be a single pg_log_error erroring out with the reason in a pg_log_detail? "fatal" means error plus exit, so this seems ok. There is no separate log level for really-bad-error. >> @@ -721,7 +721,7 @@ setFilePath(ArchiveHandle *AH, char *buf, const char *relativeFilename) >> dname = ctx->directory; >> >> if (strlen(dname) + 1 + strlen(relativeFilename) + 1 > MAXPGPATH) > > Unrelated, but shouldn't that be >= MAXPGPATH? Seems correct to me as is. >> @@ -14951,18 +14942,18 @@ createViewAsClause(Archive *fout, const TableInfo *tbinfo) > >> - fatal("definition of view \"%s\" appears to be empty (length zero)", >> - tbinfo->dobj.name); >> + pg_fatal("definition of view \"%s\" appears to be empty (length zero)", >> + tbinfo->dobj.name); > > I'm not sure we need to provide a definition of empty here, most readers will > probably understand that already =) It could mean, contains no columns, or something similar. If I had to change it, I would remove the "empty" and keep the "length zero". >> @@ -16602,13 +16593,10 @@ dumpSequence(Archive *fout, const TableInfo *tbinfo) >> res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); >> >> if (PQntuples(res) != 1) >> - { >> - pg_log_error(ngettext("query to get data of sequence \"%s\" returned %d row (expected 1)", >> - "query to get data of sequence \"%s\" returned %d rows (expected 1)", >> - PQntuples(res)), >> - tbinfo->dobj.name, PQntuples(res)); >> - exit_nicely(1); >> - } >> + pg_fatal(ngettext("query to get data of sequence \"%s\" returned %d row (expected 1)", >> + "query to get data of sequence \"%s\" returned %d rows (expected 1)", >> + PQntuples(res)), >> + tbinfo->dobj.name, PQntuples(res)); > > The ngettext() call seems a bit out of place here since we already know that > second form will be taken given the check on PQntuples(res). See for a similar case that explains why this is still correct and necessary. >> @@ -144,16 +145,10 @@ main(int argc, char *argv[]) >> if (alldb) >> { >> if (dbname) >> - { >> - pg_log_error("cannot cluster all databases and a specific one at the same time"); >> - exit(1); >> - } >> + pg_fatal("cannot cluster all databases and a specific one at the same time"); >> >> if (tables.head != NULL) >> - { >> - pg_log_error("cannot cluster specific table(s) in all databases"); >> - exit(1); >> - } >> + pg_fatal("cannot cluster specific table(s) in all databases"); > > An ngettext() candidate perhaps? There are more like this in main() hunks further down omitted for brevity here. I would just rephrase this as "cannot cluster specific tables in all databases" This is still correct and sensible if the user specified just one table.