Search Postgresql Archives

Re: Server name in psql prompt

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 01/08/2010 08:59 AM, Mark Morgan Lloyd wrote:
hubert depesz lubaczewski wrote:
On Fri, Jan 08, 2010 at 11:20:36AM +0000, Mark Morgan Lloyd wrote:
Is there any way of getting psql to display the name of the
currently-connected server in its prompt, and perhaps a custom string
identifying e.g. a disc set, without having to create a psqlrc file
on every client system that's got a precompiled psql installed?

what exactly is the problem with distributing your own .psqlrc?

for me it's one of the first things that I do - I setup environment.

Thanks everybody for the comments. The problem is that in an environment
where the end-users generally have enough nous (or are sufficiently
assertive) to run their own systems (e.g. an engineering department)
there is still a requirement to protect shared resources like a
database. It's not really feasible for the overall sysadmin to work his
way around all possible machines, work out which distro each is running,
and install a suitable psqlrc in the place expected by that distro's
psql. It's even less feasible to install a shim that forces default
command-line parameters.

When I referred to a disc set I wasn't thinking about something in the
context of PostgreSQL, I was thinking about a group of discs in
removable (Compaq) caddies that might be transferred to one of a number
of chassis. At present I've got one chassis here into which I'm putting
one of two disc sets, both of which are the 8.4 upgrade target: I'd like
to be able to confirm from the client which set is in the chassis.

After playing some more I think there are actually three issues:

i) Getting psql to take its initial defaults, i.e. if there isn't a
psqlrc file, from the server (e.g. for the prompt).

In the case you describe the below might work:
http://www.postgresql.org/docs/8.4/interactive/app-psql.html
"Before starting up, psql attempts to read and execute commands from the system-wide psqlrc file and the user's ~/.psqlrc file. (On Windows, the user's startup file is named %APPDATA%\postgresql\psqlrc.conf.) See PREFIX/share/psqlrc.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 \set and SET commands). "

Set up a system psqlrc. I have done this when working with multiple versions/multiple database clusters of Postgres on one machine to keep track.


ii) Getting the prompt to display the actual hostname of the server,
rather than what was put on the command line which might be an alias or
dotted-quad address.


Same link as above.
%M

The full host name (with domain name) of the database server, or [local] if the connection is over a Unix domain socket, or [local:/dir/name], if the Unix domain socket is not at the compiled in default location.


iii) Getting the prompt to display some other identifier from the server
to identify the disc set


Make either one of these different for each server.

%:name:

The value of the psql variable name. See the section Variables for details.

%[ ... %]

Prompts can contain terminal control characters which, for example, change the color, background, or style of the prompt text, or change the title of the terminal window. In order for the line editing features of Readline to work properly, these non-printing control characters must be designated as invisible by surrounding them with %[ and %]. Multiple pairs of these can occur within the prompt. For example:

    testdb=> \set PROMPT1 '%[%033[1;33;40m%]%n@%/%R%[%033[0m%]%# '

results in a boldfaced (1;) yellow-on-black (33;40) prompt on VT100-compatible, color-capable terminals.


I don't think anybody else thinks this is an issue so I guess all I can
say is thanks for listening :-)



--
Adrian Klaver
adrian.klaver@xxxxxxxxx

--
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux