远程 Postgresql - 非常慢

发布于 2024-10-11 06:51:35 字数 1901 浏览 1 评论 0原文

我在自己的 VPS 上设置了 PostgreSQL - 访问数据库的软件是一个名为 PokerTracker 的程序。

PokerTracker 会记录您玩在线扑克时的所有手牌和统计数据。

我希望可以从几台不同的计算机上访问它,因此决定将其安装在我的 VPS 上,经过一些小问题后,我设法让它连接,没有错误。

然而,表现却很糟糕。我已经对“远程 postgresql 慢”等进行了大量研究,但尚未找到答案,因此希望有人能够提供帮助。

需要注意的是:

我尝试执行的查询非常小。在 VPS 上本地连接时,查询会立即运行。

远程运行时,运行查询大约需要 1 分 30 秒。

VPS 运行 100MBPS,然后我连接到它的计算机位于 8MB 线路上。

两者之间的网络通信几乎是即时的,我能够很好地远程连接,没有任何延迟,并且托管了几个运行 MSSQL 的网站,并且所有查询都会立即运行,无论是远程连接还是本地连接,因此它似乎是 PostgreSQL 特有的。

我正在运行他们最新版本的软件以及与他们的软件兼容的最新版本 PostgreSQL。

该数据库是一个新数据库,几乎不包含任何数据,我运行了vacuum/analyze等都无济于事,我没有看到任何改进。

我不明白 MSSQL 如何几乎可以立即查询,但 PostgreSQL 却如此挣扎。

我能够毫无问题地远程登录到 VPS IP 上的端口 5432,正如我所说,查询确实执行,只是需要非常长的时间。

我注意到的是,当查询运行时,路由器上几乎没有使用任何带宽 - 但话又说回来,我不希望它用于简单的查询,但不确定这是否是问题所在。我现在尝试在 3 个不同的网络(包括不同的路由器)上进行远程连接,但问题仍然存在。

通过 LAN 通过另一台计算机进行远程连接是即时的。

我还编辑了 postgre conf 文件以允许更多的内存/缓冲区等,但我不认为这是问题 - 我要求它做的事情非常简单 - 它根本不应该是密集的。

谢谢, Ricky

编辑:请注意客户端和服务器都运行 Windows。

这是配置文件中的信息。

pg_hba - currently allowing all traffic:

# TYPE  DATABASE    USER        CIDR-ADDRESS          METHOD

# IPv4 local connections:
host     all     all     0.0.0.0/0   md5
# IPv6 local connections:
# host   all     all     ::1/128     md5

和 postgresqlconf - 我知道我已经给这个配置提供了一些巨大的缓冲区/内存,只是为了测试这是否是问题 - 仅显示未注释的行:

listen_addresses = '*'
port = 5432
max_connections = 100
shared_buffers = 512MB
work_mem = 64MB
max_fsm_pages = 204800
shared_preload_libraries = '$libdir/plugins/plugin_debugger.dll'
log_destination = 'stderr'
logging_collector = on
log_line_prefix = '%t '
datestyle = 'iso, mdy'
lc_messages = 'English_United States.1252'
lc_monetary = 'English_United States.1252'
lc_numeric = 'English_United States.1252'
lc_time = 'English_United States.1252'
default_text_search_config = 'pg_catalog.english'

需要任何其他信息,请告诉我。感谢您的帮助。

I have setup PostgreSQL on a VPS I own - the software that accesses the database is a program called PokerTracker.

PokerTracker logs all your hands and statistics whilst playing online poker.

I wanted this accessible from several different computers so decided to installed it on my VPS and after a few hiccups I managed to get it connecting without errors.

However, the performance is dreadful. I have done tons of research on 'remote postgresql slow' etc and am yet to find an answer so am hoping someone is able to help.

Things to note:

The query I am trying to execute is very small. Whilst connecting locally on the VPS, the query runs instantly.

While running it remotely, it takes about 1 minute and 30 seconds to run the query.

The VPS is running 100MBPS and then computer I'm connecting to it from is on an 8MB line.

The network communication between the two is almost instant, I am able to remotely connect fine with no lag whatsoever and am hosting several websites running MSSQL and all the queries run instantly, whether connected remotely or locally so it seems specific to PostgreSQL.

I'm running their newest version of the software and the newest compatible version of PostgreSQL with their software.

The database is a new database, containing hardly any data and I've ran vacuum/analyze etc all to no avail, I see no improvements.

I don't understand how MSSQL can query almost instantly yet PostgreSQL struggles so much.

I am able to telnet to the port 5432 on the VPS IP with no problems, and as I say the query does execute it just takes an extremely long time.

What I do notice is on the router when the query is running that hardly any bandwidth is being used - but then again I wouldn't expect it to for a simple query but am not sure if this is the issue. I've tried connecting remotely on 3 different networks now (including different routers) but the problem remains.

Connecting remotely via another machine via the LAN is instant.

I have also edited the postgre conf file to allow for more memory/buffers etc but I don't think this is the problem - what I am asking it to do is very simple - it shouldn't be intensive at all.

Thanks,
Ricky

Edit: Please note the client and server are both running Windows.

Here is information from the config files.

pg_hba - currently allowing all traffic:

# TYPE  DATABASE    USER        CIDR-ADDRESS          METHOD

# IPv4 local connections:
host     all     all     0.0.0.0/0   md5
# IPv6 local connections:
# host   all     all     ::1/128     md5

And postgresqlconf - I'm aware I've given some mammoth amount of buffers/memory to this config, just to test if it was the issue - showing uncommented lines only:

listen_addresses = '*'
port = 5432
max_connections = 100
shared_buffers = 512MB
work_mem = 64MB
max_fsm_pages = 204800
shared_preload_libraries = '$libdir/plugins/plugin_debugger.dll'
log_destination = 'stderr'
logging_collector = on
log_line_prefix = '%t '
datestyle = 'iso, mdy'
lc_messages = 'English_United States.1252'
lc_monetary = 'English_United States.1252'
lc_numeric = 'English_United States.1252'
lc_time = 'English_United States.1252'
default_text_search_config = 'pg_catalog.english'

Any other information required, please let me know. Thanks for all your help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

⒈起吃苦の倖褔 2024-10-18 06:51:35

我启用了日志记录并将日志发送给他们的软件开发人员。他们的答案是,该软件最初旨在在本地或近本地数据库上运行,因此由于网络延迟,在 VPS 上运行预计会很慢。

感谢您的帮助,但看起来我已经没有主意了,这是由于软件而不是 VPS 上的 PostgreSQL 造成的。

谢谢,
瑞奇

I enabled logging and sent the logs to the developers of their software. Their answer was that there software was originally intended to run on a local or near local database so running on a VPS would be expectedly slow - due to network latency.

Thanks for all your help, but it looks like I'm out of ideas and it's due to the software, rather than PostgreSQL on the VPS specifically.

Thanks,
Ricky

梦忆晨望 2024-10-18 06:51:35

您可以进行解释分析,它会告诉您在服务器上查询的执行时间(没有将结果发送到客户端的网络开销)。

如果服务器执行时间非常快(与您看到的时间相比),则这是一个网络问题。如果报告的时间与您观察到的非常相似,则这是 PostgreSQL 问题(然后您需要发布执行计划以及可能的 PostgreSQL 配置)

You can do an explain analyze which will tell you the execution time of the query on the server (without the network overhead of sending the result to the client).

If the server execution time is very quick (compared to the time you are seeing) than this is a network problem. If the reported time is very similar to what you observe on your side, it's a PostgreSQL problem (and then you need to post the execution plan and possibly your PostgreSQL configuration)

空气里的味道 2024-10-18 06:51:35

被这个问题困扰了一段时间,这个问题引导我找到了答案,所以我想我会分享,以防它有帮助。

服务器有一个辅助网络接口 (eth1),被设置为默认路由。执行查询的客户端与 eth0 在同一子网内,因此这应该不会导致任何问题......但确实如此。

禁用默认路由会使查询在正常时间范围内返回。但长期解决方案是将 listen_addresses'*' 更改为正确的 IP。

Have been plagued by this issue for awhile and this question lead me to the answer so thought I would share incase it helps.

The server had a secondary network interface (eth1) that was setup as the default route. The client performing the queries was within the same subnet as eth0, so this should not cause any issues.. but it was.

Disabling the default route made the queries return back within normal time frames. But the long term fix was to change the listen_addresses from '*' to the correct IP.

攒眉千度 2024-10-18 06:51:35

使用网络监控工具(我推荐wireshark,因为它可以跟踪许多协议,包括postgresql的)来查看网络连接是否正常。如果连接不好,您将看到丢弃/重传的数据包。

Use network monitoring tools (I reccomend wireshark, because it can trace many protocols, including postgresql's) to see if network connection is ok. You will see dropped/retransmitted packets if the connection is bad.

就此别过 2024-10-18 06:51:35

也许 Postgres 正在尝试使用 ident 对您进行身份验证,但这不起作用(例如防火墙排除) ,并且必须等待超时才能允许通过其他方式连接。

尝试使用 psql 查询远程服务器的 select version() - 这应该是即时的,因为它不接触磁盘。

如果不是即时的,请发布您的 pg_hba.conf (未注释的行)。

另一个可能的原因:

  • 使用 RevDNS 进行身份验证;
  • 服务器或客户端上的防病毒软件;
  • 其他一些连接正在阻塞表或行,因为它没有明确结束。

Maybe Postgres is trying to authenticate you using ident, which isn't working (for example firewalled out), and has to wait for timeout before allowing connection by other means.

Try to query remote server for select version() using psql - this should be instant, as it does not touch disk.

If it isn't instant please post your pg_hba.conf (uncommented lines).

Another possible causes:

  • authentication using RevDNS;
  • antivirus on server or client;
  • some other connection is blocking a table or row, because it didn't end clearly.
笑脸一如从前 2024-10-18 06:51:35

这并不是为什么 pg 通过 VPN 访问速度慢的答案,但一个可能的解决方案/替代方案是设置 TeamPostgreSQL 通过浏览器访问 PG。它是一个 AJAX Web 应用程序,包含一些非常方便的功能,用于导航数据和管理数据库。

这也可以避免连接断开,根据我的经验,通过 VPN 使用 pg 时这种情况很常见。

还有用于 Web 访问的 phpPgAdmin,但我提到了 TeamPostgreSQL,因为它对于导航和获取数据库中数据的概述非常有帮助。

This is not the answer to why pg access is slow over the VPN, but a possible solution/alternative could be setting up TeamPostgreSQL to access PG through a browser. It is an AJAX webapp that includes some very convenient features for navigating your data as well as managing the database.

This would also avoid dropped connections which in my experience is common when working with pg over a VPN.

There is also phpPgAdmin for web access but I mention TeamPostgreSQL because it can be very helpful for navigating and getting an overview over the data in the database.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文