diff --git a/lib/private/db/migrator.php b/lib/private/db/migrator.php
index 6443cf4ed48a14d47e0092450c2e8cded9ab74f7..d05f8455551faead79c2189e03c33aa7550fd4a7 100644
--- a/lib/private/db/migrator.php
+++ b/lib/private/db/migrator.php
@@ -110,7 +110,9 @@ class Migrator {
 			$this->dropTable($tmpName);
 		} catch (DBALException $e) {
 			// pgsql needs to commit it's failed transaction before doing anything else
-			$this->connection->commit();
+			if ($this->connection->isTransactionActive()) {
+				$this->connection->commit();
+			}
 			$this->dropTable($tmpName);
 			throw new MigrationException($table->getName(), $e->getMessage());
 		}