{"id":40513,"date":"2019-01-25T13:27:49","date_gmt":"2019-01-25T11:27:49","guid":{"rendered":"https:\/\/blog.superhosting.bg\/?p=40513"},"modified":"2022-04-02T10:39:17","modified_gmt":"2022-04-02T07:39:17","slug":"reduce-database-size","status":"publish","type":"post","link":"https:\/\/blog.superhosting.bg\/en\/reduce-database-size.html","title":{"rendered":"How to Reduce the Database Size?"},"content":{"rendered":"<p>Every day the SuperSupport deals with many different cases. Today we will provide you with a few tips for handling a very common problem which can lead to many unpleasant consequences, but namely &#8211; large databases.<\/p>\n<p>Large databases can lead to a few unpleasant situations. The first of them is the combination of&nbsp;non-optimized queries and lack of indexes which may cause poor database performance. This results in slow loading times which influence the number of visitors on the website and thus its Google ranking. Meanwhile large database can also reach the limit of hosting plan parameters such as &#8220;database size\u201d, \u201cCPU time\u201d and others.<\/p>\n<p class=\"boxorangedashedborder01\"><strong>Note<\/strong>: It is important to mention that the optimization of queries used defines to what extend the database performance will be reduced. If queries are not optimized well enough there will be also audible reduction in the database performance even when the database is small (MB). For example in our experience with similar situations we have encountered a database size of 100MB and website loading speed over 10 seconds only because of non-optimized queries. If the queries are well optimized, the database size may not influence performance so seriously until it reaches \u0430 more considerable size (GB, TB).<\/p>\n<p>Database growth is a natural result from the respective website\u2019s development and increasing the number of products, articles and users as well as other data objects.<\/p>\n<p>Sometimes with CMS for building websites such as WordPress, enlargement of the database may be due to installation and uninstallation of plugins, collecting statistics, temporary system data, object cache, logs, spam comments and articles, etc. This results in unnecessary data which is piled up and increases the database.<\/p>\n<p>You can prevent this by regularly removing all unnecessary data.<\/p>\n<h3 class=\"h4-gray01\" style=\"magrin: 20px -6px 14px -6px;\">How to reduce the database size?<\/h3>\n<p>Checking the database for unnecessary data starts by inspecting the tables it contains. The big-sized of them are the first ones to be checked as you should try to find out what generates data in them and if it can be removed and how piling up data can be stopped in the future.<\/p>\n<h4 class=\"h3greendashedborder01\"><strong>How to check the database size?<\/strong><\/h4>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"img-border2 alignright wp-image-40518 size-full\" src=\"https:\/\/blog.superhosting.bg\/wp-content\/uploads\/2019\/02\/cpanel-database-size-en-01-1.png\" alt=\"MySQL databases\" width=\"256\" height=\"156\"><\/p>\n<p>If now you are wondering if your database is big you can check this quickly and easily by going to&nbsp;<strong>cPanel<\/strong>&nbsp;\u00bb&nbsp;<strong>MySQL databases<\/strong>.<\/p>\n<p>You can check if the database has reached or exceeded 100% from the parameter value (1024 MB) for the hosting plan used as you go to your <a title=\"\" href=\"https:\/\/en.superhosting.bg\/web-hosting-client-profile.php\" target=\"_blank\" rel=\"noopener noreferrer\">Client Profile<\/a>&nbsp;(superhosting.bg) \u00bb&nbsp;<strong>Hosting Accounts<\/strong>&nbsp;\u00bb&nbsp;<strong>Details<\/strong>&nbsp;\u00bb <strong>Resource Usage<\/strong>&nbsp;\u00bb <strong>Databases<\/strong>.<\/p>\n<p>Also, we will send you a notification upon reaching or exceeding 100% of the parameter for the hosting plan used.<\/p>\n<p>If the database is large the next step is to check the tables which may contain unnecessary data and removing it.<\/p>\n<h4 class=\"h3greendashedborder01\"><strong>How to check the table size?<\/strong><\/h4>\n<p>To find out what increases the database size, check the tables&#8217; contents. But before that, check which the big-sized tables are. You can check the tables and their size in <strong>cPanel<\/strong> \u00bb <strong>phpMyAdmin<\/strong>.<\/p>\n<p>Log into cPanel, load phpMyAdmin, open the website\u2019s database and order the tables by size. The first table in the list should be the biggest one.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"img-border2 aligncenter wp-image-39899 size-full\" src=\"https:\/\/blog.superhosting.bg\/wp-content\/uploads\/2019\/01\/cpanel-phpmyadmin-sort-tables-by-size-02-1.png\" alt=\"phpMyAdmin\" width=\"590\" height=\"106\" srcset=\"https:\/\/blog.superhosting.bg\/wp-content\/uploads\/2019\/01\/cpanel-phpmyadmin-sort-tables-by-size-02-1.png 590w, https:\/\/blog.superhosting.bg\/wp-content\/uploads\/2019\/01\/cpanel-phpmyadmin-sort-tables-by-size-02-1-300x54.png 300w\" sizes=\"auto, (max-width: 590px) 100vw, 590px\" \/><\/p>\n<p>When you are using a CMS, the table names hint for which plugin or feature they are used.<\/p>\n<p>There might be more than one large table. You can decide whether to remove data from the table depending on the website&#8217;s system and the table\u2019s function.<\/p>\n<h4 class=\"h3greendashedborder01\"><strong>How to delete tables or data they contain?<\/strong><\/h4>\n<p>You can delete a table or data it contains through phpMyAdmin. To delete a table use the&nbsp;<strong>Drop<\/strong> option. To remove certain data from the table you may use a query especially written for this purpose. The&nbsp;<strong>Empty<\/strong> option will erase the table\u2019s whole content.<\/p>\n<p>Other ways to delete data from the database are: Through a feature available on the website&#8217;s admin panel or by using an additional plugin\/module.<\/p>\n<p class=\"boxyellowdashedborder01\"><strong>Note<\/strong>: Backup Your Database &#8211;&nbsp;make a backup copy before you start to cleaning it. It will be even better if you delete data&nbsp;first on the website&#8217;s development instance.<\/p>\n<h4 class=\"h3greendashedborder01\"><strong>Some of the most common large tables in CMS<\/strong><\/h4>\n<p>When you use a Content Management System for your website you should know that there are certain tables which are often the main reason for the big size of databases.<\/p>\n<h5 class=\"heading-gry\"><strong>WordPress<\/strong><\/h5>\n<p>Over time, records and even whole tables are piled up in the WordPress database as the website does not need them. You can remove tables for uninstalled plugins as this won\u2019t affect the website&#8217;s operation.<\/p>\n<p><strong>Some of WordPress\u2019 tables which can be checked and cleared out are:<br \/>\n<\/strong><\/p>\n<p>\ud83d\uddc3 <strong>wp_options<\/strong><br \/>\nData and settings of the installed plugins are saved in this table. If you have removed a plugin, you can erase its data from the table. In this table you should check for more piled up temporary data such as object cache &#8211; transients. It is possible that a lot of data from the WooCommerce (wc_session) plugin has been piled up as you can remove it through menu <strong>System Status<\/strong> \u00bb <strong>Tools<\/strong> &#8211; option for manually deleting these records or only the expired ones.<\/p>\n<p>Note: You can activate Memcached or Redis for the website so that to prevent object cache to be written to the options table in the WordPress database. You can activate these technologies automatically in cPanel \u00bb&nbsp;<a title=\"\" href=\"https:\/\/help.superhosting.bg\/en\/wordpress-manager-by-superhosting.html\" target=\"_blank\" rel=\"noopener noreferrer\">WordPress Manager<\/a>&nbsp;\u00bb&nbsp;<a title=\"\" href=\"https:\/\/help.superhosting.bg\/en\/wp-manager-speed-up.html\" target=\"_blank\" rel=\"noopener noreferrer\">Speed up<\/a>. To activate Memcached\/Redis manually you can enable the Object Cache feature in the <a title=\"\" href=\"https:\/\/blog.superhosting.bg\/en\/w3-total-cache-settings-part-2.html\" target=\"_blank\" rel=\"noopener noreferrer\">W3 Total Cache plugin settings<\/a>.<\/p>\n<p>\ud83d\uddc3 <strong>wp_posts<\/strong><br \/>\nCheck if there are spam posts piled up in this table. Also, you need to check the number of revisions that are being saved for an article. If they are more than 3, consider&nbsp;reducing their number&nbsp;or deleting all saved revisions from the database.<\/p>\n<p>\ud83d\uddc3 <strong>wp_comments<\/strong><br \/>\nCheck for spam comments in this table and remove them, if any. You can&nbsp;activate the Akismet&nbsp;plugin so that spam comments are automatically deleted.<\/p>\n<p>You can remove the unnecessary data from the database manually or through a plugin for database optimization such as <a href=\"https:\/\/wordpress.org\/plugins\/wp-optimize\/\" target=\"_blank\" rel=\"noopener noreferrer\">WP-Optimize<\/a>, <a href=\"https:\/\/wordpress.org\/plugins\/wp-dbmanager\/\" target=\"_blank\" rel=\"noopener noreferrer\">WP-DBManager<\/a> \u0438 <a href=\"https:\/\/wordpress.org\/plugins\/transients-manager\/\" target=\"_blank\" rel=\"noopener noreferrer\">Transients Manager<\/a>.<\/p>\n<h5 class=\"heading-gry\"><strong>Drupal<\/strong><\/h5>\n<p>System error logs are stored in Drupal\u2019s database.<\/p>\n<p>The name of the table is &#8220;<a href=\"https:\/\/drupal.stackexchange.com\/questions\/26180\/watchdog-table-grows-too-big-too-fast\" target=\"_blank\" rel=\"noopener noreferrer\">watchdog<\/a>&#8220;. In case you do not need such logs you can delete the table\u2018s content. This is a temporary solution as you need to check the errors and fix them, if possible.<\/p>\n<h5 class=\"heading-gry\"><strong>Prestashop<\/strong><\/h5>\n<p>In Prestashop you can save statistical data for user visits. Check the following tables in the database and delete the data if it is no longer needed:&nbsp;<strong>ps_connections<\/strong>,&nbsp;<strong>ps_connections_source<\/strong>&nbsp;and&nbsp;<strong>ps_connections_page<\/strong>.<\/p>\n<h5 class=\"heading-gry\"><strong>Magento<\/strong><\/h5>\n<p>As with other systems, Magento\u2019s database also stores logs and statistics, so check the tables and remove everything outdated, for example in the following tables: <strong>log_visitor_info<\/strong>, <strong>log_url_info<\/strong>, <strong>log_url<\/strong> and <strong>log_visitor<\/strong>.<\/p>\n<p>Hardly ever is it possible to have a big amount of data stored also in the following table: <strong>core_url_rewrite<\/strong>. Solutions for reducing the table&#8217;s size, however, might be more specific and may require in-depth technical knowledge, for example, <a href=\"https:\/\/magento.stackexchange.com\/questions\/17553\/magento-core-url-rewrite-table-excessively-large\" target=\"_blank\" rel=\"noopener noreferrer\">Magento core_url_rewrite table excessively large<\/a>.<\/p>\n<h3 class=\"h4-gray01\">Optimizing the database<\/h3>\n<p>Optimizing the database can reduce its size and boost its performance.<\/p>\n<p>Tools mentioned in this article are used for database optimization as they do not modify the website&#8217;s system source code or database queries. Neither do they require any special support. Optimizations are applied on a database level, not on retrieval as optimizing can be performed by any website administrator.<\/p>\n<p>For database optimization you can use the <strong>phpMyAdmin<\/strong> tool in cPanel or the <strong>mysqlckeck<\/strong> command via <strong>SSH access<\/strong>.<\/p>\n<p class=\"boxyellowdashedborder01\"><strong>Important<\/strong>: Before performing whatever operations with the database, make a&nbsp;backup.<\/p>\n<h4 class=\"h3greendashedborder01\"><strong>phpMyAdmin &#8211; database optimization<\/strong><\/h4>\n<p>By using phpMyAdmin you can optimize and repair databases.<\/p>\n<p>The feature for optimizing in phpMyAdmin (Optimize table) is using the SQL command <a href=\"https:\/\/mariadb.com\/kb\/en\/optimize-table\/\" target=\"_blank\" rel=\"noopener noreferrer\">OPTIMIZE TABLE<\/a>. This optimization reduces the disk space used by the database and increases the efficiency of <a title=\"\" href=\"https:\/\/help.superhosting.bg\/en\/what-is-io-iops.html\" target=\"_blank\" rel=\"noopener noreferrer\">I\/O<\/a>) operations.<\/p>\n<p>It is best to optimize after deleting large volumes of data from the tables.<\/p>\n<p>Load phpMyAdmin, click on the database name and select all tables on the left (<strong>Check all<\/strong>). Then select&nbsp;<strong>Optimize table<\/strong> from the drop-down menu.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"img-border2 aligncenter wp-image-39880 size-full\" src=\"https:\/\/blog.superhosting.bg\/wp-content\/uploads\/2019\/01\/cpanel-phpmyadmin-optimize-table-01-1.png\" alt=\"Optimize table\" width=\"576\" height=\"306\" srcset=\"https:\/\/blog.superhosting.bg\/wp-content\/uploads\/2019\/01\/cpanel-phpmyadmin-optimize-table-01-1.png 576w, https:\/\/blog.superhosting.bg\/wp-content\/uploads\/2019\/01\/cpanel-phpmyadmin-optimize-table-01-1-300x159.png 300w\" sizes=\"auto, (max-width: 576px) 100vw, 576px\" \/><\/p>\n<p>With large databases the optimization process can take a while.<\/p>\n<h4 class=\"h3greendashedborder01\"><strong>SSH: mysqlcheck &#8211; database optimization<\/strong><\/h4>\n<p>For optimizing the database via&nbsp;SSH access you can use the&nbsp;<strong>mysqlcheck<\/strong>&nbsp;command with the &#8220;<strong>-o<\/strong>&#8221; (&#8211;optimize) parameter.<\/p>\n<p><code>mysqlcheck -o cpuser_mydb -h localhost -u cpuser_mydbuser -pPassword<\/code><\/p>\n<p class=\"text-note-small\">cpuser_mydb &#8211; replace with the database name, cpuser_mydbuser &#8211; the database user, Password &#8211; the user password, it should be written with no spaces after the &#8211; p parameter;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"img-border2 aligncenter wp-image-39916 size-full\" src=\"https:\/\/blog.superhosting.bg\/wp-content\/uploads\/2019\/01\/ssh-mysqlcheck-optimize-database-done-02-1.png\" alt=\"mysqlcheck\" width=\"612\" height=\"271\" srcset=\"https:\/\/blog.superhosting.bg\/wp-content\/uploads\/2019\/01\/ssh-mysqlcheck-optimize-database-done-02-1.png 612w, https:\/\/blog.superhosting.bg\/wp-content\/uploads\/2019\/01\/ssh-mysqlcheck-optimize-database-done-02-1-300x133.png 300w\" sizes=\"auto, (max-width: 612px) 100vw, 612px\" \/><\/p>\n<h4 class=\"h3greendashedborder01\"><strong>Cron Job &#8211; automatic database optimization<\/strong><\/h4>\n<p>The SSH mysqlcheck command can be used in a cron job for periodic database automatic optimization. We recommend optimizing your website\u2019s database at least once a month or more often, depending on how often changes are performed to the database.<\/p>\n<p>Upon creating a cron job in cPanel you need to enter into the field for executing a command the following:<\/p>\n<p><code>\/usr\/bin\/mysqlcheck -o -v -u cpuser_mydbuser -pPassword -h localhost cpuser_mydb<\/code><\/p>\n<p class=\"text-note-small\">cpuser_mydb &#8211; replace with the database name, cpuser_mydbuser &#8211; the database user, Password &#8211; the user password, it should be written with no spaces after the &#8211; p parameter;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"img-border2 aligncenter wp-image-40521 size-full\" src=\"https:\/\/blog.superhosting.bg\/wp-content\/uploads\/2019\/02\/cpanel-cron-jobs-optimize-database-en-02-1.png\" alt=\"Cron Job\" width=\"596\" height=\"174\" srcset=\"https:\/\/blog.superhosting.bg\/wp-content\/uploads\/2019\/02\/cpanel-cron-jobs-optimize-database-en-02-1.png 596w, https:\/\/blog.superhosting.bg\/wp-content\/uploads\/2019\/02\/cpanel-cron-jobs-optimize-database-en-02-1-300x88.png 300w\" sizes=\"auto, (max-width: 596px) 100vw, 596px\" \/><\/p>\n<p>If you wish to view the results from the command execution, you can specify an email address in the cPanel page with cron jobs or add right after the command &#8220;&gt; dboptimize.txt&#8221;:<\/p>\n<p><code>\/usr\/bin\/mysqlcheck -o -v -u cpuser_mydbuser -pPassword -h localhost cpuser_mydb &gt; dboptimize.txt<\/code><\/p>\n<h3 class=\"h4-gray01\">What are the benefits from reducing the database size?<\/h3>\n<p>Small databases guarantee maximum system performance. When the database is fast, its queries are optimized and indexes are correct, website will load fast.<\/p>\n<p>Nowadays, especially after Google started to treat loading speed (on mobile and desktop) <a title=\"\" href=\"https:\/\/webmasters.googleblog.com\/2018\/01\/using-page-speed-in-mobile-search.html\" target=\"_blank\" rel=\"noopener noreferrer\">as a factor for website ranking<\/a>, each website should strive to load fast.<\/p>\n<p>Sometimes, however, reducing the database size is not possible as this happens in cases when the website\u2019s size has grown too big and all data is important. In those cases more resources and space are needed so that the website can also grow in the future. For smooth operation of the website and database, we provide suitable hosting solutions such as your own &#8211;&nbsp;<a title=\"\" href=\"https:\/\/en.superhosting.bg\/web-hosting-common-managed-vps.php\" target=\"_blank\" rel=\"noopener noreferrer\">Managed VPS<\/a>&nbsp;or&nbsp;<a title=\"\" href=\"https:\/\/en.superhosting.bg\/web-hosting-page-servers-vps.php\" target=\"_blank\" rel=\"noopener noreferrer\">VPS<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Large databases with non-optimized queries and lack of indexes may cause poor performance. You can prevent this by regularly removing all unnecessary data.<\/p>\n","protected":false},"author":16,"featured_media":62849,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"_lmt_disableupdate":"","_lmt_disable":"","footnotes":""},"categories":[118],"tags":[224],"class_list":{"0":"post-40513","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-superhosting-tips-of-support-en","8":"tag-website-speed-up"},"aioseo_notices":[],"modified_by":"\u041c\u0430\u0434\u043b\u0435\u043d\u0430 \u041c\u0435\u0442\u043e\u0434\u0438\u0435\u0432\u0430","post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/blog.superhosting.bg\/en\/wp-json\/wp\/v2\/posts\/40513","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.superhosting.bg\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.superhosting.bg\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.superhosting.bg\/en\/wp-json\/wp\/v2\/users\/16"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.superhosting.bg\/en\/wp-json\/wp\/v2\/comments?post=40513"}],"version-history":[{"count":7,"href":"https:\/\/blog.superhosting.bg\/en\/wp-json\/wp\/v2\/posts\/40513\/revisions"}],"predecessor-version":[{"id":65219,"href":"https:\/\/blog.superhosting.bg\/en\/wp-json\/wp\/v2\/posts\/40513\/revisions\/65219"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.superhosting.bg\/en\/wp-json\/wp\/v2\/media\/62849"}],"wp:attachment":[{"href":"https:\/\/blog.superhosting.bg\/en\/wp-json\/wp\/v2\/media?parent=40513"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.superhosting.bg\/en\/wp-json\/wp\/v2\/categories?post=40513"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.superhosting.bg\/en\/wp-json\/wp\/v2\/tags?post=40513"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}