Обсуждение: Custom prompt

Поиск
Список
Период
Сортировка

Custom prompt

От
craig@gtek.biz
Дата:
Good afternoon,

When accessing PostgreSQL via psql, is it possible to make use of a custom prompt? I would like something like
postgres=#instead of just postgres=#. My search was fruitless (see next paragraph). 

And if I'm allowed two questions in one post, how does one search for a phrase such as "custom prompt" in the mailing
listarchives? Everything I tried found every page with either the word custom, the word prompt, or both words somewhere
inthe message. I just wanted to search for messages containing the exact phrase "custom prompt". 

Thanks,
Craig


Sent - Gtek Web Mail




Re: Custom prompt

От
Adrian Klaver
Дата:
On 09/24/2012 11:20 AM, craig@gtek.biz wrote:
> Good afternoon,
>
> When accessing PostgreSQL via psql, is it possible to make use of a custom prompt? I would like something like
postgres=#instead of just postgres=#. My search was fruitless (see next paragraph). 

http://www.postgresql.org/docs/9.2/interactive/app-psql.html#APP-PSQL-PROMPTING

>
> And if I'm allowed two questions in one post, how does one search for a phrase such as "custom prompt" in the mailing
listarchives? Everything I tried found every page with either the word custom, the word prompt, or both words somewhere
inthe message. I just wanted to search for messages containing the exact phrase "custom prompt". 
>
> Thanks,
> Craig
>
>
> Sent - Gtek Web Mail
>
>
>
>


--
Adrian Klaver
adrian.klaver@gmail.com


Re: Custom prompt

От
David Salisbury
Дата:

On 9/24/12 12:20 PM, craig@gtek.biz wrote:
> Good afternoon,
>
> When accessing PostgreSQL via psql, is it possible to make use of a custom prompt? I would like something like
postgres=#instead of just postgres=#. My search was fruitless (see next paragraph). 
>
> And if I'm allowed two questions in one post, how does one search for a phrase such as "custom prompt" in the mailing
listarchives? Everything I tried found every page with either the word custom, the word prompt, or both words somewhere
inthe message. I just wanted to search for messages containing the exact phrase "custom prompt". 
>
> Thanks,
> Craig
>
>
> Sent - Gtek Web Mail

Try along the lines of

psql -h some.host.com   -U postgres -v "PROMPT1=*my_cool_prompt%/> " -d my_db

no se on the second Q.

ds


Re: Custom prompt

От
craig@gtek.biz
Дата:
>
> Try along the lines of
>
> psql -h some.host.com   -U postgres -v "PROMPT1=*my_cool_prompt%/> " -d my_db
>

Works like a charm! Do I have a dot file  that I can save this setting to, similar to the .exrc for vi, or will I need
toenter it every time? If the latter, I'll alias it, but I'd rather be able to save it if possible. 

Thanks!


Sent - Gtek Web Mail




Re: Custom prompt

От
Adrian Klaver
Дата:
On 09/24/2012 11:20 AM, craig@gtek.biz wrote:
> Good afternoon,
>
> When accessing PostgreSQL via psql, is it possible to make use of a custom prompt? I would like something like
postgres=#instead of just postgres=#. My search was fruitless (see next paragraph). 

Should have added:
To make it stick between sessions you can use a psqlrc file. They are
handy for customizing psql in general. These can be system wide or per
user. For more information do a find(psqlrc) on the page I previously
linked to.

>
> And if I'm allowed two questions in one post, how does one search for a phrase such as "custom prompt" in the mailing
listarchives? Everything I tried found every page with either the word custom, the word prompt, or both words somewhere
inthe message. I just wanted to search for messages containing the exact phrase "custom prompt". 

Not sure about that mailing list, but using custom prompt in the search
box in the docs finds the page I posted.

>
> Thanks,
> Craig
>
>
> Sent - Gtek Web Mail
>
>
>
>


--
Adrian Klaver
adrian.klaver@gmail.com


Re: Custom prompt

От
craig@gtek.biz
Дата:
>> When accessing PostgreSQL via psql, is it possible to make use of a custom
>> prompt? I would like something like postgres=# instead of just postgres=#. My
>> search was fruitless (see next paragraph).
>
> Should have added:
> To make it stick between sessions you can use a psqlrc file. They are
> handy for customizing psql in general. These can be system wide or per
> user. For more information do a find(psqlrc) on the page I previously
> linked to.

Aha, exactly what I was looking for. Thanks!

>>
>> And if I'm allowed two questions in one post, how does one search for a phrase
>> such as "custom prompt" in the mailing list archives? Everything I tried found
>> every page with either the word custom, the word prompt, or both words somewhere
>> in the message. I just wanted to search for messages containing the exact phrase
>> "custom prompt".
>
> Not sure about that mailing list, but using custom prompt in the search
> box in the docs finds the page I posted.

It does, but not by that exact phrase. It returns 10 hits, one of which is a page that contains the word "prompts", and
theword "customize": 

...prompts psql issues can be customized to your preference. The three variables PROMPT1 PROMPT2 , and PROMPT3...

I'd like to return results that contain the exact phrase "custom prompt", not a lucky hit on similar words that are
physicallyclose to each other. Usually enclosing the phrase in quotes will do it, but not in any PostgreSQL search form
thatI've found. 


Sent - Gtek Web Mail




Re: Custom prompt

От
craig@gtek.biz
Дата:
Apologies to all, I didn't realize this ISPs webmail client doesn't wrap lines.
My reply, formatted in a more readable way:

On Monday, September 24, 2012 14:07, craig@gtek.biz said:

>> When accessing PostgreSQL via psql, is it possible to make use of a custom
>> prompt? I would like something like postgres=# instead of just postgres=#. My
>> search was fruitless (see next paragraph).
>
> Should have added:
> To make it stick between sessions you can use a psqlrc file. They are
> handy for customizing psql in general. These can be system wide or per
> user. For more information do a find(psqlrc) on the page I previously
> linked to.

Aha, exactly what I was looking for. Thanks!

>>
>> And if I'm allowed two questions in one post, how does one search for a phrase
>> such as "custom prompt" in the mailing list archives? Everything I tried found
>> every page with either the word custom, the word prompt, or both words
>> somewhere
>> in the message. I just wanted to search for messages containing the exact
>> phrase
>> "custom prompt".
>
> Not sure about that mailing list, but using custom prompt in the search
> box in the docs finds the page I posted.

It does, but not by that exact phrase. It returns 10 hits, one of which is a page
that contains the word "prompts", and the word "customize":

...prompts psql issues can be customized to your preference. The three variables
PROMPT1 PROMPT2 , and PROMPT3...

I'd like to return results that contain the exact phrase "custom prompt", not a
lucky hit on similar words that are physically close to each other. Usually
enclosing the phrase in quotes will do it, but not in any PostgreSQL search form
that I've found.



Sent - Gtek Web Mail




Re: Custom prompt

От
craig@gtek.biz
Дата:

> Aha, exactly what I was looking for. Thanks!

  Well I certainly feel dumb. The answer is right in the documentation, I just
failed to find it (I did look first). The system-wide psqlrc, and the ~/.psqlrc
files fit the bill perfectly, and the documentation explains it all quite
nicely. I accomplished my main goal better than I had even hoped. Our two
production servers are locked down and do not accept external connections. I
wanted to customize the prompt so I could tell at a glance which I was on. The
documentation even explains how to have a tcsh-like color prompt, which I use
quite extensively in bash. I now have a yellow prompt on one server, and a red
one on the other. How cool is that!

my system-wide psqlrc (/etc/sysconfig/pgsql/psqlrc on CentOS):

\set PROMPT1 %[%033[1;31;40m%]%n%[%033[0m%]@%/%R%# >

This puts the username in red, followed by @DBNAME in white, both on a black
background. I'll probably tweak this as I go, but this works for now.

Thanks to all for the help!




Sent - Gtek Web Mail