iEntry 10th Anniversary Forum Rules Search
WebProWorld
Register FAQ Calendar Mark Forums Read
Database Discussion Forum This is the place to find help resolving those nagging questions you have about implementing and using all kinds of databases. Need help writing a query? Need an opinion on Oracle? Post here!

Share Thread: & Tags

Share Thread:

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-18-2008, 10:34 AM
edhan's Avatar
WebProWorld Veteran
 
Join Date: Aug 2003
Location: Singapore
Posts: 701
edhan RepRank 3edhan RepRank 3
Question Optimize Overhead for database

Hi

Once awhile I will check using phpMyAdmin to check on individual database tables and find there are some overhead for some fields. So I will manual select them and click to optimize.

I find this method is a little troublesome as I have about 100 databases and going through one at a time to check if there are overhead and selecting them to optimize. This really takes up a lot of my time.

So I am wondering if there is a better method where I can do it automatically?

Any suggestion? Or this is the only method?

Thanks!
Reply With Quote
  #2 (permalink)  
Old 07-18-2008, 10:57 AM
kgun's Avatar
WebProWorld 1,000+ Club
WebProWorld MVP
 
Join Date: May 2005
Location: Norway
Posts: 5,607
kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9
Default Re: Optimize Overhead for database

Data base optimization is a big, complex and very important topic.

May be a good and thoughtful (book?) search is the best. On the site in the third link in my signature you find some links under the heading

"Optimize, structure and document your code. Cache your pages where possible"

that may be relevant.
Reply With Quote
  #3 (permalink)  
Old 07-18-2008, 12:19 PM
edhan's Avatar
WebProWorld Veteran
 
Join Date: Aug 2003
Location: Singapore
Posts: 701
edhan RepRank 3edhan RepRank 3
Default Re: Optimize Overhead for database

Many thanks!

I will check out your link. Hopefully it helps to widen my knowledge and get some insights.

Appreciate your reply.
Reply With Quote
  #4 (permalink)  
Old 07-18-2008, 03:29 PM
datetopia's Avatar
WebProWorld Pro
 
Join Date: Dec 2006
Location: Datetopia Dating Software
Posts: 139
datetopia RepRank 0
Default Re: Optimize Overhead for database

If you just refer to managing existing databases and data you can make a script to run REPAIR and OPTIMIZE on all tables.
Reply With Quote
  #5 (permalink)  
Old 07-18-2008, 03:41 PM
WebProWorld Member
 
Join Date: Oct 2005
Posts: 36
wdillsmith RepRank 0
Default Re: Optimize Overhead for database

I've found that this happens most often in mysql if you delete a lot of rows. So you might want to look at how your system is organized to reduce the deletes or target just those tables that are affected. I probably have 75 tables, but only a couple have regular deletions, so I just optimize those 2 once a week and I'm all set.
__________________
Looking for a unique gift? Send one of our gourmet cookie bouquets today.
Food lovers - visit the Gourmet Gift of the Day Blog for delicious ideas.
Reply With Quote
  #6 (permalink)  
Old 07-18-2008, 10:42 PM
edhan's Avatar
WebProWorld Veteran
 
Join Date: Aug 2003
Location: Singapore
Posts: 701
edhan RepRank 3edhan RepRank 3
Default Re: Optimize Overhead for database

Quote:
Originally Posted by datetopia View Post
If you just refer to managing existing databases and data you can make a script to run REPAIR and OPTIMIZE on all tables.
I am currently running about 100 domains in one server and each domain has its own database. Currently what I am doing is accessing the phpMyAdmin once a month using root account to view all databases one by one to see if the tables are having any overhead. If there are, then I will manual choose the tables and optimize it.

Do you have a sample of the script or where can I find such script to be able to assist optimization of all domains databases from the same server at once?

Thanks!
Reply With Quote
  #7 (permalink)  
Old 07-19-2008, 07:00 PM
RichAtVNS's Avatar
WebProWorld Pro
 
Join Date: Jul 2003
Location: New York, USA
Posts: 144
RichAtVNS RepRank 1
Thumbs up Re: Optimize Overhead for database

Quote:
Originally Posted by edhan View Post
I am currently running about 100 domains in one server and each domain has its own database. Currently what I am doing is accessing the phpMyAdmin once a month using root account to view all databases one by one to see if the tables are having any overhead. If there are, then I will manual choose the tables and optimize it.

Do you have a sample of the script or where can I find such script to be able to assist optimization of all domains databases from the same server at once?

Thanks!
We actually run a script every night at 4 am to compress all our databases.

Just make a batch file to run them,
1) turn off the domain for the maintence for approximately 2 minutes.
2)copy the database to a temporary copy,
3) compress the copy (through an embedded function in a module),
4) if it succeeds copy it back (so as not to corrupt the database in case it doesn't work.)
5) turn back on the domain.
6) goto the (1) for the next domain.

You don't need to do every domain every night. if you have to many.

To launch the batch use the Timer in the system scheduler. (this is available in both dos/windows and unix/linux enviornments)

Last edited by RichAtVNS; 07-19-2008 at 07:05 PM.
Reply With Quote
  #8 (permalink)  
Old 07-19-2008, 10:52 PM
edhan's Avatar
WebProWorld Veteran
 
Join Date: Aug 2003
Location: Singapore
Posts: 701
edhan RepRank 3edhan RepRank 3
Default Re: Optimize Overhead for database

Quote:
Originally Posted by RichAtVNS View Post
We actually run a script every night at 4 am to compress all our databases.

Just make a batch file to run them,
1) turn off the domain for the maintence for approximately 2 minutes.
2)copy the database to a temporary copy,
3) compress the copy (through an embedded function in a module),
4) if it succeeds copy it back (so as not to corrupt the database in case it doesn't work.)
5) turn back on the domain.
6) goto the (1) for the next domain.

You don't need to do every domain every night. if you have to many.

To launch the batch use the Timer in the system scheduler. (this is available in both dos/windows and unix/linux enviornments)
That sounds good. Where do I find this script?
Reply With Quote
  #9 (permalink)  
Old 07-20-2008, 09:35 PM
RichAtVNS's Avatar
WebProWorld Pro
 
Join Date: Jul 2003
Location: New York, USA
Posts: 144
RichAtVNS RepRank 1
Lightbulb Re: Optimize Overhead for database

the script is a BATCH file (.bat)

You can run any program from it. Didn't you ever learn DOS or Unix?

Use a program like Workspace Macro ($25 shareware) to send keystrokes to you database if your website and database software don't take command line launches.

Note programs like access and IIS Manager can take command line parameters already. So all you need to do is to call them from in the file.

Here is a sample batch file to check if my machine needs to reboot because connectivity has been lost and may need a reset

Note it checks 3 sites 3 times to see if it can get through......

-------------------------------
@echo off

:START
echo Testing Yahoo
ping.exe yahooxxxxxx.com -n 3 -w 1000 > D:\rebootcontrol\log\YahooIP.txt
IF NOT EXIST D:\rebootcontrol\log\YahooIP.txt goto TESTFAILED1
findstr /b /c:"Reply from " D:\rebootcontrol\log\YahooIP.txt > nul
IF %errorlevel%==1 goto TESTFAILED1
echo Success
goto end


:TESTFAILED1
echo Testing USNO
ping.exe tychoxxxxxxx.usno.navy.mil -n 3 -w 1000 > D:\rebootcontrol\log\USNOIP.txt
IF NOT EXIST D:\rebootcontrol\log\USNOIP.txt goto TESTFAILED2
findstr /b /c:"Reply from " D:\rebootcontrol\log\USNOIP.txt > nul
IF %errorlevel%==1 goto TESTFAILED2
echo Success
goto end


:TESTFAILED2
echo Testing Google
ping.exe googlexxxxxx.com -n 3 -w 1000 > D:\rebootcontrol\log\GoogleIP.txt
IF NOT EXIST D:\rebootcontrol\log\Google.txt goto TESTFAILED3
findstr /b /c:"Reply from " D:\rebootcontrol\log\GoogleIP.txt > nul
IF %errorlevel%==1 goto TESTFAILED3
echo Success
goto end


:TESTFAILED3
echo Failed
IF NumberOFTries==3 GOTO REBOOT
pause 15
GOTO START
goto end

:REBOOT
call app

:end
echo The end.

pause
-------------------------------

I don't know what operating system you are running windows or unix
but they are very similar

if you need help with batch language just bring up the command line prompt in windows and type help it will come up with all the commands you can use.

After you write the batch file place it in scheduler is
which in windows is under
"program files->accesories->system tools " in your start menu.
Scheduled Tasks.

---------------------------------

If you need any more one of my programmers could probably write the whole kit and kaboodle for you in under a day it wouldn't cost to much.

Last edited by RichAtVNS; 07-20-2008 at 09:37 PM.
Reply With Quote
  #10 (permalink)  
Old 07-21-2008, 07:08 AM
edhan's Avatar
WebProWorld Veteran
 
Join Date: Aug 2003
Location: Singapore
Posts: 701
edhan RepRank 3edhan RepRank 3
Default Re: Optimize Overhead for database

Quote:
Originally Posted by RichAtVNS View Post
the script is a BATCH file (.bat)

You can run any program from it. Didn't you ever learn DOS or Unix?
Yes. I do learn DOS. I am not running my website on local computer but hosting them overseas. I am doing remote access using telnet, ftp or browser for access. So, from what you have said, I will need to create a cron file (since I am using Unix) to run the cronjob for processing the optimization.

So, guess I have to learn the command for running the cronjob to optimize the database.

Any other better way of clearing overhead for the database? I have checked and found that most of the overheads are using Wordpress Blogs.
Reply With Quote
  #11 (permalink)  
Old 02-11-2009, 01:50 AM
WebProWorld New Member
 
Join Date: Nov 2008
Posts: 15
devkant RepRank 0
Default Re: Optimize Overhead for database

Mysql tables often get overburdened and create overhead, after several deletes or several changes (edits) to a table, with variable-length rows (i.e. tables that have VARCHAR, VARBINARY, BLOB, or TEXT columns).Overhead is comparable to defragmentation in a hard dive.Overhead for active mysql tables can reach high levels,
__________________
Promotional Pens
Reply With Quote
  #12 (permalink)  
Old 02-11-2009, 04:17 AM
edhan's Avatar
WebProWorld Veteran
 
Join Date: Aug 2003
Location: Singapore
Posts: 701
edhan RepRank 3edhan RepRank 3
Default Re: Optimize Overhead for database

I still can't find a better way of doing optimization so I am sticking to manual for the time being. I am sorting out some issues as why there are overhead for wordpress as I am running around 40 per server.
Reply With Quote
  #13 (permalink)  
Old 02-12-2009, 08:23 AM
MrGamm's Avatar
WebProWorld Pro
 
Join Date: Dec 2007
Posts: 269
MrGamm RepRank 3MrGamm RepRank 3
Default Re: Optimize Overhead for database

Sometimes it sucks to have to write a shell script... it can be alot easier to just go in through php...

Code:
$con = mysql_connect()

// I forgot the command to retrieve the table names so I am guessing...

$tables = get_a_list_of_all_the_tables($con);

foreach($tables as $a => $b){

$q = mysql_query("REPAIR TABLE `".$b."`",$con);

}
I did not try this code... I don't expect it to work... it's just for illustration...


PHP: mysql_list_tables - Manual




The best place to figure out more about optimizing tables is with the EXPLAIN statement... jmo...

You can prepend it to the beginning of your database query and mysql will return info about the query rather than the data you asked for...

"SELECT * FROM `table` WHERE `cat` = '2' ORDER BY `created`"

just add...

"EXPLAIN SELECT * FROM `table` WHERE `cat` = '2' ORDER BY `created`"

It will give you a good idea on which queries are overloading the server with table scans and which columns need keys on them.

MySQL :: MySQL 5.1 Reference Manual :: 12.3.2 EXPLAIN Syntax

It's probably not going to fix the overhead issue though... I don't know...



You can also dump a cron into linux via php as well... ( I forget the proper scheduling numbers )

system('0 0 0 0 5 wget -O - http://domain.com/the_script_which_r...ir_command.php --user-agent cron');


http://ca2.php.net/system
__________________
James Weisbrod - programmer

Last edited by MrGamm; 02-12-2009 at 08:32 AM.
Reply With Quote
  #14 (permalink)  
Old 02-12-2009, 11:06 AM
edhan's Avatar
WebProWorld Veteran
 
Join Date: Aug 2003
Location: Singapore
Posts: 701
edhan RepRank 3edhan RepRank 3
Default Re: Optimize Overhead for database

Quote:
Originally Posted by MrGamm View Post
Sometimes it sucks to have to write a shell script... it can be alot easier to just go in through php...

Code:
$con = mysql_connect()

// I forgot the command to retrieve the table names so I am guessing...

$tables = get_a_list_of_all_the_tables($con);

foreach($tables as $a => $b){

$q = mysql_query("REPAIR TABLE `".$b."`",$con);

}
I did not try this code... I don't expect it to work... it's just for illustration...


PHP: mysql_list_tables - Manual

Guess I will have to spend time reading this ... hope to find a solution so I do not need to do manually.


The best place to figure out more about optimizing tables is with the EXPLAIN statement... jmo...

You can prepend it to the beginning of your database query and mysql will return info about the query rather than the data you asked for...

"SELECT * FROM `table` WHERE `cat` = '2' ORDER BY `created`"

just add...

"EXPLAIN SELECT * FROM `table` WHERE `cat` = '2' ORDER BY `created`"

It will give you a good idea on which queries are overloading the server with table scans and which columns need keys on them.

MySQL :: MySQL 5.1 Reference Manual :: 12.3.2 EXPLAIN Syntax

It's probably not going to fix the overhead issue though... I don't know...



You can also dump a cron into linux via php as well... ( I forget the proper scheduling numbers )

system('0 0 0 0 5 wget -O - http://domain.com/the_script_which_r...ir_command.php --user-agent cron');


PHP: system - Manual

I know as I am having difficulties doing so ...


Guess I will have to spend time reading this ... hope to find a solution so I do not need to do manually. AS for the cron, I do know how to do the schedule. Thanks! Anyway, I am still hoping for someone who can help with the script that works otherwise I will have to do trial and error myself.
Reply With Quote
  #15 (permalink)  
Old 04-16-2009, 07:27 AM
WebProWorld New Member
 
Join Date: Jul 2008
Posts: 24
Gtal RepRank 0
Default Re: Optimize Overhead for database

Yes that's your best solution to spend some time reading that. Then you might have to do it manually. But guess that's alright too.
__________________
Visit Talend and Talendforge for open source ETL and data integration.

Last edited by Gtal; 04-16-2009 at 07:31 AM.
Reply With Quote
  #16 (permalink)  
Old 04-16-2009, 08:13 AM
WebProWorld New Member
 
Join Date: Apr 2009
Posts: 1
IndusaExpo RepRank 0
Default Re: Optimize Overhead for database

I completly Agree...!
Reply With Quote
  #17 (permalink)  
Old 04-16-2009, 09:28 AM
edhan's Avatar
WebProWorld Veteran
 
Join Date: Aug 2003
Location: Singapore
Posts: 701
edhan RepRank 3edhan RepRank 3
Wink Re: Optimize Overhead for database

Update: Till now I am still unable to find the best way to optimize the entire database with my cronjob. If I can find the correct script to run on cronjob, I will put it here for others to see.

Meantime, still reading up on mysql database.
Reply With Quote
  #18 (permalink)  
Old 04-29-2009, 09:15 AM
edhan's Avatar
WebProWorld Veteran
 
Join Date: Aug 2003
Location: Singapore
Posts: 701
edhan RepRank 3edhan RepRank 3
Default Re: Optimize Overhead for database

Thanks. I will check SEM blogs as suggested. Hopefully I can get a solution.
Reply With Quote
  #19 (permalink)  
Old 04-29-2009, 10:58 AM
danlefree's Avatar
WebProWorld Pro
 
Join Date: Jun 2005
Location: Seattle
Posts: 255
danlefree RepRank 4danlefree RepRank 4danlefree RepRank 4danlefree RepRank 4
Default Re: Optimize Overhead for database

I threw together a basic MySQL Automated Maintenance Script which should do the trick.

Please let me know by private message if you encounter any issues with it.
__________________
Dan LeFree | Product Manager (Linux VPS Hosting) | Owner/Operator (Web development, marketing)
Reply With Quote
  #20 (permalink)  
Old 04-29-2009, 10:53 PM
edhan's Avatar
WebProWorld Veteran
 
Join Date: Aug 2003
Location: Singapore
Posts: 701
edhan RepRank 3edhan RepRank 3
Smile Re: Optimize Overhead for database

Thanks a million! I will check it out and if it does not work, I will send you a PM.
Reply With Quote
  #21 (permalink)  
Old 05-01-2009, 12:42 PM
edhan's Avatar
WebProWorld Veteran
 
Join Date: Aug 2003
Location: Singapore
Posts: 701
edhan RepRank 3edhan RepRank 3
Default Re: Optimize Overhead for database

Danlefree

Received this error:

Fatal error: Class 'mysqli' not found on line 43
Reply With Quote
  #22 (permalink)  
Old 05-02-2009, 06:44 AM
danlefree's Avatar
WebProWorld Pro
 
Join Date: Jun 2005
Location: Seattle
Posts: 255
danlefree RepRank 4danlefree RepRank 4danlefree RepRank 4danlefree RepRank 4
Default Re: Optimize Overhead for database

Sounds like it may be time for a PHP update?

Quote:
The mysqli extension is included with PHP versions 5 and later.
- PHP MySQLi Documentation

Added legacy support to the mysql_maintenance.php script, in any case.
__________________
Dan LeFree | Product Manager (Linux VPS Hosting) | Owner/Operator (Web development, marketing)
Reply With Quote
  #23 (permalink)  
Old 05-02-2009, 07:28 AM
edhan's Avatar
WebProWorld Veteran
 
Join Date: Aug 2003
Location: Singapore
Posts: 701
edhan RepRank 3edhan RepRank 3
Default Re: Optimize Overhead for database

Quote:
Originally Posted by danlefree View Post
Sounds like it may be time for a PHP update?



- PHP MySQLi Documentation

Added legacy support to the mysql_maintenance.php script, in any case.
My server is running with PHP 5. I will check with the tech support.
Reply With Quote
  #24 (permalink)  
Old 05-05-2009, 05:57 PM
danlefree's Avatar
WebProWorld Pro
 
Join Date: Jun 2005
Location: Seattle
Posts: 255
danlefree RepRank 4danlefree RepRank 4danlefree RepRank 4danlefree RepRank 4
Default Re: Optimize Overhead for database

Quote:
Originally Posted by edhan View Post
My server is running with PHP 5. I will check with the tech support.
I did update the script to support PHP's legacy mysql functions, so you should be able to run it either way.

Note: You will need to add a shebang to the beginning of the script and set the correct script execution permissions if you plan to call the script directly from a cron job - alternatively, if you have PHP's Command Line Interface (php-cli) library installed, you can invoke the script from cron with a call to PHP followed by the script's filename.
__________________
Dan LeFree | Product Manager (Linux VPS Hosting) | Owner/Operator (Web development, marketing)
Reply With Quote
  #25 (permalink)  
Old 05-05-2009, 11:25 PM
edhan's Avatar
WebProWorld Veteran
 
Join Date: Aug 2003
Location: Singapore
Posts: 701
edhan RepRank 3edhan RepRank 3
Default Re: Optimize Overhead for database

Quote:
Originally Posted by danlefree View Post
I did update the script to support PHP's legacy mysql functions, so you should be able to run it either way.

Note: You will need to add a shebang to the beginning of the script and set the correct script execution permissions if you plan to call the script directly from a cron job - alternatively, if you have PHP's Command Line Interface (php-cli) library installed, you can invoke the script from cron with a call to PHP followed by the script's filename.
This time no error but it does not optimize the table. I ended up going into phpMysql to do manual optimization.
Reply With Quote
  #26 (permalink)  
Old 05-07-2009, 03:59 AM
danlefree's Avatar
WebProWorld Pro
 
Join Date: Jun 2005
Location: Seattle
Posts: 255
danlefree RepRank 4danlefree RepRank 4danlefree RepRank 4danlefree RepRank 4
Default Re: Optimize Overhead for database

Ah, sorry - got that sorted.


I was calling mysql_fetch_assoc instead of mysql_fetch_array so the $table[0] reference was returning null.

Updated + tested for both mysqli and mysql_* pathways.
__________________
Dan LeFree | Product Manager (Linux VPS Hosting) | Owner/Operator (Web development, marketing)
Reply With Quote
  #27 (permalink)  
Old 05-07-2009, 09:13 AM
edhan's Avatar
WebProWorld Veteran
 
Join Date: Aug 2003
Location: Singapore
Posts: 701
edhan RepRank 3edhan RepRank 3
Thumbs up Re: Optimize Overhead for database

Hi danlefree

Thanks! You have solved my problem of doing manual optimization.

I would recommend anyone who faces the same problem to use your script.
Reply With Quote
Reply

  WebProWorld > Webmaster, IT and Security Discussion > Database Discussion Forum

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
What More can i do to optimize this site? finditmalta Search Engine Optimization Forum 47 05-22-2008 04:00 PM
How to optimize database pages? Steven1976a Search Engine Optimization Forum 7 05-16-2008 11:29 AM
What do you optimize? SEOforGoogle Search Engine Optimization Forum 13 03-28-2006 02:04 AM
How to Optimize your website Miki Google AdWords/Google AdSense 1 06-01-2005 09:41 AM
Optimize for INTEXT brucemcc Google Discussion Forum 14 02-13-2004 12:26 AM


All times are GMT -4. The time now is 01:22 AM.



Search Engine Optimization by vBSEO 3.3.0