Skip to content

Commit b2c17d4

Browse files
digoal zhoudigoal zhou
authored andcommitted
new doc
1 parent f7d1141 commit b2c17d4

File tree

7 files changed

+567
-17
lines changed

7 files changed

+567
-17
lines changed

202101/20210130_02.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ ssh登录ip,自动输入密码, vim ~/sshlogin
4646
```
4747
#!/usr/bin/expect #使用expect解释器
4848
49-
spawn ssh [email protected] #开启一个进程ssh
49+
spawn ssh -o TCPKeepAlive=yes -o ServerAliveInterval=15 -o ServerAliveCountMax=3 [email protected] #开启一个进程ssh
5050
expect {
5151
"yes/no" { send "yes\r"; exp_continue } #当匹配到"yes/no时,就是需要你输入yes or no时,发送yes字符串,\r带表回车;exp_continue继续匹配
5252
"password:" { send "sanshen6677\r" } #当匹配到password,就是该输入密码,发送密码,并\r回车。注意{之前要有空格。

202101/20210130_04.md

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -88,20 +88,20 @@ OutSystems在低代码界激起的水花被同期接力到了国内的资本市
8888
- 随随便便就上百个表的JOIN性能
8989

9090

91-
## 解法
92-
1、无法律风险
91+
## PG解法
92+
### 1、无法律风险
9393

9494
不论是你来分发, 还是用户自己安装, 都没有法律风险.
9595

96-
2、免费
96+
### 2、免费
9797

9898
不要钱很重要
9999

100-
3、多租户
100+
### 3、多租户
101101

102102
schema/database 级别多租户
103103

104-
4、多模
104+
### 4、多模
105105

106106
json|xml|hstore|cube schemaless支持
107107
图式查询支持
@@ -120,15 +120,16 @@ GIS地理信息数据类型和索引(PostGIS)
120120
流订阅
121121
10余种索引(btree,hash,gin,gist,spgist,brin,bloom,rum,pase(阿里云),zombodb)
122122

123-
5、大量国产数据库都基于PG
123+
### 5、大量国产数据库都基于PG
124124

125125
华为opengauss
126126
阿里polardb pg-o
127127
腾讯tbase, cynosdb
128128
亚信antdb
129129
中兴goldendb
130+
阿里云adb pg
130131

131-
6、可扩展插件, 打出垂直行业技术壁垒
132+
### 6、可扩展插件, 打出垂直行业技术壁垒
132133

133134
不需要修改内核, 通过API能支持数据库的功能扩展, 在数据库中支持行业特性, 例如:
134135
rdkit, 医疗、化学行业, 化学分子式计算
@@ -141,45 +142,45 @@ timescaledb, IoT行业时序数据处理
141142
同时开源提供了很多插件可直接使用.
142143
https://pgxn.org/
143144

144-
7、横向扩展
145+
### 7、横向扩展
145146

146147
Citus, 可以横向扩展到PB级别
147148

148-
8、平滑加减字段, 修改字段长度
149+
### 8、平滑加减字段, 修改字段长度
149150

150151
低代码下, 数据模型的要求是最灵活的, 匹配用户定制化的功能模块, 加减字段, 修改字段一定很频繁.
151152
PG支持平滑加减,修改字段长度(大量不需要rewrite)
152153

153-
9、在线加索引
154+
### 9、在线加索引
154155

155156
低代码下, 数据模型的要求是最灵活的, 匹配用户定制化的功能模块, 平滑加索引很重要.
156157
如果加个索引要锁表, 是不是要疯掉,根本无法满足敏捷要求.
157158

158-
10、自动推荐索引
159+
### 10、自动推荐索引
159160

160161
低代码下, 数据模型的要求是最灵活的, 匹配用户定制化的功能模块, ORM提供的SQL变化无穷, 支持自动推荐索引, 大量简化SaaS厂商优化工作量.
161162

162-
10、在线垃圾回收
163+
### 11、在线垃圾回收
163164

164165
不堵塞用户操作.
165166

166-
11、优化器, 高级优化器
167+
### 12、优化器, 高级优化器
167168

168169
低代码下, 数据模型的要求是最灵活的, 匹配用户定制化的功能模块, ORM提供的SQL变化无穷, 复杂SQL能不能优化好, 是很重要的能力.
169170
支持数百种数据访问方法, 支持CBO和遗传算法(超多表JOIN优化), 支持扩展aqo(基于机器学习的超多表JOIN动态优化)
170171

171-
12、并行计算
172+
### 13、并行计算
172173

173174
跑个报表是多么低的要求啊, 但是怎么才能快, 天下武功唯快不破.
174175
PG支持几乎任何SQL, 任何NODE都能用多CPU并行.
175176
10亿数据量,聚合只需要2秒.
176177
[《PostgreSQL 并行计算解说 汇总》](../201903/20190318_05.md)
177178

178-
13、稳如泰山
179+
### 14、稳如泰山
179180

180181
PG 的稳定性是产业界出了名的, 稳如狗.
181182

182-
14、功能和Oracle一个级别, 在垂直领域甚至超过Oracle
183+
### 15、功能和Oracle一个级别, 在垂直领域甚至超过Oracle
183184

184185
例如odoo是全球最流行的开源SaaS软件, 指定使用PostgreSQL数据库.
185186

202101/20210130_05.md

Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
## PostgreSQL 命令行 top 工具 - pg_activity
2+
3+
### 作者
4+
digoal
5+
6+
### 日期
7+
2021-01-30
8+
9+
### 标签
10+
PostgreSQL , top , pg_activity
11+
12+
----
13+
14+
## 背景
15+
![pg_activity](https://github.com/dalibo/pg_activity/raw/master/docs/imgs/logo-horizontal.png)
16+
17+
Command line tool for PostgreSQL server activity monitoring.
18+
19+
[![Latest PyPI version](https://img.shields.io/pypi/v/pg_activity.svg)](https://pypi.python.org/pypi/pg_activity)
20+
[![Build Status](https://travis-ci.com/dalibo/pg_activity.svg?branch=master)](https://travis-ci.com/dalibo/pg_activity)
21+
22+
![pg_activity screenshot](https://raw.github.com/dalibo/pg_activity/master/docs/imgs/screenshot.png)
23+
24+
Installation
25+
------------
26+
27+
`pg_activity` requires Python 3.6 or later. It can be installed using pip
28+
(available, e.g., as `apt install python3-pip` on Debian-based distributions):
29+
30+
$ python3 -m pip install pg_activity psycopg2-binary
31+
32+
or directly from your Linux distribution, if available, e.g.:
33+
34+
$ sudo apt install pg-activity
35+
36+
37+
Usage
38+
-----
39+
40+
`pg_activity` works locally or remotely. In local execution context, to obtain
41+
sufficient rights to display system informations, the system user running
42+
`pg_activity` must be the same user running postgresql server (`postgres` by
43+
default), or have more rights like `root`. Otherwise, `pg_activity` can fallback
44+
to a degraded mode without displaying system informations. On the same way,
45+
PostgreSQL user used to connect to the database must be super-user.
46+
ex:
47+
48+
sudo -u postgres pg_activity -U postgres
49+
50+
Options
51+
-------
52+
53+
pg_activity [options]
54+
55+
Options:
56+
--version Show program's version number and exit
57+
-U USERNAME, --username=USERNAME
58+
Database user name (default: "postgres").
59+
-p PORT, --port=PORT Database server port (default: "5432").
60+
-h HOSTNAME, --host=HOSTNAME
61+
Database server host or socket directory (default:
62+
"localhost").
63+
-d DBNAME, --dbname=DBNAME
64+
Database name to connect to (default: "postgres").
65+
--blocksize=BLOCKSIZE Filesystem blocksize (default: 4096).
66+
--rds Enable support for AWS RDS.
67+
--output=FILEPATH Store running queries as CSV.
68+
--help Show this help message and exit.
69+
--no-db-size Skip total size of DB.
70+
--min-duration Don't display queries with smaller than specified
71+
duration (in seconds).
72+
--verbose-mode=VERBOSE_MODE
73+
Queries display mode. Values: 1-TRUNCATED,
74+
2-FULL(default), 3-INDENTED
75+
--duration-mode=DURATION_MODE
76+
Duration mode. Values: 1-QUERY(default),
77+
2-TRANSACTION, 3-BACKEND
78+
79+
80+
Display options, you can exclude some columns by using them :
81+
--no-database Disable DATABASE.
82+
--no-user Disable USER.
83+
--no-client Disable CLIENT.
84+
--no-cpu Disable CPU%.
85+
--no-mem Disable MEM%.
86+
--no-read Disable READ/s.
87+
--no-write Disable WRITE/s.
88+
--no-time Disable TIME+.
89+
--no-wait Disable W.
90+
--no-app-name Disable App.
91+
92+
93+
Notes
94+
-----
95+
96+
Length of SQL query text that `pg_activity` reports relies on PostgreSQL
97+
parameter `track_activity_query_size`. Default value is `1024` (expressed in
98+
bytes). If your SQL query text look truncated, you should increase
99+
`track_activity_query_size`.
100+
101+
102+
Interactives commands
103+
---------------------
104+
105+
| Key | Action |
106+
|-----------|------------------------------------------------------------------|
107+
| `r` | Sort by READ/s, descending |
108+
| `w` | Sort by WRITE/s, descending |
109+
| `c` | Sort by CPU%, descending |
110+
| `m` | Sort by MEM%, descending |
111+
| `t` | Sort by TIME+, descending |
112+
| `T` | Change duration mode: query, transaction, backend |
113+
| `Space` | Pause on/off |
114+
| `v` | Change queries display mode: full, indented, truncated |
115+
| `UP/DOWN` | Scroll processes list |
116+
| `k/j` | Scroll processes list |
117+
| `q` | Quit |
118+
| `+` | Increase refresh time. Maximum value : 5s |
119+
| `-` | Decrease refresh time. Minimum Value : 0.5s |
120+
| `F1/1` | Running queries list |
121+
| `F2/2` | Waiting queries list |
122+
| `F3/3` | Blocking queries list |
123+
| `h` | Help page |
124+
| `R` | Refresh |
125+
| `D` | Refresh Database Size (including when --no-dbzise option applied)|
126+
127+
Navigation mode
128+
---------------
129+
130+
| Key | Action |
131+
|------------|-----------------------------------------------|
132+
| `UP`/`k` | Move up the cursor |
133+
| `DOWN`/`j` | Move down the cursor |
134+
| `K` | Terminate the current backend/tagged backends |
135+
| `C` | Cancel the current backend/tagged backends |
136+
| `Space` | Tag or untag the process |
137+
| `q` | Quit |
138+
| `Other` | Back to activity |
139+
140+
FAQ
141+
---
142+
143+
**I can't see my queries only TPS is shown**
144+
145+
`pg_activity` scans the view `pg_stat_activity` with a user defined refresh
146+
time comprised between O.5 and 5 seconds. It can be modified in the interface
147+
with the `+` and `-` keys. Any query executed between two scans won't be
148+
displayed.
149+
150+
151+
What is more, `pg_activity` uses different queries to get :
152+
153+
* settings from `pg_settings`
154+
* version info using `version()`
155+
* queries and number of connections from `pg_stat_activity`
156+
* locks from `pg_locks`
157+
* tps from `pg_database` using `pg_stat_get_db_xact_commit()` and
158+
`pg_stat_get_db_xact_rollback()`
159+
* and more ( eg : `pg_cancel_backend()` and `pg_terminate_backend()` )
160+
161+
Thoses queries cannot be seen in the query tab because all queries issued from
162+
the `pg_activity` backend are considered as noise and are not displayed . On
163+
the other hand, the transactions used to get the info for `pg_activity`'s
164+
reporting are still accounted for by postgres in `pg_stat_get_db_xact_commit()`
165+
and `pg_stat_get_db_xact_commit()`. Therefore `pg_activity` will display a non
166+
zero TPS even with no activity on the database, and/or no activity displayed on
167+
screen.
168+
169+
170+
#### [PostgreSQL 许愿链接](https://github.com/digoal/blog/issues/76 "269ac3d1c492e938c0191101c7238216")
171+
您的愿望将传达给PG kernel hacker、数据库厂商等, 帮助提高数据库产品质量和功能, 说不定下一个PG版本就有您提出的功能点. 针对非常好的提议,奖励限量版PG文化衫、纪念品、贴纸、PG热门书籍等,奖品丰富,快来许愿。[开不开森](https://github.com/digoal/blog/issues/76 "269ac3d1c492e938c0191101c7238216").
172+
173+
174+
#### [9.9元购买3个月阿里云RDS PostgreSQL实例](https://www.aliyun.com/database/postgresqlactivity "57258f76c37864c6e6d23383d05714ea")
175+
176+
177+
#### [PostgreSQL 解决方案集合](https://yq.aliyun.com/topic/118 "40cff096e9ed7122c512b35d8561d9c8")
178+
179+
180+
#### [德哥 / digoal's github - 公益是一辈子的事.](https://github.com/digoal/blog/blob/master/README.md "22709685feb7cab07d30f30387f0a9ae")
181+
182+
183+
![digoal's wechat](../pic/digoal_weixin.jpg "f7ad92eeba24523fd47a6e1a0e691b59")
184+

202101/20210130_06.md

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
## Linux Mac ssh 客户端长连接防断连 - tcp心跳 TCPKeepAlive,ServerAliveInterval,ServerAliveCountMax
2+
3+
### 作者
4+
digoal
5+
6+
### 日期
7+
2021-01-30
8+
9+
### 标签
10+
PostgreSQL , ssh
11+
12+
----
13+
14+
## 背景
15+
securecrt 可以设置会话option: send protocol no-op 来防止ssh连接长时间没有数据包时被断开.
16+
17+
linux macos自带的ssh客户端也有同样的参数:
18+
19+
ServerAliveInterval
20+
ServerAliveCountMax
21+
TCPKeepAlive
22+
23+
实际上PostgreSQL数据库也有类似设置参数
24+
25+
```
26+
# - TCP settings -
27+
# see "man tcp" for details
28+
29+
#tcp_keepalives_idle = 0 # TCP_KEEPIDLE, in seconds;
30+
# 0 selects the system default
31+
#tcp_keepalives_interval = 0 # TCP_KEEPINTVL, in seconds;
32+
# 0 selects the system default
33+
#tcp_keepalives_count = 0 # TCP_KEEPCNT;
34+
# 0 selects the system default
35+
#tcp_user_timeout = 0 # TCP_USER_TIMEOUT, in milliseconds;
36+
# 0 selects the system default
37+
```
38+
39+
例子:
40+
41+
```
42+
ssh -o TCPKeepAlive=yes -o ServerAliveInterval=15 -o ServerAliveCountMax=3 [email protected]
43+
```
44+
45+
man ssh_config
46+
47+
48+
TCPKeepAlive
49+
Specifies whether the system should send TCP keepalive messages to the other side. If they are sent, death of the connection or crash of one of the machines will be properly noticed. However, this means that connections will die if the route is down temporarily, and some people find it annoying.
50+
51+
The default is yes (to send TCP keepalive messages), and the client will notice if the network goes down or the remote host dies. This is important in scripts, and many users want it too.
52+
53+
To disable TCP keepalive messages, the value should be set to no. See also ServerAliveInterval for protocol-level keepalives.
54+
55+
56+
ServerAliveCountMax
57+
Sets the number of server alive messages (see below) which may be sent without ssh(1) receiving any messages back from the server. If this threshold is reached while server alive messages are being sent, ssh will disconnect from the server, terminating the session. It is important to note that the use of server alive messages is very different from TCPKeepAlive (below). The server alive messages are sent through the encrypted channel and therefore will not be spoofable. The TCP keepalive option enabled by TCPKeepAlive is spoofable. The server alive mechanism is valuable when the client or server depend on knowing when a connection has become unresponsive.
58+
59+
The default value is 3. If, for example, ServerAliveInterval (see below) is set to 15 and ServerAliveCountMax is left at the default, if the server becomes unresponsive, ssh will disconnect after approximately 45 seconds.
60+
61+
ServerAliveInterval
62+
Sets a timeout interval in seconds after which if no data has been received from the server, ssh(1) will send a message through the encrypted channel to request a response from the server. The default is 0, indicating that these messages will not be sent to the server.
63+
64+
65+
66+
#### [PostgreSQL 许愿链接](https://github.com/digoal/blog/issues/76 "269ac3d1c492e938c0191101c7238216")
67+
您的愿望将传达给PG kernel hacker、数据库厂商等, 帮助提高数据库产品质量和功能, 说不定下一个PG版本就有您提出的功能点. 针对非常好的提议,奖励限量版PG文化衫、纪念品、贴纸、PG热门书籍等,奖品丰富,快来许愿。[开不开森](https://github.com/digoal/blog/issues/76 "269ac3d1c492e938c0191101c7238216").
68+
69+
70+
#### [9.9元购买3个月阿里云RDS PostgreSQL实例](https://www.aliyun.com/database/postgresqlactivity "57258f76c37864c6e6d23383d05714ea")
71+
72+
73+
#### [PostgreSQL 解决方案集合](https://yq.aliyun.com/topic/118 "40cff096e9ed7122c512b35d8561d9c8")
74+
75+
76+
#### [德哥 / digoal's github - 公益是一辈子的事.](https://github.com/digoal/blog/blob/master/README.md "22709685feb7cab07d30f30387f0a9ae")
77+
78+
79+
![digoal's wechat](../pic/digoal_weixin.jpg "f7ad92eeba24523fd47a6e1a0e691b59")
80+

0 commit comments

Comments
 (0)