Last active
July 13, 2021 07:30
-
-
Save ManojKiranA/c4aeb6b3793fe3ccd2882fb5e187558a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//To Get Size of all the Databases | |
//please Avoid using this it will take very Long time based on the number of databases | |
$sizeOfAllDataBases = DB::table('information_schema.TABLES') | |
->select(['TABLE_NAME as TableName','table_rows as TableRows','data_length as DataLength','index_length as IndexLength','TABLE_SCHEMA as DatabaseName']) | |
->get() | |
->map(function($eachDatabse){ | |
$dataIndex = $eachDatabse->DataLength + $eachDatabse->IndexLength; | |
$modifiedObject = new \StdClass; | |
$kbSize = ($dataIndex/1024); | |
$mbSize = ($kbSize/1024); | |
$modifiedObject->SizeInKb = $kbSize; | |
$modifiedObject->SizeInMB = $mbSize; | |
return (object)array_merge((array)$eachDatabse,(array)$modifiedObject); | |
}) | |
->groupBy('DatabaseName') | |
->map(function($eachDb){ | |
return $eachDb->keyBy('TableName'); | |
}); | |
//To Get Size of Current Application Database | |
$sizeOfCurrentProjectDatabse = DB::table('information_schema.TABLES') | |
->select(['TABLE_NAME as TableName','table_rows as TableRows','data_length as DataLength','index_length as IndexLength']) | |
->where('information_schema.TABLES.table_schema','=',config('database.connections.'.config('database.default').'.database')) | |
->get() | |
->map(function($eachDatabse){ | |
$dataIndex = $eachDatabse->DataLength + $eachDatabse->IndexLength; | |
$modifiedObject = new \StdClass; | |
$kbSize = ($dataIndex/1024); | |
$mbSize = ($kbSize/1024); | |
$modifiedObject->SizeInKb = $kbSize; | |
$modifiedObject->SizeInMB = $mbSize; | |
return (object)array_merge((array)$eachDatabse,(array)$modifiedObject); | |
}) | |
->keyBy('TableName'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment