diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml
index b38cbd714a..1cd166063d 100644
--- a/doc/src/sgml/config.sgml
+++ b/doc/src/sgml/config.sgml
@@ -7437,6 +7437,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 ed8aa5c9fa..bcab52f4ea 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"
@@ -3017,6 +3019,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 edcc0282b2..899e1ad73b 100644
--- a/src/backend/utils/misc/postgresql.conf.sample
+++ b/src/backend/utils/misc/postgresql.conf.sample
@@ -584,6 +584,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