diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2003-09-10 20:24:09 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2003-09-10 20:24:09 +0000 |
commit | 9cb4a28f471eed8095b49f40607b340550532254 (patch) | |
tree | b1bec490b5217a8a8808b0bfaafb2c368eab59ea /src/backend/commands/dbcommands.c | |
parent | 2b56a9646a36c5df63a05ea22392a653bf3170cc (diff) | |
download | postgresql-9cb4a28f471eed8095b49f40607b340550532254.tar.gz postgresql-9cb4a28f471eed8095b49f40607b340550532254.zip |
Improve error message for cp or rm failur during create/drop database,
per recent discussions.
Diffstat (limited to 'src/backend/commands/dbcommands.c')
-rw-r--r-- | src/backend/commands/dbcommands.c | 40 |
1 files changed, 31 insertions, 9 deletions
diff --git a/src/backend/commands/dbcommands.c b/src/backend/commands/dbcommands.c index 8a7db766455..3227e300d28 100644 --- a/src/backend/commands/dbcommands.c +++ b/src/backend/commands/dbcommands.c @@ -9,7 +9,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/commands/dbcommands.c,v 1.121 2003/08/04 02:39:58 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/commands/dbcommands.c,v 1.122 2003/09/10 20:24:09 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -354,19 +354,40 @@ createdb(const CreatedbStmt *stmt) nominal_loc, alt_loc))); } - /* Copy the template database to the new location */ + /* + * Copy the template database to the new location + * + * XXX use of cp really makes this code pretty grotty, particularly + * with respect to lack of ability to report errors well. Someday + * rewrite to do it for ourselves. + */ #ifndef WIN32 snprintf(buf, sizeof(buf), "cp -r '%s' '%s'", src_loc, target_dir); if (system(buf) != 0) -#else + { + if (remove_dbdirs(nominal_loc, alt_loc)) + ereport(ERROR, + (errmsg("could not initialize database directory"), + errdetail("Failing system command was: %s", buf), + errhint("Look in the postmaster's stderr log for more information."))); + else + ereport(ERROR, + (errmsg("could not initialize database directory; delete failed as well"), + errdetail("Failing system command was: %s", buf), + errhint("Look in the postmaster's stderr log for more information."))); + } +#else /* WIN32 */ if (copydir(src_loc, target_dir) != 0) -#endif { + /* copydir should already have given details of its troubles */ if (remove_dbdirs(nominal_loc, alt_loc)) - elog(ERROR, "could not initialize database directory"); + ereport(ERROR, + (errmsg("could not initialize database directory"))); else - elog(ERROR, "could not initialize database directory; delete failed as well"); + ereport(ERROR, + (errmsg("could not initialize database directory; delete failed as well"))); } +#endif /* WIN32 */ /* * Now OK to grab exclusive lock on pg_database. @@ -935,9 +956,10 @@ remove_dbdirs(const char *nominal_loc, const char *alt_loc) if (system(buf) != 0) { ereport(WARNING, - (errcode_for_file_access(), - errmsg("could not remove database directory \"%s\": %m", - target_dir))); + (errmsg("could not remove database directory \"%s\"", + target_dir), + errdetail("Failing system command was: %s", buf), + errhint("Look in the postmaster's stderr log for more information."))); success = false; } |