gpt4 book ai didi

performance - 自 8.3 以来,您是否观察到 PostgreSQL TEMP TABLE 性能下降?

转载 作者:行者123 更新时间:2023-11-29 14:12:58 26 4
gpt4 key购买 nike

我的应用程序使用 PostgreSQL 中的临时表。对于新的 8.4 版本,我测试了它的性能比较到旧的 8.2 版本,我观察到临时表慢了倍!

8.3 版本的测试表明它在 8.3 中也变慢了。我比较了所有的配置基地,他们是相似的。所有基地都在同一个工作服务器。虽然我的应用程序使用 JDBC 驱动程序,但我使用的是 Jython测试它:

import time
import traceback
import sys

from java.sql import DriverManager
from java.lang import Class

Class.forName("org.postgresql.Driver")

def test_bench(db, temp):
if temp:
temp_str = ' TEMP '
temp_desc = 'temp '
else:
temp_str = ' '
temp_desc = 'regular'
try:
c = db.createStatement()
c.execute("CREATE %s TABLE test_table_md_speed(id serial primary key, txt varchar(100))" % temp_str)
cnt = '?'
try:
t0 = time.time()
for i in range(1000):
c.execute("INSERT INTO test_table_md_speed(txt) VALUES ('ala ma %d kota')" % i)
t2 = time.time()
rs = c.executeQuery("SELECT COUNT(*) AS ile FROM test_table_md_speed")
while (rs.next()):
cnt = rs.getString(1)
print("%s\ttime: %7.3f [s]\tcnt: %s" % (temp_desc, (t2-t0), cnt))
finally:
c.execute("DROP TABLE test_table_md_speed")
c.close()
except:
print("\nthere were errors!")
s = traceback.format_exc()
sys.stderr.write("%s\n" % (s))

def test_db(db_url, usr, passwd):
print("\n\n--------------")
db = DriverManager.getConnection(db_url, usr, passwd)
try:
c = db.createStatement()
rs = c.executeQuery("SELECT version()")
while (rs.next()):
print('ver: %s' % (rs.getString(1)))
test_bench(db, 0)
test_bench(db, 1)
finally:
db.close()

test_db('jdbc:postgresql://db-test64:5432/db_stable?stringtype=unspecified', 'postgres', 'postgres')
test_db('jdbc:postgresql://db-test64:5434/db_stable?stringtype=unspecified', 'postgres', 'postgres')
test_db('jdbc:postgresql://db-test64:5435/db_stable?stringtype=unspecified', 'postgres', 'postgres')

我还使用 ActivePython 和来自 win32 的 odbc 编写了类似的测试,这个程序显示了相同的结果。我的结果:

C:\tools\pyscripts\>jython jdbc_pg_bench.py
--------------
ver: PostgreSQL 8.2.12 on x86_64-unknown-linux-gnu, compiled by GCC gcc (GCC) 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)
regular time: 12.016 [s] cnt: 1000
temp time: 1.187 [s] cnt: 1000
--------------
ver: PostgreSQL 8.3.6 on x86_64-unknown-linux-gnu, compiled by GCC gcc (GCC) 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)
regular time: 11.922 [s] cnt: 1000
temp time: 10.516 [s] cnt: 1000
--------------
ver: PostgreSQL 8.4.0 on x86_64-unknown-linux-gnu, compiled by GCC gcc (GCC) 4.1.2 20061115 (prerelease) (Debian 4.1.1-21), 64-bit
regular time: 13.375 [s] cnt: 1000
temp time: 13.609 [s] cnt: 1000

您是否观察到 8.3 和 8.4 版本中临时表的速度同样下降?是否有任何关于 TEMP 表行为变化的信息?

编辑

我在我的 Windows 机器上安装了 PostgreSQL 8.2 和 8.4,用 10000 次插入测试它,似乎 8.2 使用临时表要快得多:

ver: PostgreSQL 8.2.11 on i686-pc-mingw32, compiled by GCC gcc.exe (GCC) 3.4.2 (mingw-special)
regular time: 40.672 [s] cnt: 10000
temp time: 14.859 [s] cnt: 10000

ver: PostgreSQL 8.4.0, compiled by Visual C++ build 1400, 32-bit
regular time: 56.860 [s] cnt: 10000
temp time: 49.110 [s] cnt: 10000

最佳答案

8.3 引入了这个变化:(来自 commit log on the wiki )

2007-06-03 13:05 tgl Create a GUC parameter temp_tablespaces that allows selection of the tablespace(s) in which to store temp tables and temporary files. This is a list to allow spreading the load across multiple tablespaces (a random list element is chosen each time a temp object is to be created). Temp files are not stored in per-database pgsql_tmp/ directories anymore, but per-tablespace directories.

Release notes感谢“Jaime Casanova、Albert Cervera、Bernd Helmle”


有报告给pgsql-performance可能相关的列表。原始海报确定changing their kernel at the same time was more likely the cause , 然而a post from Tom Lane包括:

"So I suspect that the slowdown you saw comes from making a larger number of catalog updates in 8.3;"


您评论说 8.2 配置已复制到 8.3...默认的 autovacuum 设置从关闭更改为打开。也许您的临时表在 8.3 中被清理,但在 8.2 中没有清理?

关于performance - 自 8.3 以来,您是否观察到 PostgreSQL TEMP TABLE 性能下降?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1102704/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com