Search Postgresql Archives

Re: Server name in psql prompt

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

 



Adrian Klaver wrote:

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). "

Thanks Adrian, link noted.

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.

I've gone round a number of machines setting up a basic psqlrc file, and will mail the most obnox^H^H^H^H^H demanding users warning them of the issues.

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.

I've just checked that and if I do psql -h postgres where postgres is a DNS alias to postgres1 then the expansion of %M is "postgres" not "postgres1".

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.

%[ ... %]

OK but if I understand you (and the docs) correctly I'd still need to find a way to set the variable on the client rather than having something fetched from the server.

I thought earlier that I could use finger as a hack for querying the server, i.e. I could put e.g. a disc set name in /home/postgres/.plan. However I then realised that I'd need %M to be expanded before %`, so that I could do something like

\set PROMPT1 '`finger postgres@%M|filter`: %/%R%# '

where filter only returned the bit that was needed. I've not tried this due to the ordering issue.

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.

Thanks, noted.

--
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]

--
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