@@ -5,164 +5,139 @@ title: PgBouncer FAQ
5
5
6
6
# PgBouncer FAQ
7
7
8
- ## How to connect to PgBouncer ?
8
+ ## 如何连接到PgBouncer ?
9
9
10
- PgBouncer acts as Postgres server, so simply point your client to
11
- PgBouncer port.
10
+ PgBouncer就像Postgres server,所以只需简单的指定您的客户端到PgBouncer端口。
12
11
13
- ## How to load-balance queries between several servers ?
12
+ ## 如何在几个服务器之间均衡的加载查询 ?
14
13
15
- PgBouncer does not have internal multi-host configuration.
16
- It is possible via some external tools:
14
+ PgBouncer没有内部多主机配置。
15
+ 可以通过一些额外的工具实现:
17
16
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。
23
20
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算法重用,当需要负载均衡时,这可能不太好。
31
25
32
- ## How to failover
26
+ ## 如何进行故障转移
33
27
34
- PgBouncer does not have internal failover-host configuration nor detection.
35
- It is possible via some external tools:
28
+ PgBouncer没有内部的故障切换主机配置也没有检测。
29
+ 可以通过一些外部工具实现:
36
30
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将重新查询该区域下的所有主机名。
43
35
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
+
47
39
48
- ## How to use SSL connections with PgBouncer ?
40
+ ## PgBouncer如何使用SSL连接 ?
49
41
50
- Since version 1.7, PgBouncer has built-in support for TLS. Just configure it.
42
+ 自版本1.7以来,PgBouncer对TLS有了内建的支持。只需要配置它。
51
43
52
- [ Old answer for older PgBouncer versions. ]
44
+ [ 较老PgBouncer版本的回答 ]
53
45
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 ` 激活它。
57
48
58
- Alternative is to use Stunnel on both sides of connection, then the
59
- protocol support is not needed.
49
+ 可选的是在连接的两端都使用Stunnel,然后就不需要协议支持了。
60
50
61
- ## How to use prepared statements with session pooling ?
51
+ ## 会话池如何使用预备语句 ?
62
52
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; ` 来实现。
66
55
67
- ## How to use prepared statements with transaction pooling ?
56
+ ## 事务池如何使用预备语句 ?
68
57
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的唯一方法是在客户端禁用预备语句。
73
60
74
- ### Disabling prepared statements in JDBC
61
+ ### 在JDBC中禁用预备语句
75
62
76
- The proper way to do it for JDBC is adding ` prepareThreshold=0 `
77
- parameter to connect string.
63
+ 适合JDBC的方式是添加 ` prepareThreshold=0 ` 参数到连接字符串。
78
64
79
- ### Disabling prepared statements in PHP/PDO
65
+ ### 在PHP/PDO中禁用预备语句
80
66
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 ` 。在客户端连接时设置:
84
69
85
70
$db = new PDO("dsn", "user", "pass", array(PDO::ATTR_EMULATE_PREPARES => true));
86
71
87
- or later:
72
+ 或者稍后设置:
88
73
89
74
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
90
75
91
- ## How to upgrade PgBouncer without dropping connections ?
76
+ ## 在不删除连接的情况下如何升级PgBouncer ?
92
77
93
- [ This cannot be done with TLS connections. ]
78
+ [ 这不能通过TLS连接完成。 ]
94
79
95
- This is as easy as launching new PgBouncer process with ` -R ` switch and
96
- same config:
80
+ 这和使用 ` -R ` 开关加载新的PgBouncer进程一样简单,并且配置相同:
97
81
98
82
$ pgbouncer -R -d config.ini
99
83
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
+ 并发出下列命令:
102
86
103
87
SUSPEND;
104
88
SHOW FDS;
105
89
SHUTDOWN;
106
90
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 ` 命令期间,该命令传送实际的文件描述符给新的进程。
110
93
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
+ 如果接替工作不能正常进行,那么新的进程会被杀死,老的进程继续工作。
113
95
114
- ## How to know which client is on which server connection?
96
+ ## 如何知道哪个客户端连接在哪个服务器上?
115
97
116
- Use SHOW CLIENTS and SHOW SERVERS views on console.
98
+ 在控制台使用SHOW CLIENTS和SHOW SERVERS视图。
117
99
118
- 1 . Use ` ptr ` and ` link ` to map local client connection to server
119
- connection.
100
+ 1 . 使用 ` ptr ` 和 ` link ` 映射本地客户端到服务器的连接。
120
101
121
- 2 . Use ` addr ` and ` port ` of client connection to identify TCP
122
- connection from client.
102
+ 2 . 使用客户端连接的 ` addr ` 和 ` port ` 标识来自客户端的TCP连接。
123
103
124
- 3 . Use ` local_addr ` and ` local_port ` to identify TCP connection to
125
- server.
104
+ 3 . 使用 ` local_addr ` 和 ` local_port ` 标识到服务器的TCP连接。
126
105
127
- ### Overview of important fields in SHOW CLIENTS
106
+ ### SHOW CLIENTS 中重要字段的概览
128
107
129
108
addr, port
130
- : source address of client connection
109
+ : 客户端连接的源地址
131
110
132
111
local_addr, local_port
133
- : local endpoint of client connection
112
+ : 客户端连接的本地端点
134
113
135
114
ptr
136
- : unique id for this connection
115
+ : 此连接的唯一id
137
116
138
117
link
139
- : unique id for server connection this client connection is currently linked to
118
+ : 该客户端当前连接到的服务器连接的唯一id
140
119
141
- ### Overview of important fields in SHOW SERVERS
120
+ ### SHOW SERVERS 中重要字段的概览
142
121
143
122
addr, port
144
- : server address pgbouncer connects to
123
+ : pgbouncer连接到的服务器地址
145
124
146
125
local_addr, local_port
147
- : connections local endpoint
126
+ : 连接本地端点
148
127
149
128
ptr
150
- : unique id for this connection
129
+ : 此连接的唯一id
151
130
152
131
link
153
- : unique id for client connection this server connection is currently linked to
132
+ : 该服务器当前连接到的客户端连接的唯一id
154
133
155
- ## Should PgBouncer be installed on webserver or database server?
134
+ ## PgBouncer应该安装在webserver还是数据库服务器上?
156
135
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
+ 并且它们的连接可以一起优化时,安装在数据库服务器上是好的。
163
139
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
+ 所以最好是简单测试下是不是值的这样做。
168
143
0 commit comments