显示和设置该连接当前运行参数
最近更新时间: 2024-10-17 17:10:00
- 显示当前连接的运行参数。
postgres=# SELECT CURRENT_USER;
current_user
--------------
tbase
(1 row)
postgres=# show search_path ;
search_path
----------------
"$user",public
(1 row)
postgres=# show work_mem ;
work_mem
----------
4MB
(1 row)
- 设置当前连接的运行参数。
postgres=# set search_path ="$user",public,pg_catalog;
SET
postgres=# set work_mem = '8MB';
SET
- 打开和关闭显示每个sql语句执行的时间。
postgres=# \timing on
Timing is on.
postgres=# select count(1) from tbase;
count
-------
10000
(1 row)
Time: 5.139 ms
postgres=# \timing off
Timing is off.
postgres=# select count(1) from tbase;
count
-------
10000
(1 row)
- 打开和关闭显示每个快捷操作符实际运行的sql语句。
postgres=# \set ECHO_HIDDEN on
postgres=# \dt
********* QUERY **********
SELECT n.nspname as "Schema",
c.relname as "Name",
CASE c.relkind WHEN 'r' THEN 'table' WHEN 'v' THEN 'view' WHEN 'm' THEN 'materialized view' WHEN 'i' THEN 'index' WHEN 'S' THEN 'sequence' WHEN 's' THEN 'special' WHEN 'f' THEN 'foreign table' END as "Type",
pg_catalog.pg_get_userbyid(c.relowner) as "Owner"
FROM pg_catalog.pg_class c
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
WHERE c.relkind IN ('r','')
AND n.nspname <> 'pg_catalog'
AND n.nspname <> 'information_schema'
AND n.nspname !~ '^pg_toast'
AND pg_catalog.pg_table_is_visible(c.oid)
ORDER BY 1,2;
**************************
List of relations
Schema | Name | Type | Owner
--------+--------------+-------+-------
public | t_time_range | table | tbase
public | tbase | table | tbase
(2 rows)
postgres=# \set ECHO_HIDDEN off
postgres=# \dt
List of relations
Schema | Name | Type | Owner
--------+--------------+-------+-------
public | t_time_range | table | tbase
public | tbase | table | tbase
(2 rows)
- 配置输出结果为HTML格式
postgres=# \pset format html
Output format is html.
postgres=# \d tbase
<table border="1">
<caption>Table "public.tbase"</caption>
<tr>
<th align="center">Column</th>
<th align="center">Type</th>
<th align="center">Modifiers</th>
</tr>
<tr valign="top">
<td align="left">id</td>
<td align="left">integer</td>
<td align="left">
</tr>
<tr valign="top">
<td align="left">mc</td>
<td align="left">text</td>
<td align="left">
</tr>
</table>
恢复为对齐模式
postgres=# \pset format aligned
Output format is aligned.
postgres=# \d tbase
Table "public.tbase"
Column | Type | Modifiers
--------+---------+-----------
id | integer |
mc | text |
- 配置行列显示格式
postgres=# \x on
Expanded display is on.
postgres=# select * from tbase where id=1;
-[ RECORD 1 ]
id | 1
mc | 1
-[ RECORD 2 ]
id | 1
mc | 2
-[ RECORD 3 ]
id | 1
mc | 2
postgres=# \x off
Expanded display is off.
postgres=# select * from tbase where id=1;
id | mc
----+----
1 | 1
1 | 2
1 | 2
(3 rows)
- 显示和配置客户端编码
postgres=# \encoding
UTF8
#配置客户端编码为SQL_ASCII
postgres=# \encoding sql_ascii
postgres=# \encoding
SQL_ASCII