@@ -126,7 +126,7 @@ static void MtmAddSubtransactions(MtmTransState* ts, TransactionId *subxids, int
126126static void MtmShmemStartup (void );
127127
128128static BgwPool * MtmPoolConstructor (void );
129- static bool MtmRunUtilityStmt (PGconn * conn ,char const * sql );
129+ static bool MtmRunUtilityStmt (PGconn * conn ,char const * sql , char * * errmsg );
130130static void MtmBroadcastUtilityStmt (char const * sql ,bool ignoreError );
131131
132132MtmState * Mtm ;
@@ -1791,14 +1791,24 @@ mtm_get_cluster_state(PG_FUNCTION_ARGS)
17911791/*
17921792 * Execute statement with specified parameters and check its result
17931793 */
1794- static bool MtmRunUtilityStmt (PGconn * conn ,char const * sql )
1794+ static bool MtmRunUtilityStmt (PGconn * conn ,char const * sql , char * * errmsg )
17951795{
17961796PGresult * result = PQexec (conn ,sql );
17971797int status = PQresultStatus (result );
1798+ char * errstr ;
1799+
17981800bool ret = status == PGRES_COMMAND_OK || status == PGRES_TUPLES_OK ;
1799- if (!ret ) {
1800- elog (WARNING ,"Command '%s' failed with status %d" ,sql ,status );
1801+
1802+ if (!ret ) {
1803+ char * errstr = PQresultErrorMessage (result );
1804+ int errlen = strlen (errstr );
1805+
1806+ * errmsg = palloc0 (errlen );
1807+
1808+ /* Strip "ERROR:\t" from beginning and "\n" from end of error string */
1809+ strncpy (* errmsg ,errstr + 7 ,errlen - 1 - 7 );
18011810}
1811+
18021812PQclear (result );
18031813return ret ;
18041814}
@@ -1812,6 +1822,7 @@ static void MtmBroadcastUtilityStmt(char const* sql, bool ignoreError)
18121822int failedNode = -1 ;
18131823char const * errorMsg = NULL ;
18141824PGconn * * conns = palloc0 (sizeof (PGconn * )* MtmNodes );
1825+ char * utility_errmsg ;
18151826
18161827while (conn_str < conn_str_end )
18171828{
@@ -1847,15 +1858,18 @@ static void MtmBroadcastUtilityStmt(char const* sql, bool ignoreError)
18471858{
18481859if (conns [i ])
18491860{
1850- if (!MtmRunUtilityStmt (conns [i ],"BEGIN TRANSACTION" )&& !ignoreError )
1861+ if (!MtmRunUtilityStmt (conns [i ],"BEGIN TRANSACTION" , & utility_errmsg )&& !ignoreError )
18511862{
18521863errorMsg = "Failed to start transaction at node %d" ;
18531864failedNode = i ;
18541865break ;
18551866}
1856- if (!MtmRunUtilityStmt (conns [i ],sql )&& !ignoreError )
1867+ if (!MtmRunUtilityStmt (conns [i ],sql , & utility_errmsg )&& !ignoreError )
18571868{
1858- errorMsg = "Failed to run command at node %d" ;
1869+ // errorMsg = "Failed to run command at node %d";
1870+ // XXX: add check for our node
1871+ errorMsg = utility_errmsg ;
1872+
18591873failedNode = i ;
18601874break ;
18611875}
@@ -1867,13 +1881,13 @@ static void MtmBroadcastUtilityStmt(char const* sql, bool ignoreError)
18671881{
18681882if (conns [i ])
18691883{
1870- MtmRunUtilityStmt (conns [i ],"ROLLBACK TRANSACTION" );
1884+ MtmRunUtilityStmt (conns [i ],"ROLLBACK TRANSACTION" , & utility_errmsg );
18711885}
18721886}
18731887}else {
18741888for (i = 0 ;i < MtmNodes ;i ++ )
18751889{
1876- if (conns [i ]&& !MtmRunUtilityStmt (conns [i ],"COMMIT TRANSACTION" )&& !ignoreError )
1890+ if (conns [i ]&& !MtmRunUtilityStmt (conns [i ],"COMMIT TRANSACTION" , & utility_errmsg )&& !ignoreError )
18771891{
18781892errorMsg = "Commit failed at node %d" ;
18791893failedNode = i ;
@@ -1955,8 +1969,8 @@ static bool MtmTwoPhaseCommit(MtmCurrentTrans* x)
19551969{
19561970if (x -> isDistributed && x -> containsDML ) {
19571971MtmGenerateGid (x -> gid );
1958- if (!IsTransactionBlock () ) {
1959- elog (WARNING ,"Start transaction block for %d " ,x -> xid );
1972+ if (!x -> isTransactionBlock ) {
1973+ /* elog(WARNING, "Start transaction block for %s ", x->gid); */
19601974BeginTransactionBlock ();
19611975CommitTransactionCommand ();
19621976StartTransactionCommand ();
@@ -2048,6 +2062,13 @@ static void MtmProcessUtility(Node *parsetree, const char *queryString,
20482062case T_ReindexStmt :
20492063skipCommand = true;
20502064break ;
2065+ case T_CreateStmt :
2066+ {
2067+ /* Do not replicate temp tables */
2068+ CreateStmt * stmt = (CreateStmt * )parsetree ;
2069+ skipCommand = stmt -> relation -> relpersistence == RELPERSISTENCE_TEMP ;
2070+ }
2071+ break ;
20512072default :
20522073skipCommand = false;
20532074break ;