diff --git a/src/common/logging.c b/src/common/logging.c
index d9632fffc8..13913a71ac 100644
--- a/src/common/logging.c
+++ b/src/common/logging.c
@@ -149,6 +149,12 @@ pg_logging_init(const char *argv0)
 			sgr_locus = SGR_LOCUS_DEFAULT;
 		}
 	}
+
+	/*
+	 * isatty() may fail, setting errno to ENOTTY if running for example
+	 * TAP tests that depend on IPC::Run, so reset properly.
+	 */
+	errno = 0;
 }
 
 void
