這篇文章主要講解了“怎么理解PostgreSQL創(chuàng)建數(shù)據(jù)表時(shí)的參數(shù)fillfactor”,文中的講解內(nèi)容簡(jiǎn)單清晰,易于學(xué)習(xí)與理解,下面請(qǐng)大家跟著小編的思路慢慢深入,一起來(lái)研究和學(xué)習(xí)“怎么理解PostgreSQL創(chuàng)建數(shù)據(jù)表時(shí)的參數(shù)fillfactor”吧!
創(chuàng)新互聯(lián)秉承實(shí)現(xiàn)全網(wǎng)價(jià)值營(yíng)銷(xiāo)的理念,以專(zhuān)業(yè)定制企業(yè)官網(wǎng),成都網(wǎng)站建設(shè)、成都網(wǎng)站設(shè)計(jì),重慶小程序開(kāi)發(fā),網(wǎng)頁(yè)設(shè)計(jì)制作,手機(jī)網(wǎng)站開(kāi)發(fā),成都全網(wǎng)營(yíng)銷(xiāo)幫助傳統(tǒng)企業(yè)實(shí)現(xiàn)“互聯(lián)網(wǎng)+”轉(zhuǎn)型升級(jí)專(zhuān)業(yè)定制企業(yè)官網(wǎng),公司注重人才、技術(shù)和管理,匯聚了一批優(yōu)秀的互聯(lián)網(wǎng)技術(shù)人才,對(duì)客戶(hù)都以感恩的心態(tài)奉獻(xiàn)自己的專(zhuān)業(yè)和所長(zhǎng)。
下面創(chuàng)建不同fillfactor的數(shù)據(jù)表,執(zhí)行update操作
[local]:5432 pg12@testdb=# create table t_fillfactor_100(id int,c1 varchar(30),c2 varchar(30),c3 varchar(30)) with (fillfactor=100); CREATE TABLE Time: 2.462 ms [local]:5432 pg12@testdb=# create table t_fillfactor_70(id int,c1 varchar(30),c2 varchar(30),c3 varchar(30)) with (fillfactor=70); CREATE TABLE Time: 3.437 ms [local]:5432 pg12@testdb=# create table t_fillfactor_50(id int,c1 varchar(30),c2 varchar(30),c3 varchar(30)) with (fillfactor=50); CREATE TABLE Time: 28.553 ms [local]:5432 pg12@testdb=# insert into t_fillfactor_100(id,c1,c2,c3) select x,'c1'||x,'c2'||x,'c3'||x from generate_series(1,1000000) as x; INSERT 0 1000000 Time: 3583.216 ms (00:03.583) [local]:5432 pg12@testdb=# insert into t_fillfactor_70(id,c1,c2,c3) select x,'c1'||x,'c2'||x,'c3'||x from generate_series(1,1000000) as x; INSERT 0 1000000 Time: 6506.113 ms (00:06.506) [local]:5432 pg12@testdb=# insert into t_fillfactor_50(id,c1,c2,c3) select x,'c1'||x,'c2'||x,'c3'||x from generate_series(1,1000000) as x; INSERT 0 1000000 Time: 3113.901 ms (00:03.114) [local]:5432 pg12@testdb=# update t_fillfactor_100 set c1=lpad('c1',30,'c1'),c2=lpad('c2',30,'c2'),c3=lpad('c3',30,'c3'); UPDATE 1000000 Time: 10641.794 ms (00:10.642) [local]:5432 pg12@testdb=# update t_fillfactor_70 set c1=lpad('c1',30,'c1'),c2=lpad('c2',30,'c2'),c3=lpad('c3',30,'c3'); UPDATE 1000000 Time: 8563.046 ms (00:08.563) [local]:5432 pg12@testdb=# update t_fillfactor_50 set c1=lpad('c1',30,'c1'),c2=lpad('c2',30,'c2'),c3=lpad('c3',30,'c3'); UPDATE 1000000 Time: 4036.735 ms (00:04.037)
可以看到,在插入時(shí),fillfactor較高的數(shù)據(jù)表耗時(shí)較短,而在update時(shí)(全量),fillfactor的則有較大的優(yōu)勢(shì).但,經(jīng)過(guò)多次update后,耗時(shí)并不明顯,原因在于經(jīng)過(guò)多次update,每個(gè)塊的空閑空間跟fillfactor=100的設(shè)定已相差無(wú)幾.
[local]:5432 pg12@testdb=# update t_fillfactor_100 set c1=lpad('c1',30,'c1'),c2=lpad('c2',30,'c2'),c3=lpad('c3',30,'c3'); UPDATE 1000000 Time: 4276.404 ms (00:04.276) [local]:5432 pg12@testdb=# update t_fillfactor_70 set c1=lpad('c1',30,'c1'),c2=lpad('c2',30,'c2'),c3=lpad('c3',30,'c3'); UPDATE 1000000 Time: 3856.575 ms (00:03.857) [local]:5432 pg12@testdb=# update t_fillfactor_50 set c1=lpad('c1',30,'c1'),c2=lpad('c2',30,'c2'),c3=lpad('c3',30,'c3'); UPDATE 1000000 Time: 4364.962 ms (00:04.365) [local]:5432 pg12@testdb=#
重新創(chuàng)建表,使用pgbench進(jìn)行測(cè)試
[local]:5432 pg12@testdb=# drop table if exists t_fillfactor_100; t,c1 varchar(30),c2 varchar(30),c3 varchar(30)) with (fillfactor=70); create table t_fillfactor_50(id int,c1 varchar(30),c2 varchar(30),c3 varchar(30)) with (fillfactor=50); insert into t_fillfactor_100(id,c1,c2,c3) select x,'c1'||x,'c2'||x,'c3'||x from generate_series(1,1000000) as x; insert into t_fillfactor_70(id,c1,c2,c3) select x,'c1'||x,'c2'||x,'c3'||x from generate_series(1,1000000) as x; insert into t_fillfactor_50(id,c1,c2,c3) select x,'c1'||x,'c2'||x,'c3'||x from generate_series(1,1000000) as x; DROP TABLE Time: 191.706 ms [local]:5432 pg12@testdb=# drop table if exists t_fillfactor_70; DROP TABLE Time: 35.313 ms [local]:5432 pg12@testdb=# drop table if exists t_fillfactor_50; DROP TABLE Time: 30.078 ms [local]:5432 pg12@testdb=# [local]:5432 pg12@testdb=# create table t_fillfactor_100(id int,c1 varchar(30),c2 varchar(30),c3 varchar(30)) with (fillfactor=100); CREATE TABLE Time: 40.443 ms [local]:5432 pg12@testdb=# create table t_fillfactor_70(id int,c1 varchar(30),c2 varchar(30),c3 varchar(30)) with (fillfactor=70); CREATE TABLE Time: 1.334 ms [local]:5432 pg12@testdb=# create table t_fillfactor_50(id int,c1 varchar(30),c2 varchar(30),c3 varchar(30)) with (fillfactor=50); CREATE TABLE Time: 1.024 ms [local]:5432 pg12@testdb=# [local]:5432 pg12@testdb=# insert into t_fillfactor_100(id,c1,c2,c3) select x,'c1'||x,'c2'||x,'c3'||x from generate_series(1,1000000) as x; INSERT 0 1000000 Time: 2623.943 ms (00:02.624) [local]:5432 pg12@testdb=# insert into t_fillfactor_70(id,c1,c2,c3) select x,'c1'||x,'c2'||x,'c3'||x from generate_series(1,1000000) as x; INSERT 0 1000000 Time: 2543.045 ms (00:02.543) [local]:5432 pg12@testdb=# insert into t_fillfactor_50(id,c1,c2,c3) select x,'c1'||x,'c2'||x,'c3'||x from generate_series(1,1000000) as x; INSERT 0 1000000 Time: 2662.223 ms (00:02.662) [local]:5432 pg12@testdb=#
使用pgbench進(jìn)行測(cè)試
[pg12@localhost script]$ cat update_100.sql \set id random(1,1000000) begin; update t_fillfactor_100 set c1=lpad('c1',30,'c1'),c2=lpad('c2',30,'c2'),c3=lpad('c3',30,'c3') where id= :id; end; [pg12@localhost script]$ cat update_70.sql \set id random(1,1000000) begin; update t_fillfactor_70 set c1=lpad('c1',30,'c1'),c2=lpad('c2',30,'c2'),c3=lpad('c3',30,'c3') where id= :id; end; [pg12@localhost script]$ cat update_50.sql \set id random(1,1000000) begin; update t_fillfactor_50 set c1=lpad('c1',30,'c1'),c2=lpad('c2',30,'c2'),c3=lpad('c3',30,'c3') where id= :id; end; [pg12@localhost script]$ pgbench -c 2 -C -f ~/script/update_100.sql -j 1 -n -T 60 -U pg12 testdb transaction type: /home/pg12/script/update_100.sql scaling factor: 1 query mode: simple number of clients: 2 number of threads: 1 duration: 60 s number of transactions actually processed: 691 latency average = 174.136 ms tps = 11.485277 (including connections establishing) tps = 11.625959 (excluding connections establishing) [pg12@localhost script]$ pgbench -c 2 -C -f ~/script/update_70.sql -j 1 -n -T 60 -U pg12 testdb transaction type: /home/pg12/script/update_70.sql scaling factor: 1 query mode: simple number of clients: 2 number of threads: 1 duration: 60 s number of transactions actually processed: 652 latency average = 184.293 ms tps = 10.852275 (including connections establishing) tps = 10.981136 (excluding connections establishing) [pg12@localhost script]$ pgbench -c 2 -C -f ~/script/update_50.sql -j 1 -n -T 60 -U pg12 testdb transaction type: /home/pg12/script/update_50.sql scaling factor: 1 query mode: simple number of clients: 2 number of threads: 1 duration: 60 s number of transactions actually processed: 627 latency average = 191.700 ms tps = 10.432967 (including connections establishing) tps = 10.551899 (excluding connections establishing) [pg12@localhost script]$
使用pgbench使用隨機(jī)值進(jìn)行測(cè)試,時(shí)長(zhǎng)為60s,結(jié)果差別不大.
數(shù)據(jù)表大小的比較:
[local]:5432 pg12@testdb=# select pg_size_pretty(pg_relation_size('t_fillfactor_100')); pg_size_pretty ---------------- 58 MB (1 row) Time: 2.034 ms [local]:5432 pg12@testdb=# select pg_size_pretty(pg_relation_size('t_fillfactor_70')); pg_size_pretty ---------------- 82 MB (1 row) Time: 1.469 ms [local]:5432 pg12@testdb=# select pg_size_pretty(pg_relation_size('t_fillfactor_50')); pg_size_pretty ---------------- 117 MB (1 row) Time: 2.531 ms [local]:5432 pg12@testdb=#
分別是58MB vs 82MB vs 117MB ≈ 100 vs 70 vs 50
感謝各位的閱讀,以上就是“怎么理解PostgreSQL創(chuàng)建數(shù)據(jù)表時(shí)的參數(shù)fillfactor”的內(nèi)容了,經(jīng)過(guò)本文的學(xué)習(xí)后,相信大家對(duì)怎么理解PostgreSQL創(chuàng)建數(shù)據(jù)表時(shí)的參數(shù)fillfactor這一問(wèn)題有了更深刻的體會(huì),具體使用情況還需要大家實(shí)踐驗(yàn)證。這里是創(chuàng)新互聯(lián),小編將為大家推送更多相關(guān)知識(shí)點(diǎn)的文章,歡迎關(guān)注!
本文標(biāo)題:怎么理解PostgreSQL創(chuàng)建數(shù)據(jù)表時(shí)的參數(shù)fillfactor
轉(zhuǎn)載來(lái)源:http://chinadenli.net/article48/jioiep.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供App開(kāi)發(fā)、定制開(kāi)發(fā)、商城網(wǎng)站、品牌網(wǎng)站制作、面包屑導(dǎo)航、外貿(mào)建站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話(huà):028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)