WordPress siteniz zamanla yavaşlamaya başlar. Bunun sebebi sadece hosting değil, aynı zamanda şişmiş veritabanıdır.
Veritabanı sitenizin beyni gibi düşünebilirsiniz arkadaşlar. İçinde yazılarınız, yorumlarınız, ayarlarınız saklanır. Gereksiz bilgiler temizlenmezse siteniz hantallaşır.

#1 Revizyonları (Taslakları) Temizleyin
WordPress siz yazı yazarken sürekli otomatik taslak kaydeder.
Örneğin 1 yazı = 20 revizyon demek. 100 yazınız varsa 2000 gereksiz kayıt olur öyle düşünelim.
Nasıl Temizlenir?
  • WP-Optimize veya Advanced Database Cleaner eklentisini kurun.
  • “Revizyonları temizle” seçeneğini işaretleyin.
  • Tek tıkla silin, yazılarınıza hiçbir zarar gelmez.

#2 Spam ve Çöp Yorumları Silin
Onaylamadığınız veya spam kutusuna düşen yorumlar veritabanında durmaya devam eder.
Nasıl Temizlenir?
  • WordPress admin paneli > Yorumlar menüsüne girin.
  • “Spam” ve “Çöp Kutusu” sekmelerine tıklayın.
  • “Tümünü Kalıcı Olarak Sil” butonuna basın.

#3 Otomatik Kaydetme Süresini Uzatın
WordPress yazı yazarken her 1 dakikada bir otomatik taslak kaydeder. Bu da veritabanını şişirir.
Çözüm:
  • Hostinginizdeki wp-config.php dosyasını açın.
  • Şu satırı ekleyin:
define('AUTOSAVE_INTERVAL', 300);

#4 Kullanılmayan Veritabanı Tablolarını Temizleme
Basit olarak yaptığımız Pars WordPress Blog Temamızda geliştirip kullanmayı düşündüğümüz kullanılmayan veritabanı tablolarını temizlenmesini yardımcı olması adına basit bir kodu paylaşıyorum.
Nasıl Kullanırız
  • Size iletmiş olduğumu kodu functions.php dosyasına ekleyin bazı tema yapımcıları bizlerde dahil olmak üzere ilgili dosyayı şifreliyoruz. Bu sebepten ötürü örn. Pars temamızdan baz alarak pars-functions.php gibi ek dosyaya kodu ekleyin.
  • Sol menüden Araçlar > Pars DB Temizleyici sayfasına gidin.
  • Kullanılmayan tabloları göreceksiniz onları tek tek ve/veya toplu seçim yaparak tabloları temizleyebilirsiniz.


add_action('admin_menu', 'db_cleaner_admin_menu');
function db_cleaner_admin_menu() {
    add_management_page(
        'Veritabanı Temizleyici',
        'Pars DB Temizleyici',
        'manage_options',
        'db-cleaner',
        'db_cleaner_admin_page'
    );
}
function db_cleaner_admin_page() {
    global $wpdb;
    if (!current_user_can('manage_options')) {
        wp_die(__('Bu sayfaya erişim yetkiniz yok.'));
    }
    if (isset($_POST['delete_tables']) && wp_verify_nonce($_POST['db_cleaner_nonce'], 'db_cleaner_action')) {
        $tables_to_delete = isset($_POST['tables']) ? $_POST['tables'] : array();
        $deleted_count = 0;        
        foreach ($tables_to_delete as $table) {
            $table = sanitize_text_field($table);
            if (!is_wordpress_core_table($table)) {
                $result = $wpdb->query("DROP TABLE IF EXISTS `$table`");
                if ($result !== false) {
                    $deleted_count++;
                }
            }
        }        
        echo '<div class="notice notice-success"><p>' . $deleted_count . ' tablo başarıyla silindi.</p></div>';
    }
    $all_tables = $wpdb->get_col("SHOW TABLES");
    $wp_tables = get_wordpress_core_tables();
    $unused_tables = array();
    foreach ($all_tables as $table) {
        if (!in_array($table, $wp_tables) && !is_active_plugin_table($table)) {
            $row_count = $wpdb->get_var("SELECT COUNT(*) FROM `$table`");
            $unused_tables[] = array(
                'name' => $table,
                'rows' => $row_count,
                'size' => get_table_size($table)
            );
        }
    }    
    ?>
    <div class="wrap">
        <h1>Veritabanı Temizleyici</h1>
        <div class="notice notice-warning">
            <p><strong>Uyarı:</strong> Bu araç veritabanı tablolarını kalıcı olarak siler. İşlem öncesi mutlaka yedek alın!</p>
        </div>        
        <?php if (empty($unused_tables)): ?>
            <div class="notice notice-info">
                <p>Temizlenecek kullanılmayan tablo bulunamadı. Veritabanınız temiz görünüyor!</p>
            </div>
        <?php else: ?>
            <form method="post" action="" onsubmit="return confirm('Seçili tabloları silmek istediğinizden emin misiniz? Bu işlem geri alınamaz!');">
                <?php wp_nonce_field('db_cleaner_action', 'db_cleaner_nonce'); ?>
                
                <h2>Kullanılmayan Tablolar (<?php echo count($unused_tables); ?> adet)</h2>
                <table class="wp-list-table widefat fixed striped">
                    <thead>
                        <tr>
                            <td class="check-column">
                                <input type="checkbox" id="select-all" />
                            </td>
                            <th>Tablo Adı</th>
                            <th>Satır Sayısı</th>
                            <th>Boyut</th>
                            <th>Muhtemel Kaynak</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php foreach ($unused_tables as $table): ?>
                            <tr>
                                <th class="check-column">
                                    <input type="checkbox" name="tables[]" value="<?php echo esc_attr($table['name']); ?>" />
                                </th>
                                <td><code><?php echo esc_html($table['name']); ?></code></td>
                                <td><?php echo number_format($table['rows']); ?></td>
                                <td><?php echo $table['size']; ?></td>
                                <td><?php echo guess_table_source($table['name']); ?></td>
                            </tr>
                        <?php endforeach; ?>
                    </tbody>
                </table>
                
                <p class="submit">
                    <input type="submit" name="delete_tables" class="button button-primary" value="Seçili Tabloları Sil" />
                    <button type="button" class="button" onclick="location.reload()">Yenile</button>
                </p>
            </form>
        <?php endif; ?>  
        <h2>Veritabanı İstatistikleri</h2>
        <table class="wp-list-table widefat">
            <tr>
                <td><strong>Toplam Tablo Sayısı:</strong></td>
                <td><?php echo count($all_tables); ?></td>
            </tr>
            <tr>
                <td><strong>WordPress Core Tabloları:</strong></td>
                <td><?php echo count($wp_tables); ?></td>
            </tr>
            <tr>
                <td><strong>Kullanılmayan Tablolar:</strong></td>
                <td><?php echo count($unused_tables); ?></td>
            </tr>
            <tr>
                <td><strong>Veritabanı Boyutu:</strong></td>
                <td><?php echo get_database_size(); ?></td>
            </tr>
        </table>
    </div>    
    <script>
    document.getElementById('select-all').addEventListener('change', function() {
        const checkboxes = document.querySelectorAll('input[name="tables[]"]');
        checkboxes.forEach(checkbox => checkbox.checked = this.checked);
    });
    </script>    
    <style>
    .wp-list-table code {
        background: #f1f1f1;
        padding: 2px 4px;
        border-radius: 3px;
    }
    .notice {
        margin: 15px 0;
    }
    </style>
    <?php
}
function get_wordpress_core_tables() {
    global $wpdb;    
    return array(
        $wpdb->posts,
        $wpdb->postmeta,
        $wpdb->comments,
        $wpdb->commentmeta,
        $wpdb->terms,
        $wpdb->term_taxonomy,
        $wpdb->term_relationships,
        $wpdb->users,
        $wpdb->usermeta,
        $wpdb->links,
        $wpdb->options,
        $wpdb->termmeta
    );
}
function is_wordpress_core_table($table_name) {
    $core_tables = get_wordpress_core_tables();
    return in_array($table_name, $core_tables);
}
function is_active_plugin_table($table_name) {
    $active_plugins = get_option('active_plugins');
    $known_plugin_prefixes = array(
        'woocommerce' => 'wc_',
        'contact-form-7' => 'cf7_',
        'yoast' => 'yoast_',
        'elementor' => 'elementor_',
        'wpforms' => 'wpforms_'
    );    
    foreach ($active_plugins as $plugin) {
        $plugin_slug = dirname($plugin);
        if (isset($known_plugin_prefixes[$plugin_slug])) {
            if (strpos($table_name, $known_plugin_prefixes[$plugin_slug]) !== false) {
                return true;
            }
        }
    }    
    return false;
}
function get_table_size($table_name) {
    global $wpdb;    
    $size_query = $wpdb->prepare("
        SELECT
            ROUND(((data_length + index_length) / 1024 / 1024), 2) AS 'size_mb'
        FROM information_schema.TABLES
        WHERE table_schema = %s
        AND table_name = %s
    ", DB_NAME, $table_name);
    $size = $wpdb->get_var($size_query);    
    if ($size > 1) {
        return $size . ' MB';
    } else {
        return round($size * 1024, 2) . ' KB';
    }
}
function get_database_size() {
    global $wpdb;    
    $size_query = $wpdb->prepare("
        SELECT
            ROUND(SUM(data_length + index_length) / 1024 / 1024, 2) AS 'size_mb'
        FROM information_schema.TABLES
        WHERE table_schema = %s
    ", DB_NAME);    
    $size = $wpdb->get_var($size_query);
    return $size . ' MB';
}
function guess_table_source($table_name) {
    global $wpdb;    
    $prefix = $wpdb->prefix;
    $plugin_patterns = array(
        'wc_' => 'WooCommerce',
        'cf7_' => 'Contact Form 7',
        'yoast_' => 'Yoast SEO',
        'elementor_' => 'Elementor',
        'wpforms_' => 'WPForms',
        'edd_' => 'Easy Digital Downloads',
        'give_' => 'GiveWP',
        'ninja_' => 'Ninja Forms',
        'frm_' => 'Formidable Forms',
        'mailchimp_' => 'MailChimp',
        'backup_' => 'Backup Plugin',
        'cache_' => 'Cache Plugin',
        'seo_' => 'SEO Plugin'
    );    
    foreach ($plugin_patterns as $pattern => $plugin) {
        if (strpos($table_name, $prefix . $pattern) === 0 || strpos($table_name, $pattern) !== false) {
            return $plugin;
        }
    }
    if (strpos($table_name, $prefix) === 0) {
        return 'WordPress Plugin/Theme';
    }    
    return 'Bilinmeyen';
}
Birkaç saniye sürecek, siteniz daha hızlı çalışmaya başlayacak.

DİĞER KONULARIMIZ.
#1 - cPanel’de Cron Job ile Otomatik Yedekleme Yapma
#2 - .htaccess ile WordPress Sitenizi Güvenli Hale Getirin

İyi forumlar, çalışma hayatınızda başarılar dileriz.