Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbe6bbce

Browse files
committed
Add global psql config file, psql.rc.sample.
1 parent4906841 commitbe6bbce

File tree

4 files changed

+55
-30
lines changed

4 files changed

+55
-30
lines changed

‎doc/src/sgml/ref/psql-ref.sgml

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/ref/psql-ref.sgml,v 1.112 2004/04/21 00:34:18 momjian Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/ref/psql-ref.sgml,v 1.113 2004/04/22 01:53:17 momjian Exp $
33
PostgreSQL documentation
44
-->
55

@@ -440,7 +440,8 @@ PostgreSQL documentation
440440
<term><option>--no-psqlrc</></term>
441441
<listitem>
442442
<para>
443-
Do not read the start-up file <filename>~/.psqlrc</filename>.
443+
Do not read the start-up file <filename>/psql.rc</filename> or
444+
<filename>~/.psqlrc</filename>.
444445
</para>
445446
</listitem>
446447
</varlistentry>
@@ -1859,8 +1860,9 @@ bar
18591860
<para>
18601861
The autocommit-on mode is <productname>PostgreSQL</>'s traditional
18611862
behavior, but autocommit-off is closer to the SQL spec. If you
1862-
prefer autocommit-off, you may wish to set it in
1863-
your <filename>.psqlrc</filename> file.
1863+
prefer autocommit-off, you may wish to set it in the system-wide
1864+
<filename>psql.rc</filename> or your
1865+
<filename>.psqlrc</filename> file.
18641866
</para>
18651867
</note>
18661868
</listitem>
@@ -2488,9 +2490,12 @@ $endif
24882490
<listitem>
24892491
<para>
24902492
Before starting up, <application>psql</application> attempts to
2491-
read and execute commands from the file
2492-
<filename>$HOME/.psqlrc</filename>. It could be used to set up
2493-
the client or the server to taste (using the <command>\set
2493+
read and execute commands from the the system-wide
2494+
<filename>psql.rc</filename> file and the
2495+
<filename>$HOME/.psqlrc</filename> file in the user's home
2496+
directory. See <filename><replaceable>PREFIX</>/share/psql.rc.sample</>
2497+
for information on setting up the system-wide file. It could be used
2498+
to set up the client or the server to taste (using the <command>\set
24942499
</command> and <command>SET</command> commands).
24952500
</para>
24962501
</listitem>

‎src/bin/psql/Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
66
# Portions Copyright (c) 1994, Regents of the University of California
77
#
8-
# $PostgreSQL: pgsql/src/bin/psql/Makefile,v 1.40 2004/03/09 19:47:05 petere Exp $
8+
# $PostgreSQL: pgsql/src/bin/psql/Makefile,v 1.41 2004/04/22 01:53:37 momjian Exp $
99
#
1010
#-------------------------------------------------------------------------
1111

@@ -15,7 +15,7 @@ include $(top_builddir)/src/Makefile.global
1515

1616
REFDOCDIR=$(top_srcdir)/doc/src/sgml/ref
1717

18-
overrideCPPFLAGS := -I$(libpq_srcdir)$(CPPFLAGS) -DFRONTEND
18+
overrideCPPFLAGS := -I$(libpq_srcdir)$(CPPFLAGS) -DFRONTEND -DSYSCONFDIR='"$(sysconfdir)"'
1919

2020
OBJS=command.o common.o help.o input.o stringutils.o mainloop.o copy.o\
2121
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
5050

5151
install: all installdirs
5252
$(INSTALL_PROGRAM) psql$(X)$(DESTDIR)$(bindir)/psql$(X)
53+
$(INSTALL_DATA)$(srcdir)/psql.rc.sample$(DESTDIR)$(datadir)/psql.rc.sample
5354

5455
installdirs:
5556
$(mkinstalldirs)$(DESTDIR)$(bindir)

‎src/bin/psql/psql.rc.sample

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
--
2+
--psql configuration file
3+
--
4+
-- This file is read before the .psqlrc file in the user's home directory.
5+
--
6+
-- Copy this to your sysconf directory (typically /usr/local/pgsql/etc) and
7+
-- rename it psql.rc.

‎src/bin/psql/startup.c

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 2000-2003, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/bin/psql/startup.c,v 1.88 2004/04/19 17:42:58 momjian Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/startup.c,v 1.89 2004/04/22 01:53:37 momjian Exp $
77
*/
88
#include"postgres_fe.h"
99

@@ -44,7 +44,8 @@ intoptreset;
4444
*/
4545
PsqlSettingspset;
4646

47-
#definePSQLRC ".psqlrc"
47+
#definePSQLRC ".psqlrc"
48+
#defineSYSPSQLRC"psql.rc"
4849

4950
/*
5051
* Structures to pass information between the option parsing routine
@@ -74,6 +75,7 @@ struct adhoc_opts
7475
staticvoidparse_psql_options(intargc,char*argv[],
7576
structadhoc_opts*options);
7677
staticvoidprocess_psqlrc(void);
78+
staticvoidprocess_psqlrc_file(char*filename);
7779
staticvoidshowVersion(void);
7880

7981
#ifdefUSE_SSL
@@ -562,6 +564,9 @@ parse_psql_options(int argc, char *argv[], struct adhoc_opts * options)
562564

563565
}
564566

567+
#ifndefSYSCONFDIR
568+
#error "You must compile this file with SYSCONFDIR defined."
569+
#endif
565570

566571

567572
/*
@@ -570,32 +575,39 @@ parse_psql_options(int argc, char *argv[], struct adhoc_opts * options)
570575
staticvoid
571576
process_psqlrc(void)
572577
{
573-
char*psqlrc;
578+
char*globalFile=SYSCONFDIR"/"SYSPSQLRC;
574579
char*home;
580+
char*psqlrc;
581+
582+
process_psqlrc_file(globalFile);
583+
584+
if ((home=getenv("HOME"))!=NULL)
585+
{
586+
psqlrc=pg_malloc(strlen(home)+1+strlen(PSQLRC)+1);
587+
sprintf(psqlrc,"%s/%s",home,PSQLRC);
588+
process_psqlrc_file(psqlrc);
589+
}
590+
}
591+
592+
593+
594+
staticvoid
595+
process_psqlrc_file(char*filename)
596+
{
597+
char*psqlrc;
575598

576599
#if defined(WIN32)&& (!defined(__MINGW32__))
577600
#defineR_OK 4
578601
#endif
579602

580-
/* Look for one in the home dir */
581-
home=getenv("HOME");
582-
583-
if (home)
584-
{
585-
psqlrc=pg_malloc(strlen(home)+1+strlen(PSQLRC)+1+
586-
strlen(PG_VERSION)+1);
587-
sprintf(psqlrc,"%s/%s-%s",home,PSQLRC,PG_VERSION);
603+
psqlrc=pg_malloc(strlen(filename)+1+strlen(PG_VERSION)+1);
604+
sprintf(psqlrc,"%s-%s",filename,PG_VERSION);
588605

589-
if (access(psqlrc,R_OK)==0)
590-
process_file(psqlrc);
591-
else
592-
{
593-
sprintf(psqlrc,"%s/%s",home,PSQLRC);
594-
if (access(psqlrc,R_OK)==0)
595-
process_file(psqlrc);
596-
}
597-
free(psqlrc);
598-
}
606+
if (access(psqlrc,R_OK)==0)
607+
process_file(psqlrc);
608+
elseif (access(filename,R_OK)==0)
609+
process_file(filename);
610+
free(psqlrc);
599611
}
600612

601613

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp