LOGO OA教程 ERP教程 模切知識交流 PMS教程 CRM教程 開發文檔 其他文檔  
 
網站管理員

PostgreSQL 導出數據支持 LZ4 壓縮,速率與空間靈活掌控

admin
2025年6月14日 18:41 本文熱度 142

你需要 pg_dump 導出的數據文件更小嗎?或者,你需要 pg_dump 更快速地導出數據嗎?

?
沙灘上漫步的大象

特性提交日志

為 pg_dump 添加 LZ4 壓縮功能。

擴展 pg_dump 的壓縮流和文件 API 以支持 LZ4 算法。新添加的compress_lz4.{c,h}文件涵蓋了上述 API 的所有功能。需要在多個pg_backup_*文件中進行細微修改,添加針對 'lz4' 文件后綴的代碼,同時修改 pg_dump 壓縮選項的處理邏輯。

討論:https://postgr.es/m/faUNEOpts9vunEaLnmxmG-DldLSg_ql137OC3JYDmgrOMHm1RvvWY2IdBkv_CRxm5spCCb_OmKNk2T03TMm0fBEWveFF9wA1WizPuAgB7Ss%3D%40protonmail.com

示例

PostgreSQL 的最新版本已經引入了新的壓縮選項,并為 pg_dump 提供了 LZ4 壓縮。下面,讓我們來進行一次簡單的演示。

為了能導出一些內容,我們將使用 pgbench 創建一個小型數據庫:

psql -c "create database dump"

pgbench -i -s 100 dump
dropping old tables...
creating tables...
generating data (client-side)...
10000000 of 10000000 tuples (100%) done (elapsed 28.91 s, remaining 0.00 s)
vacuuming...
creating primary keys...
done in 36.32 s (drop tables 0.00 s, create tables 0.02 s, client-side generate 29.17 s, vacuum 0.57 s, primary keys 6.56 s).

讓我們使用傳統方式,使用 gzip 最高壓縮級別來轉儲它:

mkdir /var/tmp/dump
time pg_dump --format=d --compress=gzip:9 --file=/var/tmp/dump/gzip dump
real    0m12.332s
user    0m7.687s
sys     0m0.271s

ls -lha /var/tmp/dump/gzip/
total 27M
drwx------ 2 postgres postgres 4.0K May 24 09:02 .
drwxr-xr-x 3 postgres postgres 4.0K May 24 09:02 ..
-rw-r--r-- 1 postgres postgres   25 May 24 09:02 3347.dat.gz
-rw-r--r-- 1 postgres postgres 1.8K May 24 09:02 3348.dat.gz
-rw-r--r-- 1 postgres postgres  27M May 24 09:02 3349.dat.gz
-rw-r--r-- 1 postgres postgres  208 May 24 09:02 3350.dat.gz
-rw-r--r-- 1 postgres postgres 4.0K May 24 09:02 toc.dat

這大約花費了 12 秒,結果大約為 27MB。讓我們使用 LZ4 執行相同的操作:

time pg_dump --format=d --compress=lz4:9 --file=/var/tmp/dump/lz4 dump
real    0m10.803s
user    0m6.246s
sys     0m0.271s

ls -lha /var/tmp/dump/lz4
total 48M
drwx------ 2 postgres postgres 4.0K May 24 09:06 .
drwxr-xr-x 4 postgres postgres 4.0K May 24 09:06 ..
-rw-r--r-- 1 postgres postgres   20 May 24 09:06 3347.dat.lz4
-rw-r--r-- 1 postgres postgres 4.4K May 24 09:06 3348.dat.lz4
-rw-r--r-- 1 postgres postgres  48M May 24 09:06 3349.dat.lz4
-rw-r--r-- 1 postgres postgres  415 May 24 09:06 3350.dat.lz4
-rw-r--r-- 1 postgres postgres 4.0K May 24 09:06 toc.dat

這樣速度會快一點,但也占用了更多空間。使用較低級別會怎么樣呢?

rm -rf /var/tmp/dump/lz4
rm -rf /var/tmp/dump/gzip/

time pg_dump --format=d --compress=gzip:2 --file=/var/tmp/dump/gzip dump
real    0m7.819s
user    0m3.191s
sys     0m0.203s

time pg_dump --format=d --compress=lz4:2 --file=/var/tmp/dump/lz4 dump
real    0m5.426s
user    0m0.906s
sys     0m0.236s

ls -lha /var/tmp/dump/gzip
total 28M
drwx------ 2 postgres postgres 4.0K May 24 09:10 .
drwxr-xr-x 4 postgres postgres 4.0K May 24 09:10 ..
-rw-r--r-- 1 postgres postgres   25 May 24 09:10 3347.dat.gz
-rw-r--r-- 1 postgres postgres 2.3K May 24 09:10 3348.dat.gz
-rw-r--r-- 1 postgres postgres  28M May 24 09:10 3349.dat.gz
-rw-r--r-- 1 postgres postgres  206 May 24 09:10 3350.dat.gz
-rw-r--r-- 1 postgres postgres 4.0K May 24 09:10 toc.dat

ls -lha /var/tmp/dump/lz4/
total 50M
drwx------ 2 postgres postgres 4.0K May 24 09:10 .
drwxr-xr-x 4 postgres postgres 4.0K May 24 09:10 ..
-rw-r--r-- 1 postgres postgres   20 May 24 09:10 3347.dat.lz4
-rw-r--r-- 1 postgres postgres 4.5K May 24 09:10 3348.dat.lz4
-rw-r--r-- 1 postgres postgres  50M May 24 09:10 3349.dat.lz4
-rw-r--r-- 1 postgres postgres  426 May 24 09:10 3350.dat.lz4
-rw-r--r-- 1 postgres postgres 4.0K May 24 09:10 toc.dat

同樣的情況:gzip 壓縮效果更好,但 LZ4 壓縮速度更快。現在你可以自由選擇了。

非常不錯的特性。感謝社區的所有相關人員。

參考

提交日志:https://git.postgresql.org/pg/commitdiff/0da243fed0875932f781aff08df782b56af58d02


閱讀原文:https://mp.weixin.qq.com/s/KggAR26SU_z1NujRX9Wqmw


該文章在 2025/6/16 9:03:33 編輯過
關鍵字查詢
相關文章
正在查詢...
點晴ERP是一款針對中小制造業的專業生產管理軟件系統,系統成熟度和易用性得到了國內大量中小企業的青睞。
點晴PMS碼頭管理系統主要針對港口碼頭集裝箱與散貨日常運作、調度、堆場、車隊、財務費用、相關報表等業務管理,結合碼頭的業務特點,圍繞調度、堆場作業而開發的。集技術的先進性、管理的有效性于一體,是物流碼頭及其他港口類企業的高效ERP管理信息系統。
點晴WMS倉儲管理系統提供了貨物產品管理,銷售管理,采購管理,倉儲管理,倉庫管理,保質期管理,貨位管理,庫位管理,生產管理,WMS管理系統,標簽打印,條形碼,二維碼管理,批號管理軟件。
點晴免費OA是一款軟件和通用服務都免費,不限功能、不限時間、不限用戶的免費OA協同辦公管理系統。
Copyright 2010-2025 ClickSun All Rights Reserved

黄频国产免费高清视频,久久不卡精品中文字幕一区,激情五月天AV电影在线观看,欧美国产韩国日本一区二区
中文字幕玖玖资源亚洲精品 | 一本久久sm热国产斤 | 日韩在线一区天天看 | 亚洲国产中文在线二区三区 | 最新精品久久精品 | 日韩女同一区二区三区 |