GPDB查看錶分佈策略資訊
Goal
Is to provide a simple shell scripts to help administrator identify the distribution policy of the tables in the database.
Note :Please verify the script on a test cluster , before running it on production .
Execution
Use the below steps to execute the query
/bin/sh get_distribution_policy.sh <database-name> <postgress-port>
Script
The complete shell script ( also available as attachment at the bottom of the article ).
#!/bin/bash # # get_distribution_policy.sh # pivotal - 2014 # # # # Function : To extract all the user tables. extract_table() { # echo "INFO - Extracting all the table names, schema name and oid's" # echo psql -d $PGDATABASE -p $PGPORT -Atc "SELECT a.oid , nspname , relname FROM pg_class a , pg_namespace b WHERE relkind='r' AND b.oid=a.relnamespace AND relname not in (select partitiontablename from pg_partitions) AND relnamespace in ( select oid from pg_namespace where nspname not in ('gp_toolkit','pg_toast','pg_aoseg','information_schema','pg_catalog') and nspname not like 'pg_temp%') order by 3" > $extract_table } # Function : To extract all the distribution policy. ext_parent_tb_dist_plcy() { # echo "INFO - Extracting the distribution policy for the collected table " # echo cat $extract_table | while read line do export i=`echo $line | cut -d'|' -f1` export j=`echo $line | cut -d'|' -f2` export k=`echo $line | cut -d'|' -f3` psql -d $PGDATABASE -p $PGPORT -xtc "SELECT localoid , attrnums FROM gp_distribution_policy where localoid=($i)" | tr -d '{}' | tr -d '|' | grep -v row > $ext_tab_parent_dist_info export table_oid=`grep localoid $ext_tab_parent_dist_info | awk '{print $2}'` export table_dist_col=`grep attrnums $ext_tab_parent_dist_info | awk '{print $2}'` if [ "$table_dist_col" = "" ]; then echo $j " " $k " Random">> $random_info else psql -d $PGDATABASE -p $PGPORT -Atc "SELECT attname FROM pg_attribute WHERE attrelid in ($table_oid) and attnum in ($table_dist_col)" | awk '{ printf $1 ","}' | sed s/.$// > $ext_tab_parent_dist_col_info echo $j " " $k " " `cat $ext_tab_parent_dist_col_info` >> $non_random_info fi done } # Function : To Print all the all the user tables. print_table_distribution() { # echo "INFO - Priniting the distribution policy of the table in the database " $PGDATABASE # echo echo "----| Table Name - With Random Distribution Policy |----" echo awk 'BEGIN { printf "%-30s %-30s %s\n", "SCHEMA-NAME","TABLE-NAME","DISTRIBUTION-POLICY" printf "%-30s %-30s %s\n", "-----------","----------","-------------------" } { printf "%-30s %-30s %s\n", $1, $2 , $3 }' $random_info echo echo "----| Table Name - With Distribution Policy |----" echo awk 'BEGIN { printf "%-30s %-30s %s\n", "SCHEMA-NAME","TABLE-NAME","DISTRIBUTION-POLICY" printf "%-30s %-30s %s\n", "-----------","----------","-------------------" } { printf "%-30s %-30s %s\n", $1, $2 , $3 }' $non_random_info } # Main program starts here # Checking the parameter passed echo echo "INFO - Checking the parameter passed for the script: " $0 echo if [ $# -lt 2 ] then echo "ERR - Script cannot execute since one / more parameters is missing" echo "ERR - Usage: $0 { Please provide us the database name & port number }" echo "INFO - Example to run is /bin/sh get_distribution_policy.sh template1 5432" echo exit 1 fi # Acception of the parameters # echo "INFO - Passing the parameters passed to variables " # echo export PGDATABASE=$1 export PGPORT=$2 export extract_table=/tmp/extract_table export ext_tab_parent_dist_info=/tmp/ext_tab_parent_dist_info export ext_tab_parent_dist_col_info=/tmp/ext_tab_parent_dist_col_info export random_info=/tmp/random_info export non_random_info=/tmp/non_random_info export junkfile=/tmp/junkfile # Remove old temporary files. # echo "INFO - Removing the old / temporary files from previous run, if any" # echo if (test -f $extract_table ) then rm -r $extract_table > $junkfile 2>> $junkfile fi if (test -f $ext_tab_parent_dist_info) then rm -r $ext_tab_parent_dist_info > $junkfile 2>> $junkfile fi if (test -f $ext_tab_parent_dist_col_info) then rm -r $ext_tab_parent_dist_col_info > $junkfile 2>> $junkfile fi if (test -f $random_info) then rm -r $random_info > $junkfile 2>> $junkfile fi if (test -f $non_random_info) then rm -r $non_random_info > $junkfile 2>> $junkfile fi # Calling the Function to confirm the script execution extract_table ext_parent_tb_dist_plcy print_table_distribution
Output
The output of the script would look like
gpadmin:[email protected] $ /bin/sh get_distribution_policy.sh gpadmin 9999 INFO - Checking the parameter passed for the script: get_distribution_policy.sh ----| Table Name - With Random Distribution Policy |---- SCHEMA-NAME TABLE-NAME DISTRIBUTION-POLICY ----------- ---------- ------------------- public process_err Random public test_9908 Random public webhold_1 Random ----| Table Name - With Distribution Policy |---- SCHEMA-NAME TABLE-NAME DISTRIBUTION-POLICY ----------- ---------- ------------------- public a id public test_0000 a,b,c public test_00000 a,b,c
Alternative script to retreive the same information is availablehere
相關推薦
GPDB查看錶分佈策略資訊
Goal Is to provide a simple shell scripts to help administrator identify the distribution policy of the tables in the database. Note :Please verify the sc
mysql查看錶結構資訊
需求背景是給一個表名然後給出相應的表結構資訊及索引資訊 常用的命令有如下: 1. desc tableName; desc employees.employees; 2. show columns from tableName; show COLUMNS from employees.employe
mysql查看錶結構資訊需求背景是給一個表名然後給出相應的表結構資訊及索引資訊 常用的命令有如下: 1. desc tableName; desc employees.employees; 2. sh
需求背景是給一個表名然後給出相應的表結構資訊及索引資訊 常用的命令有如下: 1. desc tableName; desc employees.employees; 2. show columns from tableName; show COLUMNS from employees.employe
oracle 查看錶資訊命令
表註釋和欄位註釋 --表 註釋 select * from all_tab_comments where table_name= upper('table_name') ; --欄位註釋 select * from all_col_comment
【Linux】mysql命令列查看錶結構,欄位等資訊
mysql查看錶結構命令,如下: desc table_name; //查表的欄位資訊(不包含欄位內容) show columns from table_name; //同上 show create table table_name; //查表字段資訊和字符集資訊
mysql命令列查看錶結構,欄位等資訊 和 TRUNCATE TABLE
mysql查看錶結構命令,如下: desc 表名; show columns from 表名; describe 表名; show create table 表名; use information_schema select * from columns where tab
如何查看錶和索引的統計資訊
這幾天要求做一個伺服器的統計資訊,主要針對表和索引。下面我就簡單分享幾個查詢資料表和索引統計資訊的方法: 1.使用T-SQL 語句實現: select schema_name(t.schema_id) AS '架構', t.name AS
mysql命令列查看錶結構,欄位等資訊
mysql查看錶結構命令,如下: desc 表名; show columns from 表名; describe 表名; show create table 表名; use information_schema select * from columns where tab
hive表資訊查詢:查看錶結構、表操作、建表語句
問題導讀: 1.如何檢視hive表結構? 2.如何查看錶結構資訊? 3.如何檢視分割槽資訊?4.哪個命令可以模糊搜尋表 28.怎麼查詢建立表語句 1.hive模糊搜尋表 show tables like '*name*'; 2.查看錶結構資訊 desc forma
查看錶佔用空間
oracle: SELECT segment_name, bytes FROM user_segments WHERE segment_type = 'TABLE'; mysql: SELECT CONCAT(ROUND(SUM(data_length/1024/1024),2),
oracle資料庫查看錶和表字段的語句
1.檢視當前使用者的表 select * from user_tables tt where tt.TABLE_NAME=upper('表名稱'); 2.查看錶對應的欄位 select * from user_tab_columns t3 where t3.T
SqlServer查看錶大小
以下是sp_spaceused和sp_MSforeachtable具體的使用示例: exec sp_spaceused '表名' (查詢表所佔
mybatis 動態新增表,查看錶,新增資料
1.動態新增表 mapper int dropExistTable(@Param("tableName") String tableName);//自動建立資料表 對映檔案 <update id="dropExistTable" paramet
Oracle查看錶鎖定及解鎖
在對Oracle資料庫的Update或者Insert等操作沒有反應時,很有可能是因為被操作的表被鎖定,導致無法進行操作。這個時候需要解鎖。 首先檢視具體有哪些表被鎖定 SELECT object_name, machine, s.sid, s.serial# FROM gv$locked_obje
資料庫MySQL之如何查看錶?
資料庫MySQL之如何查看錶? 檢視資料表列表語法 SHOW TABLES [FROM db_name] [LIKE 'pattern' | WHERE expr] 1. 檢視當前資料庫中的表 SHOW TABLES; 2. FROM之後,當前資
oracle資料庫查看錶空間預設大小及使用情況總結
oracle查詢資料庫的預設表空間情況操作步驟如下: 1. 查詢使用者對應的表空間,我們可以看到針對不同的資料庫使用者Oracle select username, default_tablespace, temporary_tablespace from dba_u
Oracle 查看錶空間的名稱及大小 表空間物理檔案的名稱及大小 回滾段名稱及大小 表空間的使用情況 控制檔案 日誌檔案 歸檔方式
首頁 > 資料庫 > Oracle > Oracle 查看錶空間的大小及使用情況sql語句 Oracle 查看錶空間的大小及使用情況sql語句 Oracle 作者:454629049&n
查看錶空間和表的使用率
1. 查看錶空間使用率 --查詢表空間的總容量 select tablespace_name,sum(bytes) /1024/1024 as MB from dba_data_files group by tablespace_name;
mysql查看錶空間佔用情況
${database} 為資料庫的名稱/*1.檢視索引 (1)單位是GB*/ SELECT CONCAT(ROUND(SUM(index_length)/(1024*1024*1024), 6), ' GB') AS 'Total Index Size' FROM i
mysql8基礎 select * 查看錶中的所有內容
資料,資料,命根就在資料 ! 操作資料庫時,一定要謹慎小心。師萬物 這裡的程式碼看看就好,要有自己的判斷。遇到抉擇,要不恥上下問。 example stu@Ubuntu:~$ mysql -u root -p Enter password: Welc