Force READ WRITE transaction while running pg_rewind
authorPavan Deolasee <[email protected]>
Fri, 26 Oct 2018 10:24:27 +0000 (15:54 +0530)
committerPavan Deolasee <[email protected]>
Fri, 26 Oct 2018 10:24:27 +0000 (15:54 +0530)
Since direct connections to a datanode by default use read-only transactions,
we need to explicitly set transaction as read write so that temporary tables
can be created and written to.

Report and patch by Virendra Kumar.

src/bin/pg_rewind/libpq_fetch.c

index 89d7886fd1733a75cdf0e0cd358457fd060afd94..0125ec1709e286a1eda1c6945ddd748831b06bbb 100644 (file)
@@ -458,8 +458,11 @@ libpq_executeFileMap(filemap_t *map)
        /*
         * First create a temporary table, and load it with the blocks that we
         * need to fetch.
+        *
+        * Since Postgres-XL defaults to read-only transactions when connected to
+        * the datanodes directly, we must overwrite that explicitly.
         */
-       sql = "CREATE TEMPORARY TABLE fetchchunks(path text, begin int8, len int4);";
+       sql = "BEGIN TRANSACTION READ WRITE; CREATE TEMPORARY TABLE fetchchunks(path text, begin int8, len int4); COMMIT";
        res = PQexec(conn, sql);
 
        if (PQresultStatus(res) != PGRES_COMMAND_OK)
@@ -467,7 +470,7 @@ libpq_executeFileMap(filemap_t *map)
                                 PQresultErrorMessage(res));
        PQclear(res);
 
-       sql = "COPY fetchchunks FROM STDIN";
+       sql = "BEGIN TRANSACTION READ WRITE; COPY fetchchunks FROM STDIN; COMMIT";
        res = PQexec(conn, sql);
 
        if (PQresultStatus(res) != PGRES_COPY_IN)