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."
目录
相关文章
|
3月前
|
存储 关系型数据库 MySQL
在阿里云的AnalyticDB MySQL版中使用CREATE TABLE语句来创建内表
在阿里云的AnalyticDB MySQL版中使用CREATE TABLE语句来创建内表【1月更文挑战第16天】【1月更文挑战第78篇】
210 3
|
9月前
|
存储 数据库
GreenPlum ANALYZE
分析有关的表的数据库中的系统表pg_statistic里的内容,并存储该结果收集统计信息。随后,Greenplum数据引擎使用这些数据来帮助判断查询的最有效的执行计划。
45 0
|
8月前
|
SQL 前端开发 关系型数据库
pg库实现sql行转列
这个主题还是比较常见的,行转列主要适用于对数据作聚合统计,如统计某类目的商品在某个时间区间的销售情况。列转行问题同样也很常见。
223 0
pg库实现sql行转列
|
SQL 关系型数据库 数据库
|
SQL 缓存 关系型数据库
分布式 PostgreSQL,Citus 11.x SQL 参考(中文手册)
分布式 PostgreSQL,Citus 11.x SQL 参考(中文手册)
519 0
|
存储 SQL JSON
Citus 分布式 PostgreSQL 集群 - SQL Reference(查询分布式表 SQL)
Citus 分布式 PostgreSQL 集群 - SQL Reference(查询分布式表 SQL)
177 0
|
索引
PolarDB-X 1.0-SQL 手册-DDL-RENAME TABLE
您可以使用RENAME TABLE语句对表名进行重命名,具体语法如下: RENAME TABLE tbl_name TO new_tbl_name
198 0
|
关系型数据库 MySQL
PolarDB-X 1.0-SQL 手册-DDL-TRUNCATE TABLE
TRUNCATE TABLE 用于清空表中的数据,需要有 DROP 权限。
103 0
|
关系型数据库 MySQL 分布式数据库
PolarDB-X 1.0-SQL 手册-DDL-DROP TABLE
DROP [TEMPORARY] TABLE [IF EXISTS] tbl_name [, tbl_name] ... [RESTRICT | CASCADE]
110 0
|
SQL 关系型数据库 MySQL
PolarDB-X 1.0-SQL 手册-DDL-ALTER TABLE
语法 ALTER [ONLINE|OFFLINE] [IGNORE] TABLE tbl_name [alter_specification [, alter_specification] ...] [partition_options]
130 0