Re: Multiple psql history files

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Jonathan Jacobson <jonjac(at)gmail(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Multiple psql history files
Date: 2016-10-18 17:50:40
Message-ID: CAKFQuwYN=+JYPv0tzXWmueUtyab1ZbFOgpnyh+PA9T4qT2_5ig@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tue, Oct 18, 2016 at 10:21 AM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:

> "David G. Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com> writes:
> > On Tue, Oct 18, 2016 at 9:45 AM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> >> One interesting point, if you wish to consider history as being
> >> connection-specific, is what happens during a \c command. Right
> >> now the answer is "nothing" but you might wish it were different.
>
> > ​Just to clarify/confirm a point inferred from the docs...
> > If you place "\set HISTFILE​ ~/.psql_history- :DBNAME"
> > ​into your .psqlrc file then when you perform a "\c" the .psqlrc file is
> > re-read and the ​new value for DBNAME is used to generate a new history
> > file name.
>
> Um, no, I see no indication of that in the code. Where did you read that
> in the docs?
>
>


DBNAME
The name of the database you are currently connected to. This is set every
time you connect to a database (including program start-up), but can be
unset.

​​HISTFILE
The file name that will be used to store the history list. The default
value is ~/.psql_history. For example, putting:
\set HISTFILE ~/.psql_history- :DBNAME
in ~/.psqlrc will cause psql to maintain a separate history for each
database.

​The "including program start-up" aspect to DBNAME means that it is changed
upon using "\c"

I inferred the part about .psqlrc being re-read and thus taking on the new
value of :DBNAME in the example.

psqlrc is later defined to be "the [system|user] startup file" so it was
wrong to conclude that it was re-read upon issuing "\c" - though
"connection startup" isn't a totally unreasonable interpretation of the
timing at which this file is read. Not everyone is going to associate the
"rc" suffix with the file only being read during program startup.

> If we wanted the history file to change at \c, I think the best way would
> be to invent some escape-patterns that could be placed in the value of
> HISTFILE, say along the lines of "\set HISTFILE ~/.psql_history-%h-%p",
> and then specify that if the value contains any such patterns we'll dump
> and reload the history file when reconnecting. But TBH I don't think
> it's worth the trouble. I'd sure like to have seen multiple requests
> for such functionality before we go to the trouble.
>

A slightly less invasive approach would be to have a "connection startup
script" file..."psql-conn-rc"...that is re-read immediately after a
successful connection is made to a database.

David J.

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Robert Haas 2016-10-18 17:51:54 Re: Minor improvement to delete.sgml
Previous Message Andres Freund 2016-10-18 17:46:35 Re: Hash Indexes