no way to compare when less than two revisions
差異處
這裏顯示兩個版本的差異處。
— | sybase:db_space [2011/05/11 01:57] (目前版本) – 建立 jal | ||
---|---|---|---|
行 1: | 行 1: | ||
+ | ====== Sybase 資料庫空間 ====== | ||
+ | 在 Sybase 如果要看一個資料庫的整體使用空間,其實真的還蠻麻煩的。 | ||
+ | 後來找到一個 perl 檔可以快速的去計算目前使用量,作為是否要增加 Device 的依據。 | ||
+ | 該 Perl 檔的來源為:http:// | ||
+ | |||
+ | ===== 相依套件 ===== | ||
+ | * 在 FreeBSD 使用此套件除了 Perl 外還需要安裝下列二個套件 | ||
+ | - p5-DBI | ||
+ | - p5-DBD-Sybase | ||
+ | |||
+ | ===== 使用方式 ===== | ||
+ | <code cmd> | ||
+ | check-space.pl -U < | ||
+ | </ | ||
+ | |||
+ | ===== 程式碼 ===== | ||
+ | 備份一下,以避免它哪天消失了... | ||
+ | |||
+ | <file perl check-space.pl> | ||
+ | # | ||
+ | |||
+ | use strict; | ||
+ | use DBI; | ||
+ | |||
+ | use Getopt:: | ||
+ | |||
+ | my %args; | ||
+ | |||
+ | GetOptions(\%args, | ||
+ | |||
+ | my $dbh = DBI-> | ||
+ | |||
+ | $dbh-> | ||
+ | |||
+ | my $dbinfo; | ||
+ | |||
+ | # First check space in the DB: | ||
+ | my $sth = $dbh-> | ||
+ | $sth-> | ||
+ | do { | ||
+ | while(my $d = $sth-> | ||
+ | if($d-> | ||
+ | $d->[1] =~ s/ | ||
+ | $dbinfo-> | ||
+ | } else { | ||
+ | foreach (@$d) { | ||
+ | s/\D//g; | ||
+ | } | ||
+ | $dbinfo-> | ||
+ | $dbinfo-> | ||
+ | $dbinfo-> | ||
+ | } | ||
+ | } | ||
+ | } while($sth-> | ||
+ | |||
+ | # Get the actual device usage from sp_helpdb to get the free log space | ||
+ | $sth = $dbh-> | ||
+ | $sth-> | ||
+ | do { | ||
+ | while(my $d = $sth-> | ||
+ | if($d-> | ||
+ | $d->[1] =~ s/ | ||
+ | $dbinfo-> | ||
+ | my ($logfree) = $d->[3] =~ /(\d+)/; | ||
+ | $dbinfo-> | ||
+ | } | ||
+ | if($d-> | ||
+ | $dbinfo-> | ||
+ | } | ||
+ | } | ||
+ | } while($sth-> | ||
+ | |||
+ | $dbinfo-> | ||
+ | |||
+ | my $freepct = ($dbinfo-> | ||
+ | |||
+ | print " | ||
+ | printf " | ||
+ | printf "Log size: %10.2f MB\n", $dbinfo-> | ||
+ | printf "Free Log: %10.2f MB\n", $dbinfo-> | ||
+ | printf " | ||
+ | printf " | ||
+ | printf " | ||
+ | printf "Free space: | ||
+ | |||
+ | if($freepct < .25) { | ||
+ | printf " | ||
+ | } | ||
+ | |||
+ | print " | ||
+ | printf "%30s %15s %10s %10s %10s\n\n", | ||
+ | |||
+ | my @tables = getTables($dbh); | ||
+ | |||
+ | foreach (@tables) { | ||
+ | my $sth = $dbh-> | ||
+ | $sth-> | ||
+ | do { | ||
+ | while(my $d = $sth-> | ||
+ | foreach (@$d) { | ||
+ | s/KB//; | ||
+ | s/\s//g; | ||
+ | } | ||
+ | printf(" | ||
+ | | ||
+ | | ||
+ | } | ||
+ | } while($sth-> | ||
+ | } | ||
+ | |||
+ | |||
+ | sub getTables { | ||
+ | my $dbh = shift; | ||
+ | |||
+ | my $sth = $dbh-> | ||
+ | my @tables; | ||
+ | do { | ||
+ | while(my $d = $sth-> | ||
+ | push(@tables, | ||
+ | } | ||
+ | } while($sth-> | ||
+ | |||
+ | @tables; | ||
+ | } | ||
+ | </ |