2014-03-14 71 views
0

我試圖優化radacct表,其中增長到91628239行和增長。我決定削減表中最古老的一部分,並將其放入歸檔db。我需要:切割/優化radacct表(FreeRADIUS)

  1. 保存AUTO_INCREMENT在radacct
  2. 進行切割時,半徑工作
  3. 留下的所有行與活動會話
  4. 移動與閉門會議中所有行存檔分貝radacct

我開始做一個程序,這個

BEGIN 
/** 
clean up radacct table procedure 
*/ 

-- create fresh radacct table same as old radacct and same auto_increment value 
CREATE TABLE db5.radacct_fresh LIKE db5.radacct; 
SELECT @my_auto_increment:=auto_increment FROM information_schema.tables WHERE table_name='radacct' AND table_schema='db5'; 
SET @query = CONCAT("ALTER TABLE db5.radacct_fresh auto_increment = ", @my_auto_increment); 
PREPARE stmt FROM @query; 
EXECUTE stmt; 
DEALLOCATE PREPARE stmt; 

-- copy active sessions to fresh table 
INSERT INTO radacct_fresh SELECT * FROM radacct WHERE acctstoptime IS NULL; 

-- move radacct to db5h 
SET @query = CONCAT('ALTER TABLE db5.radacct RENAME db5h.radacct_', UNIX_TIMESTAMP()); 
PREPARE stmt FROM @query; 
EXECUTE stmt; 
DEALLOCATE PREPARE stmt; 
END 

我無法停止radius服務器來執行此步驟。我怎樣才能順利地完成半徑? 也許我在這個優化中錯誤的方式呢?

UPDATE 這個腳本正在爲我的需求

/* 
clean up radacct table procedure 
*/ 

-- create fresh radacct table same as old radacct and same auto_increment value 
DROP TABLE IF EXISTS db5.radacct_fresh; 
CREATE TABLE db5.radacct_fresh LIKE db5.radacct; 

LOCK TABLES db5.radacct WRITE, db5.radacct_fresh WRITE; 
-- make auto_increment same as in radacct 
SELECT @my_auto_increment:=auto_increment FROM information_schema.tables WHERE table_name='radacct' AND table_schema='db5'; 
SET @query = CONCAT("ALTER TABLE db5.radacct_fresh auto_increment = ", @my_auto_increment); 
PREPARE stmt FROM @query; 
EXECUTE stmt; 
DEALLOCATE PREPARE stmt; 

-- copy active sessions to fresh table 
INSERT INTO db5.radacct_fresh SELECT * FROM radacct WHERE acctstoptime IS NULL; 

-- move radacct to db5H 
SET @query = CONCAT('ALTER TABLE db5.radacct RENAME db5H.radacct_', UNIX_TIMESTAMP()); 
PREPARE stmt FROM @query; 
EXECUTE stmt; 
DEALLOCATE PREPARE stmt; 

-- make fresh table as main 
ALTER TABLE db5.radacct_fresh RENAME db5.radacct; 

UNLOCK TABLES; 

UPDATE

我已經收到科目停止時作此方案爲半徑

CREATE DEFINER=`root`@`%` PROCEDURE `archive_radacct`(AST int(11), ASEST int(12), AINOCT bigint(20), AOUTOCT bigint(20), ATERMC varchar(32), ASTD int(12), CIS varchar(50), ASESID varchar(32), UN varchar(64), NASIP int(11)) 
BEGIN 
UPDATE db5.radacct SET 
acctstoptime = AST, 
acctsessiontime = ASEST, 
acctinputoctets = AINOCT, 
acctoutputoctets =AOUTOCT, 
acctterminatecause =ATERMC, 
acctstopdelay =ASTD, 
connectinfo_stop = CIS 
WHERE acctsessionid = ASESID 
AND username = UN 
AND nasipaddress = NASIP; 

DELETE FROM db5.radacct WHERE 
acctsessionid = ASESID 
AND username = UN 
AND nasipaddress = NASIP; 
END 
CREATE TRIGGER archive_radacct_row BEFOR DELETE ON db5.radacct FOR EACH ROW BEGIN 
INSERT INTO db5H.radacct SELECT * FROM db5.radacct WHERE radacctid = OLD.radacctid 
END 

半徑CALL存檔radacct。我正在我的一臺生產半徑服務器上測試這個方案。我試圖找出DB是更重的負載。

回答

0

更好的方法是更新觸發器,將acctstoptime設置爲非NULL值,將受影響的行移動到歷史表。

然後FreeRADIUS繼續使用活動表中的一組行。

+0

觸發器更新在這種情況下不起作用。當你試圖從活動表中刪除行時,它會給出錯誤。 –