Home » Performance » MySQL » mysql tables crashing
| mysql tables crashing [message #1697] |
Mon, 27 August 2007 05:25  |
rashmirani Messages: 5 Registered: August 2007 Location: India |
Junior Member |
|
|
Hi All,
I developed DB of one portal in mysql 5.0.26.
since last 20 days, hosted site on server win2k3. I found problem with few maximum used tables of Database. Those tables getting crashed on daily basis. daily I need to repair tables of database. I would like to fix this problem asap.
If anyone can guide me what changes I can apply in mysql configuration to stop table crashing probelm?
Or if anyone have idea how to set query log to detect problemtic queries of my php scipts.
thanks n regards.
|
|
|
| Re: mysql tables crashing [message #1713 is a reply to message #1697 ] |
Sun, 02 September 2007 11:56   |
 |
jcn50 Messages: 44 Registered: September 2007 |
Member |
|
|
What do you mean by "table crashing"??... What kind of error do you have?...
The only way to get a mySQL daemon stalled when using scripts, is when you try to INSERT overflow data...
For example, let's say that you have a TEXT field, but in your scripts you try to INSERT a variable, having a length > 65535 characters... So you will need to use the substr() function.
Hope this helps~.
Enjoy the Net!
|
|
| |
| Re: mysql tables crashing [message #1770 is a reply to message #1764 ] |
Sun, 09 September 2007 11:47   |
 |
jcn50 Messages: 44 Registered: September 2007 |
Member |
|
|
| allworknoplay wrote on Sat, 08 September 2007 17:56 | The issue is that my table is indexed and I think
all the inserts and possibly deletes is causing the index
to be out of sync...
|
How big is your index?..
What kind of "crash error" do you have?.. I really think it has to do with some overflow INSERTs...
You can use "DELETE QUICK" instead of "DELETE".
Enjoy the Net!
|
|
| |
| Re: mysql tables crashing [message #1772 is a reply to message #1771 ] |
Sun, 09 September 2007 20:18   |
 |
jcn50 Messages: 44 Registered: September 2007 |
Member |
|
|
Again: how do you know that your TABLE IS CRASHING? ..
| allworknoplay wrote on Sun, 09 September 2007 16:36 | Yes! That is what I meant to say, I'm INSERTing so much
it's having a hardtime keeping up. Atleast that is my theory.
|
What I meant by "overflow INSERT" is something like this:
- having a table with a TEXT (or BLOB) field/column
- INSERT a variable, let's call it $in
- make the mySQL query with a PHP script using $in [where it should be using substr($in,65530)]
- your mySQL query crash (not the server, only the query) so your INSERT is not recorded into the DB
- next / others queries are proceeded.
Add a full mySQL errors' report in your scripts.
Also, you can try the mySQL query "SHOW PROCESSLIST" or "SHOW FULL PROCESSLIST" to see if there's a lot of queued INSERT.
| allworknoplay wrote on Sun, 09 September 2007 16:36 | I think it is the sporadic "spikes" that causes the issue.
The data flow for the most part is pretty even but there are
times when data gets put in by our system at the same time
and perhaps during that peak, the DB can't keep up...
|
The DB can keep up, simply because all INSERTs are put on a waiting list, but some scripts may hang the server (waiting for the INSERT query to complete), and then timeout.
In that case you can use "INSERT DELAYED": your scripts will not wait for the INSERT to be completed anymore, and your mySQL server will execute the INSERT query when the load will be lower.
| allworknoplay wrote on Sun, 09 September 2007 16:36 | My key_buffer is set to 600 megs...
|
The cumulative size of all your indexes are > 113 MB?...
How much physical RAM do you have?
[Updated on: Sun, 09 September 2007 20:32] Enjoy the Net!
|
|
|
| Re: mysql tables crashing [message #1773 is a reply to message #1772 ] |
Sun, 09 September 2007 22:43   |
allworknoplay Messages: 58 Registered: September 2007 Location: New York |
Member |
|
|
| jcn50 wrote on Sun, 09 September 2007 20:18 | Again: how do you know that your TABLE IS CRASHING? ..
|
Thanks for taking the time to respond to my questions I really
appreciate it!!
I have one table called "data_day" that is heavily used.
Everyday I check the row count and file size with a script
I wrote. The data in that table should only be within a 36 hour
period so I have another program that deletes data older than 36 hours.
When the table crashes, the many INSERTS continue to still happen but the DELETES can't. So the table size gets really big.
When I see this, I jump on the server and type:
CHECK TABLE data_day
That's when it tells me that the INDEX's are corrupted because
some numbers doesn't match another number.
"REPAIR TABLE data_day" fixes the issue but I have to do this almost every 2-3 days...
The error log size should be 0, so now I have a cron job
that checks it and if anything goes into it, I get sent
an email. This way I can try to fix the problem asap, instead
of finding out hours later...
| jcn50 wrote on Sun, 09 September 2007 20:18 |
What I meant by "overflow INSERT" is something like this:
- having a table with a TEXT (or BLOB) field/column
- INSERT a variable, let's call it $in
- make the mySQL query with a PHP script using $in [where it should be using substr($in,65530)]
- your mySQL query crash (not the server, only the query) so your INSERT is not recorded into the DB
- next / others queries are proceeded.
Add a full mySQL errors' report in your scripts.
Also, you can try the mySQL query "SHOW PROCESSLIST" or "SHOW FULL PROCESSLIST" to see if there's a lot of queued INSERT.
|
My table does not have TEXT or BLOB field/column.
I'm not using substr($in,65530) however that sounds like a good
idea. I only have 8 columns that consist of: INT, VARCHAR and BIGINT. Only the first column is a primary key and another is INDEXED.
I have tried SHOW PROCESSLIST but I have not tried the FULL PROCESSLIST so I will give that a shot as well...
How would you suggest going about adding a mysql error's report
in my scripts? Also can you elaborate on the "substr($in,65530)"
I understand it is limiting the actual data to 65K characters but what is the exact reason for doing so and why would more characters cause a crash?
| jcn50 wrote on Sun, 09 September 2007 20:18 |
The DB can keep up, simply because all INSERTs are put on a waiting list, but some scripts may hang the server (waiting for the INSERT query to complete), and then timeout.
In that case you can use "INSERT DELAYED": your scripts will not wait for the INSERT to be completed anymore, and your mySQL server will execute the INSERT query when the load will be lower.
|
I've heard about the INSERT DELAYED may make things worse
in the case of a crash and repairing the table would be a little
bit more difficult so I'm a little concerned about playing around with the INSERT DELAYED command...
| jcn50 wrote on Sun, 09 September 2007 20:18 |
The cumulative size of all your indexes are > 113 MB?...
How much physical RAM do you have?
|
113MB is the exact size of all the *.MYI's when I add them
up...
The server is a Dual Core Xeon with 2GIG's RAM.
Again, thanks for taking the time to chat with me about this...I've tried to do as much homework as I can on mysql
and at the end of the day, you just can't know everything right?
|
|
| |
| Re: mysql tables crashing [message #1775 is a reply to message #1697 ] |
Mon, 10 September 2007 01:18   |
rashmirani Messages: 5 Registered: August 2007 Location: India |
Junior Member |
|
|
Hello All,
thanks for reply.
I am using phpMyAdmin frontend to access mysql databases.
Table crash mean when I select database and see the list of tables. In action with specific tables status displayed "in use" instead of operation command like browse/select/insert/properties..etc.
I set manual restrictions while insert records into tables. trim the contact as per field size. though atleast one table i can see daily with status "in use".
anyone have idea can i trace the problem using error log files??
where and how can i read:
-->The Slow Query Log
-->The General Query Log
Please help me.
regards.
-Rashmi
[Updated on: Mon, 10 September 2007 02:33] Hi...
|
|
|
| Re: mysql tables crashing [message #1777 is a reply to message #1773 ] |
Mon, 10 September 2007 04:45   |
 |
jcn50 Messages: 44 Registered: September 2007 |
Member |
|
|
| allworknoplay wrote on Mon, 10 September 2007 02:43 |
Thanks for taking the time to respond to my questions I really
appreciate it!!
|
You're welcome .
| allworknoplay wrote on Mon, 10 September 2007 02:43 |
When the table crashes, the many INSERTS continue to still happen but the DELETES can't. So the table size gets really big.
When I see this, I jump on the server and type:
CHECK TABLE data_day
That's when it tells me that the INDEX's are corrupted because
some numbers doesn't match another number.
|
It will be good if you can copy/paste here what the server exactly tells you.
Are your INSERT and DELETE queries done from the same script? Or do you have multiple scripts working on your DB at the same time?
| allworknoplay wrote on Mon, 10 September 2007 02:43 |
"REPAIR TABLE data_day" fixes the issue but I have to do this almost every 2-3 days...
|
I've never done a REPAIR TABLE in my life, but let's check it:
1) Do you have a WESTERN DIGITAL hard drive?... I got many problems with this hard drive brand in the past, so it may be a hardware problem. I know no WESTERN DIGITAL hard drive that worked more than 5 years ... MAXTOR ones aren't reliable too.
2) Most likely, I think the problems lies in the scripting. For example: let's imagine that your scripts managed to INSERT two same PRIMARY KEYs in the DB (it seems impossible, however I've done it quite a few times!), the mySQL server is likely to behave weirdly.
Thus said, never use a TIMESTAMP value as a PRIMARY KEY.
So the only way to know what's happening, it's to create its own error_log reporting (see below).
| allworknoplay wrote on Mon, 10 September 2007 02:43 |
I only have 8 columns that consist of: INT, VARCHAR and BIGINT. Only the first column is a primary key and another is INDEXED.
|
Considering what you wrote, it is likely that the VARCHAR column can be subject to an overflow.
Numeric columns like INT or BIGINT have an integrated overflow-protection. For example: if you try to put "3000000000" into an UNSIGNED INT column, the mySQL will automatically record "2147483647" (the max number).
| allworknoplay wrote on Mon, 10 September 2007 02:43 |
I have tried SHOW PROCESSLIST but I have not tried the FULL PROCESSLIST so I will give that a shot as well...
|
SHOW PROCESSLIST and SHOW FULL PROCESSLIST are the same. Some people have just an habit to know only one, so I wrote both. It's not that important if you only do SHOW PROCESSLIST.
What is important is to see the load of your server, and to check what kind of query is taking a long time.
Now looking at you wrote, it seems that the DELETE are taking a bunch of time. The only way I can think of fixing this is to use DELETE QUICK. Because when you do a DELETE, the server is likely to copy all of your table, without the row you wanted to DELETE... Very resources consuming, especially if you do a lot of INSERTs thereafter, DELETE QUICK is a must!
| allworknoplay wrote on Mon, 10 September 2007 02:43 |
How would you suggest going about adding a mysql error's report
in my scripts? Also can you elaborate on the "substr($in,65530)"
I understand it is limiting the actual data to 65K characters but what is the exact reason for doing so and why would more characters cause a crash?
|
You need to create a function, that writes to a file (or sends an email) when a query failed.
There are multiple ways to do it, but it could look like this:
function error($detailed_error,$which_query,$where)
{
/* let's say you log errors in a file */
$f=fopen("C:\\error_log.txt","a");
fwrite($f,"The detailed error is: ".$detailed_error."\r\n\r\n");
fwrite($f,"The query it tried to do is: ".$which_query."\r\n\r\n");
fwrite($f,"Line in the script where it happened: ".$where."\r\n\r\n*****************\r\n\r\n");
fclose($f);
}
One you're satisfied with your function, you have to put it in your script, after EVERY mySQL query! You call it like this:
$query = "INSERT whatever you want";
$result = mysql_query($query);
if ($result === FALSE) error(mysql_error(),$query,__LINE__);
mysql_error() is an integrated function which gives you the full text of the error, whereas __LINE__ is a constant in PHP.
It's time for some scripts update .
| allworknoplay wrote on Mon, 10 September 2007 02:43 |
I've heard about the INSERT DELAYED may make things worse
in the case of a crash and repairing the table would be a little
bit more difficult so I'm a little concerned about playing around with the INSERT DELAYED command...
|
That's because we don't know (yet) what causes the crash. But if you have, let's say 20 computers accessing the same DB, and having an INSERT every 0.5 second, believe me INSERT DELAYED is good for the employee looking at her screen and saying "why the computa is soo slow taday " .
More seriously: let's stick with the INSERT for now, and see if the error() function gives more details about the crash.
| allworknoplay wrote on Mon, 10 September 2007 02:43 |
113MB is the exact size of all the *.MYI's when I add them
up...
The server is a Dual Core Xeon with 2GIG's RAM.
|
I don't see any reason for having a huge key_buffer_size of 600 MB then... You can cut-it off half to 300 MB.
| allworknoplay wrote on Mon, 10 September 2007 02:43 |
Again, thanks for taking the time to chat with me about this...I've tried to do as much homework as I can on mysql
and at the end of the day, you just can't know everything right?
|
Sure, we are all here to learn!
[Updated on: Mon, 10 September 2007 05:10] Enjoy the Net!
|
|
|
| Re: mysql tables crashing [message #1778 is a reply to message #1775 ] |
Mon, 10 September 2007 04:59   |
 |
jcn50 Messages: 44 Registered: September 2007 |
Member |
|
|
| rashmirani wrote on Mon, 10 September 2007 05:18 | anyone have idea can i trace the problem using error log files??
where and how can i read:
-->The Slow Query Log
-->The General Query Log
|
See my previous post for error logging. Apart from SHOW PROCESSLIST, you can make your own "slow query log" taking a timestamp before and after your query.
For example:
$query = "whatever you want to INSERT / DELETE";
$time_before=date("U");
$result = mysql_query($query);
$time_after=date("U");
// let's say you want to have all the queries that took more than a minute:
if ($time_afer-$time_before>60) error("Slow query",$query,__LINE__);
Now I'm gonna rest after I took on your job!
[Updated on: Mon, 10 September 2007 05:19] Enjoy the Net!
|
|
|
| Re: mysql tables crashing [message #1783 is a reply to message #1777 ] |
Mon, 10 September 2007 18:53   |
allworknoplay Messages: 58 Registered: September 2007 Location: New York |
Member |
|
|
| jcn50 wrote on Mon, 10 September 2007 04:45 |
It will be good if you can copy/paste here what the server exactly tells you.
Are your INSERT and DELETE queries done from the same script? Or do you have multiple scripts working on your DB at the same time?
|
I didn't get a chance to save the output since I just ran
REPAIR TABLE, next time,(hoping there is no next time) it happens I'll post it here.
Yes both the INSERT/DELETE are done within the same script. Basically I have about 4 scripts that are accessed by our systems about 5 times a second. Each access creates MANY inserts and towards the end a DELETE to clean things up. The INSERTS vary depending on the data. They can easily be about 20 inserts a second within the same script or 1000 /sec within the same script. Now if you multiply that by how often per second the script gets accessed, I get a sense that the scripts are almost all fighting for INSERT resources.
I think I will modify the scripts to use BULK INSERT and see if that does any difference...I think it will!!??
| jcn50 wrote on Mon, 10 September 2007 04:45 |
I've never done a REPAIR TABLE in my life, but let's check it:
1) Do you have a WESTERN DIGITAL hard drive?... I got many problems with this hard drive brand in the past, so it may be a hardware problem. I know no WESTERN DIGITAL hard drive that worked more than 5 years ... MAXTOR ones aren't reliable too.
2) Most likely, I think the problems lies in the scripting. For example: let's imagine that your scripts managed to INSERT two same PRIMARY KEYs in the DB (it seems impossible, however I've done it quite a few times!), the mySQL server is likely to behave weirdly.
Thus said, never use a TIMESTAMP value as a PRIMARY KEY.
So the only way to know what's happening, it's to create its own error_log reporting (see below).
|
1) It's an HP DL320 DualCore Xeon so I don't know what brand the disk is. I'm sure it's HP-something. It's a SATA drive with hardware RAID 1.
I do agree with you though, both Maxtor and WD suck! I've used them in my experience and they fail often..Seagate is the best.
2)I think you're right. I truly think it's the scripting that's not making the best use of mysql syntax.
I will take your advice and go over EVERY INSERT command as well as DELETE command, basically any query, and create a condition to output to an error log file if there's a problem.
My scripts are all over 1000 lines of code so it's going to take some time and careful planning to make sure I don't mess anything up!!!
| jcn50 wrote on Mon, 10 September 2007 04:45 |
Considering what you wrote, it is likely that the VARCHAR column can be subject to an overflow.
Numeric columns like INT or BIGINT have an integrated overflow-protection. For example: if you try to put "3000000000" into an UNSIGNED INT column, the mySQL will automatically record "2147483647" (the max number).
|
I will go ahead and use the substr function. Do you think by using this for all the VARCHAR's it will be a strain or cause more memory usage for PHP?
| jcn50 wrote on Mon, 10 September 2007 04:45 |
DELETE QUICK is a must!
|
Yes I am starting to become a believer in this function!!!
| jcn50 wrote on Mon, 10 September 2007 04:45 |
You need to create a function, that writes to a file (or sends an email) when a query failed.
There are multiple ways to do it, but it could look like this:
function error($detailed_error,$which_query,$where)
{
/* let's say you log errors in a file */
$f=fopen("C:\\error_log.txt","a");
fwrite($f,"The detailed error is: ".$detailed_error."\r\n\r\n");
fwrite($f,"The query it tried to do is: ".$which_query."\r\n\r\n");
fwrite($f,"Line in the script where it happened: ".$where."\r\n\r\n*****************\r\n\r\n");
fclose($f);
}
One you're satisfied with your function, you have to put it in your script, after EVERY mySQL query! You call it like this:
$query = "INSERT whatever you want";
$result = mysql_query($query);
if ($result === FALSE) error(mysql_error(),$query,__LINE__);
mysql_error() is an integrated function which gives you the full text of the error, whereas __LINE__ is a constant in PHP.
It's time for some scripts update .
|
I like your code and I will steal it..
This is the part of coding that I hate, the long long
time it takes to find out the cause for leaks, corruptions etc...
| jcn50 wrote on Mon, 10 September 2007 04:45 |
I don't see any reason for having a huge key_buffer_size of 600 MB then... You can cut-it off half to 300 MB.
|
Yeah, I had a couple other tables that were getting big because
they stored history data. I've since removed those but they added up to about 600 which is why my key buffer was at 600.
I could probably safely change it back to the default of 384
just to give it some room for growth...
It will take me awhile to go over the code and add your suggestions, but I will most definitley come back here to update everyone on the results.
The good news is that after some tweaks over the weekend, it hasn't crashed yet, so it's been a good 3 days thus far.
The tweak I made, in case anyone wants to know is my read_rnd_buffer, it was set to 8M when it should have been 2M
since I only have 2Gigs.
I also changed my wait_timeout to 600 seconds instead of the
default of 28,800 seconds!!!!!!
[Updated on: Mon, 10 September 2007 18:59]
|
|
|
| Re: mysql tables crashing [message #1784 is a reply to message #1697 ] |
Tue, 11 September 2007 02:32   |
rashmirani Messages: 5 Registered: August 2007 Location: India |
Junior Member |
|
|
HI All,
Thanks for all reply.
let me explain my problem again here.
My site hosted on linux server before and run well.
before a month site hosted on windows server.
we are using pear class to execute query and using phpmyadmin as mysql frontend.
Problem of mysql table "in use" started after the day when site hosted on windows server. daily more than 3 tables show status "in use" frequently.
I applied required changes in my.ini file. after mysql configuration changes applied now 1 or 2 tables shows status "in use" when see table list in phpmyadmin.
Once i repair table then all run well.
now please guide me how to detect the problem area and solve this problem.
-Rashmi
[Updated on: Tue, 11 September 2007 02:32] Hi...
|
|
|
| Re: mysql tables crashing [message #1785 is a reply to message #1784 ] |
Tue, 11 September 2007 03:30   |
 |
jcn50 Messages: 44 Registered: September 2007 |
Member |
|
|
| rashmirani wrote on Tue, 11 September 2007 06:32 | HI now please guide me how to detect the problem area and solve this problem.
|
Man, you're not into it: the fact that your tables are "in use" is because they crashed. And, like you said, you need to make a repair.
Before doing a repair, you can use CHECK TABLE and open your mySQL error_log.
Check the previous posts in this thread for error reporting and logging, otherwise you won't find the cause. How can you find the origin of something if you only know/see the consequence?? How do you want us to help you if you only tell us that you need to repair your tables??
Update your scripts and post the error(s) you got here in this post. There is no way someone else does it for you, especially when I already wrote the code you need to add... 
As allworknoplay suggested, check your read_rnd_buffer value, you may need to lower it to 2MB; same for the wait_timeout value.
Alternatively, you can tell us:
- what is the version your Windows OS?
- what is the filesystem used? (FAT32 or NTFS)
- how big is your DB?
- how big is your indexes?
- the brand of your HD?
[Updated on: Tue, 11 September 2007 03:54] Enjoy the Net!
|
|
|
| Re: mysql tables crashing [message #1787 is a reply to message #1785 ] |
Tue, 11 September 2007 05:49   |
rashmirani Messages: 5 Registered: August 2007 Location: India |
Junior Member |
|
|
Hi jcn50,
Thanks for suggestion.
In my site more than 300 scripts are in use.
so, I already modify code in such a way, whenever mysql error occured, I will receieve email consist errorsum query.
Ans. of your question as much I have :
- what is the version your Windows OS?
win 2K3 R2 service pack 2
- how big is your DB?
1.5 GB, no. of tables more than 80
- RAM
2GB
I used MyIsam storage Engine.
my.ini configuration at present as:
max_connections=400
table_cache=4096
thread_cache_size=16
myisam_max_sort_file_size=100G
myisam_max_extra_sort_file_size=100G
myisam_sort_buffer_size=205M
key_buffer_size=350M
read_buffer_size=2M
read_rnd_buffer_size=8M
sort_buffer_size=3M
awating reply with suggestion for changes if require any.
-Rashmi
[Updated on: Tue, 11 September 2007 05:49] Hi...
|
|
|
| Re: mysql tables crashing [message #1792 is a reply to message #1787 ] |
Tue, 11 September 2007 10:33   |
allworknoplay Messages: 58 Registered: September 2007 Location: New York |
Member |
|
|
| rashmirani wrote on Tue, 11 September 2007 05:49 |
I used MyIsam storage Engine.
my.ini configuration at present as:
max_connections=400
table_cache=4096
thread_cache_size=16
myisam_max_sort_file_size=100G
myisam_max_extra_sort_file_size=100G
myisam_sort_buffer_size=205M
key_buffer_size=350M
read_buffer_size=2M
read_rnd_buffer_size=8M
sort_buffer_size=3M
|
Ok your key_buffer is 350M but do you know what the
total size of all your indexes are?
To make sure, total up the size of all files with a .MYI
extension. That will let you know if your key_buffer of 350M
is serving you correctly...
Your table cache could probably be reduced to 1024K
Also your read_rnd_buffer_size is wrong. As I posted earlier,
with 2GIGs of RAM you cannot have 8M.
Reduce that to 2M.
[Updated on: Tue, 11 September 2007 10:35]
|
|
|
| Re: mysql tables crashing [message #1800 is a reply to message #1792 ] |
Wed, 12 September 2007 00:43   |
rashmirani Messages: 5 Registered: August 2007 Location: India |
Junior Member |
|
|
set following in my.ini:
read_rnd_buffer_size=2M
table_cache=1024
total size of all my indexes at present is 750M.
how to calculate all these parameters? is their sure guideline available??
Hi...
|
|
| | | |
| Re: mysql tables crashing [message #1807 is a reply to message #1697 ] |
Wed, 12 September 2007 22:58   |
 |
jcn50 Messages: 44 Registered: September 2007 |
Member |
|
|
A- No error report from the scripts' side?
B- Can you post an extract of one row of "data_day" with full types used and auto_increment or timestamp if any? (you can remove any confidential data if any).
C- Did you use DELETE or DELETE QUICK?
D- Can you confirm that you're using MyISAM ?
E- Are you ready to sacrifice some disk space to gain a crash-free DB?
After you answered that, we'll see which next step you could do.
[Updated on: Wed, 12 September 2007 23:55] Enjoy the Net!
|
|
|
| Re: mysql tables crashing [message #1813 is a reply to message #1807 ] |
Thu, 13 September 2007 10:34   |
allworknoplay Messages: 58 Registered: September 2007 Location: New York |
Member |
|
|
| jcn50 wrote on Wed, 12 September 2007 22:58 |
A- No error report from the scripts' side?
B- Can you post an extract of one row of "data_day" with full types used and auto_increment or timestamp if any? (you can remove any confidential data if any).
C- Did you use DELETE or DELETE QUICK?
D- Can you confirm that you're using MyISAM ?
E- Are you ready to sacrifice some disk space to gain a crash-free DB?
After you answered that, we'll see which next step you could do.
|
A - I began to implement the error output into a logfile, but I haven't had time to finish, I have over 4000 lines of code I need to go through...but rest assured it will be implemented as it is an excellent idea...
B - There is nothing too sensitive with my data so here it is in it's full glory. This is AFTER I've already repaired the table.
mysql> select * from data_day limit 1;
+------------+------------+-----------+--------+----+------- -+-------+--------+
| device_id | timestamp | data_type | object | id | actual | gdata | gdata1 |
+------------+------------+-----------+--------+----+------- -+-------+--------+
| 1175214041 | 1189629601 | disk | C | | 1 | 31 | 0 |
+------------+------------+-----------+--------+----+------- -+-------+--------+
1 row in set (0.01 sec)
C - I don't want to use the DELETE QUICK yet and the reason why, and I think you will agree, is that from a programming/troubleshooting standpoint, you want to do one method first. Find out if that has relieved or resolved the issue.
If I go with DELETE QUICK and also the BULK INSERTS, I won't know which one was the actual fix. Since there are a lot more INSERTS, I think I want to try BULK INSERTS first...
D - Yes my tables are MYISAM.
E - If I can sleep better at night knowing my systems is crash-free, then bring it on!!!!
Compared to what I've seen out there, others have a MYSQL DB of greater than 20GIGs and are running fine, so the fact that I am less than 1GIG, I feel it's not so much the size of the DB causing the issue, it's just improper or inefficient methods that I'm using to access the DB....
|
|
| | |
| Re: mysql tables crashing [message #1824 is a reply to message #1697 ] |
Thu, 13 September 2007 18:18   |
 |
jcn50 Messages: 44 Registered: September 2007 |
Member |
|
|
OK guys,
Let's try something.
1- Be sure that NO script is running, so that your DB is not in use.
2- We are going to convert your DB engine. You don't have to update your scripts, as it will only change how your DB server handles the data. The SQL command is:
ALTER TABLE your_table_name TYPE=InnoDB;
If you have more than a table, you need to do this for every table. I don't know how long the conversion will take, but you can check with SHOW PROCESSLIST when it's done.
So, allworknoplay, let's try:
ALTER TABLE data_day TYPE=InnoDB;
3- InnoDB is a crash-free engine. The tables are repaired automatically if a crash occurs. You can revert to myISAM again anytime. As I'm new to InnoDB, I don't know how to tweak the options: if you want to do that, please open another topic.
Enjoy the Net!
|
|
| | |
| Re: mysql tables crashing [message #1827 is a reply to message #1826 ] |
Thu, 13 September 2007 23:24   |
 |
jcn50 Messages: 44 Registered: September 2007 |
Member |
|
|
| allworknoplay wrote on Fri, 14 September 2007 01:28 |
+-----------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+--------------+------+-----+---------+-------+
| device_id | int(10) | NO | PRI | | |
| timestamp | int(10) | NO | PRI | | |
| data_type | varchar(32) | NO | PRI | | |
| object | varchar(120) | NO | PRI | | |
| id | varchar(10) | NO | MUL | | |
| actual | int(1) | NO | | 0 | |
| gdata | bigint(20) | NO | | 0 | |
| gdata1 | bigint(20) | NO | | 0 | |
+-----------+--------------+------+-----+---------+-------+
|
Wait! As per mySQL standards, you should have only ONE primary key per table!
http://dev.mysql.com/doc/refman/5.0/en/create-table.html
"A PRIMARY KEY is a unique index where all key columns must be defined as NOT NULL. If they are not explicitly declared as NOT NULL, MySQL declares them so implicitly (and silently). A table can have only one PRIMARY KEY."
So you should have only one PRI, the other indexes should be noted as MUL, just like the field "id".
That's why your table was crashing man! I think we found out! Because the "timestamp" may not be unique (as I said earlier in message #1777 in this topic), same for the "data_type" and "object" fields! So be sure that "device_id" is UNIQUE in your design! (i.e: using AUTO_INCREMENT, not being generated by your script)
If you had had the scripting error_reporting, you would have had an error like "can't INSERT duplicate keys" or "can't DELETE duplicate keys". 
| allworknoplay wrote on Fri, 14 September 2007 01:28 |
Plus this stuff is PRODUCTION. If I mess up at all in any which way, I am in TROUBLE!!!!
|
Well, it can't be worse than MyISAM ....at least if you design your tables & write scripts properly!
[Updated on: Fri, 14 September 2007 00:18] Enjoy the Net!
|
|
|
| Re: mysql tables crashing [message #1831 is a reply to message #1697 ] |
Fri, 14 September 2007 09:54   |
allworknoplay Messages: 58 Registered: September 2007 Location: New York |
Member |
|
|
Well I was hoping I didn't have to explain what the table was all about but here goes...
The first 4 columns are unique as a WHOLE when I built the table, at the end I basically said,
UNIQUE(device_id, timestamp,data_type,object) so data in all 4 columns have to be a unique mix. Below is the SHOW CREATE TABLE.
CREATE TABLE `data_day` (
`device_id` int(10) NOT NULL,
`timestamp` int(10) NOT NULL,
`data_type` varchar(32) NOT NULL,
`object` varchar(120) NOT NULL,
`id` varchar(10) NOT NULL default '',
`actual` int(1) NOT NULL default '0',
`gdata` bigint(20) NOT NULL default '0',
`gdata1` bigint(20) NOT NULL default '0',
UNIQUE KEY `device_id` (`device_id`,`timestamp`,`data_type`,`object`),
KEY `id` (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1
Let me ask you this, say I am inserting a lot of data that is already unique so mysql has to reject them, do you think that in itself could be causing the crash?
|
|
|
| Re: mysql tables crashing [message #1832 is a reply to message #1697 ] |
Fri, 14 September 2007 10:28   |
 |
jcn50 Messages: 44 Registered: September 2007 |
Member |
|
|
You can have an INDEX that is NOT UNIQUE. But you can't have more than ONE PRIMARY INDEX, and that PRIMARY INDEX should be UNIQUE.
UNIQUE = there is no duplicate (in the same column). You can't consider 4 columns being unique as a whole for a PRIMARY INDEX.
I don't know if I answered your question?...
For example, if I do:
SELECT * FROM data_day WHERE device_id = 1175214041;
it should always return 0 or 1 result, even if the other columns are different as a whole.
The idea behind a PRIMARY INDEX is that it identifies each row uniquely. Let's imagine you have a list of prices, and your items have a bar code. The bar code is a PRIMARY INDEX because you can only have one price per bar code (even if the packaging changes, or the name of the product changes, or where it comes from changes; it doesn't matter, because we're talking about the same product).
What cause the crash is not the INSERT, it's the DELETE. I don't know how you make your query, but I guess MySQL wants to delete every row that as the same device_id (or any of the other 3 PRIMARY INDEXes being the same), resulting in a crash. When mySQL uses a PRIMARY INDEX for deleting, only ONE ROW can be deleted... whereas your table may contains more than a row with the same device_id (or more than a row with the same timestamp, etc).
Imagine that I ask you: "delete the product which has the bar code 1175214041", then you start to search on your list "which product has the bar code 1175214041?" and you end up with more than a single result, which one would you delete? (as you can only delete one) ... => crash
UNIQUE(device_id, timestamp,data_type,object) means:
- device_id contains no duplicate ;
- timestamp contains no duplicate ;
- data_type contains no duplicate ;
- object contains no duplicate.
UNIQUE(device_id, timestamp,data_type,object) doesn't mean: "there's only ONE UNIQUE row having a defined: device_id AND timestamp AND data_type AND object".
[Updated on: Fri, 14 September 2007 11:35] Enjoy the Net!
|
|
|
| Re: mysql tables crashing [message #1833 is a reply to message #1697 ] |
Fri, 14 September 2007 11:44   |
 |
jcn50 Messages: 44 Registered: September 2007 |
Member |
|
|
|
If you want the SQL commands to fix your indexes, ask me.
[Updated on: Fri, 14 September 2007 12:22] Enjoy the Net!
|
|
|
| Re: mysql tables crashing [message #1836 is a reply to message #1832 ] |
Fri, 14 September 2007 14:56   |
allworknoplay Messages: 58 Registered: September 2007 Location: New York |
Member |
|
|
| jcn50 wrote on Fri, 14 September 2007 10:28 |
UNIQUE(device_id, timestamp,data_type,object) means:
- device_id contains no duplicate ;
- timestamp contains no duplicate ;
- data_type contains no duplicate ;
- object contains no duplicate.
UNIQUE(device_id, timestamp,data_type,object) doesn't mean: "there's only ONE UNIQUE row having a defined: device_id AND timestamp AND data_type AND object".
|
HMMM!!!!!! Very very interesting....
Let me find some of my DELETE commands to see exactly how I'm doing it. But what you said is not how I intended my scripts
to work, that would explain a lot....
I always thought that including 4 unique columns would mean that the combination needs to be unique which is what my intentions were. so to make it simpler, let's play with 2 columns..
So I could insert a row with:
device_id = 10
timestamp = 12345677
But if I wanted to insert again:
device_id = 10
timestamp = 12345677
It shouldn't let me do that...atleast that is what I thought
I was doing...
I will confirm my DELETES, but usually the deletes are based
on timestamp, not even the device_id..
So if I have 10 records with device_id 10,12,13,14,15 etc..
My cleanup script would just delete any record that has a timestamp older than say 24 hours...
So I didn't think that I needed to be specific in that sense when deleting???
Thoughts?
|
|
|
| Re: mysql tables crashing [message #1837 is a reply to message #1697 ] |
Fri, 14 September 2007 15:12   |
 |
jcn50 Messages: 44 Registered: September 2007 |
Member |
|
|
OK, if you didn't intend to do what I wrote... it simply means that you have NO PRIMARY INDEX! ...
I'm not saying that what you want you to do is wrong, I'm just saying that the columns which are set to UNIQUE (or "PRIMARY INDEX") are wrong/misused.
SQL commands are:
ALTER TABLE data_day DROP PRIMARY KEY
(should delete all primary keys)
ALTER TABLE data_day DROP INDEX device_id
ALTER TABLE data_day DROP INDEX timestamp
ALTER TABLE data_day DROP INDEX data_type
ALTER TABLE data_day DROP INDEX object
(should remove the unique index)
ALTER TABLE data_day ADD INDEX device_id
ALTER TABLE data_day ADD INDEX timestamp
ALTER TABLE data_day ADD INDEX data_type
ALTER TABLE data_day ADD INDEX object
(should add a simple index)
And you're done!
Copy/paste your fields' type again, to show 5 beautiful "MUL" and no more "PRI".
[Updated on: Fri, 14 September 2007 15:13] Enjoy the Net!
|
|
|
| Re: mysql tables crashing [message #1838 is a reply to message #1697 ] |
Fri, 14 September 2007 15:18   |
allworknoplay Messages: 58 Registered: September 2007 Location: New York |
Member |
|
|
To answer your question, yes the data_day table should not have any column that is a primary key. The device_id is a primary key in another table and we use that in the data_day table for other purposes. Basically we dump a lot of data into the data_day table and I guess, the reason why we used Unique( 4 columns ) is that I didn't want any duplicate entry if any of the INSERTS all matched the 4 columns exactly..
Does that make any sense? So..
col1, col2, col3, col4 could have values 1,2,3,4 respectively
and if I wanted to INSERT those again, it should reject it..
But 1,2,2,3 or 1,1,1,1 any other combo would work...
I think we're pretty much on the same page, just want to confirm..
You have suggested other things to try earlier in this thread
so I want to try those first....you've given me plenty of troubleshooting ideas!!!
|
|
|
| Re: mysql tables crashing [message #1839 is a reply to message #1836 ] |
Fri, 14 September 2007 15:21   |
 |
jcn50 Messages: 44 Registered: September 2007 |
Member |
|
|
| allworknoplay wrote on Fri, 14 September 2007 18:56 | I always thought that including 4 unique columns would mean that the combination needs to be unique which is what my intentions were. so to make it simpler, let's play with 2 columns..
So I could insert a row with:
device_id = 10
timestamp = 12345677
But if I wanted to insert again:
device_id = 10
timestamp = 12345677
It shouldn't let me do that...atleast that is what I thought
I was doing...
|
1) You're right, INSERT shouldn't work if device_id and/or timestamp are set to UNIQUE.
2) What you typed here are the values of the INSERT. device_id and timestamp being UNIQUE or not, is irrelevant for what you want to do (just an INSERT).
3) So why keep having all these columns set to UNIQUE if they aren't?...
Enjoy the Net!
|
|
| |
| Re: mysql tables crashing [message #1841 is a reply to message #1838 ] |
Fri, 14 September 2007 15:26   |
 |
jcn50 Messages: 44 Registered: September 2007 |
Member |
|
|
| allworknoplay wrote on Fri, 14 September 2007 19:18 | To answer your question, yes the data_day table should not have any column that is a primary key. The device_id is a primary key in another table and we use that in the data_day table for other purposes. Basically we dump a lot of data into the data_day table and I guess, the reason why we used Unique( 4 columns ) is that I didn't want any duplicate entry if any of the INSERTS all matched the 4 columns exactly..
Does that make any sense? So..
|
Ok I got it... but it doesn't work like that. (see below)
| allworknoplay wrote on Fri, 14 September 2007 19:18 | col1, col2, col3, col4 could have values 1,2,3,4 respectively
and if I wanted to INSERT those again, it should reject it..
But 1,2,2,3 or 1,1,1,1 any other combo would work...
|
No it will not work:
- if you already have 1,2,3,4
AND
- if you try to insert 1,1,1,1
=> mySQL won't proceed the INSERT (because the first value is not distinct in the column), and mySQL will simply dump 1,1,1,1.
| allworknoplay wrote on Fri, 14 September 2007 19:18 |
You have suggested other things to try earlier in this thread
so I want to try those first....you've given me plenty of troubleshooting ideas!!!
|
Debugging is part of programming ... good luck!
Enjoy the Net!
|
|
|
| Re: mysql tables crashing [message #1842 is a reply to message #1841 ] |
Fri, 14 September 2007 15:30   |
allworknoplay Messages: 58 Registered: September 2007 Location: New York |
Member |
|
|
| jcn50 wrote on Fri, 14 September 2007 15:26 |
No it will not work:
- if you already have 1,2,3,4
AND
- if you try to insert 1,1,1,1
=> mySQL won't proceed the INSERT (because the first value is not distinct in the column), and mySQL will simply dump 1,1,1,1.
|
HMMMM, that is very interesting....
Let me do some research, because this could very well be
the problem!!!!!!!
|
|
| | |
Goto Forum:
Current Time: Sat Jul 4 11:20:45 EDT 2009
Total time taken to generate the page: 0.03088 seconds |