*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/bootstrap/bootparse.y,v 1.35 2001/01/24 19:42:51 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/bootstrap/bootparse.y,v 1.36 2001/05/12 01:48:49 petere Exp $
*
*-------------------------------------------------------------------------
*/
-#include
-
#include "postgres.h"
+#include
+#include
#include "access/attnum.h"
#include "access/htup.h"
#include "utils/nabstime.h"
#include "utils/rel.h"
-#define DO_START { \
- StartTransactionCommand();\
- }
-#define DO_END { \
- CommitTransactionCommand();\
- if (!Quiet) { EMITPROMPT; }\
- fflush(stdout); \
- }
+static void
+do_start()
+{
+ StartTransactionCommand();
+ if (DebugMode)
+ elog(DEBUG, "start transaction");
+}
+
-int num_tuples_read = 0;
+static void
+do_end()
+{
+ CommitTransactionCommand();
+ if (DebugMode)
+ elog(DEBUG, "commit transaction");
+ if (isatty(0))
+ {
+ printf("bootstrap> ");
+ fflush(stdout);
+ }
+}
+
+
+int num_columns_read = 0;
static Oid objectid;
%}
IndexElem *ielem;
char *str;
int ival;
+ Oid oidval;
}
%type boot_index_params
%type boot_index_param
%type boot_const boot_ident
-%type optbootstrap optoideq boot_tuple boot_tuplelist
+%type optbootstrap boot_tuple boot_tuplelist
+%type optoideq
%token CONST ID
%token OPEN XCLOSE XCREATE INSERT_TUPLE
Boot_OpenStmt:
OPEN boot_ident
{
- DO_START;
+ do_start();
boot_openrel(LexIDStr($2));
- DO_END;
+ do_end();
}
;
Boot_CloseStmt:
XCLOSE boot_ident %prec low
{
- DO_START;
+ do_start();
closerel(LexIDStr($2));
- DO_END;
+ do_end();
}
| XCLOSE %prec high
{
- DO_START;
+ do_start();
closerel(NULL);
- DO_END;
+ do_end();
}
;
Boot_CreateStmt:
XCREATE optbootstrap boot_ident LPAREN
{
- DO_START;
- numattr=(int)0;
+ do_start();
+ numattr = 0;
+ if (DebugMode)
+ {
+ if ($2)
+ elog(DEBUG, "creating bootstrap relation %s...",
+ LexIDStr($3));
+ else
+ elog(DEBUG, "creating relation %s...",
+ LexIDStr($3));
+ }
}
boot_typelist
{
- if (!Quiet)
- putchar('\n');
- DO_END;
+ do_end();
}
RPAREN
{
- DO_START;
+ do_start();
if ($2)
{
if (reldesc)
{
- puts("create bootstrap: Warning, open relation");
- puts("exists, closing first");
+ elog(DEBUG, "create bootstrap: warning, open relation exists, closing first");
closerel(NULL);
}
- if (DebugMode)
- puts("creating bootstrap relation");
+
tupdesc = CreateTupleDesc(numattr,attrtypes);
reldesc = heap_create(LexIDStr($3), tupdesc,
false, true, true);
if (DebugMode)
- puts("bootstrap relation created ok");
+ elog(DEBUG, "bootstrap relation created");
}
else
{
RELKIND_RELATION,
false,
true);
- if (!Quiet)
- printf("CREATED relation %s with OID %u\n",
- LexIDStr($3), id);
+ if (DebugMode)
+ elog(DEBUG, "relation created with oid %u", id);
}
- DO_END;
- if (DebugMode)
- puts("Commit End");
+ do_end();
}
;
Boot_InsertStmt:
INSERT_TUPLE optoideq
{
- DO_START;
+ do_start();
if (DebugMode)
- printf("tuple %d<", $2);
- num_tuples_read = 0;
+ {
+ if ($2)
+ elog(DEBUG, "inserting row with oid %u...", $2);
+ else
+ elog(DEBUG, "inserting row...");
+ }
+ num_columns_read = 0;
}
LPAREN boot_tuplelist RPAREN
{
- if (num_tuples_read != numattr)
- elog(ERROR,"incorrect number of values for tuple");
+ if (num_columns_read != numattr)
+ elog(ERROR, "incorrect number of columns in row (expected %d, got %d)",
+ numattr, num_columns_read);
if (reldesc == (Relation)NULL)
{
- elog(ERROR,"must OPEN RELATION before INSERT\n");
+ elog(ERROR, "relation not open");
err_out();
}
- if (DebugMode)
- puts("Insert Begin");
objectid = $2;
InsertOneTuple(objectid);
- if (DebugMode)
- puts("Insert End");
- if (!Quiet)
- putchar('\n');
- DO_END;
- if (DebugMode)
- puts("Transaction End");
+ do_end();
}
;
Boot_DeclareIndexStmt:
XDECLARE INDEX boot_ident ON boot_ident USING boot_ident LPAREN boot_index_params RPAREN
{
- DO_START;
+ do_start();
DefineIndex(LexIDStr($5),
LexIDStr($3),
LexIDStr($7),
$9, NIL, 0, 0, 0, NIL);
- DO_END;
+ do_end();
}
;
Boot_DeclareUniqueIndexStmt:
XDECLARE UNIQUE INDEX boot_ident ON boot_ident USING boot_ident LPAREN boot_index_params RPAREN
{
- DO_START;
+ do_start();
DefineIndex(LexIDStr($6),
LexIDStr($4),
LexIDStr($8),
$10, NIL, 1, 0, 0, NIL);
- DO_END;
+ do_end();
}
;
boot_ident EQUALS boot_ident
{
if(++numattr > MAXATTR)
- elog(FATAL,"Too many attributes\n");
+ elog(FATAL, "too many columns");
DefineAttr(LexIDStr($1),LexIDStr($3),numattr-1);
- if (DebugMode)
- printf("\n");
}
;
;
boot_tuple:
- boot_ident {InsertOneValue(objectid, LexIDStr($1), num_tuples_read++); }
- | boot_const {InsertOneValue(objectid, LexIDStr($1), num_tuples_read++); }
+ boot_ident {InsertOneValue(objectid, LexIDStr($1), num_columns_read++); }
+ | boot_const {InsertOneValue(objectid, LexIDStr($1), num_columns_read++); }
| NULLVAL
- { InsertOneNull(num_tuples_read++); }
+ { InsertOneNull(num_columns_read++); }
;
boot_const :
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/bootstrap/bootstrap.c,v 1.106 2001/03/22 06:16:10 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/bootstrap/bootstrap.c,v 1.107 2001/05/12 01:48:49 petere Exp $
*
*-------------------------------------------------------------------------
*/
static void
usage(void)
{
- fprintf(stderr, "Usage: postgres -boot [-d] [-C] [-F] [-O] [-Q] ");
- fprintf(stderr, "[-P portno] [dbName]\n");
- fprintf(stderr, " d: debug mode\n");
- fprintf(stderr, " C: disable version checking\n");
- fprintf(stderr, " F: turn off fsync\n");
- fprintf(stderr, " O: set BootstrapProcessing mode\n");
- fprintf(stderr, " P portno: specify port number\n");
+ fprintf(stderr, "Usage:\n postgres -boot [-d] [-D datadir] [-F] [-x num] dbname\n");
+ fprintf(stderr, " -d debug mode\n");
+ fprintf(stderr, " -D datadir data directory\n");
+ fprintf(stderr, " -F turn off fsync\n");
+ fprintf(stderr, " -x num internal use\n");
proc_exit(1);
}
*/
/* Set defaults, to be overriden by explicit options below */
- Quiet = false;
- Noversion = false;
dbName = NULL;
if (!IsUnderPostmaster)
{
* variable */
}
- while ((flag = getopt(argc, argv, "D:dCQx:pB:F")) != EOF)
+ while ((flag = getopt(argc, argv, "B:dD:Fpx:")) != EOF)
{
switch (flag)
{
DebugMode = true; /* print out debugging info while
* parsing */
break;
- case 'C':
- Noversion = true;
- break;
case 'F':
enableFsync = false;
break;
- case 'Q':
- Quiet = true;
- break;
case 'x':
xlogop = atoi(optarg);
break;
}
} /* while */
- if (argc - optind > 1)
+ if (argc - optind != 1)
usage();
- else if (argc - optind == 1)
- dbName = argv[optind];
- if (dbName == NULL)
- {
- dbName = getenv("USER");
- if (dbName == NULL)
- {
- fputs("bootstrap backend: failed, no db name specified\n", stderr);
- fputs(" and no USER enviroment variable\n", stderr);
- proc_exit(1);
- }
- }
+ dbName = argv[optind];
+
+ Assert(dbName);
if (!IsUnderPostmaster)
{
if (reldesc != NULL)
closerel(NULL);
- if (!Quiet)
- printf("Amopen: relation %s. attrsize %d\n", relname ? relname : "(null)",
- (int) ATTRIBUTE_TUPLE_SIZE);
+ if (DebugMode)
+ elog(DEBUG, "open relation %s, attrsize %d", relname ? relname : "(null)",
+ (int) ATTRIBUTE_TUPLE_SIZE);
reldesc = heap_openr(relname, NoLock);
numattr = reldesc->rd_rel->relnatts;
{
Form_pg_attribute at = attrtypes[i];
- printf("create attribute %d name %s len %d num %d type %d\n",
- i, NameStr(at->attname), at->attlen, at->attnum,
- at->atttypid
+ elog(DEBUG, "create attribute %d name %s len %d num %d type %u",
+ i, NameStr(at->attname), at->attlen, at->attnum,
+ at->atttypid
);
- fflush(stdout);
}
}
}
}
if (reldesc == NULL)
- elog(ERROR, "Warning: no opened relation to close.\n");
+ elog(ERROR, "no open relation to close");
else
{
- if (!Quiet)
- printf("Amclose: relation %s.\n", relname ? relname : "(null)");
+ if (DebugMode)
+ elog(DEBUG, "close relation %s", relname ? relname : "(null)");
heap_close(reldesc, NoLock);
reldesc = (Relation) NULL;
}
if (reldesc != NULL)
{
- fputs("Warning: no open relations allowed with 't' command.\n", stderr);
+ elog(DEBUG, "warning: no open relations allowed with 'create' command");
closerel(relname);
}
{
attrtypes[attnum]->atttypid = Ap->am_oid;
namestrcpy(&attrtypes[attnum]->attname, name);
- if (!Quiet)
- printf("<%s %s> ", NameStr(attrtypes[attnum]->attname), type);
+ if (DebugMode)
+ elog(DEBUG, "column %s %s", NameStr(attrtypes[attnum]->attname), type);
attrtypes[attnum]->attnum = 1 + attnum; /* fillatt */
attlen = attrtypes[attnum]->attlen = Ap->am_typ.typlen;
attrtypes[attnum]->attbyval = Ap->am_typ.typbyval;
{
attrtypes[attnum]->atttypid = Procid[typeoid].oid;
namestrcpy(&attrtypes[attnum]->attname, name);
- if (!Quiet)
- printf("<%s %s> ", NameStr(attrtypes[attnum]->attname), type);
+ if (DebugMode)
+ elog(DEBUG, "column %s %s", NameStr(attrtypes[attnum]->attname), type);
attrtypes[attnum]->attnum = 1 + attnum; /* fillatt */
attlen = attrtypes[attnum]->attlen = Procid[typeoid].len;
attrtypes[attnum]->attstorage = 'p';
int i;
if (DebugMode)
- {
- printf("InsertOneTuple oid %u, %d attrs\n", objectid, numattr);
- fflush(stdout);
- }
+ elog(DEBUG, "inserting row oid %u, %d columns", objectid, numattr);
tupDesc = CreateTupleDesc(numattr, attrtypes);
tuple = heap_formtuple(tupDesc, values, Blanks);
heap_insert(reldesc, tuple);
heap_freetuple(tuple);
if (DebugMode)
- {
- printf("End InsertOneTuple, objectid=%u\n", objectid);
- fflush(stdout);
- }
+ elog(DEBUG, "row inserted");
/*
* Reset blanks for next tuple
char *prt;
struct typmap **app;
+ AssertArg(i >= 0 || i < MAXATTR);
+
if (DebugMode)
- printf("Inserting value: '%s'\n", value);
- if (i < 0 || i >= MAXATTR)
- {
- printf("i out of range: %d\n", i);
- Assert(0);
- }
+ elog(DEBUG, "inserting column %d value '%s'", i, value);
if (Typ != (struct typmap **) NULL)
{
struct typmap *ap;
if (DebugMode)
- puts("Typ != NULL");
+ elog(DEBUG, "Typ != NULL");
app = Typ;
while (*app && (*app)->am_oid != reldesc->rd_att->attrs[i]->atttypid)
++app;
ap = *app;
if (ap == NULL)
{
- printf("Unable to find atttypid in Typ list! %u\n",
- reldesc->rd_att->attrs[i]->atttypid
- );
- Assert(0);
+ elog(FATAL, "unable to find atttypid %u in Typ list",
+ reldesc->rd_att->attrs[i]->atttypid);
}
values[i] = OidFunctionCall3(ap->am_typ.typinput,
CStringGetDatum(value),
values[i],
ObjectIdGetDatum(ap->am_typ.typelem),
Int32GetDatum(-1)));
- if (!Quiet)
- printf("%s ", prt);
+ if (DebugMode)
+ elog(DEBUG, " -> %s", prt);
pfree(prt);
}
else
break;
}
if (typeindex >= n_types)
- elog(ERROR, "can't find type OID %u", attrtypes[i]->atttypid);
+ elog(ERROR, "type oid %u not found", attrtypes[i]->atttypid);
if (DebugMode)
- printf("Typ == NULL, typeindex = %u idx = %d\n", typeindex, i);
+ elog(DEBUG, "Typ == NULL, typeindex = %u", typeindex);
values[i] = OidFunctionCall3(Procid[typeindex].inproc,
CStringGetDatum(value),
ObjectIdGetDatum(Procid[typeindex].elem),
values[i],
ObjectIdGetDatum(Procid[typeindex].elem),
Int32GetDatum(-1)));
- if (!Quiet)
- printf("%s ", prt);
+ if (DebugMode)
+ elog(DEBUG, " -> %s", prt);
pfree(prt);
}
if (DebugMode)
- {
- puts("End InsertValue");
- fflush(stdout);
- }
+ elog(DEBUG, "inserted");
}
/* ----------------
InsertOneNull(int i)
{
if (DebugMode)
- printf("Inserting null\n");
- if (i < 0 || i >= MAXATTR)
- elog(FATAL, "i out of range (too many attrs): %d\n", i);
+ elog(DEBUG, "inserting column %d NULL", i);
+ Assert(i >= 0 || i < MAXATTR);
values[i] = PointerGetDatum(NULL);
Blanks[i] = 'n';
}
return i;
}
if (DebugMode)
- printf("bootstrap.c: External Type: %s\n", type);
+ elog(DEBUG, "external type: %s", type);
rel = heap_openr(TypeRelationName, NoLock);
scan = heap_beginscan(rel, 0, SnapshotNow, 0, (ScanKey) NULL);
i = 0;