酷酷娱乐网

站内广告

PostgreSQL DBA(69) - Postgres tips for the average and power user

时间:2020-09-15 02:30:01   作者:酷酷娱乐网   来源:www.kukuyl.com  
内容摘要:


下面是一些有用的tips:



In psql......

下面是一些有用的tips:

In psql, tag your queries and use Ctrl+R


[local]:5432 pg12@testdb=# select * from t1 limit 1;
 id | c1 | c2 
----+----+----
  4 |  4 |  4
(1 row)
Time: 1.872 ms
[local]:5432 pg12@testdb=# select * from test limit 1;
ERROR:  relation "test" does not exist
LINE 1: select * from test limit 1;
                      ^
Time: 0.996 ms
[local]:5432 pg12@testdb=# create table test(id int);
CREATE TABLE
Time: 6.019 ms
[local]:5432 pg12@testdb=# insert into test values(1);
INSERT 0 1
Time: 2.310 ms
[local]:5432 pg12@testdb=# insert into test values(2);
INSERT 0 1
Time: 2.409 ms

这时候使用快捷键Ctrl + R,显示搜索框,输入t1,psql检索t1相关的sql并显示在界面上.


(reverse-i-search)`': 
(reverse-i-search)`t1': select * from t1 limit 1;

Better psql output
\x不够强大,可使用pspg.

Get a stack trace for an error
使用gdb在errfinish上设置断点可跟踪错误


[local]:5432 pg12@testdb=# SELECT pg_backend_pid();
 pg_backend_pid 
----------------
           1538
(1 row)
...
(gdb) b errfinish
Breakpoint 1 at 0xa65517: file elog.c, line 412.
(gdb) c
Continuing.

如出现执行错误,会在gdb中停止,利用bt可打印调用栈

参考资料
Postgres tips for the average and power user

本文章url:https://www.kukuyl.com/new/30000565.html

相关文章

本栏最新更新

本栏推荐

阅读排行

CopyRight 2018 - 2020 http://www.kukuyl.com 酷酷娱乐网 All Rights Reserved .