Postgresql (psql) .psqlrc技巧和窍门

前端之家收集整理的这篇文章主要介绍了Postgresql (psql) .psqlrc技巧和窍门前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

Set all null fields to NULL:

\pset null 'NULL'

After this,the query results look like this:

select 'test' as test_text,null as test_null;
 test_text | test_null
-----------+-----------
 test| NULL
(1 row)

Set the command history file names for each host and database:

\set@H_301_27@ HISTFILE ~/@H_301_27@.psql_history- :HOST - :DBNAME

After this,the history file naming look like this:

.psql_history-alpha-testdb
.psql_history-localhost-test
.psql_history-10.20.10.101-production
...

Set the number of commands to store in the command history:@H_301_27@

\set@H_301_27@ HISTSIZE 2000

Set timing on and see how long query took:@H_301_27@

\timing

psql prompt can be customized to your preference:@H_301_27@

\set@H_301_27@ PROMPT1 '(%n@%M:%>) [%/] > ' \set@H_301_27@ PROMPT2 ''

After this,the PROMPT1 look like this:

(wwwuser@alpha:5432) [webdb] > 

And PROMPT2 is empty.
Complete information can be found here,under prompting.

Set client encoding:

\encoding unicode

Final .psqlrc file look like this:@H_301_27@

'NULL' \set@H_301_27@ HISTFILE ~/@H_301_27@.psql_history- :HOST - :DBNAME \set@H_301_27@ HISTSIZE 2000 \timing \set@H_301_27@ PROMPT1 '' \encoding unicode

One additional tip is to add less to PAGER environment variable if you want to use less rather than more. So simply add following row to profile (/etc/profile or ~/.profile):

export@H_301_27@ PAGER=less@H_301_27@

猜你在找的Postgre SQL相关文章