Skip to content

Commit f6ae796

Browse files
committed
faq、features翻译
1 parent edfc525 commit f6ae796

File tree

2 files changed

+107
-144
lines changed

2 files changed

+107
-144
lines changed

faq.md

+70-95
Original file line numberDiff line numberDiff line change
@@ -5,164 +5,139 @@ title: PgBouncer FAQ
55

66
# PgBouncer FAQ
77

8-
## How to connect to PgBouncer?
8+
## 如何连接到PgBouncer?
99

10-
PgBouncer acts as Postgres server, so simply point your client to
11-
PgBouncer port.
10+
PgBouncer就像Postgres server,所以只需简单的指定您的客户端到PgBouncer端口。
1211

13-
## How to load-balance queries between several servers?
12+
## 如何在几个服务器之间均衡的加载查询?
1413

15-
PgBouncer does not have internal multi-host configuration.
16-
It is possible via some external tools:
14+
PgBouncer没有内部多主机配置。
15+
可以通过一些额外的工具实现:
1716

18-
1. DNS round-robin. Use several IPs behind one DNS name. PgBouncer does
19-
not look up DNS each time new connection is launched. Instead it
20-
caches all IPs and does round-robin internally. Note: if there is
21-
more than 8 IPs behind one name, the DNS backend must support EDNS0
22-
protocol. See README for details.
17+
1. DNS循环。在一个DNS名称后面使用几个IP。每次新的连接启动时,PgBouncer都不会查找DNS。
18+
相反,它缓存所有IP并在内部循环。注意:如果一个名称后面有超过8个IP,
19+
则DNS后端必须支持EDNS0协议。详见README。
2320

24-
2. Use a TCP connection load-balancer. Either
25-
[LVS](http://www.linuxvirtualserver.org/) or
26-
[HAProxy](http://www.haproxy.org/) seem to be good choices. On
27-
PgBouncer side it may be good idea to make `server_lifetime` smaller
28-
and also turn `server_round_robin` on - by default idle connections
29-
are reused by LIFO algorithm which may work not so well when
30-
load-balancing is needed.
21+
2. 使用TCP连接负载均衡器。[LVS](http://www.linuxvirtualserver.org/)或者
22+
[HAProxy](http://www.haproxy.org/)是较好的选择。
23+
在PgBouncer方面,最好让 `server_lifetime` 更小,也可以把 `server_round_robin` 打开 -
24+
默认情况下,空闲连接由LIFO算法重用,当需要负载均衡时,这可能不太好。
3125

32-
## How to failover
26+
## 如何进行故障转移
3327

34-
PgBouncer does not have internal failover-host configuration nor detection.
35-
It is possible via some external tools:
28+
PgBouncer没有内部的故障切换主机配置也没有检测。
29+
可以通过一些外部工具实现:
3630

37-
1. DNS reconfiguration - when ip behind DNS name is reconfigured, pgbouncer
38-
will reconnect to new server. This behaviour can be tuned via 2
39-
config parameters - **dns_max_ttl** tunes lifetime for one hostname,
40-
and **dns_zone_check_period** tunes how often zone SOA will be
41-
queried for changes. If zone SOA record has changed, pgbouncer
42-
will re-query all hostnames under that zone.
31+
1. DNS重新配置 - 当重新配置DNS名称后的ip时,pgbouncer将重新连接到新服务器。
32+
这个行为可以通过2个配置参数进行调整- **dns_max_ttl** 调整一个主机名的生命周期,
33+
**dns_zone_check_period** 调整区域SOA查询更改的频率。
34+
如果区域SOA记录已更改,pgbouncer将重新查询该区域下的所有主机名。
4335

44-
2. Write new host to config and let PgBouncer reload it - send SIGHUP
45-
or use RELOAD; command on console. PgBouncer will detect changed
46-
host config and reconnect to new server.
36+
2. 写新的主机名到配置并让PgBouncer重新加载它 - 在控制台发送SIGHUP或使用RELOAD;命令。
37+
PgBouncer将检测修改后的主机配置并重连接到新的服务器。
38+
4739

48-
## How to use SSL connections with PgBouncer?
40+
## PgBouncer如何使用SSL连接?
4941

50-
Since version 1.7, PgBouncer has built-in support for TLS. Just configure it.
42+
自版本1.7以来,PgBouncer对TLS有了内建的支持。只需要配置它。
5143

52-
[ Old answer for older PgBouncer versions. ]
44+
[ 较老PgBouncer版本的回答 ]
5345

54-
Use [Stunnel](https://www.stunnel.org/). Since version 4.27 it supports
55-
PostgreSQL protocol for both client and server side. It is activated by
56-
setting `protocol=pgsql`.
46+
使用[Stunnel](https://www.stunnel.org/)。自版本4.27以来,
47+
它在客户端和服务器端都支持PostgreSQL协议。通过设置 `protocol=pgsql` 激活它。
5748

58-
Alternative is to use Stunnel on both sides of connection, then the
59-
protocol support is not needed.
49+
可选的是在连接的两端都使用Stunnel,然后就不需要协议支持了。
6050

61-
## How to use prepared statements with session pooling?
51+
## 会话池如何使用预备语句?
6252

63-
In session pooling mode, the reset query must clean old prepared
64-
statements. This can be achieved by `server_reset_query = DISCARD ALL;`
65-
or at least to `DEALLOCATE ALL;`
53+
在会话池模式,重置查询必须清理老的预备语句。这可以通过
54+
`server_reset_query = DISCARD ALL;` 或至少是 `DEALLOCATE ALL;` 来实现。
6655

67-
## How to use prepared statements with transaction pooling?
56+
## 事务池如何使用预备语句?
6857

69-
To make prepared statements work in this mode would need PgBouncer to
70-
keep track of them internally, which it does not do. So only way to keep
71-
using PgBouncer in this mode is to disable prepared statements in the
72-
client.
58+
要使预备语句在该模式中可用,将需要PgBouncer在内部保持追踪它们。
59+
所以在这种模式下保持使用PgBouncer的唯一方法是在客户端禁用预备语句。
7360

74-
### Disabling prepared statements in JDBC
61+
### 在JDBC中禁用预备语句
7562

76-
The proper way to do it for JDBC is adding `prepareThreshold=0`
77-
parameter to connect string.
63+
适合JDBC的方式是添加 `prepareThreshold=0` 参数到连接字符串。
7864

79-
### Disabling prepared statements in PHP/PDO
65+
### 在PHP/PDO中禁用预备语句
8066

81-
To disable use of server-side prepared statements, the PDO attribute
82-
`PDO::ATTR_EMULATE_PREPARES` must be set to `true`. Either at
83-
connect-time:
67+
要禁用服务器端的预备语句,PD0属性 `PDO::ATTR_EMULATE_PREPARES` 必须设置为
68+
`true`。在客户端连接时设置:
8469

8570
$db = new PDO("dsn", "user", "pass", array(PDO::ATTR_EMULATE_PREPARES => true));
8671

87-
or later:
72+
或者稍后设置:
8873

8974
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
9075

91-
## How to upgrade PgBouncer without dropping connections?
76+
## 在不删除连接的情况下如何升级PgBouncer?
9277

93-
[ This cannot be done with TLS connections. ]
78+
[ 这不能通过TLS连接完成。]
9479

95-
This is as easy as launching new PgBouncer process with `-R` switch and
96-
same config:
80+
这和使用 `-R` 开关加载新的PgBouncer进程一样简单,并且配置相同:
9781

9882
$ pgbouncer -R -d config.ini
9983

100-
The `-R` (reboot) switch makes new process connect to console of the old
101-
process (dbname=pgbouncer) via unix socket and issue following commands:
84+
`-R` (reboot)开关通过unix套接字让新的进程连接到老进程(dbname=pgbouncer)的控制台,
85+
并发出下列命令:
10286

10387
SUSPEND;
10488
SHOW FDS;
10589
SHUTDOWN;
10690

107-
After that if new one notices old one gone it resumes work with old
108-
connections. The magic happens during `SHOW FDS` command which
109-
transports actual file descriptors to new process.
91+
之后,如果新的进程发现旧进程已经结束了就恢复老的连接的工作。
92+
魔法发生在 `SHOW FDS` 命令期间,该命令传送实际的文件描述符给新的进程。
11093

111-
If the takeover does not work for whatever reason, the new process can
112-
be simply killed, old one notices this and resumes work.
94+
如果接替工作不能正常进行,那么新的进程会被杀死,老的进程继续工作。
11395

114-
## How to know which client is on which server connection?
96+
## 如何知道哪个客户端连接在哪个服务器上?
11597

116-
Use SHOW CLIENTS and SHOW SERVERS views on console.
98+
在控制台使用SHOW CLIENTS和SHOW SERVERS视图。
11799

118-
1. Use `ptr` and `link` to map local client connection to server
119-
connection.
100+
1. 使用 `ptr``link` 映射本地客户端到服务器的连接。
120101

121-
2. Use `addr` and `port` of client connection to identify TCP
122-
connection from client.
102+
2. 使用客户端连接的 `addr``port` 标识来自客户端的TCP连接。
123103

124-
3. Use `local_addr` and `local_port` to identify TCP connection to
125-
server.
104+
3. 使用 `local_addr``local_port` 标识到服务器的TCP连接。
126105

127-
### Overview of important fields in SHOW CLIENTS
106+
### SHOW CLIENTS 中重要字段的概览
128107

129108
addr, port
130-
: source address of client connection
109+
: 客户端连接的源地址
131110

132111
local_addr, local_port
133-
: local endpoint of client connection
112+
: 客户端连接的本地端点
134113

135114
ptr
136-
: unique id for this connection
115+
: 此连接的唯一id
137116

138117
link
139-
: unique id for server connection this client connection is currently linked to
118+
: 该客户端当前连接到的服务器连接的唯一id
140119

141-
### Overview of important fields in SHOW SERVERS
120+
### SHOW SERVERS 中重要字段的概览
142121

143122
addr, port
144-
: server address pgbouncer connects to
123+
: pgbouncer连接到的服务器地址
145124

146125
local_addr, local_port
147-
: connections local endpoint
126+
: 连接本地端点
148127

149128
ptr
150-
: unique id for this connection
129+
: 此连接的唯一id
151130

152131
link
153-
: unique id for client connection this server connection is currently linked to
132+
: 该服务器当前连接到的客户端连接的唯一id
154133

155-
## Should PgBouncer be installed on webserver or database server?
134+
## PgBouncer应该安装在webserver还是数据库服务器上?
156135

157-
It depends. Installing on webserver is good when short-connections are
158-
used, then the connection setup latency is minimised - TCP requires
159-
couple of packet roundtrips before connection is usable. Installing on
160-
database server is good when there are many different hosts (eg.
161-
webservers) connecting to it, then their connections can be optimised
162-
together.
136+
这个要看情况。当使用短的连接,连接设置延迟最小化——在连接可用前TCP需要几个包往返时,
137+
安装在webserver上是好的。当有许多不同的主机(比如webserver)连接,
138+
并且它们的连接可以一起优化时,安装在数据库服务器上是好的。
163139

164-
It is also possible to install PgBouncer on both webserver and database
165-
servers. Only negative aspect of that is that each PgBouncer hop adds
166-
small amount of latency to each query. So it’s probably best to simply
167-
test whether the payoff is worth the cost.
140+
在webserver和数据库服务器上都安装PgBouncer也是可以的。
141+
唯一不好的一点是每个PgBouncer会给每个查询增加一点延迟。
142+
所以最好是简单测试下是不是值的这样做。
168143

features.md

+37-49
Original file line numberDiff line numberDiff line change
@@ -7,74 +7,62 @@ title: PgBouncer features
77

88
- Several levels of brutality when rotating connections:
99

10-
Session pooling
11-
: Most polite method. When client connects, a server connection
12-
will be assigned to it for the whole duration it stays
13-
connected. When client disconnects, the server connection will
14-
be put back into pool.
10+
Session pooling/会话连接池
11+
: 最礼貌的方法。在客户端连接的时候,在它的连接生命期内,
12+
会给它赋予一个服务器连接。在客户端断开的时候,服务器连接会放回到连接池中。
1513

16-
Transaction pooling
17-
: Server connection is assigned to client only during a
18-
transaction. When PgBouncer notices that transaction is over,
19-
the server will be put back into pool. This is a hack as it
20-
breaks application expectations of backend connection. You can
21-
use it only when application cooperates with such usage by not
22-
using features that can break. See the table below for breaking
23-
features.
14+
Transaction pooling/事务连接池
15+
: 仅在事务期间将服务器连接分配给客户端。当PgBouncer注意到该事务结束时,
16+
服务器将被放回到池中。它打破了应用程序对后端连接的期望。
17+
只有在应用配合这样的使用模式,没有使用会破坏这种使用模式的时候才能用这个连接方式。
18+
参阅下表获取会破坏这种模式的特性。
2419

25-
Statement pooling
26-
: Most aggressive method. This is transaction pooling with a twist
27-
- multi-statement transactions are disallowed. This is meant to
28-
enforce "autocommit" mode on client, mostly targeted for
29-
PL/Proxy.
20+
Statement pooling/语句连接池
21+
: 最积极的方法。这是一个事务池的一个扭曲的变种——不允许多语句事务。
22+
这意味着在客户端上强制 "autocommit" 模式,主要针对PL/Proxy。
3023

31-
- Low memory requirements (2k per connection by default). This is due
32-
to the fact that PgBouncer does not need to see full packet at
33-
once.
24+
- 内存需求低(默认是每个连接2K)。这是因为PgBouncer不需要一次性查看所有包。
3425

35-
- It is not tied to one backend server, the destination databases can
36-
reside on different hosts.
26+
- 它不绑定到一个后端服务器,目标数据库可以位于不同的主机上。
3727

38-
- Supports online reconfiguration for most of the settings.
28+
- 支持在线重新配置大部分设置。
3929

40-
- Supports online restart/upgrade without dropping client connections.
30+
- 支持在线重启/升级,而不用删除客户端连接。
4131

42-
- Supports protocol V3 only, so backend version must be \>= 7.4.
32+
- 仅支持协议V3,所以后端版本必须 \>= 7.4
4333

4434

45-
## SQL feature map for pooling modes
35+
## 池模式的SQL特性映射
4636

47-
Following table list various PostgreSQL features and whether they are
48-
ompatible with PgBouncer pooling modes. Note that 'transaction'
49-
pooling breaks client expectations of server and can be used only
50-
if application cooperates by not using non-working features.
37+
下面的表列出了各种PostgreSQL特性和它们是否能与PgBouncer池模式一起共用。
38+
请注意, '事务' 池打破了客户端对服务器的期望,
39+
只有在应用程序不使用非工作功能的情况下才能使用。
5140

5241
|----------------------------------+-----------------+---------------------|
53-
| Feature | Session pooling | Transaction pooling |
42+
| 特性 | 会话池 | 事务池 |
5443
|----------------------------------+-----------------+---------------------|
55-
| Startup parameters | Yes [^0] | Yes [^0] |
56-
| SET/RESET | Yes | Never |
57-
| LISTEN/NOTIFY | Yes | Never |
58-
| WITHOUT HOLD CURSOR | Yes | Yes |
59-
| WITH HOLD CURSOR | Yes [^1] | Never |
60-
| Protocol-level prepared plans | Yes [^1] | No [^2] |
61-
| PREPARE / DEALLOCATE | Yes [^1] | Never |
62-
| ON COMMIT DROP temp tables | Yes | Yes |
63-
| PRESERVE/DELETE ROWS temp tables | Yes [^1] | Never |
64-
| Cached plan reset | Yes [^1] | Yes [^1] |
65-
| LOAD statement | Yes | Never |
44+
| 启动参数 | 支持 [^0] | 支持 [^0] |
45+
| SET/RESET | 支持 | 从不支持 |
46+
| LISTEN/NOTIFY | 支持 | 从不支持 |
47+
| WITHOUT HOLD CURSOR | 支持 | 支持 |
48+
| WITH HOLD CURSOR | 支持 [^1] | 从不支持 |
49+
| 协议级准备计划 | 支持 [^1] | 不支持 [^2] |
50+
| PREPARE / DEALLOCATE | 支持 [^1] | 从不支持 |
51+
| ON COMMIT DROP temp tables | 支持 | 支持 |
52+
| PRESERVE/DELETE ROWS temp tables | 支持 [^1] | 从不支持 |
53+
| 重置缓存的计划 | 支持 [^1] | 支持 [^1] |
54+
| LOAD 语句 | 支持 | 从不支持 |
6655
|----------------------------------+-----------------+---------------------|
6756

6857
[^0]:
69-
Startup parameters are: **client_encoding**, **datestyle**, **timezone**
70-
and **standard_conforming_strings**. PgBouncer can detect their changes
71-
so it can guarantee they remain consistent for client. Available
72-
from PgBouncer 1.1.
58+
启动参数是: **client_encoding**, **datestyle**, **timezone**
59+
**standard_conforming_strings**. PgBouncer 可以检测到它们的改动,
60+
所以它可以保证这些参数对客户端保持一致。自PgBouncer 1.1开始可用。
7361

7462
[^1]:
75-
Full transparency requires PostgreSQL 8.3 and PgBouncer 1.1 with
63+
完全透明要求 PostgreSQL 8.3 PgBouncer 1.1 并设置
7664
`server_reset_query = DISCARD ALL`.
7765

7866
[^2]:
79-
It is possible to add support for that into PgBouncer.
67+
有望在PgBouncer中添加对它的支持。
8068

0 commit comments

Comments
 (0)