Add global psql config file, psql.rc.sample.
This commit is contained in:
parent
4906841901
commit
be6bbcef56
|
@ -1,5 +1,5 @@
|
||||||
<!--
|
<!--
|
||||||
$PostgreSQL: pgsql/doc/src/sgml/ref/psql-ref.sgml,v 1.112 2004/04/21 00:34:18 momjian Exp $
|
$PostgreSQL: pgsql/doc/src/sgml/ref/psql-ref.sgml,v 1.113 2004/04/22 01:53:17 momjian Exp $
|
||||||
PostgreSQL documentation
|
PostgreSQL documentation
|
||||||
-->
|
-->
|
||||||
|
|
||||||
|
@ -440,7 +440,8 @@ PostgreSQL documentation
|
||||||
<term><option>--no-psqlrc</></term>
|
<term><option>--no-psqlrc</></term>
|
||||||
<listitem>
|
<listitem>
|
||||||
<para>
|
<para>
|
||||||
Do not read the start-up file <filename>~/.psqlrc</filename>.
|
Do not read the start-up file <filename>/psql.rc</filename> or
|
||||||
|
<filename>~/.psqlrc</filename>.
|
||||||
</para>
|
</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
@ -1859,8 +1860,9 @@ bar
|
||||||
<para>
|
<para>
|
||||||
The autocommit-on mode is <productname>PostgreSQL</>'s traditional
|
The autocommit-on mode is <productname>PostgreSQL</>'s traditional
|
||||||
behavior, but autocommit-off is closer to the SQL spec. If you
|
behavior, but autocommit-off is closer to the SQL spec. If you
|
||||||
prefer autocommit-off, you may wish to set it in
|
prefer autocommit-off, you may wish to set it in the system-wide
|
||||||
your <filename>.psqlrc</filename> file.
|
<filename>psql.rc</filename> or your
|
||||||
|
<filename>.psqlrc</filename> file.
|
||||||
</para>
|
</para>
|
||||||
</note>
|
</note>
|
||||||
</listitem>
|
</listitem>
|
||||||
|
@ -2488,9 +2490,12 @@ $endif
|
||||||
<listitem>
|
<listitem>
|
||||||
<para>
|
<para>
|
||||||
Before starting up, <application>psql</application> attempts to
|
Before starting up, <application>psql</application> attempts to
|
||||||
read and execute commands from the file
|
read and execute commands from the the system-wide
|
||||||
<filename>$HOME/.psqlrc</filename>. It could be used to set up
|
<filename>psql.rc</filename> file and the
|
||||||
the client or the server to taste (using the <command>\set
|
<filename>$HOME/.psqlrc</filename> file in the user's home
|
||||||
|
directory. See <filename><replaceable>PREFIX</>/share/psql.rc.sample</>
|
||||||
|
for information on setting up the system-wide file. It could be used
|
||||||
|
to set up the client or the server to taste (using the <command>\set
|
||||||
</command> and <command>SET</command> commands).
|
</command> and <command>SET</command> commands).
|
||||||
</para>
|
</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
# Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
|
# Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
|
||||||
# Portions Copyright (c) 1994, Regents of the University of California
|
# Portions Copyright (c) 1994, Regents of the University of California
|
||||||
#
|
#
|
||||||
# $PostgreSQL: pgsql/src/bin/psql/Makefile,v 1.40 2004/03/09 19:47:05 petere Exp $
|
# $PostgreSQL: pgsql/src/bin/psql/Makefile,v 1.41 2004/04/22 01:53:37 momjian Exp $
|
||||||
#
|
#
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ include $(top_builddir)/src/Makefile.global
|
||||||
|
|
||||||
REFDOCDIR= $(top_srcdir)/doc/src/sgml/ref
|
REFDOCDIR= $(top_srcdir)/doc/src/sgml/ref
|
||||||
|
|
||||||
override CPPFLAGS := -I$(libpq_srcdir) $(CPPFLAGS) -DFRONTEND
|
override CPPFLAGS := -I$(libpq_srcdir) $(CPPFLAGS) -DFRONTEND -DSYSCONFDIR='"$(sysconfdir)"'
|
||||||
|
|
||||||
OBJS= command.o common.o help.o input.o stringutils.o mainloop.o copy.o \
|
OBJS= command.o common.o help.o input.o stringutils.o mainloop.o copy.o \
|
||||||
startup.o prompt.o variables.o large_obj.o print.o describe.o \
|
startup.o prompt.o variables.o large_obj.o print.o describe.o \
|
||||||
|
@ -50,6 +50,7 @@ distprep: $(srcdir)/sql_help.h $(srcdir)/psqlscan.c
|
||||||
|
|
||||||
install: all installdirs
|
install: all installdirs
|
||||||
$(INSTALL_PROGRAM) psql$(X) $(DESTDIR)$(bindir)/psql$(X)
|
$(INSTALL_PROGRAM) psql$(X) $(DESTDIR)$(bindir)/psql$(X)
|
||||||
|
$(INSTALL_DATA) $(srcdir)/psql.rc.sample $(DESTDIR)$(datadir)/psql.rc.sample
|
||||||
|
|
||||||
installdirs:
|
installdirs:
|
||||||
$(mkinstalldirs) $(DESTDIR)$(bindir)
|
$(mkinstalldirs) $(DESTDIR)$(bindir)
|
||||||
|
|
7
src/bin/psql/psql.rc.sample
Normal file
7
src/bin/psql/psql.rc.sample
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
--
|
||||||
|
-- psql configuration file
|
||||||
|
--
|
||||||
|
-- This file is read before the .psqlrc file in the user's home directory.
|
||||||
|
--
|
||||||
|
-- Copy this to your sysconf directory (typically /usr/local/pgsql/etc) and
|
||||||
|
-- rename it psql.rc.
|
|
@ -3,7 +3,7 @@
|
||||||
*
|
*
|
||||||
* Copyright (c) 2000-2003, PostgreSQL Global Development Group
|
* Copyright (c) 2000-2003, PostgreSQL Global Development Group
|
||||||
*
|
*
|
||||||
* $PostgreSQL: pgsql/src/bin/psql/startup.c,v 1.88 2004/04/19 17:42:58 momjian Exp $
|
* $PostgreSQL: pgsql/src/bin/psql/startup.c,v 1.89 2004/04/22 01:53:37 momjian Exp $
|
||||||
*/
|
*/
|
||||||
#include "postgres_fe.h"
|
#include "postgres_fe.h"
|
||||||
|
|
||||||
|
@ -44,7 +44,8 @@ int optreset;
|
||||||
*/
|
*/
|
||||||
PsqlSettings pset;
|
PsqlSettings pset;
|
||||||
|
|
||||||
#define PSQLRC ".psqlrc"
|
#define PSQLRC ".psqlrc"
|
||||||
|
#define SYSPSQLRC "psql.rc"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Structures to pass information between the option parsing routine
|
* Structures to pass information between the option parsing routine
|
||||||
|
@ -74,6 +75,7 @@ struct adhoc_opts
|
||||||
static void parse_psql_options(int argc, char *argv[],
|
static void parse_psql_options(int argc, char *argv[],
|
||||||
struct adhoc_opts * options);
|
struct adhoc_opts * options);
|
||||||
static void process_psqlrc(void);
|
static void process_psqlrc(void);
|
||||||
|
static void process_psqlrc_file(char *filename);
|
||||||
static void showVersion(void);
|
static void showVersion(void);
|
||||||
|
|
||||||
#ifdef USE_SSL
|
#ifdef USE_SSL
|
||||||
|
@ -562,6 +564,9 @@ parse_psql_options(int argc, char *argv[], struct adhoc_opts * options)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef SYSCONFDIR
|
||||||
|
#error "You must compile this file with SYSCONFDIR defined."
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -570,32 +575,39 @@ parse_psql_options(int argc, char *argv[], struct adhoc_opts * options)
|
||||||
static void
|
static void
|
||||||
process_psqlrc(void)
|
process_psqlrc(void)
|
||||||
{
|
{
|
||||||
char *psqlrc;
|
char *globalFile = SYSCONFDIR "/" SYSPSQLRC;
|
||||||
char *home;
|
char *home;
|
||||||
|
char *psqlrc;
|
||||||
|
|
||||||
|
process_psqlrc_file(globalFile);
|
||||||
|
|
||||||
|
if ((home = getenv("HOME")) != NULL)
|
||||||
|
{
|
||||||
|
psqlrc = pg_malloc(strlen(home) + 1 + strlen(PSQLRC) + 1);
|
||||||
|
sprintf(psqlrc, "%s/%s", home, PSQLRC);
|
||||||
|
process_psqlrc_file(psqlrc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
process_psqlrc_file(char *filename)
|
||||||
|
{
|
||||||
|
char *psqlrc;
|
||||||
|
|
||||||
#if defined(WIN32) && (!defined(__MINGW32__))
|
#if defined(WIN32) && (!defined(__MINGW32__))
|
||||||
#define R_OK 4
|
#define R_OK 4
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Look for one in the home dir */
|
psqlrc = pg_malloc(strlen(filename) + 1 + strlen(PG_VERSION) + 1);
|
||||||
home = getenv("HOME");
|
sprintf(psqlrc, "%s-%s", filename, PG_VERSION);
|
||||||
|
|
||||||
if (home)
|
if (access(psqlrc, R_OK) == 0)
|
||||||
{
|
process_file(psqlrc);
|
||||||
psqlrc = pg_malloc(strlen(home) + 1 + strlen(PSQLRC) + 1 +
|
else if (access(filename, R_OK) == 0)
|
||||||
strlen(PG_VERSION) + 1);
|
process_file(filename);
|
||||||
sprintf(psqlrc, "%s/%s-%s", home, PSQLRC, PG_VERSION);
|
free(psqlrc);
|
||||||
|
|
||||||
if (access(psqlrc, R_OK) == 0)
|
|
||||||
process_file(psqlrc);
|
|
||||||
else
|
|
||||||
{
|
|
||||||
sprintf(psqlrc, "%s/%s", home, PSQLRC);
|
|
||||||
if (access(psqlrc, R_OK) == 0)
|
|
||||||
process_file(psqlrc);
|
|
||||||
}
|
|
||||||
free(psqlrc);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue