相关疑难解决方法(0)

为读取性能配置 PostgreSQL

我们的系统写入了大量数据(一种大数据系统)。写入性能足以满足我们的需求,但读取性能真的太慢了​​。

我们所有表的主键(约束)结构都相似:

timestamp(Timestamp) ; index(smallint) ; key(integer).
Run Code Online (Sandbox Code Playgroud)

一个表可以有数百万行,甚至数十亿行,而一个读请求通常是针对特定时间段(时间戳/索引)和标记的。查询返回大约 20 万行是很常见的。目前,我们每秒可以读取大约 15k 行,但我们需要快 10 倍。这是可能的,如果是,如何?

注意: PostgreSQL 是和我们的软件一起打包的,所以不同客户端的硬件是不一样的。

它是一个用于测试的虚拟机。VM 的主机是具有 24.0 GB RAM 的 Windows Server 2008 R2 x64。

服务器规范(虚拟机 VMWare)

Server 2008 R2 x64
2.00 GB of memory
Intel Xeon W3520 @ 2.67GHz (2 cores)
Run Code Online (Sandbox Code Playgroud)

postgresql.conf 优化

shared_buffers = 512MB (default: 32MB)
effective_cache_size = 1024MB (default: 128MB)
checkpoint_segment = 32 (default: 3)
checkpoint_completion_target = 0.9 (default: 0.5)
default_statistics_target = 1000 (default: 100)
work_mem = 100MB (default: 1MB)
maintainance_work_mem = 256MB …
Run Code Online (Sandbox Code Playgroud)

postgresql performance postgresql-9.1 query-performance

47
推荐指数
2
解决办法
4万
查看次数

PostgreSQL:强制数据进入内存

有没有一种系统的方法可以强制 PostgreSQL 将特定表加载到内存中,或者至少从磁盘中读取它以便系统缓存它?

postgresql memory cache

41
推荐指数
3
解决办法
4万
查看次数

带有位图索引扫描的查询计划中的“重新检查条件:”行

这是对上一个问题的评论的衍生:

使用 PostgreSQL 9.4,Recheck Cond:EXPLAIN.

就像在EXPLAIN引用问题的输出中一样:

->  Bitmap Heap Scan on table_three  (cost=2446.92..19686.74 rows=8159 width=7)
      Recheck Cond: (("timestamp" > (now() - '30 days'::interval)) AND (client_id > 0))
      ->  BitmapAnd  (cost=2446.92..2446.92 rows=8159 width=0)
            ->  Bitmap Index Scan on table_one_timestamp_idx  (cost=0.00..1040.00 rows=79941 width=0)
                  Index Cond: ("timestamp" > (now() - '30 days'::interval))
            ->  Bitmap Index Scan on fki_table_three_client_id  (cost=0.00..1406.05 rows=107978 width=0)
                  Index Cond: (client_id > 0)
Run Code Online (Sandbox Code Playgroud)

或者在EXPLAIN ANALYZE一个简单的大表(很少work_mem)的输出中:

EXPLAIN ANALYZE …
Run Code Online (Sandbox Code Playgroud)

postgresql index execution-plan postgresql-9.4

26
推荐指数
2
解决办法
1万
查看次数