Tuesday, April 2, 2013

Facebook Feed is not getting displayed in latest release of Skype - version 6.3

Hi Guys, Yes i know this post is something out of the scope of this blog but still i though to write this as i believe most of us uses Skype for communication, and if you have upgraded to Skype latest version 6.3 then you must have noticed Facebook Feed Disconnection on Skype Home Page which is very annoying.

I tried to dig it a bit deeper and found the reason, but don't be happy i do not have the fix for this :(

When you first connect to Facebook using Skype, it ask for some permission. On of them is Permission to access your data when you are offline which has been Deprecated by Facebook recently.




You might see Facebook wall for a while and suddenly it goes and you left with the prompt to connect to Facebook again :)


If you wish to dig it deeper then Login to Facebook and go to Security Setting -> App Setting click on edit against Skype.


And you will get actual error here:





Guys help me with the solution if you have any? or i hope Microsoft/Skype Team will see my post and soon release a fix for this ;)


Thursday, October 4, 2012

Change the email across all Job alerts using script in SQL Server


As a DBA sometimes we get request for add/update/delete of DL’s – Distribution Lists (email groups) across all jobs on a SQL Server Instances. If the frequency of such request is very frequent then it’s better to write a script and run it on requests by simply modifying the email addresses.

Here is how we will do this:

We will take help of 2 tables  msdb.dbo.sysjobsteps and msdb.dbo.sysjobsteps

Query to retrive the list of jobs along with steps which satisfies the condition to search for an email (Simply update the “your-email-address-here” below and execute the query).

SELECT j.name, js.step_name, js.command FROM msdb.dbo.sysjobsteps js WITH(NOLOCK)
LEFT JOIN msdb.dbo.sysjobs j WITH(NOLOCK)
ON j.job_id = js.job_id  
WHERE js.command  like '%<your-email-address-here>%'



Update the old DL with new:

UPDATE msdb.dbo.sysjobsteps
SET command = REPLACE(command,'<search-email-group>','<new-email-group>')
WHERE command  like '%<your-search-term-here>%'
Wednesday, July 4, 2012

Reset MySQL root password in Windows and UNIX

1.    Shutdown the MySQL Server –

a.    Use windows services to shut down: Start > run > services.msc  > MySQL > right click and select STOP 




b.    Using mysqladmin by running following command in command prompt:

mysqladmin -u root shutdown (make sure to provide the correct path for mysqladmin if it has not been added in windows path)

2.     Start the MySQL Server in safe mode (anonymous login):

         C:\>start mysqld-nt --skip-grant-tables (A black screen will flicker and here you go)




        In UNIX environment u has to use below command:

              mysqld_safe --skip-grant-tables

3.    Now you open the command line and try to connect to the root user with empty password by running below command:

             C:\>Mysql -uroot

4.    when you logged in u will get a prompt as

             mysql>

5.    Now select the MySQL database:

             use mysql;




6.    Update the root password by running this command:

             mysql> update user set Password=PASSWORD('<new-password>') WHERE User='root';



7.    Shutdown the MySQL Server:  (it is very important to stop the server at this stage since it is running in anonymous mode):

              mysqladmin -u root shutdown

8.    Now start server again and can log in with new password.
Thursday, June 7, 2012

Simple script to find the free space in sql server db files (data, log) against all databases

Here is a simple SQL script to retrieve the free spaces on db files (data, log).

The below script will give you the File size, used space and free space of currently selected database only.


select
      name
    , filename
    , convert(decimal(12,2),round(a.size/128.000,2)) as FileSizeMB
    , convert(decimal(12,2),round(fileproperty(a.name,'SpaceUsed')/128.000,2)) as SpaceUsedMB
    , convert(decimal(12,2),round((a.size-fileproperty(a.name,'SpaceUsed'))/128.000,2)) as FreeSpaceMB
    from dbo.sysfiles a


Output:



To retrieve the File size, used space and free space across all databases i have written a script using above query.


-- create a temporary table to insert the above mentioned output against each databases.

create table #db_files(
db_files varchar(300),
file_loc varchar(300),
filesizeMB decimal(9,2),
spaceUsedMB decimal(9,2),
FreespaceMB decimal(9,2))

declare @strSQL nvarchar(2000)
DECLARE @dbName varchar(MAX)
DECLARE @getDBname CURSOR

SET @getDBname = CURSOR FOR
select name from sys.databases

OPEN @getDBname
FETCH NEXT
FROM @getDBname INTO @dbName
WHILE @@FETCH_STATUS = 0
BEGIN
PRINT @dbName

select @strSQL =
    '
        use ' + @dbname + '
        INSERT INTO #db_files
        select
      name
    , filename
    , convert(decimal(12,2),round(a.size/128.000,2)) as FileSizeMB
    , convert(decimal(12,2),round(fileproperty(a.name,''SpaceUsed'')/128.000,2)) as SpaceUsedMB
    , convert(decimal(12,2),round((a.size-fileproperty(a.name,''SpaceUsed''))/128.000,2)) as FreeSpaceMB
    from dbo.sysfiles a
    '
    exec sp_executesql @strSQL

FETCH NEXT
FROM @getDBname INTO @dbName

END
CLOSE @getDBname
DEALLOCATE @getDBname
GO

select * from #db_files
-- drop the temporary table
drop table #db_files




Output:






This script will be helpful for lot of SQL Server DBA's out there.. cheers..  

Tuesday, May 29, 2012

Space Management Report - Get Drive Size and Drive Free Space :SQL Server

One of the regular DBA practice is to maintain the free space on Drives where the data files are located.

Here i have created a script (Space Management) which gives us the database files, its location,size, growth rate, the drive where its located, drive size, drive free space etc...

Most of the thing is very easy to retrieve through SQL Queries as those are maintained in tables under msdb databases, but the free space and size of drive is something which require system interaction using master..xp_cmdshell and that part of query is a bit complex :)



declare @Drive table(DriveName char,freespace decimal(9,2), totalspace decimal(9,2),percentfree decimal(9,2))

BEGIN

    SET NOCOUNT ON;

    DECLARE @v_cmd nvarchar(255)
    ,@v_drive char(99)
    ,@v_sql nvarchar(255)
    ,@i int

    SELECT @v_cmd = 'fsutil volume diskfree %d%'
    SET @i = 1

    -- Creating temporary tables to retrive system space information.
    CREATE TABLE #drives(iddrive smallint ,drive char(99))

    CREATE TABLE #temp1(drive char(99),shellCmd nvarchar(500));

    CREATE TABLE #results(drive char(99),freespace decimal(9,2), totalspace decimal(9,2));


    INSERT #drives (drive)

    EXEC master..xp_cmdshell 'mountvol'

    DELETE #drives WHERE drive not like '%:\%' or drive is null


    WHILE (@i <= (SELECT count(drive) FROM #drives))

    BEGIN

         UPDATE #drives
         SET iddrive=@i
         WHERE drive = (SELECT TOP 1 drive FROM #drives WHERE iddrive IS NULL)

         SELECT @v_sql = REPLACE(@v_cmd,'%d%',LTRIM(RTRIM(drive))) from #drives where iddrive=@i

         INSERT #temp1(shellCmd)
         EXEC master..xp_cmdshell @v_sql

         UPDATE #temp1
         SET #temp1.drive = d.drive
         FROM #drives d
         WHERE #temp1.drive IS NULL and iddrive=@i

        SET @i = @i + 1

    END


        INSERT INTO #results
        SELECT bb.drive
        ,CAST(CAST(REPLACE(REPLACE(SUBSTRING(shellCmd,CHARINDEX(':',shellCmd)+1,LEN(shellCmd)),SPACE(1),SPACE(0))
        ,char(13),SPACE(0)) AS NUMERIC(32,2))/1024/1024/1024 AS DECIMAL(9,2)) as freespace
        ,tt.titi as total
        FROM #temp1 bb
        JOIN (SELECT drive
        ,CAST(CAST(REPLACE(REPLACE(SUBSTRING(shellCmd,CHARINDEX(':',shellCmd)+1,LEN(shellCmd)),SPACE(1),SPACE(0))
        ,char(13),SPACE(0)) AS NUMERIC(32,2))/1024/1024/1024 AS DECIMAL(9,2)) as titi
        FROM #temp1
        WHERE drive IS NOT NULL
        AND shellCmd NOT LIKE '%free bytes%') tt
        ON bb.drive = tt.drive
        WHERE bb.drive IS NOT NULL
        AND bb.shellCmd NOT LIKE '%avail free bytes%'
        AND bb.shellCmd LIKE '%free bytes%';

    -- getting all system specific formatted data into @Drive table
    INSERT INTO @Drive
    SELECT LEFT(RTRIM(LTRIM(drive)),1) as drive
     ,freespace
     ,totalspace
     ,CAST((freespace/totalspace * 100) AS DECIMAL(5,2)) as [percent free]
    FROM #results
    ORDER BY drive

    -- Dropping temporary tables
    DROP TABLE #drives
    DROP TABLE #temp1
    DROP TABLE #results

    SELECT
         @@Servername as Server,
         sd.name as Database_name,
        mas.name as File_Name,
        mas.size * 8 / 1024 File_Size_MB,
        CASE [is_percent_growth]  
               WHEN 1 THEN CAST(mas.growth AS varchar(20)) + '%' 
                ELSE CAST(mas.growth*8/1024 AS varchar(20)) + ' MB' 
        END as Growth_rate,     
        drv.DriveName as Drive_Name,
        drv.FreeSpace,
        drv.totalspace,
        CASE type
               WHEN 0 THEN 'Data'  
               WHEN 1 THEN 'Log' 
        END as File_type, 
        mas.physical_name as File_Location
    FROM sys.master_files mas
    LEFT JOIN @Drive drv ON LEFT(mas.physical_name, 1) = drv.DriveName
    LEFT JOIN sys.databases sd ON mas.database_id = sd.database_id
    --WHERE sd.name IN ('db1','db2','db3') -- Specify the database name if this report is needed for specific databases
    --AND mas.growth <>0 -- Condition to retrive the record for growing files only.

END


  • You can restrict the output for some of the databases by providing the database name which is commented by default.

             --WHERE sd.name IN ('db1','db2','db3')  

  •  You can also restrict the output for growing files of the databases only by providing the growth <>0 which is commented by default.
             --AND mas.growth <>0

There are further filters also possible like if someone want to restrict the query upto a size limit of files etc. simply write it down in where clause.


Output:

Output should be like this:




This could be very useful where someone have multiple servers and DBA has to generate weekly/Monthly report for all of the server, in such scenario one can create a SSIS package and execute this query on all the server and generate a single report for all the servers.

Hope this will be helpful for people out there :) let me know if anyone has any issue.




Tuesday, May 22, 2012

Script all the jobs in SQL Server

This is very interesting fact that people always look for shortcuts especially while accomplishing the big tasks.

Here i have came up with a scenario: I have got a task to setup a new server B (lets assume) exactly as a replica of Existing Server A.

It involve a lot of steps in which there is a step to copy all the EXISTING JOBS FROM SERVER A to SERVER B (Please note i have written All the Jobs).

 Here is a easiest way i have found which might be helpful for many people.

Step1: Enable Object explorer detail.

Step2:
In SQL Server 2005 or earlier:  goto view->Summary
In SQL Server 2008 or older:  goto view-> Object Explorer Details

Step3:
Expand SQL Server Agent and click on Jobs.

All the jobs will be visible in summary/Object Explorer Detail window. (See Screenshot).





Step4:

Here you can select all the jobs or the desired jobs which you want to script out.

After select right click -> Script Job As -> Create To -> and select the desired location where you want to script all the selected jobs (In the screenshot i have selected New Query Editor Window).




Note: The above screenshots/Examples are of SQL Server 2008R2 you can follow the same steps with SQL Server 2005 or earlier versions.


I hope this will be helpful for may people out there :)



Friday, May 18, 2012

Database is in Transition. try the statement later: SQL Server

Problem:

I was trying to take the database offline to perform some maintenance on one of our QA server.

We have got a strange error "Database is in Transition. try the statement later Error 952"

Even i was not able to run the sp_who and sp_who2 also as it was also giving the same error.


Resolution:  What i have tried?

I closed the SSMS (SQL Server Management Studio) and restarted it again.

Then to confirm and check for any blocking query, i ran sp_who and sp_who2 and it ran successfully.

 Then to make Database offline/online i have used the below command and it worked like a charm :)

USE master
GO

ALTER DATABASE <db_name>

SET OFFLINE WITH ROLLBACK IMMEDIATE
...
...
ALTER DATABASE <db_name> SET ONLINE


Its a strange error with SQL-2005 Management Studio or we can say a bug.


This small issue can cause a big headache for someone.. hope this will helpful. :)

Saturday, August 20, 2011

zfs Snapshot Commands Example


As i have already discussed in my previous post zfs filesystem and MySQL about zfs overview and two most important command zpool and zfs. I am going to continue with usage of zfs snapshots. It includes create a pool, Create file system, Taking a snapshot, Renaming Snapshots, Listing all snapshots, restoring from snapshot and Moving the snapshot to other location.

snapshot is a read-only copy of a file system or volume. Snapshots can be created almost instantly, and initially consume no additional disk space within the pool. However, as data within the active dataset changes, the snapshot consumes disk space by continuing to reference the old data and so prevents the space from being freed. Snapshots of volumes cannot be accessed directly, but they can be cloned, backed up, rolled back to.

Creating a Pool:
# zpool create zpool1 c2t0d0

List pool:
# zpool list

Create file system under above create pool:
Once you have a storage pool, you can build file systems on it:

# zfs create zpool1/data # zfs create zpool1/logs
Here we have built “/data” file system on pool zpool1

List all zfs file systems:
# zfs list

Taking a Snapshot:
zfs snapshot < pool name>/<filesystem name>@<snapshot name>
Example:
# zfs snapshot zpool1/data01@Snapshot1

Remove/Destroy a Snapshot:
zfs destroy < pool name>/<filesystem name>@<snapshot name>
Example:
# zfs destroy zpool1/data01@Snapshot1

Rename Snapshots:
You can rename snapshots but they must be renamed within the pool and dataset from which they were created.
zfs rename < pool name>/<filesystem name>@<snapshot name> < pool name>/<filesystem name>@<snapshot name>
Example:
# zfs rename zpool1/data01@Snapshot1 zpool1/data01@Snapshot2

Below snapshot rename operation is not supported because the target pool and file system name are different from the pool and file system where the snapshot was created.

# zfs rename zpool1/data01@Snapshot1 zpool3/data01@Snapshot2

Displaying zfs Snapshots:
zfs list
zfs list -t snapshot

You can also list snapshots that were created for a particular file system:
zfs list -r -t snapshot -o <name>,<creation> <pool>/<home>

Restore/Rolling Back zfs snapshots:
zfs rollback < pool name>/<filesystem name>@<snapshot name>
Example:
# zfs rollback zpool1/data01@Snapshot1

This will restore the entire file system with snapshot.

Restoring individual files:
It is possible to copy individual file from a snapshot by changing into the hidden “.zfs” directory of the pool that has been snapped.

cd /<pool name>/<file system name>
cd .zfs
cp <required file source location> <destination>

Example:
cd /zpool1/data01
cd .zfs
cp <required file source location> <destination>

Moving a  Snapshot to another system:
Wecan move the snapshot to another system and install it there as a usable file system. But at first we need to create a pool to receive the snapshot on the target system.

Step1: Create Pool on another system.
# zpool create -f zpool11 c2t0d0

Step2: Send the snapshot over the network and receive it into the pool using a combination of zfs send/receive command and a netwolrk pipe.
# zfs send zpool1/data01@snapshot1 | ssh <destination host> “usr/sbin/zfs receive zpool11/<myfilesystem>

Here zpool11 is the name of pool on another system which we have created above and myfilesystem is the name of filesystem you wish to put.

 
© Copyright 2010-2012 Learn MySQL All Rights Reserved.
Template powered by Blogger.com.