Thread: [HACKERS] PSQL man page patch
Since one of my pet hates is people who add features without adding them to the documentation, I thought I'd better supply a patch to the psql man page which documents the .psqlrc file :-) (I forgot yesterday....) Andrew *** psql.1.old Sat Jun 21 14:54:46 1997 - --- psql.1 Sat Jun 21 15:02:09 1997 *************** *** 97,102 **** - --- 97,113 ---- environment variable or, if that's not set, to the Unix account name of the current user. .PP + When + .IR "psql" + starts, it reads SQL commands from + .IR "/etc/psqlrc" + and then from + .IR "$(HOME)/.psqlrc" + This allows SQL commands like + .IR SET + which can be used to set the date style to be run at the start of + evry session. + .PP .IR "psql" understands the following command-line options: .TP - ---------------------------------------------------------------------------- Dr. Andrew C.R. Martin University College London EMAIL: (Work) martin@biochem.ucl.ac.uk (Home) andrew@stagleys.demon.co.uk URL: http://www.biochem.ucl.ac.uk/~martin Tel: (Work) +44(0)171 419 3890 (Home) +44(0)1372 275775 ------------------------------
OK, we never installed this for 6.2 because we were already in Beta. Can we do this for 6.3? Vadim suggested we make this part of libpq, so all applications could make use of it. I have one of the original patches, but not the others. Martin, what do you think? Any other comments on this? > > > Since one of my pet hates is people who add features without > adding them to the documentation, I thought I'd better supply > a patch to the psql man page which documents the .psqlrc file :-) > (I forgot yesterday....) > > > Andrew > > > > *** psql.1.old Sat Jun 21 14:54:46 1997 > --- psql.1 Sat Jun 21 15:02:09 1997 > *************** > *** 97,102 **** > --- 97,113 ---- > environment variable or, if that's not set, to the Unix account name of the > current user. > .PP > + When > + .IR "psql" > + starts, it reads SQL commands from > + .IR "/etc/psqlrc" > + and then from > + .IR "$(HOME)/.psqlrc" > + This allows SQL commands like > + .IR SET > + which can be used to set the date style to be run at the start of > + evry session. > + .PP > .IR "psql" > understands the following command-line options: > .TP > > > > ---------------------------------------------------------------------------- > Dr. Andrew C.R. Martin University College London > EMAIL: (Work) martin@biochem.ucl.ac.uk (Home) andrew@stagleys.demon.co.uk > URL: http://www.biochem.ucl.ac.uk/~martin > Tel: (Work) +44(0)171 419 3890 (Home) +44(0)1372 275775 > > -- Bruce Momjian maillist@candle.pha.pa.us
> OK, we never installed this for 6.2 because we were already in Beta. > Can we do this for 6.3? Vadim suggested we make this part of libpq, so > all applications could make use of it. > > I have one of the original patches, but not the others. Martin, what do you > think? Any other comments on this? > > > > > > > > adding them to the documentation, I thought I'd better supply > > a patch to the psql man page which documents the .psqlrc file :-) > > (I forgot yesterday....) > > > > > > Andrew > > > > [DELETED patch to man page for psql.1 which documents suggested addition of support for a /etc/psqlrc and/or $(HOME)/.psqlrc containing SQL code to be run whenever psql is started] Personally, I think this should just be a function of psql not libpq - it's really there as a convenience to the person running psql to save typing a few lines of SQL every time (like setting the date format). If you are running PG/SQL via some other interface (such as Perl), then it is trivial to write those few lines as part of your Perl script rather than in a .psqlrc file. I still have the patch file for the source as well as for the man page Andrew ---------------------------------------------------------------------------- Dr. Andrew C.R. Martin University College London EMAIL: (Work) martin@biochem.ucl.ac.uk (Home) andrew@stagleys.demon.co.uk URL: http://www.biochem.ucl.ac.uk/~martin Tel: (Work) +44(0)171 419 3890 (Home) +44(0)1372 275775
> ... patch to man page for psql.1 which documents suggested addition > of support for a /etc/psqlrc and/or $(HOME)/.psqlrc containing SQL code > to be run whenever psql is started] > > Personally, I think this should just be a function of psql not libpq - it's > really there as a convenience to the person running psql to save typing a > few lines of SQL every time (like setting the date format). If you are > running PG/SQL via some other interface (such as Perl), then it is > trivial to write those few lines as part of your Perl script rather than > in a .psqlrc file. I have added support for PGTZ to libpq and fixed the existing PGDATESTYLE support, so at least a few common environment settings will not need .psqlrc. The bigger problem is that .psqlrc could contain commands which might screw up an embedded application. For example. a query to show the current time in .psqlrc would result in an unexpected response from the backend as an app fires up. It does seem like a nice feature for at least psql though, as Andrew suggests. I'd suggest that if we add it to libpq that we do so as a separate call or an option, so an embedded app can choose to use it or not. - Tom > I still have the patch file for the source as well as for the man page
> OK, we never installed this for 6.2 because we were already in Beta. > Can we do this for 6.3? Vadim suggested we make this part of libpq, so > all applications could make use of it. > > Any more comments about adding support for .psqlrc? The original proposal was that psql should read commands from /etc/psqlrc and then from $(HOME)/.psqlrc Nobody seems to have raised any objections. I vote for including this for 6.3 Andrew ---------------------------------------------------------------------------- Dr. Andrew C.R. Martin University College London EMAIL: (Work) martin@biochem.ucl.ac.uk (Home) andrew@stagleys.demon.co.uk URL: http://www.biochem.ucl.ac.uk/~martin Tel: (Work) +44(0)171 419 3890 (Home) +44(0)1372 275775
> > > > OK, we never installed this for 6.2 because we were already in Beta. > > Can we do this for 6.3? Vadim suggested we make this part of libpq, so > > all applications could make use of it. > > > > > > Any more comments about adding support for .psqlrc? The original > proposal was that psql should read commands from /etc/psqlrc > and then from $(HOME)/.psqlrc > > Nobody seems to have raised any objections. I vote for including this > for 6.3 > Sure. Let's do it from psql only, I think. -- Bruce Momjian maillist@candle.pha.pa.us
On Fri, 16 Jan 1998, Andrew Martin wrote: > > > OK, we never installed this for 6.2 because we were already in Beta. > > Can we do this for 6.3? Vadim suggested we make this part of libpq, so > > all applications could make use of it. > > > > > > Any more comments about adding support for .psqlrc? The original > proposal was that psql should read commands from /etc/psqlrc > and then from $(HOME)/.psqlrc > > Nobody seems to have raised any objections. I vote for including this > for 6.3 I think its a good thing and should be added...I also agree with Bruce(?) who disagreed with Vadim...it shouldn't be inherent in libpq itself, only in the "applications" themselves
Andrew Martin wrote: > > OK, we never installed this for 6.2 because we were already in Beta. > > Can we do this for 6.3? Vadim suggested we make this part of libpq, so > > all applications could make use of it. > > > > > > Any more comments about adding support for .psqlrc? The original > proposal was that psql should read commands from /etc/psqlrc > and then from $(HOME)/.psqlrc > > Nobody seems to have raised any objections. I vote for including this > for 6.3 I'm in favor of it also, perhaps as a libpq function call which is used in psql. That way, other apps or frontends can choose to use it or not. Would much prefer leaving it out as a _mandatory_ part of connection initialization, since there will be side-effects for embedded apps. Combined with PGDATESTYLE and PGTZ there will be pretty good control over the frontend environment. - Tom
On Fri, 16 Jan 1998, Thomas G. Lockhart wrote: > I'm in favor of it also, perhaps as a libpq function call which is used in > psql. That way, other apps or frontends can choose to use it or not. > > Would much prefer leaving it out as a _mandatory_ part of connection > initialization, since there will be side-effects for embedded apps. Combined > with PGDATESTYLE and PGTZ there will be pretty good control over the frontend > environment. I agree entirely with you Tom, as this could cause problems if it was a _mandatory_ part of connecting. Infact, it would (with the JDBC driver) prevent it from being used with Applets (accessing local files violate applet security). It's best to make this an optional call for libpq. For jdbc use, the following is the best way to do this (rather than including it in the driver): public void readRCfile(Statement stat,File file) throws SQLException { try { FileInputStream fis = new FileInputStream(file); BufferedReader r = new BufferedReader(new Reader(fis)); while((String line=r.readLine())!=null) { if(!line.startsWith("#")) stat.executeUpdate(line); } r.close(); } catch(IOException ioe) throw new SQLException(ioe.toString()); } public void initConnection(Connection con) throws SQLException { Statement stat = con.createStatement(); // Process ~/.psqlrc try { String dir=System.getProperty("user.home"); if(dir!=null) readRCfile(stat,new File(dir,".psqlrc")); } catch(SQLException se) { // Ignore if it doesn't exist. } // Now /etc/psqlrc readRCfile(stat,new File("/etc/psqlrc")); stat.close(); } I'll add this to the examples later. -- Peter T Mount petermount@earthling.net or pmount@maidast.demon.co.uk Main Homepage: http://www.demon.co.uk/finder Work Homepage: http://www.maidstone.gov.uk Work EMail: peter@maidstone.gov.uk
Peter T Mount wrote: > > On Fri, 16 Jan 1998, Thomas G. Lockhart wrote: > > > I'm in favor of it also, perhaps as a libpq function call which is used in > > psql. That way, other apps or frontends can choose to use it or not. > > > > Would much prefer leaving it out as a _mandatory_ part of connection > > initialization, since there will be side-effects for embedded apps. Combined > > with PGDATESTYLE and PGTZ there will be pretty good control over the frontend > > environment. > > I agree entirely with you Tom, as this could cause problems if it was a > _mandatory_ part of connecting. Agreed! BTW, do you like X11 ? XLock.background: Black Netscape*background: #B2B2B2 How about following this way ? psql.pgdatestyle: euro # this is for psql _some_app_.pgdatestyle: iso # this is for some application pgaccess.background: black # setting pgaccess' specific feature *.pggeqo: on=3 # this is for all applics We could use 'pg' prefix for standard features (datestyle, tz, etc) to give applic developers ability to set applic' specific features in the pgsqlrc file(s). Vadim
On Sun, 18 Jan 1998, Vadim B. Mikheev wrote: > Peter T Mount wrote: > > > > On Fri, 16 Jan 1998, Thomas G. Lockhart wrote: > > > > > I'm in favor of it also, perhaps as a libpq function call which is used in > > > psql. That way, other apps or frontends can choose to use it or not. > > > > > > Would much prefer leaving it out as a _mandatory_ part of connection > > > initialization, since there will be side-effects for embedded apps. Combined > > > with PGDATESTYLE and PGTZ there will be pretty good control over the frontend > > > environment. > > > > I agree entirely with you Tom, as this could cause problems if it was a > > _mandatory_ part of connecting. > > Agreed! > > BTW, do you like X11 ? Yes, as its much better than a certain other windowing front end I could mention ;-) > XLock.background: Black > Netscape*background: #B2B2B2 > > How about following this way ? > > psql.pgdatestyle: euro # this is for psql > _some_app_.pgdatestyle: iso # this is for some application > pgaccess.background: black # setting pgaccess' specific feature > *.pggeqo: on=3 # this is for all applics I assume you mean using X style configuration in /etc/psqlrc ? If so, then yes, it's a good way to go, as it allows a lot of flexibility. One problem with the earlier .psqlrc idea was that any commands would run for any database (as I saw it). This could cause big problems, if the user accessed a database that didn't support those commands. With the above method, you can get round this, by something like: psql.database.mydb: .mydbrc # sql file run when mydb is opened psql.database.*: .generalrc # sql file run when any db is # opened Now, JDBC driver can't use the same config file as that violates security. To get round this, we use Java's system properties. For applets, the driver simply gets nothing when it asks for the parameter. Applications can load their own parameters from a file, or have them set on the command line. The file looks like: # Default authorisation scheme postgresql.auth=password The command line form looks like: java -Dpostgresql.auth=password myapp > We could use 'pg' prefix for standard features (datestyle, tz, etc) > to give applic developers ability to set applic' specific features > in the pgsqlrc file(s). Sounds good to me -- Peter T Mount petermount@earthling.net or pmount@maidast.demon.co.uk Main Homepage: http://www.demon.co.uk/finder Work Homepage: http://www.maidstone.gov.uk Work EMail: peter@maidstone.gov.uk
> Agreed! > > BTW, do you like X11 ? > > XLock.background: Black > Netscape*background: #B2B2B2 > > How about following this way ? > > psql.pgdatestyle: euro # this is for psql > _some_app_.pgdatestyle: iso # this is for some application > pgaccess.background: black # setting pgaccess' specific feature > *.pggeqo: on=3 # this is for all applics > > We could use 'pg' prefix for standard features (datestyle, tz, etc) > to give applic developers ability to set applic' specific features > in the pgsqlrc file(s). > Cool idea. -- Bruce Momjian maillist@candle.pha.pa.us