Monday 23 December 2013

32-bit and 64-bit explained

If you've asked these questions then this tutorial should help you to understand the concepts of 32-bit and 64-bit computing. We'll look at your computer system as three parts: the hardware, the operating system and the application programs.
32-bit versus 64-bit
As the number of bits increases there are two important benefits.
·         More bits means that data can be processed in larger chunks which also means more accurately.
·         More bits means our system can point to or address a larger number of locations in physical memory.
32-bit systems were once desired because they could address (point to) 4 Gigabytes (GB) of memory in one go. Some modern applications require more than 4 GB of memory to complete their tasks so 64-bit systems are now becoming more attractive because they can potentially address up to 4 billion times that many locations.
Since 1995, when Windows 95 was introduced with support for 32-bit applications, most of the software and operating system code has been 32-bit compatible.
Here is the problem, while most of the software available today is 32-bit, the processors we buy are almost all 64-bit.
So how long will the transition from 32-bit to 64-bit systems take?
The main issue is that your computer works from the hardware such as the processor (or CPU, as it is called), through the operating system (OS), to the highest level which is your applications. So the computer hardware is designed first, the matching operating systems are developed, and finally the applications appear.
We can look back at the transition from 16-bit to 32-bit Windows on 32-bit processors. It took 10 years (from 1985 to 1995) to get a 32-bit operating system and even now, more than 15 years later, there are many people still using 16-bit Windows applications on older versions of Windows.
The hardware and software vendors learnt from the previous transition, so the new operating systems have been released at the same time as the new processors. The problem this time is that there haven't been enough 64-bit applications. Ten years after the PC's first 64-bit processors, installs of 64-bit Windows are only now exceeding those of 32-bit Windows. Further evidence of this inertia is that you are probably reading this tutorial because you are looking to install your first 64-bit software.
Your computer system in three parts
Now we'll look at those three components of your system. In simple terms they are three layers with the processor or CPU as the central or lowest layer and the application as the outermost or highest layer as shown below:



To run a 64-bit operating system you need support from the lower level: the 64-bit CPU.
To run a 64-bit application you need support from all lower levels: the 64-bit OS and the 64-bit CPU.
This simplification will be enough for us to look what happens when we mix the 32-bit and 64-bit parts. But if you want to understand the issue more deeply then you will also need to consider the hardware that supports the CPU and the device drivers that allow the OS and the applications to interface with the system hardware.
What 32-bit and 64-bit combinations are compatible and will work together?
This is where we get to the practicalities and can start answering common questions.
The general rule is that 32-bit will run on a lower level 64-bit component but 64-bit does not run on a lower level 32-bit component:
·         A 32-bit OS will run on a 32-bit or 64-bit processor without any problem.
·         A 32-bit application will run on a 32-bit or 64-bit OS without any problem.
·         But a 64-bit application will only run on a 64-bit OS and a 64-bit OS will only run on a 64-bit processor.
These two tables illustrate the same rule:
Table 1 — What is compatible if I have a 32-bit CPU?
Processor (CPU)
32-bit
32-bit
32-bit
32-bit
Operating System (OS)
32-bit
32-bit
64-bit
64-bit
Application Program
32-bit
64-bit
32-bit
64-bit

Yes
No
No
No

Table 2 — What is compatible if I have a 64-bit CPU?
Processor (CPU)
64-bit
64-bit
64-bit
64-bit
Operating System (OS)
64-bit
64-bit
32-bit
32-bit
Application Program
64-bit
32-bit
32-bit
64-bit

Yes
Yes
Yes
No
The main reason that 32-bit will always run on 64-bit is that the 64-bit components have been designed to work that way. So the newer 64-bit systems are backward-compatible with the 32-bit systems (which is the main reason most of us haven't moved to 64-bit software).
An example of backward compatibility is Windows 64-bit. It has software called WOW64 that provides compatibility by emulating a 32-bit system. One important point that is made in that article is that it is not possible to install a 32-bit device driver on a 64-bit operating system. This is because device drivers run in parallel to the operating system. The emulation is done at the operating system level so it is available to the higher layer, the application, but it is not available to the device driver which runs on the same level.
Hardware virtualization is the exception to the rule
Another question many people have is whether a 32-bit system can run 64-bit software. As more people are looking to use 64-bit Windows they are wanting to try it out on their existing systems. So we are getting more questions about whether they can run it on their 32-bit processor or under their 32-bit OS.
Following the general rule, we would expect that you cannot run 64-bit software on a 32-bit system. Except that there is one exception called virtualization.
Virtualization creates a virtual system within the actual system. Virtualization can be achieved in hardware or software but it works best if the virtual machine is created in the system hardware. The guest operating system is not aware that there is a host operating system already running. This is the way that a 64-bit operating system can think that it is running on 64-bit hardware without being aware that there is a 32-bit operating system in the mix.
Tables 3 and 4 illustrate the result. Provided that the virtual machine can actually be created and isolated by the virtualizing software then the host OS is effectively removed from the equation, so I've grayed it out. We can now apply the general rules for a non-virtualized system to the three remaining layers.
Table 3 — What is compatible if I have a 32-bit CPU and software virtualization?
Processor (CPU)
32-bit
32-bit
32-bit
32-bit
Host Operating System
32-bit
32-bit
32-bit
32-bit
Guest Operating System
32-bit
32-bit
64-bit
64-bit
Application Program
32-bit
64-bit
32-bit
64-bit

Yes
No
No
No

Table 4 — What is compatible if I have a 64-bit CPU and software virtualization?
Processor (CPU)
64-bit
64-bit
64-bit
64-bit
Host Operating System
32/64-bit
32/64-bit
32/64-bit
32/64-bit
Guest Operating System
64-bit
64-bit
32-bit
32-bit
Application Program
64-bit
32-bit
32-bit
64-bit

Yes
Yes
Yes
No
Before you hurry away to try running 64-bit in a virtual machine, you must check that your computer BIOS supports hardware virtualization. If it does not then hardware virtualization will not work even if the CPU does support it.
Emulation of the 64-bit CPU is not an option
All the feasible configurations that we have looked at so far have the processors (CPUs) running software that use the instruction set that is native to that processor. Running 64-bit software on a 32-bit processor doesn't work because the 64-bit instructions are not native to a 32-bit processor. But what if I could emulate a 64-bit processor using 32-bit software?
It is theoretically possible but practically impossible to emulate a 64-bit processor while running software on a 32-bit processor. Even if you can get non-native 64-bit emulation to work, the virtual machine that duplicates a 64-bit CPU would run very slowly because every 64-bit instruction has to be trapped and handled by the emulator. 64-bit memory pointers also have to be converted to work within the 32-bit address space.

Furthermore, my understanding is that the x86 (32-bit) processors used in PCs and Apple Macs are not able to completely emulate the x64 (64-bit) instruction set. Some 64-bit instructions cannot be trapped by the emulator. This causes the system to crash when the x86 processor tried to run those x64 instructions.

Failover and Failback in Logshipping (MSSQL Server 2008 R2)

   Database State & Jobs on Primary & Secondary Server:

    Database State on Primary Server (bhamare3):

 Database State on Secondary Server (bhamare3\Named):
  Log shipping jobs on Primary & Secondary Server:

·         Log shipping Jobs on Primary Server (bhamare3):


         Log shipping Jobs on Secondary Server (bhamare3\Named):



·         Check the log shipping is in sync by executing following query on Secondary Server (bhamare3\Named).


select secondary_database,last_copied_file,last_restored_file from msdb..log_shipping_monitor_secondary




·         You can generate the log shipping sync report on Secondary Server (bhamare3\Named)  by

Right click on Instance Name > Reports > Standard Reports > Transaction Log shipping status




   Backup Logins:

If you simply want to make a backup of your SQL Server Logins for disaster recovery purposes
 just follow these easy steps:

On the Primary server (bhamare3) launch SQL Management Studio & connect to the instance of SQL Server.

USE master
GO
IF OBJECT_ID ('sp_hexadecimal') IS NOT NULL
  DROP PROCEDURE sp_hexadecimal
GO
CREATE PROCEDURE sp_hexadecimal
    @binvalue varbinary(256),
    @hexvalue varchar (514) OUTPUT
AS
DECLARE @charvalue varchar (514)
DECLARE @i int
DECLARE @length int
DECLARE @hexstring char(16)
SELECT @charvalue = '0x'
SELECT @i = 1
SELECT @length = DATALENGTH (@binvalue)
SELECT @hexstring = '0123456789ABCDEF'
WHILE (@i <= @length)
BEGIN
  DECLARE @tempint int
  DECLARE @firstint int
  DECLARE @secondint int
  SELECT @tempint = CONVERT(int, SUBSTRING(@binvalue,@i,1))
  SELECT @firstint = FLOOR(@tempint/16)
  SELECT @secondint = @tempint - (@firstint*16)
  SELECT @charvalue = @charvalue +
    SUBSTRING(@hexstring, @firstint+1, 1) +
    SUBSTRING(@hexstring, @secondint+1, 1)
  SELECT @i = @i + 1
END

SELECT @hexvalue = @charvalue
GO

IF OBJECT_ID ('sp_help_revlogin') IS NOT NULL
  DROP PROCEDURE sp_help_revlogin
GO
CREATE PROCEDURE sp_help_revlogin @login_name sysname = NULL AS
DECLARE @name sysname
DECLARE @type varchar (1)
DECLARE @hasaccess int
DECLARE @denylogin int
DECLARE @is_disabled int
DECLARE @PWD_varbinary  varbinary (256)
DECLARE @PWD_string  varchar (514)
DECLARE @SID_varbinary varbinary (85)
DECLARE @SID_string varchar (514)
DECLARE @tmpstr  varchar (1024)
DECLARE @is_policy_checked varchar (3)
DECLARE @is_expiration_checked varchar (3)

DECLARE @defaultdb sysname

IF (@login_name IS NULL)
  DECLARE login_curs CURSOR FOR

      SELECT p.sid, p.name, p.type, p.is_disabled, p.default_database_name, l.hasaccess, l.denylogin FROM
sys.server_principals p LEFT JOIN sys.syslogins l
      ON ( l.name = p.name ) WHERE p.type IN ( 'S', 'G', 'U' ) AND p.name <> 'sa'
ELSE
  DECLARE login_curs CURSOR FOR


      SELECT p.sid, p.name, p.type, p.is_disabled, p.default_database_name, l.hasaccess, l.denylogin FROM
sys.server_principals p LEFT JOIN sys.syslogins l
      ON ( l.name = p.name ) WHERE p.type IN ( 'S', 'G', 'U' ) AND p.name = @login_name
OPEN login_curs

FETCH NEXT FROM login_curs INTO @SID_varbinary, @name, @type, @is_disabled, @defaultdb, @hasaccess, @denylogin
IF (@@fetch_status = -1)
BEGIN
  PRINT 'No login(s) found.'
  CLOSE login_curs
  DEALLOCATE login_curs
  RETURN -1
END
SET @tmpstr = '/* sp_help_revlogin script '
PRINT @tmpstr
SET @tmpstr = '** Generated ' + CONVERT (varchar, GETDATE()) + ' on ' + @@SERVERNAME + ' */'
PRINT @tmpstr
PRINT ''
WHILE (@@fetch_status <> -1)
BEGIN
  IF (@@fetch_status <> -2)
  BEGIN
    PRINT ''
    SET @tmpstr = '-- Login: ' + @name
    PRINT @tmpstr
    IF (@type IN ( 'G', 'U'))
    BEGIN -- NT authenticated account/group

      SET @tmpstr = 'CREATE LOGIN ' + QUOTENAME( @name ) + ' FROM WINDOWS WITH DEFAULT_DATABASE = [' + @defaultdb + ']'
    END
    ELSE BEGIN -- SQL Server authentication
        -- obtain password and sid
            SET @PWD_varbinary = CAST( LOGINPROPERTY( @name, 'PasswordHash' ) AS varbinary (256) )
        EXEC sp_hexadecimal @PWD_varbinary, @PWD_string OUT
        EXEC sp_hexadecimal @SID_varbinary,@SID_string OUT

        -- obtain password policy state
        SELECT @is_policy_checked = CASE is_policy_checked WHEN 1 THEN 'ON' WHEN 0 THEN 'OFF' ELSE NULL END FROM sys.sql_logins WHERE name = @name
        SELECT @is_expiration_checked = CASE is_expiration_checked WHEN 1 THEN 'ON' WHEN 0 THEN 'OFF' ELSE NULL END FROM sys.sql_logins WHERE name = @name

            SET @tmpstr = 'CREATE LOGIN ' + QUOTENAME( @name ) + ' WITH PASSWORD = ' + @PWD_string + ' HASHED, SID = ' + @SID_string + ', DEFAULT_DATABASE = [' + @defaultdb + ']'

        IF ( @is_policy_checked IS NOT NULL )
        BEGIN
          SET @tmpstr = @tmpstr + ', CHECK_POLICY = ' + @is_policy_checked
        END
        IF ( @is_expiration_checked IS NOT NULL )
        BEGIN
          SET @tmpstr = @tmpstr + ', CHECK_EXPIRATION = ' + @is_expiration_checked
        END
    END
    IF (@denylogin = 1)
    BEGIN -- login is denied access
      SET @tmpstr = @tmpstr + '; DENY CONNECT SQL TO ' + QUOTENAME( @name )
    END
    ELSE IF (@hasaccess = 0)
    BEGIN -- login exists but does not have access
      SET @tmpstr = @tmpstr + '; REVOKE CONNECT SQL TO ' + QUOTENAME( @name )
    END
    IF (@is_disabled = 1)
    BEGIN -- login is disabled
      SET @tmpstr = @tmpstr + '; ALTER LOGIN ' + QUOTENAME( @name ) + ' DISABLE'
    END
    PRINT @tmpstr
  END

  FETCH NEXT FROM login_curs INTO @SID_varbinary, @name, @type, @is_disabled, @defaultdb, @hasaccess, @denylogin
   END
CLOSE login_curs
DEALLOCATE login_curs
RETURN 0
GO

·         Note This script creates two stored procedures in the master database. The two stored procedures are named the sp_hexadecimal stored procedure and the sp_help_revlogin stored procedure.


·         Run the following statement.
EXEC sp_help_revlogin
·         The output script that is generated by the sp_help_revlogin stored procedure is the login script. This login script creates the logins that have the original Security Identifier (SID) and the original password.


  
    Failover:

·         Before Disabling Log shipping jobs please Copy any uncopied backup files from the Shared Folder on Primary server to the Shared destination folder on secondary server by using copy job.

·         Check all the Transaction log has been successfully applied on the secondary server, if not please run the Restore Job to apply unapplied transaction log backups on secondary server.


             Disable Log Shipping Jobs:


·         Disable Log shipping jobs on Primary Server (bhamare3).


·         Disable Log shipping jobs on Secondary Server (bhamare3\Named).





       T-Log Backup:

  • Kill the sessions open for the DB on which you have to take Tail log backup.
  • Manually perform a tail-log backup of the transaction log on the primary database specifying leave database in Restoring State. This log backup captures any log records that have not been backed up yet and takes the database in Restoring state. The following example creates a tail log backup of the ‘AdventureWorks2008’ database on the primary server.
  • We recommend that you use a distinct file naming convention to differentiate the manually-created backup file from the backup files created by the log shipping backup job.




·         Select Backup tail log and leave database in restoring state option.



·         DB on primary Server (bhamare3) will go in restoring state.
             Restore T-Log Backup:

·         Now restore the tlog backup on Secondary Server(bhamare3\Named).




·         The database on secondary server (bhamare3\Named) will come in online state.


·         Check all the transactions are happening correctly.

        Log Shipping Configuration:


·         Now configure log shipping on Secondary Server (bhamare3\Named) DB.









       Failback:

           Run Log shipping jobs:


·         Run the log shipping jobs on the primary server(bhamare3\Named).






           Log shipping Sync:

·         Check the log shipping is in sync by executing following query on Secondary Server (bhamare3).

select secondary_database,last_copied_file,last_restored_file from msdb..log_shipping_monitor_secondary




·         You can generate the log shipping sync report on Secondary Server (bhamare3)by

Right click on Instance Name > Reports > Standard Reports > Transaction Log shipping status




             T-Log Backup:

  • Kill the sessions open for the DB on which you have to take Tail log backup.
  • Manually perform a tail-log backup of the transaction log on the primary database specifying leave database in Restoring State. This log backup captures any log records that have not been backed up yet and takes the database in Restoring state. The following example creates a tail log backup of the ‘AdventureWorks2008’ database on the primary server.
  • We recommend that you use a distinct file naming convention to differentiate the manually-created backup file from the backup files created by the log shipping backup job.



·         Select Backup tail log and leave database in restoring state option.





            Disable Log shipping jobs:

·         Disable the Log shipping job on Primary Server (bhamare3\Named).


·         Before Disabling Log shipping jobs please Copy any uncopied backup files from the Shared Folder on Primary server to the Shared destination folder on secondary server by using copy job.

·         Check all the Transaction log has been successfully applied on the secondary server, if not please run the Restore Job to apply unapplied transaction log backups on secondary server.






            Restore T-Log Backup:


·         Now restore the tlog backup on Secondary Server (bhamare3).






·         The DB on Secondary server (bhamare3) will go in restoring state.




·         Now enable the Log shipping jobs on Secondary server (bhamare3).






·         Start / Run Log shipping Jobs on secondary server (bhamare3).






·         The DB on primary Server (bhamare3\Named) will go in Stand by state means this server will become secondary server.
              Log Shipping Sync:

·         Check the log shipping is in sync by executing following query on Secondary Server(bhamare3\Named).

select secondary_database,last_copied_file,last_restored_file from msdb..log_shipping_monitor_secondary




·         You can generate the log shipping sync report on Secondary Server (bhamare3\Named) by Right click on Instance Name > Reports > Standard Reports > Transaction Log shipping status