Skyscraper

lunes, 26 de septiembre de 2011

Recovering a CentOS Grub After a Windows Installation

As you well know, the ways that windows uses always rewrite the MBR of the hard drive, I believe that Microsoft do this deliberately. Yesterday I installed a Windows XP in my laptop to do some compatibility test, but after two or three boots I discovered that my Grub is gone.  So I cannot boot CentOS, but not all is lost.

Below I will describe the steps to reinstall the Grub loader in the MBR:

First, boot with the CentOS DVD to access the rescue mode typing "linux rescue" in the command line.


Linux will boot in rescue mode and ask about the read only mode or continue with the rescue mode making changes in the filesystems.  Here is mandatory to select "Continue"


Now, we have a linux command line and the original system mounted under /mnt/sysimage, we need to change the root system with the chroot command to edit and reinstall grub.  In the image I use fdisk, chroot and ls.  The file grub.conf contains all grub texts and target filesystems.


With a simple vi, I added the entry for Windows XP.  In my case Windows resides in /dev/hda1 or (hd0,0)


Save the changes and execute /sbin/grub-install hd0 to install grub in the MBR of the hard disk.


Finally exit the command line or just reboot the system.  After the next boot grub appear (with the changes) as in the next image:



I think the solution also applies to Windows Vista, Windows 7 and I wish that Windows 8 respect the MBR and leave Grub in peace.

lunes, 18 de abril de 2011

Making Oracle 9i & 10g Case Insensitive

Sometimes it's useful to perform queries in Oracle that fetches all similar rows without worrying of uppercase or lowercase.

For example:

SELECT name FROM scott.users WHERE name LIKE '%Tiger%'

With case insensitive all results that contains the word "Tiger" are fetched, even the followings:
  • TIGER
  • tiger
  • TigeR
And all the possible variations.

These are the scripts to make a single session in Oracle 9i case insensitive:

ALTER SESSION SET NLS_COMP = ANSI;
ALTER SESSION SET NLS_SORT = GENERIC_BASELETTER;


These are the scripts to make a single session in Oracle 10g case insensitive:

ALTER SESSION SET NLS_COMP = LINGUISTIC;
ALTER SESSION SET NLS_SORT = BINARY_CI;


To make the session case sensitive again (Oracle 9i & Oracle 10g):

ALTER SESSION SET NLS_COMP = BINARY;
ALTER SESSION SET NLS_SORT = BINARY; 


This query will help checking the parameters of the database, instance and session:

SELECT d.parameter Dparameter, d.value Dvalue, i.parameter Iparameter, i.value Ivalue,
   s.parameter Sparameter, s.value Svalue
FROM nls_database_parameters d, nls_instance_parameters i, nls_session_parameters s
WHERE d.parameter = i.parameter (+) AND d.parameter = s.parameter (+)
ORDER BY 1;


Thanks to Don Burleson for publishing this SELECT statement Read more about NLS parameters here

lunes, 21 de febrero de 2011

AUTOMATIC BACKUP IN SQL SERVER

This entry will explain the implementation of an automatic backup in a SQL Server database using the SQL Server Agent.

First, we need to connect to a 'Database Engine' using the 'sa' user or an administrative account in the Microsoft SQL Server Managment Studio.

Once the SQL Server Agent tree is opened click on the New Job option.

A new window is displayed and asks for the following fields:
  • Name: The name of the job.
  • Owner: The owner of the job.  A existant login in the database
  • Category: Useful to group the database jobs.
  • Description: Useful to document the job.
  • Enabled: Checkbox that activate or deactivate the job after create it.

After filling all fields, click on the Steps Page.


Click on the New button to add a Script.

A new window is displayed and asks for the following fields:
  • Step Name: It's possible to define multiple steps in a job, this is the name of the step.
  • Type: The step permits to add different kind of Scripts (Operating System, ActiveX, Analysis Services, Integration Services Package) To automatic Backup choose Transact-SQL. 
  • Run as: In case that you want to use impersonation.
  • Database: Database where the script starts it's execution.
  • Command: The script itself.

After filling all fields, click OK to return to Steps page and click again on the Schedule Page or add more steps in case that it's necessary.


Click on the New button to add a Schedule.

A new window is displayed and asks for the following fields:
  • Name: It's possible to define multiple schedules in a job, this is the name of the schedule.
  • Schedule Type: The Schedule permits to add four different ways: (At the start of the SQL Server Agent, when the CPU becomes idle, recurring or one time execution) To automatic Backup choose Recurring. 
  • Frecuency: The schedule may occurs Daily, Weekly or Monthly. Each one has his own options.

After filling all fields, click OK to return to Schedule page.

Alerts and notifications can be set, or the Job can be created clicking again in the OK button.

martes, 11 de enero de 2011

Truncate LOG in a SQL Server 2005 Database

When the transaction log grows without control in a SQL Server 2005 database can reach the point to leave the database unavailable.  To avoid this situations it's recommended to execute this script to erase all transactions and recover some space:


USE ReportServerTempDB -- Database
GO
DBCC SHRINKFILE(ReportServerTempDB_log, 1) -- Parameters are: Logical Name of the file, percent occupied
BACKUP LOG ReportServerTempDB WITH TRUNCATE_ONLY
DBCC SHRINKFILE(ReportServerTempDB_log, 1) -- Parameters are: Logical Name of the file, percent occupied
GO 

It has been tested and works fine, another recommendation is never leave the database files with unrestricted Growth enabled.  I was notified about databases with 300 GB transaction log and this situation makes me laugh so much.

To learn more about this, check this link from Pinal's Dave Blog: Original Page