diff --git a/core/lib/Drupal/Core/Database/Driver/pgsql/Insert.php b/core/lib/Drupal/Core/Database/Driver/pgsql/Insert.php
index 9c2c448..fba74da 100644
--- a/core/lib/Drupal/Core/Database/Driver/pgsql/Insert.php
+++ b/core/lib/Drupal/Core/Database/Driver/pgsql/Insert.php
@@ -58,6 +58,10 @@ public function execute() {
             if ($index == 0) {
               $last_insert_id = $serial_value;
             }
+            // Sequences must be greater than or equal to 1.
+            if ($serial_value === NULL || !$serial_value) {
+              $serial_value = 1;
+            }
             // Set the sequence to the bigger value of either the passed
             // value or the max value of the column. It can happen that another
             // thread calls nextval() which could lead to a serial number being
diff --git a/core/lib/Drupal/Core/Entity/ContentEntityDatabaseStorage.php b/core/lib/Drupal/Core/Entity/ContentEntityDatabaseStorage.php
index 6f246f7..8ec74a9 100644
--- a/core/lib/Drupal/Core/Entity/ContentEntityDatabaseStorage.php
+++ b/core/lib/Drupal/Core/Entity/ContentEntityDatabaseStorage.php
@@ -720,9 +720,9 @@ protected function doSave($id, EntityInterface $entity) {
         ->fields((array) $record)
         ->execute();
       // Even if this is a new entity the ID key might have been set, in which
-      // case we should not override the provided ID. An empty value for the
-      // ID is interpreted as NULL and thus overridden.
-      if (empty($record->{$this->idKey})) {
+      // case we should not override the provided ID. An ID key that is not set
+      // to any value is interpreted as NULL (or DEFAULT) and thus overridden.
+      if (!isset($record->{$this->idKey})) {
         $record->{$this->idKey} = $insert_id;
       }
       $return = SAVED_NEW;
@@ -850,7 +850,14 @@ protected function mapToStorageRecord(ContentEntityInterface $entity, $table_nam
         if (!empty($definition->getSchema()['columns'][$column_name]['serialize'])) {
           $value = serialize($value);
         }
-        $record->$schema_name = drupal_schema_get_field_value($definition->getSchema()['columns'][$column_name], $value);
+
+        // Do not set serial fields if we do not have a value. This supports all
+        // SQL database drivers.
+        // @see https://www.drupal.org/node/2279395
+        $value = drupal_schema_get_field_value($definition->getSchema()['columns'][$column_name], $value);
+        if (!(empty($value) && $this->getSchema()[$table_name]['fields'][$field_name]['type'] == 'serial')) {
+          $record->$schema_name = $value;
+        }
       }
     }
 
