diff --git a/core/modules/simpletest/src/Tests/KernelTestBaseTest.php b/core/modules/simpletest/src/Tests/KernelTestBaseTest.php
index 4c8343f..c777fed 100644
--- a/core/modules/simpletest/src/Tests/KernelTestBaseTest.php
+++ b/core/modules/simpletest/src/Tests/KernelTestBaseTest.php
@@ -68,6 +68,13 @@ function testSetUp() {
 
     // Verify that the settings.testing.php got taken into account.
     $this->assertTrue(function_exists('simpletest_test_stub_settings_function'));
+
+    // Ensure that the database tasks have been run during set up.
+    $database = $this->container->get('database');
+    if ($database->driver() == 'pgsql') {
+      $this->assertEqual('on', $database->query("SHOW standard_conforming_strings")->fetchField());
+      $this->assertEqual('escape', $database->query("SHOW bytea_output")->fetchField());
+    }
   }
 
   /**
diff --git a/core/modules/system/src/Tests/Database/SchemaTest.php b/core/modules/system/src/Tests/Database/SchemaTest.php
index fb5a1c2..e6aea74 100644
--- a/core/modules/system/src/Tests/Database/SchemaTest.php
+++ b/core/modules/system/src/Tests/Database/SchemaTest.php
@@ -640,7 +640,7 @@ protected function assertFieldCharacteristics($table_name, $field_name, $field_s
   }
 
   /**
-   * Tests changing columns between numeric types.
+   * Tests changing columns between types.
    */
   function testSchemaChangeField() {
     $field_specs = array(
@@ -661,6 +661,27 @@ function testSchemaChangeField() {
         $this->assertFieldChange($old_spec, $new_spec);
       }
     }
+
+    $field_specs = array(
+      array('type' => 'varchar_ascii', 'length' => '255'),
+      array('type' => 'varchar', 'length' => '255'),
+      array('type' => 'text'),
+      array('type' => 'blob', 'size' => 'big'),
+    );
+
+    foreach ($field_specs as $i => $old_spec) {
+      foreach ($field_specs as $j => $new_spec) {
+        if ($i === $j) {
+          // Do not change a field into itself.
+          continue;
+        }
+        // Note if the serialized data contained an object this would fail on
+        // Postgres.
+        // @see https://www.drupal.org/node/1031122
+        $this->assertFieldChange($old_spec, $new_spec, serialize(['string' => "This \n has \\\\ some backslash \"*string action.\\n"]));
+      }
+    }
+
   }
 
   /**
@@ -671,7 +692,7 @@ function testSchemaChangeField() {
    * @param $new_spec
    *   The ending field specification.
    */
-  protected function assertFieldChange($old_spec, $new_spec) {
+  protected function assertFieldChange($old_spec, $new_spec, $test_data = NULL) {
     $table_name = 'test_table_' . ($this->counter++);
     $table_spec = array(
       'fields' => array(
@@ -689,9 +710,24 @@ protected function assertFieldChange($old_spec, $new_spec) {
     // Remove inserted rows.
     db_truncate($table_name)->execute();
 
+    if ($test_data) {
+      $id = db_insert($table_name)
+        ->fields(['test_field'], [$test_data])
+        ->execute();
+    }
+
     // Change the field.
     db_change_field($table_name, 'test_field', 'test_field', $new_spec);
 
+    if ($test_data) {
+      $field_value = db_select($table_name)
+        ->fields($table_name, ['test_field'])
+        ->condition('serial_column', $id)
+        ->execute()
+        ->fetchField();
+      $this->assertIdentical($field_value, $test_data);
+    }
+
     // Check the field was changed.
     $this->assertFieldCharacteristics($table_name, 'test_field', $new_spec);
 
diff --git a/core/modules/system/src/Tests/Update/UpdatePathTestBaseTest.php b/core/modules/system/src/Tests/Update/UpdatePathTestBaseTest.php
index 65e0b21..df21db4 100644
--- a/core/modules/system/src/Tests/Update/UpdatePathTestBaseTest.php
+++ b/core/modules/system/src/Tests/Update/UpdatePathTestBaseTest.php
@@ -44,6 +44,13 @@ public function testDatabaseLoaded() {
     $this->assertEqual(\Drupal::config('system.site')->get('name'), 'Site-Install');
     $this->drupalGet('<front>');
     $this->assertText('Site-Install');
+
+    // Ensure that the database tasks have been run during set up.
+    $database = $this->container->get('database');
+    if ($database->driver() == 'pgsql') {
+      $this->assertEqual('on', $database->query("SHOW standard_conforming_strings")->fetchField());
+      $this->assertEqual('escape', $database->query("SHOW bytea_output")->fetchField());
+    }
   }
 
   /**
diff --git a/core/tests/Drupal/KernelTests/KernelTestBaseTest.php b/core/tests/Drupal/KernelTests/KernelTestBaseTest.php
index bb798fe..f76d047 100644
--- a/core/tests/Drupal/KernelTests/KernelTestBaseTest.php
+++ b/core/tests/Drupal/KernelTests/KernelTestBaseTest.php
@@ -74,8 +74,8 @@ public function testSetUp() {
     $GLOBALS['destroy-me'] = TRUE;
     $this->assertArrayHasKey('destroy-me', $GLOBALS);
 
-    $schema = $this->container->get('database')->schema();
-    $schema->createTable('foo', array(
+    $database = $this->container->get('database');
+    $database->schema()->createTable('foo', array(
       'fields' => array(
         'number' => array(
           'type' => 'int',
@@ -84,7 +84,13 @@ public function testSetUp() {
         ),
       ),
     ));
-    $this->assertTrue($schema->tableExists('foo'));
+    $this->assertTrue($database->schema()->tableExists('foo'));
+
+    // Ensure that the database tasks have been run during set up.
+    if ($database->driver() == 'pgsql') {
+      $this->assertEquals('on', $database->query("SHOW standard_conforming_strings")->fetchField());
+      $this->assertEquals('escape', $database->query("SHOW bytea_output")->fetchField());
+    }
   }
 
   /**
