Tuesday, 16 May 2017

Job failed due to No global profile is configured. Specify a profile name in the @profile_name parameter


To day there is job failed in one of the our server.

Below is the error:

No global profile is configured. Specify a profile name in the @profile_name parameter

Work around:-

We verified the profile name and default setting using below query. Profile is not set default that is the reason it got failed.


EXEC msdb.dbo.sysmail_help_principalprofile_sp;
Return Code Values

0 (success) or 1 (failure)

is _default -The flag that states whether the profile is the default profile for the user.

Solution:

1. Login into the serve
2. Open run and type SQLWB\SSMS
3. Connect to server
4. Go to maintenance tab
5. Select the Database Mail
6. Right click Database Mail and start the wizard
7. Click on next
8. Select the manage profile security
9. Click on next
10. Go to the Default profile and select Yes
11. Click on next button
12. Click on finish
13. Click on close

Then reran the job it was successfully completed with out errors.

Screen shots:

























Thursday, 11 May 2017

How to Eliminate all successful backups messages in SQL server error log

We have got a one request in my organization To Eliminate the all successful backup's messages only from SQL server error log,use below trace flag.
-T3226


Normally Sql server error log contain all the information about how the sql server is running, what is happening and occurring on your database, its normally the first place you look at when you have any issue of the database. Keeping it small and as useful as it can be helps a lot when it comes to troubleshooting, since you don’t have to scan through hundreds of lines of useless information and locate the issue you might be having. Keeping it recycle on a regular interval is a good practice and should be set as default for easier maintenance.

If you have many databases within a single instance and/or have frequent backup mean that you will have all the successful backup entries written to SQL error log and makes the file grow large (and fast). If you do not have any scripts or monitoring that requires the successful backup entry in error log, it would be recommended to turn on trace flag 3226 to suppress all successful backups entries. It will, however, still write out the error entry if backup is unsuccessful, and all successful entry are still logged in msdb database.

Manually How to implement:

To manually turn on this trace flag globally, you can use the below code:

DBCC TRACEON (3226, -1)

To turn this trace off, you can just below query execute:

DBCC TRACEOFF (3226)


To see the what traces are enable globally use Trace status command:

DBCC TRACESTATUS(-1)

As above setup is a manual setup, it will not effect after service restart, to keep this setting effective after restart please use through startup parameter option.

Globally how to enable trace flag:

Step-1: Open sql server configuration manager through run command or startup programs
Step-2: After sql server configuration manager open select the sql server service in left pane
Step-3: In right pane select and right on MSSQLSERVER service
Step-4: click on ok properties sql server process
Step-5: Go to the advanced startup parameter tab
Step-6: Enter and add the below trace flag
-T 3226
Step-7: Apply and Click on OK, ok
Step-8: Restart the sql services.
Step-9: After restart connect to instance and open new query analyzer run below command to verify the trace flag whether enable or not.

DBCC TRACESTATUS(-1)

Or
use master
go
exec xp_readerrorlog 0, 1, 'lock'

Screen shots for above steps:


Lab test:

Let try to run this and see what happens, we are testing manual setup method mentioned above.

BACKUP DATABASE DBA_test TO DISK = 'D:\DBA_test.bak'
GO
DBCC TRACEON (3226, -1)

BACKUP DATABASE DBA_test TO DISK = 'D:\DBA_test.bak'
GO
DBCC TRACEOFF (3226, -1)

BACKUP DATABASE DBA_test TO DISK = 'D:\DBA_test.bak'
GO
--wanted make the backup fail

DBCC TRACEON (3226, -1)

BACKUP DATABASE DBA_test TO DISK = 'D:\MSSQL\DBA_test.bak'
GO
DBCC TRACEOFF (3226, -1)

From the code above, we will firstly backup the test database, enable the trace flag and perform the backup again, turn the trace flag off and perform the backup the third time. After its done, we will turn on the trace flag and wanted perform a failure backup. What we are expecting is that we should see the backup entry from the first try, nothing from the second and an entry for the third. The reason for the last part is to ensure that even if we have the trace flag on, we will still get failure backup entry in error log. Let check the result:




The above result in screen shot match's what we are expecting. we can conclude is that if you are not depending on the successful backup entry in SQL error log, you can enable this trace flag to minimize the number of entries in it.

T-SQL Script, It returns all Backups history information:

Using this script, you can find different types of information like Backup media, Type of Backup, Taken Duration.
 BOL
T-SQL Script, It returns all Backups history information:

SELECT
       bs.server_name AS ServerName,
       bs.database_name AS DatabaseName
       ,CASE bs.type
              WHEN 'D' THEN 'Full'
              WHEN 'I' THEN 'Differential'
              WHEN 'L' THEN 'Transaction Log'
       END AS BackupType
       ,CAST(DATEDIFF
              (SECOND,bs.backup_start_date,bs.backup_finish_date)
              AS VARCHAR(4)) + ' ' + 'Seconds' AS TotalTimeTaken
       ,bs.backup_start_date AS BackupStartDate
       ,CAST(bs.first_lsn AS VARCHAR(50)) AS FirstLSN
       ,CAST(bs.last_lsn AS VARCHAR(50)) AS LastLSN
       ,bmf.physical_device_name AS PhysicalDeviceName
       ,CAST(CAST(bs.backup_size / 1000000 AS INT) AS VARCHAR(14))
              + ' ' + 'MB' AS BackupSize
       ,bs.recovery_model AS RecoveryModel
FROM msdb.dbo.backupset AS bs
INNER JOIN msdb.dbo.backupmediafamily AS bmf
       ON bs.media_set_id = bmf.media_set_id
WHERE bs.database_name = 'master'
ORDER BY
       backup_start_date DESC

       ,backup_finish_date

How to refresh a database backup from source (prod server) to target(destination\non prod) server


The below process is How to refresh a database backup from source (prod server) to target(destination\non prod) server

1. Check For Calendar entry is there or Ad-hoc request.
2. Before starting anything gather all the details like Prod and Non Prod environment details(Confirm Source & Target\Destination Databases and Source & Destination\Target server names) used by application.
3. Check for the Current SQL version. (Source and  Target)
4. Login to the Source server and see where are all the DB files(Data&Log) are kept using below query.
 use master
go
sp_helpdb <Your database name>

5. To check the backup path, size etc.. use below script (Note: Need to run on source server) and Back up files Availability in Local\Network shared Servers

use master
go
--T-SQL Script to Check the Native Compressed backup file size and Backup Compression Ratio, backup type, size, time
Declare @FromDate as datetime
-- Specify the from date value
set @FromDate = GETDATE() -1

SELECT
   CONVERT(CHAR(100), SERVERPROPERTY('Servername')) AS SQLServerName,
   msdb.dbo.backupset.database_name, 
   CASE msdb..backupset.type 
       WHEN 'D' THEN 'Database-Full'
       WHEN 'L' THEN 'Log'
       WHEN 'I' THEN 'Differential'
   END AS backup_type, 
   msdb.dbo.backupset.backup_start_date, 
   msdb.dbo.backupset.backup_finish_date,
   msdb.dbo.backupmediafamily.physical_device_name,
   msdb.dbo.backupset.backup_size, 
   msdb.dbo.backupset.expiration_date,
   DATEDIFF (SECOND, msdb.dbo.backupset.backup_start_date, msdb.dbo.backupset.backup_finish_date) 'Backup Elapsed Time (sec)',
   msdb.dbo.backupset.compressed_backup_size AS 'Compressed Backup Size in KB',
  (msdb.dbo.backupset.compressed_backup_size/1024/1024) AS 'Compress Backup Size in MB',
   CONVERT (NUMERIC (20,3), (CONVERT (FLOAT, msdb.dbo.backupset.backup_size) /CONVERT (FLOAT, msdb.dbo.backupset.compressed_backup_size))) 'Compression Ratio',
   CASE msdb..backupset.type 
       WHEN 'D' THEN 'Database'
       WHEN 'L' THEN 'Log'
   END AS backup_type, 
    
   msdb.dbo.backupmediafamily.logical_device_name, 
   msdb.dbo.backupset.name AS backupset_name,
   msdb.dbo.backupset.description
FROM   msdb.dbo.backupmediafamily 
   INNER JOIN msdb.dbo.backupset ON msdb.dbo.backupmediafamily.media_set_id = msdb.dbo.backupset.media_set_id
WHERE
CONVERT(datetime, msdb.dbo.backupset.backup_start_date, 102) >= @FromDate
AND msdb.dbo.backupset.backup_size > 0
ORDER BY
   msdb.dbo.backupset.database_name,
   msdb.dbo.backupset.backup_finish_date

Verify the backup are valid or not using below commands.

Check a backup file on disk
The following command will check the backup file and return a message of whether the file is valid or not. If it is not valid, this means the file is not going to be useable for a restore and a new backup should be taken. One thing to note is that if there are multiple backups in a file, this only checks the first file.

RESTORE VERIFYONLY FROM DISK = C:\AdventureWorks.BAK
GO

Check a backup file on disk for a particular backup
This command will check the second backup in this backup file. To check the contents in a backup you can use RESTORE HEADERONLY and use the Position column to specify the FILE number.

RESTORE VERIFYONLY FROM DISK = C:\AdventureWorks.BAK WITH FILE = 2
GO
6. Do Space Projection[Prep Work involves]

a)      Use below query to get the database data&log files size along with physical name(path of the data&log files).

SELECT        DB_NAME(database_id) AS DatabaseName,
                            Name AS Logical_Name,
                            Physical_Name,
(size*8)/1024 SizeMB,
                            (size*8)/1024/1024 SizeGB
              FROM          sys.master_files
              WHERE         DB_NAME(database_id) = 'DBA_test'

Capture the results from the ablove query and save it excel file for cross verification in non pord(Target) server.

7. Space Requirement in Data file Drives in non prod:-Now you have to login into the Target\Destination server->verify the database data&log files are in which drives(use step 4 query) then compare the source database data&log files  sizes with prod&non prod, if enough space is available in target\Destination server you can proceed with refresh activity or else verify any un used files(if here clean it), try to shrink if any other db data\log files if still no luck please raise a request to respective(storage\Vm\window) team through change request(CR-ITIL process).

Once all the above things are in handy we have to start the activity as per the schedule\whenever activity start.
1.       Inform to application team to bring down the a Application, wait Until the Environment is down(Once got the confirmation from application\respective team).
2.       Once confirmation receives follow the below steps

Check for the active connection .

use master
go
select a.* from master..sysprocesses a,
master..sysdatabases b where a.dbid=b.dbid and b.name='your database name'
go

If there is any, kill it using the session id.
Note: If active connection is coming up again and again, first verify with the application team and then kill based on confirmation.

Kill <session_id>

Remove replication\if any high availability options. Replication is used to sync different databases.
After removing the replication\ all high availability option and no active connections on target server, start the restoration activity.

If only full backup having use below query

--Restore a full backup
RESTORE DATABASE AdventureWorks FROM DISK = 'C:\AdventureWorks.BAK'
GO

If you have full backup along with diff and transactional backups please follow the below steps.

Restore a full backup allowing additional restores such as a differential or transaction log backup (NORECOVERY)

RESTORE DATABASE AdventureWorks FROM DISK = 'C:\AdventureWorks.BAK' WITH NORECOVERY
GO

Restore a differential backup

RESTORE DATABASE AdventureWorks FROM DISK = 'C:\AdventureWorks.dif' WITH NORECOVERY
GO

Restore using a backup file that has multiple backups

RESTORE LOG AdventureWorks FROM DISK = 'C:\AdventureWorks.TRN'
GO

If you have multiple transactional backups please use below quires.

RESTORE LOG AdventureWorks FROM DISK = 'C:\AdventureWorks_1.TRN' WITH NORECOVERY
GO
RESTORE LOG AdventureWorks FROM DISK = 'C:\AdventureWorks_2.TRN'
GO

Below query is to verify the percentage of the restoration.

SELECT  r.session_id [Session Id],
r.command [Command],
CONVERT(NUMERIC(6,2),r.percent_complete) AS [Percent Complete],
CONVERT(VARCHAR(20),DATEADD(ms,r.estimated_completion_time,GetDate()),20) AS [ETA Completion Time],
CONVERT(NUMERIC(10,2),r.total_elapsed_time/1000.0/60.0) AS [Elapsed Min],
CONVERT(NUMERIC(10,2),r.estimated_completion_time/1000.0) AS [ETA Sec],
CONVERT(NUMERIC(10,2),r.estimated_completion_time/1000.0/60.0) AS [ETA Min],
CONVERT(NUMERIC(10,2),r.estimated_completion_time/1000.0/60.0/60.0) AS [ETA Hours],
CONVERT(VARCHAR(1000),(
SELECT  SUBSTRING(text,r.statement_start_offset/2,
CASE
WHEN r.statement_end_offset = -1 THEN 1000
ELSE (r.statement_end_offset-r.statement_start_offset)/2
END
) FROM sys.dm_exec_sql_text(sql_handle))) AS [SQL]
FROM    sys.dm_exec_requests r
WHERE   r.session_id > 50
and     r.session_id <> @@SPID
AND     command IN ('RESTORE DATABASE','BACKUP DATABASE','RESTORE LOG','BACKUP LOG')


Once it is completed fix the orphaned logins\user access to the databases

First, make sure that this will lists the orphaned users:


use yourdatabse --(replace with actual database name)
go
exec sp_change_users_login 'report'

If you already have a login id and password for this user, fix it by doing:
go
exec sp_change_users_login 'auto_fix', 'user'
go

If you want to create a new login id and password for this user, fix it by doing:

EXEC sp_change_users_login 'Auto_Fix', 'user', 'login', 'password'
go



Inform to application team to bring up the application and validation.


Please feel free to correct me by comments. If you like the article, do Like & Share.

Disable CDC at table level

 How to Disable CDC( Change Data Capture) for tables Change Data Capture (cdc) property is disabled as default.  here I will Query you how t...