Best Practices are -
1. Number of Physical tempdb files = number of processors
2. All tempdb files should have same initial size and unrestricted growth.
More best practices -
http://msdn.microsoft.com/en-us/library/ms175527.aspx
Syntax to add -
ALTER DATABASE tempdb
ADD FILE
(
NAME = tempdev5,
FILENAME = 'F:\SQLDatabases\tempdb\tempdev5.ndf',
SIZE = 14000MB,
MAXSIZE = UNLIMITED,
FILEGROWTH = 100MB
),
(
NAME = tempdev6,
FILENAME = 'F:\SQLDatabases\tempdb\tempdev6.ndf',
SIZE = 14000MB,
MAXSIZE = UNLIMITED,
FILEGROWTH = 100MB
),
(
NAME = tempdev7,
FILENAME = 'F:\SQLDatabases\tempdb\tempdev7.ndf',
SIZE = 14000MB,
MAXSIZE = UNLIMITED,
FILEGROWTH = 100MB
)
GO
Tuesday, December 23, 2008
Friday, December 19, 2008
Getting Performance Metrics
To get the information on File level fragmentation - Use following commands
Following command will analyze the file level fragmentation -
Defrag -a
Same defrag command can be used to defragment files.
To find missing statistics run below query - SELECT O.name AS [table name], I.rowmodctr AS [Rows Modified] FROM SYSOBJECTS o JOIN SYSINDEXES I ON O.id = I.id WHERE I.rowmodctr > 0 and O.xtype = 'U' ORDER BY I.rowmodctr DESC
Following the query to get report for Index defrag scan percentage from 10 to 99% for various indexes.
use
GO
Select [Object_id] AS ObjectId,
index_id AS IndexId,
avg_fragmentation_in_percent AS FragPercent,
partition_number AS PartitionNumber,
index_type_desc AS IndexType,
alloc_unit_type_desc AS AllocUnitType,
0 AS Online
FROM sys.dm_db_index_physical_stats (db_id(''), NULL, NULL, NULL, 'LIMITED')
WHERE
avg_fragmentation_in_percent > 10.0 AND
index_id > 0 and page_count > 32
ORDER BY ObjectId
Following command will analyze the file level fragmentation -
Defrag -a
Same defrag command can be used to defragment files.
To find missing statistics run below query - SELECT O.name AS [table name], I.rowmodctr AS [Rows Modified] FROM SYSOBJECTS o JOIN SYSINDEXES I ON O.id = I.id WHERE I.rowmodctr > 0 and O.xtype = 'U' ORDER BY I.rowmodctr DESC
Following the query to get report for Index defrag scan percentage from 10 to 99% for various indexes.
use
GO
Select [Object_id] AS ObjectId,
index_id AS IndexId,
avg_fragmentation_in_percent AS FragPercent,
partition_number AS PartitionNumber,
index_type_desc AS IndexType,
alloc_unit_type_desc AS AllocUnitType,
0 AS Online
FROM sys.dm_db_index_physical_stats (db_id(''), NULL, NULL, NULL, 'LIMITED')
WHERE
avg_fragmentation_in_percent > 10.0 AND
index_id > 0 and page_count > 32
ORDER BY ObjectId
Tuesday, February 12, 2008
Tuesday, February 5, 2008
Restore Job Fails in SQL Server 2005 with error 3159
Error MesaThe tail of the log for the database "%ls" has not been backed up. Use BACKUP LOG WITH NORECOVERY to back up the log if it contains work that you do not want to lose. Use the WITH REPLACE or WITH STOPAT clause of the RESTORE statement to just overwrite the contents of the log.
Here the scenario was , we were robo copying the database from other server to local drive and restoring the existing database
Step leading for failure:
EXEC master.dbo.xp_restore_database @database='ABCD', @filename = 'E:\MSSQL\Bak\ABCD.sls'
Step replaced to trouble shoot it
EXEC master.dbo.xp_restore_database @database='ABCD', @filename = 'E:\MSSQL\Bak\ABCD.sls'
@with='MOVE "ABCD_DATA" TO "H:\MSSQL\Data\ABCD.mdf"', @with='MOVE "Configuration_LOG" TO "O:\MSSQL\Data\ABCD.ldf"',@with = 'REPLACE'
Explaination: In most cases, under the full or bulk-logged recovery models, SQL Server 2005 requires that you back up the tail of the log to capture the log records that have not yet been backed up. A log backup taken of the tail of the log just before a restore operation is called a tail-log backup.
When you are recovering a database to the point of a failure, the tail-log backup is the last backup of interest in the recovery plan. If you cannot back up the tail of the log, you can recover a database only to the end of the last backup that was created before the failure.
SQL Server 2005 usually requires that you take a tail-log backup before you start to restore a database. The tail-log backup prevents work loss and keeps the log chain intact. However, not all restore scenarios require a tail-log backup. You do not have to have a tail-log backup if the recovery point is included in an earlier log backup, or if you are moving or replacing (overwriting) the database. Also, if the log files are damaged and a tail-log backup cannot be created, you must restore the database without using a tail-log backup. Any transactions committed after the latest log backup are lost
Here the scenario was , we were robo copying the database from other server to local drive and restoring the existing database
Step leading for failure:
EXEC master.dbo.xp_restore_database @database='ABCD', @filename = 'E:\MSSQL\Bak\ABCD.sls'
Step replaced to trouble shoot it
EXEC master.dbo.xp_restore_database @database='ABCD', @filename = 'E:\MSSQL\Bak\ABCD.sls'
@with='MOVE "ABCD_DATA" TO "H:\MSSQL\Data\ABCD.mdf"', @with='MOVE "Configuration_LOG" TO "O:\MSSQL\Data\ABCD.ldf"',@with = 'REPLACE'
Explaination: In most cases, under the full or bulk-logged recovery models, SQL Server 2005 requires that you back up the tail of the log to capture the log records that have not yet been backed up. A log backup taken of the tail of the log just before a restore operation is called a tail-log backup.
When you are recovering a database to the point of a failure, the tail-log backup is the last backup of interest in the recovery plan. If you cannot back up the tail of the log, you can recover a database only to the end of the last backup that was created before the failure.
SQL Server 2005 usually requires that you take a tail-log backup before you start to restore a database. The tail-log backup prevents work loss and keeps the log chain intact. However, not all restore scenarios require a tail-log backup. You do not have to have a tail-log backup if the recovery point is included in an earlier log backup, or if you are moving or replacing (overwriting) the database. Also, if the log files are damaged and a tail-log backup cannot be created, you must restore the database without using a tail-log backup. Any transactions committed after the latest log backup are lost
Sunday, March 11, 2007
Installing SQL Server 2005
SQL Server includes 5 editions
1. Enterprise edition
2. Standard edition
3.Develeoper edition
4.workgroup edition
5.express edition
1. Enterprise edition has no limitations and has all features and functionality
2. Develeoper edition has no limitations and has all features and functionality, but it is not licensed for production
3. Standard edition has all features and functionality suited for larger data set, but it is limited in the no of nodes(4 processors) it supports for clustering as well as in its capability to use system resources , online indexing, fast recovery, indexing views, online restores and data processing.
4.workgroup edition does not include the features and functionality needed to operate large databases and is restricted in capacity(2 processors) to support mid-size and large companies
5. Express edition is used for small application-installed databases that need to be distributed free of charge. It is not suited for organization-wide databases.
1. Enterprise edition
2. Standard edition
3.Develeoper edition
4.workgroup edition
5.express edition
1. Enterprise edition has no limitations and has all features and functionality
2. Develeoper edition has no limitations and has all features and functionality, but it is not licensed for production
3. Standard edition has all features and functionality suited for larger data set, but it is limited in the no of nodes(4 processors) it supports for clustering as well as in its capability to use system resources , online indexing, fast recovery, indexing views, online restores and data processing.
4.workgroup edition does not include the features and functionality needed to operate large databases and is restricted in capacity(2 processors) to support mid-size and large companies
5. Express edition is used for small application-installed databases that need to be distributed free of charge. It is not suited for organization-wide databases.
Saturday, January 6, 2007
A,B,C's of Database
A very simple term to be defined, includes set of tables, stored procedures, views that pertain to particular grouping of data stored in database's tables.
when you first load SQL Server, you will start with 4 system databases
1. Master
2. Model
3. MSDB
4. tempdb
Master: The database holds a special set of tables (system tables) that keeps track of the system as a whole.
-> Master includes metadata such as logon accounts, endpoints, linked servers and system configuration settings. Also, master is the database that records the existence of all other databases and the location of those database files and records the initialization information for SQL Server. Therefore, SQL Server cannot start if the master database is unavailable.
-> Datatype info for that instance of SQL Server, Monitoring Info(Like last run, CPU time etc), Logins, Users, etc and etc
Model: The model database is used as the template for all databases created on an instance of SQL Server. Because tempdb is created every time SQL Server is started, the model database must always exist on a SQL Server system.
tempdb: One of the key working areas for our server. whenever you issue a complex or large query that sql server needs to build interim tables to solve, it does so in tempdb, even though you think you are creating in the current database.
MSDB: is where SQL Agent process stores any system tasks. If you schedule backups to run on a database nightly, there is an entry in msdb
Transaction Log:
Changes that were made database will not go to database directly instead they are written serially to transaction log. At the later point in time, database is issued a check point – is at that point changes in the log are propagated to the actual database file
-> Database is in a random access arrangement, which helps in speedy access, while log is serial in future, which allows the things to be tracked in the proper order
Table:
Table is made up of what is called domain data(columns) and entity data(rows). The actual data of database is stored in tables.
Indexes:
An index is an object that exists only within the framework of a particular table or view
Clustered Index: table is physically sorted according to that index, Only one clustered index can be there for a table
Non clustered index: This kind of index points to a value which will let you find the data
Triggers:
Triggers are pieces of logical code that are automatically executed when certain things, such as inserts, updates or delete happens to a table. It is an object that exists only within the framework of the table
Constraints
Confine the data in a table to meet certain conditions
Views
view is a virtual table
There are many things like stored proecedures, which is set of t-sql stmts bundled up into a single logic unit, User defined functions, Users and Roles, Rules, defaaults, User-defined datatypes
when you first load SQL Server, you will start with 4 system databases
1. Master
2. Model
3. MSDB
4. tempdb
Master: The database holds a special set of tables (system tables) that keeps track of the system as a whole.
-> Master includes metadata such as logon accounts, endpoints, linked servers and system configuration settings. Also, master is the database that records the existence of all other databases and the location of those database files and records the initialization information for SQL Server. Therefore, SQL Server cannot start if the master database is unavailable.
-> Datatype info for that instance of SQL Server, Monitoring Info(Like last run, CPU time etc), Logins, Users, etc and etc
Model: The model database is used as the template for all databases created on an instance of SQL Server. Because tempdb is created every time SQL Server is started, the model database must always exist on a SQL Server system.
tempdb: One of the key working areas for our server. whenever you issue a complex or large query that sql server needs to build interim tables to solve, it does so in tempdb, even though you think you are creating in the current database.
MSDB: is where SQL Agent process stores any system tasks. If you schedule backups to run on a database nightly, there is an entry in msdb
Transaction Log:
Changes that were made database will not go to database directly instead they are written serially to transaction log. At the later point in time, database is issued a check point – is at that point changes in the log are propagated to the actual database file
-> Database is in a random access arrangement, which helps in speedy access, while log is serial in future, which allows the things to be tracked in the proper order
Table:
Table is made up of what is called domain data(columns) and entity data(rows). The actual data of database is stored in tables.
Indexes:
An index is an object that exists only within the framework of a particular table or view
Clustered Index: table is physically sorted according to that index, Only one clustered index can be there for a table
Non clustered index: This kind of index points to a value which will let you find the data
Triggers:
Triggers are pieces of logical code that are automatically executed when certain things, such as inserts, updates or delete happens to a table. It is an object that exists only within the framework of the table
Constraints
Confine the data in a table to meet certain conditions
Views
view is a virtual table
There are many things like stored proecedures, which is set of t-sql stmts bundled up into a single logic unit, User defined functions, Users and Roles, Rules, defaaults, User-defined datatypes
Subscribe to:
Posts (Atom)