diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml
index ffb6b023fd..8d1fcb08d1 100644
--- a/doc/src/sgml/config.sgml
+++ b/doc/src/sgml/config.sgml
@@ -7479,6 +7479,11 @@ local0.* /var/log/postgresql
Remote host name or IP address
yes
+
+ %L
+ Local interface
+ yes
+
%b
Backend type
diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c
index d91a85cb2d..00f6661120 100644
--- a/src/backend/utils/error/elog.c
+++ b/src/backend/utils/error/elog.c
@@ -67,6 +67,7 @@
#endif
#include "access/xact.h"
+#include "common/ip.h"
#include "libpq/libpq.h"
#include "libpq/pqformat.h"
#include "mb/pg_wchar.h"
@@ -79,6 +80,7 @@
#include "storage/ipc.h"
#include "storage/proc.h"
#include "tcop/tcopprot.h"
+#include "utils/builtins.h"
#include "utils/guc_hooks.h"
#include "utils/memutils.h"
#include "utils/ps_status.h"
@@ -3023,6 +3025,27 @@ log_status_format(StringInfo buf, const char *format, ErrorData *edata)
appendStringInfoSpaces(buf,
padding > 0 ? padding : -padding);
break;
+ case 'L':
+ if (MyProcPort
+ && (MyProcPort->laddr.addr.ss_family == AF_INET
+ ||
+ MyProcPort->laddr.addr.ss_family == AF_INET6)
+ )
+ {
+ Port *port = MyProcPort;
+ char local_host[NI_MAXHOST];
+
+ local_host[0] = '\0';
+
+ if (0 == pg_getnameinfo_all(&port->laddr.addr, port->laddr.salen,
+ local_host, sizeof(local_host),
+ NULL, 0,
+ NI_NUMERICHOST | NI_NUMERICSERV)
+ )
+ /* We do not need clean_ipv6_addr here: just report verbatim */
+ appendStringInfo(buf, "%s", local_host);
+ }
+ break;
case 'r':
if (MyProcPort && MyProcPort->remote_host)
{
diff --git a/src/backend/utils/misc/postgresql.conf.sample b/src/backend/utils/misc/postgresql.conf.sample
index 2166ea4a87..9a87469110 100644
--- a/src/backend/utils/misc/postgresql.conf.sample
+++ b/src/backend/utils/misc/postgresql.conf.sample
@@ -587,6 +587,7 @@
# %d = database name
# %r = remote host and port
# %h = remote host
+ # %L = local interface
# %b = backend type
# %p = process ID
# %P = process ID of parallel group leader