diff --git a/src/bin/psql/prompt.c b/src/bin/psql/prompt.c
index 195192a95d..eb8953aec0 100644
--- a/src/bin/psql/prompt.c
+++ b/src/bin/psql/prompt.c
@@ -39,6 +39,7 @@
  * %n - database user name
  * %/ - current database
  * %~ - like %/ but "~" when database name equals user name
+ * %w - whitespace of the same width as the current database
  * %# - "#" if superuser, ">" otherwise
  * %R - in prompt1 normally =, or ^ if single line mode,
  *			or a ! if session is not connected to a database;
@@ -123,6 +124,14 @@ get_prompt(promptStatus_t status, ConditionalStack cstack)
 							strlcpy(buf, PQdb(pset.db), sizeof(buf));
 					}
 					break;
+				case 'w':
+					if (pset.db)
+					{
+						size_t		len = strlen(PQdb(pset.db));
+
+						memset(buf, ' ', Min(len, sizeof(buf) - 1));
+					}
+					break;
 
 					/* DB server hostname (long/short) */
 				case 'M':
