1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-30 11:03:19 +03:00

In pg_upgrade, add various logging improvements:

add ability to control permissions of created files
	have psql echo its queries for easier debugging
	output four separate log files, and delete them on success
	add -r/--retain option to keep log files after success
	make logs file append-only
	remove -g/-G/-l logging options
	sugggest tailing appropriate log file on failure
	enhance -v/--verbose behavior
This commit is contained in:
Bruce Momjian
2012-03-12 19:47:54 -04:00
parent b4af1c25bb
commit 717f6d6085
16 changed files with 257 additions and 234 deletions

View File

@ -35,6 +35,34 @@
#define GLOBALS_DUMP_FILE "pg_upgrade_dump_globals.sql"
#define DB_DUMP_FILE "pg_upgrade_dump_db.sql"
#define SERVER_LOG_FILE "pg_upgrade_server.log"
#define RESTORE_LOG_FILE "pg_upgrade_restore.log"
#define UTILITY_LOG_FILE "pg_upgrade_utility.log"
#define INTERNAL_LOG_FILE "pg_upgrade_internal.log"
#define NUM_LOG_FILES 4
extern char *output_files[];
/*
* WIN32 files do not accept writes from multiple processes
*
* On Win32, we can't send both pg_upgrade output and command output to the
* same file because we get the error: "The process cannot access the file
* because it is being used by another process." so send the pg_ctl
* command-line output to the utility log file on Windows, rather than
* into the server log file.
*
* We could use the Windows pgwin32_open() flags to allow shared file
* writes but is unclear how all other tools would use those flags, so
* we just avoid it and log a little differently on Windows; we adjust
* the error message appropriately.
*/
#ifndef WIN32
#define SERVER_LOG_FILE2 SERVER_LOG_FILE
#else
#define SERVER_LOG_FILE2 UTILITY_LOG_FILE
#endif
#ifndef WIN32
#define pg_copy_file copy_file
#define pg_mv_file rename
@ -166,11 +194,10 @@ typedef enum
*/
typedef enum
{
PG_INFO,
PG_VERBOSE,
PG_REPORT,
PG_WARNING,
PG_FATAL,
PG_DEBUG
PG_FATAL
} eLogType;
@ -204,25 +231,9 @@ typedef struct
*/
typedef struct
{
char *filename; /* name of log file (may be /dev/null) */
/*
* WIN32 files do not accept writes from multiple processes
*
* On Win32, we can't send both pg_upgrade output and command output to the
* same file because we get the error: "The process cannot access the file
* because it is being used by another process." so we have to send all
* other output to 'nul'. Therefore, we set this to DEVNULL on Win32, and
* it equals 'filename' on all other platforms.
*
* We could use the Windows pgwin32_open() flags to allow shared file
* writes but is unclear how all other tools would use those flags, so
* we just avoid it and log a little less on Windows.
*/
char *filename2;
FILE *fd; /* log FILE */
bool debug; /* TRUE -> log more information */
FILE *debug_fd; /* debug-level log FILE */
FILE *internal; /* internal log FILE */
bool verbose; /* TRUE -> be verbose in messages */
bool retain; /* retain log files on success */
} LogOpts;
@ -245,7 +256,6 @@ typedef struct
const char *progname; /* complete pathname for this program */
char *exec_path; /* full path to my executable */
char *user; /* username for clusters */
char cwd[MAXPGPATH]; /* current working directory, used for output */
char **tablespaces; /* tablespaces */
int num_tablespaces;
char **libraries; /* loadable libraries */
@ -294,8 +304,9 @@ void split_old_dump(void);
/* exec.c */
int exec_prog(bool throw_error, const char *cmd, ...)
__attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3)));
int exec_prog(bool throw_error, bool is_priv,
const char *log_file, const char *cmd, ...)
__attribute__((format(PG_PRINTF_ATTRIBUTE, 4, 5)));
void verify_directories(void);
bool is_server_running(const char *datadir);
@ -339,6 +350,7 @@ const char *linkAndUpdateFile(pageCnvCtx *pageConverter, const char *src,
const char *dst);
void check_hard_link(void);
FILE *fopen_priv(const char *path, const char *mode);
/* function.c */