Post Pacific  

Go Back   Post Pacific > Lineage 2 > Lineage 2 Stickies

Notices

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
Old 11.10.2006, 13:00   #14
Drag
Архивный участник
 
Join Date: Mar 2006
Posts: 241
Default Optimize Database

Credits to Shawnmb.

Defragment
Code:
DECLARE Tables CURSOR FOR
SELECT DISTINCT
    OBJECT_NAME([id]),
    [name]
FROM dbo.sysindexes
WHERE OBJECTPROPERTY([id], 'IsUserTable') = 1

OPEN Tables
DECLARE @database varchar(128)
DECLARE @table varchar(128)
DECLARE @index varchar(128)

SET @database = DB_NAME()

FETCH NEXT FROM Tables INTO @table, @index

WHILE @@FETCH_STATUS = 0
BEGIN
  PRINT 'Reindexing table ' +
        ISNULL(@table, '<NULL>') +
        ' on index ' + ISNULL(@index, '<NULL')

 IF @table IS NOT NULL AND @index IS NOT NULL
 BEGIN
  DBCC INDEXDEFRAG(@database, @table, @index)
 END
 FETCH NEXT FROM Tables INTO @table, @index
END

CLOSE Tables
DEALLOCATE Tables
Reindex
Code:
DECLARE Tables CURSOR FOR
SELECT DISTINCT
  QUOTENAME(TABLE_CATALOG) + '.' + 
    QUOTENAME(TABLE_SCHEMA) + '.' +
    QUOTENAME(TABLE_NAME)
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE = 'BASE TABLE'

OPEN Tables
DECLARE @table varchar(128)

FETCH NEXT FROM Tables INTO @table

WHILE @@FETCH_STATUS = 0
BEGIN
  PRINT 'Reindexing table ' + ISNULL(@table, '<NULL>')
  IF @table IS NOT NULL
    BEGIN
    DBCC DBREINDEX( @table)
  END
  FETCH NEXT FROM Tables INTO @table
END

CLOSE Tables
DEALLOCATE Tables
Next useful things:
- Tab database by right button, Shrink -> Database (lin2db, lin2world, all)
- Set in table preferences 'Simple recovery model'. Just search for it in options

Clear logs
Code:
Backup log lin2world with truncate_only
Go

Use lin2world
DBCC Shrinkfile (lin2world_log, 1)
Go

Backup log lin2db with truncate_only
Go

Use lin2db
DBCC Shrinkfile (lin2db_log, 1)
Go

Thats all about optimizing.

I just writed it in quick way, and removed ' + ' which cause error in reindex

Original Post: https://postpacific.mmorpg-game.onli...read.php?t=930
Drag is offline  
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

Forum Jump


All times are GMT. The time now is 05:40.