iis服务器助手广告广告
返回顶部
首页 > 资讯 > 数据库 >PostgreSQL DBA(95) - PG 12 Partition(out of shared memory)
  • 820
分享到

PostgreSQL DBA(95) - PG 12 Partition(out of shared memory)

2024-04-02 19:04:59 820人浏览 薄情痞子
摘要

postgresql 12 Bet

postgresql 12 Beta3,创建包含8192个子分区的分区表,执行查询语句,在分区键上排序,出错。
数据库版本:


[local]:5432 pg12@testdb=# select version();
                                                  version                                   
--------------------------------------------------------------------------------------------
 Postgresql 12beta3 on x86_64-pc-linux-gnu, compiled by GCc (GCC) 4.8.5 20150623 (Red Hat 4.
8.5-16), 64-bit
(1 row)
Time: 9.511 ms

数据表结构


[local]:5432 pg12@testdb=# \d t_hash_manypartitions
        Partitioned table "public.t_hash_manypartitions"
 Column |         Type          | Collation | Nullable | Default 
--------+-----------------------+-----------+----------+---------
 c1     | integer               |           |          | 
 c2     | character varying(40) |           |          | 
 c3     | character varying(40) |           |          | 
Partition key: HASH (c2)
Number of partitions: 8191 (Use \d+ to list them.)

只有1行数据


[local]:5432 pg12@testdb=# insert into t_hash_manypartitions(c1,c2,c3) values(0,'c2-0','c3-0');
INSERT 0 1
Time: 14.038 ms
[local]:5432 pg12@testdb=# select * from t_hash_manypartitions;
 c1 |  c2  |  c3  
----+------+------
  0 | c2-0 | c3-0
(1 row)
Time: 917.996 ms
[local]:5432 pg12@testdb=#

虽然只有1行数据,但全表扫描仍然很慢,接近1s,而普通表仅几毫秒。


[local]:5432 pg12@testdb=# select * from t_hash_manypartitions;
 c1 |  c2  |  c3  
----+------+------
  0 | c2-0 | c3-0
(1 row)
Time: 898.615 ms
[local]:5432 pg12@testdb=# select * from t_hash_manypartitions;
 c1 |  c2  |  c3  
----+------+------
  0 | c2-0 | c3-0
(1 row)
Time: 898.783 ms
[local]:5432 pg12@testdb=#

执行查询,在分区键c2上排序


[local]:5432 pg12@testdb=# select * from t_hash_manypartitions order by c2;
ERROR:  out of shared memory
HINT:  You might need to increase max_locks_per_transaction.
CONTEXT:  parallel worker
Time: 2420.971 ms (00:02.421)
[local]:5432 pg12@testdb=#

提示out of shared memory,内存溢出


[local]:5432 pg12@testdb=# alter system set max_locks_per_transaction=128;
ALTER SYSTEM
Time: 7.705 ms
[local]:5432 pg12@testdb=# select * from t_hash_manypartitions order by c2;
ERROR:  out of shared memory
HINT:  You might need to increase max_locks_per_transaction.
CONTEXT:  parallel worker
Time: 1988.893 ms (00:01.989)
[local]:5432 pg12@testdb=# alter system set max_locks_per_transaction=512;
ALTER SYSTEM
Time: 13.137 ms
[local]:5432 pg12@testdb=# select * from t_hash_manypartitions order by c2;
ERROR:  out of shared memory
HINT:  You might need to increase max_locks_per_transaction.
CONTEXT:  parallel worker
Time: 1968.974 ms (00:01.969)
[local]:5432 pg12@testdb=# alter system set max_locks_per_transaction=8192;
ALTER SYSTEM
Time: 4.060 ms
[local]:5432 pg12@testdb=# select * from t_hash_manypartitions order by c2;
ERROR:  out of shared memory
HINT:  You might need to increase max_locks_per_transaction.
CONTEXT:  parallel worker
Time: 1985.106 ms (00:01.985)
[local]:5432 pg12@testdb=# alter system set max_locks_per_transaction=16384;
ALTER SYSTEM
Time: 7.791 ms
[local]:5432 pg12@testdb=# select * from t_hash_manypartitions order by c2;
ERROR:  out of shared memory
HINT:  You might need to increase max_locks_per_transaction.
CONTEXT:  parallel worker
Time: 1953.134 ms (00:01.953)
[local]:5432 pg12@testdb=#

可以看到,增大该参数值至16384,仍然报错。 修改此参数需重启数据库,重启数据库后重新执行即可
查看执行计划,PG在每个分区上执行并行扫描,然后使用Parallel Append合并结果集,然后再执行排序。


[local]:5432 pg12@testdb=# explain select * from t_hash_manypartitions order by c2;
                                                QUERY PLAN                                  
--------------------------------------------------------------------------------------------
 Gather Merge  (cost=455382.87..734442.42 rows=2391772 width=200)
   Workers Planned: 2
   ->  Sort  (cost=454382.84..457372.56 rows=1195886 width=200)
         Sort Key: t_hash_manypartitions_1.c2
         ->  Parallel Append  (cost=0.00..104753.25 rows=1195886 width=200)
               ->  Parallel Seq Scan on t_hash_manypartitions_1  (cost=0.00..12.06 rows=206 
width=200)
               ->  Parallel Seq Scan on t_hash_manypartitions_2  (cost=0.00..12.06 rows=206 
width=200)
               ->  Parallel Seq Scan on t_hash_manypartitions_3  (cost=0.00..12.06 rows=206 
width=200)
               ->  Parallel Seq Scan on t_hash_manypartitions_4  (cost=0.00..12.06 rows=206 
width=200)
               ->  Parallel Seq Scan on t_hash_manypartitions_5  (cost=0.00..12.06 rows=206 
width=200)
               ->  Parallel Seq Scan on t_hash_manypartitions_6  (cost=0.00..12.06 rows=206 
width=200)
               ->  Parallel Seq Scan on t_hash_manypartitions_7  (cost=0.00..12.06 rows=206 
width=200)
               ->  Parallel Seq Scan on t_hash_manypartitions_8  (cost=0.00..12.06 rows=206 
width=200)
               ->  Parallel Seq Scan on t_hash_manypartitions_9  (cost=0.00..12.06 rows=206 
width=200)
               ->  Parallel Seq Scan on t_hash_manypartitions_10  (cost=0.00..12.06 rows=206
 width=200)
               ->  Parallel Seq Scan on t_hash_manypartitions_11  (cost=0.00..12.06 rows=206
 width=200)
               ->  Parallel Seq Scan on t_hash_manypartitions_12  (cost=0.00..12.06 rows=206
 width=200)
               ->  Parallel Seq Scan on t_hash_manypartitions_13  (cost=0.00..12.06 rows=206
 width=200)
               ->  Parallel Seq Scan on t_hash_manypartitions_14  (cost=0.00..12.06 rows=206
 width=200)
               ->  Parallel Seq Scan on t_hash_manypartitions_15  (cost=0.00..12.06 rows=206
 width=200)
               ->  Parallel Seq Scan on t_hash_manypartitions_16  (cost=0.00..12.06 rows=206
 width=200)
               ->  Parallel Seq Scan on t_hash_manypartitions_17  (cost=0.00..12.06 rows=206
 width=200)
               ->  Parallel Seq Scan on t_hash_manypartitions_18  (cost=0.00..12.06 rows=206
 width=200)
               ->  Parallel Seq Scan on t_hash_manypartitions_19  (cost=0.00..12.06 rows=206
 width=200)
               ->  Parallel Seq Scan on t_hash_manypartitions_20  (cost=0.00..12.06 rows=206
--More--

在PG 11.2上则没有问题


testdb=# select version();
                                                 version                                    
--------------------------------------------------------------------------------------------
 PostgreSQL 11.2 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5
-16), 64-bit
(1 row)
testdb=# select * from t_hash_manypartitions order by c2;
 c1 |  c2  |  c3  
----+------+------
  0 | c2-0 | c3-0
(1 row)
testdb=#
您可能感兴趣的文档:

--结束END--

本文标题: PostgreSQL DBA(95) - PG 12 Partition(out of shared memory)

本文链接: https://www.lsjlt.com/news/47263.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • mysql拒绝访问怎么办
    mysql 出现拒绝访问的原因和解决方法:权限问题:授予用户适当的数据库或表访问权限。防火墙或安全组:允许对 mysql 端口(3306)的入站连接。密码错误:重置 mysql 密码或使...
    99+
    2024-05-20
    mysql
  • mysql怎么比较日期大小
    mysql 中比较日期大小的方法包括:直接比较两个日期,使用 、= 运算符。使用 date_format() 函数将日期转换为字符串,然后比较字符串大小。使用 str_to_date()...
    99+
    2024-05-20
    mysql
  • mysql怎么加锁
    mysql中加锁是一种确保数据并发访问一致性的机制。加锁方式有:表级锁(对整个表加锁)和行级锁(对特定行加锁)。加锁类型有共享锁(允许读取但禁止修改)、排他锁(禁止读取和修改)和意向锁(...
    99+
    2024-05-20
    mysql 并发访问
  • mysql误删数据怎么恢复
    mysql误删数据可通过以下步骤恢复:停止数据库服务,防止数据覆盖。若开启binlog日志,可从中提取删除语句,再重新执行后将数据恢复。使用恢复工具修复表文件或恢复事务。从备份中恢复数据...
    99+
    2024-05-20
    mysql
  • 怎么判断mysql安装成功
    成功安装 mysql 的方法:检查命令行界面版本号;连接到 mysql 服务器,输入 "mysql -u root -p";创建数据库,输入 "create database test;...
    99+
    2024-05-20
    mysql linux macos 防火墙配置
  • mysql怎么修改表名
    如何修改 mysql 表名:检查当前表名:show tables;运行 rename table 语句:rename table 旧表名 to 新表名;验证更改:show tables;...
    99+
    2024-05-20
    mysql
  • mysql删除的表怎么恢复
    mysql 中已删除表的恢复方法主要涉及以下步骤:检查 binlog 日志以获取删除事务信息;使用数据恢复工具扫描数据库文件;从备份还原表数据;或联系 mysql 支持寻求帮助。 My...
    99+
    2024-05-20
    mysql 数据丢失
  • mysql复合主键怎么写
    在 mysql 中编写复合主键:在 create table 语句中使用 primary key 约束并列出字段名称。复合主键的好处包括提高查询效率、保证数据完整性和强制数据顺序。注意选...
    99+
    2024-05-20
    mysql
  • 怎么查看mysql数据库版本
    如何查看 mysql 数据库版本?连接到数据库并执行查询:select version();检查命令行或 mysql workbench 中的服务器属性。 如何查看 MySQL 数据库...
    99+
    2024-05-20
    mysql linux
  • 怎么检测mysql安装成功
    要验证 mysql 安装是否成功,请执行以下步骤:检查系统服务是否正在运行。使用 mysql 命令行工具连接到服务器。创建一个测试数据库并使用它。在数据库中创建一个测试表。插入测试数据并...
    99+
    2024-05-20
    mysql linux
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作