@@ -113,7 +113,8 @@ wait_command_completion(PGconn* conn)
113
113
Datum
114
114
broadcast (PG_FUNCTION_ARGS )
115
115
{
116
- char * sql = text_to_cstring (PG_GETARG_TEXT_PP (0 ));
116
+ char * sql_full = text_to_cstring (PG_GETARG_TEXT_PP (0 ));
117
+ char * sql = pstrdup (sql_full );
117
118
bool ignore_errors = PG_GETARG_BOOL (1 );
118
119
bool two_phase = PG_GETARG_BOOL (2 );
119
120
bool sync_commit_on = PG_GETARG_BOOL (3 );
@@ -196,6 +197,7 @@ broadcast(PG_FUNCTION_ARGS)
196
197
}
197
198
if (!sync_commit_on )
198
199
{
200
+ /* mem freed with context */
199
201
if (two_phase )
200
202
{
201
203
sql = psprintf ("SET SESSION synchronous_commit TO local; BEGIN; %s; PREPARE TRANSACTION 'shardlord';" , sql );
@@ -220,8 +222,6 @@ broadcast(PG_FUNCTION_ARGS)
220
222
node_id , PQerrorMessage (conn [n_cmds - 1 ]));
221
223
goto cleanup ;
222
224
}
223
- if (!sync_commit_on )
224
- pfree (sql );
225
225
226
226
sql = sep + 1 ;
227
227
}
@@ -249,10 +249,10 @@ broadcast(PG_FUNCTION_ARGS)
249
249
{
250
250
if (ignore_errors )
251
251
{
252
- errmsg = psprintf ("%s%d:Failed to received response for '%s': %s" , errmsg ? errmsg : "" , node_id , sql , PQerrorMessage (conn [i ]));
252
+ errmsg = psprintf ("%s%d:Failed to received response for '%s': %s" , errmsg ? errmsg : "" , node_id , sql_full , PQerrorMessage (conn [i ]));
253
253
continue ;
254
254
}
255
- errmsg = psprintf ("Failed to receive response for query %s from node %d: %s" , sql , node_id , PQerrorMessage (conn [i ]));
255
+ errmsg = psprintf ("Failed to receive response for query %s from node %d: %s" , sql_full , node_id , PQerrorMessage (conn [i ]));
256
256
goto cleanup ;
257
257
}
258
258
@@ -262,11 +262,11 @@ broadcast(PG_FUNCTION_ARGS)
262
262
{
263
263
if (ignore_errors )
264
264
{
265
- errmsg = psprintf ("%s%d:Command %s failed: %s" , errmsg ? errmsg : "" , node_id , sql , PQerrorMessage (conn [i ]));
265
+ errmsg = psprintf ("%s%d:Command %s failed: %s" , errmsg ? errmsg : "" , node_id , sql_full , PQerrorMessage (conn [i ]));
266
266
PQclear (res );
267
267
continue ;
268
268
}
269
- errmsg = psprintf ("Command %s failed at node %d: %s" , sql , node_id , PQerrorMessage (conn [i ]));
269
+ errmsg = psprintf ("Command %s failed at node %d: %s" , sql_full , node_id , PQerrorMessage (conn [i ]));
270
270
PQclear (res );
271
271
goto cleanup ;
272
272
}
@@ -277,11 +277,11 @@ broadcast(PG_FUNCTION_ARGS)
277
277
if (ignore_errors )
278
278
{
279
279
appendStringInfoString (& resp , "?;" );
280
- elog (WARNING , "SHARDMAN: Query '%s' doesn't return single tuple at node %d" , sql , node_id );
280
+ elog (WARNING , "SHARDMAN: Query '%s' doesn't return single tuple at node %d" , sql_full , node_id );
281
281
}
282
282
else
283
283
{
284
- errmsg = psprintf ("Query '%s' doesn't return single tuple at node %d" , sql , node_id );
284
+ errmsg = psprintf ("Query '%s' doesn't return single tuple at node %d" , sql_full , node_id );
285
285
PQclear (res );
286
286
goto cleanup ;
287
287
}
@@ -384,7 +384,7 @@ gen_create_table_sql(PG_FUNCTION_ARGS)
384
384
join_path_components (pg_dump_path , pg_dump_path , "pg_dump" );
385
385
canonicalize_path (pg_dump_path );
386
386
387
- cmd = psprintf ("%s -t '%s' --schema-only --dbname='%s' 2>&1" ,
387
+ cmd = psprintf ("%s -t '%s' --no-owner -- schema-only --dbname='%s' 2>&1" ,
388
388
pg_dump_path , relation , shardlord_connstring );
389
389
390
390
if ((fp = popen (cmd , "r" )) == NULL )
0 commit comments