create database test
on
(
name = 'test_data',
filename = 'D:\Data\test.mdf',
size = 2,
maxsize = unlimited,
filegrowth = 10%
)
log on
(
name = 'test_log',
filename = 'E:\Log\test.ldf',
size = 1,
maxsize = unlimited,
filegrowth = 10
)
alter database test set recovery simple
alter database test set recovery bulk_logged
use test
create table t1 (c int)
backup database test to disk = 'F:\testfull2.bak' with init
backup database test to disk = 'F:\testdiff2.bak' with differential,init
backup log test to disk = 'F:\testlog3.bak'
insert t1 select 1
insert t1 select 2
select * from t1
restore headeronly from disk = 'F:\testdiff1.bak'
restore headeronly from disk = 'F:\testdiff2.bak'
restore headeronly from disk = 'F:\testfull1.bak'
restore headeronly from disk = 'F:\testfull2.bak'
restore headeronly from disk = 'F:\testlog1.bak'
restore headeronly from disk = 'F:\testlog2.bak'
restore headeronly from disk = 'F:\testlog3.bak'
drop database test
use master
restore database test from disk = 'F:\testfull2.bak' with norecovery
move 'test_data' to 'F:\Data\test_data.mdf',
move 'test_log' to 'F:\Log\test_log.ldf'
restore database test from disk = 'F:\testdiff2.bak' with norecovery
sp_helpdb test
restore log test from disk = 'F:\testlog3.bak' with norecovery
restore database test with recovery
drop database test
select * from t1
sp_detach_db test
create database test on (filename = 'F:\Data\test_data.mdf') log on (filename = 'F:\Log\test_log.ldf') for attach
Saturday, January 16, 2010
Friday, January 15, 2010
Activity views
select * from sys.dm_exec_connections
select * from sys.dm_exec_sessions
select * from sys.dm_exec_requests
select * from sys.dm_exec_sessions
select * from sys.dm_exec_requests
More on Backups
Full backup results in:
1. Backs up any activity that took place during the backup
2. Backs up any uncommitted transactions in the transaction log. (When the database is recovered from this backup, the uncommitted transactions are rolled back.)
Transaction log backup results in:
1. Backs up the log from the last successful [Backup Log] statement to the end of the current log.
2. Truncates the log up to the beginning of the active portion of the log and discards the information in the inactive portion.
Active portion of the transaction log starts at the point of the oldest open transaction and continues to the end of the log.
A Tail log backup includes the portion of the log that has not been backed up (active portion) - this backup does not truncate the log and is used when the data files are damaged but the log is undamaged.
Differential backup results in:
1. Backs up the parts of the database that have changed since the last full database backup.
2. Backs up only the extents that changed since the last base backup.
3. Backs up the activity that took place during the differential backup and any uncommitted transactions as well - this is similar to full backup.
1. Backs up any activity that took place during the backup
2. Backs up any uncommitted transactions in the transaction log. (When the database is recovered from this backup, the uncommitted transactions are rolled back.)
Transaction log backup results in:
1. Backs up the log from the last successful [Backup Log] statement to the end of the current log.
2. Truncates the log up to the beginning of the active portion of the log and discards the information in the inactive portion.
Active portion of the transaction log starts at the point of the oldest open transaction and continues to the end of the log.
A Tail log backup includes the portion of the log that has not been backed up (active portion) - this backup does not truncate the log and is used when the data files are damaged but the log is undamaged.
Differential backup results in:
1. Backs up the parts of the database that have changed since the last full database backup.
2. Backs up only the extents that changed since the last base backup.
3. Backs up the activity that took place during the differential backup and any uncommitted transactions as well - this is similar to full backup.
Simplifying Database Mail
Easy steps to configure this:
1. Add the SQL Server Agent service account to the msdb users and then to the DatabaseMailUserRole.
2. Configure the Database Mail to create a default SQL Mail profile - keeping 'Anonymous Authentication' for the SMTP account.
3, Map this SMTP profile to the SQL Server Agent - Properties -> Alert System.
4. Restart Agent.
1. Add the SQL Server Agent service account to the msdb users and then to the DatabaseMailUserRole.
2. Configure the Database Mail to create a default SQL Mail profile - keeping 'Anonymous Authentication' for the SMTP account.
3, Map this SMTP profile to the SQL Server Agent - Properties -> Alert System.
4. Restart Agent.
Saturday, January 9, 2010
Tail log
In most cases, under the full or bulk-logged recovery models, SQL Server 2005 and later versions require 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.
SQL Server 2005 and later versions usually require 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. 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.
Not all restore scenarios require a tail-log backup. You do not have to have a tail-log backup if the recovery point is contained in an earlier log backup, or if you are moving or replacing (overwriting) the database and do not need to restore it to a point of time after the most recent backup. 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.
If the database is online, before starting a restore sequence, back up the tail of the log using WITH NORECOVERY whenever the next action you plan to perform on the database is a restore operation:
BACKUP LOG database_name TO WITH NORECOVERY
If the database is offline and does not start.
Try to take a tail-log backup. Because no transactions can occur at this time, using WITH NORECOVERY is optional. If the database is damaged, use either WITH CONTINUE_AFTER_ERROR or WITH NO_TRUNCATE.
BACKUP LOG database_name TO [WITH { CONTINUE_AFTER_ERROR | NO_TRUNCATE }
SQL Server 2005 and later versions usually require 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. 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.
Not all restore scenarios require a tail-log backup. You do not have to have a tail-log backup if the recovery point is contained in an earlier log backup, or if you are moving or replacing (overwriting) the database and do not need to restore it to a point of time after the most recent backup. 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.
If the database is online, before starting a restore sequence, back up the tail of the log using WITH NORECOVERY whenever the next action you plan to perform on the database is a restore operation:
BACKUP LOG database_name TO
If the database is offline and does not start.
Try to take a tail-log backup. Because no transactions can occur at this time, using WITH NORECOVERY is optional. If the database is damaged, use either WITH CONTINUE_AFTER_ERROR or WITH NO_TRUNCATE.
BACKUP LOG database_name TO
Thursday, May 28, 2009
Grant Alter.....
There are two commands quite similar:
Grant Alter to User1
Grant Alter on Table1 to User1
Grant Alter allows User1 to make any change - modify, create and drop - to the current database whereas Grant Alter On Table limits the privilege to just change the schema of Table1 - User1, however, cannot drop the table in the latter.
Grant Alter to User1
Grant Alter on Table1 to User1
Grant Alter allows User1 to make any change - modify, create and drop - to the current database whereas Grant Alter On Table limits the privilege to just change the schema of Table1 - User1, however, cannot drop the table in the latter.
Tuesday, April 29, 2008
Mirroring notes...
In database mirroring, an originating SQL Server 2005 instance continuously sends a database's transaction log records to a copy of the database on another standby SQL Server instance.
The originating database and server have the role of principal, and the receiving database and server have the role of mirror.
The principal and mirror servers must be separate instances of SQL Server 2005.
Some important items to note about database mirroring:
• The principal database must be in the FULL recovery model. Log records that result from bulk-logged operations cannot be sent to the mirror database.
• The mirror database must be initialized from a restore of the principal database with NORECOVERY, followed by restores in sequence of principal transaction log backups.
• The mirror database must have the same name as the principal database.
• Because the mirror database is in a recovering state, it cannot be accessed directly. You can create database snapshots on the mirror to indirectly read the mirror database at a point in time.
Transaction Safety
If transaction safety is set to FULL, the principal and mirror servers operate in a synchronous transfer mode. As the principal server hardens its principal database log records to disk, it also sends them to the mirror. The principal then waits for a response from the mirror server. The mirror responds when it has hardened those same log records to the mirror's log disk. When safety is set OFF, the principal does not wait for acknowledgment from the mirror, and so the principal and mirror may not be fully synchronized (that is, the mirror may not quite keep up with the principal).
Synchronous transfer guarantees that all transactions in the mirror database's transaction log will be synchronized with the principal database's transaction log, and so the transactions are considered safely transferred. You set safety to FULL using
ALTER DATABASE [dbname] SET SAFETY FULL;
When safety is set to OFF, the communication between the principal and the mirror is asynchronous. The principal server will not wait for an acknowledgment from the mirror that the mirror has hardened a block of transaction records. The mirror will attempt to keep up with the principal, by recording transactions as quickly as possible, but some transactions may be lost if the principal suddenly fails and you force the mirror into service.

to get a list of all endpoints along with Port numbers
Select * from sys.tcp_endpoints
To get info about the state of mirroring....includes the lsn for failover..should be same as that in the mirror for failover with out data loss.
select * from sys.database_mirroring
Manually force a failover
ALTER DATABASE demo SET PARTNER FAILOVER
at the principal
Check the mirror failover lsn before doing this so as to ensure there is no data loss.
High Availability Mode
It requires that you set safety to FULL and define a witness server as part of the database mirroring session.
The High Availability mode is best used where you have fast and very reliable communication paths between the servers and you require automatic failover for a single database.
High Protection
The High Protection operating mode also has transactional safety FULL, but has no witness server as part of the mirroring session. The principal database does not need to form a quorum to serve the database. In this mode only a manual failover is possible, because there is no witness to fill the tie-breaker role.
High Performance
In the High Performance operating mode, transactional safety is OFF, and the transfer of log records is asynchronous. The principal server does not wait for an acknowledgement from the mirror that all transaction log records have been recorded on the mirror.
Manual failover is not enabled for the High Performance mode. The only type of failover allowed is forced service failover, which is also a manual operation:
ALTER DATABASE dbname SET PARTNER FORCE_SERVICE_ALLOW_DATA_LOSS
SQL Express and the Workgroup Edition can be used as a witness server, but they cannot be used as a partner server in database mirroring.
Principal Server States
When safety is FULL, the normal operating state for the principal database is the SYNCHRONIZED state. When safety is OFF, the normal operating state for the principal database starts as the SYNCHRONZING state. Once the mirror has caught up, the state goes to SYNCHRONIZED and stays there regardless of how far behind it is.
• If safety is FULL, the principal database always starts off in the SYNCHRONIZING state, and transitions to the SYNCHRONIZED state when the principal and mirror transactions logs are synchronized.
• If safety is FULL and the principal server is disconnected from the witness server but can still process transactions, the database is exposed.
Principal Database states with a witness set and with safety FULL and safety OFF

Principal Database states with no witness set and with safety FULL and safety OFF

For both safety settings, if the session is paused or there are redo errors on the mirror, the principal enters the SUSPENDED state. If the mirror becomes unavailable, the principal will enter the DISCONNECTED state.
In the DISCONNECTED and SUSPENDED states:
• When a witness has been set, if the principal can form a quorum with the witness or mirror server, the principal database is considered exposed. That means the principal database is active with user connections and processing transactions. However, no log records are being sent to the mirror database, and if the principal should fail, the mirror will not have any of the transactions from the principal from the point the principal entered that state. Also, the principal's transaction log cannot be truncated, so the log file will be growing indefinitely.
• When a witness has been set, if the principal cannot form a quorum with another server, it cannot serve the database. All users will be disconnected and no new transactions will be processed.
• When safety is OFF, the principal database is considered exposed, because no transaction log records are being sent to the mirror.
Mirror Server Database States

Witness Server States
The originating database and server have the role of principal, and the receiving database and server have the role of mirror.
The principal and mirror servers must be separate instances of SQL Server 2005.
Some important items to note about database mirroring:
• The principal database must be in the FULL recovery model. Log records that result from bulk-logged operations cannot be sent to the mirror database.
• The mirror database must be initialized from a restore of the principal database with NORECOVERY, followed by restores in sequence of principal transaction log backups.
• The mirror database must have the same name as the principal database.
• Because the mirror database is in a recovering state, it cannot be accessed directly. You can create database snapshots on the mirror to indirectly read the mirror database at a point in time.
Transaction Safety
If transaction safety is set to FULL, the principal and mirror servers operate in a synchronous transfer mode. As the principal server hardens its principal database log records to disk, it also sends them to the mirror. The principal then waits for a response from the mirror server. The mirror responds when it has hardened those same log records to the mirror's log disk. When safety is set OFF, the principal does not wait for acknowledgment from the mirror, and so the principal and mirror may not be fully synchronized (that is, the mirror may not quite keep up with the principal).
Synchronous transfer guarantees that all transactions in the mirror database's transaction log will be synchronized with the principal database's transaction log, and so the transactions are considered safely transferred. You set safety to FULL using
ALTER DATABASE [dbname] SET SAFETY FULL;
When safety is set to OFF, the communication between the principal and the mirror is asynchronous. The principal server will not wait for an acknowledgment from the mirror that the mirror has hardened a block of transaction records. The mirror will attempt to keep up with the principal, by recording transactions as quickly as possible, but some transactions may be lost if the principal suddenly fails and you force the mirror into service.

to get a list of all endpoints along with Port numbers
Select * from sys.tcp_endpoints
To get info about the state of mirroring....includes the lsn for failover..should be same as that in the mirror for failover with out data loss.
select * from sys.database_mirroring
Manually force a failover
ALTER DATABASE demo SET PARTNER FAILOVER
at the principal
Check the mirror failover lsn before doing this so as to ensure there is no data loss.
High Availability Mode
It requires that you set safety to FULL and define a witness server as part of the database mirroring session.
The High Availability mode is best used where you have fast and very reliable communication paths between the servers and you require automatic failover for a single database.
High Protection
The High Protection operating mode also has transactional safety FULL, but has no witness server as part of the mirroring session. The principal database does not need to form a quorum to serve the database. In this mode only a manual failover is possible, because there is no witness to fill the tie-breaker role.
High Performance
In the High Performance operating mode, transactional safety is OFF, and the transfer of log records is asynchronous. The principal server does not wait for an acknowledgement from the mirror that all transaction log records have been recorded on the mirror.
Manual failover is not enabled for the High Performance mode. The only type of failover allowed is forced service failover, which is also a manual operation:
ALTER DATABASE dbname SET PARTNER FORCE_SERVICE_ALLOW_DATA_LOSS
SQL Express and the Workgroup Edition can be used as a witness server, but they cannot be used as a partner server in database mirroring.
Principal Server States
When safety is FULL, the normal operating state for the principal database is the SYNCHRONIZED state. When safety is OFF, the normal operating state for the principal database starts as the SYNCHRONZING state. Once the mirror has caught up, the state goes to SYNCHRONIZED and stays there regardless of how far behind it is.
• If safety is FULL, the principal database always starts off in the SYNCHRONIZING state, and transitions to the SYNCHRONIZED state when the principal and mirror transactions logs are synchronized.
• If safety is FULL and the principal server is disconnected from the witness server but can still process transactions, the database is exposed.
Principal Database states with a witness set and with safety FULL and safety OFF

Principal Database states with no witness set and with safety FULL and safety OFF

For both safety settings, if the session is paused or there are redo errors on the mirror, the principal enters the SUSPENDED state. If the mirror becomes unavailable, the principal will enter the DISCONNECTED state.
In the DISCONNECTED and SUSPENDED states:
• When a witness has been set, if the principal can form a quorum with the witness or mirror server, the principal database is considered exposed. That means the principal database is active with user connections and processing transactions. However, no log records are being sent to the mirror database, and if the principal should fail, the mirror will not have any of the transactions from the principal from the point the principal entered that state. Also, the principal's transaction log cannot be truncated, so the log file will be growing indefinitely.
• When a witness has been set, if the principal cannot form a quorum with another server, it cannot serve the database. All users will be disconnected and no new transactions will be processed.
• When safety is OFF, the principal database is considered exposed, because no transaction log records are being sent to the mirror.
Mirror Server Database States

Witness Server States
Subscribe to:
Posts (Atom)