* This is a C implementation of the previous shell script for setting up a
* PostgreSQL cluster location, and should be highly compatible with it.
*
- * $Header: /cvsroot/pgsql/src/bin/initdb/initdb.c,v 1.3 2003/11/13 01:09:24 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/bin/initdb/initdb.c,v 1.4 2003/11/13 01:36:00 tgl Exp $
*
* TODO:
* - clean up find_postgres code and return values
if ((infile = fopen(path, "r")) == NULL)
{
- fprintf(stderr, "could not read %s ... ", path);
+ fprintf(stderr, "could not read %s\n", path);
exit_nicely();
}
;
if ((out_file = fopen(path, PG_BINARY_W)) == NULL)
{
- fprintf(stderr, "could not write %s ... ", path);
+ fprintf(stderr, "could not write %s\n", path);
exit_nicely();
}
for (line = lines; *line != NULL; line++)
int i,
status;
+ printf("selecting default max_connections ... ");
+ fflush(stdout);
+
for (i = 0; i < len; i++)
{
snprintf(cmd, sizeof(cmd), format,
if (i >= len)
i = len - 1;
n_connections = conns[i];
- printf("connections set to %d\n", n_connections);
+
+ printf("%d\n", n_connections);
}
/*
int i,
status;
+ printf("selecting default shared_buffers ... ");
+ fflush(stdout);
+
for (i = 0; i < len; i++)
{
snprintf(cmd, sizeof(cmd), format, pgpath, bufs[i], n_connections,
if (i >= len)
i = len - 1;
n_buffers = bufs[i];
- printf("buffers set to %d\n", n_buffers);
+
+ printf("%d\n", n_buffers);
}
/*
char path[MAXPGPATH];
fputs("creating configuration files ... ", stdout);
+ fflush(stdout);
/* postgresql.conf */
PG_CMD_DECL;
printf("creating template1 database in %s/base/1 ... ", pg_data);
+ fflush(stdout);
if (debug)
talkargs = "-d 5";
PG_CMD_DECL;
fputs("initializing pg_shadow ... ", stdout);
+ fflush(stdout);
snprintf(cmd, MAXPGPATH,
"\"%s/postgres\" -F -O -c search_path=pg_catalog "
free(pwd2);
printf("storing the password ... ");
+ fflush(stdout);
snprintf(cmd, MAXPGPATH,
"\"%s/postgres\" -F -O -c search_path=pg_catalog "
"-c exit_on_error=true template1 >%s", pgpath, DEVNULL);
-
PG_CMD_OPEN;
- if (fprintf(
- pg, "ALTER USER \"%s\" WITH PASSWORD '%s';\n", username, pwd1) < 0)
+ if (fprintf(pg,
+ "ALTER USER \"%s\" WITH PASSWORD '%s';\n", username, pwd1) < 0)
{
/* write failure */
exit_nicely();
PG_CMD_DECL;
fputs("enabling unlimited row size for system tables ... ", stdout);
+ fflush(stdout);
snprintf(cmd, MAXPGPATH,
"\"%s/postgres\" -F -O -c search_path=pg_catalog "
PG_CMD_DECL;
fputs("initializing pg_depend ... ", stdout);
+ fflush(stdout);
snprintf(cmd, MAXPGPATH,
"\"%s/postgres\" -F -O -c search_path=pg_catalog "
char **sysviews_setup;
fputs("creating system views ... ", stdout);
+ fflush(stdout);
sysviews_setup = readfile(system_views_file);
char **desc_lines;
fputs("loading pg_description ... ", stdout);
+ fflush(stdout);
snprintf(cmd, MAXPGPATH,
"\"%s/postgres\" -F -O -c search_path=pg_catalog "
char **conv_lines;
fputs("creating conversions ... ", stdout);
+ fflush(stdout);
snprintf(cmd, MAXPGPATH,
"\"%s/postgres\" -F -O -c search_path=pg_catalog "
char **priv_lines;
- fputs("setting privileges on builtin objects ... ", stdout);
+ fputs("setting privileges on built-in objects ... ", stdout);
+ fflush(stdout);
snprintf(cmd, MAXPGPATH,
"\"%s/postgres\" -F -O -c search_path=pg_catalog "
int fres;
fputs("creating information schema ... ", stdout);
+ fflush(stdout);
lines = readfile(info_schema_file);
PG_CMD_DECL_NOLINE;
fputs("vacuuming database template1 ... ", stdout);
+ fflush(stdout);
snprintf(cmd, MAXPGPATH,
"\"%s/postgres\" -F -O -c search_path=pg_catalog "
PG_CMD_DECL;
fputs("copying template1 to template0 ... ", stdout);
+ fflush(stdout);
snprintf(cmd, MAXPGPATH,
"\"%s/postgres\" -F -O -c search_path=pg_catalog "
strcmp(lc_ctype, lc_monetary) == 0 &&
strcmp(lc_ctype, lc_messages) == 0)
{
- printf("The database cluster will be initialized with locale %s\n",
+ printf("The database cluster will be initialized with locale %s.\n\n",
lc_ctype);
}
else
" MESSAGES: %s\n"
" MONETARY: %s\n"
" NUMERIC: %s\n"
- " TIME: %s\n",
+ " TIME: %s\n\n",
lc_collate,
lc_ctype,
lc_messages,
*/
if (errno == ENOENT)
{
- printf("creating directory \"%s\" ... ", pg_data);
+ printf("creating directory %s ... ", pg_data);
+ fflush(stdout);
if (!mkdatadir(NULL))
exit_nicely();
for (i = 0; i < (sizeof(subdirs) / sizeof(char *)); i++)
{
printf("creating directory %s/%s ... ", pg_data, subdirs[i]);
+ fflush(stdout);
if (!mkdatadir(subdirs[i]))
exit_nicely();