diff --git a/src/backend/bootstrap/bootparse.y b/src/backend/bootstrap/bootparse.y index eb9ebc046b..1e4f1ace65 100644 --- a/src/backend/bootstrap/bootparse.y +++ b/src/backend/bootstrap/bootparse.y @@ -9,15 +9,15 @@ * * * 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" @@ -50,17 +50,31 @@ #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; %} @@ -71,12 +85,14 @@ 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 @@ -114,42 +130,49 @@ Boot_Query : 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) { @@ -158,17 +181,15 @@ Boot_CreateStmt: 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 { @@ -181,70 +202,65 @@ Boot_CreateStmt: 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(); } ; @@ -280,10 +296,8 @@ boot_type_thing: 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"); } ; @@ -299,10 +313,10 @@ boot_tuplelist: ; 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 : diff --git a/src/backend/bootstrap/bootscanner.l b/src/backend/bootstrap/bootscanner.l index dc1ac46819..992b970116 100644 --- a/src/backend/bootstrap/bootscanner.l +++ b/src/backend/bootstrap/bootscanner.l @@ -9,14 +9,14 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/bootstrap/bootscanner.l,v 1.19 2001/01/24 19:42:51 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/bootstrap/bootscanner.l,v 1.20 2001/05/12 01:48:49 petere Exp $ * *------------------------------------------------------------------------- */ -#include - #include "postgres.h" +#include + #include "access/attnum.h" #include "access/htup.h" #include "access/itup.h" @@ -122,7 +122,7 @@ insert { return(INSERT_TUPLE); } } . { - printf("syntax error %d : -> %s\n", yyline, yytext); + elog(ERROR, "syntax error at line %d: unexpected character %s", yyline, yytext); } @@ -138,5 +138,5 @@ yywrap(void) void yyerror(const char *str) { - fprintf(stderr,"\tsyntax error %d : %s",yyline, str); + elog(ERROR, "syntax error at line %d: unexpected token %s", yyline, str); } diff --git a/src/backend/bootstrap/bootstrap.c b/src/backend/bootstrap/bootstrap.c index aeb90c1ffa..c6ca5e081d 100644 --- a/src/backend/bootstrap/bootstrap.c +++ b/src/backend/bootstrap/bootstrap.c @@ -8,7 +8,7 @@ * 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 $ * *------------------------------------------------------------------------- */ @@ -185,13 +185,11 @@ err_out(void) 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); } @@ -240,8 +238,6 @@ BootstrapMain(int argc, char *argv[]) */ /* Set defaults, to be overriden by explicit options below */ - Quiet = false; - Noversion = false; dbName = NULL; if (!IsUnderPostmaster) { @@ -250,7 +246,7 @@ BootstrapMain(int argc, char *argv[]) * variable */ } - while ((flag = getopt(argc, argv, "D:dCQx:pB:F")) != EOF) + while ((flag = getopt(argc, argv, "B:dD:Fpx:")) != EOF) { switch (flag) { @@ -261,15 +257,9 @@ BootstrapMain(int argc, char *argv[]) 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; @@ -285,21 +275,12 @@ BootstrapMain(int argc, char *argv[]) } } /* 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) { @@ -493,9 +474,9 @@ boot_openrel(char *relname) 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; @@ -523,11 +504,10 @@ boot_openrel(char *relname) { 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); } } } @@ -554,11 +534,11 @@ closerel(char *name) } 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; } @@ -582,7 +562,7 @@ DefineAttr(char *name, char *type, int attnum) 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); } @@ -593,8 +573,8 @@ DefineAttr(char *name, char *type, int attnum) { 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; @@ -605,8 +585,8 @@ DefineAttr(char *name, char *type, int attnum) { 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'; @@ -654,10 +634,7 @@ InsertOneTuple(Oid objectid) 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); @@ -668,10 +645,7 @@ InsertOneTuple(Oid objectid) 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 @@ -691,30 +665,25 @@ InsertOneValue(Oid objectid, char *value, int i) 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), @@ -724,8 +693,8 @@ InsertOneValue(Oid objectid, char *value, int i) values[i], ObjectIdGetDatum(ap->am_typ.typelem), Int32GetDatum(-1))); - if (!Quiet) - printf("%s ", prt); + if (DebugMode) + elog(DEBUG, " -> %s", prt); pfree(prt); } else @@ -736,9 +705,9 @@ InsertOneValue(Oid objectid, char *value, int i) 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), @@ -747,15 +716,12 @@ InsertOneValue(Oid objectid, char *value, int i) 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"); } /* ---------------- @@ -766,9 +732,8 @@ void 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'; } @@ -855,7 +820,7 @@ gettype(char *type) 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; diff --git a/src/backend/utils/init/globals.c b/src/backend/utils/init/globals.c index 2a1a0aaaae..b20d7d0ab6 100644 --- a/src/backend/utils/init/globals.c +++ b/src/backend/utils/init/globals.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/init/globals.c,v 1.55 2001/03/22 03:59:59 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/init/globals.c,v 1.56 2001/05/12 01:48:49 petere Exp $ * * NOTES * Globals used all over the place should be declared here and not @@ -33,7 +33,6 @@ ProtocolVersion FrontendProtocol = PG_PROTOCOL_LATEST; bool Noversion = false; -bool Quiet = false; volatile bool InterruptPending = false; volatile bool QueryCancelPending = false; diff --git a/src/bin/initdb/initdb.sh b/src/bin/initdb/initdb.sh index b00a4bf571..de81152e24 100644 --- a/src/bin/initdb/initdb.sh +++ b/src/bin/initdb/initdb.sh @@ -23,7 +23,7 @@ # Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group # Portions Copyright (c) 1994, Regents of the University of California # -# $Header: /cvsroot/pgsql/src/bin/initdb/Attic/initdb.sh,v 1.124 2001/05/08 16:28:46 momjian Exp $ +# $Header: /cvsroot/pgsql/src/bin/initdb/Attic/initdb.sh,v 1.125 2001/05/12 01:48:49 petere Exp $ # #------------------------------------------------------------------------- @@ -453,12 +453,10 @@ mkdir "$PGDATA"/base/1 || exit_nicely if [ "$debug" = yes ] then BACKEND_TALK_ARG="-d" -else - BACKEND_TALK_ARG="-Q" fi -BACKENDARGS="-boot -C -F -D$PGDATA $BACKEND_TALK_ARG" -FIRSTRUN="-boot -x1 -C -F -D$PGDATA $BACKEND_TALK_ARG" +BACKENDARGS="-boot -F -D$PGDATA $BACKEND_TALK_ARG" +FIRSTRUN="-boot -x1 -F -D$PGDATA $BACKEND_TALK_ARG" echo "Creating template1 database in $PGDATA/base/1" [ "$debug" = yes ] && echo "Running: $PGPATH/postgres $FIRSTRUN template1" diff --git a/src/include/bootstrap/bootstrap.h b/src/include/bootstrap/bootstrap.h index 16faa4f405..5c3ebbcaae 100644 --- a/src/include/bootstrap/bootstrap.h +++ b/src/include/bootstrap/bootstrap.h @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $Id: bootstrap.h,v 1.21 2001/01/24 19:43:20 momjian Exp $ + * $Id: bootstrap.h,v 1.22 2001/05/12 01:48:49 petere Exp $ * *------------------------------------------------------------------------- */ @@ -18,8 +18,9 @@ #include "nodes/execnodes.h" #include "utils/rel.h" -/* MAXATTR is the maximum number of attributes in a relation supported - * at bootstrap time (ie, the max possible in a system table). +/* + * MAXATTR is the maximum number of attributes in a relation supported + * at bootstrap time (i.e., the max possible in a system table). */ #define MAXATTR 40 @@ -29,7 +30,6 @@ typedef struct hashnode struct hashnode *next; } hashnode; -#define EMITPROMPT printf("> ") extern Relation reldesc; extern Form_pg_attribute attrtypes[MAXATTR]; diff --git a/src/include/miscadmin.h b/src/include/miscadmin.h index e69fba4b87..742f58137c 100644 --- a/src/include/miscadmin.h +++ b/src/include/miscadmin.h @@ -12,7 +12,7 @@ * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $Id: miscadmin.h,v 1.84 2001/05/08 21:06:43 petere Exp $ + * $Id: miscadmin.h,v 1.85 2001/05/12 01:48:49 petere Exp $ * * NOTES * some of the information in this file should be moved to @@ -113,7 +113,6 @@ extern int PostmasterMain(int argc, char *argv[]); * from utils/init/globals.c */ extern bool Noversion; -extern bool Quiet; extern char *DataDir; extern int MyProcPid;