diff --git a/core/modules/views/src/Plugin/views/relationship/RelationshipPluginBase.php b/core/modules/views/src/Plugin/views/relationship/RelationshipPluginBase.php
index 05d675509b..3afaa1ee8b 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,8 +180,23 @@ 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($table_name) {
 
-/**
- * @}
- */
+    if (strlen($table_name) < 20) {
+      return $table_name;
+    }
+
+    $hash = sha1($table_name);
+
+    return substr($table_name, 0, 3) . '_' . substr($hash, 0, 16);
+  }
+
+}
