8
8
* @brief Client Modules
9
9
*/
10
10
11
- const char * PROGRAM_VERSION = "1.0.4 " ;
11
+ const char * PROGRAM_VERSION = "1.0.5 " ;
12
12
const char * PROGRAM_URL = "http://reorg.projects.postgresql.org/" ;
13
13
const char * PROGRAM_EMAIL = "reorg-general@lists.pgfoundry.org" ;
14
14
@@ -92,9 +92,9 @@ static bool sqlstate_equals(PGresult *res, const char *state)
92
92
return strcmp (PQresultErrorField (res , PG_DIAG_SQLSTATE ), state ) == 0 ;
93
93
}
94
94
95
- static bool echo = false;
96
95
static bool verbose = false;
97
96
static bool quiet = false;
97
+ static bool analyze = true;
98
98
99
99
/*
100
100
* The table begin re-organized. If not null, we need to cleanup temp
@@ -110,16 +110,14 @@ utoa(unsigned int value, char *buffer)
110
110
return buffer ;
111
111
}
112
112
113
- const char * pgut_optstring = "eqvat:no:" ;
114
-
115
- const struct option pgut_longopts [] = {
116
- {"echo" , no_argument , NULL , 'e' },
113
+ const struct option pgut_options [] = {
117
114
{"quiet" , no_argument , NULL , 'q' },
118
115
{"verbose" , no_argument , NULL , 'v' },
119
116
{"all" , no_argument , NULL , 'a' },
120
117
{"table" , required_argument , NULL , 't' },
121
118
{"no-order" , no_argument , NULL , 'n' },
122
119
{"order-by" , required_argument , NULL , 'o' },
120
+ {"no-analyze" , no_argument , NULL , 'Z' },
123
121
{NULL , 0 , NULL , 0 }
124
122
};
125
123
@@ -132,9 +130,6 @@ pgut_argument(int c, const char *arg)
132
130
{
133
131
switch (c )
134
132
{
135
- case 'e' :
136
- echo = true;
137
- break ;
138
133
case 'q' :
139
134
quiet = true;
140
135
break ;
@@ -153,6 +148,9 @@ pgut_argument(int c, const char *arg)
153
148
case 'o' :
154
149
assign_option (& orderby , c , arg );
155
150
break ;
151
+ case 'Z' :
152
+ analyze = false;
153
+ break ;
156
154
default :
157
155
return false;
158
156
}
@@ -249,9 +247,9 @@ reorg_one_database(const char *orderby, const char *table)
249
247
PGresult * res ;
250
248
int i ;
251
249
int num ;
252
- PQExpBufferData sql ;
250
+ StringInfoData sql ;
253
251
254
- initPQExpBuffer (& sql );
252
+ initStringInfo (& sql );
255
253
256
254
reconnect ();
257
255
@@ -262,18 +260,18 @@ reorg_one_database(const char *orderby, const char *table)
262
260
command ("SET client_min_messages = warning" , 0 , NULL );
263
261
264
262
/* acquire target tables */
265
- appendPQExpBufferStr (& sql , "SELECT * FROM reorg.tables WHERE " );
263
+ appendStringInfoString (& sql , "SELECT * FROM reorg.tables WHERE " );
266
264
if (table )
267
265
{
268
- appendPQExpBufferStr (& sql , "relid = $1::regclass" );
269
- res = execute_nothrow (sql .data , 1 , & table );
266
+ appendStringInfoString (& sql , "relid = $1::regclass" );
267
+ res = execute_elevel (sql .data , 1 , & table , LOG );
270
268
}
271
269
else
272
270
{
273
- appendPQExpBufferStr (& sql , "pkid IS NOT NULL" );
271
+ appendStringInfoString (& sql , "pkid IS NOT NULL" );
274
272
if (!orderby )
275
- appendPQExpBufferStr (& sql , " AND ckid IS NOT NULL" );
276
- res = execute_nothrow (sql .data , 0 , NULL );
273
+ appendStringInfoString (& sql , " AND ckid IS NOT NULL" );
274
+ res = execute_elevel (sql .data , 0 , NULL , LOG );
277
275
}
278
276
279
277
if (PQresultStatus (res ) != PGRES_TUPLES_OK )
@@ -321,13 +319,13 @@ reorg_one_database(const char *orderby, const char *table)
321
319
table .lock_table = getstr (res , i , c ++ );
322
320
ckey = getstr (res , i , c ++ );
323
321
324
- resetPQExpBuffer (& sql );
322
+ resetStringInfo (& sql );
325
323
if (!orderby )
326
324
{
327
325
/* CLUSTER mode */
328
326
if (ckey == NULL )
329
327
elog (ERROR , "relation \"%s\" has no cluster key" , table .target_name );
330
- appendPQExpBuffer (& sql , "%s ORDER BY %s" , create_table , ckey );
328
+ appendStringInfo (& sql , "%s ORDER BY %s" , create_table , ckey );
331
329
table .create_table = sql .data ;
332
330
}
333
331
else if (!orderby [0 ])
@@ -338,7 +336,7 @@ reorg_one_database(const char *orderby, const char *table)
338
336
else
339
337
{
340
338
/* User specified ORDER BY */
341
- appendPQExpBuffer (& sql , "%s ORDER BY %s" , create_table , orderby );
339
+ appendStringInfo (& sql , "%s ORDER BY %s" , create_table , orderby );
342
340
table .create_table = sql .data ;
343
341
}
344
342
@@ -354,7 +352,7 @@ reorg_one_database(const char *orderby, const char *table)
354
352
cleanup :
355
353
PQclear (res );
356
354
disconnect ();
357
- termPQExpBuffer (& sql );
355
+ termStringInfo (& sql );
358
356
return ret ;
359
357
}
360
358
@@ -387,12 +385,15 @@ apply_log(const reorg_table *table, int count)
387
385
static void
388
386
reorg_one_table (const reorg_table * table , const char * orderby )
389
387
{
390
- PGresult * res ;
391
- const char * params [1 ];
392
- int num ;
393
- int i ;
394
- char * vxid ;
395
- char buffer [12 ];
388
+ PGresult * res ;
389
+ const char * params [1 ];
390
+ int num ;
391
+ int i ;
392
+ char * vxid ;
393
+ char buffer [12 ];
394
+ StringInfoData sql ;
395
+
396
+ initStringInfo (& sql );
396
397
397
398
if (verbose )
398
399
{
@@ -430,16 +431,16 @@ reorg_one_table(const reorg_table *table, const char *orderby)
430
431
*/
431
432
params [0 ] = utoa (table -> target_oid , buffer );
432
433
433
- res = execute (
434
- "SELECT 1 FROM pg_trigger"
435
- " WHERE tgrelid = $1 AND tgname >= 'z_reorg_trigger' LIMIT 1" ,
436
- 1 , params );
434
+ res = execute ("SELECT reorg.conflicted_triggers($1)" , 1 , params );
437
435
if (PQntuples (res ) > 0 )
438
- elog (ERROR , "trigger conflicted for %s" , table -> target_name );
436
+ elog (ERROR , "trigger %s conflicted for %s" ,
437
+ PQgetvalue (res , 0 , 0 ), table -> target_name );
439
438
440
439
command (table -> create_pktype , 0 , NULL );
441
440
command (table -> create_log , 0 , NULL );
442
441
command (table -> create_trigger , 0 , NULL );
442
+ printfStringInfo (& sql , "SELECT reorg.disable_autovacuum('reorg.log_%u')" , table -> target_oid );
443
+ command (sql .data , 0 , NULL );
443
444
command ("COMMIT" , 0 , NULL );
444
445
445
446
/*
@@ -465,6 +466,8 @@ reorg_one_table(const reorg_table *table, const char *orderby)
465
466
PQclear (res );
466
467
command (table -> delete_log , 0 , NULL );
467
468
command (table -> create_table , 0 , NULL );
469
+ printfStringInfo (& sql , "SELECT reorg.disable_autovacuum('reorg.table_%u')" , table -> target_oid );
470
+ command (sql .data , 0 , NULL );
468
471
command ("COMMIT" , 0 , NULL );
469
472
470
473
/*
@@ -537,7 +540,7 @@ reorg_one_table(const reorg_table *table, const char *orderby)
537
540
for (;;)
538
541
{
539
542
command ("BEGIN ISOLATION LEVEL READ COMMITTED" , 0 , NULL );
540
- res = execute_nothrow (table -> lock_table , 0 , NULL );
543
+ res = execute_elevel (table -> lock_table , 0 , NULL , NOTICE );
541
544
if (PQresultStatus (res ) == PGRES_COMMAND_OK )
542
545
{
543
546
PQclear (res );
@@ -577,8 +580,23 @@ reorg_one_table(const reorg_table *table, const char *orderby)
577
580
command ("COMMIT" , 0 , NULL );
578
581
579
582
current_table = NULL ;
580
-
581
583
free (vxid );
584
+
585
+ /*
586
+ * 7. Analyze.
587
+ * Note that current_table is already set to NULL here because analyze
588
+ * is an unimportant operation; No clean up even if failed.
589
+ */
590
+ if (verbose )
591
+ fprintf (stderr , "---- analyze ----\n" );
592
+
593
+ command ("BEGIN ISOLATION LEVEL READ COMMITTED" , 0 , NULL );
594
+ printfStringInfo (& sql , "ANALYZE %s%s" ,
595
+ (verbose ? "VERBOSE " : "" ), table -> target_name );
596
+ command (sql .data , 0 , NULL );
597
+ command ("COMMIT" , 0 , NULL );
598
+
599
+ termStringInfo (& sql );
582
600
}
583
601
584
602
void
@@ -624,7 +642,7 @@ pgut_help(void)
624
642
" -t, --table=TABLE reorg specific table only\n"
625
643
" -n, --no-order do vacuum full instead of cluster\n"
626
644
" -o, --order-by=columns order by columns instead of cluster keys\n"
627
- " -e , --echo show the commands being sent to the server \n"
645
+ " -Z , --no-analyze don't analyze at end \n"
628
646
" -q, --quiet don't write any messages\n"
629
647
" -v, --verbose display detailed information during processing\n" ,
630
648
PROGRAM_NAME , PROGRAM_NAME );
0 commit comments