diff --git a/src/backend/utils/misc/ps_status.c b/src/backend/utils/misc/ps_status.c
index 5d829e6e483..b4ed2b1a365 100644
--- a/src/backend/utils/misc/ps_status.c
+++ b/src/backend/utils/misc/ps_status.c
@@ -151,7 +151,37 @@ save_ps_display_args(int argc, char **argv)
 		for (i = 0; environ[i] != NULL; i++)
 		{
 			if (end_of_area + 1 == environ[i])
-				end_of_area = environ[i] + strlen(environ[i]);
+			{
+
+#if defined(__linux__) && (! defined(__GLIBC__) && ! defined(__UCLIBC__ ))
+				/*
+				 * The musl runtime linker stores pointers to variable
+				 * values which are defined in the process's environment.
+				 * Therefore, in these cases we cannot overwrite such
+				 * variable values when setting the process title or dynamic
+				 * linking (dlopen) might fail.  Here, we truncate the update
+				 * of the process title when either of two important dynamic
+				 * linking environment variables are set.  Musl does not
+				 * define any compiler symbols, so we have to do this for
+				 * any Linux libc we don't know is safe.
+				 */
+				if (strstr(environ[i], "LD_LIBRARY_PATH=") == environ[i] ||
+					strstr(environ[i], "LD_PRELOAD=") == environ[i])
+				{
+					/*
+					 * We can overwrite the name, but stop at the equals sign.
+					 * Future loops will not find contiguous space, but we
+					 * don't break early because we want to count the total
+					 * number.
+					 */
+					end_of_area = strchr(environ[i], '=');
+				}
+				else
+#endif
+				{
+					end_of_area = environ[i] + strlen(environ[i]);
+				}
+			}
 		}
 
 		ps_buffer = argv[0];
