| Author |
Neal |
Iceman
Joined: Aug 31, 2002 Posts: 128 From: Mesa Arizona
| Posted: 2003-02-17 19:21  
[quote]
On 2003-02-16 21:40, Neal Stevens wrote:
Ok, we need to give you guys something more important to think about How about searching the web and locating a SQL statement that will allow me to remove records from a MySQL database older than a certain date? I've looked but cannot find anything and this forum db is over 40MB, I gotta prune! So put the crucial date debate off a few days and see what you can do.
Microsoft SQLSVR
Data Purge
Technique provided by Warren Humphrey, Sega Inc.
Microsoft SQLSVR is a cost effective way to provide a true SQL engine storage for large FactoryLink installations. Benefits of using an SQL engine include ad-hoc reporting, data backup and multi-person access of data without using FactoryLink.
FactoryLink does not provide a means for "rolling over" data in SQLSVR. This requires the end-user to purge unneeded data from the server periodically to ensure that there is space to store the most recent data.
This procedure uses SQLSVR scheduled tasks to automate the data purge of unneeded data.
Here is a brief overview of the steps necessary to use SQL Server to do Factory Link trending.
1) Install SQL Server and select both the MS SQLServer and Enterprise Manager services to start when the system boots. Note: The WindowsNT "Server" service must also be installed and in automatic.
2) Install the ODBC32 drivers. These are available on the SQL Server CD or from Microsoft.
3) Configure an ODBC32 connection (In Windows Control Panel) for each FactoryLink database you wish to put on SQL Server. (eg. Trending, logging, alarms, etc.) If security is not an issue, a trusted connection can be selected to avoid having to configure the ODBC historian in Factory Link with username and password.
4) Configure the FactoryLink ODBC Historian. Be sure there are no mailbox tags common to both the DB4 and ODBC historians if both are being used. In the connection string field, type...DSN=[name assigned in ODBC32]. If trused connection is not used, you must also supply the server name, username, and password in the connection string field. The FactoryLink manuals do not give the syntax for this for MS SQL Server.
5) In SQL Server, first register the server, then configure a new database device under which the FactoryLink databases will reside and a new database device for transaction logs. Next configure each of the new FactoryLink databases. Be sure to follow the SQL manuals recommendations on space requirements for both the data and transaction log. IMPORTANT!!! When first defining a new database, be sure and specify a database device for tranaction log and under the Options tab, select "Truncate log on checkpoint". Otherwise, your transaction log will fill up and stop logging new data.
6) In FactoryLink, create an IML procedure to build a text string which is one of the valid MS-SQL Server datetime formats. Put this newly created tag (eg. TIMESTMP) in all log tables but do not index on this field. Log it as a CHAR field.
7) To use SQL Server for trending, you must create scheduled tasks to delete old records and make room for new ones. A separate scheduled task is required for each table to be used for trending. Use something similar to the following T-SQL command when creating these scheduled tasks.
DELETE FROM tablename WHERE TIMESTMP < CONVERT(char(32),DATEADD(DAY,-1,GETDATE()),112)
NOTE: Be careful when selecting a datetime format as not all formats can be used for chronological comparison as a character field. One example of a datetime format that works would be yyyymmdd. This is MS-SQL format 112 in the MS-SQL Server manual. This format assures that the < and > operators will work correctly (or chronologically) on this character field.
Thanks to whumphrey@segainc.com
'
' Script to delete files older than a given number of days.
'
' WARNING: Files deleted with this program could not be recovered. They don't even get to Recycle Bin.
' Use at your own risk.
'
' (C) Copyright, 2002. Ferran Foz. Barcelona, Spain. ferran@ostres.com
'
' You may copy and distribute without changing the copyright notice.
'
'
Set StdOut = WScript.StdOut
Main
Sub Main()
'
' DropOldFiles
' folderspec - Folder where you want to delete files
' logfile - File where logfile will be generated.
' days - Number of days to keep files.
'
Call DropOldFiles("C:zzTEMP","C:TEMPLOG.TXT", 100)
End Sub
Sub DropOldFiles(folderspec, logfile, days)
Dim fso,f,f1,s,fi, cnt, tot
StdOut.WriteLine "Starting DropOldFiles..."
LogOpen(logfile)
cnt = 0
tot = 0
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(folderspec)
Set fc = f.Files
For Each f1 in fc
If DateDiff ("d",f1.DateLastModified, Now ) > days Then
LogWrite f1.name & " DateLastModified:" & f1.DateLastModified & " DaysOld:" & DateDiff ("d",f1.DateLastModified, Now )
fso.DeleteFile (folderspec & f1.name)
cnt = cnt + 1
End If
tot = tot + 1
Next
LogWrite "--------------------------------------------------------------"
LogWrite " Processed " & tot & " file(s). Deleted " & cnt & " file(s)."
LogWrite "--------------------------------------------------------------"
LogClose
StdOut.WriteLine "Ending DropOldFiles..."
End Sub
'
' *****************************************************************************************
'
'
' Write to the Logfile
'
Dim LogFile
Sub LogWrite (Text)
LogFile.WriteLine "[" & Now & "] " & Text
End Sub
Sub LogClose ()
LogFile.Close
Set Logfile=nothing
End Sub
Sub LogOpen (LogPath)
Dim fso, f1
Const ForAppend = 8
Set fso = CreateObject("Scripting.FileSystemObject")
Set LogFile = fso.OpenTextFile(LogPath, ForAppend, True)
Set fso = nothing
End Sub
Don't know if this will help you.
http://pdsf.nersc.gov/documentation/lsf/4.1/analyzer_msql_4.1/datasum_orasql.html
http://www.iss.net/support/product_utilities/realsecure_tech_center/utilities/index.php
http://web.mit.edu/admin/procedures/post_office/purge.html
_________________ <img src="http://members.cox.net/cga/ice.jpg" width="400" height="149">
"No bastard ever won a war by dying for his country. He won it by making the other poor dumb bastard die for his country."
- General George S. Patton, Jr
 
|
Neal Stevens
Joined: May 06, 2006 Posts: 0 From: Houston, Texas
| Posted: 2003-02-17 22:03  
Man, I wish I hadn't asked!
_________________
 
|
Iceman
Joined: Aug 31, 2002 Posts: 128 From: Mesa Arizona
| Posted: 2003-02-17 22:22  
Sorry I tried...
 
|
Neal Stevens
Joined: May 06, 2006 Posts: 0 From: Houston, Texas
| Posted: 2003-02-17 22:27  
LOl, thanks anyway That's a bit over my head at the moment. I was hoping for an SQL statement I could use with phpMyAdmin.
_________________
 
|
Madcowz
Joined: Feb 28, 2002 Posts: 574 From: Cambridge (UK)
| Posted: 2003-02-18 04:42  
DELETE * FROM TABLENAME where DATE > YEAR:MONTH:DAY
should do it.
Mad
_________________
Comsa
'When the hunter comes, the tiger runs with the deer'
 
|
Drebbel
Joined: Mar 05, 2002 Posts: 1782 | Posted: 2003-02-18 06:25  
Maybe you should consider to delete all "General Topics " and "Comments to SUBSIM Review" threads older than 1-1-2003.
That way we loose no valuable data from the on-topic forums. But maybe the gained space from this is too little ;-(
_________________
Drebbel
<a href="http://www.DutchSubmarines.com" target="_new">www.DutchSubmarines.com</a>
The Submarines of the Royal Netherlands Navy

 
|
Madcowz
Joined: Feb 28, 2002 Posts: 574 From: Cambridge (UK)
| Posted: 2003-02-18 08:28  
Like this.....
DELETE * FROM TABLENAME where USER LIKE DREBBEL
_________________
Comsa
'When the hunter comes, the tiger runs with the deer'
 
|
BaronVonRed
Joined: Jan 03, 2003 Posts: 577 | Posted: 2003-02-18 08:38  
Quote:
|
On 2003-02-18 04:42, Madcowz wrote:
DELETE * FROM TABLENAME where DATE > YEAR:MONTH:DAY
should do it.
Mad
|
|
Shouldn't that be a '<' rather than a '>'??
EDIT:
Also, depending on the version of SQL, I don't think the '*' is required and MAY generate an error if used. As always, I could be wrong, but I'd try it without the '*' first...
[ This Message was edited by: BaronVonRed on 2003-02-18 08:42 ]
 
|
Drebbel
Joined: Mar 05, 2002 Posts: 1782 | Posted: 2003-02-18 09:35  
Quote:
|
On 2003-02-18 08:28, Madcowz wrote:
Like this.....
DELETE * FROM TABLENAME where USER LIKE DREBBEL
|
|
So people please donate to Subsim (as I did) so Neal will keep all my wonderful posts in the database !
_________________
Drebbel
<a href="http://www.DutchSubmarines.com" target="_new">www.DutchSubmarines.com</a>
The Submarines of the Royal Netherlands Navy

 
|
|