PostgreSQL11自定义带日期等个性化配置的登录提示符

在centos7上编辑/root/.psqlrc文件,

# vi /root/.psqlrc

添加如下内容:

\set PROMPT1 '%`date +%H:%M:%S` (%n@%M:%>)%/%R%#%x '

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

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

\timing

\set QUIET 1

\pset null '[null]'

\set COMP_KEYWORD_CASE upper

\set HISTSIZE 2000

\set VERBOSITY verbose

\set QUIET 0

\echo 'Welcome to PostgreSQL! \n'

\echo 'Type \\c to change database. \n'

\echo 'Type \\q to exit. \n'


测试:

# psql -h 127.0.0.1 -U postgres -p 5432 -d test

Timing is on.

Welcome to PostgreSQL! 


Type \c to change database. 


Type \q to exit. 


psql (11.3)

Type "help" for help.


10:54:52 (postgres@127.0.0.1:5432)test=# 

10:55:11 (postgres@127.0.0.1:5432)test=# 

10:55:11 (postgres@127.0.0.1:5432)test=# 

10:55:11 (postgres@127.0.0.1:5432)test=# 

10:55:11 (postgres@127.0.0.1:5432)test=# 

10:55:11 (postgres@127.0.0.1:5432)test=# 

10:55:11 (postgres@127.0.0.1:5432)test=# \q



请使用浏览器的分享功能分享到微信等