1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
| --- \set prompt1 修改提示符 客户端psql提供两种方式,修改提示符: 1、在psql命令行进行修改,退出登陆后失败 2、在文件~/.psqlrc中进行配置
--- psql命令行修改 [postgres@server ~]$ psql psql (10.12) Type "help" for help.
postgres=# \set PROMPT1 '%/@%M:%>%R%#%p '
postgres@[local]:5432=#5635 \echo :PROMPT1 %/@%M:%>%R%#%p
--- .psqlrc配置文件修改 cd ~ touch .psqlrc vi .psqlrc \set PROMPT1 '%/@%M:%>%R%#%p ' :wq
[postgres@pg14 ~]$ psql psql (14.2) Type "help" for help.
postgres@[local]:1931=#8201
常用设置项:
%M 数据库别名,不是主机名 %> 数据库服务端口号 %n 数据库会话的用户名 %/ 当前数据库名称 %# 超级用户显示# ,其它用户显示> %p 显示当前连接的进程号 %R 在PROMPT1中通常显示为= ,当进程被断开则显示! %1 显示命令行号
Prompting The prompts psql issues can be customized to your preference. The three variables PROMPT1, PROMPT2, and PROMPT3 contain strings and special escape sequences that describe the appearance of the prompt. Prompt 1 is the normal prompt that is issued when psql requests a new command. Prompt 2 is issued when more input is expected during command entry, for example because the command was not terminated with a semicolon or a quote was not closed. Prompt 3 is issued when you are running an SQL COPY FROM STDIN command and you need to type in a row value on the terminal.
The value of the selected prompt variable is printed literally, except where a percent sign (%) is encountered. Depending on the next character, certain other text is substituted instead. Defined substitutions are:
%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.
%m The host name of the database server, truncated at the first dot, or [local] if the connection is over a Unix domain socket.
%> The port number at which the database server is listening.
%n The database session user name. (The expansion of this value might change during a database session as the result of the command SET SESSION AUTHORIZATION.)
%/ The name of the current database.
%~ Like %/, but the output is ~ (tilde) if the database is your default database.
%# If the session user is a database superuser, then a #, otherwise a >. (The expansion of this value might change during a database session as the result of the command SET SESSION AUTHORIZATION.)
%p The process ID of the backend currently connected to.
%R In prompt 1 normally =, but @ if the session is in an inactive branch of a conditional block, or ^ if in single-line mode, or ! if the session is disconnected from the database (which can happen if \connect fails). In prompt 2 %R is replaced by a character that depends on why psql expects more input: - if the command simply wasn't terminated yet, but * if there is an unfinished /* ... */ comment, a single quote if there is an unfinished quoted string, a double quote if there is an unfinished quoted identifier, a dollar sign if there is an unfinished dollar-quoted string, or ( if there is an unmatched left parenthesis. In prompt 3 %R doesn't produce anything.
%x Transaction status: an empty string when not in a transaction block, or * when in a transaction block, or ! when in a failed transaction block, or ? when the transaction state is indeterminate (for example, because there is no connection).
%l The line number inside the current statement, starting from 1.
%digits The character with the indicated octal code is substituted.
%:name: The value of the psql variable name. See the section Variables for details.
%`command` The output of command, similar to ordinary “back-tick” substitution.
%[ ... %] 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.
To insert a percent sign into your prompt, write %%. The default prompts are '%/%R%# ' for prompts 1 and 2, and '>> ' for prompt 3.
|