Convert elog(LOG) calls to ereport() where appropriate
authorPeter Eisentraut <peter@eisentraut.org>
Fri, 4 Dec 2020 13:25:23 +0000 (14:25 +0100)
committerPeter Eisentraut <peter@eisentraut.org>
Fri, 4 Dec 2020 13:25:23 +0000 (14:25 +0100)
User-visible log messages should go through ereport(), so they are
subject to translation.  Many remaining elog(LOG) calls are really
debugging calls.

Reviewed-by: Alvaro Herrera <alvherre@alvh.no-ip.org>
Reviewed-by: Michael Paquier <michael@paquier.xyz>
Reviewed-by: Noah Misch <noah@leadboat.com>
Discussion: https://www.postgresql.org/message-id/flat/92d6f545-5102-65d8-3c87-489f71ea0a37%40enterprisedb.com

12 files changed:
src/backend/access/gist/gist.c
src/backend/access/nbtree/nbtpage.c
src/backend/access/transam/xlog.c
src/backend/libpq/auth.c
src/backend/libpq/hba.c
src/backend/libpq/pqcomm.c
src/backend/postmaster/bgworker.c
src/backend/postmaster/pgstat.c
src/backend/postmaster/postmaster.c
src/backend/replication/logical/origin.c
src/backend/storage/file/fd.c
src/backend/utils/misc/guc.c

index 25b42e38f224b2c6f846a874c4528982091d90d1..3f2b416ce1cef1b4db1079be43f0c826a19a9933 100644 (file)
@@ -1167,8 +1167,9 @@ gistfixsplit(GISTInsertState *state, GISTSTATE *giststate)
        Page            page;
        List       *splitinfo = NIL;
 
-       elog(LOG, "fixing incomplete split in index \"%s\", block %u",
-                RelationGetRelationName(state->r), stack->blkno);
+       ereport(LOG,
+                       (errmsg("fixing incomplete split in index \"%s\", block %u",
+                                       RelationGetRelationName(state->r), stack->blkno)));
 
        Assert(GistFollowRight(stack->page));
        Assert(OffsetNumberIsValid(stack->downlinkoffnum));
index 848123d921838d401d4ba757bfc0c7dfab43aa1a..793434c026ca0d04bc43542b3f822574fda26ece 100644 (file)
@@ -2151,9 +2151,10 @@ _bt_unlink_halfdead_page(Relation rel, Buffer leafbuf, BlockNumber scanblkno,
 
                        if (leftsib == P_NONE)
                        {
-                               elog(LOG, "no left sibling (concurrent deletion?) of block %u in \"%s\"",
-                                        target,
-                                        RelationGetRelationName(rel));
+                               ereport(LOG,
+                                               (errmsg("no left sibling (concurrent deletion?) of block %u in \"%s\"",
+                                                               target,
+                                                               RelationGetRelationName(rel))));
                                if (target != leafblkno)
                                {
                                        /* we have only a pin on target, but pin+lock on leafbuf */
index 13f1d8c3dc7f41c4e3f6fd29ca2c7d9b7120a31a..7e81ce4f173f9b2968b7df964531d7802e0e8b89 100644 (file)
@@ -1811,9 +1811,10 @@ WaitXLogInsertionsToFinish(XLogRecPtr upto)
         */
        if (upto > reservedUpto)
        {
-               elog(LOG, "request to flush past end of generated WAL; request %X/%X, currpos %X/%X",
-                        (uint32) (upto >> 32), (uint32) upto,
-                        (uint32) (reservedUpto >> 32), (uint32) reservedUpto);
+               ereport(LOG,
+                               (errmsg("request to flush past end of generated WAL; request %X/%X, current position %X/%X",
+                                               (uint32) (upto >> 32), (uint32) upto,
+                                               (uint32) (reservedUpto >> 32), (uint32) reservedUpto)));
                upto = reservedUpto;
        }
 
@@ -8532,16 +8533,30 @@ ShutdownXLOG(int code, Datum arg)
 static void
 LogCheckpointStart(int flags, bool restartpoint)
 {
-       elog(LOG, "%s starting:%s%s%s%s%s%s%s%s",
-                restartpoint ? "restartpoint" : "checkpoint",
-                (flags & CHECKPOINT_IS_SHUTDOWN) ? " shutdown" : "",
-                (flags & CHECKPOINT_END_OF_RECOVERY) ? " end-of-recovery" : "",
-                (flags & CHECKPOINT_IMMEDIATE) ? " immediate" : "",
-                (flags & CHECKPOINT_FORCE) ? " force" : "",
-                (flags & CHECKPOINT_WAIT) ? " wait" : "",
-                (flags & CHECKPOINT_CAUSE_XLOG) ? " wal" : "",
-                (flags & CHECKPOINT_CAUSE_TIME) ? " time" : "",
-                (flags & CHECKPOINT_FLUSH_ALL) ? " flush-all" : "");
+       if (restartpoint)
+               ereport(LOG,
+                               /* translator: the placeholders show checkpoint options */
+                               (errmsg("restartpoint starting:%s%s%s%s%s%s%s%s",
+                                               (flags & CHECKPOINT_IS_SHUTDOWN) ? " shutdown" : "",
+                                               (flags & CHECKPOINT_END_OF_RECOVERY) ? " end-of-recovery" : "",
+                                               (flags & CHECKPOINT_IMMEDIATE) ? " immediate" : "",
+                                               (flags & CHECKPOINT_FORCE) ? " force" : "",
+                                               (flags & CHECKPOINT_WAIT) ? " wait" : "",
+                                               (flags & CHECKPOINT_CAUSE_XLOG) ? " wal" : "",
+                                               (flags & CHECKPOINT_CAUSE_TIME) ? " time" : "",
+                                               (flags & CHECKPOINT_FLUSH_ALL) ? " flush-all" : "")));
+       else
+               ereport(LOG,
+                               /* translator: the placeholders show checkpoint options */
+                               (errmsg("checkpoint starting:%s%s%s%s%s%s%s%s",
+                                               (flags & CHECKPOINT_IS_SHUTDOWN) ? " shutdown" : "",
+                                               (flags & CHECKPOINT_END_OF_RECOVERY) ? " end-of-recovery" : "",
+                                               (flags & CHECKPOINT_IMMEDIATE) ? " immediate" : "",
+                                               (flags & CHECKPOINT_FORCE) ? " force" : "",
+                                               (flags & CHECKPOINT_WAIT) ? " wait" : "",
+                                               (flags & CHECKPOINT_CAUSE_XLOG) ? " wal" : "",
+                                               (flags & CHECKPOINT_CAUSE_TIME) ? " time" : "",
+                                               (flags & CHECKPOINT_FLUSH_ALL) ? " flush-all" : "")));
 }
 
 /*
@@ -8591,25 +8606,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",
-                restartpoint ? "restartpoint" : "checkpoint",
-                CheckpointStats.ckpt_bufs_written,
-                (double) CheckpointStats.ckpt_bufs_written * 100 / NBuffers,
-                CheckpointStats.ckpt_segs_added,
-                CheckpointStats.ckpt_segs_removed,
-                CheckpointStats.ckpt_segs_recycled,
-                write_msecs / 1000, (int) (write_msecs % 1000),
-                sync_msecs / 1000, (int) (sync_msecs % 1000),
-                total_msecs / 1000, (int) (total_msecs % 1000),
-                CheckpointStats.ckpt_sync_rels,
-                longest_msecs / 1000, (int) (longest_msecs % 1000),
-                average_msecs / 1000, (int) (average_msecs % 1000),
-                (int) (PrevCheckPointDistance / 1024.0),
-                (int) (CheckPointDistanceEstimate / 1024.0));
+       if (restartpoint)
+               ereport(LOG,
+                               (errmsg("restartpoint 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",
+                                               CheckpointStats.ckpt_bufs_written,
+                                               (double) CheckpointStats.ckpt_bufs_written * 100 / NBuffers,
+                                               CheckpointStats.ckpt_segs_added,
+                                               CheckpointStats.ckpt_segs_removed,
+                                               CheckpointStats.ckpt_segs_recycled,
+                                               write_msecs / 1000, (int) (write_msecs % 1000),
+                                               sync_msecs / 1000, (int) (sync_msecs % 1000),
+                                               total_msecs / 1000, (int) (total_msecs % 1000),
+                                               CheckpointStats.ckpt_sync_rels,
+                                               longest_msecs / 1000, (int) (longest_msecs % 1000),
+                                               average_msecs / 1000, (int) (average_msecs % 1000),
+                                               (int) (PrevCheckPointDistance / 1024.0),
+                                               (int) (CheckPointDistanceEstimate / 1024.0))));
+       else
+               ereport(LOG,
+                               (errmsg("checkpoint 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",
+                                               CheckpointStats.ckpt_bufs_written,
+                                               (double) CheckpointStats.ckpt_bufs_written * 100 / NBuffers,
+                                               CheckpointStats.ckpt_segs_added,
+                                               CheckpointStats.ckpt_segs_removed,
+                                               CheckpointStats.ckpt_segs_recycled,
+                                               write_msecs / 1000, (int) (write_msecs % 1000),
+                                               sync_msecs / 1000, (int) (sync_msecs % 1000),
+                                               total_msecs / 1000, (int) (total_msecs % 1000),
+                                               CheckpointStats.ckpt_sync_rels,
+                                               longest_msecs / 1000, (int) (longest_msecs % 1000),
+                                               average_msecs / 1000, (int) (average_msecs % 1000),
+                                               (int) (PrevCheckPointDistance / 1024.0),
+                                               (int) (CheckPointDistanceEstimate / 1024.0))));
 }
 
 /*
index d132c5cb48bd70a453fd54a73ee99701f34dfd06..3d80930968517ff053130539aa9f0d51b5f29419 100644 (file)
@@ -2131,9 +2131,10 @@ pam_passwd_conv_proc(int num_msg, const struct pam_message **msg,
                                reply[i].resp_retcode = PAM_SUCCESS;
                                break;
                        default:
-                               elog(LOG, "unsupported PAM conversation %d/\"%s\"",
-                                        msg[i]->msg_style,
-                                        msg[i]->msg ? msg[i]->msg : "(none)");
+                               ereport(LOG,
+                                               (errmsg("unsupported PAM conversation %d/\"%s\"",
+                                                               msg[i]->msg_style,
+                                                               msg[i]->msg ? msg[i]->msg : "(none)")));
                                goto fail;
                }
        }
index 3a78d2043e57c0b6c9ff7ced2a854f0c9c962ef1..0cc43977691dcf98174f48ba08a45cd3be2ef2ae 100644 (file)
@@ -857,7 +857,8 @@ check_same_host_or_net(SockAddr *raddr, IPCompareMethod method)
        errno = 0;
        if (pg_foreach_ifaddr(check_network_callback, &cn) < 0)
        {
-               elog(LOG, "error enumerating network interfaces: %m");
+               ereport(LOG,
+                               (errmsg("error enumerating network interfaces: %m")));
                return false;
        }
 
index 64a351cedcb1920c08ddad9e6ca86eb2ae15f1ef..0b511008fc837ff7ae227d56ca189cd4bb767e5e 100644 (file)
@@ -750,7 +750,8 @@ StreamConnection(pgsocket server_fd, Port *port)
                                        (struct sockaddr *) &port->laddr.addr,
                                        &port->laddr.salen) < 0)
        {
-               elog(LOG, "getsockname() failed: %m");
+               ereport(LOG,
+                               (errmsg("getsockname() failed: %m")));
                return STATUS_ERROR;
        }
 
@@ -769,7 +770,8 @@ StreamConnection(pgsocket server_fd, Port *port)
                if (setsockopt(port->sock, IPPROTO_TCP, TCP_NODELAY,
                                           (char *) &on, sizeof(on)) < 0)
                {
-                       elog(LOG, "setsockopt(%s) failed: %m", "TCP_NODELAY");
+                       ereport(LOG,
+                                       (errmsg("setsockopt(%s) failed: %m", "TCP_NODELAY")));
                        return STATUS_ERROR;
                }
 #endif
@@ -777,7 +779,8 @@ StreamConnection(pgsocket server_fd, Port *port)
                if (setsockopt(port->sock, SOL_SOCKET, SO_KEEPALIVE,
                                           (char *) &on, sizeof(on)) < 0)
                {
-                       elog(LOG, "setsockopt(%s) failed: %m", "SO_KEEPALIVE");
+                       ereport(LOG,
+                                       (errmsg("setsockopt(%s) failed: %m", "SO_KEEPALIVE")));
                        return STATUS_ERROR;
                }
 
@@ -808,7 +811,8 @@ StreamConnection(pgsocket server_fd, Port *port)
                if (getsockopt(port->sock, SOL_SOCKET, SO_SNDBUF, (char *) &oldopt,
                                           &optlen) < 0)
                {
-                       elog(LOG, "getsockopt(%s) failed: %m", "SO_SNDBUF");
+                       ereport(LOG,
+                                       (errmsg("getsockopt(%s) failed: %m", "SO_SNDBUF")));
                        return STATUS_ERROR;
                }
                newopt = PQ_SEND_BUFFER_SIZE * 4;
@@ -817,7 +821,8 @@ StreamConnection(pgsocket server_fd, Port *port)
                        if (setsockopt(port->sock, SOL_SOCKET, SO_SNDBUF, (char *) &newopt,
                                                   sizeof(newopt)) < 0)
                        {
-                               elog(LOG, "setsockopt(%s) failed: %m", "SO_SNDBUF");
+                               ereport(LOG,
+                                               (errmsg("setsockopt(%s) failed: %m", "SO_SNDBUF")));
                                return STATUS_ERROR;
                        }
                }
@@ -1677,8 +1682,9 @@ pq_setkeepaliveswin32(Port *port, int idle, int interval)
                                 NULL)
                != 0)
        {
-               elog(LOG, "WSAIoctl(SIO_KEEPALIVE_VALS) failed: %ui",
-                        WSAGetLastError());
+               ereport(LOG,
+                               (errmsg("WSAIoctl(%s) failed: %ui",
+                                               "SIO_KEEPALIVE_VALS", WSAGetLastError())));
                return STATUS_ERROR;
        }
        if (port->keepalives_idle != idle)
@@ -1708,7 +1714,8 @@ pq_getkeepalivesidle(Port *port)
                                           (char *) &port->default_keepalives_idle,
                                           &size) < 0)
                {
-                       elog(LOG, "getsockopt(%s) failed: %m", PG_TCP_KEEPALIVE_IDLE_STR);
+                       ereport(LOG,
+                                       (errmsg("getsockopt(%s) failed: %m", PG_TCP_KEEPALIVE_IDLE_STR)));
                        port->default_keepalives_idle = -1; /* don't know */
                }
 #else                                                  /* WIN32 */
@@ -1752,7 +1759,8 @@ pq_setkeepalivesidle(int idle, Port *port)
        if (setsockopt(port->sock, IPPROTO_TCP, PG_TCP_KEEPALIVE_IDLE,
                                   (char *) &idle, sizeof(idle)) < 0)
        {
-               elog(LOG, "setsockopt(%s) failed: %m", PG_TCP_KEEPALIVE_IDLE_STR);
+               ereport(LOG,
+                               (errmsg("setsockopt(%s) failed: %m", PG_TCP_KEEPALIVE_IDLE_STR)));
                return STATUS_ERROR;
        }
 
@@ -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")));
                return STATUS_ERROR;
        }
 #endif
@@ -1790,7 +1799,8 @@ pq_getkeepalivesinterval(Port *port)
                                           (char *) &port->default_keepalives_interval,
                                           &size) < 0)
                {
-                       elog(LOG, "getsockopt(%s) failed: %m", "TCP_KEEPINTVL");
+                       ereport(LOG,
+                                       (errmsg("getsockopt(%s) failed: %m", "TCP_KEEPINTVL")));
                        port->default_keepalives_interval = -1; /* don't know */
                }
 #else
@@ -1833,7 +1843,8 @@ pq_setkeepalivesinterval(int interval, Port *port)
        if (setsockopt(port->sock, IPPROTO_TCP, TCP_KEEPINTVL,
                                   (char *) &interval, sizeof(interval)) < 0)
        {
-               elog(LOG, "setsockopt(%s) failed: %m", "TCP_KEEPINTVL");
+               ereport(LOG,
+                               (errmsg("setsockopt(%s) failed: %m", "TCP_KEEPINTVL")));
                return STATUS_ERROR;
        }
 
@@ -1844,7 +1855,8 @@ pq_setkeepalivesinterval(int interval, Port *port)
 #else
        if (interval != 0)
        {
-               elog(LOG, "setsockopt(%s) not supported", "TCP_KEEPINTVL");
+               ereport(LOG,
+                               (errmsg("setsockopt(%s) not supported", "TCP_KEEPINTVL")));
                return STATUS_ERROR;
        }
 #endif
@@ -1870,7 +1882,8 @@ pq_getkeepalivescount(Port *port)
                                           (char *) &port->default_keepalives_count,
                                           &size) < 0)
                {
-                       elog(LOG, "getsockopt(%s) failed: %m", "TCP_KEEPCNT");
+                       ereport(LOG,
+                                       (errmsg("getsockopt(%s) failed: %m", "TCP_KEEPCNT")));
                        port->default_keepalives_count = -1;    /* don't know */
                }
        }
@@ -1908,7 +1921,8 @@ pq_setkeepalivescount(int count, Port *port)
        if (setsockopt(port->sock, IPPROTO_TCP, TCP_KEEPCNT,
                                   (char *) &count, sizeof(count)) < 0)
        {
-               elog(LOG, "setsockopt(%s) failed: %m", "TCP_KEEPCNT");
+               ereport(LOG,
+                               (errmsg("setsockopt(%s) failed: %m", "TCP_KEEPCNT")));
                return STATUS_ERROR;
        }
 
@@ -1916,7 +1930,8 @@ pq_setkeepalivescount(int count, Port *port)
 #else
        if (count != 0)
        {
-               elog(LOG, "setsockopt(%s) not supported", "TCP_KEEPCNT");
+               ereport(LOG,
+                               (errmsg("setsockopt(%s) not supported", "TCP_KEEPCNT")));
                return STATUS_ERROR;
        }
 #endif
@@ -1942,7 +1957,8 @@ pq_gettcpusertimeout(Port *port)
                                           (char *) &port->default_tcp_user_timeout,
                                           &size) < 0)
                {
-                       elog(LOG, "getsockopt(%s) failed: %m", "TCP_USER_TIMEOUT");
+                       ereport(LOG,
+                                       (errmsg("getsockopt(%s) failed: %m", "TCP_USER_TIMEOUT")));
                        port->default_tcp_user_timeout = -1;    /* don't know */
                }
        }
@@ -1980,7 +1996,8 @@ pq_settcpusertimeout(int timeout, Port *port)
        if (setsockopt(port->sock, IPPROTO_TCP, TCP_USER_TIMEOUT,
                                   (char *) &timeout, sizeof(timeout)) < 0)
        {
-               elog(LOG, "setsockopt(%s) failed: %m", "TCP_USER_TIMEOUT");
+               ereport(LOG,
+                               (errmsg("setsockopt(%s) failed: %m", "TCP_USER_TIMEOUT")));
                return STATUS_ERROR;
        }
 
@@ -1988,7 +2005,8 @@ pq_settcpusertimeout(int timeout, Port *port)
 #else
        if (timeout != 0)
        {
-               elog(LOG, "setsockopt(%s) not supported", "TCP_USER_TIMEOUT");
+               ereport(LOG,
+                               (errmsg("setsockopt(%s) not supported", "TCP_USER_TIMEOUT")));
                return STATUS_ERROR;
        }
 #endif
index 5a9a0e34353767e68587a53e6d980f1f853c0fa5..7ef6259eb50c5fe854f3cec9af1d9c773c8cabd8 100644 (file)
@@ -250,10 +250,10 @@ BackgroundWorkerStateChange(void)
         */
        if (max_worker_processes != BackgroundWorkerData->total_slots)
        {
-               elog(LOG,
-                        "inconsistent background worker state (max_worker_processes=%d, total_slots=%d",
-                        max_worker_processes,
-                        BackgroundWorkerData->total_slots);
+               ereport(LOG,
+                               (errmsg("inconsistent background worker state (max_worker_processes=%d, total_slots=%d)",
+                                               max_worker_processes,
+                                               BackgroundWorkerData->total_slots)));
                return;
        }
 
index 9bad14981b861f32f36bddf53b72fdd2761f3052..7c75a25d210c108cf0a363d8ed6e33aa74874871 100644 (file)
@@ -636,7 +636,8 @@ retry2:
                if (getsockopt(pgStatSock, SOL_SOCKET, SO_RCVBUF,
                                           (char *) &old_rcvbuf, &rcvbufsize) < 0)
                {
-                       elog(LOG, "getsockopt(SO_RCVBUF) failed: %m");
+                       ereport(LOG,
+                                       (errmsg("getsockopt(%s) failed: %m", "SO_RCVBUF")));
                        /* if we can't get existing size, always try to set it */
                        old_rcvbuf = 0;
                }
@@ -646,7 +647,8 @@ retry2:
                {
                        if (setsockopt(pgStatSock, SOL_SOCKET, SO_RCVBUF,
                                                   (char *) &new_rcvbuf, sizeof(new_rcvbuf)) < 0)
-                               elog(LOG, "setsockopt(SO_RCVBUF) failed: %m");
+                               ereport(LOG,
+                                               (errmsg("setsockopt(%s) failed: %m", "SO_RCVBUF")));
                }
        }
 
@@ -6108,8 +6110,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)));
                                pfree(filetime);
                                pfree(mytime);
                        }
@@ -6251,9 +6254,9 @@ pgstat_recv_inquiry(PgStat_MsgInquiry *msg, int len)
                        /* Copy because timestamptz_to_str returns a static buffer */
                        writetime = pstrdup(timestamptz_to_str(dbentry->stats_timestamp));
                        mytime = pstrdup(timestamptz_to_str(cur_ts));
-                       elog(LOG,
-                                "stats_timestamp %s is later than collector's time %s for database %u",
-                                writetime, mytime, dbentry->databaseid);
+                       ereport(LOG,
+                                       (errmsg("stats_timestamp %s is later than collector's time %s for database %u",
+                                                       writetime, mytime, dbentry->databaseid)));
                        pfree(writetime);
                        pfree(mytime);
                }
index b7799ed1d244043ca3e35a3744093aede9572c10..5d09822c8189a08410aa4401fd47bcd9331c772b 100644 (file)
@@ -1207,8 +1207,9 @@ PostmasterMain(int argc, char *argv[])
                                                                 NULL,
                                                                 NULL);
                if (err != kDNSServiceErr_NoError)
-                       elog(LOG, "DNSServiceRegister() failed: error code %ld",
-                                (long) err);
+                       ereport(LOG,
+                                       (errmsg("DNSServiceRegister() failed: error code %ld",
+                                                       (long) err)));
 
                /*
                 * We don't bother to read the mDNS daemon's reply, and we expect that
@@ -1466,7 +1467,8 @@ getInstallationPaths(const char *argv0)
 
        /* Locate the postgres executable itself */
        if (find_my_exec(argv0, my_exec_path) < 0)
-               elog(FATAL, "%s: could not locate my own executable path", argv0);
+               ereport(FATAL,
+                               (errmsg("%s: could not locate my own executable path", argv0)));
 
 #ifdef EXEC_BACKEND
        /* Locate executable backend before we change working directory */
@@ -4674,16 +4676,18 @@ retry:
                                                                        NULL);
        if (paramHandle == INVALID_HANDLE_VALUE)
        {
-               elog(LOG, "could not create backend parameter file mapping: error code %lu",
-                        GetLastError());
+               ereport(LOG,
+                               (errmsg("could not create backend parameter file mapping: error code %lu",
+                                               GetLastError())));
                return -1;
        }
 
        param = MapViewOfFile(paramHandle, FILE_MAP_WRITE, 0, 0, sizeof(BackendParameters));
        if (!param)
        {
-               elog(LOG, "could not map backend parameter memory: error code %lu",
-                        GetLastError());
+               ereport(LOG,
+                               (errmsg("could not map backend parameter memory: error code %lu",
+                                               GetLastError())));
                CloseHandle(paramHandle);
                return -1;
        }
@@ -4708,7 +4712,8 @@ retry:
        }
        if (cmdLine[sizeof(cmdLine) - 2] != '\0')
        {
-               elog(LOG, "subprocess command line too long");
+               ereport(LOG,
+                               (errmsg("subprocess command line too long")));
                UnmapViewOfFile(param);
                CloseHandle(paramHandle);
                return -1;
@@ -4725,8 +4730,9 @@ retry:
        if (!CreateProcess(NULL, cmdLine, NULL, NULL, TRUE, CREATE_SUSPENDED,
                                           NULL, NULL, &si, &pi))
        {
-               elog(LOG, "CreateProcess call failed: %m (error code %lu)",
-                        GetLastError());
+               ereport(LOG,
+                               (errmsg("CreateProcess() call failed: %m (error code %lu)",
+                                               GetLastError())));
                UnmapViewOfFile(param);
                CloseHandle(paramHandle);
                return -1;
@@ -4751,11 +4757,13 @@ retry:
 
        /* Drop the parameter shared memory that is now inherited to the backend */
        if (!UnmapViewOfFile(param))
-               elog(LOG, "could not unmap view of backend parameter file: error code %lu",
-                        GetLastError());
+               ereport(LOG,
+                               (errmsg("could not unmap view of backend parameter file: error code %lu",
+                                               GetLastError())));
        if (!CloseHandle(paramHandle))
-               elog(LOG, "could not close handle to backend parameter file: error code %lu",
-                        GetLastError());
+               ereport(LOG,
+                               (errmsg("could not close handle to backend parameter file: error code %lu",
+                                               GetLastError())));
 
        /*
         * Reserve the memory region used by our main shared memory segment before
@@ -5639,7 +5647,9 @@ CreateOptsFile(int argc, char *argv[], char *fullprogname)
 
        if ((fp = fopen(OPTS_FILE, "w")) == NULL)
        {
-               elog(LOG, "could not create file \"%s\": %m", OPTS_FILE);
+               ereport(LOG,
+                               (errcode_for_file_access(),
+                                errmsg("could not create file \"%s\": %m", OPTS_FILE)));
                return false;
        }
 
@@ -5650,7 +5660,9 @@ CreateOptsFile(int argc, char *argv[], char *fullprogname)
 
        if (fclose(fp))
        {
-               elog(LOG, "could not write file \"%s\": %m", OPTS_FILE);
+               ereport(LOG,
+                               (errcode_for_file_access(),
+                                errmsg("could not write file \"%s\": %m", OPTS_FILE)));
                return false;
        }
 
index 1b220315dff86aa56a3f39b6359349fb9a0f6ae5..15ab8e7204b6cfb6b6c0ae55c4945d38a8bef9ba 100644 (file)
@@ -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)));
        }
 
        /* now check checksum */
index 88004c6fae8e22d8835c3b20b7fcf48bb6ee4729..f07b5325aa5b8c8559a0f446b68b68bddcc72b9d 100644 (file)
@@ -1914,7 +1914,9 @@ 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,
+                                       (errcode_for_file_access(),
+                                        errmsg("could not delete file \"%s\": %m", vfdP->fileName)));
 
                /* and last report the stat results */
                if (stat_errno == 0)
@@ -1922,7 +1924,9 @@ FileClose(File file)
                else
                {
                        errno = stat_errno;
-                       elog(LOG, "could not stat file \"%s\": %m", vfdP->fileName);
+                       ereport(LOG,
+                                       (errcode_for_file_access(),
+                                        errmsg("could not stat file \"%s\": %m", vfdP->fileName)));
                }
        }
 
index 02d2d267b5c34b46063b63c94dd81860aa1fd9b6..635d91d50ac065fe318c8d1eab7456ad14033adc 100644 (file)
@@ -11533,7 +11533,7 @@ assign_tcp_keepalives_idle(int newval, void *extra)
         * once we set it we might fail to unset it.  So there seems little point
         * in fully implementing the check-then-assign GUC API for these
         * variables.  Instead we just do the assignment on demand.  pqcomm.c
-        * reports any problems via elog(LOG).
+        * reports any problems via ereport(LOG).
         *
         * This approach means that the GUC value might have little to do with the
         * actual kernel value, so we use a show_hook that retrieves the kernel