【问题标题】:postgresql slow: primary key on 80M row tablepostgresql 慢:80M 行表上的主键
【发布时间】:2016-08-08 12:32:32
【问题描述】:

我有一台 64GB RAM 机器,20 个 CPU,这是在一个有 80M 行的表上创建主键的命令:

ALTER TABLE ONLY wikipedia_article ADD CONSTRAINT pagelinks_pkey PRIMARY KEY (language, title);

我遇到的问题是:

  • 只有 1 个 CPU 使用率高达 100%(平均负载为 99%),其余的根本不使用
  • 主键创建期间的写入速度非常低,2.6 M/s,pg_activity 生成的报告中完全没有读取速度

这是表结构:

                          Table "public.wikipedia_article"
    Column    |       Type       | Modifiers | Storage  | Stats target | Description
--------------+------------------+-----------+----------+--------------+-------------
 language     | text             | not null  | extended |              |
 title        | text             | not null  | extended |              |
 langcount    | integer          |           | plain    |              |
 othercount   | integer          |           | plain    |              |
 totalcount   | integer          |           | plain    |              |
 lat          | double precision |           | plain    |              |
 lon          | double precision |           | plain    |              |
 importance   | double precision |           | plain    |              |
 osm_type     | character(1)     |           | extended |              |
 osm_id       | bigint           |           | plain    |              |
 infobox_type | text             |           | extended |              |
 population   | bigint           |           | plain    |              |
 website      | text             |           | extended |              |
Has OIDs: no

通过 pg_restore 自动导入,这是源代码

http://www.nominatim.org/data/wikipedia_article.sql.bin

有什么想法可以让事情变得更快吗?我将 conf 变量“maintenance_work_mem”的值更改为 RAM 大小的一半。我还尝试更改一些内核设置,但没有任何乐趣:

sysctl -w kernel.shmmax=17179869184
sysctl -w kernel.shmall=1048576
sysctl vm.overcommit_memory=1 
sysctl vm.swappiness=10

操作系统运行在虚拟机上、Digital Ocean 中、SSD 驱动器上,我期待这样的虚拟机配置可以更快地运行。

服务器信息:x86_64-unknown-linux-gnu 上的 PostgreSQL 9.3.13,由 gcc (Ubuntu 4.8.4-2ubuntu1~14.04.1) 4.8.4 编译,64 位

非常感谢,VG

【问题讨论】:

  • BTW:我觉得这是一个比较奇怪的PK选择。表中没有任何数字(“代理”)ID吗?

标签: postgresql


【解决方案1】:

PostgreSQL 为一个语句使用一个 CPU - 因此预计 CPU 利用率为 100%。您可以尝试将maintenance_work_mem 设置为更高的值。默认值太低 - 例如,您可以尝试“2GB”。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-06-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-21
    • 2013-11-15
    • 2015-05-17
    相关资源
    最近更新 更多