Skip to content

feat(db): add occ db:info, db:size, db:index-usage and db:locks#60840

Merged
artonge merged 3 commits into
nextcloud:masterfrom
rodrigocorreiaist:feature/db-diagnostics
Jun 11, 2026
Merged

feat(db): add occ db:info, db:size, db:index-usage and db:locks#60840
artonge merged 3 commits into
nextcloud:masterfrom
rodrigocorreiaist:feature/db-diagnostics

Conversation

@rodrigocorreiaist

Copy link
Copy Markdown
Contributor

feat(occ): add db:info, db:size, db:index-usage, db:locks diagnostic commands

Body:

Implements RFC #59422. Adds four read-only diagnostic commands to the occ CLI:

  • db:info — engine version and key config variables with health checks
  • db:size — tables ordered by total disk usage
  • db:index-usage — unused indexes (MySQL via performance_schema, PostgreSQL via pg_stat_user_indexes)
  • db:locks — active blocking transactions and deadlocks

Supports MySQL/MariaDB and PostgreSQL. --json flag available for automated parsing.
Includes 31 unit tests.

Closes #59422

Implements RFC nextcloud#59422. Adds four read-only diagnostic commands to
the occ CLI for administrators to inspect database health without
needing external tools:

- db:info: shows engine version and key config variables with
  health check against recommended values
- db:size: lists all tables ordered by total disk usage
- db:index-usage: reports unused indexes via performance_schema
  (MySQL) or pg_stat_user_indexes (PostgreSQL)
- db:locks: detects active blocking transactions and deadlocks

All commands support MySQL/MariaDB and PostgreSQL. A --json flag
is available for automated parsing. Includes 31 unit tests.

Closes nextcloud#59422
Signed-off-by: Rodrigo Correia <rodrigo.mendes.correia@tecnico.ulisboa.pt>
Signed-off-by: Carolina Quinteiro <carolinafquinteiro@tecnico.ulisboa.pt>
Co-authored-by: Carolina Quinteiro <carolinafquinteiro@tecnico.ulisboa.pt>
@rodrigocorreiaist rodrigocorreiaist requested a review from a team as a code owner May 29, 2026 14:56
@rodrigocorreiaist rodrigocorreiaist requested review from CarlSchwan, icewind1991, leftybournes and provokateurin and removed request for a team May 29, 2026 14:56
@artonge artonge requested a review from Altahrim June 3, 2026 14:10
@susnux susnux added the community pull requests from community label Jun 9, 2026
@susnux susnux added this to the Nextcloud 35 milestone Jun 9, 2026

@CarlSchwan CarlSchwan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested and works great!

@artonge artonge merged commit 73272c3 into nextcloud:master Jun 11, 2026
110 of 121 checks passed
@welcome

welcome Bot commented Jun 11, 2026

Copy link
Copy Markdown

Thanks for your first pull request and welcome to the community! Feel free to keep them coming! If you are looking for issues to tackle then have a look at this selection: https://github.com/nextcloud/server/issues?q=is%3Aopen+is%3Aissue+label%3A%22good+first+issue%22

artonge added a commit that referenced this pull request Jun 11, 2026
Signed-off-by: Louis Chmn <louis@chmn.me>
artonge added a commit that referenced this pull request Jun 11, 2026
@kesselb

kesselb commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

@artonge @CarlSchwan Linter and Psalm failures are related.


if (!$showAll) {
$output->writeln(sprintf(
'<comment>Found %d unused index(es). Consider removing them to improve write performance.</comment>',

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should reword that ;)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would you put instead? It sounds clear to me, but maybe the meaning needs to be changed 😅

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI: #61208

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm unsure about suggestiong to remove an index. We don't want user's messing around with the db schema?

@artonge artonge Jun 11, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed in the follow-up PR

Suggested change
'<comment>Found %d unused index(es). Consider removing them to improve write performance.</comment>',
'<comment>Found %d unused index(es). If those were not created by Nextcloud, consider removing them to improve write performance.</comment>',

Comment thread core/Command/Db/DbLocks.php
Comment thread core/Command/Db/DbSize.php
Comment thread core/Command/Db/DbIndexUsage.php
artonge added a commit that referenced this pull request Jun 11, 2026
pull Bot pushed a commit to Klomgor/server that referenced this pull request Jun 11, 2026
Signed-off-by: Louis Chmn <louis@chmn.me>
giacomoarru pushed a commit to giacomoarru/server that referenced this pull request Jun 11, 2026
Signed-off-by: Louis Chmn <louis@chmn.me>
Signed-off-by: Jack Arru <jack@x2x.cloud>
giacomoarru pushed a commit to giacomoarru/server that referenced this pull request Jun 11, 2026
Signed-off-by: Louis Chmn <louis@chmn.me>
Signed-off-by: Jack Arru <jack@x2x.cloud>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community pull requests from community

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[RFC] Database CLI tools

5 participants