<!--
-$PostgreSQL: pgsql/doc/src/sgml/ref/psql-ref.sgml,v 1.144 2005/06/13 06:36:22 neilc Exp $
+$PostgreSQL: pgsql/doc/src/sgml/ref/psql-ref.sgml,v 1.145 2005/06/14 02:57:38 momjian Exp $
PostgreSQL documentation
-->
</listitem>
</varlistentry>
+ <varlistentry>
+ <term><option>-L <replaceable class="parameter">filename</replaceable></></term>
+ <term><option>--log <replaceable class="parameter">filename</replaceable></></term>
+ <listitem>
+ <para>
+ Log all query output into file <replaceable
+ class="parameter">filename</replaceable> in addition to the regular output source.
+ </para>
+ </listitem>
+ </varlistentry>
+
<varlistentry>
<term><option>-o <replaceable class="parameter">filename</replaceable></></term>
<term><option>--output <replaceable class="parameter">filename</replaceable></></term>
*
* Copyright (c) 2000-2005, PostgreSQL Global Development Group
*
- * $PostgreSQL: pgsql/src/bin/psql/common.c,v 1.101 2005/06/13 06:36:22 neilc Exp $
+ * $PostgreSQL: pgsql/src/bin/psql/common.c,v 1.102 2005/06/14 02:57:41 momjian Exp $
*/
#include "postgres_fe.h"
#include "common.h"
"%s\n"
"**************************\n\n", query);
fflush(stdout);
+ if (pset.logfile)
+ {
+ fprintf(pset.logfile, "********* QUERY **********\n"
+ "%s\n"
+ "**************************\n\n", query);
+ fflush(pset.logfile);
+ }
if (echo_hidden == 1) /* noexec? */
return NULL;
return false;
}
- printQuery(results, &my_popt, pset.queryFout);
+ printQuery(results, &my_popt, pset.queryFout, pset.logfile);
/* close file/pipe, restore old setting */
setQFout(NULL);
pset.gfname = NULL;
}
else
- printQuery(results, &my_popt, pset.queryFout);
+ printQuery(results, &my_popt, pset.queryFout, pset.logfile);
return true;
}
else
fprintf(pset.queryFout, "%s\n", PQcmdStatus(results));
}
+ if (pset.logfile)
+ fprintf(pset.logfile, "%s\n", PQcmdStatus(results));
SetVariable(pset.vars, "LASTOID", buf);
break;
}
fflush(stdout);
}
+ if (pset.logfile)
+ {
+ fprintf(pset.logfile, "********* QUERY **********\n"
+ "%s\n"
+ "**************************\n\n", query);
+ fflush(pset.logfile);
+ }
+
SetCancelConn();
transaction_status = PQtransactionStatus(pset.db);
*
* Copyright (c) 2000-2005, PostgreSQL Global Development Group
*
- * $PostgreSQL: pgsql/src/bin/psql/describe.c,v 1.115 2005/04/06 05:23:32 neilc Exp $
+ * $PostgreSQL: pgsql/src/bin/psql/describe.c,v 1.116 2005/06/14 02:57:41 momjian Exp $
*/
#include "postgres_fe.h"
#include "describe.h"
myopt.nullPrint = NULL;
myopt.title = _("List of aggregate functions");
- printQuery(res, &myopt, pset.queryFout);
+ printQuery(res, &myopt, pset.queryFout, pset.logfile);
PQclear(res);
return true;
myopt.nullPrint = NULL;
myopt.title = _("List of tablespaces");
- printQuery(res, &myopt, pset.queryFout);
+ printQuery(res, &myopt, pset.queryFout, pset.logfile);
PQclear(res);
return true;
myopt.nullPrint = NULL;
myopt.title = _("List of functions");
- printQuery(res, &myopt, pset.queryFout);
+ printQuery(res, &myopt, pset.queryFout, pset.logfile);
PQclear(res);
return true;
myopt.nullPrint = NULL;
myopt.title = _("List of data types");
- printQuery(res, &myopt, pset.queryFout);
+ printQuery(res, &myopt, pset.queryFout, pset.logfile);
PQclear(res);
return true;
myopt.nullPrint = NULL;
myopt.title = _("List of operators");
- printQuery(res, &myopt, pset.queryFout);
+ printQuery(res, &myopt, pset.queryFout, pset.logfile);
PQclear(res);
return true;
myopt.nullPrint = NULL;
myopt.title = _("List of databases");
- printQuery(res, &myopt, pset.queryFout);
+ printQuery(res, &myopt, pset.queryFout, pset.logfile);
PQclear(res);
return true;
printfPQExpBuffer(&buf, _("Access privileges for database \"%s\""), PQdb(pset.db));
myopt.title = buf.data;
- printQuery(res, &myopt, pset.queryFout);
+ printQuery(res, &myopt, pset.queryFout, pset.logfile);
termPQExpBuffer(&buf);
PQclear(res);
myopt.nullPrint = NULL;
myopt.title = _("Object descriptions");
- printQuery(res, &myopt, pset.queryFout);
+ printQuery(res, &myopt, pset.queryFout, pset.logfile);
PQclear(res);
return true;
printTable(title.data, headers,
(const char **) cells, (const char **) footers,
- "llll", &myopt, pset.queryFout);
+ "llll", &myopt, pset.queryFout, pset.logfile);
retval = true;
myopt.nullPrint = NULL;
myopt.title = _("List of users");
- printQuery(res, &myopt, pset.queryFout);
+ printQuery(res, &myopt, pset.queryFout, pset.logfile);
PQclear(res);
return true;
myopt.nullPrint = NULL;
myopt.title = _("List of groups");
- printQuery(res, &myopt, pset.queryFout);
+ printQuery(res, &myopt, pset.queryFout, pset.logfile);
PQclear(res);
return true;
myopt.nullPrint = NULL;
myopt.title = _("List of relations");
- printQuery(res, &myopt, pset.queryFout);
+ printQuery(res, &myopt, pset.queryFout, pset.logfile);
}
PQclear(res);
myopt.nullPrint = NULL;
myopt.title = _("List of domains");
- printQuery(res, &myopt, pset.queryFout);
+ printQuery(res, &myopt, pset.queryFout, pset.logfile);
PQclear(res);
return true;
myopt.nullPrint = NULL;
myopt.title = _("List of conversions");
- printQuery(res, &myopt, pset.queryFout);
+ printQuery(res, &myopt, pset.queryFout, pset.logfile);
PQclear(res);
return true;
myopt.nullPrint = NULL;
myopt.title = _("List of casts");
- printQuery(res, &myopt, pset.queryFout);
+ printQuery(res, &myopt, pset.queryFout, pset.logfile);
PQclear(res);
return true;
myopt.nullPrint = NULL;
myopt.title = _("List of schemas");
- printQuery(res, &myopt, pset.queryFout);
+ printQuery(res, &myopt, pset.queryFout, pset.logfile);
PQclear(res);
return true;
*
* Copyright (c) 2000-2005, PostgreSQL Global Development Group
*
- * $PostgreSQL: pgsql/src/bin/psql/help.c,v 1.101 2005/02/22 04:40:55 momjian Exp $
+ * $PostgreSQL: pgsql/src/bin/psql/help.c,v 1.102 2005/06/14 02:57:41 momjian Exp $
*/
#include "postgres_fe.h"
#include "common.h"
user = getenv("PGUSER");
if (!user)
{
-#ifndef WIN32
+#if !defined(WIN32) && !defined(__OS2__)
pw = getpwuid(geteuid());
if (pw)
user = pw->pw_name;
puts(_(" -n disable enhanced command line editing (readline)"));
puts(_(" -s single-step mode (confirm each query)"));
puts(_(" -S single-line mode (end of line terminates SQL command)"));
+ puts(_(" -L FILENAME send session log to file"));
puts(_("\nOutput format options:"));
puts(_(" -A unaligned table output mode (-P format=unaligned)"));
*
* Copyright (c) 2000-2005, PostgreSQL Global Development Group
*
- * $PostgreSQL: pgsql/src/bin/psql/large_obj.c,v 1.36 2005/02/22 04:40:55 momjian Exp $
+ * $PostgreSQL: pgsql/src/bin/psql/large_obj.c,v 1.37 2005/06/14 02:57:41 momjian Exp $
*/
#include "postgres_fe.h"
#include "large_obj.h"
myopt.nullPrint = NULL;
myopt.title = _("Large objects");
- printQuery(res, &myopt, pset.queryFout);
+ printQuery(res, &myopt, pset.queryFout, pset.logfile);
PQclear(res);
return true;
*
* Copyright (c) 2000-2005, PostgreSQL Global Development Group
*
- * $PostgreSQL: pgsql/src/bin/psql/print.c,v 1.58 2005/06/13 06:36:22 neilc Exp $
+ * $PostgreSQL: pgsql/src/bin/psql/print.c,v 1.59 2005/06/14 02:57:41 momjian Exp $
*/
#include "postgres_fe.h"
#include "common.h"
const char *const * cells,
const char *const * footers,
const char *align,
- const printTableOpt *opt, FILE *fout)
+ const printTableOpt *opt, FILE *fout, FILE *flog)
{
const char *default_footer[] = {NULL};
unsigned short int border = opt->border;
/* print the stuff */
+ if (flog)
+ print_aligned_text(title, headers, cells, footers, align, opt->tuples_only, border, opt->encoding, flog);
+
switch (opt->format)
{
case PRINT_UNALIGNED:
void
-printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout)
+printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, FILE *flog)
{
int nfields;
int ncells;
/* call table printer */
printTable(opt->title, headers, cells,
(const char *const *) footers,
- align, &opt->topt, fout);
+ align, &opt->topt, fout, flog);
free(headers);
free(cells);
*
* Copyright (c) 2000-2005, PostgreSQL Global Development Group
*
- * $PostgreSQL: pgsql/src/bin/psql/print.h,v 1.24 2005/06/13 06:36:22 neilc Exp $
+ * $PostgreSQL: pgsql/src/bin/psql/print.h,v 1.25 2005/06/14 02:57:41 momjian Exp $
*/
#ifndef PRINT_H
#define PRINT_H
void printTable(const char *title, const char *const * headers,
const char *const * cells, const char *const * footers,
const char *align,
- const printTableOpt *opt, FILE *fout);
+ const printTableOpt *opt, FILE *fout, FILE *flog);
*
* It calls the printTable above with all the things set straight.
*/
-void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout);
+void printQuery(const PGresult *result, const printQueryOpt *opt,
+ FILE *fout, FILE *flog);
#ifndef __CYGWIN__
#define DEFAULT_PAGER "more"
*
* Copyright (c) 2000-2005, PostgreSQL Global Development Group
*
- * $PostgreSQL: pgsql/src/bin/psql/settings.h,v 1.24 2005/06/09 23:28:10 momjian Exp $
+ * $PostgreSQL: pgsql/src/bin/psql/settings.h,v 1.25 2005/06/14 02:57:41 momjian Exp $
*/
#ifndef SETTINGS_H
#define SETTINGS_H
bool timing; /* enable timing of all queries */
PGVerbosity verbosity; /* current error verbosity level */
+ FILE *logfile; /* session log file handle */
} PsqlSettings;
extern PsqlSettings pset;
*
* Copyright (c) 2000-2005, PostgreSQL Global Development Group
*
- * $PostgreSQL: pgsql/src/bin/psql/startup.c,v 1.116 2005/06/13 06:36:22 neilc Exp $
+ * $PostgreSQL: pgsql/src/bin/psql/startup.c,v 1.117 2005/06/14 02:57:41 momjian Exp $
*/
#include "postgres_fe.h"
char *host;
char *port;
char *username;
+ char *logfilename;
enum _actions action;
char *action_string;
bool no_readline;
set_pglocale_pgservice(argv[0], "psql");
- pset.progname = get_progname(argv[0]);
-
if (argc > 1)
{
if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
}
}
+ pset.progname = get_progname(argv[0]);
+
#ifdef WIN32
setvbuf(stderr, NULL, _IONBF, 0);
setup_win32_locks();
exit(success ? EXIT_SUCCESS : EXIT_FAILURE);
}
+ if (options.logfilename)
+ {
+ pset.logfile = fopen(options.logfilename, "a");
+ if (!pset.logfile)
+ fprintf(stderr, gettext("logfile open failed for %s\n\n"), options.logfilename);
+ }
+
/*
* Now find something to do
*/
}
/* clean up */
+ if (pset.logfile)
+ fclose(pset.logfile);
PQfinish(pset.db);
setQFout(NULL);
{"host", required_argument, NULL, 'h'},
{"html", no_argument, NULL, 'H'},
{"list", no_argument, NULL, 'l'},
+ {"log", required_argument, NULL, 'L'},
{"no-readline", no_argument, NULL, 'n'},
{"output", required_argument, NULL, 'o'},
{"port", required_argument, NULL, 'p'},
memset(options, 0, sizeof *options);
- while ((c = getopt_long(argc, argv, "aAc:d:eEf:F:h:Hlno:p:P:qR:sStT:uU:v:VWxX?",
+ while ((c = getopt_long(argc, argv, "aAc:d:eEf:F:h:HlL:no:p:P:qR:sStT:uU:v:VWxX?",
long_options, &optindex)) != -1)
{
switch (c)
case 'l':
options->action = ACT_LIST_DB;
break;
+ case 'L':
+ options->logfilename = optarg;
+ break;
case 'n':
options->no_readline = true;
break;
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/bin/scripts/createlang.c,v 1.15 2004/12/31 22:03:17 pgsql Exp $
+ * $PostgreSQL: pgsql/src/bin/scripts/createlang.c,v 1.16 2005/06/14 02:57:45 momjian Exp $
*
*-------------------------------------------------------------------------
*/
popt.topt.border = 1;
popt.topt.encoding = PQclientEncoding(conn);
popt.title = _("Procedural Languages");
- printQuery(result, &popt, stdout);
+ printQuery(result, &popt, stdout, NULL);
PQfinish(conn);
exit(0);
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/bin/scripts/droplang.c,v 1.14 2004/12/31 22:03:17 pgsql Exp $
+ * $PostgreSQL: pgsql/src/bin/scripts/droplang.c,v 1.15 2005/06/14 02:57:45 momjian Exp $
*
*-------------------------------------------------------------------------
*/
popt.topt.border = 1;
popt.topt.encoding = PQclientEncoding(conn);
popt.title = _("Procedural Languages");
- printQuery(result, &popt, stdout);
+ printQuery(result, &popt, stdout, NULL);
PQfinish(conn);
exit(0);