简体   繁体   English

postgresql可以改善多少个连接?

[英]How many connections can postgresql perform better?

I have 3 tables which are accessed every time. 我有3个表,每次都可以访问。 My PHP web page sends request to an intermediate C-language based layer which in-turn transfers the calls to postgresql. 我的PHP网页将请求发送到基于C语言的中间层,该层又将调用转移到postgresql。 However, when I browse from a single tab, all the records are fetched properly. 但是,当我从单个选项卡浏览时,所有记录均已正确获取。 But, when I make more requests from many browsers/tabs, at least half of them fails and as its an embedded domain, debugging is the real problem. 但是,当我从许多浏览器/选项卡发出更多请求时,其中至少有一半失败,并且作为嵌入式域,调试才是真正的问题。 I suspect that database connections from various browsers concurrently are put into queues, and something blunder might happen. 我怀疑来自各种浏览器的数据库连接会同时进入队列,并且可能会发生一些错误。 Could anybody please convey your thoughts on this production issue? 有人可以传达您对这个生产问题的想法吗?

Don't guess, know. 不要猜测,知道。

You can get PostgreSQL to log connect and disconnects. 您可以使PostgreSQL记录连接和断开连接。 It's probably already logging an error message for you. 它可能已经为您记录了一条错误消息。 Check the logs. 检查日志。

Difficult to say more without knowing what this "C" layer is doing. 在不知道此“ C”层正在做什么的情况下很难说更多。 You may find a connection-pool helpful. 您可能会发现连接池有帮助。 Start by looking at pgbouncer perhaps. 首先看一下pgbouncer

If you're not getting any errors from the C layer, check the Postgresql log file to see if you're getting errors in there. 如果您没有从C层收到任何错误,请检查Postgresql日志文件以查看是否在其中收到错误。

My initial guesses would be that either: 我最初的猜测是:

a) The C layer is getting connections confused between threads and doing two things with the same connection at once. a)C层使线程之间的连接混乱,并且一次使用相同的连接完成两项操作。

or b) The C layer isn't releasing connections when its done with them, so you're hitting memory limits. 或b)C层完成连接后不会释放连接,因此您遇到了内存限制。

Either way, you really need to be able to find the error before you can progress it. 无论哪种方式,您都确实需要先找到错误,然后才能进行处理。

Postgresql itself will handle lots of concurrent connections, although you'd probably want to pool them to reduce setup/teardown times of each session. 尽管您可能希望将它们合并以减少每个会话的建立/删除时间,但Postgresql本身将处理许多并发连接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM