Deepgreen(Greenplum)數據表集中Analyze腳本
數據加載完成以後,通常需要更新分析計劃,因為單獨做一個表的Analyze比較麻煩,整庫做Analyze會比較耗時,我們可以通過下麵這個腳本,指定Analyze部分表。
具體實踐時,隻需修改下麵對應的SQL語句、數據庫psql命令地址、IP端口及數據庫名即可:
#!/bin/bash
# filename: analyze_table.sh
# start time
start_time=$(date)
echo "-------- Start time is $start_time --------"
start_seconds=$(date +%s)
# get no partition tables
cmd_get_nopartitions="select schemaname||'.'||tablename as tablename from pg_tables where schemaname like 'rwnas_%' and tablename not like '%_1_prt_%' and schemaname||'.'||tablename not in (select schemaname||'.'||tablename from pg_partitions group by schemaname,tablename)"
exec_get_nopartitions=$(/app/greenplum-db-4.1.1.1/bin/psql -h 127.0.0.1 -p 5432 -d rwnas -U rwnas -t -c "${cmd_get_nopartitions}")
echo "${exec_get_nopartitions}" > nopartitions_tables.txt
echo "-------- No Partitions Tables List Below --------"
nopartitions_file=$(cat nopartitions_tables.txt)
echo "$nopartitions_file"
# analyze nopartition tables
rm -rf analyze_nopartitions_tables.txt
function for_np_file(){
for i in $nopartitions_file
do
echo "$(/app/greenplum-db-4.1.1.1/bin/psql -h 127.0.0.1 -p 5432 -d rwnas -U rwnas -c "analyze $i")"
echo "$i" >> analyze_nopartitions_tables.txt
done
}
for_np_file
# get partition tables
cmd_get_partitions="select schemaname||'.'||tablename as tablename from pg_partitions where schemaname like 'rwnas_%' group by schemaname, tablename"
exec_get_partitions=$(/app/greenplum-db-4.1.1.1/bin/psql -h 127.0.0.1 -p 5432 -d rwnas -U rwnas -t -c "${cmd_get_partitions}")
echo "${exec_get_partitions}" > partitions_tables.txt
echo "-------- Partitions Tables List Below --------"
partitions_file=$(cat partitions_tables.txt)
echo "$partitions_file"
# analyze partition tables
rm -rf analyze_partitions_tables.txt
function for_p_file(){
for q in $partitions_file
do
echo "$(/app/greenplum-db-4.1.1.1/bin/psql -h 127.0.0.1 -p 5432 -d rwnas -U rwnas -c "analyze $q")"
echo "$q" >> analyze_partitions_tables.txt
done
}
for_p_file
# end time
end_time=$(date)
echo "-------- End time is $end_time --------"
end_seconds=$(date +%s)
diff=$((end_seconds - start_seconds))
echo "Total $diff seconds."
最後更新:2017-06-12 00:31:51
上一篇:
Tideways和xhgui打造PHP非侵入式監控平台
下一篇:
Deepgreen數據庫日誌清理腳本
activiti 工作流的 整合視頻教程 SSM和獨立部署 web 流程設計器
pl/sql developer執行光標所在行
Docker: the Linux container engine
《正則表達式經典實例(第2版)》——第 2 章 正則表達式的基本技能 2.1匹配字麵文本
醫療護理與監測 智能可穿戴發展的另一個方向
struts2上傳的Web文件ContentType類型大全
android軟件開發之webView.addJavascriptInterface循環漸進【一】
16年IT老兵:技術管理者的多維度能力及轉型之痛
Java IO: PipedInputStream
Windows 8怎麼了?戴爾都想拋棄你了