psql color hostname prompt
От | Cal Heldenbrand |
---|---|
Тема | psql color hostname prompt |
Дата | |
Msg-id | CAAcwKhcjsxG9_gDPmiUZF280+eXg06zD9i+U_JL67ULo5MTOpQ@mail.gmail.com обсуждение исходный текст |
Ответы |
Re: psql color hostname prompt
Re: psql color hostname prompt Re: psql color hostname prompt |
Список | pgsql-general |
Hi everyone,
The default psql prompt can be a little frustrating when managing many hosts. Typing the wrong command on the wrong host can ruin your day. ;-)==============================================
-- PROMPT1 is the primary prompt
\set PROMPT1 '%[%033[1;31m%]%`/usr/local/pgsql/etc/psql_hostname.sh`%[%033[0m%] %n@%/%R%#%x '
-- PROMPT2 is the secondary (query continue) prompt
\set PROMPT2 '%[%033[1;31m%]%`/usr/local/pgsql/etc/psql_hostname.sh`[%033[0m%] %n@%/%R %# '
==============================================
-- PROMPT1 is the primary prompt
\set PROMPT1 '%[%033[1;31m%]%`/usr/local/pgsql/etc/psql_hostname.sh`%[%033[0m%] %n@%/%R%#%x '
-- PROMPT2 is the secondary (query continue) prompt
\set PROMPT2 '%[%033[1;31m%]%`/usr/local/pgsql/etc/psql_hostname.sh`[%033[0m%] %n@%/%R %# '
==============================================
/usr/local/pgsql/etc/psql_hostname.sh
==============================================#!/bin/bash
# Intelligently return local hostname, or remote server connection
# - list file descriptors of my parent PID (psql command)
# - include only FD #3, which is the postgres socket
# - print the NAME column
name=$(/usr/sbin/lsof -p $PPID -a -d 3 | tail -1 | awk '{print $9}')
if [[ "$name" == "socket" ]]; then
# We're on the local socket
hostname -f
else
# Cut out the destination machine from the socket pair
echo $( sed 's/.*->\(.*\):postgres/\1/' <<< $name )
fi
==============================================
Thank you!
---------------------------------------------------------------
Cal Heldenbrand
Web Operations at FBS
Creators of flexmls® and Spark Platform
cal@fbsdata.com
В списке pgsql-general по дате отправления: