23
23
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
24
24
* Portions Copyright (c) 1994, Regents of the University of California
25
25
*
26
- * $Header: /cvsroot/pgsql/src/bin/pg_resetxlog/pg_resetxlog.c,v 1.6 2002/10/02 19:45:47 tgl Exp $
26
+ * $Header: /cvsroot/pgsql/src/bin/pg_resetxlog/pg_resetxlog.c,v 1.7 2002/10/02 21:30:13 tgl Exp $
27
27
*
28
28
*-------------------------------------------------------------------------
29
29
*/
@@ -90,8 +90,11 @@ main(int argc, char *argv[])
90
90
bool force = false;
91
91
bool noupdate = false;
92
92
TransactionId set_xid = 0 ;
93
+ Oid set_oid = 0 ;
93
94
uint32 minXlogId = 0 ,
94
95
minXlogSeg = 0 ;
96
+ char * endptr ;
97
+ char * endptr2 ;
95
98
char * DataDir ;
96
99
int fd ;
97
100
char path [MAXPGPATH ];
@@ -122,7 +125,7 @@ main(int argc, char *argv[])
122
125
}
123
126
124
127
125
- while ((c = getopt (argc , argv , "fl:nx :" )) != -1 )
128
+ while ((c = getopt (argc , argv , "fl:no:x :" )) != -1 )
126
129
{
127
130
switch (c )
128
131
{
@@ -135,16 +138,45 @@ main(int argc, char *argv[])
135
138
break ;
136
139
137
140
case 'x' :
138
- set_xid = strtoul (optarg , NULL , 0 );
141
+ set_xid = strtoul (optarg , & endptr , 0 );
142
+ if (endptr == optarg || * endptr != '\0' )
143
+ {
144
+ fprintf (stderr , _ ("%s: invalid argument for -x option\n" ), progname );
145
+ fprintf (stderr , _ ("Try '%s --help' for more information.\n" ), progname );
146
+ exit (1 );
147
+ }
139
148
if (set_xid == 0 )
140
149
{
141
150
fprintf (stderr , _ ("%s: transaction ID (-x) must not be 0\n" ), progname );
142
151
exit (1 );
143
152
}
144
153
break ;
145
154
155
+ case 'o' :
156
+ set_oid = strtoul (optarg , & endptr , 0 );
157
+ if (endptr == optarg || * endptr != '\0' )
158
+ {
159
+ fprintf (stderr , _ ("%s: invalid argument for -o option\n" ), progname );
160
+ fprintf (stderr , _ ("Try '%s --help' for more information.\n" ), progname );
161
+ exit (1 );
162
+ }
163
+ if (set_oid == 0 )
164
+ {
165
+ fprintf (stderr , _ ("%s: OID (-o) must not be 0\n" ), progname );
166
+ exit (1 );
167
+ }
168
+ break ;
169
+
146
170
case 'l' :
147
- if (sscanf (optarg , "%u,%u" , & minXlogId , & minXlogSeg ) != 2 )
171
+ minXlogId = strtoul (optarg , & endptr , 0 );
172
+ if (endptr == optarg || * endptr != ',' )
173
+ {
174
+ fprintf (stderr , _ ("%s: invalid argument for -l option\n" ), progname );
175
+ fprintf (stderr , _ ("Try '%s --help' for more information.\n" ), progname );
176
+ exit (1 );
177
+ }
178
+ minXlogSeg = strtoul (endptr + 1 , & endptr2 , 0 );
179
+ if (endptr2 == endptr + 1 || * endptr2 != '\0' )
148
180
{
149
181
fprintf (stderr , _ ("%s: invalid argument for -l option\n" ), progname );
150
182
fprintf (stderr , _ ("Try '%s --help' for more information.\n" ), progname );
@@ -198,6 +230,24 @@ main(int argc, char *argv[])
198
230
if (!ReadControlFile ())
199
231
GuessControlValues ();
200
232
233
+ /*
234
+ * Adjust fields if required by switches. (Do this now so that
235
+ * printout, if any, includes these values.)
236
+ */
237
+ if (set_xid != 0 )
238
+ ControlFile .checkPointCopy .nextXid = set_xid ;
239
+
240
+ if (set_oid != 0 )
241
+ ControlFile .checkPointCopy .nextOid = set_oid ;
242
+
243
+ if (minXlogId > ControlFile .logId ||
244
+ (minXlogId == ControlFile .logId &&
245
+ minXlogSeg > ControlFile .logSeg ))
246
+ {
247
+ ControlFile .logId = minXlogId ;
248
+ ControlFile .logSeg = minXlogSeg ;
249
+ }
250
+
201
251
/*
202
252
* If we had to guess anything, and -f was not given, just print the
203
253
* guessed values and exit. Also print if -n is given.
@@ -227,19 +277,7 @@ main(int argc, char *argv[])
227
277
228
278
/*
229
279
* Else, do the dirty deed.
230
- *
231
- * First adjust fields if required by switches.
232
280
*/
233
- if (set_xid != 0 )
234
- ControlFile .checkPointCopy .nextXid = set_xid ;
235
-
236
- if (minXlogId > ControlFile .logId ||
237
- (minXlogId == ControlFile .logId && minXlogSeg > ControlFile .logSeg ))
238
- {
239
- ControlFile .logId = minXlogId ;
240
- ControlFile .logSeg = minXlogSeg ;
241
- }
242
-
243
281
RewriteControlFile ();
244
282
KillExistingXLOG ();
245
283
WriteEmptyXLOG ();
@@ -659,6 +697,7 @@ usage(void)
659
697
printf (_ (" -f force update to be done\n" ));
660
698
printf (_ (" -l FILEID,SEG force minimum WAL starting location for new transaction log\n" ));
661
699
printf (_ (" -n no update, just show extracted control values (for testing)\n" ));
700
+ printf (_ (" -o OID set next OID\n" ));
662
701
printf (_ (" -x XID set next transaction ID\n" ));
663
702
printf (_ ("\nReport bugs to <pgsql-bugs@postgresql.org>.\n" ));
664
703
}
0 commit comments