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 1kkjSl-00022m-NO for pgsql-hackers@arkaria.postgresql.org; Thu, 03 Dec 2020 07:55:39 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kkjSk-0002bX-Kz for pgsql-hackers@arkaria.postgresql.org; Thu, 03 Dec 2020 07:55:38 +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 1kkjSk-0002bO-6a for pgsql-hackers@lists.postgresql.org; Thu, 03 Dec 2020 07:55:38 +0000 Received: from mail-pg1-x534.google.com ([2607:f8b0:4864:20::534]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kkjSh-0002Bb-Hf for pgsql-hackers@postgresql.org; Thu, 03 Dec 2020 07:55:36 +0000 Received: by mail-pg1-x534.google.com with SMTP id o4so934376pgj.0 for ; Wed, 02 Dec 2020 23:55:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=leadboat.com; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=fdPEDO4OcjBpxUNcl3C1Wiik//oKtXnRVmdQzoeHc84=; b=QlbgA7nHBvIMHzo+wq8dFdh6/JsKaPR3tJffQkbhaZhSP3nlZLpb2qdQl7iJQLK+Ot 3swpMHPl/Xb7lxn1YdRdaCR5OCGTJqAKubXgBhKbPfz1T0kn7vdfd2tYblaU6+bdIg0F 7TrXwZfoy/X+TP09HNUrERoSBDFBRL+qpIFXY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=fdPEDO4OcjBpxUNcl3C1Wiik//oKtXnRVmdQzoeHc84=; b=MWu6bYzs29wb6FD3RV3uxfdOw6RKv52NOIJh9dMCtL0Dx+0K9MpO9wUSjqpq+Z6cDN A8LFASPIyOAEtghERDW6Ofk36F6Ry0TNAY0MP2/cY75DE9WPLhyF4tt1NZ872vqcsk/3 uMdjiyni/ggaQ1qOFmwFXUCqTcGlbypwaEWxeKVw0psNKz9b/6OgWUVXABCnKDbPFG6J Uf/zD3M+HJVjhyQkmklfdX0oJltsp0QoVUSQ5fXEfQsx+D5yj9TKITOWhQBMFkj3qtV0 PmIhN6oWZHhQPIdmmmAMcsQZuzL35dG/w2MConEZAW5OZ7AVj4AzxHmMZ9lUJPaPxb7M l9Fg== X-Gm-Message-State: AOAM531AOPCsRtlFD43t9AMEbfXW03byDLvPyPXSM2t3gb02l5wOuB7J Y24rhNwZG/Pl6OWXPzvoUDBiWQ== X-Google-Smtp-Source: ABdhPJy/objqR8H+9H3p8rcn9CJ97YAt6aD5QWFok693KCjWb9aJxhEPVov9KObpncJBESK08uomNQ== X-Received: by 2002:a62:2ec4:0:b029:18e:f566:d459 with SMTP id u187-20020a622ec40000b029018ef566d459mr2066598pfu.80.1606982133908; Wed, 02 Dec 2020 23:55:33 -0800 (PST) Received: from rfd.leadboat.com ([2600:1702:a20:5750::43]) by smtp.gmail.com with ESMTPSA id u6sm571641pjn.56.2020.12.02.23.55.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 02 Dec 2020 23:55:32 -0800 (PST) Date: Wed, 2 Dec 2020 23:55:30 -0800 From: Noah Misch To: Peter Eisentraut Cc: pgsql-hackers Subject: Re: convert elog(LOG) calls to ereport Message-ID: <20201203075530.GA866006@rfd.leadboat.com> References: <92d6f545-5102-65d8-3c87-489f71ea0a37@enterprisedb.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <92d6f545-5102-65d8-3c87-489f71ea0a37@enterprisedb.com> User-Agent: Mutt/1.5.24 (2015-08-30) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Wed, Dec 02, 2020 at 02:26:24PM +0100, Peter Eisentraut wrote: > There are a number of elog(LOG) calls that appear to be user-facing, so they > should be ereport()s. > @@ -8591,25 +8604,46 @@ LogCheckpointEnd(bool restartpoint) > CheckpointStats.ckpt_sync_rels; > average_msecs = (long) ((average_sync_time + 999) / 1000); > > - elog(LOG, "%s complete: wrote %d buffers (%.1f%%); " > - "%d WAL file(s) added, %d removed, %d recycled; " > - "write=%ld.%03d s, sync=%ld.%03d s, total=%ld.%03d s; " > - "sync files=%d, longest=%ld.%03d s, average=%ld.%03d s; " > - "distance=%d kB, estimate=%d kB", +1 to this change. > @@ -1763,7 +1771,8 @@ pq_setkeepalivesidle(int idle, Port *port) > #else > if (idle != 0) > { > - elog(LOG, "setting the keepalive idle time is not supported"); > + ereport(LOG, > + (errmsg("setting the keepalive idle time is not supported"))); +1 > --- a/src/backend/optimizer/geqo/geqo_erx.c > +++ b/src/backend/optimizer/geqo/geqo_erx.c > @@ -420,7 +420,8 @@ edge_failure(PlannerInfo *root, Gene *gene, int index, Edge *edge_table, int num > } > } > > - elog(LOG, "no edge found via random decision and total_edges == 4"); > + ereport(LOG, > + (errmsg("no edge found via random decision and total_edges == 4"))); The user can't act upon this without reading the source code. This and the other messages proposed in this file are better as elog(). > @@ -343,7 +346,8 @@ PGSharedMemoryCreate(Size size, > * care. > */ > if (!CloseHandle(hmap)) > - elog(LOG, "could not close handle to shared memory: error code %lu", GetLastError()); > + ereport(LOG, > + (errmsg("could not close handle to shared memory: error code %lu", GetLastError()))); The numerous messages proposed in src/backend/port/ files are can't-happen events, and there's little a DBA can do without reading the source code. They're better as elog(). > @@ -6108,8 +6111,9 @@ backend_read_statsfile(void) > /* Copy because timestamptz_to_str returns a static buffer */ > filetime = pstrdup(timestamptz_to_str(file_ts)); > mytime = pstrdup(timestamptz_to_str(cur_ts)); > - elog(LOG, "stats collector's time %s is later than backend local time %s", > - filetime, mytime); > + ereport(LOG, > + (errmsg("statistics collector's time %s is later than backend local time %s", > + filetime, mytime))); +1 > @@ -769,10 +769,11 @@ StartupReplicationOrigin(void) > replication_states[last_state].remote_lsn = disk_state.remote_lsn; > last_state++; > > - elog(LOG, "recovered replication state of node %u to %X/%X", > - disk_state.roident, > - (uint32) (disk_state.remote_lsn >> 32), > - (uint32) disk_state.remote_lsn); > + ereport(LOG, > + (errmsg("recovered replication state of node %u to %X/%X", > + disk_state.roident, > + (uint32) (disk_state.remote_lsn >> 32), > + (uint32) disk_state.remote_lsn))); +1 > @@ -1914,7 +1914,8 @@ FileClose(File file) > > /* in any case do the unlink */ > if (unlink(vfdP->fileName)) > - elog(LOG, "could not unlink file \"%s\": %m", vfdP->fileName); > + ereport(LOG, > + (errmsg("could not unlink file \"%s\": %m", vfdP->fileName))); +1 > > /* and last report the stat results */ > if (stat_errno == 0) > @@ -1922,7 +1923,8 @@ FileClose(File file) > else > { > errno = stat_errno; > - elog(LOG, "could not stat file \"%s\": %m", vfdP->fileName); > + ereport(LOG, > + (errmsg("could not stat file \"%s\": %m", vfdP->fileName))); +1 For the changes I didn't mention explicitly (most of them), I'm -0.5. Many of them "can't happen", use source code terms of art, and/or breach guideline "Avoid mentioning called function names, either; instead say what the code was trying to do" (https://www.postgresql.org/docs/devel/error-style-guide.html).