diff --git a/core/modules/views/src/Plugin/views/relationship/RelationshipPluginBase.php b/core/modules/views/src/Plugin/views/relationship/RelationshipPluginBase.php
index 05d675509b..daf5581bd5 100644
--- a/core/modules/views/src/Plugin/views/relationship/RelationshipPluginBase.php
+++ b/core/modules/views/src/Plugin/views/relationship/RelationshipPluginBase.php
@@ -158,7 +158,7 @@ public function query() {
     $join = Views::pluginManager('join')->createInstance($id, $def);
 
     // use a short alias for this:
-    $alias = $def['table'] . '_' . $this->table;
+    $alias = $this->shortenTableAlias($def['table'] . '_' . $this->table);
 
     $this->alias = $this->query->addRelationship($alias, $join, $this->definition['base'], $this->relationship);
 
@@ -180,6 +180,32 @@ public function calculateDependencies() {
     return $dependencies;
   }
 
+   /**
+    * Shorten table name to avoid pgsql error on long alias names.
+    *
+    * @param string $table_name
+    *   Table name.
+    *
+    * @return string
+    */
+   private function shortenTableAlias(string $table_name) {
+     $new_alias = '';
+     foreach (explode('_', $table_name) as $word) {
+       if (strlen($word) < 1) {
+         continue;
+       }
+
+       if (strlen($word) < 4) {
+         $new_alias .= $word;
+         continue;
+       }
+
+       $new_alias .= sprintf('%s%s', substr($word, 0, 2), substr($word, -2));
+     }
+
+     return !empty($new_alias) ? $new_alias : $table_name;
+   }
+
 }
 
 /**
