简体   繁体   English

PostgreSQL 9.1上的SELECT性能问题

[英]SELECT performance issues on postgresql 9.1

I am building a large postgres 9.1 database on ubuntu 12.04, with one table that holds about 80 million rows or so. 我正在ubuntu 12.04上建立一个大型的postgres 9.1数据库,其中一个表可容纳约8000万行。 Whenever I run a SELECT statement: 每当我运行SELECT语句时:

SELECT * FROM db WHERE ID=1;

It takes almost 2.5 minutes to execute the query which returns only a few thousand rows. 执行查询仅需2.5分钟,查询仅返回几千行。 After running a few diagnostics on the disk I/O, I think that is not the problem, but just in case below is the output from a diagnostic. 在磁盘I / O上运行了一些诊断程序之后,我认为这不是问题,但以防万一,下面是诊断程序的输出。 (I have 2GB of RAM) I am not exactly sure what a good output is here, but it seems ballpark given stats found for other servers on the internet. (我有2GB的RAM)我不确定在这里有什么好输出,但是考虑到互联网上其他服务器的统计数据,这似乎是个难题。

time sh -c "dd if=/dev/zero of=bigfile bs=8k count=500000 && sync"


500000+0 records in
500000+0 records out
4096000000 bytes (4.1 GB) copied, 106.969 s, 38.3 MB/s

real    1m49.091s
user    0m0.248s
sys     0m9.369s

I have modified postgresql.conf considerably, boosting the effective_cache to 75% of ram, shared_buffers to 25%, checkpoint_segments to 15, work_mem to 256MB, autovacuum, SHMMAX on the kernel, etc. I have had some performance increases, but not more than 5% better. 我已经对postgresql.conf进行了相当大的修改,将有效缓存提高到ram的75%,将共享缓冲区提高到25%,将checkpoint_segments提升到15,将work_mem提升到256MB,在内核上增加了autovacuum,SHMMAX,等等。我的性能有所提高,但不超过好5%。 Networking shouldnt be an issue since it still takes a long time even running on localhost. 网络不应该是一个问题,因为即使在本地主机上运行仍然需要很长时间。 I am planning to add even more data, and the query time seems to be growing quickly with the number of rows. 我计划添加更多数据,并且查询时间似乎随着行数的增长而迅速增长。

It seems like I should be able to run these SELECT statements in a few seconds, not a few minutes. 看来我应该能够在几秒钟而不是几分钟内运行这些SELECT语句。 Any suggestions on where this bottleneck could be? 关于此瓶颈可能存在的任何建议?

sorry if this is inexcusably obvious, but do you have an index on the ID column? 很抱歉,如果这是不可避免的,但是您在ID列上有索引吗?

also, though I'm not blaming the disk, you merely tested sequential bandwidth, which tells you very little about latency. 同样,尽管我没有责怪磁盘,但是您仅测试了顺序带宽,这几乎没有告诉您延迟。 though I have to say that 38 MB/s is underwhelming even for that measure... 尽管我不得不说38 MB / s的速度仍然不尽人意...

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

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