From 719248cdc3e692d575dc0ec9301fece70269e317 Mon Sep 17 00:00:00 2001 From: Max Semenik Date: Sun, 18 Oct 2009 10:55:36 +0000 Subject: [PATCH] Added a script for SQLite-specific maintenance tasks --- RELEASE-NOTES | 1 + maintenance/sqlite.php | 80 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 maintenance/sqlite.php diff --git a/RELEASE-NOTES b/RELEASE-NOTES index ff9dd16c91..58bfc33ad9 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -248,6 +248,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN * (bug 21095) Tracking categories produced by the parser (expensive parser function limit exceeded, __NOINDEX__ tracking, etc) can now be disabled by setting the system message ([[MediaWiki:expensive-parserfunction-category]] etc) to "-". +* Added maintenance script sqlite.php for SQLite-specific maintenance tasks. === Bug fixes in 1.16 === diff --git a/maintenance/sqlite.php b/maintenance/sqlite.php new file mode 100644 index 0000000000..0bbcb25cfc --- /dev/null +++ b/maintenance/sqlite.php @@ -0,0 +1,80 @@ +mDescription = "Performs some operations specific to SQLite database backend"; + $this->addOption( 'vacuum', 'Clean up database by removing deleted pages. Decreases database file size' ); + $this->addOption( 'integrity', 'Check database for integrity' ); + } + + public function execute() { + global $wgDBtype; + + if ( $wgDBtype != 'sqlite' ) { + $this->error( "This maintenance script requires a SQLite database.\n" ); + return; + } + + $this->db = wfGetDB( DB_MASTER ); + + if ( $this->hasOption( 'vacuum' ) ) + $this->vacuum(); + + if ( $this->hasOption( 'integrity' ) ) + $this->integrityCheck(); + } + + private function vacuum() { + $prevSize = filesize( $this->db->mDatabaseFile ); + + $this->output( 'VACUUM: ' ); + if ( $this->db->query( 'VACUUM' ) ) { + clearstatcache(); + $newSize = filesize( $this->db->mDatabaseFile ); + $this->output( sprintf( "Database size was %d bytes, now %d (%.1f%% reduction).\n", + $prevSize, $newSize, ( $prevSize - $newSize) / $prevSize ) ); + } else { + $this->output( 'Error\n' ); + } + } + + private function integrityCheck() { + $this->output( "Performing database integrity checks:\n" ); + $res = $this->db->query( 'PRAGMA integrity_check' ); + + if ( !$res || $res->numRows() == 0 ) { + $this->error( "Error: integrity check query returned nothing.\n" ); + return; + } + + foreach ( $res as $row ) { + $this->output( $row->integrity_check ); + } + } +} + +$maintClass = "SqliteMaintenance"; +require_once( DO_MAINTENANCE ); \ No newline at end of file -- 2.20.1