首页 > 解决方案 > PostgreSQL 中的性能问题

问题描述

我们正在处理从 SQL Server 到 Aurora PostgreSQL 的数据库转换。对于数据库中的某些函数,我们看到 PG 中的执行时间(30 多秒)与 SQL Server(0.5-2 秒)相比非常高。

我们已经将数据库参数设置为最佳性能所需的值。

其中许多函数使用外部表视图从另一个数据库引用表。

客户的期望是功能的性能至少应该比我们目前在 SQL Server 中的性能更好。

有哪些方法可以提高 PG 的性能?

以下是各自的配置详细信息:

SQL server config: Microsoft SQL Server 2012 (SP4) (KB4018073) – 11.0.7001.0 (X64). RAM: 16GB. Inter Xeon
Aurora RDS config: 4 vCPU, 30.5 GB RAM.

示例代码:

代码示例:// 这个花费不到一秒钟。

insert into temptable(
                column1 ,column2,column3 ,
                column4 ,column5, column6 ,
                column7                                                             
        )
    SELECT  --DISTINCT
        t.col AS column1, d.column1,null as column3 ,
                null as column4 ,null as column5,null as column6 ,
                null as column7 
    FROM 
        view1 AS d
        INNER JOIN table2 AS t
            ON t.column2= d.column1
        LEFT OUTER JOIN table2 AS i
            ON i.col1 = t.col AND i.col = t.col2 AND i.col = var1 AND i.svc_type = var2
            AND i.col2= var3 AND i.col1 = var4
    WHERE 
        (i.col3 = 'XXX' OR d.col3 = 'XX') 
        AND i.col4 IN (var5, var6) 
        ;
// This update query only taking 27 seconds and result 39 rows      
update temptable set 
        column3=function1(column2, v1, v2, v3), -- this is single execution it took 412ms
        column4=function2(column2, v3),-- this is single execution it took 350ms
        column5=function3(column2, v3),
        column6=function4(column2),
        column7=function5(column2);
// this one taking less then one seconds.
OPEN rs1 FOR
    select  column1 ,column2,column3 ,
                column4 ,column5, column6 ,
                column7 from temptable;
    RETURN NEXT rs1;

标签: postgresqlamazon-aurora

解决方案


推荐阅读