您好,登录后才能下订单哦!
这篇文章主要讲解了“怎么使用PostgreSQL的INDEX_CLEANUP”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“怎么使用PostgreSQL的INDEX_CLEANUP”吧!
VACUUM命令在PG 12有所增强,提供新的Option可供选择
PG 11 vacuum命令
[xdb@localhost ~]$ psql -d testdb -p 5433 psql (11.2) Type "help" for help. testdb=# \help vacuum; Command: VACUUM Description: garbage-collect and optionally analyze a database Syntax: VACUUM [ ( option [, ...] ) ] [ table_and_columns [, ...] ] VACUUM [ FULL ] [ FREEZE ] [ VERBOSE ] [ ANALYZE ] [ table_and_columns [, ...] ] where option can be one of: FULL FREEZE VERBOSE ANALYZE DISABLE_PAGE_SKIPPING and table_and_columns is: table_name [ ( column_name [, ...] ) ] testdb=#
PG 12 vacuum命令
[local]:5432 pg12@pgbench=# 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: 11.981 ms [local]:5432 pg12@pgbench=# \help vacuum Command: VACUUM Description: garbage-collect and optionally analyze a database Syntax: VACUUM [ ( option [, ...] ) ] [ table_and_columns [, ...] ] VACUUM [ FULL ] [ FREEZE ] [ VERBOSE ] [ ANALYZE ] [ table_and_columns [, ...] ] where option can be one of: FULL [ boolean ] FREEZE [ boolean ] VERBOSE [ boolean ] ANALYZE [ boolean ] DISABLE_PAGE_SKIPPING [ boolean ] SKIP_LOCKED [ boolean ] INDEX_CLEANUP [ boolean ] TRUNCATE [ boolean ] and table_and_columns is: table_name [ ( column_name [, ...] ) ] URL: https://www.postgresql.org/docs/12/sql-vacuum.html [local]:5432 pg12@pgbench=#
下面通过pgbench执行简单的测试
[pg12@localhost ~]$ createdb pgbench; [pg12@localhost ~]$ pgbench --initialize --scale=100 pgbench dropping old tables... NOTICE: table "pgbench_accounts" does not exist, skipping NOTICE: table "pgbench_branches" does not exist, skipping NOTICE: table "pgbench_history" does not exist, skipping NOTICE: table "pgbench_tellers" does not exist, skipping creating tables... generating data... 100000 of 10000000 tuples (1%) done (elapsed 0.14 s, remaining 14.30 s)
使用pgbench执行60s的压力测试
[pg12@localhost ~]$ pgbench --no-vacuum --time=60 --client=2 --jobs=2 pgbench transaction type: <builtin: TPC-B (sort of)> scaling factor: 100 query mode: simple number of clients: 2 number of threads: 2 duration: 60 s number of transactions actually processed: 42499 latency average = 2.824 ms tps = 708.298224 (including connections establishing) tps = 708.325760 (excluding connections establishing) [pg12@localhost ~]$
执行常规的vacuum
[local]:5432 pg12@testdb=# VACUUM (VERBOSE) pgbench_accounts ; ERROR: relation "pgbench_accounts" does not exist Time: 54.069 ms [local]:5432 pg12@testdb=# \c pgbench You are now connected to database "pgbench" as user "pg12". [local]:5432 pg12@pgbench=# VACUUM (VERBOSE) pgbench_accounts ; INFO: vacuuming "public.pgbench_accounts" INFO: scanned index "pgbench_accounts_pkey" to remove 37520 row versions DETAIL: CPU: user: 1.28 s, system: 0.68 s, elapsed: 2.54 s INFO: "pgbench_accounts": removed 37520 row versions in 37520 pages DETAIL: CPU: user: 0.21 s, system: 0.04 s, elapsed: 0.28 s INFO: index "pgbench_accounts_pkey" now contains 10000000 row versions in 27422 pages DETAIL: 37520 index row versions were removed. 0 index pages have been deleted, 0 are currently reusable. CPU: user: 0.00 s, system: 0.00 s, elapsed: 0.00 s. INFO: "pgbench_accounts": found 37444 removable, 9976515 nonremovable row versions in 164166 out of 164551 pages DETAIL: 0 dead row versions cannot be removed yet, oldest xmin: 48279 There were 7 unused item identifiers. Skipped 0 pages due to buffer pins, 0 frozen pages. 0 pages are entirely empty. CPU: user: 3.15 s, system: 7.45 s, elapsed: 11.31 s. VACUUM Time: 11811.362 ms (00:11.811) [local]:5432 pg12@pgbench=#
再次使用pgbench执行压力测试,但在执行vacumm指定INDEX_CLEANUP选项为false
[pg12@localhost ~]$ pgbench --no-vacuum --time=60 --client=2 --jobs=2 pgbench transaction type: <builtin: TPC-B (sort of)> scaling factor: 100 query mode: simple number of clients: 2 number of threads: 2 duration: 60 s number of transactions actually processed: 41268 latency average = 2.908 ms tps = 687.790258 (including connections establishing) tps = 687.817603 (excluding connections establishing) [local]:5432 pg12@pgbench=# VACUUM (INDEX_CLEANUP False, VERBOSE) pgbench_accounts ; INFO: vacuuming "public.pgbench_accounts" INFO: "pgbench_accounts": found 36498 removable, 10000000 nonremovable row versions in 164967 out of 164967 pages DETAIL: 0 dead row versions cannot be removed yet, oldest xmin: 168578 There were 161 unused item identifiers. Skipped 0 pages due to buffer pins, 0 frozen pages. 0 pages are entirely empty. CPU: user: 0.96 s, system: 4.10 s, elapsed: 5.30 s. VACUUM Time: 5314.340 ms (00:05.314) [local]:5432 pg12@pgbench=#
跳过了Index的清理,再次执行vacumm,这次指定INDEX_CLEANUP为true
[local]:5432 pg12@pgbench=# VACUUM (INDEX_CLEANUP true, VERBOSE) pgbench_accounts ; INFO: vacuuming "public.pgbench_accounts" INFO: scanned index "pgbench_accounts_pkey" to remove 84133 row versions DETAIL: CPU: user: 2.48 s, system: 0.98 s, elapsed: 3.53 s INFO: scanned index "idx_accounts_bid" to remove 84133 row versions DETAIL: CPU: user: 1.54 s, system: 1.13 s, elapsed: 2.80 s INFO: "pgbench_accounts": removed 84133 row versions in 81168 pages DETAIL: CPU: user: 1.09 s, system: 2.47 s, elapsed: 5.04 s INFO: index "pgbench_accounts_pkey" now contains 10000000 row versions in 27422 pages DETAIL: 84133 index row versions were removed. 0 index pages have been deleted, 0 are currently reusable. CPU: user: 0.00 s, system: 0.00 s, elapsed: 0.00 s. INFO: index "idx_accounts_bid" now contains 10000000 row versions in 27665 pages DETAIL: 25763 index row versions were removed. 0 index pages have been deleted, 0 are currently reusable. CPU: user: 0.00 s, system: 0.00 s, elapsed: 0.00 s. INFO: "pgbench_accounts": found 0 removable, 10000000 nonremovable row versions in 164967 out of 164967 pages DETAIL: 0 dead row versions cannot be removed yet, oldest xmin: 168578 There were 161 unused item identifiers. Skipped 0 pages due to buffer pins, 0 frozen pages. 0 pages are entirely empty. CPU: user: 6.03 s, system: 5.34 s, elapsed: 13.06 s. VACUUM Time: 13109.490 ms (00:13.109) [local]:5432 pg12@pgbench=#
这次操作只对index执行清理.
PG 12提供的INDEX_CLEANUP vacumm选项在对大表并存在多索引进行清理时可有效的缩短执行时间,但index上的废弃tuple仍然保留,空间仍会膨胀,只不过时间滞后了而已.
感谢各位的阅读,以上就是“怎么使用PostgreSQL的INDEX_CLEANUP”的内容了,经过本文的学习后,相信大家对怎么使用PostgreSQL的INDEX_CLEANUP这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是亿速云,小编将为大家推送更多相关知识点的文章,欢迎关注!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。