Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions core/Command/Db/DbIndexUsage.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
*/
namespace OC\Core\Command\Db;

use Doctrine\DBAL\Platforms\MySQLPlatform;
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
use OC\DB\Connection;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Doctrine\DBAL\Platforms\MySQLPlatform;
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;

class DbIndexUsage extends Command {

Expand Down
14 changes: 7 additions & 7 deletions core/Command/Db/DbInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
*/
namespace OC\Core\Command\Db;

use Doctrine\DBAL\Platforms\MySQLPlatform;
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
use Doctrine\DBAL\Platforms\SqlitePlatform;
use OC\DB\Connection;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Doctrine\DBAL\Platforms\MySQLPlatform;
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
use Doctrine\DBAL\Platforms\SqlitePlatform;

class DbInfo extends Command {

Expand All @@ -37,7 +37,7 @@ protected function configure(): void {
#[\Override]
protected function execute(InputInterface $input, OutputInterface $output): int {
$platform = $this->connection->getDatabasePlatform();
$asJson = $input->getOption('json');
$asJson = $input->getOption('json');

if ($platform instanceof MySQLPlatform) {
$rows = $this->getMySQLInfo();
Expand Down Expand Up @@ -76,9 +76,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int

private function getMySQLInfo(): array {
$result = $this->connection->executeQuery(
"SELECT VERSION() AS version, @@innodb_buffer_pool_size AS buffer_pool,
'SELECT VERSION() AS version, @@innodb_buffer_pool_size AS buffer_pool,
@@max_connections AS max_conn, @@character_set_database AS charset,
@@transaction_isolation AS tx_isolation"
@@transaction_isolation AS tx_isolation'
);
$info = $result->fetchAssociative();

Expand Down Expand Up @@ -114,7 +114,7 @@ private function getPostgreSQLInfo(): array {

private function getSQLiteInfo(): array {
$result = $this->connection->executeQuery('SELECT sqlite_version() AS version');
$info = $result->fetchAssociative();
$info = $result->fetchAssociative();
return [
['setting' => 'Engine', 'value' => 'SQLite'],
['setting' => 'Version', 'value' => $info['version']],
Expand Down
16 changes: 8 additions & 8 deletions core/Command/Db/DbLocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
*/
namespace OC\Core\Command\Db;

use Doctrine\DBAL\Platforms\MySQLPlatform;
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
use OC\DB\Connection;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Doctrine\DBAL\Platforms\MySQLPlatform;
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;

class DbLocks extends Command {

Expand All @@ -39,19 +39,19 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$asJson = $input->getOption('json');

if ($platform instanceof MySQLPlatform) {
$sql = "SELECT r.trx_id AS waiting_trx_id,
$sql = 'SELECT r.trx_id AS waiting_trx_id,
r.trx_mysql_thread_id AS waiting_thread,
r.trx_query AS waiting_query,
b.trx_id AS blocking_trx_id,
b.trx_mysql_thread_id AS blocking_thread,
b.trx_query AS blocking_query
FROM information_schema.innodb_lock_waits w
JOIN information_schema.innodb_trx b ON b.trx_id = w.blocking_trx_id
JOIN information_schema.innodb_trx r ON r.trx_id = w.requesting_trx_id";
JOIN information_schema.innodb_trx r ON r.trx_id = w.requesting_trx_id';
$headers = ['Waiting TRX', 'Waiting Thread', 'Waiting Query', 'Blocking TRX', 'Blocking Thread', 'Blocking Query'];
$cols = ['waiting_trx_id', 'waiting_thread', 'waiting_query', 'blocking_trx_id', 'blocking_thread', 'blocking_query'];
} elseif ($platform instanceof PostgreSQLPlatform) {
$sql = "SELECT blocked_locks.pid AS blocked_pid,
$sql = 'SELECT blocked_locks.pid AS blocked_pid,
blocked_activity.usename AS blocked_user,
blocking_locks.pid AS blocking_pid,
blocking_activity.usename AS blocking_user,
Expand All @@ -65,9 +65,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int
AND blocking_locks.relation IS NOT DISTINCT FROM blocked_locks.relation
AND blocking_locks.pid != blocked_locks.pid
JOIN pg_catalog.pg_stat_activity blocking_activity ON blocking_activity.pid = blocking_locks.pid
WHERE NOT blocked_locks.granted";
WHERE NOT blocked_locks.granted';
$headers = ['Blocked PID', 'Blocked User', 'Blocking PID', 'Blocking User', 'Blocked Query', 'Duration'];
$cols = ['blocked_pid', 'blocked_user', 'blocking_pid', 'blocking_user', 'blocked_query', 'blocked_duration'];
$cols = ['blocked_pid', 'blocked_user', 'blocking_pid', 'blocking_user', 'blocked_query', 'blocked_duration'];
} else {
$output->writeln('<comment>db:locks is not supported for SQLite and Oracle (SQLite uses file-level locking).</comment>');
return Command::SUCCESS;
Expand All @@ -92,7 +92,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$table->setHeaders($headers);

foreach ($rows as $row) {
$table->addRow(array_map(fn($col) => $row[$col] ?? '—', $cols));
$table->addRow(array_map(fn ($col) => $row[$col] ?? '—', $cols));
}

$table->render();
Expand Down
16 changes: 8 additions & 8 deletions core/Command/Db/DbSize.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
*/
namespace OC\Core\Command\Db;

use Doctrine\DBAL\Platforms\MySQLPlatform;
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
use OC\DB\Connection;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Doctrine\DBAL\Platforms\MySQLPlatform;
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;

class DbSize extends Command {

Expand All @@ -36,10 +36,10 @@ protected function configure(): void {
#[\Override]
protected function execute(InputInterface $input, OutputInterface $output): int {
$platform = $this->connection->getDatabasePlatform();
$asJson = $input->getOption('json');
$asJson = $input->getOption('json');

if ($platform instanceof MySQLPlatform) {
$sql = "
$sql = '
SELECT table_name AS `table`,
ROUND((data_length + index_length) / 1024 / 1024, 2) AS total_mb,
ROUND(data_length / 1024 / 1024, 2) AS data_mb,
Expand All @@ -49,9 +49,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int
FROM information_schema.tables
WHERE table_schema = DATABASE()
ORDER BY (data_length + index_length) DESC
";
';
$headers = ['Table', 'Total (MB)', 'Data (MB)', 'Index (MB)', 'Rows', 'Avg Row (bytes)'];
$cols = ['table', 'total_mb', 'data_mb', 'index_mb', 'rows', 'avg_row_bytes'];
$cols = ['table', 'total_mb', 'data_mb', 'index_mb', 'rows', 'avg_row_bytes'];
} elseif ($platform instanceof PostgreSQLPlatform) {
$sql = "
SELECT relname AS table,
Expand All @@ -66,7 +66,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
ORDER BY pg_total_relation_size(c.oid) DESC
";
$headers = ['Table', 'Total (MB)', 'Data (MB)', 'Index (MB)', 'Rows (est.)', 'Avg Row (bytes)'];
$cols = ['table', 'total_mb', 'data_mb', 'index_mb', 'rows', 'avg_row_bytes'];
$cols = ['table', 'total_mb', 'data_mb', 'index_mb', 'rows', 'avg_row_bytes'];
} else {
$output->writeln('<comment>db:size is not supported for SQLite and Oracle.</comment>');
return Command::SUCCESS;
Expand All @@ -83,7 +83,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$table->setHeaders($headers);

foreach ($rows as $row) {
$table->addRow(array_map(fn($col) => $row[$col], $cols));
$table->addRow(array_map(fn ($col) => $row[$col], $cols));
}

$table->render();
Expand Down
Loading
Loading