-- Found this on thoughtbot here:
-- https://robots.thoughtbot.com/improving-the-command-line-postgres-experience
-- and it fixes problems with psql, some I didn't even know I had.
-- Set up a nice friendly prompt
\set PROMPT1 '%[%033[1m%]%M %n@%/%R%[%033[0m%]%# '
\set PROMPT2 '[more] %R > '
-- By default, NULL displays as an empty space. Is it actually an empty
-- string, or is it null? This makes that distinction visible.
\pset null '[NULL]'
-- Use table format (with headers across the top) by default, but switch to
-- expanded table format when there's a lot of data, which makes it much
-- easier to read.
\x auto
-- Verbose error reports.
\set VERBOSITY verbose
-- Use a separate history file per-database.
\set HISTFILE ~/.psql_history- :DBNAME
-- If a command is run more than once in a row, only store it once in the
-- history.
\set HISTCONTROL ignoredups
-- Autocomplete keywords (like SELECT) in upper-case, even if you started
-- typing them in lower case.

上面设置完的psql提示样式如下: sky@sky=# SELECT * from hello limit 1;
(1 row)

Time: 0.226 ms sky@sky=# 


\set QUIET 1

\set PROMPT1 '%M:%[%033[1;31m%]%>%[%033[0m%] %n@%/%R%#%x '

\set PROMPT2 '%M %n@%/%R %# '

\pset null '[null]'



\set HISTSIZE 2000

\x auto

\set VERBOSITY verbose

\set QUIET 0

\echo 'Welcome to PostgreSQL! \n'
\echo 'Type :version to see the PostgreSQL version. \n' 
\echo 'Type :extensions to see the available extensions. \n'
\echo 'Type \\q to exit. \n'
\set version 'SELECT version();'
\set extensions 'select * from pg_available_extensions;'


╭─sky@sky-linux /ihome/nodejs/blog  
╰─➤  psql -U sky -W -h
Password for user sky: 
Welcome to PostgreSQL! 

Type :version to see the PostgreSQL version. 

Type :extensions to see the available extensions. 

Type \q to exit. 

psql (9.5.0)
Type "help" for help. sky@sky=#